@clawos-dev/clawd 0.2.293 → 0.2.294

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.
@@ -92,7 +92,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
92
92
  0 -6px 16px 0 rgba(0, 0, 0, 0.08),
93
93
  0 -3px 6px -4px rgba(0, 0, 0, 0.12),
94
94
  0 -9px 28px 8px rgba(0, 0, 0, 0.05)
95
- `,boxShadowTabsOverflowLeft:"inset 10px 0 8px -8px rgba(0, 0, 0, 0.08)",boxShadowTabsOverflowRight:"inset -10px 0 8px -8px rgba(0, 0, 0, 0.08)",boxShadowTabsOverflowTop:"inset 0 10px 8px -8px rgba(0, 0, 0, 0.08)",boxShadowTabsOverflowBottom:"inset 0 -10px 8px -8px rgba(0, 0, 0, 0.08)"}),r)}var ob=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};const cD={lineHeight:!0,lineHeightSM:!0,lineHeightLG:!0,lineHeightHeading1:!0,lineHeightHeading2:!0,lineHeightHeading3:!0,lineHeightHeading4:!0,lineHeightHeading5:!0,opacityLoading:!0,fontWeightStrong:!0,zIndexPopupBase:!0,zIndexBase:!0,opacityImage:!0},uD={motionBase:!0,motionUnit:!0},dD={screenXS:!0,screenXSMin:!0,screenXSMax:!0,screenSM:!0,screenSMMin:!0,screenSMMax:!0,screenMD:!0,screenMDMin:!0,screenMDMax:!0,screenLG:!0,screenLGMin:!0,screenLGMax:!0,screenXL:!0,screenXLMin:!0,screenXLMax:!0,screenXXL:!0,screenXXLMin:!0},GE=(e,t,n)=>{const r=n.getDerivativeToken(e),{override:i}=t,s=ob(t,["override"]);let o=Object.assign(Object.assign({},r),{override:i});return o=KE(o),s&&Object.entries(s).forEach(([a,l])=>{const{theme:c}=l,u=ob(l,["theme"]);let d=u;c&&(d=GE(Object.assign(Object.assign({},o),u),{override:u},c)),o[a]=d}),o};function XE(){const{token:e,hashed:t,theme:n,override:r,cssVar:i}=st.useContext(VE),s=`${aD}-${t||""}`,o=n||WE,[a,l,c]=Z3(o,[Tc,e],{salt:s,override:r,getComputedToken:GE,formatToken:KE,cssVar:i&&{prefix:i.prefix,key:i.key,unitless:cD,ignore:uD,preserve:dD}});return[o,c,t?l:"",a,i]}const hD=()=>({display:"inline-flex",alignItems:"center",color:"inherit",fontStyle:"normal",lineHeight:0,textAlign:"center",textTransform:"none",verticalAlign:"-0.125em",textRendering:"optimizeLegibility","-webkit-font-smoothing":"antialiased","-moz-osx-font-smoothing":"grayscale","> *":{lineHeight:1},svg:{display:"inline-block"}}),fD=e=>({[`.${e}`]:Object.assign(Object.assign({},hD()),{[`.${e} .${e}-icon`]:{display:"block"}})}),pD=(e,t)=>{const[n,r]=XE();return C4({token:r,hashId:"",path:["ant-design-icons",e],nonce:()=>t==null?void 0:t.nonce,layer:{name:"antd"}},()=>fD(e))},mD=Object.assign({},Ha),{useId:ab}=mD,gD=()=>"",vD=typeof ab>"u"?gD:ab;function xD(e,t,n){var r;const i=e||{},s=i.inherit===!1||!t?Object.assign(Object.assign({},bh),{hashed:(r=t==null?void 0:t.hashed)!==null&&r!==void 0?r:bh.hashed,cssVar:t==null?void 0:t.cssVar}):t,o=vD();return fE(()=>{var a,l;if(!e)return t;const c=Object.assign({},s.components);Object.keys(e.components||{}).forEach(f=>{c[f]=Object.assign(Object.assign({},c[f]),e.components[f])});const u=`css-var-${o.replace(/:/g,"")}`,d=((a=i.cssVar)!==null&&a!==void 0?a:s.cssVar)&&Object.assign(Object.assign(Object.assign({prefix:n==null?void 0:n.prefixCls},typeof s.cssVar=="object"?s.cssVar:{}),typeof i.cssVar=="object"?i.cssVar:{}),{key:typeof i.cssVar=="object"&&((l=i.cssVar)===null||l===void 0?void 0:l.key)||u});return Object.assign(Object.assign(Object.assign({},s),i),{token:Object.assign(Object.assign({},s.token),i.token),components:c,cssVar:d})},[i,s],(a,l)=>a.some((c,u)=>{const d=l[u];return!C3(c,d,!0)}))}var _D=["children"],YE=g.createContext({});function yD(e){var t=e.children,n=Hg(e,_D);return g.createElement(YE.Provider,{value:n},t)}var bD=function(e){mE(n,e);var t=vE(n);function n(){return Va(this,n),t.apply(this,arguments)}return qa(n,[{key:"render",value:function(){return this.props.children}}]),n}(g.Component);function wD(e){var t=g.useReducer(function(a){return a+1},0),n=Qe(t,2),r=n[1],i=g.useRef(e),s=uv(function(){return i.current}),o=uv(function(a){i.current=typeof a=="function"?a(i.current):a,r()});return[s,o]}var Ji="none",Uu="appear",Wu="enter",Vu="leave",lb="none",Tr="prepare",la="start",ca="active",$x="end",ZE="prepared";function cb(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n["Webkit".concat(e)]="webkit".concat(t),n["Moz".concat(e)]="moz".concat(t),n["ms".concat(e)]="MS".concat(t),n["O".concat(e)]="o".concat(t.toLowerCase()),n}function SD(e,t){var n={animationend:cb("Animation","AnimationEnd"),transitionend:cb("Transition","TransitionEnd")};return e&&("AnimationEvent"in t||delete n.animationend.animation,"TransitionEvent"in t||delete n.transitionend.transition),n}var kD=SD(Oi(),typeof window<"u"?window:{}),QE={};if(Oi()){var CD=document.createElement("div");QE=CD.style}var qu={};function JE(e){if(qu[e])return qu[e];var t=kD[e];if(t)for(var n=Object.keys(t),r=n.length,i=0;i<r;i+=1){var s=n[i];if(Object.prototype.hasOwnProperty.call(t,s)&&s in QE)return qu[e]=t[s],qu[e]}return""}var eN=JE("animationend"),tN=JE("transitionend"),nN=!!(eN&&tN),ub=eN||"animationend",db=tN||"transitionend";function hb(e,t){if(!e)return null;if(Ct(e)==="object"){var n=t.replace(/-\w/g,function(r){return r[1].toUpperCase()});return e[n]}return"".concat(e,"-").concat(t)}const ED=function(e){var t=g.useRef();function n(i){i&&(i.removeEventListener(db,e),i.removeEventListener(ub,e))}function r(i){t.current&&t.current!==i&&n(t.current),i&&i!==t.current&&(i.addEventListener(db,e),i.addEventListener(ub,e),t.current=i)}return g.useEffect(function(){return function(){n(t.current)}},[]),[r,n]};var rN=Oi()?g.useLayoutEffect:g.useEffect;const ND=function(){var e=g.useRef(null);function t(){$g.cancel(e.current)}function n(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2;t();var s=$g(function(){i<=1?r({isCanceled:function(){return s!==e.current}}):n(r,i-1)});e.current=s}return g.useEffect(function(){return function(){t()}},[]),[n,t]};var TD=[Tr,la,ca,$x],PD=[Tr,ZE],iN=!1,ID=!0;function sN(e){return e===ca||e===$x}const RD=function(e,t,n){var r=dv(lb),i=Qe(r,2),s=i[0],o=i[1],a=ND(),l=Qe(a,2),c=l[0],u=l[1];function d(){o(Tr,!0)}var f=t?PD:TD;return rN(function(){if(s!==lb&&s!==$x){var p=f.indexOf(s),m=f[p+1],v=n(s);v===iN?o(m,!0):m&&c(function(y){function x(){y.isCanceled()||o(m,!0)}v===!0?x():Promise.resolve(v).then(x)})}},[e,s]),g.useEffect(function(){return function(){u()}},[]),[d,s]};function MD(e,t,n,r){var i=r.motionEnter,s=i===void 0?!0:i,o=r.motionAppear,a=o===void 0?!0:o,l=r.motionLeave,c=l===void 0?!0:l,u=r.motionDeadline,d=r.motionLeaveImmediately,f=r.onAppearPrepare,p=r.onEnterPrepare,m=r.onLeavePrepare,v=r.onAppearStart,y=r.onEnterStart,x=r.onLeaveStart,_=r.onAppearActive,b=r.onEnterActive,w=r.onLeaveActive,k=r.onAppearEnd,C=r.onEnterEnd,N=r.onLeaveEnd,T=r.onVisibleChanged,L=dv(),P=Qe(L,2),O=P[0],I=P[1],R=wD(Ji),D=Qe(R,2),z=D[0],$=D[1],F=dv(null),j=Qe(F,2),B=j[0],E=j[1],H=z(),q=g.useRef(!1),M=g.useRef(null);function re(){return n()}var oe=g.useRef(!1);function V(){$(Ji),E(null,!0)}var pe=uv(function(Ue){var nt=z();if(nt!==Ji){var mt=re();if(!(Ue&&!Ue.deadline&&Ue.target!==mt)){var Xt=oe.current,pn;nt===Uu&&Xt?pn=k==null?void 0:k(mt,Ue):nt===Wu&&Xt?pn=C==null?void 0:C(mt,Ue):nt===Vu&&Xt&&(pn=N==null?void 0:N(mt,Ue)),Xt&&pn!==!1&&V()}}}),Oe=ED(pe),ie=Qe(Oe,1),Ae=ie[0],Fe=function(nt){switch(nt){case Uu:return we(we(we({},Tr,f),la,v),ca,_);case Wu:return we(we(we({},Tr,p),la,y),ca,b);case Vu:return we(we(we({},Tr,m),la,x),ca,w);default:return{}}},We=g.useMemo(function(){return Fe(H)},[H]),ge=RD(H,!e,function(Ue){if(Ue===Tr){var nt=We[Tr];return nt?nt(re()):iN}if(wt in We){var mt;E(((mt=We[wt])===null||mt===void 0?void 0:mt.call(We,re(),null))||null)}return wt===ca&&H!==Ji&&(Ae(re()),u>0&&(clearTimeout(M.current),M.current=setTimeout(function(){pe({deadline:!0})},u))),wt===ZE&&V(),ID}),qe=Qe(ge,2),Gt=qe[0],wt=qe[1],Rt=sN(wt);oe.current=Rt;var ln=g.useRef(null);rN(function(){if(!(q.current&&ln.current===t)){I(t);var Ue=q.current;q.current=!0;var nt;!Ue&&t&&a&&(nt=Uu),Ue&&t&&s&&(nt=Wu),(Ue&&!t&&c||!Ue&&d&&!t&&c)&&(nt=Vu);var mt=Fe(nt);nt&&(e||mt[Tr])?($(nt),Gt()):$(Ji),ln.current=t}},[t]),g.useEffect(function(){(H===Uu&&!a||H===Wu&&!s||H===Vu&&!c)&&$(Ji)},[a,s,c]),g.useEffect(function(){return function(){q.current=!1,clearTimeout(M.current)}},[]);var Bt=g.useRef(!1);g.useEffect(function(){O&&(Bt.current=!0),O!==void 0&&H===Ji&&((Bt.current||O)&&(T==null||T(O)),Bt.current=!0)},[O,H]);var at=B;return We[Tr]&&wt===la&&(at=Be({transition:"none"},at)),[H,wt,at,O??t]}function AD(e){var t=e;Ct(e)==="object"&&(t=e.transitionSupport);function n(i,s){return!!(i.motionName&&t&&s!==!1)}var r=g.forwardRef(function(i,s){var o=i.visible,a=o===void 0?!0:o,l=i.removeOnLeave,c=l===void 0?!0:l,u=i.forceRender,d=i.children,f=i.motionName,p=i.leavedClassName,m=i.eventProps,v=g.useContext(YE),y=v.motion,x=n(i,y),_=g.useRef(),b=g.useRef();function w(){try{return _.current instanceof HTMLElement?_.current:l3(b.current)}catch{return null}}var k=MD(x,a,w,i),C=Qe(k,4),N=C[0],T=C[1],L=C[2],P=C[3],O=g.useRef(P);P&&(O.current=!0);var I=g.useCallback(function(j){_.current=j,h3(s,j)},[s]),R,D=Be(Be({},m),{},{visible:a});if(!d)R=null;else if(N===Ji)P?R=d(Be({},D),I):!c&&O.current&&p?R=d(Be(Be({},D),{},{className:p}),I):u||!c&&!p?R=d(Be(Be({},D),{},{style:{display:"none"}}),I):R=null;else{var z;T===Tr?z="prepare":sN(T)?z="active":T===la&&(z="start");var $=hb(f,"".concat(N,"-").concat(z));R=d(Be(Be({},D),{},{className:Y5(hb(f,N),we(we({},$,$&&z),f,typeof f=="string")),style:L}),I)}if(g.isValidElement(R)&&f3(R)){var F=p3(R);F||(R=g.cloneElement(R,{ref:I}))}return g.createElement(bD,{ref:b},R)});return r.displayName="CSSMotion",r}const jD=AD(nN);var hv="add",fv="keep",pv="remove",qp="removed";function DD(e){var t;return e&&Ct(e)==="object"&&"key"in e?t=e:t={key:e},Be(Be({},t),{},{key:String(t.key)})}function mv(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return e.map(DD)}function LD(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],n=[],r=0,i=t.length,s=mv(e),o=mv(t);s.forEach(function(c){for(var u=!1,d=r;d<i;d+=1){var f=o[d];if(f.key===c.key){r<d&&(n=n.concat(o.slice(r,d).map(function(p){return Be(Be({},p),{},{status:hv})})),r=d),n.push(Be(Be({},f),{},{status:fv})),r+=1,u=!0;break}}u||n.push(Be(Be({},c),{},{status:pv}))}),r<i&&(n=n.concat(o.slice(r).map(function(c){return Be(Be({},c),{},{status:hv})})));var a={};n.forEach(function(c){var u=c.key;a[u]=(a[u]||0)+1});var l=Object.keys(a).filter(function(c){return a[c]>1});return l.forEach(function(c){n=n.filter(function(u){var d=u.key,f=u.status;return d!==c||f!==pv}),n.forEach(function(u){u.key===c&&(u.status=fv)})}),n}var OD=["component","children","onVisibleChanged","onAllRemoved"],BD=["status"],zD=["eventProps","visible","children","motionName","motionAppear","motionEnter","motionLeave","motionLeaveImmediately","motionDeadline","removeOnLeave","leavedClassName","onAppearPrepare","onAppearStart","onAppearActive","onAppearEnd","onEnterStart","onEnterActive","onEnterEnd","onLeaveStart","onLeaveActive","onLeaveEnd"];function $D(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:jD,n=function(r){mE(s,r);var i=vE(s);function s(){var o;Va(this,s);for(var a=arguments.length,l=new Array(a),c=0;c<a;c++)l[c]=arguments[c];return o=i.call.apply(i,[this].concat(l)),we(Bg(o),"state",{keyEntities:[]}),we(Bg(o),"removeKey",function(u){o.setState(function(d){var f=d.keyEntities.map(function(p){return p.key!==u?p:Be(Be({},p),{},{status:qp})});return{keyEntities:f}},function(){var d=o.state.keyEntities,f=d.filter(function(p){var m=p.status;return m!==qp}).length;f===0&&o.props.onAllRemoved&&o.props.onAllRemoved()})}),o}return qa(s,[{key:"render",value:function(){var a=this,l=this.state.keyEntities,c=this.props,u=c.component,d=c.children,f=c.onVisibleChanged;c.onAllRemoved;var p=Hg(c,OD),m=u||g.Fragment,v={};return zD.forEach(function(y){v[y]=p[y],delete p[y]}),delete p.keys,g.createElement(m,p,l.map(function(y,x){var _=y.status,b=Hg(y,BD),w=_===hv||_===fv;return g.createElement(t,xh({},v,{key:b.key,visible:w,eventProps:b,onVisibleChanged:function(C){f==null||f(C,{key:b.key}),C||a.removeKey(b.key)}}),function(k,C){return d(Be(Be({},k),{},{index:x}),C)})}))}}],[{key:"getDerivedStateFromProps",value:function(a,l){var c=a.keys,u=l.keyEntities,d=mv(c),f=LD(u,d);return{keyEntities:f.filter(function(p){var m=u.find(function(v){var y=v.key;return p.key===y});return!(m&&m.status===qp&&p.status===pv)})}}}]),s}(g.Component);return we(n,"defaultProps",{component:"div"}),n}$D(nN);const fb=g.createContext(!0);function FD(e){const t=g.useContext(fb),{children:n}=e,[,r]=XE(),{motion:i}=r,s=g.useRef(!1);return s.current||(s.current=t!==i),s.current?g.createElement(fb.Provider,{value:i},g.createElement(yD,{motion:i},n)):n}const HD=()=>null;var UD=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};const WD=["getTargetContainer","getPopupContainer","renderEmpty","input","pagination","form","select","button"];let oN;function VD(){return oN||lv}function qD(e){return Object.keys(e).some(t=>t.endsWith("Color"))}const KD=e=>{const{prefixCls:t,iconPrefixCls:n,theme:r,holderRender:i}=e;t!==void 0&&(oN=t),r&&qD(r)&&tD(VD(),r)},GD=e=>{const{children:t,csp:n,autoInsertSpaceInButton:r,alert:i,anchor:s,form:o,locale:a,componentSize:l,direction:c,space:u,splitter:d,virtual:f,dropdownMatchSelectWidth:p,popupMatchSelectWidth:m,popupOverflow:v,legacyLocale:y,parentContext:x,iconPrefixCls:_,theme:b,componentDisabled:w,segmented:k,statistic:C,spin:N,calendar:T,carousel:L,cascader:P,collapse:O,typography:I,checkbox:R,descriptions:D,divider:z,drawer:$,skeleton:F,steps:j,image:B,layout:E,list:H,mentions:q,modal:M,progress:re,result:oe,slider:V,breadcrumb:pe,menu:Oe,pagination:ie,input:Ae,textArea:Fe,empty:We,badge:ge,radio:qe,rate:Gt,switch:wt,transfer:Rt,avatar:ln,message:Bt,tag:at,table:Ue,card:nt,tabs:mt,timeline:Xt,timePicker:pn,upload:U,notification:Q,tree:ve,colorPicker:Se,datePicker:J,rangePicker:Xe,flex:Yt,wave:Zt,dropdown:ue,warning:Te,tour:Je,tooltip:Dn,popover:Qt,popconfirm:sl,floatButton:jo,floatButtonGroup:_u,variant:yu,inputNumber:cp,treeSelect:up}=e,bu=g.useCallback((Tt,$t)=>{const{prefixCls:or}=e;if($t)return $t;const Ln=or||x.getPrefixCls("");return Tt?`${Ln}-${Tt}`:Ln},[x.getPrefixCls,e.prefixCls]),Do=_||x.iconPrefixCls||qE,Lo=n||x.csp;pD(Do,Lo);const ol=xD(b,x.theme,{prefixCls:bu("")}),al={csp:Lo,autoInsertSpaceInButton:r,alert:i,anchor:s,locale:a||y,direction:c,space:u,splitter:d,virtual:f,popupMatchSelectWidth:m??p,popupOverflow:v,getPrefixCls:bu,iconPrefixCls:Do,theme:ol,segmented:k,statistic:C,spin:N,calendar:T,carousel:L,cascader:P,collapse:O,typography:I,checkbox:R,descriptions:D,divider:z,drawer:$,skeleton:F,steps:j,image:B,input:Ae,textArea:Fe,layout:E,list:H,mentions:q,modal:M,progress:re,result:oe,slider:V,breadcrumb:pe,menu:Oe,pagination:ie,empty:We,badge:ge,radio:qe,rate:Gt,switch:wt,transfer:Rt,avatar:ln,message:Bt,tag:at,table:Ue,card:nt,tabs:mt,timeline:Xt,timePicker:pn,upload:U,notification:Q,tree:ve,colorPicker:Se,datePicker:J,rangePicker:Xe,flex:Yt,wave:Zt,dropdown:ue,warning:Te,tour:Je,tooltip:Dn,popover:Qt,popconfirm:sl,floatButton:jo,floatButtonGroup:_u,variant:yu,inputNumber:cp,treeSelect:up},Wi=Object.assign({},x);Object.keys(al).forEach(Tt=>{al[Tt]!==void 0&&(Wi[Tt]=al[Tt])}),WD.forEach(Tt=>{const $t=e[Tt];$t&&(Wi[Tt]=$t)}),typeof r<"u"&&(Wi.button=Object.assign({autoInsertSpace:r},Wi.button));const Vi=fE(()=>Wi,Wi,(Tt,$t)=>{const or=Object.keys(Tt),Ln=Object.keys($t);return or.length!==Ln.length||or.some(Z=>Tt[Z]!==$t[Z])}),{layer:ll}=g.useContext(Tf),wu=g.useMemo(()=>({prefixCls:Do,csp:Lo,layer:ll?"antd":void 0}),[Do,Lo,ll]);let zt=g.createElement(g.Fragment,null,g.createElement(HD,{dropdownMatchSelectWidth:p}),t);const cl=g.useMemo(()=>{var Tt,$t,or,Ln;return A4(((Tt=Rf.Form)===null||Tt===void 0?void 0:Tt.defaultValidateMessages)||{},((or=($t=Vi.locale)===null||$t===void 0?void 0:$t.Form)===null||or===void 0?void 0:or.defaultValidateMessages)||{},((Ln=Vi.form)===null||Ln===void 0?void 0:Ln.validateMessages)||{},(o==null?void 0:o.validateMessages)||{})},[Vi,o==null?void 0:o.validateMessages]);Object.keys(cl).length>0&&(zt=g.createElement(D4.Provider,{value:cl},zt)),a&&(zt=g.createElement(B4,{locale:a,_ANT_MARK__:O4},zt)),zt=g.createElement(P4.Provider,{value:wu},zt),l&&(zt=g.createElement(rD,{size:l},zt)),zt=g.createElement(FD,null,zt);const ul=g.useMemo(()=>{const Tt=ol||{},{algorithm:$t,token:or,components:Ln,cssVar:Z}=Tt,xe=UD(Tt,["algorithm","token","components","cssVar"]),ye=$t&&(!Array.isArray($t)||$t.length>0)?Wg($t):WE,Ze={};Object.entries(Ln||{}).forEach(([mA,gA])=>{const fi=Object.assign({},gA);"algorithm"in fi&&(fi.algorithm===!0?fi.theme=ye:(Array.isArray(fi.algorithm)||typeof fi.algorithm=="function")&&(fi.theme=Wg(fi.algorithm)),delete fi.algorithm),Ze[mA]=fi});const hi=Object.assign(Object.assign({},Tc),or);return Object.assign(Object.assign({},xe),{theme:ye,token:hi,components:Ze,override:Object.assign({override:hi},Ze),cssVar:Z})},[ol]);return b&&(zt=g.createElement(VE.Provider,{value:ul},zt)),Vi.warning&&(zt=g.createElement(j4.Provider,{value:Vi.warning},zt)),w!==void 0&&(zt=g.createElement(nD,{disabled:w},zt)),g.createElement(Mf.Provider,{value:Vi},zt)},Ga=e=>{const t=g.useContext(Mf),n=g.useContext($E);return g.createElement(GD,Object.assign({parentContext:t,legacyLocale:n},e))};Ga.ConfigContext=Mf;Ga.SizeContext=Pc;Ga.config=KD;Ga.useConfig=iD;Object.defineProperty(Ga,"SizeContext",{get:()=>Pc});const lr=(e,t)=>new _t(e).setA(t).toRgbString(),zo=(e,t)=>new _t(e).lighten(t).toHexString(),XD=e=>{const t=Aa(e,{theme:"dark"});return{1:t[0],2:t[1],3:t[2],4:t[3],5:t[6],6:t[5],7:t[4],8:t[6],9:t[5],10:t[4]}},YD=(e,t)=>{const n=e||"#000",r=t||"#fff";return{colorBgBase:n,colorTextBase:r,colorText:lr(r,.85),colorTextSecondary:lr(r,.65),colorTextTertiary:lr(r,.45),colorTextQuaternary:lr(r,.25),colorFill:lr(r,.18),colorFillSecondary:lr(r,.12),colorFillTertiary:lr(r,.08),colorFillQuaternary:lr(r,.04),colorBgSolid:lr(r,.95),colorBgSolidHover:lr(r,1),colorBgSolidActive:lr(r,.9),colorBgElevated:zo(n,12),colorBgContainer:zo(n,8),colorBgLayout:zo(n,0),colorBgSpotlight:zo(n,26),colorBgBlur:lr(r,.04),colorBorder:zo(n,26),colorBorderSecondary:zo(n,19)}},ZD=(e,t)=>{const n=Object.keys(Bx).map(s=>{const o=Aa(e[s],{theme:"dark"});return Array.from({length:10},()=>1).reduce((a,l,c)=>(a[`${s}-${c+1}`]=o[c],a[`${s}${c+1}`]=o[c],a),{})}).reduce((s,o)=>(s=Object.assign(Object.assign({},s),o),s),{}),r=t??zx(e),i=UE(e,{generateColorPalettes:XD,generateNeutralColorPalettes:YD});return Object.assign(Object.assign(Object.assign(Object.assign({},r),n),i),{colorPrimaryBg:i.colorPrimaryBorder,colorPrimaryBgHover:i.colorPrimaryBorderHover})},pb={defaultSeed:bh.token,defaultAlgorithm:zx,darkAlgorithm:ZD};function mb({children:e}){const t=Ix(),[n,r]=g.useState(t.theme);return g.useEffect(()=>t.onThemeChange(r),[t]),h.jsx(Ga,{theme:{algorithm:n.mode==="dark"?pb.darkAlgorithm:pb.defaultAlgorithm,token:{colorPrimary:n.colorPrimary,colorBgContainer:n.colorBgContainer,colorText:n.colorText,colorBorder:n.colorBorder}},children:e})}var Ke;(function(e){e.assertEqual=i=>{};function t(i){}e.assertIs=t;function n(i){throw new Error}e.assertNever=n,e.arrayToEnum=i=>{const s={};for(const o of i)s[o]=o;return s},e.getValidEnumValues=i=>{const s=e.objectKeys(i).filter(a=>typeof i[i[a]]!="number"),o={};for(const a of s)o[a]=i[a];return e.objectValues(o)},e.objectValues=i=>e.objectKeys(i).map(function(s){return i[s]}),e.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{const s=[];for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&s.push(o);return s},e.find=(i,s)=>{for(const o of i)if(s(o))return o},e.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,s=" | "){return i.map(o=>typeof o=="string"?`'${o}'`:o).join(s)}e.joinValues=r,e.jsonStringifyReplacer=(i,s)=>typeof s=="bigint"?s.toString():s})(Ke||(Ke={}));var gb;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(gb||(gb={}));const ce=Ke.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),rs=e=>{switch(typeof e){case"undefined":return ce.undefined;case"string":return ce.string;case"number":return Number.isNaN(e)?ce.nan:ce.number;case"boolean":return ce.boolean;case"function":return ce.function;case"bigint":return ce.bigint;case"symbol":return ce.symbol;case"object":return Array.isArray(e)?ce.array:e===null?ce.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?ce.promise:typeof Map<"u"&&e instanceof Map?ce.map:typeof Set<"u"&&e instanceof Set?ce.set:typeof Date<"u"&&e instanceof Date?ce.date:ce.object;default:return ce.unknown}},K=Ke.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class Ri extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=t}format(t){const n=t||function(s){return s.message},r={_errors:[]},i=s=>{for(const o of s.issues)if(o.code==="invalid_union")o.unionErrors.map(i);else if(o.code==="invalid_return_type")i(o.returnTypeError);else if(o.code==="invalid_arguments")i(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let a=r,l=0;for(;l<o.path.length;){const c=o.path[l];l===o.path.length-1?(a[c]=a[c]||{_errors:[]},a[c]._errors.push(n(o))):a[c]=a[c]||{_errors:[]},a=a[c],l++}}};return i(this),r}static assert(t){if(!(t instanceof Ri))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Ke.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=n=>n.message){const n={},r=[];for(const i of this.issues)if(i.path.length>0){const s=i.path[0];n[s]=n[s]||[],n[s].push(t(i))}else r.push(t(i));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}Ri.create=e=>new Ri(e);const gv=(e,t)=>{let n;switch(e.code){case K.invalid_type:e.received===ce.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case K.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Ke.jsonStringifyReplacer)}`;break;case K.unrecognized_keys:n=`Unrecognized key(s) in object: ${Ke.joinValues(e.keys,", ")}`;break;case K.invalid_union:n="Invalid input";break;case K.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Ke.joinValues(e.options)}`;break;case K.invalid_enum_value:n=`Invalid enum value. Expected ${Ke.joinValues(e.options)}, received '${e.received}'`;break;case K.invalid_arguments:n="Invalid function arguments";break;case K.invalid_return_type:n="Invalid function return type";break;case K.invalid_date:n="Invalid date";break;case K.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:Ke.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case K.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="bigint"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case K.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case K.custom:n="Invalid input";break;case K.invalid_intersection_types:n="Intersection results could not be merged";break;case K.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case K.not_finite:n="Number must be finite";break;default:n=t.defaultError,Ke.assertNever(e)}return{message:n}};let QD=gv;function JD(){return QD}const eL=e=>{const{data:t,path:n,errorMaps:r,issueData:i}=e,s=[...n,...i.path||[]],o={...i,path:s};if(i.message!==void 0)return{...i,path:s,message:i.message};let a="";const l=r.filter(c=>!!c).slice().reverse();for(const c of l)a=c(o,{data:t,defaultError:a}).message;return{...i,path:s,message:a}};function se(e,t){const n=JD(),r=eL({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===gv?void 0:gv].filter(i=>!!i)});e.common.issues.push(r)}class Tn{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,n){const r=[];for(const i of n){if(i.status==="aborted")return Ce;i.status==="dirty"&&t.dirty(),r.push(i.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const i of n){const s=await i.key,o=await i.value;r.push({key:s,value:o})}return Tn.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const i of n){const{key:s,value:o}=i;if(s.status==="aborted"||o.status==="aborted")return Ce;s.status==="dirty"&&t.dirty(),o.status==="dirty"&&t.dirty(),s.value!=="__proto__"&&(typeof o.value<"u"||i.alwaysSet)&&(r[s.value]=o.value)}return{status:t.value,value:r}}}const Ce=Object.freeze({status:"aborted"}),Ll=e=>({status:"dirty",value:e}),Sr=e=>({status:"valid",value:e}),vb=e=>e.status==="aborted",xb=e=>e.status==="dirty",ja=e=>e.status==="valid",wh=e=>typeof Promise<"u"&&e instanceof Promise;var me;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(me||(me={}));class ii{constructor(t,n,r,i){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const _b=(e,t)=>{if(ja(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new Ri(e.common.issues);return this._error=n,this._error}}};function Me(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:i}=e;if(t&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:i}:{errorMap:(o,a)=>{const{message:l}=e;return o.code==="invalid_enum_value"?{message:l??a.defaultError}:typeof a.data>"u"?{message:l??r??a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:l??n??a.defaultError}},description:i}}class He{get description(){return this._def.description}_getType(t){return rs(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:rs(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Tn,ctx:{common:t.parent.common,data:t.data,parsedType:rs(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(wh(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(t){const n=this._parse(t);return Promise.resolve(n)}parse(t,n){const r=this.safeParse(t,n);if(r.success)return r.data;throw r.error}safeParse(t,n){const r={common:{issues:[],async:(n==null?void 0:n.async)??!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:rs(t)},i=this._parseSync({data:t,path:r.path,parent:r});return _b(r,i)}"~validate"(t){var r,i;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:rs(t)};if(!this["~standard"].async)try{const s=this._parseSync({data:t,path:[],parent:n});return ja(s)?{value:s.value}:{issues:n.common.issues}}catch(s){(i=(r=s==null?void 0:s.message)==null?void 0:r.toLowerCase())!=null&&i.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:n}).then(s=>ja(s)?{value:s.value}:{issues:n.common.issues})}async parseAsync(t,n){const r=await this.safeParseAsync(t,n);if(r.success)return r.data;throw r.error}async safeParseAsync(t,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:rs(t)},i=this._parse({data:t,path:r.path,parent:r}),s=await(wh(i)?i:Promise.resolve(i));return _b(r,s)}refine(t,n){const r=i=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(i):n;return this._refinement((i,s)=>{const o=t(i),a=()=>s.addIssue({code:K.custom,...r(i)});return typeof Promise<"u"&&o instanceof Promise?o.then(l=>l?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(t,n){return this._refinement((r,i)=>t(r)?!0:(i.addIssue(typeof n=="function"?n(r,i):n),!1))}_refinement(t){return new ho({schema:this,typeName:Ee.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Ei.create(this,this._def)}nullable(){return fo.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ei.create(this)}promise(){return Th.create(this,this._def)}or(t){return kh.create([this,t],this._def)}and(t){return Ch.create(this,t,this._def)}transform(t){return new ho({...Me(this._def),schema:this,typeName:Ee.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new Ph({...Me(this._def),innerType:this,defaultValue:n,typeName:Ee.ZodDefault})}brand(){return new uN({typeName:Ee.ZodBranded,type:this,...Me(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new Ih({...Me(this._def),innerType:this,catchValue:n,typeName:Ee.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return Hx.create(this,t)}readonly(){return Rh.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const tL=/^c[^\s-]{8,}$/i,nL=/^[0-9a-z]+$/,rL=/^[0-9A-HJKMNP-TV-Z]{26}$/i,iL=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,sL=/^[a-z0-9_-]{21}$/i,oL=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,aL=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,lL=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,cL="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Kp;const uL=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,dL=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,hL=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,fL=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,pL=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,mL=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,aN="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",gL=new RegExp(`^${aN}$`);function lN(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:e.precision==null&&(t=`${t}(\\.\\d+)?`);const n=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${n}`}function vL(e){return new RegExp(`^${lN(e)}$`)}function xL(e){let t=`${aN}T${lN(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function _L(e,t){return!!((t==="v4"||!t)&&uL.test(e)||(t==="v6"||!t)&&hL.test(e))}function yL(e,t){if(!oL.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),i=JSON.parse(atob(r));return!(typeof i!="object"||i===null||"typ"in i&&(i==null?void 0:i.typ)!=="JWT"||!i.alg||t&&i.alg!==t)}catch{return!1}}function bL(e,t){return!!((t==="v4"||!t)&&dL.test(e)||(t==="v6"||!t)&&fL.test(e))}class wi extends He{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==ce.string){const s=this._getOrReturnCtx(t);return se(s,{code:K.invalid_type,expected:ce.string,received:s.parsedType}),Ce}const r=new Tn;let i;for(const s of this._def.checks)if(s.kind==="min")t.data.length<s.value&&(i=this._getOrReturnCtx(t,i),se(i,{code:K.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="max")t.data.length>s.value&&(i=this._getOrReturnCtx(t,i),se(i,{code:K.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="length"){const o=t.data.length>s.value,a=t.data.length<s.value;(o||a)&&(i=this._getOrReturnCtx(t,i),o?se(i,{code:K.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):a&&se(i,{code:K.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if(s.kind==="email")lL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"email",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="emoji")Kp||(Kp=new RegExp(cL,"u")),Kp.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"emoji",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="uuid")iL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"uuid",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="nanoid")sL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"nanoid",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid")tL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"cuid",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid2")nL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"cuid2",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="ulid")rL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"ulid",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="url")try{new URL(t.data)}catch{i=this._getOrReturnCtx(t,i),se(i,{validation:"url",code:K.invalid_string,message:s.message}),r.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"regex",code:K.invalid_string,message:s.message}),r.dirty())):s.kind==="trim"?t.data=t.data.trim():s.kind==="includes"?t.data.includes(s.value,s.position)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):s.kind==="toLowerCase"?t.data=t.data.toLowerCase():s.kind==="toUpperCase"?t.data=t.data.toUpperCase():s.kind==="startsWith"?t.data.startsWith(s.value)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):s.kind==="endsWith"?t.data.endsWith(s.value)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):s.kind==="datetime"?xL(s).test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:"datetime",message:s.message}),r.dirty()):s.kind==="date"?gL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:"date",message:s.message}),r.dirty()):s.kind==="time"?vL(s).test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:"time",message:s.message}),r.dirty()):s.kind==="duration"?aL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"duration",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="ip"?_L(t.data,s.version)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"ip",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="jwt"?yL(t.data,s.alg)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"jwt",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="cidr"?bL(t.data,s.version)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"cidr",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="base64"?pL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"base64",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="base64url"?mL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"base64url",code:K.invalid_string,message:s.message}),r.dirty()):Ke.assertNever(s);return{status:r.value,value:t.data}}_regex(t,n,r){return this.refinement(i=>t.test(i),{validation:n,code:K.invalid_string,...me.errToObj(r)})}_addCheck(t){return new wi({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...me.errToObj(t)})}url(t){return this._addCheck({kind:"url",...me.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...me.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...me.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...me.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...me.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...me.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...me.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...me.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...me.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...me.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...me.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...me.errToObj(t)})}datetime(t){return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof(t==null?void 0:t.precision)>"u"?null:t==null?void 0:t.precision,offset:(t==null?void 0:t.offset)??!1,local:(t==null?void 0:t.local)??!1,...me.errToObj(t==null?void 0:t.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof(t==null?void 0:t.precision)>"u"?null:t==null?void 0:t.precision,...me.errToObj(t==null?void 0:t.message)})}duration(t){return this._addCheck({kind:"duration",...me.errToObj(t)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...me.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...me.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...me.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...me.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...me.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...me.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...me.errToObj(n)})}nonempty(t){return this.min(1,me.errToObj(t))}trim(){return new wi({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new wi({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new wi({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isCIDR(){return!!this._def.checks.find(t=>t.kind==="cidr")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get isBase64url(){return!!this._def.checks.find(t=>t.kind==="base64url")}get minLength(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxLength(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}}wi.create=e=>new wi({checks:[],typeName:Ee.ZodString,coerce:(e==null?void 0:e.coerce)??!1,...Me(e)});function wL(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,i=n>r?n:r,s=Number.parseInt(e.toFixed(i).replace(".","")),o=Number.parseInt(t.toFixed(i).replace(".",""));return s%o/10**i}class Da extends He{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==ce.number){const s=this._getOrReturnCtx(t);return se(s,{code:K.invalid_type,expected:ce.number,received:s.parsedType}),Ce}let r;const i=new Tn;for(const s of this._def.checks)s.kind==="int"?Ke.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),se(r,{code:K.invalid_type,expected:"integer",received:"float",message:s.message}),i.dirty()):s.kind==="min"?(s.inclusive?t.data<s.value:t.data<=s.value)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),i.dirty()):s.kind==="max"?(s.inclusive?t.data>s.value:t.data>=s.value)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),i.dirty()):s.kind==="multipleOf"?wL(t.data,s.value)!==0&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.not_multiple_of,multipleOf:s.value,message:s.message}),i.dirty()):s.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),se(r,{code:K.not_finite,message:s.message}),i.dirty()):Ke.assertNever(s);return{status:i.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,me.toString(n))}gt(t,n){return this.setLimit("min",t,!1,me.toString(n))}lte(t,n){return this.setLimit("max",t,!0,me.toString(n))}lt(t,n){return this.setLimit("max",t,!1,me.toString(n))}setLimit(t,n,r,i){return new Da({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:me.toString(i)}]})}_addCheck(t){return new Da({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:me.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:me.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:me.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:me.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:me.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:me.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:me.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:me.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:me.toString(t)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}get isInt(){return!!this._def.checks.find(t=>t.kind==="int"||t.kind==="multipleOf"&&Ke.isInteger(t.value))}get isFinite(){let t=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(t===null||r.value<t)&&(t=r.value)}return Number.isFinite(n)&&Number.isFinite(t)}}Da.create=e=>new Da({checks:[],typeName:Ee.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...Me(e)});class Ic extends He{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==ce.bigint)return this._getInvalidInput(t);let r;const i=new Tn;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?t.data<s.value:t.data<=s.value)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),i.dirty()):s.kind==="max"?(s.inclusive?t.data>s.value:t.data>=s.value)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),i.dirty()):s.kind==="multipleOf"?t.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.not_multiple_of,multipleOf:s.value,message:s.message}),i.dirty()):Ke.assertNever(s);return{status:i.value,value:t.data}}_getInvalidInput(t){const n=this._getOrReturnCtx(t);return se(n,{code:K.invalid_type,expected:ce.bigint,received:n.parsedType}),Ce}gte(t,n){return this.setLimit("min",t,!0,me.toString(n))}gt(t,n){return this.setLimit("min",t,!1,me.toString(n))}lte(t,n){return this.setLimit("max",t,!0,me.toString(n))}lt(t,n){return this.setLimit("max",t,!1,me.toString(n))}setLimit(t,n,r,i){return new Ic({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:me.toString(i)}]})}_addCheck(t){return new Ic({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:me.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:me.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:me.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:me.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:me.toString(n)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}}Ic.create=e=>new Ic({checks:[],typeName:Ee.ZodBigInt,coerce:(e==null?void 0:e.coerce)??!1,...Me(e)});class vv extends He{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==ce.boolean){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.boolean,received:r.parsedType}),Ce}return Sr(t.data)}}vv.create=e=>new vv({typeName:Ee.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...Me(e)});class Sh extends He{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==ce.date){const s=this._getOrReturnCtx(t);return se(s,{code:K.invalid_type,expected:ce.date,received:s.parsedType}),Ce}if(Number.isNaN(t.data.getTime())){const s=this._getOrReturnCtx(t);return se(s,{code:K.invalid_date}),Ce}const r=new Tn;let i;for(const s of this._def.checks)s.kind==="min"?t.data.getTime()<s.value&&(i=this._getOrReturnCtx(t,i),se(i,{code:K.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):s.kind==="max"?t.data.getTime()>s.value&&(i=this._getOrReturnCtx(t,i),se(i,{code:K.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):Ke.assertNever(s);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Sh({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:me.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:me.toString(n)})}get minDate(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t!=null?new Date(t):null}}Sh.create=e=>new Sh({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:Ee.ZodDate,...Me(e)});class yb extends He{_parse(t){if(this._getType(t)!==ce.symbol){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.symbol,received:r.parsedType}),Ce}return Sr(t.data)}}yb.create=e=>new yb({typeName:Ee.ZodSymbol,...Me(e)});class xv extends He{_parse(t){if(this._getType(t)!==ce.undefined){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.undefined,received:r.parsedType}),Ce}return Sr(t.data)}}xv.create=e=>new xv({typeName:Ee.ZodUndefined,...Me(e)});class _v extends He{_parse(t){if(this._getType(t)!==ce.null){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.null,received:r.parsedType}),Ce}return Sr(t.data)}}_v.create=e=>new _v({typeName:Ee.ZodNull,...Me(e)});class bb extends He{constructor(){super(...arguments),this._any=!0}_parse(t){return Sr(t.data)}}bb.create=e=>new bb({typeName:Ee.ZodAny,...Me(e)});class yv extends He{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Sr(t.data)}}yv.create=e=>new yv({typeName:Ee.ZodUnknown,...Me(e)});class ks extends He{_parse(t){const n=this._getOrReturnCtx(t);return se(n,{code:K.invalid_type,expected:ce.never,received:n.parsedType}),Ce}}ks.create=e=>new ks({typeName:Ee.ZodNever,...Me(e)});class wb extends He{_parse(t){if(this._getType(t)!==ce.undefined){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.void,received:r.parsedType}),Ce}return Sr(t.data)}}wb.create=e=>new wb({typeName:Ee.ZodVoid,...Me(e)});class ei extends He{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),i=this._def;if(n.parsedType!==ce.array)return se(n,{code:K.invalid_type,expected:ce.array,received:n.parsedType}),Ce;if(i.exactLength!==null){const o=n.data.length>i.exactLength.value,a=n.data.length<i.exactLength.value;(o||a)&&(se(n,{code:o?K.too_big:K.too_small,minimum:a?i.exactLength.value:void 0,maximum:o?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),r.dirty())}if(i.minLength!==null&&n.data.length<i.minLength.value&&(se(n,{code:K.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),r.dirty()),i.maxLength!==null&&n.data.length>i.maxLength.value&&(se(n,{code:K.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,a)=>i.type._parseAsync(new ii(n,o,n.path,a)))).then(o=>Tn.mergeArray(r,o));const s=[...n.data].map((o,a)=>i.type._parseSync(new ii(n,o,n.path,a)));return Tn.mergeArray(r,s)}get element(){return this._def.type}min(t,n){return new ei({...this._def,minLength:{value:t,message:me.toString(n)}})}max(t,n){return new ei({...this._def,maxLength:{value:t,message:me.toString(n)}})}length(t,n){return new ei({...this._def,exactLength:{value:t,message:me.toString(n)}})}nonempty(t){return this.min(1,t)}}ei.create=(e,t)=>new ei({type:e,minLength:null,maxLength:null,exactLength:null,typeName:Ee.ZodArray,...Me(t)});function Go(e){if(e instanceof jt){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Ei.create(Go(r))}return new jt({...e._def,shape:()=>t})}else return e instanceof ei?new ei({...e._def,type:Go(e.element)}):e instanceof Ei?Ei.create(Go(e.unwrap())):e instanceof fo?fo.create(Go(e.unwrap())):e instanceof co?co.create(e.items.map(t=>Go(t))):e}class jt extends He{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),n=Ke.objectKeys(t);return this._cached={shape:t,keys:n},this._cached}_parse(t){if(this._getType(t)!==ce.object){const c=this._getOrReturnCtx(t);return se(c,{code:K.invalid_type,expected:ce.object,received:c.parsedType}),Ce}const{status:r,ctx:i}=this._processInputParams(t),{shape:s,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof ks&&this._def.unknownKeys==="strip"))for(const c in i.data)o.includes(c)||a.push(c);const l=[];for(const c of o){const u=s[c],d=i.data[c];l.push({key:{status:"valid",value:c},value:u._parse(new ii(i,d,i.path,c)),alwaysSet:c in i.data})}if(this._def.catchall instanceof ks){const c=this._def.unknownKeys;if(c==="passthrough")for(const u of a)l.push({key:{status:"valid",value:u},value:{status:"valid",value:i.data[u]}});else if(c==="strict")a.length>0&&(se(i,{code:K.unrecognized_keys,keys:a}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const u of a){const d=i.data[u];l.push({key:{status:"valid",value:u},value:c._parse(new ii(i,d,i.path,u)),alwaysSet:u in i.data})}}return i.common.async?Promise.resolve().then(async()=>{const c=[];for(const u of l){const d=await u.key,f=await u.value;c.push({key:d,value:f,alwaysSet:u.alwaysSet})}return c}).then(c=>Tn.mergeObjectSync(r,c)):Tn.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(t){return me.errToObj,new jt({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{var s,o;const i=((o=(s=this._def).errorMap)==null?void 0:o.call(s,n,r).message)??r.defaultError;return n.code==="unrecognized_keys"?{message:me.errToObj(t).message??i}:{message:i}}}:{}})}strip(){return new jt({...this._def,unknownKeys:"strip"})}passthrough(){return new jt({...this._def,unknownKeys:"passthrough"})}extend(t){return new jt({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new jt({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:Ee.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new jt({...this._def,catchall:t})}pick(t){const n={};for(const r of Ke.objectKeys(t))t[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new jt({...this._def,shape:()=>n})}omit(t){const n={};for(const r of Ke.objectKeys(this.shape))t[r]||(n[r]=this.shape[r]);return new jt({...this._def,shape:()=>n})}deepPartial(){return Go(this)}partial(t){const n={};for(const r of Ke.objectKeys(this.shape)){const i=this.shape[r];t&&!t[r]?n[r]=i:n[r]=i.optional()}return new jt({...this._def,shape:()=>n})}required(t){const n={};for(const r of Ke.objectKeys(this.shape))if(t&&!t[r])n[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof Ei;)s=s._def.innerType;n[r]=s}return new jt({...this._def,shape:()=>n})}keyof(){return cN(Ke.objectKeys(this.shape))}}jt.create=(e,t)=>new jt({shape:()=>e,unknownKeys:"strip",catchall:ks.create(),typeName:Ee.ZodObject,...Me(t)});jt.strictCreate=(e,t)=>new jt({shape:()=>e,unknownKeys:"strict",catchall:ks.create(),typeName:Ee.ZodObject,...Me(t)});jt.lazycreate=(e,t)=>new jt({shape:e,unknownKeys:"strip",catchall:ks.create(),typeName:Ee.ZodObject,...Me(t)});class kh extends He{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function i(s){for(const a of s)if(a.result.status==="valid")return a.result;for(const a of s)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const o=s.map(a=>new Ri(a.ctx.common.issues));return se(n,{code:K.invalid_union,unionErrors:o}),Ce}if(n.common.async)return Promise.all(r.map(async s=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(i);{let s;const o=[];for(const l of r){const c={...n,common:{...n.common,issues:[]},parent:null},u=l._parseSync({data:n.data,path:n.path,parent:c});if(u.status==="valid")return u;u.status==="dirty"&&!s&&(s={result:u,ctx:c}),c.common.issues.length&&o.push(c.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;const a=o.map(l=>new Ri(l));return se(n,{code:K.invalid_union,unionErrors:a}),Ce}}get options(){return this._def.options}}kh.create=(e,t)=>new kh({options:e,typeName:Ee.ZodUnion,...Me(t)});const vi=e=>e instanceof wv?vi(e.schema):e instanceof ho?vi(e.innerType()):e instanceof Nh?[e.value]:e instanceof uo?e.options:e instanceof Sv?Ke.objectValues(e.enum):e instanceof Ph?vi(e._def.innerType):e instanceof xv?[void 0]:e instanceof _v?[null]:e instanceof Ei?[void 0,...vi(e.unwrap())]:e instanceof fo?[null,...vi(e.unwrap())]:e instanceof uN||e instanceof Rh?vi(e.unwrap()):e instanceof Ih?vi(e._def.innerType):[];class Fx extends He{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==ce.object)return se(n,{code:K.invalid_type,expected:ce.object,received:n.parsedType}),Ce;const r=this.discriminator,i=n.data[r],s=this.optionsMap.get(i);return s?n.common.async?s._parseAsync({data:n.data,path:n.path,parent:n}):s._parseSync({data:n.data,path:n.path,parent:n}):(se(n,{code:K.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),Ce)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const i=new Map;for(const s of n){const o=vi(s.shape[t]);if(!o.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const a of o){if(i.has(a))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(a)}`);i.set(a,s)}}return new Fx({typeName:Ee.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:i,...Me(r)})}}function bv(e,t){const n=rs(e),r=rs(t);if(e===t)return{valid:!0,data:e};if(n===ce.object&&r===ce.object){const i=Ke.objectKeys(t),s=Ke.objectKeys(e).filter(a=>i.indexOf(a)!==-1),o={...e,...t};for(const a of s){const l=bv(e[a],t[a]);if(!l.valid)return{valid:!1};o[a]=l.data}return{valid:!0,data:o}}else if(n===ce.array&&r===ce.array){if(e.length!==t.length)return{valid:!1};const i=[];for(let s=0;s<e.length;s++){const o=e[s],a=t[s],l=bv(o,a);if(!l.valid)return{valid:!1};i.push(l.data)}return{valid:!0,data:i}}else return n===ce.date&&r===ce.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}class Ch extends He{_parse(t){const{status:n,ctx:r}=this._processInputParams(t),i=(s,o)=>{if(vb(s)||vb(o))return Ce;const a=bv(s.value,o.value);return a.valid?((xb(s)||xb(o))&&n.dirty(),{status:n.value,value:a.data}):(se(r,{code:K.invalid_intersection_types}),Ce)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([s,o])=>i(s,o)):i(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Ch.create=(e,t,n)=>new Ch({left:e,right:t,typeName:Ee.ZodIntersection,...Me(n)});class co extends He{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==ce.array)return se(r,{code:K.invalid_type,expected:ce.array,received:r.parsedType}),Ce;if(r.data.length<this._def.items.length)return se(r,{code:K.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Ce;!this._def.rest&&r.data.length>this._def.items.length&&(se(r,{code:K.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const s=[...r.data].map((o,a)=>{const l=this._def.items[a]||this._def.rest;return l?l._parse(new ii(r,o,r.path,a)):null}).filter(o=>!!o);return r.common.async?Promise.all(s).then(o=>Tn.mergeArray(n,o)):Tn.mergeArray(n,s)}get items(){return this._def.items}rest(t){return new co({...this._def,rest:t})}}co.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new co({items:e,typeName:Ee.ZodTuple,rest:null,...Me(t)})};class Eh extends He{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==ce.object)return se(r,{code:K.invalid_type,expected:ce.object,received:r.parsedType}),Ce;const i=[],s=this._def.keyType,o=this._def.valueType;for(const a in r.data)i.push({key:s._parse(new ii(r,a,r.path,a)),value:o._parse(new ii(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?Tn.mergeObjectAsync(n,i):Tn.mergeObjectSync(n,i)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof He?new Eh({keyType:t,valueType:n,typeName:Ee.ZodRecord,...Me(r)}):new Eh({keyType:wi.create(),valueType:t,typeName:Ee.ZodRecord,...Me(n)})}}class Sb extends He{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==ce.map)return se(r,{code:K.invalid_type,expected:ce.map,received:r.parsedType}),Ce;const i=this._def.keyType,s=this._def.valueType,o=[...r.data.entries()].map(([a,l],c)=>({key:i._parse(new ii(r,a,r.path,[c,"key"])),value:s._parse(new ii(r,l,r.path,[c,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const l of o){const c=await l.key,u=await l.value;if(c.status==="aborted"||u.status==="aborted")return Ce;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const l of o){const c=l.key,u=l.value;if(c.status==="aborted"||u.status==="aborted")return Ce;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}}}}Sb.create=(e,t,n)=>new Sb({valueType:t,keyType:e,typeName:Ee.ZodMap,...Me(n)});class Rc extends He{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==ce.set)return se(r,{code:K.invalid_type,expected:ce.set,received:r.parsedType}),Ce;const i=this._def;i.minSize!==null&&r.data.size<i.minSize.value&&(se(r,{code:K.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),n.dirty()),i.maxSize!==null&&r.data.size>i.maxSize.value&&(se(r,{code:K.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),n.dirty());const s=this._def.valueType;function o(l){const c=new Set;for(const u of l){if(u.status==="aborted")return Ce;u.status==="dirty"&&n.dirty(),c.add(u.value)}return{status:n.value,value:c}}const a=[...r.data.values()].map((l,c)=>s._parse(new ii(r,l,r.path,c)));return r.common.async?Promise.all(a).then(l=>o(l)):o(a)}min(t,n){return new Rc({...this._def,minSize:{value:t,message:me.toString(n)}})}max(t,n){return new Rc({...this._def,maxSize:{value:t,message:me.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}Rc.create=(e,t)=>new Rc({valueType:e,minSize:null,maxSize:null,typeName:Ee.ZodSet,...Me(t)});class wv extends He{get schema(){return this._def.getter()}_parse(t){const{ctx:n}=this._processInputParams(t);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}wv.create=(e,t)=>new wv({getter:e,typeName:Ee.ZodLazy,...Me(t)});class Nh extends He{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return se(n,{received:n.data,code:K.invalid_literal,expected:this._def.value}),Ce}return{status:"valid",value:t.data}}get value(){return this._def.value}}Nh.create=(e,t)=>new Nh({value:e,typeName:Ee.ZodLiteral,...Me(t)});function cN(e,t){return new uo({values:e,typeName:Ee.ZodEnum,...Me(t)})}class uo extends He{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return se(n,{expected:Ke.joinValues(r),received:n.parsedType,code:K.invalid_type}),Ce}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){const n=this._getOrReturnCtx(t),r=this._def.values;return se(n,{received:n.data,code:K.invalid_enum_value,options:r}),Ce}return Sr(t.data)}get options(){return this._def.values}get enum(){const t={};for(const n of this._def.values)t[n]=n;return t}get Values(){const t={};for(const n of this._def.values)t[n]=n;return t}get Enum(){const t={};for(const n of this._def.values)t[n]=n;return t}extract(t,n=this._def){return uo.create(t,{...this._def,...n})}exclude(t,n=this._def){return uo.create(this.options.filter(r=>!t.includes(r)),{...this._def,...n})}}uo.create=cN;class Sv extends He{_parse(t){const n=Ke.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==ce.string&&r.parsedType!==ce.number){const i=Ke.objectValues(n);return se(r,{expected:Ke.joinValues(i),received:r.parsedType,code:K.invalid_type}),Ce}if(this._cache||(this._cache=new Set(Ke.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){const i=Ke.objectValues(n);return se(r,{received:r.data,code:K.invalid_enum_value,options:i}),Ce}return Sr(t.data)}get enum(){return this._def.values}}Sv.create=(e,t)=>new Sv({values:e,typeName:Ee.ZodNativeEnum,...Me(t)});class Th extends He{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==ce.promise&&n.common.async===!1)return se(n,{code:K.invalid_type,expected:ce.promise,received:n.parsedType}),Ce;const r=n.parsedType===ce.promise?n.data:Promise.resolve(n.data);return Sr(r.then(i=>this._def.type.parseAsync(i,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Th.create=(e,t)=>new Th({type:e,typeName:Ee.ZodPromise,...Me(t)});class ho extends He{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Ee.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),i=this._def.effect||null,s={addIssue:o=>{se(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),i.type==="preprocess"){const o=i.transform(r.data,s);if(r.common.async)return Promise.resolve(o).then(async a=>{if(n.value==="aborted")return Ce;const l=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return l.status==="aborted"?Ce:l.status==="dirty"||n.value==="dirty"?Ll(l.value):l});{if(n.value==="aborted")return Ce;const a=this._def.schema._parseSync({data:o,path:r.path,parent:r});return a.status==="aborted"?Ce:a.status==="dirty"||n.value==="dirty"?Ll(a.value):a}}if(i.type==="refinement"){const o=a=>{const l=i.refinement(a,s);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?Ce:(a.status==="dirty"&&n.dirty(),o(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?Ce:(a.status==="dirty"&&n.dirty(),o(a.value).then(()=>({status:n.value,value:a.value}))))}if(i.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!ja(o))return Ce;const a=i.transform(o.value,s);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>ja(o)?Promise.resolve(i.transform(o.value,s)).then(a=>({status:n.value,value:a})):Ce);Ke.assertNever(i)}}ho.create=(e,t,n)=>new ho({schema:e,typeName:Ee.ZodEffects,effect:t,...Me(n)});ho.createWithPreprocess=(e,t,n)=>new ho({schema:t,effect:{type:"preprocess",transform:e},typeName:Ee.ZodEffects,...Me(n)});class Ei extends He{_parse(t){return this._getType(t)===ce.undefined?Sr(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Ei.create=(e,t)=>new Ei({innerType:e,typeName:Ee.ZodOptional,...Me(t)});class fo extends He{_parse(t){return this._getType(t)===ce.null?Sr(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}fo.create=(e,t)=>new fo({innerType:e,typeName:Ee.ZodNullable,...Me(t)});class Ph extends He{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===ce.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Ph.create=(e,t)=>new Ph({innerType:e,typeName:Ee.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...Me(t)});class Ih extends He{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},i=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return wh(i)?i.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Ri(r.common.issues)},input:r.data})})):{status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new Ri(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Ih.create=(e,t)=>new Ih({innerType:e,typeName:Ee.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...Me(t)});class kb extends He{_parse(t){if(this._getType(t)!==ce.nan){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.nan,received:r.parsedType}),Ce}return{status:"valid",value:t.data}}}kb.create=e=>new kb({typeName:Ee.ZodNaN,...Me(e)});class uN extends He{_parse(t){const{ctx:n}=this._processInputParams(t),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Hx extends He{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Ce:s.status==="dirty"?(n.dirty(),Ll(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{const i=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?Ce:i.status==="dirty"?(n.dirty(),{status:"dirty",value:i.value}):this._def.out._parseSync({data:i.value,path:r.path,parent:r})}}static create(t,n){return new Hx({in:t,out:n,typeName:Ee.ZodPipeline})}}class Rh extends He{_parse(t){const n=this._def.innerType._parse(t),r=i=>(ja(i)&&(i.value=Object.freeze(i.value)),i);return wh(n)?n.then(i=>r(i)):r(n)}unwrap(){return this._def.innerType}}Rh.create=(e,t)=>new Rh({innerType:e,typeName:Ee.ZodReadonly,...Me(t)});var Ee;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(Ee||(Ee={}));const S=wi.create,G=Da.create,Ne=vv.create,to=yv.create;ks.create;const _e=ei.create,A=jt.create;kh.create;const ai=Fx.create;Ch.create;co.create;const Xa=Eh.create,ee=Nh.create,Ye=uo.create;Th.create;Ei.create;fo.create;new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");const SL=["owner"],kL=["agent","owner","user-upload"],dN=A({id:S().min(1),relPath:S().min(1),from:Ye(kL),label:S().optional(),size:G().int().nonnegative(),mime:S().min(1),addedAt:G().int().nonnegative(),lastEditedAt:G().int().nonnegative().optional(),stale:Ne().optional()});A({sessionId:S().min(1),relPath:S().min(1),ttlSeconds:G().int().positive().nullable().optional(),view:Ye(["raw","md-rendered"]).optional()});A({url:S().min(1),expiresAt:G().int().nonnegative().nullable()});A({sessionId:S().min(1),relPath:S().min(1),label:S().optional(),origin:ee("agent").optional()});A({entry:dN});A({sessionId:S().min(1),relPath:S().min(1)});A({removed:ee(!0)});A({sessionId:S().min(1)});A({entries:_e(dN)});A({attachmentId:S().min(1),url:S().min(1),relPath:S().min(1),sizeBytes:G().int().nonnegative(),mimeType:S().min(1)});const CL=ai("type",[A({type:ee("persona"),id:S().min(1)}).strict(),A({type:ee("chat"),id:S().min(1)}).strict(),A({type:ee("*")}).strict()]),EL=Ye(["read","send","admin"]),Ux=A({resource:CL,actions:_e(EL).min(1)}).strict(),NL=A({id:S().min(1),secretHash:S().regex(/^[a-f0-9]{64}$/),displayName:S(),grants:_e(Ux),issuedAt:G().int().nonnegative(),expiresAt:G().int().positive().optional(),maxUses:G().int().positive().optional(),usedCount:G().int().nonnegative(),peerOwnerId:S().min(1).optional(),firstUsedByPeerAt:G().int().positive().optional(),peerDisplayName:S().optional()}).strict(),TL=NL.omit({secretHash:!0});A({type:ee("whoami:ok"),owner:A({id:S(),kind:Ye(["owner","guest"]),displayName:S(),ownerId:S(),provider:S()}).strict(),capability:TL,grantedPersonas:_e(A({id:S().min(1),displayName:S()}).strict())}).strict();A({selfUrl:S().min(1)});A({type:ee("contact:handshake:ok"),owner:A({id:S(),ownerId:S(),provider:S(),displayName:S()}),grants:_e(Ux)});A({deviceId:S().min(1),remoteAccessAllowed:Ne()}).strict();A({type:ee("contact:setRemoteAccess:ok"),deviceId:S().min(1),remoteAccessAllowed:Ne()}).strict();A({type:ee("contact:remote-access-updated"),deviceId:S().min(1),remoteAccessAllowed:Ne()}).strict();const PL=A({deviceId:S().min(1),ownerId:S().min(1),provider:S().min(1),displayName:S(),remoteUrl:S().min(1),connectToken:S(),grants:_e(Ux),addedAt:G().int().nonnegative(),pinnedAt:G().int().nullable().default(null),remoteAccessAllowed:Ne().default(!1)}).strict(),hN=PL;A({deviceId:S().min(1)}).strict();A({type:ee("contact:remove:ok"),deviceId:S().min(1)}).strict();A({type:ee("contact:list:ok"),contacts:_e(hN)}).strict();A({type:ee("contact:added"),contact:hN}).strict();A({type:ee("contact:removed"),deviceId:S().min(1)}).strict();A({deviceId:S().min(1),pinned:Ne()}).strict();A({type:ee("contact:pin:ok"),deviceId:S().min(1),pinnedAt:G().int().nullable()}).strict();A({type:ee("contact:pinned"),deviceId:S().min(1),pinnedAt:G().int().nullable()}).strict();const IL=A({deviceId:S().min(1),name:S().min(1),url:S().min(1)});A({type:ee("device:list:ok"),devices:_e(IL)});A({deviceId:S().min(1),url:S().min(1).optional(),name:S().optional()});A({type:ee("device:connect:ok"),deviceId:S(),name:S(),url:S()});const fN=A({ownerId:S().min(1),provider:S().min(1),displayName:S().min(1),avatarUrl:S().optional(),unionId:S().optional()});A({type:ee("auth:login:start:ok"),authUrl:S().min(1),state:S().min(1)});A({type:ee("auth:getIdentity:ok"),identity:fN.nullable(),deviceId:S().min(1)});A({type:ee("auth:logout:ok")});A({type:ee("auth:login:done"),identity:fN});A({type:ee("auth:login:failed"),reason:S()});const Wx=ai("kind",[A({kind:ee("success"),text:S(),filePaths:_e(S()).optional()}),A({kind:ee("failure"),reason:S()})]);A({targetPersona:S().min(1).optional(),dispatchId:S().min(1).optional(),prompt:S(),targetDeviceId:S().min(1).optional(),model:S().min(1).optional(),sessionLabel:S().min(1).max(60).optional()}).refine(e=>e.targetPersona!==void 0||e.dispatchId!==void 0,{message:"either targetPersona (new dispatch) or dispatchId (follow-up) is required"}).refine(e=>!(e.dispatchId!==void 0&&e.targetDeviceId!==void 0),{message:"cross-device dispatch cannot be continued (dispatchId + targetDeviceId are mutually exclusive)"});A({dispatchId:S().min(1),outcome:Wx});const RL=["running","completed","failed"],pN=Ye(RL),ML=A({dispatchId:S().min(1),sourceSessionId:S().min(1),sourcePersonaId:S().min(1).optional(),targetPersonaId:S().min(1),workerSessionId:S().min(1).optional(),taskText:S(),status:pN,outcome:Wx.optional(),meta:Xa(to()).optional(),createdAt:S().min(1),completedAt:S().min(1).optional(),deliveredAt:S().min(1).optional()});A({sourceSessionId:S().min(1).optional()});A({records:_e(ML)});A({dispatchId:S().min(1)});A({type:ee("personaDispatch:get:ok"),status:pN,outcome:Wx.optional()});const AL=/^[a-z0-9][a-z0-9-]*$/;Ye(["stopped","starting","running","crashed","invalid"]);const jL=new Set(["localhost","127.0.0.1"]);function DL(e){let t;try{t=new URL(e)}catch{return!1}return!!(t.protocol==="https:"||t.protocol==="http:"&&jL.has(t.hostname))}const Ku=A({id:S().regex(AL),name:S().min(1),version:S().min(1),apiVersion:ee("1"),runtime:A({startCommand:S().min(1)}).passthrough().optional(),entry:A({url:S().url().refine(DL,{message:"INVALID_URL_SCHEME: only https or http://localhost is allowed"})}).strict().optional()}).passthrough().superRefine((e,t)=>{var i;const n=!!e.runtime,r=!!((i=e.entry)!=null&&i.url);n&&r&&t.addIssue({code:K.custom,message:"INVALID_MANIFEST: entry.url and runtime cannot coexist"}),!n&&!r&&t.addIssue({code:K.custom,message:"INVALID_MANIFEST: must have either entry.url or runtime"})}),LL=ai("kind",[A({kind:ee("local"),port:G().int().min(1).max(65535)}),A({kind:ee("hosted"),url:S().url()})]);ai("state",[A({extId:S(),manifest:Ku,state:ee("stopped")}),A({extId:S(),manifest:Ku,state:ee("starting")}),A({extId:S(),manifest:Ku,state:ee("running"),target:LL}),A({extId:S(),manifest:Ku,state:ee("crashed")}),A({extId:S(),manifest:to().nullable(),state:ee("invalid"),invalidReason:S().min(1)})]);A({snapshotHash:S().min(1),version:S().min(1),publishedAt:G()});const OL=ai("kind",[A({kind:ee("p2p-tunnel"),ownerPrincipalId:S().min(1),extId:S().min(1)})]);ai("kind",[A({kind:ee("p2p-tunnel"),ownerPrincipalId:S().min(1),extId:S().min(1),snapshotHash:S().min(1)})]);A({extId:S().min(1),name:S().min(1),version:S().min(1),contentHash:S().min(1),publishedAt:G()});const BL=ai("kind",[A({kind:ee("clean")}),A({kind:ee("ready-new-version"),fromVersion:S().min(1),toVersion:S().min(1)}),A({kind:ee("error-same-hash"),version:S().min(1)}),A({kind:ee("error-version-not-bumped"),localVersion:S().min(1),publishedVersion:S().min(1)}),A({kind:ee("error-version-regression"),localVersion:S().min(1),publishedVersion:S().min(1)})]);A({localManifest:A({name:S().min(1),version:S().min(1),contentHash:S().min(1)}),publishState:ai("kind",[A({kind:ee("unpublished")}),A({kind:ee("published"),version:S().min(1),contentHash:S().min(1),publishedAt:G()})]),check:BL});A({extId:S().min(1),newVersion:S().min(1).nullish()});A({extId:S().min(1)});A({extId:S().min(1),snapshotHash:S().min(1)});A({channelRef:OL,snapshotHash:S().min(1),zipBase64:S().min(1)});A({id:S().min(1),peerDeviceId:S().min(1),senderDeviceId:S().min(1),text:S().min(1),createdAt:G().int().nonnegative(),readBy:Xa(S().min(1),G().int().positive()).default({}),origin:A({kind:ee("persona"),personaId:S().min(1)}).optional()}).strict();A({peerDeviceId:S().min(1).optional(),id:S().min(1),text:S().min(1),createdAt:G().int().nonnegative(),origin:A({kind:ee("persona"),personaId:S().min(1)}).optional()}).strict();A({peerDeviceId:S().min(1),sinceCreatedAt:G().int().nonnegative().optional()}).strict();A({peerDeviceId:S().min(1),upToCreatedAt:G().int().nonnegative()}).strict();A({peerDeviceId:S().min(1).optional(),text:S().min(1)});A({peerDeviceId:S().min(1).optional(),command:S().min(1),timeoutMs:G().int().positive().optional()}).strict();A({type:ee("peerExec:run:ok"),stdout:S(),stderr:S(),exitCode:G().int().nullable(),timedOut:Ne(),stdoutTruncated:Ne(),stderrTruncated:Ne()}).strict();const mN=ai("kind",[A({kind:ee("at"),at:S().min(1)}),A({kind:ee("every"),everyMs:G().int().positive(),anchorMs:G().int().nonnegative().optional()}),A({kind:ee("cron"),expr:S().min(1),tz:S().min(1).optional()})]),ru=S().trim().min(1);A({personaId:ru,name:S().min(1),schedule:mN,prompt:S().min(1),targetPersona:S().min(1).optional(),timeoutMs:G().int().positive().optional()});A({personaId:ru,onlyMine:Ne().optional()});A({personaId:ru,shiftId:S().min(1)});const zL=A({name:S().min(1).optional(),schedule:mN.optional(),prompt:S().min(1).optional(),targetPersona:S().min(1).optional(),timeoutMs:G().int().positive().optional(),enabled:Ne().optional()});A({personaId:ru,shiftId:S().min(1),patch:zL});A({personaId:ru,shiftId:S().min(1),limit:G().int().positive().optional()});A({personaId:S().min(1)});A({personaId:S().min(1),appId:S().min(1),appSecret:S().min(1),botName:S().min(1).optional()});const $L=A({chatId:S().min(1),chatName:S().optional(),lastActiveAt:G().int().optional()}),FL=A({state:Ye(["unbound","bound","broken"]),appId:S().optional(),botName:S().optional(),brokenReason:S().optional(),groups:_e($L)});FL.extend({personaId:S().min(1)});const HL=A({personaId:S(),label:S(),model:S().optional(),public:Ne(),iconKey:S().optional(),tool:S().optional(),createdAt:G(),updatedAt:G()}).strict(),UL=A({name:S().min(1),description:S().optional()}),WL=A({id:S().min(1)}),VL=A({permissions:A({defaultMode:S().optional(),allow:_e(S()).optional(),deny:_e(S()).optional()}).optional(),sandbox:A({enabled:Ne().optional(),autoAllowBashIfSandboxed:Ne().optional(),allowUnsandboxedCommands:Ne().optional(),excludedCommands:_e(S()).optional(),filesystem:A({denyRead:_e(S()).optional(),allowRead:_e(S()).optional(),denyWrite:_e(S()).optional(),allowWrite:_e(S()).optional()}).optional(),network:A({allowedDomains:_e(S()).optional(),allowLocalBinding:Ne().optional()}).optional()}).optional()});HL.extend({personality:S().optional(),skills:_e(UL).optional(),plugins:_e(WL).optional(),sandboxSettings:VL.nullable().optional()});A({slug:S().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/).max(32),label:S().min(1),personality:S(),model:S().optional(),tool:S().optional(),public:Ne().optional(),iconKey:S().optional()}).strict();A({personaId:S().min(1)});A({personaId:S().min(1),patch:A({label:S().min(1).optional(),model:S().optional(),tool:S().optional(),personality:S().optional(),public:Ne().optional(),iconKey:S().nullable().optional()}).strict()}).strict();A({writableRoots:_e(S()).optional(),denyRead:_e(S()).optional(),network:Ne().optional()}).strict();const gN=["ready","session:info","session:status","session:event","session:deleted","session:rewound","session:cleared","permission:request","session:question","session:question:cleared","pong","error","subscribed","unsubscribed","auth:ok","tunnel:ready","tunnel:exited","tunnel:unavailable","session:control","session:pty","contact:added","contact:pinned","contact:removed","contact:remote-access-updated","inbox:event","friend:reverseTokenOffered","auth:login:done","auth:login:failed","appBuilder:project-updated","appBuilder:publish-progress","appBuilder:publish-failed","larkBot:state"],vN=["idle","running","running-idle","stopped","error","observing"],qL=["task-notification","slash-command","local-command","system-reminder","skill-hint","meta-text","attachment-skills","attachment-deferred-tools"],KL=["builtin","global","project","plugin"],GL=["builtin","global","project","policy","plugin"],xN=Ye(["owner","guest"]);A({id:S().min(1),kind:xN,displayName:S(),feishuUnionId:S().optional()}).strict();const XL=A({did:S().min(1),displayName:S(),feishuUnionId:S().optional(),principal:xN}).strict(),YL=Ye(vN),ZL=A({input_tokens:G().int().nonnegative().optional(),cache_read_input_tokens:G().int().nonnegative().optional(),cache_creation_input_tokens:G().int().nonnegative().optional(),output_tokens:G().int().nonnegative().optional()}),QL=A({inputTokens:G().int().nonnegative(),outputTokens:G().int().nonnegative(),cacheReadTokens:G().int().nonnegative().optional(),cacheCreateTokens:G().int().nonnegative().optional()}),_N={gitBranch:S().optional(),resolvedModel:S().optional(),contextUsage:QL.optional(),contextWindowSize:G().int().positive().optional()},JL=A(_N),yN=A({value:S(),label:S(),description:S().optional()}),eO=A({id:S().min(1),label:S().min(1),description:S().optional(),contextWindowSize:G().int().positive(),default:Ne().optional(),efforts:_e(yN).optional(),defaultEffort:S().optional()}),tO=A({id:S().min(1),label:S().min(1),description:S().optional()}),nO=A({name:S().min(1),type:Ye(["string","select","toggle"]),label:S().min(1),description:S().optional(),options:_e(yN).optional(),default:to().optional(),scope:Ye(["core","tool-specific"])});A({tool:S().min(1)});const rO=A({rewind:Ne(),subagents:Ne(),tui:Ne(),observe:Ne(),fileSharing:Ne(),fork:Ne()});A({tool:S().min(1),toolSessionIdLabel:S().optional(),models:_e(eO),permissionModes:_e(tO),configSchema:_e(nO),features:rO});const iO=A({tool:S().min(1),pattern:S().min(1),createdAt:S().min(1).optional()});A({sessionId:S().min(1),cwd:S().min(1),tool:ee("claude").or(S().min(1)).default("claude"),toolSessionId:S().optional(),label:S().optional(),model:S().optional(),permissionMode:S().optional(),effort:S().optional(),..._N,permissionRules:_e(iO).optional(),pinnedAt:G().int().nonnegative().nullable().optional(),pinSortOrder:G().int().nullable().optional(),unreadAt:S().min(1).nullable().optional(),iconKey:S().optional(),forkedFromSessionId:S().min(1).optional(),ephemeral:Ne().optional(),ownerPersonaId:S().min(1).optional(),appBuilderProject:S().regex(/^[a-z][a-z0-9-]{0,39}$/).optional(),chatId:S().min(1).optional(),creatorPrincipalId:S().min(1).optional(),creatorDisplayName:S().min(1).optional(),creatorFeishuUnionId:S().min(1).optional(),originOwnerPrincipalId:S().min(1).optional(),originOwnerPersonaId:S().min(1).optional(),dispatchedFromSessionId:S().min(1).optional(),shiftFiredFromSessionId:S().min(1).optional(),larkChatId:S().min(1).optional(),larkChatName:S().min(1).optional(),createdAt:S().min(1),updatedAt:S().min(1)});const On={seq:G().int().nonnegative().optional(),ts:S().optional(),uuid:S().optional()},sO=Ye(qL),oO=A({readCount:G().int().nonnegative().optional(),searchCount:G().int().nonnegative().optional(),bashCount:G().int().nonnegative().optional(),editFileCount:G().int().nonnegative().optional(),linesAdded:G().int().nonnegative().optional(),linesRemoved:G().int().nonnegative().optional(),otherToolCount:G().int().nonnegative().optional()}),aO=A({oldStart:G().int().nonnegative(),oldLines:G().int().nonnegative(),newStart:G().int().nonnegative(),newLines:G().int().nonnegative(),lines:_e(S())}),lO=A({agentId:S().optional(),agentType:S().optional(),status:S().optional(),prompt:S().optional(),filePath:S().optional(),structuredPatch:_e(aO).optional(),stats:A({durationMs:G().int().nonnegative().optional(),tokens:G().int().nonnegative().optional(),toolUseCount:G().int().nonnegative().optional(),toolStats:oO.optional(),usage:ZL.optional()}).optional()}),cO=A({path:S(),content:S(),mtimeMs:G().optional()}),uO=A({label:S().min(1),description:S().optional()}),bN=A({question:S().min(1),multiSelect:Ne(),options:_e(uO).min(1)});ai("kind",[A({...On,kind:ee("session_init"),toolSessionId:S().optional()}),A({...On,kind:ee("thinking"),text:S(),partialId:S().optional()}),A({...On,kind:ee("text"),text:S(),partialId:S().optional()}),A({...On,kind:ee("user_text"),text:S(),meta:sO.optional(),taskId:S().optional(),parentToolUseId:S().optional(),sender:XL.optional()}),A({...On,kind:ee("tool_call"),toolUseId:S(),tool:S(),toolKind:S().optional(),input:to()}),A({...On,kind:ee("tool_result"),toolUseId:S(),output:to().optional(),error:S().optional(),toolResultExtra:lO.optional(),sourceToolAssistantUUID:S().optional(),askQuestionAnswers:Xa(S(),S()).optional()}),A({...On,kind:ee("attachment_memories"),memories:_e(cO)}),A({...On,kind:ee("permission_request"),requestId:S(),tool:S(),input:to(),toolUseId:S().optional()}),A({...On,kind:ee("ask_user_question"),toolUseId:S(),questions:_e(bN)}),A({...On,kind:ee("turn_end")}),A({...On,kind:ee("subagent_progress"),toolUseId:S(),agentId:S(),status:Ye(["started","running","completed","failed"]),description:S().optional(),lastToolName:S().optional(),prompt:S().optional(),stats:A({durationMs:G().int().nonnegative().optional(),tokens:G().int().nonnegative().optional(),toolUseCount:G().int().nonnegative().optional()}).optional()}),A({...On,kind:ee("error"),message:S()}),A({...On,kind:ee("meta_update"),patch:JL}),A({...On,kind:ee("meta-text"),text:S(),metaSource:Ye(["cc","owner"]).optional()})]);A({cwd:S().min(1).optional(),tool:S().optional(),label:S().optional(),model:S().optional(),permissionMode:S().optional(),effort:S().optional(),iconKey:S().optional(),forkedFromSessionId:S().min(1).optional(),ephemeral:Ne().optional(),ownerPersonaId:S().min(1).optional()}).refine(e=>e.cwd!=null||e.ownerPersonaId!=null,{message:"cwd 与 ownerPersonaId 至少传一个"});A({cwd:S().min(1),tool:S().min(1),toolSessionId:S().min(1),label:S().optional(),iconKey:S().optional(),createdAt:S().datetime(),updatedAt:S().datetime(),ownerPersonaId:S().min(1).optional()});A({originOnly:Ne().optional(),ownerPersonaId:S().min(1).optional(),limit:G().int().positive().optional(),offset:G().int().nonnegative().optional()});A({sessionId:S().min(1)});A({sessionId:S().min(1),patch:A({label:S().optional(),model:S().optional(),permissionMode:S().optional(),effort:S().optional(),cwd:S().optional(),iconKey:S().optional(),ephemeral:ee(!1).optional()})});A({sessionId:S().min(1),text:S()});A({sessionId:S().min(1),userMessageId:S().min(1),dryRun:Ne().optional()});A({canRewind:Ne(),error:S().optional(),filesChanged:_e(S()).optional(),insertions:G().int().nonnegative().optional(),deletions:G().int().nonnegative().optional()});A({sessionId:S().min(1),userMessageId:S().min(1)});const dO=A({oldStart:G().int().nonnegative(),oldLines:G().int().nonnegative(),newStart:G().int().nonnegative(),newLines:G().int().nonnegative(),lines:_e(S())}),hO=A({filePath:S().min(1),hunks:_e(dO),insertions:G().int().nonnegative(),deletions:G().int().nonnegative(),status:Ye(["modified","added","deleted"]).optional()});A({canRewind:Ne(),error:S().optional(),files:_e(hO),totalInsertions:G().int().nonnegative(),totalDeletions:G().int().nonnegative()});A({userMessageIds:_e(S())});A({sessionId:S().min(1),toolSessionId:S().min(1)});A({cwd:S().min(1),toolSessionId:S().min(1),messageUuid:S().min(1),targetCwd:S().min(1).optional()});A({forkedToolSessionId:S().min(1),forkedFilePath:S().min(1)});A({sessionId:S().min(1),toolSessionId:S().min(1),jsonlPath:S().optional()});A({sessionId:S().min(1),afterSeq:G().int().min(-1)});A({sessionId:S().min(1),permissionRequestId:S().min(1),allow:Ne(),permanent:Ne().optional(),pattern:S().optional()});A({projectPath:S().min(1)});A({sessionId:S().min(1),limit:G().int().positive().max(5e3).optional(),offset:G().int().nonnegative().optional(),slim:Ne().optional()});A({cwd:S().min(1),toolSessionId:S().min(1)});A({cwd:S().min(1),toolSessionId:S().min(1),subagentId:S().min(1)});A({cwd:S().min(1).optional(),path:S().optional(),showHidden:Ne().optional()});A({cwd:S().min(1),path:S().min(1)});A({cwd:S().min(1),tool:S().optional()});A({name:S().min(1),source:Ye(KL),path:S().optional(),description:S().optional(),plugin:S().optional()});const fO=A({name:S().min(1),source:Ye(GL),path:S().optional(),description:S().optional(),whenToUse:S().optional(),plugin:S().optional()});A({cwd:S().min(1),tool:S().optional()});A({agents:_e(fO)});A({sessionId:S().optional()});A({sessionId:S().min(1).optional()});A({sessionId:S().min(1),pinned:Ne()});A({type:ee("peerSession:upsert:ok")});A({sessionId:S().min(1)});A({type:ee("peerSession:remove:ok")});A({orderedIds:_e(S().min(1)).min(1)});A({cwd:S().min(1)});A({isGitRoot:Ne(),gitRoot:S().nullable()});A({cwd:S().min(1)});A({branch:S().nullable()});A({cwd:S().min(1)});A({branches:_e(S()),head:S().nullable()});A({}).optional();const pO=A({cwd:S().min(1),updatedAt:S().min(1)});A({dirs:_e(pO)});A({type:ee("session:question"),sessionId:S().min(1),toolUseId:S().min(1),requestId:S().min(1),questions:_e(bN).min(1)});A({type:ee("session:question:cleared"),sessionId:S().min(1),toolUseId:S().min(1),answers:Xa(S(),S()).optional()});A({sessionId:S().min(1),toolUseId:S().min(1),answers:Xa(S(),S())});A({ok:ee(!0)});A({sessionId:S().min(1),toolUseId:S().min(1)});A({ok:ee(!0)});const wN=A({name:S().min(1),version:S().min(1),instanceId:S().min(1),deviceLabel:S().transform(e=>e.trim().slice(0,64)).optional()});A({type:ee("auth"),token:S().min(1),scheme:ee("bearer").optional(),clientInfo:wN.optional()});A({type:ee("auth:ok"),version:S().min(1).optional(),protocolVersion:G().int().nonnegative().optional()});const mO=A({clientId:S().min(1),connectedAt:G().int().nonnegative(),self:Ne(),clientInfo:wN.optional()});A({type:ee("device:connections:ok"),connections:_e(mO)});A({type:ee("tunnel:ready"),url:S().min(1),subdomain:S().min(1)});A({type:ee("tunnel:exited"),code:G().int().nullable(),subdomain:S().nullable(),url:S().nullable()});A({type:ee("tunnel:unavailable"),reason:S().min(1),failedAt:S().min(1)});const gO=A({sessionId:S().min(1),status:YL,freshSpawn:Ne(),pendingPermissionRequestIds:_e(S().min(1)),pendingQuestionToolUseIds:_e(S().min(1))});A({type:ee("info"),version:S(),protocolVersion:G(),hostname:S(),os:S(),tools:_e(A({id:S(),available:Ne()})),runningSessions:_e(gO),tokenRole:Ye(SL).optional(),isLoopback:Ne().optional(),httpBaseUrl:S().optional(),httpToken:S().optional(),daemonSource:Ye(["ota","packaged"]).optional(),globalCliVersion:S().nullable().optional()});const vO=6173,xO=6272,Ya=/^[a-z][a-z0-9-]{0,39}$/,iu=A({name:S().regex(Ya,{message:"kebab-case, 小写字母开头,只允许小写字母 / 数字 / -,最长 40 字符"}),port:G().int().min(vO).max(xO),createdAt:S().datetime(),devCommand:S().min(1),prodUrl:S().url().optional(),readyPattern:S().optional(),publishJob:A({jobId:S().min(1),stage:Ye(["build","deploy","verify"]),startedAt:G().int().nonnegative()}).optional()}),_O=["install-pending","installing","starting-dev-server","running","stopped","failed"],SN=Ye(_O),Vx=iu.extend({isRunning:Ne(),boundSessionId:S().nullable(),stage:SN.optional(),stageReason:S().optional(),publishJob:A({jobId:S().min(1),stage:Ye(["build","deploy","verify"]),startedAt:G().int().nonnegative(),status:Ye(["in-flight","interrupted"])}).optional()});A({}).strict();A({projects:_e(Vx)}).strict();A({sessionId:S().min(1)}).strict();A({project:Vx.nullable()}).strict();A({sessionId:S().min(1),name:S().min(1)}).strict();A({project:iu}).strict();A({name:S()}).strict();A({}).strict();A({name:S(),newPort:G().int()}).strict();A({project:iu}).strict();A({name:S().regex(Ya),url:S().url()}).strict();A({project:iu}).strict();A({sessionId:S().min(1),force:Ne().optional()}).strict();A({project:iu}).strict();const yO=["installing","failed"];A({sessionId:S().min(1),stage:Ye(yO),reason:S().optional()}).strict();A({ok:ee(!0)}).strict();A({sessionId:S().min(1)}).strict();A({ok:ee(!0)}).strict();A({type:ee("appBuilder:project-updated"),project:Vx,stage:SN,stageReason:S().optional()}).strict();A({name:S().regex(Ya)});A({jobId:S().min(1),status:Ye(["started","already-publishing"])}).strict();A({name:S().regex(Ya)});A({ok:ee(!0)}).strict();A({type:ee("appBuilder:publish-progress"),name:S().regex(Ya),jobId:S().min(1),stage:Ye(["build","deploy","verify"]),status:Ye(["started","completed"])}).strict();A({type:ee("appBuilder:publish-failed"),name:S().regex(Ya),jobId:S().min(1),stage:Ye(["build","deploy","verify","unknown"]),errorSummary:S()}).strict();A({});A({method:S().min(1).optional()});const bO=["allowed","conditional","denied"],wO=Ye(bO),SO=A({name:S().min(1),status:wO,description:S().min(1),args:_e(A({name:S(),required:Ne()})).nullable(),argsSchema:Xa(to()).optional(),reason:S().optional()});A({type:ee("meta:methods"),methods:_e(SO)});const Cb=1,kO=["daemon","main","renderer"],CO=Ye(kO),EO=["debug","info","warn","error"],NO=Ye(EO);A({ts:G().int(),source:CO,level:NO,msg:S(),ownerPrincipalId:S(),deviceId:S(),appVersion:S(),daemonVersion:S().optional(),os:S(),meta_json:S().optional(),sessionId:S().optional()});A({v:ee(1),visitorId:S().min(1),displayName:S(),provider:S(),iat:G(),exp:G()});const TO=A({visitorId:S(),displayName:S(),avatarUrl:S().optional(),provider:S(),firstSeen:G(),lastSeen:G()});A({visitors:_e(TO)});const PO=/<system-reminder>此消息来自飞书群成员 (.+?)<\/system-reminder>\s*$/,IO=new Set(["localhost","127.0.0.1","0.0.0.0","::1"]);let pi=null;function RO(){if(pi!==null)return pi;if(typeof window>"u")return pi=!1,!1;if(IO.has(window.location.hostname)||window.location.protocol==="file:")return pi=!0,!0;if(new URLSearchParams(window.location.search).get("debug")==="1"){pi=!0;try{sessionStorage.setItem("debug","1")}catch{}}else try{pi=sessionStorage.getItem("debug")==="1"}catch{pi=!1}return pi}function Re(e,...t){RO()&&console.log(`[${e}][${new Date().toISOString()}]`,...t)}function Gu(e){if(!e)return"<none>";let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return`<len:${e.length} hash:${(t>>>0).toString(16)}>`}const MO=e=>{const t=[1e3,2e3,4e3,8e3,16e3,3e4];return t[Math.min(e,t.length-1)]},AO=new Set(["auth:ok","pong","error"]),Eb=new Set(gN.filter(e=>!AO.has(e)));let jO=0;const Nb=()=>`r${++jO}`;function DO(e){let t=e.url,n=e.authToken,r=e.selfIdentity;const i=e.clientInfo,s=e.requestTimeoutMs??3e4,o=e.pingIntervalMs??3e4,a=e.watchdogMs??6e4,l=e.authTimeoutMs??1e4,c=e.backoffMs??MO;let u=null,d=!1,f=0,p=null,m=null,v=null,y=null,x=!1,_="disconnected";const b=new Map,w=new Map;let k=null;const C=(B,E)=>{var H;B==="ready"&&(k=E),(H=w.get(B))==null||H.forEach(q=>{try{q(E)}catch{}})},N=B=>{_!==B&&(_=B,C("status",B))},T=(B,E)=>{const H=w.get(B)??new Set;if(H.add(E),w.set(B,H),B==="ready"&&k!==null)try{E(k)}catch{}return()=>H.delete(E)},L=()=>{m&&(clearInterval(m),m=null),v&&(clearTimeout(v),v=null),y&&(clearTimeout(y),y=null)},P=()=>{v&&clearTimeout(v),v=setTimeout(()=>{try{u==null||u.close(4e3,"pong watchdog")}catch{}},a)},O=()=>{m&&clearInterval(m),m=setInterval(()=>{(u==null?void 0:u.readyState)===1&&u.send(JSON.stringify({type:"ping",requestId:Nb()}))},o),P()},I=B=>{for(const[,E]of b)clearTimeout(E.timer),E.reject(new Error(B));b.clear()},R=[],D=()=>{if(R.length===0)return;const B=R.splice(0);for(const E of B)(u==null?void 0:u.readyState)===1&&!x?E.doSend():(clearTimeout(E.timer),E.reject(new Error("NOT_CONNECTED")))},z=B=>{if(R.length===0)return;const E=R.splice(0);for(const H of E)clearTimeout(H.timer),H.reject(new Error(B))},$=()=>{if(d)return;const B=c(f);B<0||(C("daemon:reconnecting",{attempt:f+1,nextDelayMs:B,scheduledAt:Date.now()}),p&&clearTimeout(p),p=setTimeout(()=>{f+=1,j()},B))},F=B=>{P();const E=String(B.type??"");if(E==="auth:ok"){Re("daemon-client","auth:ok received → connected",{url:t}),y&&(clearTimeout(y),y=null),x=!1,f=0,N("connected"),C("daemon:connected",{url:t}),O(),D();return}if(E==="pong")return;if(E==="ready"){const q=Number(B.protocolVersion??-1);q!==Cb&&C("daemon:version-mismatch",{daemonProtocol:q,supportedProtocol:Cb}),C("ready",B);return}const H=B.requestId;if(typeof H=="string"&&b.has(H)){const q=b.get(H);if(b.delete(H),clearTimeout(q.timer),E==="error"){const M=String(B.code??"ERR"),re=String(B.message??"unknown");q.reject(new Error(`${M}: ${re}`))}else Eb.has(E)&&C(E,B),q.resolve(B);return}Eb.has(E)&&C(E,B)},j=()=>{p&&(clearTimeout(p),p=null),Re("daemon-client","connect →",{url:t,token:Gu(n),attempt:f}),N("connecting");let B;try{B=new WebSocket(t)}catch(E){N("disconnected"),C("daemon:disconnected",{reason:(E==null?void 0:E.message)??"ws constructor failed"}),$();return}u=B,x=!!n,B.onopen=()=>{if(B!==u){Re("daemon-client","onopen → stale (replaced before opened), ignore");return}if(n){Re("daemon-client","onopen → send auth frame",{token:Gu(n)});const E={type:"auth",token:n};r!=null&&r.principalId&&(E.selfPrincipalId=r.principalId),r!=null&&r.displayName&&(E.selfDisplayName=r.displayName),i&&(E.clientInfo=i),B.send(JSON.stringify(E)),y=setTimeout(()=>{try{B.close(4001,"auth handshake timeout")}catch{}},l)}else Re("daemon-client","onopen → no token, treat as connected (daemon authMode=none)"),f=0,N("connected"),C("daemon:connected",{url:t}),O(),D()},B.onclose=E=>{if(B!==u){Re("daemon-client","onclose → stale, ignore",{code:E.code,reason:E.reason});return}const H=E.reason||(E.code===1008?"auth failed":`close ${E.code}`);if(Re("daemon-client","onclose →",{code:E.code,reason:H,awaitingAuth:x,manualStop:d}),L(),I(`connection closed: ${H}`),u=null,E.code===4401?N("revoked"):N("disconnected"),C("daemon:disconnected",{reason:H}),E.code===1008||E.code===4401){z(`connection closed: ${H}`);return}d?z(`connection closed: ${H}`):$()},B.onerror=()=>{},B.onmessage=E=>{if(B!==u)return;let H;try{H=JSON.parse(String(E.data))}catch{return}F(H)}};return{start(){d=!1,f=0,j()},stop(){d=!0,p&&(clearTimeout(p),p=null),L();try{u==null||u.close(1e3,"shutdown")}catch{}u=null,I("shutdown"),z("shutdown"),N("disconnected")},switchProfile(B){Re("daemon-client","switchProfile →",{url:B.url,token:Gu(B.authToken)},"prev:",{url:t,token:Gu(n)}),t=B.url,n=B.authToken,B.selfIdentity!==void 0&&(r=B.selfIdentity),f=0,d=!0,p&&(clearTimeout(p),p=null),L(),I("switch profile"),z("switch profile");try{u==null||u.close(1e3,"switch profile")}catch{}u=null,d=!1,j()},request(B,E){return new Promise((H,q)=>{const M=Nb(),re=setTimeout(()=>{b.delete(M);const V=R.findIndex(pe=>pe.timer===re);V>=0&&R.splice(V,1),q(new Error(`request timeout: ${B}`))},s),oe=()=>{b.set(M,{resolve:V=>H(V),reject:q,timer:re}),u.send(JSON.stringify({...E,type:B,requestId:M}))};(u==null?void 0:u.readyState)===1&&!x?oe():d||u==null&&p==null?(clearTimeout(re),q(new Error("NOT_CONNECTED"))):R.push({doSend:oe,reject:q,timer:re})})},on:T,get isOpen(){return(u==null?void 0:u.readyState)===1&&!x},get url(){return t},getStatus(){return _}}}function LO(e){if(!e)return"<none>";let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return`<len:${e.length} hash:${(t>>>0).toString(16)}>`}function OO(e){return e?{id:e.id,mode:e.mode,url:e.url,token:LO(e.token),name:e.name}:null}function Xu(e){return e?Array.isArray(e)?e.map(OO):{_notArray:typeof e,_value:e}:null}function Tb(e){return e==null?null:typeof e=="object"&&"value"in e?e.value:e}const BO="ws://127.0.0.1:18790",Pb="daemon:profiles",Ib="daemon:active-profile-id";function zO(){return Math.random().toString(36).slice(2,10)}function $O(e){const t=e.trim(),n=t.indexOf("#");if(n<0)return{url:t};const r=t.slice(0,n),i=new URLSearchParams(t.slice(n+1)).get("token")??void 0;return{url:r,token:i}}function FO(e){if(!e||typeof e!="object")return!1;const t=e;return typeof t.id=="string"&&typeof t.name=="string"&&(t.mode==="localhost"||t.mode==="remote")&&typeof t.url=="string"&&(t.token===void 0||typeof t.token=="string")}function kN(e){let t={profiles:[],activeId:null},n=!1,r=null;const i=new Set,s=()=>{for(const l of i)l(t)},o=async()=>{Re("profile-store","persist →",Xu(t.profiles),"active:",t.activeId),await e.kv.set(Pb,t.profiles),await e.kv.set(Ib,t.activeId)},a=async()=>{if(!n){if(r){await r;return}r=(async()=>{var l;try{let c=null;try{const d=await e.kv.get(Pb);c=Tb(d)}catch{c=null}let u=null;try{const d=await e.kv.get(Ib);u=Tb(d)??null}catch{u=null}if(Re("profile-store","ensureLoaded read kv →","profiles:",Xu(c),"activeId:",u),Array.isArray(c)&&c.length>0){const d=c.filter(FO),f=u&&d.some(p=>p.id===u)?u:((l=d[0])==null?void 0:l.id)??null;t={profiles:d,activeId:f},n=!0,Re("profile-store","ensureLoaded → use kv profiles",Xu(d),"active:",f);return}t={profiles:[{id:"default",name:"本机",mode:"localhost",url:BO}],activeId:"default"},Re("profile-store","ensureLoaded → fallback synthesized default (NO token)",Xu(t.profiles)),n=!0,await o()}finally{r=null}})(),await r}};return{async load(){return await a(),s(),t},async snapshot(){return await a(),t},async upsert(l){var y;await a();let c=l.url,u=l.token;if(c&&c.includes("#")){const x=$O(c);c=x.url,!u&&x.token&&(u=x.token)}const d=l.id?t.profiles.find(x=>x.id===l.id):void 0,f=u!=null&&u.trim()?u.trim():d==null?void 0:d.token;if(l.mode==="remote"&&!f)throw new Error("remote mode requires token");const p=l.id??zO(),m={id:p,name:((y=l.name)==null?void 0:y.trim())||(d==null?void 0:d.name)||(l.mode==="remote"?"远程":"本机"),mode:l.mode,url:c.trim(),token:f};return t={profiles:[...t.profiles.filter(x=>x.id!==p),m],activeId:p},await o(),s(),m},async delete(l){var d;await a();const c=t.profiles.filter(f=>f.id!==l);let u=t.activeId;u===l&&(u=((d=c[0])==null?void 0:d.id)??null),t={profiles:c,activeId:u},await o(),s()},async activate(l){await a(),t.profiles.some(c=>c.id===l)&&(t={...t,activeId:l},await o(),s())},subscribe(l){return i.add(l),()=>i.delete(l)},getActive(){return n?t.profiles.find(l=>l.id===t.activeId)??null:null}}}const Rb="clawd.client-instance-id";let HO={name:"clawd-web",version:"unknown"};function UO(){let e=null;try{e=localStorage.getItem(Rb),e||(e=crypto.randomUUID(),localStorage.setItem(Rb,e))}catch{e=e??crypto.randomUUID()}return{...HO,instanceId:e}}function Mb(e){if(!e)return"<none>";let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return`<len:${e.length} hash:${(t>>>0).toString(16)}>`}const CN=g.createContext(null);function WO({host:e,children:t}){const[n,r]=g.useState(null),i=g.useMemo(()=>async()=>{const s=kN(e),o=await s.load(),a=o.profiles.find(c=>c.id===o.activeId)??o.profiles[0];if(!a)throw new Error("DaemonProvider: profile store has no profiles after load");return Re("daemon-context","bootstrap → createDaemonClient",{id:a.id,url:a.url,token:Mb(a.token)}),{client:DO({url:a.url,authToken:a.token,clientInfo:UO()}),store:s}},[e]);return g.useEffect(()=>{let s=!0,o=null,a=null;return i().then(l=>{s&&(l.client.start(),o=l,r(l),a=l.store.subscribe(()=>{const c=l.store.getActive();if(!c){Re("daemon-context","subscribe → no active profile, skip switchProfile");return}Re("daemon-context","subscribe → switchProfile",{id:c.id,url:c.url,token:Mb(c.token)}),l.client.switchProfile({url:c.url,authToken:c.token})}))}),()=>{s=!1,a==null||a(),o==null||o.client.stop()}},[i]),n?h.jsx(CN.Provider,{value:n,children:t}):null}function Bi(){const e=g.useContext(CN);if(!e)throw new Error("useDaemonClient must be used inside <DaemonProvider>");return e.client}function VO(){const e=Bi(),[t,n]=g.useState(void 0);return g.useEffect(()=>e.on("ready",i=>{const s=i.mode,o=s==="tui"?"tui":"sdk";Re("daemon-context","useDaemonMode ready.mode =",{rawMode:s,resolved:o}),n(o)}),[e]),t}const EN=g.createContext(null);function qO({cache:e,children:t}){return g.createElement(EN.Provider,{value:e},t)}function Co(){const e=g.useContext(EN);if(!e)throw new Error("useCache must be used inside <CacheProvider>");return e}function si(e){const t=Co(),n=g.useCallback(i=>t.observe(e,()=>i()),[t,e]),r=g.useCallback(()=>t.read(e),[t,e]);return g.useSyncExternalStore(n,r,r)}const NN={actionsLevel:"none",httpBaseUrl:null,httpToken:null},TN=g.createContext(NN);function Af(){return g.useContext(TN)}function KO(e){return e!=null&&e.httpBaseUrl?{actionsLevel:e.tokenRole==="owner"?"owner":"none",httpBaseUrl:e.httpBaseUrl,httpToken:e.httpToken??null}:NN}function GO(){const e=si("daemon-info");return g.useMemo(()=>KO(e),[e])}function XO({children:e}){const t=GO();return st.createElement(TN.Provider,{value:t},e)}function YO(e,t,n){if(!e.httpBaseUrl)return null;const r=encodeURIComponent(n);return`${e.httpBaseUrl}/session/${encodeURIComponent(t.sessionId)}/files?path=${r}`}function ZO(e){const t=new Map;return{observe(n,r){let i=t.get(n);i||(i={data:void 0,hasData:!1,listeners:new Set},t.set(n,i));const s=l=>r(l);i.listeners.add(s);const o=i.listeners.size===1;s(i.hasData?i.data:void 0),o&&e.onFirstObserver(n);let a=!1;return()=>{if(a)return;a=!0;const l=t.get(n);l&&(l.listeners.delete(s),l.listeners.size===0&&(t.delete(n),e.onLastObserver(n)))}},read(n){const r=t.get(n);return r!=null&&r.hasData?r.data:void 0},setData(n,r){const i=t.get(n);if(!i)return;const s=i.hasData?i.data:void 0,o=r(s);i.data=o,i.hasData=!0;for(const a of i.listeners)a(o)}}}function QO(){const e=[],t=new Map,n=r=>{for(const i of e)if(i.pattern.test(r))return i.source;return null};return{register(r,i){e.push({pattern:r,source:i})},activate(r){if(t.has(r))return;const i=n(r);if(!i)throw new Error(`no source registered for key: ${r}`);t.set(r,i.start(r))},deactivate(r){const i=t.get(r);i&&(t.delete(r),i())}}}function JO(e){return{request:(t,n)=>e.request(t,n),onFrame(t){const n=[];for(const r of gN)n.push(e.on(r,i=>t(r,i)));return()=>{for(const r of n)r()}},onConnect(t){return e.on("daemon:connected",()=>t())},get isConnected(){return e.isOpen}}}function PN(e){const t=(e??"claude")==="claude";return{rewind:t,subagents:t,tui:t,observe:t,fileSharing:t,fork:t}}const eB=e=>({tool:e,models:[{id:"",label:"Default",contextWindowSize:2e5,default:!0}],permissionModes:[{id:"",label:"Default"}],configSchema:[],features:PN(e)});function tB(e,t){return{start(n){const r=n.replace(/^capabilities\//,"");let i=!1;const s=async()=>{try{const a=await e.request("capabilities:get",{tool:r});if(i)return;t(n,()=>a)}catch{if(i)return;t(n,()=>eB(r))}},o=e.onConnect(()=>{s()});return s(),()=>{i=!0,o()}}}}function nB(e,t){return{start(n){let r=!1;const i=async()=>{try{const a=await e.request("session:list",void 0);if(r)return;t(n,()=>a.sessions??[])}catch{}},s=e.onFrame((a,l)=>{if(a==="session:info"){const c=l;if(c.chatId!==void 0)return;t(n,u=>[c,...(u??[]).filter(d=>d.sessionId!==c.sessionId)])}else if(a==="session:deleted"){const c=l;t(n,u=>(u??[]).filter(d=>d.sessionId!==c.sessionId))}}),o=e.onConnect(()=>{i()});return i(),()=>{r=!0,s(),o()}}}}const Mc={sessionId:null,events:[],lastSeq:-1,pendingPermissions:[],status:"idle",pendingQuestions:{}};function Gp(e,t){const n=t;if(n.kind==="permission_request"&&typeof n.requestId=="string"){if(e.some(i=>i.requestId===n.requestId))return e;const r={requestId:n.requestId,tool:typeof n.tool=="string"?n.tool:"",input:n.input,...typeof n.toolUseId=="string"&&n.toolUseId?{toolUseId:n.toolUseId}:{}};return[...e,r]}if(n.kind==="tool_result"&&typeof n.toolUseId=="string"&&n.toolUseId){const r=e.findIndex(i=>i.toolUseId===n.toolUseId);if(r>=0)return e.filter((i,s)=>s!==r)}return e}function IN(e,t,n){const r=n===void 0?e.sessionId:n;switch(t.type){case"session:change":return{...Mc,sessionId:t.sessionId};case"session:event":{if(!r||t.sessionId!==r)return e;const i=typeof t.event.seq=="number"?t.event.seq:-1,s=[...e.events,t.event],o=i>e.lastSeq?i:e.lastSeq,a=Gp(e.pendingPermissions,t.event);return{...e,events:s,lastSeq:o,pendingPermissions:a}}case"session:status":return!r||t.sessionId!==r?e:{...e,status:t.status};case"session:events":{if(!r||t.sessionId!==r)return e;const i=t.events.map(o=>o.event),s=i.reduce((o,a)=>Gp(o,a),[]);return{...e,sessionId:t.sessionId,events:i,lastSeq:t.latestSeq,pendingPermissions:s}}case"session:events:append":{if(!r||t.sessionId!==r)return e;const i=new Set;for(const c of e.events){const u=c.seq;typeof u=="number"&&i.add(u)}const s=[];for(const c of t.events)typeof c.seq=="number"&&(i.has(c.seq)||s.push(c.event));const o=t.latestSeq>e.lastSeq?t.latestSeq:e.lastSeq;if(s.length===0)return o===e.lastSeq?e:{...e,lastSeq:o};const a=[...e.events,...s].sort((c,u)=>{const d=c.seq??-1,f=u.seq??-1;return d-f}),l=s.reduce((c,u)=>Gp(c,u),e.pendingPermissions);return{...e,events:a,lastSeq:o,pendingPermissions:l}}case"permission:request":{if(!r||t.sessionId!==r||e.pendingPermissions.some(s=>s.requestId===t.requestId))return e;const i={requestId:t.requestId,tool:t.tool,input:t.input,...t.toolUseId?{toolUseId:t.toolUseId}:{}};return{...e,pendingPermissions:[...e.pendingPermissions,i]}}case"permission:clear":{if(!r||r!==t.sessionId)return e;const i=t.requestId,s=e.pendingPermissions.findIndex(c=>c.requestId===i),o=s>=0?e.pendingPermissions.filter((c,u)=>u!==s):e.pendingPermissions;if(e.events.length===0)return o===e.pendingPermissions?e:{...e,pendingPermissions:o};const a=e.events.length-1,l=e.events[a];return l.kind==="permission_request"&&l.requestId===i?{...e,pendingPermissions:o,events:e.events.slice(0,a)}:o===e.pendingPermissions?e:{...e,pendingPermissions:o}}case"session:question":return!r||t.sessionId!==r?e:{...e,pendingQuestions:{...e.pendingQuestions,[t.toolUseId]:{toolUseId:t.toolUseId,requestId:t.requestId,questions:t.questions}}};case"session:question:clear":{if(!r||t.sessionId!==r||!(t.toolUseId in e.pendingQuestions))return e;const{[t.toolUseId]:i,...s}=e.pendingQuestions;return{...e,pendingQuestions:s}}case"session:question:submitted":{if(!r||t.sessionId!==r)return e;const i=e.pendingQuestions[t.toolUseId];return i?{...e,pendingQuestions:{...e.pendingQuestions,[t.toolUseId]:{...i,submittedAnswers:t.answers}}}:e}case"session:rewound":return!r||t.sessionId!==r?e:{...e,pendingPermissions:[],status:"idle"};case"ready":{if(!r)return e;const i=t.runningSessions.find(o=>o.sessionId===r);if(i!=null&&i.freshSpawn)return{...Mc,sessionId:r};const s=(i==null?void 0:i.status)??"idle";return s===e.status?e:{...e,status:s}}case"daemon:disconnected":return{...e,pendingPermissions:[]};default:return e}}const rB="session/";function iB(e){return{sid:e.slice(rB.length)}}const sB=new Set(vN);function RN(e){return sB.has(e)}function Ab(e){return RN(e)?e:"idle"}function oB(e,t){return{start(n){const{sid:r}=iB(n);let i=!1,s=-1;const o=f=>{t(n,p=>IN(p??Mc,f,r))},a=async f=>{const p=f==="baseline"?-1:s;try{const m=await e.request("session:events",{sessionId:r,afterSeq:p});if(i)return;const v=m.events??[],y=m.latestSeq??-1;if(f==="baseline")o({type:"session:events",sessionId:r,events:v,latestSeq:y}),s=y;else{const x=m.bufferStartSeq??0,_=y<p||x>p+1;o({type:_?"session:events":"session:events:append",sessionId:r,events:v,latestSeq:y}),s=Math.max(s,y)}}catch{}},l=async()=>{try{const f=await e.request("info");if(i)return;o({type:"ready",runningSessions:(f.runningSessions??[]).map(p=>({sessionId:p.sessionId,freshSpawn:p.freshSpawn,status:Ab(p.status)}))})}catch{}},c=async()=>{try{await e.request("session:subscribe",{sessionId:r})}catch{}i||(await a(s<0?"baseline":"delta"),!i&&await l())},u=e.onFrame((f,p)=>{if(!i)if(f==="session:event"){const m=p;if(m.sessionId!==r)return;const v=m.event.seq;Re("session-events","push session:event",{sid:r,kind:m.event.kind,seq:v,lastSeqBefore:s}),o({type:"session:event",sessionId:m.sessionId,event:m.event}),typeof v=="number"&&v>s&&(s=v)}else if(f==="session:status"){const m=p;if(m.sessionId!==r)return;if(!RN(m.status)){Re("session-events","push session:status drop",{sid:r,status:m.status});return}Re("session-events","push session:status",{sid:r,status:m.status}),o({type:"session:status",sessionId:m.sessionId,status:m.status})}else if(f==="session:cleared"){if(p.sessionId!==r)return;Re("session-events","push session:cleared",{sid:r}),o({type:"session:change",sessionId:r}),s=-1}else if(f==="permission:request"){const m=p;if(m.sessionId!==r)return;o({type:"permission:request",sessionId:m.sessionId,requestId:m.requestId,tool:m.tool,input:m.input,...typeof m.toolUseId=="string"&&m.toolUseId?{toolUseId:m.toolUseId}:{}})}else if(f==="session:question"){const m=p;if(m.sessionId!==r)return;o({type:"session:question",sessionId:m.sessionId,toolUseId:m.toolUseId,requestId:m.requestId,questions:m.questions})}else if(f==="session:question:cleared"){const m=p;if(m.sessionId!==r)return;m.answers&&Object.keys(m.answers).length>0?o({type:"session:question:submitted",sessionId:m.sessionId,toolUseId:m.toolUseId,answers:m.answers}):o({type:"session:question:clear",sessionId:m.sessionId,toolUseId:m.toolUseId})}else if(f==="session:rewound"){const m=p;if(m.sessionId!==r)return;o({type:"session:rewound",sessionId:m.sessionId,userMessageId:m.userMessageId})}else f==="ready"&&o({type:"ready",runningSessions:(p.runningSessions??[]).map(v=>({sessionId:v.sessionId,freshSpawn:v.freshSpawn,status:Ab(v.status)}))})}),d=e.onConnect(()=>{c()});return e.isConnected&&c(),()=>{i=!0,u(),d(),e.request("session:unsubscribe",{sessionId:r}).catch(()=>{})}}}}const aB=new Set(["tunnel:ready","tunnel:exited","tunnel:unavailable"]);function lB(e,t){return{start(n){let r=!1;const i=async()=>{try{const a=await e.request("info",void 0);if(r)return;t(n,()=>a)}catch{}},s=e.onConnect(()=>{i()}),o=e.onFrame(a=>{aB.has(a)&&i()});return i(),()=>{r=!0,s(),o()}}}}function cB(){return{start(){return()=>{}}}}function uB(e,t){return{start(n){let r=!1;const i=async()=>{try{const o=await e.request("persona:list",{});if(r)return;t(n,()=>o.personas??[])}catch{}},s=e.onConnect(()=>{i()});return i(),()=>{r=!0,s()}}}}function dB(e){const t=JO(e),n=QO();let r=null;const i=(o,a)=>{r==null||r.setData(o,a)};n.register(/^capabilities\//,tB(t,i)),n.register(/^sessions$/,nB(t,i)),n.register(/^session\//,oB(t,i)),n.register(/^personas$/,uB(t,i)),n.register(/^persona-detail\//,cB()),n.register(/^daemon-info$/,lB(t,i));const s=ZO({onFirstObserver:o=>{o&&n.activate(o)},onLastObserver:o=>{o&&n.deactivate(o)}});return r=s,{cache:s,channel:t}}class qx{constructor(t){this.client=t}info(){return this.client.request("info")}attachmentSignUrl(t){return this.client.request("attachment.signUrl",t)}attachmentGroupAdd(t,n,r){return this.client.request("attachment.groupAdd",{sessionId:t,relPath:n,...r?{label:r}:{}})}attachmentGroupRemove(t,n){return this.client.request("attachment.groupRemove",{sessionId:t,relPath:n})}attachmentGroupList(t){return this.client.request("attachment.groupList",{sessionId:t})}sessionCreate(t){return this.client.request("session:create",t)}appBuilderListProjects(){return this.client.request("appBuilder:listProjects",{})}appBuilderGetProject(t){return this.client.request("appBuilder:getProject",{sessionId:t})}appBuilderUpdateProjectPort(t,n){return this.client.request("appBuilder:updateProjectPort",{name:t,newPort:n})}appBuilderStartDevServer(t,n){return this.client.request("appBuilder:startDevServer",{sessionId:t,...n!=null&&n.force?{force:!0}:{}})}appBuilderStopDevServer(t){return this.client.request("appBuilder:stopDevServer",{sessionId:t})}appBuilderPublish(t){return this.client.request("appBuilder:publish",{name:t})}appBuilderDismissPublishJob(t){return this.client.request("appBuilder:dismissPublishJob",{name:t})}sessionList(){return this.client.request("session:list")}sessionGet(t){return this.client.request("session:get",{sessionId:t})}sessionUpdate(t,n){return this.client.request("session:update",{sessionId:t,patch:n})}sessionDelete(t){return this.client.request("session:delete",{sessionId:t})}sessionSend(t,n){return this.client.request("session:send",{sessionId:t,text:n})}sessionStop(t){return this.client.request("session:stop",{sessionId:t})}sessionInterrupt(t){return this.client.request("session:interrupt",{sessionId:t})}sessionRewind(t){return this.client.request("session:rewind",t)}sessionRewindableMessageIds(t){return this.client.request("session:rewindable-message-ids",{sessionId:t})}sessionRewindDiff(t){return this.client.request("session:rewind-diff",t)}sessionNew(t){return this.client.request("session:new",{sessionId:t})}sessionFork(t){return this.client.request("session:fork",t)}sessionResume(t,n){return this.client.request("session:resume",{sessionId:t,toolSessionId:n})}sessionObserve(t){return this.client.request("session:observe",t)}sessionEvents(t,n){return this.client.request("session:events",{sessionId:t,afterSeq:n})}sessionSubscribe(t){return this.client.request("session:subscribe",{sessionId:t})}sessionUnsubscribe(t){return this.client.request("session:unsubscribe",{sessionId:t})}pinSession(t,n){return this.client.request("session:pin",{sessionId:t,pinned:n})}markSessionRead(t){return this.client.request("session:markRead",{sessionId:t})}reorderPins(t){return this.client.request("session:reorderPins",{orderedIds:t})}peerSessionUpsert(t){return this.client.request("peerSession:upsert",t)}peerSessionRemove(t){return this.client.request("peerSession:remove",{sessionId:t})}permissionRespond(t){return this.client.request("permission:respond",t)}answerQuestion(t){return this.client.request("session:answerQuestion",t)}cancelQuestion(t){return this.client.request("session:cancelQuestion",t)}historyProjects(){return this.client.request("history:projects")}historyList(t){return this.client.request("history:list",{projectPath:t})}historyRead(t){return this.client.request("history:read",t)}historySubagents(t){return this.client.request("history:subagents",t)}historySubagentRead(t){return this.client.request("history:subagent-read",t)}listRecentDirs(){return this.client.request("history:recentDirs",{})}getGitRoot(t){return this.client.request("git:root",{cwd:t})}getGitBranch(t){return this.client.request("git:branch",{cwd:t})}listGitBranches(t){return this.client.request("git:branches",{cwd:t})}personaCreate(t){return this.client.request("persona:create",t)}personaList(){return this.client.request("persona:list",{})}personaGet(t){return this.client.request("persona:get",{personaId:t})}personaUpdate(t,n){return this.client.request("persona:update",{personaId:t,patch:n})}personaDelete(t){return this.client.request("persona:delete",{personaId:t})}larkBotBindManual(t,n,r){return this.client.request("larkBot:bindManual",{personaId:t,appId:n,appSecret:r})}larkBotUnbind(t){return this.client.request("larkBot:unbind",{personaId:t})}larkBotStatus(t){return this.client.request("larkBot:status",{personaId:t})}visitorList(){return this.client.request("visitor:list",{})}workspaceList(t={}){return this.client.request("workspace:list",t)}workspaceRead(t){return this.client.request("workspace:read",t)}skillsList(t,n){return this.client.request("skills:list",{cwd:t,...n?{tool:n}:{}})}agentsList(t,n){return this.client.request("agents:list",{cwd:t,...n?{tool:n}:{}})}capabilitiesGet(t="claude"){return this.client.request("capabilities:get",{tool:t})}shiftList(){return this.client.request("shift:list")}}function hB(e){const[t,n]=g.useState(e.isOpen?{kind:"connected",url:""}:{kind:"connecting"});return g.useEffect(()=>{const r=e.on("ready",l=>{const c=l;n(u=>({kind:"connected",url:u.kind==="connected"?u.url:"",mode:u.kind==="connected"?u.mode:void 0,daemonVersion:c.version,protocolVersion:c.protocolVersion,daemonSource:c.daemonSource,globalCliVersion:c.globalCliVersion}))}),i=e.on("daemon:connected",l=>{const c=l;n(u=>({kind:"connected",url:c.url,mode:c.mode,daemonVersion:u.kind==="connected"?u.daemonVersion:void 0,protocolVersion:u.kind==="connected"?u.protocolVersion:void 0,daemonSource:u.kind==="connected"?u.daemonSource:void 0,globalCliVersion:u.kind==="connected"?u.globalCliVersion:void 0}))}),s=e.on("daemon:disconnected",l=>{const c=(l==null?void 0:l.reason)??"";/auth failed|auth timeout|auth required|auth handshake timeout/i.test(c)?n({kind:"auth-failed",reason:c}):n({kind:"disconnected",reason:c})}),o=e.on("daemon:reconnecting",l=>{const c=l;n({kind:"reconnecting",attempt:c.attempt,nextDelayMs:c.nextDelayMs,scheduledAt:c.scheduledAt??Date.now()})}),a=e.on("daemon:version-mismatch",l=>{const c=l;n({kind:"version-mismatch",daemonProtocol:c.daemonProtocol,supportedProtocol:c.supportedProtocol})});return()=>{r(),i(),s(),o(),a()}},[e]),t}function fB(e){const t=Co(),n=si(e.kind==="connected"?"sessions":""),r=g.useCallback(async()=>{t.setData("sessions",i=>i??[])},[t]);return{sessions:n??[],loading:!1,loaded:n!==void 0,error:null,refresh:r}}function Za(){const e=Bi();return g.useMemo(()=>new qx(e),[e])}function MN(e){return{personaId:e.personaId,label:e.label,model:e.model,tool:e.tool,iconKey:e.iconKey,public:e.public,createdAt:e.createdAt,updatedAt:e.updatedAt}}function AN(){const e=Co(),t=Za(),n=si("personas")??[],r=g.useMemo(()=>n.map(s=>MN(s)),[n]),i=g.useCallback(async()=>{const s=await t.personaList();e.setData("personas",()=>s.personas??[])},[t,e]);return{personas:r,raw:n,loaded:si("personas")!==void 0,refresh:i}}function jN(e){const{raw:t}=AN(),n=Co(),r=Za(),i=e?t.find(a=>a.personaId===e)??null:null,s=i?MN(i):null,o=g.useCallback(async()=>{if(!e)return;const a=await r.personaList();n.setData("personas",()=>a.personas??[])},[e,r,n]);return{persona:s,raw:i,loaded:!!s,refresh:o}}function pB(e){const t=Za(),n=Co(),r=e?`persona-detail/${e}`:"",i=si(r),s=g.useCallback(async()=>{const o={personality:"",skills:[],plugins:[],sandboxSettings:null};if(!e)return o;const a=await t.personaGet(e);let l;if("persona"in a&&a.persona===null)l=o;else{const c=a;l={personality:c.personality??"",skills:c.skills??[],plugins:c.plugins??[],sandboxSettings:c.sandboxSettings??null}}return n.setData(r,()=>l),l},[t,n,e,r]);return g.useEffect(()=>{e&&s()},[e,s]),{personality:(i==null?void 0:i.personality)??"",skills:(i==null?void 0:i.skills)??[],plugins:(i==null?void 0:i.plugins)??[],sandboxSettings:(i==null?void 0:i.sandboxSettings)??null,loaded:i!==void 0,refresh:s}}function DN(){const e=Co(),t=Za();return g.useCallback(async()=>{const n=await t.personaList();e.setData("personas",()=>n.personas??[])},[e,t])}function mB(){const e=Za(),t=DN();return g.useCallback(async(n,r)=>{const i=await e.personaUpdate(n,r);return await t(),i},[e,t])}function gB(){const e=Za(),t=DN();return g.useCallback(async n=>{await e.personaDelete(n),await t()},[e,t])}const jb="clawd:sidebar:tree-collapsed";function vB(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function xB(e){const t=vB(e);if(!Array.isArray(t))return new Set;const n=new Set;for(const r of t)typeof r=="string"&&n.add(r);return n}function _B(){const e=Ix(),[t,n]=g.useState(()=>new Set),r=g.useRef(t);r.current=t,g.useEffect(()=>{let l=!1;return(async()=>{try{const c=await e.kv.get(jb);if(l)return;n(xB(c))}catch{}})(),()=>{l=!0}},[e]);const i=g.useCallback(l=>{e.kv.set(jb,[...l]).catch(()=>{})},[e]),s=g.useCallback(l=>r.current.has(l),[]),o=g.useCallback(l=>{n(c=>{const u=new Set(c);return u.has(l)?u.delete(l):u.add(l),i(u),u})},[i]),a=g.useCallback(l=>{n(c=>{let u=!1;const d=new Set;for(const f of c)l.has(f)?d.add(f):u=!0;return u?(i(d),d):c})},[i]);return{isCollapsed:s,toggle:o,prune:a}}const Kx=g.createContext(null);function yB(){const e=g.useContext(Kx);if(!e)throw new Error("SessionTreeCollapsedContext.Provider missing — wrap SessionTreeNode tree with <SessionTreeCollapsedContext.Provider value={useSessionTreeCollapsed()}>");return e}/**
95
+ `,boxShadowTabsOverflowLeft:"inset 10px 0 8px -8px rgba(0, 0, 0, 0.08)",boxShadowTabsOverflowRight:"inset -10px 0 8px -8px rgba(0, 0, 0, 0.08)",boxShadowTabsOverflowTop:"inset 0 10px 8px -8px rgba(0, 0, 0, 0.08)",boxShadowTabsOverflowBottom:"inset 0 -10px 8px -8px rgba(0, 0, 0, 0.08)"}),r)}var ob=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};const cD={lineHeight:!0,lineHeightSM:!0,lineHeightLG:!0,lineHeightHeading1:!0,lineHeightHeading2:!0,lineHeightHeading3:!0,lineHeightHeading4:!0,lineHeightHeading5:!0,opacityLoading:!0,fontWeightStrong:!0,zIndexPopupBase:!0,zIndexBase:!0,opacityImage:!0},uD={motionBase:!0,motionUnit:!0},dD={screenXS:!0,screenXSMin:!0,screenXSMax:!0,screenSM:!0,screenSMMin:!0,screenSMMax:!0,screenMD:!0,screenMDMin:!0,screenMDMax:!0,screenLG:!0,screenLGMin:!0,screenLGMax:!0,screenXL:!0,screenXLMin:!0,screenXLMax:!0,screenXXL:!0,screenXXLMin:!0},GE=(e,t,n)=>{const r=n.getDerivativeToken(e),{override:i}=t,s=ob(t,["override"]);let o=Object.assign(Object.assign({},r),{override:i});return o=KE(o),s&&Object.entries(s).forEach(([a,l])=>{const{theme:c}=l,u=ob(l,["theme"]);let d=u;c&&(d=GE(Object.assign(Object.assign({},o),u),{override:u},c)),o[a]=d}),o};function XE(){const{token:e,hashed:t,theme:n,override:r,cssVar:i}=st.useContext(VE),s=`${aD}-${t||""}`,o=n||WE,[a,l,c]=Z3(o,[Tc,e],{salt:s,override:r,getComputedToken:GE,formatToken:KE,cssVar:i&&{prefix:i.prefix,key:i.key,unitless:cD,ignore:uD,preserve:dD}});return[o,c,t?l:"",a,i]}const hD=()=>({display:"inline-flex",alignItems:"center",color:"inherit",fontStyle:"normal",lineHeight:0,textAlign:"center",textTransform:"none",verticalAlign:"-0.125em",textRendering:"optimizeLegibility","-webkit-font-smoothing":"antialiased","-moz-osx-font-smoothing":"grayscale","> *":{lineHeight:1},svg:{display:"inline-block"}}),fD=e=>({[`.${e}`]:Object.assign(Object.assign({},hD()),{[`.${e} .${e}-icon`]:{display:"block"}})}),pD=(e,t)=>{const[n,r]=XE();return C4({token:r,hashId:"",path:["ant-design-icons",e],nonce:()=>t==null?void 0:t.nonce,layer:{name:"antd"}},()=>fD(e))},mD=Object.assign({},Ha),{useId:ab}=mD,gD=()=>"",vD=typeof ab>"u"?gD:ab;function xD(e,t,n){var r;const i=e||{},s=i.inherit===!1||!t?Object.assign(Object.assign({},bh),{hashed:(r=t==null?void 0:t.hashed)!==null&&r!==void 0?r:bh.hashed,cssVar:t==null?void 0:t.cssVar}):t,o=vD();return fE(()=>{var a,l;if(!e)return t;const c=Object.assign({},s.components);Object.keys(e.components||{}).forEach(f=>{c[f]=Object.assign(Object.assign({},c[f]),e.components[f])});const u=`css-var-${o.replace(/:/g,"")}`,d=((a=i.cssVar)!==null&&a!==void 0?a:s.cssVar)&&Object.assign(Object.assign(Object.assign({prefix:n==null?void 0:n.prefixCls},typeof s.cssVar=="object"?s.cssVar:{}),typeof i.cssVar=="object"?i.cssVar:{}),{key:typeof i.cssVar=="object"&&((l=i.cssVar)===null||l===void 0?void 0:l.key)||u});return Object.assign(Object.assign(Object.assign({},s),i),{token:Object.assign(Object.assign({},s.token),i.token),components:c,cssVar:d})},[i,s],(a,l)=>a.some((c,u)=>{const d=l[u];return!C3(c,d,!0)}))}var _D=["children"],YE=g.createContext({});function yD(e){var t=e.children,n=Hg(e,_D);return g.createElement(YE.Provider,{value:n},t)}var bD=function(e){mE(n,e);var t=vE(n);function n(){return Va(this,n),t.apply(this,arguments)}return qa(n,[{key:"render",value:function(){return this.props.children}}]),n}(g.Component);function wD(e){var t=g.useReducer(function(a){return a+1},0),n=Qe(t,2),r=n[1],i=g.useRef(e),s=uv(function(){return i.current}),o=uv(function(a){i.current=typeof a=="function"?a(i.current):a,r()});return[s,o]}var Ji="none",Uu="appear",Wu="enter",Vu="leave",lb="none",Tr="prepare",la="start",ca="active",$x="end",ZE="prepared";function cb(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n["Webkit".concat(e)]="webkit".concat(t),n["Moz".concat(e)]="moz".concat(t),n["ms".concat(e)]="MS".concat(t),n["O".concat(e)]="o".concat(t.toLowerCase()),n}function SD(e,t){var n={animationend:cb("Animation","AnimationEnd"),transitionend:cb("Transition","TransitionEnd")};return e&&("AnimationEvent"in t||delete n.animationend.animation,"TransitionEvent"in t||delete n.transitionend.transition),n}var kD=SD(Oi(),typeof window<"u"?window:{}),QE={};if(Oi()){var CD=document.createElement("div");QE=CD.style}var qu={};function JE(e){if(qu[e])return qu[e];var t=kD[e];if(t)for(var n=Object.keys(t),r=n.length,i=0;i<r;i+=1){var s=n[i];if(Object.prototype.hasOwnProperty.call(t,s)&&s in QE)return qu[e]=t[s],qu[e]}return""}var eN=JE("animationend"),tN=JE("transitionend"),nN=!!(eN&&tN),ub=eN||"animationend",db=tN||"transitionend";function hb(e,t){if(!e)return null;if(Ct(e)==="object"){var n=t.replace(/-\w/g,function(r){return r[1].toUpperCase()});return e[n]}return"".concat(e,"-").concat(t)}const ED=function(e){var t=g.useRef();function n(i){i&&(i.removeEventListener(db,e),i.removeEventListener(ub,e))}function r(i){t.current&&t.current!==i&&n(t.current),i&&i!==t.current&&(i.addEventListener(db,e),i.addEventListener(ub,e),t.current=i)}return g.useEffect(function(){return function(){n(t.current)}},[]),[r,n]};var rN=Oi()?g.useLayoutEffect:g.useEffect;const ND=function(){var e=g.useRef(null);function t(){$g.cancel(e.current)}function n(r){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2;t();var s=$g(function(){i<=1?r({isCanceled:function(){return s!==e.current}}):n(r,i-1)});e.current=s}return g.useEffect(function(){return function(){t()}},[]),[n,t]};var TD=[Tr,la,ca,$x],PD=[Tr,ZE],iN=!1,ID=!0;function sN(e){return e===ca||e===$x}const RD=function(e,t,n){var r=dv(lb),i=Qe(r,2),s=i[0],o=i[1],a=ND(),l=Qe(a,2),c=l[0],u=l[1];function d(){o(Tr,!0)}var f=t?PD:TD;return rN(function(){if(s!==lb&&s!==$x){var p=f.indexOf(s),m=f[p+1],v=n(s);v===iN?o(m,!0):m&&c(function(y){function x(){y.isCanceled()||o(m,!0)}v===!0?x():Promise.resolve(v).then(x)})}},[e,s]),g.useEffect(function(){return function(){u()}},[]),[d,s]};function MD(e,t,n,r){var i=r.motionEnter,s=i===void 0?!0:i,o=r.motionAppear,a=o===void 0?!0:o,l=r.motionLeave,c=l===void 0?!0:l,u=r.motionDeadline,d=r.motionLeaveImmediately,f=r.onAppearPrepare,p=r.onEnterPrepare,m=r.onLeavePrepare,v=r.onAppearStart,y=r.onEnterStart,x=r.onLeaveStart,_=r.onAppearActive,b=r.onEnterActive,w=r.onLeaveActive,k=r.onAppearEnd,C=r.onEnterEnd,N=r.onLeaveEnd,T=r.onVisibleChanged,L=dv(),P=Qe(L,2),O=P[0],I=P[1],R=wD(Ji),D=Qe(R,2),z=D[0],$=D[1],F=dv(null),j=Qe(F,2),B=j[0],E=j[1],H=z(),q=g.useRef(!1),M=g.useRef(null);function re(){return n()}var oe=g.useRef(!1);function V(){$(Ji),E(null,!0)}var pe=uv(function(Ue){var nt=z();if(nt!==Ji){var mt=re();if(!(Ue&&!Ue.deadline&&Ue.target!==mt)){var Xt=oe.current,pn;nt===Uu&&Xt?pn=k==null?void 0:k(mt,Ue):nt===Wu&&Xt?pn=C==null?void 0:C(mt,Ue):nt===Vu&&Xt&&(pn=N==null?void 0:N(mt,Ue)),Xt&&pn!==!1&&V()}}}),Oe=ED(pe),ie=Qe(Oe,1),Ae=ie[0],Fe=function(nt){switch(nt){case Uu:return we(we(we({},Tr,f),la,v),ca,_);case Wu:return we(we(we({},Tr,p),la,y),ca,b);case Vu:return we(we(we({},Tr,m),la,x),ca,w);default:return{}}},We=g.useMemo(function(){return Fe(H)},[H]),ge=RD(H,!e,function(Ue){if(Ue===Tr){var nt=We[Tr];return nt?nt(re()):iN}if(wt in We){var mt;E(((mt=We[wt])===null||mt===void 0?void 0:mt.call(We,re(),null))||null)}return wt===ca&&H!==Ji&&(Ae(re()),u>0&&(clearTimeout(M.current),M.current=setTimeout(function(){pe({deadline:!0})},u))),wt===ZE&&V(),ID}),qe=Qe(ge,2),Gt=qe[0],wt=qe[1],Rt=sN(wt);oe.current=Rt;var ln=g.useRef(null);rN(function(){if(!(q.current&&ln.current===t)){I(t);var Ue=q.current;q.current=!0;var nt;!Ue&&t&&a&&(nt=Uu),Ue&&t&&s&&(nt=Wu),(Ue&&!t&&c||!Ue&&d&&!t&&c)&&(nt=Vu);var mt=Fe(nt);nt&&(e||mt[Tr])?($(nt),Gt()):$(Ji),ln.current=t}},[t]),g.useEffect(function(){(H===Uu&&!a||H===Wu&&!s||H===Vu&&!c)&&$(Ji)},[a,s,c]),g.useEffect(function(){return function(){q.current=!1,clearTimeout(M.current)}},[]);var Bt=g.useRef(!1);g.useEffect(function(){O&&(Bt.current=!0),O!==void 0&&H===Ji&&((Bt.current||O)&&(T==null||T(O)),Bt.current=!0)},[O,H]);var at=B;return We[Tr]&&wt===la&&(at=Be({transition:"none"},at)),[H,wt,at,O??t]}function AD(e){var t=e;Ct(e)==="object"&&(t=e.transitionSupport);function n(i,s){return!!(i.motionName&&t&&s!==!1)}var r=g.forwardRef(function(i,s){var o=i.visible,a=o===void 0?!0:o,l=i.removeOnLeave,c=l===void 0?!0:l,u=i.forceRender,d=i.children,f=i.motionName,p=i.leavedClassName,m=i.eventProps,v=g.useContext(YE),y=v.motion,x=n(i,y),_=g.useRef(),b=g.useRef();function w(){try{return _.current instanceof HTMLElement?_.current:l3(b.current)}catch{return null}}var k=MD(x,a,w,i),C=Qe(k,4),N=C[0],T=C[1],L=C[2],P=C[3],O=g.useRef(P);P&&(O.current=!0);var I=g.useCallback(function(j){_.current=j,h3(s,j)},[s]),R,D=Be(Be({},m),{},{visible:a});if(!d)R=null;else if(N===Ji)P?R=d(Be({},D),I):!c&&O.current&&p?R=d(Be(Be({},D),{},{className:p}),I):u||!c&&!p?R=d(Be(Be({},D),{},{style:{display:"none"}}),I):R=null;else{var z;T===Tr?z="prepare":sN(T)?z="active":T===la&&(z="start");var $=hb(f,"".concat(N,"-").concat(z));R=d(Be(Be({},D),{},{className:Y5(hb(f,N),we(we({},$,$&&z),f,typeof f=="string")),style:L}),I)}if(g.isValidElement(R)&&f3(R)){var F=p3(R);F||(R=g.cloneElement(R,{ref:I}))}return g.createElement(bD,{ref:b},R)});return r.displayName="CSSMotion",r}const jD=AD(nN);var hv="add",fv="keep",pv="remove",qp="removed";function DD(e){var t;return e&&Ct(e)==="object"&&"key"in e?t=e:t={key:e},Be(Be({},t),{},{key:String(t.key)})}function mv(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return e.map(DD)}function LD(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],n=[],r=0,i=t.length,s=mv(e),o=mv(t);s.forEach(function(c){for(var u=!1,d=r;d<i;d+=1){var f=o[d];if(f.key===c.key){r<d&&(n=n.concat(o.slice(r,d).map(function(p){return Be(Be({},p),{},{status:hv})})),r=d),n.push(Be(Be({},f),{},{status:fv})),r+=1,u=!0;break}}u||n.push(Be(Be({},c),{},{status:pv}))}),r<i&&(n=n.concat(o.slice(r).map(function(c){return Be(Be({},c),{},{status:hv})})));var a={};n.forEach(function(c){var u=c.key;a[u]=(a[u]||0)+1});var l=Object.keys(a).filter(function(c){return a[c]>1});return l.forEach(function(c){n=n.filter(function(u){var d=u.key,f=u.status;return d!==c||f!==pv}),n.forEach(function(u){u.key===c&&(u.status=fv)})}),n}var OD=["component","children","onVisibleChanged","onAllRemoved"],BD=["status"],zD=["eventProps","visible","children","motionName","motionAppear","motionEnter","motionLeave","motionLeaveImmediately","motionDeadline","removeOnLeave","leavedClassName","onAppearPrepare","onAppearStart","onAppearActive","onAppearEnd","onEnterStart","onEnterActive","onEnterEnd","onLeaveStart","onLeaveActive","onLeaveEnd"];function $D(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:jD,n=function(r){mE(s,r);var i=vE(s);function s(){var o;Va(this,s);for(var a=arguments.length,l=new Array(a),c=0;c<a;c++)l[c]=arguments[c];return o=i.call.apply(i,[this].concat(l)),we(Bg(o),"state",{keyEntities:[]}),we(Bg(o),"removeKey",function(u){o.setState(function(d){var f=d.keyEntities.map(function(p){return p.key!==u?p:Be(Be({},p),{},{status:qp})});return{keyEntities:f}},function(){var d=o.state.keyEntities,f=d.filter(function(p){var m=p.status;return m!==qp}).length;f===0&&o.props.onAllRemoved&&o.props.onAllRemoved()})}),o}return qa(s,[{key:"render",value:function(){var a=this,l=this.state.keyEntities,c=this.props,u=c.component,d=c.children,f=c.onVisibleChanged;c.onAllRemoved;var p=Hg(c,OD),m=u||g.Fragment,v={};return zD.forEach(function(y){v[y]=p[y],delete p[y]}),delete p.keys,g.createElement(m,p,l.map(function(y,x){var _=y.status,b=Hg(y,BD),w=_===hv||_===fv;return g.createElement(t,xh({},v,{key:b.key,visible:w,eventProps:b,onVisibleChanged:function(C){f==null||f(C,{key:b.key}),C||a.removeKey(b.key)}}),function(k,C){return d(Be(Be({},k),{},{index:x}),C)})}))}}],[{key:"getDerivedStateFromProps",value:function(a,l){var c=a.keys,u=l.keyEntities,d=mv(c),f=LD(u,d);return{keyEntities:f.filter(function(p){var m=u.find(function(v){var y=v.key;return p.key===y});return!(m&&m.status===qp&&p.status===pv)})}}}]),s}(g.Component);return we(n,"defaultProps",{component:"div"}),n}$D(nN);const fb=g.createContext(!0);function FD(e){const t=g.useContext(fb),{children:n}=e,[,r]=XE(),{motion:i}=r,s=g.useRef(!1);return s.current||(s.current=t!==i),s.current?g.createElement(fb.Provider,{value:i},g.createElement(yD,{motion:i},n)):n}const HD=()=>null;var UD=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};const WD=["getTargetContainer","getPopupContainer","renderEmpty","input","pagination","form","select","button"];let oN;function VD(){return oN||lv}function qD(e){return Object.keys(e).some(t=>t.endsWith("Color"))}const KD=e=>{const{prefixCls:t,iconPrefixCls:n,theme:r,holderRender:i}=e;t!==void 0&&(oN=t),r&&qD(r)&&tD(VD(),r)},GD=e=>{const{children:t,csp:n,autoInsertSpaceInButton:r,alert:i,anchor:s,form:o,locale:a,componentSize:l,direction:c,space:u,splitter:d,virtual:f,dropdownMatchSelectWidth:p,popupMatchSelectWidth:m,popupOverflow:v,legacyLocale:y,parentContext:x,iconPrefixCls:_,theme:b,componentDisabled:w,segmented:k,statistic:C,spin:N,calendar:T,carousel:L,cascader:P,collapse:O,typography:I,checkbox:R,descriptions:D,divider:z,drawer:$,skeleton:F,steps:j,image:B,layout:E,list:H,mentions:q,modal:M,progress:re,result:oe,slider:V,breadcrumb:pe,menu:Oe,pagination:ie,input:Ae,textArea:Fe,empty:We,badge:ge,radio:qe,rate:Gt,switch:wt,transfer:Rt,avatar:ln,message:Bt,tag:at,table:Ue,card:nt,tabs:mt,timeline:Xt,timePicker:pn,upload:U,notification:Q,tree:ve,colorPicker:Se,datePicker:J,rangePicker:Ye,flex:Yt,wave:Zt,dropdown:ue,warning:Te,tour:Je,tooltip:Dn,popover:Qt,popconfirm:sl,floatButton:jo,floatButtonGroup:_u,variant:yu,inputNumber:cp,treeSelect:up}=e,bu=g.useCallback((Tt,$t)=>{const{prefixCls:or}=e;if($t)return $t;const Ln=or||x.getPrefixCls("");return Tt?`${Ln}-${Tt}`:Ln},[x.getPrefixCls,e.prefixCls]),Do=_||x.iconPrefixCls||qE,Lo=n||x.csp;pD(Do,Lo);const ol=xD(b,x.theme,{prefixCls:bu("")}),al={csp:Lo,autoInsertSpaceInButton:r,alert:i,anchor:s,locale:a||y,direction:c,space:u,splitter:d,virtual:f,popupMatchSelectWidth:m??p,popupOverflow:v,getPrefixCls:bu,iconPrefixCls:Do,theme:ol,segmented:k,statistic:C,spin:N,calendar:T,carousel:L,cascader:P,collapse:O,typography:I,checkbox:R,descriptions:D,divider:z,drawer:$,skeleton:F,steps:j,image:B,input:Ae,textArea:Fe,layout:E,list:H,mentions:q,modal:M,progress:re,result:oe,slider:V,breadcrumb:pe,menu:Oe,pagination:ie,empty:We,badge:ge,radio:qe,rate:Gt,switch:wt,transfer:Rt,avatar:ln,message:Bt,tag:at,table:Ue,card:nt,tabs:mt,timeline:Xt,timePicker:pn,upload:U,notification:Q,tree:ve,colorPicker:Se,datePicker:J,rangePicker:Ye,flex:Yt,wave:Zt,dropdown:ue,warning:Te,tour:Je,tooltip:Dn,popover:Qt,popconfirm:sl,floatButton:jo,floatButtonGroup:_u,variant:yu,inputNumber:cp,treeSelect:up},Wi=Object.assign({},x);Object.keys(al).forEach(Tt=>{al[Tt]!==void 0&&(Wi[Tt]=al[Tt])}),WD.forEach(Tt=>{const $t=e[Tt];$t&&(Wi[Tt]=$t)}),typeof r<"u"&&(Wi.button=Object.assign({autoInsertSpace:r},Wi.button));const Vi=fE(()=>Wi,Wi,(Tt,$t)=>{const or=Object.keys(Tt),Ln=Object.keys($t);return or.length!==Ln.length||or.some(Z=>Tt[Z]!==$t[Z])}),{layer:ll}=g.useContext(Tf),wu=g.useMemo(()=>({prefixCls:Do,csp:Lo,layer:ll?"antd":void 0}),[Do,Lo,ll]);let zt=g.createElement(g.Fragment,null,g.createElement(HD,{dropdownMatchSelectWidth:p}),t);const cl=g.useMemo(()=>{var Tt,$t,or,Ln;return A4(((Tt=Rf.Form)===null||Tt===void 0?void 0:Tt.defaultValidateMessages)||{},((or=($t=Vi.locale)===null||$t===void 0?void 0:$t.Form)===null||or===void 0?void 0:or.defaultValidateMessages)||{},((Ln=Vi.form)===null||Ln===void 0?void 0:Ln.validateMessages)||{},(o==null?void 0:o.validateMessages)||{})},[Vi,o==null?void 0:o.validateMessages]);Object.keys(cl).length>0&&(zt=g.createElement(D4.Provider,{value:cl},zt)),a&&(zt=g.createElement(B4,{locale:a,_ANT_MARK__:O4},zt)),zt=g.createElement(P4.Provider,{value:wu},zt),l&&(zt=g.createElement(rD,{size:l},zt)),zt=g.createElement(FD,null,zt);const ul=g.useMemo(()=>{const Tt=ol||{},{algorithm:$t,token:or,components:Ln,cssVar:Z}=Tt,xe=UD(Tt,["algorithm","token","components","cssVar"]),ye=$t&&(!Array.isArray($t)||$t.length>0)?Wg($t):WE,Ze={};Object.entries(Ln||{}).forEach(([mA,gA])=>{const fi=Object.assign({},gA);"algorithm"in fi&&(fi.algorithm===!0?fi.theme=ye:(Array.isArray(fi.algorithm)||typeof fi.algorithm=="function")&&(fi.theme=Wg(fi.algorithm)),delete fi.algorithm),Ze[mA]=fi});const hi=Object.assign(Object.assign({},Tc),or);return Object.assign(Object.assign({},xe),{theme:ye,token:hi,components:Ze,override:Object.assign({override:hi},Ze),cssVar:Z})},[ol]);return b&&(zt=g.createElement(VE.Provider,{value:ul},zt)),Vi.warning&&(zt=g.createElement(j4.Provider,{value:Vi.warning},zt)),w!==void 0&&(zt=g.createElement(nD,{disabled:w},zt)),g.createElement(Mf.Provider,{value:Vi},zt)},Ga=e=>{const t=g.useContext(Mf),n=g.useContext($E);return g.createElement(GD,Object.assign({parentContext:t,legacyLocale:n},e))};Ga.ConfigContext=Mf;Ga.SizeContext=Pc;Ga.config=KD;Ga.useConfig=iD;Object.defineProperty(Ga,"SizeContext",{get:()=>Pc});const lr=(e,t)=>new _t(e).setA(t).toRgbString(),zo=(e,t)=>new _t(e).lighten(t).toHexString(),XD=e=>{const t=Aa(e,{theme:"dark"});return{1:t[0],2:t[1],3:t[2],4:t[3],5:t[6],6:t[5],7:t[4],8:t[6],9:t[5],10:t[4]}},YD=(e,t)=>{const n=e||"#000",r=t||"#fff";return{colorBgBase:n,colorTextBase:r,colorText:lr(r,.85),colorTextSecondary:lr(r,.65),colorTextTertiary:lr(r,.45),colorTextQuaternary:lr(r,.25),colorFill:lr(r,.18),colorFillSecondary:lr(r,.12),colorFillTertiary:lr(r,.08),colorFillQuaternary:lr(r,.04),colorBgSolid:lr(r,.95),colorBgSolidHover:lr(r,1),colorBgSolidActive:lr(r,.9),colorBgElevated:zo(n,12),colorBgContainer:zo(n,8),colorBgLayout:zo(n,0),colorBgSpotlight:zo(n,26),colorBgBlur:lr(r,.04),colorBorder:zo(n,26),colorBorderSecondary:zo(n,19)}},ZD=(e,t)=>{const n=Object.keys(Bx).map(s=>{const o=Aa(e[s],{theme:"dark"});return Array.from({length:10},()=>1).reduce((a,l,c)=>(a[`${s}-${c+1}`]=o[c],a[`${s}${c+1}`]=o[c],a),{})}).reduce((s,o)=>(s=Object.assign(Object.assign({},s),o),s),{}),r=t??zx(e),i=UE(e,{generateColorPalettes:XD,generateNeutralColorPalettes:YD});return Object.assign(Object.assign(Object.assign(Object.assign({},r),n),i),{colorPrimaryBg:i.colorPrimaryBorder,colorPrimaryBgHover:i.colorPrimaryBorderHover})},pb={defaultSeed:bh.token,defaultAlgorithm:zx,darkAlgorithm:ZD};function mb({children:e}){const t=Ix(),[n,r]=g.useState(t.theme);return g.useEffect(()=>t.onThemeChange(r),[t]),h.jsx(Ga,{theme:{algorithm:n.mode==="dark"?pb.darkAlgorithm:pb.defaultAlgorithm,token:{colorPrimary:n.colorPrimary,colorBgContainer:n.colorBgContainer,colorText:n.colorText,colorBorder:n.colorBorder}},children:e})}var Ke;(function(e){e.assertEqual=i=>{};function t(i){}e.assertIs=t;function n(i){throw new Error}e.assertNever=n,e.arrayToEnum=i=>{const s={};for(const o of i)s[o]=o;return s},e.getValidEnumValues=i=>{const s=e.objectKeys(i).filter(a=>typeof i[i[a]]!="number"),o={};for(const a of s)o[a]=i[a];return e.objectValues(o)},e.objectValues=i=>e.objectKeys(i).map(function(s){return i[s]}),e.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{const s=[];for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&s.push(o);return s},e.find=(i,s)=>{for(const o of i)if(s(o))return o},e.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,s=" | "){return i.map(o=>typeof o=="string"?`'${o}'`:o).join(s)}e.joinValues=r,e.jsonStringifyReplacer=(i,s)=>typeof s=="bigint"?s.toString():s})(Ke||(Ke={}));var gb;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(gb||(gb={}));const ce=Ke.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),rs=e=>{switch(typeof e){case"undefined":return ce.undefined;case"string":return ce.string;case"number":return Number.isNaN(e)?ce.nan:ce.number;case"boolean":return ce.boolean;case"function":return ce.function;case"bigint":return ce.bigint;case"symbol":return ce.symbol;case"object":return Array.isArray(e)?ce.array:e===null?ce.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?ce.promise:typeof Map<"u"&&e instanceof Map?ce.map:typeof Set<"u"&&e instanceof Set?ce.set:typeof Date<"u"&&e instanceof Date?ce.date:ce.object;default:return ce.unknown}},K=Ke.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class Ri extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=t}format(t){const n=t||function(s){return s.message},r={_errors:[]},i=s=>{for(const o of s.issues)if(o.code==="invalid_union")o.unionErrors.map(i);else if(o.code==="invalid_return_type")i(o.returnTypeError);else if(o.code==="invalid_arguments")i(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let a=r,l=0;for(;l<o.path.length;){const c=o.path[l];l===o.path.length-1?(a[c]=a[c]||{_errors:[]},a[c]._errors.push(n(o))):a[c]=a[c]||{_errors:[]},a=a[c],l++}}};return i(this),r}static assert(t){if(!(t instanceof Ri))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Ke.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=n=>n.message){const n={},r=[];for(const i of this.issues)if(i.path.length>0){const s=i.path[0];n[s]=n[s]||[],n[s].push(t(i))}else r.push(t(i));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}Ri.create=e=>new Ri(e);const gv=(e,t)=>{let n;switch(e.code){case K.invalid_type:e.received===ce.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case K.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Ke.jsonStringifyReplacer)}`;break;case K.unrecognized_keys:n=`Unrecognized key(s) in object: ${Ke.joinValues(e.keys,", ")}`;break;case K.invalid_union:n="Invalid input";break;case K.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Ke.joinValues(e.options)}`;break;case K.invalid_enum_value:n=`Invalid enum value. Expected ${Ke.joinValues(e.options)}, received '${e.received}'`;break;case K.invalid_arguments:n="Invalid function arguments";break;case K.invalid_return_type:n="Invalid function return type";break;case K.invalid_date:n="Invalid date";break;case K.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:Ke.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case K.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="bigint"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case K.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case K.custom:n="Invalid input";break;case K.invalid_intersection_types:n="Intersection results could not be merged";break;case K.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case K.not_finite:n="Number must be finite";break;default:n=t.defaultError,Ke.assertNever(e)}return{message:n}};let QD=gv;function JD(){return QD}const eL=e=>{const{data:t,path:n,errorMaps:r,issueData:i}=e,s=[...n,...i.path||[]],o={...i,path:s};if(i.message!==void 0)return{...i,path:s,message:i.message};let a="";const l=r.filter(c=>!!c).slice().reverse();for(const c of l)a=c(o,{data:t,defaultError:a}).message;return{...i,path:s,message:a}};function se(e,t){const n=JD(),r=eL({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===gv?void 0:gv].filter(i=>!!i)});e.common.issues.push(r)}class Tn{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,n){const r=[];for(const i of n){if(i.status==="aborted")return Ce;i.status==="dirty"&&t.dirty(),r.push(i.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const i of n){const s=await i.key,o=await i.value;r.push({key:s,value:o})}return Tn.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const i of n){const{key:s,value:o}=i;if(s.status==="aborted"||o.status==="aborted")return Ce;s.status==="dirty"&&t.dirty(),o.status==="dirty"&&t.dirty(),s.value!=="__proto__"&&(typeof o.value<"u"||i.alwaysSet)&&(r[s.value]=o.value)}return{status:t.value,value:r}}}const Ce=Object.freeze({status:"aborted"}),Ll=e=>({status:"dirty",value:e}),Sr=e=>({status:"valid",value:e}),vb=e=>e.status==="aborted",xb=e=>e.status==="dirty",ja=e=>e.status==="valid",wh=e=>typeof Promise<"u"&&e instanceof Promise;var me;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(me||(me={}));class ii{constructor(t,n,r,i){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const _b=(e,t)=>{if(ja(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new Ri(e.common.issues);return this._error=n,this._error}}};function Me(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:i}=e;if(t&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:i}:{errorMap:(o,a)=>{const{message:l}=e;return o.code==="invalid_enum_value"?{message:l??a.defaultError}:typeof a.data>"u"?{message:l??r??a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:l??n??a.defaultError}},description:i}}class He{get description(){return this._def.description}_getType(t){return rs(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:rs(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Tn,ctx:{common:t.parent.common,data:t.data,parsedType:rs(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(wh(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(t){const n=this._parse(t);return Promise.resolve(n)}parse(t,n){const r=this.safeParse(t,n);if(r.success)return r.data;throw r.error}safeParse(t,n){const r={common:{issues:[],async:(n==null?void 0:n.async)??!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:rs(t)},i=this._parseSync({data:t,path:r.path,parent:r});return _b(r,i)}"~validate"(t){var r,i;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:rs(t)};if(!this["~standard"].async)try{const s=this._parseSync({data:t,path:[],parent:n});return ja(s)?{value:s.value}:{issues:n.common.issues}}catch(s){(i=(r=s==null?void 0:s.message)==null?void 0:r.toLowerCase())!=null&&i.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:n}).then(s=>ja(s)?{value:s.value}:{issues:n.common.issues})}async parseAsync(t,n){const r=await this.safeParseAsync(t,n);if(r.success)return r.data;throw r.error}async safeParseAsync(t,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:rs(t)},i=this._parse({data:t,path:r.path,parent:r}),s=await(wh(i)?i:Promise.resolve(i));return _b(r,s)}refine(t,n){const r=i=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(i):n;return this._refinement((i,s)=>{const o=t(i),a=()=>s.addIssue({code:K.custom,...r(i)});return typeof Promise<"u"&&o instanceof Promise?o.then(l=>l?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(t,n){return this._refinement((r,i)=>t(r)?!0:(i.addIssue(typeof n=="function"?n(r,i):n),!1))}_refinement(t){return new ho({schema:this,typeName:Ee.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Ei.create(this,this._def)}nullable(){return fo.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ei.create(this)}promise(){return Th.create(this,this._def)}or(t){return kh.create([this,t],this._def)}and(t){return Ch.create(this,t,this._def)}transform(t){return new ho({...Me(this._def),schema:this,typeName:Ee.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new Ph({...Me(this._def),innerType:this,defaultValue:n,typeName:Ee.ZodDefault})}brand(){return new uN({typeName:Ee.ZodBranded,type:this,...Me(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new Ih({...Me(this._def),innerType:this,catchValue:n,typeName:Ee.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return Hx.create(this,t)}readonly(){return Rh.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const tL=/^c[^\s-]{8,}$/i,nL=/^[0-9a-z]+$/,rL=/^[0-9A-HJKMNP-TV-Z]{26}$/i,iL=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,sL=/^[a-z0-9_-]{21}$/i,oL=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,aL=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,lL=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,cL="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Kp;const uL=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,dL=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,hL=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,fL=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,pL=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,mL=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,aN="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",gL=new RegExp(`^${aN}$`);function lN(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:e.precision==null&&(t=`${t}(\\.\\d+)?`);const n=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${n}`}function vL(e){return new RegExp(`^${lN(e)}$`)}function xL(e){let t=`${aN}T${lN(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function _L(e,t){return!!((t==="v4"||!t)&&uL.test(e)||(t==="v6"||!t)&&hL.test(e))}function yL(e,t){if(!oL.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),i=JSON.parse(atob(r));return!(typeof i!="object"||i===null||"typ"in i&&(i==null?void 0:i.typ)!=="JWT"||!i.alg||t&&i.alg!==t)}catch{return!1}}function bL(e,t){return!!((t==="v4"||!t)&&dL.test(e)||(t==="v6"||!t)&&fL.test(e))}class wi extends He{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==ce.string){const s=this._getOrReturnCtx(t);return se(s,{code:K.invalid_type,expected:ce.string,received:s.parsedType}),Ce}const r=new Tn;let i;for(const s of this._def.checks)if(s.kind==="min")t.data.length<s.value&&(i=this._getOrReturnCtx(t,i),se(i,{code:K.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="max")t.data.length>s.value&&(i=this._getOrReturnCtx(t,i),se(i,{code:K.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="length"){const o=t.data.length>s.value,a=t.data.length<s.value;(o||a)&&(i=this._getOrReturnCtx(t,i),o?se(i,{code:K.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):a&&se(i,{code:K.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if(s.kind==="email")lL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"email",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="emoji")Kp||(Kp=new RegExp(cL,"u")),Kp.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"emoji",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="uuid")iL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"uuid",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="nanoid")sL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"nanoid",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid")tL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"cuid",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid2")nL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"cuid2",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="ulid")rL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"ulid",code:K.invalid_string,message:s.message}),r.dirty());else if(s.kind==="url")try{new URL(t.data)}catch{i=this._getOrReturnCtx(t,i),se(i,{validation:"url",code:K.invalid_string,message:s.message}),r.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"regex",code:K.invalid_string,message:s.message}),r.dirty())):s.kind==="trim"?t.data=t.data.trim():s.kind==="includes"?t.data.includes(s.value,s.position)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):s.kind==="toLowerCase"?t.data=t.data.toLowerCase():s.kind==="toUpperCase"?t.data=t.data.toUpperCase():s.kind==="startsWith"?t.data.startsWith(s.value)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):s.kind==="endsWith"?t.data.endsWith(s.value)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):s.kind==="datetime"?xL(s).test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:"datetime",message:s.message}),r.dirty()):s.kind==="date"?gL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:"date",message:s.message}),r.dirty()):s.kind==="time"?vL(s).test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{code:K.invalid_string,validation:"time",message:s.message}),r.dirty()):s.kind==="duration"?aL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"duration",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="ip"?_L(t.data,s.version)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"ip",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="jwt"?yL(t.data,s.alg)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"jwt",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="cidr"?bL(t.data,s.version)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"cidr",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="base64"?pL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"base64",code:K.invalid_string,message:s.message}),r.dirty()):s.kind==="base64url"?mL.test(t.data)||(i=this._getOrReturnCtx(t,i),se(i,{validation:"base64url",code:K.invalid_string,message:s.message}),r.dirty()):Ke.assertNever(s);return{status:r.value,value:t.data}}_regex(t,n,r){return this.refinement(i=>t.test(i),{validation:n,code:K.invalid_string,...me.errToObj(r)})}_addCheck(t){return new wi({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...me.errToObj(t)})}url(t){return this._addCheck({kind:"url",...me.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...me.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...me.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...me.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...me.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...me.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...me.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...me.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...me.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...me.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...me.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...me.errToObj(t)})}datetime(t){return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof(t==null?void 0:t.precision)>"u"?null:t==null?void 0:t.precision,offset:(t==null?void 0:t.offset)??!1,local:(t==null?void 0:t.local)??!1,...me.errToObj(t==null?void 0:t.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof(t==null?void 0:t.precision)>"u"?null:t==null?void 0:t.precision,...me.errToObj(t==null?void 0:t.message)})}duration(t){return this._addCheck({kind:"duration",...me.errToObj(t)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...me.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...me.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...me.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...me.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...me.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...me.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...me.errToObj(n)})}nonempty(t){return this.min(1,me.errToObj(t))}trim(){return new wi({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new wi({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new wi({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isCIDR(){return!!this._def.checks.find(t=>t.kind==="cidr")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get isBase64url(){return!!this._def.checks.find(t=>t.kind==="base64url")}get minLength(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxLength(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}}wi.create=e=>new wi({checks:[],typeName:Ee.ZodString,coerce:(e==null?void 0:e.coerce)??!1,...Me(e)});function wL(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,i=n>r?n:r,s=Number.parseInt(e.toFixed(i).replace(".","")),o=Number.parseInt(t.toFixed(i).replace(".",""));return s%o/10**i}class Da extends He{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==ce.number){const s=this._getOrReturnCtx(t);return se(s,{code:K.invalid_type,expected:ce.number,received:s.parsedType}),Ce}let r;const i=new Tn;for(const s of this._def.checks)s.kind==="int"?Ke.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),se(r,{code:K.invalid_type,expected:"integer",received:"float",message:s.message}),i.dirty()):s.kind==="min"?(s.inclusive?t.data<s.value:t.data<=s.value)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),i.dirty()):s.kind==="max"?(s.inclusive?t.data>s.value:t.data>=s.value)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),i.dirty()):s.kind==="multipleOf"?wL(t.data,s.value)!==0&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.not_multiple_of,multipleOf:s.value,message:s.message}),i.dirty()):s.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),se(r,{code:K.not_finite,message:s.message}),i.dirty()):Ke.assertNever(s);return{status:i.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,me.toString(n))}gt(t,n){return this.setLimit("min",t,!1,me.toString(n))}lte(t,n){return this.setLimit("max",t,!0,me.toString(n))}lt(t,n){return this.setLimit("max",t,!1,me.toString(n))}setLimit(t,n,r,i){return new Da({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:me.toString(i)}]})}_addCheck(t){return new Da({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:me.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:me.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:me.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:me.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:me.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:me.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:me.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:me.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:me.toString(t)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}get isInt(){return!!this._def.checks.find(t=>t.kind==="int"||t.kind==="multipleOf"&&Ke.isInteger(t.value))}get isFinite(){let t=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(t===null||r.value<t)&&(t=r.value)}return Number.isFinite(n)&&Number.isFinite(t)}}Da.create=e=>new Da({checks:[],typeName:Ee.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...Me(e)});class Ic extends He{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==ce.bigint)return this._getInvalidInput(t);let r;const i=new Tn;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?t.data<s.value:t.data<=s.value)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),i.dirty()):s.kind==="max"?(s.inclusive?t.data>s.value:t.data>=s.value)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),i.dirty()):s.kind==="multipleOf"?t.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),se(r,{code:K.not_multiple_of,multipleOf:s.value,message:s.message}),i.dirty()):Ke.assertNever(s);return{status:i.value,value:t.data}}_getInvalidInput(t){const n=this._getOrReturnCtx(t);return se(n,{code:K.invalid_type,expected:ce.bigint,received:n.parsedType}),Ce}gte(t,n){return this.setLimit("min",t,!0,me.toString(n))}gt(t,n){return this.setLimit("min",t,!1,me.toString(n))}lte(t,n){return this.setLimit("max",t,!0,me.toString(n))}lt(t,n){return this.setLimit("max",t,!1,me.toString(n))}setLimit(t,n,r,i){return new Ic({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:me.toString(i)}]})}_addCheck(t){return new Ic({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:me.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:me.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:me.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:me.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:me.toString(n)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}}Ic.create=e=>new Ic({checks:[],typeName:Ee.ZodBigInt,coerce:(e==null?void 0:e.coerce)??!1,...Me(e)});class vv extends He{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==ce.boolean){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.boolean,received:r.parsedType}),Ce}return Sr(t.data)}}vv.create=e=>new vv({typeName:Ee.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...Me(e)});class Sh extends He{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==ce.date){const s=this._getOrReturnCtx(t);return se(s,{code:K.invalid_type,expected:ce.date,received:s.parsedType}),Ce}if(Number.isNaN(t.data.getTime())){const s=this._getOrReturnCtx(t);return se(s,{code:K.invalid_date}),Ce}const r=new Tn;let i;for(const s of this._def.checks)s.kind==="min"?t.data.getTime()<s.value&&(i=this._getOrReturnCtx(t,i),se(i,{code:K.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):s.kind==="max"?t.data.getTime()>s.value&&(i=this._getOrReturnCtx(t,i),se(i,{code:K.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):Ke.assertNever(s);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Sh({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:me.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:me.toString(n)})}get minDate(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t!=null?new Date(t):null}}Sh.create=e=>new Sh({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:Ee.ZodDate,...Me(e)});class yb extends He{_parse(t){if(this._getType(t)!==ce.symbol){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.symbol,received:r.parsedType}),Ce}return Sr(t.data)}}yb.create=e=>new yb({typeName:Ee.ZodSymbol,...Me(e)});class xv extends He{_parse(t){if(this._getType(t)!==ce.undefined){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.undefined,received:r.parsedType}),Ce}return Sr(t.data)}}xv.create=e=>new xv({typeName:Ee.ZodUndefined,...Me(e)});class _v extends He{_parse(t){if(this._getType(t)!==ce.null){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.null,received:r.parsedType}),Ce}return Sr(t.data)}}_v.create=e=>new _v({typeName:Ee.ZodNull,...Me(e)});class bb extends He{constructor(){super(...arguments),this._any=!0}_parse(t){return Sr(t.data)}}bb.create=e=>new bb({typeName:Ee.ZodAny,...Me(e)});class yv extends He{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Sr(t.data)}}yv.create=e=>new yv({typeName:Ee.ZodUnknown,...Me(e)});class ks extends He{_parse(t){const n=this._getOrReturnCtx(t);return se(n,{code:K.invalid_type,expected:ce.never,received:n.parsedType}),Ce}}ks.create=e=>new ks({typeName:Ee.ZodNever,...Me(e)});class wb extends He{_parse(t){if(this._getType(t)!==ce.undefined){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.void,received:r.parsedType}),Ce}return Sr(t.data)}}wb.create=e=>new wb({typeName:Ee.ZodVoid,...Me(e)});class ei extends He{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),i=this._def;if(n.parsedType!==ce.array)return se(n,{code:K.invalid_type,expected:ce.array,received:n.parsedType}),Ce;if(i.exactLength!==null){const o=n.data.length>i.exactLength.value,a=n.data.length<i.exactLength.value;(o||a)&&(se(n,{code:o?K.too_big:K.too_small,minimum:a?i.exactLength.value:void 0,maximum:o?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),r.dirty())}if(i.minLength!==null&&n.data.length<i.minLength.value&&(se(n,{code:K.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),r.dirty()),i.maxLength!==null&&n.data.length>i.maxLength.value&&(se(n,{code:K.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,a)=>i.type._parseAsync(new ii(n,o,n.path,a)))).then(o=>Tn.mergeArray(r,o));const s=[...n.data].map((o,a)=>i.type._parseSync(new ii(n,o,n.path,a)));return Tn.mergeArray(r,s)}get element(){return this._def.type}min(t,n){return new ei({...this._def,minLength:{value:t,message:me.toString(n)}})}max(t,n){return new ei({...this._def,maxLength:{value:t,message:me.toString(n)}})}length(t,n){return new ei({...this._def,exactLength:{value:t,message:me.toString(n)}})}nonempty(t){return this.min(1,t)}}ei.create=(e,t)=>new ei({type:e,minLength:null,maxLength:null,exactLength:null,typeName:Ee.ZodArray,...Me(t)});function Go(e){if(e instanceof jt){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Ei.create(Go(r))}return new jt({...e._def,shape:()=>t})}else return e instanceof ei?new ei({...e._def,type:Go(e.element)}):e instanceof Ei?Ei.create(Go(e.unwrap())):e instanceof fo?fo.create(Go(e.unwrap())):e instanceof co?co.create(e.items.map(t=>Go(t))):e}class jt extends He{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),n=Ke.objectKeys(t);return this._cached={shape:t,keys:n},this._cached}_parse(t){if(this._getType(t)!==ce.object){const c=this._getOrReturnCtx(t);return se(c,{code:K.invalid_type,expected:ce.object,received:c.parsedType}),Ce}const{status:r,ctx:i}=this._processInputParams(t),{shape:s,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof ks&&this._def.unknownKeys==="strip"))for(const c in i.data)o.includes(c)||a.push(c);const l=[];for(const c of o){const u=s[c],d=i.data[c];l.push({key:{status:"valid",value:c},value:u._parse(new ii(i,d,i.path,c)),alwaysSet:c in i.data})}if(this._def.catchall instanceof ks){const c=this._def.unknownKeys;if(c==="passthrough")for(const u of a)l.push({key:{status:"valid",value:u},value:{status:"valid",value:i.data[u]}});else if(c==="strict")a.length>0&&(se(i,{code:K.unrecognized_keys,keys:a}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const u of a){const d=i.data[u];l.push({key:{status:"valid",value:u},value:c._parse(new ii(i,d,i.path,u)),alwaysSet:u in i.data})}}return i.common.async?Promise.resolve().then(async()=>{const c=[];for(const u of l){const d=await u.key,f=await u.value;c.push({key:d,value:f,alwaysSet:u.alwaysSet})}return c}).then(c=>Tn.mergeObjectSync(r,c)):Tn.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(t){return me.errToObj,new jt({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{var s,o;const i=((o=(s=this._def).errorMap)==null?void 0:o.call(s,n,r).message)??r.defaultError;return n.code==="unrecognized_keys"?{message:me.errToObj(t).message??i}:{message:i}}}:{}})}strip(){return new jt({...this._def,unknownKeys:"strip"})}passthrough(){return new jt({...this._def,unknownKeys:"passthrough"})}extend(t){return new jt({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new jt({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:Ee.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new jt({...this._def,catchall:t})}pick(t){const n={};for(const r of Ke.objectKeys(t))t[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new jt({...this._def,shape:()=>n})}omit(t){const n={};for(const r of Ke.objectKeys(this.shape))t[r]||(n[r]=this.shape[r]);return new jt({...this._def,shape:()=>n})}deepPartial(){return Go(this)}partial(t){const n={};for(const r of Ke.objectKeys(this.shape)){const i=this.shape[r];t&&!t[r]?n[r]=i:n[r]=i.optional()}return new jt({...this._def,shape:()=>n})}required(t){const n={};for(const r of Ke.objectKeys(this.shape))if(t&&!t[r])n[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof Ei;)s=s._def.innerType;n[r]=s}return new jt({...this._def,shape:()=>n})}keyof(){return cN(Ke.objectKeys(this.shape))}}jt.create=(e,t)=>new jt({shape:()=>e,unknownKeys:"strip",catchall:ks.create(),typeName:Ee.ZodObject,...Me(t)});jt.strictCreate=(e,t)=>new jt({shape:()=>e,unknownKeys:"strict",catchall:ks.create(),typeName:Ee.ZodObject,...Me(t)});jt.lazycreate=(e,t)=>new jt({shape:e,unknownKeys:"strip",catchall:ks.create(),typeName:Ee.ZodObject,...Me(t)});class kh extends He{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function i(s){for(const a of s)if(a.result.status==="valid")return a.result;for(const a of s)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const o=s.map(a=>new Ri(a.ctx.common.issues));return se(n,{code:K.invalid_union,unionErrors:o}),Ce}if(n.common.async)return Promise.all(r.map(async s=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(i);{let s;const o=[];for(const l of r){const c={...n,common:{...n.common,issues:[]},parent:null},u=l._parseSync({data:n.data,path:n.path,parent:c});if(u.status==="valid")return u;u.status==="dirty"&&!s&&(s={result:u,ctx:c}),c.common.issues.length&&o.push(c.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;const a=o.map(l=>new Ri(l));return se(n,{code:K.invalid_union,unionErrors:a}),Ce}}get options(){return this._def.options}}kh.create=(e,t)=>new kh({options:e,typeName:Ee.ZodUnion,...Me(t)});const vi=e=>e instanceof wv?vi(e.schema):e instanceof ho?vi(e.innerType()):e instanceof Nh?[e.value]:e instanceof uo?e.options:e instanceof Sv?Ke.objectValues(e.enum):e instanceof Ph?vi(e._def.innerType):e instanceof xv?[void 0]:e instanceof _v?[null]:e instanceof Ei?[void 0,...vi(e.unwrap())]:e instanceof fo?[null,...vi(e.unwrap())]:e instanceof uN||e instanceof Rh?vi(e.unwrap()):e instanceof Ih?vi(e._def.innerType):[];class Fx extends He{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==ce.object)return se(n,{code:K.invalid_type,expected:ce.object,received:n.parsedType}),Ce;const r=this.discriminator,i=n.data[r],s=this.optionsMap.get(i);return s?n.common.async?s._parseAsync({data:n.data,path:n.path,parent:n}):s._parseSync({data:n.data,path:n.path,parent:n}):(se(n,{code:K.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),Ce)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const i=new Map;for(const s of n){const o=vi(s.shape[t]);if(!o.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const a of o){if(i.has(a))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(a)}`);i.set(a,s)}}return new Fx({typeName:Ee.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:i,...Me(r)})}}function bv(e,t){const n=rs(e),r=rs(t);if(e===t)return{valid:!0,data:e};if(n===ce.object&&r===ce.object){const i=Ke.objectKeys(t),s=Ke.objectKeys(e).filter(a=>i.indexOf(a)!==-1),o={...e,...t};for(const a of s){const l=bv(e[a],t[a]);if(!l.valid)return{valid:!1};o[a]=l.data}return{valid:!0,data:o}}else if(n===ce.array&&r===ce.array){if(e.length!==t.length)return{valid:!1};const i=[];for(let s=0;s<e.length;s++){const o=e[s],a=t[s],l=bv(o,a);if(!l.valid)return{valid:!1};i.push(l.data)}return{valid:!0,data:i}}else return n===ce.date&&r===ce.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}class Ch extends He{_parse(t){const{status:n,ctx:r}=this._processInputParams(t),i=(s,o)=>{if(vb(s)||vb(o))return Ce;const a=bv(s.value,o.value);return a.valid?((xb(s)||xb(o))&&n.dirty(),{status:n.value,value:a.data}):(se(r,{code:K.invalid_intersection_types}),Ce)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([s,o])=>i(s,o)):i(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Ch.create=(e,t,n)=>new Ch({left:e,right:t,typeName:Ee.ZodIntersection,...Me(n)});class co extends He{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==ce.array)return se(r,{code:K.invalid_type,expected:ce.array,received:r.parsedType}),Ce;if(r.data.length<this._def.items.length)return se(r,{code:K.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Ce;!this._def.rest&&r.data.length>this._def.items.length&&(se(r,{code:K.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const s=[...r.data].map((o,a)=>{const l=this._def.items[a]||this._def.rest;return l?l._parse(new ii(r,o,r.path,a)):null}).filter(o=>!!o);return r.common.async?Promise.all(s).then(o=>Tn.mergeArray(n,o)):Tn.mergeArray(n,s)}get items(){return this._def.items}rest(t){return new co({...this._def,rest:t})}}co.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new co({items:e,typeName:Ee.ZodTuple,rest:null,...Me(t)})};class Eh extends He{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==ce.object)return se(r,{code:K.invalid_type,expected:ce.object,received:r.parsedType}),Ce;const i=[],s=this._def.keyType,o=this._def.valueType;for(const a in r.data)i.push({key:s._parse(new ii(r,a,r.path,a)),value:o._parse(new ii(r,r.data[a],r.path,a)),alwaysSet:a in r.data});return r.common.async?Tn.mergeObjectAsync(n,i):Tn.mergeObjectSync(n,i)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof He?new Eh({keyType:t,valueType:n,typeName:Ee.ZodRecord,...Me(r)}):new Eh({keyType:wi.create(),valueType:t,typeName:Ee.ZodRecord,...Me(n)})}}class Sb extends He{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==ce.map)return se(r,{code:K.invalid_type,expected:ce.map,received:r.parsedType}),Ce;const i=this._def.keyType,s=this._def.valueType,o=[...r.data.entries()].map(([a,l],c)=>({key:i._parse(new ii(r,a,r.path,[c,"key"])),value:s._parse(new ii(r,l,r.path,[c,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const l of o){const c=await l.key,u=await l.value;if(c.status==="aborted"||u.status==="aborted")return Ce;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const l of o){const c=l.key,u=l.value;if(c.status==="aborted"||u.status==="aborted")return Ce;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}}}}Sb.create=(e,t,n)=>new Sb({valueType:t,keyType:e,typeName:Ee.ZodMap,...Me(n)});class Rc extends He{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==ce.set)return se(r,{code:K.invalid_type,expected:ce.set,received:r.parsedType}),Ce;const i=this._def;i.minSize!==null&&r.data.size<i.minSize.value&&(se(r,{code:K.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),n.dirty()),i.maxSize!==null&&r.data.size>i.maxSize.value&&(se(r,{code:K.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),n.dirty());const s=this._def.valueType;function o(l){const c=new Set;for(const u of l){if(u.status==="aborted")return Ce;u.status==="dirty"&&n.dirty(),c.add(u.value)}return{status:n.value,value:c}}const a=[...r.data.values()].map((l,c)=>s._parse(new ii(r,l,r.path,c)));return r.common.async?Promise.all(a).then(l=>o(l)):o(a)}min(t,n){return new Rc({...this._def,minSize:{value:t,message:me.toString(n)}})}max(t,n){return new Rc({...this._def,maxSize:{value:t,message:me.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}Rc.create=(e,t)=>new Rc({valueType:e,minSize:null,maxSize:null,typeName:Ee.ZodSet,...Me(t)});class wv extends He{get schema(){return this._def.getter()}_parse(t){const{ctx:n}=this._processInputParams(t);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}wv.create=(e,t)=>new wv({getter:e,typeName:Ee.ZodLazy,...Me(t)});class Nh extends He{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return se(n,{received:n.data,code:K.invalid_literal,expected:this._def.value}),Ce}return{status:"valid",value:t.data}}get value(){return this._def.value}}Nh.create=(e,t)=>new Nh({value:e,typeName:Ee.ZodLiteral,...Me(t)});function cN(e,t){return new uo({values:e,typeName:Ee.ZodEnum,...Me(t)})}class uo extends He{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return se(n,{expected:Ke.joinValues(r),received:n.parsedType,code:K.invalid_type}),Ce}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){const n=this._getOrReturnCtx(t),r=this._def.values;return se(n,{received:n.data,code:K.invalid_enum_value,options:r}),Ce}return Sr(t.data)}get options(){return this._def.values}get enum(){const t={};for(const n of this._def.values)t[n]=n;return t}get Values(){const t={};for(const n of this._def.values)t[n]=n;return t}get Enum(){const t={};for(const n of this._def.values)t[n]=n;return t}extract(t,n=this._def){return uo.create(t,{...this._def,...n})}exclude(t,n=this._def){return uo.create(this.options.filter(r=>!t.includes(r)),{...this._def,...n})}}uo.create=cN;class Sv extends He{_parse(t){const n=Ke.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==ce.string&&r.parsedType!==ce.number){const i=Ke.objectValues(n);return se(r,{expected:Ke.joinValues(i),received:r.parsedType,code:K.invalid_type}),Ce}if(this._cache||(this._cache=new Set(Ke.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){const i=Ke.objectValues(n);return se(r,{received:r.data,code:K.invalid_enum_value,options:i}),Ce}return Sr(t.data)}get enum(){return this._def.values}}Sv.create=(e,t)=>new Sv({values:e,typeName:Ee.ZodNativeEnum,...Me(t)});class Th extends He{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==ce.promise&&n.common.async===!1)return se(n,{code:K.invalid_type,expected:ce.promise,received:n.parsedType}),Ce;const r=n.parsedType===ce.promise?n.data:Promise.resolve(n.data);return Sr(r.then(i=>this._def.type.parseAsync(i,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Th.create=(e,t)=>new Th({type:e,typeName:Ee.ZodPromise,...Me(t)});class ho extends He{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Ee.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),i=this._def.effect||null,s={addIssue:o=>{se(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),i.type==="preprocess"){const o=i.transform(r.data,s);if(r.common.async)return Promise.resolve(o).then(async a=>{if(n.value==="aborted")return Ce;const l=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return l.status==="aborted"?Ce:l.status==="dirty"||n.value==="dirty"?Ll(l.value):l});{if(n.value==="aborted")return Ce;const a=this._def.schema._parseSync({data:o,path:r.path,parent:r});return a.status==="aborted"?Ce:a.status==="dirty"||n.value==="dirty"?Ll(a.value):a}}if(i.type==="refinement"){const o=a=>{const l=i.refinement(a,s);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?Ce:(a.status==="dirty"&&n.dirty(),o(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?Ce:(a.status==="dirty"&&n.dirty(),o(a.value).then(()=>({status:n.value,value:a.value}))))}if(i.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!ja(o))return Ce;const a=i.transform(o.value,s);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>ja(o)?Promise.resolve(i.transform(o.value,s)).then(a=>({status:n.value,value:a})):Ce);Ke.assertNever(i)}}ho.create=(e,t,n)=>new ho({schema:e,typeName:Ee.ZodEffects,effect:t,...Me(n)});ho.createWithPreprocess=(e,t,n)=>new ho({schema:t,effect:{type:"preprocess",transform:e},typeName:Ee.ZodEffects,...Me(n)});class Ei extends He{_parse(t){return this._getType(t)===ce.undefined?Sr(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Ei.create=(e,t)=>new Ei({innerType:e,typeName:Ee.ZodOptional,...Me(t)});class fo extends He{_parse(t){return this._getType(t)===ce.null?Sr(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}fo.create=(e,t)=>new fo({innerType:e,typeName:Ee.ZodNullable,...Me(t)});class Ph extends He{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===ce.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Ph.create=(e,t)=>new Ph({innerType:e,typeName:Ee.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...Me(t)});class Ih extends He{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},i=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return wh(i)?i.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Ri(r.common.issues)},input:r.data})})):{status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new Ri(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Ih.create=(e,t)=>new Ih({innerType:e,typeName:Ee.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...Me(t)});class kb extends He{_parse(t){if(this._getType(t)!==ce.nan){const r=this._getOrReturnCtx(t);return se(r,{code:K.invalid_type,expected:ce.nan,received:r.parsedType}),Ce}return{status:"valid",value:t.data}}}kb.create=e=>new kb({typeName:Ee.ZodNaN,...Me(e)});class uN extends He{_parse(t){const{ctx:n}=this._processInputParams(t),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Hx extends He{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Ce:s.status==="dirty"?(n.dirty(),Ll(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{const i=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?Ce:i.status==="dirty"?(n.dirty(),{status:"dirty",value:i.value}):this._def.out._parseSync({data:i.value,path:r.path,parent:r})}}static create(t,n){return new Hx({in:t,out:n,typeName:Ee.ZodPipeline})}}class Rh extends He{_parse(t){const n=this._def.innerType._parse(t),r=i=>(ja(i)&&(i.value=Object.freeze(i.value)),i);return wh(n)?n.then(i=>r(i)):r(n)}unwrap(){return this._def.innerType}}Rh.create=(e,t)=>new Rh({innerType:e,typeName:Ee.ZodReadonly,...Me(t)});var Ee;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(Ee||(Ee={}));const S=wi.create,G=Da.create,Ne=vv.create,to=yv.create;ks.create;const _e=ei.create,A=jt.create;kh.create;const ai=Fx.create;Ch.create;co.create;const Xa=Eh.create,ee=Nh.create,Xe=uo.create;Th.create;Ei.create;fo.create;new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");const SL=["owner"],kL=["agent","owner","user-upload"],dN=A({id:S().min(1),relPath:S().min(1),from:Xe(kL),label:S().optional(),size:G().int().nonnegative(),mime:S().min(1),addedAt:G().int().nonnegative(),lastEditedAt:G().int().nonnegative().optional(),stale:Ne().optional()});A({sessionId:S().min(1),relPath:S().min(1),ttlSeconds:G().int().positive().nullable().optional(),view:Xe(["raw","md-rendered"]).optional()});A({url:S().min(1),expiresAt:G().int().nonnegative().nullable()});A({sessionId:S().min(1),relPath:S().min(1),label:S().optional(),origin:ee("agent").optional()});A({entry:dN});A({sessionId:S().min(1),relPath:S().min(1)});A({removed:ee(!0)});A({sessionId:S().min(1)});A({entries:_e(dN)});A({attachmentId:S().min(1),url:S().min(1),relPath:S().min(1),sizeBytes:G().int().nonnegative(),mimeType:S().min(1)});const CL=ai("type",[A({type:ee("persona"),id:S().min(1)}).strict(),A({type:ee("chat"),id:S().min(1)}).strict(),A({type:ee("*")}).strict()]),EL=Xe(["read","send","admin"]),Ux=A({resource:CL,actions:_e(EL).min(1)}).strict(),NL=A({id:S().min(1),secretHash:S().regex(/^[a-f0-9]{64}$/),displayName:S(),grants:_e(Ux),issuedAt:G().int().nonnegative(),expiresAt:G().int().positive().optional(),maxUses:G().int().positive().optional(),usedCount:G().int().nonnegative(),peerOwnerId:S().min(1).optional(),firstUsedByPeerAt:G().int().positive().optional(),peerDisplayName:S().optional()}).strict(),TL=NL.omit({secretHash:!0});A({type:ee("whoami:ok"),owner:A({id:S(),kind:Xe(["owner","guest"]),displayName:S(),ownerId:S(),provider:S()}).strict(),capability:TL,grantedPersonas:_e(A({id:S().min(1),displayName:S()}).strict())}).strict();A({selfUrl:S().min(1)});A({type:ee("contact:handshake:ok"),owner:A({id:S(),ownerId:S(),provider:S(),displayName:S()}),grants:_e(Ux)});A({deviceId:S().min(1),remoteAccessAllowed:Ne()}).strict();A({type:ee("contact:setRemoteAccess:ok"),deviceId:S().min(1),remoteAccessAllowed:Ne()}).strict();A({type:ee("contact:remote-access-updated"),deviceId:S().min(1),remoteAccessAllowed:Ne()}).strict();const PL=A({deviceId:S().min(1),ownerId:S().min(1),provider:S().min(1),displayName:S(),remoteUrl:S().min(1),connectToken:S(),grants:_e(Ux),addedAt:G().int().nonnegative(),pinnedAt:G().int().nullable().default(null),remoteAccessAllowed:Ne().default(!1)}).strict(),hN=PL;A({deviceId:S().min(1)}).strict();A({type:ee("contact:remove:ok"),deviceId:S().min(1)}).strict();A({type:ee("contact:list:ok"),contacts:_e(hN)}).strict();A({type:ee("contact:added"),contact:hN}).strict();A({type:ee("contact:removed"),deviceId:S().min(1)}).strict();A({deviceId:S().min(1),pinned:Ne()}).strict();A({type:ee("contact:pin:ok"),deviceId:S().min(1),pinnedAt:G().int().nullable()}).strict();A({type:ee("contact:pinned"),deviceId:S().min(1),pinnedAt:G().int().nullable()}).strict();const IL=A({deviceId:S().min(1),name:S().min(1),url:S().min(1)});A({type:ee("device:list:ok"),devices:_e(IL)});A({deviceId:S().min(1),url:S().min(1).optional(),name:S().optional()});A({type:ee("device:connect:ok"),deviceId:S(),name:S(),url:S()});const fN=A({ownerId:S().min(1),provider:S().min(1),displayName:S().min(1),avatarUrl:S().optional(),unionId:S().optional()});A({type:ee("auth:login:start:ok"),authUrl:S().min(1),state:S().min(1)});A({type:ee("auth:getIdentity:ok"),identity:fN.nullable(),deviceId:S().min(1)});A({type:ee("auth:logout:ok")});A({type:ee("auth:login:done"),identity:fN});A({type:ee("auth:login:failed"),reason:S()});const Wx=ai("kind",[A({kind:ee("success"),text:S(),filePaths:_e(S()).optional()}),A({kind:ee("failure"),reason:S()})]);A({targetPersona:S().min(1).optional(),dispatchId:S().min(1).optional(),prompt:S(),targetDeviceId:S().min(1).optional(),model:S().min(1).optional(),sessionLabel:S().min(1).max(60).optional()}).refine(e=>e.targetPersona!==void 0||e.dispatchId!==void 0,{message:"either targetPersona (new dispatch) or dispatchId (follow-up) is required"}).refine(e=>!(e.dispatchId!==void 0&&e.targetDeviceId!==void 0),{message:"cross-device dispatch cannot be continued (dispatchId + targetDeviceId are mutually exclusive)"});A({dispatchId:S().min(1),outcome:Wx});const RL=["running","completed","failed"],pN=Xe(RL),ML=A({dispatchId:S().min(1),sourceSessionId:S().min(1),sourcePersonaId:S().min(1).optional(),targetPersonaId:S().min(1),workerSessionId:S().min(1).optional(),taskText:S(),status:pN,outcome:Wx.optional(),meta:Xa(to()).optional(),createdAt:S().min(1),completedAt:S().min(1).optional(),deliveredAt:S().min(1).optional()});A({sourceSessionId:S().min(1).optional()});A({records:_e(ML)});A({dispatchId:S().min(1)});A({type:ee("personaDispatch:get:ok"),status:pN,outcome:Wx.optional()});const AL=/^[a-z0-9][a-z0-9-]*$/;Xe(["stopped","starting","running","crashed","invalid"]);const jL=new Set(["localhost","127.0.0.1"]);function DL(e){let t;try{t=new URL(e)}catch{return!1}return!!(t.protocol==="https:"||t.protocol==="http:"&&jL.has(t.hostname))}const Ku=A({id:S().regex(AL),name:S().min(1),version:S().min(1),apiVersion:ee("1"),runtime:A({startCommand:S().min(1)}).passthrough().optional(),entry:A({url:S().url().refine(DL,{message:"INVALID_URL_SCHEME: only https or http://localhost is allowed"})}).strict().optional()}).passthrough().superRefine((e,t)=>{var i;const n=!!e.runtime,r=!!((i=e.entry)!=null&&i.url);n&&r&&t.addIssue({code:K.custom,message:"INVALID_MANIFEST: entry.url and runtime cannot coexist"}),!n&&!r&&t.addIssue({code:K.custom,message:"INVALID_MANIFEST: must have either entry.url or runtime"})}),LL=ai("kind",[A({kind:ee("local"),port:G().int().min(1).max(65535)}),A({kind:ee("hosted"),url:S().url()})]);ai("state",[A({extId:S(),manifest:Ku,state:ee("stopped")}),A({extId:S(),manifest:Ku,state:ee("starting")}),A({extId:S(),manifest:Ku,state:ee("running"),target:LL}),A({extId:S(),manifest:Ku,state:ee("crashed")}),A({extId:S(),manifest:to().nullable(),state:ee("invalid"),invalidReason:S().min(1)})]);A({snapshotHash:S().min(1),version:S().min(1),publishedAt:G()});const OL=ai("kind",[A({kind:ee("p2p-tunnel"),ownerPrincipalId:S().min(1),extId:S().min(1)})]);ai("kind",[A({kind:ee("p2p-tunnel"),ownerPrincipalId:S().min(1),extId:S().min(1),snapshotHash:S().min(1)})]);A({extId:S().min(1),name:S().min(1),version:S().min(1),contentHash:S().min(1),publishedAt:G()});const BL=ai("kind",[A({kind:ee("clean")}),A({kind:ee("ready-new-version"),fromVersion:S().min(1),toVersion:S().min(1)}),A({kind:ee("error-same-hash"),version:S().min(1)}),A({kind:ee("error-version-not-bumped"),localVersion:S().min(1),publishedVersion:S().min(1)}),A({kind:ee("error-version-regression"),localVersion:S().min(1),publishedVersion:S().min(1)})]);A({localManifest:A({name:S().min(1),version:S().min(1),contentHash:S().min(1)}),publishState:ai("kind",[A({kind:ee("unpublished")}),A({kind:ee("published"),version:S().min(1),contentHash:S().min(1),publishedAt:G()})]),check:BL});A({extId:S().min(1),newVersion:S().min(1).nullish()});A({extId:S().min(1)});A({extId:S().min(1),snapshotHash:S().min(1)});A({channelRef:OL,snapshotHash:S().min(1),zipBase64:S().min(1)});A({id:S().min(1),peerDeviceId:S().min(1),senderDeviceId:S().min(1),text:S().min(1),createdAt:G().int().nonnegative(),readBy:Xa(S().min(1),G().int().positive()).default({}),origin:A({kind:ee("persona"),personaId:S().min(1)}).optional()}).strict();A({peerDeviceId:S().min(1).optional(),id:S().min(1),text:S().min(1),createdAt:G().int().nonnegative(),origin:A({kind:ee("persona"),personaId:S().min(1)}).optional()}).strict();A({peerDeviceId:S().min(1),sinceCreatedAt:G().int().nonnegative().optional()}).strict();A({peerDeviceId:S().min(1),upToCreatedAt:G().int().nonnegative()}).strict();A({peerDeviceId:S().min(1).optional(),text:S().min(1)});A({peerDeviceId:S().min(1).optional(),command:S().min(1),timeoutMs:G().int().positive().optional()}).strict();A({type:ee("peerExec:run:ok"),stdout:S(),stderr:S(),exitCode:G().int().nullable(),timedOut:Ne(),stdoutTruncated:Ne(),stderrTruncated:Ne()}).strict();const mN=ai("kind",[A({kind:ee("at"),at:S().min(1)}),A({kind:ee("every"),everyMs:G().int().positive(),anchorMs:G().int().nonnegative().optional()}),A({kind:ee("cron"),expr:S().min(1),tz:S().min(1).optional()})]),ru=S().trim().min(1);A({personaId:ru,name:S().min(1),schedule:mN,prompt:S().min(1),targetPersona:S().min(1).optional(),timeoutMs:G().int().positive().optional()});A({personaId:ru,onlyMine:Ne().optional()});A({personaId:ru,shiftId:S().min(1)});const zL=A({name:S().min(1).optional(),schedule:mN.optional(),prompt:S().min(1).optional(),targetPersona:S().min(1).optional(),timeoutMs:G().int().positive().optional(),enabled:Ne().optional()});A({personaId:ru,shiftId:S().min(1),patch:zL});A({personaId:ru,shiftId:S().min(1),limit:G().int().positive().optional()});A({personaId:S().min(1)});A({personaId:S().min(1),appId:S().min(1),appSecret:S().min(1),botName:S().min(1).optional()});const $L=A({chatId:S().min(1),chatName:S().optional(),lastActiveAt:G().int().optional()}),FL=A({state:Xe(["unbound","bound","broken"]),appId:S().optional(),botName:S().optional(),brokenReason:S().optional(),groups:_e($L)});FL.extend({personaId:S().min(1)});const HL=A({personaId:S(),label:S(),model:S().optional(),public:Ne(),iconKey:S().optional(),tool:S().optional(),createdAt:G(),updatedAt:G()}).strict(),UL=A({name:S().min(1),description:S().optional()}),WL=A({id:S().min(1)}),VL=A({permissions:A({defaultMode:S().optional(),allow:_e(S()).optional(),deny:_e(S()).optional()}).optional(),sandbox:A({enabled:Ne().optional(),autoAllowBashIfSandboxed:Ne().optional(),allowUnsandboxedCommands:Ne().optional(),excludedCommands:_e(S()).optional(),filesystem:A({denyRead:_e(S()).optional(),allowRead:_e(S()).optional(),denyWrite:_e(S()).optional(),allowWrite:_e(S()).optional()}).optional(),network:A({allowedDomains:_e(S()).optional(),allowLocalBinding:Ne().optional()}).optional()}).optional()});HL.extend({personality:S().optional(),skills:_e(UL).optional(),plugins:_e(WL).optional(),sandboxSettings:VL.nullable().optional()});A({slug:S().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/).max(32),label:S().min(1),personality:S(),model:S().optional(),tool:S().optional(),public:Ne().optional(),iconKey:S().optional()}).strict();A({personaId:S().min(1)});A({personaId:S().min(1),patch:A({label:S().min(1).optional(),model:S().optional(),tool:S().optional(),personality:S().optional(),public:Ne().optional(),iconKey:S().nullable().optional()}).strict()}).strict();A({writableRoots:_e(S()).optional(),denyRead:_e(S()).optional(),network:Ne().optional()}).strict();const gN=["ready","session:info","session:status","session:event","session:deleted","session:rewound","session:cleared","permission:request","session:question","session:question:cleared","pong","error","subscribed","unsubscribed","auth:ok","tunnel:ready","tunnel:exited","tunnel:unavailable","session:control","session:pty","contact:added","contact:pinned","contact:removed","contact:remote-access-updated","inbox:event","friend:reverseTokenOffered","auth:login:done","auth:login:failed","appBuilder:project-updated","appBuilder:publish-progress","appBuilder:publish-failed","larkBot:state"],vN=["idle","running","running-idle","stopped","error","observing"],qL=["task-notification","slash-command","local-command","system-reminder","skill-hint","meta-text","attachment-skills","attachment-deferred-tools"],KL=["builtin","global","project","plugin"],GL=["builtin","global","project","policy","plugin"],xN=Xe(["owner","guest"]);A({id:S().min(1),kind:xN,displayName:S(),feishuUnionId:S().optional()}).strict();const XL=A({did:S().min(1),displayName:S(),feishuUnionId:S().optional(),principal:xN}).strict(),YL=Xe(vN),ZL=A({input_tokens:G().int().nonnegative().optional(),cache_read_input_tokens:G().int().nonnegative().optional(),cache_creation_input_tokens:G().int().nonnegative().optional(),output_tokens:G().int().nonnegative().optional()}),QL=A({inputTokens:G().int().nonnegative(),outputTokens:G().int().nonnegative(),cacheReadTokens:G().int().nonnegative().optional(),cacheCreateTokens:G().int().nonnegative().optional()}),_N={gitBranch:S().optional(),resolvedModel:S().optional(),contextUsage:QL.optional(),contextWindowSize:G().int().positive().optional()},JL=A(_N),yN=A({value:S(),label:S(),description:S().optional()}),eO=A({id:S().min(1),label:S().min(1),description:S().optional(),contextWindowSize:G().int().positive(),default:Ne().optional(),efforts:_e(yN).optional(),defaultEffort:S().optional()}),tO=A({id:S().min(1),label:S().min(1),description:S().optional()}),nO=A({name:S().min(1),type:Xe(["string","select","toggle"]),label:S().min(1),description:S().optional(),options:_e(yN).optional(),default:to().optional(),scope:Xe(["core","tool-specific"])});A({tool:S().min(1)});const rO=A({rewind:Ne(),subagents:Ne(),tui:Ne(),observe:Ne(),fileSharing:Ne(),fork:Ne()});A({tool:S().min(1),toolSessionIdLabel:S().optional(),models:_e(eO),permissionModes:_e(tO),configSchema:_e(nO),features:rO});const iO=A({tool:S().min(1),pattern:S().min(1),createdAt:S().min(1).optional()});A({sessionId:S().min(1),cwd:S().min(1),tool:ee("claude").or(S().min(1)).default("claude"),toolSessionId:S().optional(),label:S().optional(),model:S().optional(),permissionMode:S().optional(),effort:S().optional(),..._N,permissionRules:_e(iO).optional(),pinnedAt:G().int().nonnegative().nullable().optional(),pinSortOrder:G().int().nullable().optional(),unreadAt:S().min(1).nullable().optional(),iconKey:S().optional(),forkedFromSessionId:S().min(1).optional(),ephemeral:Ne().optional(),ownerPersonaId:S().min(1).optional(),appBuilderProject:S().regex(/^[a-z][a-z0-9-]{0,39}$/).optional(),chatId:S().min(1).optional(),creatorPrincipalId:S().min(1).optional(),creatorDisplayName:S().min(1).optional(),creatorFeishuUnionId:S().min(1).optional(),originOwnerPrincipalId:S().min(1).optional(),originOwnerPersonaId:S().min(1).optional(),dispatchedFromSessionId:S().min(1).optional(),shiftFiredFromSessionId:S().min(1).optional(),larkChatId:S().min(1).optional(),larkChatName:S().min(1).optional(),larkChatType:Xe(["p2p","group"]).optional(),createdAt:S().min(1),updatedAt:S().min(1)});const On={seq:G().int().nonnegative().optional(),ts:S().optional(),uuid:S().optional()},sO=Xe(qL),oO=A({readCount:G().int().nonnegative().optional(),searchCount:G().int().nonnegative().optional(),bashCount:G().int().nonnegative().optional(),editFileCount:G().int().nonnegative().optional(),linesAdded:G().int().nonnegative().optional(),linesRemoved:G().int().nonnegative().optional(),otherToolCount:G().int().nonnegative().optional()}),aO=A({oldStart:G().int().nonnegative(),oldLines:G().int().nonnegative(),newStart:G().int().nonnegative(),newLines:G().int().nonnegative(),lines:_e(S())}),lO=A({agentId:S().optional(),agentType:S().optional(),status:S().optional(),prompt:S().optional(),filePath:S().optional(),structuredPatch:_e(aO).optional(),stats:A({durationMs:G().int().nonnegative().optional(),tokens:G().int().nonnegative().optional(),toolUseCount:G().int().nonnegative().optional(),toolStats:oO.optional(),usage:ZL.optional()}).optional()}),cO=A({path:S(),content:S(),mtimeMs:G().optional()}),uO=A({label:S().min(1),description:S().optional()}),bN=A({question:S().min(1),multiSelect:Ne(),options:_e(uO).min(1)});ai("kind",[A({...On,kind:ee("session_init"),toolSessionId:S().optional()}),A({...On,kind:ee("thinking"),text:S(),partialId:S().optional()}),A({...On,kind:ee("text"),text:S(),partialId:S().optional()}),A({...On,kind:ee("user_text"),text:S(),meta:sO.optional(),taskId:S().optional(),parentToolUseId:S().optional(),sender:XL.optional()}),A({...On,kind:ee("tool_call"),toolUseId:S(),tool:S(),toolKind:S().optional(),input:to()}),A({...On,kind:ee("tool_result"),toolUseId:S(),output:to().optional(),error:S().optional(),toolResultExtra:lO.optional(),sourceToolAssistantUUID:S().optional(),askQuestionAnswers:Xa(S(),S()).optional()}),A({...On,kind:ee("attachment_memories"),memories:_e(cO)}),A({...On,kind:ee("permission_request"),requestId:S(),tool:S(),input:to(),toolUseId:S().optional()}),A({...On,kind:ee("ask_user_question"),toolUseId:S(),questions:_e(bN)}),A({...On,kind:ee("turn_end")}),A({...On,kind:ee("subagent_progress"),toolUseId:S(),agentId:S(),status:Xe(["started","running","completed","failed"]),description:S().optional(),lastToolName:S().optional(),prompt:S().optional(),stats:A({durationMs:G().int().nonnegative().optional(),tokens:G().int().nonnegative().optional(),toolUseCount:G().int().nonnegative().optional()}).optional()}),A({...On,kind:ee("error"),message:S()}),A({...On,kind:ee("meta_update"),patch:JL}),A({...On,kind:ee("meta-text"),text:S(),metaSource:Xe(["cc","owner"]).optional()})]);A({cwd:S().min(1).optional(),tool:S().optional(),label:S().optional(),model:S().optional(),permissionMode:S().optional(),effort:S().optional(),iconKey:S().optional(),forkedFromSessionId:S().min(1).optional(),ephemeral:Ne().optional(),ownerPersonaId:S().min(1).optional()}).refine(e=>e.cwd!=null||e.ownerPersonaId!=null,{message:"cwd 与 ownerPersonaId 至少传一个"});A({cwd:S().min(1),tool:S().min(1),toolSessionId:S().min(1),label:S().optional(),iconKey:S().optional(),createdAt:S().datetime(),updatedAt:S().datetime(),ownerPersonaId:S().min(1).optional()});A({originOnly:Ne().optional(),ownerPersonaId:S().min(1).optional(),limit:G().int().positive().optional(),offset:G().int().nonnegative().optional()});A({sessionId:S().min(1)});A({sessionId:S().min(1),patch:A({label:S().optional(),model:S().optional(),permissionMode:S().optional(),effort:S().optional(),cwd:S().optional(),iconKey:S().optional(),ephemeral:ee(!1).optional()})});A({sessionId:S().min(1),text:S()});A({sessionId:S().min(1),userMessageId:S().min(1),dryRun:Ne().optional()});A({canRewind:Ne(),error:S().optional(),filesChanged:_e(S()).optional(),insertions:G().int().nonnegative().optional(),deletions:G().int().nonnegative().optional()});A({sessionId:S().min(1),userMessageId:S().min(1)});const dO=A({oldStart:G().int().nonnegative(),oldLines:G().int().nonnegative(),newStart:G().int().nonnegative(),newLines:G().int().nonnegative(),lines:_e(S())}),hO=A({filePath:S().min(1),hunks:_e(dO),insertions:G().int().nonnegative(),deletions:G().int().nonnegative(),status:Xe(["modified","added","deleted"]).optional()});A({canRewind:Ne(),error:S().optional(),files:_e(hO),totalInsertions:G().int().nonnegative(),totalDeletions:G().int().nonnegative()});A({userMessageIds:_e(S())});A({sessionId:S().min(1),toolSessionId:S().min(1)});A({cwd:S().min(1),toolSessionId:S().min(1),messageUuid:S().min(1),targetCwd:S().min(1).optional()});A({forkedToolSessionId:S().min(1),forkedFilePath:S().min(1)});A({sessionId:S().min(1),toolSessionId:S().min(1),jsonlPath:S().optional()});A({sessionId:S().min(1),afterSeq:G().int().min(-1)});A({sessionId:S().min(1),permissionRequestId:S().min(1),allow:Ne(),permanent:Ne().optional(),pattern:S().optional()});A({projectPath:S().min(1)});A({sessionId:S().min(1),limit:G().int().positive().max(5e3).optional(),offset:G().int().nonnegative().optional(),slim:Ne().optional()});A({cwd:S().min(1),toolSessionId:S().min(1)});A({cwd:S().min(1),toolSessionId:S().min(1),subagentId:S().min(1)});A({cwd:S().min(1).optional(),path:S().optional(),showHidden:Ne().optional()});A({cwd:S().min(1),path:S().min(1)});A({cwd:S().min(1),tool:S().optional()});A({name:S().min(1),source:Xe(KL),path:S().optional(),description:S().optional(),plugin:S().optional()});const fO=A({name:S().min(1),source:Xe(GL),path:S().optional(),description:S().optional(),whenToUse:S().optional(),plugin:S().optional()});A({cwd:S().min(1),tool:S().optional()});A({agents:_e(fO)});A({sessionId:S().optional()});A({sessionId:S().min(1).optional()});A({sessionId:S().min(1),pinned:Ne()});A({type:ee("peerSession:upsert:ok")});A({sessionId:S().min(1)});A({type:ee("peerSession:remove:ok")});A({orderedIds:_e(S().min(1)).min(1)});A({cwd:S().min(1)});A({isGitRoot:Ne(),gitRoot:S().nullable()});A({cwd:S().min(1)});A({branch:S().nullable()});A({cwd:S().min(1)});A({branches:_e(S()),head:S().nullable()});A({}).optional();const pO=A({cwd:S().min(1),updatedAt:S().min(1)});A({dirs:_e(pO)});A({type:ee("session:question"),sessionId:S().min(1),toolUseId:S().min(1),requestId:S().min(1),questions:_e(bN).min(1)});A({type:ee("session:question:cleared"),sessionId:S().min(1),toolUseId:S().min(1),answers:Xa(S(),S()).optional()});A({sessionId:S().min(1),toolUseId:S().min(1),answers:Xa(S(),S())});A({ok:ee(!0)});A({sessionId:S().min(1),toolUseId:S().min(1)});A({ok:ee(!0)});const wN=A({name:S().min(1),version:S().min(1),instanceId:S().min(1),deviceLabel:S().transform(e=>e.trim().slice(0,64)).optional()});A({type:ee("auth"),token:S().min(1),scheme:ee("bearer").optional(),clientInfo:wN.optional()});A({type:ee("auth:ok"),version:S().min(1).optional(),protocolVersion:G().int().nonnegative().optional()});const mO=A({clientId:S().min(1),connectedAt:G().int().nonnegative(),self:Ne(),clientInfo:wN.optional()});A({type:ee("device:connections:ok"),connections:_e(mO)});A({type:ee("tunnel:ready"),url:S().min(1),subdomain:S().min(1)});A({type:ee("tunnel:exited"),code:G().int().nullable(),subdomain:S().nullable(),url:S().nullable()});A({type:ee("tunnel:unavailable"),reason:S().min(1),failedAt:S().min(1)});const gO=A({sessionId:S().min(1),status:YL,freshSpawn:Ne(),pendingPermissionRequestIds:_e(S().min(1)),pendingQuestionToolUseIds:_e(S().min(1))});A({type:ee("info"),version:S(),protocolVersion:G(),hostname:S(),os:S(),tools:_e(A({id:S(),available:Ne()})),runningSessions:_e(gO),tokenRole:Xe(SL).optional(),isLoopback:Ne().optional(),httpBaseUrl:S().optional(),httpToken:S().optional(),daemonSource:Xe(["ota","packaged"]).optional(),globalCliVersion:S().nullable().optional()});const vO=6173,xO=6272,Ya=/^[a-z][a-z0-9-]{0,39}$/,iu=A({name:S().regex(Ya,{message:"kebab-case, 小写字母开头,只允许小写字母 / 数字 / -,最长 40 字符"}),port:G().int().min(vO).max(xO),createdAt:S().datetime(),devCommand:S().min(1),prodUrl:S().url().optional(),readyPattern:S().optional(),publishJob:A({jobId:S().min(1),stage:Xe(["build","deploy","verify"]),startedAt:G().int().nonnegative()}).optional()}),_O=["install-pending","installing","starting-dev-server","running","stopped","failed"],SN=Xe(_O),Vx=iu.extend({isRunning:Ne(),boundSessionId:S().nullable(),stage:SN.optional(),stageReason:S().optional(),publishJob:A({jobId:S().min(1),stage:Xe(["build","deploy","verify"]),startedAt:G().int().nonnegative(),status:Xe(["in-flight","interrupted"])}).optional()});A({}).strict();A({projects:_e(Vx)}).strict();A({sessionId:S().min(1)}).strict();A({project:Vx.nullable()}).strict();A({sessionId:S().min(1),name:S().min(1)}).strict();A({project:iu}).strict();A({name:S()}).strict();A({}).strict();A({name:S(),newPort:G().int()}).strict();A({project:iu}).strict();A({name:S().regex(Ya),url:S().url()}).strict();A({project:iu}).strict();A({sessionId:S().min(1),force:Ne().optional()}).strict();A({project:iu}).strict();const yO=["installing","failed"];A({sessionId:S().min(1),stage:Xe(yO),reason:S().optional()}).strict();A({ok:ee(!0)}).strict();A({sessionId:S().min(1)}).strict();A({ok:ee(!0)}).strict();A({type:ee("appBuilder:project-updated"),project:Vx,stage:SN,stageReason:S().optional()}).strict();A({name:S().regex(Ya)});A({jobId:S().min(1),status:Xe(["started","already-publishing"])}).strict();A({name:S().regex(Ya)});A({ok:ee(!0)}).strict();A({type:ee("appBuilder:publish-progress"),name:S().regex(Ya),jobId:S().min(1),stage:Xe(["build","deploy","verify"]),status:Xe(["started","completed"])}).strict();A({type:ee("appBuilder:publish-failed"),name:S().regex(Ya),jobId:S().min(1),stage:Xe(["build","deploy","verify","unknown"]),errorSummary:S()}).strict();A({});A({method:S().min(1).optional()});const bO=["allowed","conditional","denied"],wO=Xe(bO),SO=A({name:S().min(1),status:wO,description:S().min(1),args:_e(A({name:S(),required:Ne()})).nullable(),argsSchema:Xa(to()).optional(),reason:S().optional()});A({type:ee("meta:methods"),methods:_e(SO)});const Cb=1,kO=["daemon","main","renderer"],CO=Xe(kO),EO=["debug","info","warn","error"],NO=Xe(EO);A({ts:G().int(),source:CO,level:NO,msg:S(),ownerPrincipalId:S(),deviceId:S(),appVersion:S(),daemonVersion:S().optional(),os:S(),meta_json:S().optional(),sessionId:S().optional()});A({v:ee(1),visitorId:S().min(1),displayName:S(),provider:S(),iat:G(),exp:G()});const TO=A({visitorId:S(),displayName:S(),avatarUrl:S().optional(),provider:S(),firstSeen:G(),lastSeen:G()});A({visitors:_e(TO)});const PO=/<system-reminder>此消息来自飞书群成员 (.+?)<\/system-reminder>\s*$/,IO=new Set(["localhost","127.0.0.1","0.0.0.0","::1"]);let pi=null;function RO(){if(pi!==null)return pi;if(typeof window>"u")return pi=!1,!1;if(IO.has(window.location.hostname)||window.location.protocol==="file:")return pi=!0,!0;if(new URLSearchParams(window.location.search).get("debug")==="1"){pi=!0;try{sessionStorage.setItem("debug","1")}catch{}}else try{pi=sessionStorage.getItem("debug")==="1"}catch{pi=!1}return pi}function Re(e,...t){RO()&&console.log(`[${e}][${new Date().toISOString()}]`,...t)}function Gu(e){if(!e)return"<none>";let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return`<len:${e.length} hash:${(t>>>0).toString(16)}>`}const MO=e=>{const t=[1e3,2e3,4e3,8e3,16e3,3e4];return t[Math.min(e,t.length-1)]},AO=new Set(["auth:ok","pong","error"]),Eb=new Set(gN.filter(e=>!AO.has(e)));let jO=0;const Nb=()=>`r${++jO}`;function DO(e){let t=e.url,n=e.authToken,r=e.selfIdentity;const i=e.clientInfo,s=e.requestTimeoutMs??3e4,o=e.pingIntervalMs??3e4,a=e.watchdogMs??6e4,l=e.authTimeoutMs??1e4,c=e.backoffMs??MO;let u=null,d=!1,f=0,p=null,m=null,v=null,y=null,x=!1,_="disconnected";const b=new Map,w=new Map;let k=null;const C=(B,E)=>{var H;B==="ready"&&(k=E),(H=w.get(B))==null||H.forEach(q=>{try{q(E)}catch{}})},N=B=>{_!==B&&(_=B,C("status",B))},T=(B,E)=>{const H=w.get(B)??new Set;if(H.add(E),w.set(B,H),B==="ready"&&k!==null)try{E(k)}catch{}return()=>H.delete(E)},L=()=>{m&&(clearInterval(m),m=null),v&&(clearTimeout(v),v=null),y&&(clearTimeout(y),y=null)},P=()=>{v&&clearTimeout(v),v=setTimeout(()=>{try{u==null||u.close(4e3,"pong watchdog")}catch{}},a)},O=()=>{m&&clearInterval(m),m=setInterval(()=>{(u==null?void 0:u.readyState)===1&&u.send(JSON.stringify({type:"ping",requestId:Nb()}))},o),P()},I=B=>{for(const[,E]of b)clearTimeout(E.timer),E.reject(new Error(B));b.clear()},R=[],D=()=>{if(R.length===0)return;const B=R.splice(0);for(const E of B)(u==null?void 0:u.readyState)===1&&!x?E.doSend():(clearTimeout(E.timer),E.reject(new Error("NOT_CONNECTED")))},z=B=>{if(R.length===0)return;const E=R.splice(0);for(const H of E)clearTimeout(H.timer),H.reject(new Error(B))},$=()=>{if(d)return;const B=c(f);B<0||(C("daemon:reconnecting",{attempt:f+1,nextDelayMs:B,scheduledAt:Date.now()}),p&&clearTimeout(p),p=setTimeout(()=>{f+=1,j()},B))},F=B=>{P();const E=String(B.type??"");if(E==="auth:ok"){Re("daemon-client","auth:ok received → connected",{url:t}),y&&(clearTimeout(y),y=null),x=!1,f=0,N("connected"),C("daemon:connected",{url:t}),O(),D();return}if(E==="pong")return;if(E==="ready"){const q=Number(B.protocolVersion??-1);q!==Cb&&C("daemon:version-mismatch",{daemonProtocol:q,supportedProtocol:Cb}),C("ready",B);return}const H=B.requestId;if(typeof H=="string"&&b.has(H)){const q=b.get(H);if(b.delete(H),clearTimeout(q.timer),E==="error"){const M=String(B.code??"ERR"),re=String(B.message??"unknown");q.reject(new Error(`${M}: ${re}`))}else Eb.has(E)&&C(E,B),q.resolve(B);return}Eb.has(E)&&C(E,B)},j=()=>{p&&(clearTimeout(p),p=null),Re("daemon-client","connect →",{url:t,token:Gu(n),attempt:f}),N("connecting");let B;try{B=new WebSocket(t)}catch(E){N("disconnected"),C("daemon:disconnected",{reason:(E==null?void 0:E.message)??"ws constructor failed"}),$();return}u=B,x=!!n,B.onopen=()=>{if(B!==u){Re("daemon-client","onopen → stale (replaced before opened), ignore");return}if(n){Re("daemon-client","onopen → send auth frame",{token:Gu(n)});const E={type:"auth",token:n};r!=null&&r.principalId&&(E.selfPrincipalId=r.principalId),r!=null&&r.displayName&&(E.selfDisplayName=r.displayName),i&&(E.clientInfo=i),B.send(JSON.stringify(E)),y=setTimeout(()=>{try{B.close(4001,"auth handshake timeout")}catch{}},l)}else Re("daemon-client","onopen → no token, treat as connected (daemon authMode=none)"),f=0,N("connected"),C("daemon:connected",{url:t}),O(),D()},B.onclose=E=>{if(B!==u){Re("daemon-client","onclose → stale, ignore",{code:E.code,reason:E.reason});return}const H=E.reason||(E.code===1008?"auth failed":`close ${E.code}`);if(Re("daemon-client","onclose →",{code:E.code,reason:H,awaitingAuth:x,manualStop:d}),L(),I(`connection closed: ${H}`),u=null,E.code===4401?N("revoked"):N("disconnected"),C("daemon:disconnected",{reason:H}),E.code===1008||E.code===4401){z(`connection closed: ${H}`);return}d?z(`connection closed: ${H}`):$()},B.onerror=()=>{},B.onmessage=E=>{if(B!==u)return;let H;try{H=JSON.parse(String(E.data))}catch{return}F(H)}};return{start(){d=!1,f=0,j()},stop(){d=!0,p&&(clearTimeout(p),p=null),L();try{u==null||u.close(1e3,"shutdown")}catch{}u=null,I("shutdown"),z("shutdown"),N("disconnected")},switchProfile(B){Re("daemon-client","switchProfile →",{url:B.url,token:Gu(B.authToken)},"prev:",{url:t,token:Gu(n)}),t=B.url,n=B.authToken,B.selfIdentity!==void 0&&(r=B.selfIdentity),f=0,d=!0,p&&(clearTimeout(p),p=null),L(),I("switch profile"),z("switch profile");try{u==null||u.close(1e3,"switch profile")}catch{}u=null,d=!1,j()},request(B,E){return new Promise((H,q)=>{const M=Nb(),re=setTimeout(()=>{b.delete(M);const V=R.findIndex(pe=>pe.timer===re);V>=0&&R.splice(V,1),q(new Error(`request timeout: ${B}`))},s),oe=()=>{b.set(M,{resolve:V=>H(V),reject:q,timer:re}),u.send(JSON.stringify({...E,type:B,requestId:M}))};(u==null?void 0:u.readyState)===1&&!x?oe():d||u==null&&p==null?(clearTimeout(re),q(new Error("NOT_CONNECTED"))):R.push({doSend:oe,reject:q,timer:re})})},on:T,get isOpen(){return(u==null?void 0:u.readyState)===1&&!x},get url(){return t},getStatus(){return _}}}function LO(e){if(!e)return"<none>";let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return`<len:${e.length} hash:${(t>>>0).toString(16)}>`}function OO(e){return e?{id:e.id,mode:e.mode,url:e.url,token:LO(e.token),name:e.name}:null}function Xu(e){return e?Array.isArray(e)?e.map(OO):{_notArray:typeof e,_value:e}:null}function Tb(e){return e==null?null:typeof e=="object"&&"value"in e?e.value:e}const BO="ws://127.0.0.1:18790",Pb="daemon:profiles",Ib="daemon:active-profile-id";function zO(){return Math.random().toString(36).slice(2,10)}function $O(e){const t=e.trim(),n=t.indexOf("#");if(n<0)return{url:t};const r=t.slice(0,n),i=new URLSearchParams(t.slice(n+1)).get("token")??void 0;return{url:r,token:i}}function FO(e){if(!e||typeof e!="object")return!1;const t=e;return typeof t.id=="string"&&typeof t.name=="string"&&(t.mode==="localhost"||t.mode==="remote")&&typeof t.url=="string"&&(t.token===void 0||typeof t.token=="string")}function kN(e){let t={profiles:[],activeId:null},n=!1,r=null;const i=new Set,s=()=>{for(const l of i)l(t)},o=async()=>{Re("profile-store","persist →",Xu(t.profiles),"active:",t.activeId),await e.kv.set(Pb,t.profiles),await e.kv.set(Ib,t.activeId)},a=async()=>{if(!n){if(r){await r;return}r=(async()=>{var l;try{let c=null;try{const d=await e.kv.get(Pb);c=Tb(d)}catch{c=null}let u=null;try{const d=await e.kv.get(Ib);u=Tb(d)??null}catch{u=null}if(Re("profile-store","ensureLoaded read kv →","profiles:",Xu(c),"activeId:",u),Array.isArray(c)&&c.length>0){const d=c.filter(FO),f=u&&d.some(p=>p.id===u)?u:((l=d[0])==null?void 0:l.id)??null;t={profiles:d,activeId:f},n=!0,Re("profile-store","ensureLoaded → use kv profiles",Xu(d),"active:",f);return}t={profiles:[{id:"default",name:"本机",mode:"localhost",url:BO}],activeId:"default"},Re("profile-store","ensureLoaded → fallback synthesized default (NO token)",Xu(t.profiles)),n=!0,await o()}finally{r=null}})(),await r}};return{async load(){return await a(),s(),t},async snapshot(){return await a(),t},async upsert(l){var y;await a();let c=l.url,u=l.token;if(c&&c.includes("#")){const x=$O(c);c=x.url,!u&&x.token&&(u=x.token)}const d=l.id?t.profiles.find(x=>x.id===l.id):void 0,f=u!=null&&u.trim()?u.trim():d==null?void 0:d.token;if(l.mode==="remote"&&!f)throw new Error("remote mode requires token");const p=l.id??zO(),m={id:p,name:((y=l.name)==null?void 0:y.trim())||(d==null?void 0:d.name)||(l.mode==="remote"?"远程":"本机"),mode:l.mode,url:c.trim(),token:f};return t={profiles:[...t.profiles.filter(x=>x.id!==p),m],activeId:p},await o(),s(),m},async delete(l){var d;await a();const c=t.profiles.filter(f=>f.id!==l);let u=t.activeId;u===l&&(u=((d=c[0])==null?void 0:d.id)??null),t={profiles:c,activeId:u},await o(),s()},async activate(l){await a(),t.profiles.some(c=>c.id===l)&&(t={...t,activeId:l},await o(),s())},subscribe(l){return i.add(l),()=>i.delete(l)},getActive(){return n?t.profiles.find(l=>l.id===t.activeId)??null:null}}}const Rb="clawd.client-instance-id";let HO={name:"clawd-web",version:"unknown"};function UO(){let e=null;try{e=localStorage.getItem(Rb),e||(e=crypto.randomUUID(),localStorage.setItem(Rb,e))}catch{e=e??crypto.randomUUID()}return{...HO,instanceId:e}}function Mb(e){if(!e)return"<none>";let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return`<len:${e.length} hash:${(t>>>0).toString(16)}>`}const CN=g.createContext(null);function WO({host:e,children:t}){const[n,r]=g.useState(null),i=g.useMemo(()=>async()=>{const s=kN(e),o=await s.load(),a=o.profiles.find(c=>c.id===o.activeId)??o.profiles[0];if(!a)throw new Error("DaemonProvider: profile store has no profiles after load");return Re("daemon-context","bootstrap → createDaemonClient",{id:a.id,url:a.url,token:Mb(a.token)}),{client:DO({url:a.url,authToken:a.token,clientInfo:UO()}),store:s}},[e]);return g.useEffect(()=>{let s=!0,o=null,a=null;return i().then(l=>{s&&(l.client.start(),o=l,r(l),a=l.store.subscribe(()=>{const c=l.store.getActive();if(!c){Re("daemon-context","subscribe → no active profile, skip switchProfile");return}Re("daemon-context","subscribe → switchProfile",{id:c.id,url:c.url,token:Mb(c.token)}),l.client.switchProfile({url:c.url,authToken:c.token})}))}),()=>{s=!1,a==null||a(),o==null||o.client.stop()}},[i]),n?h.jsx(CN.Provider,{value:n,children:t}):null}function Bi(){const e=g.useContext(CN);if(!e)throw new Error("useDaemonClient must be used inside <DaemonProvider>");return e.client}function VO(){const e=Bi(),[t,n]=g.useState(void 0);return g.useEffect(()=>e.on("ready",i=>{const s=i.mode,o=s==="tui"?"tui":"sdk";Re("daemon-context","useDaemonMode ready.mode =",{rawMode:s,resolved:o}),n(o)}),[e]),t}const EN=g.createContext(null);function qO({cache:e,children:t}){return g.createElement(EN.Provider,{value:e},t)}function Co(){const e=g.useContext(EN);if(!e)throw new Error("useCache must be used inside <CacheProvider>");return e}function si(e){const t=Co(),n=g.useCallback(i=>t.observe(e,()=>i()),[t,e]),r=g.useCallback(()=>t.read(e),[t,e]);return g.useSyncExternalStore(n,r,r)}const NN={actionsLevel:"none",httpBaseUrl:null,httpToken:null},TN=g.createContext(NN);function Af(){return g.useContext(TN)}function KO(e){return e!=null&&e.httpBaseUrl?{actionsLevel:e.tokenRole==="owner"?"owner":"none",httpBaseUrl:e.httpBaseUrl,httpToken:e.httpToken??null}:NN}function GO(){const e=si("daemon-info");return g.useMemo(()=>KO(e),[e])}function XO({children:e}){const t=GO();return st.createElement(TN.Provider,{value:t},e)}function YO(e,t,n){if(!e.httpBaseUrl)return null;const r=encodeURIComponent(n);return`${e.httpBaseUrl}/session/${encodeURIComponent(t.sessionId)}/files?path=${r}`}function ZO(e){const t=new Map;return{observe(n,r){let i=t.get(n);i||(i={data:void 0,hasData:!1,listeners:new Set},t.set(n,i));const s=l=>r(l);i.listeners.add(s);const o=i.listeners.size===1;s(i.hasData?i.data:void 0),o&&e.onFirstObserver(n);let a=!1;return()=>{if(a)return;a=!0;const l=t.get(n);l&&(l.listeners.delete(s),l.listeners.size===0&&(t.delete(n),e.onLastObserver(n)))}},read(n){const r=t.get(n);return r!=null&&r.hasData?r.data:void 0},setData(n,r){const i=t.get(n);if(!i)return;const s=i.hasData?i.data:void 0,o=r(s);i.data=o,i.hasData=!0;for(const a of i.listeners)a(o)}}}function QO(){const e=[],t=new Map,n=r=>{for(const i of e)if(i.pattern.test(r))return i.source;return null};return{register(r,i){e.push({pattern:r,source:i})},activate(r){if(t.has(r))return;const i=n(r);if(!i)throw new Error(`no source registered for key: ${r}`);t.set(r,i.start(r))},deactivate(r){const i=t.get(r);i&&(t.delete(r),i())}}}function JO(e){return{request:(t,n)=>e.request(t,n),onFrame(t){const n=[];for(const r of gN)n.push(e.on(r,i=>t(r,i)));return()=>{for(const r of n)r()}},onConnect(t){return e.on("daemon:connected",()=>t())},get isConnected(){return e.isOpen}}}function PN(e){const t=(e??"claude")==="claude";return{rewind:t,subagents:t,tui:t,observe:t,fileSharing:t,fork:t}}const eB=e=>({tool:e,models:[{id:"",label:"Default",contextWindowSize:2e5,default:!0}],permissionModes:[{id:"",label:"Default"}],configSchema:[],features:PN(e)});function tB(e,t){return{start(n){const r=n.replace(/^capabilities\//,"");let i=!1;const s=async()=>{try{const a=await e.request("capabilities:get",{tool:r});if(i)return;t(n,()=>a)}catch{if(i)return;t(n,()=>eB(r))}},o=e.onConnect(()=>{s()});return s(),()=>{i=!0,o()}}}}function nB(e,t){return{start(n){let r=!1;const i=async()=>{try{const a=await e.request("session:list",void 0);if(r)return;t(n,()=>a.sessions??[])}catch{}},s=e.onFrame((a,l)=>{if(a==="session:info"){const c=l;if(c.chatId!==void 0)return;t(n,u=>[c,...(u??[]).filter(d=>d.sessionId!==c.sessionId)])}else if(a==="session:deleted"){const c=l;t(n,u=>(u??[]).filter(d=>d.sessionId!==c.sessionId))}}),o=e.onConnect(()=>{i()});return i(),()=>{r=!0,s(),o()}}}}const Mc={sessionId:null,events:[],lastSeq:-1,pendingPermissions:[],status:"idle",pendingQuestions:{}};function Gp(e,t){const n=t;if(n.kind==="permission_request"&&typeof n.requestId=="string"){if(e.some(i=>i.requestId===n.requestId))return e;const r={requestId:n.requestId,tool:typeof n.tool=="string"?n.tool:"",input:n.input,...typeof n.toolUseId=="string"&&n.toolUseId?{toolUseId:n.toolUseId}:{}};return[...e,r]}if(n.kind==="tool_result"&&typeof n.toolUseId=="string"&&n.toolUseId){const r=e.findIndex(i=>i.toolUseId===n.toolUseId);if(r>=0)return e.filter((i,s)=>s!==r)}return e}function IN(e,t,n){const r=n===void 0?e.sessionId:n;switch(t.type){case"session:change":return{...Mc,sessionId:t.sessionId};case"session:event":{if(!r||t.sessionId!==r)return e;const i=typeof t.event.seq=="number"?t.event.seq:-1,s=[...e.events,t.event],o=i>e.lastSeq?i:e.lastSeq,a=Gp(e.pendingPermissions,t.event);return{...e,events:s,lastSeq:o,pendingPermissions:a}}case"session:status":return!r||t.sessionId!==r?e:{...e,status:t.status};case"session:events":{if(!r||t.sessionId!==r)return e;const i=t.events.map(o=>o.event),s=i.reduce((o,a)=>Gp(o,a),[]);return{...e,sessionId:t.sessionId,events:i,lastSeq:t.latestSeq,pendingPermissions:s}}case"session:events:append":{if(!r||t.sessionId!==r)return e;const i=new Set;for(const c of e.events){const u=c.seq;typeof u=="number"&&i.add(u)}const s=[];for(const c of t.events)typeof c.seq=="number"&&(i.has(c.seq)||s.push(c.event));const o=t.latestSeq>e.lastSeq?t.latestSeq:e.lastSeq;if(s.length===0)return o===e.lastSeq?e:{...e,lastSeq:o};const a=[...e.events,...s].sort((c,u)=>{const d=c.seq??-1,f=u.seq??-1;return d-f}),l=s.reduce((c,u)=>Gp(c,u),e.pendingPermissions);return{...e,events:a,lastSeq:o,pendingPermissions:l}}case"permission:request":{if(!r||t.sessionId!==r||e.pendingPermissions.some(s=>s.requestId===t.requestId))return e;const i={requestId:t.requestId,tool:t.tool,input:t.input,...t.toolUseId?{toolUseId:t.toolUseId}:{}};return{...e,pendingPermissions:[...e.pendingPermissions,i]}}case"permission:clear":{if(!r||r!==t.sessionId)return e;const i=t.requestId,s=e.pendingPermissions.findIndex(c=>c.requestId===i),o=s>=0?e.pendingPermissions.filter((c,u)=>u!==s):e.pendingPermissions;if(e.events.length===0)return o===e.pendingPermissions?e:{...e,pendingPermissions:o};const a=e.events.length-1,l=e.events[a];return l.kind==="permission_request"&&l.requestId===i?{...e,pendingPermissions:o,events:e.events.slice(0,a)}:o===e.pendingPermissions?e:{...e,pendingPermissions:o}}case"session:question":return!r||t.sessionId!==r?e:{...e,pendingQuestions:{...e.pendingQuestions,[t.toolUseId]:{toolUseId:t.toolUseId,requestId:t.requestId,questions:t.questions}}};case"session:question:clear":{if(!r||t.sessionId!==r||!(t.toolUseId in e.pendingQuestions))return e;const{[t.toolUseId]:i,...s}=e.pendingQuestions;return{...e,pendingQuestions:s}}case"session:question:submitted":{if(!r||t.sessionId!==r)return e;const i=e.pendingQuestions[t.toolUseId];return i?{...e,pendingQuestions:{...e.pendingQuestions,[t.toolUseId]:{...i,submittedAnswers:t.answers}}}:e}case"session:rewound":return!r||t.sessionId!==r?e:{...e,pendingPermissions:[],status:"idle"};case"ready":{if(!r)return e;const i=t.runningSessions.find(o=>o.sessionId===r);if(i!=null&&i.freshSpawn)return{...Mc,sessionId:r};const s=(i==null?void 0:i.status)??"idle";return s===e.status?e:{...e,status:s}}case"daemon:disconnected":return{...e,pendingPermissions:[]};default:return e}}const rB="session/";function iB(e){return{sid:e.slice(rB.length)}}const sB=new Set(vN);function RN(e){return sB.has(e)}function Ab(e){return RN(e)?e:"idle"}function oB(e,t){return{start(n){const{sid:r}=iB(n);let i=!1,s=-1;const o=f=>{t(n,p=>IN(p??Mc,f,r))},a=async f=>{const p=f==="baseline"?-1:s;try{const m=await e.request("session:events",{sessionId:r,afterSeq:p});if(i)return;const v=m.events??[],y=m.latestSeq??-1;if(f==="baseline")o({type:"session:events",sessionId:r,events:v,latestSeq:y}),s=y;else{const x=m.bufferStartSeq??0,_=y<p||x>p+1;o({type:_?"session:events":"session:events:append",sessionId:r,events:v,latestSeq:y}),s=Math.max(s,y)}}catch{}},l=async()=>{try{const f=await e.request("info");if(i)return;o({type:"ready",runningSessions:(f.runningSessions??[]).map(p=>({sessionId:p.sessionId,freshSpawn:p.freshSpawn,status:Ab(p.status)}))})}catch{}},c=async()=>{try{await e.request("session:subscribe",{sessionId:r})}catch{}i||(await a(s<0?"baseline":"delta"),!i&&await l())},u=e.onFrame((f,p)=>{if(!i)if(f==="session:event"){const m=p;if(m.sessionId!==r)return;const v=m.event.seq;Re("session-events","push session:event",{sid:r,kind:m.event.kind,seq:v,lastSeqBefore:s}),o({type:"session:event",sessionId:m.sessionId,event:m.event}),typeof v=="number"&&v>s&&(s=v)}else if(f==="session:status"){const m=p;if(m.sessionId!==r)return;if(!RN(m.status)){Re("session-events","push session:status drop",{sid:r,status:m.status});return}Re("session-events","push session:status",{sid:r,status:m.status}),o({type:"session:status",sessionId:m.sessionId,status:m.status})}else if(f==="session:cleared"){if(p.sessionId!==r)return;Re("session-events","push session:cleared",{sid:r}),o({type:"session:change",sessionId:r}),s=-1}else if(f==="permission:request"){const m=p;if(m.sessionId!==r)return;o({type:"permission:request",sessionId:m.sessionId,requestId:m.requestId,tool:m.tool,input:m.input,...typeof m.toolUseId=="string"&&m.toolUseId?{toolUseId:m.toolUseId}:{}})}else if(f==="session:question"){const m=p;if(m.sessionId!==r)return;o({type:"session:question",sessionId:m.sessionId,toolUseId:m.toolUseId,requestId:m.requestId,questions:m.questions})}else if(f==="session:question:cleared"){const m=p;if(m.sessionId!==r)return;m.answers&&Object.keys(m.answers).length>0?o({type:"session:question:submitted",sessionId:m.sessionId,toolUseId:m.toolUseId,answers:m.answers}):o({type:"session:question:clear",sessionId:m.sessionId,toolUseId:m.toolUseId})}else if(f==="session:rewound"){const m=p;if(m.sessionId!==r)return;o({type:"session:rewound",sessionId:m.sessionId,userMessageId:m.userMessageId})}else f==="ready"&&o({type:"ready",runningSessions:(p.runningSessions??[]).map(v=>({sessionId:v.sessionId,freshSpawn:v.freshSpawn,status:Ab(v.status)}))})}),d=e.onConnect(()=>{c()});return e.isConnected&&c(),()=>{i=!0,u(),d(),e.request("session:unsubscribe",{sessionId:r}).catch(()=>{})}}}}const aB=new Set(["tunnel:ready","tunnel:exited","tunnel:unavailable"]);function lB(e,t){return{start(n){let r=!1;const i=async()=>{try{const a=await e.request("info",void 0);if(r)return;t(n,()=>a)}catch{}},s=e.onConnect(()=>{i()}),o=e.onFrame(a=>{aB.has(a)&&i()});return i(),()=>{r=!0,s(),o()}}}}function cB(){return{start(){return()=>{}}}}function uB(e,t){return{start(n){let r=!1;const i=async()=>{try{const o=await e.request("persona:list",{});if(r)return;t(n,()=>o.personas??[])}catch{}},s=e.onConnect(()=>{i()});return i(),()=>{r=!0,s()}}}}function dB(e){const t=JO(e),n=QO();let r=null;const i=(o,a)=>{r==null||r.setData(o,a)};n.register(/^capabilities\//,tB(t,i)),n.register(/^sessions$/,nB(t,i)),n.register(/^session\//,oB(t,i)),n.register(/^personas$/,uB(t,i)),n.register(/^persona-detail\//,cB()),n.register(/^daemon-info$/,lB(t,i));const s=ZO({onFirstObserver:o=>{o&&n.activate(o)},onLastObserver:o=>{o&&n.deactivate(o)}});return r=s,{cache:s,channel:t}}class qx{constructor(t){this.client=t}info(){return this.client.request("info")}attachmentSignUrl(t){return this.client.request("attachment.signUrl",t)}attachmentGroupAdd(t,n,r){return this.client.request("attachment.groupAdd",{sessionId:t,relPath:n,...r?{label:r}:{}})}attachmentGroupRemove(t,n){return this.client.request("attachment.groupRemove",{sessionId:t,relPath:n})}attachmentGroupList(t){return this.client.request("attachment.groupList",{sessionId:t})}sessionCreate(t){return this.client.request("session:create",t)}appBuilderListProjects(){return this.client.request("appBuilder:listProjects",{})}appBuilderGetProject(t){return this.client.request("appBuilder:getProject",{sessionId:t})}appBuilderUpdateProjectPort(t,n){return this.client.request("appBuilder:updateProjectPort",{name:t,newPort:n})}appBuilderStartDevServer(t,n){return this.client.request("appBuilder:startDevServer",{sessionId:t,...n!=null&&n.force?{force:!0}:{}})}appBuilderStopDevServer(t){return this.client.request("appBuilder:stopDevServer",{sessionId:t})}appBuilderPublish(t){return this.client.request("appBuilder:publish",{name:t})}appBuilderDismissPublishJob(t){return this.client.request("appBuilder:dismissPublishJob",{name:t})}sessionList(){return this.client.request("session:list")}sessionGet(t){return this.client.request("session:get",{sessionId:t})}sessionUpdate(t,n){return this.client.request("session:update",{sessionId:t,patch:n})}sessionDelete(t){return this.client.request("session:delete",{sessionId:t})}sessionSend(t,n){return this.client.request("session:send",{sessionId:t,text:n})}sessionStop(t){return this.client.request("session:stop",{sessionId:t})}sessionInterrupt(t){return this.client.request("session:interrupt",{sessionId:t})}sessionRewind(t){return this.client.request("session:rewind",t)}sessionRewindableMessageIds(t){return this.client.request("session:rewindable-message-ids",{sessionId:t})}sessionRewindDiff(t){return this.client.request("session:rewind-diff",t)}sessionNew(t){return this.client.request("session:new",{sessionId:t})}sessionFork(t){return this.client.request("session:fork",t)}sessionResume(t,n){return this.client.request("session:resume",{sessionId:t,toolSessionId:n})}sessionObserve(t){return this.client.request("session:observe",t)}sessionEvents(t,n){return this.client.request("session:events",{sessionId:t,afterSeq:n})}sessionSubscribe(t){return this.client.request("session:subscribe",{sessionId:t})}sessionUnsubscribe(t){return this.client.request("session:unsubscribe",{sessionId:t})}pinSession(t,n){return this.client.request("session:pin",{sessionId:t,pinned:n})}markSessionRead(t){return this.client.request("session:markRead",{sessionId:t})}reorderPins(t){return this.client.request("session:reorderPins",{orderedIds:t})}peerSessionUpsert(t){return this.client.request("peerSession:upsert",t)}peerSessionRemove(t){return this.client.request("peerSession:remove",{sessionId:t})}permissionRespond(t){return this.client.request("permission:respond",t)}answerQuestion(t){return this.client.request("session:answerQuestion",t)}cancelQuestion(t){return this.client.request("session:cancelQuestion",t)}historyProjects(){return this.client.request("history:projects")}historyList(t){return this.client.request("history:list",{projectPath:t})}historyRead(t){return this.client.request("history:read",t)}historySubagents(t){return this.client.request("history:subagents",t)}historySubagentRead(t){return this.client.request("history:subagent-read",t)}listRecentDirs(){return this.client.request("history:recentDirs",{})}getGitRoot(t){return this.client.request("git:root",{cwd:t})}getGitBranch(t){return this.client.request("git:branch",{cwd:t})}listGitBranches(t){return this.client.request("git:branches",{cwd:t})}personaCreate(t){return this.client.request("persona:create",t)}personaList(){return this.client.request("persona:list",{})}personaGet(t){return this.client.request("persona:get",{personaId:t})}personaUpdate(t,n){return this.client.request("persona:update",{personaId:t,patch:n})}personaDelete(t){return this.client.request("persona:delete",{personaId:t})}larkBotBindManual(t,n,r){return this.client.request("larkBot:bindManual",{personaId:t,appId:n,appSecret:r})}larkBotUnbind(t){return this.client.request("larkBot:unbind",{personaId:t})}larkBotStatus(t){return this.client.request("larkBot:status",{personaId:t})}visitorList(){return this.client.request("visitor:list",{})}workspaceList(t={}){return this.client.request("workspace:list",t)}workspaceRead(t){return this.client.request("workspace:read",t)}skillsList(t,n){return this.client.request("skills:list",{cwd:t,...n?{tool:n}:{}})}agentsList(t,n){return this.client.request("agents:list",{cwd:t,...n?{tool:n}:{}})}capabilitiesGet(t="claude"){return this.client.request("capabilities:get",{tool:t})}shiftList(){return this.client.request("shift:list")}}function hB(e){const[t,n]=g.useState(e.isOpen?{kind:"connected",url:""}:{kind:"connecting"});return g.useEffect(()=>{const r=e.on("ready",l=>{const c=l;n(u=>({kind:"connected",url:u.kind==="connected"?u.url:"",mode:u.kind==="connected"?u.mode:void 0,daemonVersion:c.version,protocolVersion:c.protocolVersion,daemonSource:c.daemonSource,globalCliVersion:c.globalCliVersion}))}),i=e.on("daemon:connected",l=>{const c=l;n(u=>({kind:"connected",url:c.url,mode:c.mode,daemonVersion:u.kind==="connected"?u.daemonVersion:void 0,protocolVersion:u.kind==="connected"?u.protocolVersion:void 0,daemonSource:u.kind==="connected"?u.daemonSource:void 0,globalCliVersion:u.kind==="connected"?u.globalCliVersion:void 0}))}),s=e.on("daemon:disconnected",l=>{const c=(l==null?void 0:l.reason)??"";/auth failed|auth timeout|auth required|auth handshake timeout/i.test(c)?n({kind:"auth-failed",reason:c}):n({kind:"disconnected",reason:c})}),o=e.on("daemon:reconnecting",l=>{const c=l;n({kind:"reconnecting",attempt:c.attempt,nextDelayMs:c.nextDelayMs,scheduledAt:c.scheduledAt??Date.now()})}),a=e.on("daemon:version-mismatch",l=>{const c=l;n({kind:"version-mismatch",daemonProtocol:c.daemonProtocol,supportedProtocol:c.supportedProtocol})});return()=>{r(),i(),s(),o(),a()}},[e]),t}function fB(e){const t=Co(),n=si(e.kind==="connected"?"sessions":""),r=g.useCallback(async()=>{t.setData("sessions",i=>i??[])},[t]);return{sessions:n??[],loading:!1,loaded:n!==void 0,error:null,refresh:r}}function Za(){const e=Bi();return g.useMemo(()=>new qx(e),[e])}function MN(e){return{personaId:e.personaId,label:e.label,model:e.model,tool:e.tool,iconKey:e.iconKey,public:e.public,createdAt:e.createdAt,updatedAt:e.updatedAt}}function AN(){const e=Co(),t=Za(),n=si("personas")??[],r=g.useMemo(()=>n.map(s=>MN(s)),[n]),i=g.useCallback(async()=>{const s=await t.personaList();e.setData("personas",()=>s.personas??[])},[t,e]);return{personas:r,raw:n,loaded:si("personas")!==void 0,refresh:i}}function jN(e){const{raw:t}=AN(),n=Co(),r=Za(),i=e?t.find(a=>a.personaId===e)??null:null,s=i?MN(i):null,o=g.useCallback(async()=>{if(!e)return;const a=await r.personaList();n.setData("personas",()=>a.personas??[])},[e,r,n]);return{persona:s,raw:i,loaded:!!s,refresh:o}}function pB(e){const t=Za(),n=Co(),r=e?`persona-detail/${e}`:"",i=si(r),s=g.useCallback(async()=>{const o={personality:"",skills:[],plugins:[],sandboxSettings:null};if(!e)return o;const a=await t.personaGet(e);let l;if("persona"in a&&a.persona===null)l=o;else{const c=a;l={personality:c.personality??"",skills:c.skills??[],plugins:c.plugins??[],sandboxSettings:c.sandboxSettings??null}}return n.setData(r,()=>l),l},[t,n,e,r]);return g.useEffect(()=>{e&&s()},[e,s]),{personality:(i==null?void 0:i.personality)??"",skills:(i==null?void 0:i.skills)??[],plugins:(i==null?void 0:i.plugins)??[],sandboxSettings:(i==null?void 0:i.sandboxSettings)??null,loaded:i!==void 0,refresh:s}}function DN(){const e=Co(),t=Za();return g.useCallback(async()=>{const n=await t.personaList();e.setData("personas",()=>n.personas??[])},[e,t])}function mB(){const e=Za(),t=DN();return g.useCallback(async(n,r)=>{const i=await e.personaUpdate(n,r);return await t(),i},[e,t])}function gB(){const e=Za(),t=DN();return g.useCallback(async n=>{await e.personaDelete(n),await t()},[e,t])}const jb="clawd:sidebar:tree-collapsed";function vB(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function xB(e){const t=vB(e);if(!Array.isArray(t))return new Set;const n=new Set;for(const r of t)typeof r=="string"&&n.add(r);return n}function _B(){const e=Ix(),[t,n]=g.useState(()=>new Set),r=g.useRef(t);r.current=t,g.useEffect(()=>{let l=!1;return(async()=>{try{const c=await e.kv.get(jb);if(l)return;n(xB(c))}catch{}})(),()=>{l=!0}},[e]);const i=g.useCallback(l=>{e.kv.set(jb,[...l]).catch(()=>{})},[e]),s=g.useCallback(l=>r.current.has(l),[]),o=g.useCallback(l=>{n(c=>{const u=new Set(c);return u.has(l)?u.delete(l):u.add(l),i(u),u})},[i]),a=g.useCallback(l=>{n(c=>{let u=!1;const d=new Set;for(const f of c)l.has(f)?d.add(f):u=!0;return u?(i(d),d):c})},[i]);return{isCollapsed:s,toggle:o,prune:a}}const Kx=g.createContext(null);function yB(){const e=g.useContext(Kx);if(!e)throw new Error("SessionTreeCollapsedContext.Provider missing — wrap SessionTreeNode tree with <SessionTreeCollapsedContext.Provider value={useSessionTreeCollapsed()}>");return e}/**
96
96
  * @license lucide-react v0.577.0 - ISC
97
97
  *
98
98
  * This source code is licensed under the ISC license.
@@ -487,10 +487,10 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
487
487
  `)},cw=function(){var e=parseInt(document.body.getAttribute(ya)||"0",10);return isFinite(e)?e:0},j8=function(){g.useEffect(function(){return document.body.setAttribute(ya,(cw()+1).toString()),function(){var e=cw()-1;e<=0?document.body.removeAttribute(ya):document.body.setAttribute(ya,e.toString())}},[])},D8=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;j8();var s=g.useMemo(function(){return R8(i)},[i]);return g.createElement(M8,{styles:A8(s,!t,i,n?"":"!important")})},Mv=!1;if(typeof window<"u")try{var nd=Object.defineProperty({},"passive",{get:function(){return Mv=!0,!0}});window.addEventListener("test",nd,nd),window.removeEventListener("test",nd,nd)}catch{Mv=!1}var Fo=Mv?{passive:!1}:!1,L8=function(e){return e.tagName==="TEXTAREA"},nP=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!L8(e)&&n[t]==="visible")},O8=function(e){return nP(e,"overflowY")},B8=function(e){return nP(e,"overflowX")},uw=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=rP(e,r);if(i){var s=iP(e,r),o=s[1],a=s[2];if(o>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},z8=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},$8=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},rP=function(e,t){return e==="v"?O8(t):B8(t)},iP=function(e,t){return e==="v"?z8(t):$8(t)},F8=function(e,t){return e==="h"&&t==="rtl"?-1:1},H8=function(e,t,n,r,i){var s=F8(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=iP(e,a),m=p[0],v=p[1],y=p[2],x=v-y-s*m;(m||x)&&rP(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},rd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},dw=function(e){return[e.deltaX,e.deltaY]},hw=function(e){return e&&"current"in e?e.current:e},U8=function(e,t){return e[0]===t[0]&&e[1]===t[1]},W8=function(e){return`
488
488
  .block-interactivity-`.concat(e,` {pointer-events: none;}
489
489
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
490
- `)},V8=0,Ho=[];function q8(e){var t=g.useRef([]),n=g.useRef([0,0]),r=g.useRef(),i=g.useState(V8++)[0],s=g.useState(tP)[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=f8([e.lockRef.current],(e.shards||[]).map(hw),!0).filter(Boolean);return v.forEach(function(y){return y.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),v.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var a=g.useCallback(function(v,y){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!o.current.allowPinchZoom;var x=rd(v),_=n.current,b="deltaX"in v?v.deltaX:_[0]-x[0],w="deltaY"in v?v.deltaY:_[1]-x[1],k,C=v.target,N=Math.abs(b)>Math.abs(w)?"h":"v";if("touches"in v&&N==="h"&&C.type==="range")return!1;var T=window.getSelection(),L=T&&T.anchorNode,P=L?L===C||L.contains(C):!1;if(P)return!1;var O=uw(N,C);if(!O)return!0;if(O?k=N:(k=N==="v"?"h":"v",O=uw(N,C)),!O)return!1;if(!r.current&&"changedTouches"in v&&(b||w)&&(r.current=k),!k)return!0;var I=r.current||k;return H8(I,y,v,I==="h"?b:w)},[]),l=g.useCallback(function(v){var y=v;if(!(!Ho.length||Ho[Ho.length-1]!==s)){var x="deltaY"in y?dw(y):rd(y),_=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&U8(k.delta,x)})[0];if(_&&_.should){y.cancelable&&y.preventDefault();return}if(!_){var b=(o.current.shards||[]).map(hw).filter(Boolean).filter(function(k){return k.contains(y.target)}),w=b.length>0?a(y,b[0]):!o.current.noIsolation;w&&y.cancelable&&y.preventDefault()}}},[]),c=g.useCallback(function(v,y,x,_){var b={name:v,delta:y,target:x,should:_,shadowParent:K8(x)};t.current.push(b),setTimeout(function(){t.current=t.current.filter(function(w){return w!==b})},1)},[]),u=g.useCallback(function(v){n.current=rd(v),r.current=void 0},[]),d=g.useCallback(function(v){c(v.type,dw(v),v.target,a(v,e.lockRef.current))},[]),f=g.useCallback(function(v){c(v.type,rd(v),v.target,a(v,e.lockRef.current))},[]);g.useEffect(function(){return Ho.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",l,Fo),document.addEventListener("touchmove",l,Fo),document.addEventListener("touchstart",u,Fo),function(){Ho=Ho.filter(function(v){return v!==s}),document.removeEventListener("wheel",l,Fo),document.removeEventListener("touchmove",l,Fo),document.removeEventListener("touchstart",u,Fo)}},[]);var p=e.removeScrollBar,m=e.inert;return g.createElement(g.Fragment,null,m?g.createElement(s,{styles:W8(i)}):null,p?g.createElement(D8,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function K8(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const G8=w8(eP,q8);var c_=g.forwardRef(function(e,t){return g.createElement(Uf,Gr({},e,{ref:t,sideCar:G8}))});c_.classNames=Uf.classNames;var Av=["Enter"," "],X8=["ArrowDown","PageUp","Home"],sP=["ArrowUp","PageDown","End"],Y8=[...X8,...sP],Z8={ltr:[...Av,"ArrowRight"],rtl:[...Av,"ArrowLeft"]},Q8={ltr:["ArrowLeft"],rtl:["ArrowRight"]},cu="Menu",[Oc,J8,e9]=fT(cu),[To,oP]=No(cu,[e9,Hf,VT]),Wf=Hf(),aP=VT(),[t9,Po]=To(cu),[n9,uu]=To(cu),lP=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Wf(t),[l,c]=g.useState(null),u=g.useRef(!1),d=Mi(s),f=pT(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($T,{...a,children:h.jsx(t9,{scope:t,open:n,onOpenChange:d,content:l,onContentChange:c,children:h.jsx(n9,{scope:t,onClose:g.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})};lP.displayName=cu;var r9="MenuAnchor",u_=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Wf(n);return h.jsx(FT,{...i,...r,ref:t})});u_.displayName=r9;var d_="MenuPortal",[i9,cP]=To(d_,{forceMount:void 0}),uP=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=Po(d_,t);return h.jsx(i9,{scope:t,forceMount:n,children:h.jsx($i,{present:n||s.open,children:h.jsx(l_,{asChild:!0,container:i,children:r})})})};uP.displayName=d_;var vr="MenuContent",[s9,h_]=To(vr),dP=g.forwardRef((e,t)=>{const n=cP(vr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Po(vr,e.__scopeMenu),o=uu(vr,e.__scopeMenu);return h.jsx(Oc.Provider,{scope:e.__scopeMenu,children:h.jsx($i,{present:r||s.open,children:h.jsx(Oc.Slot,{scope:e.__scopeMenu,children:o.modal?h.jsx(o9,{...i,ref:t}):h.jsx(a9,{...i,ref:t})})})})}),o9=g.forwardRef((e,t)=>{const n=Po(vr,e.__scopeMenu),r=g.useRef(null),i=qt(t,r);return g.useEffect(()=>{const s=r.current;if(s)return ZT(s)},[]),h.jsx(f_,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Pe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),a9=g.forwardRef((e,t)=>{const n=Po(vr,e.__scopeMenu);return h.jsx(f_,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),l9=Dc("MenuContent.ScrollLock"),f_=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,y=Po(vr,n),x=uu(vr,n),_=Wf(n),b=aP(n),w=J8(n),[k,C]=g.useState(null),N=g.useRef(null),T=qt(t,N,y.onContentChange),L=g.useRef(0),P=g.useRef(""),O=g.useRef(0),I=g.useRef(null),R=g.useRef("right"),D=g.useRef(0),z=m?c_:g.Fragment,$=m?{as:l9,allowPinchZoom:!0}:void 0,F=B=>{var pe,Oe;const E=P.current+B,H=w().filter(ie=>!ie.disabled),q=document.activeElement,M=(pe=H.find(ie=>ie.ref.current===q))==null?void 0:pe.textValue,re=H.map(ie=>ie.textValue),oe=y9(re,E,M),V=(Oe=H.find(ie=>ie.textValue===oe))==null?void 0:Oe.ref.current;(function ie(Ae){P.current=Ae,window.clearTimeout(L.current),Ae!==""&&(L.current=window.setTimeout(()=>ie(""),1e3))})(E),V&&setTimeout(()=>V.focus())};g.useEffect(()=>()=>window.clearTimeout(L.current),[]),vT();const j=g.useCallback(B=>{var H,q;return R.current===((H=I.current)==null?void 0:H.side)&&w9(B,(q=I.current)==null?void 0:q.area)},[]);return h.jsx(s9,{scope:n,searchRef:P,onItemEnter:g.useCallback(B=>{j(B)&&B.preventDefault()},[j]),onItemLeave:g.useCallback(B=>{var E;j(B)||((E=N.current)==null||E.focus(),C(null))},[j]),onTriggerLeave:g.useCallback(B=>{j(B)&&B.preventDefault()},[j]),pointerGraceTimerRef:O,onPointerGraceIntentChange:g.useCallback(B=>{I.current=B},[]),children:h.jsx(z,{...$,children:h.jsx(Jx,{asChild:!0,trapped:i,onMountAutoFocus:Pe(s,B=>{var E;B.preventDefault(),(E=N.current)==null||E.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:h.jsx(Of,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:h.jsx(l8,{asChild:!0,...b,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:Pe(l,B=>{x.isUsingKeyboardRef.current||B.preventDefault()}),preventScrollOnEntryFocus:!0,children:h.jsx(HT,{role:"menu","aria-orientation":"vertical","data-state":NP(y.open),"data-radix-menu-content":"",dir:x.dir,..._,...v,ref:T,style:{outline:"none",...v.style},onKeyDown:Pe(v.onKeyDown,B=>{const H=B.target.closest("[data-radix-menu-content]")===B.currentTarget,q=B.ctrlKey||B.altKey||B.metaKey,M=B.key.length===1;H&&(B.key==="Tab"&&B.preventDefault(),!q&&M&&F(B.key));const re=N.current;if(B.target!==re||!Y8.includes(B.key))return;B.preventDefault();const V=w().filter(pe=>!pe.disabled).map(pe=>pe.ref.current);sP.includes(B.key)&&V.reverse(),x9(V)}),onBlur:Pe(e.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(L.current),P.current="")}),onPointerMove:Pe(e.onPointerMove,Bc(B=>{const E=B.target,H=D.current!==B.clientX;if(B.currentTarget.contains(E)&&H){const q=B.clientX>D.current?"right":"left";R.current=q,D.current=B.clientX}}))})})})})})})});dP.displayName=vr;var c9="MenuGroup",p_=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(Et.div,{role:"group",...r,ref:t})});p_.displayName=c9;var u9="MenuLabel",hP=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(Et.div,{...r,ref:t})});hP.displayName=u9;var Bh="MenuItem",fw="menu.itemSelect",Vf=g.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=g.useRef(null),o=uu(Bh,e.__scopeMenu),a=h_(Bh,e.__scopeMenu),l=qt(t,s),c=g.useRef(!1),u=()=>{const d=s.current;if(!n&&d){const f=new CustomEvent(fw,{bubbles:!0,cancelable:!0});d.addEventListener(fw,p=>r==null?void 0:r(p),{once:!0}),hT(d,f),f.defaultPrevented?c.current=!1:o.onClose()}};return h.jsx(fP,{...i,ref:l,disabled:n,onClick:Pe(e.onClick,u),onPointerDown:d=>{var f;(f=e.onPointerDown)==null||f.call(e,d),c.current=!0},onPointerUp:Pe(e.onPointerUp,d=>{var f;c.current||(f=d.currentTarget)==null||f.click()}),onKeyDown:Pe(e.onKeyDown,d=>{const f=a.searchRef.current!=="";n||f&&d.key===" "||Av.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})})});Vf.displayName=Bh;var fP=g.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=h_(Bh,n),a=aP(n),l=g.useRef(null),c=qt(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(Oc.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:h.jsx(c8,{asChild:!0,...a,focusable:!r,children:h.jsx(Et.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:Pe(e.onPointerMove,Bc(m=>{r?o.onItemLeave(m):(o.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Pe(e.onPointerLeave,Bc(m=>o.onItemLeave(m))),onFocus:Pe(e.onFocus,()=>d(!0)),onBlur:Pe(e.onBlur,()=>d(!1))})})})}),d9="MenuCheckboxItem",pP=g.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return h.jsx(_P,{scope:e.__scopeMenu,checked:n,children:h.jsx(Vf,{role:"menuitemcheckbox","aria-checked":zh(n)?"mixed":n,...i,ref:t,"data-state":g_(n),onSelect:Pe(i.onSelect,()=>r==null?void 0:r(zh(n)?!0:!n),{checkForDefaultPrevented:!1})})})});pP.displayName=d9;var mP="MenuRadioGroup",[h9,f9]=To(mP,{value:void 0,onValueChange:()=>{}}),gP=g.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Mi(r);return h.jsx(h9,{scope:e.__scopeMenu,value:n,onValueChange:s,children:h.jsx(p_,{...i,ref:t})})});gP.displayName=mP;var vP="MenuRadioItem",xP=g.forwardRef((e,t)=>{const{value:n,...r}=e,i=f9(vP,e.__scopeMenu),s=n===i.value;return h.jsx(_P,{scope:e.__scopeMenu,checked:s,children:h.jsx(Vf,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":g_(s),onSelect:Pe(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});xP.displayName=vP;var m_="MenuItemIndicator",[_P,p9]=To(m_,{checked:!1}),yP=g.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=p9(m_,n);return h.jsx($i,{present:r||zh(s.checked)||s.checked===!0,children:h.jsx(Et.span,{...i,ref:t,"data-state":g_(s.checked)})})});yP.displayName=m_;var m9="MenuSeparator",bP=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(Et.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});bP.displayName=m9;var g9="MenuArrow",wP=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Wf(n);return h.jsx(UT,{...i,...r,ref:t})});wP.displayName=g9;var v9="MenuSub",[Kne,SP]=To(v9),Ol="MenuSubTrigger",kP=g.forwardRef((e,t)=>{const n=Po(Ol,e.__scopeMenu),r=uu(Ol,e.__scopeMenu),i=SP(Ol,e.__scopeMenu),s=h_(Ol,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(u_,{asChild:!0,...c,children:h.jsx(fP,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":NP(n.open),...e,ref:ou(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:Pe(e.onPointerMove,Bc(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:Pe(e.onPointerLeave,Bc(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,y=v==="right",x=y?-5:5,_=f[y?"left":"right"],b=f[y?"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:Pe(e.onKeyDown,d=>{var p;const f=s.searchRef.current!=="";e.disabled||f&&d.key===" "||Z8[r.dir].includes(d.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),d.preventDefault())})})})});kP.displayName=Ol;var CP="MenuSubContent",EP=g.forwardRef((e,t)=>{const n=cP(vr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Po(vr,e.__scopeMenu),o=uu(vr,e.__scopeMenu),a=SP(CP,e.__scopeMenu),l=g.useRef(null),c=qt(t,l);return h.jsx(Oc.Provider,{scope:e.__scopeMenu,children:h.jsx($i,{present:r||s.open,children:h.jsx(Oc.Slot,{scope:e.__scopeMenu,children:h.jsx(f_,{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:Pe(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Pe(e.onEscapeKeyDown,u=>{o.onClose(),u.preventDefault()}),onKeyDown:Pe(e.onKeyDown,u=>{var p;const d=u.currentTarget.contains(u.target),f=Q8[o.dir].includes(u.key);d&&f&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});EP.displayName=CP;function NP(e){return e?"open":"closed"}function zh(e){return e==="indeterminate"}function g_(e){return zh(e)?"indeterminate":e?"checked":"unchecked"}function x9(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function _9(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function y9(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=_9(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 b9(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 w9(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return b9(n,t)}function Bc(e){return t=>t.pointerType==="mouse"?e(t):void 0}var S9=lP,k9=u_,C9=uP,E9=dP,N9=p_,T9=hP,P9=Vf,I9=pP,R9=gP,M9=xP,A9=yP,j9=bP,D9=wP,L9=kP,O9=EP,qf="DropdownMenu",[B9]=No(qf,[oP]),Mn=oP(),[z9,TP]=B9(qf),PP=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:a=!0}=e,l=Mn(t),c=g.useRef(null),[u,d]=Lf({prop:i,defaultProp:s??!1,onChange:o,caller:qf});return h.jsx(z9,{scope:t,triggerId:no(),triggerRef:c,contentId:no(),open:u,onOpenChange:d,onOpenToggle:g.useCallback(()=>d(f=>!f),[d]),modal:a,children:h.jsx(S9,{...l,open:u,onOpenChange:d,dir:r,modal:a,children:n})})};PP.displayName=qf;var IP="DropdownMenuTrigger",RP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=TP(IP,n),o=Mn(n);return h.jsx(k9,{asChild:!0,...o,children:h.jsx(Et.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:ou(t,s.triggerRef),onPointerDown:Pe(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:Pe(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});RP.displayName=IP;var $9="DropdownMenuPortal",MP=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Mn(t);return h.jsx(C9,{...r,...n})};MP.displayName=$9;var AP="DropdownMenuContent",jP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=TP(AP,n),s=Mn(n),o=g.useRef(!1);return h.jsx(E9,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Pe(e.onCloseAutoFocus,a=>{var l;o.current||(l=i.triggerRef.current)==null||l.focus(),o.current=!1,a.preventDefault()}),onInteractOutside:Pe(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)"}})});jP.displayName=AP;var F9="DropdownMenuGroup",H9=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(N9,{...i,...r,ref:t})});H9.displayName=F9;var U9="DropdownMenuLabel",DP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(T9,{...i,...r,ref:t})});DP.displayName=U9;var W9="DropdownMenuItem",LP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(P9,{...i,...r,ref:t})});LP.displayName=W9;var V9="DropdownMenuCheckboxItem",OP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(I9,{...i,...r,ref:t})});OP.displayName=V9;var q9="DropdownMenuRadioGroup",K9=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(R9,{...i,...r,ref:t})});K9.displayName=q9;var G9="DropdownMenuRadioItem",X9=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(M9,{...i,...r,ref:t})});X9.displayName=G9;var Y9="DropdownMenuItemIndicator",BP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(A9,{...i,...r,ref:t})});BP.displayName=Y9;var Z9="DropdownMenuSeparator",zP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(j9,{...i,...r,ref:t})});zP.displayName=Z9;var Q9="DropdownMenuArrow",J9=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(D9,{...i,...r,ref:t})});J9.displayName=Q9;var eH="DropdownMenuSubTrigger",tH=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(L9,{...i,...r,ref:t})});tH.displayName=eH;var nH="DropdownMenuSubContent",rH=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(O9,{...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)"}})});rH.displayName=nH;var iH=PP,sH=RP,oH=MP,$P=jP,FP=DP,HP=LP,UP=OP,aH=BP,WP=zP;const VP=iH,qP=sH,v_=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(oH,{children:h.jsx($P,{ref:r,sideOffset:t,className:ne("z-50 min-w-[8rem] overflow-hidden rounded-md border border-border bg-elevated p-1","text-text-100 shadow-md",e),...n})}));v_.displayName=$P.displayName;const Ys=g.forwardRef(({className:e,inset:t,...n},r)=>h.jsx(HP,{ref:r,className:ne("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-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ys.displayName=HP.displayName;const lH=g.forwardRef(({className:e,children:t,checked:n,...r},i)=>h.jsxs(UP,{ref:i,checked:n,className:ne("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-[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(aH,{children:h.jsx(Qa,{className:"h-3.5 w-3.5"})})}),t]}));lH.displayName=UP.displayName;const KP=g.forwardRef(({className:e,...t},n)=>h.jsx(WP,{ref:n,className:ne("-mx-1 my-1 h-px bg-border",e),...t}));KP.displayName=WP.displayName;const cH=g.forwardRef(({className:e,...t},n)=>h.jsx(FP,{ref:n,className:ne("px-2 py-1.5 text-xs font-semibold text-text-400",e),...t}));cH.displayName=FP.displayName;function uH({iconKey:e,className:t}){const n=uT(e);if(!n)return h.jsx(jf,{className:ne("w-3.5 h-3.5 shrink-0 text-text-400",t),"data-testid":"session-icon-default","aria-label":"未分类"});const r=n.Icon;return h.jsx(r,{className:ne("w-3.5 h-3.5 shrink-0",n.colorClass,t),"data-testid":`session-icon-${n.key}`,"aria-label":n.label})}var dH=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"}),hH="VisuallyHidden",GP=g.forwardRef((e,t)=>h.jsx(Et.span,{...e,ref:t,style:{...dH,...e.style}}));GP.displayName=hH;var fH=GP,[Kf]=No("Tooltip",[Hf]),Gf=Hf(),XP="TooltipProvider",pH=700,jv="tooltip.open",[mH,x_]=Kf(XP),YP=e=>{const{__scopeTooltip:t,delayDuration:n=pH,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(mH,{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})};YP.displayName=XP;var zc="Tooltip",[gH,Xf]=Kf(zc),ZP=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:a}=e,l=x_(zc,e.__scopeTooltip),c=Gf(t),[u,d]=g.useState(null),f=no(),p=g.useRef(0),m=o??l.disableHoverableContent,v=a??l.delayDuration,y=g.useRef(!1),[x,_]=Lf({prop:r,defaultProp:i??!1,onChange:N=>{N?(l.onOpen(),document.dispatchEvent(new CustomEvent(jv))):l.onClose(),s==null||s(N)},caller:zc}),b=g.useMemo(()=>x?y.current?"delayed-open":"instant-open":"closed",[x]),w=g.useCallback(()=>{window.clearTimeout(p.current),p.current=0,y.current=!1,_(!0)},[_]),k=g.useCallback(()=>{window.clearTimeout(p.current),p.current=0,_(!1)},[_]),C=g.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{y.current=!0,_(!0),p.current=0},v)},[v,_]);return g.useEffect(()=>()=>{p.current&&(window.clearTimeout(p.current),p.current=0)},[]),h.jsx($T,{...c,children:h.jsx(gH,{scope:t,contentId:f,open:x,stateAttribute:b,trigger:u,onTriggerChange:d,onTriggerEnter:g.useCallback(()=>{l.isOpenDelayedRef.current?C():w()},[l.isOpenDelayedRef,C,w]),onTriggerLeave:g.useCallback(()=>{m?k():(window.clearTimeout(p.current),p.current=0)},[k,m]),onOpen:w,onClose:k,disableHoverableContent:m,children:n})})};ZP.displayName=zc;var Dv="TooltipTrigger",QP=g.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Xf(Dv,n),s=x_(Dv,n),o=Gf(n),a=g.useRef(null),l=qt(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(FT,{asChild:!0,...o,children:h.jsx(Et.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:l,onPointerMove:Pe(e.onPointerMove,f=>{f.pointerType!=="touch"&&!u.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),u.current=!0)}),onPointerLeave:Pe(e.onPointerLeave,()=>{i.onTriggerLeave(),u.current=!1}),onPointerDown:Pe(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener("pointerup",d,{once:!0})}),onFocus:Pe(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:Pe(e.onBlur,i.onClose),onClick:Pe(e.onClick,i.onClose)})})});QP.displayName=Dv;var vH="TooltipPortal",[Gne,xH]=Kf(vH,{forceMount:void 0}),Oa="TooltipContent",JP=g.forwardRef((e,t)=>{const n=xH(Oa,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Xf(Oa,e.__scopeTooltip);return h.jsx($i,{present:r||o.open,children:o.disableHoverableContent?h.jsx(eI,{side:i,...s,ref:t}):h.jsx(_H,{side:i,...s,ref:t})})}),_H=g.forwardRef((e,t)=>{const n=Xf(Oa,e.__scopeTooltip),r=x_(Oa,e.__scopeTooltip),i=g.useRef(null),s=qt(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 y=m.currentTarget,x={x:m.clientX,y:m.clientY},_=kH(x,y.getBoundingClientRect()),b=CH(x,_),w=EH(v.getBoundingClientRect()),k=TH([...b,...w]);a(k),d(!0)},[d]);return g.useEffect(()=>()=>f(),[f]),g.useEffect(()=>{if(l&&u){const m=y=>p(y,u),v=y=>p(y,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 y=v.target,x={x:v.clientX,y:v.clientY},_=(l==null?void 0:l.contains(y))||(u==null?void 0:u.contains(y)),b=!NH(x,o);_?f():b&&(f(),c())};return document.addEventListener("pointermove",m),()=>document.removeEventListener("pointermove",m)}},[l,u,o,c,f]),h.jsx(eI,{...e,ref:s})}),[yH,bH]=Kf(zc,{isInside:!1}),wH=h$("TooltipContent"),eI=g.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...a}=e,l=Xf(Oa,n),c=Gf(n),{onClose:u}=l;return g.useEffect(()=>(document.addEventListener(jv,u),()=>document.removeEventListener(jv,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(Of,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:d=>d.preventDefault(),onDismiss:u,children:h.jsxs(HT,{"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(wH,{children:r}),h.jsx(yH,{scope:n,isInside:!0,children:h.jsx(fH,{id:l.contentId,role:"tooltip",children:i||r})})]})})});JP.displayName=Oa;var tI="TooltipArrow",SH=g.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Gf(n);return bH(tI,n).isInside?null:h.jsx(UT,{...i,...r,ref:t})});SH.displayName=tI;function kH(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 CH(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 EH(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 NH(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 TH(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),PH(t)}function PH(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 IH=YP,RH=ZP,MH=QP,nI=JP;const __=IH,y_=RH,b_=MH,Yf=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(nI,{ref:r,sideOffset:t,className:ne("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}));Yf.displayName=nI.displayName;function rI({value:e,onChange:t}){return h.jsx(__,{delayDuration:150,children:h.jsx("div",{className:"flex items-center gap-1 flex-wrap","data-testid":"session-icon-picker",children:cT.map(n=>{const r=n.Icon,i=e===n.key;return h.jsxs(y_,{children:[h.jsx(b_,{asChild:!0,children:h.jsx("button",{type:"button",onClick:()=>t(i?null:n.key),"data-testid":`session-icon-option-${n.key}`,"aria-label":n.label,"aria-pressed":i,className:ne("w-8 h-8 rounded-md flex items-center justify-center transition-colors cursor-pointer",i?"bg-text-100/10 ring-1 ring-text-100/30":"hover:bg-text-100/5"),children:h.jsx(r,{className:ne("w-4 h-4",n.colorClass)})})}),h.jsx(Yf,{side:"bottom",children:n.label})]},n.key)})})})}function AH({open:e,initialLabel:t,initialIconKey:n,placeholder:r,onSubmit:i,onCancel:s}){const[o,a]=g.useState(t),[l,c]=g.useState(n);return g.useEffect(()=>{e&&(a(t),c(n))},[e,t,n]),g.useEffect(()=>{if(!e)return;const u=d=>{d.key==="Escape"&&s()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e,s]),e?nu.createPortal(h.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:s,"data-testid":"session-edit-dialog-overlay",children:h.jsxs("div",{"data-testid":"session-edit-dialog",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:u=>u.stopPropagation(),children:[h.jsx("div",{className:"text-[15px] font-semibold text-text-100",children:"Edit session"}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:"Label"}),h.jsx("input",{autoFocus:!0,type:"text",value:o,onChange:u=>a(u.target.value),placeholder:r,"data-testid":"session-edit-dialog-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",{children:[h.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:"Icon"}),h.jsx(rI,{value:l,onChange:c})]}),h.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[h.jsx("button",{type:"button",onClick:s,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:()=>i({label:o.trim(),iconKey:l}),"data-testid":"session-edit-dialog-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",children:"Save"})]})]})}),document.body):null}const jH=10,DH=20,LH=16,OH=20,BH=60,zH=4;function $H({session:e,active:t,hasUnread:n,running:r=!1,awaitingUser:i=!1,onSelect:s,onEdit:o,onDelete:a,onPin:l,depth:c=0,chevron:u,showCopyResume:d=!0,contactDisplayName:f}){const[p,m]=g.useState(!1),v=!!e.pinnedAt,y=c===0,x=jH+c*DH,_=g.useCallback(async()=>{const C=e.toolSessionId;if(!C)return;const T=`cd ${`'${e.cwd.replace(/'/g,"'\\''")}'`} && claude --resume ${C} --permission-mode bypassPermissions`;try{await navigator.clipboard.writeText(T)}catch{}},[e.toolSessionId,e.cwd]),b=e.appBuilderProject?`[app] ${e.appBuilderProject}`:e.label||e.larkChatName||e.larkChatId||e.cwd.split("/").filter(Boolean).pop()||e.sessionId.slice(0,8),w=e.originOwnerPrincipalId,k=w?`@${f??`…${w.slice(-8)}`}`:null;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":`session-item-${e.sessionId}`,onClick:s,style:{paddingLeft:x,display:"grid",gridTemplateColumns:`${LH}px ${OH}px 1fr auto ${BH}px`,gridTemplateAreas:'"chev icon name dot time" ". . sub sub sub"',columnGap:`${zH}px`,rowGap:"2px",alignItems:"center"},className:ne("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:u??null}),h.jsx("div",{style:{gridArea:"icon"},className:"flex items-center justify-center",children:h.jsx(uH,{iconKey:e.iconKey})}),h.jsxs("div",{style:{gridArea:"name"},className:"flex items-center gap-1 min-w-0",children:[e.dispatchedFromSessionId?h.jsx(n6,{"data-testid":`dispatched-icon-${e.sessionId}`,className:"w-3 h-3 text-accent shrink-0",strokeWidth:2.25,"aria-label":"dispatched from another session",children:h.jsx("title",{children:"由另一个 session dispatch 派生"})}):null,e.shiftFiredFromSessionId?h.jsx(NB,{"data-testid":`shift-fired-icon-${e.sessionId}`,className:"w-3 h-3 text-accent shrink-0",strokeWidth:2.25,"aria-label":"fired by clawd-shift scheduler",children:h.jsx("title",{children:"由 shift 排班到点 fire 派生"})}):null,e.larkChatId?h.jsx(I6,{"data-testid":`lark-chat-icon-${e.sessionId}`,className:"w-3 h-3 text-accent shrink-0",strokeWidth:2.25,"aria-label":"driven by feishu group chat",children:h.jsx("title",{children:"飞书群会话(群成员 @ bot 驱动)"})}):null,h.jsx("span",{"data-testid":`session-title-${e.sessionId}`,className:ne("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:b})]}),i?h.jsx(RB,{"data-testid":`awaiting-dot-${e.sessionId}`,style:{gridArea:"dot"},className:"w-3 h-3 text-warning shrink-0 animate-pulse",strokeWidth:2.25,"aria-label":"awaiting user"}):n?h.jsx("span",{"data-testid":`unread-dot-${e.sessionId}`,style:{gridArea:"dot"},className:"w-2 h-2 rounded-full bg-error shrink-0","aria-label":"unread"}):r?h.jsx("span",{"data-testid":`running-dot-${e.sessionId}`,style:{gridArea:"dot"},className:"w-2 h-2 rounded-full bg-success shrink-0 animate-pulse","aria-label":"running"}):null,h.jsx("span",{style:{gridArea:"time"},className:ne("text-[11px] text-text-400/70 text-right shrink-0","transition-opacity duration-150 group-hover:opacity-0"),children:e.updatedAt?s$(e.updatedAt):""}),h.jsxs("span",{style:{gridArea:"sub"},className:ne("flex items-center gap-1.5 text-[11px] text-text-400/70 min-w-0","group-hover:flex-wrap"),children:[k?h.jsx("span",{"data-testid":`session-mirror-chip-${e.sessionId}`,title:`在 ${k.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:k}):null,h.jsx("span",{"data-testid":`session-subtitle-${e.sessionId}`,className:ne("block text-[11px] text-text-400/70 truncate font-mono min-w-0","group-hover:whitespace-normal group-hover:overflow-visible group-hover:break-all"),children:e.cwd.replace(/^\/Users\/[^/]+/,"~")})]}),o||a||l?h.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100 transition-opacity",children:h.jsxs(VP,{modal:!1,children:[h.jsx(qP,{asChild:!0,children:h.jsx("button",{type:"button",onClick:C=>C.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(kv,{className:"w-4 h-4"})})}),h.jsxs(v_,{align:"end",onClick:C=>C.stopPropagation(),children:[l&&y&&h.jsxs(Ys,{onSelect:()=>l(e.sessionId,!v),"data-testid":`session-${v?"unpin":"pin"}-${e.sessionId}`,children:[v?h.jsx(B6,{className:"w-3 h-3 mr-2 text-text-400"}):h.jsx(WN,{className:"w-3 h-3 mr-2 text-text-400"}),v?"Unpin":"Pin"]}),o&&h.jsxs(Ys,{onSelect:()=>m(!0),"data-testid":`session-rename-${e.sessionId}`,children:[h.jsx(UN,{className:"w-3 h-3 mr-2 text-text-400"}),"Rename"]}),d&&e.toolSessionId?h.jsxs(Ys,{onSelect:()=>void _(),"data-testid":`session-copy-resume-${e.sessionId}`,children:[h.jsx(su,{className:"w-3 h-3 mr-2 text-text-400"}),"Copy Resume Command"]}):null,(l||o||d&&e.toolSessionId)&&a&&h.jsx(KP,{}),a&&h.jsxs(Ys,{onSelect:()=>void a(e.sessionId),className:"text-destructive focus:text-destructive focus:bg-destructive/10","data-testid":`session-delete-${e.sessionId}`,children:[h.jsx(Xx,{className:"w-3 h-3 mr-2"}),"Delete"]})]})]})}):null]}),o?h.jsx(AH,{open:p,initialLabel:e.label??"",initialIconKey:e.iconKey??null,placeholder:e.cwd.split("/").pop()||"",onSubmit:C=>{o(e.sessionId,C),m(!1)},onCancel:()=>m(!1)}):null]})}function w_({node:e,depth:t=0,activeId:n,unreadIds:r,runningIds:i,awaitingIds:s,onSelect:o,onEdit:a,onDelete:l,onPin:c,getContactDisplayName:u,showCopyResume:d}){const f=e.children.length>0,{isCollapsed:p,toggle:m}=yB(),v=!p(e.session.sessionId),y=g.useCallback(_=>{_.stopPropagation(),m(e.session.sessionId)},[m,e.session.sessionId]),x=f?h.jsx("button",{type:"button",onClick:y,"data-testid":`session-chevron-${e.session.sessionId}`,"aria-label":v?"collapse":"expand","aria-expanded":v,className:"shrink-0 flex items-center justify-center w-4 h-4 text-text-400 hover:text-text-100 cursor-pointer",children:v?h.jsx(li,{className:"w-3 h-3"}):h.jsx(ci,{className:"w-3 h-3"})}):null;return h.jsxs("div",{"data-testid":`session-tree-node-${e.session.sessionId}`,children:[h.jsx($H,{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,showCopyResume:d,depth:t,chevron:x,contactDisplayName:e.session.originOwnerPrincipalId?u==null?void 0:u(e.session.originOwnerPrincipalId):void 0}),f&&v?h.jsx("div",{"data-testid":`session-tree-children-${e.session.sessionId}`,children:e.children.map(_=>h.jsx(w_,{node:_,depth:t+1,activeId:n,unreadIds:r,runningIds:i,awaitingIds:s,onSelect:o,onEdit:a,onDelete:l,onPin:c,getContactDisplayName:u,showCopyResume:d},_.session.sessionId))}):null]})}function FH(e){return e.forkedFromSessionId??e.dispatchedFromSessionId??e.shiftFiredFromSessionId}function iI(e){e=e.filter(s=>!s.ephemeral);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=FH(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((l,c)=>l.createdAt<c.createdAt?-1:l.createdAt>c.createdAt?1:0);return{session:s,children:a.map(i)}};return[...r].sort(HH).map(i)}function sI(e){return[...e].sort((t,n)=>t.session.updatedAt<n.session.updatedAt?1:t.session.updatedAt>n.session.updatedAt?-1:0)}function HH(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||e.updatedAt<t.updatedAt?1:e.updatedAt>t.updatedAt?-1:0}function UH(e,t){if(e.appBuilderProject)return`[app] ${e.appBuilderProject}`;if(e.label)return e.label;const n=e.cwd.split("/").filter(Boolean).pop();return n||((e.ownerPersonaId?t==null?void 0:t(e.ownerPersonaId):void 0)??"")}function pw(e,t){const n=t.trim().toLowerCase();return n===""?!0:e.toLowerCase().includes(n)}function oI(e){return e.compositionActive||!!e.nativeIsComposing||e.keyCode===229}function aI(e){return e.key==="Enter"&&!e.shiftKey&&!oI(e)}function WH(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(aI({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}}const VH={isCollapsed:()=>!1,toggle:()=>{},prune:()=>{}};function qH({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:y,showCopyResume:x,treatSessionsAsRoots:_,searchQuery:b}){const[w,k]=g.useState(null),[C,N]=g.useState(()=>new Set),T=p??(I=>C.has(I)),L=g.useCallback(I=>{if(m){m(I);return}N(R=>{const D=new Set(R);return D.has(I)?D.delete(I):D.add(I),D})},[m]),P=g.useMemo(()=>i==null?void 0:i.filter(I=>!I.ephemeral),[i]);if(e.length===0)return h.jsx(KH,{});const O=(b??"").trim();return O?h.jsx(Kx.Provider,{value:VH,children:h.jsx("div",{"data-testid":"my-personas-list",className:"flex flex-col gap-0.5",children:e.map(I=>{const R=P?P.filter(F=>F.ownerPersonaId===I.personaId).sort((F,j)=>j.updatedAt>F.updatedAt?1:-1):[],D=pw(I.label,O),z=R.filter(F=>pw(UH(F),O));if(!D&&z.length===0)return null;const $=D?R:z;return h.jsx(mw,{persona:I,active:I.personaId===t,editing:!1,onSelectPersona:n,onSubmitCreateSession:()=>{},onCancelCreateSession:()=>{},personaSessions:$,collapsed:!1,onToggleCollapsed:()=>{},activeSessionId:s??null,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,onEditSession:v,onPinSession:y,showCopyResume:x,treatSessionsAsRoots:_,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f},I.personaId)})})}):h.jsx("div",{"data-testid":"my-personas-list",className:"flex flex-col gap-0.5",children:e.map(I=>{const R=P?P.filter(D=>D.ownerPersonaId===I.personaId).sort((D,z)=>z.updatedAt>D.updatedAt?1:-1):[];return h.jsx(mw,{persona:I,active:I.personaId===t,editing:I.personaId===w,onSelectPersona:n,onStartCreateSession:r?()=>k(I.personaId):void 0,onSubmitCreateSession:D=>{k(null),r==null||r(I.personaId,D)},onCancelCreateSession:()=>k(null),personaSessions:R,collapsed:!T(I.personaId),onToggleCollapsed:()=>L(I.personaId),activeSessionId:s??null,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,onEditSession:v,onPinSession:y,showCopyResume:x,treatSessionsAsRoots:_,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f},I.personaId)})})}function KH(){return h.jsx("div",{className:"px-3 py-3 text-[11px] leading-relaxed text-text-400",children:"还没有 persona。点上方 Personas 标题右侧 + 创建第一个。"})}function mw({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:y,onPinSession:x,showCopyResume:_,treatSessionsAsRoots:b,ownerPrincipalId:w,creatorDisplayNameByOwnerId:k}){const C=lI(e.iconKey),N=a.length>0,T=!l,L=g.useMemo(()=>{const I=[],R=new Map;for(const D of a){const z=D.creatorPrincipalId;if(D.larkChatId!=null||!z||w&&z===w){I.push(D);continue}const $=z,F=(k==null?void 0:k.get($))??`…${$.slice(-8)}`,j=R.get($);j?j.sessions.push(D):R.set($,{groupKey:$,displayName:F,sessions:[D]})}return{self:I,byPeer:[...R.values()]}},[a,w,k]),P=L.byPeer.length>0,O=g.useMemo(()=>T&&!P?sI(iI(a)):[],[T,P,a]);return h.jsxs("div",{"data-testid":`persona-node-${e.personaId}`,children:[h.jsxs("div",{className:ne("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:[N?h.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),c()},"aria-label":T?"collapse":"expand","aria-expanded":T,"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:T?h.jsx(li,{className:"h-3 w-3"}):h.jsx(ci,{className:"h-3 w-3"})}):h.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),h.jsx(C.Component,{className:ne("h-3.5 w-3.5 shrink-0",C.colorClass),"aria-hidden":"true"}),h.jsx("span",{className:"flex-1 truncate text-[13px]",children:e.label}),N?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:I=>{I.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(U6,{className:"h-3.5 w-3.5"})}):null]}),n?h.jsx(GH,{personaId:e.personaId,iconKey:e.iconKey,onSubmit:s,onCancel:o}):null,N&&T?h.jsx("div",{"data-testid":`persona-sessions-${e.personaId}`,children:P?h.jsxs(h.Fragment,{children:[L.self.length>0&&h.jsx(gw,{groupKey:`${e.personaId}-self`,label:"我自己",testId:`persona-sessions-${e.personaId}-self`,sessions:L.self,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:y,onPinSession:x,showCopyResume:_}),L.byPeer.map(I=>h.jsx(gw,{groupKey:`${e.personaId}-peer-${I.groupKey}`,label:I.displayName,testId:`persona-sessions-${e.personaId}-peer-${I.groupKey}`,sessions:I.sessions,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:y,onPinSession:x,showCopyResume:_},`${e.personaId}-peer-${I.groupKey}`))]}):O.map(I=>h.jsx(w_,{node:I,depth:b?0:1,activeId:u,unreadIds:p,runningIds:f,awaitingIds:d,onSelect:R=>m==null?void 0:m(R),onDelete:v,onEdit:y,onPin:x,showCopyResume:_},I.session.sessionId))}):null]})}function gw({label:e,testId:t,sessions:n,activeSessionId:r,awaitingIds:i,runningIds:s,unreadIds:o,onSelectSession:a,onDeleteSession:l,onEditSession:c,onPinSession:u,showCopyResume:d}){const[f,p]=g.useState(!1),m=!f,v=g.useMemo(()=>m?sI(iI(n)):[],[m,n]);return h.jsxs("div",{"data-testid":t,children:[h.jsxs("button",{type:"button",onClick:()=>p(y=>!y),"aria-label":m?"collapse":"expand","aria-expanded":m,"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:[m?h.jsx(li,{className:"h-3 w-3"}):h.jsx(ci,{className:"h-3 w-3"}),h.jsx(Yx,{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})]}),m&&h.jsx("div",{children:v.map(y=>h.jsx(w_,{node:y,depth:2,activeId:r,unreadIds:o,runningIds:s,awaitingIds:i,onSelect:x=>a==null?void 0:a(x),onDelete:l,onEdit:c,onPin:u,showCopyResume:d},y.session.sessionId))})]})}function GH({personaId:e,iconKey:t,onSubmit:n,onCancel:r}){const[i,s]=g.useState(""),o=g.useRef(null),a=lI(t),l=i.trim(),c=l.length>0;g.useEffect(()=>{var f;(f=o.current)==null||f.focus()},[]);const u=g.useCallback(()=>{c&&n(l)},[c,l,n]),d=WH(u,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(a.Component,{className:ne("h-3 w-3 shrink-0",a.colorClass),"aria-hidden":"true"}),h.jsx("input",{ref:o,type:"text",value:i,onChange:f=>s(f.target.value),...d,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:f=>{f.preventDefault(),u()},disabled:!c,"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(Qa,{className:"h-3 w-3"})}),h.jsx("button",{type:"button",onMouseDown:f=>{f.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(Rn,{className:"h-3 w-3"})})]})}function lI(e){const t=uT(e);return t?{Component:t.Icon,colorClass:t.colorClass}:{Component:cz,colorClass:"text-text-400"}}function XH(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function YH(e,t){const n=getComputedStyle(e.ownerDocument.documentElement),r=parseFloat(n.fontSize);return t*r}function ZH(e){return e/100*window.innerHeight}function QH(e){return e/100*window.innerWidth}function JH(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 Bl({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=JH(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=YH(t,i);break}case"em":{r=XH(t,i);break}case"vh":{r=ZH(i);break}case"vw":{r=QH(i);break}}return r}function En(e){return parseFloat(e.toFixed(3))}function Ba({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 Lv(e){const{panels:t}=e,n=Ba({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=Bl({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=En(u/n*100)}let a;if(s.defaultSize!==void 0){const u=Bl({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=En(u/n*100)}let l=0;if(s.minSize!==void 0){const u=Bl({groupSize:n,panelElement:i,styleProp:s.minSize});l=En(u/n*100)}let c=100;if(s.maxSize!==void 0){const u=Bl({groupSize:n,panelElement:i,styleProp:s.maxSize});c=En(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 it(e,t="Assertion error"){if(!e)throw Error(t)}function Ov(e,t){return Array.from(t).sort(e==="horizontal"?e7:t7)}function e7(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function t7(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function cI(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function uI(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 n7({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}=uI(r,o),c=e==="horizontal"?a:l;c<s&&(s=c,i=o)}return it(i,"No rect found"),i}let id;function r7(){return id===void 0&&(typeof matchMedia=="function"?id=!!matchMedia("(pointer:coarse)").matches:id=!1),id}function dI(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=Ov(n,Array.from(t.children).filter(cI).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 y=r.find(x=>x.element===v);if(y){if(f){const x=f.element.getBoundingClientRect(),_=v.getBoundingClientRect();let b;if(l){const w=n==="horizontal"?new DOMRect(x.right,x.top,0,x.height):new DOMRect(x.left,x.bottom,x.width,0),k=n==="horizontal"?new DOMRect(_.left,_.top,0,_.height):new DOMRect(_.left,_.top,_.width,0);switch(p.length){case 0:{b=[w,k];break}case 1:{const C=p[0],N=n7({orientation:n,rects:[x,_],targetRect:C.element.getBoundingClientRect()});b=[C,N===x?k:w];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 w of b){let k="width"in w?w:w.element.getBoundingClientRect();const C=r7()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(k.width<C){const T=C-k.width;k=new DOMRect(k.x-T/2,k.y,k.width+T,k.height)}if(k.height<C){const T=C-k.height;k=new DOMRect(k.x,k.y-T/2,k.width,k.height+T)}const N=m<=c||m>u;!a&&!N&&o.push({group:e,groupSize:Ba({group:e}),panels:[f,y],separator:"width"in w?void 0:w,rect:k}),a=!1}}l=!1,f=y,p=[]}}else if(v.hasAttribute("data-separator")){v.ariaDisabled!==null&&(a=!0);const y=i.find(x=>x.element===v);y?p.push(y):(f=void 0,p=[])}else l=!0}return o}var as;class hI{constructor(){ky(this,as,{})}addListener(t,n){const r=dl(this,as)[t];return r===void 0?dl(this,as)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=dl(this,as)[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(){Cy(this,as,{})}removeListener(t,n){const r=dl(this,as)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}}as=new WeakMap;let ba={cursorFlags:0,state:"inactive"};const S_=new hI;function mo(){return ba}function i7(e){return S_.addListener("change",e)}function s7(e){const t=ba,n={...ba};n.cursorFlags=e,ba=n,S_.emit("change",{prev:t,next:n})}function wa(e){const t=ba;ba=e,S_.emit("change",{prev:t,next:e})}const o7=e=>e,am=()=>{},fI=1,pI=2,mI=4,gI=8,vw=3,xw=12;let sd;function _w(){return sd===void 0&&(sd=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(sd=!0)),sd}function a7({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&&_w()){const s=(e&fI)!==0,o=(e&pI)!==0,a=(e&mI)!==0,l=(e&gI)!==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 _w()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const yw=new WeakMap;function k_(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=yw.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=mo();switch(r.state){case"active":case"hover":{const i=a7({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}}yw.set(e,{prevStyle:t,styleSheet:n})}let Yr=new Map;const vI=new hI;function l7(e){Yr=new Map(Yr),Yr.delete(e)}function bw(e,t){for(const[n]of Yr)if(n.id===e)return n}function ys(e,t){for(const[n,r]of Yr)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Io(){return Yr}function C_(e,t){return vI.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function Di(e,t,n){const r=Yr.get(e);Yr=new Map(Yr),Yr.set(e,t),vI.emit("groupChange",{group:e,isUserInteraction:(n==null?void 0:n.isUserInteraction)===!0,prev:r,next:t})}function xI(e){const t=mo();let n=!1;switch(t.state){case"active":wa({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(k_(e),n=!0,t.hitRegions.forEach(r=>{const i=ys(r.group.id,!0);Di(r.group,i,{isUserInteraction:!0})}))}return n}function ww(e){e.defaultPrevented||xI(e.currentTarget)}function c7(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=uI(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 u7(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function d7(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Cw(e),b:Cw(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();it(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:kw(Sw(n.a)),b:kw(Sw(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 h7=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function f7(e){const t=getComputedStyle(_I(e)??e).display;return t==="flex"||t==="inline-flex"}function p7(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||f7(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"||h7.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Sw(e){let t=e.length;for(;t--;){const n=e[t];if(it(n,"Missing node"),p7(n))return n}return null}function kw(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Cw(e){const t=[];for(;e;)t.push(e),e=_I(e);return t}function _I(e){const{parentNode:t}=e;return u7(t)?t.host:t}function m7(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 g7({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!cI(n)||n.contains(e)||e.contains(n))return!0;if(d7(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(m7(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function E_(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=dI(i),o=c7(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&g7({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function v7(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 xn(e,t,n=0){return Math.abs(En(e)-En(t))<=n}function qr(e,t){return xn(e,t)?0:e>t?1:-1}function ua({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(qr(r,l)<0)if(s){const c=(i+l)/2;qr(r,c)<0?r=i:r=l}else r=l;return r=Math.min(a,r),r=En(r),r}function $c({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(xn(e,0))return t;const o=s==="imperative-api",a=Object.values(t),l=Object.values(i),c=[...a],[u,d]=r;it(u!=null,"Invalid first pivot index"),it(d!=null,"Invalid second pivot index");let f=0;switch(s){case"keyboard":{{const v=e<0?d:u,y=n[v];it(y,`Panel constraints not found for index ${v}`);const{collapsedSize:x=0,collapsible:_,minSize:b=0}=y;if(_){const w=a[v];if(it(w!=null,`Previous layout not found for panel index ${v}`),xn(w,x)){const k=b-w;qr(k,Math.abs(e))>0&&(e=e<0?0-k:k)}}}{const v=e<0?u:d,y=n[v];it(y,`No panel constraints found for index ${v}`);const{collapsedSize:x=0,collapsible:_,minSize:b=0}=y;if(_){const w=a[v];if(it(w!=null,`Previous layout not found for panel index ${v}`),xn(w,b)){const k=w-x;qr(k,Math.abs(e))>0&&(e=e<0?0-k:k)}}}break}default:{const v=e<0?d:u,y=n[v];it(y,`Panel constraints not found for index ${v}`);const x=a[v],{collapsible:_,collapsedSize:b,minSize:w}=y;if(_&&qr(x,w)<0)if(e>0){const k=w-b,C=k/2,N=x+e;qr(N,w)<0&&(e=qr(e,C)<=0?0:k)}else{const k=w-b,C=100-k/2,N=x-e;qr(N,w)<0&&(e=qr(100+e,C)>0?0:-k)}break}}{const v=e<0?1:-1;let y=e<0?d:u,x=0;for(;;){const b=a[y];it(b!=null,`Previous layout not found for panel index ${y}`);const w=ua({overrideDisabledPanels:o,panelConstraints:n[y],prevSize:b,size:100})-b;if(x+=w,y+=v,y<0||y>=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 y=Math.abs(e)-Math.abs(f),x=a[v];it(x!=null,`Previous layout not found for panel index ${v}`);const _=x-y,b=ua({overrideDisabledPanels:o,panelConstraints:n[v],prevSize:x,size:_});if(!xn(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(v7(l,c))return i;{const v=e<0?d:u,y=a[v];it(y!=null,`Previous layout not found for panel index ${v}`);const x=y+f,_=ua({overrideDisabledPanels:o,panelConstraints:n[v],prevSize:y,size:x});if(c[v]=_,!xn(_,x)){let b=x-_,w=e<0?d:u;for(;w>=0&&w<n.length;){const k=c[w];it(k!=null,`Previous layout not found for panel index ${w}`);const C=k+b,N=ua({overrideDisabledPanels:o,panelConstraints:n[w],prevSize:k,size:C});if(xn(k,N)||(b-=N-k,c[w]=N),xn(b,0))break;e>0?w--:w++}}}const p=Object.values(c).reduce((v,y)=>y+v,0);if(!xn(p,100,.1))return i;const m=Object.keys(i);return c.reduce((v,y,x)=>(v[m[x]]=y,v),{})}function go(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||qr(e[n],t[n])!==0)return!1;return!0}function vo({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(!xn(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const l=r[a];it(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];it(l!=null,`No layout data found for index ${a}`);const c=r[a];it(c!=null,`No layout data found for index ${a}`);const u=ua({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:l,size:c});c!=u&&(s+=c-u,r[a]=u)}if(!xn(s,0))for(let a=0;a<t.length;a++){const l=r[a];it(l!=null,`No layout data found for index ${a}`);const c=l+s,u=ua({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:l,size:c});if(l!==u&&(s-=u-l,r[a]=u,xn(s,0)))break}const o=Object.keys(e);return r.reduce((a,l,c)=>(a[o[c]]=l,a),{})}function yI({groupId:e,panelId:t}){const n=()=>{const l=Io();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(y=>y.id===t),m=p===0,v=p===c.length-1;if(v&&l<f&&(m||c.slice(0,p).every((y,x)=>{const _=d[x];return(_==null?void 0:_.collapsible)&&xn(_.collapsedSize,u[_.panelId])}))){const y=c.slice(0,p).reduce((x,_)=>x+u[_.id],0);return{...u,[t]:En(100-y)}}return $c({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(),y=o({nextSize:l,panels:f.panels,prevLayout:m,derivedPanelConstraints:d}),x=vo({layout:y,panelConstraints:d});go(m,x)||Di(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&&xn(c,u)},resize:l=>{const{group:c}=n(),{element:u}=i(),d=Ba({group:c}),f=Bl({groupSize:d,panelElement:u,styleProp:l}),p=En(f/d*100);a(p)}}}function Ew(e){if(e.defaultPrevented)return;const t=Io();E_(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=yI({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function Od(e){const t=Io();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 bI({groupId:e}){const t=()=>{const n=Io();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=vo({layout:n,panelConstraints:i});return r?a:(go(a,c)||Di(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:c,separatorToPanels:l}),c)}}}function Os(e,t){const n=Od(e),r=ys(n.id,!0),i=n.separators.find(u=>u.element===e);it(i,"Matching separator not found");const s=r.separatorToPanels.get(i);it(s,"Matching panels not found");const o=s.map(u=>n.panels.indexOf(u)),a=bI({groupId:n.id}).getLayout(),l=$c({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),c=vo({layout:l,panelConstraints:r.derivedPanelConstraints});go(a,c)||Di(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels},{isUserInteraction:!0})}function Nw(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Od(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&Os(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&Os(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&Os(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&Os(t,-5);break}case"End":{e.preventDefault(),Os(t,100);break}case"Enter":{e.preventDefault();const r=Od(t),i=ys(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,l=r.separators.find(f=>f.element===t);it(l,"Matching separator not found");const c=a.get(l);it(c,"Matching panels not found");const u=c[0],d=s.find(f=>f.panelId===u.id);if(it(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;Os(t,p-f)}break}case"F6":{e.preventDefault();const r=Od(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);it(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(),Os(t,-100);break}}}function Tw(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Io(),n=E_(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)}),wa({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}function wI({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 y=r.get(u),x=i.get(u);if(!y||!x)return;const{defaultLayoutDeferred:_,derivedPanelConstraints:b,groupSize:w,layout:k,separatorToPanels:C}=x;if(b&&k&&C){const N=$c({delta:v,initialLayout:y,panelConstraints:b,pivotIndices:c.panels.map(T=>p.indexOf(T)),prevLayout:k,trigger:"mouse-or-touch"});if(go(N,k)){if(v!==0&&!m)switch(f){case"horizontal":{a|=v<0?fI:pI;break}case"vertical":{a|=v<0?mI:gI;break}}}else Di(c.group,{defaultLayoutDeferred:_,derivedPanelConstraints:b,groupSize:w,layout:N,separatorToPanels:C})}});let l=0;t.movementX===0?l|=o&vw:l|=a&vw,t.movementY===0?l|=o&xw:l|=a&xw,s7(l),k_(e)}function Pw(e){const t=Io(),n=mo();switch(n.state){case"active":wI({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function Iw(e){var r,i;if(e.defaultPrevented)return;const t=mo(),n=Io();switch(t.state){case"active":{if(e.buttons===0){wa({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(s=>{const o=ys(s.group.id,!0);Di(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))}wI({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const s=E_(e,n);s.length===0?t.state!=="inactive"&&wa({cursorFlags:0,state:"inactive"}):wa({cursorFlags:0,hitRegions:s,state:"hover"}),k_(e.currentTarget);break}}}function Rw(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(mo().state){case"hover":wa({cursorFlags:0,state:"inactive"})}}function Mw(e){e.defaultPrevented||e.pointerType==="mouse"&&e.button>0||xI(e.currentTarget)&&e.preventDefault()}function Aw(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=En(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=En((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function x7(e,t,n){if(!n[0])return;const r=e.panels.find(l=>l.element===t);if(!r||!r.onResize)return;const i=Ba({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:En(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function _7(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 y7({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=En(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]=En(f/s*c)}else{const d=En(c/l.length);for(const f of l)u[f]=d}return u}function b7(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 Uo=new Map;function w7(e){let t=!0;it(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:y,target:x}=v;if(x===e.element){if(t){const _=Ba({group:e});if(_===0)return;const b=ys(e.id);if(!b)return;const w=Lv(e),k=b.defaultLayoutDeferred?Aw(w):b.layout,C=y7({group:e,nextGroupSize:_,prevGroupSize:b.groupSize,prevLayout:k}),N=vo({layout:C,panelConstraints:w});if(!b.defaultLayoutDeferred&&go(b.layout,N)&&_7(b.derivedPanelConstraints,w)&&b.groupSize===_)return;Di(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:w,groupSize:_,layout:N,separatorToPanels:b.separatorToPanels})}}else x7(e,x,y)}});s.observe(e.element),e.panels.forEach(m=>{it(!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=Ba({group:e}),a=Lv(e),l=e.panels.map(({id:m})=>m).join(",");let c=e.mutableState.defaultLayout;c&&(b7(e.panels,c)||(c=void 0));const u=e.mutableState.layouts[l]??c??Aw(a),d=vo({layout:u,panelConstraints:a}),f=e.element.ownerDocument;Uo.set(f,(Uo.get(f)??0)+1);const p=new Map;return dI(e).forEach(m=>{m.separator&&p.set(m.separator,m.panels)}),Di(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:d,separatorToPanels:p}),e.separators.forEach(m=>{it(!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",Nw)}),Uo.get(f)===1&&(f.addEventListener("contextmenu",ww,!0),f.addEventListener("dblclick",Ew,!0),f.addEventListener("pointerdown",Tw,!0),f.addEventListener("pointerleave",Pw),f.addEventListener("pointermove",Iw),f.addEventListener("pointerout",Rw),f.addEventListener("pointerup",Mw,!0)),function(){t=!1,Uo.set(f,Math.max(0,(Uo.get(f)??0)-1)),l7(e),e.separators.forEach(m=>{m.element.removeEventListener("keydown",Nw)}),Uo.get(f)||(f.removeEventListener("contextmenu",ww,!0),f.removeEventListener("dblclick",Ew,!0),f.removeEventListener("pointerdown",Tw,!0),f.removeEventListener("pointerleave",Pw),f.removeEventListener("pointermove",Iw),f.removeEventListener("pointerout",Rw),f.removeEventListener("pointerup",Mw,!0)),s.disconnect()}}function S7(){const[e,t]=g.useState({}),n=g.useCallback(()=>t({}),[]);return[e,n]}function N_(e){const t=g.useId();return`${e??t}`}const Ro=typeof window<"u"?g.useLayoutEffect:g.useEffect;function rc(e){const t=g.useRef(e);return Ro(()=>{t.current=e},[e]),g.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function T_(...e){return rc(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function P_(e){const t=g.useRef({...e});return Ro(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const SI=g.createContext(null);function k7(e,t){const n=g.useRef({getLayout:()=>({}),setLayout:o7});g.useImperativeHandle(t,()=>n.current,[]),Ro(()=>{Object.assign(n.current,bI({groupId:e}))})}function I_({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=rc(O=>{go(m.current.onLayoutChange,O)||(m.current.onLayoutChange=O,l==null||l(O))}),y=rc((O,I)=>{go(m.current.onLayoutChanged,O)||(m.current.onLayoutChanged=O,c==null||c(O,{isUserInteraction:I}))}),x=N_(a),_=g.useRef(null),[b,w]=S7(),k=g.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),C=T_(_,s);k7(x,o);const N=rc((O,I)=>{const R=mo(),D=bw(O),z=ys(O);if(z){let $=!1;switch(R.state){case"active":{$=R.hitRegions.some(F=>F.group===D);break}}return{flexGrow:z.layout[I]??1,pointerEvents:$?"none":void 0}}if(n!=null&&n[I])return{flexGrow:n==null?void 0:n[I]}}),T=P_({defaultLayout:n,disableCursor:r}),L=g.useMemo(()=>({get disableCursor(){return!!T.disableCursor},getPanelStyles:N,id:x,orientation:u,registerPanel:O=>{const I=k.current;return I.panels=Ov(u,[...I.panels,O]),w(),()=>{I.panels=I.panels.filter(R=>R!==O),w()}},registerSeparator:O=>{const I=k.current;return I.separators=Ov(u,[...I.separators,O]),w(),()=>{I.separators=I.separators.filter(R=>R!==O),w()}},updatePanelProps:(O,{disabled:I})=>{const R=k.current.panels.find($=>$.id===O);R&&(R.panelConstraints.disabled=I);const D=bw(x),z=ys(x);D&&z&&Di(D,{...z,derivedPanelConstraints:Lv(D)})},updateSeparatorProps:(O,{disabled:I,disableDoubleClick:R})=>{const D=k.current.separators.find(z=>z.id===O);D&&(D.disabled=I,D.disableDoubleClick=R)}}),[N,x,w,u,T]),P=g.useRef(null);return Ro(()=>{const O=_.current;if(O===null)return;const I=k.current;let R;if(T.defaultLayout!==void 0&&Object.keys(T.defaultLayout).length===I.panels.length){R={};for(const E of I.panels){const H=T.defaultLayout[E.id];H!==void 0&&(R[E.id]=H)}}const D={disabled:!!i,element:O,id:x,mutableState:{defaultLayout:R,disableCursor:!!T.disableCursor,expandedPanelSizes:k.current.lastExpandedPanelSizes,layouts:k.current.layouts},orientation:u,panels:I.panels,resizeTargetMinimumSize:I.resizeTargetMinimumSize,separators:I.separators};P.current=D;const z=w7(D),{defaultLayoutDeferred:$,derivedPanelConstraints:F,layout:j}=ys(D.id,!0);!$&&F.length>0&&(v(j),y(j,!1));const B=C_(x,E=>{const{defaultLayoutDeferred:H,derivedPanelConstraints:q,layout:M}=E.next;if(H||q.length===0)return;const re=D.panels.map(({id:V})=>V).join(",");D.mutableState.layouts[re]=M,q.forEach(V=>{if(V.collapsible){const{layout:pe}=E.prev??{};if(pe){const Oe=xn(V.collapsedSize,M[V.panelId]),ie=xn(V.collapsedSize,pe[V.panelId]);Oe&&!ie&&(D.mutableState.expandedPanelSizes[V.panelId]=pe[V.panelId])}}});const oe=mo().state!=="active";v(M),oe&&y(M,E.isUserInteraction)});return()=>{P.current=null,z(),B()}},[i,x,y,v,u,b,T]),g.useEffect(()=>{const O=P.current;O&&(O.mutableState.defaultLayout=n,O.mutableState.disableCursor=!!r)}),h.jsx(SI.Provider,{value:L,children:h.jsx("div",{...p,className:t,"data-group":!0,"data-testid":x,id:x,ref:C,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})})}I_.displayName="Group";function R_(){const e=g.useContext(SI);return it(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function C7(e,t){const{id:n}=R_(),r=g.useRef({collapse:am,expand:am,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:am});g.useImperativeHandle(t,()=>r.current,[]),Ro(()=>{Object.assign(r.current,yI({groupId:n,panelId:e}))})}function Fc({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,y=N_(l),x=P_({disabled:s}),_=g.useRef(null),b=T_(_,o),{getPanelStyles:w,id:k,orientation:C,registerPanel:N,updatePanelProps:T}=R_(),L=d!==null,P=rc((D,z,$)=>{d==null||d(D,l,$)});Ro(()=>{const D=_.current;if(D!==null){const z={element:D,id:y,idIsStable:v,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:L?P:void 0,panelConstraints:{groupResizeBehavior:a,collapsedSize:n,collapsible:r,defaultSize:i,disabled:x.disabled,maxSize:c,minSize:u}};return N(z)}},[a,n,r,i,L,y,v,c,u,P,N,x]),g.useEffect(()=>{T(y,{disabled:s})},[s,y,T]),C7(y,f);const O=()=>{const D=w(k,y);if(D)return JSON.stringify(D)},I=g.useSyncExternalStore(D=>C_(k,D),O,O);let R;return I?R=JSON.parse(I):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":y,id:y,ref:b,style:{...E7,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:C==="horizontal"?"pan-y":"pan-x"},children:e})})}Fc.displayName="Panel";const E7={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function N7({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=vo({layout:$c({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=vo({layout:$c({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function M_({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:s,style:o,...a}){const l=N_(s),c=P_({disabled:n,disableDoubleClick:r}),[u,d]=g.useState({}),[f,p]=g.useState("inactive"),[m,v]=g.useState(!1),y=g.useRef(null),x=T_(y,i),{disableCursor:_,id:b,orientation:w,registerSeparator:k,updateSeparatorProps:C}=R_(),N=w==="horizontal"?"vertical":"horizontal";Ro(()=>{const P=y.current;if(P!==null){const O={disabled:c.disabled,disableDoubleClick:c.disableDoubleClick,element:P,id:l},I=k(O),R=i7(z=>{p(z.next.state!=="inactive"&&z.next.hitRegions.some($=>$.separator===O)?z.next.state:"inactive")}),D=C_(b,z=>{const{derivedPanelConstraints:$,layout:F,separatorToPanels:j}=z.next,B=j.get(O);if(B){const E=B[0],H=B.indexOf(E);d(N7({layout:F,panelConstraints:$,panelId:E.id,panelIndex:H}))}});return()=>{R(),D(),I()}}},[b,l,k,c]),g.useEffect(()=>{C(l,{disabled:n,disableDoubleClick:r})},[n,r,l,C]);let T;n&&!_&&(T="not-allowed");let L;if(n)L="disabled";else switch(f){case"active":{L="active";break}default:m?L="focus":L=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":L,"data-testid":l,id:l,onBlur:()=>v(!1),onFocus:()=>v(!0),ref:x,role:"separator",style:{flexBasis:"auto",cursor:T,...o,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}M_.displayName="Separator";function T7(e,t,n,r=!0){const i=g.useRef({sid:null,tsid:void 0});g.useEffect(()=>{const s=i.current;i.current={sid:t,tsid:n},!(!r||!n||s.sid===t&&(s.tsid===void 0||s.tsid===null)&&typeof n=="string")&&e.sessionObserve({sessionId:t,toolSessionId:n}).catch(()=>{})},[e,t,n,r])}function P7(e,t,n){const r=g.useRef(e),i=g.useRef(t),s=g.useRef(n);s.current=n,g.useEffect(()=>{const o=r.current,a=i.current;r.current=e,i.current=t;const l=o!==e,c=typeof a=="string"&&t==null;!l&&!c||s.current()},[e,t])}const I7=/^Scheduled (?:recurring job|one-shot task) ([0-9a-f]{8}) \(([^)]+)\)/;function R7(e){const t=new Map,n=new Map,r=new Map;for(const i of e)if(i.kind==="tool_call"&&i.tool==="CronCreate"){const s=i.input;if(!s||typeof s.cron!="string"||typeof s.prompt!="string")continue;const o=i.ts;t.set(i.toolUseId,{cron:s.cron,prompt:s.prompt,recurring:s.recurring!==!1,ts:typeof o=="string"?o:"",toolUseId:i.toolUseId})}else if(i.kind==="tool_call"&&i.tool==="CronDelete"){const s=i.input;if(!s||typeof s.id!="string")continue;n.set(i.toolUseId,s.id)}else if(i.kind==="tool_result"){const s=t.get(i.toolUseId);if(s){if(t.delete(i.toolUseId),i.error||typeof i.output!="string")continue;const a=i.output.match(I7);if(!a)continue;r.set(a[1],{id:a[1],cron:s.cron,prompt:s.prompt,recurring:s.recurring,humanSchedule:a[2],createdAt:s.ts,toolUseId:s.toolUseId});continue}const o=n.get(i.toolUseId);o!==void 0&&(n.delete(i.toolUseId),i.error||r.delete(o))}return Array.from(r.values()).sort((i,s)=>i.createdAt.localeCompare(s.createdAt))}const M7=["TaskCreate","TaskUpdate","TaskList","TaskGet"];function A7(e){return M7.includes(e)}function kI(e){return e==="in_progress"||e==="completed"?e:"pending"}function j7(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:kI(n.status),activeForm:i,description:s}]}function D7(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=kI(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 L7(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=j7(t,i.input);break;case"TaskUpdate":t=D7(t,i.input);break}}return{tasks:t,lastEventIndex:n}}function O7(e){const{tasks:t,lastEventIndex:n}=L7(e);let r=-1;for(let c=e.length-1;c>=0;c--)if(e[c].kind==="todo-checklist"){r=c;break}const i=[],s=new Map,o=new Map,a=new Map,l=(c,u)=>{var f,p,m;const d={agentId:u.agentId,status:u.status};u.description?d.description=u.description:(f=c.progress)!=null&&f.description&&(d.description=c.progress.description),u.lastToolName?d.lastToolName=u.lastToolName:(p=c.progress)!=null&&p.lastToolName&&(d.lastToolName=c.progress.lastToolName),u.stats?d.stats=u.stats:(m=c.progress)!=null&&m.stats&&(d.stats=c.progress.stats),c.progress=d};for(let c=0;c<e.length;c++){const u=e[c];switch(u.kind){case"tool-call":{const d={kind:"merged-tool",seq:u.seq,tool:u.tool,toolKind:u.toolKind,toolUseId:u.toolUseId,input:u.input,pending:!0};s.set(u.toolUseId,i.length),i.push(d);break}case"tool-result":{const d=s.get(u.toolUseId);if(d!==void 0){const p=i[d];p.output=u.output,p.error=u.error,p.pending=!1,s.delete(u.toolUseId);break}const f=o.get(u.toolUseId);if(f!==void 0){const p=i[f];p.output=u.output,p.error=u.error,p.pending=!1,u.toolResultExtra&&(p.toolResultExtra=u.toolResultExtra);break}break}case"agent-call":{const d={kind:"merged-agent",seq:u.seq,toolUseId:u.toolUseId,description:u.description,input:u.input,pending:!0,notifications:[]};o.set(u.toolUseId,i.length),i.push(d);const f=a.get(u.toolUseId);f&&(l(d,f),a.delete(u.toolUseId));break}case"agent-progress":{const d=o.get(u.toolUseId);if(d!==void 0){l(i[d],u);break}a.set(u.toolUseId,u);break}case"agent-notification":{const d=u.parentToolUseId;if(d){const f=o.get(d);if(f!==void 0){i[f].notifications.push({text:u.text,taskId:u.taskId});break}}i.push({kind:"agent-notification",seq:u.seq,text:u.text,taskId:u.taskId,parentToolUseId:u.parentToolUseId});break}case"todo-checklist":{c===r&&u.todos.length>0&&i.push({kind:"todo-checklist",seq:u.seq,toolUseId:u.toolUseId,todos:u.todos});break}case"task-event":{c===n&&t.length>0&&i.push({kind:"plan-card",seq:u.seq,tasks:t});break}default:i.push(u)}}return i}const B7=/<(system-reminder|related-dir|clawd-shift-fire)\b[^>]*>[\s\S]*?<\/\1>/gi,z7=/<builder-preview\b[^>]*\/>/gi;function CI(e){return e?e.replace(B7,"").replace(z7,"").trim():""}const $7=CI;function F7(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const H7=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,U7=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,W7={};function jw(e,t){return(W7.jsx?U7:H7).test(e)}const V7=/[ \t\n\f\r]/g;function q7(e){return typeof e=="object"?e.type==="text"?Dw(e.value):!1:Dw(e)}function Dw(e){return e.replace(V7,"")===""}class du{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}du.prototype.normal={};du.prototype.property={};du.prototype.space=void 0;function EI(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new du(n,r,t)}function Bv(e){return e.toLowerCase()}class Vn{constructor(t,n){this.attribute=n,this.property=t}}Vn.prototype.attribute="";Vn.prototype.booleanish=!1;Vn.prototype.boolean=!1;Vn.prototype.commaOrSpaceSeparated=!1;Vn.prototype.commaSeparated=!1;Vn.prototype.defined=!1;Vn.prototype.mustUseProperty=!1;Vn.prototype.number=!1;Vn.prototype.overloadedBoolean=!1;Vn.prototype.property="";Vn.prototype.spaceSeparated=!1;Vn.prototype.space=void 0;let K7=0;const Ie=Mo(),Mt=Mo(),zv=Mo(),Y=Mo(),lt=Mo(),Sa=Mo(),Xn=Mo();function Mo(){return 2**++K7}const $v=Object.freeze(Object.defineProperty({__proto__:null,boolean:Ie,booleanish:Mt,commaOrSpaceSeparated:Xn,commaSeparated:Sa,number:Y,overloadedBoolean:zv,spaceSeparated:lt},Symbol.toStringTag,{value:"Module"})),lm=Object.keys($v);class A_ extends Vn{constructor(t,n,r,i){let s=-1;if(super(t,n),Lw(this,"space",i),typeof r=="number")for(;++s<lm.length;){const o=lm[s];Lw(this,lm[s],(r&$v[o])===$v[o])}}}A_.prototype.defined=!0;function Lw(e,t,n){n&&(e[t]=n)}function tl(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new A_(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[Bv(r)]=r,n[Bv(s.attribute)]=r}return new du(t,n,e.space)}const NI=tl({properties:{ariaActiveDescendant:null,ariaAtomic:Mt,ariaAutoComplete:null,ariaBusy:Mt,ariaChecked:Mt,ariaColCount:Y,ariaColIndex:Y,ariaColSpan:Y,ariaControls:lt,ariaCurrent:null,ariaDescribedBy:lt,ariaDetails:null,ariaDisabled:Mt,ariaDropEffect:lt,ariaErrorMessage:null,ariaExpanded:Mt,ariaFlowTo:lt,ariaGrabbed:Mt,ariaHasPopup:null,ariaHidden:Mt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:lt,ariaLevel:Y,ariaLive:null,ariaModal:Mt,ariaMultiLine:Mt,ariaMultiSelectable:Mt,ariaOrientation:null,ariaOwns:lt,ariaPlaceholder:null,ariaPosInSet:Y,ariaPressed:Mt,ariaReadOnly:Mt,ariaRelevant:null,ariaRequired:Mt,ariaRoleDescription:lt,ariaRowCount:Y,ariaRowIndex:Y,ariaRowSpan:Y,ariaSelected:Mt,ariaSetSize:Y,ariaSort:null,ariaValueMax:Y,ariaValueMin:Y,ariaValueNow:Y,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function TI(e,t){return t in e?e[t]:t}function PI(e,t){return TI(e,t.toLowerCase())}const G7=tl({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:Sa,acceptCharset:lt,accessKey:lt,action:null,allow:null,allowFullScreen:Ie,allowPaymentRequest:Ie,allowUserMedia:Ie,alt:null,as:null,async:Ie,autoCapitalize:null,autoComplete:lt,autoFocus:Ie,autoPlay:Ie,blocking:lt,capture:null,charSet:null,checked:Ie,cite:null,className:lt,cols:Y,colSpan:null,content:null,contentEditable:Mt,controls:Ie,controlsList:lt,coords:Y|Sa,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Ie,defer:Ie,dir:null,dirName:null,disabled:Ie,download:zv,draggable:Mt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Ie,formTarget:null,headers:lt,height:Y,hidden:zv,high:Y,href:null,hrefLang:null,htmlFor:lt,httpEquiv:lt,id:null,imageSizes:null,imageSrcSet:null,inert:Ie,inputMode:null,integrity:null,is:null,isMap:Ie,itemId:null,itemProp:lt,itemRef:lt,itemScope:Ie,itemType:lt,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Ie,low:Y,manifest:null,max:null,maxLength:Y,media:null,method:null,min:null,minLength:Y,multiple:Ie,muted:Ie,name:null,nonce:null,noModule:Ie,noValidate:Ie,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Ie,optimum:Y,pattern:null,ping:lt,placeholder:null,playsInline:Ie,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Ie,referrerPolicy:null,rel:lt,required:Ie,reversed:Ie,rows:Y,rowSpan:Y,sandbox:lt,scope:null,scoped:Ie,seamless:Ie,selected:Ie,shadowRootClonable:Ie,shadowRootDelegatesFocus:Ie,shadowRootMode:null,shape:null,size:Y,sizes:null,slot:null,span:Y,spellCheck:Mt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Y,step:null,style:null,tabIndex:Y,target:null,title:null,translate:null,type:null,typeMustMatch:Ie,useMap:null,value:Mt,width:Y,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:lt,axis:null,background:null,bgColor:null,border:Y,borderColor:null,bottomMargin:Y,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Ie,declare:Ie,event:null,face:null,frame:null,frameBorder:null,hSpace:Y,leftMargin:Y,link:null,longDesc:null,lowSrc:null,marginHeight:Y,marginWidth:Y,noResize:Ie,noHref:Ie,noShade:Ie,noWrap:Ie,object:null,profile:null,prompt:null,rev:null,rightMargin:Y,rules:null,scheme:null,scrolling:Mt,standby:null,summary:null,text:null,topMargin:Y,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Y,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Ie,disableRemotePlayback:Ie,prefix:null,property:null,results:Y,security:null,unselectable:null},space:"html",transform:PI}),X7=tl({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:Xn,accentHeight:Y,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Y,amplitude:Y,arabicForm:null,ascent:Y,attributeName:null,attributeType:null,azimuth:Y,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Y,by:null,calcMode:null,capHeight:Y,className:lt,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Y,diffuseConstant:Y,direction:null,display:null,dur:null,divisor:Y,dominantBaseline:null,download:Ie,dx:null,dy:null,edgeMode:null,editable:null,elevation:Y,enableBackground:null,end:null,event:null,exponent:Y,externalResourcesRequired:null,fill:null,fillOpacity:Y,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:Sa,g2:Sa,glyphName:Sa,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Y,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Y,horizOriginX:Y,horizOriginY:Y,id:null,ideographic:Y,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Y,k:Y,k1:Y,k2:Y,k3:Y,k4:Y,kernelMatrix:Xn,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Y,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Y,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Y,overlineThickness:Y,paintOrder:null,panose1:null,path:null,pathLength:Y,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:lt,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Y,pointsAtY:Y,pointsAtZ:Y,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Xn,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Xn,rev:Xn,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Xn,requiredFeatures:Xn,requiredFonts:Xn,requiredFormats:Xn,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Y,specularExponent:Y,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Y,strikethroughThickness:Y,string:null,stroke:null,strokeDashArray:Xn,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Y,strokeOpacity:Y,strokeWidth:null,style:null,surfaceScale:Y,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Xn,tabIndex:Y,tableValues:null,target:null,targetX:Y,targetY:Y,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Xn,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Y,underlineThickness:Y,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Y,values:null,vAlphabetic:Y,vMathematical:Y,vectorEffect:null,vHanging:Y,vIdeographic:Y,version:null,vertAdvY:Y,vertOriginX:Y,vertOriginY:Y,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Y,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:TI}),II=tl({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),RI=tl({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:PI}),MI=tl({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Y7={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},Z7=/[A-Z]/g,Ow=/-[a-z]/g,Q7=/^data[-\w.:]+$/i;function J7(e,t){const n=Bv(t);let r=t,i=Vn;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Q7.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(Ow,tU);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!Ow.test(s)){let o=s.replace(Z7,eU);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=A_}return new i(r,t)}function eU(e){return"-"+e.toLowerCase()}function tU(e){return e.charAt(1).toUpperCase()}const nU=EI([NI,G7,II,RI,MI],"html"),j_=EI([NI,X7,II,RI,MI],"svg");function rU(e){return e.join(" ").trim()}var D_={},Bw=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,iU=/\n/g,sU=/^\s*/,oU=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,aU=/^:\s*/,lU=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,cU=/^[;\s]*/,uU=/^\s+|\s+$/g,dU=`
490
+ `)},V8=0,Ho=[];function q8(e){var t=g.useRef([]),n=g.useRef([0,0]),r=g.useRef(),i=g.useState(V8++)[0],s=g.useState(tP)[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=f8([e.lockRef.current],(e.shards||[]).map(hw),!0).filter(Boolean);return v.forEach(function(y){return y.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),v.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var a=g.useCallback(function(v,y){if("touches"in v&&v.touches.length===2||v.type==="wheel"&&v.ctrlKey)return!o.current.allowPinchZoom;var x=rd(v),_=n.current,b="deltaX"in v?v.deltaX:_[0]-x[0],w="deltaY"in v?v.deltaY:_[1]-x[1],k,C=v.target,N=Math.abs(b)>Math.abs(w)?"h":"v";if("touches"in v&&N==="h"&&C.type==="range")return!1;var T=window.getSelection(),L=T&&T.anchorNode,P=L?L===C||L.contains(C):!1;if(P)return!1;var O=uw(N,C);if(!O)return!0;if(O?k=N:(k=N==="v"?"h":"v",O=uw(N,C)),!O)return!1;if(!r.current&&"changedTouches"in v&&(b||w)&&(r.current=k),!k)return!0;var I=r.current||k;return H8(I,y,v,I==="h"?b:w)},[]),l=g.useCallback(function(v){var y=v;if(!(!Ho.length||Ho[Ho.length-1]!==s)){var x="deltaY"in y?dw(y):rd(y),_=t.current.filter(function(k){return k.name===y.type&&(k.target===y.target||y.target===k.shadowParent)&&U8(k.delta,x)})[0];if(_&&_.should){y.cancelable&&y.preventDefault();return}if(!_){var b=(o.current.shards||[]).map(hw).filter(Boolean).filter(function(k){return k.contains(y.target)}),w=b.length>0?a(y,b[0]):!o.current.noIsolation;w&&y.cancelable&&y.preventDefault()}}},[]),c=g.useCallback(function(v,y,x,_){var b={name:v,delta:y,target:x,should:_,shadowParent:K8(x)};t.current.push(b),setTimeout(function(){t.current=t.current.filter(function(w){return w!==b})},1)},[]),u=g.useCallback(function(v){n.current=rd(v),r.current=void 0},[]),d=g.useCallback(function(v){c(v.type,dw(v),v.target,a(v,e.lockRef.current))},[]),f=g.useCallback(function(v){c(v.type,rd(v),v.target,a(v,e.lockRef.current))},[]);g.useEffect(function(){return Ho.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",l,Fo),document.addEventListener("touchmove",l,Fo),document.addEventListener("touchstart",u,Fo),function(){Ho=Ho.filter(function(v){return v!==s}),document.removeEventListener("wheel",l,Fo),document.removeEventListener("touchmove",l,Fo),document.removeEventListener("touchstart",u,Fo)}},[]);var p=e.removeScrollBar,m=e.inert;return g.createElement(g.Fragment,null,m?g.createElement(s,{styles:W8(i)}):null,p?g.createElement(D8,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function K8(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const G8=w8(eP,q8);var c_=g.forwardRef(function(e,t){return g.createElement(Uf,Gr({},e,{ref:t,sideCar:G8}))});c_.classNames=Uf.classNames;var Av=["Enter"," "],X8=["ArrowDown","PageUp","Home"],sP=["ArrowUp","PageDown","End"],Y8=[...X8,...sP],Z8={ltr:[...Av,"ArrowRight"],rtl:[...Av,"ArrowLeft"]},Q8={ltr:["ArrowLeft"],rtl:["ArrowRight"]},cu="Menu",[Oc,J8,e9]=fT(cu),[To,oP]=No(cu,[e9,Hf,VT]),Wf=Hf(),aP=VT(),[t9,Po]=To(cu),[n9,uu]=To(cu),lP=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:s,modal:o=!0}=e,a=Wf(t),[l,c]=g.useState(null),u=g.useRef(!1),d=Mi(s),f=pT(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($T,{...a,children:h.jsx(t9,{scope:t,open:n,onOpenChange:d,content:l,onContentChange:c,children:h.jsx(n9,{scope:t,onClose:g.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})};lP.displayName=cu;var r9="MenuAnchor",u_=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Wf(n);return h.jsx(FT,{...i,...r,ref:t})});u_.displayName=r9;var d_="MenuPortal",[i9,cP]=To(d_,{forceMount:void 0}),uP=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:i}=e,s=Po(d_,t);return h.jsx(i9,{scope:t,forceMount:n,children:h.jsx($i,{present:n||s.open,children:h.jsx(l_,{asChild:!0,container:i,children:r})})})};uP.displayName=d_;var vr="MenuContent",[s9,h_]=To(vr),dP=g.forwardRef((e,t)=>{const n=cP(vr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Po(vr,e.__scopeMenu),o=uu(vr,e.__scopeMenu);return h.jsx(Oc.Provider,{scope:e.__scopeMenu,children:h.jsx($i,{present:r||s.open,children:h.jsx(Oc.Slot,{scope:e.__scopeMenu,children:o.modal?h.jsx(o9,{...i,ref:t}):h.jsx(a9,{...i,ref:t})})})})}),o9=g.forwardRef((e,t)=>{const n=Po(vr,e.__scopeMenu),r=g.useRef(null),i=qt(t,r);return g.useEffect(()=>{const s=r.current;if(s)return ZT(s)},[]),h.jsx(f_,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:Pe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),a9=g.forwardRef((e,t)=>{const n=Po(vr,e.__scopeMenu);return h.jsx(f_,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),l9=Dc("MenuContent.ScrollLock"),f_=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,y=Po(vr,n),x=uu(vr,n),_=Wf(n),b=aP(n),w=J8(n),[k,C]=g.useState(null),N=g.useRef(null),T=qt(t,N,y.onContentChange),L=g.useRef(0),P=g.useRef(""),O=g.useRef(0),I=g.useRef(null),R=g.useRef("right"),D=g.useRef(0),z=m?c_:g.Fragment,$=m?{as:l9,allowPinchZoom:!0}:void 0,F=B=>{var pe,Oe;const E=P.current+B,H=w().filter(ie=>!ie.disabled),q=document.activeElement,M=(pe=H.find(ie=>ie.ref.current===q))==null?void 0:pe.textValue,re=H.map(ie=>ie.textValue),oe=y9(re,E,M),V=(Oe=H.find(ie=>ie.textValue===oe))==null?void 0:Oe.ref.current;(function ie(Ae){P.current=Ae,window.clearTimeout(L.current),Ae!==""&&(L.current=window.setTimeout(()=>ie(""),1e3))})(E),V&&setTimeout(()=>V.focus())};g.useEffect(()=>()=>window.clearTimeout(L.current),[]),vT();const j=g.useCallback(B=>{var H,q;return R.current===((H=I.current)==null?void 0:H.side)&&w9(B,(q=I.current)==null?void 0:q.area)},[]);return h.jsx(s9,{scope:n,searchRef:P,onItemEnter:g.useCallback(B=>{j(B)&&B.preventDefault()},[j]),onItemLeave:g.useCallback(B=>{var E;j(B)||((E=N.current)==null||E.focus(),C(null))},[j]),onTriggerLeave:g.useCallback(B=>{j(B)&&B.preventDefault()},[j]),pointerGraceTimerRef:O,onPointerGraceIntentChange:g.useCallback(B=>{I.current=B},[]),children:h.jsx(z,{...$,children:h.jsx(Jx,{asChild:!0,trapped:i,onMountAutoFocus:Pe(s,B=>{var E;B.preventDefault(),(E=N.current)==null||E.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:h.jsx(Of,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:h.jsx(l8,{asChild:!0,...b,dir:x.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:C,onEntryFocus:Pe(l,B=>{x.isUsingKeyboardRef.current||B.preventDefault()}),preventScrollOnEntryFocus:!0,children:h.jsx(HT,{role:"menu","aria-orientation":"vertical","data-state":NP(y.open),"data-radix-menu-content":"",dir:x.dir,..._,...v,ref:T,style:{outline:"none",...v.style},onKeyDown:Pe(v.onKeyDown,B=>{const H=B.target.closest("[data-radix-menu-content]")===B.currentTarget,q=B.ctrlKey||B.altKey||B.metaKey,M=B.key.length===1;H&&(B.key==="Tab"&&B.preventDefault(),!q&&M&&F(B.key));const re=N.current;if(B.target!==re||!Y8.includes(B.key))return;B.preventDefault();const V=w().filter(pe=>!pe.disabled).map(pe=>pe.ref.current);sP.includes(B.key)&&V.reverse(),x9(V)}),onBlur:Pe(e.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(L.current),P.current="")}),onPointerMove:Pe(e.onPointerMove,Bc(B=>{const E=B.target,H=D.current!==B.clientX;if(B.currentTarget.contains(E)&&H){const q=B.clientX>D.current?"right":"left";R.current=q,D.current=B.clientX}}))})})})})})})});dP.displayName=vr;var c9="MenuGroup",p_=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(Et.div,{role:"group",...r,ref:t})});p_.displayName=c9;var u9="MenuLabel",hP=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(Et.div,{...r,ref:t})});hP.displayName=u9;var Bh="MenuItem",fw="menu.itemSelect",Vf=g.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...i}=e,s=g.useRef(null),o=uu(Bh,e.__scopeMenu),a=h_(Bh,e.__scopeMenu),l=qt(t,s),c=g.useRef(!1),u=()=>{const d=s.current;if(!n&&d){const f=new CustomEvent(fw,{bubbles:!0,cancelable:!0});d.addEventListener(fw,p=>r==null?void 0:r(p),{once:!0}),hT(d,f),f.defaultPrevented?c.current=!1:o.onClose()}};return h.jsx(fP,{...i,ref:l,disabled:n,onClick:Pe(e.onClick,u),onPointerDown:d=>{var f;(f=e.onPointerDown)==null||f.call(e,d),c.current=!0},onPointerUp:Pe(e.onPointerUp,d=>{var f;c.current||(f=d.currentTarget)==null||f.click()}),onKeyDown:Pe(e.onKeyDown,d=>{const f=a.searchRef.current!=="";n||f&&d.key===" "||Av.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})})});Vf.displayName=Bh;var fP=g.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:i,...s}=e,o=h_(Bh,n),a=aP(n),l=g.useRef(null),c=qt(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(Oc.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:h.jsx(c8,{asChild:!0,...a,focusable:!r,children:h.jsx(Et.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:Pe(e.onPointerMove,Bc(m=>{r?o.onItemLeave(m):(o.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Pe(e.onPointerLeave,Bc(m=>o.onItemLeave(m))),onFocus:Pe(e.onFocus,()=>d(!0)),onBlur:Pe(e.onBlur,()=>d(!1))})})})}),d9="MenuCheckboxItem",pP=g.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...i}=e;return h.jsx(_P,{scope:e.__scopeMenu,checked:n,children:h.jsx(Vf,{role:"menuitemcheckbox","aria-checked":zh(n)?"mixed":n,...i,ref:t,"data-state":g_(n),onSelect:Pe(i.onSelect,()=>r==null?void 0:r(zh(n)?!0:!n),{checkForDefaultPrevented:!1})})})});pP.displayName=d9;var mP="MenuRadioGroup",[h9,f9]=To(mP,{value:void 0,onValueChange:()=>{}}),gP=g.forwardRef((e,t)=>{const{value:n,onValueChange:r,...i}=e,s=Mi(r);return h.jsx(h9,{scope:e.__scopeMenu,value:n,onValueChange:s,children:h.jsx(p_,{...i,ref:t})})});gP.displayName=mP;var vP="MenuRadioItem",xP=g.forwardRef((e,t)=>{const{value:n,...r}=e,i=f9(vP,e.__scopeMenu),s=n===i.value;return h.jsx(_P,{scope:e.__scopeMenu,checked:s,children:h.jsx(Vf,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":g_(s),onSelect:Pe(r.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,n)},{checkForDefaultPrevented:!1})})})});xP.displayName=vP;var m_="MenuItemIndicator",[_P,p9]=To(m_,{checked:!1}),yP=g.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...i}=e,s=p9(m_,n);return h.jsx($i,{present:r||zh(s.checked)||s.checked===!0,children:h.jsx(Et.span,{...i,ref:t,"data-state":g_(s.checked)})})});yP.displayName=m_;var m9="MenuSeparator",bP=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return h.jsx(Et.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});bP.displayName=m9;var g9="MenuArrow",wP=g.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,i=Wf(n);return h.jsx(UT,{...i,...r,ref:t})});wP.displayName=g9;var v9="MenuSub",[Kne,SP]=To(v9),Ol="MenuSubTrigger",kP=g.forwardRef((e,t)=>{const n=Po(Ol,e.__scopeMenu),r=uu(Ol,e.__scopeMenu),i=SP(Ol,e.__scopeMenu),s=h_(Ol,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(u_,{asChild:!0,...c,children:h.jsx(fP,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":i.contentId,"data-state":NP(n.open),...e,ref:ou(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:Pe(e.onPointerMove,Bc(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:Pe(e.onPointerLeave,Bc(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,y=v==="right",x=y?-5:5,_=f[y?"left":"right"],b=f[y?"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:Pe(e.onKeyDown,d=>{var p;const f=s.searchRef.current!=="";e.disabled||f&&d.key===" "||Z8[r.dir].includes(d.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),d.preventDefault())})})})});kP.displayName=Ol;var CP="MenuSubContent",EP=g.forwardRef((e,t)=>{const n=cP(vr,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,s=Po(vr,e.__scopeMenu),o=uu(vr,e.__scopeMenu),a=SP(CP,e.__scopeMenu),l=g.useRef(null),c=qt(t,l);return h.jsx(Oc.Provider,{scope:e.__scopeMenu,children:h.jsx($i,{present:r||s.open,children:h.jsx(Oc.Slot,{scope:e.__scopeMenu,children:h.jsx(f_,{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:Pe(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:Pe(e.onEscapeKeyDown,u=>{o.onClose(),u.preventDefault()}),onKeyDown:Pe(e.onKeyDown,u=>{var p;const d=u.currentTarget.contains(u.target),f=Q8[o.dir].includes(u.key);d&&f&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});EP.displayName=CP;function NP(e){return e?"open":"closed"}function zh(e){return e==="indeterminate"}function g_(e){return zh(e)?"indeterminate":e?"checked":"unchecked"}function x9(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function _9(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function y9(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=_9(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 b9(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 w9(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return b9(n,t)}function Bc(e){return t=>t.pointerType==="mouse"?e(t):void 0}var S9=lP,k9=u_,C9=uP,E9=dP,N9=p_,T9=hP,P9=Vf,I9=pP,R9=gP,M9=xP,A9=yP,j9=bP,D9=wP,L9=kP,O9=EP,qf="DropdownMenu",[B9]=No(qf,[oP]),Mn=oP(),[z9,TP]=B9(qf),PP=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:s,onOpenChange:o,modal:a=!0}=e,l=Mn(t),c=g.useRef(null),[u,d]=Lf({prop:i,defaultProp:s??!1,onChange:o,caller:qf});return h.jsx(z9,{scope:t,triggerId:no(),triggerRef:c,contentId:no(),open:u,onOpenChange:d,onOpenToggle:g.useCallback(()=>d(f=>!f),[d]),modal:a,children:h.jsx(S9,{...l,open:u,onOpenChange:d,dir:r,modal:a,children:n})})};PP.displayName=qf;var IP="DropdownMenuTrigger",RP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,s=TP(IP,n),o=Mn(n);return h.jsx(k9,{asChild:!0,...o,children:h.jsx(Et.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:ou(t,s.triggerRef),onPointerDown:Pe(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:Pe(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});RP.displayName=IP;var $9="DropdownMenuPortal",MP=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Mn(t);return h.jsx(C9,{...r,...n})};MP.displayName=$9;var AP="DropdownMenuContent",jP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=TP(AP,n),s=Mn(n),o=g.useRef(!1);return h.jsx(E9,{id:i.contentId,"aria-labelledby":i.triggerId,...s,...r,ref:t,onCloseAutoFocus:Pe(e.onCloseAutoFocus,a=>{var l;o.current||(l=i.triggerRef.current)==null||l.focus(),o.current=!1,a.preventDefault()}),onInteractOutside:Pe(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)"}})});jP.displayName=AP;var F9="DropdownMenuGroup",H9=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(N9,{...i,...r,ref:t})});H9.displayName=F9;var U9="DropdownMenuLabel",DP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(T9,{...i,...r,ref:t})});DP.displayName=U9;var W9="DropdownMenuItem",LP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(P9,{...i,...r,ref:t})});LP.displayName=W9;var V9="DropdownMenuCheckboxItem",OP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(I9,{...i,...r,ref:t})});OP.displayName=V9;var q9="DropdownMenuRadioGroup",K9=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(R9,{...i,...r,ref:t})});K9.displayName=q9;var G9="DropdownMenuRadioItem",X9=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(M9,{...i,...r,ref:t})});X9.displayName=G9;var Y9="DropdownMenuItemIndicator",BP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(A9,{...i,...r,ref:t})});BP.displayName=Y9;var Z9="DropdownMenuSeparator",zP=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(j9,{...i,...r,ref:t})});zP.displayName=Z9;var Q9="DropdownMenuArrow",J9=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(D9,{...i,...r,ref:t})});J9.displayName=Q9;var eH="DropdownMenuSubTrigger",tH=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(L9,{...i,...r,ref:t})});tH.displayName=eH;var nH="DropdownMenuSubContent",rH=g.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,i=Mn(n);return h.jsx(O9,{...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)"}})});rH.displayName=nH;var iH=PP,sH=RP,oH=MP,$P=jP,FP=DP,HP=LP,UP=OP,aH=BP,WP=zP;const VP=iH,qP=sH,v_=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(oH,{children:h.jsx($P,{ref:r,sideOffset:t,className:ne("z-50 min-w-[8rem] overflow-hidden rounded-md border border-border bg-elevated p-1","text-text-100 shadow-md",e),...n})}));v_.displayName=$P.displayName;const Ys=g.forwardRef(({className:e,inset:t,...n},r)=>h.jsx(HP,{ref:r,className:ne("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-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ys.displayName=HP.displayName;const lH=g.forwardRef(({className:e,children:t,checked:n,...r},i)=>h.jsxs(UP,{ref:i,checked:n,className:ne("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-[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(aH,{children:h.jsx(Qa,{className:"h-3.5 w-3.5"})})}),t]}));lH.displayName=UP.displayName;const KP=g.forwardRef(({className:e,...t},n)=>h.jsx(WP,{ref:n,className:ne("-mx-1 my-1 h-px bg-border",e),...t}));KP.displayName=WP.displayName;const cH=g.forwardRef(({className:e,...t},n)=>h.jsx(FP,{ref:n,className:ne("px-2 py-1.5 text-xs font-semibold text-text-400",e),...t}));cH.displayName=FP.displayName;function uH({iconKey:e,className:t}){const n=uT(e);if(!n)return h.jsx(jf,{className:ne("w-3.5 h-3.5 shrink-0 text-text-400",t),"data-testid":"session-icon-default","aria-label":"未分类"});const r=n.Icon;return h.jsx(r,{className:ne("w-3.5 h-3.5 shrink-0",n.colorClass,t),"data-testid":`session-icon-${n.key}`,"aria-label":n.label})}var dH=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"}),hH="VisuallyHidden",GP=g.forwardRef((e,t)=>h.jsx(Et.span,{...e,ref:t,style:{...dH,...e.style}}));GP.displayName=hH;var fH=GP,[Kf]=No("Tooltip",[Hf]),Gf=Hf(),XP="TooltipProvider",pH=700,jv="tooltip.open",[mH,x_]=Kf(XP),YP=e=>{const{__scopeTooltip:t,delayDuration:n=pH,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(mH,{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})};YP.displayName=XP;var zc="Tooltip",[gH,Xf]=Kf(zc),ZP=e=>{const{__scopeTooltip:t,children:n,open:r,defaultOpen:i,onOpenChange:s,disableHoverableContent:o,delayDuration:a}=e,l=x_(zc,e.__scopeTooltip),c=Gf(t),[u,d]=g.useState(null),f=no(),p=g.useRef(0),m=o??l.disableHoverableContent,v=a??l.delayDuration,y=g.useRef(!1),[x,_]=Lf({prop:r,defaultProp:i??!1,onChange:N=>{N?(l.onOpen(),document.dispatchEvent(new CustomEvent(jv))):l.onClose(),s==null||s(N)},caller:zc}),b=g.useMemo(()=>x?y.current?"delayed-open":"instant-open":"closed",[x]),w=g.useCallback(()=>{window.clearTimeout(p.current),p.current=0,y.current=!1,_(!0)},[_]),k=g.useCallback(()=>{window.clearTimeout(p.current),p.current=0,_(!1)},[_]),C=g.useCallback(()=>{window.clearTimeout(p.current),p.current=window.setTimeout(()=>{y.current=!0,_(!0),p.current=0},v)},[v,_]);return g.useEffect(()=>()=>{p.current&&(window.clearTimeout(p.current),p.current=0)},[]),h.jsx($T,{...c,children:h.jsx(gH,{scope:t,contentId:f,open:x,stateAttribute:b,trigger:u,onTriggerChange:d,onTriggerEnter:g.useCallback(()=>{l.isOpenDelayedRef.current?C():w()},[l.isOpenDelayedRef,C,w]),onTriggerLeave:g.useCallback(()=>{m?k():(window.clearTimeout(p.current),p.current=0)},[k,m]),onOpen:w,onClose:k,disableHoverableContent:m,children:n})})};ZP.displayName=zc;var Dv="TooltipTrigger",QP=g.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Xf(Dv,n),s=x_(Dv,n),o=Gf(n),a=g.useRef(null),l=qt(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(FT,{asChild:!0,...o,children:h.jsx(Et.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...r,ref:l,onPointerMove:Pe(e.onPointerMove,f=>{f.pointerType!=="touch"&&!u.current&&!s.isPointerInTransitRef.current&&(i.onTriggerEnter(),u.current=!0)}),onPointerLeave:Pe(e.onPointerLeave,()=>{i.onTriggerLeave(),u.current=!1}),onPointerDown:Pe(e.onPointerDown,()=>{i.open&&i.onClose(),c.current=!0,document.addEventListener("pointerup",d,{once:!0})}),onFocus:Pe(e.onFocus,()=>{c.current||i.onOpen()}),onBlur:Pe(e.onBlur,i.onClose),onClick:Pe(e.onClick,i.onClose)})})});QP.displayName=Dv;var vH="TooltipPortal",[Gne,xH]=Kf(vH,{forceMount:void 0}),Oa="TooltipContent",JP=g.forwardRef((e,t)=>{const n=xH(Oa,e.__scopeTooltip),{forceMount:r=n.forceMount,side:i="top",...s}=e,o=Xf(Oa,e.__scopeTooltip);return h.jsx($i,{present:r||o.open,children:o.disableHoverableContent?h.jsx(eI,{side:i,...s,ref:t}):h.jsx(_H,{side:i,...s,ref:t})})}),_H=g.forwardRef((e,t)=>{const n=Xf(Oa,e.__scopeTooltip),r=x_(Oa,e.__scopeTooltip),i=g.useRef(null),s=qt(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 y=m.currentTarget,x={x:m.clientX,y:m.clientY},_=kH(x,y.getBoundingClientRect()),b=CH(x,_),w=EH(v.getBoundingClientRect()),k=TH([...b,...w]);a(k),d(!0)},[d]);return g.useEffect(()=>()=>f(),[f]),g.useEffect(()=>{if(l&&u){const m=y=>p(y,u),v=y=>p(y,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 y=v.target,x={x:v.clientX,y:v.clientY},_=(l==null?void 0:l.contains(y))||(u==null?void 0:u.contains(y)),b=!NH(x,o);_?f():b&&(f(),c())};return document.addEventListener("pointermove",m),()=>document.removeEventListener("pointermove",m)}},[l,u,o,c,f]),h.jsx(eI,{...e,ref:s})}),[yH,bH]=Kf(zc,{isInside:!1}),wH=h$("TooltipContent"),eI=g.forwardRef((e,t)=>{const{__scopeTooltip:n,children:r,"aria-label":i,onEscapeKeyDown:s,onPointerDownOutside:o,...a}=e,l=Xf(Oa,n),c=Gf(n),{onClose:u}=l;return g.useEffect(()=>(document.addEventListener(jv,u),()=>document.removeEventListener(jv,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(Of,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:o,onFocusOutside:d=>d.preventDefault(),onDismiss:u,children:h.jsxs(HT,{"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(wH,{children:r}),h.jsx(yH,{scope:n,isInside:!0,children:h.jsx(fH,{id:l.contentId,role:"tooltip",children:i||r})})]})})});JP.displayName=Oa;var tI="TooltipArrow",SH=g.forwardRef((e,t)=>{const{__scopeTooltip:n,...r}=e,i=Gf(n);return bH(tI,n).isInside?null:h.jsx(UT,{...i,...r,ref:t})});SH.displayName=tI;function kH(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 CH(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 EH(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 NH(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 TH(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),PH(t)}function PH(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 IH=YP,RH=ZP,MH=QP,nI=JP;const __=IH,y_=RH,b_=MH,Yf=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>h.jsx(nI,{ref:r,sideOffset:t,className:ne("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}));Yf.displayName=nI.displayName;function rI({value:e,onChange:t}){return h.jsx(__,{delayDuration:150,children:h.jsx("div",{className:"flex items-center gap-1 flex-wrap","data-testid":"session-icon-picker",children:cT.map(n=>{const r=n.Icon,i=e===n.key;return h.jsxs(y_,{children:[h.jsx(b_,{asChild:!0,children:h.jsx("button",{type:"button",onClick:()=>t(i?null:n.key),"data-testid":`session-icon-option-${n.key}`,"aria-label":n.label,"aria-pressed":i,className:ne("w-8 h-8 rounded-md flex items-center justify-center transition-colors cursor-pointer",i?"bg-text-100/10 ring-1 ring-text-100/30":"hover:bg-text-100/5"),children:h.jsx(r,{className:ne("w-4 h-4",n.colorClass)})})}),h.jsx(Yf,{side:"bottom",children:n.label})]},n.key)})})})}function AH({open:e,initialLabel:t,initialIconKey:n,placeholder:r,onSubmit:i,onCancel:s}){const[o,a]=g.useState(t),[l,c]=g.useState(n);return g.useEffect(()=>{e&&(a(t),c(n))},[e,t,n]),g.useEffect(()=>{if(!e)return;const u=d=>{d.key==="Escape"&&s()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[e,s]),e?nu.createPortal(h.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:s,"data-testid":"session-edit-dialog-overlay",children:h.jsxs("div",{"data-testid":"session-edit-dialog",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:u=>u.stopPropagation(),children:[h.jsx("div",{className:"text-[15px] font-semibold text-text-100",children:"Edit session"}),h.jsxs("div",{children:[h.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:"Label"}),h.jsx("input",{autoFocus:!0,type:"text",value:o,onChange:u=>a(u.target.value),placeholder:r,"data-testid":"session-edit-dialog-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",{children:[h.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:"Icon"}),h.jsx(rI,{value:l,onChange:c})]}),h.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[h.jsx("button",{type:"button",onClick:s,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:()=>i({label:o.trim(),iconKey:l}),"data-testid":"session-edit-dialog-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",children:"Save"})]})]})}),document.body):null}const jH=10,DH=20,LH=16,OH=20,BH=60,zH=4;function $H({session:e,active:t,hasUnread:n,running:r=!1,awaitingUser:i=!1,onSelect:s,onEdit:o,onDelete:a,onPin:l,depth:c=0,chevron:u,showCopyResume:d=!0,contactDisplayName:f}){const[p,m]=g.useState(!1),v=!!e.pinnedAt,y=c===0,x=jH+c*DH,_=g.useCallback(async()=>{const C=e.toolSessionId;if(!C)return;const T=`cd ${`'${e.cwd.replace(/'/g,"'\\''")}'`} && claude --resume ${C} --permission-mode bypassPermissions`;try{await navigator.clipboard.writeText(T)}catch{}},[e.toolSessionId,e.cwd]),b=e.appBuilderProject?`[app] ${e.appBuilderProject}`:e.label||e.larkChatName||e.larkChatId||e.cwd.split("/").filter(Boolean).pop()||e.sessionId.slice(0,8),w=e.originOwnerPrincipalId,k=w?`@${f??`…${w.slice(-8)}`}`:null;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":`session-item-${e.sessionId}`,onClick:s,style:{paddingLeft:x,display:"grid",gridTemplateColumns:`${LH}px ${OH}px 1fr auto ${BH}px`,gridTemplateAreas:'"chev icon name dot time" ". . sub sub sub"',columnGap:`${zH}px`,rowGap:"2px",alignItems:"center"},className:ne("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:u??null}),h.jsx("div",{style:{gridArea:"icon"},className:"flex items-center justify-center",children:h.jsx(uH,{iconKey:e.iconKey})}),h.jsxs("div",{style:{gridArea:"name"},className:"flex items-center gap-1 min-w-0",children:[e.dispatchedFromSessionId?h.jsx(n6,{"data-testid":`dispatched-icon-${e.sessionId}`,className:"w-3 h-3 text-accent shrink-0",strokeWidth:2.25,"aria-label":"dispatched from another session",children:h.jsx("title",{children:"由另一个 session dispatch 派生"})}):null,e.shiftFiredFromSessionId?h.jsx(NB,{"data-testid":`shift-fired-icon-${e.sessionId}`,className:"w-3 h-3 text-accent shrink-0",strokeWidth:2.25,"aria-label":"fired by clawd-shift scheduler",children:h.jsx("title",{children:"由 shift 排班到点 fire 派生"})}):null,e.larkChatId?h.jsx(I6,{"data-testid":`lark-chat-icon-${e.sessionId}`,className:"w-3 h-3 text-accent shrink-0",strokeWidth:2.25,"aria-label":"driven by feishu chat",children:h.jsx("title",{children:e.larkChatType==="p2p"?"飞书私聊会话(对方消息驱动)":"飞书群会话(群成员 @ bot 驱动)"})}):null,h.jsx("span",{"data-testid":`session-title-${e.sessionId}`,className:ne("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:b})]}),i?h.jsx(RB,{"data-testid":`awaiting-dot-${e.sessionId}`,style:{gridArea:"dot"},className:"w-3 h-3 text-warning shrink-0 animate-pulse",strokeWidth:2.25,"aria-label":"awaiting user"}):n?h.jsx("span",{"data-testid":`unread-dot-${e.sessionId}`,style:{gridArea:"dot"},className:"w-2 h-2 rounded-full bg-error shrink-0","aria-label":"unread"}):r?h.jsx("span",{"data-testid":`running-dot-${e.sessionId}`,style:{gridArea:"dot"},className:"w-2 h-2 rounded-full bg-success shrink-0 animate-pulse","aria-label":"running"}):null,h.jsx("span",{style:{gridArea:"time"},className:ne("text-[11px] text-text-400/70 text-right shrink-0","transition-opacity duration-150 group-hover:opacity-0"),children:e.updatedAt?s$(e.updatedAt):""}),h.jsxs("span",{style:{gridArea:"sub"},className:ne("flex items-center gap-1.5 text-[11px] text-text-400/70 min-w-0","group-hover:flex-wrap"),children:[k?h.jsx("span",{"data-testid":`session-mirror-chip-${e.sessionId}`,title:`在 ${k.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:k}):null,h.jsx("span",{"data-testid":`session-subtitle-${e.sessionId}`,className:ne("block text-[11px] text-text-400/70 truncate font-mono min-w-0","group-hover:whitespace-normal group-hover:overflow-visible group-hover:break-all"),children:e.cwd.replace(/^\/Users\/[^/]+/,"~")})]}),o||a||l?h.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100 transition-opacity",children:h.jsxs(VP,{modal:!1,children:[h.jsx(qP,{asChild:!0,children:h.jsx("button",{type:"button",onClick:C=>C.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(kv,{className:"w-4 h-4"})})}),h.jsxs(v_,{align:"end",onClick:C=>C.stopPropagation(),children:[l&&y&&h.jsxs(Ys,{onSelect:()=>l(e.sessionId,!v),"data-testid":`session-${v?"unpin":"pin"}-${e.sessionId}`,children:[v?h.jsx(B6,{className:"w-3 h-3 mr-2 text-text-400"}):h.jsx(WN,{className:"w-3 h-3 mr-2 text-text-400"}),v?"Unpin":"Pin"]}),o&&h.jsxs(Ys,{onSelect:()=>m(!0),"data-testid":`session-rename-${e.sessionId}`,children:[h.jsx(UN,{className:"w-3 h-3 mr-2 text-text-400"}),"Rename"]}),d&&e.toolSessionId?h.jsxs(Ys,{onSelect:()=>void _(),"data-testid":`session-copy-resume-${e.sessionId}`,children:[h.jsx(su,{className:"w-3 h-3 mr-2 text-text-400"}),"Copy Resume Command"]}):null,(l||o||d&&e.toolSessionId)&&a&&h.jsx(KP,{}),a&&h.jsxs(Ys,{onSelect:()=>void a(e.sessionId),className:"text-destructive focus:text-destructive focus:bg-destructive/10","data-testid":`session-delete-${e.sessionId}`,children:[h.jsx(Xx,{className:"w-3 h-3 mr-2"}),"Delete"]})]})]})}):null]}),o?h.jsx(AH,{open:p,initialLabel:e.label??"",initialIconKey:e.iconKey??null,placeholder:e.cwd.split("/").pop()||"",onSubmit:C=>{o(e.sessionId,C),m(!1)},onCancel:()=>m(!1)}):null]})}function w_({node:e,depth:t=0,activeId:n,unreadIds:r,runningIds:i,awaitingIds:s,onSelect:o,onEdit:a,onDelete:l,onPin:c,getContactDisplayName:u,showCopyResume:d}){const f=e.children.length>0,{isCollapsed:p,toggle:m}=yB(),v=!p(e.session.sessionId),y=g.useCallback(_=>{_.stopPropagation(),m(e.session.sessionId)},[m,e.session.sessionId]),x=f?h.jsx("button",{type:"button",onClick:y,"data-testid":`session-chevron-${e.session.sessionId}`,"aria-label":v?"collapse":"expand","aria-expanded":v,className:"shrink-0 flex items-center justify-center w-4 h-4 text-text-400 hover:text-text-100 cursor-pointer",children:v?h.jsx(li,{className:"w-3 h-3"}):h.jsx(ci,{className:"w-3 h-3"})}):null;return h.jsxs("div",{"data-testid":`session-tree-node-${e.session.sessionId}`,children:[h.jsx($H,{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,showCopyResume:d,depth:t,chevron:x,contactDisplayName:e.session.originOwnerPrincipalId?u==null?void 0:u(e.session.originOwnerPrincipalId):void 0}),f&&v?h.jsx("div",{"data-testid":`session-tree-children-${e.session.sessionId}`,children:e.children.map(_=>h.jsx(w_,{node:_,depth:t+1,activeId:n,unreadIds:r,runningIds:i,awaitingIds:s,onSelect:o,onEdit:a,onDelete:l,onPin:c,getContactDisplayName:u,showCopyResume:d},_.session.sessionId))}):null]})}function FH(e){return e.forkedFromSessionId??e.dispatchedFromSessionId??e.shiftFiredFromSessionId}function iI(e){e=e.filter(s=>!s.ephemeral);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=FH(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((l,c)=>l.createdAt<c.createdAt?-1:l.createdAt>c.createdAt?1:0);return{session:s,children:a.map(i)}};return[...r].sort(HH).map(i)}function sI(e){return[...e].sort((t,n)=>t.session.updatedAt<n.session.updatedAt?1:t.session.updatedAt>n.session.updatedAt?-1:0)}function HH(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||e.updatedAt<t.updatedAt?1:e.updatedAt>t.updatedAt?-1:0}function UH(e,t){if(e.appBuilderProject)return`[app] ${e.appBuilderProject}`;if(e.label)return e.label;const n=e.cwd.split("/").filter(Boolean).pop();return n||((e.ownerPersonaId?t==null?void 0:t(e.ownerPersonaId):void 0)??"")}function pw(e,t){const n=t.trim().toLowerCase();return n===""?!0:e.toLowerCase().includes(n)}function oI(e){return e.compositionActive||!!e.nativeIsComposing||e.keyCode===229}function aI(e){return e.key==="Enter"&&!e.shiftKey&&!oI(e)}function WH(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(aI({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}}const VH={isCollapsed:()=>!1,toggle:()=>{},prune:()=>{}};function qH({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:y,showCopyResume:x,treatSessionsAsRoots:_,searchQuery:b}){const[w,k]=g.useState(null),[C,N]=g.useState(()=>new Set),T=p??(I=>C.has(I)),L=g.useCallback(I=>{if(m){m(I);return}N(R=>{const D=new Set(R);return D.has(I)?D.delete(I):D.add(I),D})},[m]),P=g.useMemo(()=>i==null?void 0:i.filter(I=>!I.ephemeral),[i]);if(e.length===0)return h.jsx(KH,{});const O=(b??"").trim();return O?h.jsx(Kx.Provider,{value:VH,children:h.jsx("div",{"data-testid":"my-personas-list",className:"flex flex-col gap-0.5",children:e.map(I=>{const R=P?P.filter(F=>F.ownerPersonaId===I.personaId).sort((F,j)=>j.updatedAt>F.updatedAt?1:-1):[],D=pw(I.label,O),z=R.filter(F=>pw(UH(F),O));if(!D&&z.length===0)return null;const $=D?R:z;return h.jsx(mw,{persona:I,active:I.personaId===t,editing:!1,onSelectPersona:n,onSubmitCreateSession:()=>{},onCancelCreateSession:()=>{},personaSessions:$,collapsed:!1,onToggleCollapsed:()=>{},activeSessionId:s??null,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,onEditSession:v,onPinSession:y,showCopyResume:x,treatSessionsAsRoots:_,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f},I.personaId)})})}):h.jsx("div",{"data-testid":"my-personas-list",className:"flex flex-col gap-0.5",children:e.map(I=>{const R=P?P.filter(D=>D.ownerPersonaId===I.personaId).sort((D,z)=>z.updatedAt>D.updatedAt?1:-1):[];return h.jsx(mw,{persona:I,active:I.personaId===t,editing:I.personaId===w,onSelectPersona:n,onStartCreateSession:r?()=>k(I.personaId):void 0,onSubmitCreateSession:D=>{k(null),r==null||r(I.personaId,D)},onCancelCreateSession:()=>k(null),personaSessions:R,collapsed:!T(I.personaId),onToggleCollapsed:()=>L(I.personaId),activeSessionId:s??null,awaitingIds:o,runningIds:a,unreadIds:l,onSelectSession:c,onDeleteSession:u,onEditSession:v,onPinSession:y,showCopyResume:x,treatSessionsAsRoots:_,ownerPrincipalId:d,creatorDisplayNameByOwnerId:f},I.personaId)})})}function KH(){return h.jsx("div",{className:"px-3 py-3 text-[11px] leading-relaxed text-text-400",children:"还没有 persona。点上方 Personas 标题右侧 + 创建第一个。"})}function mw({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:y,onPinSession:x,showCopyResume:_,treatSessionsAsRoots:b,ownerPrincipalId:w,creatorDisplayNameByOwnerId:k}){const C=lI(e.iconKey),N=a.length>0,T=!l,L=g.useMemo(()=>{const I=[],R=new Map;for(const D of a){const z=D.creatorPrincipalId;if(D.larkChatId!=null||!z||w&&z===w){I.push(D);continue}const $=z,F=(k==null?void 0:k.get($))??`…${$.slice(-8)}`,j=R.get($);j?j.sessions.push(D):R.set($,{groupKey:$,displayName:F,sessions:[D]})}return{self:I,byPeer:[...R.values()]}},[a,w,k]),P=L.byPeer.length>0,O=g.useMemo(()=>T&&!P?sI(iI(a)):[],[T,P,a]);return h.jsxs("div",{"data-testid":`persona-node-${e.personaId}`,children:[h.jsxs("div",{className:ne("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:[N?h.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),c()},"aria-label":T?"collapse":"expand","aria-expanded":T,"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:T?h.jsx(li,{className:"h-3 w-3"}):h.jsx(ci,{className:"h-3 w-3"})}):h.jsx("span",{className:"h-4 w-4 shrink-0","aria-hidden":"true"}),h.jsx(C.Component,{className:ne("h-3.5 w-3.5 shrink-0",C.colorClass),"aria-hidden":"true"}),h.jsx("span",{className:"flex-1 truncate text-[13px]",children:e.label}),N?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:I=>{I.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(U6,{className:"h-3.5 w-3.5"})}):null]}),n?h.jsx(GH,{personaId:e.personaId,iconKey:e.iconKey,onSubmit:s,onCancel:o}):null,N&&T?h.jsx("div",{"data-testid":`persona-sessions-${e.personaId}`,children:P?h.jsxs(h.Fragment,{children:[L.self.length>0&&h.jsx(gw,{groupKey:`${e.personaId}-self`,label:"我自己",testId:`persona-sessions-${e.personaId}-self`,sessions:L.self,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:y,onPinSession:x,showCopyResume:_}),L.byPeer.map(I=>h.jsx(gw,{groupKey:`${e.personaId}-peer-${I.groupKey}`,label:I.displayName,testId:`persona-sessions-${e.personaId}-peer-${I.groupKey}`,sessions:I.sessions,activeSessionId:u,awaitingIds:d,runningIds:f,unreadIds:p,onSelectSession:m,onDeleteSession:v,onEditSession:y,onPinSession:x,showCopyResume:_},`${e.personaId}-peer-${I.groupKey}`))]}):O.map(I=>h.jsx(w_,{node:I,depth:b?0:1,activeId:u,unreadIds:p,runningIds:f,awaitingIds:d,onSelect:R=>m==null?void 0:m(R),onDelete:v,onEdit:y,onPin:x,showCopyResume:_},I.session.sessionId))}):null]})}function gw({label:e,testId:t,sessions:n,activeSessionId:r,awaitingIds:i,runningIds:s,unreadIds:o,onSelectSession:a,onDeleteSession:l,onEditSession:c,onPinSession:u,showCopyResume:d}){const[f,p]=g.useState(!1),m=!f,v=g.useMemo(()=>m?sI(iI(n)):[],[m,n]);return h.jsxs("div",{"data-testid":t,children:[h.jsxs("button",{type:"button",onClick:()=>p(y=>!y),"aria-label":m?"collapse":"expand","aria-expanded":m,"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:[m?h.jsx(li,{className:"h-3 w-3"}):h.jsx(ci,{className:"h-3 w-3"}),h.jsx(Yx,{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})]}),m&&h.jsx("div",{children:v.map(y=>h.jsx(w_,{node:y,depth:2,activeId:r,unreadIds:o,runningIds:s,awaitingIds:i,onSelect:x=>a==null?void 0:a(x),onDelete:l,onEdit:c,onPin:u,showCopyResume:d},y.session.sessionId))})]})}function GH({personaId:e,iconKey:t,onSubmit:n,onCancel:r}){const[i,s]=g.useState(""),o=g.useRef(null),a=lI(t),l=i.trim(),c=l.length>0;g.useEffect(()=>{var f;(f=o.current)==null||f.focus()},[]);const u=g.useCallback(()=>{c&&n(l)},[c,l,n]),d=WH(u,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(a.Component,{className:ne("h-3 w-3 shrink-0",a.colorClass),"aria-hidden":"true"}),h.jsx("input",{ref:o,type:"text",value:i,onChange:f=>s(f.target.value),...d,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:f=>{f.preventDefault(),u()},disabled:!c,"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(Qa,{className:"h-3 w-3"})}),h.jsx("button",{type:"button",onMouseDown:f=>{f.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(Rn,{className:"h-3 w-3"})})]})}function lI(e){const t=uT(e);return t?{Component:t.Icon,colorClass:t.colorClass}:{Component:cz,colorClass:"text-text-400"}}function XH(e,t){const n=getComputedStyle(e),r=parseFloat(n.fontSize);return t*r}function YH(e,t){const n=getComputedStyle(e.ownerDocument.documentElement),r=parseFloat(n.fontSize);return t*r}function ZH(e){return e/100*window.innerHeight}function QH(e){return e/100*window.innerWidth}function JH(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 Bl({groupSize:e,panelElement:t,styleProp:n}){let r;const[i,s]=JH(n);switch(s){case"%":{r=i/100*e;break}case"px":{r=i;break}case"rem":{r=YH(t,i);break}case"em":{r=XH(t,i);break}case"vh":{r=ZH(i);break}case"vw":{r=QH(i);break}}return r}function En(e){return parseFloat(e.toFixed(3))}function Ba({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 Lv(e){const{panels:t}=e,n=Ba({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=Bl({groupSize:n,panelElement:i,styleProp:s.collapsedSize});o=En(u/n*100)}let a;if(s.defaultSize!==void 0){const u=Bl({groupSize:n,panelElement:i,styleProp:s.defaultSize});a=En(u/n*100)}let l=0;if(s.minSize!==void 0){const u=Bl({groupSize:n,panelElement:i,styleProp:s.minSize});l=En(u/n*100)}let c=100;if(s.maxSize!==void 0){const u=Bl({groupSize:n,panelElement:i,styleProp:s.maxSize});c=En(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 it(e,t="Assertion error"){if(!e)throw Error(t)}function Ov(e,t){return Array.from(t).sort(e==="horizontal"?e7:t7)}function e7(e,t){const n=e.element.offsetLeft-t.element.offsetLeft;return n!==0?n:e.element.offsetWidth-t.element.offsetWidth}function t7(e,t){const n=e.element.offsetTop-t.element.offsetTop;return n!==0?n:e.element.offsetHeight-t.element.offsetHeight}function cI(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.ELEMENT_NODE}function uI(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 n7({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}=uI(r,o),c=e==="horizontal"?a:l;c<s&&(s=c,i=o)}return it(i,"No rect found"),i}let id;function r7(){return id===void 0&&(typeof matchMedia=="function"?id=!!matchMedia("(pointer:coarse)").matches:id=!1),id}function dI(e){const{element:t,orientation:n,panels:r,separators:i}=e,s=Ov(n,Array.from(t.children).filter(cI).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 y=r.find(x=>x.element===v);if(y){if(f){const x=f.element.getBoundingClientRect(),_=v.getBoundingClientRect();let b;if(l){const w=n==="horizontal"?new DOMRect(x.right,x.top,0,x.height):new DOMRect(x.left,x.bottom,x.width,0),k=n==="horizontal"?new DOMRect(_.left,_.top,0,_.height):new DOMRect(_.left,_.top,_.width,0);switch(p.length){case 0:{b=[w,k];break}case 1:{const C=p[0],N=n7({orientation:n,rects:[x,_],targetRect:C.element.getBoundingClientRect()});b=[C,N===x?k:w];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 w of b){let k="width"in w?w:w.element.getBoundingClientRect();const C=r7()?e.resizeTargetMinimumSize.coarse:e.resizeTargetMinimumSize.fine;if(k.width<C){const T=C-k.width;k=new DOMRect(k.x-T/2,k.y,k.width+T,k.height)}if(k.height<C){const T=C-k.height;k=new DOMRect(k.x,k.y-T/2,k.width,k.height+T)}const N=m<=c||m>u;!a&&!N&&o.push({group:e,groupSize:Ba({group:e}),panels:[f,y],separator:"width"in w?void 0:w,rect:k}),a=!1}}l=!1,f=y,p=[]}}else if(v.hasAttribute("data-separator")){v.ariaDisabled!==null&&(a=!0);const y=i.find(x=>x.element===v);y?p.push(y):(f=void 0,p=[])}else l=!0}return o}var as;class hI{constructor(){ky(this,as,{})}addListener(t,n){const r=dl(this,as)[t];return r===void 0?dl(this,as)[t]=[n]:r.includes(n)||r.push(n),()=>{this.removeListener(t,n)}}emit(t,n){const r=dl(this,as)[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(){Cy(this,as,{})}removeListener(t,n){const r=dl(this,as)[t];if(r!==void 0){const i=r.indexOf(n);i>=0&&r.splice(i,1)}}}as=new WeakMap;let ba={cursorFlags:0,state:"inactive"};const S_=new hI;function mo(){return ba}function i7(e){return S_.addListener("change",e)}function s7(e){const t=ba,n={...ba};n.cursorFlags=e,ba=n,S_.emit("change",{prev:t,next:n})}function wa(e){const t=ba;ba=e,S_.emit("change",{prev:t,next:e})}const o7=e=>e,am=()=>{},fI=1,pI=2,mI=4,gI=8,vw=3,xw=12;let sd;function _w(){return sd===void 0&&(sd=!1,typeof window<"u"&&(window.navigator.userAgent.includes("Chrome")||window.navigator.userAgent.includes("Firefox"))&&(sd=!0)),sd}function a7({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&&_w()){const s=(e&fI)!==0,o=(e&pI)!==0,a=(e&mI)!==0,l=(e&gI)!==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 _w()?r>0&&i>0?"move":r>0?"ew-resize":"ns-resize":r>0&&i>0?"grab":r>0?"col-resize":"row-resize"}}const yw=new WeakMap;function k_(e){if(e.defaultView===null||e.defaultView===void 0)return;let{prevStyle:t,styleSheet:n}=yw.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=mo();switch(r.state){case"active":case"hover":{const i=a7({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}}yw.set(e,{prevStyle:t,styleSheet:n})}let Yr=new Map;const vI=new hI;function l7(e){Yr=new Map(Yr),Yr.delete(e)}function bw(e,t){for(const[n]of Yr)if(n.id===e)return n}function ys(e,t){for(const[n,r]of Yr)if(n.id===e)return r;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Io(){return Yr}function C_(e,t){return vI.addListener("groupChange",n=>{n.group.id===e&&t(n)})}function Di(e,t,n){const r=Yr.get(e);Yr=new Map(Yr),Yr.set(e,t),vI.emit("groupChange",{group:e,isUserInteraction:(n==null?void 0:n.isUserInteraction)===!0,prev:r,next:t})}function xI(e){const t=mo();let n=!1;switch(t.state){case"active":wa({cursorFlags:0,state:"inactive"}),t.hitRegions.length>0&&(k_(e),n=!0,t.hitRegions.forEach(r=>{const i=ys(r.group.id,!0);Di(r.group,i,{isUserInteraction:!0})}))}return n}function ww(e){e.defaultPrevented||xI(e.currentTarget)}function c7(e,t,n){let r,i={x:1/0,y:1/0};for(const s of t){const o=uI(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 u7(e){return e!==null&&typeof e=="object"&&"nodeType"in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function d7(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Cw(e),b:Cw(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();it(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:kw(Sw(n.a)),b:kw(Sw(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 h7=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function f7(e){const t=getComputedStyle(_I(e)??e).display;return t==="flex"||t==="inline-flex"}function p7(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||f7(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"||h7.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Sw(e){let t=e.length;for(;t--;){const n=e[t];if(it(n,"Missing node"),p7(n))return n}return null}function kw(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Cw(e){const t=[];for(;e;)t.push(e),e=_I(e);return t}function _I(e){const{parentNode:t}=e;return u7(t)?t.host:t}function m7(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 g7({groupElement:e,hitRegion:t,pointerEventTarget:n}){if(!cI(n)||n.contains(e)||e.contains(n))return!0;if(d7(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(m7(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function E_(e,t){const n=[];return t.forEach((r,i)=>{if(i.disabled)return;const s=dI(i),o=c7(i.orientation,s,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&g7({groupElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&n.push(o.hitRegion)}),n}function v7(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 xn(e,t,n=0){return Math.abs(En(e)-En(t))<=n}function qr(e,t){return xn(e,t)?0:e>t?1:-1}function ua({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(qr(r,l)<0)if(s){const c=(i+l)/2;qr(r,c)<0?r=i:r=l}else r=l;return r=Math.min(a,r),r=En(r),r}function $c({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(xn(e,0))return t;const o=s==="imperative-api",a=Object.values(t),l=Object.values(i),c=[...a],[u,d]=r;it(u!=null,"Invalid first pivot index"),it(d!=null,"Invalid second pivot index");let f=0;switch(s){case"keyboard":{{const v=e<0?d:u,y=n[v];it(y,`Panel constraints not found for index ${v}`);const{collapsedSize:x=0,collapsible:_,minSize:b=0}=y;if(_){const w=a[v];if(it(w!=null,`Previous layout not found for panel index ${v}`),xn(w,x)){const k=b-w;qr(k,Math.abs(e))>0&&(e=e<0?0-k:k)}}}{const v=e<0?u:d,y=n[v];it(y,`No panel constraints found for index ${v}`);const{collapsedSize:x=0,collapsible:_,minSize:b=0}=y;if(_){const w=a[v];if(it(w!=null,`Previous layout not found for panel index ${v}`),xn(w,b)){const k=w-x;qr(k,Math.abs(e))>0&&(e=e<0?0-k:k)}}}break}default:{const v=e<0?d:u,y=n[v];it(y,`Panel constraints not found for index ${v}`);const x=a[v],{collapsible:_,collapsedSize:b,minSize:w}=y;if(_&&qr(x,w)<0)if(e>0){const k=w-b,C=k/2,N=x+e;qr(N,w)<0&&(e=qr(e,C)<=0?0:k)}else{const k=w-b,C=100-k/2,N=x-e;qr(N,w)<0&&(e=qr(100+e,C)>0?0:-k)}break}}{const v=e<0?1:-1;let y=e<0?d:u,x=0;for(;;){const b=a[y];it(b!=null,`Previous layout not found for panel index ${y}`);const w=ua({overrideDisabledPanels:o,panelConstraints:n[y],prevSize:b,size:100})-b;if(x+=w,y+=v,y<0||y>=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 y=Math.abs(e)-Math.abs(f),x=a[v];it(x!=null,`Previous layout not found for panel index ${v}`);const _=x-y,b=ua({overrideDisabledPanels:o,panelConstraints:n[v],prevSize:x,size:_});if(!xn(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(v7(l,c))return i;{const v=e<0?d:u,y=a[v];it(y!=null,`Previous layout not found for panel index ${v}`);const x=y+f,_=ua({overrideDisabledPanels:o,panelConstraints:n[v],prevSize:y,size:x});if(c[v]=_,!xn(_,x)){let b=x-_,w=e<0?d:u;for(;w>=0&&w<n.length;){const k=c[w];it(k!=null,`Previous layout not found for panel index ${w}`);const C=k+b,N=ua({overrideDisabledPanels:o,panelConstraints:n[w],prevSize:k,size:C});if(xn(k,N)||(b-=N-k,c[w]=N),xn(b,0))break;e>0?w--:w++}}}const p=Object.values(c).reduce((v,y)=>y+v,0);if(!xn(p,100,.1))return i;const m=Object.keys(i);return c.reduce((v,y,x)=>(v[m[x]]=y,v),{})}function go(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(t[n]===void 0||qr(e[n],t[n])!==0)return!1;return!0}function vo({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(!xn(i,100)&&r.length>0)for(let a=0;a<t.length;a++){const l=r[a];it(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];it(l!=null,`No layout data found for index ${a}`);const c=r[a];it(c!=null,`No layout data found for index ${a}`);const u=ua({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:l,size:c});c!=u&&(s+=c-u,r[a]=u)}if(!xn(s,0))for(let a=0;a<t.length;a++){const l=r[a];it(l!=null,`No layout data found for index ${a}`);const c=l+s,u=ua({overrideDisabledPanels:!0,panelConstraints:t[a],prevSize:l,size:c});if(l!==u&&(s-=u-l,r[a]=u,xn(s,0)))break}const o=Object.keys(e);return r.reduce((a,l,c)=>(a[o[c]]=l,a),{})}function yI({groupId:e,panelId:t}){const n=()=>{const l=Io();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(y=>y.id===t),m=p===0,v=p===c.length-1;if(v&&l<f&&(m||c.slice(0,p).every((y,x)=>{const _=d[x];return(_==null?void 0:_.collapsible)&&xn(_.collapsedSize,u[_.panelId])}))){const y=c.slice(0,p).reduce((x,_)=>x+u[_.id],0);return{...u,[t]:En(100-y)}}return $c({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(),y=o({nextSize:l,panels:f.panels,prevLayout:m,derivedPanelConstraints:d}),x=vo({layout:y,panelConstraints:d});go(m,x)||Di(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&&xn(c,u)},resize:l=>{const{group:c}=n(),{element:u}=i(),d=Ba({group:c}),f=Bl({groupSize:d,panelElement:u,styleProp:l}),p=En(f/d*100);a(p)}}}function Ew(e){if(e.defaultPrevented)return;const t=Io();E_(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=yI({groupId:n.group.id,panelId:r.id});s&&i!==void 0&&(s.resize(i),e.preventDefault())}}})}function Od(e){const t=Io();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 bI({groupId:e}){const t=()=>{const n=Io();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=vo({layout:n,panelConstraints:i});return r?a:(go(a,c)||Di(s,{defaultLayoutDeferred:r,derivedPanelConstraints:i,groupSize:o,layout:c,separatorToPanels:l}),c)}}}function Os(e,t){const n=Od(e),r=ys(n.id,!0),i=n.separators.find(u=>u.element===e);it(i,"Matching separator not found");const s=r.separatorToPanels.get(i);it(s,"Matching panels not found");const o=s.map(u=>n.panels.indexOf(u)),a=bI({groupId:n.id}).getLayout(),l=$c({delta:t,initialLayout:a,panelConstraints:r.derivedPanelConstraints,pivotIndices:o,prevLayout:a,trigger:"keyboard"}),c=vo({layout:l,panelConstraints:r.derivedPanelConstraints});go(a,c)||Di(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedPanelConstraints:r.derivedPanelConstraints,groupSize:r.groupSize,layout:c,separatorToPanels:r.separatorToPanels},{isUserInteraction:!0})}function Nw(e){if(e.defaultPrevented)return;const t=e.currentTarget,n=Od(t);if(!n.disabled)switch(e.key){case"ArrowDown":{e.preventDefault(),n.orientation==="vertical"&&Os(t,5);break}case"ArrowLeft":{e.preventDefault(),n.orientation==="horizontal"&&Os(t,-5);break}case"ArrowRight":{e.preventDefault(),n.orientation==="horizontal"&&Os(t,5);break}case"ArrowUp":{e.preventDefault(),n.orientation==="vertical"&&Os(t,-5);break}case"End":{e.preventDefault(),Os(t,100);break}case"Enter":{e.preventDefault();const r=Od(t),i=ys(r.id,!0),{derivedPanelConstraints:s,layout:o,separatorToPanels:a}=i,l=r.separators.find(f=>f.element===t);it(l,"Matching separator not found");const c=a.get(l);it(c,"Matching panels not found");const u=c[0],d=s.find(f=>f.panelId===u.id);if(it(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;Os(t,p-f)}break}case"F6":{e.preventDefault();const r=Od(t).separators.map(o=>o.element),i=Array.from(r).findIndex(o=>o===e.currentTarget);it(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(),Os(t,-100);break}}}function Tw(e){if(e.defaultPrevented||e.pointerType==="mouse"&&e.button>0)return;const t=Io(),n=E_(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)}),wa({cursorFlags:0,hitRegions:n,initialLayoutMap:r,pointerDownAtPoint:{x:e.clientX,y:e.clientY},state:"active"}),n.length&&e.preventDefault()}function wI({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 y=r.get(u),x=i.get(u);if(!y||!x)return;const{defaultLayoutDeferred:_,derivedPanelConstraints:b,groupSize:w,layout:k,separatorToPanels:C}=x;if(b&&k&&C){const N=$c({delta:v,initialLayout:y,panelConstraints:b,pivotIndices:c.panels.map(T=>p.indexOf(T)),prevLayout:k,trigger:"mouse-or-touch"});if(go(N,k)){if(v!==0&&!m)switch(f){case"horizontal":{a|=v<0?fI:pI;break}case"vertical":{a|=v<0?mI:gI;break}}}else Di(c.group,{defaultLayoutDeferred:_,derivedPanelConstraints:b,groupSize:w,layout:N,separatorToPanels:C})}});let l=0;t.movementX===0?l|=o&vw:l|=a&vw,t.movementY===0?l|=o&xw:l|=a&xw,s7(l),k_(e)}function Pw(e){const t=Io(),n=mo();switch(n.state){case"active":wI({document:e.currentTarget,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedGroups:t,prevCursorFlags:n.cursorFlags})}}function Iw(e){var r,i;if(e.defaultPrevented)return;const t=mo(),n=Io();switch(t.state){case"active":{if(e.buttons===0){wa({cursorFlags:0,state:"inactive"}),t.hitRegions.forEach(s=>{const o=ys(s.group.id,!0);Di(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))}wI({document:e.currentTarget,event:e,hitRegions:t.hitRegions,initialLayoutMap:t.initialLayoutMap,mountedGroups:n,pointerDownAtPoint:t.pointerDownAtPoint,prevCursorFlags:t.cursorFlags});break}default:{const s=E_(e,n);s.length===0?t.state!=="inactive"&&wa({cursorFlags:0,state:"inactive"}):wa({cursorFlags:0,hitRegions:s,state:"hover"}),k_(e.currentTarget);break}}}function Rw(e){if(e.relatedTarget instanceof HTMLIFrameElement)switch(mo().state){case"hover":wa({cursorFlags:0,state:"inactive"})}}function Mw(e){e.defaultPrevented||e.pointerType==="mouse"&&e.button>0||xI(e.currentTarget)&&e.preventDefault()}function Aw(e){let t=0,n=0;const r={};for(const s of e)if(s.defaultSize!==void 0){t++;const o=En(s.defaultSize);n+=o,r[s.panelId]=o}else r[s.panelId]=void 0;const i=e.length-t;if(i!==0){const s=En((100-n)/i);for(const o of e)o.defaultSize===void 0&&(r[o.panelId]=s)}return r}function x7(e,t,n){if(!n[0])return;const r=e.panels.find(l=>l.element===t);if(!r||!r.onResize)return;const i=Ba({group:e}),s=e.orientation==="horizontal"?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,a={asPercentage:En(s/i*100),inPixels:s};r.mutableValues.prevSize=a,r.onResize(a,r.id,o)}function _7(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 y7({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=En(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]=En(f/s*c)}else{const d=En(c/l.length);for(const f of l)u[f]=d}return u}function b7(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 Uo=new Map;function w7(e){let t=!0;it(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:y,target:x}=v;if(x===e.element){if(t){const _=Ba({group:e});if(_===0)return;const b=ys(e.id);if(!b)return;const w=Lv(e),k=b.defaultLayoutDeferred?Aw(w):b.layout,C=y7({group:e,nextGroupSize:_,prevGroupSize:b.groupSize,prevLayout:k}),N=vo({layout:C,panelConstraints:w});if(!b.defaultLayoutDeferred&&go(b.layout,N)&&_7(b.derivedPanelConstraints,w)&&b.groupSize===_)return;Di(e,{defaultLayoutDeferred:!1,derivedPanelConstraints:w,groupSize:_,layout:N,separatorToPanels:b.separatorToPanels})}}else x7(e,x,y)}});s.observe(e.element),e.panels.forEach(m=>{it(!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=Ba({group:e}),a=Lv(e),l=e.panels.map(({id:m})=>m).join(",");let c=e.mutableState.defaultLayout;c&&(b7(e.panels,c)||(c=void 0));const u=e.mutableState.layouts[l]??c??Aw(a),d=vo({layout:u,panelConstraints:a}),f=e.element.ownerDocument;Uo.set(f,(Uo.get(f)??0)+1);const p=new Map;return dI(e).forEach(m=>{m.separator&&p.set(m.separator,m.panels)}),Di(e,{defaultLayoutDeferred:o===0,derivedPanelConstraints:a,groupSize:o,layout:d,separatorToPanels:p}),e.separators.forEach(m=>{it(!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",Nw)}),Uo.get(f)===1&&(f.addEventListener("contextmenu",ww,!0),f.addEventListener("dblclick",Ew,!0),f.addEventListener("pointerdown",Tw,!0),f.addEventListener("pointerleave",Pw),f.addEventListener("pointermove",Iw),f.addEventListener("pointerout",Rw),f.addEventListener("pointerup",Mw,!0)),function(){t=!1,Uo.set(f,Math.max(0,(Uo.get(f)??0)-1)),l7(e),e.separators.forEach(m=>{m.element.removeEventListener("keydown",Nw)}),Uo.get(f)||(f.removeEventListener("contextmenu",ww,!0),f.removeEventListener("dblclick",Ew,!0),f.removeEventListener("pointerdown",Tw,!0),f.removeEventListener("pointerleave",Pw),f.removeEventListener("pointermove",Iw),f.removeEventListener("pointerout",Rw),f.removeEventListener("pointerup",Mw,!0)),s.disconnect()}}function S7(){const[e,t]=g.useState({}),n=g.useCallback(()=>t({}),[]);return[e,n]}function N_(e){const t=g.useId();return`${e??t}`}const Ro=typeof window<"u"?g.useLayoutEffect:g.useEffect;function rc(e){const t=g.useRef(e);return Ro(()=>{t.current=e},[e]),g.useCallback((...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[t])}function T_(...e){return rc(t=>{e.forEach(n=>{if(n)switch(typeof n){case"function":{n(t);break}case"object":{n.current=t;break}}})})}function P_(e){const t=g.useRef({...e});return Ro(()=>{for(const n in e)t.current[n]=e[n]},[e]),t.current}const SI=g.createContext(null);function k7(e,t){const n=g.useRef({getLayout:()=>({}),setLayout:o7});g.useImperativeHandle(t,()=>n.current,[]),Ro(()=>{Object.assign(n.current,bI({groupId:e}))})}function I_({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=rc(O=>{go(m.current.onLayoutChange,O)||(m.current.onLayoutChange=O,l==null||l(O))}),y=rc((O,I)=>{go(m.current.onLayoutChanged,O)||(m.current.onLayoutChanged=O,c==null||c(O,{isUserInteraction:I}))}),x=N_(a),_=g.useRef(null),[b,w]=S7(),k=g.useRef({lastExpandedPanelSizes:{},layouts:{},panels:[],resizeTargetMinimumSize:d,separators:[]}),C=T_(_,s);k7(x,o);const N=rc((O,I)=>{const R=mo(),D=bw(O),z=ys(O);if(z){let $=!1;switch(R.state){case"active":{$=R.hitRegions.some(F=>F.group===D);break}}return{flexGrow:z.layout[I]??1,pointerEvents:$?"none":void 0}}if(n!=null&&n[I])return{flexGrow:n==null?void 0:n[I]}}),T=P_({defaultLayout:n,disableCursor:r}),L=g.useMemo(()=>({get disableCursor(){return!!T.disableCursor},getPanelStyles:N,id:x,orientation:u,registerPanel:O=>{const I=k.current;return I.panels=Ov(u,[...I.panels,O]),w(),()=>{I.panels=I.panels.filter(R=>R!==O),w()}},registerSeparator:O=>{const I=k.current;return I.separators=Ov(u,[...I.separators,O]),w(),()=>{I.separators=I.separators.filter(R=>R!==O),w()}},updatePanelProps:(O,{disabled:I})=>{const R=k.current.panels.find($=>$.id===O);R&&(R.panelConstraints.disabled=I);const D=bw(x),z=ys(x);D&&z&&Di(D,{...z,derivedPanelConstraints:Lv(D)})},updateSeparatorProps:(O,{disabled:I,disableDoubleClick:R})=>{const D=k.current.separators.find(z=>z.id===O);D&&(D.disabled=I,D.disableDoubleClick=R)}}),[N,x,w,u,T]),P=g.useRef(null);return Ro(()=>{const O=_.current;if(O===null)return;const I=k.current;let R;if(T.defaultLayout!==void 0&&Object.keys(T.defaultLayout).length===I.panels.length){R={};for(const E of I.panels){const H=T.defaultLayout[E.id];H!==void 0&&(R[E.id]=H)}}const D={disabled:!!i,element:O,id:x,mutableState:{defaultLayout:R,disableCursor:!!T.disableCursor,expandedPanelSizes:k.current.lastExpandedPanelSizes,layouts:k.current.layouts},orientation:u,panels:I.panels,resizeTargetMinimumSize:I.resizeTargetMinimumSize,separators:I.separators};P.current=D;const z=w7(D),{defaultLayoutDeferred:$,derivedPanelConstraints:F,layout:j}=ys(D.id,!0);!$&&F.length>0&&(v(j),y(j,!1));const B=C_(x,E=>{const{defaultLayoutDeferred:H,derivedPanelConstraints:q,layout:M}=E.next;if(H||q.length===0)return;const re=D.panels.map(({id:V})=>V).join(",");D.mutableState.layouts[re]=M,q.forEach(V=>{if(V.collapsible){const{layout:pe}=E.prev??{};if(pe){const Oe=xn(V.collapsedSize,M[V.panelId]),ie=xn(V.collapsedSize,pe[V.panelId]);Oe&&!ie&&(D.mutableState.expandedPanelSizes[V.panelId]=pe[V.panelId])}}});const oe=mo().state!=="active";v(M),oe&&y(M,E.isUserInteraction)});return()=>{P.current=null,z(),B()}},[i,x,y,v,u,b,T]),g.useEffect(()=>{const O=P.current;O&&(O.mutableState.defaultLayout=n,O.mutableState.disableCursor=!!r)}),h.jsx(SI.Provider,{value:L,children:h.jsx("div",{...p,className:t,"data-group":!0,"data-testid":x,id:x,ref:C,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})})}I_.displayName="Group";function R_(){const e=g.useContext(SI);return it(e,"Group Context not found; did you render a Panel or Separator outside of a Group?"),e}function C7(e,t){const{id:n}=R_(),r=g.useRef({collapse:am,expand:am,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:am});g.useImperativeHandle(t,()=>r.current,[]),Ro(()=>{Object.assign(r.current,yI({groupId:n,panelId:e}))})}function Fc({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,y=N_(l),x=P_({disabled:s}),_=g.useRef(null),b=T_(_,o),{getPanelStyles:w,id:k,orientation:C,registerPanel:N,updatePanelProps:T}=R_(),L=d!==null,P=rc((D,z,$)=>{d==null||d(D,l,$)});Ro(()=>{const D=_.current;if(D!==null){const z={element:D,id:y,idIsStable:v,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:L?P:void 0,panelConstraints:{groupResizeBehavior:a,collapsedSize:n,collapsible:r,defaultSize:i,disabled:x.disabled,maxSize:c,minSize:u}};return N(z)}},[a,n,r,i,L,y,v,c,u,P,N,x]),g.useEffect(()=>{T(y,{disabled:s})},[s,y,T]),C7(y,f);const O=()=>{const D=w(k,y);if(D)return JSON.stringify(D)},I=g.useSyncExternalStore(D=>C_(k,D),O,O);let R;return I?R=JSON.parse(I):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":y,id:y,ref:b,style:{...E7,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:C==="horizontal"?"pan-y":"pan-x"},children:e})})}Fc.displayName="Panel";const E7={minHeight:0,maxHeight:"100%",height:"auto",minWidth:0,maxWidth:"100%",width:"auto",border:"none",borderWidth:0,padding:0,margin:0};function N7({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=vo({layout:$c({delta:c-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n],i=vo({layout:$c({delta:l-o,initialLayout:e,panelConstraints:t,pivotIndices:u,prevLayout:e}),panelConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:s,valueNow:o}}function M_({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:s,style:o,...a}){const l=N_(s),c=P_({disabled:n,disableDoubleClick:r}),[u,d]=g.useState({}),[f,p]=g.useState("inactive"),[m,v]=g.useState(!1),y=g.useRef(null),x=T_(y,i),{disableCursor:_,id:b,orientation:w,registerSeparator:k,updateSeparatorProps:C}=R_(),N=w==="horizontal"?"vertical":"horizontal";Ro(()=>{const P=y.current;if(P!==null){const O={disabled:c.disabled,disableDoubleClick:c.disableDoubleClick,element:P,id:l},I=k(O),R=i7(z=>{p(z.next.state!=="inactive"&&z.next.hitRegions.some($=>$.separator===O)?z.next.state:"inactive")}),D=C_(b,z=>{const{derivedPanelConstraints:$,layout:F,separatorToPanels:j}=z.next,B=j.get(O);if(B){const E=B[0],H=B.indexOf(E);d(N7({layout:F,panelConstraints:$,panelId:E.id,panelIndex:H}))}});return()=>{R(),D(),I()}}},[b,l,k,c]),g.useEffect(()=>{C(l,{disabled:n,disableDoubleClick:r})},[n,r,l,C]);let T;n&&!_&&(T="not-allowed");let L;if(n)L="disabled";else switch(f){case"active":{L="active";break}default:m?L="focus":L=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":L,"data-testid":l,id:l,onBlur:()=>v(!1),onFocus:()=>v(!0),ref:x,role:"separator",style:{flexBasis:"auto",cursor:T,...o,flexGrow:0,flexShrink:0,touchAction:"none"},tabIndex:n?void 0:0})}M_.displayName="Separator";function T7(e,t,n,r=!0){const i=g.useRef({sid:null,tsid:void 0});g.useEffect(()=>{const s=i.current;i.current={sid:t,tsid:n},!(!r||!n||s.sid===t&&(s.tsid===void 0||s.tsid===null)&&typeof n=="string")&&e.sessionObserve({sessionId:t,toolSessionId:n}).catch(()=>{})},[e,t,n,r])}function P7(e,t,n){const r=g.useRef(e),i=g.useRef(t),s=g.useRef(n);s.current=n,g.useEffect(()=>{const o=r.current,a=i.current;r.current=e,i.current=t;const l=o!==e,c=typeof a=="string"&&t==null;!l&&!c||s.current()},[e,t])}const I7=/^Scheduled (?:recurring job|one-shot task) ([0-9a-f]{8}) \(([^)]+)\)/;function R7(e){const t=new Map,n=new Map,r=new Map;for(const i of e)if(i.kind==="tool_call"&&i.tool==="CronCreate"){const s=i.input;if(!s||typeof s.cron!="string"||typeof s.prompt!="string")continue;const o=i.ts;t.set(i.toolUseId,{cron:s.cron,prompt:s.prompt,recurring:s.recurring!==!1,ts:typeof o=="string"?o:"",toolUseId:i.toolUseId})}else if(i.kind==="tool_call"&&i.tool==="CronDelete"){const s=i.input;if(!s||typeof s.id!="string")continue;n.set(i.toolUseId,s.id)}else if(i.kind==="tool_result"){const s=t.get(i.toolUseId);if(s){if(t.delete(i.toolUseId),i.error||typeof i.output!="string")continue;const a=i.output.match(I7);if(!a)continue;r.set(a[1],{id:a[1],cron:s.cron,prompt:s.prompt,recurring:s.recurring,humanSchedule:a[2],createdAt:s.ts,toolUseId:s.toolUseId});continue}const o=n.get(i.toolUseId);o!==void 0&&(n.delete(i.toolUseId),i.error||r.delete(o))}return Array.from(r.values()).sort((i,s)=>i.createdAt.localeCompare(s.createdAt))}const M7=["TaskCreate","TaskUpdate","TaskList","TaskGet"];function A7(e){return M7.includes(e)}function kI(e){return e==="in_progress"||e==="completed"?e:"pending"}function j7(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:kI(n.status),activeForm:i,description:s}]}function D7(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=kI(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 L7(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=j7(t,i.input);break;case"TaskUpdate":t=D7(t,i.input);break}}return{tasks:t,lastEventIndex:n}}function O7(e){const{tasks:t,lastEventIndex:n}=L7(e);let r=-1;for(let c=e.length-1;c>=0;c--)if(e[c].kind==="todo-checklist"){r=c;break}const i=[],s=new Map,o=new Map,a=new Map,l=(c,u)=>{var f,p,m;const d={agentId:u.agentId,status:u.status};u.description?d.description=u.description:(f=c.progress)!=null&&f.description&&(d.description=c.progress.description),u.lastToolName?d.lastToolName=u.lastToolName:(p=c.progress)!=null&&p.lastToolName&&(d.lastToolName=c.progress.lastToolName),u.stats?d.stats=u.stats:(m=c.progress)!=null&&m.stats&&(d.stats=c.progress.stats),c.progress=d};for(let c=0;c<e.length;c++){const u=e[c];switch(u.kind){case"tool-call":{const d={kind:"merged-tool",seq:u.seq,tool:u.tool,toolKind:u.toolKind,toolUseId:u.toolUseId,input:u.input,pending:!0};s.set(u.toolUseId,i.length),i.push(d);break}case"tool-result":{const d=s.get(u.toolUseId);if(d!==void 0){const p=i[d];p.output=u.output,p.error=u.error,p.pending=!1,s.delete(u.toolUseId);break}const f=o.get(u.toolUseId);if(f!==void 0){const p=i[f];p.output=u.output,p.error=u.error,p.pending=!1,u.toolResultExtra&&(p.toolResultExtra=u.toolResultExtra);break}break}case"agent-call":{const d={kind:"merged-agent",seq:u.seq,toolUseId:u.toolUseId,description:u.description,input:u.input,pending:!0,notifications:[]};o.set(u.toolUseId,i.length),i.push(d);const f=a.get(u.toolUseId);f&&(l(d,f),a.delete(u.toolUseId));break}case"agent-progress":{const d=o.get(u.toolUseId);if(d!==void 0){l(i[d],u);break}a.set(u.toolUseId,u);break}case"agent-notification":{const d=u.parentToolUseId;if(d){const f=o.get(d);if(f!==void 0){i[f].notifications.push({text:u.text,taskId:u.taskId});break}}i.push({kind:"agent-notification",seq:u.seq,text:u.text,taskId:u.taskId,parentToolUseId:u.parentToolUseId});break}case"todo-checklist":{c===r&&u.todos.length>0&&i.push({kind:"todo-checklist",seq:u.seq,toolUseId:u.toolUseId,todos:u.todos});break}case"task-event":{c===n&&t.length>0&&i.push({kind:"plan-card",seq:u.seq,tasks:t});break}default:i.push(u)}}return i}const B7=/<(system-reminder|related-dir|clawd-shift-fire)\b[^>]*>[\s\S]*?<\/\1>/gi,z7=/<builder-preview\b[^>]*\/>/gi;function CI(e){return e?e.replace(B7,"").replace(z7,"").trim():""}const $7=CI;function F7(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const H7=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,U7=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,W7={};function jw(e,t){return(W7.jsx?U7:H7).test(e)}const V7=/[ \t\n\f\r]/g;function q7(e){return typeof e=="object"?e.type==="text"?Dw(e.value):!1:Dw(e)}function Dw(e){return e.replace(V7,"")===""}class du{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}du.prototype.normal={};du.prototype.property={};du.prototype.space=void 0;function EI(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new du(n,r,t)}function Bv(e){return e.toLowerCase()}class Vn{constructor(t,n){this.attribute=n,this.property=t}}Vn.prototype.attribute="";Vn.prototype.booleanish=!1;Vn.prototype.boolean=!1;Vn.prototype.commaOrSpaceSeparated=!1;Vn.prototype.commaSeparated=!1;Vn.prototype.defined=!1;Vn.prototype.mustUseProperty=!1;Vn.prototype.number=!1;Vn.prototype.overloadedBoolean=!1;Vn.prototype.property="";Vn.prototype.spaceSeparated=!1;Vn.prototype.space=void 0;let K7=0;const Ie=Mo(),Mt=Mo(),zv=Mo(),Y=Mo(),lt=Mo(),Sa=Mo(),Xn=Mo();function Mo(){return 2**++K7}const $v=Object.freeze(Object.defineProperty({__proto__:null,boolean:Ie,booleanish:Mt,commaOrSpaceSeparated:Xn,commaSeparated:Sa,number:Y,overloadedBoolean:zv,spaceSeparated:lt},Symbol.toStringTag,{value:"Module"})),lm=Object.keys($v);class A_ extends Vn{constructor(t,n,r,i){let s=-1;if(super(t,n),Lw(this,"space",i),typeof r=="number")for(;++s<lm.length;){const o=lm[s];Lw(this,lm[s],(r&$v[o])===$v[o])}}}A_.prototype.defined=!0;function Lw(e,t,n){n&&(e[t]=n)}function tl(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new A_(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[Bv(r)]=r,n[Bv(s.attribute)]=r}return new du(t,n,e.space)}const NI=tl({properties:{ariaActiveDescendant:null,ariaAtomic:Mt,ariaAutoComplete:null,ariaBusy:Mt,ariaChecked:Mt,ariaColCount:Y,ariaColIndex:Y,ariaColSpan:Y,ariaControls:lt,ariaCurrent:null,ariaDescribedBy:lt,ariaDetails:null,ariaDisabled:Mt,ariaDropEffect:lt,ariaErrorMessage:null,ariaExpanded:Mt,ariaFlowTo:lt,ariaGrabbed:Mt,ariaHasPopup:null,ariaHidden:Mt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:lt,ariaLevel:Y,ariaLive:null,ariaModal:Mt,ariaMultiLine:Mt,ariaMultiSelectable:Mt,ariaOrientation:null,ariaOwns:lt,ariaPlaceholder:null,ariaPosInSet:Y,ariaPressed:Mt,ariaReadOnly:Mt,ariaRelevant:null,ariaRequired:Mt,ariaRoleDescription:lt,ariaRowCount:Y,ariaRowIndex:Y,ariaRowSpan:Y,ariaSelected:Mt,ariaSetSize:Y,ariaSort:null,ariaValueMax:Y,ariaValueMin:Y,ariaValueNow:Y,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function TI(e,t){return t in e?e[t]:t}function PI(e,t){return TI(e,t.toLowerCase())}const G7=tl({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:Sa,acceptCharset:lt,accessKey:lt,action:null,allow:null,allowFullScreen:Ie,allowPaymentRequest:Ie,allowUserMedia:Ie,alt:null,as:null,async:Ie,autoCapitalize:null,autoComplete:lt,autoFocus:Ie,autoPlay:Ie,blocking:lt,capture:null,charSet:null,checked:Ie,cite:null,className:lt,cols:Y,colSpan:null,content:null,contentEditable:Mt,controls:Ie,controlsList:lt,coords:Y|Sa,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Ie,defer:Ie,dir:null,dirName:null,disabled:Ie,download:zv,draggable:Mt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Ie,formTarget:null,headers:lt,height:Y,hidden:zv,high:Y,href:null,hrefLang:null,htmlFor:lt,httpEquiv:lt,id:null,imageSizes:null,imageSrcSet:null,inert:Ie,inputMode:null,integrity:null,is:null,isMap:Ie,itemId:null,itemProp:lt,itemRef:lt,itemScope:Ie,itemType:lt,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Ie,low:Y,manifest:null,max:null,maxLength:Y,media:null,method:null,min:null,minLength:Y,multiple:Ie,muted:Ie,name:null,nonce:null,noModule:Ie,noValidate:Ie,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Ie,optimum:Y,pattern:null,ping:lt,placeholder:null,playsInline:Ie,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Ie,referrerPolicy:null,rel:lt,required:Ie,reversed:Ie,rows:Y,rowSpan:Y,sandbox:lt,scope:null,scoped:Ie,seamless:Ie,selected:Ie,shadowRootClonable:Ie,shadowRootDelegatesFocus:Ie,shadowRootMode:null,shape:null,size:Y,sizes:null,slot:null,span:Y,spellCheck:Mt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Y,step:null,style:null,tabIndex:Y,target:null,title:null,translate:null,type:null,typeMustMatch:Ie,useMap:null,value:Mt,width:Y,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:lt,axis:null,background:null,bgColor:null,border:Y,borderColor:null,bottomMargin:Y,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Ie,declare:Ie,event:null,face:null,frame:null,frameBorder:null,hSpace:Y,leftMargin:Y,link:null,longDesc:null,lowSrc:null,marginHeight:Y,marginWidth:Y,noResize:Ie,noHref:Ie,noShade:Ie,noWrap:Ie,object:null,profile:null,prompt:null,rev:null,rightMargin:Y,rules:null,scheme:null,scrolling:Mt,standby:null,summary:null,text:null,topMargin:Y,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Y,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Ie,disableRemotePlayback:Ie,prefix:null,property:null,results:Y,security:null,unselectable:null},space:"html",transform:PI}),X7=tl({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:Xn,accentHeight:Y,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Y,amplitude:Y,arabicForm:null,ascent:Y,attributeName:null,attributeType:null,azimuth:Y,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Y,by:null,calcMode:null,capHeight:Y,className:lt,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Y,diffuseConstant:Y,direction:null,display:null,dur:null,divisor:Y,dominantBaseline:null,download:Ie,dx:null,dy:null,edgeMode:null,editable:null,elevation:Y,enableBackground:null,end:null,event:null,exponent:Y,externalResourcesRequired:null,fill:null,fillOpacity:Y,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:Sa,g2:Sa,glyphName:Sa,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Y,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Y,horizOriginX:Y,horizOriginY:Y,id:null,ideographic:Y,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Y,k:Y,k1:Y,k2:Y,k3:Y,k4:Y,kernelMatrix:Xn,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Y,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Y,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Y,overlineThickness:Y,paintOrder:null,panose1:null,path:null,pathLength:Y,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:lt,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Y,pointsAtY:Y,pointsAtZ:Y,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Xn,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Xn,rev:Xn,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Xn,requiredFeatures:Xn,requiredFonts:Xn,requiredFormats:Xn,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Y,specularExponent:Y,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Y,strikethroughThickness:Y,string:null,stroke:null,strokeDashArray:Xn,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Y,strokeOpacity:Y,strokeWidth:null,style:null,surfaceScale:Y,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Xn,tabIndex:Y,tableValues:null,target:null,targetX:Y,targetY:Y,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Xn,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Y,underlineThickness:Y,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Y,values:null,vAlphabetic:Y,vMathematical:Y,vectorEffect:null,vHanging:Y,vIdeographic:Y,version:null,vertAdvY:Y,vertOriginX:Y,vertOriginY:Y,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Y,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:TI}),II=tl({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),RI=tl({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:PI}),MI=tl({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Y7={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},Z7=/[A-Z]/g,Ow=/-[a-z]/g,Q7=/^data[-\w.:]+$/i;function J7(e,t){const n=Bv(t);let r=t,i=Vn;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Q7.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(Ow,tU);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!Ow.test(s)){let o=s.replace(Z7,eU);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=A_}return new i(r,t)}function eU(e){return"-"+e.toLowerCase()}function tU(e){return e.charAt(1).toUpperCase()}const nU=EI([NI,G7,II,RI,MI],"html"),j_=EI([NI,X7,II,RI,MI],"svg");function rU(e){return e.join(" ").trim()}var D_={},Bw=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,iU=/\n/g,sU=/^\s*/,oU=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,aU=/^:\s*/,lU=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,cU=/^[;\s]*/,uU=/^\s+|\s+$/g,dU=`
491
491
  `,zw="/",$w="*",Vs="",hU="comment",fU="declaration";function pU(e,t){if(typeof e!="string")throw new TypeError("First argument must be a string");if(!e)return[];t=t||{};var n=1,r=1;function i(m){var v=m.match(iU);v&&(n+=v.length);var y=m.lastIndexOf(dU);r=~y?m.length-y:r+m.length}function s(){var m={line:n,column:r};return function(v){return v.position=new o(m),c(),v}}function o(m){this.start=m,this.end={line:n,column:r},this.source=t.source}o.prototype.content=e;function a(m){var v=new Error(t.source+":"+n+":"+r+": "+m);if(v.reason=m,v.filename=t.source,v.line=n,v.column=r,v.source=e,!t.silent)throw v}function l(m){var v=m.exec(e);if(v){var y=v[0];return i(y),e=e.slice(y.length),v}}function c(){l(sU)}function u(m){var v;for(m=m||[];v=d();)v!==!1&&m.push(v);return m}function d(){var m=s();if(!(zw!=e.charAt(0)||$w!=e.charAt(1))){for(var v=2;Vs!=e.charAt(v)&&($w!=e.charAt(v)||zw!=e.charAt(v+1));)++v;if(v+=2,Vs===e.charAt(v-1))return a("End of comment missing");var y=e.slice(2,v-2);return r+=2,i(y),e=e.slice(v),r+=2,m({type:hU,comment:y})}}function f(){var m=s(),v=l(oU);if(v){if(d(),!l(aU))return a("property missing ':'");var y=l(lU),x=m({type:fU,property:Fw(v[0].replace(Bw,Vs)),value:y?Fw(y[0].replace(Bw,Vs)):Vs});return l(cU),x}}function p(){var m=[];u(m);for(var v;v=f();)v!==!1&&(m.push(v),u(m));return m}return c(),p()}function Fw(e){return e?e.replace(uU,Vs):Vs}var mU=pU,gU=Kd&&Kd.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(D_,"__esModule",{value:!0});D_.default=xU;const vU=gU(mU);function xU(e,t){let n=null;if(!e||typeof e!="string")return n;const r=(0,vU.default)(e),i=typeof t=="function";return r.forEach(s=>{if(s.type!=="declaration")return;const{property:o,value:a}=s;i?t(o,a,s):a&&(n=n||{},n[o]=a)}),n}var Zf={};Object.defineProperty(Zf,"__esModule",{value:!0});Zf.camelCase=void 0;var _U=/^--[a-zA-Z0-9_-]+$/,yU=/-([a-z])/g,bU=/^[^-]+$/,wU=/^-(webkit|moz|ms|o|khtml)-/,SU=/^-(ms)-/,kU=function(e){return!e||bU.test(e)||_U.test(e)},CU=function(e,t){return t.toUpperCase()},Hw=function(e,t){return"".concat(t,"-")},EU=function(e,t){return t===void 0&&(t={}),kU(e)?e:(e=e.toLowerCase(),t.reactCompat?e=e.replace(SU,Hw):e=e.replace(wU,Hw),e.replace(yU,CU))};Zf.camelCase=EU;var NU=Kd&&Kd.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},TU=NU(D_),PU=Zf;function Fv(e,t){var n={};return!e||typeof e!="string"||(0,TU.default)(e,function(r,i){r&&i&&(n[(0,PU.camelCase)(r,t)]=i)}),n}Fv.default=Fv;var IU=Fv;const RU=Yc(IU),AI=jI("end"),L_=jI("start");function jI(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function MU(e){const t=L_(e),n=AI(e);if(t&&n)return{start:t,end:n}}function ic(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Uw(e.position):"start"in e||"end"in e?Uw(e):"line"in e||"column"in e?Hv(e):""}function Hv(e){return Ww(e&&e.line)+":"+Ww(e&&e.column)}function Uw(e){return Hv(e&&e.start)+"-"+Hv(e&&e.end)}function Ww(e){return e&&typeof e=="number"?e:1}class wn extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},o=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?i=t:!s.cause&&t&&(o=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?s.ruleId=r:(s.source=r.slice(0,l),s.ruleId=r.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){const l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}const a=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=ic(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=o&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}wn.prototype.file="";wn.prototype.name="";wn.prototype.reason="";wn.prototype.message="";wn.prototype.stack="";wn.prototype.column=void 0;wn.prototype.line=void 0;wn.prototype.ancestors=void 0;wn.prototype.cause=void 0;wn.prototype.fatal=void 0;wn.prototype.place=void 0;wn.prototype.ruleId=void 0;wn.prototype.source=void 0;const O_={}.hasOwnProperty,AU=new Map,jU=/[A-Z]/g,DU=new Set(["table","tbody","thead","tfoot","tr"]),LU=new Set(["td","th"]),DI="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function OU(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=VU(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=WU(n,t.jsx,t.jsxs)}const i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?j_:nU,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=LI(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function LI(e,t,n){if(t.type==="element")return BU(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return zU(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return FU(e,t,n);if(t.type==="mdxjsEsm")return $U(e,t);if(t.type==="root")return HU(e,t,n);if(t.type==="text")return UU(e,t)}function BU(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=j_,e.schema=i),e.ancestors.push(t);const s=BI(e,t.tagName,!1),o=qU(e,t);let a=z_(e,t);return DU.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!q7(l):!0})),OI(e,o,s,t),B_(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function zU(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}Hc(e,t.position)}function $U(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Hc(e,t.position)}function FU(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=j_,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:BI(e,t.name,!0),o=KU(e,t),a=z_(e,t);return OI(e,o,s,t),B_(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function HU(e,t,n){const r={};return B_(r,z_(e,t)),e.create(t,e.Fragment,r,n)}function UU(e,t){return t.value}function OI(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function B_(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function WU(e,t,n){return r;function r(i,s,o,a){const c=Array.isArray(o.children)?n:t;return a?c(s,o,a):c(s,o)}}function VU(e,t){return n;function n(r,i,s,o){const a=Array.isArray(s.children),l=L_(r);return t(i,s,o,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function qU(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&O_.call(t.properties,i)){const s=GU(e,i,t.properties[i]);if(s){const[o,a]=s;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&LU.has(t.tagName)?r=a:n[o]=a}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function KU(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const s=r.data.estree.body[0];s.type;const o=s.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else Hc(e,t.position);else{const i=r.name;let s;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,s=e.evaluater.evaluateExpression(a.expression)}else Hc(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function z_(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:AU;for(;++r<t.children.length;){const s=t.children[r];let o;if(e.passKeys){const l=s.type==="element"?s.tagName:s.type==="mdxJsxFlowElement"||s.type==="mdxJsxTextElement"?s.name:void 0;if(l){const c=i.get(l)||0;o=l+"-"+c,i.set(l,c+1)}}const a=LI(e,s,o);a!==void 0&&n.push(a)}return n}function GU(e,t,n){const r=J7(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?F7(n):rU(n)),r.property==="style"){let i=typeof n=="object"?n:XU(e,String(n));return e.stylePropertyNameCase==="css"&&(i=YU(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?Y7[r.property]||r.property:r.attribute,n]}}function XU(e,t){try{return RU(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new wn("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw i.file=e.filePath||void 0,i.url=DI+"#cannot-parse-style-attribute",i}}function BI(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,o;for(;++s<i.length;){const a=jw(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(s&&a.type==="Literal"),optional:!1}:a}r=o}else r=jw(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return O_.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);Hc(e)}function Hc(e,t){const n=new wn("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=DI+"#cannot-handle-mdx-estrees-without-createevaluater",n}function YU(e){const t={};let n;for(n in e)O_.call(e,n)&&(t[ZU(n)]=e[n]);return t}function ZU(e){let t=e.replace(jU,QU);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function QU(e){return"-"+e.toLowerCase()}const cm={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},JU={};function $_(e,t){const n=JU,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return zI(e,r,i)}function zI(e,t,n){if(eW(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return Vw(e.children,t,n)}return Array.isArray(e)?Vw(e,t,n):""}function Vw(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=zI(e[i],t,n);return r.join("")}function eW(e){return!!(e&&typeof e=="object")}const qw=document.createElement("i");function F_(e){const t="&"+e+";";qw.innerHTML=t;const n=qw.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function tr(e,t,n,r){const i=e.length;let s=0,o;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);s<r.length;)o=r.slice(s,s+1e4),o.unshift(t,0),e.splice(...o),s+=1e4,t+=1e4}function pr(e,t){return e.length>0?(tr(e,e.length,0,t),e):t}const Kw={}.hasOwnProperty;function $I(e){const t={};let n=-1;for(;++n<e.length;)tW(t,e[n]);return t}function tW(e,t){let n;for(n in t){const i=(Kw.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let o;if(s)for(o in s){Kw.call(i,o)||(i[o]=[]);const a=s[o];nW(i[o],Array.isArray(a)?a:a?[a]:[])}}}function nW(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);tr(e,0,0,r)}function FI(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function Ar(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Cn=js(/[A-Za-z]/),yn=js(/[\dA-Za-z]/),rW=js(/[#-'*+\--9=?A-Z^-~]/);function $h(e){return e!==null&&(e<32||e===127)}const Uv=js(/\d/),iW=js(/[\dA-Fa-f]/),sW=js(/[!-/:-@[-`{-~]/);function be(e){return e!==null&&e<-2}function ot(e){return e!==null&&(e<0||e===32)}function ze(e){return e===-2||e===-1||e===32}const Qf=js(new RegExp("\\p{P}|\\p{S}","u")),xo=js(/\s/);function js(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function nl(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let o="";if(s===37&&yn(e.charCodeAt(n+1))&&yn(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(o=String.fromCharCode(s));else if(s>55295&&s<57344){const a=e.charCodeAt(n+1);s<56320&&a>56319&&a<57344?(o=String.fromCharCode(s,a),i=1):o="�"}else o=String.fromCharCode(s);o&&(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,o=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function Ve(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return o;function o(l){return ze(l)?(e.enter(n),a(l)):t(l)}function a(l){return ze(l)&&s++<i?(e.consume(l),a):(e.exit(n),t(l))}}const oW={tokenize:aW};function aW(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),Ve(e,t,"linePrefix")}function i(a){return e.enter("paragraph"),s(a)}function s(a){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,o(a)}function o(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return be(a)?(e.consume(a),e.exit("chunkText"),s):(e.consume(a),o)}}const lW={tokenize:cW},Gw={tokenize:uW};function cW(e){const t=this,n=[];let r=0,i,s,o;return a;function a(b){if(r<n.length){const w=n[r];return t.containerState=w[1],e.attempt(w[0].continuation,l,c)(b)}return c(b)}function l(b){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&_();const w=t.events.length;let k=w,C;for(;k--;)if(t.events[k][0]==="exit"&&t.events[k][1].type==="chunkFlow"){C=t.events[k][1].end;break}x(r);let N=w;for(;N<t.events.length;)t.events[N][1].end={...C},N++;return tr(t.events,k+1,0,t.events.slice(w)),t.events.length=N,c(b)}return a(b)}function c(b){if(r===n.length){if(!i)return f(b);if(i.currentConstruct&&i.currentConstruct.concrete)return m(b);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Gw,u,d)(b)}function u(b){return i&&_(),x(r),f(b)}function d(b){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(b)}function f(b){return t.containerState={},e.attempt(Gw,p,m)(b)}function p(b){return r++,n.push([t.currentConstruct,t.containerState]),f(b)}function m(b){if(b===null){i&&_(),x(0),e.consume(b);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),v(b)}function v(b){if(b===null){y(e.exit("chunkFlow"),!0),x(0),e.consume(b);return}return be(b)?(e.consume(b),y(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(b),v)}function y(b,w){const k=t.sliceStream(b);if(w&&k.push(null),b.previous=s,s&&(s.next=b),s=b,i.defineSkip(b.start),i.write(k),t.parser.lazy[b.start.line]){let C=i.events.length;for(;C--;)if(i.events[C][1].start.offset<o&&(!i.events[C][1].end||i.events[C][1].end.offset>o))return;const N=t.events.length;let T=N,L,P;for(;T--;)if(t.events[T][0]==="exit"&&t.events[T][1].type==="chunkFlow"){if(L){P=t.events[T][1].end;break}L=!0}for(x(r),C=N;C<t.events.length;)t.events[C][1].end={...P},C++;tr(t.events,T+1,0,t.events.slice(N)),t.events.length=C}}function x(b){let w=n.length;for(;w-- >b;){const k=n[w];t.containerState=k[1],k[0].exit.call(t,e)}n.length=b}function _(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function uW(e,t,n){return Ve(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function za(e){if(e===null||ot(e)||xo(e))return 1;if(Qf(e))return 2}function Jf(e,t,n){const r=[];let i=-1;for(;++i<e.length;){const s=e[i].resolveAll;s&&!r.includes(s)&&(t=s(t,n),r.push(s))}return t}const Wv={name:"attention",resolveAll:dW,tokenize:hW};function dW(e,t){let n=-1,r,i,s,o,a,l,c,u;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const d={...e[r][1].end},f={...e[n][1].start};Xw(d,-l),Xw(f,l),o={type:l>1?"strongSequence":"emphasisSequence",start:d,end:{...e[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:f},s={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...o.start},end:{...a.end}},e[r][1].end={...o.start},e[n][1].start={...a.end},c=[],e[r][1].end.offset-e[r][1].start.offset&&(c=pr(c,[["enter",e[r][1],t],["exit",e[r][1],t]])),c=pr(c,[["enter",i,t],["enter",o,t],["exit",o,t],["enter",s,t]]),c=pr(c,Jf(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),c=pr(c,[["exit",s,t],["enter",a,t],["exit",a,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,c=pr(c,[["enter",e[n][1],t],["exit",e[n][1],t]])):u=0,tr(e,r-1,n-r+3,c),n=r+c.length-u-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function hW(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=za(r);let s;return o;function o(l){return s=l,e.enter("attentionSequence"),a(l)}function a(l){if(l===s)return e.consume(l),a;const c=e.exit("attentionSequence"),u=za(l),d=!u||u===2&&i||n.includes(l),f=!i||i===2&&u||n.includes(r);return c._open=!!(s===42?d:d&&(i||!f)),c._close=!!(s===42?f:f&&(u||!d)),t(l)}}function Xw(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const fW={name:"autolink",tokenize:pW};function pW(e,t,n){let r=0;return i;function i(p){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(p){return Cn(p)?(e.consume(p),o):p===64?n(p):c(p)}function o(p){return p===43||p===45||p===46||yn(p)?(r=1,a(p)):c(p)}function a(p){return p===58?(e.consume(p),r=0,l):(p===43||p===45||p===46||yn(p))&&r++<32?(e.consume(p),a):(r=0,c(p))}function l(p){return p===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):p===null||p===32||p===60||$h(p)?n(p):(e.consume(p),l)}function c(p){return p===64?(e.consume(p),u):rW(p)?(e.consume(p),c):n(p)}function u(p){return yn(p)?d(p):n(p)}function d(p){return p===46?(e.consume(p),r=0,u):p===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):f(p)}function f(p){if((p===45||yn(p))&&r++<63){const m=p===45?f:d;return e.consume(p),m}return n(p)}}const hu={partial:!0,tokenize:mW};function mW(e,t,n){return r;function r(s){return ze(s)?Ve(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||be(s)?t(s):n(s)}}const HI={continuation:{tokenize:vW},exit:xW,name:"blockQuote",tokenize:gW};function gW(e,t,n){const r=this;return i;function i(o){if(o===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(o),e.exit("blockQuoteMarker"),s}return n(o)}function s(o){return ze(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(o))}}function vW(e,t,n){const r=this;return i;function i(o){return ze(o)?Ve(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):s(o)}function s(o){return e.attempt(HI,t,n)(o)}}function xW(e){e.exit("blockQuote")}const UI={name:"characterEscape",tokenize:_W};function _W(e,t,n){return r;function r(s){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(s),e.exit("escapeMarker"),i}function i(s){return sW(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const WI={name:"characterReference",tokenize:yW};function yW(e,t,n){const r=this;let i=0,s,o;return a;function a(d){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),l}function l(d){return d===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(d),e.exit("characterReferenceMarkerNumeric"),c):(e.enter("characterReferenceValue"),s=31,o=yn,u(d))}function c(d){return d===88||d===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(d),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,o=iW,u):(e.enter("characterReferenceValue"),s=7,o=Uv,u(d))}function u(d){if(d===59&&i){const f=e.exit("characterReferenceValue");return o===yn&&!F_(r.sliceSerialize(f))?n(d):(e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return o(d)&&i++<s?(e.consume(d),u):n(d)}}const Yw={partial:!0,tokenize:wW},Zw={concrete:!0,name:"codeFenced",tokenize:bW};function bW(e,t,n){const r=this,i={partial:!0,tokenize:k};let s=0,o=0,a;return l;function l(C){return c(C)}function c(C){const N=r.events[r.events.length-1];return s=N&&N[1].type==="linePrefix"?N[2].sliceSerialize(N[1],!0).length:0,a=C,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),u(C)}function u(C){return C===a?(o++,e.consume(C),u):o<3?n(C):(e.exit("codeFencedFenceSequence"),ze(C)?Ve(e,d,"whitespace")(C):d(C))}function d(C){return C===null||be(C)?(e.exit("codeFencedFence"),r.interrupt?t(C):e.check(Yw,v,w)(C)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),f(C))}function f(C){return C===null||be(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),d(C)):ze(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),Ve(e,p,"whitespace")(C)):C===96&&C===a?n(C):(e.consume(C),f)}function p(C){return C===null||be(C)?d(C):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),m(C))}function m(C){return C===null||be(C)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),d(C)):C===96&&C===a?n(C):(e.consume(C),m)}function v(C){return e.attempt(i,w,y)(C)}function y(C){return e.enter("lineEnding"),e.consume(C),e.exit("lineEnding"),x}function x(C){return s>0&&ze(C)?Ve(e,_,"linePrefix",s+1)(C):_(C)}function _(C){return C===null||be(C)?e.check(Yw,v,w)(C):(e.enter("codeFlowValue"),b(C))}function b(C){return C===null||be(C)?(e.exit("codeFlowValue"),_(C)):(e.consume(C),b)}function w(C){return e.exit("codeFenced"),t(C)}function k(C,N,T){let L=0;return P;function P(z){return C.enter("lineEnding"),C.consume(z),C.exit("lineEnding"),O}function O(z){return C.enter("codeFencedFence"),ze(z)?Ve(C,I,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(z):I(z)}function I(z){return z===a?(C.enter("codeFencedFenceSequence"),R(z)):T(z)}function R(z){return z===a?(L++,C.consume(z),R):L>=o?(C.exit("codeFencedFenceSequence"),ze(z)?Ve(C,D,"whitespace")(z):D(z)):T(z)}function D(z){return z===null||be(z)?(C.exit("codeFencedFence"),N(z)):T(z)}}}function wW(e,t,n){const r=this;return i;function i(o){return o===null?n(o):(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}const um={name:"codeIndented",tokenize:kW},SW={partial:!0,tokenize:CW};function kW(e,t,n){const r=this;return i;function i(c){return e.enter("codeIndented"),Ve(e,s,"linePrefix",5)(c)}function s(c){const u=r.events[r.events.length-1];return u&&u[1].type==="linePrefix"&&u[2].sliceSerialize(u[1],!0).length>=4?o(c):n(c)}function o(c){return c===null?l(c):be(c)?e.attempt(SW,o,l)(c):(e.enter("codeFlowValue"),a(c))}function a(c){return c===null||be(c)?(e.exit("codeFlowValue"),o(c)):(e.consume(c),a)}function l(c){return e.exit("codeIndented"),t(c)}}function CW(e,t,n){const r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):be(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):Ve(e,s,"linePrefix",5)(o)}function s(o){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):be(o)?i(o):n(o)}}const EW={name:"codeText",previous:TW,resolve:NW,tokenize:PW};function NW(e){let t=e.length-4,n=3,r,i;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(i=r):(r===t||e[r][1].type==="lineEnding")&&(e[i][1].type="codeTextData",r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function TW(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function PW(e,t,n){let r=0,i,s;return o;function o(d){return e.enter("codeText"),e.enter("codeTextSequence"),a(d)}function a(d){return d===96?(e.consume(d),r++,a):(e.exit("codeTextSequence"),l(d))}function l(d){return d===null?n(d):d===32?(e.enter("space"),e.consume(d),e.exit("space"),l):d===96?(s=e.enter("codeTextSequence"),i=0,u(d)):be(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),l):(e.enter("codeTextData"),c(d))}function c(d){return d===null||d===32||d===96||be(d)?(e.exit("codeTextData"),l(d)):(e.consume(d),c)}function u(d){return d===96?(e.consume(d),i++,u):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(d)):(s.type="codeTextData",c(d))}}class IW{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&Sl(this.left,r),s.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Sl(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Sl(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Sl(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Sl(this.left,n.reverse())}}}function Sl(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function VI(e){const t={};let n=-1,r,i,s,o,a,l,c;const u=new IW(e);for(;++n<u.length;){for(;n in t;)n=t[n];if(r=u.get(n),n&&r[1].type==="chunkFlow"&&u.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,RW(u,n)),n=t[n],c=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(o=u.get(s),o[1].type==="lineEnding"||o[1].type==="lineEndingBlank")o[0]==="enter"&&(i&&(u.get(i)[1].type="lineEndingBlank"),o[1].type="lineEnding",i=s);else if(!(o[1].type==="linePrefix"||o[1].type==="listItemIndent"))break;i&&(r[1].end={...u.get(i)[1].start},a=u.slice(i,n),a.unshift(r),u.splice(i,n-i+1,a))}}return tr(e,0,Number.POSITIVE_INFINITY,u.slice(0)),!c}function RW(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));const a=o.events,l=[],c={};let u,d,f=-1,p=n,m=0,v=0;const y=[v];for(;p;){for(;e.get(++i)[1]!==p;);s.push(i),p._tokenizer||(u=r.sliceStream(p),p.next||u.push(null),d&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(u),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++f<a.length;)a[f][0]==="exit"&&a[f-1][0]==="enter"&&a[f][1].type===a[f-1][1].type&&a[f][1].start.line!==a[f][1].end.line&&(v=f+1,y.push(v),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):y.pop(),f=y.length;f--;){const x=a.slice(y[f],y[f+1]),_=s.pop();l.push([_,_+x.length-1]),e.splice(_,2,x)}for(l.reverse(),f=-1;++f<l.length;)c[m+l[f][0]]=m+l[f][1],m+=l[f][1]-l[f][0]-1;return c}const MW={resolve:jW,tokenize:DW},AW={partial:!0,tokenize:LW};function jW(e){return VI(e),e}function DW(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(a)}function i(a){return a===null?s(a):be(a)?e.check(AW,o,s)(a):(e.consume(a),i)}function s(a){return e.exit("chunkContent"),e.exit("content"),t(a)}function o(a){return e.consume(a),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function LW(e,t,n){const r=this;return i;function i(o){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),Ve(e,s,"linePrefix")}function s(o){if(o===null||be(o))return n(o);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):e.interrupt(r.parser.constructs.flow,n,t)(o)}}function qI(e,t,n,r,i,s,o,a,l){const c=l||Number.POSITIVE_INFINITY;let u=0;return d;function d(x){return x===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(x),e.exit(s),f):x===null||x===32||x===41||$h(x)?n(x):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),v(x))}function f(x){return x===62?(e.enter(s),e.consume(x),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),p(x))}function p(x){return x===62?(e.exit("chunkString"),e.exit(a),f(x)):x===null||x===60||be(x)?n(x):(e.consume(x),x===92?m:p)}function m(x){return x===60||x===62||x===92?(e.consume(x),p):p(x)}function v(x){return!u&&(x===null||x===41||ot(x))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(x)):u<c&&x===40?(e.consume(x),u++,v):x===41?(e.consume(x),u--,v):x===null||x===32||x===40||$h(x)?n(x):(e.consume(x),x===92?y:v)}function y(x){return x===40||x===41||x===92?(e.consume(x),v):v(x)}}function KI(e,t,n,r,i,s){const o=this;let a=0,l;return c;function c(p){return e.enter(r),e.enter(i),e.consume(p),e.exit(i),e.enter(s),u}function u(p){return a>999||p===null||p===91||p===93&&!l||p===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(p):p===93?(e.exit(s),e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):be(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),u):(e.enter("chunkString",{contentType:"string"}),d(p))}function d(p){return p===null||p===91||p===93||be(p)||a++>999?(e.exit("chunkString"),u(p)):(e.consume(p),l||(l=!ze(p)),p===92?f:d)}function f(p){return p===91||p===92||p===93?(e.consume(p),a++,d):d(p)}}function GI(e,t,n,r,i,s){let o;return a;function a(f){return f===34||f===39||f===40?(e.enter(r),e.enter(i),e.consume(f),e.exit(i),o=f===40?41:f,l):n(f)}function l(f){return f===o?(e.enter(i),e.consume(f),e.exit(i),e.exit(r),t):(e.enter(s),c(f))}function c(f){return f===o?(e.exit(s),l(o)):f===null?n(f):be(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),Ve(e,c,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),u(f))}function u(f){return f===o||f===null||be(f)?(e.exit("chunkString"),c(f)):(e.consume(f),f===92?d:u)}function d(f){return f===o||f===92?(e.consume(f),u):u(f)}}function sc(e,t){let n;return r;function r(i){return be(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):ze(i)?Ve(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const OW={name:"definition",tokenize:zW},BW={partial:!0,tokenize:$W};function zW(e,t,n){const r=this;let i;return s;function s(p){return e.enter("definition"),o(p)}function o(p){return KI.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=Ar(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(e.enter("definitionMarker"),e.consume(p),e.exit("definitionMarker"),l):n(p)}function l(p){return ot(p)?sc(e,c)(p):c(p)}function c(p){return qI(e,u,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function u(p){return e.attempt(BW,d,d)(p)}function d(p){return ze(p)?Ve(e,f,"whitespace")(p):f(p)}function f(p){return p===null||be(p)?(e.exit("definition"),r.parser.defined.push(i),t(p)):n(p)}}function $W(e,t,n){return r;function r(a){return ot(a)?sc(e,i)(a):n(a)}function i(a){return GI(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function s(a){return ze(a)?Ve(e,o,"whitespace")(a):o(a)}function o(a){return a===null||be(a)?t(a):n(a)}}const FW={name:"hardBreakEscape",tokenize:HW};function HW(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return be(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const UW={name:"headingAtx",resolve:WW,tokenize:VW};function WW(e,t){let n=e.length-2,r=3,i,s;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},s={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},tr(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function VW(e,t,n){let r=0;return i;function i(u){return e.enter("atxHeading"),s(u)}function s(u){return e.enter("atxHeadingSequence"),o(u)}function o(u){return u===35&&r++<6?(e.consume(u),o):u===null||ot(u)?(e.exit("atxHeadingSequence"),a(u)):n(u)}function a(u){return u===35?(e.enter("atxHeadingSequence"),l(u)):u===null||be(u)?(e.exit("atxHeading"),t(u)):ze(u)?Ve(e,a,"whitespace")(u):(e.enter("atxHeadingText"),c(u))}function l(u){return u===35?(e.consume(u),l):(e.exit("atxHeadingSequence"),a(u))}function c(u){return u===null||u===35||ot(u)?(e.exit("atxHeadingText"),a(u)):(e.consume(u),c)}}const qW=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Qw=["pre","script","style","textarea"],KW={concrete:!0,name:"htmlFlow",resolveTo:YW,tokenize:ZW},GW={partial:!0,tokenize:JW},XW={partial:!0,tokenize:QW};function YW(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function ZW(e,t,n){const r=this;let i,s,o,a,l;return c;function c(M){return u(M)}function u(M){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(M),d}function d(M){return M===33?(e.consume(M),f):M===47?(e.consume(M),s=!0,v):M===63?(e.consume(M),i=3,r.interrupt?t:E):Cn(M)?(e.consume(M),o=String.fromCharCode(M),y):n(M)}function f(M){return M===45?(e.consume(M),i=2,p):M===91?(e.consume(M),i=5,a=0,m):Cn(M)?(e.consume(M),i=4,r.interrupt?t:E):n(M)}function p(M){return M===45?(e.consume(M),r.interrupt?t:E):n(M)}function m(M){const re="CDATA[";return M===re.charCodeAt(a++)?(e.consume(M),a===re.length?r.interrupt?t:I:m):n(M)}function v(M){return Cn(M)?(e.consume(M),o=String.fromCharCode(M),y):n(M)}function y(M){if(M===null||M===47||M===62||ot(M)){const re=M===47,oe=o.toLowerCase();return!re&&!s&&Qw.includes(oe)?(i=1,r.interrupt?t(M):I(M)):qW.includes(o.toLowerCase())?(i=6,re?(e.consume(M),x):r.interrupt?t(M):I(M)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(M):s?_(M):b(M))}return M===45||yn(M)?(e.consume(M),o+=String.fromCharCode(M),y):n(M)}function x(M){return M===62?(e.consume(M),r.interrupt?t:I):n(M)}function _(M){return ze(M)?(e.consume(M),_):P(M)}function b(M){return M===47?(e.consume(M),P):M===58||M===95||Cn(M)?(e.consume(M),w):ze(M)?(e.consume(M),b):P(M)}function w(M){return M===45||M===46||M===58||M===95||yn(M)?(e.consume(M),w):k(M)}function k(M){return M===61?(e.consume(M),C):ze(M)?(e.consume(M),k):b(M)}function C(M){return M===null||M===60||M===61||M===62||M===96?n(M):M===34||M===39?(e.consume(M),l=M,N):ze(M)?(e.consume(M),C):T(M)}function N(M){return M===l?(e.consume(M),l=null,L):M===null||be(M)?n(M):(e.consume(M),N)}function T(M){return M===null||M===34||M===39||M===47||M===60||M===61||M===62||M===96||ot(M)?k(M):(e.consume(M),T)}function L(M){return M===47||M===62||ze(M)?b(M):n(M)}function P(M){return M===62?(e.consume(M),O):n(M)}function O(M){return M===null||be(M)?I(M):ze(M)?(e.consume(M),O):n(M)}function I(M){return M===45&&i===2?(e.consume(M),$):M===60&&i===1?(e.consume(M),F):M===62&&i===4?(e.consume(M),H):M===63&&i===3?(e.consume(M),E):M===93&&i===5?(e.consume(M),B):be(M)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(GW,q,R)(M)):M===null||be(M)?(e.exit("htmlFlowData"),R(M)):(e.consume(M),I)}function R(M){return e.check(XW,D,q)(M)}function D(M){return e.enter("lineEnding"),e.consume(M),e.exit("lineEnding"),z}function z(M){return M===null||be(M)?R(M):(e.enter("htmlFlowData"),I(M))}function $(M){return M===45?(e.consume(M),E):I(M)}function F(M){return M===47?(e.consume(M),o="",j):I(M)}function j(M){if(M===62){const re=o.toLowerCase();return Qw.includes(re)?(e.consume(M),H):I(M)}return Cn(M)&&o.length<8?(e.consume(M),o+=String.fromCharCode(M),j):I(M)}function B(M){return M===93?(e.consume(M),E):I(M)}function E(M){return M===62?(e.consume(M),H):M===45&&i===2?(e.consume(M),E):I(M)}function H(M){return M===null||be(M)?(e.exit("htmlFlowData"),q(M)):(e.consume(M),H)}function q(M){return e.exit("htmlFlow"),t(M)}}function QW(e,t,n){const r=this;return i;function i(o){return be(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s):n(o)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}function JW(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(hu,t,n)}}const eV={name:"htmlText",tokenize:tV};function tV(e,t,n){const r=this;let i,s,o;return a;function a(E){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(E),l}function l(E){return E===33?(e.consume(E),c):E===47?(e.consume(E),k):E===63?(e.consume(E),b):Cn(E)?(e.consume(E),T):n(E)}function c(E){return E===45?(e.consume(E),u):E===91?(e.consume(E),s=0,m):Cn(E)?(e.consume(E),_):n(E)}function u(E){return E===45?(e.consume(E),p):n(E)}function d(E){return E===null?n(E):E===45?(e.consume(E),f):be(E)?(o=d,F(E)):(e.consume(E),d)}function f(E){return E===45?(e.consume(E),p):d(E)}function p(E){return E===62?$(E):E===45?f(E):d(E)}function m(E){const H="CDATA[";return E===H.charCodeAt(s++)?(e.consume(E),s===H.length?v:m):n(E)}function v(E){return E===null?n(E):E===93?(e.consume(E),y):be(E)?(o=v,F(E)):(e.consume(E),v)}function y(E){return E===93?(e.consume(E),x):v(E)}function x(E){return E===62?$(E):E===93?(e.consume(E),x):v(E)}function _(E){return E===null||E===62?$(E):be(E)?(o=_,F(E)):(e.consume(E),_)}function b(E){return E===null?n(E):E===63?(e.consume(E),w):be(E)?(o=b,F(E)):(e.consume(E),b)}function w(E){return E===62?$(E):b(E)}function k(E){return Cn(E)?(e.consume(E),C):n(E)}function C(E){return E===45||yn(E)?(e.consume(E),C):N(E)}function N(E){return be(E)?(o=N,F(E)):ze(E)?(e.consume(E),N):$(E)}function T(E){return E===45||yn(E)?(e.consume(E),T):E===47||E===62||ot(E)?L(E):n(E)}function L(E){return E===47?(e.consume(E),$):E===58||E===95||Cn(E)?(e.consume(E),P):be(E)?(o=L,F(E)):ze(E)?(e.consume(E),L):$(E)}function P(E){return E===45||E===46||E===58||E===95||yn(E)?(e.consume(E),P):O(E)}function O(E){return E===61?(e.consume(E),I):be(E)?(o=O,F(E)):ze(E)?(e.consume(E),O):L(E)}function I(E){return E===null||E===60||E===61||E===62||E===96?n(E):E===34||E===39?(e.consume(E),i=E,R):be(E)?(o=I,F(E)):ze(E)?(e.consume(E),I):(e.consume(E),D)}function R(E){return E===i?(e.consume(E),i=void 0,z):E===null?n(E):be(E)?(o=R,F(E)):(e.consume(E),R)}function D(E){return E===null||E===34||E===39||E===60||E===61||E===96?n(E):E===47||E===62||ot(E)?L(E):(e.consume(E),D)}function z(E){return E===47||E===62||ot(E)?L(E):n(E)}function $(E){return E===62?(e.consume(E),e.exit("htmlTextData"),e.exit("htmlText"),t):n(E)}function F(E){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(E),e.exit("lineEnding"),j}function j(E){return ze(E)?Ve(e,B,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(E):B(E)}function B(E){return e.enter("htmlTextData"),o(E)}}const H_={name:"labelEnd",resolveAll:sV,resolveTo:oV,tokenize:aV},nV={tokenize:lV},rV={tokenize:cV},iV={tokenize:uV};function sV(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const i=r.type==="labelImage"?4:2;r.type="data",t+=i}}return e.length!==n.length&&tr(e,0,e.length,n),e}function oV(e,t){let n=e.length,r=0,i,s,o,a;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(o){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(o=n);const l={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},c={type:"label",start:{...e[s][1].start},end:{...e[o][1].end}},u={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[o-2][1].start}};return a=[["enter",l,t],["enter",c,t]],a=pr(a,e.slice(s+1,s+r+3)),a=pr(a,[["enter",u,t]]),a=pr(a,Jf(t.parser.constructs.insideSpan.null,e.slice(s+r+4,o-3),t)),a=pr(a,[["exit",u,t],e[o-2],e[o-1],["exit",c,t]]),a=pr(a,e.slice(o+1)),a=pr(a,[["exit",l,t]]),tr(e,s,e.length,a),e}function aV(e,t,n){const r=this;let i=r.events.length,s,o;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){s=r.events[i][1];break}return a;function a(f){return s?s._inactive?d(f):(o=r.parser.defined.includes(Ar(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(f),e.exit("labelMarker"),e.exit("labelEnd"),l):n(f)}function l(f){return f===40?e.attempt(nV,u,o?u:d)(f):f===91?e.attempt(rV,u,o?c:d)(f):o?u(f):d(f)}function c(f){return e.attempt(iV,u,d)(f)}function u(f){return t(f)}function d(f){return s._balanced=!0,n(f)}}function lV(e,t,n){return r;function r(d){return e.enter("resource"),e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),i}function i(d){return ot(d)?sc(e,s)(d):s(d)}function s(d){return d===41?u(d):qI(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(d)}function o(d){return ot(d)?sc(e,l)(d):u(d)}function a(d){return n(d)}function l(d){return d===34||d===39||d===40?GI(e,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(d):u(d)}function c(d){return ot(d)?sc(e,u)(d):u(d)}function u(d){return d===41?(e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),e.exit("resource"),t):n(d)}}function cV(e,t,n){const r=this;return i;function i(a){return KI.call(r,e,s,o,"reference","referenceMarker","referenceString")(a)}function s(a){return r.parser.defined.includes(Ar(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function o(a){return n(a)}}function uV(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const dV={name:"labelStartImage",resolveAll:H_.resolveAll,tokenize:hV};function hV(e,t,n){const r=this;return i;function i(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),s}function s(a){return a===91?(e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelImage"),o):n(a)}function o(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const fV={name:"labelStartLink",resolveAll:H_.resolveAll,tokenize:pV};function pV(e,t,n){const r=this;return i;function i(o){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelLink"),s}function s(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const dm={name:"lineEnding",tokenize:mV};function mV(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),Ve(e,t,"linePrefix")}}const Bd={name:"thematicBreak",tokenize:gV};function gV(e,t,n){let r=0,i;return s;function s(c){return e.enter("thematicBreak"),o(c)}function o(c){return i=c,a(c)}function a(c){return c===i?(e.enter("thematicBreakSequence"),l(c)):r>=3&&(c===null||be(c))?(e.exit("thematicBreak"),t(c)):n(c)}function l(c){return c===i?(e.consume(c),r++,l):(e.exit("thematicBreakSequence"),ze(c)?Ve(e,a,"whitespace")(c):a(c))}}const zn={continuation:{tokenize:yV},exit:wV,name:"list",tokenize:_V},vV={partial:!0,tokenize:SV},xV={partial:!0,tokenize:bV};function _V(e,t,n){const r=this,i=r.events[r.events.length-1];let s=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,o=0;return a;function a(p){const m=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(m==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:Uv(p)){if(r.containerState.type||(r.containerState.type=m,e.enter(m,{_container:!0})),m==="listUnordered")return e.enter("listItemPrefix"),p===42||p===45?e.check(Bd,n,c)(p):c(p);if(!r.interrupt||p===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(p)}return n(p)}function l(p){return Uv(p)&&++o<10?(e.consume(p),l):(!r.interrupt||o<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(e.exit("listItemValue"),c(p)):n(p)}function c(p){return e.enter("listItemMarker"),e.consume(p),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,e.check(hu,r.interrupt?n:u,e.attempt(vV,f,d))}function u(p){return r.containerState.initialBlankLine=!0,s++,f(p)}function d(p){return ze(p)?(e.enter("listItemPrefixWhitespace"),e.consume(p),e.exit("listItemPrefixWhitespace"),f):n(p)}function f(p){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(p)}}function yV(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(hu,i,s);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Ve(e,t,"listItemIndent",r.containerState.size+1)(a)}function s(a){return r.containerState.furtherBlankLines||!ze(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(xV,t,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,Ve(e,e.attempt(zn,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function bV(e,t,n){const r=this;return Ve(e,i,"listItemIndent",r.containerState.size+1);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="listItemIndent"&&o[2].sliceSerialize(o[1],!0).length===r.containerState.size?t(s):n(s)}}function wV(e){e.exit(this.containerState.type)}function SV(e,t,n){const r=this;return Ve(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const o=r.events[r.events.length-1];return!ze(s)&&o&&o[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const Jw={name:"setextUnderline",resolveTo:kV,tokenize:CV};function kV(e,t){let n=e.length,r,i,s;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(i=n)}else e[n][1].type==="content"&&e.splice(n,1),!s&&e[n][1].type==="definition"&&(s=n);const o={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type="setextHeadingText",s?(e.splice(i,0,["enter",o,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=o,e.push(["exit",o,t]),e}function CV(e,t,n){const r=this;let i;return s;function s(c){let u=r.events.length,d;for(;u--;)if(r.events[u][1].type!=="lineEnding"&&r.events[u][1].type!=="linePrefix"&&r.events[u][1].type!=="content"){d=r.events[u][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||d)?(e.enter("setextHeadingLine"),i=c,o(c)):n(c)}function o(c){return e.enter("setextHeadingLineSequence"),a(c)}function a(c){return c===i?(e.consume(c),a):(e.exit("setextHeadingLineSequence"),ze(c)?Ve(e,l,"lineSuffix")(c):l(c))}function l(c){return c===null||be(c)?(e.exit("setextHeadingLine"),t(c)):n(c)}}const EV={tokenize:NV};function NV(e){const t=this,n=e.attempt(hu,r,e.attempt(this.parser.constructs.flowInitial,i,Ve(e,e.attempt(this.parser.constructs.flow,i,e.attempt(MW,i)),"linePrefix")));return n;function r(s){if(s===null){e.consume(s);return}return e.enter("lineEndingBlank"),e.consume(s),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function i(s){if(s===null){e.consume(s);return}return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const TV={resolveAll:YI()},PV=XI("string"),IV=XI("text");function XI(e){return{resolveAll:YI(e==="text"?RV:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,o,a);return o;function o(u){return c(u)?s(u):a(u)}function a(u){if(u===null){n.consume(u);return}return n.enter("data"),n.consume(u),l}function l(u){return c(u)?(n.exit("data"),s(u)):(n.consume(u),l)}function c(u){if(u===null)return!0;const d=i[u];let f=-1;if(d)for(;++f<d.length;){const p=d[f];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function YI(e){return t;function t(n,r){let i=-1,s;for(;++i<=n.length;)s===void 0?n[i]&&n[i][1].type==="data"&&(s=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==s+2&&(n[s][1].end=n[i-1][1].end,n.splice(s+2,i-s-2),i=s+2),s=void 0);return e?e(n,r):n}}function RV(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],i=t.sliceStream(r);let s=i.length,o=-1,a=0,l;for(;s--;){const c=i[s];if(typeof c=="string"){for(o=c.length;c.charCodeAt(o-1)===32;)a++,o--;if(o)break;o=-1}else if(c===-2)l=!0,a++;else if(c!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const c={type:n===e.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?o:r.start._bufferIndex+o,_index:r.start._index+s,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...c.start},r.start.offset===r.end.offset?Object.assign(r,c):(e.splice(n,0,["enter",c,t],["exit",c,t]),n+=2)}n++}return e}const MV={42:zn,43:zn,45:zn,48:zn,49:zn,50:zn,51:zn,52:zn,53:zn,54:zn,55:zn,56:zn,57:zn,62:HI},AV={91:OW},jV={[-2]:um,[-1]:um,32:um},DV={35:UW,42:Bd,45:[Jw,Bd],60:KW,61:Jw,95:Bd,96:Zw,126:Zw},LV={38:WI,92:UI},OV={[-5]:dm,[-4]:dm,[-3]:dm,33:dV,38:WI,42:Wv,60:[fW,eV],91:fV,92:[FW,UI],93:H_,95:Wv,96:EW},BV={null:[Wv,TV]},zV={null:[42,95]},$V={null:[]},FV=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:zV,contentInitial:AV,disable:$V,document:MV,flow:DV,flowInitial:jV,insideSpan:BV,string:LV,text:OV},Symbol.toStringTag,{value:"Module"}));function HV(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},s=[];let o=[],a=[];const l={attempt:N(k),check:N(C),consume:_,enter:b,exit:w,interrupt:N(C,{interrupt:!0})},c={code:null,containerState:{},defineSkip:v,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d};let u=t.tokenize.call(c,l);return t.resolveAll&&s.push(t),c;function d(O){return o=pr(o,O),y(),o[o.length-1]!==null?[]:(T(t,0),c.events=Jf(s,c.events,c),c.events)}function f(O,I){return WV(p(O),I)}function p(O){return UV(o,O)}function m(){const{_bufferIndex:O,_index:I,line:R,column:D,offset:z}=r;return{_bufferIndex:O,_index:I,line:R,column:D,offset:z}}function v(O){i[O.line]=O.column,P()}function y(){let O;for(;r._index<o.length;){const I=o[r._index];if(typeof I=="string")for(O=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===O&&r._bufferIndex<I.length;)x(I.charCodeAt(r._bufferIndex));else x(I)}}function x(O){u=u(O)}function _(O){be(O)?(r.line++,r.column=1,r.offset+=O===-3?2:1,P()):O!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),c.previous=O}function b(O,I){const R=I||{};return R.type=O,R.start=m(),c.events.push(["enter",R,c]),a.push(R),R}function w(O){const I=a.pop();return I.end=m(),c.events.push(["exit",I,c]),I}function k(O,I){T(O,I.from)}function C(O,I){I.restore()}function N(O,I){return R;function R(D,z,$){let F,j,B,E;return Array.isArray(D)?q(D):"tokenize"in D?q([D]):H(D);function H(V){return pe;function pe(Oe){const ie=Oe!==null&&V[Oe],Ae=Oe!==null&&V.null,Fe=[...Array.isArray(ie)?ie:ie?[ie]:[],...Array.isArray(Ae)?Ae:Ae?[Ae]:[]];return q(Fe)(Oe)}}function q(V){return F=V,j=0,V.length===0?$:M(V[j])}function M(V){return pe;function pe(Oe){return E=L(),B=V,V.partial||(c.currentConstruct=V),V.name&&c.parser.constructs.disable.null.includes(V.name)?oe():V.tokenize.call(I?Object.assign(Object.create(c),I):c,l,re,oe)(Oe)}}function re(V){return O(B,E),z}function oe(V){return E.restore(),++j<F.length?M(F[j]):$}}}function T(O,I){O.resolveAll&&!s.includes(O)&&s.push(O),O.resolve&&tr(c.events,I,c.events.length-I,O.resolve(c.events.slice(I),c)),O.resolveTo&&(c.events=O.resolveTo(c.events,c))}function L(){const O=m(),I=c.previous,R=c.currentConstruct,D=c.events.length,z=Array.from(a);return{from:D,restore:$};function $(){r=O,c.previous=I,c.currentConstruct=R,c.events.length=D,a=z,P()}}function P(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function UV(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let o;if(n===i)o=[e[n].slice(r,s)];else{if(o=e.slice(n,i),r>-1){const a=o[0];typeof a=="string"?o[0]=a.slice(r):o.shift()}s>0&&o.push(e[i].slice(0,s))}return o}function WV(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let o;if(typeof s=="string")o=s;else switch(s){case-5:{o="\r";break}case-4:{o=`
492
492
  `;break}case-3:{o=`\r
493
- `;break}case-2:{o=t?" ":" ";break}case-1:{if(!t&&i)continue;o=" ";break}default:o=String.fromCharCode(s)}i=s===-2,r.push(o)}return r.join("")}function VV(e){const r={constructs:$I([FV,...(e||{}).extensions||[]]),content:i(oW),defined:[],document:i(lW),flow:i(EV),lazy:{},string:i(PV),text:i(IV)};return r;function i(s){return o;function o(a){return HV(r,s,a)}}}function qV(e){for(;!VI(e););return e}const eS=/[\0\t\n\r]/g;function KV(){let e=1,t="",n=!0,r;return i;function i(s,o,a){const l=[];let c,u,d,f,p;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(o||void 0).decode(s)),d=0,t="",n&&(s.charCodeAt(0)===65279&&d++,n=void 0);d<s.length;){if(eS.lastIndex=d,c=eS.exec(s),f=c&&c.index!==void 0?c.index:s.length,p=s.charCodeAt(f),!c){t=s.slice(d);break}if(p===10&&d===f&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),d<f&&(l.push(s.slice(d,f)),e+=f-d),p){case 0:{l.push(65533),e++;break}case 9:{for(u=Math.ceil(e/4)*4,l.push(-2);e++<u;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}d=f+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const GV=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function XV(e){return e.replace(GV,YV)}function YV(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return FI(n.slice(s?2:1),s?16:10)}return F_(n)||e}const ZI={}.hasOwnProperty;function ZV(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),QV(n)(qV(VV(n).document().write(KV()(e,t,!0))))}function QV(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(Bt),autolinkProtocol:L,autolinkEmail:L,atxHeading:s(Gt),blockQuote:s(Ae),characterEscape:L,characterReference:L,codeFenced:s(Fe),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(Fe,o),codeText:s(We,o),codeTextData:L,data:L,codeFlowValue:L,definition:s(ge),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(qe),hardBreakEscape:s(wt),hardBreakTrailing:s(wt),htmlFlow:s(Rt,o),htmlFlowData:L,htmlText:s(Rt,o),htmlTextData:L,image:s(ln),label:o,link:s(Bt),listItem:s(Ue),listItemValue:f,listOrdered:s(at,d),listUnordered:s(at),paragraph:s(nt),reference:M,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(Gt),strong:s(mt),thematicBreak:s(pn)},exit:{atxHeading:l(),atxHeadingSequence:k,autolink:l(),autolinkEmail:ie,autolinkProtocol:Oe,blockQuote:l(),characterEscapeValue:P,characterReferenceMarkerHexadecimal:oe,characterReferenceMarkerNumeric:oe,characterReferenceValue:V,characterReference:pe,codeFenced:l(y),codeFencedFence:v,codeFencedFenceInfo:p,codeFencedFenceMeta:m,codeFlowValue:P,codeIndented:l(x),codeText:l(z),codeTextData:P,data:P,definition:l(),definitionDestinationString:w,definitionLabelString:_,definitionTitleString:b,emphasis:l(),hardBreakEscape:l(I),hardBreakTrailing:l(I),htmlFlow:l(R),htmlFlowData:P,htmlText:l(D),htmlTextData:P,image:l(F),label:B,labelText:j,lineEnding:O,link:l($),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:re,resourceDestinationString:E,resourceTitleString:H,resource:q,setextHeading:l(T),setextHeadingLineSequence:N,setextHeadingText:C,strong:l(),thematicBreak:l()}};QI(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(U){let Q={type:"root",children:[]};const ve={stack:[Q],tokenStack:[],config:t,enter:a,exit:c,buffer:o,resume:u,data:n},Se=[];let J=-1;for(;++J<U.length;)if(U[J][1].type==="listOrdered"||U[J][1].type==="listUnordered")if(U[J][0]==="enter")Se.push(J);else{const Xe=Se.pop();J=i(U,Xe,J)}for(J=-1;++J<U.length;){const Xe=t[U[J][0]];ZI.call(Xe,U[J][1].type)&&Xe[U[J][1].type].call(Object.assign({sliceSerialize:U[J][2].sliceSerialize},ve),U[J][1])}if(ve.tokenStack.length>0){const Xe=ve.tokenStack[ve.tokenStack.length-1];(Xe[1]||tS).call(ve,void 0,Xe[0])}for(Q.position={start:Xi(U.length>0?U[0][1].start:{line:1,column:1,offset:0}),end:Xi(U.length>0?U[U.length-2][1].end:{line:1,column:1,offset:0})},J=-1;++J<t.transforms.length;)Q=t.transforms[J](Q)||Q;return Q}function i(U,Q,ve){let Se=Q-1,J=-1,Xe=!1,Yt,Zt,ue,Te;for(;++Se<=ve;){const Je=U[Se];switch(Je[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{Je[0]==="enter"?J++:J--,Te=void 0;break}case"lineEndingBlank":{Je[0]==="enter"&&(Yt&&!Te&&!J&&!ue&&(ue=Se),Te=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:Te=void 0}if(!J&&Je[0]==="enter"&&Je[1].type==="listItemPrefix"||J===-1&&Je[0]==="exit"&&(Je[1].type==="listUnordered"||Je[1].type==="listOrdered")){if(Yt){let Dn=Se;for(Zt=void 0;Dn--;){const Qt=U[Dn];if(Qt[1].type==="lineEnding"||Qt[1].type==="lineEndingBlank"){if(Qt[0]==="exit")continue;Zt&&(U[Zt][1].type="lineEndingBlank",Xe=!0),Qt[1].type="lineEnding",Zt=Dn}else if(!(Qt[1].type==="linePrefix"||Qt[1].type==="blockQuotePrefix"||Qt[1].type==="blockQuotePrefixWhitespace"||Qt[1].type==="blockQuoteMarker"||Qt[1].type==="listItemIndent"))break}ue&&(!Zt||ue<Zt)&&(Yt._spread=!0),Yt.end=Object.assign({},Zt?U[Zt][1].start:Je[1].end),U.splice(Zt||Se,0,["exit",Yt,Je[2]]),Se++,ve++}if(Je[1].type==="listItemPrefix"){const Dn={type:"listItem",_spread:!1,start:Object.assign({},Je[1].start),end:void 0};Yt=Dn,U.splice(Se,0,["enter",Dn,Je[2]]),Se++,ve++,ue=void 0,Te=!0}}}return U[Q][1]._spread=Xe,ve}function s(U,Q){return ve;function ve(Se){a.call(this,U(Se),Se),Q&&Q.call(this,Se)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(U,Q,ve){this.stack[this.stack.length-1].children.push(U),this.stack.push(U),this.tokenStack.push([Q,ve||void 0]),U.position={start:Xi(Q.start),end:void 0}}function l(U){return Q;function Q(ve){U&&U.call(this,ve),c.call(this,ve)}}function c(U,Q){const ve=this.stack.pop(),Se=this.tokenStack.pop();if(Se)Se[0].type!==U.type&&(Q?Q.call(this,U,Se[0]):(Se[1]||tS).call(this,U,Se[0]));else throw new Error("Cannot close `"+U.type+"` ("+ic({start:U.start,end:U.end})+"): it’s not open");ve.position.end=Xi(U.end)}function u(){return $_(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function f(U){if(this.data.expectingFirstListItemValue){const Q=this.stack[this.stack.length-2];Q.start=Number.parseInt(this.sliceSerialize(U),10),this.data.expectingFirstListItemValue=void 0}}function p(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.lang=U}function m(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.meta=U}function v(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function y(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function x(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U.replace(/(\r?\n|\r)$/g,"")}function _(U){const Q=this.resume(),ve=this.stack[this.stack.length-1];ve.label=Q,ve.identifier=Ar(this.sliceSerialize(U)).toLowerCase()}function b(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.title=U}function w(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.url=U}function k(U){const Q=this.stack[this.stack.length-1];if(!Q.depth){const ve=this.sliceSerialize(U).length;Q.depth=ve}}function C(){this.data.setextHeadingSlurpLineEnding=!0}function N(U){const Q=this.stack[this.stack.length-1];Q.depth=this.sliceSerialize(U).codePointAt(0)===61?1:2}function T(){this.data.setextHeadingSlurpLineEnding=void 0}function L(U){const ve=this.stack[this.stack.length-1].children;let Se=ve[ve.length-1];(!Se||Se.type!=="text")&&(Se=Xt(),Se.position={start:Xi(U.start),end:void 0},ve.push(Se)),this.stack.push(Se)}function P(U){const Q=this.stack.pop();Q.value+=this.sliceSerialize(U),Q.position.end=Xi(U.end)}function O(U){const Q=this.stack[this.stack.length-1];if(this.data.atHardBreak){const ve=Q.children[Q.children.length-1];ve.position.end=Xi(U.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(Q.type)&&(L.call(this,U),P.call(this,U))}function I(){this.data.atHardBreak=!0}function R(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U}function D(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U}function z(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U}function $(){const U=this.stack[this.stack.length-1];if(this.data.inReference){const Q=this.data.referenceType||"shortcut";U.type+="Reference",U.referenceType=Q,delete U.url,delete U.title}else delete U.identifier,delete U.label;this.data.referenceType=void 0}function F(){const U=this.stack[this.stack.length-1];if(this.data.inReference){const Q=this.data.referenceType||"shortcut";U.type+="Reference",U.referenceType=Q,delete U.url,delete U.title}else delete U.identifier,delete U.label;this.data.referenceType=void 0}function j(U){const Q=this.sliceSerialize(U),ve=this.stack[this.stack.length-2];ve.label=XV(Q),ve.identifier=Ar(Q).toLowerCase()}function B(){const U=this.stack[this.stack.length-1],Q=this.resume(),ve=this.stack[this.stack.length-1];if(this.data.inReference=!0,ve.type==="link"){const Se=U.children;ve.children=Se}else ve.alt=Q}function E(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.url=U}function H(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.title=U}function q(){this.data.inReference=void 0}function M(){this.data.referenceType="collapsed"}function re(U){const Q=this.resume(),ve=this.stack[this.stack.length-1];ve.label=Q,ve.identifier=Ar(this.sliceSerialize(U)).toLowerCase(),this.data.referenceType="full"}function oe(U){this.data.characterReferenceType=U.type}function V(U){const Q=this.sliceSerialize(U),ve=this.data.characterReferenceType;let Se;ve?(Se=FI(Q,ve==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):Se=F_(Q);const J=this.stack[this.stack.length-1];J.value+=Se}function pe(U){const Q=this.stack.pop();Q.position.end=Xi(U.end)}function Oe(U){P.call(this,U);const Q=this.stack[this.stack.length-1];Q.url=this.sliceSerialize(U)}function ie(U){P.call(this,U);const Q=this.stack[this.stack.length-1];Q.url="mailto:"+this.sliceSerialize(U)}function Ae(){return{type:"blockquote",children:[]}}function Fe(){return{type:"code",lang:null,meta:null,value:""}}function We(){return{type:"inlineCode",value:""}}function ge(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function qe(){return{type:"emphasis",children:[]}}function Gt(){return{type:"heading",depth:0,children:[]}}function wt(){return{type:"break"}}function Rt(){return{type:"html",value:""}}function ln(){return{type:"image",title:null,url:"",alt:null}}function Bt(){return{type:"link",title:null,url:"",children:[]}}function at(U){return{type:"list",ordered:U.type==="listOrdered",start:null,spread:U._spread,children:[]}}function Ue(U){return{type:"listItem",spread:U._spread,checked:null,children:[]}}function nt(){return{type:"paragraph",children:[]}}function mt(){return{type:"strong",children:[]}}function Xt(){return{type:"text",value:""}}function pn(){return{type:"thematicBreak"}}}function Xi(e){return{line:e.line,column:e.column,offset:e.offset}}function QI(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?QI(e,r):JV(e,r)}}function JV(e,t){let n;for(n in t)if(ZI.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function tS(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+ic({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+ic({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+ic({start:t.start,end:t.end})+") is still open")}function eq(e){const t=this;t.parser=n;function n(r){return ZV(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function tq(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function nq(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
493
+ `;break}case-2:{o=t?" ":" ";break}case-1:{if(!t&&i)continue;o=" ";break}default:o=String.fromCharCode(s)}i=s===-2,r.push(o)}return r.join("")}function VV(e){const r={constructs:$I([FV,...(e||{}).extensions||[]]),content:i(oW),defined:[],document:i(lW),flow:i(EV),lazy:{},string:i(PV),text:i(IV)};return r;function i(s){return o;function o(a){return HV(r,s,a)}}}function qV(e){for(;!VI(e););return e}const eS=/[\0\t\n\r]/g;function KV(){let e=1,t="",n=!0,r;return i;function i(s,o,a){const l=[];let c,u,d,f,p;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(o||void 0).decode(s)),d=0,t="",n&&(s.charCodeAt(0)===65279&&d++,n=void 0);d<s.length;){if(eS.lastIndex=d,c=eS.exec(s),f=c&&c.index!==void 0?c.index:s.length,p=s.charCodeAt(f),!c){t=s.slice(d);break}if(p===10&&d===f&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),d<f&&(l.push(s.slice(d,f)),e+=f-d),p){case 0:{l.push(65533),e++;break}case 9:{for(u=Math.ceil(e/4)*4,l.push(-2);e++<u;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}d=f+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const GV=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function XV(e){return e.replace(GV,YV)}function YV(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return FI(n.slice(s?2:1),s?16:10)}return F_(n)||e}const ZI={}.hasOwnProperty;function ZV(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),QV(n)(qV(VV(n).document().write(KV()(e,t,!0))))}function QV(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(Bt),autolinkProtocol:L,autolinkEmail:L,atxHeading:s(Gt),blockQuote:s(Ae),characterEscape:L,characterReference:L,codeFenced:s(Fe),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(Fe,o),codeText:s(We,o),codeTextData:L,data:L,codeFlowValue:L,definition:s(ge),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(qe),hardBreakEscape:s(wt),hardBreakTrailing:s(wt),htmlFlow:s(Rt,o),htmlFlowData:L,htmlText:s(Rt,o),htmlTextData:L,image:s(ln),label:o,link:s(Bt),listItem:s(Ue),listItemValue:f,listOrdered:s(at,d),listUnordered:s(at),paragraph:s(nt),reference:M,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(Gt),strong:s(mt),thematicBreak:s(pn)},exit:{atxHeading:l(),atxHeadingSequence:k,autolink:l(),autolinkEmail:ie,autolinkProtocol:Oe,blockQuote:l(),characterEscapeValue:P,characterReferenceMarkerHexadecimal:oe,characterReferenceMarkerNumeric:oe,characterReferenceValue:V,characterReference:pe,codeFenced:l(y),codeFencedFence:v,codeFencedFenceInfo:p,codeFencedFenceMeta:m,codeFlowValue:P,codeIndented:l(x),codeText:l(z),codeTextData:P,data:P,definition:l(),definitionDestinationString:w,definitionLabelString:_,definitionTitleString:b,emphasis:l(),hardBreakEscape:l(I),hardBreakTrailing:l(I),htmlFlow:l(R),htmlFlowData:P,htmlText:l(D),htmlTextData:P,image:l(F),label:B,labelText:j,lineEnding:O,link:l($),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:re,resourceDestinationString:E,resourceTitleString:H,resource:q,setextHeading:l(T),setextHeadingLineSequence:N,setextHeadingText:C,strong:l(),thematicBreak:l()}};QI(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(U){let Q={type:"root",children:[]};const ve={stack:[Q],tokenStack:[],config:t,enter:a,exit:c,buffer:o,resume:u,data:n},Se=[];let J=-1;for(;++J<U.length;)if(U[J][1].type==="listOrdered"||U[J][1].type==="listUnordered")if(U[J][0]==="enter")Se.push(J);else{const Ye=Se.pop();J=i(U,Ye,J)}for(J=-1;++J<U.length;){const Ye=t[U[J][0]];ZI.call(Ye,U[J][1].type)&&Ye[U[J][1].type].call(Object.assign({sliceSerialize:U[J][2].sliceSerialize},ve),U[J][1])}if(ve.tokenStack.length>0){const Ye=ve.tokenStack[ve.tokenStack.length-1];(Ye[1]||tS).call(ve,void 0,Ye[0])}for(Q.position={start:Xi(U.length>0?U[0][1].start:{line:1,column:1,offset:0}),end:Xi(U.length>0?U[U.length-2][1].end:{line:1,column:1,offset:0})},J=-1;++J<t.transforms.length;)Q=t.transforms[J](Q)||Q;return Q}function i(U,Q,ve){let Se=Q-1,J=-1,Ye=!1,Yt,Zt,ue,Te;for(;++Se<=ve;){const Je=U[Se];switch(Je[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{Je[0]==="enter"?J++:J--,Te=void 0;break}case"lineEndingBlank":{Je[0]==="enter"&&(Yt&&!Te&&!J&&!ue&&(ue=Se),Te=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:Te=void 0}if(!J&&Je[0]==="enter"&&Je[1].type==="listItemPrefix"||J===-1&&Je[0]==="exit"&&(Je[1].type==="listUnordered"||Je[1].type==="listOrdered")){if(Yt){let Dn=Se;for(Zt=void 0;Dn--;){const Qt=U[Dn];if(Qt[1].type==="lineEnding"||Qt[1].type==="lineEndingBlank"){if(Qt[0]==="exit")continue;Zt&&(U[Zt][1].type="lineEndingBlank",Ye=!0),Qt[1].type="lineEnding",Zt=Dn}else if(!(Qt[1].type==="linePrefix"||Qt[1].type==="blockQuotePrefix"||Qt[1].type==="blockQuotePrefixWhitespace"||Qt[1].type==="blockQuoteMarker"||Qt[1].type==="listItemIndent"))break}ue&&(!Zt||ue<Zt)&&(Yt._spread=!0),Yt.end=Object.assign({},Zt?U[Zt][1].start:Je[1].end),U.splice(Zt||Se,0,["exit",Yt,Je[2]]),Se++,ve++}if(Je[1].type==="listItemPrefix"){const Dn={type:"listItem",_spread:!1,start:Object.assign({},Je[1].start),end:void 0};Yt=Dn,U.splice(Se,0,["enter",Dn,Je[2]]),Se++,ve++,ue=void 0,Te=!0}}}return U[Q][1]._spread=Ye,ve}function s(U,Q){return ve;function ve(Se){a.call(this,U(Se),Se),Q&&Q.call(this,Se)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(U,Q,ve){this.stack[this.stack.length-1].children.push(U),this.stack.push(U),this.tokenStack.push([Q,ve||void 0]),U.position={start:Xi(Q.start),end:void 0}}function l(U){return Q;function Q(ve){U&&U.call(this,ve),c.call(this,ve)}}function c(U,Q){const ve=this.stack.pop(),Se=this.tokenStack.pop();if(Se)Se[0].type!==U.type&&(Q?Q.call(this,U,Se[0]):(Se[1]||tS).call(this,U,Se[0]));else throw new Error("Cannot close `"+U.type+"` ("+ic({start:U.start,end:U.end})+"): it’s not open");ve.position.end=Xi(U.end)}function u(){return $_(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function f(U){if(this.data.expectingFirstListItemValue){const Q=this.stack[this.stack.length-2];Q.start=Number.parseInt(this.sliceSerialize(U),10),this.data.expectingFirstListItemValue=void 0}}function p(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.lang=U}function m(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.meta=U}function v(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function y(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function x(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U.replace(/(\r?\n|\r)$/g,"")}function _(U){const Q=this.resume(),ve=this.stack[this.stack.length-1];ve.label=Q,ve.identifier=Ar(this.sliceSerialize(U)).toLowerCase()}function b(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.title=U}function w(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.url=U}function k(U){const Q=this.stack[this.stack.length-1];if(!Q.depth){const ve=this.sliceSerialize(U).length;Q.depth=ve}}function C(){this.data.setextHeadingSlurpLineEnding=!0}function N(U){const Q=this.stack[this.stack.length-1];Q.depth=this.sliceSerialize(U).codePointAt(0)===61?1:2}function T(){this.data.setextHeadingSlurpLineEnding=void 0}function L(U){const ve=this.stack[this.stack.length-1].children;let Se=ve[ve.length-1];(!Se||Se.type!=="text")&&(Se=Xt(),Se.position={start:Xi(U.start),end:void 0},ve.push(Se)),this.stack.push(Se)}function P(U){const Q=this.stack.pop();Q.value+=this.sliceSerialize(U),Q.position.end=Xi(U.end)}function O(U){const Q=this.stack[this.stack.length-1];if(this.data.atHardBreak){const ve=Q.children[Q.children.length-1];ve.position.end=Xi(U.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(Q.type)&&(L.call(this,U),P.call(this,U))}function I(){this.data.atHardBreak=!0}function R(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U}function D(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U}function z(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.value=U}function $(){const U=this.stack[this.stack.length-1];if(this.data.inReference){const Q=this.data.referenceType||"shortcut";U.type+="Reference",U.referenceType=Q,delete U.url,delete U.title}else delete U.identifier,delete U.label;this.data.referenceType=void 0}function F(){const U=this.stack[this.stack.length-1];if(this.data.inReference){const Q=this.data.referenceType||"shortcut";U.type+="Reference",U.referenceType=Q,delete U.url,delete U.title}else delete U.identifier,delete U.label;this.data.referenceType=void 0}function j(U){const Q=this.sliceSerialize(U),ve=this.stack[this.stack.length-2];ve.label=XV(Q),ve.identifier=Ar(Q).toLowerCase()}function B(){const U=this.stack[this.stack.length-1],Q=this.resume(),ve=this.stack[this.stack.length-1];if(this.data.inReference=!0,ve.type==="link"){const Se=U.children;ve.children=Se}else ve.alt=Q}function E(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.url=U}function H(){const U=this.resume(),Q=this.stack[this.stack.length-1];Q.title=U}function q(){this.data.inReference=void 0}function M(){this.data.referenceType="collapsed"}function re(U){const Q=this.resume(),ve=this.stack[this.stack.length-1];ve.label=Q,ve.identifier=Ar(this.sliceSerialize(U)).toLowerCase(),this.data.referenceType="full"}function oe(U){this.data.characterReferenceType=U.type}function V(U){const Q=this.sliceSerialize(U),ve=this.data.characterReferenceType;let Se;ve?(Se=FI(Q,ve==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):Se=F_(Q);const J=this.stack[this.stack.length-1];J.value+=Se}function pe(U){const Q=this.stack.pop();Q.position.end=Xi(U.end)}function Oe(U){P.call(this,U);const Q=this.stack[this.stack.length-1];Q.url=this.sliceSerialize(U)}function ie(U){P.call(this,U);const Q=this.stack[this.stack.length-1];Q.url="mailto:"+this.sliceSerialize(U)}function Ae(){return{type:"blockquote",children:[]}}function Fe(){return{type:"code",lang:null,meta:null,value:""}}function We(){return{type:"inlineCode",value:""}}function ge(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function qe(){return{type:"emphasis",children:[]}}function Gt(){return{type:"heading",depth:0,children:[]}}function wt(){return{type:"break"}}function Rt(){return{type:"html",value:""}}function ln(){return{type:"image",title:null,url:"",alt:null}}function Bt(){return{type:"link",title:null,url:"",children:[]}}function at(U){return{type:"list",ordered:U.type==="listOrdered",start:null,spread:U._spread,children:[]}}function Ue(U){return{type:"listItem",spread:U._spread,checked:null,children:[]}}function nt(){return{type:"paragraph",children:[]}}function mt(){return{type:"strong",children:[]}}function Xt(){return{type:"text",value:""}}function pn(){return{type:"thematicBreak"}}}function Xi(e){return{line:e.line,column:e.column,offset:e.offset}}function QI(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?QI(e,r):JV(e,r)}}function JV(e,t){let n;for(n in t)if(ZI.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function tS(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+ic({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+ic({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+ic({start:t.start,end:t.end})+") is still open")}function eq(e){const t=this;t.parser=n;function n(r){return ZV(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function tq(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function nq(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
494
494
  `}]}function rq(e,t){const n=t.value?t.value+`
495
495
  `:"",r={},i=t.lang?t.lang.split(/\s+/):[];i.length>0&&(r.className=["language-"+i[0]]);let s={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return t.meta&&(s.data={meta:t.meta}),e.patch(t,s),s=e.applyData(t,s),s={type:"element",tagName:"pre",properties:{},children:[s]},e.patch(t,s),s}function iq(e,t){const n={type:"element",tagName:"del",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function sq(e,t){const n={type:"element",tagName:"em",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function oq(e,t){const n=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",r=String(t.identifier).toUpperCase(),i=nl(r.toLowerCase()),s=e.footnoteOrder.indexOf(r);let o,a=e.footnoteCounts.get(r);a===void 0?(a=0,e.footnoteOrder.push(r),o=e.footnoteOrder.length):o=s+1,a+=1,e.footnoteCounts.set(r,a);const l={type:"element",tagName:"a",properties:{href:"#"+n+"fn-"+i,id:n+"fnref-"+i+(a>1?"-"+a:""),dataFootnoteRef:!0,ariaDescribedBy:["footnote-label"]},children:[{type:"text",value:String(o)}]};e.patch(t,l);const c={type:"element",tagName:"sup",properties:{},children:[l]};return e.patch(t,c),e.applyData(t,c)}function aq(e,t){const n={type:"element",tagName:"h"+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function lq(e,t){if(e.options.allowDangerousHtml){const n={type:"raw",value:t.value};return e.patch(t,n),e.applyData(t,n)}}function JI(e,t){const n=t.referenceType;let r="]";if(n==="collapsed"?r+="[]":n==="full"&&(r+="["+(t.label||t.identifier)+"]"),t.type==="imageReference")return[{type:"text",value:"!["+t.alt+r}];const i=e.all(t),s=i[0];s&&s.type==="text"?s.value="["+s.value:i.unshift({type:"text",value:"["});const o=i[i.length-1];return o&&o.type==="text"?o.value+=r:i.push({type:"text",value:r}),i}function cq(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return JI(e,t);const i={src:nl(r.url||""),alt:t.alt};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"img",properties:i,children:[]};return e.patch(t,s),e.applyData(t,s)}function uq(e,t){const n={src:nl(t.url)};t.alt!==null&&t.alt!==void 0&&(n.alt=t.alt),t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"img",properties:n,children:[]};return e.patch(t,r),e.applyData(t,r)}function dq(e,t){const n={type:"text",value:t.value.replace(/\r?\n|\r/g," ")};e.patch(t,n);const r={type:"element",tagName:"code",properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)}function hq(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return JI(e,t);const i={href:nl(r.url||"")};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"a",properties:i,children:e.all(t)};return e.patch(t,s),e.applyData(t,s)}function fq(e,t){const n={href:nl(t.url)};t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"a",properties:n,children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function pq(e,t,n){const r=e.all(t),i=n?mq(n):eR(t),s={},o=[];if(typeof t.checked=="boolean"){const u=r[0];let d;u&&u.type==="element"&&u.tagName==="p"?d=u:(d={type:"element",tagName:"p",properties:{},children:[]},r.unshift(d)),d.children.length>0&&d.children.unshift({type:"text",value:" "}),d.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:t.checked,disabled:!0},children:[]}),s.className=["task-list-item"]}let a=-1;for(;++a<r.length;){const u=r[a];(i||a!==0||u.type!=="element"||u.tagName!=="p")&&o.push({type:"text",value:`
496
496
  `}),u.type==="element"&&u.tagName==="p"&&!i?o.push(...u.children):o.push(u)}const l=r[r.length-1];l&&(i||l.type!=="element"||l.tagName!=="p")&&o.push({type:"text",value:`
@@ -518,7 +518,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
518
518
  `))}function l(p,m,v,y){const x=v.enter("tableCell"),_=v.enter("phrasing"),b=v.containerPhrasing(p,{...y,before:s,after:s});return _(),x(),b}function c(p,m){return iG(p,{align:m,alignDelimiters:r,padding:n,stringLength:i})}function u(p,m,v){const y=p.children;let x=-1;const _=[],b=m.enter("table");for(;++x<y.length;)_[x]=d(y[x],m,v);return b(),_}function d(p,m,v){const y=p.children;let x=-1;const _=[],b=m.enter("tableRow");for(;++x<y.length;)_[x]=l(y[x],p,m,v);return b(),_}function f(p,m,v){let y=wR.inlineCode(p,m,v);return v.stack.includes("tableCell")&&(y=y.replace(/\|/g,"\\$&")),y}}function VG(){return{exit:{taskListCheckValueChecked:NS,taskListCheckValueUnchecked:NS,paragraph:KG}}}function qG(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:GG}}}function NS(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function KG(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const a=i[s];if(a.type==="paragraph"){o=a;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function GG(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(o);let l=wR.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),l;function c(u){return u+o}}function XG(){return[NK(),GK(),QK(),BG(),VG()]}function YG(e){return{extensions:[TK(),XK(e),JK(),WG(e),qG()]}}const ZG={tokenize:rX,partial:!0},SR={tokenize:iX,partial:!0},kR={tokenize:sX,partial:!0},CR={tokenize:oX,partial:!0},QG={tokenize:aX,partial:!0},ER={name:"wwwAutolink",tokenize:tX,previous:TR},NR={name:"protocolAutolink",tokenize:nX,previous:PR},Fi={name:"emailAutolink",tokenize:eX,previous:IR},di={};function JG(){return{text:di}}let Bs=48;for(;Bs<123;)di[Bs]=Fi,Bs++,Bs===58?Bs=65:Bs===91&&(Bs=97);di[43]=Fi;di[45]=Fi;di[46]=Fi;di[95]=Fi;di[72]=[Fi,NR];di[104]=[Fi,NR];di[87]=[Fi,ER];di[119]=[Fi,ER];function eX(e,t,n){const r=this;let i,s;return o;function o(d){return!Xv(d)||!IR.call(r,r.previous)||Z_(r.events)?n(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(d))}function a(d){return Xv(d)?(e.consume(d),a):d===64?(e.consume(d),l):n(d)}function l(d){return d===46?e.check(QG,u,c)(d):d===45||d===95||yn(d)?(s=!0,e.consume(d),l):u(d)}function c(d){return e.consume(d),i=!0,l}function u(d){return s&&i&&Cn(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):n(d)}}function tX(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!TR.call(r,r.previous)||Z_(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(ZG,e.attempt(SR,e.attempt(kR,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function nX(e,t,n){const r=this;let i="",s=!1;return o;function o(d){return(d===72||d===104)&&PR.call(r,r.previous)&&!Z_(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(d),e.consume(d),a):n(d)}function a(d){if(Cn(d)&&i.length<5)return i+=String.fromCodePoint(d),e.consume(d),a;if(d===58){const f=i.toLowerCase();if(f==="http"||f==="https")return e.consume(d),l}return n(d)}function l(d){return d===47?(e.consume(d),s?c:(s=!0,l)):n(d)}function c(d){return d===null||$h(d)||ot(d)||xo(d)||Qf(d)?n(d):e.attempt(SR,e.attempt(kR,u),n)(d)}function u(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function rX(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function iX(e,t,n){let r,i,s;return o;function o(c){return c===46||c===95?e.check(CR,l,a)(c):c===null||ot(c)||xo(c)||c!==45&&Qf(c)?l(c):(s=!0,e.consume(c),o)}function a(c){return c===95?r=!0:(i=r,r=void 0),e.consume(c),o}function l(c){return i||r||!s?n(c):t(c)}}function sX(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(CR,t,s)(o):o===null||ot(o)||xo(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function oX(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),i):a===60||a===null||ot(a)||xo(a)?t(a):n(a)}function i(a){return a===null||a===40||a===91||ot(a)||xo(a)?t(a):r(a)}function s(a){return Cn(a)?o(a):n(a)}function o(a){return a===59?(e.consume(a),r):Cn(a)?(e.consume(a),o):n(a)}}function aX(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return yn(s)?n(s):t(s)}}function TR(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||ot(e)}function PR(e){return!Cn(e)}function IR(e){return!(e===47||Xv(e))}function Xv(e){return e===43||e===45||e===46||e===95||yn(e)}function Z_(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const lX={tokenize:gX,partial:!0};function cX(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:fX,continuation:{tokenize:pX},exit:mX}},text:{91:{name:"gfmFootnoteCall",tokenize:hX},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:uX,resolveTo:dX}}}}function uX(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const l=r.events[i][1];if(l.type==="labelImage"){o=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!o||!o._balanced)return n(l);const c=Ar(r.sliceSerialize({start:o.end,end:r.now()}));return c.codePointAt(0)!==94||!s.includes(c.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function dX(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function hX(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return a;function a(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),l}function l(d){return d!==94?n(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(d){if(s>999||d===93&&!o||d===null||d===91||ot(d))return n(d);if(d===93){e.exit("chunkString");const f=e.exit("gfmFootnoteCallString");return i.includes(Ar(r.sliceSerialize(f)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(d)}return ot(d)||(o=!0),s++,e.consume(d),d===92?u:c}function u(d){return d===91||d===92||d===93?(e.consume(d),s++,c):c(d)}}function fX(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,a;return l;function l(m){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(m){return m===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",u):n(m)}function u(m){if(o>999||m===93&&!a||m===null||m===91||ot(m))return n(m);if(m===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return s=Ar(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(m),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),f}return ot(m)||(a=!0),o++,e.consume(m),m===92?d:u}function d(m){return m===91||m===92||m===93?(e.consume(m),o++,u):u(m)}function f(m){return m===58?(e.enter("definitionMarker"),e.consume(m),e.exit("definitionMarker"),i.includes(s)||i.push(s),Ve(e,p,"gfmFootnoteDefinitionWhitespace")):n(m)}function p(m){return t(m)}}function pX(e,t,n){return e.check(hu,t,e.attempt(lX,t,n))}function mX(e){e.exit("gfmFootnoteDefinition")}function gX(e,t,n){const r=this;return Ve(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function vX(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,a){let l=-1;for(;++l<o.length;)if(o[l][0]==="enter"&&o[l][1].type==="strikethroughSequenceTemporary"&&o[l][1]._close){let c=l;for(;c--;)if(o[c][0]==="exit"&&o[c][1].type==="strikethroughSequenceTemporary"&&o[c][1]._open&&o[l][1].end.offset-o[l][1].start.offset===o[c][1].end.offset-o[c][1].start.offset){o[l][1].type="strikethroughSequence",o[c][1].type="strikethroughSequence";const u={type:"strikethrough",start:Object.assign({},o[c][1].start),end:Object.assign({},o[l][1].end)},d={type:"strikethroughText",start:Object.assign({},o[c][1].end),end:Object.assign({},o[l][1].start)},f=[["enter",u,a],["enter",o[c][1],a],["exit",o[c][1],a],["enter",d,a]],p=a.parser.constructs.insideSpan.null;p&&tr(f,f.length,0,Jf(p,o.slice(c+1,l),a)),tr(f,f.length,0,[["exit",d,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",u,a]]),tr(o,c-1,l-c+3,f),l=c+f.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function s(o,a,l){const c=this.previous,u=this.events;let d=0;return f;function f(m){return c===126&&u[u.length-1][1].type!=="characterEscape"?l(m):(o.enter("strikethroughSequenceTemporary"),p(m))}function p(m){const v=za(c);if(m===126)return d>1?l(m):(o.consume(m),d++,p);if(d<2&&!n)return l(m);const y=o.exit("strikethroughSequenceTemporary"),x=za(m);return y._open=!x||x===2&&!!v,y._close=!v||v===2&&!!x,a(m)}}}class xX{constructor(){this.map=[]}add(t,n,r){_X(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function _X(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function yX(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function bX(){return{flow:{null:{name:"table",tokenize:wX,resolveAll:SX}}}}function wX(e,t,n){const r=this;let i=0,s=0,o;return a;function a(P){let O=r.events.length-1;for(;O>-1;){const D=r.events[O][1].type;if(D==="lineEnding"||D==="linePrefix")O--;else break}const I=O>-1?r.events[O][1].type:null,R=I==="tableHead"||I==="tableRow"?C:l;return R===C&&r.parser.lazy[r.now().line]?n(P):R(P)}function l(P){return e.enter("tableHead"),e.enter("tableRow"),c(P)}function c(P){return P===124||(o=!0,s+=1),u(P)}function u(P){return P===null?n(P):be(P)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(P),e.exit("lineEnding"),p):n(P):ze(P)?Ve(e,u,"whitespace")(P):(s+=1,o&&(o=!1,i+=1),P===124?(e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),o=!0,u):(e.enter("data"),d(P)))}function d(P){return P===null||P===124||ot(P)?(e.exit("data"),u(P)):(e.consume(P),P===92?f:d)}function f(P){return P===92||P===124?(e.consume(P),d):d(P)}function p(P){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(P):(e.enter("tableDelimiterRow"),o=!1,ze(P)?Ve(e,m,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(P):m(P))}function m(P){return P===45||P===58?y(P):P===124?(o=!0,e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),v):k(P)}function v(P){return ze(P)?Ve(e,y,"whitespace")(P):y(P)}function y(P){return P===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(P),e.exit("tableDelimiterMarker"),x):P===45?(s+=1,x(P)):P===null||be(P)?w(P):k(P)}function x(P){return P===45?(e.enter("tableDelimiterFiller"),_(P)):k(P)}function _(P){return P===45?(e.consume(P),_):P===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(P),e.exit("tableDelimiterMarker"),b):(e.exit("tableDelimiterFiller"),b(P))}function b(P){return ze(P)?Ve(e,w,"whitespace")(P):w(P)}function w(P){return P===124?m(P):P===null||be(P)?!o||i!==s?k(P):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(P)):k(P)}function k(P){return n(P)}function C(P){return e.enter("tableRow"),N(P)}function N(P){return P===124?(e.enter("tableCellDivider"),e.consume(P),e.exit("tableCellDivider"),N):P===null||be(P)?(e.exit("tableRow"),t(P)):ze(P)?Ve(e,N,"whitespace")(P):(e.enter("data"),T(P))}function T(P){return P===null||P===124||ot(P)?(e.exit("data"),N(P)):(e.consume(P),P===92?L:T)}function L(P){return P===92||P===124?(e.consume(P),T):T(P)}}function SX(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,c,u,d;const f=new xX;for(;++n<e.length;){const p=e[n],m=p[1];p[0]==="enter"?m.type==="tableHead"?(a=!1,l!==0&&(TS(f,t,l,c,u),u=void 0,l=0),c={type:"table",start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[["enter",c,t]])):m.type==="tableRow"||m.type==="tableDelimiterRow"?(r=!0,d=void 0,s=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,u={type:"tableBody",start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[["enter",u,t]])),i=m.type==="tableDelimiterRow"?2:u?3:1):i&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],d=cd(f,t,s,i,void 0,d),s=[0,0,0,0]),o[2]=n)):m.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],d=cd(f,t,s,i,void 0,d)),s=o,o=[s[1],n,0,0])):m.type==="tableHead"?(a=!0,l=n):m.type==="tableRow"||m.type==="tableDelimiterRow"?(l=n,s[1]!==0?(o[0]=o[1],d=cd(f,t,s,i,n,d)):o[1]!==0&&(d=cd(f,t,o,i,n,d)),i=0):i&&(m.type==="data"||m.type==="tableDelimiterMarker"||m.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&TS(f,t,l,c,u),f.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=yX(t.events,n))}return e}function cd(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},Xo(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=Xo(t.events,n[1]);if(s={type:o,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const c=Xo(t.events,n[2]),u=Xo(t.events,n[3]),d={type:a,start:Object.assign({},c),end:Object.assign({},u)};if(e.add(n[2],0,[["enter",d,t]]),r!==2){const f=t.events[n[2]],p=t.events[n[3]];if(f[1].end=Object.assign({},p[1].end),f[1].type="chunkText",f[1].contentType="text",n[3]>n[2]+1){const m=n[2]+1,v=n[3]-n[2]-1;e.add(m,v,[])}}e.add(n[3]+1,0,[["exit",d,t]])}return i!==void 0&&(s.end=Object.assign({},Xo(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function TS(e,t,n,r,i){const s=[],o=Xo(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function Xo(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const kX={name:"tasklistCheck",tokenize:EX};function CX(){return{text:{91:kX}}}function EX(e,t,n){const r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return ot(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),o):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),o):n(l)}function o(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return be(l)?t(l):ze(l)?e.check({tokenize:NX},t,n)(l):n(l)}}function NX(e,t,n){return Ve(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function TX(e){return $I([JG(),cX(),vX(e),bX(),CX()])}const PX={};function Vc(e){const t=this,n=e||PX,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(TX(n)),s.push(XG()),o.push(YG(n))}const IX=/<command-name>([\s\S]*?)<\/command-name>/i,RX=/<command-message>([\s\S]*?)<\/command-message>/i,MX=/<command-args>([\s\S]*?)<\/command-args>/i,AX=/<(local-command-[a-z]+|command-(?:stdout|stderr))>[\s\S]*?<\/\1>/gi;function rp(e){if(!e)return{commandName:null,commandMessage:null,commandArgs:null,body:""};const t=e.match(IX),n=e.match(RX),r=e.match(MX);let i=e;return t&&(i=i.replace(t[0],"")),n&&(i=i.replace(n[0],"")),r&&(i=i.replace(r[0],"")),i=i.replace(AX,""),i=i.trim(),{commandName:t?t[1].trim():null,commandMessage:n?n[1].trim():null,commandArgs:r?r[1].trim():null,body:i}}const jX=/\.(png|jpe?g|webp|gif|svg)$/i;function DX(e,t){if((typeof t=="string"?t:null)!==e)return!1;try{const r=new URL(e);return jX.test(r.pathname)}catch{return!1}}function LX(e){try{return new URL(e).pathname.split("/").filter(Boolean).pop()??""}catch{return""}}const qc={a:({node:e,href:t,children:n,...r})=>typeof t=="string"&&DX(t,n)?h.jsxs("span",{className:"my-1 inline-flex flex-col items-start gap-1 align-top",children:[h.jsx("img",{src:t,alt:LX(t),className:"max-w-full h-auto rounded border border-border"}),h.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"max-w-full truncate text-[11px] text-text-300 underline decoration-dotted underline-offset-2 hover:text-text-100",children:t})]}):h.jsx("a",{...r,href:t,target:"_blank",rel:"noopener noreferrer",children:n})};function OX({text:e,forkTarget:t}){const{body:n}=rp(e);return n?h.jsxs("div",{className:"group flex min-w-0 max-w-full flex-col items-start","data-testid":"msg-line-assistant-wrapper",children:[h.jsx("div",{"data-testid":"msg-line-assistant",className:"assistant-markdown w-full min-w-0 max-w-full py-1 break-words",children:h.jsx(Uc,{remarkPlugins:[Vc],components:qc,children:n})}),t?h.jsxs("div",{className:"mt-1 flex flex-row items-center gap-1",children:[t.onFork?h.jsxs("button",{type:"button","data-testid":"assistant-msg-fork","aria-label":"fork from this message",title:"从这条消息派生新 session(截断之后的对话)",onClick:()=>t.onFork(t.messageUuid),className:"inline-flex items-center justify-start gap-1 h-7 w-7 md:h-6 md:w-auto md:px-1.5 rounded-md text-[11px] text-text-400/60 md:text-text-400 hover:bg-text-100/5 hover:text-text-200 md:opacity-0 md:group-hover:opacity-100 md:transition-opacity cursor-pointer",children:[h.jsx(BN,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{className:"hidden md:inline",children:"Fork"})]}):null,t.onQuickAsk?h.jsxs("button",{type:"button","data-testid":"assistant-msg-quick-ask","aria-label":"quick ask from this message",title:"快速问答:从这条消息派生临时会话,关闭即删",onClick:()=>t.onQuickAsk(t.messageUuid),className:"inline-flex items-center justify-start gap-1 h-7 w-7 md:h-6 md:w-auto md:px-1.5 rounded-md text-[11px] text-text-400/60 md:text-text-400 hover:bg-text-100/5 hover:text-text-200 md:opacity-0 md:group-hover:opacity-100 md:transition-opacity cursor-pointer",children:[h.jsx(FN,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{className:"hidden md:inline",children:"问一下"})]}):null]}):null]}):null}function BX({text:e}){const[t,n]=g.useState(!1);return e?h.jsxs("div",{"data-testid":"msg-line-thinking",className:"text-[12px] text-text-400",children:[h.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"flex items-center gap-1 hover:text-text-300 transition-colors cursor-pointer","aria-expanded":t,"data-testid":"msg-line-thinking-toggle",children:[t?h.jsx(li,{className:"w-3 h-3"}):h.jsx(ci,{className:"w-3 h-3"}),h.jsx("span",{children:"💭 Thinking"})]}),t?h.jsx("div",{className:"ml-4 mt-1 italic text-text-400 whitespace-pre-wrap break-words",children:e}):null]}):null}function RR(e){if(!e)return!1;const n=e.split("#")[0].split("?")[0].toLowerCase();return n.endsWith(".md")||n.endsWith(".markdown")}const zX=new Set(["Write","Edit","MultiEdit","NotebookEdit"]);function Yv(e){return zX.has(e)}function $X({tool:e,relPath:t,scope:n,onShareFile:r}){if(!Yv(e)||!t||!n||!r)return null;const i=RR(t)?"md-rendered":"raw";return h.jsx("span",{"data-testid":"file-edit-hover-row",className:"inline-flex shrink-0 items-center gap-1",children:h.jsx("span",{role:"button",tabIndex:0,"data-testid":"file-edit-share-btn","aria-label":"Share link",title:"Share link",onClick:s=>{s.stopPropagation(),r(t,i)},onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.stopPropagation(),s.preventDefault(),r(t,i))},className:"inline-flex h-3.5 w-3.5 items-center justify-center text-text-400 hover:text-text-200 cursor-pointer",children:h.jsx(Gx,{className:"h-3.5 w-3.5"})})})}function FX(e){if(!e||typeof e!="object")return null;const t=e;return typeof t.file_path=="string"&&t.file_path||typeof t.notebook_path=="string"&&t.notebook_path||typeof t.path=="string"&&t.path||null||null}function MR(e,t){const[n,r]=g.useState({kind:"idle"});return g.useEffect(()=>{let i=!1,s=null;r({kind:"loading"});const o={};return t&&(o.Authorization=`Bearer ${t}`),fetch(e,{headers:o,credentials:"omit"}).then(async a=>{if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.blob()}).then(a=>{if(i)return;const l=URL.createObjectURL(a);s=l,r({kind:"ready",objectUrl:l})}).catch(a=>{i||r({kind:"error",message:a.message})}),()=>{i=!0,s&&URL.revokeObjectURL(s)}},[e,t]),n}function HX({url:e,bearerToken:t,alt:n,className:r}){const i=MR(e,t);return h.jsxs("div",{"data-testid":"blob-image","data-state":i.kind,className:ne("relative inline-flex items-center justify-center rounded-md border border-border bg-bg-0",r),children:[i.kind==="loading"?h.jsx("div",{className:"flex h-24 w-32 items-center justify-center",children:h.jsx(rr,{className:"h-4 w-4 animate-spin text-text-400"})}):null,i.kind==="error"?h.jsxs("div",{className:"flex h-24 w-32 items-center justify-center gap-1 px-2 text-[11px] text-text-400",children:[h.jsx(Rs,{className:"h-3 w-3"}),h.jsx("span",{title:i.message,children:"加载失败"})]}):null,i.kind==="ready"?h.jsx("img",{src:i.objectUrl,alt:n,className:"block max-h-[180px] max-w-[420px] rounded-md object-contain"}):null]})}function UX({url:e,bearerToken:t,className:n}){const r=MR(e,t);return h.jsxs("div",{"data-testid":"blob-video","data-state":r.kind,className:ne("relative inline-flex items-center justify-center rounded-md border border-border bg-bg-0",n),children:[r.kind==="loading"?h.jsx(rr,{className:"h-4 w-4 animate-spin text-text-400"}):null,r.kind==="error"?h.jsx("span",{className:"px-2 text-[11px] text-text-400",children:"加载失败"}):null,r.kind==="ready"?h.jsx("video",{src:r.objectUrl,controls:!0,className:"block max-h-[240px] max-w-[420px] rounded-md"}):null]})}const WX=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg"]),VX=new Set([".mp4",".webm",".mov"]),qX=new Set([".pdf"]);function KX(e){const t=e.lastIndexOf("."),n=t>=0?e.slice(t).toLowerCase():"";return WX.has(n)?"image":VX.has(n)?"video":qX.has(n)?"pdf":"binary"}function AR(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function GX({relPath:e,scope:t,size:n}){const r=Af();if(r.actionsLevel==="none")return null;const i=YO(r,t,e);if(!i)return null;const s=KX(e);return s==="image"?h.jsx("div",{"data-testid":"file-edit-inline-preview","data-kind":"image",className:"mt-2",children:h.jsx(HX,{url:i,bearerToken:r.httpToken,alt:e})}):s==="video"?h.jsx("div",{"data-testid":"file-edit-inline-preview","data-kind":"video",className:"mt-2",children:h.jsx(UX,{url:i,bearerToken:r.httpToken})}):s==="pdf"?h.jsx(XX,{relPath:e,url:i,size:n}):typeof n=="number"&&n>=1024*1024?h.jsxs("div",{"data-testid":"file-edit-inline-preview","data-kind":"binary",className:"mt-2 inline-flex items-center gap-1.5 rounded border border-border bg-bg-50 px-2 py-1 text-[11px] text-text-400",children:[h.jsx(Ms,{className:"h-3 w-3"}),h.jsx("span",{className:"font-mono",children:e.split("/").pop()}),h.jsx("span",{children:"·"}),h.jsx("span",{children:AR(n)})]}):null}function XX({relPath:e,url:t,size:n}){return h.jsxs("a",{"data-testid":"file-edit-inline-preview","data-kind":"pdf",href:t,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex items-center gap-1.5 rounded border border-border bg-bg-50 px-2 py-1 text-[11px] text-text-300 hover:bg-bg-100",children:[h.jsx(Ms,{className:"h-3 w-3"}),h.jsx("span",{className:"font-mono",children:e.split("/").pop()}),typeof n=="number"?h.jsxs(h.Fragment,{children:[h.jsx("span",{children:"·"}),h.jsx("span",{children:AR(n)})]}):null,h.jsx(Ac,{className:"h-3 w-3"})]})}const YX={Bash:VN,Read:Ms,Edit:UN,Write:l6,Grep:Cv,Glob:Cv};function ZX(e){return YX[e]??dz}function QX(e){if(!e||typeof e!="object")return"";const t=e,n=t.command??t.file_path??t.path??t.pattern??t.query??t.url??t.description;if(typeof n=="string")return n;for(const r of Object.values(t))if(typeof r=="string"&&r)return r;return""}function jR({tool:e,input:t,output:n,error:r,pending:i=!1,expandedBody:s,fileScope:o,onOpenInTab:a,onPreviewMarkdown:l,onShareFile:c}){const[u,d]=g.useState(!1),f=!!r,p=ZX(e),m=QX(t),v=FX(t);return h.jsxs("div",{"data-testid":"msg-line-tool","data-tool":e,className:ne("group min-w-0 max-w-full rounded-md border px-3 py-2 text-[13px]",f?"border-destructive/40 bg-destructive/5":"border-border bg-bg-50"),children:[h.jsxs("button",{type:"button",onClick:()=>d(y=>!y),"aria-expanded":u,"data-testid":"msg-line-tool-header",className:"flex w-full items-center gap-2 text-left cursor-pointer min-w-0",children:[f?h.jsx(Rs,{className:"w-4 h-4 text-destructive shrink-0"}):h.jsx(p,{className:ne("w-4 h-4 shrink-0",i?"text-text-400":"text-text-300")}),h.jsx("span",{className:"font-medium text-text-100 shrink-0",children:e}),m?(()=>{if(f||!Yv(e)||!v)return null;const x=RR(v)&&l?l:a;return x?h.jsx("span",{role:"button",tabIndex:0,"data-testid":"msg-line-tool-preview","data-clickable":"true",title:m,onClick:_=>{_.stopPropagation(),x(v)},onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.stopPropagation(),_.preventDefault(),x(v))},className:"text-[12px] text-accent font-mono truncate min-w-0 max-w-full cursor-pointer underline underline-offset-2 hover:opacity-80",children:m}):null})()??h.jsx("span",{"data-testid":"msg-line-tool-preview",className:"text-[12px] text-text-400 font-mono truncate min-w-0 max-w-full",title:m,children:m}):null,h.jsx("span",{"aria-hidden":"true","data-testid":"msg-line-tool-header-spacer",className:"flex-1 min-w-0 self-stretch"}),i?h.jsx(rr,{"data-testid":"msg-line-tool-pending",className:"w-3 h-3 text-text-400 animate-spin shrink-0"}):null,!f&&o?h.jsx($X,{tool:e,relPath:v,scope:o,...c?{onShareFile:c}:{}}):null]}),u?s!==void 0?h.jsxs("div",{"data-testid":"msg-line-tool-body",className:"mt-2 min-w-0 text-[12px]",children:[s,f?h.jsxs("div",{className:"mt-2",children:[h.jsx("div",{className:"text-destructive mb-0.5",children:"error"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-destructive/40 rounded p-2 overflow-auto text-destructive",children:String(r)})]}):null]}):h.jsxs("div",{"data-testid":"msg-line-tool-body",className:"mt-2 min-w-0 space-y-1 text-[12px]",children:[h.jsxs("div",{children:[h.jsx("div",{className:"text-text-400 mb-0.5",children:"input"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 overflow-auto text-text-200",children:JSON.stringify(t,null,2)})]}),n!==void 0?h.jsxs("div",{children:[h.jsx("div",{className:"text-text-400 mb-0.5",children:"output"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 overflow-auto text-text-200",children:typeof n=="string"?n:JSON.stringify(n,null,2)})]}):null,f?h.jsxs("div",{children:[h.jsx("div",{className:"text-destructive mb-0.5",children:"error"}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-destructive/40 rounded p-2 overflow-auto text-destructive",children:String(r)})]}):null]}):null,!f&&o&&v&&Yv(e)?h.jsx(GX,{relPath:v,scope:o}):null]})}var JX=Symbol.for("react.lazy"),Wh=Ha[" use ".trim().toString()];function eY(e){return typeof e=="object"&&e!==null&&"then"in e}function DR(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===JX&&"_payload"in e&&eY(e._payload)}function tY(e){const t=rY(e),n=g.forwardRef((r,i)=>{let{children:s,...o}=r;DR(s)&&typeof Wh=="function"&&(s=Wh(s._payload));const a=g.Children.toArray(s),l=a.find(sY);if(l){const c=l.props.children,u=a.map(d=>d===l?g.Children.count(c)>1?g.Children.only(null):g.isValidElement(c)?c.props.children:null:d);return h.jsx(t,{...o,ref:i,children:g.isValidElement(c)?g.cloneElement(c,void 0,u):null})}return h.jsx(t,{...o,ref:i,children:s})});return n.displayName=`${e}.Slot`,n}var nY=tY("Slot");function rY(e){const t=g.forwardRef((n,r)=>{let{children:i,...s}=n;if(DR(i)&&typeof Wh=="function"&&(i=Wh(i._payload)),g.isValidElement(i)){const o=aY(i),a=oY(s,i.props);return i.type!==g.Fragment&&(a.ref=r?ou(r,o):o),g.cloneElement(i,a)}return g.Children.count(i)>1?g.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var iY=Symbol("radix.slottable");function sY(e){return g.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===iY}function oY(e,t){const n={...t};for(const r in t){const i=e[r],s=t[r];/^on[A-Z]/.test(r)?i&&s?n[r]=(...a)=>{const l=s(...a);return i(...a),l}:i&&(n[r]=i):r==="style"?n[r]={...i,...s}:r==="className"&&(n[r]=[i,s].filter(Boolean).join(" "))}return{...e,...n}}function aY(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}const PS=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,IS=GN,lY=(e,t)=>n=>{var r;if((t==null?void 0:t.variants)==null)return IS(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:i,defaultVariants:s}=t,o=Object.keys(i).map(c=>{const u=n==null?void 0:n[c],d=s==null?void 0:s[c];if(u===null)return null;const f=PS(u)||PS(d);return i[c][f]}),a=n&&Object.entries(n).reduce((c,u)=>{let[d,f]=u;return f===void 0||(c[d]=f),c},{}),l=t==null||(r=t.compoundVariants)===null||r===void 0?void 0:r.reduce((c,u)=>{let{class:d,className:f,...p}=u;return Object.entries(p).every(m=>{let[v,y]=m;return Array.isArray(y)?y.includes({...s,...a}[v]):{...s,...a}[v]===y})?[...c,d,f]:c},[]);return IS(e,o,l,n==null?void 0:n.class,n==null?void 0:n.className)},cY=lY("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{variants:{variant:{default:"bg-accent text-accent-contrast hover:bg-accent-hover",destructive:"bg-destructive text-white hover:bg-destructive-hover",outline:"border border-border bg-transparent text-text-100 hover:bg-bg-200",ghost:"bg-transparent text-text-200 hover:bg-bg-200 hover:text-text-100"},size:{sm:"h-8 px-3 text-xs",md:"h-9 px-4",lg:"h-11 px-6 text-base"}},defaultVariants:{variant:"default",size:"md"}}),ni=g.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},s)=>{const o=r?nY:"button";return h.jsx(o,{ref:s,className:ne(cY({variant:t,size:n}),e),...i})});ni.displayName="Button";function uY({tool:e,input:t,onRespond:n,onInterrupt:r}){return h.jsxs("div",{"data-testid":"msg-line-permission",className:"min-w-0 max-w-full rounded-md border border-warning/40 bg-warning-dim/60 px-3 py-2.5 text-[13px]",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 mb-1.5",children:[h.jsx(J6,{className:"w-4 h-4 text-warning shrink-0"}),h.jsxs("span",{className:"min-w-0 font-medium text-text-100 truncate",children:["权限请求:",e]}),r?h.jsx("button",{type:"button",onClick:r,"data-testid":"msg-line-permission-interrupt","aria-label":"interrupt current turn",title:"中断当前轮次(不杀进程)",className:"ml-auto h-6 w-6 rounded-md flex items-center justify-center text-text-400 hover:bg-text-100/10 hover:text-text-200 transition-colors cursor-pointer",children:h.jsx(HN,{className:"w-3.5 h-3.5",strokeWidth:2})}):null]}),h.jsx("pre",{className:"min-w-0 max-w-full bg-bg-0 border border-border rounded p-2 mb-2 max-h-[140px] overflow-auto text-[12px] text-text-200",children:JSON.stringify(t,null,2)}),h.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[h.jsx(ni,{size:"sm",variant:"default",onClick:()=>n(!0,!1),"data-testid":"msg-line-permission-allow",children:"Allow"}),h.jsx(ni,{size:"sm",variant:"outline",onClick:()=>n(!0,!0),"data-testid":"msg-line-permission-allow-always",children:"Allow Always"}),h.jsx(ni,{size:"sm",variant:"destructive",onClick:()=>n(!1,!1),"data-testid":"msg-line-permission-deny",children:"Deny"})]})]})}function dY({message:e}){return h.jsxs("div",{"data-testid":"msg-line-error",className:"flex min-w-0 max-w-full items-start gap-2 text-destructive text-[13px] rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2",children:[h.jsx(jc,{className:"w-4 h-4 shrink-0 mt-0.5"}),h.jsx("span",{className:"min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:e})]})}const RS=/\[attachment:(image|file):([^\]]+)\]/g;function hY(e){const t=[];let n;for(;(n=RS.exec(e))!==null;){const i=n[2],s=decodeURIComponent(i.split("/").pop()??"file");t.push({type:n[1],url:i,fileName:s})}const r=e.replace(RS,"").trim();return{attachments:t,text:r}}function fY(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(`
519
519
  `)+`
520
520
  `+e}const pY=/\[skill:(.+?):(\/[^\]]+)\]/g;function mY(e){const t=[],n=e.replace(pY,(r,i)=>(t.push(i),""));return{skills:t,text:t.length>0?n.trim():e}}function gY({text:e,senderDisplayName:t,rewindTarget:n}){const r=CI(e),{attachments:i,text:s}=hY(r),{skills:o,text:a}=mY(s),{commandName:l,body:c}=rp(a),u=c.length>0;return u||i.length>0||!!l||o.length>0?(l||o.length>0)&&!u&&i.length===0?h.jsxs("div",{className:"flex min-w-0 max-w-full justify-end gap-1.5 py-2 mt-2","data-testid":"msg-line-user",children:[o.map((f,p)=>h.jsxs("span",{"data-testid":"user-skill-chip",className:"inline-flex items-center rounded-md bg-bg-200/60 px-2 py-0.5 text-[11px] font-mono text-text-300",children:["/",f]},`${f}-${p}`)),l?h.jsx("span",{className:"inline-flex items-center rounded-md bg-bg-200/60 px-2 py-0.5 text-[11px] font-mono text-text-300",children:l}):null]}):h.jsxs("div",{className:"group flex min-w-0 max-w-full flex-col items-end py-2 mt-2","data-testid":"msg-line-user",children:[h.jsxs("div",{className:"min-w-0 max-w-[85%] rounded-2xl rounded-br-sm bg-accent px-3.5 py-2 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:[i.length>0?h.jsx(vY,{attachments:i}):null,o.length>0?h.jsx("div",{className:ne("flex flex-wrap gap-1.5",(u||l)&&"mb-1.5"),children:o.map((f,p)=>h.jsxs("span",{"data-testid":"user-skill-chip",className:"inline-flex items-center rounded-md bg-white/15 px-2 py-0.5 text-[11px] font-mono text-white/90",children:["/",f]},`${f}-${p}`))}):null,l?h.jsx("div",{className:ne("flex",u&&"mb-1.5"),children:h.jsx("span",{"data-testid":"user-command-chip",className:"inline-flex items-center rounded-md bg-white/15 px-2 py-0.5 text-[11px] font-mono text-white/90",children:l})}):null,u?h.jsx("div",{className:"text-[14px] text-white font-medium leading-relaxed",children:c}):null]}),t?h.jsx("div",{"data-testid":"user-msg-sender-label",className:"mt-1 text-[11px] text-text-400",children:t}):null,n?h.jsxs("button",{type:"button","data-testid":"user-msg-rewind","aria-label":"rewind to this message",title:"回退到这条消息(会撤销之后 CC 的文件编辑)",onClick:()=>n.onRewind(n.userMessageId),className:"mt-1 inline-flex items-center gap-1 h-6 px-1.5 rounded-md text-[11px] text-text-400 hover:bg-text-100/5 hover:text-text-200 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:[h.jsx(qN,{className:"w-3 h-3",strokeWidth:2}),h.jsx("span",{children:"Rewind"})]}):null]}):null}function vY({attachments:e}){return h.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1.5","data-testid":"user-attachment-row",children:e.map(t=>h.jsx(xY,{attachment:t},t.url))})}function xY({attachment:e}){return e.type==="image"?h.jsx("img",{src:e.url,alt:e.fileName,"data-testid":"user-attachment-image",className:"h-16 w-16 rounded object-cover shrink-0 border border-bg-300/50"}):h.jsxs("div",{"data-testid":"user-attachment-file",className:"flex items-center gap-1.5 rounded-md border border-bg-300 bg-bg-100/60 px-2 py-1 text-[12px] text-text-200",children:[h.jsx(Ms,{className:"h-3.5 w-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"max-w-[140px] truncate",children:e.fileName})]})}const _Y={"task-notification":"子任务通知","slash-command":"斜杠命令","local-command":"本地命令输出","system-reminder":"系统提醒","skill-hint":"Skill 注入","meta-text":"系统消息","attachment-skills":"技能列表","attachment-deferred-tools":"Deferred 工具变更"},yY={"task-notification":Lb,"slash-command":nz,"local-command":VN,"system-reminder":Lb,"skill-hint":Mh,"meta-text":zN,"attachment-skills":Mh,"attachment-deferred-tools":F6};function bY({metaKind:e,text:t}){const[n,r]=g.useState(!1),i=yY[e];if(e==="slash-command"){const{commandName:o,commandMessage:a,commandArgs:l,body:c}=rp(t),u=o??(a?`/${a}`:null),d=!!(l&&l.length>0),f=c.length>0;return!u&&!d&&!f?null:h.jsxs("div",{"data-testid":"msg-line-user-meta","data-meta-kind":e,className:"flex min-w-0 max-w-full flex-col items-end gap-0.5 py-1",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 max-w-full",children:[u?h.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-md bg-bg-200/60 px-2 py-0.5 text-[11px] font-mono text-text-300 shrink-0",children:[h.jsx(i,{className:"w-3 h-3 opacity-70"}),u]}):null,d?h.jsx("span",{"data-testid":"user-meta-command-args",className:"min-w-0 text-[12px] text-text-200 whitespace-pre-wrap break-words max-w-[70ch] [overflow-wrap:anywhere]",children:l}):null]}),f?h.jsx("span",{className:"ml-2 max-w-[60%] truncate text-[11px] text-text-400",children:c}):null]})}const s=t.replace(/\s+/g," ").trim().slice(0,80);return h.jsxs("div",{"data-testid":"msg-line-user-meta","data-meta-kind":e,className:"flex min-w-0 max-w-full flex-col items-start gap-1 py-1",children:[h.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>r(o=>!o),className:ne("group inline-flex items-center gap-1.5 rounded-md border border-bg-200/60 bg-bg-100/40","px-2 py-1 text-[11px] text-text-400 hover:bg-bg-200/40 transition-colors max-w-full"),children:[h.jsx(i,{className:"w-3 h-3 opacity-70 shrink-0"}),h.jsx("span",{className:"font-medium shrink-0",children:_Y[e]}),h.jsx("span",{className:"truncate text-text-400/80 max-w-[60ch]",children:s}),n?h.jsx(li,{className:"w-3 h-3 opacity-60 shrink-0"}):h.jsx(ci,{className:"w-3 h-3 opacity-60 shrink-0"})]}),n?h.jsx("pre",{"data-testid":"user-meta-body",className:"w-full max-w-full whitespace-pre-wrap break-words text-[11px] text-text-400 bg-bg-50/60 rounded-md p-2 border border-bg-200/60 [overflow-wrap:anywhere]",children:t}):null]})}function wY({text:e,metaSource:t}){return t==="owner"?h.jsx("div",{className:"flex min-w-0 max-w-full flex-col items-start py-1.5","data-testid":"msg-line-owner-meta",children:h.jsxs("div",{className:ne("inline-flex min-w-0 max-w-[85%] items-start gap-2 rounded-md","border-l-[3px] border-accent bg-accent-dim px-3 py-2"),children:[h.jsx(T6,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-accent","aria-label":"补充信息"}),h.jsx("span",{className:"min-w-0 text-[12px] leading-relaxed text-text-100 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:e})]})}):h.jsxs("div",{className:"flex min-w-0 max-w-full items-start gap-1.5 py-1 text-[11px] text-text-400","data-testid":"msg-line-cc-meta",children:[h.jsx(zN,{className:"mt-0.5 h-3 w-3 shrink-0"}),h.jsx("span",{className:"min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",children:e})]})}function zr(e,t){const r=new RegExp(`<${t}\\b[^>]*>([\\s\\S]*?)</${t}>`,"i").exec(e);if(!r)return;const i=r[1].trim();return i||void 0}function Sm(e,t){const r=new RegExp(`${t}\\s*=\\s*"([^"]+)"`,"i").exec(e);if(!r)return;const i=Number(r[1]);return Number.isFinite(i)?i:void 0}function LR(e){var i,s,o;const t={};if(!e)return t;t.taskId=zr(e,"task-id"),t.toolUseId=zr(e,"tool-use-id"),t.outputFile=zr(e,"output-file"),t.status=zr(e,"status"),t.summary=zr(e,"summary"),t.result=zr(e,"result");const n=zr(e,"usage");if(n){const a=(i=/<total_tokens>\s*(\d+)\s*<\/total_tokens>/i.exec(n))==null?void 0:i[1],l=(s=/<tool_uses>\s*(\d+)\s*<\/tool_uses>/i.exec(n))==null?void 0:s[1],c=(o=/<duration_ms>\s*(\d+)\s*<\/duration_ms>/i.exec(n))==null?void 0:o[1];a&&(t.totalTokens=Number(a)),l&&(t.toolUses=Number(l)),c&&(t.durationMs=Number(c))}const r=zr(e,"worktree");if(r)t.worktreePath=zr(r,"worktreePath"),t.worktreeBranch=zr(r,"worktreeBranch");else{const a=/<worktree\b([^>]*)\/>/i.exec(e);if(a){const l=a[1],c=/worktreePath\s*=\s*"([^"]+)"/i.exec(l),u=/worktreeBranch\s*=\s*"([^"]+)"/i.exec(l);c&&(t.worktreePath=c[1]),u&&(t.worktreeBranch=u[1])}}if(t.totalTokens===void 0&&t.toolUses===void 0&&t.durationMs===void 0){const a=Sm(e,"total_tokens"),l=Sm(e,"tool_uses"),c=Sm(e,"duration_ms");a!==void 0&&(t.totalTokens=a),l!==void 0&&(t.toolUses=l),c!==void 0&&(t.durationMs=c)}return t}function SY(e){if(!e||!Number.isFinite(e))return null;if(e<1e3)return`${e}ms`;const t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;const n=Math.floor(t/60),r=Math.round(t-n*60);return`${n}m${r.toString().padStart(2,"0")}s`}function kY({text:e,taskId:t,parentToolUseId:n}){const r=g.useMemo(()=>LR(e),[e]),[i,s]=g.useState(!1),o=t??r.taskId,a=n??r.toolUseId,l=r.status==="failed"?h.jsx(Rs,{className:"w-3.5 h-3.5 text-error"}):r.status==="completed"?h.jsx(Df,{className:"w-3.5 h-3.5 text-success"}):h.jsx(jf,{className:"w-3.5 h-3.5 text-text-400"}),c=r.status??"unknown",u=SY(r.durationMs);return h.jsxs("div",{"data-testid":"msg-line-agent-notification","data-task-id":o??"","data-parent-tool-use-id":a??"",className:"my-1 min-w-0 max-w-full rounded-md border border-bg-200/60 bg-bg-100/40",children:[h.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>s(d=>!d),className:ne("flex w-full min-w-0 items-start gap-2 px-2.5 py-1.5 text-left text-[12px]","hover:bg-bg-200/40 rounded-md transition-colors"),children:[h.jsx("span",{className:"mt-[2px] shrink-0",children:l}),h.jsxs("span",{className:"flex-1 min-w-0",children:[h.jsxs("span",{className:"flex items-center gap-2 flex-wrap",children:[h.jsx("span",{className:"font-medium text-text-200",children:"子任务"}),h.jsx("span",{className:"text-text-400 text-[11px] font-mono",children:o?o.slice(0,12):"未知"}),h.jsx("span",{className:"text-text-400 text-[11px] uppercase tracking-wide",children:c}),u?h.jsxs("span",{className:"text-text-400 text-[11px] tabular-nums",children:["· ",u]}):null,r.totalTokens?h.jsxs("span",{className:"text-text-400 text-[11px] tabular-nums",children:["· ",r.totalTokens," tok"]}):null,r.toolUses?h.jsxs("span",{className:"text-text-400 text-[11px] tabular-nums",children:["· ",r.toolUses," tools"]}):null]}),r.summary?h.jsx("span",{className:"block truncate text-text-300 text-[12px] mt-0.5",children:r.summary}):null]}),i?h.jsx(li,{className:"w-3.5 h-3.5 mt-[3px] text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3.5 h-3.5 mt-[3px] text-text-400 shrink-0"})]}),i?h.jsxs("div",{"data-testid":"agent-notification-body",className:"min-w-0 border-t border-bg-200/60 px-3 py-2 text-[12px] text-text-300 space-y-2",children:[r.worktreePath||r.worktreeBranch?h.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-400",children:[h.jsx(BN,{className:"w-3 h-3"}),r.worktreeBranch?h.jsx("span",{className:"font-mono",children:r.worktreeBranch}):null,r.worktreePath?h.jsx("span",{className:"truncate font-mono",children:r.worktreePath}):null]}):null,r.outputFile?h.jsxs("div",{className:"text-[11px] text-text-400",children:[h.jsx("span",{children:"输出文件:"}),h.jsx("span",{className:"font-mono",children:r.outputFile})]}):null,a?h.jsxs("div",{className:"text-[11px] text-text-400",children:[h.jsx("span",{children:"父工具调用:"}),h.jsx("span",{className:"font-mono",children:a})]}):null,r.result?h.jsx("div",{"data-testid":"agent-notification-result",className:"assistant-markdown text-[12px] leading-relaxed break-words",children:h.jsx(Uc,{remarkPlugins:[Vc],components:qc,children:r.result})}):h.jsx("div",{className:"text-[11px] text-text-400 italic",children:"无详细结果"})]}):null]})}const OR=g.createContext(null);function CY({children:e}){const[t,n]=g.useState({agentId:null}),r=g.useCallback((o,a)=>{n({agentId:o,agentType:a})},[]),i=g.useCallback(()=>{n(o=>({agentId:null,agentType:o.agentType}))},[]),s=g.useMemo(()=>({state:t,open:r,close:i}),[t,r,i]);return h.jsx(OR.Provider,{value:s,children:e})}function BR(){return g.useContext(OR)}function EY(e){if(e==null)return null;if(typeof e=="string")return e;if(Array.isArray(e)){const t=[];for(const n of e)if(n&&typeof n=="object"){const r=n;r.type==="text"&&typeof r.text=="string"&&t.push(r.text)}else typeof n=="string"&&t.push(n);return t.length?t.join(`
521
- `):null}if(typeof e=="object"){const t=e;if(typeof t.text=="string")return t.text}return null}function MS(e){if(!e||!Number.isFinite(e))return null;if(e<1e3)return`${e}ms`;const t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;const n=Math.floor(t/60),r=Math.round(t-n*60);return`${n}m${r.toString().padStart(2,"0")}s`}function NY(e){return!e||!Number.isFinite(e)?null:e<1e3?`${e} tok`:e<1e4?`${(e/1e3).toFixed(1)}k tok`:`${Math.round(e/1e3)}k tok`}const TY={readCount:"read",searchCount:"search",bashCount:"bash",editFileCount:"edit",linesAdded:"+lines",linesRemoved:"-lines",otherToolCount:"other"};function PY(e){if(!e)return[];const t=[];for(const[n,r]of Object.entries(e)){if(!r||r<=0)continue;const i=TY[n]??n;t.push(`${i}:${r}`)}return t}function IY({description:e,input:t,output:n,error:r,pending:i,notifications:s,toolResultExtra:o,progress:a}){const[l,c]=g.useState(!1),u=BR(),d=g.useMemo(()=>{if(!t||typeof t!="object")return null;const T=t;return typeof T.prompt=="string"?T.prompt:null},[t]),f=(o==null?void 0:o.prompt)??d,p=g.useMemo(()=>EY(n),[n]),m=o==null?void 0:o.stats,v=a==null?void 0:a.stats,y=MS((m==null?void 0:m.durationMs)??(v==null?void 0:v.durationMs)),x=NY((m==null?void 0:m.tokens)??(v==null?void 0:v.tokens)),_=PY(m==null?void 0:m.toolStats),b=i&&(a!=null&&a.lastToolName)?`now:${a.lastToolName}`:null,w=!!(o!=null&&o.agentType||y||x||_.length>0||b),k=(o==null?void 0:o.agentId)??(a==null?void 0:a.agentId),C=g.useMemo(()=>s.map(T=>({taskId:T.taskId,text:T.text,parsed:LR(T.text)})),[s]),N=r?h.jsx(Rs,{className:"w-3.5 h-3.5 text-error"}):i?h.jsx(rr,{className:"w-3.5 h-3.5 text-blue-400 animate-spin"}):h.jsx(Df,{className:"w-3.5 h-3.5 text-green-500"});return h.jsxs("div",{"data-testid":"msg-line-agent-call","data-pending":i?"true":"false","data-has-error":r?"true":"false","data-notification-count":s.length,"data-has-stats":w?"true":"false","data-agent-id":k??"",className:"my-1 min-w-0 max-w-full rounded-md border border-bg-200/60 bg-bg-100/30",children:[h.jsxs("button",{type:"button","aria-expanded":l,onClick:()=>c(T=>!T),className:ne("flex w-full min-w-0 items-center gap-2 px-2.5 py-1.5 text-left text-[13px]","hover:bg-bg-200/40 rounded-md transition-colors"),children:[h.jsx("span",{className:"w-5 h-5 flex items-center justify-center text-[10px] rounded bg-violet-500/10 text-violet-500 shrink-0","aria-hidden":!0,children:h.jsx(pz,{className:"w-3 h-3"})}),h.jsx("span",{className:"shrink-0",children:N}),h.jsx("span",{className:"flex-1 min-w-0 truncate font-medium text-text-200",children:e}),w?null:s.length>0?h.jsxs("span",{className:"text-[11px] text-text-400 tabular-nums shrink-0",children:[s.length," 次通知"]}):null,k&&(u!=null&&u.open)?h.jsx("span",{role:"button",tabIndex:0,"data-testid":"open-subagent-btn-header","data-agent-id":k,"aria-label":"打开子 agent 对话",onClick:T=>{T.stopPropagation(),u.open(k,o==null?void 0:o.agentType)},onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&(T.stopPropagation(),T.preventDefault(),u.open(k,o==null?void 0:o.agentType))},className:"shrink-0 inline-flex items-center justify-center w-3.5 h-3.5 text-text-400 hover:text-text-200",children:h.jsx(Ac,{className:"w-3.5 h-3.5"})}):null,l?h.jsx(li,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3.5 h-3.5 text-text-400 shrink-0"})]}),i&&(a!=null&&a.description)?h.jsx("div",{"data-testid":"agent-call-progress-desc",className:"px-3 pt-0 pb-1 text-[12px] text-text-300 truncate",children:a.description}):null,w?h.jsxs("div",{"data-testid":"agent-call-stats",className:"flex items-center gap-1.5 flex-wrap px-3 pb-1.5 pt-0 text-[11px] text-text-400",children:[o!=null&&o.agentType?h.jsx("span",{"data-testid":"agent-call-stats-type",className:"inline-flex items-center rounded-sm bg-violet-500/10 px-1.5 py-0.5 text-violet-400 font-medium",children:o.agentType}):null,y?h.jsx("span",{className:"tabular-nums",children:y}):null,x?h.jsx("span",{className:"tabular-nums",children:x}):null,b?h.jsx("span",{"data-testid":"agent-call-stats-now",className:"font-mono tabular-nums text-blue-400",children:b}):null,_.map(T=>h.jsx("span",{className:"font-mono tabular-nums text-text-400/80",children:T},T)),s.length>0?h.jsxs("span",{className:"tabular-nums text-text-400/70",children:["· ",s.length," 次通知"]}):null]}):null,l?h.jsxs("div",{"data-testid":"agent-call-body",className:"min-w-0 border-t border-bg-200/60 px-3 py-2 space-y-3",children:[r?h.jsx("div",{className:"text-[12px] text-error whitespace-pre-wrap",children:r}):null,C.map((T,L)=>{const P=T.parsed,O=MS(P.durationMs);return h.jsxs("div",{"data-testid":"agent-call-notification","data-task-id":T.taskId??"",className:"min-w-0 rounded-md border border-bg-200/60 bg-bg-0/40 p-2 space-y-1.5",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-400 flex-wrap",children:[h.jsx("span",{className:"font-mono",children:(T.taskId??P.taskId??"未知").slice(0,12)}),h.jsx("span",{className:"uppercase tracking-wide",children:P.status??"unknown"}),O?h.jsxs("span",{className:"tabular-nums",children:["· ",O]}):null,P.totalTokens?h.jsxs("span",{className:"tabular-nums",children:["· ",P.totalTokens," tok"]}):null,P.toolUses?h.jsxs("span",{className:"tabular-nums",children:["· ",P.toolUses," tools"]}):null,P.worktreeBranch?h.jsxs("span",{className:"font-mono",children:["· ",P.worktreeBranch]}):null]}),P.summary?h.jsx("div",{className:"text-[12px] text-text-300",children:P.summary}):null,P.result?h.jsx("div",{"data-testid":"agent-call-notification-result",className:"assistant-markdown text-[12px] leading-relaxed break-words",children:h.jsx(Uc,{remarkPlugins:[Vc],components:qc,children:P.result})}):null]},`${T.taskId??"n"}-${L}`)}),f?h.jsxs("div",{"data-testid":"agent-call-prompt-block",className:"min-w-0 space-y-1",children:[h.jsx("div",{className:"text-[11px] text-text-400 font-medium",children:"任务指令"}),h.jsx("pre",{"data-testid":"agent-call-prompt",className:"max-w-full whitespace-pre-wrap break-words text-[11px] text-text-300 bg-bg-50/60 rounded p-2 border border-bg-200/60 max-h-64 overflow-auto [overflow-wrap:anywhere]",children:f})]}):null,p?h.jsxs("div",{"data-testid":"agent-call-result-block",className:"min-w-0 space-y-1",children:[h.jsx("div",{className:"text-[11px] text-text-400 font-medium",children:"子 agent 报告"}),h.jsx("div",{"data-testid":"agent-call-result",className:"assistant-markdown text-[12px] leading-relaxed break-words",children:h.jsx(Uc,{remarkPlugins:[Vc],components:qc,children:p})})]}):null,!p&&C.length===0&&!r&&!f?h.jsx("div",{className:"text-[11px] text-text-400 italic",children:"无详细信息"}):null,k&&(u!=null&&u.open)?h.jsx("div",{className:"flex justify-end",children:h.jsxs("button",{type:"button","data-testid":"open-subagent-btn","data-agent-id":k,onClick:()=>u.open(k,o==null?void 0:o.agentType),className:ne("inline-flex items-center gap-1 rounded-md border border-bg-200/60","bg-bg-100/40 hover:bg-bg-200/40 transition-colors","px-2 py-1 text-[11px] text-text-300"),children:[h.jsx(Ac,{className:"w-3 h-3"}),h.jsx("span",{children:"打开子 agent 对话"})]})}):null]}):null]})}function zR({title:e,items:t,live:n,progressColor:r="bg-green-500",listKind:i,children:s}){const[o,a]=g.useState(!!n),l=t.length,c=t.filter(d=>d.status==="completed").length,u=l>0?Math.round(c/l*100):0;return h.jsxs("div",{"data-testid":"msg-line-checklist","data-list-kind":i,className:"min-w-0 max-w-full py-1",children:[h.jsxs("button",{type:"button",onClick:()=>a(d=>!d),"aria-expanded":o,className:"flex items-center gap-2.5 w-full text-left rounded-md px-1.5 py-1 hover:bg-text-100/5 cursor-pointer",children:[o?h.jsx(li,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"text-[13px] font-medium text-text-200",children:e}),h.jsxs("span",{className:"text-[11px] text-text-400 tabular-nums",children:[c,"/",l]}),h.jsx("div",{className:"flex-1 max-w-[120px] h-1.5 rounded-full bg-text-100/10 overflow-hidden",children:h.jsx("div",{className:ne("h-full rounded-full transition-all duration-300",r),style:{width:`${u}%`}})})]}),o?h.jsxs("div",{"data-testid":"checklist-body",className:"ml-6 mt-0.5",children:[h.jsx("div",{className:"space-y-px",children:t.map((d,f)=>h.jsxs("div",{className:"flex min-w-0 items-start gap-2 py-0.5 px-1",children:[h.jsx("span",{className:"w-4 h-4 mt-0.5 flex items-center justify-center shrink-0",children:d.status==="completed"?h.jsx(Qa,{className:"w-3.5 h-3.5 text-green-500"}):d.status==="in_progress"&&n?h.jsx(rr,{className:"w-3.5 h-3.5 text-blue-400 animate-spin"}):h.jsx("span",{className:"w-2 h-2 rounded-full border border-text-400/40"})}),h.jsx("span",{className:ne("min-w-0 text-[13px] leading-snug break-words [overflow-wrap:anywhere]",d.status==="completed"?"text-text-400 line-through":"text-text-200"),children:d.status==="in_progress"&&d.activeForm?d.activeForm:d.content})]},`${f}-${d.content}`))}),s]}):null]})}function RY({todos:e,live:t}){return h.jsx(zR,{title:"Tasks",items:e,live:t,progressColor:"bg-green-500",listKind:"todo"})}function MY({tasks:e,live:t}){return h.jsx(zR,{title:"Plan",items:e,live:t,progressColor:"bg-blue-500",listKind:"plan"})}function AY(e){if(!e||!Number.isFinite(e))return null;const t=Date.now()-e;if(t<0)return null;const n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const i=Math.floor(r/60);if(i<24)return`${i}h ago`;const s=Math.floor(i/24);if(s<7)return`${s}d ago`;const o=Math.floor(s/7);return o<5?`${o}w ago`:new Date(e).toISOString().slice(0,10)}function jY(e){return(e.split("/").pop()??e)||e}function DY({memories:e}){return!e||e.length===0?null:h.jsxs("div",{"data-testid":"memory-callout",className:"my-1 min-w-0 max-w-full rounded-md border border-bg-200/60 bg-bg-100/30",children:[h.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 text-[12px] text-text-300 border-b border-bg-200/60",children:[h.jsx(jB,{className:"w-3.5 h-3.5 text-amber-500 shrink-0"}),h.jsx("span",{className:"font-medium",children:"项目记忆"}),h.jsxs("span",{className:"text-text-400 tabular-nums",children:["· ",e.length]})]}),h.jsx("ul",{className:"divide-y divide-bg-200/40",children:e.map(t=>h.jsx(LY,{memory:t},t.path))})]})}function LY({memory:e}){const[t,n]=g.useState(!1),r=AY(e.mtimeMs),i=e.content.replace(/\s+/g," ").trim().slice(0,80);return h.jsxs("li",{className:"px-2.5 py-1.5",children:[h.jsxs("button",{type:"button","aria-expanded":t,onClick:()=>n(s=>!s),className:ne("flex w-full items-center gap-1.5 text-left text-[12px]","hover:bg-bg-200/30 rounded-sm py-0.5"),children:[t?h.jsx(li,{className:"w-3 h-3 text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3 h-3 text-text-400 shrink-0"}),h.jsx("span",{className:"font-mono text-text-300 shrink-0 max-w-[20ch] truncate",title:e.path,children:jY(e.path)}),h.jsx("span",{className:"flex-1 min-w-0 truncate text-text-400/80",children:i}),r?h.jsx("span",{className:"shrink-0 text-[11px] text-text-400 tabular-nums",children:r}):null]}),t?h.jsx("pre",{"data-testid":"memory-callout-body",className:"mt-1 max-w-full whitespace-pre-wrap break-words text-[12px] text-text-300 bg-bg-50/60 rounded-md p-2 border border-bg-200/60 [overflow-wrap:anywhere]",children:e.content}):null]})}function OY({toolUseId:e,questions:t,onSubmit:n,onCancel:r,submittedAnswers:i}){const[s,o]=g.useState({}),[a,l]=g.useState({}),[c,u]=g.useState({}),[d,f]=g.useState(!1),[p,m]=g.useState(!1),v=i!==void 0&&Object.keys(i).length>0,y=v||p,x=!n&&!v,_=(k,C)=>{const N={labels:new Set,freeText:""};if(!v||!i)return N;const T=i[k];if(typeof T!="string")return N;const L=T.split(",").map(R=>R.trim()).filter(Boolean),P=new Set(C.map(R=>R.label)),O=new Set,I=[];for(const R of L)P.has(R)?O.add(R):I.push(R);return{labels:O,freeText:I.join(", ")}},b=g.useMemo(()=>t.every(k=>{if((c[k.question]??"").trim().length>0)return!0;if(k.multiSelect){const N=a[k.question];return!!(N&&N.size>0)}return typeof s[k.question]=="string"&&s[k.question].length>0}),[t,s,a,c]),w=async()=>{if(!b||d||y||x||!n)return;const k={};for(const C of t){const N=(c[C.question]??"").trim();if(C.multiSelect){const T=a[C.question],L=T?C.options.filter(P=>T.has(P.label)).map(P=>P.label):[];if(N.length>0&&L.push(N),L.length===0)continue;k[C.question]=L.join(", ")}else if(N.length>0)k[C.question]=N;else{const T=s[C.question];typeof T=="string"&&(k[C.question]=T)}}f(!0);try{await n(k),m(!0)}finally{f(!1)}};return h.jsxs("div",{"data-testid":"msg-line-question","data-tool-use-id":e,className:"min-w-0 max-w-full rounded-md border border-accent/40 bg-accent/5 px-3 py-2.5 text-[13px]",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 mb-2",children:[h.jsx(GB,{className:"w-4 h-4 text-accent shrink-0"}),h.jsx("span",{className:"min-w-0 font-medium text-text-100",children:"需要你的回答 / Need your answer"}),t.length>1?h.jsxs("span",{className:"ml-auto text-[12px] text-text-400","data-testid":"msg-line-question-count",children:[t.length," 个问题"]}):null]}),h.jsx("div",{className:"flex flex-col gap-3 mb-3",children:t.map((k,C)=>{const N=`q-${C}`,T=`${e}-${C}`,L=_(k.question,k.options),P=y||x,O=c[k.question]??"",I=v?L.freeText:p?(c[k.question]??"").trim():"";return h.jsxs("div",{"data-testid":"msg-line-question-item",children:[k.question?h.jsx("div",{className:"text-text-200 mb-1.5",children:k.question}):null,h.jsx("div",{className:"flex flex-col gap-1",children:k.options.map((R,D)=>{var F;const z=`${N}-${D}`,$=v?L.labels.has(R.label):k.multiSelect?!!((F=a[k.question])!=null&&F.has(R.label)):s[k.question]===R.label;return h.jsxs("label",{className:"flex min-w-0 items-start gap-2 cursor-pointer select-none py-1 px-2 rounded hover:bg-bg-100",children:[h.jsx("input",{type:k.multiSelect?"checkbox":"radio",name:T,value:R.label,checked:$,disabled:y||x,onChange:()=>{y||x||(k.multiSelect?l(j=>{const B=new Set(j[k.question]??[]);return B.has(R.label)?B.delete(R.label):B.add(R.label),{...j,[k.question]:B}}):o(j=>({...j,[k.question]:R.label})))},className:"mt-0.5","data-testid":"msg-line-question-option"}),h.jsxs("span",{className:"flex min-w-0 flex-col",children:[h.jsx("span",{className:"text-text-100 [overflow-wrap:anywhere]",children:R.label}),R.description?h.jsx("span",{className:"text-[12px] text-text-400 [overflow-wrap:anywhere]",children:R.description}):null]})]},z)})}),P?I.length>0?h.jsx("div",{className:"mt-2 rounded-lg border border-accent/15 bg-bg-100/60 px-3 py-2 text-[13px] leading-relaxed text-text-200 [overflow-wrap:anywhere]","data-testid":"msg-line-question-freetext-result",children:I}):null:h.jsx("textarea",{rows:3,value:O,placeholder:"或自行输入回答...",onChange:R=>{const D=R.target.value;u(z=>({...z,[k.question]:D}))},className:"mt-2 w-full resize-y rounded-lg border border-accent/20 bg-bg-000/60 px-3 py-2 text-[13px] leading-relaxed text-text-100 placeholder:text-text-400 outline-none transition-colors focus:border-accent/60 focus:bg-bg-000","data-testid":"msg-line-question-freetext"})]},N)})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(ni,{size:"sm",variant:"default",onClick:()=>void w(),disabled:!b||d||y||x,"data-testid":"msg-line-question-submit",children:y?"已提交 / Submitted":x?"已结束 / Ended":"提交 / Submit"}),r&&!y&&!x?h.jsx(ni,{size:"sm",variant:"ghost",onClick:()=>void r(),disabled:d,"data-testid":"msg-line-question-cancel",children:"跳过 / Skip"}):null]})]})}function BY({toolUseId:e,questions:t,historicalAnswers:n,realtimeAnswers:r,onSubmit:i,onCancel:s}){const o=r??n,a=g.useCallback(async c=>{i&&await i(e,c)},[i,e]),l=g.useCallback(async()=>{s&&await s(e)},[s,e]);return h.jsx(OY,{toolUseId:e,questions:t,onSubmit:i?a:void 0,...s?{onCancel:l}:{},submittedAnswers:o})}function zY(){const e=new Map,t=(n,r)=>`${n}::${r}`;return{register(n,r,i){e.set(t(n,r),i)},resolve(n,r){return n?e.get(t(n,r))??null:null},reset(){e.clear()}}}const pu=zY();function $R({lines:e,onPermissionRespond:t,onPermissionInterrupt:n,topSlot:r,onRewind:i,rewindableUserMessageIds:s,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v}){const y=g.useMemo(()=>O7(e),[e]);return h.jsxs("div",{"data-testid":"message-list",className:"flex w-full min-w-0 max-w-full flex-col gap-2 px-4 py-3",children:[r,y.map(x=>$Y(x,{onRewind:i,rewindableUserMessageIds:s,onPermissionRespond:t,onPermissionInterrupt:n,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v}))]})}function $Y(e,t){const{onRewind:n,rewindableUserMessageIds:r,onPermissionRespond:i,onPermissionInterrupt:s,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v}=t,y=`${e.kind}-${e.seq}`;switch(e.kind){case"session-init":return null;case"user-text":{const x=typeof e.uuid=="string"?e.uuid:void 0,_=!!(n&&x&&(!r||r.has(x)));return h.jsx(gY,{text:e.text,senderDisplayName:e.senderDisplayName,rewindTarget:_&&x&&n?{userMessageId:x,onRewind:n}:void 0},y)}case"user-meta":return h.jsx(bY,{metaKind:e.metaKind,text:e.text},y);case"meta-text":return h.jsx(wY,{text:e.text,metaSource:e.metaSource},y);case"agent-notification":return h.jsx(kY,{text:e.text,taskId:e.taskId,parentToolUseId:e.parentToolUseId},y);case"assistant-text":{const x=typeof e.uuid=="string"?e.uuid:void 0,_=x&&(o||a)?{messageUuid:x,onFork:o,onQuickAsk:a}:void 0;return h.jsx(OX,{text:$7(e.text),forkTarget:_},y)}case"assistant-thinking":return h.jsx(BX,{text:e.text},y);case"permission-inline":return h.jsx(uY,{tool:e.tool,input:e.input,onRespond:i??(()=>{}),onInterrupt:s},y);case"error":return h.jsx(dY,{message:e.message},y);case"turn-end":return null;case"merged-tool":return FY(e,y,{fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v});case"merged-agent":return h.jsx(IY,{description:e.description,input:e.input,output:e.output,error:e.error,pending:e.pending,notifications:e.notifications,toolResultExtra:e.toolResultExtra,progress:e.progress},y);case"plan-card":return h.jsx(MY,{tasks:e.tasks},y);case"todo-checklist":return h.jsx(RY,{todos:e.todos},y);case"memory-callout":return h.jsx(DY,{memories:e.memories},y);case"question-card":{const x=d===void 0||d.has(e.toolUseId);return h.jsx(BY,{toolUseId:e.toolUseId,questions:e.questions,historicalAnswers:e.submittedAnswers,realtimeAnswers:l==null?void 0:l[e.toolUseId],onSubmit:x?c:void 0,...x&&u?{onCancel:u}:{}},y)}default:return null}}function FY(e,t,n){const r=pu.resolve(e.toolKind,e.tool),i=r?r.render({input:e.input,output:e.output,error:e.error,pending:e.pending,toolUseId:e.toolUseId,...n.fileSharingScope?{fileScope:n.fileSharingScope}:{},...n.onShareFile?{onShareFile:n.onShareFile}:{},...n.onOpenInTab?{onOpenInTab:n.onOpenInTab}:{},...n.onPreviewMarkdown?{onPreviewMarkdown:n.onPreviewMarkdown}:{}}):null;return h.jsx(st.Fragment,{children:i??h.jsx(jR,{tool:e.tool,input:e.input,output:e.output,error:e.error,pending:e.pending,...n.fileSharingScope?{fileScope:n.fileSharingScope}:{},...n.onShareFile?{onShareFile:n.onShareFile}:{},...n.onOpenInTab?{onOpenInTab:n.onOpenInTab}:{},...n.onPreviewMarkdown?{onPreviewMarkdown:n.onPreviewMarkdown}:{}})},t)}function $d(e){return e==="codex"?"Codex":"Claude Code"}const HY={builtin:"Commands",global:"Global",project:"Project",plugin:"Plugin"},AS={builtin:0,global:1,project:2,plugin:3};function UY({query:e,skills:t,activeIndex:n,onActiveIndexChange:r,onSelect:i,onEmpty:s}){const o=g.useRef(null),a=g.useMemo(()=>FR(t,e),[t,e]),l=g.useMemo(()=>{const c=new Set;let u=null;for(let d=0;d<a.length;d++)a[d].source!==u&&(c.add(d),u=a[d].source);return c},[a]);return g.useEffect(()=>{a.length===0&&(s==null||s())},[a.length,s]),g.useEffect(()=>{var c;try{(c=o.current)==null||c.scrollIntoView({block:"nearest"})}catch{}},[n]),a.length===0?null:h.jsx("div",{"data-testid":"cc-skill-selector",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 max-h-[320px] overflow-y-auto rounded-2xl border border-bg-300 bg-bg-50 shadow-lg",children:a.map((c,u)=>{const d=u===n,f=l.has(u);return h.jsxs(st.Fragment,{children:[f?h.jsx("div",{className:"sticky top-0 z-10 bg-bg-50/95 backdrop-blur-sm px-4 py-2 text-[10px] font-semibold uppercase tracking-wider text-text-400/70 border-b border-bg-200/60",children:HY[c.source]}):null,h.jsxs("div",{ref:d?o:void 0,"data-testid":`cc-skill-item-${c.name}`,onMouseEnter:()=>r(u),onClick:()=>i(c),className:ne("flex items-center gap-2.5 px-4 py-2 cursor-pointer transition-colors duration-75",d?"bg-[var(--text-100-dim)]":"hover:bg-bg-100/60"),children:[h.jsxs("code",{className:"text-[12px] font-mono font-semibold text-text-100 shrink-0",children:["/",c.name]}),c.description?h.jsx("span",{className:"text-[11px] text-text-300 truncate ml-auto",children:c.description}):null]})]},`${c.source}/${c.name}`)})})}function FR(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(i=>i.name.toLowerCase().includes(n)||(i.description??"").toLowerCase().includes(n)):e.slice();return r.sort((i,s)=>(AS[i.source]??9)-(AS[s.source]??9)),r.slice(0,30)}const WY={builtin:"Built-in",global:"Global",project:"Project",policy:"Policy",plugin:"Plugin",persona:"My personas",contact:"People","remote-persona":"Remote personas"},jS={builtin:0,global:1,project:2,policy:3,plugin:4,persona:5,contact:6,"remote-persona":7};function Vh(e){switch(e.kind){case"persona":return"persona";case"contact":return"contact";case"remote-persona":return"remote-persona";case"cc-agent":return e.agent.source}}function VY(e){switch(e.kind){case"persona":return`persona/${e.persona.personaId}`;case"contact":return`contact/${e.contact.deviceId}`;case"remote-persona":return`remote/${e.deviceId}/${e.persona.personaId}`;case"cc-agent":return`${e.agent.source}/${e.agent.name}`}}function qY(e){switch(e.kind){case"persona":return`${e.persona.personaId} ${e.persona.label}`.toLowerCase();case"contact":return`${e.contact.displayName} ${e.contact.deviceId}`.toLowerCase();case"remote-persona":return`${e.persona.personaId} ${e.persona.label}`.toLowerCase();case"cc-agent":{const t=e.agent;return`${t.name} ${t.description??""} ${t.whenToUse??""}`.toLowerCase()}}}function KY(e){switch(e.kind){case"persona":return{displayName:`@persona/${e.persona.personaId}`,description:e.persona.label,testid:`cc-agent-item-persona-${e.persona.personaId}`};case"contact":return{displayName:`@${e.contact.displayName}`,description:e.contact.deviceId,testid:`cc-agent-item-contact-${e.contact.deviceId}`};case"remote-persona":return{displayName:`@persona/${e.persona.personaId}`,description:e.persona.label,testid:`cc-agent-item-remote-${e.deviceId}-${e.persona.personaId}`};case"cc-agent":return{displayName:`@${e.agent.name}`,description:e.agent.description,whenToUse:e.agent.whenToUse,plugin:e.agent.plugin,testid:`cc-agent-item-${e.agent.name}`}}}function HR(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(i=>qY(i).includes(n)):e.slice();return r.sort((i,s)=>(jS[Vh(i)]??9)-(jS[Vh(s)]??9)),r.slice(0,30)}function DS({query:e,entries:t,activeIndex:n,onActiveIndexChange:r,onSelect:i,onEmpty:s}){const o=g.useRef(null),a=g.useMemo(()=>HR(t,e),[t,e]),l=g.useMemo(()=>{const c=new Set;let u=null;for(let d=0;d<a.length;d++){const f=Vh(a[d]);f!==u&&(c.add(d),u=f)}return c},[a]);return g.useEffect(()=>{a.length===0&&(s==null||s())},[a.length,s]),g.useEffect(()=>{var c;try{(c=o.current)==null||c.scrollIntoView({block:"nearest"})}catch{}},[n]),a.length===0?null:h.jsx("div",{"data-testid":"cc-agent-selector",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 max-h-[320px] overflow-y-auto rounded-2xl border border-bg-300 bg-bg-50 shadow-lg",children:a.map((c,u)=>{const d=u===n,f=l.has(u),p=Vh(c),m=KY(c);return h.jsxs(st.Fragment,{children:[f?h.jsx("div",{"data-testid":`cc-agent-group-header-${p}`,"data-source":p,className:"sticky top-0 z-10 bg-bg-50/95 backdrop-blur-sm px-4 py-2 text-[10px] font-semibold uppercase tracking-wider text-text-400/70 border-b border-bg-200/60",children:WY[p]}):null,h.jsxs("div",{ref:d?o:void 0,"data-testid":m.testid,onMouseEnter:()=>r(u),onClick:()=>i(c),className:ne("flex items-center gap-2.5 px-4 py-2 cursor-pointer transition-colors duration-75",d?"bg-[var(--text-100-dim)]":"hover:bg-bg-100/60"),children:[h.jsx("code",{className:"text-[12px] font-mono font-semibold text-text-100 shrink-0",children:m.displayName}),m.description?h.jsx("span",{className:"text-[11px] text-text-300 truncate ml-2",children:m.description}):null,m.whenToUse?h.jsx("span",{className:"text-[10px] text-text-400/70 italic truncate ml-auto",children:m.whenToUse}):null,m.plugin?h.jsx("span",{className:"text-[10px] text-text-400/70 ml-2 shrink-0",children:m.plugin}):null]})]},VY(c))})})}function GY({attachment:e,onRemove:t,onOpenPreview:n}){const r=e.mimeType.startsWith("image/"),i=e.status==="error",s=e.status==="uploading",o=r&&e.status==="done"&&!!e.previewUrl&&!!n;return h.jsxs("div",{"data-testid":`attachment-pill-${e.id}`,className:ne("group relative flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[12px] transition-colors",i?"border-red-400/40 bg-red-500/5":"border-bg-300 bg-bg-100"),children:[r&&e.previewUrl?h.jsxs("div",{className:"relative h-7 w-7 shrink-0",children:[h.jsx("img",{src:e.previewUrl,alt:e.fileName,onClick:o?n:void 0,"data-testid":`attachment-thumb-${e.id}`,className:ne("h-7 w-7 rounded object-cover",o&&"cursor-pointer hover:opacity-80",s&&"opacity-40")}),s?h.jsx(rr,{"data-testid":`attachment-spinner-${e.id}`,className:"absolute inset-0 m-auto h-3.5 w-3.5 animate-spin text-text-200"}):null]}):h.jsx("div",{className:"relative flex h-7 w-7 items-center justify-center rounded bg-text-100/5 shrink-0",children:s?h.jsx(rr,{"data-testid":`attachment-spinner-${e.id}`,className:"h-3.5 w-3.5 animate-spin text-text-400"}):h.jsx(Ms,{className:"h-3.5 w-3.5 text-text-400"})}),h.jsx("span",{className:ne("max-w-[120px] truncate text-text-200",s&&"text-text-400"),title:e.error??e.fileName,children:e.fileName}),i?h.jsx(Rs,{className:"h-3 w-3 text-red-400 shrink-0"}):null,h.jsx("button",{type:"button",onClick:t,"data-testid":`attachment-remove-${e.id}`,className:"flex h-4 w-4 items-center justify-center rounded-full text-text-400 hover:text-text-100 hover:bg-text-100/10 transition-colors cursor-pointer shrink-0","aria-label":"remove",children:h.jsx(Rn,{className:"h-3 w-3"})})]})}function XY({attachments:e,onRemove:t,onOpenPreview:n}){return e.length===0?null:h.jsx("div",{"data-testid":"attachment-row",className:"flex flex-wrap gap-1.5 mb-2 px-1",children:e.map(r=>h.jsx(GY,{attachment:r,onRemove:()=>t(r.id),onOpenPreview:n?()=>n(r):void 0},r.id))})}class zl extends Error{constructor(t,n,r){super(n),this.code=t,this.status=r,this.name="UploadAttachmentError"}}async function YY(e){if(!e.httpBaseUrl)throw new zl("TUNNEL_NOT_READY","daemon httpBaseUrl unavailable");if(!e.httpToken)throw new zl("NO_AUTH","daemon httpToken unavailable");const t=new URLSearchParams({sessionId:e.sessionId,fileName:e.file.name,mimeType:e.file.type||"application/octet-stream"}),n=`${e.httpBaseUrl.replace(/\/$/,"")}/attachments/upload?${t.toString()}`;let r;try{r=await fetch(n,{method:"POST",headers:{Authorization:`Bearer ${e.httpToken}`,"Content-Type":e.file.type||"application/octet-stream"},body:e.file})}catch(i){throw new zl("NETWORK_ERROR",i.message)}if(!r.ok){let i="UPLOAD_FAILED",s=`HTTP ${r.status}`;try{const o=await r.json();o.code&&(i=o.code),o.message&&(s=o.message)}catch{}throw new zl(i,s,r.status)}return await r.json()}const LS=25*1024*1024,ZY="image/*,.txt,.md,.markdown,.csv,.json,.log,.yaml,.yml,.html,.xml,.pdf",QY=["image/","text/"],JY=new Set(["application/json","application/xml","application/x-yaml","application/yaml","application/pdf"]),eZ=new Set(["txt","md","markdown","csv","json","log","yaml","yml","html","xml","pdf"]);function tZ(e){var r;const t=(e.type||"").toLowerCase();if(t&&QY.some(i=>t.startsWith(i))||t&&JY.has(t))return!0;const n=((r=e.name.split(".").pop())==null?void 0:r.toLowerCase())??"";return n.length>0&&eZ.has(n)}let nZ=0;const rZ=()=>`att-${++nZ}-${Date.now()}`;function iZ(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(typeof r.result=="string"?r.result:""),r.onerror=()=>n(r.error??new Error("read failed")),r.readAsDataURL(e)})}function sZ(e){const[t,n]=g.useState(e.initial??[]),r=g.useCallback(async o=>{const a=Array.from(o);if(a.length===0)return;const l=[],c=[],u=[];for(const d of a){const f={id:rZ(),fileName:d.name,mimeType:d.type||"application/octet-stream"};if(!tZ(d)){c.push({...f,url:null,status:"error",error:"不支持的文件类型"});continue}if(d.size>LS){c.push({...f,url:null,status:"error",error:`超过 ${Math.round(LS/1024/1024)}MB 上限`});continue}if(e.sessionId==null){u.push({id:f.id,file:d,mimeType:f.mimeType}),c.push({...f,url:null,status:"uploading"});continue}const p=f.mimeType.startsWith("image/")?URL.createObjectURL(d):void 0;c.push({...f,url:null,status:"uploading",...p?{previewUrl:p}:{}}),l.push({id:f.id,file:d})}n(d=>[...d,...c]);for(const d of u)try{const f=await iZ(d.file);n(p=>p.map(m=>m.id===d.id?{...m,url:f,status:"done",...d.mimeType.startsWith("image/")?{previewUrl:f}:{}}:m))}catch(f){n(p=>p.map(m=>m.id===d.id?{...m,status:"error",error:f.message??"read failed"}:m))}l.length!==0&&await Promise.all(l.map(async d=>{try{const f=await YY({httpBaseUrl:e.httpBaseUrl,httpToken:e.httpToken,sessionId:e.sessionId,file:d.file});n(p=>p.map(m=>m.id===d.id?{...m,url:f.url,status:"done"}:m))}catch(f){const p=f instanceof zl?f.code:"UPLOAD_FAILED",m=f.message??"upload failed";n(v=>v.map(y=>y.id===d.id?{...y,status:"error",error:`${p}: ${m}`}:y))}}))},[e.sessionId,e.httpBaseUrl,e.httpToken]),i=g.useCallback(o=>{n(a=>a.filter(l=>l.id!==o))},[]),s=g.useCallback(()=>{n([])},[]);return{attachments:t,setAttachments:n,addFiles:r,removeAttachment:i,clearAttachments:s}}const Zv=new Map,oZ=[];function OS(e){if(e)return Zv.get(e)}function BS(e,t){e&&(t.draft.length===0&&t.attachments.length===0?Zv.delete(e):Zv.set(e,t))}function aZ(e,t){return e.replace(/(^|\s)\/(\S+)/g,(n,r,i)=>{const s=t.find(o=>o.name===i&&o.path);return s!=null&&s.path?`${r}[skill:${i}:${s.path}]`:n})}function lZ({api:e,cwd:t,sessionKey:n,onSend:r,disabled:i,onNewSession:s,onClearSession:o,tool:a,spawnableContacts:l=oZ,ensureRemotePersonas:c,remotePersonasByDeviceId:u}){const d=OS(n),[f,p]=g.useState((d==null?void 0:d.draft)??""),[m,v]=g.useState(!1),y=g.useRef(null),x=g.useRef(!1),_=g.useCallback(()=>{x.current=!0},[]),b=g.useCallback(()=>{x.current=!1},[]),w=Af(),{attachments:k,setAttachments:C,addFiles:N,removeAttachment:T,clearAttachments:L}=sZ({httpBaseUrl:w.httpBaseUrl,httpToken:w.httpToken,sessionId:n,initial:(d==null?void 0:d.attachments)??[]}),[P,O]=g.useState([]),[I,R]=g.useState(!1),[D,z]=g.useState(0),[$,F]=g.useState(!1),[j,B]=g.useState([]),[E,H]=g.useState(!1),[q,M]=g.useState(0),[re,oe]=g.useState(!1),[V,pe]=g.useState([]),[Oe,ie]=g.useState(!1),[Ae,Fe]=g.useState(null),[We,ge]=g.useState(!1),qe=g.useRef(null),Gt=g.useMemo(()=>{const ue=[];return s&&ue.push({name:"new",source:"builtin",description:"在当前目录下新建会话"}),o&&n&&ue.push({name:"clear",source:"builtin",description:"清除当前会话"}),ue},[s,o,n]),wt=g.useMemo(()=>[...Gt,...P],[Gt,P]),Rt=g.useMemo(()=>{const ue=f.match(/^\/(\S*)$/);return ue?ue[1]:null},[f]),ln=Rt!==null&&!$,Bt=g.useMemo(()=>Rt!==null?FR(wt,Rt):[],[wt,Rt]),at=g.useMemo(()=>{const ue=f.match(/^@(\S*)$/);return ue?ue[1]:null},[f]),Ue=at!==null&&!re,nt=g.useMemo(()=>Ae?((u==null?void 0:u.get(Ae.deviceId))??[]).map(Te=>({kind:"remote-persona",persona:Te,deviceId:Ae.deviceId})):[...j.map(ue=>({kind:"cc-agent",agent:ue})),...V.map(ue=>({kind:"persona",persona:ue})),...l.map(ue=>({kind:"contact",contact:ue}))],[Ae,u,j,V,l]),mt=g.useMemo(()=>at!==null?HR(nt,at):[],[nt,at]),Xt=g.useRef(f);g.useEffect(()=>{f!==Xt.current&&(F(!1),oe(!1),Xt.current=f)},[f]);const pn=g.useCallback(()=>{F(!0)},[]),U=g.useCallback(()=>{oe(!0)},[]),Q=g.useRef(f),ve=g.useRef(k);g.useEffect(()=>{Q.current=f},[f]),g.useEffect(()=>{ve.current=k},[k]);const Se=g.useRef(n);g.useEffect(()=>{const ue=Se.current;if(ue===n)return;BS(ue,{draft:Q.current,attachments:ve.current});const Te=OS(n);p((Te==null?void 0:Te.draft)??""),C((Te==null?void 0:Te.attachments)??[]),z(0),M(0),F(!1),oe(!1),Fe(null),qe.current=null,ge(!1),queueMicrotask(()=>{Te!=null&&Te.draft?UR(y.current):Vo(y.current)}),Se.current=n},[n,C]),g.useEffect(()=>()=>{BS(Se.current,{draft:Q.current,attachments:ve.current})},[]),g.useEffect(()=>{z(0)},[Rt]),g.useEffect(()=>{M(0)},[at]),g.useEffect(()=>{at===null&&Ae&&(Fe(null),qe.current=null,ge(!1))},[at,Ae]),g.useEffect(()=>{if(!ln||I)return;if(!e){R(!0);return}let ue=!1;return(async()=>{try{const Te=await e.skillsList(t,a);ue||(O(Te.skills??[]),R(!0))}catch{ue||R(!0)}})(),()=>{ue=!0}},[ln,I,e,t,a]),g.useEffect(()=>{if(!Ue||E)return;if(!e){H(!0);return}let ue=!1;return(async()=>{try{const Te=await e.agentsList(t,a);ue||(B(Te.agents??[]),H(!0))}catch{ue||H(!0)}})(),()=>{ue=!0}},[Ue,E,e,t,a]),g.useEffect(()=>{if(!Ue||Oe)return;if(!e){ie(!0);return}let ue=!1;return(async()=>{try{const Te=await e.personaList();ue||(pe((Te.personas??[]).map(Je=>({personaId:Je.personaId,label:Je.label,iconKey:Je.iconKey}))),ie(!0))}catch{ue||ie(!0)}})(),()=>{ue=!0}},[Ue,Oe,e]);const J=g.useCallback(ue=>{switch(ue.kind){case"persona":p(`@persona/${ue.persona.personaId} `);break;case"cc-agent":p(`@"${ue.agent.name} (agent)" `);break;case"contact":{const Te=ue.contact.deviceId;Fe({deviceId:Te,displayName:ue.contact.displayName}),qe.current=Te,ge(!0),Promise.resolve(c==null?void 0:c(Te)).finally(()=>{qe.current===Te&&ge(!1)}),p("@"),oe(!1),setTimeout(()=>{var Je;return(Je=y.current)==null?void 0:Je.focus()},0);return}case"remote-persona":p(`@persona/${ue.persona.personaId}@${ue.deviceId} `),Fe(null);break}oe(!1),setTimeout(()=>{var Te;return(Te=y.current)==null?void 0:Te.focus()},0)},[c]),Xe=g.useCallback(()=>{Fe(null),qe.current=null,ge(!1),p("@"),setTimeout(()=>{var ue;return(ue=y.current)==null?void 0:ue.focus()},0)},[]),Yt=g.useCallback(ue=>{if(ue.source==="builtin"&&ue.name==="new"&&s){p(""),L(),Vo(y.current),s(t);return}if(ue.source==="builtin"&&ue.name==="clear"&&o){p(""),L(),Vo(y.current),o();return}p(`/${ue.name} `),setTimeout(()=>{var Te;return(Te=y.current)==null?void 0:Te.focus()},0)},[s,t,L,o]),Zt=g.useCallback(async()=>{const ue=f.trim(),Te=k.filter(Je=>Je.status==="done");if(!(!ue&&Te.length===0)&&!(m||i)){if(ue==="/new"&&s){v(!0);try{await s(t),p(""),L(),Vo(y.current)}finally{v(!1)}return}if(ue==="/clear"&&o){v(!0);try{await o(),p(""),L(),Vo(y.current)}finally{v(!1)}return}v(!0);try{const Je=a==="codex"?aZ(ue,P):ue,Dn=fY(Je,k);await r(Dn),p(""),L(),Vo(y.current)}finally{v(!1)}}},[f,k,m,i,r,s,t,L,o,a,P]);return{draft:f,setDraft:p,sending:m,textareaRef:y,isComposingRef:x,onCompositionStart:_,onCompositionEnd:b,attachments:k,addFiles:N,removeAttachment:T,skillSelectorVisible:ln,filteredSkills:Bt,slashQuery:Rt??"",activeSkillIdx:D,setActiveSkillIdx:z,selectSkill:Yt,dismissSkillSelector:pn,agentSelectorVisible:Ue,filteredAgents:mt,mentionQuery:at,activeAgentIdx:q,setActiveAgentIdx:M,selectAgent:J,dismissAgentSelector:U,drilldown:Ae,drilldownLoading:We,exitDrilldown:Xe,doSend:Zt}}const cZ=120;function UR(e){e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,cZ)}px`)}function Vo(e){e&&(e.style.height="auto")}const uZ={spawnableContacts:[],ensureRemotePersonas:()=>Promise.resolve(),remotePersonasByDeviceId:new Map},dZ=g.createContext(uZ);function hZ(){return g.useContext(dZ)}function fZ({url:e,fileName:t,onClose:n}){const[r,i]=g.useState(!1);g.useEffect(()=>{const o=a=>{a.key==="Escape"&&n()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[n]);const s=async()=>{try{const a=await(await fetch(e)).blob();await navigator.clipboard.write([new ClipboardItem({[a.type]:a})]),i(!0),setTimeout(()=>i(!1),2e3)}catch{zS(e,t)}};return h.jsx("div",{"data-testid":"image-lightbox",className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60",onClick:n,role:"dialog","aria-modal":"true",children:h.jsxs("div",{className:"relative",onClick:o=>o.stopPropagation(),children:[h.jsx("img",{src:e,alt:t,className:"max-h-[90vh] max-w-[92vw] rounded-lg object-contain shadow-2xl"}),h.jsxs("div",{className:"absolute right-2 top-2 flex items-center gap-1.5",children:[h.jsxs("button",{type:"button",onClick:s,"data-testid":"image-lightbox-copy",className:"flex cursor-pointer items-center gap-1 rounded-full border border-bg-300 bg-bg-50/95 px-2 py-0.5 text-[11px] font-medium text-text-200 shadow transition-colors hover:bg-bg-100",children:[h.jsx(su,{className:"h-3 w-3"}),r?"Copied":"Copy"]}),h.jsxs("button",{type:"button",onClick:()=>zS(e,t),"data-testid":"image-lightbox-save",className:"flex cursor-pointer items-center gap-1 rounded-full border border-bg-300 bg-bg-50/95 px-2 py-0.5 text-[11px] font-medium text-text-200 shadow transition-colors hover:bg-bg-100",children:[h.jsx(i6,{className:"h-3.5 w-3.5"}),"Save"]}),h.jsx("button",{type:"button",onClick:n,"data-testid":"image-lightbox-close","aria-label":"close",className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded-full border border-bg-300 bg-bg-50/95 text-text-300 transition-colors hover:bg-bg-100 hover:text-text-100",children:h.jsx(Rn,{className:"h-3 w-3"})})]})]})})}function zS(e,t){const n=document.createElement("a");n.href=e,n.download=t||"image",n.click()}function pZ({meta:e,api:t,cwd:n,tool:r,onSend:i,sessionKey:s,disabled:o=!1,placeholder:a,className:l,awaitingUser:c=!1,onAbort:u,onNewSession:d,onClearSession:f}){const p=(e==null?void 0:e.streamInProgress)??!1,m=g.useRef(null),v=hZ(),y=lZ({...t?{api:t}:{},cwd:n,...r?{tool:r}:{},sessionKey:s,onSend:i,disabled:o,...d?{onNewSession:d}:{},...f?{onClearSession:f}:{},spawnableContacts:v.spawnableContacts,ensureRemotePersonas:v.ensureRemotePersonas,remotePersonasByDeviceId:v.remotePersonasByDeviceId}),{draft:x,setDraft:_,sending:b,textareaRef:w,attachments:k,addFiles:C,removeAttachment:N,skillSelectorVisible:T,filteredSkills:L,slashQuery:P,activeSkillIdx:O,setActiveSkillIdx:I,selectSkill:R,dismissSkillSelector:D,agentSelectorVisible:z,filteredAgents:$,mentionQuery:F,activeAgentIdx:j,setActiveAgentIdx:B,selectAgent:E,dismissAgentSelector:H,drilldown:q,drilldownLoading:M,exitDrilldown:re,doSend:oe}=y,V=!!t,pe=b||o||p,ie=(x.trim().length>0||k.some(J=>J.status==="done"))&&!o&&!b&&!c,Ae=a??(c?"Answer the question above first...":pe?"Queue a message...":`Message ${$d(r)}...`),Fe=g.useRef(!1),We=g.useCallback(()=>{Fe.current=!0},[]),ge=g.useCallback(()=>{Fe.current=!1},[]),qe=g.useCallback(J=>{if(T&&L.length>0){if(J.key==="ArrowDown")return J.preventDefault(),I(O>=L.length-1?0:O+1),!0;if(J.key==="ArrowUp")return J.preventDefault(),I(O<=0?L.length-1:O-1),!0;if(J.key==="Tab"||J.key==="Enter"&&!J.shiftKey){J.preventDefault();const Xe=L[O];return Xe&&R(Xe),!0}if(J.key==="Escape")return J.preventDefault(),D(),!0}return!1},[T,L,O,I,R,D]),Gt=g.useCallback(J=>{if(z&&$.length>0){if(J.key==="ArrowDown")return J.preventDefault(),B(j>=$.length-1?0:j+1),!0;if(J.key==="ArrowUp")return J.preventDefault(),B(j<=0?$.length-1:j-1),!0;if(J.key==="Tab"||J.key==="Enter"&&!J.shiftKey){J.preventDefault();const Xe=$[j];return Xe&&E(Xe),!0}if(J.key==="Escape")return J.preventDefault(),q?re():H(),!0}return!1},[z,$,j,B,E,H,q,re]),wt=g.useCallback(J=>{const Xe=J.nativeEvent;J.key==="Enter"&&oI({compositionActive:Fe.current,nativeIsComposing:Xe.isComposing,keyCode:Xe.keyCode})||qe(J)||Gt(J)||aI({key:J.key,shiftKey:J.shiftKey,compositionActive:Fe.current,nativeIsComposing:Xe.isComposing,keyCode:Xe.keyCode})&&(J.preventDefault(),ie&&oe())},[qe,Gt,ie,oe]),Rt=g.useCallback(J=>{_(J.target.value),UR(J.target)},[_]),ln=g.useCallback(J=>{J.target.files&&C(J.target.files),J.target.value=""},[C]),Bt=g.useCallback(J=>{if(!V)return;const Xe=Array.from(J.clipboardData.items).map(Yt=>Yt.getAsFile()).filter(Yt=>!!(Yt&&Yt.type.startsWith("image/")));Xe.length!==0&&(J.preventDefault(),C(Xe))},[C,V]),[at,Ue]=g.useState(null),nt=g.useCallback(J=>{J.previewUrl&&Ue({url:J.previewUrl,name:J.fileName})},[]),[mt,Xt]=g.useState(!1),pn=g.useCallback(J=>{V&&(J.preventDefault(),Xt(!0))},[V]),U=g.useCallback(()=>Xt(!1),[]),Q=g.useCallback(J=>{V&&(J.preventDefault(),Xt(!1),J.dataTransfer.files.length>0&&C(J.dataTransfer.files))},[C,V]),ve=p&&!c&&typeof u=="function",Se=o||c;return h.jsxs("div",{"data-testid":"chat-input",className:ne("shrink-0 border-t border-bg-300/20 px-4 py-3",l),onDragOver:pn,onDragLeave:U,onDrop:Q,children:[h.jsxs("div",{className:"max-w-3xl mx-auto relative",children:[V?h.jsx("input",{ref:m,type:"file",multiple:!0,accept:ZY,hidden:!0,onChange:ln,"data-testid":"chat-input-file"}):null,h.jsxs("div",{"data-testid":"chat-input-bare",className:ne("flex flex-col gap-2"),children:[c||b||p?h.jsxs("div",{"data-testid":"chat-input-status-bar",className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsxs("div",{className:"flex gap-1",children:[h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"0ms"}}),h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"150ms"}}),h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"300ms"}})]}),h.jsx("span",{children:c?"Waiting for your answer":`${r==="codex"?"Codex":"Claude"} is working`})]}):null,T?h.jsx(UY,{query:P,skills:L,activeIndex:O,onActiveIndexChange:I,onSelect:R}):null,z?q?!v.remotePersonasByDeviceId.has(q.deviceId)&&M?h.jsx("div",{"data-testid":"cc-agent-remote-loading",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 rounded-2xl border border-bg-300 bg-bg-50 px-4 py-3 text-[12px] text-text-300 shadow-lg",children:`正在加载 @${q.displayName} 的 persona…`}):$.length>0?h.jsx(DS,{query:F??"",entries:$,activeIndex:j,onActiveIndexChange:B,onSelect:E}):h.jsx("div",{"data-testid":"cc-agent-remote-empty",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 rounded-2xl border border-bg-300 bg-bg-50 px-4 py-3 text-[12px] text-text-300 shadow-lg",children:`@${q.displayName} 暂无可派活的 persona(可能离线或未公开)`}):h.jsx(DS,{query:F??"",entries:$,activeIndex:j,onActiveIndexChange:B,onSelect:E}):null,k.length>0?h.jsx(XY,{attachments:k,onRemove:N,onOpenPreview:nt}):null,h.jsxs("div",{"data-testid":"bare-chat-input-frame",className:ne("flex items-end gap-2 rounded-xl border border-bg-300 bg-bg-50 px-3 py-2 transition-colors duration-200",Se?"opacity-60":null,mt?"border-accent/60 bg-accent/5":null),children:[V?h.jsx("button",{type:"button",onClick:()=>{var J;return(J=m.current)==null?void 0:J.click()},disabled:pe,"data-testid":"chat-input-attach","aria-label":"attach files",className:ne("flex h-8 w-8 shrink-0 self-end items-center justify-center rounded-md transition-colors",pe?"cursor-default text-text-400/50":"cursor-pointer text-text-400 hover:bg-text-100/5 hover:text-text-200"),children:h.jsx(j6,{className:"h-4 w-4"})}):null,h.jsx("textarea",{ref:w,"data-testid":"chat-input-textarea",value:x,onChange:Rt,onKeyDown:wt,onCompositionStart:We,onCompositionEnd:ge,onPaste:Bt,placeholder:Ae,disabled:Se,readOnly:Se,rows:1,className:"flex-1 resize-none bg-transparent border-0 outline-none text-[14px] text-text-100 placeholder:text-text-400 leading-relaxed py-1 min-h-[22px] max-h-[120px] overflow-y-auto disabled:cursor-not-allowed"}),h.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 pb-0.5",children:[ve?h.jsx("button",{type:"button",onClick:u,"data-testid":"chat-input-abort","aria-label":"interrupt",title:"中断当前轮次(不杀进程)",className:"h-8 w-8 rounded-full flex items-center justify-center border border-text-400/40 text-text-400 hover:bg-text-100/5 hover:text-text-100 transition-colors cursor-pointer",children:h.jsx(HN,{className:"w-3.5 h-3.5",strokeWidth:2.5})}):null,h.jsx("button",{type:"button",onClick:()=>{ie&&oe()},disabled:!ie,"data-testid":"chat-input-send","aria-label":"send",className:ne("h-8 w-8 rounded-full flex items-center justify-center transition-colors",ie?"bg-accent text-white hover:bg-accent-hover cursor-pointer shadow-sm":"bg-[var(--text-400-dim)] text-[var(--text-400-dim-fg)] cursor-default"),children:h.jsx(PB,{className:"w-4 h-4",strokeWidth:2.5})})]})]})]})]}),at?h.jsx(fZ,{url:at.url,fileName:at.name,onClose:()=>Ue(null)}):null]})}function mZ(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function gZ({meta:e,tool:t,connState:n,onOpenConfig:r,models:i,liveGitBranch:s,liveWorktreeRoot:o,onForceStop:a,cronActiveCount:l,onCronClick:c,onOpenFiles:u,onTogglePin:d,isHolded:f=!1,onToggleHold:p,personaName:m,onOpenPersona:v,className:y}){const x=e.procAlive??!1,_=e.streamInProgress??!1,b=e.permissionMode,w=b&&b!=="default"?b:null,k=w==="bypassPermissions"?"YOLO":w==="plan"?"Plan":null,C=e.model??"",N=vZ(i,C),T=e.contextPct??null,L=T==null?"":T>=80?"text-red-400":T>=50?"text-amber-400":"text-text-500",P=s!==void 0?s:e.gitBranch??null,O=o??e.cwd??"",R=!!e.sessionLabel&&e.sessionLabel!==e.sessionId?e.sessionLabel:mZ(O),D=O,z=e.pinnedAt!=null;return h.jsxs("div",{"data-testid":"chat-header",className:ne("relative flex flex-col justify-center shrink-0 px-4 pr-14 py-2 gap-1",y),children:[h.jsxs("div",{className:"flex items-center min-w-0 gap-2 text-[13px]",children:[d?h.jsx("button",{type:"button",onClick:()=>d(!z),"data-testid":"chat-header-pin-toggle","data-pinned":z?"true":"false","aria-pressed":z,title:z?"Unpin session":"Pin session",className:ne("shrink-0 inline-flex items-center justify-center h-5 w-5 rounded-md cursor-pointer transition-colors",z?"text-amber-400 hover:bg-amber-500/10":"text-text-500 hover:text-text-200 hover:bg-text-100/5"),children:h.jsx(WN,{className:ne("w-3.5 h-3.5",z&&"fill-current")})}):null,p?h.jsx("button",{type:"button",onClick:()=>p(!f),"data-testid":"chat-header-hold-toggle","data-holded":f?"true":"false","aria-pressed":f,title:f?"Release hold":"Hold session",className:ne("shrink-0 inline-flex items-center justify-center h-5 w-5 rounded-md cursor-pointer transition-colors",f?"text-amber-400 hover:bg-amber-500/10":"text-text-500 hover:text-text-200 hover:bg-text-100/5"),children:h.jsx(BB,{className:ne("w-3.5 h-3.5",f&&"fill-current")})}):null,h.jsx("span",{className:"font-semibold text-text-100 truncate","data-testid":"chat-header-worktree",title:D,children:R}),P?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500 shrink-0",children:":"}),h.jsx("span",{className:"font-mono text-text-300 truncate","data-testid":"chat-header-git",title:P,children:P})]}):null]}),h.jsxs("div",{className:"flex items-center min-w-0 gap-2 text-[11px]",children:[k?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",onClick:()=>r==null?void 0:r("desktop"),"data-testid":"chat-header-mode-chip",className:ne("hidden md:inline-flex shrink-0 px-2 py-0.5 rounded-md font-semibold cursor-pointer transition-colors",w==="bypassPermissions"?"bg-red-500/15 text-red-400 hover:bg-red-500/25":"bg-blue-500/15 text-blue-400 hover:bg-blue-500/25"),children:k}),h.jsx("button",{type:"button",onClick:()=>r==null?void 0:r("mobile"),"aria-hidden":"true",tabIndex:-1,className:ne("inline-flex md:hidden shrink-0 px-2 py-0.5 rounded-md font-semibold cursor-pointer transition-colors",w==="bypassPermissions"?"bg-red-500/15 text-red-400 hover:bg-red-500/25":"bg-blue-500/15 text-blue-400 hover:bg-blue-500/25"),children:k})]}):null,C||i?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",onClick:()=>r==null?void 0:r("desktop"),"data-testid":"chat-header-model-chip",className:"hidden md:inline-flex shrink-0 font-mono text-text-400 cursor-pointer hover:text-text-200 transition-colors",children:N}),h.jsx("button",{type:"button",onClick:()=>r==null?void 0:r("mobile"),"aria-hidden":"true",tabIndex:-1,className:"inline-flex md:hidden shrink-0 font-mono text-text-400 cursor-pointer hover:text-text-200 transition-colors",children:N})]}):null,T!=null?h.jsxs("span",{className:ne("shrink-0 font-mono",L),"data-testid":"chat-header-ctx",children:["ctx:",T,"%"]}):null,h.jsxs("span",{"data-testid":"chat-header-proc-status",className:"inline-flex items-center gap-1 text-text-500 shrink-0",title:_?`${$d(t)} 正在跑当前 turn`:x?`${$d(t)} 进程仍活,等下一轮输入`:`${$d(t)} 进程未运行(发送消息会自动启动)`,children:[h.jsx("span",{className:ne("w-1.5 h-1.5 rounded-full",_?"bg-green-500":"bg-text-400/50")}),h.jsx("span",{children:_?"running":"idle"})]}),x&&a?h.jsxs("button",{type:"button",onClick:a,"data-testid":"chat-header-force-stop",title:t==="codex"?"强制停止 Codex 进程":"强制停止 Claude Code 进程(会丢失 initialize / 预热缓存)",className:"shrink-0 inline-flex items-center gap-1 h-5 px-2 rounded-md text-text-400 hover:bg-red-500/10 hover:text-red-400 transition-colors cursor-pointer",children:[h.jsx(M6,{className:"w-3 h-3"}),h.jsx("span",{children:"Stop"})]}):null,m&&v||u||l&&l>0&&c?h.jsx("span",{className:"text-text-500 shrink-0","aria-hidden":"true",children:"·"}):null,m&&v?h.jsxs("button",{type:"button",onClick:v,"data-testid":"chat-header-persona",title:m,className:"shrink-0 inline-flex items-center gap-1 h-5 px-2 rounded-md text-text-300 hover:bg-bg-200 hover:text-text-100 transition-colors cursor-pointer",children:[h.jsx(Yx,{className:"w-3 h-3"}),h.jsx("span",{className:"truncate max-w-[80px] md:max-w-[120px]",children:m})]}):null,u?h.jsxs("button",{type:"button",onClick:u,"data-testid":"chat-header-files",title:"Edited Files",className:"shrink-0 inline-flex items-center gap-1 h-5 px-2 rounded-md text-text-300 hover:bg-bg-200 hover:text-text-100 transition-colors cursor-pointer",children:[h.jsx(d6,{className:"w-3 h-3"}),h.jsx("span",{className:"hidden md:inline",children:"Edited Files"})]}):null,l&&l>0&&c?h.jsxs("button",{type:"button","data-testid":"chat-header-cron-button",onClick:c,"aria-label":"Cron tasks",title:`${l} active cron task${l===1?"":"s"}`,className:"shrink-0 inline-flex items-center gap-1 h-5 px-2 rounded-md text-text-400 hover:bg-accent-dim hover:text-accent transition-colors cursor-pointer",children:[h.jsx(ZB,{className:"w-3 h-3"}),h.jsx("span",{"data-testid":"chat-header-cron-badge",className:"font-mono",children:l})]}):null]}),r?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button","aria-label":"Session settings","data-testid":"chat-header-settings",onClick:()=>r("desktop"),title:"Session settings",className:"hidden md:flex absolute right-4 top-3 z-10 h-7 w-7 items-center justify-center rounded-md bg-transparent text-text-300 transition-colors duration-150 hover:bg-bg-200 hover:text-text-100 cursor-pointer outline-none",children:h.jsx(kv,{className:"w-4 h-4"})}),h.jsx("button",{type:"button","aria-label":"Session settings","data-testid":"chat-header-settings-mobile",onClick:()=>r("mobile"),title:"Session settings",className:"flex md:hidden absolute right-4 top-3 z-10 h-7 w-7 items-center justify-center rounded-md bg-transparent text-text-300 transition-colors duration-150 hover:bg-bg-200 hover:text-text-100 cursor-pointer outline-none",children:h.jsx(kv,{className:"w-4 h-4"})})]}):null]})}function vZ(e,t){if(!t)return"default";const n=t.toLowerCase(),r=[["opus","Opus"],["sonnet","Sonnet"],["haiku","Haiku"]];for(const[a,l]of r){if(!n.includes(a))continue;const c=n.match(new RegExp(`${a}-(\\d+)-(\\d+)`));return c?`${l} ${c[1]}.${c[2]}`:l}const i=e??[],s=i.find(a=>a.id===t);if(s)return s.label;const o=i.find(a=>a.id&&t.toLowerCase().includes(a.id.toLowerCase()));return o?o.label:t}function xZ(e){return e==="TodoWrite"}function _Z(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 yZ(e,t,n){var s;const r=[],i=new Map;for(let o=0;o<e.length;o++){const a=e[o],l=typeof a.seq=="number"?a.seq:o;switch(a.kind){case"session_init":r.push({kind:"session-init",seq:l,toolSessionId:a.toolSessionId});break;case"text":$S(r,l,"assistant-text",a.text,a.partialId,a.uuid);break;case"thinking":$S(r,l,"assistant-thinking",a.text,a.partialId);break;case"user_text":{a.meta==="task-notification"?r.push({kind:"agent-notification",seq:l,text:a.text,taskId:a.taskId,parentToolUseId:a.parentToolUseId}):a.meta?r.push({kind:"user-meta",seq:l,metaKind:a.meta,text:a.text}):r.push({kind:"user-text",seq:l,text:a.text,uuid:a.uuid,senderDisplayName:(s=a.sender)==null?void 0:s.displayName});break}case"tool_call":WR(r,l,a.toolUseId,a.tool,a.input,a.toolKind);break;case"tool_result":{const c=i.get(a.toolUseId);if(c!==void 0){if(a.askQuestionAnswers){const d=r[c];d.submittedAnswers=a.askQuestionAnswers}i.delete(a.toolUseId);break}const u={kind:"tool-result",seq:l,toolUseId:a.toolUseId,output:a.output,error:a.error};a.toolResultExtra&&(u.toolResultExtra=a.toolResultExtra),r.push(u);break}case"attachment_memories":r.push({kind:"memory-callout",seq:l,memories:a.memories});break;case"permission_request":{if(!t||a.requestId!==t)break;r.push({kind:"permission-inline",seq:l,requestId:a.requestId,tool:a.tool,input:a.input});break}case"ask_user_question":i.set(a.toolUseId,r.length),r.push({kind:"question-card",seq:l,toolUseId:a.toolUseId,questions:a.questions});break;case"turn_end":r.push({kind:"turn-end",seq:l});break;case"subagent_progress":{const c={kind:"agent-progress",seq:l,toolUseId:a.toolUseId,agentId:a.agentId,status:a.status};a.description&&(c.description=a.description),a.lastToolName&&(c.lastToolName=a.lastToolName),a.prompt&&(c.prompt=a.prompt),a.stats&&(c.stats=a.stats),r.push(c);break}case"error":r.push({kind:"error",seq:l,message:a.message});break}}return r}function WR(e,t,n,r,i,s){if(xZ(r)){const o=_Z(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(A7(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 $S(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 bZ="AskUserQuestion";function VR(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=(o=PO.exec(a.text??""))==null?void 0:o[1];r.push({kind:"user-text",seq:l,text:a.text??"",uuid:a.uuid,...u?{senderDisplayName:u}:{}})}break;case"assistant-text":r.push({kind:"assistant-text",seq:l,text:a.text??"",uuid:a.uuid});break;case"tool_call":{if(a.tool===bZ){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}WR(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}}return r}function wZ({api:e,cwd:t,toolSessionId:n}){const r=BR(),i=(r==null?void 0:r.state.agentId)??null,s=r==null?void 0:r.state.agentType,[o,a]=g.useState([]),[l,c]=g.useState(!1),[u,d]=g.useState(null);g.useEffect(()=>{if(!i)return;let p=!1;return c(!0),d(null),a([]),e.historySubagentRead({cwd:t,toolSessionId:n,subagentId:i}).then(m=>{p||a(m.messages??[])}).catch(m=>{p||d(m instanceof Error?m.message:String(m))}).finally(()=>{p||c(!1)}),()=>{p=!0}},[i,t,n,e]);const f=g.useMemo(()=>o.length>0?VR(o,0,"claude"):[],[o]);return!r||!i?null:h.jsxs("div",{"data-testid":"subagent-drawer","data-agent-id":i,className:ne("fixed inset-y-0 right-0 z-50 w-[min(560px,92vw)]","flex flex-col border-l border-bg-200/60 bg-bg-50 shadow-xl"),style:{paddingTop:"env(safe-area-inset-top)"},children:[h.jsxs("div",{className:"flex flex-col gap-0.5 px-3 py-2 border-b border-bg-200/60",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s?h.jsx("span",{className:"inline-flex items-center rounded-sm bg-violet-500/10 px-1.5 py-0.5 text-[11px] text-violet-400 font-medium",children:s}):null,h.jsx("span",{className:"font-mono text-[11px] text-text-400 truncate",title:i,children:i})]}),h.jsx("button",{type:"button","aria-label":"关闭",onClick:()=>r.close(),className:"p-1 rounded hover:bg-bg-200/50 text-text-400 hover:text-text-200",children:h.jsx(Rn,{className:"w-4 h-4"})})]}),!l&&!u&&o.length>0?h.jsxs("div",{className:"text-[11px] text-text-400",children:[o.length," 条消息 · 首条为主会话派发的任务指令"]}):null]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden px-3 py-2",children:l?h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsx(rr,{className:"w-3.5 h-3.5 animate-spin"}),h.jsx("span",{children:"加载中…"})]}):u?h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-error",children:[h.jsx(Rs,{className:"w-3.5 h-3.5"}),h.jsx("span",{children:u})]}):f.length===0?h.jsx("div",{className:"text-[12px] text-text-400 italic",children:"无消息"}):h.jsx($R,{lines:f})})]})}function FS(e,t){let n=0;for(const r of e.lines)r.startsWith(t)&&n++;return n}function SZ(e,t){const n=e.findIndex(c=>c.kind==="user-text"&&c.uuid===t);if(n<0)return{userMessageId:t,files:[],totalInsertions:0,totalDeletions:0,anchorFound:!1};let r=e.length;for(let c=n+1;c<e.length;c++)if(e[c].kind==="user-text"){r=c;break}const i=[],s=new Map;for(let c=n+1;c<r;c++){const u=e[c];if(u.kind!=="tool-result")continue;const d=u.toolResultExtra;if(!(d!=null&&d.filePath)||!d.structuredPatch||d.structuredPatch.length===0)continue;const f=d.filePath;let p=s.get(f);p||(p={filePath:f,hunks:[],insertions:0,deletions:0},s.set(f,p),i.push(f));for(const m of d.structuredPatch)p.hunks.push(m),p.insertions+=FS(m,"+"),p.deletions+=FS(m,"-")}const o=i.map(c=>s.get(c)),a=o.reduce((c,u)=>c+u.insertions,0),l=o.reduce((c,u)=>c+u.deletions,0);return{userMessageId:t,files:o,totalInsertions:a,totalDeletions:l,anchorFound:!0}}function kZ({open:e,onOpenChange:t,api:n,sessionId:r,userMessageId:i,lines:s,procAlive:o,onApplied:a,onNoChanges:l}){const c=g.useMemo(()=>SZ(s,i),[s,i]),[u,d]=g.useState(null),[f,p]=g.useState(!1),[m,v]=g.useState(!1),[y,x]=g.useState(null);g.useEffect(()=>{if(!e)return;let C=!1;return p(!0),d(null),(async()=>{try{const N=await n.sessionRewindDiff({sessionId:r,userMessageId:i});C||(d(N),!N.canRewind&&!N.error&&N.files.length===0&&(l==null||l(i)))}catch{C||d(null)}finally{C||p(!1)}})(),()=>{C=!0}},[e,n,r,i]);const _=g.useMemo(()=>{if(u){const C=!u.canRewind&&!u.error&&u.files.length===0;if(u.canRewind||C)return{source:"rpc",anchorFound:!0,files:u.files.map(N=>({filePath:N.filePath,hunks:N.hunks,insertions:N.insertions,deletions:N.deletions})),totalInsertions:u.totalInsertions,totalDeletions:u.totalDeletions}}return{source:"local",anchorFound:c.anchorFound,files:c.files,totalInsertions:c.totalInsertions,totalDeletions:c.totalDeletions,rpcError:u==null?void 0:u.error}},[u,c]),b=g.useCallback(async()=>{v(!0),x(null);try{const C=await n.sessionRewind({sessionId:r,userMessageId:i,dryRun:!1});if(!C.canRewind){x(C.error??"回退失败");return}a==null||a(),t(!1)}catch(C){x(C.message||"回退失败")}finally{v(!1)}},[n,r,i,a,t]);if(!e)return null;const w=_.files.length>0,k=!f&&!m&&_.anchorFound&&w&&!y;return h.jsxs("div",{"data-testid":"rewind-preview-drawer",className:"fixed right-0 top-0 bottom-0 z-40 flex flex-col border-l border-bg-300/40 bg-bg-0 shadow-xl",style:{width:480,minWidth:480},children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bg-300/30 shrink-0",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(qN,{className:"w-4 h-4 text-text-300"}),h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Rewind 预览"})]}),h.jsx("button",{type:"button",onClick:()=>t(!1),"data-testid":"rewind-drawer-close",className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:bg-text-100/5 hover:text-text-200 cursor-pointer","aria-label":"close",children:h.jsx(Rn,{className:"w-4 h-4"})})]}),y?h.jsxs("div",{"data-testid":"rewind-error-banner",className:"mx-4 mt-3 flex items-start gap-2 rounded-md border border-red-400/40 bg-red-500/10 px-3 py-2 text-[12px] text-red-400",children:[h.jsx(jc,{className:"w-4 h-4 shrink-0 mt-0.5"}),h.jsx("span",{children:y})]}):null,h.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3 space-y-3",children:f?h.jsxs("div",{"data-testid":"rewind-loading",className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsx(rr,{className:"w-3.5 h-3.5 animate-spin"}),h.jsx("span",{children:"正在读取快照…"})]}):_.anchorFound?w?h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":"rewind-summary",className:"rounded-md border border-bg-300 bg-bg-100/40 px-3 py-2 text-[12px] text-text-200",children:[h.jsxs("div",{children:["将回退 ",h.jsx("span",{className:"font-semibold text-text-100",children:_.files.length})," ","个文件,",h.jsxs("span",{className:"text-green-500 font-mono",children:["+",_.totalInsertions]})," / ",h.jsxs("span",{className:"text-red-400 font-mono",children:["-",_.totalDeletions]})]}),_.source==="local"?h.jsx("div",{"data-testid":"rewind-source-hint",className:"mt-1 text-text-400 text-[11px]",children:"基于对话里 tool_result 估算(未读到 CC 快照,数字可能与实际磁盘略有差异)"}):null]}),_.files.map(C=>h.jsx(EZ,{file:C},C.filePath))]}):h.jsxs("div",{"data-testid":"rewind-no-changes",className:"rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300 space-y-1",children:[h.jsx("div",{children:"磁盘上的文件已经和这个时刻的快照完全一致——没有需要回退的改动。"}),h.jsx("div",{className:"text-text-400 text-[11px]",children:"可能这条消息之后 Claude 没落盘编辑,或之前已经 rewind 过了。"})]}):h.jsx("div",{"data-testid":"rewind-no-anchor",className:"rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300",children:"未能在当前消息流中找到对应的用户消息(可能已被历史裁剪)。"})}),h.jsxs("div",{className:"flex flex-col gap-2 px-4 py-3 border-t border-bg-300/30 shrink-0",children:[w&&_.anchorFound&&!o?h.jsxs("div",{"data-testid":"rewind-needs-cc",className:"flex items-start gap-2 rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300",children:[h.jsx(jc,{className:"w-4 h-4 shrink-0 mt-0.5 text-warning"}),h.jsx("span",{children:'Claude Code 进程当前未运行。点击"确认回退"时会自动启动它再执行 — 可能需要等一两秒。'})]}):null,h.jsxs("div",{className:"flex items-center justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:()=>t(!1),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",disabled:!k,onClick:()=>void b(),"data-testid":"rewind-apply",className:ne("h-8 px-3 rounded-md text-[12px] font-medium transition-colors",k?"bg-accent text-white hover:bg-accent-hover cursor-pointer":"bg-bg-200 text-text-400 cursor-not-allowed"),children:m?"回退中…":"确认回退"})]})]})]})}function CZ(e){return e.replace(/^\/Users\/[^/]+/,"~")}function EZ({file:e}){const[t,n]=g.useState(!0);return h.jsxs("div",{"data-testid":"rewind-file-block","data-file":e.filePath,className:"rounded-md border border-bg-300 overflow-hidden bg-bg-0",children:[h.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"w-full flex items-center gap-1.5 px-3 py-2 text-[12px] hover:bg-text-100/5 cursor-pointer",children:[t?h.jsx(li,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"font-mono text-text-200 truncate flex-1 text-left",title:e.filePath,children:CZ(e.filePath)}),h.jsxs("span",{className:"font-mono shrink-0 text-text-400",children:[h.jsxs("span",{className:"text-green-500",children:["+",e.insertions]})," ",h.jsxs("span",{className:"text-red-400",children:["-",e.deletions]})]})]}),t?h.jsx("div",{className:"border-t border-bg-300",children:e.hunks.map(r=>h.jsx(NZ,{hunk:r},`${r.oldStart}-${r.oldLines}-${r.newStart}-${r.newLines}`))}):null]})}function NZ({hunk:e}){const t=`@@ -${e.oldStart},${e.oldLines} +${e.newStart},${e.newLines} @@`;return h.jsxs("div",{className:"text-[11px] font-mono leading-relaxed",children:[h.jsx("div",{className:"px-3 py-1 text-text-400 bg-bg-100/40 border-b border-bg-300",children:t}),e.lines.map((n,r)=>{const i=n.charAt(0),s=i==="+"?"bg-green-500/10 text-green-300":i==="-"?"bg-red-500/10 text-red-300":"text-text-300";return h.jsx("div",{className:ne("px-3 whitespace-pre",s),children:n.length>0?n:" "},r)})]})}var ip="Dialog",[qR]=No(ip),[TZ,Or]=qR(ip),KR=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!0}=e,a=g.useRef(null),l=g.useRef(null),[c,u]=Lf({prop:r,defaultProp:i??!1,onChange:s,caller:ip});return h.jsx(TZ,{scope:t,triggerRef:a,contentRef:l,contentId:no(),titleId:no(),descriptionId:no(),open:c,onOpenChange:u,onOpenToggle:g.useCallback(()=>u(d=>!d),[u]),modal:o,children:n})};KR.displayName=ip;var GR="DialogTrigger",PZ=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(GR,n),s=qt(t,i.triggerRef);return h.jsx(Et.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":ey(i.open),...r,ref:s,onClick:Pe(e.onClick,i.onOpenToggle)})});PZ.displayName=GR;var Q_="DialogPortal",[IZ,XR]=qR(Q_,{forceMount:void 0}),YR=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,s=Or(Q_,t);return h.jsx(IZ,{scope:t,forceMount:n,children:g.Children.map(r,o=>h.jsx($i,{present:n||s.open,children:h.jsx(l_,{asChild:!0,container:i,children:o})}))})};YR.displayName=Q_;var qh="DialogOverlay",ZR=g.forwardRef((e,t)=>{const n=XR(qh,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,s=Or(qh,e.__scopeDialog);return s.modal?h.jsx($i,{present:r||s.open,children:h.jsx(MZ,{...i,ref:t})}):null});ZR.displayName=qh;var RZ=Dc("DialogOverlay.RemoveScroll"),MZ=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(qh,n);return h.jsx(c_,{as:RZ,allowPinchZoom:!0,shards:[i.contentRef],children:h.jsx(Et.div,{"data-state":ey(i.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),_o="DialogContent",QR=g.forwardRef((e,t)=>{const n=XR(_o,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,s=Or(_o,e.__scopeDialog);return h.jsx($i,{present:r||s.open,children:s.modal?h.jsx(AZ,{...i,ref:t}):h.jsx(jZ,{...i,ref:t})})});QR.displayName=_o;var AZ=g.forwardRef((e,t)=>{const n=Or(_o,e.__scopeDialog),r=g.useRef(null),i=qt(t,n.contentRef,r);return g.useEffect(()=>{const s=r.current;if(s)return ZT(s)},[]),h.jsx(JR,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Pe(e.onCloseAutoFocus,s=>{var o;s.preventDefault(),(o=n.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Pe(e.onPointerDownOutside,s=>{const o=s.detail.originalEvent,a=o.button===0&&o.ctrlKey===!0;(o.button===2||a)&&s.preventDefault()}),onFocusOutside:Pe(e.onFocusOutside,s=>s.preventDefault())})}),jZ=g.forwardRef((e,t)=>{const n=Or(_o,e.__scopeDialog),r=g.useRef(!1),i=g.useRef(!1);return h.jsx(JR,{...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()}})}),JR=g.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,...o}=e,a=Or(_o,n),l=g.useRef(null),c=qt(t,l);return vT(),h.jsxs(h.Fragment,{children:[h.jsx(Jx,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:h.jsx(Of,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ey(a.open),...o,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),h.jsxs(h.Fragment,{children:[h.jsx(DZ,{titleId:a.titleId}),h.jsx(OZ,{contentRef:l,descriptionId:a.descriptionId})]})]})}),J_="DialogTitle",eM=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(J_,n);return h.jsx(Et.h2,{id:i.titleId,...r,ref:t})});eM.displayName=J_;var tM="DialogDescription",nM=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(tM,n);return h.jsx(Et.p,{id:i.descriptionId,...r,ref:t})});nM.displayName=tM;var rM="DialogClose",iM=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(rM,n);return h.jsx(Et.button,{type:"button",...r,ref:t,onClick:Pe(e.onClick,()=>i.onOpenChange(!1))})});iM.displayName=rM;function ey(e){return e?"open":"closed"}var sM="DialogTitleWarning",[Xne,oM]=o$(sM,{contentName:_o,titleName:J_,docsSlug:"dialog"}),DZ=({titleId:e})=>{const t=oM(sM),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
521
+ `):null}if(typeof e=="object"){const t=e;if(typeof t.text=="string")return t.text}return null}function MS(e){if(!e||!Number.isFinite(e))return null;if(e<1e3)return`${e}ms`;const t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;const n=Math.floor(t/60),r=Math.round(t-n*60);return`${n}m${r.toString().padStart(2,"0")}s`}function NY(e){return!e||!Number.isFinite(e)?null:e<1e3?`${e} tok`:e<1e4?`${(e/1e3).toFixed(1)}k tok`:`${Math.round(e/1e3)}k tok`}const TY={readCount:"read",searchCount:"search",bashCount:"bash",editFileCount:"edit",linesAdded:"+lines",linesRemoved:"-lines",otherToolCount:"other"};function PY(e){if(!e)return[];const t=[];for(const[n,r]of Object.entries(e)){if(!r||r<=0)continue;const i=TY[n]??n;t.push(`${i}:${r}`)}return t}function IY({description:e,input:t,output:n,error:r,pending:i,notifications:s,toolResultExtra:o,progress:a}){const[l,c]=g.useState(!1),u=BR(),d=g.useMemo(()=>{if(!t||typeof t!="object")return null;const T=t;return typeof T.prompt=="string"?T.prompt:null},[t]),f=(o==null?void 0:o.prompt)??d,p=g.useMemo(()=>EY(n),[n]),m=o==null?void 0:o.stats,v=a==null?void 0:a.stats,y=MS((m==null?void 0:m.durationMs)??(v==null?void 0:v.durationMs)),x=NY((m==null?void 0:m.tokens)??(v==null?void 0:v.tokens)),_=PY(m==null?void 0:m.toolStats),b=i&&(a!=null&&a.lastToolName)?`now:${a.lastToolName}`:null,w=!!(o!=null&&o.agentType||y||x||_.length>0||b),k=(o==null?void 0:o.agentId)??(a==null?void 0:a.agentId),C=g.useMemo(()=>s.map(T=>({taskId:T.taskId,text:T.text,parsed:LR(T.text)})),[s]),N=r?h.jsx(Rs,{className:"w-3.5 h-3.5 text-error"}):i?h.jsx(rr,{className:"w-3.5 h-3.5 text-blue-400 animate-spin"}):h.jsx(Df,{className:"w-3.5 h-3.5 text-green-500"});return h.jsxs("div",{"data-testid":"msg-line-agent-call","data-pending":i?"true":"false","data-has-error":r?"true":"false","data-notification-count":s.length,"data-has-stats":w?"true":"false","data-agent-id":k??"",className:"my-1 min-w-0 max-w-full rounded-md border border-bg-200/60 bg-bg-100/30",children:[h.jsxs("button",{type:"button","aria-expanded":l,onClick:()=>c(T=>!T),className:ne("flex w-full min-w-0 items-center gap-2 px-2.5 py-1.5 text-left text-[13px]","hover:bg-bg-200/40 rounded-md transition-colors"),children:[h.jsx("span",{className:"w-5 h-5 flex items-center justify-center text-[10px] rounded bg-violet-500/10 text-violet-500 shrink-0","aria-hidden":!0,children:h.jsx(pz,{className:"w-3 h-3"})}),h.jsx("span",{className:"shrink-0",children:N}),h.jsx("span",{className:"flex-1 min-w-0 truncate font-medium text-text-200",children:e}),w?null:s.length>0?h.jsxs("span",{className:"text-[11px] text-text-400 tabular-nums shrink-0",children:[s.length," 次通知"]}):null,k&&(u!=null&&u.open)?h.jsx("span",{role:"button",tabIndex:0,"data-testid":"open-subagent-btn-header","data-agent-id":k,"aria-label":"打开子 agent 对话",onClick:T=>{T.stopPropagation(),u.open(k,o==null?void 0:o.agentType)},onKeyDown:T=>{(T.key==="Enter"||T.key===" ")&&(T.stopPropagation(),T.preventDefault(),u.open(k,o==null?void 0:o.agentType))},className:"shrink-0 inline-flex items-center justify-center w-3.5 h-3.5 text-text-400 hover:text-text-200",children:h.jsx(Ac,{className:"w-3.5 h-3.5"})}):null,l?h.jsx(li,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3.5 h-3.5 text-text-400 shrink-0"})]}),i&&(a!=null&&a.description)?h.jsx("div",{"data-testid":"agent-call-progress-desc",className:"px-3 pt-0 pb-1 text-[12px] text-text-300 truncate",children:a.description}):null,w?h.jsxs("div",{"data-testid":"agent-call-stats",className:"flex items-center gap-1.5 flex-wrap px-3 pb-1.5 pt-0 text-[11px] text-text-400",children:[o!=null&&o.agentType?h.jsx("span",{"data-testid":"agent-call-stats-type",className:"inline-flex items-center rounded-sm bg-violet-500/10 px-1.5 py-0.5 text-violet-400 font-medium",children:o.agentType}):null,y?h.jsx("span",{className:"tabular-nums",children:y}):null,x?h.jsx("span",{className:"tabular-nums",children:x}):null,b?h.jsx("span",{"data-testid":"agent-call-stats-now",className:"font-mono tabular-nums text-blue-400",children:b}):null,_.map(T=>h.jsx("span",{className:"font-mono tabular-nums text-text-400/80",children:T},T)),s.length>0?h.jsxs("span",{className:"tabular-nums text-text-400/70",children:["· ",s.length," 次通知"]}):null]}):null,l?h.jsxs("div",{"data-testid":"agent-call-body",className:"min-w-0 border-t border-bg-200/60 px-3 py-2 space-y-3",children:[r?h.jsx("div",{className:"text-[12px] text-error whitespace-pre-wrap",children:r}):null,C.map((T,L)=>{const P=T.parsed,O=MS(P.durationMs);return h.jsxs("div",{"data-testid":"agent-call-notification","data-task-id":T.taskId??"",className:"min-w-0 rounded-md border border-bg-200/60 bg-bg-0/40 p-2 space-y-1.5",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-400 flex-wrap",children:[h.jsx("span",{className:"font-mono",children:(T.taskId??P.taskId??"未知").slice(0,12)}),h.jsx("span",{className:"uppercase tracking-wide",children:P.status??"unknown"}),O?h.jsxs("span",{className:"tabular-nums",children:["· ",O]}):null,P.totalTokens?h.jsxs("span",{className:"tabular-nums",children:["· ",P.totalTokens," tok"]}):null,P.toolUses?h.jsxs("span",{className:"tabular-nums",children:["· ",P.toolUses," tools"]}):null,P.worktreeBranch?h.jsxs("span",{className:"font-mono",children:["· ",P.worktreeBranch]}):null]}),P.summary?h.jsx("div",{className:"text-[12px] text-text-300",children:P.summary}):null,P.result?h.jsx("div",{"data-testid":"agent-call-notification-result",className:"assistant-markdown text-[12px] leading-relaxed break-words",children:h.jsx(Uc,{remarkPlugins:[Vc],components:qc,children:P.result})}):null]},`${T.taskId??"n"}-${L}`)}),f?h.jsxs("div",{"data-testid":"agent-call-prompt-block",className:"min-w-0 space-y-1",children:[h.jsx("div",{className:"text-[11px] text-text-400 font-medium",children:"任务指令"}),h.jsx("pre",{"data-testid":"agent-call-prompt",className:"max-w-full whitespace-pre-wrap break-words text-[11px] text-text-300 bg-bg-50/60 rounded p-2 border border-bg-200/60 max-h-64 overflow-auto [overflow-wrap:anywhere]",children:f})]}):null,p?h.jsxs("div",{"data-testid":"agent-call-result-block",className:"min-w-0 space-y-1",children:[h.jsx("div",{className:"text-[11px] text-text-400 font-medium",children:"子 agent 报告"}),h.jsx("div",{"data-testid":"agent-call-result",className:"assistant-markdown text-[12px] leading-relaxed break-words",children:h.jsx(Uc,{remarkPlugins:[Vc],components:qc,children:p})})]}):null,!p&&C.length===0&&!r&&!f?h.jsx("div",{className:"text-[11px] text-text-400 italic",children:"无详细信息"}):null,k&&(u!=null&&u.open)?h.jsx("div",{className:"flex justify-end",children:h.jsxs("button",{type:"button","data-testid":"open-subagent-btn","data-agent-id":k,onClick:()=>u.open(k,o==null?void 0:o.agentType),className:ne("inline-flex items-center gap-1 rounded-md border border-bg-200/60","bg-bg-100/40 hover:bg-bg-200/40 transition-colors","px-2 py-1 text-[11px] text-text-300"),children:[h.jsx(Ac,{className:"w-3 h-3"}),h.jsx("span",{children:"打开子 agent 对话"})]})}):null]}):null]})}function zR({title:e,items:t,live:n,progressColor:r="bg-green-500",listKind:i,children:s}){const[o,a]=g.useState(!!n),l=t.length,c=t.filter(d=>d.status==="completed").length,u=l>0?Math.round(c/l*100):0;return h.jsxs("div",{"data-testid":"msg-line-checklist","data-list-kind":i,className:"min-w-0 max-w-full py-1",children:[h.jsxs("button",{type:"button",onClick:()=>a(d=>!d),"aria-expanded":o,className:"flex items-center gap-2.5 w-full text-left rounded-md px-1.5 py-1 hover:bg-text-100/5 cursor-pointer",children:[o?h.jsx(li,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"text-[13px] font-medium text-text-200",children:e}),h.jsxs("span",{className:"text-[11px] text-text-400 tabular-nums",children:[c,"/",l]}),h.jsx("div",{className:"flex-1 max-w-[120px] h-1.5 rounded-full bg-text-100/10 overflow-hidden",children:h.jsx("div",{className:ne("h-full rounded-full transition-all duration-300",r),style:{width:`${u}%`}})})]}),o?h.jsxs("div",{"data-testid":"checklist-body",className:"ml-6 mt-0.5",children:[h.jsx("div",{className:"space-y-px",children:t.map((d,f)=>h.jsxs("div",{className:"flex min-w-0 items-start gap-2 py-0.5 px-1",children:[h.jsx("span",{className:"w-4 h-4 mt-0.5 flex items-center justify-center shrink-0",children:d.status==="completed"?h.jsx(Qa,{className:"w-3.5 h-3.5 text-green-500"}):d.status==="in_progress"&&n?h.jsx(rr,{className:"w-3.5 h-3.5 text-blue-400 animate-spin"}):h.jsx("span",{className:"w-2 h-2 rounded-full border border-text-400/40"})}),h.jsx("span",{className:ne("min-w-0 text-[13px] leading-snug break-words [overflow-wrap:anywhere]",d.status==="completed"?"text-text-400 line-through":"text-text-200"),children:d.status==="in_progress"&&d.activeForm?d.activeForm:d.content})]},`${f}-${d.content}`))}),s]}):null]})}function RY({todos:e,live:t}){return h.jsx(zR,{title:"Tasks",items:e,live:t,progressColor:"bg-green-500",listKind:"todo"})}function MY({tasks:e,live:t}){return h.jsx(zR,{title:"Plan",items:e,live:t,progressColor:"bg-blue-500",listKind:"plan"})}function AY(e){if(!e||!Number.isFinite(e))return null;const t=Date.now()-e;if(t<0)return null;const n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const i=Math.floor(r/60);if(i<24)return`${i}h ago`;const s=Math.floor(i/24);if(s<7)return`${s}d ago`;const o=Math.floor(s/7);return o<5?`${o}w ago`:new Date(e).toISOString().slice(0,10)}function jY(e){return(e.split("/").pop()??e)||e}function DY({memories:e}){return!e||e.length===0?null:h.jsxs("div",{"data-testid":"memory-callout",className:"my-1 min-w-0 max-w-full rounded-md border border-bg-200/60 bg-bg-100/30",children:[h.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-1.5 text-[12px] text-text-300 border-b border-bg-200/60",children:[h.jsx(jB,{className:"w-3.5 h-3.5 text-amber-500 shrink-0"}),h.jsx("span",{className:"font-medium",children:"项目记忆"}),h.jsxs("span",{className:"text-text-400 tabular-nums",children:["· ",e.length]})]}),h.jsx("ul",{className:"divide-y divide-bg-200/40",children:e.map(t=>h.jsx(LY,{memory:t},t.path))})]})}function LY({memory:e}){const[t,n]=g.useState(!1),r=AY(e.mtimeMs),i=e.content.replace(/\s+/g," ").trim().slice(0,80);return h.jsxs("li",{className:"px-2.5 py-1.5",children:[h.jsxs("button",{type:"button","aria-expanded":t,onClick:()=>n(s=>!s),className:ne("flex w-full items-center gap-1.5 text-left text-[12px]","hover:bg-bg-200/30 rounded-sm py-0.5"),children:[t?h.jsx(li,{className:"w-3 h-3 text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3 h-3 text-text-400 shrink-0"}),h.jsx("span",{className:"font-mono text-text-300 shrink-0 max-w-[20ch] truncate",title:e.path,children:jY(e.path)}),h.jsx("span",{className:"flex-1 min-w-0 truncate text-text-400/80",children:i}),r?h.jsx("span",{className:"shrink-0 text-[11px] text-text-400 tabular-nums",children:r}):null]}),t?h.jsx("pre",{"data-testid":"memory-callout-body",className:"mt-1 max-w-full whitespace-pre-wrap break-words text-[12px] text-text-300 bg-bg-50/60 rounded-md p-2 border border-bg-200/60 [overflow-wrap:anywhere]",children:e.content}):null]})}function OY({toolUseId:e,questions:t,onSubmit:n,onCancel:r,submittedAnswers:i}){const[s,o]=g.useState({}),[a,l]=g.useState({}),[c,u]=g.useState({}),[d,f]=g.useState(!1),[p,m]=g.useState(!1),v=i!==void 0&&Object.keys(i).length>0,y=v||p,x=!n&&!v,_=(k,C)=>{const N={labels:new Set,freeText:""};if(!v||!i)return N;const T=i[k];if(typeof T!="string")return N;const L=T.split(",").map(R=>R.trim()).filter(Boolean),P=new Set(C.map(R=>R.label)),O=new Set,I=[];for(const R of L)P.has(R)?O.add(R):I.push(R);return{labels:O,freeText:I.join(", ")}},b=g.useMemo(()=>t.every(k=>{if((c[k.question]??"").trim().length>0)return!0;if(k.multiSelect){const N=a[k.question];return!!(N&&N.size>0)}return typeof s[k.question]=="string"&&s[k.question].length>0}),[t,s,a,c]),w=async()=>{if(!b||d||y||x||!n)return;const k={};for(const C of t){const N=(c[C.question]??"").trim();if(C.multiSelect){const T=a[C.question],L=T?C.options.filter(P=>T.has(P.label)).map(P=>P.label):[];if(N.length>0&&L.push(N),L.length===0)continue;k[C.question]=L.join(", ")}else if(N.length>0)k[C.question]=N;else{const T=s[C.question];typeof T=="string"&&(k[C.question]=T)}}f(!0);try{await n(k),m(!0)}finally{f(!1)}};return h.jsxs("div",{"data-testid":"msg-line-question","data-tool-use-id":e,className:"min-w-0 max-w-full rounded-md border border-accent/40 bg-accent/5 px-3 py-2.5 text-[13px]",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 mb-2",children:[h.jsx(GB,{className:"w-4 h-4 text-accent shrink-0"}),h.jsx("span",{className:"min-w-0 font-medium text-text-100",children:"需要你的回答 / Need your answer"}),t.length>1?h.jsxs("span",{className:"ml-auto text-[12px] text-text-400","data-testid":"msg-line-question-count",children:[t.length," 个问题"]}):null]}),h.jsx("div",{className:"flex flex-col gap-3 mb-3",children:t.map((k,C)=>{const N=`q-${C}`,T=`${e}-${C}`,L=_(k.question,k.options),P=y||x,O=c[k.question]??"",I=v?L.freeText:p?(c[k.question]??"").trim():"";return h.jsxs("div",{"data-testid":"msg-line-question-item",children:[k.question?h.jsx("div",{className:"text-text-200 mb-1.5",children:k.question}):null,h.jsx("div",{className:"flex flex-col gap-1",children:k.options.map((R,D)=>{var F;const z=`${N}-${D}`,$=v?L.labels.has(R.label):k.multiSelect?!!((F=a[k.question])!=null&&F.has(R.label)):s[k.question]===R.label;return h.jsxs("label",{className:"flex min-w-0 items-start gap-2 cursor-pointer select-none py-1 px-2 rounded hover:bg-bg-100",children:[h.jsx("input",{type:k.multiSelect?"checkbox":"radio",name:T,value:R.label,checked:$,disabled:y||x,onChange:()=>{y||x||(k.multiSelect?l(j=>{const B=new Set(j[k.question]??[]);return B.has(R.label)?B.delete(R.label):B.add(R.label),{...j,[k.question]:B}}):o(j=>({...j,[k.question]:R.label})))},className:"mt-0.5","data-testid":"msg-line-question-option"}),h.jsxs("span",{className:"flex min-w-0 flex-col",children:[h.jsx("span",{className:"text-text-100 [overflow-wrap:anywhere]",children:R.label}),R.description?h.jsx("span",{className:"text-[12px] text-text-400 [overflow-wrap:anywhere]",children:R.description}):null]})]},z)})}),P?I.length>0?h.jsx("div",{className:"mt-2 rounded-lg border border-accent/15 bg-bg-100/60 px-3 py-2 text-[13px] leading-relaxed text-text-200 [overflow-wrap:anywhere]","data-testid":"msg-line-question-freetext-result",children:I}):null:h.jsx("textarea",{rows:3,value:O,placeholder:"或自行输入回答...",onChange:R=>{const D=R.target.value;u(z=>({...z,[k.question]:D}))},className:"mt-2 w-full resize-y rounded-lg border border-accent/20 bg-bg-000/60 px-3 py-2 text-[13px] leading-relaxed text-text-100 placeholder:text-text-400 outline-none transition-colors focus:border-accent/60 focus:bg-bg-000","data-testid":"msg-line-question-freetext"})]},N)})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(ni,{size:"sm",variant:"default",onClick:()=>void w(),disabled:!b||d||y||x,"data-testid":"msg-line-question-submit",children:y?"已提交 / Submitted":x?"已结束 / Ended":"提交 / Submit"}),r&&!y&&!x?h.jsx(ni,{size:"sm",variant:"ghost",onClick:()=>void r(),disabled:d,"data-testid":"msg-line-question-cancel",children:"跳过 / Skip"}):null]})]})}function BY({toolUseId:e,questions:t,historicalAnswers:n,realtimeAnswers:r,onSubmit:i,onCancel:s}){const o=r??n,a=g.useCallback(async c=>{i&&await i(e,c)},[i,e]),l=g.useCallback(async()=>{s&&await s(e)},[s,e]);return h.jsx(OY,{toolUseId:e,questions:t,onSubmit:i?a:void 0,...s?{onCancel:l}:{},submittedAnswers:o})}function zY(){const e=new Map,t=(n,r)=>`${n}::${r}`;return{register(n,r,i){e.set(t(n,r),i)},resolve(n,r){return n?e.get(t(n,r))??null:null},reset(){e.clear()}}}const pu=zY();function $R({lines:e,onPermissionRespond:t,onPermissionInterrupt:n,topSlot:r,onRewind:i,rewindableUserMessageIds:s,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v}){const y=g.useMemo(()=>O7(e),[e]);return h.jsxs("div",{"data-testid":"message-list",className:"flex w-full min-w-0 max-w-full flex-col gap-2 px-4 py-3",children:[r,y.map(x=>$Y(x,{onRewind:i,rewindableUserMessageIds:s,onPermissionRespond:t,onPermissionInterrupt:n,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v}))]})}function $Y(e,t){const{onRewind:n,rewindableUserMessageIds:r,onPermissionRespond:i,onPermissionInterrupt:s,onFork:o,onQuickAsk:a,realtimeQuestionAnswers:l,onSubmitQuestion:c,onCancelQuestion:u,liveQuestionToolUseIds:d,fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v}=t,y=`${e.kind}-${e.seq}`;switch(e.kind){case"session-init":return null;case"user-text":{const x=typeof e.uuid=="string"?e.uuid:void 0,_=!!(n&&x&&(!r||r.has(x)));return h.jsx(gY,{text:e.text,senderDisplayName:e.senderDisplayName,rewindTarget:_&&x&&n?{userMessageId:x,onRewind:n}:void 0},y)}case"user-meta":return h.jsx(bY,{metaKind:e.metaKind,text:e.text},y);case"meta-text":return h.jsx(wY,{text:e.text,metaSource:e.metaSource},y);case"agent-notification":return h.jsx(kY,{text:e.text,taskId:e.taskId,parentToolUseId:e.parentToolUseId},y);case"assistant-text":{const x=typeof e.uuid=="string"?e.uuid:void 0,_=x&&(o||a)?{messageUuid:x,onFork:o,onQuickAsk:a}:void 0;return h.jsx(OX,{text:$7(e.text),forkTarget:_},y)}case"assistant-thinking":return h.jsx(BX,{text:e.text},y);case"permission-inline":return h.jsx(uY,{tool:e.tool,input:e.input,onRespond:i??(()=>{}),onInterrupt:s},y);case"error":return h.jsx(dY,{message:e.message},y);case"turn-end":return null;case"merged-tool":return FY(e,y,{fileSharingScope:f,onShareFile:p,onOpenInTab:m,onPreviewMarkdown:v});case"merged-agent":return h.jsx(IY,{description:e.description,input:e.input,output:e.output,error:e.error,pending:e.pending,notifications:e.notifications,toolResultExtra:e.toolResultExtra,progress:e.progress},y);case"plan-card":return h.jsx(MY,{tasks:e.tasks},y);case"todo-checklist":return h.jsx(RY,{todos:e.todos},y);case"memory-callout":return h.jsx(DY,{memories:e.memories},y);case"question-card":{const x=d===void 0||d.has(e.toolUseId);return h.jsx(BY,{toolUseId:e.toolUseId,questions:e.questions,historicalAnswers:e.submittedAnswers,realtimeAnswers:l==null?void 0:l[e.toolUseId],onSubmit:x?c:void 0,...x&&u?{onCancel:u}:{}},y)}default:return null}}function FY(e,t,n){const r=pu.resolve(e.toolKind,e.tool),i=r?r.render({input:e.input,output:e.output,error:e.error,pending:e.pending,toolUseId:e.toolUseId,...n.fileSharingScope?{fileScope:n.fileSharingScope}:{},...n.onShareFile?{onShareFile:n.onShareFile}:{},...n.onOpenInTab?{onOpenInTab:n.onOpenInTab}:{},...n.onPreviewMarkdown?{onPreviewMarkdown:n.onPreviewMarkdown}:{}}):null;return h.jsx(st.Fragment,{children:i??h.jsx(jR,{tool:e.tool,input:e.input,output:e.output,error:e.error,pending:e.pending,...n.fileSharingScope?{fileScope:n.fileSharingScope}:{},...n.onShareFile?{onShareFile:n.onShareFile}:{},...n.onOpenInTab?{onOpenInTab:n.onOpenInTab}:{},...n.onPreviewMarkdown?{onPreviewMarkdown:n.onPreviewMarkdown}:{}})},t)}function $d(e){return e==="codex"?"Codex":"Claude Code"}const HY={builtin:"Commands",global:"Global",project:"Project",plugin:"Plugin"},AS={builtin:0,global:1,project:2,plugin:3};function UY({query:e,skills:t,activeIndex:n,onActiveIndexChange:r,onSelect:i,onEmpty:s}){const o=g.useRef(null),a=g.useMemo(()=>FR(t,e),[t,e]),l=g.useMemo(()=>{const c=new Set;let u=null;for(let d=0;d<a.length;d++)a[d].source!==u&&(c.add(d),u=a[d].source);return c},[a]);return g.useEffect(()=>{a.length===0&&(s==null||s())},[a.length,s]),g.useEffect(()=>{var c;try{(c=o.current)==null||c.scrollIntoView({block:"nearest"})}catch{}},[n]),a.length===0?null:h.jsx("div",{"data-testid":"cc-skill-selector",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 max-h-[320px] overflow-y-auto rounded-2xl border border-bg-300 bg-bg-50 shadow-lg",children:a.map((c,u)=>{const d=u===n,f=l.has(u);return h.jsxs(st.Fragment,{children:[f?h.jsx("div",{className:"sticky top-0 z-10 bg-bg-50/95 backdrop-blur-sm px-4 py-2 text-[10px] font-semibold uppercase tracking-wider text-text-400/70 border-b border-bg-200/60",children:HY[c.source]}):null,h.jsxs("div",{ref:d?o:void 0,"data-testid":`cc-skill-item-${c.name}`,onMouseEnter:()=>r(u),onClick:()=>i(c),className:ne("flex items-center gap-2.5 px-4 py-2 cursor-pointer transition-colors duration-75",d?"bg-[var(--text-100-dim)]":"hover:bg-bg-100/60"),children:[h.jsxs("code",{className:"text-[12px] font-mono font-semibold text-text-100 shrink-0",children:["/",c.name]}),c.description?h.jsx("span",{className:"text-[11px] text-text-300 truncate ml-auto",children:c.description}):null]})]},`${c.source}/${c.name}`)})})}function FR(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(i=>i.name.toLowerCase().includes(n)||(i.description??"").toLowerCase().includes(n)):e.slice();return r.sort((i,s)=>(AS[i.source]??9)-(AS[s.source]??9)),r.slice(0,30)}const WY={builtin:"Built-in",global:"Global",project:"Project",policy:"Policy",plugin:"Plugin",persona:"My personas",contact:"People","remote-persona":"Remote personas"},jS={builtin:0,global:1,project:2,policy:3,plugin:4,persona:5,contact:6,"remote-persona":7};function Vh(e){switch(e.kind){case"persona":return"persona";case"contact":return"contact";case"remote-persona":return"remote-persona";case"cc-agent":return e.agent.source}}function VY(e){switch(e.kind){case"persona":return`persona/${e.persona.personaId}`;case"contact":return`contact/${e.contact.deviceId}`;case"remote-persona":return`remote/${e.deviceId}/${e.persona.personaId}`;case"cc-agent":return`${e.agent.source}/${e.agent.name}`}}function qY(e){switch(e.kind){case"persona":return`${e.persona.personaId} ${e.persona.label}`.toLowerCase();case"contact":return`${e.contact.displayName} ${e.contact.deviceId}`.toLowerCase();case"remote-persona":return`${e.persona.personaId} ${e.persona.label}`.toLowerCase();case"cc-agent":{const t=e.agent;return`${t.name} ${t.description??""} ${t.whenToUse??""}`.toLowerCase()}}}function KY(e){switch(e.kind){case"persona":return{displayName:`@persona/${e.persona.personaId}`,description:e.persona.label,testid:`cc-agent-item-persona-${e.persona.personaId}`};case"contact":return{displayName:`@${e.contact.displayName}`,description:e.contact.deviceId,testid:`cc-agent-item-contact-${e.contact.deviceId}`};case"remote-persona":return{displayName:`@persona/${e.persona.personaId}`,description:e.persona.label,testid:`cc-agent-item-remote-${e.deviceId}-${e.persona.personaId}`};case"cc-agent":return{displayName:`@${e.agent.name}`,description:e.agent.description,whenToUse:e.agent.whenToUse,plugin:e.agent.plugin,testid:`cc-agent-item-${e.agent.name}`}}}function HR(e,t){const n=t.trim().toLowerCase(),r=n?e.filter(i=>qY(i).includes(n)):e.slice();return r.sort((i,s)=>(jS[Vh(i)]??9)-(jS[Vh(s)]??9)),r.slice(0,30)}function DS({query:e,entries:t,activeIndex:n,onActiveIndexChange:r,onSelect:i,onEmpty:s}){const o=g.useRef(null),a=g.useMemo(()=>HR(t,e),[t,e]),l=g.useMemo(()=>{const c=new Set;let u=null;for(let d=0;d<a.length;d++){const f=Vh(a[d]);f!==u&&(c.add(d),u=f)}return c},[a]);return g.useEffect(()=>{a.length===0&&(s==null||s())},[a.length,s]),g.useEffect(()=>{var c;try{(c=o.current)==null||c.scrollIntoView({block:"nearest"})}catch{}},[n]),a.length===0?null:h.jsx("div",{"data-testid":"cc-agent-selector",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 max-h-[320px] overflow-y-auto rounded-2xl border border-bg-300 bg-bg-50 shadow-lg",children:a.map((c,u)=>{const d=u===n,f=l.has(u),p=Vh(c),m=KY(c);return h.jsxs(st.Fragment,{children:[f?h.jsx("div",{"data-testid":`cc-agent-group-header-${p}`,"data-source":p,className:"sticky top-0 z-10 bg-bg-50/95 backdrop-blur-sm px-4 py-2 text-[10px] font-semibold uppercase tracking-wider text-text-400/70 border-b border-bg-200/60",children:WY[p]}):null,h.jsxs("div",{ref:d?o:void 0,"data-testid":m.testid,onMouseEnter:()=>r(u),onClick:()=>i(c),className:ne("flex items-center gap-2.5 px-4 py-2 cursor-pointer transition-colors duration-75",d?"bg-[var(--text-100-dim)]":"hover:bg-bg-100/60"),children:[h.jsx("code",{className:"text-[12px] font-mono font-semibold text-text-100 shrink-0",children:m.displayName}),m.description?h.jsx("span",{className:"text-[11px] text-text-300 truncate ml-2",children:m.description}):null,m.whenToUse?h.jsx("span",{className:"text-[10px] text-text-400/70 italic truncate ml-auto",children:m.whenToUse}):null,m.plugin?h.jsx("span",{className:"text-[10px] text-text-400/70 ml-2 shrink-0",children:m.plugin}):null]})]},VY(c))})})}function GY({attachment:e,onRemove:t,onOpenPreview:n}){const r=e.mimeType.startsWith("image/"),i=e.status==="error",s=e.status==="uploading",o=r&&e.status==="done"&&!!e.previewUrl&&!!n;return h.jsxs("div",{"data-testid":`attachment-pill-${e.id}`,className:ne("group relative flex items-center gap-1.5 rounded-lg border px-2 py-1.5 text-[12px] transition-colors",i?"border-red-400/40 bg-red-500/5":"border-bg-300 bg-bg-100"),children:[r&&e.previewUrl?h.jsxs("div",{className:"relative h-7 w-7 shrink-0",children:[h.jsx("img",{src:e.previewUrl,alt:e.fileName,onClick:o?n:void 0,"data-testid":`attachment-thumb-${e.id}`,className:ne("h-7 w-7 rounded object-cover",o&&"cursor-pointer hover:opacity-80",s&&"opacity-40")}),s?h.jsx(rr,{"data-testid":`attachment-spinner-${e.id}`,className:"absolute inset-0 m-auto h-3.5 w-3.5 animate-spin text-text-200"}):null]}):h.jsx("div",{className:"relative flex h-7 w-7 items-center justify-center rounded bg-text-100/5 shrink-0",children:s?h.jsx(rr,{"data-testid":`attachment-spinner-${e.id}`,className:"h-3.5 w-3.5 animate-spin text-text-400"}):h.jsx(Ms,{className:"h-3.5 w-3.5 text-text-400"})}),h.jsx("span",{className:ne("max-w-[120px] truncate text-text-200",s&&"text-text-400"),title:e.error??e.fileName,children:e.fileName}),i?h.jsx(Rs,{className:"h-3 w-3 text-red-400 shrink-0"}):null,h.jsx("button",{type:"button",onClick:t,"data-testid":`attachment-remove-${e.id}`,className:"flex h-4 w-4 items-center justify-center rounded-full text-text-400 hover:text-text-100 hover:bg-text-100/10 transition-colors cursor-pointer shrink-0","aria-label":"remove",children:h.jsx(Rn,{className:"h-3 w-3"})})]})}function XY({attachments:e,onRemove:t,onOpenPreview:n}){return e.length===0?null:h.jsx("div",{"data-testid":"attachment-row",className:"flex flex-wrap gap-1.5 mb-2 px-1",children:e.map(r=>h.jsx(GY,{attachment:r,onRemove:()=>t(r.id),onOpenPreview:n?()=>n(r):void 0},r.id))})}class zl extends Error{constructor(t,n,r){super(n),this.code=t,this.status=r,this.name="UploadAttachmentError"}}async function YY(e){if(!e.httpBaseUrl)throw new zl("TUNNEL_NOT_READY","daemon httpBaseUrl unavailable");if(!e.httpToken)throw new zl("NO_AUTH","daemon httpToken unavailable");const t=new URLSearchParams({sessionId:e.sessionId,fileName:e.file.name,mimeType:e.file.type||"application/octet-stream"}),n=`${e.httpBaseUrl.replace(/\/$/,"")}/attachments/upload?${t.toString()}`;let r;try{r=await fetch(n,{method:"POST",headers:{Authorization:`Bearer ${e.httpToken}`,"Content-Type":e.file.type||"application/octet-stream"},body:e.file})}catch(i){throw new zl("NETWORK_ERROR",i.message)}if(!r.ok){let i="UPLOAD_FAILED",s=`HTTP ${r.status}`;try{const o=await r.json();o.code&&(i=o.code),o.message&&(s=o.message)}catch{}throw new zl(i,s,r.status)}return await r.json()}const LS=25*1024*1024,ZY="image/*,.txt,.md,.markdown,.csv,.json,.log,.yaml,.yml,.html,.xml,.pdf",QY=["image/","text/"],JY=new Set(["application/json","application/xml","application/x-yaml","application/yaml","application/pdf"]),eZ=new Set(["txt","md","markdown","csv","json","log","yaml","yml","html","xml","pdf"]);function tZ(e){var r;const t=(e.type||"").toLowerCase();if(t&&QY.some(i=>t.startsWith(i))||t&&JY.has(t))return!0;const n=((r=e.name.split(".").pop())==null?void 0:r.toLowerCase())??"";return n.length>0&&eZ.has(n)}let nZ=0;const rZ=()=>`att-${++nZ}-${Date.now()}`;function iZ(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(typeof r.result=="string"?r.result:""),r.onerror=()=>n(r.error??new Error("read failed")),r.readAsDataURL(e)})}function sZ(e){const[t,n]=g.useState(e.initial??[]),r=g.useCallback(async o=>{const a=Array.from(o);if(a.length===0)return;const l=[],c=[],u=[];for(const d of a){const f={id:rZ(),fileName:d.name,mimeType:d.type||"application/octet-stream"};if(!tZ(d)){c.push({...f,url:null,status:"error",error:"不支持的文件类型"});continue}if(d.size>LS){c.push({...f,url:null,status:"error",error:`超过 ${Math.round(LS/1024/1024)}MB 上限`});continue}if(e.sessionId==null){u.push({id:f.id,file:d,mimeType:f.mimeType}),c.push({...f,url:null,status:"uploading"});continue}const p=f.mimeType.startsWith("image/")?URL.createObjectURL(d):void 0;c.push({...f,url:null,status:"uploading",...p?{previewUrl:p}:{}}),l.push({id:f.id,file:d})}n(d=>[...d,...c]);for(const d of u)try{const f=await iZ(d.file);n(p=>p.map(m=>m.id===d.id?{...m,url:f,status:"done",...d.mimeType.startsWith("image/")?{previewUrl:f}:{}}:m))}catch(f){n(p=>p.map(m=>m.id===d.id?{...m,status:"error",error:f.message??"read failed"}:m))}l.length!==0&&await Promise.all(l.map(async d=>{try{const f=await YY({httpBaseUrl:e.httpBaseUrl,httpToken:e.httpToken,sessionId:e.sessionId,file:d.file});n(p=>p.map(m=>m.id===d.id?{...m,url:f.url,status:"done"}:m))}catch(f){const p=f instanceof zl?f.code:"UPLOAD_FAILED",m=f.message??"upload failed";n(v=>v.map(y=>y.id===d.id?{...y,status:"error",error:`${p}: ${m}`}:y))}}))},[e.sessionId,e.httpBaseUrl,e.httpToken]),i=g.useCallback(o=>{n(a=>a.filter(l=>l.id!==o))},[]),s=g.useCallback(()=>{n([])},[]);return{attachments:t,setAttachments:n,addFiles:r,removeAttachment:i,clearAttachments:s}}const Zv=new Map,oZ=[];function OS(e){if(e)return Zv.get(e)}function BS(e,t){e&&(t.draft.length===0&&t.attachments.length===0?Zv.delete(e):Zv.set(e,t))}function aZ(e,t){return e.replace(/(^|\s)\/(\S+)/g,(n,r,i)=>{const s=t.find(o=>o.name===i&&o.path);return s!=null&&s.path?`${r}[skill:${i}:${s.path}]`:n})}function lZ({api:e,cwd:t,sessionKey:n,onSend:r,disabled:i,onNewSession:s,onClearSession:o,tool:a,spawnableContacts:l=oZ,ensureRemotePersonas:c,remotePersonasByDeviceId:u}){const d=OS(n),[f,p]=g.useState((d==null?void 0:d.draft)??""),[m,v]=g.useState(!1),y=g.useRef(null),x=g.useRef(!1),_=g.useCallback(()=>{x.current=!0},[]),b=g.useCallback(()=>{x.current=!1},[]),w=Af(),{attachments:k,setAttachments:C,addFiles:N,removeAttachment:T,clearAttachments:L}=sZ({httpBaseUrl:w.httpBaseUrl,httpToken:w.httpToken,sessionId:n,initial:(d==null?void 0:d.attachments)??[]}),[P,O]=g.useState([]),[I,R]=g.useState(!1),[D,z]=g.useState(0),[$,F]=g.useState(!1),[j,B]=g.useState([]),[E,H]=g.useState(!1),[q,M]=g.useState(0),[re,oe]=g.useState(!1),[V,pe]=g.useState([]),[Oe,ie]=g.useState(!1),[Ae,Fe]=g.useState(null),[We,ge]=g.useState(!1),qe=g.useRef(null),Gt=g.useMemo(()=>{const ue=[];return s&&ue.push({name:"new",source:"builtin",description:"在当前目录下新建会话"}),o&&n&&ue.push({name:"clear",source:"builtin",description:"清除当前会话"}),ue},[s,o,n]),wt=g.useMemo(()=>[...Gt,...P],[Gt,P]),Rt=g.useMemo(()=>{const ue=f.match(/^\/(\S*)$/);return ue?ue[1]:null},[f]),ln=Rt!==null&&!$,Bt=g.useMemo(()=>Rt!==null?FR(wt,Rt):[],[wt,Rt]),at=g.useMemo(()=>{const ue=f.match(/^@(\S*)$/);return ue?ue[1]:null},[f]),Ue=at!==null&&!re,nt=g.useMemo(()=>Ae?((u==null?void 0:u.get(Ae.deviceId))??[]).map(Te=>({kind:"remote-persona",persona:Te,deviceId:Ae.deviceId})):[...j.map(ue=>({kind:"cc-agent",agent:ue})),...V.map(ue=>({kind:"persona",persona:ue})),...l.map(ue=>({kind:"contact",contact:ue}))],[Ae,u,j,V,l]),mt=g.useMemo(()=>at!==null?HR(nt,at):[],[nt,at]),Xt=g.useRef(f);g.useEffect(()=>{f!==Xt.current&&(F(!1),oe(!1),Xt.current=f)},[f]);const pn=g.useCallback(()=>{F(!0)},[]),U=g.useCallback(()=>{oe(!0)},[]),Q=g.useRef(f),ve=g.useRef(k);g.useEffect(()=>{Q.current=f},[f]),g.useEffect(()=>{ve.current=k},[k]);const Se=g.useRef(n);g.useEffect(()=>{const ue=Se.current;if(ue===n)return;BS(ue,{draft:Q.current,attachments:ve.current});const Te=OS(n);p((Te==null?void 0:Te.draft)??""),C((Te==null?void 0:Te.attachments)??[]),z(0),M(0),F(!1),oe(!1),Fe(null),qe.current=null,ge(!1),queueMicrotask(()=>{Te!=null&&Te.draft?UR(y.current):Vo(y.current)}),Se.current=n},[n,C]),g.useEffect(()=>()=>{BS(Se.current,{draft:Q.current,attachments:ve.current})},[]),g.useEffect(()=>{z(0)},[Rt]),g.useEffect(()=>{M(0)},[at]),g.useEffect(()=>{at===null&&Ae&&(Fe(null),qe.current=null,ge(!1))},[at,Ae]),g.useEffect(()=>{if(!ln||I)return;if(!e){R(!0);return}let ue=!1;return(async()=>{try{const Te=await e.skillsList(t,a);ue||(O(Te.skills??[]),R(!0))}catch{ue||R(!0)}})(),()=>{ue=!0}},[ln,I,e,t,a]),g.useEffect(()=>{if(!Ue||E)return;if(!e){H(!0);return}let ue=!1;return(async()=>{try{const Te=await e.agentsList(t,a);ue||(B(Te.agents??[]),H(!0))}catch{ue||H(!0)}})(),()=>{ue=!0}},[Ue,E,e,t,a]),g.useEffect(()=>{if(!Ue||Oe)return;if(!e){ie(!0);return}let ue=!1;return(async()=>{try{const Te=await e.personaList();ue||(pe((Te.personas??[]).map(Je=>({personaId:Je.personaId,label:Je.label,iconKey:Je.iconKey}))),ie(!0))}catch{ue||ie(!0)}})(),()=>{ue=!0}},[Ue,Oe,e]);const J=g.useCallback(ue=>{switch(ue.kind){case"persona":p(`@persona/${ue.persona.personaId} `);break;case"cc-agent":p(`@"${ue.agent.name} (agent)" `);break;case"contact":{const Te=ue.contact.deviceId;Fe({deviceId:Te,displayName:ue.contact.displayName}),qe.current=Te,ge(!0),Promise.resolve(c==null?void 0:c(Te)).finally(()=>{qe.current===Te&&ge(!1)}),p("@"),oe(!1),setTimeout(()=>{var Je;return(Je=y.current)==null?void 0:Je.focus()},0);return}case"remote-persona":p(`@persona/${ue.persona.personaId}@${ue.deviceId} `),Fe(null);break}oe(!1),setTimeout(()=>{var Te;return(Te=y.current)==null?void 0:Te.focus()},0)},[c]),Ye=g.useCallback(()=>{Fe(null),qe.current=null,ge(!1),p("@"),setTimeout(()=>{var ue;return(ue=y.current)==null?void 0:ue.focus()},0)},[]),Yt=g.useCallback(ue=>{if(ue.source==="builtin"&&ue.name==="new"&&s){p(""),L(),Vo(y.current),s(t);return}if(ue.source==="builtin"&&ue.name==="clear"&&o){p(""),L(),Vo(y.current),o();return}p(`/${ue.name} `),setTimeout(()=>{var Te;return(Te=y.current)==null?void 0:Te.focus()},0)},[s,t,L,o]),Zt=g.useCallback(async()=>{const ue=f.trim(),Te=k.filter(Je=>Je.status==="done");if(!(!ue&&Te.length===0)&&!(m||i)){if(ue==="/new"&&s){v(!0);try{await s(t),p(""),L(),Vo(y.current)}finally{v(!1)}return}if(ue==="/clear"&&o){v(!0);try{await o(),p(""),L(),Vo(y.current)}finally{v(!1)}return}v(!0);try{const Je=a==="codex"?aZ(ue,P):ue,Dn=fY(Je,k);await r(Dn),p(""),L(),Vo(y.current)}finally{v(!1)}}},[f,k,m,i,r,s,t,L,o,a,P]);return{draft:f,setDraft:p,sending:m,textareaRef:y,isComposingRef:x,onCompositionStart:_,onCompositionEnd:b,attachments:k,addFiles:N,removeAttachment:T,skillSelectorVisible:ln,filteredSkills:Bt,slashQuery:Rt??"",activeSkillIdx:D,setActiveSkillIdx:z,selectSkill:Yt,dismissSkillSelector:pn,agentSelectorVisible:Ue,filteredAgents:mt,mentionQuery:at,activeAgentIdx:q,setActiveAgentIdx:M,selectAgent:J,dismissAgentSelector:U,drilldown:Ae,drilldownLoading:We,exitDrilldown:Ye,doSend:Zt}}const cZ=120;function UR(e){e&&(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,cZ)}px`)}function Vo(e){e&&(e.style.height="auto")}const uZ={spawnableContacts:[],ensureRemotePersonas:()=>Promise.resolve(),remotePersonasByDeviceId:new Map},dZ=g.createContext(uZ);function hZ(){return g.useContext(dZ)}function fZ({url:e,fileName:t,onClose:n}){const[r,i]=g.useState(!1);g.useEffect(()=>{const o=a=>{a.key==="Escape"&&n()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[n]);const s=async()=>{try{const a=await(await fetch(e)).blob();await navigator.clipboard.write([new ClipboardItem({[a.type]:a})]),i(!0),setTimeout(()=>i(!1),2e3)}catch{zS(e,t)}};return h.jsx("div",{"data-testid":"image-lightbox",className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60",onClick:n,role:"dialog","aria-modal":"true",children:h.jsxs("div",{className:"relative",onClick:o=>o.stopPropagation(),children:[h.jsx("img",{src:e,alt:t,className:"max-h-[90vh] max-w-[92vw] rounded-lg object-contain shadow-2xl"}),h.jsxs("div",{className:"absolute right-2 top-2 flex items-center gap-1.5",children:[h.jsxs("button",{type:"button",onClick:s,"data-testid":"image-lightbox-copy",className:"flex cursor-pointer items-center gap-1 rounded-full border border-bg-300 bg-bg-50/95 px-2 py-0.5 text-[11px] font-medium text-text-200 shadow transition-colors hover:bg-bg-100",children:[h.jsx(su,{className:"h-3 w-3"}),r?"Copied":"Copy"]}),h.jsxs("button",{type:"button",onClick:()=>zS(e,t),"data-testid":"image-lightbox-save",className:"flex cursor-pointer items-center gap-1 rounded-full border border-bg-300 bg-bg-50/95 px-2 py-0.5 text-[11px] font-medium text-text-200 shadow transition-colors hover:bg-bg-100",children:[h.jsx(i6,{className:"h-3.5 w-3.5"}),"Save"]}),h.jsx("button",{type:"button",onClick:n,"data-testid":"image-lightbox-close","aria-label":"close",className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded-full border border-bg-300 bg-bg-50/95 text-text-300 transition-colors hover:bg-bg-100 hover:text-text-100",children:h.jsx(Rn,{className:"h-3 w-3"})})]})]})})}function zS(e,t){const n=document.createElement("a");n.href=e,n.download=t||"image",n.click()}function pZ({meta:e,api:t,cwd:n,tool:r,onSend:i,sessionKey:s,disabled:o=!1,placeholder:a,className:l,awaitingUser:c=!1,onAbort:u,onNewSession:d,onClearSession:f}){const p=(e==null?void 0:e.streamInProgress)??!1,m=g.useRef(null),v=hZ(),y=lZ({...t?{api:t}:{},cwd:n,...r?{tool:r}:{},sessionKey:s,onSend:i,disabled:o,...d?{onNewSession:d}:{},...f?{onClearSession:f}:{},spawnableContacts:v.spawnableContacts,ensureRemotePersonas:v.ensureRemotePersonas,remotePersonasByDeviceId:v.remotePersonasByDeviceId}),{draft:x,setDraft:_,sending:b,textareaRef:w,attachments:k,addFiles:C,removeAttachment:N,skillSelectorVisible:T,filteredSkills:L,slashQuery:P,activeSkillIdx:O,setActiveSkillIdx:I,selectSkill:R,dismissSkillSelector:D,agentSelectorVisible:z,filteredAgents:$,mentionQuery:F,activeAgentIdx:j,setActiveAgentIdx:B,selectAgent:E,dismissAgentSelector:H,drilldown:q,drilldownLoading:M,exitDrilldown:re,doSend:oe}=y,V=!!t,pe=b||o||p,ie=(x.trim().length>0||k.some(J=>J.status==="done"))&&!o&&!b&&!c,Ae=a??(c?"Answer the question above first...":pe?"Queue a message...":`Message ${$d(r)}...`),Fe=g.useRef(!1),We=g.useCallback(()=>{Fe.current=!0},[]),ge=g.useCallback(()=>{Fe.current=!1},[]),qe=g.useCallback(J=>{if(T&&L.length>0){if(J.key==="ArrowDown")return J.preventDefault(),I(O>=L.length-1?0:O+1),!0;if(J.key==="ArrowUp")return J.preventDefault(),I(O<=0?L.length-1:O-1),!0;if(J.key==="Tab"||J.key==="Enter"&&!J.shiftKey){J.preventDefault();const Ye=L[O];return Ye&&R(Ye),!0}if(J.key==="Escape")return J.preventDefault(),D(),!0}return!1},[T,L,O,I,R,D]),Gt=g.useCallback(J=>{if(z&&$.length>0){if(J.key==="ArrowDown")return J.preventDefault(),B(j>=$.length-1?0:j+1),!0;if(J.key==="ArrowUp")return J.preventDefault(),B(j<=0?$.length-1:j-1),!0;if(J.key==="Tab"||J.key==="Enter"&&!J.shiftKey){J.preventDefault();const Ye=$[j];return Ye&&E(Ye),!0}if(J.key==="Escape")return J.preventDefault(),q?re():H(),!0}return!1},[z,$,j,B,E,H,q,re]),wt=g.useCallback(J=>{const Ye=J.nativeEvent;J.key==="Enter"&&oI({compositionActive:Fe.current,nativeIsComposing:Ye.isComposing,keyCode:Ye.keyCode})||qe(J)||Gt(J)||aI({key:J.key,shiftKey:J.shiftKey,compositionActive:Fe.current,nativeIsComposing:Ye.isComposing,keyCode:Ye.keyCode})&&(J.preventDefault(),ie&&oe())},[qe,Gt,ie,oe]),Rt=g.useCallback(J=>{_(J.target.value),UR(J.target)},[_]),ln=g.useCallback(J=>{J.target.files&&C(J.target.files),J.target.value=""},[C]),Bt=g.useCallback(J=>{if(!V)return;const Ye=Array.from(J.clipboardData.items).map(Yt=>Yt.getAsFile()).filter(Yt=>!!(Yt&&Yt.type.startsWith("image/")));Ye.length!==0&&(J.preventDefault(),C(Ye))},[C,V]),[at,Ue]=g.useState(null),nt=g.useCallback(J=>{J.previewUrl&&Ue({url:J.previewUrl,name:J.fileName})},[]),[mt,Xt]=g.useState(!1),pn=g.useCallback(J=>{V&&(J.preventDefault(),Xt(!0))},[V]),U=g.useCallback(()=>Xt(!1),[]),Q=g.useCallback(J=>{V&&(J.preventDefault(),Xt(!1),J.dataTransfer.files.length>0&&C(J.dataTransfer.files))},[C,V]),ve=p&&!c&&typeof u=="function",Se=o||c;return h.jsxs("div",{"data-testid":"chat-input",className:ne("shrink-0 border-t border-bg-300/20 px-4 py-3",l),onDragOver:pn,onDragLeave:U,onDrop:Q,children:[h.jsxs("div",{className:"max-w-3xl mx-auto relative",children:[V?h.jsx("input",{ref:m,type:"file",multiple:!0,accept:ZY,hidden:!0,onChange:ln,"data-testid":"chat-input-file"}):null,h.jsxs("div",{"data-testid":"chat-input-bare",className:ne("flex flex-col gap-2"),children:[c||b||p?h.jsxs("div",{"data-testid":"chat-input-status-bar",className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsxs("div",{className:"flex gap-1",children:[h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"0ms"}}),h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"150ms"}}),h.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-text-400-dim-fg animate-bounce",style:{animationDelay:"300ms"}})]}),h.jsx("span",{children:c?"Waiting for your answer":`${r==="codex"?"Codex":"Claude"} is working`})]}):null,T?h.jsx(UY,{query:P,skills:L,activeIndex:O,onActiveIndexChange:I,onSelect:R}):null,z?q?!v.remotePersonasByDeviceId.has(q.deviceId)&&M?h.jsx("div",{"data-testid":"cc-agent-remote-loading",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 rounded-2xl border border-bg-300 bg-bg-50 px-4 py-3 text-[12px] text-text-300 shadow-lg",children:`正在加载 @${q.displayName} 的 persona…`}):$.length>0?h.jsx(DS,{query:F??"",entries:$,activeIndex:j,onActiveIndexChange:B,onSelect:E}):h.jsx("div",{"data-testid":"cc-agent-remote-empty",className:"absolute bottom-full left-0 right-0 z-50 mb-1.5 rounded-2xl border border-bg-300 bg-bg-50 px-4 py-3 text-[12px] text-text-300 shadow-lg",children:`@${q.displayName} 暂无可派活的 persona(可能离线或未公开)`}):h.jsx(DS,{query:F??"",entries:$,activeIndex:j,onActiveIndexChange:B,onSelect:E}):null,k.length>0?h.jsx(XY,{attachments:k,onRemove:N,onOpenPreview:nt}):null,h.jsxs("div",{"data-testid":"bare-chat-input-frame",className:ne("flex items-end gap-2 rounded-xl border border-bg-300 bg-bg-50 px-3 py-2 transition-colors duration-200",Se?"opacity-60":null,mt?"border-accent/60 bg-accent/5":null),children:[V?h.jsx("button",{type:"button",onClick:()=>{var J;return(J=m.current)==null?void 0:J.click()},disabled:pe,"data-testid":"chat-input-attach","aria-label":"attach files",className:ne("flex h-8 w-8 shrink-0 self-end items-center justify-center rounded-md transition-colors",pe?"cursor-default text-text-400/50":"cursor-pointer text-text-400 hover:bg-text-100/5 hover:text-text-200"),children:h.jsx(j6,{className:"h-4 w-4"})}):null,h.jsx("textarea",{ref:w,"data-testid":"chat-input-textarea",value:x,onChange:Rt,onKeyDown:wt,onCompositionStart:We,onCompositionEnd:ge,onPaste:Bt,placeholder:Ae,disabled:Se,readOnly:Se,rows:1,className:"flex-1 resize-none bg-transparent border-0 outline-none text-[14px] text-text-100 placeholder:text-text-400 leading-relaxed py-1 min-h-[22px] max-h-[120px] overflow-y-auto disabled:cursor-not-allowed"}),h.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 pb-0.5",children:[ve?h.jsx("button",{type:"button",onClick:u,"data-testid":"chat-input-abort","aria-label":"interrupt",title:"中断当前轮次(不杀进程)",className:"h-8 w-8 rounded-full flex items-center justify-center border border-text-400/40 text-text-400 hover:bg-text-100/5 hover:text-text-100 transition-colors cursor-pointer",children:h.jsx(HN,{className:"w-3.5 h-3.5",strokeWidth:2.5})}):null,h.jsx("button",{type:"button",onClick:()=>{ie&&oe()},disabled:!ie,"data-testid":"chat-input-send","aria-label":"send",className:ne("h-8 w-8 rounded-full flex items-center justify-center transition-colors",ie?"bg-accent text-white hover:bg-accent-hover cursor-pointer shadow-sm":"bg-[var(--text-400-dim)] text-[var(--text-400-dim-fg)] cursor-default"),children:h.jsx(PB,{className:"w-4 h-4",strokeWidth:2.5})})]})]})]})]}),at?h.jsx(fZ,{url:at.url,fileName:at.name,onClose:()=>Ue(null)}):null]})}function mZ(e){const t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n>=0?t.slice(n+1):t}function gZ({meta:e,tool:t,connState:n,onOpenConfig:r,models:i,liveGitBranch:s,liveWorktreeRoot:o,onForceStop:a,cronActiveCount:l,onCronClick:c,onOpenFiles:u,onTogglePin:d,isHolded:f=!1,onToggleHold:p,personaName:m,onOpenPersona:v,className:y}){const x=e.procAlive??!1,_=e.streamInProgress??!1,b=e.permissionMode,w=b&&b!=="default"?b:null,k=w==="bypassPermissions"?"YOLO":w==="plan"?"Plan":null,C=e.model??"",N=vZ(i,C),T=e.contextPct??null,L=T==null?"":T>=80?"text-red-400":T>=50?"text-amber-400":"text-text-500",P=s!==void 0?s:e.gitBranch??null,O=o??e.cwd??"",R=!!e.sessionLabel&&e.sessionLabel!==e.sessionId?e.sessionLabel:mZ(O),D=O,z=e.pinnedAt!=null;return h.jsxs("div",{"data-testid":"chat-header",className:ne("relative flex flex-col justify-center shrink-0 px-4 pr-14 py-2 gap-1",y),children:[h.jsxs("div",{className:"flex items-center min-w-0 gap-2 text-[13px]",children:[d?h.jsx("button",{type:"button",onClick:()=>d(!z),"data-testid":"chat-header-pin-toggle","data-pinned":z?"true":"false","aria-pressed":z,title:z?"Unpin session":"Pin session",className:ne("shrink-0 inline-flex items-center justify-center h-5 w-5 rounded-md cursor-pointer transition-colors",z?"text-amber-400 hover:bg-amber-500/10":"text-text-500 hover:text-text-200 hover:bg-text-100/5"),children:h.jsx(WN,{className:ne("w-3.5 h-3.5",z&&"fill-current")})}):null,p?h.jsx("button",{type:"button",onClick:()=>p(!f),"data-testid":"chat-header-hold-toggle","data-holded":f?"true":"false","aria-pressed":f,title:f?"Release hold":"Hold session",className:ne("shrink-0 inline-flex items-center justify-center h-5 w-5 rounded-md cursor-pointer transition-colors",f?"text-amber-400 hover:bg-amber-500/10":"text-text-500 hover:text-text-200 hover:bg-text-100/5"),children:h.jsx(BB,{className:ne("w-3.5 h-3.5",f&&"fill-current")})}):null,h.jsx("span",{className:"font-semibold text-text-100 truncate","data-testid":"chat-header-worktree",title:D,children:R}),P?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-text-500 shrink-0",children:":"}),h.jsx("span",{className:"font-mono text-text-300 truncate","data-testid":"chat-header-git",title:P,children:P})]}):null]}),h.jsxs("div",{className:"flex items-center min-w-0 gap-2 text-[11px]",children:[k?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",onClick:()=>r==null?void 0:r("desktop"),"data-testid":"chat-header-mode-chip",className:ne("hidden md:inline-flex shrink-0 px-2 py-0.5 rounded-md font-semibold cursor-pointer transition-colors",w==="bypassPermissions"?"bg-red-500/15 text-red-400 hover:bg-red-500/25":"bg-blue-500/15 text-blue-400 hover:bg-blue-500/25"),children:k}),h.jsx("button",{type:"button",onClick:()=>r==null?void 0:r("mobile"),"aria-hidden":"true",tabIndex:-1,className:ne("inline-flex md:hidden shrink-0 px-2 py-0.5 rounded-md font-semibold cursor-pointer transition-colors",w==="bypassPermissions"?"bg-red-500/15 text-red-400 hover:bg-red-500/25":"bg-blue-500/15 text-blue-400 hover:bg-blue-500/25"),children:k})]}):null,C||i?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button",onClick:()=>r==null?void 0:r("desktop"),"data-testid":"chat-header-model-chip",className:"hidden md:inline-flex shrink-0 font-mono text-text-400 cursor-pointer hover:text-text-200 transition-colors",children:N}),h.jsx("button",{type:"button",onClick:()=>r==null?void 0:r("mobile"),"aria-hidden":"true",tabIndex:-1,className:"inline-flex md:hidden shrink-0 font-mono text-text-400 cursor-pointer hover:text-text-200 transition-colors",children:N})]}):null,T!=null?h.jsxs("span",{className:ne("shrink-0 font-mono",L),"data-testid":"chat-header-ctx",children:["ctx:",T,"%"]}):null,h.jsxs("span",{"data-testid":"chat-header-proc-status",className:"inline-flex items-center gap-1 text-text-500 shrink-0",title:_?`${$d(t)} 正在跑当前 turn`:x?`${$d(t)} 进程仍活,等下一轮输入`:`${$d(t)} 进程未运行(发送消息会自动启动)`,children:[h.jsx("span",{className:ne("w-1.5 h-1.5 rounded-full",_?"bg-green-500":"bg-text-400/50")}),h.jsx("span",{children:_?"running":"idle"})]}),x&&a?h.jsxs("button",{type:"button",onClick:a,"data-testid":"chat-header-force-stop",title:t==="codex"?"强制停止 Codex 进程":"强制停止 Claude Code 进程(会丢失 initialize / 预热缓存)",className:"shrink-0 inline-flex items-center gap-1 h-5 px-2 rounded-md text-text-400 hover:bg-red-500/10 hover:text-red-400 transition-colors cursor-pointer",children:[h.jsx(M6,{className:"w-3 h-3"}),h.jsx("span",{children:"Stop"})]}):null,m&&v||u||l&&l>0&&c?h.jsx("span",{className:"text-text-500 shrink-0","aria-hidden":"true",children:"·"}):null,m&&v?h.jsxs("button",{type:"button",onClick:v,"data-testid":"chat-header-persona",title:m,className:"shrink-0 inline-flex items-center gap-1 h-5 px-2 rounded-md text-text-300 hover:bg-bg-200 hover:text-text-100 transition-colors cursor-pointer",children:[h.jsx(Yx,{className:"w-3 h-3"}),h.jsx("span",{className:"truncate max-w-[80px] md:max-w-[120px]",children:m})]}):null,u?h.jsxs("button",{type:"button",onClick:u,"data-testid":"chat-header-files",title:"Edited Files",className:"shrink-0 inline-flex items-center gap-1 h-5 px-2 rounded-md text-text-300 hover:bg-bg-200 hover:text-text-100 transition-colors cursor-pointer",children:[h.jsx(d6,{className:"w-3 h-3"}),h.jsx("span",{className:"hidden md:inline",children:"Edited Files"})]}):null,l&&l>0&&c?h.jsxs("button",{type:"button","data-testid":"chat-header-cron-button",onClick:c,"aria-label":"Cron tasks",title:`${l} active cron task${l===1?"":"s"}`,className:"shrink-0 inline-flex items-center gap-1 h-5 px-2 rounded-md text-text-400 hover:bg-accent-dim hover:text-accent transition-colors cursor-pointer",children:[h.jsx(ZB,{className:"w-3 h-3"}),h.jsx("span",{"data-testid":"chat-header-cron-badge",className:"font-mono",children:l})]}):null]}),r?h.jsxs(h.Fragment,{children:[h.jsx("button",{type:"button","aria-label":"Session settings","data-testid":"chat-header-settings",onClick:()=>r("desktop"),title:"Session settings",className:"hidden md:flex absolute right-4 top-3 z-10 h-7 w-7 items-center justify-center rounded-md bg-transparent text-text-300 transition-colors duration-150 hover:bg-bg-200 hover:text-text-100 cursor-pointer outline-none",children:h.jsx(kv,{className:"w-4 h-4"})}),h.jsx("button",{type:"button","aria-label":"Session settings","data-testid":"chat-header-settings-mobile",onClick:()=>r("mobile"),title:"Session settings",className:"flex md:hidden absolute right-4 top-3 z-10 h-7 w-7 items-center justify-center rounded-md bg-transparent text-text-300 transition-colors duration-150 hover:bg-bg-200 hover:text-text-100 cursor-pointer outline-none",children:h.jsx(kv,{className:"w-4 h-4"})})]}):null]})}function vZ(e,t){if(!t)return"default";const n=t.toLowerCase(),r=[["opus","Opus"],["sonnet","Sonnet"],["haiku","Haiku"]];for(const[a,l]of r){if(!n.includes(a))continue;const c=n.match(new RegExp(`${a}-(\\d+)-(\\d+)`));return c?`${l} ${c[1]}.${c[2]}`:l}const i=e??[],s=i.find(a=>a.id===t);if(s)return s.label;const o=i.find(a=>a.id&&t.toLowerCase().includes(a.id.toLowerCase()));return o?o.label:t}function xZ(e){return e==="TodoWrite"}function _Z(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 yZ(e,t,n){var s;const r=[],i=new Map;for(let o=0;o<e.length;o++){const a=e[o],l=typeof a.seq=="number"?a.seq:o;switch(a.kind){case"session_init":r.push({kind:"session-init",seq:l,toolSessionId:a.toolSessionId});break;case"text":$S(r,l,"assistant-text",a.text,a.partialId,a.uuid);break;case"thinking":$S(r,l,"assistant-thinking",a.text,a.partialId);break;case"user_text":{a.meta==="task-notification"?r.push({kind:"agent-notification",seq:l,text:a.text,taskId:a.taskId,parentToolUseId:a.parentToolUseId}):a.meta?r.push({kind:"user-meta",seq:l,metaKind:a.meta,text:a.text}):r.push({kind:"user-text",seq:l,text:a.text,uuid:a.uuid,senderDisplayName:(s=a.sender)==null?void 0:s.displayName});break}case"tool_call":WR(r,l,a.toolUseId,a.tool,a.input,a.toolKind);break;case"tool_result":{const c=i.get(a.toolUseId);if(c!==void 0){if(a.askQuestionAnswers){const d=r[c];d.submittedAnswers=a.askQuestionAnswers}i.delete(a.toolUseId);break}const u={kind:"tool-result",seq:l,toolUseId:a.toolUseId,output:a.output,error:a.error};a.toolResultExtra&&(u.toolResultExtra=a.toolResultExtra),r.push(u);break}case"attachment_memories":r.push({kind:"memory-callout",seq:l,memories:a.memories});break;case"permission_request":{if(!t||a.requestId!==t)break;r.push({kind:"permission-inline",seq:l,requestId:a.requestId,tool:a.tool,input:a.input});break}case"ask_user_question":i.set(a.toolUseId,r.length),r.push({kind:"question-card",seq:l,toolUseId:a.toolUseId,questions:a.questions});break;case"turn_end":r.push({kind:"turn-end",seq:l});break;case"subagent_progress":{const c={kind:"agent-progress",seq:l,toolUseId:a.toolUseId,agentId:a.agentId,status:a.status};a.description&&(c.description=a.description),a.lastToolName&&(c.lastToolName=a.lastToolName),a.prompt&&(c.prompt=a.prompt),a.stats&&(c.stats=a.stats),r.push(c);break}case"error":r.push({kind:"error",seq:l,message:a.message});break}}return r}function WR(e,t,n,r,i,s){if(xZ(r)){const o=_Z(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(A7(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 $S(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 bZ="AskUserQuestion";function VR(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=(o=PO.exec(a.text??""))==null?void 0:o[1];r.push({kind:"user-text",seq:l,text:a.text??"",uuid:a.uuid,...u?{senderDisplayName:u}:{}})}break;case"assistant-text":r.push({kind:"assistant-text",seq:l,text:a.text??"",uuid:a.uuid});break;case"tool_call":{if(a.tool===bZ){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}WR(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}}return r}function wZ({api:e,cwd:t,toolSessionId:n}){const r=BR(),i=(r==null?void 0:r.state.agentId)??null,s=r==null?void 0:r.state.agentType,[o,a]=g.useState([]),[l,c]=g.useState(!1),[u,d]=g.useState(null);g.useEffect(()=>{if(!i)return;let p=!1;return c(!0),d(null),a([]),e.historySubagentRead({cwd:t,toolSessionId:n,subagentId:i}).then(m=>{p||a(m.messages??[])}).catch(m=>{p||d(m instanceof Error?m.message:String(m))}).finally(()=>{p||c(!1)}),()=>{p=!0}},[i,t,n,e]);const f=g.useMemo(()=>o.length>0?VR(o,0,"claude"):[],[o]);return!r||!i?null:h.jsxs("div",{"data-testid":"subagent-drawer","data-agent-id":i,className:ne("fixed inset-y-0 right-0 z-50 w-[min(560px,92vw)]","flex flex-col border-l border-bg-200/60 bg-bg-50 shadow-xl"),style:{paddingTop:"env(safe-area-inset-top)"},children:[h.jsxs("div",{className:"flex flex-col gap-0.5 px-3 py-2 border-b border-bg-200/60",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s?h.jsx("span",{className:"inline-flex items-center rounded-sm bg-violet-500/10 px-1.5 py-0.5 text-[11px] text-violet-400 font-medium",children:s}):null,h.jsx("span",{className:"font-mono text-[11px] text-text-400 truncate",title:i,children:i})]}),h.jsx("button",{type:"button","aria-label":"关闭",onClick:()=>r.close(),className:"p-1 rounded hover:bg-bg-200/50 text-text-400 hover:text-text-200",children:h.jsx(Rn,{className:"w-4 h-4"})})]}),!l&&!u&&o.length>0?h.jsxs("div",{className:"text-[11px] text-text-400",children:[o.length," 条消息 · 首条为主会话派发的任务指令"]}):null]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden px-3 py-2",children:l?h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsx(rr,{className:"w-3.5 h-3.5 animate-spin"}),h.jsx("span",{children:"加载中…"})]}):u?h.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-error",children:[h.jsx(Rs,{className:"w-3.5 h-3.5"}),h.jsx("span",{children:u})]}):f.length===0?h.jsx("div",{className:"text-[12px] text-text-400 italic",children:"无消息"}):h.jsx($R,{lines:f})})]})}function FS(e,t){let n=0;for(const r of e.lines)r.startsWith(t)&&n++;return n}function SZ(e,t){const n=e.findIndex(c=>c.kind==="user-text"&&c.uuid===t);if(n<0)return{userMessageId:t,files:[],totalInsertions:0,totalDeletions:0,anchorFound:!1};let r=e.length;for(let c=n+1;c<e.length;c++)if(e[c].kind==="user-text"){r=c;break}const i=[],s=new Map;for(let c=n+1;c<r;c++){const u=e[c];if(u.kind!=="tool-result")continue;const d=u.toolResultExtra;if(!(d!=null&&d.filePath)||!d.structuredPatch||d.structuredPatch.length===0)continue;const f=d.filePath;let p=s.get(f);p||(p={filePath:f,hunks:[],insertions:0,deletions:0},s.set(f,p),i.push(f));for(const m of d.structuredPatch)p.hunks.push(m),p.insertions+=FS(m,"+"),p.deletions+=FS(m,"-")}const o=i.map(c=>s.get(c)),a=o.reduce((c,u)=>c+u.insertions,0),l=o.reduce((c,u)=>c+u.deletions,0);return{userMessageId:t,files:o,totalInsertions:a,totalDeletions:l,anchorFound:!0}}function kZ({open:e,onOpenChange:t,api:n,sessionId:r,userMessageId:i,lines:s,procAlive:o,onApplied:a,onNoChanges:l}){const c=g.useMemo(()=>SZ(s,i),[s,i]),[u,d]=g.useState(null),[f,p]=g.useState(!1),[m,v]=g.useState(!1),[y,x]=g.useState(null);g.useEffect(()=>{if(!e)return;let C=!1;return p(!0),d(null),(async()=>{try{const N=await n.sessionRewindDiff({sessionId:r,userMessageId:i});C||(d(N),!N.canRewind&&!N.error&&N.files.length===0&&(l==null||l(i)))}catch{C||d(null)}finally{C||p(!1)}})(),()=>{C=!0}},[e,n,r,i]);const _=g.useMemo(()=>{if(u){const C=!u.canRewind&&!u.error&&u.files.length===0;if(u.canRewind||C)return{source:"rpc",anchorFound:!0,files:u.files.map(N=>({filePath:N.filePath,hunks:N.hunks,insertions:N.insertions,deletions:N.deletions})),totalInsertions:u.totalInsertions,totalDeletions:u.totalDeletions}}return{source:"local",anchorFound:c.anchorFound,files:c.files,totalInsertions:c.totalInsertions,totalDeletions:c.totalDeletions,rpcError:u==null?void 0:u.error}},[u,c]),b=g.useCallback(async()=>{v(!0),x(null);try{const C=await n.sessionRewind({sessionId:r,userMessageId:i,dryRun:!1});if(!C.canRewind){x(C.error??"回退失败");return}a==null||a(),t(!1)}catch(C){x(C.message||"回退失败")}finally{v(!1)}},[n,r,i,a,t]);if(!e)return null;const w=_.files.length>0,k=!f&&!m&&_.anchorFound&&w&&!y;return h.jsxs("div",{"data-testid":"rewind-preview-drawer",className:"fixed right-0 top-0 bottom-0 z-40 flex flex-col border-l border-bg-300/40 bg-bg-0 shadow-xl",style:{width:480,minWidth:480},children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bg-300/30 shrink-0",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(qN,{className:"w-4 h-4 text-text-300"}),h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Rewind 预览"})]}),h.jsx("button",{type:"button",onClick:()=>t(!1),"data-testid":"rewind-drawer-close",className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:bg-text-100/5 hover:text-text-200 cursor-pointer","aria-label":"close",children:h.jsx(Rn,{className:"w-4 h-4"})})]}),y?h.jsxs("div",{"data-testid":"rewind-error-banner",className:"mx-4 mt-3 flex items-start gap-2 rounded-md border border-red-400/40 bg-red-500/10 px-3 py-2 text-[12px] text-red-400",children:[h.jsx(jc,{className:"w-4 h-4 shrink-0 mt-0.5"}),h.jsx("span",{children:y})]}):null,h.jsx("div",{className:"flex-1 overflow-y-auto px-4 py-3 space-y-3",children:f?h.jsxs("div",{"data-testid":"rewind-loading",className:"flex items-center gap-2 text-[12px] text-text-400",children:[h.jsx(rr,{className:"w-3.5 h-3.5 animate-spin"}),h.jsx("span",{children:"正在读取快照…"})]}):_.anchorFound?w?h.jsxs(h.Fragment,{children:[h.jsxs("div",{"data-testid":"rewind-summary",className:"rounded-md border border-bg-300 bg-bg-100/40 px-3 py-2 text-[12px] text-text-200",children:[h.jsxs("div",{children:["将回退 ",h.jsx("span",{className:"font-semibold text-text-100",children:_.files.length})," ","个文件,",h.jsxs("span",{className:"text-green-500 font-mono",children:["+",_.totalInsertions]})," / ",h.jsxs("span",{className:"text-red-400 font-mono",children:["-",_.totalDeletions]})]}),_.source==="local"?h.jsx("div",{"data-testid":"rewind-source-hint",className:"mt-1 text-text-400 text-[11px]",children:"基于对话里 tool_result 估算(未读到 CC 快照,数字可能与实际磁盘略有差异)"}):null]}),_.files.map(C=>h.jsx(EZ,{file:C},C.filePath))]}):h.jsxs("div",{"data-testid":"rewind-no-changes",className:"rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300 space-y-1",children:[h.jsx("div",{children:"磁盘上的文件已经和这个时刻的快照完全一致——没有需要回退的改动。"}),h.jsx("div",{className:"text-text-400 text-[11px]",children:"可能这条消息之后 Claude 没落盘编辑,或之前已经 rewind 过了。"})]}):h.jsx("div",{"data-testid":"rewind-no-anchor",className:"rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300",children:"未能在当前消息流中找到对应的用户消息(可能已被历史裁剪)。"})}),h.jsxs("div",{className:"flex flex-col gap-2 px-4 py-3 border-t border-bg-300/30 shrink-0",children:[w&&_.anchorFound&&!o?h.jsxs("div",{"data-testid":"rewind-needs-cc",className:"flex items-start gap-2 rounded-md border border-bg-300 bg-bg-100/60 px-3 py-2 text-[12px] text-text-300",children:[h.jsx(jc,{className:"w-4 h-4 shrink-0 mt-0.5 text-warning"}),h.jsx("span",{children:'Claude Code 进程当前未运行。点击"确认回退"时会自动启动它再执行 — 可能需要等一两秒。'})]}):null,h.jsxs("div",{className:"flex items-center justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:()=>t(!1),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",disabled:!k,onClick:()=>void b(),"data-testid":"rewind-apply",className:ne("h-8 px-3 rounded-md text-[12px] font-medium transition-colors",k?"bg-accent text-white hover:bg-accent-hover cursor-pointer":"bg-bg-200 text-text-400 cursor-not-allowed"),children:m?"回退中…":"确认回退"})]})]})]})}function CZ(e){return e.replace(/^\/Users\/[^/]+/,"~")}function EZ({file:e}){const[t,n]=g.useState(!0);return h.jsxs("div",{"data-testid":"rewind-file-block","data-file":e.filePath,className:"rounded-md border border-bg-300 overflow-hidden bg-bg-0",children:[h.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"w-full flex items-center gap-1.5 px-3 py-2 text-[12px] hover:bg-text-100/5 cursor-pointer",children:[t?h.jsx(li,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}):h.jsx(ci,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),h.jsx("span",{className:"font-mono text-text-200 truncate flex-1 text-left",title:e.filePath,children:CZ(e.filePath)}),h.jsxs("span",{className:"font-mono shrink-0 text-text-400",children:[h.jsxs("span",{className:"text-green-500",children:["+",e.insertions]})," ",h.jsxs("span",{className:"text-red-400",children:["-",e.deletions]})]})]}),t?h.jsx("div",{className:"border-t border-bg-300",children:e.hunks.map(r=>h.jsx(NZ,{hunk:r},`${r.oldStart}-${r.oldLines}-${r.newStart}-${r.newLines}`))}):null]})}function NZ({hunk:e}){const t=`@@ -${e.oldStart},${e.oldLines} +${e.newStart},${e.newLines} @@`;return h.jsxs("div",{className:"text-[11px] font-mono leading-relaxed",children:[h.jsx("div",{className:"px-3 py-1 text-text-400 bg-bg-100/40 border-b border-bg-300",children:t}),e.lines.map((n,r)=>{const i=n.charAt(0),s=i==="+"?"bg-green-500/10 text-green-300":i==="-"?"bg-red-500/10 text-red-300":"text-text-300";return h.jsx("div",{className:ne("px-3 whitespace-pre",s),children:n.length>0?n:" "},r)})]})}var ip="Dialog",[qR]=No(ip),[TZ,Or]=qR(ip),KR=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:s,modal:o=!0}=e,a=g.useRef(null),l=g.useRef(null),[c,u]=Lf({prop:r,defaultProp:i??!1,onChange:s,caller:ip});return h.jsx(TZ,{scope:t,triggerRef:a,contentRef:l,contentId:no(),titleId:no(),descriptionId:no(),open:c,onOpenChange:u,onOpenToggle:g.useCallback(()=>u(d=>!d),[u]),modal:o,children:n})};KR.displayName=ip;var GR="DialogTrigger",PZ=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(GR,n),s=qt(t,i.triggerRef);return h.jsx(Et.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":ey(i.open),...r,ref:s,onClick:Pe(e.onClick,i.onOpenToggle)})});PZ.displayName=GR;var Q_="DialogPortal",[IZ,XR]=qR(Q_,{forceMount:void 0}),YR=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:i}=e,s=Or(Q_,t);return h.jsx(IZ,{scope:t,forceMount:n,children:g.Children.map(r,o=>h.jsx($i,{present:n||s.open,children:h.jsx(l_,{asChild:!0,container:i,children:o})}))})};YR.displayName=Q_;var qh="DialogOverlay",ZR=g.forwardRef((e,t)=>{const n=XR(qh,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,s=Or(qh,e.__scopeDialog);return s.modal?h.jsx($i,{present:r||s.open,children:h.jsx(MZ,{...i,ref:t})}):null});ZR.displayName=qh;var RZ=Dc("DialogOverlay.RemoveScroll"),MZ=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(qh,n);return h.jsx(c_,{as:RZ,allowPinchZoom:!0,shards:[i.contentRef],children:h.jsx(Et.div,{"data-state":ey(i.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),_o="DialogContent",QR=g.forwardRef((e,t)=>{const n=XR(_o,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,s=Or(_o,e.__scopeDialog);return h.jsx($i,{present:r||s.open,children:s.modal?h.jsx(AZ,{...i,ref:t}):h.jsx(jZ,{...i,ref:t})})});QR.displayName=_o;var AZ=g.forwardRef((e,t)=>{const n=Or(_o,e.__scopeDialog),r=g.useRef(null),i=qt(t,n.contentRef,r);return g.useEffect(()=>{const s=r.current;if(s)return ZT(s)},[]),h.jsx(JR,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Pe(e.onCloseAutoFocus,s=>{var o;s.preventDefault(),(o=n.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Pe(e.onPointerDownOutside,s=>{const o=s.detail.originalEvent,a=o.button===0&&o.ctrlKey===!0;(o.button===2||a)&&s.preventDefault()}),onFocusOutside:Pe(e.onFocusOutside,s=>s.preventDefault())})}),jZ=g.forwardRef((e,t)=>{const n=Or(_o,e.__scopeDialog),r=g.useRef(!1),i=g.useRef(!1);return h.jsx(JR,{...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()}})}),JR=g.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:s,...o}=e,a=Or(_o,n),l=g.useRef(null),c=qt(t,l);return vT(),h.jsxs(h.Fragment,{children:[h.jsx(Jx,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:s,children:h.jsx(Of,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":ey(a.open),...o,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),h.jsxs(h.Fragment,{children:[h.jsx(DZ,{titleId:a.titleId}),h.jsx(OZ,{contentRef:l,descriptionId:a.descriptionId})]})]})}),J_="DialogTitle",eM=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(J_,n);return h.jsx(Et.h2,{id:i.titleId,...r,ref:t})});eM.displayName=J_;var tM="DialogDescription",nM=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(tM,n);return h.jsx(Et.p,{id:i.descriptionId,...r,ref:t})});nM.displayName=tM;var rM="DialogClose",iM=g.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,i=Or(rM,n);return h.jsx(Et.button,{type:"button",...r,ref:t,onClick:Pe(e.onClick,()=>i.onOpenChange(!1))})});iM.displayName=rM;function ey(e){return e?"open":"closed"}var sM="DialogTitleWarning",[Xne,oM]=o$(sM,{contentName:_o,titleName:J_,docsSlug:"dialog"}),DZ=({titleId:e})=>{const t=oM(sM),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
522
522
 
523
523
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
524
524
 
@@ -559,4 +559,4 @@ WARNING: This link could potentially be dangerous`)){let n=window.open();if(n){t
559
559
  * Fabrice Bellard's javascript vt100 for jslinux:
560
560
  * http://bellard.org/jslinux/
561
561
  * Copyright (c) 2011 Fabrice Bellard
562
- */var ete=2,tte=1,nte=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){var d;if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:((d=this._terminal.options.overviewRuler)==null?void 0:d.width)||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue("height")),i=Math.max(0,parseInt(n.getPropertyValue("width"))),s=window.getComputedStyle(this._terminal.element),o={top:parseInt(s.getPropertyValue("padding-top")),bottom:parseInt(s.getPropertyValue("padding-bottom")),right:parseInt(s.getPropertyValue("padding-right")),left:parseInt(s.getPropertyValue("padding-left"))},a=o.top+o.bottom,l=o.right+o.left,c=r-a,u=i-l-t;return{cols:Math.max(ete,Math.floor(u/e.css.cell.width)),rows:Math.max(tte,Math.floor(c/e.css.cell.height))}}};let Om;function Bm(){return{count:0,byteSum:0,firstT:null,lastT:null}}const zm=32,Lk=320;function rte({sessionId:e,client:t}){const n=g.useRef(null),r=g.useRef(null),i=g.useRef(null),s=g.useRef([]),o=g.useRef(Bm()),a=g.useRef(!1),[l,c]=g.useState("collapsed"),[u,d]=g.useState(null);g.useEffect(()=>{const v=n.current;if(!v)return;let y=!1;const x=(N,T)=>getComputedStyle(document.documentElement).getPropertyValue(N).trim()||T,_=x("--bg-0","#1B1B1B"),b=x("--text-100","#ECECEC"),w=new Jee({fontFamily:"ui-monospace, SF Mono, Menlo, monospace",fontSize:12,lineHeight:1.2,theme:{background:_,foreground:b},minimumContrastRatio:4.5,cursorBlink:!0,convertEol:!1,scrollback:5e3,allowProposedApi:!0,cols:120,rows:40}),k=new nte;w.loadAddon(k),Re("xterm-mount",{sessionId:e,hostChildCount:v.childNodes.length}),Om!==e&&(Re("xterm-trace",`===== SWITCH ${Om??"(initial)"} → ${e} =====`),Om=e),Re("xterm-trace","effect-setup-start",{sessionId:e,t:performance.now()}),o.current=Bm(),w.open(v);const C=w.onData(N=>{const T=btoa(unescape(encodeURIComponent(N)));t.request("session:pty:input",{sessionId:e,data:T}).catch(()=>{})});return(async()=>{var R;let N=0,T=null,L=null;try{Re("xterm-trace","snapshot-rpc-start",{sessionId:e,t:performance.now()});const D=await t.request("session:pty:snapshot",{sessionId:e});if(Re("xterm-trace","snapshot-rpc-resolved",{sessionId:e,cancelled:y,byteLen:((R=D==null?void 0:D.data)==null?void 0:R.length)??0,atSeq:D==null?void 0:D.atSeq,t:performance.now()}),y)return;if(D!=null&&D.ok&&typeof D.data=="string"&&D.data.length>0){const z=atob(D.data),$=new Uint8Array(z.length);for(let F=0;F<z.length;F++)$[F]=z.charCodeAt(F);T=$}D!=null&&D.ok&&typeof D.atSeq=="number"&&(N=D.atSeq),D!=null&&D.ok&&D.popupKind!=null&&(L=D.popupKind)}catch{}if(y)return;r.current=w,i.current=k;let P=!1,O;const I=w.onRender(()=>{if(!P){P=!0;try{k.fit(),T&&w.write(T),Re("xterm-trace","snapshot-flush",{sessionId:e,atSeq:N,pendingFrameCount:s.current.length,frameStatsBeforeFlush:{...o.current},t:performance.now()}),o.current=Bm();const D=s.current;s.current=[];let z=0;for(const $ of D){if($.seq!==void 0&&$.seq<=N){z++;continue}w.write($.bytes)}z>0&&Re("xterm-trace","snapshot-flush-dropped",{sessionId:e,dropped:z,atSeq:N}),a.current=!0,L!=null&&(d(L),c("expanded"),requestAnimationFrame(()=>w.focus())),t.request("session:pty:resize",{sessionId:e,cols:w.cols,rows:w.rows}).catch(()=>{})}catch{}w.scrollToBottom(),O?O():setTimeout(()=>O==null?void 0:O(),0)}});O=()=>I.dispose()})(),()=>{Re("xterm-trace","cleanup-start",{sessionId:e,pendingFrameCount:s.current.length,termReady:a.current,frameStatsThisMount:{...o.current},t:performance.now()}),y=!0,C.dispose(),w.dispose(),r.current=null,i.current=null,a.current=!1,s.current=[],Re("xterm-trace","cleanup-cleared-pending",{sessionId:e,t:performance.now()})}},[e,t]),g.useEffect(()=>{const v=t.on("session:pty",x=>{const _=x;if(_.sessionId!==e||typeof _.data!="string")return;const b=o.current;b.count++,b.byteSum+=_.data.length;const w=performance.now();b.firstT===null&&(b.firstT=w),b.lastT=w;try{const k=atob(_.data),C=new Uint8Array(k.length);for(let N=0;N<k.length;N++)C[N]=k.charCodeAt(N);a.current&&r.current?r.current.write(C):s.current.push({seq:_.seq,bytes:C})}catch{}}),y=t.on("session:control",x=>{const _=x;if(_.sessionId===e)switch(_.kind){case"popup_open":(_.popupKind==="permission"||_.popupKind==="question")&&(d(_.popupKind),c("expanded"),requestAnimationFrame(()=>{var b;return(b=r.current)==null?void 0:b.focus()}));break;case"popup_close":d(null),c("collapsed");break}});return()=>{v(),y(),Re("xterm-trace","cleanup-off-listener",{sessionId:e,t:performance.now()})}},[e,t]),g.useEffect(()=>{const v=n.current;if(!v)return;let y=0,x=0;const _=()=>{const w=i.current,k=r.current;if(!(!w||!k)){try{w.fit()}catch{return}try{k.refresh(0,k.rows-1)}catch{}k.cols===y&&k.rows===x||(y=k.cols,x=k.rows,t.request("session:pty:resize",{sessionId:e,cols:k.cols,rows:k.rows}).catch(()=>{}))}},b=new ResizeObserver(()=>_());return b.observe(v),()=>b.disconnect()},[e,t]);const f=()=>{c(v=>{const y=v==="collapsed"?"expanded":"collapsed";return y==="expanded"&&requestAnimationFrame(()=>{var x;return(x=r.current)==null?void 0:x.focus()}),y})},p=l==="expanded"?Lk:zm,m=Lk-zm;return h.jsxs("div",{className:"border-t border-border bg-bg-0 overflow-hidden",style:{height:p},"data-testid":"xterm-panel","data-state":l,"data-mode":"tui","data-popup-kind":u??"",children:[h.jsxs("button",{type:"button",onClick:f,className:"flex items-center justify-between w-full px-3 py-1 text-xs text-text-200 bg-bg-200 hover:bg-bg-300 cursor-pointer border-b border-border",style:{height:zm,flexShrink:0},"data-testid":"xterm-panel-toggle",children:[h.jsxs("span",{className:"font-mono",children:[u==="permission"&&"⚠️ CC 需要权限确认 — 在下方终端按数字键 / Enter 选择",u==="question"&&"❓ CC 在问问题 — 在下方终端用 ↑/↓ + Enter 选择",u===null&&(l==="collapsed"?"▴ 展开原生 TUI 终端":"▾ 收起 TUI 终端")]}),h.jsx("span",{className:"text-text-200 text-[10px] opacity-60",children:l==="expanded"?"点击收起":"点击展开"})]}),h.jsx("div",{ref:n,className:"p-1",style:{height:m},"data-testid":"xterm-panel-host"})]})}function sA(e,t){const n=Co(),r=e?`session/${e}`:"",i=si(r)??Mc,s=g.useCallback(d=>{!e||!r||n.setData(r,f=>IN(f??Mc,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 my(e){const t=si(e?`capabilities/${e}`:"");return e?{capabilities:t??null,loading:!t}:{capabilities:null,loading:!1}}const ite=50;function ste({api:e,sessionId:t,toolSessionId:n,pageSize:r=ite}){const[i,s]=g.useState({messages:[],total:0,loading:!1,hasMore:!1,error:null}),o=g.useRef(0),a=g.useRef(n),l=g.useRef(null),c=g.useRef(0);g.useEffect(()=>{const d=a.current;if(a.current=n,!(l.current!==t)&&!(typeof d=="string"&&d!==n))return;if(s({messages:[],total:0,loading:!1,hasMore:!1,error:null}),o.current=0,!t){l.current=null;return}l.current=t;const m=++c.current;s(v=>({...v,loading:!0,error:null})),(async()=>{try{const v=await e.historyRead({sessionId:t,limit:r});if(m!==c.current)return;o.current=v.offset,s({messages:v.messages??[],total:v.total??0,loading:!1,hasMore:v.offset>0,error:null})}catch(v){if(m!==c.current)return;s({messages:[],total:0,loading:!1,hasMore:!1,error:v.message??"history load failed"})}})()},[e,t,n,r]);const u=g.useCallback(async()=>{if(!t)return;const d=o.current;if(d<=0)return;const f=Math.max(0,d-r),p=d-f;s(m=>({...m,loading:!0,error:null}));try{const m=await e.historyRead({sessionId:t,limit:p,offset:f});o.current=m.offset,s(v=>({...v,messages:[...m.messages??[],...v.messages],loading:!1,hasMore:m.offset>0}))}catch(m){s(v=>({...v,loading:!1,error:m.message??"load more failed"}))}},[e,t,r]);return{...i,loadMore:u}}function Ok(e){const t=rp(e);return t.commandName?t.commandArgs?`${t.commandName} ${t.commandArgs}`:t.commandName:e}function Bk(e){return e.kind==="user-text"||e.kind==="user-meta"&&e.metaKind==="slash-command"}function ote(e,t){const n=t.find(Bk);if(!n)return e;const r=Ok(n.text);for(let i=e.length-1;i>=0;i--){const s=e[i];if(Bk(s)&&Ok(s.text)===r)return e.slice(0,i)}return e}const ate=1e6;function lte(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 oA(e){const t=Bi(),n=g.useMemo(()=>new qx(t),[t]),r=si("sessions"),i=g.useMemo(()=>r==null?void 0:r.find(F=>F.sessionId===e),[r,e]),s=i==null?void 0:i.toolSessionId,o=i==null?void 0:i.tool,a=sA(e),{events:l,pendingPermissions:c,status:u,clearPermission:d,restorePermission:f}=a,p=ste({api:n,sessionId:e,toolSessionId:s}),m=g.useMemo(()=>p.messages.filter(F=>!F.isSidechain),[p.messages]),v=g.useMemo(()=>VR(m,0,o),[m,o]),y=c[0]??null,x=g.useMemo(()=>yZ(l,(y==null?void 0:y.requestId)??null),[l,y==null?void 0:y.requestId]),_=g.useMemo(()=>ote(v,x),[v,x]),b=g.useMemo(()=>x.map((F,j)=>({...F,seq:ate+j})),[x]),w=g.useMemo(()=>[..._,...b],[_,b]),k=pM(u),C=WZ(u),N=(i==null?void 0:i.resolvedModel)??(i==null?void 0:i.model),T=g.useMemo(()=>({sessionLabel:(i==null?void 0:i.label)||(i==null?void 0:i.larkChatName)||(i==null?void 0:i.larkChatId)||e,sessionId:e,...i!=null&&i.larkChatId?{larkChatName:i.larkChatName??i.larkChatId}:{},...N?{model:N}:{},...(()=>{const F=i==null?void 0:i.gitBranch;return F?{gitBranch:F}:{}})(),...(()=>{const F=lte(i);return F!==void 0?{contextPct:F}:{}})(),...i!=null&&i.cwd?{cwd:i.cwd}:{},...(()=>{const F=i==null?void 0:i.permissionMode;return F?{permissionMode:F}:{}})(),procAlive:k,streamInProgress:C,pinnedAt:(i==null?void 0:i.pinnedAt)??null}),[i,e,N,k,C]),L=g.useMemo(()=>t.isOpen?u==="error"?{kind:"error",message:"session error"}:{kind:"ready"}:{kind:"closed"},[t.isOpen,u]),P=g.useCallback(async F=>{await n.sessionSend(e,F)},[n,e]),O=g.useCallback(async F=>{if(!(i!=null&&i.cwd)||!s)throw new Error("fork requires sessionFile with cwd + toolSessionId");await n.sessionFork({cwd:i.cwd,toolSessionId:s,messageUuid:F})},[n,i==null?void 0:i.cwd,s]),I=g.useCallback(async F=>{await n.sessionRewind({sessionId:e,userMessageId:F,dryRun:!1})},[n,e]),R=g.useCallback(async F=>{await n.sessionUpdate(e,{model:F})},[n,e]),D=g.useCallback(async()=>{await n.sessionNew(e)},[n,e]),z=g.useCallback(async(F,j)=>{const B=c.find(E=>E.requestId===F);B&&d(F);try{await n.permissionRespond({sessionId:e,permissionRequestId:F,allow:j==="allow"})}catch(E){throw!((E==null?void 0:E.message)??"").startsWith("PERMISSION_REQUEST_STALE")&&B&&f(B),E}},[n,e,c,d,f]),$=g.useCallback(async()=>{await p.loadMore()},[p]);return g.useMemo(()=>({lines:w,connState:L,meta:T,historyDone:!p.hasMore,historyLoading:p.loading,pendingPermissions:c,sendText:P,fork:O,rewind:I,switchModel:R,clearSession:D,respondPermission:z,loadMoreHistory:$}),[w,L,T,p.hasMore,p.loading,c,P,O,I,R,D,z,$])}function cte({api:e,open:t,onOpenChange:n,scope:r,sessionId:i,onShareFile:s,onOpenInTab:o}){const[a,l]=g.useState([]),[c,u]=g.useState(null);g.useEffect(()=>{if(!t)return;let f=!1;return(async()=>{try{const p=await e.attachmentGroupList(i);if(f)return;l(p.entries)}catch(p){f||u(p.message)}})(),()=>{f=!0}},[e,i,t]);async function d(f){try{await e.attachmentGroupRemove(i,f.relPath),l(p=>f.from==="owner"?p.filter(m=>m.relPath!==f.relPath):p.map(m=>m.relPath===f.relPath?{...m,stale:!0}:m))}catch(p){u(p.message)}}return t?h.jsx(__,{delayDuration:120,children:h.jsxs("div",{"data-testid":"files-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-[420px] flex-col border-l border-border bg-elevated shadow-2xl",children:[h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-text-100",children:[h.jsx(f6,{className:"h-4 w-4"}),"Edited Files"]}),h.jsx("button",{type:"button",onClick:()=>n(!1),className:"flex h-7 w-7 items-center justify-center rounded text-text-400 hover:bg-bg-200 hover:text-text-100","aria-label":"Close drawer",children:h.jsx(Rn,{className:"h-4 w-4"})})]}),h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[h.jsx(ute,{title:`Session files (${a.length})`,subtitle:"agent Write/Edit 自动入清单",children:a.length===0?h.jsx(hte,{text:"还没有文件。agent Write/Edit 会自动加入清单。"}):a.map(f=>h.jsx(dte,{entry:f,onShareLink:()=>s(f.relPath),...o?{onOpenInTab:()=>o(f.relPath)}:{},onRemove:()=>d(f)},f.id))}),c?h.jsx("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-[11px] text-destructive",children:c}):null]})]})}):null}function ute({title:e,subtitle:t,children:n}){return h.jsxs("div",{className:"border-b border-border last:border-b-0",children:[h.jsx("div",{className:"sticky top-0 z-10 flex items-start justify-between bg-elevated px-4 py-2",children:h.jsxs("div",{className:"flex-1",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wide text-text-300",children:e}),t?h.jsx("div",{className:"mt-0.5 text-[11px] text-text-400",children:t}):null]})}),h.jsx("div",{className:"flex flex-col",children:n})]})}function dte({entry:e,onShareLink:t,onOpenInTab:n,onRemove:r}){var l;const i=(l=e.mime)!=null&&l.startsWith("image/")?y6:Ms,s=e.relPath.lastIndexOf("/"),o=s>=0?e.relPath.slice(0,s+1):"",a=s>=0?e.relPath.slice(s+1):e.relPath;return h.jsxs("div",{"data-testid":"files-drawer-group-row",className:ne("group flex items-center gap-2 px-4 py-2 hover:bg-bg-200",e.stale&&"opacity-50"),children:[h.jsx(i,{className:"h-4 w-4 shrink-0 text-text-400"}),h.jsxs("div",{className:"min-w-0 flex-1",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsxs(y_,{children:[h.jsx(b_,{asChild:!0,children:h.jsxs("span",{className:"flex min-w-0 items-baseline text-[13px] text-text-100",children:[o?h.jsx("span",{className:"truncate text-text-400",children:o}):null,h.jsx("span",{className:"shrink-0",children:a})]})}),h.jsx(Yf,{side:"top",align:"start",className:"max-w-[380px] break-all",children:e.relPath})]}),e.stale&&h.jsx("span",{className:"rounded bg-text-100/10 px-1 py-0 text-[10px] uppercase text-text-400",children:"stale"})]}),h.jsxs("div",{className:"flex items-center gap-1.5 truncate text-[11px] text-text-400",children:[h.jsx("span",{children:e.from}),h.jsx("span",{children:"·"}),h.jsx("span",{children:fte(e.addedAt)})]})]}),!e.stale&&h.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[n?h.jsx($m,{icon:h.jsx(Ac,{className:"h-3.5 w-3.5"}),title:"Open in tab",onClick:n}):null,h.jsx($m,{icon:h.jsx(Gx,{className:"h-3.5 w-3.5"}),title:"Share link",onClick:t}),e.from==="owner"&&h.jsx($m,{icon:h.jsx(Xx,{className:"h-3.5 w-3.5"}),title:"Remove",onClick:r})]})]})}function $m({icon:e,title:t,onClick:n}){return h.jsx("button",{type:"button",onClick:n,title:t,"aria-label":t,className:"flex h-7 w-7 items-center justify-center rounded text-text-400 hover:bg-text-100/10 hover:text-text-100",children:e})}function hte({text:e}){return h.jsx("div",{className:"px-4 py-3 text-[12px] italic text-text-400",children:e})}function fte(e){const t=Date.now()-e;return t<6e4?`${Math.max(1,Math.floor(t/1e3))}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function pte({persona:e,open:t,onClose:n,onTogglePublic:r,guestShareUrl:i,onChangeIcon:s,onDelete:o,embedded:a,onLoadPersonality:l,onSavePersonality:c,onDirtyChange:u,initialPersonality:d,onShareCapability:f,readOnly:p=!1,onChangeTool:m,larkBot:v}){const[y,x]=g.useState(!1),[_,b]=g.useState(!1),w=()=>{i&&navigator.clipboard.writeText(i).then(()=>{b(!0),setTimeout(()=>b(!1),2e3)})},k=N=>{x(N),u==null||u(N)},C=()=>{y&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!a&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:C,"aria-hidden":"true"}),h.jsxs("aside",{className:a?"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(Y6,{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(Rn,{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(x6,{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(g6,{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(Gx,{className:"h-3.5 w-3.5"}),"分享"]}):null,o?h.jsx("button",{type:"button",onClick:o,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(Xx,{className:"h-4 w-4"})}):null]})]}),h.jsx("hr",{className:"border-border"}),r?h.jsxs(h.Fragment,{children:[h.jsxs("section",{className:"flex items-center justify-between gap-3",children:[h.jsxs("div",{className:"flex flex-col gap-0.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"公开访问"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"开启后这个 persona 才会出现在「邀请联系人」的可选列表里。关闭即拒所有新分享(已颁出的 token 不受影响)。"})]}),h.jsx(gte,{checked:e.public??!1,onChange:N=>r(N)})]}),e.public?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"guest-share-link",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx($N,{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:"访客分享链接"})]}),i?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("input",{readOnly:!0,value:i,onFocus:N=>N.currentTarget.select(),className:"min-w-0 flex-1 truncate rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"guest-share-link-input"}),h.jsx("button",{type:"button",onClick:w,className:"flex shrink-0 items-center gap-1 rounded border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200","data-testid":"guest-share-link-copy",children:_?h.jsxs(h.Fragment,{children:[h.jsx(Qa,{className:"h-3 w-3"})," 已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(su,{className:"h-3 w-3"})," 复制"]})})]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"任何 TTC 员工打开此链接(飞书登录)即可在该 persona 下交互。"})]}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"guest-share-link-no-tunnel",children:"需先开启 tunnel(公网访问)才能生成可分享给外部的链接。"})]}):null,h.jsx("hr",{className:"border-border"})]}):null,v?h.jsxs(h.Fragment,{children:[h.jsx(mte,{...v}),h.jsx("hr",{className:"border-border"})]}):null,s?h.jsxs("section",{className:"flex flex-col gap-1.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"默认图标"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"新建该 persona 的 session 会默认继承此图标。"}),h.jsx(rI,{value:e.iconKey??null,onChange:s})]}):null,s?h.jsx("hr",{className:"border-border"}):null,m&&!p?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-col gap-1.5",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"Agent"}),h.jsx("div",{className:"flex gap-2",children:["claude","codex"].map(N=>h.jsx("button",{type:"button","data-testid":`persona-edit-tool-${N}`,onClick:()=>m(N),className:ne("flex-1 rounded-md border px-3 py-2 text-[12px]",(e.tool??"claude")===N?"border-accent bg-accent/10 text-accent":"border-bg-300 text-text-300"),children:N==="claude"?"Claude Code":"Codex"},N))}),h.jsx("span",{className:"text-[11px] text-text-400",children:"切换只影响之后新建的会话,已有会话保持原 tool。"})]}),h.jsx("hr",{className:"border-border"})]}):null,l?h.jsxs(h.Fragment,{children:[h.jsx(yte,{onLoad:l,...c?{onSave:c}:{},onDirtyChange:k,initialPersonality:d,readOnly:p}),h.jsx("hr",{className:"border-border"})]}):null,h.jsx(vte,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(xte,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(_te,{plugins:e.plugins??[]})]})]})]}):null}function mte({status:e,onBindManual:t,onUnbind:n}){const[r,i]=g.useState(!1),[s,o]=g.useState(null),[a,l]=g.useState(""),[c,u]=g.useState(""),d=p=>{p&&(i(!0),o(null),p().catch(m=>o(m instanceof Error?m.message:String(m))).finally(()=>i(!1)))},f=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(jf,{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:[f,e.state==="unbound"?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"绑定一个飞书自建应用后,这个 persona 就是它的 bot:拉进群后群成员 @ 它提问, 推理跑在你本机,回复自动发回群。"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"先在飞书开放平台(open.feishu.cn)创建企业自建应用并启用机器人能力,再填入凭证:"}),t?h.jsxs("div",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-manual-form",children:[h.jsx("input",{value:a,onChange:p=>l(p.target.value),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:c,onChange:p=>u(p.target.value),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:r||!a||!c,onClick:()=>d(()=>t({appId:a,appSecret:c})),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:r?"绑定中…":"绑定"})]}):null]}):null,e.state==="bound"||e.state==="broken"?h.jsxs("div",{className:"flex flex-col gap-1.5",children:[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(p=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",p.chatName??p.chatId]},p.chatId))}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"lark-bot-groups-empty",children:"还没有服务中的群。"}),n?h.jsx("button",{type:"button",disabled:r,onClick:()=>d(n),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,s?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:s}):null]}):h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[f,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function gte({checked:e,onChange:t}){return h.jsx("button",{type:"button",role:"switch","aria-checked":e,onClick:()=>t(!e),"data-testid":"persona-public-toggle",className:ne("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e?"bg-success":"bg-bg-300"),children:h.jsx("span",{className:ne("inline-block h-5 w-5 rounded-full bg-bg-0 shadow transition-transform",e?"translate-x-[22px]":"translate-x-0.5")})})}function vte({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(gd,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(gd,{label:"沙箱启用",value:Fm((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(gd,{label:"沙箱内自动放行 Bash",value:Fm((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(gd,{label:"允许非沙箱命令",value:Fm((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(Rl,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(Rl,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(Rl,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(Rl,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(Rl,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function Fm(e){return e===!0?"是":e===!1?"否":"—"}function gd({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 Rl({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 xte({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 _te({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 yte({onLoad:e,onSave:t,onDirtyChange:n,initialPersonality:r,readOnly:i=!1}){const s=r!==void 0,[o,a]=g.useState(s),[l,c]=g.useState(s?r:""),[u,d]=g.useState(s?r:""),[f,p]=g.useState(null),[m,v]=g.useState(!1),[y,x]=g.useState(null),_=st.useRef(e),b=st.useRef(t),w=st.useRef(n);st.useEffect(()=>{_.current=e,b.current=t,w.current=n});const k=st.useCallback(()=>{a(!1),p(null),_.current().then(L=>{c(L),d(L),a(!0)}).catch(L=>{p(L instanceof Error?L.message:String(L))})},[]);st.useEffect(()=>{s||k()},[s,k]);const C=!i&&o&&u!==l;st.useEffect(()=>{i||w.current(C)},[C,i]);const N=()=>{b.current&&(v(!0),x(null),b.current(u).then(()=>{c(u),v(!1)}).catch(L=>{x(L instanceof Error?L.message:String(L)),v(!1)}))},T=()=>{d(l),x(null)};return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-personality-section",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"人格 (Personality)"}),f?h.jsxs("div",{"data-testid":"persona-personality-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:["加载失败:",f]}),h.jsx("button",{type:"button",onClick:k,className:"rounded-sm border border-error px-2 py-0.5 text-[11px] hover:bg-error/10",children:"重试"})]}):null,y?h.jsxs("div",{"data-testid":"persona-personality-save-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error",children:["保存失败:",y]}):null,h.jsx("textarea",{"data-testid":"persona-personality-textarea",value:u,onChange:L=>d(L.target.value),readOnly:i,disabled:!i&&(!o||m),placeholder:o?"":"加载中…",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"}),!i&&h.jsxs("p",{className:"text-[10px] text-text-400",children:["写入到 ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/CLAUDE.md"}),"。 修改只对新启动的 sub-session 生效。"]}),o&&C?h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:T,disabled:m,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:N,disabled:m,"data-testid":"persona-personality-save-btn",className:"rounded-sm bg-accent-dim px-2 py-1 text-[12px] text-text-100 hover:opacity-90 disabled:opacity-60",children:m?"保存中…":"保存"})]}):null]})}const bte={state:"unbound",groups:[]};function wte(e,t){const[n,r]=g.useState(null);g.useEffect(()=>{if(!e)return;let o=!1;r(null);const a=async()=>{try{const u=await e.request("larkBot:status",{personaId:t});o||r(u)}catch{o||r(bte)}};a();const l=e.on("larkBot:state",u=>{const d=u;if(d.personaId!==t)return;const{personaId:f,...p}=d;r(p)}),c=e.on("daemon:connected",()=>{a()});return()=>{o=!0,l(),c()}},[e,t]);const i=g.useCallback(async o=>{e&&await e.request("larkBot:bindManual",{personaId:t,...o})},[e,t]),s=g.useCallback(async()=>{e&&await e.request("larkBot:unbind",{personaId:t})},[e,t]);return{status:n,bindManual:i,unbind:s}}function Ste({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const{persona:l}=jN(e),c=pB(e),u=mB(),d=gB(),{httpBaseUrl:f}=Af(),p=Bi(),m=wte(a==="guest"?null:p,e),v=g.useMemo(()=>!(l!=null&&l.public)||!f||/^https?:\/\/(127\.0\.0\.1|localhost|0\.0\.0\.0|\[?::1\]?)([:/]|$)/i.test(f)?null:`${f}/s/${e}`,[l==null?void 0:l.public,f,e]),y=g.useCallback(N=>{u(e,{public:N}).catch(T=>{Re("persona","togglePublic failed",T)})},[u,e]),x=g.useCallback(N=>{u(e,{iconKey:N}).catch(T=>{Re("persona","changeIcon failed",T)})},[u,e]),_=g.useCallback(N=>{u(e,{tool:N}).catch(T=>{Re("persona","changeTool failed",T)})},[u,e]),b=g.useCallback(()=>{l&&confirm(`删除 persona "${l.label}"?`)&&(d(e).catch(N=>{Re("persona","delete failed",N)}),n())},[l,d,e,n]),w=g.useCallback(async()=>c.loaded?c.personality:(await c.refresh()).personality,[c]),k=g.useCallback(async N=>{await u(e,{personality:N}),await c.refresh()},[u,e,c]);if(!l)return null;const C=a==="guest";return h.jsx(pte,{embedded:i,persona:{...l,skills:c.skills,plugins:c.plugins,sandboxSettings:c.sandboxSettings},open:t,onClose:n,onLoadPersonality:w,onDirtyChange:s,readOnly:C,...C?{}:{onTogglePublic:y,guestShareUrl:v,onChangeIcon:x,onChangeTool:_,onDelete:b,onSavePersonality:k,larkBot:{status:m.status,onBindManual:m.bindManual,onUnbind:m.unbind},...o?{onShareCapability:o}:{}}})}function kte({api:e,open:t,onOpenChange:n,personaId:r,personaName:i,viewerRole:s}){return t?h.jsxs("div",{"data-testid":"persona-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-[420px] flex-col border-l border-border bg-elevated shadow-2xl",children:[h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-[13px] font-semibold text-text-100",children:[h.jsx(Yx,{className:"h-4 w-4 shrink-0"}),h.jsxs("span",{className:"truncate",title:i,children:["Persona · ",i]})]}),h.jsx("button",{type:"button",onClick:()=>n(!1),className:"flex h-7 w-7 items-center justify-center rounded text-text-400 hover:bg-bg-200 hover:text-text-100","aria-label":"Close drawer",children:h.jsx(Rn,{className:"h-4 w-4"})})]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:h.jsx(Ste,{personaId:r,open:!0,onClose:()=>n(!1),api:e,embedded:!0,...s?{viewerRole:s}:{}},r)})]}):null}function Cte(e){try{const t=new URL(e);return t.protocol==="ws:"?t.protocol="http:":t.protocol==="wss:"&&(t.protocol="https:"),`${t.protocol}//${t.host}`}catch{return e}}function Ete(e,t){try{const n=new URL(e),r=new URL(t);return n.protocol=r.protocol,n.host=r.host,n.toString()}catch{return e}}async function gy(e,t,n,r,i){const s=await e.attachmentSignUrl({sessionId:n,relPath:r,...i!==void 0?{ttlSeconds:i}:{}});return Ete(s.url,Cte(t.url))}async function Nte(e,t,n,r,i=60){const s=window.open("about:blank","_blank");try{const o=await gy(e,t,n,r,i);s?s.location.href=o:window.open(o,"_blank")}catch(o){throw s&&s.close(),o}}async function Tte(e){var t;try{if((t=navigator.clipboard)!=null&&t.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{const n=document.createElement("textarea");n.value=e,n.style.position="fixed",n.style.left="-9999px",n.style.top="0",n.setAttribute("readonly",""),document.body.appendChild(n),n.select();const r=document.execCommand("copy");return document.body.removeChild(n),r}catch{return!1}}const Pte={...qc,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 Ite(e){const t=e.split("/");return t[t.length-1]||e}function aA({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:Ite(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(Uc,{remarkPlugins:[Vc],components:Pte,children:i})}):null})]})}function Rte({open:e,onOpenChange:t,relPath:n,loadMarkdown:r,onShare:i}){return e?h.jsx("div",{"data-testid":"md-preview-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-1/2 max-w-[900px] flex-col border-l border-border bg-elevated shadow-2xl",children:h.jsx(aA,{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($N,{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(Rn,{className:"h-4 w-4"})})]})})}):null}function Mte({left:e,right:t,stage:n,onExpand:r,onCollapse:i}){const s=n==="stopped",[o,a]=g.useState(!1);async function l(){if(!o){a(!0);try{await r()}catch{}finally{a(!1)}}}async function c(){if(!o){a(!0);try{await i()}catch{}finally{a(!1)}}}return h.jsxs("div",{className:"flex h-full w-full min-h-0","data-testid":"two-pane-layout",children:[h.jsxs("div",{className:"relative flex min-w-0 flex-1 flex-col","data-testid":"two-pane-left",children:[s&&h.jsx("button",{type:"button",disabled:o,className:"absolute right-14 top-2 z-10 rounded border border-border bg-elevated px-2 py-1 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50 disabled:cursor-not-allowed",onClick:l,children:o?"启动中…":"展开预览"}),e]}),!s&&h.jsxs("div",{className:"flex w-1/2 min-w-[320px] flex-col border-l border-bg-200","data-testid":"two-pane-right",children:[h.jsx("div",{className:"flex items-center justify-end gap-2 border-b border-bg-200 bg-bg-50 px-2 py-1",children:h.jsx("button",{type:"button",disabled:o,className:"rounded px-2 py-1 text-[12px] text-text-300 hover:bg-bg-100 disabled:opacity-50",onClick:c,children:"收起预览"})}),h.jsx("div",{className:"min-h-0 flex-1",children:t})]})]})}const lA=aM,Ate=lM,cA=g.forwardRef(({className:e,...t},n)=>h.jsx(ty,{ref:n,className:ne("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));cA.displayName=ty.displayName;const vy=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(Ate,{children:[h.jsx(cA,{}),h.jsxs(ny,{ref:r,className:ne("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(cM,{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(Rn,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));vy.displayName=ny.displayName;const xy=({className:e,...t})=>h.jsx("div",{className:ne("flex flex-col space-y-1.5 text-left",e),...t});xy.displayName="DialogHeader";const _y=({className:e,...t})=>h.jsx("div",{className:ne("flex flex-row justify-end gap-2",e),...t});_y.displayName="DialogFooter";const yy=g.forwardRef(({className:e,...t},n)=>h.jsx(ry,{ref:n,className:ne("text-lg font-semibold leading-none text-text-100",e),...t}));yy.displayName=ry.displayName;const uA=g.forwardRef(({className:e,...t},n)=>h.jsx(iy,{ref:n,className:ne("text-sm text-text-300",e),...t}));uA.displayName=iy.displayName;const jte=6173,Dte=6182;function Lte({open:e,onOpenChange:t,projectName:n,currentPort:r,allUsedPorts:i,onUpdate:s}){const o=[];for(let v=jte;v<=Dte;v++)(v===r||!i.includes(v))&&o.push(v);const[a,l]=g.useState(r),[c,u]=g.useState(!1),[d,f]=g.useState(null),p=a!==r&&!c;async function m(){if(p){u(!0),f(null);try{await s(a),t(!1)}catch(v){f((v==null?void 0:v.message)??String(v))}finally{u(!1)}}}return h.jsx(lA,{open:e,onOpenChange:t,children:h.jsxs(vy,{className:"max-w-md",children:[h.jsxs(xy,{children:[h.jsxs(yy,{children:["改端口 · ",n]}),h.jsxs(uA,{children:["手改通常发生在系统其他进程占了默认分配的端口、dev server 起不来时。 提交后 daemon 会停 dev server → 写 ",h.jsx("code",{className:"mx-1 rounded bg-bg-100 px-1 py-0.5 text-[11px]",children:".clawd-project.json"})," → 用新端口重新起。"]})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx("label",{className:"text-xs text-text-400",children:"新端口(仅显示段内可用 + 当前端口)"}),h.jsx("select",{className:"h-9 rounded-md border border-border bg-elevated px-3 py-1 text-sm text-text-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",value:a,onChange:v=>l(Number(v.target.value)),disabled:c,children:o.map(v=>h.jsxs("option",{value:v,children:[v,v===r?"(当前)":""]},v))}),o.length===1&&h.jsx("div",{className:"text-[11px] text-text-400",children:"端口段已全被其它 project 占用,没有可换的;先删一个 idle project 释放端口。"}),d&&h.jsx("div",{className:"rounded border border-destructive/30 bg-destructive/5 px-3 py-2 text-[12px] text-destructive",children:d})]}),h.jsxs(_y,{children:[h.jsx(ni,{variant:"ghost",onClick:()=>t(!1),disabled:c,children:"取消"}),h.jsx(ni,{onClick:m,disabled:!p,children:c?"应用中…":"应用新端口"})]})]})})}const zk=[{stage:"build",label:"构建"},{stage:"deploy",label:"部署到阿里云"},{stage:"verify",label:"验证可访问性"}];function Ote({currentStage:e,onCancel:t}){const n=zk.findIndex(r=>r.stage===e);return h.jsxs("div",{"data-testid":"publish-progress",className:"flex items-center gap-3 border-b border-bg-200 bg-bg-50 px-3 py-1.5 text-[12px]",children:[zk.map((r,i)=>{const s=i<n,o=i===n,a=s?"text-text-300":o?"text-text-200":"text-text-500/50";return h.jsxs("span",{className:`flex items-center gap-1 ${a}`,children:[s?h.jsx(Df,{className:"size-3.5"}):o?h.jsx(rr,{className:"size-3.5 animate-spin"}):h.jsx(ON,{className:"size-3.5"}),h.jsxs("span",{children:[r.label,o?"中…":""]})]},r.stage)}),h.jsx("button",{type:"button",onClick:t,className:"ml-auto rounded px-2 py-0.5 text-[11px] text-text-400 hover:bg-bg-100 hover:text-text-200",children:"取消"})]})}const Bte={build:"构建",deploy:"部署",verify:"验证"};function zte({stage:e,onRetry:t,onDismiss:n}){return h.jsxs("div",{"data-testid":"publish-interrupted-banner",className:"flex items-center gap-2 border-b border-yellow-400/40 bg-yellow-400/10 px-3 py-1.5 text-[12px]",children:[h.jsx(jc,{className:"size-3.5 text-yellow-500"}),h.jsxs("span",{className:"text-text-200",children:["上次发布在 ",h.jsxs("strong",{className:"font-medium",children:["[",Bte[e],"]"]})," ","阶段被中断(daemon 重启)"]}),h.jsx("button",{type:"button",onClick:t,className:"ml-auto rounded bg-accent-main-100 px-2 py-0.5 text-[11px] text-oncolor-100 hover:opacity-90",children:"重新发布"}),h.jsx("button",{type:"button",onClick:n,className:"rounded px-2 py-0.5 text-[11px] text-text-400 hover:bg-bg-100 hover:text-text-200",children:"取消"})]})}const $te={build:"构建",deploy:"部署",verify:"验证",unknown:"未知"};function Fte({stage:e,onFocusChat:t,onClose:n}){return h.jsxs("div",{"data-testid":"publish-failed-banner",className:"flex items-center gap-2 border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[12px]",children:[h.jsx(Rs,{className:"size-3.5 text-destructive"}),h.jsxs("button",{type:"button",onClick:t,className:"flex-1 text-left text-text-200 hover:underline",children:["发布失败:",h.jsxs("strong",{className:"font-medium",children:["[",$te[e],"]"]})," ","已通知 assistant 接管 →"]}),h.jsx("button",{type:"button",onClick:n,"aria-label":"关闭失败提示",className:"rounded p-0.5 text-text-400 hover:bg-bg-100 hover:text-text-200",children:h.jsx(Rn,{className:"size-3.5"})})]})}const $k={"install-pending":{label:"等装依赖…",step:"1/3"},installing:{label:"安装依赖中…(可能要几十秒到几分钟)",step:"2/3"},"starting-dev-server":{label:"启动 dev server…(等监听端口才挂 iframe)",step:"3/3"}};function Hte({project:e,previewHost:t,previewScheme:n,onUpdatePort:r,allUsedPorts:i,publishSlot:s,publishInFlightStage:o,onDismissPublishJob:a,onRetryPublish:l,publishFailureBanner:c,onPublishFailureBannerClose:u,onPublishFailureBannerFocusChat:d}){var x,_;const[f,p]=g.useState(!1);if(!e)return h.jsx("div",{className:"flex h-full w-full items-center justify-center p-6 text-center text-[13px] text-text-400",children:"未绑定 project"});const m=e.stage??(e.isRunning?"running":"stopped"),v=t?`${n}://${t}/preview/${e.port}/`:null,y=e.prodUrl??null;return h.jsxs("div",{className:"flex h-full w-full flex-col","data-testid":"preview-pane",children:[h.jsxs("header",{className:"flex items-center justify-between gap-2 border-b border-bg-200 bg-bg-50 px-3 py-1.5",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[12px]",children:[h.jsx("span",{className:"font-medium text-text-200",children:e.name}),h.jsx("span",{className:"rounded bg-bg-100 px-1.5 py-0.5 text-[11px] text-text-400",children:e.port}),h.jsx("span",{className:"text-[10px] uppercase tracking-wider text-text-500",children:m==="running"?"dev":m})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[y?h.jsxs("a",{href:y,target:"_blank",rel:"noopener noreferrer",title:`打开线上:${y}`,className:"inline-flex items-center gap-1 rounded border border-bg-200 px-2 py-0.5 text-[11px] text-text-300 hover:bg-bg-100",children:[h.jsx(Ac,{className:"size-3"}),"打开线上"]}):null,s,h.jsxs(VP,{children:[h.jsx(qP,{asChild:!0,children:h.jsx("button",{type:"button","aria-label":"Project settings",className:"rounded p-1 text-text-400 hover:bg-bg-100",children:h.jsx(G6,{className:"size-3.5"})})}),h.jsxs(v_,{align:"end",children:[h.jsx(Ys,{onSelect:()=>p(!0),children:"Update Port…"}),h.jsxs(Ys,{disabled:!0,title:"rename not supported yet",onSelect:b=>b.preventDefault(),children:["Name: ",e.name]})]})]})]})]}),c?h.jsx(Fte,{stage:c.stage,onClose:()=>u==null?void 0:u(),onFocusChat:()=>d==null?void 0:d()}):null,((x=e.publishJob)==null?void 0:x.status)==="in-flight"?h.jsx(Ote,{currentStage:o??e.publishJob.stage,onCancel:()=>void(a==null?void 0:a())}):null,((_=e.publishJob)==null?void 0:_.status)==="interrupted"?h.jsx(zte,{stage:e.publishJob.stage,onRetry:()=>void(l==null?void 0:l()),onDismiss:()=>void(a==null?void 0:a())}):null,h.jsx("div",{className:"min-h-0 flex-1",children:m==="failed"?h.jsx(Ute,{reason:e.stageReason}):m==="stopped"?null:m==="running"?v?h.jsx("iframe",{"data-testid":"preview-iframe",className:"size-full border-0 bg-white",src:v,title:"preview"}):h.jsx(Fk,{label:"等 tunnel 起来…",step:"-"}):h.jsx(Fk,{label:$k[m].label,step:$k[m].step})}),h.jsx(Lte,{open:f,onOpenChange:p,projectName:e.name,currentPort:e.port,allUsedPorts:i,onUpdate:async b=>{await r(b)}})]})}function Fk({label:e,step:t}){return h.jsxs("div",{"data-testid":"preview-spinner",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(rr,{className:"size-6 animate-spin text-accent-main-100"}),h.jsx("div",{className:"text-[13px] text-text-200",children:e}),h.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-500",children:t}),h.jsx("div",{className:"mt-2 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度"})]})}function Ute({reason:e}){return h.jsxs("div",{"data-testid":"preview-failed",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(Rs,{className:"size-6 text-destructive"}),h.jsx("div",{className:"text-[13px] text-text-200",children:"project 启动失败"}),h.jsx("div",{className:"max-w-[400px] text-[12px] text-text-400",children:e??"未知原因 —— 看 ~/.clawd/clawd.log 排查"}),h.jsx("div",{className:"mt-1 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度 / 跟它说怎么修"})]})}function Wte({error:e,onClose:t}){const[n,r]=g.useState(!1),i=async()=>{var a;if(!e)return;const s=e.message;let o=!1;try{(a=navigator.clipboard)!=null&&a.writeText&&(await navigator.clipboard.writeText(s),o=!0)}catch{o=!1}if(!o){const l=document.createElement("textarea");l.value=s,l.style.position="fixed",l.style.opacity="0",document.body.appendChild(l),l.select();try{document.execCommand("copy"),o=!0}catch{o=!1}finally{document.body.removeChild(l)}}o&&(r(!0),setTimeout(()=>r(!1),1500))};return h.jsx(lA,{open:!!e,onOpenChange:s=>{s||(r(!1),t())},children:h.jsxs(vy,{className:"max-w-lg",children:[h.jsx(xy,{children:h.jsx(yy,{children:(e==null?void 0:e.title)??"错误"})}),h.jsx("pre",{"data-testid":"rpc-error-message",className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded border border-bg-200 bg-bg-50 px-3 py-2 text-[12px] text-text-200",children:(e==null?void 0:e.message)??""}),h.jsxs(_y,{children:[h.jsx(ni,{variant:"ghost",onClick:i,className:"gap-1.5",children:n?h.jsxs(h.Fragment,{children:[h.jsx(Qa,{className:"size-3.5"}),"已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(su,{className:"size-3.5"}),"复制"]})}),h.jsx(ni,{onClick:t,children:"关闭"})]})]})})}function Vte(e,t){for(const n of[e,t])if(n)try{const r=new URL(n),i=r.protocol==="https:"||r.protocol==="wss:"?"https":"http";return{host:r.host,scheme:i}}catch{}return{host:null,scheme:"https"}}const qte={codex:"on-request",claude:"bypassPermissions"};function Kte(e){const t={cwd:e.cwd,permissionMode:e.sourcePermissionMode??qte[e.sourceTool??"claude"]??"bypassPermissions",forkedFromSessionId:e.sourceSessionId};return e.sourceOwnerPersonaId&&(t.ownerPersonaId=e.sourceOwnerPersonaId),e.sourceTool&&(t.tool=e.sourceTool),t}async function Gte(e,t,n,r={}){if(!t.toolSessionId)return null;const i=await e.sessionCreate({...Kte({cwd:t.cwd,sourceSessionId:t.sessionId,sourcePermissionMode:t.permissionMode,sourceOwnerPersonaId:t.ownerPersonaId,sourceTool:t.tool}),...r.ephemeral?{ephemeral:!0}:{}});try{const{forkedToolSessionId:s}=await e.sessionFork({cwd:t.cwd,toolSessionId:t.toolSessionId,messageUuid:n,targetCwd:i.cwd});await e.sessionResume(i.sessionId,s)}catch(s){throw e.sessionDelete(i.sessionId).catch(o=>Re("quick-ask","fork rollback failed",o)),s}return i}async function Xte(e,t,n){return Gte(e,t,n,{ephemeral:!0})}function vd(e){return e!=null&&e.ephemeral!==!1}async function Yte(e,t){return!t.stillEphemeral||!t.nextHold?!1:(await e.sessionUpdate(t.sessionId,{ephemeral:!1}),!0)}const Zte=300;function Qte(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function dA(e,t){const n=Ix(),[r,i]=g.useState(null),s=g.useRef(null);g.useEffect(()=>{let a=!1;return(async()=>{try{const l=await n.kv.get(e);if(a)return;const c=Qte(l);typeof c=="number"&&Number.isFinite(c)&&c>0?i(c):i(t)}catch{a||i(t)}})(),()=>{a=!0}},[n,e,t]);const o=g.useCallback(a=>{s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{s.current=null,n.kv.set(e,a).catch(()=>{})},Zte)},[n,e]);return g.useEffect(()=>()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),{initialSize:r??t,setSize:o,loading:r===null}}function Jte(){return{quickAsk:null,mds:[],active:null}}function ene(e,t){return{...e,quickAsk:{sessionId:t.sessionId,ephemeral:!0},active:"quick-ask"}}function tne(e,t){const n=e.mds.includes(t);return{...e,mds:n?e.mds:[...e.mds,t],active:{kind:"md",relPath:t}}}function nne(e){if(!e.quickAsk)return e;const t=e.active==="quick-ask",n=e.mds[0],r=t?n?{kind:"md",relPath:n}:null:e.active;return{...e,quickAsk:null,active:r}}function rne(e){return e.quickAsk?{...e,quickAsk:{...e.quickAsk,ephemeral:!1}}:e}function ine(e,t){const n=e.mds.indexOf(t);if(n<0)return e;const r=e.mds.filter(l=>l!==t);if(!(e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===t))return{...e,mds:r};const s=r[n],o=n>0?r[n-1]:void 0;let a=null;return s?a={kind:"md",relPath:s}:o?a={kind:"md",relPath:o}:e.quickAsk&&(a="quick-ask"),{...e,mds:r,active:a}}function sne(e,t){return{...e,active:t}}function one(e,t){return e===null||t===null||e==="quick-ask"||t==="quick-ask"?e===t:e.relPath===t.relPath}function hA(e){return e.quickAsk!==null||e.mds.length>0}function ane(e){return e.split("/").pop()||e}function lne({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onToggleHold:a,holdIds:l}){if(!hA(e))return null;const c=[];e.quickAsk&&c.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(Mh,{className:"w-3.5 h-3.5"})});for(const u of e.mds)c.push({id:{kind:"md",relPath:u},label:ane(u),title:u,icon:h.jsx(Ms,{className:"w-3.5 h-3.5"})});return h.jsxs("div",{className:"flex flex-col h-full bg-bg-0 border-l border-text-100/10",children:[h.jsx(__,{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:c.map(u=>{const d=one(e.active,u.id),f=u.id==="quick-ask"?"quick-ask":`md:${u.id.relPath}`;return h.jsxs(y_,{children:[h.jsx(b_,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":d,"data-tab-title":u.title,onClick:()=>n(u.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",d?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[u.icon,h.jsx("span",{className:"truncate",children:u.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${u.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",d?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:p=>{p.stopPropagation(),u.id==="quick-ask"?r():i(u.id.relPath)},children:h.jsx(Rn,{className:"w-3 h-3"})}),d?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(Yf,{side:"bottom",align:"start",className:"max-w-sm break-all",children:u.title})]},f)})})}),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(une,{session:o,api:t,holdIds:l,...a?{onToggleHold:a}:{}})}):null,e.mds.map(u=>{const d=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===u;return h.jsx("div",{className:"absolute inset-0",style:{display:d?"block":"none"},children:h.jsx(aA,{relPath:u,loadMarkdown:s,showTitleBar:!1})},`md-body:${u}`)})]})]})}function cne({state:e,extras:t}){const{api:n,session:r,holdIds:i,onToggleHold:s}=t,o=Bi(),[a,l]=g.useState(Jte()),c=g.useRef(a);c.current=a;const u=g.useRef(!1),d=g.useCallback(async N=>{const T=c.current.quickAsk,L=await Xte(n,r,N);if(L){if(u.current){n.sessionDelete(L.sessionId).catch(()=>{});return}vd(T)&&n.sessionDelete(T.sessionId).catch(()=>{}),l(P=>ene(P,{sessionId:L.sessionId}))}},[n,r]),f=g.useCallback(async(N,T)=>{const L=c.current.quickAsk,P=(L==null?void 0:L.sessionId)===N;try{await Yte(n,{sessionId:N,stillEphemeral:P&&vd(L),nextHold:T})&&l(I=>rne(I))}catch(O){Re("quick-ask","promote failed",O);return}s==null||s(N,T)},[n,s]),p=g.useCallback(N=>{l(T=>tne(T,N))},[]),m=g.useCallback(N=>{l(T=>sne(T,N))},[]),v=g.useCallback(()=>{const N=c.current.quickAsk;vd(N)&&n.sessionDelete(N.sessionId).catch(()=>{}),l(T=>nne(T))},[n]),y=g.useCallback(N=>{l(T=>ine(T,N))},[]);g.useEffect(()=>()=>{u.current=!0;const N=c.current.quickAsk;vd(N)&&n.sessionDelete(N.sessionId).catch(()=>{})},[]);const x=si("sessions")??[],_=a.quickAsk?x.find(N=>N.sessionId===a.quickAsk.sessionId)??{sessionId:a.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,b=g.useCallback(async N=>{const T=await gy(n,o,r.sessionId,N,60),L=await fetch(T);if(!L.ok)throw new Error(`fetch ${L.status} ${L.statusText}`);return L.text()},[n,o,r.sessionId]),w=h.jsx(by,{state:e,extras:t,onQuickAskInternal:d,onPreviewMdInternal:p}),{initialSize:k,setSize:C}=dA("chat-panel-right-slot-width",480);return hA(a)?h.jsxs(I_,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Fc,{id:"chat",minSize:"400px",children:w}),h.jsx(M_,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Fc,{id:"right-slot",defaultSize:`${k}px`,minSize:"360px",maxSize:"800px",onResize:N=>C(N.inPixels),children:h.jsx(lne,{state:a,api:n,onSwitchTab:m,onCloseQuickAsk:v,onCloseMd:y,loadMarkdown:b,quickAskSession:_,holdIds:i,onToggleHold:f})})]}):w}function une({session:e,api:t,holdIds:n,onToggleHold:r}){const i=oA(e.sessionId);return h.jsx(by,{state:i,extras:{session:e,api:t,holdIds:n,...r?{onToggleHold:r}:{}}})}function dne({extras:e}){const t=oA(e.session.sessionId);if(e.session.appBuilderProject){const n=h.jsx(by,{state:t,extras:e});return h.jsx(hne,{state:t,chat:n,extras:e})}return h.jsx(cne,{state:t,extras:e})}function hne({state:e,chat:t,extras:n}){var T;const r=si("daemon-info"),i=Bi(),s=n.api,o=n.session,a=o.appBuilderProject,[l,c]=g.useState(null),u=g.useCallback(()=>{s.appBuilderGetProject(o.sessionId).then(L=>c(L.project)).catch(()=>c(null))},[s,o.sessionId]);g.useEffect(()=>{u()},[u]);const[d,f]=g.useState([]),p=g.useCallback(()=>{s.appBuilderListProjects().then(L=>f(L.projects)).catch(()=>f([]))},[s]);g.useEffect(()=>{p()},[p]),g.useEffect(()=>i.on("appBuilder:project-updated",P=>{const O=P;O!=null&&O.project&&(O.project.name===a&&c(O.project),f(I=>{const R=I.findIndex(z=>z.name===O.project.name);if(R<0)return[...I,O.project];const D=I.slice();return D[R]=O.project,D}))}),[i,a]);const{host:m,scheme:v}=Vte(i.url,r==null?void 0:r.tunnelUrl),[y,x]=g.useState(void 0),[_,b]=g.useState(null);g.useEffect(()=>{const L=i.on("appBuilder:publish-progress",O=>{const I=O;!I||I.name!==a||I.status==="started"&&x(I.stage)}),P=i.on("appBuilder:publish-failed",O=>{const I=O;!I||I.name!==a||(x(void 0),b({stage:I.stage}))});return()=>{L(),P()}},[i,a]),g.useEffect(()=>{x(void 0),b(null)},[a]);const[w,k]=g.useState(null),C=h.jsx("button",{type:"button",className:"rounded bg-accent-main-100 px-2.5 py-1 text-[12px] text-oncolor-100 hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",disabled:((T=l==null?void 0:l.publishJob)==null?void 0:T.status)==="in-flight",onClick:async()=>{try{await s.appBuilderPublish(a)}catch(L){k({title:"发布请求失败",message:(L==null?void 0:L.message)??String(L)})}},children:"发布上线"}),N=(l==null?void 0:l.stage)??(l!=null&&l.isRunning?"running":"stopped");return h.jsxs(h.Fragment,{children:[h.jsx(Mte,{left:t,stage:N,onExpand:async()=>{await s.appBuilderStartDevServer(o.sessionId)},onCollapse:async()=>{await s.appBuilderStopDevServer(o.sessionId)},right:h.jsx(Hte,{project:l,previewHost:m,previewScheme:v,allUsedPorts:d.map(L=>L.port),onUpdatePort:async L=>{await s.appBuilderUpdateProjectPort(a,L),p()},publishSlot:C,publishInFlightStage:y,onDismissPublishJob:async()=>{try{await s.appBuilderDismissPublishJob(a)}catch(L){k({title:"取消发布失败",message:(L==null?void 0:L.message)??String(L)})}},onRetryPublish:async()=>{try{await s.appBuilderPublish(a)}catch(L){k({title:"重新发布失败",message:(L==null?void 0:L.message)??String(L)})}},publishFailureBanner:_,onPublishFailureBannerClose:()=>b(null),onPublishFailureBannerFocusChat:()=>{}})}),h.jsx(Wte,{error:w,onClose:()=>k(null)})]})}function fne({headerMeta:e,connState:t,models:n,liveGitBranch:r,liveWorktreeRoot:i,onOpenConfig:s,onForceStop:o,cronActiveCount:a,onCronClick:l,lines:c,pendingPermissions:u,procAlive:d,rewindableUserMessageIds:f,onPermissionRespond:p,onPermissionInterrupt:m,onRewind:v,onFork:y,onQuickAsk:x,topSlot:_,realtimeQuestionAnswers:b,onSubmitQuestion:w,onCancelQuestion:k,liveQuestionToolUseIds:C,api:N,cwd:T,tool:L,sessionKey:P,onSend:O,awaitingUser:I,onAbort:R,onNewSession:D,onClearSession:z,chatRootRef:$,chatBodyRef:F,topSentinelRef:j,drawers:B,xtermSlot:E,fileSharingScope:H,onShareFile:q,onOpenInTab:M,onPreviewMarkdown:re,onOpenFiles:oe,onTogglePin:V,isHolded:pe,onToggleHold:Oe,personaName:ie,onOpenPersona:Ae}){return h.jsx(CY,{children:h.jsxs("div",{ref:$,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-0",children:[h.jsx(gZ,{meta:e,...L?{tool:L}:{},connState:t,...n?{models:n}:{},...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},...s?{onOpenConfig:s}:{},...o?{onForceStop:o}:{},cronActiveCount:a,...l?{onCronClick:l}:{},...oe?{onOpenFiles:oe}:{},...V?{onTogglePin:V}:{},isHolded:pe??!1,...Oe?{onToggleHold:Oe}:{},...ie?{personaName:ie}:{},...Ae?{onOpenPersona:Ae}:{}}),h.jsxs("div",{ref:F,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none"},children:[j?h.jsx("div",{ref:j,"data-testid":"top-sentinel","aria-hidden":"true",style:{height:1}}):null,h.jsx($R,{lines:c,...p?{onPermissionRespond:p}:{},...m&&d?{onPermissionInterrupt:m}:{},topSlot:_,...v?{onRewind:v}:{},rewindableUserMessageIds:f,...y?{onFork:y}:{},...x?{onQuickAsk:x}:{},realtimeQuestionAnswers:b,onSubmitQuestion:w,...k?{onCancelQuestion:k}:{},liveQuestionToolUseIds:C,...H?{fileSharingScope:H}:{},...q?{onShareFile:q}:{},...M?{onOpenInTab:M}:{},...re?{onPreviewMarkdown:re}:{}})]}),E,e.larkChatName?h.jsxs("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.larkChatName,"」驱动——群成员 @ bot 提问触发,这里仅供观察。"]}):h.jsx(pZ,{meta:e,...N?{api:N}:{},cwd:T,...L?{tool:L}:{},sessionKey:P,onSend:O,awaitingUser:I,...R?{onAbort:R}:{},...D?{onNewSession:D}:{},...z?{onClearSession:z}:{}}),B]})})}function by({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){const{session:i,api:s,models:o,liveGitBranch:a,liveWorktreeRoot:l,onNewSession:c,onTurnEnd:u,onOpenConfig:d,onFork:f,onQuickAsk:p,viewerRole:m,holdIds:v,onToggleHold:y}=t,{capabilities:x}=my(i.tool||"claude"),_=(x==null?void 0:x.features)??PN(i.tool),[b,w]=g.useState(null),[k,C]=g.useState(!1),[N,T]=g.useState(!1),L=Af(),P=!!s&&L.actionsLevel==="owner"&&_.fileSharing,O=jN(i.ownerPersonaId??null).persona,I=(O==null?void 0:O.label)??null,R=!!I&&!!i.ownerPersonaId,D=g.useCallback(()=>{T(!1),C(!0)},[]),z=g.useCallback(()=>{C(!1),T(!0)},[]),$=g.useCallback((Z,xe)=>{w({kind:Z,text:xe}),setTimeout(()=>{w(ye=>(ye==null?void 0:ye.text)===xe?null:ye)},2e3)},[]),F=Bi(),j=VO(),B=sA(i.sessionId,i.toolSessionId),{events:E,pendingQuestions:H,clearQuestion:q,markQuestionSubmitted:M,status:re}=B,oe=e.historyLoading,V=pM(re);g.useEffect(()=>{Re("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:re,procAlive:V})},[re,V,i.sessionId]);const pe=e.lines,Oe=e.pendingPermissions,ie=Oe[0]??null,Ae=g.useMemo(()=>R7(E),[E]),[Fe,We]=g.useState(!1),[ge,qe]=g.useState(null),[Gt,wt]=g.useState(()=>new Set);T7(s,i.sessionId,i.toolSessionId,_.observe);const Rt=g.useRef(i.sessionId);g.useEffect(()=>{if(Rt.current=i.sessionId,!_.rewind){qe(null);return}let Z=!1;return qe(null),(async()=>{try{const xe=await s.sessionRewindableMessageIds(i.sessionId);if(Z)return;qe(new Set(xe.userMessageIds))}catch{Z||qe(null)}})(),()=>{Z=!0}},[s,i.sessionId,_.rewind]);const ln=g.useCallback(()=>{const Z=i.sessionId;s.sessionRewindableMessageIds(Z).then(xe=>{Rt.current===Z&&qe(new Set(xe.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),Bt=g.useMemo(()=>{if(ge!==null){const Ze=new Set(ge);for(const hi of Gt)Ze.delete(hi);return Ze}const Z=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),xe=new Set;let ye=null;for(const Ze of pe)Ze.kind==="user-text"?ye=Ze.uuid??null:ye&&Ze.kind==="tool-call"&&Z.has(Ze.tool)&&!Gt.has(ye)&&xe.add(ye);return xe},[pe,Gt,ge]),at=g.useRef(u);at.current=u,P7(i.sessionId,i.toolSessionId,()=>{pn(null),wt(new Set)});const Ue=UZ({sessionStatus:re}),nt=g.useRef(null);g.useEffect(()=>{var ye;const Z=nt.current,xe=(Z==null?void 0:Z.sid)===i.sessionId;xe&&Z.phase===Ue||(nt.current={sid:i.sessionId,phase:Ue},Re("session-phase",Ue,{sid:i.sessionId,phase:Ue,prev:xe?Z.phase:null,desc:HZ[Ue]}),xe&&Z.phase==="turn-running"&&Ue!=="turn-running"&&((ye=at.current)==null||ye.call(at),ln()))},[Ue,i.sessionId,ln]);const mt=g.useCallback(()=>{s.sessionInterrupt(i.sessionId).catch(()=>{})},[s,i.sessionId]),[Xt,pn]=g.useState(null),U=g.useCallback(Z=>{pn(Z)},[]),[Q,ve]=g.useState(!1),Se=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),ve(!1)},[s,i.sessionId]),J=g.useCallback(Z=>{s.pinSession(i.sessionId,Z).catch(xe=>{Re("chat-panel","pinSession failed",{err:xe==null?void 0:xe.message})})},[s,i.sessionId]),Xe=(v==null?void 0:v.has(i.sessionId))??!1,Yt=g.useCallback(Z=>{y==null||y(i.sessionId,Z)},[y,i.sessionId]),Zt=g.useRef(0),ue=g.useRef(null);g.useEffect(()=>{const Z=xe=>{if(xe.key!=="Escape")return;if(!V){Zt.current=0;return}if(xe.isComposing)return;const Ze=xe.target;if(Ze&&Ze.closest("[data-cc-chat-root]")!==ue.current)return;const hi=Date.now();hi-Zt.current<2e3?(Zt.current=0,ve(!0)):(Zt.current=hi,mt())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[mt,V]);const Te=g.useRef(null),Je=g.useRef(null),Dn=g.useRef(!0),Qt=g.useRef(null),sl=g.useRef(0),jo=g.useRef(0);g.useEffect(()=>{Dn.current=!0,Qt.current=null,sl.current=0,jo.current=0},[i.sessionId]),g.useEffect(()=>{We(!1)},[i.sessionId]);const _u=g.useRef(e);_u.current=e;const yu=g.useCallback(()=>{var ye;const Z=Te.current;if(!Z||Qt.current!==null)return;const xe=_u.current;xe.historyDone||xe.historyLoading||(Qt.current={distFromBottom:Z.scrollHeight-Z.scrollTop},(ye=xe.loadMoreHistory)==null||ye.call(xe))},[]);g.useEffect(()=>{const Z=Te.current,xe=Je.current;if(!Z||!xe)return;const ye=new IntersectionObserver(Ze=>{for(const hi of Ze)hi.isIntersecting&&yu()},{root:Z,threshold:0});return ye.observe(xe),()=>ye.disconnect()},[yu]),g.useEffect(()=>{const Z=Te.current;if(!Z)return;const xe=150,ye=Ze=>{Date.now()<jo.current&&(Ze.preventDefault(),jo.current=Date.now()+xe)};return Z.addEventListener("wheel",ye,{passive:!1}),()=>Z.removeEventListener("wheel",ye)},[]),g.useEffect(()=>{const Z=Te.current;if(!Z)return;const xe=32,ye=()=>{const Ze=Z.scrollHeight-Z.scrollTop-Z.clientHeight;Dn.current=Ze<=xe};return Z.addEventListener("scroll",ye,{passive:!0}),()=>Z.removeEventListener("scroll",ye)},[]),g.useLayoutEffect(()=>{const Z=Te.current;if(!Z)return;const xe=sl.current,ye=pe.length;sl.current=ye;const Ze=Qt.current;if(Ze!==null&&ye>xe){Qt.current=null,Z.scrollTop=Z.scrollHeight-Ze.distFromBottom,jo.current=Date.now()+200;return}Ze!==null&&(Qt.current={distFromBottom:Z.scrollHeight-Z.scrollTop}),Dn.current&&(Z.scrollTop=Z.scrollHeight)},[pe,ie==null?void 0:ie.requestId]);const cp=g.useMemo(()=>{const Z={};for(const[xe,ye]of Object.entries(H))ye.submittedAnswers&&(Z[xe]=ye.submittedAnswers);return Z},[H]),up=g.useMemo(()=>new Set(Object.keys(H)),[H]),bu=g.useCallback(async(Z,xe)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:Z,answers:xe}),M(Z,xe)}catch{}},[s,i.sessionId,M]),Do=g.useCallback(async Z=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:Z}),q(Z)}catch{}},[s,i.sessionId,q]),Lo=g.useCallback(async(Z,xe)=>{var ye;if(ie)try{await((ye=e.respondPermission)==null?void 0:ye.call(e,ie.requestId,Z?"allow":"deny"))}catch{}},[e,ie]),ol=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]),al=g.useMemo(()=>oe&&pe.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(rr,{className:"w-4 h-4 text-text-400 animate-spin"})}):e.historyDone?null:h.jsx("div",{className:"flex justify-center py-2",children:h.jsx("button",{type:"button",onClick:()=>{var Z;return void((Z=e.loadMoreHistory)==null?void 0:Z.call(e))},disabled:oe,"data-testid":"history-load-more",className:"text-[12px] text-text-400 hover:text-text-200 cursor-pointer px-3 py-1 rounded-md border border-bg-300 hover:bg-bg-100 transition-colors disabled:opacity-60",children:oe?"加载中…":"Load earlier messages"})}),[oe,pe.length,e.historyDone,e.loadMoreHistory]),Wi=e.meta,Vi=h.jsxs(h.Fragment,{children:[i.toolSessionId&&_.subagents?h.jsx(wZ,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId}):null,Xt&&_.rewind?h.jsx(kZ,{open:!0,onOpenChange:Z=>{Z||pn(null)},api:s,sessionId:i.sessionId,userMessageId:Xt,lines:pe,procAlive:V,onNoChanges:Z=>{wt(xe=>{if(xe.has(Z))return xe;const ye=new Set(xe);return ye.add(Z),ye})}}):null,Q?h.jsx(pne,{onConfirm:Se,onCancel:()=>ve(!1)}):null,h.jsx(FZ,{open:Fe,onClose:()=>We(!1),jobs:Ae})]}),ll={kind:"session",sessionId:i.sessionId},wu=g.useCallback(async Z=>{if(s)try{await Nte(s,F,i.sessionId,Z)}catch(xe){const ye=xe.message;Re("chat-panel","open-in-tab failed",{err:ye}),$("err",`Open in tab 失败:${ye}`)}},[s,F,i.sessionId,$]),[zt,cl]=g.useState(!1),[ul,Tt]=g.useState(null),$t=g.useCallback(Z=>{if(r){r(Z);return}Tt(Z),cl(!0)},[r]),or=g.useCallback(async Z=>{if(!s)throw new Error("daemon api not ready");const xe=await gy(s,F,i.sessionId,Z,60),ye=await fetch(xe);if(!ye.ok)throw new Error(`fetch ${ye.status} ${ye.statusText}`);return await ye.text()},[s,F,i.sessionId]),Ln=g.useCallback(async(Z,xe)=>{if(s)try{const{url:ye}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:Z,ttlSeconds:86400,...xe?{view:xe}:{}}),Ze=await Tte(ye);$(Ze?"ok":"err",Ze?"分享链接已复制到剪贴板(24h 有效)":"复制失败:请手动复制")}catch(ye){const Ze=ye.message;Re("chat-panel","share-file failed",{err:Ze}),$("err",`生成分享链接失败:${Ze}`)}},[s,i.sessionId,$]);return h.jsxs(h.Fragment,{children:[h.jsx(fne,{headerMeta:Wi,connState:e.connState,...o?{models:o}:{},...a!==void 0?{liveGitBranch:a}:{},...l!==void 0?{liveWorktreeRoot:l}:{},...d?{onOpenConfig:d}:{},onForceStop:()=>ve(!0),cronActiveCount:Ae.length,onCronClick:()=>We(!0),lines:pe,pendingPermissions:Oe,procAlive:V,rewindableUserMessageIds:Bt,onPermissionRespond:Lo,onPermissionInterrupt:mt,onRewind:_.rewind?U:void 0,...f&&_.fork?{onFork:f}:{},...n&&_.fork?{onQuickAsk:n}:p&&_.fork?{onQuickAsk:p}:{},topSlot:al,realtimeQuestionAnswers:cp,onSubmitQuestion:bu,onCancelQuestion:Do,liveQuestionToolUseIds:up,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},sessionKey:i.sessionId,onSend:e.sendText,awaitingUser:Oe.length>0||Object.values(H).some(Z=>!Z.submittedAnswers),onAbort:mt,...c?{onNewSession:c}:{},onClearSession:ol,chatRootRef:ue,chatBodyRef:Te,topSentinelRef:Je,drawers:Vi,xtermSlot:j==="tui"&&V&&_.tui?h.jsx(rte,{sessionId:i.sessionId,client:F},i.sessionId):null,fileSharingScope:ll,...s?{onShareFile:Ln}:{},...s?{onOpenInTab:wu}:{},...s?{onPreviewMarkdown:$t}:{},...P?{onOpenFiles:D}:{},onTogglePin:J,isHolded:Xe,...y?{onToggleHold:Yt}:{},...R?{personaName:I}:{},...R?{onOpenPersona:z}:{}}),P&&s?h.jsx(cte,{api:s,open:k,onOpenChange:C,scope:ll,sessionId:i.sessionId,onShareFile:Ln,onOpenInTab:wu}):null,s?h.jsx(Rte,{open:zt,onOpenChange:cl,relPath:ul,loadMarkdown:or,onShare:ul?()=>void Ln(ul,"md-rendered"):void 0}):null,R&&s&&i.ownerPersonaId?h.jsx(kte,{api:s,open:N,onOpenChange:T,personaId:i.ownerPersonaId,personaName:I??"",...m?{viewerRole:m}:{}}):null,b?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:b.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:b.text}):null]})}function pne({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(jc,{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 mne(e,t,n){const r=e?t.find(s=>s.id===e):void 0;if(r!=null&&r.efforts&&r.efforts.length>0)return{options:r.efforts,defaultValue:r.defaultEffort??""};const i=n.find(s=>s.name==="effort");return{options:(i==null?void 0:i.options)??[],defaultValue:typeof(i==null?void 0:i.default)=="string"?i.default:""}}function gne({current:e,models:t,onSelect:n}){return h.jsxs("div",{children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Model"}),h.jsx("div",{className:"flex flex-wrap gap-1.5","data-testid":"config-model-selector",children:t.map(r=>{const i=(e||"")===r.id;return h.jsx("button",{type:"button",onClick:()=>n(r.id),"data-testid":`config-model-${r.id||"default"}`,className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",i?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:r.label},r.id||"default")})})]})}function vne({current:e,modes:t,onSelect:n}){var i;const r=(i=t.find(s=>s.id===(e||"")))==null?void 0:i.description;return h.jsxs("div",{children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Permission Mode"}),h.jsx("div",{className:"flex flex-wrap gap-1.5","data-testid":"config-mode-selector",children:t.map(s=>{const o=(e||"")===s.id;return h.jsx("button",{type:"button",onClick:()=>n(s.id),"data-testid":`config-mode-${s.id||"default"}`,className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",o?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:s.label},s.id||"default")})}),r?h.jsx("p",{className:"text-[11px] text-text-400 mt-1.5",children:r}):null]})}function xne({open:e,onOpenChange:t,session:n,onPatch:r,embedded:i=!1,viewerRole:s="owner"}){var m;const{capabilities:o}=my(e?n.tool||"claude":null),a=(o==null?void 0:o.models)??[],l=(o==null?void 0:o.permissionModes)??[],c=((m=o==null?void 0:o.configSchema.find(v=>v.name==="permissionMode"))==null?void 0:m.default)??"",u=n.permissionMode&&l.some(v=>v.id===n.permissionMode)?n.permissionMode:c,d=g.useMemo(()=>(o==null?void 0:o.configSchema.filter(v=>v.scope==="tool-specific"))??[],[o]),f=(o==null?void 0:o.toolSessionIdLabel)??"Tool Session ID";if(!e)return null;const p=h.jsxs("div",{className:"flex-1 min-h-0 flex flex-col px-4 py-4 gap-6 overflow-y-auto",children:[h.jsxs("div",{className:"shrink-0",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1",children:"Working Directory"}),h.jsx("div",{className:"text-[12px] font-mono text-text-300 bg-bg-100 rounded-lg px-3 py-2 truncate","data-testid":"config-cwd",title:n.cwd,children:n.cwd})]}),h.jsx("div",{className:"shrink-0",children:h.jsx(gne,{current:n.model??"",models:a,onSelect:v=>void r({model:v})})}),h.jsx("div",{className:"shrink-0",children:h.jsx(vne,{current:u,modes:l,onSelect:v=>void r({permissionMode:v})})}),d.length>0?h.jsx("div",{className:"shrink-0",children:h.jsx(_ne,{fields:d,models:a,session:n,onPatch:r})}):null,h.jsx("div",{className:"shrink-0",children:h.jsx(Hk,{testId:"config-session-id",label:"Clawd Session ID",value:n.sessionId})}),n.toolSessionId?h.jsx("div",{className:"shrink-0",children:h.jsx(Hk,{testId:"config-tool-session-id",label:f,value:n.toolSessionId})}):null]});return i?h.jsxs("div",{"data-testid":"config-drawer",className:"h-full w-full flex flex-col",children:[h.jsx("div",{className:"flex items-center px-4 py-3 border-b border-bg-300/30 shrink-0",children:h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Session Settings"})}),p]}):h.jsxs("div",{"data-testid":"config-drawer",className:"h-full w-full flex flex-col border-l border-bg-300/40 bg-bg-0 min-w-0",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bg-300/30 shrink-0",children:[h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Session Settings"}),h.jsx("button",{type:"button",onClick:()=>t(!1),"data-testid":"config-drawer-close",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":"Close",children:h.jsx(Rn,{className:"w-4 h-4"})})]}),p]})}function Hk({testId:e,label:t,value:n}){const[r,i]=g.useState(!1),s=g.useRef(null);g.useEffect(()=>()=>{s.current&&clearTimeout(s.current)},[]);const o=()=>{typeof navigator>"u"||!navigator.clipboard||navigator.clipboard.writeText(n).then(()=>{i(!0),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>i(!1),2e3)},()=>{})};return h.jsxs("div",{"data-testid":e,children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1",children:t}),h.jsxs("button",{type:"button",onClick:o,"data-testid":`${e}-copy`,title:r?"Copied":`Copy: ${n}`,className:"w-full flex items-center gap-2 text-[12px] font-mono text-text-300 bg-bg-100 hover:bg-bg-200 rounded-lg px-3 py-2 transition-colors cursor-pointer text-left group",children:[h.jsx("span",{className:"truncate flex-1 min-w-0","data-testid":`${e}-value`,children:n}),r?h.jsx(Qa,{className:"w-3.5 h-3.5 shrink-0 text-accent"}):h.jsx(su,{className:"w-3.5 h-3.5 shrink-0 opacity-60 group-hover:opacity-100 transition-opacity"})]})]})}function _ne({fields:e,models:t,session:n,onPatch:r}){return h.jsxs("div",{"data-testid":"config-advanced",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Advanced"}),h.jsx("div",{className:"space-y-3",children:e.map(i=>h.jsx(yne,{field:i,models:t,session:n,onPatch:r},i.name))})]})}function yne({field:e,models:t,session:n,onPatch:r}){const i=e.name==="effort"?mne(n.model??"",t,[e]):{options:e.options??[],defaultValue:e.default??""},s=i.options;if(e.type!=="select"||s.length===0)return null;const o=n[e.name]??"",a=s.some(l=>l.value===o)?o:i.defaultValue;return h.jsxs("div",{"data-testid":`config-advanced-${e.name}`,children:[h.jsx("div",{className:"text-[11px] text-text-400 mb-1.5",children:e.label}),h.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map(l=>{const c=a===l.value;return h.jsx("button",{type:"button","data-testid":`config-advanced-${e.name}-${l.value||"default"}`,onClick:()=>void r({[e.name]:l.value}),className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",c?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:l.label},l.value||"default")})})]})}function bne(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 wne(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()}}function Sne({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onConfigPatch:l,onFork:c,onQuickAsk:u,className:d,viewerRole:f="owner",holdIds:p,onToggleHold:m}){const{capabilities:v}=my(t.tool),[y,x]=g.useState(0),[_,b]=g.useState(!1),{initialSize:w,setSize:k}=dA("clawd:panel:config-px",360),{branch:C}=bne(e,t.cwd,y),{worktreeRoot:N}=wne(e,t.cwd,y),T=r>1,L=P=>{P==="desktop"?b(!0):a()};return h.jsxs("div",{className:`group/pane relative flex-1 ${d??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${T?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsxs(I_,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Fc,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:h.jsx(kne,{api:e,session:t,models:v==null?void 0:v.models,liveGitBranch:C,liveWorktreeRoot:N,onNewSession:o,onTurnEnd:()=>x(P=>P+1),onOpenConfig:L,onFork:c,onQuickAsk:u,viewerRole:f,holdIds:p,onToggleHold:m})})}),_&&h.jsxs(h.Fragment,{children:[h.jsx(M_,{className:"hidden md:block w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Fc,{id:"config",defaultSize:`${w}px`,minSize:"360px",maxSize:"560px",onResize:P=>k(P.inPixels),children:h.jsx("div",{className:"hidden md:flex h-full",children:h.jsx(xne,{open:_,onOpenChange:b,session:t,onPatch:l,viewerRole:f})})})]})]}),T&&h.jsx("button",{type:"button",onClick:P=>{P.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(Rn,{className:"w-3.5 h-3.5"})})]})}function kne({api:e,session:t,models:n,liveGitBranch:r,liveWorktreeRoot:i,onNewSession:s,onTurnEnd:o,onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:u,holdIds:d,onToggleHold:f}){return h.jsx(dne,{extras:{session:t,api:e,...n?{models:n}:{},...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},onNewSession:s,onTurnEnd:o,onOpenConfig:a,...l?{onFork:p=>{l(p)}}:{},...c?{onQuickAsk:p=>{c(p)}}:{},...u?{viewerRole:u}:{},...d?{holdIds:d}:{},...f?{onToggleHold:f}:{}}})}function Cne({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,onConfigPatch:p}){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(qH,{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(Sne,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},onConfigPatch:p,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 Ene(){const e=Bi(),t=g.useMemo(()=>new qx(e),[e]),n=hB(e),{sessions:r,refresh:i}=fB(n),{personas:s}=AN(),o=_B(),a=g.useMemo(()=>{const w=window.location.pathname.match(/^\/s\/([^/]+)/);return w?decodeURIComponent(w[1]):null},[]),l=g.useMemo(()=>r.filter(w=>!w.ephemeral&&w.larkChatId==null),[r]),c=g.useMemo(()=>a?s.filter(w=>w.personaId===a):s,[s,a]),[u,d]=g.useState(null),[f,p]=g.useState(null),[m,v]=g.useState(null);g.useEffect(()=>{let w=!1;return e.request("whoami",{}).then(k=>{w||d(k.capability.id)}).catch(()=>{}),()=>{w=!0}},[e]),g.useEffect(()=>{a&&p(a)},[a]);const y=g.useCallback(async(w,k)=>{const C=await t.sessionCreate({ownerPersonaId:w,...k.trim()?{label:k.trim()}:{}});await i(),p(w),v(C.sessionId)},[t,i]),x=g.useCallback(async w=>{await t.sessionDelete(w),await i(),v(k=>k===w?null:k)},[t,i]),_=g.useCallback(async(w,k)=>{await t.sessionUpdate(w,{label:k.label,iconKey:k.iconKey===null?"":k.iconKey}),await i()},[t,i]),b=g.useMemo(()=>l.find(w=>w.sessionId===m)??null,[l,m]);return h.jsx(Kx.Provider,{value:o,children:h.jsx(Cne,{personas:c,sessions:l,api:t,selfPrincipalId:u,selectedPersonaId:f,selectedSessionId:m,selectedSession:b,onSelectPersona:p,onSelectSession:v,onCreateSession:(w,k)=>void y(w,k),onDeleteSession:w=>void x(w),onEditSession:(w,k)=>void _(w,k),onCloseSession:()=>v(null),onConfigPatch:async()=>{}})})}const Uk="https://app.ttcadvisory.com";function Nne({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=`${Uk}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==Uk)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 D0="clawd-visitor:token";function Tne(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function Pne(){return{async getUrl(e){const t=localStorage.getItem(D0);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=Tne(window.location,{});return await kN(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function Ine(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function Rne(){const e=Bi(),t=g.useMemo(()=>dB(e),[e]);return h.jsx(qO,{cache:t.cache,children:h.jsx(XO,{children:h.jsx(Ene,{})})})}function Mne({host:e}){const[t]=g.useState(()=>localStorage.getItem(D0)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>Ine(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return Pne().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(L1,{host:e,children:h.jsx(mb,{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(WO,{host:e,children:h.jsx(Rne,{})}):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(L1,{host:e,children:h.jsx(mb,{children:h.jsx(Nne,{onAuthed:o=>{localStorage.setItem(D0,o),window.location.reload()}})})})}function Ane({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):jne(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:ne("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 jne(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 Dne({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(Lne,{status:t.status}),h.jsx("span",{className:ne("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 Lne({status:e}){return e==="completed"?h.jsx(Df,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(rr,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(ON,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function One(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 Bne({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(jf,{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 zne(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 $ne={render:({input:e})=>st.createElement(Dne,{items:One(e)})},Fne={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=zne(e);return st.createElement(Bne,{description:t,prompt:n,subagentType:r})}},fA={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=Une(e),c=l?st.createElement(Ane,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return st.createElement(jR,{tool:Hne(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function Hne(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function Une(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}}pu.register("claude","TodoWrite",$ne);pu.register("claude","Task",Fne);pu.register("claude","Edit",fA);pu.register("claude","Write",fA);const pA=document.getElementById("root");if(!pA)throw new Error("guest-main: #root not found");const Wne=G5({});Hm.createRoot(pA).render(h.jsx(st.StrictMode,{children:h.jsx(Mne,{host:Wne})}));
562
+ */var ete=2,tte=1,nte=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){var d;if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:((d=this._terminal.options.overviewRuler)==null?void 0:d.width)||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue("height")),i=Math.max(0,parseInt(n.getPropertyValue("width"))),s=window.getComputedStyle(this._terminal.element),o={top:parseInt(s.getPropertyValue("padding-top")),bottom:parseInt(s.getPropertyValue("padding-bottom")),right:parseInt(s.getPropertyValue("padding-right")),left:parseInt(s.getPropertyValue("padding-left"))},a=o.top+o.bottom,l=o.right+o.left,c=r-a,u=i-l-t;return{cols:Math.max(ete,Math.floor(u/e.css.cell.width)),rows:Math.max(tte,Math.floor(c/e.css.cell.height))}}};let Om;function Bm(){return{count:0,byteSum:0,firstT:null,lastT:null}}const zm=32,Lk=320;function rte({sessionId:e,client:t}){const n=g.useRef(null),r=g.useRef(null),i=g.useRef(null),s=g.useRef([]),o=g.useRef(Bm()),a=g.useRef(!1),[l,c]=g.useState("collapsed"),[u,d]=g.useState(null);g.useEffect(()=>{const v=n.current;if(!v)return;let y=!1;const x=(N,T)=>getComputedStyle(document.documentElement).getPropertyValue(N).trim()||T,_=x("--bg-0","#1B1B1B"),b=x("--text-100","#ECECEC"),w=new Jee({fontFamily:"ui-monospace, SF Mono, Menlo, monospace",fontSize:12,lineHeight:1.2,theme:{background:_,foreground:b},minimumContrastRatio:4.5,cursorBlink:!0,convertEol:!1,scrollback:5e3,allowProposedApi:!0,cols:120,rows:40}),k=new nte;w.loadAddon(k),Re("xterm-mount",{sessionId:e,hostChildCount:v.childNodes.length}),Om!==e&&(Re("xterm-trace",`===== SWITCH ${Om??"(initial)"} → ${e} =====`),Om=e),Re("xterm-trace","effect-setup-start",{sessionId:e,t:performance.now()}),o.current=Bm(),w.open(v);const C=w.onData(N=>{const T=btoa(unescape(encodeURIComponent(N)));t.request("session:pty:input",{sessionId:e,data:T}).catch(()=>{})});return(async()=>{var R;let N=0,T=null,L=null;try{Re("xterm-trace","snapshot-rpc-start",{sessionId:e,t:performance.now()});const D=await t.request("session:pty:snapshot",{sessionId:e});if(Re("xterm-trace","snapshot-rpc-resolved",{sessionId:e,cancelled:y,byteLen:((R=D==null?void 0:D.data)==null?void 0:R.length)??0,atSeq:D==null?void 0:D.atSeq,t:performance.now()}),y)return;if(D!=null&&D.ok&&typeof D.data=="string"&&D.data.length>0){const z=atob(D.data),$=new Uint8Array(z.length);for(let F=0;F<z.length;F++)$[F]=z.charCodeAt(F);T=$}D!=null&&D.ok&&typeof D.atSeq=="number"&&(N=D.atSeq),D!=null&&D.ok&&D.popupKind!=null&&(L=D.popupKind)}catch{}if(y)return;r.current=w,i.current=k;let P=!1,O;const I=w.onRender(()=>{if(!P){P=!0;try{k.fit(),T&&w.write(T),Re("xterm-trace","snapshot-flush",{sessionId:e,atSeq:N,pendingFrameCount:s.current.length,frameStatsBeforeFlush:{...o.current},t:performance.now()}),o.current=Bm();const D=s.current;s.current=[];let z=0;for(const $ of D){if($.seq!==void 0&&$.seq<=N){z++;continue}w.write($.bytes)}z>0&&Re("xterm-trace","snapshot-flush-dropped",{sessionId:e,dropped:z,atSeq:N}),a.current=!0,L!=null&&(d(L),c("expanded"),requestAnimationFrame(()=>w.focus())),t.request("session:pty:resize",{sessionId:e,cols:w.cols,rows:w.rows}).catch(()=>{})}catch{}w.scrollToBottom(),O?O():setTimeout(()=>O==null?void 0:O(),0)}});O=()=>I.dispose()})(),()=>{Re("xterm-trace","cleanup-start",{sessionId:e,pendingFrameCount:s.current.length,termReady:a.current,frameStatsThisMount:{...o.current},t:performance.now()}),y=!0,C.dispose(),w.dispose(),r.current=null,i.current=null,a.current=!1,s.current=[],Re("xterm-trace","cleanup-cleared-pending",{sessionId:e,t:performance.now()})}},[e,t]),g.useEffect(()=>{const v=t.on("session:pty",x=>{const _=x;if(_.sessionId!==e||typeof _.data!="string")return;const b=o.current;b.count++,b.byteSum+=_.data.length;const w=performance.now();b.firstT===null&&(b.firstT=w),b.lastT=w;try{const k=atob(_.data),C=new Uint8Array(k.length);for(let N=0;N<k.length;N++)C[N]=k.charCodeAt(N);a.current&&r.current?r.current.write(C):s.current.push({seq:_.seq,bytes:C})}catch{}}),y=t.on("session:control",x=>{const _=x;if(_.sessionId===e)switch(_.kind){case"popup_open":(_.popupKind==="permission"||_.popupKind==="question")&&(d(_.popupKind),c("expanded"),requestAnimationFrame(()=>{var b;return(b=r.current)==null?void 0:b.focus()}));break;case"popup_close":d(null),c("collapsed");break}});return()=>{v(),y(),Re("xterm-trace","cleanup-off-listener",{sessionId:e,t:performance.now()})}},[e,t]),g.useEffect(()=>{const v=n.current;if(!v)return;let y=0,x=0;const _=()=>{const w=i.current,k=r.current;if(!(!w||!k)){try{w.fit()}catch{return}try{k.refresh(0,k.rows-1)}catch{}k.cols===y&&k.rows===x||(y=k.cols,x=k.rows,t.request("session:pty:resize",{sessionId:e,cols:k.cols,rows:k.rows}).catch(()=>{}))}},b=new ResizeObserver(()=>_());return b.observe(v),()=>b.disconnect()},[e,t]);const f=()=>{c(v=>{const y=v==="collapsed"?"expanded":"collapsed";return y==="expanded"&&requestAnimationFrame(()=>{var x;return(x=r.current)==null?void 0:x.focus()}),y})},p=l==="expanded"?Lk:zm,m=Lk-zm;return h.jsxs("div",{className:"border-t border-border bg-bg-0 overflow-hidden",style:{height:p},"data-testid":"xterm-panel","data-state":l,"data-mode":"tui","data-popup-kind":u??"",children:[h.jsxs("button",{type:"button",onClick:f,className:"flex items-center justify-between w-full px-3 py-1 text-xs text-text-200 bg-bg-200 hover:bg-bg-300 cursor-pointer border-b border-border",style:{height:zm,flexShrink:0},"data-testid":"xterm-panel-toggle",children:[h.jsxs("span",{className:"font-mono",children:[u==="permission"&&"⚠️ CC 需要权限确认 — 在下方终端按数字键 / Enter 选择",u==="question"&&"❓ CC 在问问题 — 在下方终端用 ↑/↓ + Enter 选择",u===null&&(l==="collapsed"?"▴ 展开原生 TUI 终端":"▾ 收起 TUI 终端")]}),h.jsx("span",{className:"text-text-200 text-[10px] opacity-60",children:l==="expanded"?"点击收起":"点击展开"})]}),h.jsx("div",{ref:n,className:"p-1",style:{height:m},"data-testid":"xterm-panel-host"})]})}function sA(e,t){const n=Co(),r=e?`session/${e}`:"",i=si(r)??Mc,s=g.useCallback(d=>{!e||!r||n.setData(r,f=>IN(f??Mc,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 my(e){const t=si(e?`capabilities/${e}`:"");return e?{capabilities:t??null,loading:!t}:{capabilities:null,loading:!1}}const ite=50;function ste({api:e,sessionId:t,toolSessionId:n,pageSize:r=ite}){const[i,s]=g.useState({messages:[],total:0,loading:!1,hasMore:!1,error:null}),o=g.useRef(0),a=g.useRef(n),l=g.useRef(null),c=g.useRef(0);g.useEffect(()=>{const d=a.current;if(a.current=n,!(l.current!==t)&&!(typeof d=="string"&&d!==n))return;if(s({messages:[],total:0,loading:!1,hasMore:!1,error:null}),o.current=0,!t){l.current=null;return}l.current=t;const m=++c.current;s(v=>({...v,loading:!0,error:null})),(async()=>{try{const v=await e.historyRead({sessionId:t,limit:r});if(m!==c.current)return;o.current=v.offset,s({messages:v.messages??[],total:v.total??0,loading:!1,hasMore:v.offset>0,error:null})}catch(v){if(m!==c.current)return;s({messages:[],total:0,loading:!1,hasMore:!1,error:v.message??"history load failed"})}})()},[e,t,n,r]);const u=g.useCallback(async()=>{if(!t)return;const d=o.current;if(d<=0)return;const f=Math.max(0,d-r),p=d-f;s(m=>({...m,loading:!0,error:null}));try{const m=await e.historyRead({sessionId:t,limit:p,offset:f});o.current=m.offset,s(v=>({...v,messages:[...m.messages??[],...v.messages],loading:!1,hasMore:m.offset>0}))}catch(m){s(v=>({...v,loading:!1,error:m.message??"load more failed"}))}},[e,t,r]);return{...i,loadMore:u}}function Ok(e){const t=rp(e);return t.commandName?t.commandArgs?`${t.commandName} ${t.commandArgs}`:t.commandName:e}function Bk(e){return e.kind==="user-text"||e.kind==="user-meta"&&e.metaKind==="slash-command"}function ote(e,t){const n=t.find(Bk);if(!n)return e;const r=Ok(n.text);for(let i=e.length-1;i>=0;i--){const s=e[i];if(Bk(s)&&Ok(s.text)===r)return e.slice(0,i)}return e}const ate=1e6;function lte(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 oA(e){const t=Bi(),n=g.useMemo(()=>new qx(t),[t]),r=si("sessions"),i=g.useMemo(()=>r==null?void 0:r.find(F=>F.sessionId===e),[r,e]),s=i==null?void 0:i.toolSessionId,o=i==null?void 0:i.tool,a=sA(e),{events:l,pendingPermissions:c,status:u,clearPermission:d,restorePermission:f}=a,p=ste({api:n,sessionId:e,toolSessionId:s}),m=g.useMemo(()=>p.messages.filter(F=>!F.isSidechain),[p.messages]),v=g.useMemo(()=>VR(m,0,o),[m,o]),y=c[0]??null,x=g.useMemo(()=>yZ(l,(y==null?void 0:y.requestId)??null),[l,y==null?void 0:y.requestId]),_=g.useMemo(()=>ote(v,x),[v,x]),b=g.useMemo(()=>x.map((F,j)=>({...F,seq:ate+j})),[x]),w=g.useMemo(()=>[..._,...b],[_,b]),k=pM(u),C=WZ(u),N=(i==null?void 0:i.resolvedModel)??(i==null?void 0:i.model),T=g.useMemo(()=>({sessionLabel:(i==null?void 0:i.label)||(i==null?void 0:i.larkChatName)||(i==null?void 0:i.larkChatId)||e,sessionId:e,...i!=null&&i.larkChatId?{larkChatName:i.larkChatName??i.larkChatId,larkChatType:i.larkChatType??"group"}:{},...N?{model:N}:{},...(()=>{const F=i==null?void 0:i.gitBranch;return F?{gitBranch:F}:{}})(),...(()=>{const F=lte(i);return F!==void 0?{contextPct:F}:{}})(),...i!=null&&i.cwd?{cwd:i.cwd}:{},...(()=>{const F=i==null?void 0:i.permissionMode;return F?{permissionMode:F}:{}})(),procAlive:k,streamInProgress:C,pinnedAt:(i==null?void 0:i.pinnedAt)??null}),[i,e,N,k,C]),L=g.useMemo(()=>t.isOpen?u==="error"?{kind:"error",message:"session error"}:{kind:"ready"}:{kind:"closed"},[t.isOpen,u]),P=g.useCallback(async F=>{await n.sessionSend(e,F)},[n,e]),O=g.useCallback(async F=>{if(!(i!=null&&i.cwd)||!s)throw new Error("fork requires sessionFile with cwd + toolSessionId");await n.sessionFork({cwd:i.cwd,toolSessionId:s,messageUuid:F})},[n,i==null?void 0:i.cwd,s]),I=g.useCallback(async F=>{await n.sessionRewind({sessionId:e,userMessageId:F,dryRun:!1})},[n,e]),R=g.useCallback(async F=>{await n.sessionUpdate(e,{model:F})},[n,e]),D=g.useCallback(async()=>{await n.sessionNew(e)},[n,e]),z=g.useCallback(async(F,j)=>{const B=c.find(E=>E.requestId===F);B&&d(F);try{await n.permissionRespond({sessionId:e,permissionRequestId:F,allow:j==="allow"})}catch(E){throw!((E==null?void 0:E.message)??"").startsWith("PERMISSION_REQUEST_STALE")&&B&&f(B),E}},[n,e,c,d,f]),$=g.useCallback(async()=>{await p.loadMore()},[p]);return g.useMemo(()=>({lines:w,connState:L,meta:T,historyDone:!p.hasMore,historyLoading:p.loading,pendingPermissions:c,sendText:P,fork:O,rewind:I,switchModel:R,clearSession:D,respondPermission:z,loadMoreHistory:$}),[w,L,T,p.hasMore,p.loading,c,P,O,I,R,D,z,$])}function cte({api:e,open:t,onOpenChange:n,scope:r,sessionId:i,onShareFile:s,onOpenInTab:o}){const[a,l]=g.useState([]),[c,u]=g.useState(null);g.useEffect(()=>{if(!t)return;let f=!1;return(async()=>{try{const p=await e.attachmentGroupList(i);if(f)return;l(p.entries)}catch(p){f||u(p.message)}})(),()=>{f=!0}},[e,i,t]);async function d(f){try{await e.attachmentGroupRemove(i,f.relPath),l(p=>f.from==="owner"?p.filter(m=>m.relPath!==f.relPath):p.map(m=>m.relPath===f.relPath?{...m,stale:!0}:m))}catch(p){u(p.message)}}return t?h.jsx(__,{delayDuration:120,children:h.jsxs("div",{"data-testid":"files-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-[420px] flex-col border-l border-border bg-elevated shadow-2xl",children:[h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-semibold text-text-100",children:[h.jsx(f6,{className:"h-4 w-4"}),"Edited Files"]}),h.jsx("button",{type:"button",onClick:()=>n(!1),className:"flex h-7 w-7 items-center justify-center rounded text-text-400 hover:bg-bg-200 hover:text-text-100","aria-label":"Close drawer",children:h.jsx(Rn,{className:"h-4 w-4"})})]}),h.jsxs("div",{className:"flex-1 overflow-y-auto",children:[h.jsx(ute,{title:`Session files (${a.length})`,subtitle:"agent Write/Edit 自动入清单",children:a.length===0?h.jsx(hte,{text:"还没有文件。agent Write/Edit 会自动加入清单。"}):a.map(f=>h.jsx(dte,{entry:f,onShareLink:()=>s(f.relPath),...o?{onOpenInTab:()=>o(f.relPath)}:{},onRemove:()=>d(f)},f.id))}),c?h.jsx("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-[11px] text-destructive",children:c}):null]})]})}):null}function ute({title:e,subtitle:t,children:n}){return h.jsxs("div",{className:"border-b border-border last:border-b-0",children:[h.jsx("div",{className:"sticky top-0 z-10 flex items-start justify-between bg-elevated px-4 py-2",children:h.jsxs("div",{className:"flex-1",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wide text-text-300",children:e}),t?h.jsx("div",{className:"mt-0.5 text-[11px] text-text-400",children:t}):null]})}),h.jsx("div",{className:"flex flex-col",children:n})]})}function dte({entry:e,onShareLink:t,onOpenInTab:n,onRemove:r}){var l;const i=(l=e.mime)!=null&&l.startsWith("image/")?y6:Ms,s=e.relPath.lastIndexOf("/"),o=s>=0?e.relPath.slice(0,s+1):"",a=s>=0?e.relPath.slice(s+1):e.relPath;return h.jsxs("div",{"data-testid":"files-drawer-group-row",className:ne("group flex items-center gap-2 px-4 py-2 hover:bg-bg-200",e.stale&&"opacity-50"),children:[h.jsx(i,{className:"h-4 w-4 shrink-0 text-text-400"}),h.jsxs("div",{className:"min-w-0 flex-1",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsxs(y_,{children:[h.jsx(b_,{asChild:!0,children:h.jsxs("span",{className:"flex min-w-0 items-baseline text-[13px] text-text-100",children:[o?h.jsx("span",{className:"truncate text-text-400",children:o}):null,h.jsx("span",{className:"shrink-0",children:a})]})}),h.jsx(Yf,{side:"top",align:"start",className:"max-w-[380px] break-all",children:e.relPath})]}),e.stale&&h.jsx("span",{className:"rounded bg-text-100/10 px-1 py-0 text-[10px] uppercase text-text-400",children:"stale"})]}),h.jsxs("div",{className:"flex items-center gap-1.5 truncate text-[11px] text-text-400",children:[h.jsx("span",{children:e.from}),h.jsx("span",{children:"·"}),h.jsx("span",{children:fte(e.addedAt)})]})]}),!e.stale&&h.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[n?h.jsx($m,{icon:h.jsx(Ac,{className:"h-3.5 w-3.5"}),title:"Open in tab",onClick:n}):null,h.jsx($m,{icon:h.jsx(Gx,{className:"h-3.5 w-3.5"}),title:"Share link",onClick:t}),e.from==="owner"&&h.jsx($m,{icon:h.jsx(Xx,{className:"h-3.5 w-3.5"}),title:"Remove",onClick:r})]})]})}function $m({icon:e,title:t,onClick:n}){return h.jsx("button",{type:"button",onClick:n,title:t,"aria-label":t,className:"flex h-7 w-7 items-center justify-center rounded text-text-400 hover:bg-text-100/10 hover:text-text-100",children:e})}function hte({text:e}){return h.jsx("div",{className:"px-4 py-3 text-[12px] italic text-text-400",children:e})}function fte(e){const t=Date.now()-e;return t<6e4?`${Math.max(1,Math.floor(t/1e3))}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function pte({persona:e,open:t,onClose:n,onTogglePublic:r,guestShareUrl:i,onChangeIcon:s,onDelete:o,embedded:a,onLoadPersonality:l,onSavePersonality:c,onDirtyChange:u,initialPersonality:d,onShareCapability:f,readOnly:p=!1,onChangeTool:m,larkBot:v}){const[y,x]=g.useState(!1),[_,b]=g.useState(!1),w=()=>{i&&navigator.clipboard.writeText(i).then(()=>{b(!0),setTimeout(()=>b(!1),2e3)})},k=N=>{x(N),u==null||u(N)},C=()=>{y&&!window.confirm("修改未保存,确定关闭?")||n()};return t?h.jsxs(h.Fragment,{children:[!a&&h.jsx("div",{className:"absolute inset-0 z-30 bg-black/30",onClick:C,"aria-hidden":"true"}),h.jsxs("aside",{className:a?"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(Y6,{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(Rn,{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(x6,{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(g6,{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(Gx,{className:"h-3.5 w-3.5"}),"分享"]}):null,o?h.jsx("button",{type:"button",onClick:o,"aria-label":"删除 persona",className:"rounded-sm p-1.5 text-text-400 hover:bg-bg-200 hover:text-error",children:h.jsx(Xx,{className:"h-4 w-4"})}):null]})]}),h.jsx("hr",{className:"border-border"}),r?h.jsxs(h.Fragment,{children:[h.jsxs("section",{className:"flex items-center justify-between gap-3",children:[h.jsxs("div",{className:"flex flex-col gap-0.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"公开访问"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"开启后这个 persona 才会出现在「邀请联系人」的可选列表里。关闭即拒所有新分享(已颁出的 token 不受影响)。"})]}),h.jsx(gte,{checked:e.public??!1,onChange:N=>r(N)})]}),e.public?h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"guest-share-link",children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx($N,{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:"访客分享链接"})]}),i?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("input",{readOnly:!0,value:i,onFocus:N=>N.currentTarget.select(),className:"min-w-0 flex-1 truncate rounded border border-border bg-bg-100 px-2 py-1 text-[12px] text-text-200","data-testid":"guest-share-link-input"}),h.jsx("button",{type:"button",onClick:w,className:"flex shrink-0 items-center gap-1 rounded border border-border px-2 py-1 text-[12px] text-text-200 hover:bg-bg-200","data-testid":"guest-share-link-copy",children:_?h.jsxs(h.Fragment,{children:[h.jsx(Qa,{className:"h-3 w-3"})," 已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(su,{className:"h-3 w-3"})," 复制"]})})]}),h.jsx("span",{className:"text-[11px] text-text-400",children:"任何 TTC 员工打开此链接(飞书登录)即可在该 persona 下交互。"})]}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"guest-share-link-no-tunnel",children:"需先开启 tunnel(公网访问)才能生成可分享给外部的链接。"})]}):null,h.jsx("hr",{className:"border-border"})]}):null,v?h.jsxs(h.Fragment,{children:[h.jsx(mte,{...v}),h.jsx("hr",{className:"border-border"})]}):null,s?h.jsxs("section",{className:"flex flex-col gap-1.5",children:[h.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"默认图标"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"新建该 persona 的 session 会默认继承此图标。"}),h.jsx(rI,{value:e.iconKey??null,onChange:s})]}):null,s?h.jsx("hr",{className:"border-border"}):null,m&&!p?h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"flex flex-col gap-1.5",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"Agent"}),h.jsx("div",{className:"flex gap-2",children:["claude","codex"].map(N=>h.jsx("button",{type:"button","data-testid":`persona-edit-tool-${N}`,onClick:()=>m(N),className:ne("flex-1 rounded-md border px-3 py-2 text-[12px]",(e.tool??"claude")===N?"border-accent bg-accent/10 text-accent":"border-bg-300 text-text-300"),children:N==="claude"?"Claude Code":"Codex"},N))}),h.jsx("span",{className:"text-[11px] text-text-400",children:"切换只影响之后新建的会话,已有会话保持原 tool。"})]}),h.jsx("hr",{className:"border-border"})]}):null,l?h.jsxs(h.Fragment,{children:[h.jsx(yte,{onLoad:l,...c?{onSave:c}:{},onDirtyChange:k,initialPersonality:d,readOnly:p}),h.jsx("hr",{className:"border-border"})]}):null,h.jsx(vte,{settings:e.sandboxSettings??null}),h.jsx("hr",{className:"border-border"}),h.jsx(xte,{skills:e.skills??[]}),h.jsx("hr",{className:"border-border"}),h.jsx(_te,{plugins:e.plugins??[]})]})]})]}):null}function mte({status:e,onBindManual:t,onUnbind:n}){const[r,i]=g.useState(!1),[s,o]=g.useState(null),[a,l]=g.useState(""),[c,u]=g.useState(""),d=p=>{p&&(i(!0),o(null),p().catch(m=>o(m instanceof Error?m.message:String(m))).finally(()=>i(!1)))},f=h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx(jf,{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:[f,e.state==="unbound"?h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"text-[11px] text-text-400",children:"绑定一个飞书自建应用后,这个 persona 就是它的 bot:拉进群后群成员 @ 它提问, 推理跑在你本机,回复自动发回群。"}),h.jsx("span",{className:"text-[11px] text-text-400",children:"先在飞书开放平台(open.feishu.cn)创建企业自建应用并启用机器人能力,再填入凭证:"}),t?h.jsxs("div",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-manual-form",children:[h.jsx("input",{value:a,onChange:p=>l(p.target.value),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:c,onChange:p=>u(p.target.value),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:r||!a||!c,onClick:()=>d(()=>t({appId:a,appSecret:c})),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:r?"绑定中…":"绑定"})]}):null]}):null,e.state==="bound"||e.state==="broken"?h.jsxs("div",{className:"flex flex-col gap-1.5",children:[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(p=>h.jsxs("li",{className:"text-[11px] text-text-300 truncate",children:["· ",p.chatName??p.chatId]},p.chatId))}):h.jsx("span",{className:"text-[11px] text-text-400","data-testid":"lark-bot-groups-empty",children:"还没有服务中的群。"}),n?h.jsx("button",{type:"button",disabled:r,onClick:()=>d(n),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,s?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:s}):null]}):h.jsxs("section",{className:"flex flex-col gap-1.5","data-testid":"lark-bot-section",children:[f,h.jsx("span",{className:"text-[11px] text-text-400",children:"状态加载中…"})]})}function gte({checked:e,onChange:t}){return h.jsx("button",{type:"button",role:"switch","aria-checked":e,onClick:()=>t(!e),"data-testid":"persona-public-toggle",className:ne("relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors",e?"bg-success":"bg-bg-300"),children:h.jsx("span",{className:ne("inline-block h-5 w-5 rounded-full bg-bg-0 shadow transition-transform",e?"translate-x-[22px]":"translate-x-0.5")})})}function vte({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(gd,{label:"权限默认模式",value:((t=e.permissions)==null?void 0:t.defaultMode)??"—"}),h.jsx(gd,{label:"沙箱启用",value:Fm((n=e.sandbox)==null?void 0:n.enabled)}),h.jsx(gd,{label:"沙箱内自动放行 Bash",value:Fm((r=e.sandbox)==null?void 0:r.autoAllowBashIfSandboxed)}),h.jsx(gd,{label:"允许非沙箱命令",value:Fm((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(Rl,{label:"沙箱外命令",paths:(s=e.sandbox)==null?void 0:s.excludedCommands}),h.jsx(Rl,{label:"允许读取",paths:(a=(o=e.sandbox)==null?void 0:o.filesystem)==null?void 0:a.allowRead}),h.jsx(Rl,{label:"拒绝读取",paths:(c=(l=e.sandbox)==null?void 0:l.filesystem)==null?void 0:c.denyRead}),h.jsx(Rl,{label:"允许写入",paths:(d=(u=e.sandbox)==null?void 0:u.filesystem)==null?void 0:d.allowWrite}),h.jsx(Rl,{label:"拒绝写入",paths:(p=(f=e.sandbox)==null?void 0:f.filesystem)==null?void 0:p.denyWrite})]})]})]})}function Fm(e){return e===!0?"是":e===!1?"否":"—"}function gd({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 Rl({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 xte({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 _te({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 yte({onLoad:e,onSave:t,onDirtyChange:n,initialPersonality:r,readOnly:i=!1}){const s=r!==void 0,[o,a]=g.useState(s),[l,c]=g.useState(s?r:""),[u,d]=g.useState(s?r:""),[f,p]=g.useState(null),[m,v]=g.useState(!1),[y,x]=g.useState(null),_=st.useRef(e),b=st.useRef(t),w=st.useRef(n);st.useEffect(()=>{_.current=e,b.current=t,w.current=n});const k=st.useCallback(()=>{a(!1),p(null),_.current().then(L=>{c(L),d(L),a(!0)}).catch(L=>{p(L instanceof Error?L.message:String(L))})},[]);st.useEffect(()=>{s||k()},[s,k]);const C=!i&&o&&u!==l;st.useEffect(()=>{i||w.current(C)},[C,i]);const N=()=>{b.current&&(v(!0),x(null),b.current(u).then(()=>{c(u),v(!1)}).catch(L=>{x(L instanceof Error?L.message:String(L)),v(!1)}))},T=()=>{d(l),x(null)};return h.jsxs("section",{className:"flex flex-col gap-2","data-testid":"persona-personality-section",children:[h.jsx("span",{className:"text-[12px] font-medium text-text-200",children:"人格 (Personality)"}),f?h.jsxs("div",{"data-testid":"persona-personality-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:["加载失败:",f]}),h.jsx("button",{type:"button",onClick:k,className:"rounded-sm border border-error px-2 py-0.5 text-[11px] hover:bg-error/10",children:"重试"})]}):null,y?h.jsxs("div",{"data-testid":"persona-personality-save-error",className:"rounded-md border border-error bg-error-dim px-3 py-2 text-[12px] text-error",children:["保存失败:",y]}):null,h.jsx("textarea",{"data-testid":"persona-personality-textarea",value:u,onChange:L=>d(L.target.value),readOnly:i,disabled:!i&&(!o||m),placeholder:o?"":"加载中…",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"}),!i&&h.jsxs("p",{className:"text-[10px] text-text-400",children:["写入到 ",h.jsx("code",{className:"font-mono",children:"<persona-dir>/CLAUDE.md"}),"。 修改只对新启动的 sub-session 生效。"]}),o&&C?h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx("button",{type:"button",onClick:T,disabled:m,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:N,disabled:m,"data-testid":"persona-personality-save-btn",className:"rounded-sm bg-accent-dim px-2 py-1 text-[12px] text-text-100 hover:opacity-90 disabled:opacity-60",children:m?"保存中…":"保存"})]}):null]})}const bte={state:"unbound",groups:[]};function wte(e,t){const[n,r]=g.useState(null);g.useEffect(()=>{if(!e)return;let o=!1;r(null);const a=async()=>{try{const u=await e.request("larkBot:status",{personaId:t});o||r(u)}catch{o||r(bte)}};a();const l=e.on("larkBot:state",u=>{const d=u;if(d.personaId!==t)return;const{personaId:f,...p}=d;r(p)}),c=e.on("daemon:connected",()=>{a()});return()=>{o=!0,l(),c()}},[e,t]);const i=g.useCallback(async o=>{e&&await e.request("larkBot:bindManual",{personaId:t,...o})},[e,t]),s=g.useCallback(async()=>{e&&await e.request("larkBot:unbind",{personaId:t})},[e,t]);return{status:n,bindManual:i,unbind:s}}function Ste({personaId:e,open:t,onClose:n,api:r,embedded:i,onDirtyChange:s,onShareCapability:o,viewerRole:a="owner"}){const{persona:l}=jN(e),c=pB(e),u=mB(),d=gB(),{httpBaseUrl:f}=Af(),p=Bi(),m=wte(a==="guest"?null:p,e),v=g.useMemo(()=>!(l!=null&&l.public)||!f||/^https?:\/\/(127\.0\.0\.1|localhost|0\.0\.0\.0|\[?::1\]?)([:/]|$)/i.test(f)?null:`${f}/s/${e}`,[l==null?void 0:l.public,f,e]),y=g.useCallback(N=>{u(e,{public:N}).catch(T=>{Re("persona","togglePublic failed",T)})},[u,e]),x=g.useCallback(N=>{u(e,{iconKey:N}).catch(T=>{Re("persona","changeIcon failed",T)})},[u,e]),_=g.useCallback(N=>{u(e,{tool:N}).catch(T=>{Re("persona","changeTool failed",T)})},[u,e]),b=g.useCallback(()=>{l&&confirm(`删除 persona "${l.label}"?`)&&(d(e).catch(N=>{Re("persona","delete failed",N)}),n())},[l,d,e,n]),w=g.useCallback(async()=>c.loaded?c.personality:(await c.refresh()).personality,[c]),k=g.useCallback(async N=>{await u(e,{personality:N}),await c.refresh()},[u,e,c]);if(!l)return null;const C=a==="guest";return h.jsx(pte,{embedded:i,persona:{...l,skills:c.skills,plugins:c.plugins,sandboxSettings:c.sandboxSettings},open:t,onClose:n,onLoadPersonality:w,onDirtyChange:s,readOnly:C,...C?{}:{onTogglePublic:y,guestShareUrl:v,onChangeIcon:x,onChangeTool:_,onDelete:b,onSavePersonality:k,larkBot:{status:m.status,onBindManual:m.bindManual,onUnbind:m.unbind},...o?{onShareCapability:o}:{}}})}function kte({api:e,open:t,onOpenChange:n,personaId:r,personaName:i,viewerRole:s}){return t?h.jsxs("div",{"data-testid":"persona-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-[420px] flex-col border-l border-border bg-elevated shadow-2xl",children:[h.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[h.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-[13px] font-semibold text-text-100",children:[h.jsx(Yx,{className:"h-4 w-4 shrink-0"}),h.jsxs("span",{className:"truncate",title:i,children:["Persona · ",i]})]}),h.jsx("button",{type:"button",onClick:()=>n(!1),className:"flex h-7 w-7 items-center justify-center rounded text-text-400 hover:bg-bg-200 hover:text-text-100","aria-label":"Close drawer",children:h.jsx(Rn,{className:"h-4 w-4"})})]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:h.jsx(Ste,{personaId:r,open:!0,onClose:()=>n(!1),api:e,embedded:!0,...s?{viewerRole:s}:{}},r)})]}):null}function Cte(e){try{const t=new URL(e);return t.protocol==="ws:"?t.protocol="http:":t.protocol==="wss:"&&(t.protocol="https:"),`${t.protocol}//${t.host}`}catch{return e}}function Ete(e,t){try{const n=new URL(e),r=new URL(t);return n.protocol=r.protocol,n.host=r.host,n.toString()}catch{return e}}async function gy(e,t,n,r,i){const s=await e.attachmentSignUrl({sessionId:n,relPath:r,...i!==void 0?{ttlSeconds:i}:{}});return Ete(s.url,Cte(t.url))}async function Nte(e,t,n,r,i=60){const s=window.open("about:blank","_blank");try{const o=await gy(e,t,n,r,i);s?s.location.href=o:window.open(o,"_blank")}catch(o){throw s&&s.close(),o}}async function Tte(e){var t;try{if((t=navigator.clipboard)!=null&&t.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{const n=document.createElement("textarea");n.value=e,n.style.position="fixed",n.style.left="-9999px",n.style.top="0",n.setAttribute("readonly",""),document.body.appendChild(n),n.select();const r=document.execCommand("copy");return document.body.removeChild(n),r}catch{return!1}}const Pte={...qc,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 Ite(e){const t=e.split("/");return t[t.length-1]||e}function aA({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:Ite(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(Uc,{remarkPlugins:[Vc],components:Pte,children:i})}):null})]})}function Rte({open:e,onOpenChange:t,relPath:n,loadMarkdown:r,onShare:i}){return e?h.jsx("div",{"data-testid":"md-preview-drawer",className:"fixed inset-y-0 right-0 z-50 flex w-1/2 max-w-[900px] flex-col border-l border-border bg-elevated shadow-2xl",children:h.jsx(aA,{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($N,{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(Rn,{className:"h-4 w-4"})})]})})}):null}function Mte({left:e,right:t,stage:n,onExpand:r,onCollapse:i}){const s=n==="stopped",[o,a]=g.useState(!1);async function l(){if(!o){a(!0);try{await r()}catch{}finally{a(!1)}}}async function c(){if(!o){a(!0);try{await i()}catch{}finally{a(!1)}}}return h.jsxs("div",{className:"flex h-full w-full min-h-0","data-testid":"two-pane-layout",children:[h.jsxs("div",{className:"relative flex min-w-0 flex-1 flex-col","data-testid":"two-pane-left",children:[s&&h.jsx("button",{type:"button",disabled:o,className:"absolute right-14 top-2 z-10 rounded border border-border bg-elevated px-2 py-1 text-[12px] text-text-100 hover:bg-bg-200 disabled:opacity-50 disabled:cursor-not-allowed",onClick:l,children:o?"启动中…":"展开预览"}),e]}),!s&&h.jsxs("div",{className:"flex w-1/2 min-w-[320px] flex-col border-l border-bg-200","data-testid":"two-pane-right",children:[h.jsx("div",{className:"flex items-center justify-end gap-2 border-b border-bg-200 bg-bg-50 px-2 py-1",children:h.jsx("button",{type:"button",disabled:o,className:"rounded px-2 py-1 text-[12px] text-text-300 hover:bg-bg-100 disabled:opacity-50",onClick:c,children:"收起预览"})}),h.jsx("div",{className:"min-h-0 flex-1",children:t})]})]})}const lA=aM,Ate=lM,cA=g.forwardRef(({className:e,...t},n)=>h.jsx(ty,{ref:n,className:ne("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",e),...t}));cA.displayName=ty.displayName;const vy=g.forwardRef(({className:e,children:t,...n},r)=>h.jsxs(Ate,{children:[h.jsx(cA,{}),h.jsxs(ny,{ref:r,className:ne("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(cM,{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(Rn,{className:"h-4 w-4"}),h.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));vy.displayName=ny.displayName;const xy=({className:e,...t})=>h.jsx("div",{className:ne("flex flex-col space-y-1.5 text-left",e),...t});xy.displayName="DialogHeader";const _y=({className:e,...t})=>h.jsx("div",{className:ne("flex flex-row justify-end gap-2",e),...t});_y.displayName="DialogFooter";const yy=g.forwardRef(({className:e,...t},n)=>h.jsx(ry,{ref:n,className:ne("text-lg font-semibold leading-none text-text-100",e),...t}));yy.displayName=ry.displayName;const uA=g.forwardRef(({className:e,...t},n)=>h.jsx(iy,{ref:n,className:ne("text-sm text-text-300",e),...t}));uA.displayName=iy.displayName;const jte=6173,Dte=6182;function Lte({open:e,onOpenChange:t,projectName:n,currentPort:r,allUsedPorts:i,onUpdate:s}){const o=[];for(let v=jte;v<=Dte;v++)(v===r||!i.includes(v))&&o.push(v);const[a,l]=g.useState(r),[c,u]=g.useState(!1),[d,f]=g.useState(null),p=a!==r&&!c;async function m(){if(p){u(!0),f(null);try{await s(a),t(!1)}catch(v){f((v==null?void 0:v.message)??String(v))}finally{u(!1)}}}return h.jsx(lA,{open:e,onOpenChange:t,children:h.jsxs(vy,{className:"max-w-md",children:[h.jsxs(xy,{children:[h.jsxs(yy,{children:["改端口 · ",n]}),h.jsxs(uA,{children:["手改通常发生在系统其他进程占了默认分配的端口、dev server 起不来时。 提交后 daemon 会停 dev server → 写 ",h.jsx("code",{className:"mx-1 rounded bg-bg-100 px-1 py-0.5 text-[11px]",children:".clawd-project.json"})," → 用新端口重新起。"]})]}),h.jsxs("div",{className:"flex flex-col gap-2",children:[h.jsx("label",{className:"text-xs text-text-400",children:"新端口(仅显示段内可用 + 当前端口)"}),h.jsx("select",{className:"h-9 rounded-md border border-border bg-elevated px-3 py-1 text-sm text-text-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",value:a,onChange:v=>l(Number(v.target.value)),disabled:c,children:o.map(v=>h.jsxs("option",{value:v,children:[v,v===r?"(当前)":""]},v))}),o.length===1&&h.jsx("div",{className:"text-[11px] text-text-400",children:"端口段已全被其它 project 占用,没有可换的;先删一个 idle project 释放端口。"}),d&&h.jsx("div",{className:"rounded border border-destructive/30 bg-destructive/5 px-3 py-2 text-[12px] text-destructive",children:d})]}),h.jsxs(_y,{children:[h.jsx(ni,{variant:"ghost",onClick:()=>t(!1),disabled:c,children:"取消"}),h.jsx(ni,{onClick:m,disabled:!p,children:c?"应用中…":"应用新端口"})]})]})})}const zk=[{stage:"build",label:"构建"},{stage:"deploy",label:"部署到阿里云"},{stage:"verify",label:"验证可访问性"}];function Ote({currentStage:e,onCancel:t}){const n=zk.findIndex(r=>r.stage===e);return h.jsxs("div",{"data-testid":"publish-progress",className:"flex items-center gap-3 border-b border-bg-200 bg-bg-50 px-3 py-1.5 text-[12px]",children:[zk.map((r,i)=>{const s=i<n,o=i===n,a=s?"text-text-300":o?"text-text-200":"text-text-500/50";return h.jsxs("span",{className:`flex items-center gap-1 ${a}`,children:[s?h.jsx(Df,{className:"size-3.5"}):o?h.jsx(rr,{className:"size-3.5 animate-spin"}):h.jsx(ON,{className:"size-3.5"}),h.jsxs("span",{children:[r.label,o?"中…":""]})]},r.stage)}),h.jsx("button",{type:"button",onClick:t,className:"ml-auto rounded px-2 py-0.5 text-[11px] text-text-400 hover:bg-bg-100 hover:text-text-200",children:"取消"})]})}const Bte={build:"构建",deploy:"部署",verify:"验证"};function zte({stage:e,onRetry:t,onDismiss:n}){return h.jsxs("div",{"data-testid":"publish-interrupted-banner",className:"flex items-center gap-2 border-b border-yellow-400/40 bg-yellow-400/10 px-3 py-1.5 text-[12px]",children:[h.jsx(jc,{className:"size-3.5 text-yellow-500"}),h.jsxs("span",{className:"text-text-200",children:["上次发布在 ",h.jsxs("strong",{className:"font-medium",children:["[",Bte[e],"]"]})," ","阶段被中断(daemon 重启)"]}),h.jsx("button",{type:"button",onClick:t,className:"ml-auto rounded bg-accent-main-100 px-2 py-0.5 text-[11px] text-oncolor-100 hover:opacity-90",children:"重新发布"}),h.jsx("button",{type:"button",onClick:n,className:"rounded px-2 py-0.5 text-[11px] text-text-400 hover:bg-bg-100 hover:text-text-200",children:"取消"})]})}const $te={build:"构建",deploy:"部署",verify:"验证",unknown:"未知"};function Fte({stage:e,onFocusChat:t,onClose:n}){return h.jsxs("div",{"data-testid":"publish-failed-banner",className:"flex items-center gap-2 border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[12px]",children:[h.jsx(Rs,{className:"size-3.5 text-destructive"}),h.jsxs("button",{type:"button",onClick:t,className:"flex-1 text-left text-text-200 hover:underline",children:["发布失败:",h.jsxs("strong",{className:"font-medium",children:["[",$te[e],"]"]})," ","已通知 assistant 接管 →"]}),h.jsx("button",{type:"button",onClick:n,"aria-label":"关闭失败提示",className:"rounded p-0.5 text-text-400 hover:bg-bg-100 hover:text-text-200",children:h.jsx(Rn,{className:"size-3.5"})})]})}const $k={"install-pending":{label:"等装依赖…",step:"1/3"},installing:{label:"安装依赖中…(可能要几十秒到几分钟)",step:"2/3"},"starting-dev-server":{label:"启动 dev server…(等监听端口才挂 iframe)",step:"3/3"}};function Hte({project:e,previewHost:t,previewScheme:n,onUpdatePort:r,allUsedPorts:i,publishSlot:s,publishInFlightStage:o,onDismissPublishJob:a,onRetryPublish:l,publishFailureBanner:c,onPublishFailureBannerClose:u,onPublishFailureBannerFocusChat:d}){var x,_;const[f,p]=g.useState(!1);if(!e)return h.jsx("div",{className:"flex h-full w-full items-center justify-center p-6 text-center text-[13px] text-text-400",children:"未绑定 project"});const m=e.stage??(e.isRunning?"running":"stopped"),v=t?`${n}://${t}/preview/${e.port}/`:null,y=e.prodUrl??null;return h.jsxs("div",{className:"flex h-full w-full flex-col","data-testid":"preview-pane",children:[h.jsxs("header",{className:"flex items-center justify-between gap-2 border-b border-bg-200 bg-bg-50 px-3 py-1.5",children:[h.jsxs("div",{className:"flex items-center gap-2 text-[12px]",children:[h.jsx("span",{className:"font-medium text-text-200",children:e.name}),h.jsx("span",{className:"rounded bg-bg-100 px-1.5 py-0.5 text-[11px] text-text-400",children:e.port}),h.jsx("span",{className:"text-[10px] uppercase tracking-wider text-text-500",children:m==="running"?"dev":m})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[y?h.jsxs("a",{href:y,target:"_blank",rel:"noopener noreferrer",title:`打开线上:${y}`,className:"inline-flex items-center gap-1 rounded border border-bg-200 px-2 py-0.5 text-[11px] text-text-300 hover:bg-bg-100",children:[h.jsx(Ac,{className:"size-3"}),"打开线上"]}):null,s,h.jsxs(VP,{children:[h.jsx(qP,{asChild:!0,children:h.jsx("button",{type:"button","aria-label":"Project settings",className:"rounded p-1 text-text-400 hover:bg-bg-100",children:h.jsx(G6,{className:"size-3.5"})})}),h.jsxs(v_,{align:"end",children:[h.jsx(Ys,{onSelect:()=>p(!0),children:"Update Port…"}),h.jsxs(Ys,{disabled:!0,title:"rename not supported yet",onSelect:b=>b.preventDefault(),children:["Name: ",e.name]})]})]})]})]}),c?h.jsx(Fte,{stage:c.stage,onClose:()=>u==null?void 0:u(),onFocusChat:()=>d==null?void 0:d()}):null,((x=e.publishJob)==null?void 0:x.status)==="in-flight"?h.jsx(Ote,{currentStage:o??e.publishJob.stage,onCancel:()=>void(a==null?void 0:a())}):null,((_=e.publishJob)==null?void 0:_.status)==="interrupted"?h.jsx(zte,{stage:e.publishJob.stage,onRetry:()=>void(l==null?void 0:l()),onDismiss:()=>void(a==null?void 0:a())}):null,h.jsx("div",{className:"min-h-0 flex-1",children:m==="failed"?h.jsx(Ute,{reason:e.stageReason}):m==="stopped"?null:m==="running"?v?h.jsx("iframe",{"data-testid":"preview-iframe",className:"size-full border-0 bg-white",src:v,title:"preview"}):h.jsx(Fk,{label:"等 tunnel 起来…",step:"-"}):h.jsx(Fk,{label:$k[m].label,step:$k[m].step})}),h.jsx(Lte,{open:f,onOpenChange:p,projectName:e.name,currentPort:e.port,allUsedPorts:i,onUpdate:async b=>{await r(b)}})]})}function Fk({label:e,step:t}){return h.jsxs("div",{"data-testid":"preview-spinner",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(rr,{className:"size-6 animate-spin text-accent-main-100"}),h.jsx("div",{className:"text-[13px] text-text-200",children:e}),h.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-500",children:t}),h.jsx("div",{className:"mt-2 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度"})]})}function Ute({reason:e}){return h.jsxs("div",{"data-testid":"preview-failed",className:"flex h-full w-full flex-col items-center justify-center gap-3 p-6 text-center",children:[h.jsx(Rs,{className:"size-6 text-destructive"}),h.jsx("div",{className:"text-[13px] text-text-200",children:"project 启动失败"}),h.jsx("div",{className:"max-w-[400px] text-[12px] text-text-400",children:e??"未知原因 —— 看 ~/.clawd/clawd.log 排查"}),h.jsx("div",{className:"mt-1 max-w-[300px] text-[11px] text-text-500",children:"左侧 chat 可看 assistant 详细进度 / 跟它说怎么修"})]})}function Wte({error:e,onClose:t}){const[n,r]=g.useState(!1),i=async()=>{var a;if(!e)return;const s=e.message;let o=!1;try{(a=navigator.clipboard)!=null&&a.writeText&&(await navigator.clipboard.writeText(s),o=!0)}catch{o=!1}if(!o){const l=document.createElement("textarea");l.value=s,l.style.position="fixed",l.style.opacity="0",document.body.appendChild(l),l.select();try{document.execCommand("copy"),o=!0}catch{o=!1}finally{document.body.removeChild(l)}}o&&(r(!0),setTimeout(()=>r(!1),1500))};return h.jsx(lA,{open:!!e,onOpenChange:s=>{s||(r(!1),t())},children:h.jsxs(vy,{className:"max-w-lg",children:[h.jsx(xy,{children:h.jsx(yy,{children:(e==null?void 0:e.title)??"错误"})}),h.jsx("pre",{"data-testid":"rpc-error-message",className:"max-h-72 overflow-auto whitespace-pre-wrap break-words rounded border border-bg-200 bg-bg-50 px-3 py-2 text-[12px] text-text-200",children:(e==null?void 0:e.message)??""}),h.jsxs(_y,{children:[h.jsx(ni,{variant:"ghost",onClick:i,className:"gap-1.5",children:n?h.jsxs(h.Fragment,{children:[h.jsx(Qa,{className:"size-3.5"}),"已复制"]}):h.jsxs(h.Fragment,{children:[h.jsx(su,{className:"size-3.5"}),"复制"]})}),h.jsx(ni,{onClick:t,children:"关闭"})]})]})})}function Vte(e,t){for(const n of[e,t])if(n)try{const r=new URL(n),i=r.protocol==="https:"||r.protocol==="wss:"?"https":"http";return{host:r.host,scheme:i}}catch{}return{host:null,scheme:"https"}}const qte={codex:"on-request",claude:"bypassPermissions"};function Kte(e){const t={cwd:e.cwd,permissionMode:e.sourcePermissionMode??qte[e.sourceTool??"claude"]??"bypassPermissions",forkedFromSessionId:e.sourceSessionId};return e.sourceOwnerPersonaId&&(t.ownerPersonaId=e.sourceOwnerPersonaId),e.sourceTool&&(t.tool=e.sourceTool),t}async function Gte(e,t,n,r={}){if(!t.toolSessionId)return null;const i=await e.sessionCreate({...Kte({cwd:t.cwd,sourceSessionId:t.sessionId,sourcePermissionMode:t.permissionMode,sourceOwnerPersonaId:t.ownerPersonaId,sourceTool:t.tool}),...r.ephemeral?{ephemeral:!0}:{}});try{const{forkedToolSessionId:s}=await e.sessionFork({cwd:t.cwd,toolSessionId:t.toolSessionId,messageUuid:n,targetCwd:i.cwd});await e.sessionResume(i.sessionId,s)}catch(s){throw e.sessionDelete(i.sessionId).catch(o=>Re("quick-ask","fork rollback failed",o)),s}return i}async function Xte(e,t,n){return Gte(e,t,n,{ephemeral:!0})}function vd(e){return e!=null&&e.ephemeral!==!1}async function Yte(e,t){return!t.stillEphemeral||!t.nextHold?!1:(await e.sessionUpdate(t.sessionId,{ephemeral:!1}),!0)}const Zte=300;function Qte(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function dA(e,t){const n=Ix(),[r,i]=g.useState(null),s=g.useRef(null);g.useEffect(()=>{let a=!1;return(async()=>{try{const l=await n.kv.get(e);if(a)return;const c=Qte(l);typeof c=="number"&&Number.isFinite(c)&&c>0?i(c):i(t)}catch{a||i(t)}})(),()=>{a=!0}},[n,e,t]);const o=g.useCallback(a=>{s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{s.current=null,n.kv.set(e,a).catch(()=>{})},Zte)},[n,e]);return g.useEffect(()=>()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),{initialSize:r??t,setSize:o,loading:r===null}}function Jte(){return{quickAsk:null,mds:[],active:null}}function ene(e,t){return{...e,quickAsk:{sessionId:t.sessionId,ephemeral:!0},active:"quick-ask"}}function tne(e,t){const n=e.mds.includes(t);return{...e,mds:n?e.mds:[...e.mds,t],active:{kind:"md",relPath:t}}}function nne(e){if(!e.quickAsk)return e;const t=e.active==="quick-ask",n=e.mds[0],r=t?n?{kind:"md",relPath:n}:null:e.active;return{...e,quickAsk:null,active:r}}function rne(e){return e.quickAsk?{...e,quickAsk:{...e.quickAsk,ephemeral:!1}}:e}function ine(e,t){const n=e.mds.indexOf(t);if(n<0)return e;const r=e.mds.filter(l=>l!==t);if(!(e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===t))return{...e,mds:r};const s=r[n],o=n>0?r[n-1]:void 0;let a=null;return s?a={kind:"md",relPath:s}:o?a={kind:"md",relPath:o}:e.quickAsk&&(a="quick-ask"),{...e,mds:r,active:a}}function sne(e,t){return{...e,active:t}}function one(e,t){return e===null||t===null||e==="quick-ask"||t==="quick-ask"?e===t:e.relPath===t.relPath}function hA(e){return e.quickAsk!==null||e.mds.length>0}function ane(e){return e.split("/").pop()||e}function lne({state:e,api:t,onSwitchTab:n,onCloseQuickAsk:r,onCloseMd:i,loadMarkdown:s,quickAskSession:o,onToggleHold:a,holdIds:l}){if(!hA(e))return null;const c=[];e.quickAsk&&c.push({id:"quick-ask",label:"问一下",title:"问一下",icon:h.jsx(Mh,{className:"w-3.5 h-3.5"})});for(const u of e.mds)c.push({id:{kind:"md",relPath:u},label:ane(u),title:u,icon:h.jsx(Ms,{className:"w-3.5 h-3.5"})});return h.jsxs("div",{className:"flex flex-col h-full bg-bg-0 border-l border-text-100/10",children:[h.jsx(__,{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:c.map(u=>{const d=one(e.active,u.id),f=u.id==="quick-ask"?"quick-ask":`md:${u.id.relPath}`;return h.jsxs(y_,{children:[h.jsx(b_,{asChild:!0,children:h.jsxs("div",{role:"tab","aria-selected":d,"data-tab-title":u.title,onClick:()=>n(u.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",d?"text-text-100":"text-text-400 hover:text-text-100 hover:bg-text-100/[0.04]"].join(" "),children:[u.icon,h.jsx("span",{className:"truncate",children:u.label}),h.jsx("button",{type:"button","aria-label":`关闭 ${u.label}`,className:["ml-1 rounded p-0.5 shrink-0 transition-opacity","hover:bg-text-100/10",d?"opacity-70 hover:opacity-100":"opacity-0 group-hover:opacity-70"].join(" "),onClick:p=>{p.stopPropagation(),u.id==="quick-ask"?r():i(u.id.relPath)},children:h.jsx(Rn,{className:"w-3 h-3"})}),d?h.jsx("span",{"aria-hidden":"true",className:"absolute left-2 right-2 -bottom-px h-[2px] rounded-full bg-accent"}):null]})}),h.jsx(Yf,{side:"bottom",align:"start",className:"max-w-sm break-all",children:u.title})]},f)})})}),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(une,{session:o,api:t,holdIds:l,...a?{onToggleHold:a}:{}})}):null,e.mds.map(u=>{const d=e.active!==null&&e.active!=="quick-ask"&&e.active.relPath===u;return h.jsx("div",{className:"absolute inset-0",style:{display:d?"block":"none"},children:h.jsx(aA,{relPath:u,loadMarkdown:s,showTitleBar:!1})},`md-body:${u}`)})]})]})}function cne({state:e,extras:t}){const{api:n,session:r,holdIds:i,onToggleHold:s}=t,o=Bi(),[a,l]=g.useState(Jte()),c=g.useRef(a);c.current=a;const u=g.useRef(!1),d=g.useCallback(async N=>{const T=c.current.quickAsk,L=await Xte(n,r,N);if(L){if(u.current){n.sessionDelete(L.sessionId).catch(()=>{});return}vd(T)&&n.sessionDelete(T.sessionId).catch(()=>{}),l(P=>ene(P,{sessionId:L.sessionId}))}},[n,r]),f=g.useCallback(async(N,T)=>{const L=c.current.quickAsk,P=(L==null?void 0:L.sessionId)===N;try{await Yte(n,{sessionId:N,stillEphemeral:P&&vd(L),nextHold:T})&&l(I=>rne(I))}catch(O){Re("quick-ask","promote failed",O);return}s==null||s(N,T)},[n,s]),p=g.useCallback(N=>{l(T=>tne(T,N))},[]),m=g.useCallback(N=>{l(T=>sne(T,N))},[]),v=g.useCallback(()=>{const N=c.current.quickAsk;vd(N)&&n.sessionDelete(N.sessionId).catch(()=>{}),l(T=>nne(T))},[n]),y=g.useCallback(N=>{l(T=>ine(T,N))},[]);g.useEffect(()=>()=>{u.current=!0;const N=c.current.quickAsk;vd(N)&&n.sessionDelete(N.sessionId).catch(()=>{})},[]);const x=si("sessions")??[],_=a.quickAsk?x.find(N=>N.sessionId===a.quickAsk.sessionId)??{sessionId:a.quickAsk.sessionId,cwd:r.cwd,tool:r.tool}:null,b=g.useCallback(async N=>{const T=await gy(n,o,r.sessionId,N,60),L=await fetch(T);if(!L.ok)throw new Error(`fetch ${L.status} ${L.statusText}`);return L.text()},[n,o,r.sessionId]),w=h.jsx(by,{state:e,extras:t,onQuickAskInternal:d,onPreviewMdInternal:p}),{initialSize:k,setSize:C}=dA("chat-panel-right-slot-width",480);return hA(a)?h.jsxs(I_,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Fc,{id:"chat",minSize:"400px",children:w}),h.jsx(M_,{className:"w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Fc,{id:"right-slot",defaultSize:`${k}px`,minSize:"360px",maxSize:"800px",onResize:N=>C(N.inPixels),children:h.jsx(lne,{state:a,api:n,onSwitchTab:m,onCloseQuickAsk:v,onCloseMd:y,loadMarkdown:b,quickAskSession:_,holdIds:i,onToggleHold:f})})]}):w}function une({session:e,api:t,holdIds:n,onToggleHold:r}){const i=oA(e.sessionId);return h.jsx(by,{state:i,extras:{session:e,api:t,holdIds:n,...r?{onToggleHold:r}:{}}})}function dne({extras:e}){const t=oA(e.session.sessionId);if(e.session.appBuilderProject){const n=h.jsx(by,{state:t,extras:e});return h.jsx(hne,{state:t,chat:n,extras:e})}return h.jsx(cne,{state:t,extras:e})}function hne({state:e,chat:t,extras:n}){var T;const r=si("daemon-info"),i=Bi(),s=n.api,o=n.session,a=o.appBuilderProject,[l,c]=g.useState(null),u=g.useCallback(()=>{s.appBuilderGetProject(o.sessionId).then(L=>c(L.project)).catch(()=>c(null))},[s,o.sessionId]);g.useEffect(()=>{u()},[u]);const[d,f]=g.useState([]),p=g.useCallback(()=>{s.appBuilderListProjects().then(L=>f(L.projects)).catch(()=>f([]))},[s]);g.useEffect(()=>{p()},[p]),g.useEffect(()=>i.on("appBuilder:project-updated",P=>{const O=P;O!=null&&O.project&&(O.project.name===a&&c(O.project),f(I=>{const R=I.findIndex(z=>z.name===O.project.name);if(R<0)return[...I,O.project];const D=I.slice();return D[R]=O.project,D}))}),[i,a]);const{host:m,scheme:v}=Vte(i.url,r==null?void 0:r.tunnelUrl),[y,x]=g.useState(void 0),[_,b]=g.useState(null);g.useEffect(()=>{const L=i.on("appBuilder:publish-progress",O=>{const I=O;!I||I.name!==a||I.status==="started"&&x(I.stage)}),P=i.on("appBuilder:publish-failed",O=>{const I=O;!I||I.name!==a||(x(void 0),b({stage:I.stage}))});return()=>{L(),P()}},[i,a]),g.useEffect(()=>{x(void 0),b(null)},[a]);const[w,k]=g.useState(null),C=h.jsx("button",{type:"button",className:"rounded bg-accent-main-100 px-2.5 py-1 text-[12px] text-oncolor-100 hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",disabled:((T=l==null?void 0:l.publishJob)==null?void 0:T.status)==="in-flight",onClick:async()=>{try{await s.appBuilderPublish(a)}catch(L){k({title:"发布请求失败",message:(L==null?void 0:L.message)??String(L)})}},children:"发布上线"}),N=(l==null?void 0:l.stage)??(l!=null&&l.isRunning?"running":"stopped");return h.jsxs(h.Fragment,{children:[h.jsx(Mte,{left:t,stage:N,onExpand:async()=>{await s.appBuilderStartDevServer(o.sessionId)},onCollapse:async()=>{await s.appBuilderStopDevServer(o.sessionId)},right:h.jsx(Hte,{project:l,previewHost:m,previewScheme:v,allUsedPorts:d.map(L=>L.port),onUpdatePort:async L=>{await s.appBuilderUpdateProjectPort(a,L),p()},publishSlot:C,publishInFlightStage:y,onDismissPublishJob:async()=>{try{await s.appBuilderDismissPublishJob(a)}catch(L){k({title:"取消发布失败",message:(L==null?void 0:L.message)??String(L)})}},onRetryPublish:async()=>{try{await s.appBuilderPublish(a)}catch(L){k({title:"重新发布失败",message:(L==null?void 0:L.message)??String(L)})}},publishFailureBanner:_,onPublishFailureBannerClose:()=>b(null),onPublishFailureBannerFocusChat:()=>{}})}),h.jsx(Wte,{error:w,onClose:()=>k(null)})]})}function fne({headerMeta:e,connState:t,models:n,liveGitBranch:r,liveWorktreeRoot:i,onOpenConfig:s,onForceStop:o,cronActiveCount:a,onCronClick:l,lines:c,pendingPermissions:u,procAlive:d,rewindableUserMessageIds:f,onPermissionRespond:p,onPermissionInterrupt:m,onRewind:v,onFork:y,onQuickAsk:x,topSlot:_,realtimeQuestionAnswers:b,onSubmitQuestion:w,onCancelQuestion:k,liveQuestionToolUseIds:C,api:N,cwd:T,tool:L,sessionKey:P,onSend:O,awaitingUser:I,onAbort:R,onNewSession:D,onClearSession:z,chatRootRef:$,chatBodyRef:F,topSentinelRef:j,drawers:B,xtermSlot:E,fileSharingScope:H,onShareFile:q,onOpenInTab:M,onPreviewMarkdown:re,onOpenFiles:oe,onTogglePin:V,isHolded:pe,onToggleHold:Oe,personaName:ie,onOpenPersona:Ae}){return h.jsx(CY,{children:h.jsxs("div",{ref:$,"data-cc-chat-root":"",className:"flex flex-col h-full bg-bg-0",children:[h.jsx(gZ,{meta:e,...L?{tool:L}:{},connState:t,...n?{models:n}:{},...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},...s?{onOpenConfig:s}:{},...o?{onForceStop:o}:{},cronActiveCount:a,...l?{onCronClick:l}:{},...oe?{onOpenFiles:oe}:{},...V?{onTogglePin:V}:{},isHolded:pe??!1,...Oe?{onToggleHold:Oe}:{},...ie?{personaName:ie}:{},...Ae?{onOpenPersona:Ae}:{}}),h.jsxs("div",{ref:F,"data-testid":"chat-body",className:"flex-1 overflow-y-auto min-h-0",style:{overflowAnchor:"none"},children:[j?h.jsx("div",{ref:j,"data-testid":"top-sentinel","aria-hidden":"true",style:{height:1}}):null,h.jsx($R,{lines:c,...p?{onPermissionRespond:p}:{},...m&&d?{onPermissionInterrupt:m}:{},topSlot:_,...v?{onRewind:v}:{},rewindableUserMessageIds:f,...y?{onFork:y}:{},...x?{onQuickAsk:x}:{},realtimeQuestionAnswers:b,onSubmitQuestion:w,...k?{onCancelQuestion:k}:{},liveQuestionToolUseIds:C,...H?{fileSharingScope:H}:{},...q?{onShareFile:q}:{},...M?{onOpenInTab:M}:{},...re?{onPreviewMarkdown:re}:{}})]}),E,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(pZ,{meta:e,...N?{api:N}:{},cwd:T,...L?{tool:L}:{},sessionKey:P,onSend:O,awaitingUser:I,...R?{onAbort:R}:{},...D?{onNewSession:D}:{},...z?{onClearSession:z}:{}}),B]})})}function by({state:e,extras:t,onQuickAskInternal:n,onPreviewMdInternal:r}){const{session:i,api:s,models:o,liveGitBranch:a,liveWorktreeRoot:l,onNewSession:c,onTurnEnd:u,onOpenConfig:d,onFork:f,onQuickAsk:p,viewerRole:m,holdIds:v,onToggleHold:y}=t,{capabilities:x}=my(i.tool||"claude"),_=(x==null?void 0:x.features)??PN(i.tool),[b,w]=g.useState(null),[k,C]=g.useState(!1),[N,T]=g.useState(!1),L=Af(),P=!!s&&L.actionsLevel==="owner"&&_.fileSharing,O=jN(i.ownerPersonaId??null).persona,I=(O==null?void 0:O.label)??null,R=!!I&&!!i.ownerPersonaId,D=g.useCallback(()=>{T(!1),C(!0)},[]),z=g.useCallback(()=>{C(!1),T(!0)},[]),$=g.useCallback((Z,xe)=>{w({kind:Z,text:xe}),setTimeout(()=>{w(ye=>(ye==null?void 0:ye.text)===xe?null:ye)},2e3)},[]),F=Bi(),j=VO(),B=sA(i.sessionId,i.toolSessionId),{events:E,pendingQuestions:H,clearQuestion:q,markQuestionSubmitted:M,status:re}=B,oe=e.historyLoading,V=pM(re);g.useEffect(()=>{Re("chat-panel","sessionStatus",{sessionId:i.sessionId,sessionStatus:re,procAlive:V})},[re,V,i.sessionId]);const pe=e.lines,Oe=e.pendingPermissions,ie=Oe[0]??null,Ae=g.useMemo(()=>R7(E),[E]),[Fe,We]=g.useState(!1),[ge,qe]=g.useState(null),[Gt,wt]=g.useState(()=>new Set);T7(s,i.sessionId,i.toolSessionId,_.observe);const Rt=g.useRef(i.sessionId);g.useEffect(()=>{if(Rt.current=i.sessionId,!_.rewind){qe(null);return}let Z=!1;return qe(null),(async()=>{try{const xe=await s.sessionRewindableMessageIds(i.sessionId);if(Z)return;qe(new Set(xe.userMessageIds))}catch{Z||qe(null)}})(),()=>{Z=!0}},[s,i.sessionId,_.rewind]);const ln=g.useCallback(()=>{const Z=i.sessionId;s.sessionRewindableMessageIds(Z).then(xe=>{Rt.current===Z&&qe(new Set(xe.userMessageIds))}).catch(()=>{})},[s,i.sessionId]),Bt=g.useMemo(()=>{if(ge!==null){const Ze=new Set(ge);for(const hi of Gt)Ze.delete(hi);return Ze}const Z=new Set(["Edit","Write","MultiEdit","NotebookEdit"]),xe=new Set;let ye=null;for(const Ze of pe)Ze.kind==="user-text"?ye=Ze.uuid??null:ye&&Ze.kind==="tool-call"&&Z.has(Ze.tool)&&!Gt.has(ye)&&xe.add(ye);return xe},[pe,Gt,ge]),at=g.useRef(u);at.current=u,P7(i.sessionId,i.toolSessionId,()=>{pn(null),wt(new Set)});const Ue=UZ({sessionStatus:re}),nt=g.useRef(null);g.useEffect(()=>{var ye;const Z=nt.current,xe=(Z==null?void 0:Z.sid)===i.sessionId;xe&&Z.phase===Ue||(nt.current={sid:i.sessionId,phase:Ue},Re("session-phase",Ue,{sid:i.sessionId,phase:Ue,prev:xe?Z.phase:null,desc:HZ[Ue]}),xe&&Z.phase==="turn-running"&&Ue!=="turn-running"&&((ye=at.current)==null||ye.call(at),ln()))},[Ue,i.sessionId,ln]);const mt=g.useCallback(()=>{s.sessionInterrupt(i.sessionId).catch(()=>{})},[s,i.sessionId]),[Xt,pn]=g.useState(null),U=g.useCallback(Z=>{pn(Z)},[]),[Q,ve]=g.useState(!1),Se=g.useCallback(()=>{s.sessionStop(i.sessionId).catch(()=>{}),ve(!1)},[s,i.sessionId]),J=g.useCallback(Z=>{s.pinSession(i.sessionId,Z).catch(xe=>{Re("chat-panel","pinSession failed",{err:xe==null?void 0:xe.message})})},[s,i.sessionId]),Ye=(v==null?void 0:v.has(i.sessionId))??!1,Yt=g.useCallback(Z=>{y==null||y(i.sessionId,Z)},[y,i.sessionId]),Zt=g.useRef(0),ue=g.useRef(null);g.useEffect(()=>{const Z=xe=>{if(xe.key!=="Escape")return;if(!V){Zt.current=0;return}if(xe.isComposing)return;const Ze=xe.target;if(Ze&&Ze.closest("[data-cc-chat-root]")!==ue.current)return;const hi=Date.now();hi-Zt.current<2e3?(Zt.current=0,ve(!0)):(Zt.current=hi,mt())};return window.addEventListener("keydown",Z),()=>window.removeEventListener("keydown",Z)},[mt,V]);const Te=g.useRef(null),Je=g.useRef(null),Dn=g.useRef(!0),Qt=g.useRef(null),sl=g.useRef(0),jo=g.useRef(0);g.useEffect(()=>{Dn.current=!0,Qt.current=null,sl.current=0,jo.current=0},[i.sessionId]),g.useEffect(()=>{We(!1)},[i.sessionId]);const _u=g.useRef(e);_u.current=e;const yu=g.useCallback(()=>{var ye;const Z=Te.current;if(!Z||Qt.current!==null)return;const xe=_u.current;xe.historyDone||xe.historyLoading||(Qt.current={distFromBottom:Z.scrollHeight-Z.scrollTop},(ye=xe.loadMoreHistory)==null||ye.call(xe))},[]);g.useEffect(()=>{const Z=Te.current,xe=Je.current;if(!Z||!xe)return;const ye=new IntersectionObserver(Ze=>{for(const hi of Ze)hi.isIntersecting&&yu()},{root:Z,threshold:0});return ye.observe(xe),()=>ye.disconnect()},[yu]),g.useEffect(()=>{const Z=Te.current;if(!Z)return;const xe=150,ye=Ze=>{Date.now()<jo.current&&(Ze.preventDefault(),jo.current=Date.now()+xe)};return Z.addEventListener("wheel",ye,{passive:!1}),()=>Z.removeEventListener("wheel",ye)},[]),g.useEffect(()=>{const Z=Te.current;if(!Z)return;const xe=32,ye=()=>{const Ze=Z.scrollHeight-Z.scrollTop-Z.clientHeight;Dn.current=Ze<=xe};return Z.addEventListener("scroll",ye,{passive:!0}),()=>Z.removeEventListener("scroll",ye)},[]),g.useLayoutEffect(()=>{const Z=Te.current;if(!Z)return;const xe=sl.current,ye=pe.length;sl.current=ye;const Ze=Qt.current;if(Ze!==null&&ye>xe){Qt.current=null,Z.scrollTop=Z.scrollHeight-Ze.distFromBottom,jo.current=Date.now()+200;return}Ze!==null&&(Qt.current={distFromBottom:Z.scrollHeight-Z.scrollTop}),Dn.current&&(Z.scrollTop=Z.scrollHeight)},[pe,ie==null?void 0:ie.requestId]);const cp=g.useMemo(()=>{const Z={};for(const[xe,ye]of Object.entries(H))ye.submittedAnswers&&(Z[xe]=ye.submittedAnswers);return Z},[H]),up=g.useMemo(()=>new Set(Object.keys(H)),[H]),bu=g.useCallback(async(Z,xe)=>{try{await s.answerQuestion({sessionId:i.sessionId,toolUseId:Z,answers:xe}),M(Z,xe)}catch{}},[s,i.sessionId,M]),Do=g.useCallback(async Z=>{try{await s.cancelQuestion({sessionId:i.sessionId,toolUseId:Z}),q(Z)}catch{}},[s,i.sessionId,q]),Lo=g.useCallback(async(Z,xe)=>{var ye;if(ie)try{await((ye=e.respondPermission)==null?void 0:ye.call(e,ie.requestId,Z?"allow":"deny"))}catch{}},[e,ie]),ol=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]),al=g.useMemo(()=>oe&&pe.length===0?h.jsx("div",{className:"flex justify-center py-4","data-testid":"history-loading",children:h.jsx(rr,{className:"w-4 h-4 text-text-400 animate-spin"})}):e.historyDone?null:h.jsx("div",{className:"flex justify-center py-2",children:h.jsx("button",{type:"button",onClick:()=>{var Z;return void((Z=e.loadMoreHistory)==null?void 0:Z.call(e))},disabled:oe,"data-testid":"history-load-more",className:"text-[12px] text-text-400 hover:text-text-200 cursor-pointer px-3 py-1 rounded-md border border-bg-300 hover:bg-bg-100 transition-colors disabled:opacity-60",children:oe?"加载中…":"Load earlier messages"})}),[oe,pe.length,e.historyDone,e.loadMoreHistory]),Wi=e.meta,Vi=h.jsxs(h.Fragment,{children:[i.toolSessionId&&_.subagents?h.jsx(wZ,{api:s,cwd:i.cwd,toolSessionId:i.toolSessionId}):null,Xt&&_.rewind?h.jsx(kZ,{open:!0,onOpenChange:Z=>{Z||pn(null)},api:s,sessionId:i.sessionId,userMessageId:Xt,lines:pe,procAlive:V,onNoChanges:Z=>{wt(xe=>{if(xe.has(Z))return xe;const ye=new Set(xe);return ye.add(Z),ye})}}):null,Q?h.jsx(pne,{onConfirm:Se,onCancel:()=>ve(!1)}):null,h.jsx(FZ,{open:Fe,onClose:()=>We(!1),jobs:Ae})]}),ll={kind:"session",sessionId:i.sessionId},wu=g.useCallback(async Z=>{if(s)try{await Nte(s,F,i.sessionId,Z)}catch(xe){const ye=xe.message;Re("chat-panel","open-in-tab failed",{err:ye}),$("err",`Open in tab 失败:${ye}`)}},[s,F,i.sessionId,$]),[zt,cl]=g.useState(!1),[ul,Tt]=g.useState(null),$t=g.useCallback(Z=>{if(r){r(Z);return}Tt(Z),cl(!0)},[r]),or=g.useCallback(async Z=>{if(!s)throw new Error("daemon api not ready");const xe=await gy(s,F,i.sessionId,Z,60),ye=await fetch(xe);if(!ye.ok)throw new Error(`fetch ${ye.status} ${ye.statusText}`);return await ye.text()},[s,F,i.sessionId]),Ln=g.useCallback(async(Z,xe)=>{if(s)try{const{url:ye}=await s.attachmentSignUrl({sessionId:i.sessionId,relPath:Z,ttlSeconds:86400,...xe?{view:xe}:{}}),Ze=await Tte(ye);$(Ze?"ok":"err",Ze?"分享链接已复制到剪贴板(24h 有效)":"复制失败:请手动复制")}catch(ye){const Ze=ye.message;Re("chat-panel","share-file failed",{err:Ze}),$("err",`生成分享链接失败:${Ze}`)}},[s,i.sessionId,$]);return h.jsxs(h.Fragment,{children:[h.jsx(fne,{headerMeta:Wi,connState:e.connState,...o?{models:o}:{},...a!==void 0?{liveGitBranch:a}:{},...l!==void 0?{liveWorktreeRoot:l}:{},...d?{onOpenConfig:d}:{},onForceStop:()=>ve(!0),cronActiveCount:Ae.length,onCronClick:()=>We(!0),lines:pe,pendingPermissions:Oe,procAlive:V,rewindableUserMessageIds:Bt,onPermissionRespond:Lo,onPermissionInterrupt:mt,onRewind:_.rewind?U:void 0,...f&&_.fork?{onFork:f}:{},...n&&_.fork?{onQuickAsk:n}:p&&_.fork?{onQuickAsk:p}:{},topSlot:al,realtimeQuestionAnswers:cp,onSubmitQuestion:bu,onCancelQuestion:Do,liveQuestionToolUseIds:up,api:s,cwd:i.cwd,...i.tool?{tool:i.tool}:{},sessionKey:i.sessionId,onSend:e.sendText,awaitingUser:Oe.length>0||Object.values(H).some(Z=>!Z.submittedAnswers),onAbort:mt,...c?{onNewSession:c}:{},onClearSession:ol,chatRootRef:ue,chatBodyRef:Te,topSentinelRef:Je,drawers:Vi,xtermSlot:j==="tui"&&V&&_.tui?h.jsx(rte,{sessionId:i.sessionId,client:F},i.sessionId):null,fileSharingScope:ll,...s?{onShareFile:Ln}:{},...s?{onOpenInTab:wu}:{},...s?{onPreviewMarkdown:$t}:{},...P?{onOpenFiles:D}:{},onTogglePin:J,isHolded:Ye,...y?{onToggleHold:Yt}:{},...R?{personaName:I}:{},...R?{onOpenPersona:z}:{}}),P&&s?h.jsx(cte,{api:s,open:k,onOpenChange:C,scope:ll,sessionId:i.sessionId,onShareFile:Ln,onOpenInTab:wu}):null,s?h.jsx(Rte,{open:zt,onOpenChange:cl,relPath:ul,loadMarkdown:or,onShare:ul?()=>void Ln(ul,"md-rendered"):void 0}):null,R&&s&&i.ownerPersonaId?h.jsx(kte,{api:s,open:N,onOpenChange:T,personaId:i.ownerPersonaId,personaName:I??"",...m?{viewerRole:m}:{}}):null,b?h.jsx("div",{"data-testid":"share-toast",role:"status","aria-live":"polite",className:b.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:b.text}):null]})}function pne({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(jc,{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 mne(e,t,n){const r=e?t.find(s=>s.id===e):void 0;if(r!=null&&r.efforts&&r.efforts.length>0)return{options:r.efforts,defaultValue:r.defaultEffort??""};const i=n.find(s=>s.name==="effort");return{options:(i==null?void 0:i.options)??[],defaultValue:typeof(i==null?void 0:i.default)=="string"?i.default:""}}function gne({current:e,models:t,onSelect:n}){return h.jsxs("div",{children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Model"}),h.jsx("div",{className:"flex flex-wrap gap-1.5","data-testid":"config-model-selector",children:t.map(r=>{const i=(e||"")===r.id;return h.jsx("button",{type:"button",onClick:()=>n(r.id),"data-testid":`config-model-${r.id||"default"}`,className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",i?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:r.label},r.id||"default")})})]})}function vne({current:e,modes:t,onSelect:n}){var i;const r=(i=t.find(s=>s.id===(e||"")))==null?void 0:i.description;return h.jsxs("div",{children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Permission Mode"}),h.jsx("div",{className:"flex flex-wrap gap-1.5","data-testid":"config-mode-selector",children:t.map(s=>{const o=(e||"")===s.id;return h.jsx("button",{type:"button",onClick:()=>n(s.id),"data-testid":`config-mode-${s.id||"default"}`,className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",o?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:s.label},s.id||"default")})}),r?h.jsx("p",{className:"text-[11px] text-text-400 mt-1.5",children:r}):null]})}function xne({open:e,onOpenChange:t,session:n,onPatch:r,embedded:i=!1,viewerRole:s="owner"}){var m;const{capabilities:o}=my(e?n.tool||"claude":null),a=(o==null?void 0:o.models)??[],l=(o==null?void 0:o.permissionModes)??[],c=((m=o==null?void 0:o.configSchema.find(v=>v.name==="permissionMode"))==null?void 0:m.default)??"",u=n.permissionMode&&l.some(v=>v.id===n.permissionMode)?n.permissionMode:c,d=g.useMemo(()=>(o==null?void 0:o.configSchema.filter(v=>v.scope==="tool-specific"))??[],[o]),f=(o==null?void 0:o.toolSessionIdLabel)??"Tool Session ID";if(!e)return null;const p=h.jsxs("div",{className:"flex-1 min-h-0 flex flex-col px-4 py-4 gap-6 overflow-y-auto",children:[h.jsxs("div",{className:"shrink-0",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1",children:"Working Directory"}),h.jsx("div",{className:"text-[12px] font-mono text-text-300 bg-bg-100 rounded-lg px-3 py-2 truncate","data-testid":"config-cwd",title:n.cwd,children:n.cwd})]}),h.jsx("div",{className:"shrink-0",children:h.jsx(gne,{current:n.model??"",models:a,onSelect:v=>void r({model:v})})}),h.jsx("div",{className:"shrink-0",children:h.jsx(vne,{current:u,modes:l,onSelect:v=>void r({permissionMode:v})})}),d.length>0?h.jsx("div",{className:"shrink-0",children:h.jsx(_ne,{fields:d,models:a,session:n,onPatch:r})}):null,h.jsx("div",{className:"shrink-0",children:h.jsx(Hk,{testId:"config-session-id",label:"Clawd Session ID",value:n.sessionId})}),n.toolSessionId?h.jsx("div",{className:"shrink-0",children:h.jsx(Hk,{testId:"config-tool-session-id",label:f,value:n.toolSessionId})}):null]});return i?h.jsxs("div",{"data-testid":"config-drawer",className:"h-full w-full flex flex-col",children:[h.jsx("div",{className:"flex items-center px-4 py-3 border-b border-bg-300/30 shrink-0",children:h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Session Settings"})}),p]}):h.jsxs("div",{"data-testid":"config-drawer",className:"h-full w-full flex flex-col border-l border-bg-300/40 bg-bg-0 min-w-0",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bg-300/30 shrink-0",children:[h.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"Session Settings"}),h.jsx("button",{type:"button",onClick:()=>t(!1),"data-testid":"config-drawer-close",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":"Close",children:h.jsx(Rn,{className:"w-4 h-4"})})]}),p]})}function Hk({testId:e,label:t,value:n}){const[r,i]=g.useState(!1),s=g.useRef(null);g.useEffect(()=>()=>{s.current&&clearTimeout(s.current)},[]);const o=()=>{typeof navigator>"u"||!navigator.clipboard||navigator.clipboard.writeText(n).then(()=>{i(!0),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>i(!1),2e3)},()=>{})};return h.jsxs("div",{"data-testid":e,children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-1",children:t}),h.jsxs("button",{type:"button",onClick:o,"data-testid":`${e}-copy`,title:r?"Copied":`Copy: ${n}`,className:"w-full flex items-center gap-2 text-[12px] font-mono text-text-300 bg-bg-100 hover:bg-bg-200 rounded-lg px-3 py-2 transition-colors cursor-pointer text-left group",children:[h.jsx("span",{className:"truncate flex-1 min-w-0","data-testid":`${e}-value`,children:n}),r?h.jsx(Qa,{className:"w-3.5 h-3.5 shrink-0 text-accent"}):h.jsx(su,{className:"w-3.5 h-3.5 shrink-0 opacity-60 group-hover:opacity-100 transition-opacity"})]})]})}function _ne({fields:e,models:t,session:n,onPatch:r}){return h.jsxs("div",{"data-testid":"config-advanced",children:[h.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-text-400/70 mb-2",children:"Advanced"}),h.jsx("div",{className:"space-y-3",children:e.map(i=>h.jsx(yne,{field:i,models:t,session:n,onPatch:r},i.name))})]})}function yne({field:e,models:t,session:n,onPatch:r}){const i=e.name==="effort"?mne(n.model??"",t,[e]):{options:e.options??[],defaultValue:e.default??""},s=i.options;if(e.type!=="select"||s.length===0)return null;const o=n[e.name]??"",a=s.some(l=>l.value===o)?o:i.defaultValue;return h.jsxs("div",{"data-testid":`config-advanced-${e.name}`,children:[h.jsx("div",{className:"text-[11px] text-text-400 mb-1.5",children:e.label}),h.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map(l=>{const c=a===l.value;return h.jsx("button",{type:"button","data-testid":`config-advanced-${e.name}-${l.value||"default"}`,onClick:()=>void r({[e.name]:l.value}),className:ne("px-3 py-1.5 rounded-lg text-[12px] font-medium transition-colors cursor-pointer",c?"bg-accent text-white shadow-sm":"bg-bg-100 text-text-300 hover:bg-bg-200 hover:text-text-100"),children:l.label},l.value||"default")})})]})}function bne(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 wne(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()}}function Sne({api:e,session:t,focused:n,totalPanes:r,onFocus:i,onClose:s,onNewSession:o,onOpenConfig:a,onConfigPatch:l,onFork:c,onQuickAsk:u,className:d,viewerRole:f="owner",holdIds:p,onToggleHold:m}){const{capabilities:v}=my(t.tool),[y,x]=g.useState(0),[_,b]=g.useState(!1),{initialSize:w,setSize:k}=dA("clawd:panel:config-px",360),{branch:C}=bne(e,t.cwd,y),{worktreeRoot:N}=wne(e,t.cwd,y),T=r>1,L=P=>{P==="desktop"?b(!0):a()};return h.jsxs("div",{className:`group/pane relative flex-1 ${d??"flex"} flex-row min-w-0 min-h-0 overflow-hidden ${T?`rounded-md border transition-colors ${n?"border-accent ring-1 ring-accent":"border-border"}`:""}`,onMouseDown:i,"data-testid":`session-pane-${t.sessionId}`,children:[h.jsxs(I_,{orientation:"horizontal",className:"flex-1 flex min-w-0 min-h-0",children:[h.jsx(Fc,{id:"chat",minSize:"400px",children:h.jsx("div",{className:"flex flex-col min-w-0 min-h-0 h-full",children:h.jsx(kne,{api:e,session:t,models:v==null?void 0:v.models,liveGitBranch:C,liveWorktreeRoot:N,onNewSession:o,onTurnEnd:()=>x(P=>P+1),onOpenConfig:L,onFork:c,onQuickAsk:u,viewerRole:f,holdIds:p,onToggleHold:m})})}),_&&h.jsxs(h.Fragment,{children:[h.jsx(M_,{className:"hidden md:block w-1 bg-text-100/10 hover:bg-text-100/25 transition-colors cursor-col-resize"}),h.jsx(Fc,{id:"config",defaultSize:`${w}px`,minSize:"360px",maxSize:"560px",onResize:P=>k(P.inPixels),children:h.jsx("div",{className:"hidden md:flex h-full",children:h.jsx(xne,{open:_,onOpenChange:b,session:t,onPatch:l,viewerRole:f})})})]})]}),T&&h.jsx("button",{type:"button",onClick:P=>{P.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(Rn,{className:"w-3.5 h-3.5"})})]})}function kne({api:e,session:t,models:n,liveGitBranch:r,liveWorktreeRoot:i,onNewSession:s,onTurnEnd:o,onOpenConfig:a,onFork:l,onQuickAsk:c,viewerRole:u,holdIds:d,onToggleHold:f}){return h.jsx(dne,{extras:{session:t,api:e,...n?{models:n}:{},...r!==void 0?{liveGitBranch:r}:{},...i!==void 0?{liveWorktreeRoot:i}:{},onNewSession:s,onTurnEnd:o,onOpenConfig:a,...l?{onFork:p=>{l(p)}}:{},...c?{onQuickAsk:p=>{c(p)}}:{},...u?{viewerRole:u}:{},...d?{holdIds:d}:{},...f?{onToggleHold:f}:{}}})}function Cne({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,onConfigPatch:p}){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(qH,{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(Sne,{api:n,session:o,focused:!0,totalPanes:1,onFocus:()=>{},onClose:f,onNewSession:()=>{},onOpenConfig:()=>{},onConfigPatch:p,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 Ene(){const e=Bi(),t=g.useMemo(()=>new qx(e),[e]),n=hB(e),{sessions:r,refresh:i}=fB(n),{personas:s}=AN(),o=_B(),a=g.useMemo(()=>{const w=window.location.pathname.match(/^\/s\/([^/]+)/);return w?decodeURIComponent(w[1]):null},[]),l=g.useMemo(()=>r.filter(w=>!w.ephemeral&&w.larkChatId==null),[r]),c=g.useMemo(()=>a?s.filter(w=>w.personaId===a):s,[s,a]),[u,d]=g.useState(null),[f,p]=g.useState(null),[m,v]=g.useState(null);g.useEffect(()=>{let w=!1;return e.request("whoami",{}).then(k=>{w||d(k.capability.id)}).catch(()=>{}),()=>{w=!0}},[e]),g.useEffect(()=>{a&&p(a)},[a]);const y=g.useCallback(async(w,k)=>{const C=await t.sessionCreate({ownerPersonaId:w,...k.trim()?{label:k.trim()}:{}});await i(),p(w),v(C.sessionId)},[t,i]),x=g.useCallback(async w=>{await t.sessionDelete(w),await i(),v(k=>k===w?null:k)},[t,i]),_=g.useCallback(async(w,k)=>{await t.sessionUpdate(w,{label:k.label,iconKey:k.iconKey===null?"":k.iconKey}),await i()},[t,i]),b=g.useMemo(()=>l.find(w=>w.sessionId===m)??null,[l,m]);return h.jsx(Kx.Provider,{value:o,children:h.jsx(Cne,{personas:c,sessions:l,api:t,selfPrincipalId:u,selectedPersonaId:f,selectedSessionId:m,selectedSession:b,onSelectPersona:p,onSelectSession:v,onCreateSession:(w,k)=>void y(w,k),onDeleteSession:w=>void x(w),onEditSession:(w,k)=>void _(w,k),onCloseSession:()=>v(null),onConfigPatch:async()=>{}})})}const Uk="https://app.ttcadvisory.com";function Nne({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=`${Uk}/auth/authorize?callback_url=${encodeURIComponent(a)}&auto=1`,c=async d=>{if(d.origin!==Uk)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 D0="clawd-visitor:token";function Tne(e,t){const r=`${e.protocol==="https:"?"wss:":"ws:"}//${e.host}`;return t!=null&&t.devPath?`${r}${t.devPath}`:r}function Pne(){return{async getUrl(e){const t=localStorage.getItem(D0);if(!t)throw new Error("NO_VISITOR_TOKEN");const n=Tne(window.location,{});return await kN(e).upsert({id:"guest",name:"访客",mode:"remote",url:n,token:t}),{url:n}}}}function Ine(e){const t=n=>{document.documentElement.classList.toggle("dark",n==="dark")};return t(e.theme.mode),e.onThemeChange(n=>t(n.mode))}function Rne(){const e=Bi(),t=g.useMemo(()=>dB(e),[e]);return h.jsx(qO,{cache:t.cache,children:h.jsx(XO,{children:h.jsx(Ene,{})})})}function Mne({host:e}){const[t]=g.useState(()=>localStorage.getItem(D0)),[n,r]=g.useState(!1),[i,s]=g.useState(null);return g.useEffect(()=>Ine(e),[e]),g.useEffect(()=>{if(!t)return;let o=!1;return Pne().getUrl(e).then(()=>{o||r(!0)}).catch(a=>{o||s(a instanceof Error?a.message:String(a))}),()=>{o=!0}},[e,t]),t?h.jsx(L1,{host:e,children:h.jsx(mb,{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(WO,{host:e,children:h.jsx(Rne,{})}):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(L1,{host:e,children:h.jsx(mb,{children:h.jsx(Nne,{onAuthed:o=>{localStorage.setItem(D0,o),window.location.reload()}})})})}function Ane({filePath:e,oldString:t,newString:n,content:r}){const i=g.useMemo(()=>r!=null?r.split(/\r?\n/).map(s=>({type:"add",text:s})):jne(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:ne("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 jne(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 Dne({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(Lne,{status:t.status}),h.jsx("span",{className:ne("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 Lne({status:e}){return e==="completed"?h.jsx(Df,{className:"w-3.5 h-3.5 text-success mt-0.5 shrink-0"}):e==="in_progress"?h.jsx(rr,{className:"w-3.5 h-3.5 text-warning mt-0.5 shrink-0 animate-spin"}):h.jsx(ON,{className:"w-3.5 h-3.5 text-text-400 mt-0.5 shrink-0"})}function One(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 Bne({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(jf,{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 zne(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 $ne={render:({input:e})=>st.createElement(Dne,{items:One(e)})},Fne={render:({input:e})=>{const{description:t,prompt:n,subagentType:r}=zne(e);return st.createElement(Bne,{description:t,prompt:n,subagentType:r})}},fA={render:({input:e,output:t,error:n,pending:r,fileScope:i,onShareFile:s,onOpenInTab:o,onPreviewMarkdown:a})=>{const l=Une(e),c=l?st.createElement(Ane,{filePath:l.filePath,oldString:l.oldString,newString:l.newString,content:l.content}):void 0;return st.createElement(jR,{tool:Hne(e),input:e,output:t,error:n,pending:r,expandedBody:c,...i?{fileScope:i}:{},...s?{onShareFile:s}:{},...o?{onOpenInTab:o}:{},...a?{onPreviewMarkdown:a}:{}})}};function Hne(e){const t=e??{};return"content"in t&&t.content!==void 0?"Write":("old_string"in t&&t.old_string!==void 0,"Edit")}function Une(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}}pu.register("claude","TodoWrite",$ne);pu.register("claude","Task",Fne);pu.register("claude","Edit",fA);pu.register("claude","Write",fA);const pA=document.getElementById("root");if(!pA)throw new Error("guest-main: #root not found");const Wne=G5({});Hm.createRoot(pA).render(h.jsx(st.StrictMode,{children:h.jsx(Mne,{host:Wne})}));