@clawos-dev/clawd 0.2.733 → 0.2.735
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-builder-plugin/mcp-server.cjs +1 -1
- package/dist/cli.cjs +46 -5
- package/dist/cloud-persona-conversations.html +2 -2
- package/dist/cloud-persona-metrics.html +1 -1
- package/dist/cloud-persona-schedules.html +117 -0
- package/dist/dispatch/mcp-server.cjs +1 -1
- package/dist/owner-ui/assets/owner-Dq_Gvi-x.css +32 -0
- package/dist/owner-ui/assets/{owner-V72Fs11W.js → owner-cVBwPD6W.js} +2 -2
- package/dist/owner-ui/owner.html +2 -2
- package/dist/persona-defaults/persona-app-builder/mcp/clawd-app-builder/mcp-server.cjs +1 -1
- package/dist/persona-defaults/persona-clawd-butler/.claude/skills/inspection-persona-authoring/SKILL.md +29 -0
- package/dist/persona-defaults/persona-clawd-butler/CLAUDE.md +2 -1
- package/dist/persona-defaults/persona-dataclaw-builder/mcp/clawd-app-builder/mcp-server.cjs +1 -1
- package/dist/share-md-viewer-error.html +1 -1
- package/dist/share-md-viewer.html +1 -1
- package/dist/share-ui/assets/guest-BVSbAs1-.css +32 -0
- package/dist/share-ui/assets/{guest-DPqaHbma.js → guest-ndYQiP8d.js} +1 -1
- package/dist/share-ui/guest.html +2 -2
- package/package.json +1 -1
- package/dist/owner-ui/assets/owner-tAd4oFVr.css +0 -32
- package/dist/share-ui/assets/guest-D-8nYbPl.css +0 -32
|
@@ -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 eO=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 s=0,r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(n[r[s]]=e[r[s]]);return n};const $ae={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},Lae={motionBase:!0,motionUnit:!0},Fae={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},o7=(e,t,n)=>{const r=n.getDerivativeToken(e),{override:s}=t,i=eO(t,["override"]);let o=Object.assign(Object.assign({},r),{override:s});return o=i7(o),i&&Object.entries(i).forEach(([l,c])=>{const{theme:u}=c,d=eO(c,["theme"]);let h=d;u&&(h=o7(Object.assign(Object.assign({},o),d),{override:d},u)),o[l]=h}),o};function a7(){const{token:e,hashed:t,theme:n,override:r,cssVar:s}=q.useContext(r7),i=`${Dae}-${t||""}`,o=n||n7,[l,c,u]=Noe(o,[yg,e],{salt:i,override:r,getComputedToken:o7,formatToken:i7,cssVar:s&&{prefix:s.prefix,key:s.key,unitless:$ae,ignore:Lae,preserve:Fae}});return[o,u,t?c:"",l,s]}const Bae=()=>({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"}}),zae=e=>({[`.${e}`]:Object.assign(Object.assign({},Bae()),{[`.${e} .${e}-icon`]:{display:"block"}})}),Hae=(e,t)=>{const[n,r]=a7();return eae({token:r,hashId:"",path:["ant-design-icons",e],nonce:()=>t==null?void 0:t.nonce,layer:{name:"antd"}},()=>zae(e))},Uae=Object.assign({},Sf),{useId:tO}=Uae,Wae=()=>"",Vae=typeof tO>"u"?Wae:tO;function qae(e,t,n){var r;const s=e||{},i=s.inherit===!1||!t?Object.assign(Object.assign({},Eb),{hashed:(r=t==null?void 0:t.hashed)!==null&&r!==void 0?r:Eb.hashed,cssVar:t==null?void 0:t.cssVar}):t,o=Vae();return N9(()=>{var l,c;if(!e)return t;const u=Object.assign({},i.components);Object.keys(e.components||{}).forEach(f=>{u[f]=Object.assign(Object.assign({},u[f]),e.components[f])});const d=`css-var-${o.replace(/:/g,"")}`,h=((l=s.cssVar)!==null&&l!==void 0?l:i.cssVar)&&Object.assign(Object.assign(Object.assign({prefix:n==null?void 0:n.prefixCls},typeof i.cssVar=="object"?i.cssVar:{}),typeof s.cssVar=="object"?s.cssVar:{}),{key:typeof s.cssVar=="object"&&((c=s.cssVar)===null||c===void 0?void 0:c.key)||d});return Object.assign(Object.assign(Object.assign({},i),s),{token:Object.assign(Object.assign({},i.token),s.token),components:u,cssVar:h})},[s,i],(l,c)=>l.some((u,d)=>{const h=c[d];return!eoe(u,h,!0)}))}var Kae=["children"],l7=p.createContext({});function Gae(e){var t=e.children,n=li(e,Kae);return p.createElement(l7.Provider,{value:n},t)}var Yae=function(e){Rr(n,e);var t=I9(n);function n(){return Rn(this,n),t.apply(this,arguments)}return Mn(n,[{key:"render",value:function(){return this.props.children}}]),n}(p.Component);function Xae(e){var t=p.useReducer(function(l){return l+1},0),n=_t(t,2),r=n[1],s=p.useRef(e),i=WN(function(){return s.current}),o=WN(function(l){s.current=typeof l=="function"?l(s.current):l,r()});return[i,o]}var Al="none",r0="appear",s0="enter",i0="leave",nO="none",fo="prepare",ah="start",lh="active",T5="end",c7="prepared";function rO(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 Zae(e,t){var n={animationend:rO("Animation","AnimationEnd"),transitionend:rO("Transition","TransitionEnd")};return e&&("AnimationEvent"in t||delete n.animationend.animation,"TransitionEvent"in t||delete n.transitionend.transition),n}var Qae=Zae(dl(),typeof window<"u"?window:{}),u7={};if(dl()){var Jae=document.createElement("div");u7=Jae.style}var o0={};function d7(e){if(o0[e])return o0[e];var t=Qae[e];if(t)for(var n=Object.keys(t),r=n.length,s=0;s<r;s+=1){var i=n[s];if(Object.prototype.hasOwnProperty.call(t,i)&&i in u7)return o0[e]=t[i],o0[e]}return""}var h7=d7("animationend"),f7=d7("transitionend"),p7=!!(h7&&f7),sO=h7||"animationend",iO=f7||"transitionend";function oO(e,t){if(!e)return null;if(Tn(e)==="object"){var n=t.replace(/-\w/g,function(r){return r[1].toUpperCase()});return e[n]}return"".concat(e,"-").concat(t)}const ele=function(e){var t=p.useRef();function n(s){s&&(s.removeEventListener(iO,e),s.removeEventListener(sO,e))}function r(s){t.current&&t.current!==s&&n(t.current),s&&s!==t.current&&(s.addEventListener(iO,e),s.addEventListener(sO,e),t.current=s)}return p.useEffect(function(){return function(){n(t.current)}},[]),[r,n]};var m7=dl()?p.useLayoutEffect:p.useEffect;const tle=function(){var e=p.useRef(null);function t(){wN.cancel(e.current)}function n(r){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2;t();var i=wN(function(){s<=1?r({isCanceled:function(){return i!==e.current}}):n(r,s-1)});e.current=i}return p.useEffect(function(){return function(){t()}},[]),[n,t]};var nle=[fo,ah,lh,T5],rle=[fo,c7],g7=!1,sle=!0;function x7(e){return e===lh||e===T5}const ile=function(e,t,n){var r=VN(nO),s=_t(r,2),i=s[0],o=s[1],l=tle(),c=_t(l,2),u=c[0],d=c[1];function h(){o(fo,!0)}var f=t?rle:nle;return m7(function(){if(i!==nO&&i!==T5){var m=f.indexOf(i),g=f[m+1],x=n(i);x===g7?o(g,!0):g&&u(function(b){function y(){b.isCanceled()||o(g,!0)}x===!0?y():Promise.resolve(x).then(y)})}},[e,i]),p.useEffect(function(){return function(){d()}},[]),[h,i]};function ole(e,t,n,r){var s=r.motionEnter,i=s===void 0?!0:s,o=r.motionAppear,l=o===void 0?!0:o,c=r.motionLeave,u=c===void 0?!0:c,d=r.motionDeadline,h=r.motionLeaveImmediately,f=r.onAppearPrepare,m=r.onEnterPrepare,g=r.onLeavePrepare,x=r.onAppearStart,b=r.onEnterStart,y=r.onLeaveStart,v=r.onAppearActive,w=r.onEnterActive,_=r.onLeaveActive,S=r.onAppearEnd,k=r.onEnterEnd,C=r.onLeaveEnd,N=r.onVisibleChanged,T=VN(),E=_t(T,2),R=E[0],O=E[1],P=Xae(Al),$=_t(P,2),F=$[0],B=$[1],W=VN(null),L=_t(W,2),D=L[0],I=L[1],V=F(),H=p.useRef(!1),M=p.useRef(null);function Y(){return n()}var X=p.useRef(!1);function K(){B(Al),I(null,!0)}var te=WN(function(De){var Me=F();if(Me!==Al){var We=Y();if(!(De&&!De.deadline&&De.target!==We)){var wt=X.current,Ct;Me===r0&&wt?Ct=S==null?void 0:S(We,De):Me===s0&&wt?Ct=k==null?void 0:k(We,De):Me===i0&&wt&&(Ct=C==null?void 0:C(We,De)),wt&&Ct!==!1&&K()}}}),ce=ele(te),J=_t(ce,1),de=J[0],we=function(Me){switch(Me){case r0:return Ze(Ze(Ze({},fo,f),ah,x),lh,v);case s0:return Ze(Ze(Ze({},fo,m),ah,b),lh,w);case i0:return Ze(Ze(Ze({},fo,g),ah,y),lh,_);default:return{}}},se=p.useMemo(function(){return we(V)},[V]),ae=ile(V,!e,function(De){if(De===fo){var Me=se[fo];return Me?Me(Y()):g7}if(ve in se){var We;I(((We=se[ve])===null||We===void 0?void 0:We.call(se,Y(),null))||null)}return ve===lh&&V!==Al&&(de(Y()),d>0&&(clearTimeout(M.current),M.current=setTimeout(function(){te({deadline:!0})},d))),ve===c7&&K(),sle}),Z=_t(ae,2),fe=Z[0],ve=Z[1],Te=x7(ve);X.current=Te;var Qe=p.useRef(null);m7(function(){if(!(H.current&&Qe.current===t)){O(t);var De=H.current;H.current=!0;var Me;!De&&t&&l&&(Me=r0),De&&t&&i&&(Me=s0),(De&&!t&&u||!De&&h&&!t&&u)&&(Me=i0);var We=we(Me);Me&&(e||We[fo])?(B(Me),fe()):B(Al),Qe.current=t}},[t]),p.useEffect(function(){(V===r0&&!l||V===s0&&!i||V===i0&&!u)&&B(Al)},[l,i,u]),p.useEffect(function(){return function(){H.current=!1,clearTimeout(M.current)}},[]);var ge=p.useRef(!1);p.useEffect(function(){R&&(ge.current=!0),R!==void 0&&V===Al&&((ge.current||R)&&(N==null||N(R)),ge.current=!0)},[R,V]);var Ce=D;return se[fo]&&ve===ah&&(Ce=Pt({transition:"none"},Ce)),[V,ve,Ce,R??t]}function ale(e){var t=e;Tn(e)==="object"&&(t=e.transitionSupport);function n(s,i){return!!(s.motionName&&t&&i!==!1)}var r=p.forwardRef(function(s,i){var o=s.visible,l=o===void 0?!0:o,c=s.removeOnLeave,u=c===void 0?!0:c,d=s.forceRender,h=s.children,f=s.motionName,m=s.leavedClassName,g=s.eventProps,x=p.useContext(l7),b=x.motion,y=n(s,b),v=p.useRef(),w=p.useRef();function _(){try{return v.current instanceof HTMLElement?v.current:Fie(w.current)}catch{return null}}var S=ole(y,l,_,s),k=_t(S,4),C=k[0],N=k[1],T=k[2],E=k[3],R=p.useRef(E);E&&(R.current=!0);var O=p.useCallback(function(L){v.current=L,Uie(i,L)},[i]),P,$=Pt(Pt({},g),{},{visible:l});if(!h)P=null;else if(C===Al)E?P=h(Pt({},$),O):!u&&R.current&&m?P=h(Pt(Pt({},$),{},{className:m}),O):d||!u&&!m?P=h(Pt(Pt({},$),{},{style:{display:"none"}}),O):P=null;else{var F;N===fo?F="prepare":x7(N)?F="active":N===ah&&(F="start");var B=oO(f,"".concat(C,"-").concat(F));P=h(Pt(Pt({},$),{},{className:jie(oO(f,C),Ze(Ze({},B,B&&F),f,typeof f=="string")),style:T}),O)}if(p.isValidElement(P)&&Wie(P)){var W=Vie(P);W||(P=p.cloneElement(P,{ref:O}))}return p.createElement(Yae,{ref:w},P)});return r.displayName="CSSMotion",r}const lle=ale(p7);var qN="add",KN="keep",GN="remove",kk="removed";function cle(e){var t;return e&&Tn(e)==="object"&&"key"in e?t=e:t={key:e},Pt(Pt({},t),{},{key:String(t.key)})}function YN(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return e.map(cle)}function ule(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],n=[],r=0,s=t.length,i=YN(e),o=YN(t);i.forEach(function(u){for(var d=!1,h=r;h<s;h+=1){var f=o[h];if(f.key===u.key){r<h&&(n=n.concat(o.slice(r,h).map(function(m){return Pt(Pt({},m),{},{status:qN})})),r=h),n.push(Pt(Pt({},f),{},{status:KN})),r+=1,d=!0;break}}d||n.push(Pt(Pt({},u),{},{status:GN}))}),r<s&&(n=n.concat(o.slice(r).map(function(u){return Pt(Pt({},u),{},{status:qN})})));var l={};n.forEach(function(u){var d=u.key;l[d]=(l[d]||0)+1});var c=Object.keys(l).filter(function(u){return l[u]>1});return c.forEach(function(u){n=n.filter(function(d){var h=d.key,f=d.status;return h!==u||f!==GN}),n.forEach(function(d){d.key===u&&(d.status=KN)})}),n}var dle=["component","children","onVisibleChanged","onAllRemoved"],hle=["status"],fle=["eventProps","visible","children","motionName","motionAppear","motionEnter","motionLeave","motionLeaveImmediately","motionDeadline","removeOnLeave","leavedClassName","onAppearPrepare","onAppearStart","onAppearActive","onAppearEnd","onEnterStart","onEnterActive","onEnterEnd","onLeaveStart","onLeaveActive","onLeaveEnd"];function ple(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:lle,n=function(r){Rr(i,r);var s=I9(i);function i(){var o;Rn(this,i);for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];return o=s.call.apply(s,[this].concat(c)),Ze(yN(o),"state",{keyEntities:[]}),Ze(yN(o),"removeKey",function(d){o.setState(function(h){var f=h.keyEntities.map(function(m){return m.key!==d?m:Pt(Pt({},m),{},{status:kk})});return{keyEntities:f}},function(){var h=o.state.keyEntities,f=h.filter(function(m){var g=m.status;return g!==kk}).length;f===0&&o.props.onAllRemoved&&o.props.onAllRemoved()})}),o}return Mn(i,[{key:"render",value:function(){var l=this,c=this.state.keyEntities,u=this.props,d=u.component,h=u.children,f=u.onVisibleChanged;u.onAllRemoved;var m=li(u,dle),g=d||p.Fragment,x={};return fle.forEach(function(b){x[b]=m[b],delete m[b]}),delete m.keys,p.createElement(g,m,c.map(function(b,y){var v=b.status,w=li(b,hle),_=v===qN||v===KN;return p.createElement(t,bt({},x,{key:w.key,visible:_,eventProps:w,onVisibleChanged:function(k){f==null||f(k,{key:w.key}),k||l.removeKey(w.key)}}),function(S,k){return h(Pt(Pt({},S),{},{index:y}),k)})}))}}],[{key:"getDerivedStateFromProps",value:function(l,c){var u=l.keys,d=c.keyEntities,h=YN(u),f=ule(d,h);return{keyEntities:f.filter(function(m){var g=d.find(function(x){var b=x.key;return m.key===b});return!(g&&g.status===kk&&m.status===GN)})}}}]),i}(p.Component);return Ze(n,"defaultProps",{component:"div"}),n}ple(p7);const aO=p.createContext(!0);function mle(e){const t=p.useContext(aO),{children:n}=e,[,r]=a7(),{motion:s}=r,i=p.useRef(!1);return i.current||(i.current=t!==s),i.current?p.createElement(aO.Provider,{value:s},p.createElement(Gae,{motion:s},n)):n}const gle=()=>null;var xle=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 s=0,r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(n[r[s]]=e[r[s]]);return n};const vle=["getTargetContainer","getPopupContainer","renderEmpty","input","pagination","form","select","button"];let v7;function yle(){return v7||HN}function ble(e){return Object.keys(e).some(t=>t.endsWith("Color"))}const wle=e=>{const{prefixCls:t,iconPrefixCls:n,theme:r,holderRender:s}=e;t!==void 0&&(v7=t),r&&ble(r)&&Iae(yle(),r)},_le=e=>{const{children:t,csp:n,autoInsertSpaceInButton:r,alert:s,anchor:i,form:o,locale:l,componentSize:c,direction:u,space:d,splitter:h,virtual:f,dropdownMatchSelectWidth:m,popupMatchSelectWidth:g,popupOverflow:x,legacyLocale:b,parentContext:y,iconPrefixCls:v,theme:w,componentDisabled:_,segmented:S,statistic:k,spin:C,calendar:N,carousel:T,cascader:E,collapse:R,typography:O,checkbox:P,descriptions:$,divider:F,drawer:B,skeleton:W,steps:L,image:D,layout:I,list:V,mentions:H,modal:M,progress:Y,result:X,slider:K,breadcrumb:te,menu:ce,pagination:J,input:de,textArea:we,empty:se,badge:ae,radio:Z,rate:fe,switch:ve,transfer:Te,avatar:Qe,message:ge,tag:Ce,table:De,card:Me,tabs:We,timeline:wt,timePicker:Ct,upload:oe,notification:le,tree:pe,colorPicker:Ke,datePicker:Ge,rangePicker:ut,flex:rn,wave:Ve,dropdown:en,warning:ye,tour:Oe,tooltip:dt,popover:Nt,popconfirm:vn,floatButton:be,floatButtonGroup:ne,variant:Ae,inputNumber:nt,treeSelect:rt}=e,Mt=p.useCallback((jt,Wt)=>{const{prefixCls:Zn}=e;if(Wt)return Wt;const dr=Zn||y.getPrefixCls("");return jt?`${dr}-${jt}`:dr},[y.getPrefixCls,e.prefixCls]),$t=v||y.iconPrefixCls||s7,Ht=n||y.csp;Hae($t,Ht);const sn=qae(w,y.theme,{prefixCls:Mt("")}),$n={csp:Ht,autoInsertSpaceInButton:r,alert:s,anchor:i,locale:l||b,direction:u,space:d,splitter:h,virtual:f,popupMatchSelectWidth:g??m,popupOverflow:x,getPrefixCls:Mt,iconPrefixCls:$t,theme:sn,segmented:S,statistic:k,spin:C,calendar:N,carousel:T,cascader:E,collapse:R,typography:O,checkbox:P,descriptions:$,divider:F,drawer:B,skeleton:W,steps:L,image:D,input:de,textArea:we,layout:I,list:V,mentions:H,modal:M,progress:Y,result:X,slider:K,breadcrumb:te,menu:ce,pagination:J,empty:se,badge:ae,radio:Z,rate:fe,switch:ve,transfer:Te,avatar:Qe,message:ge,tag:Ce,table:De,card:Me,tabs:We,timeline:wt,timePicker:Ct,upload:oe,notification:le,tree:pe,colorPicker:Ke,datePicker:Ge,rangePicker:ut,flex:rn,wave:Ve,dropdown:en,warning:ye,tour:Oe,tooltip:dt,popover:Nt,popconfirm:vn,floatButton:be,floatButtonGroup:ne,variant:Ae,inputNumber:nt,treeSelect:rt},Lt=Object.assign({},y);Object.keys($n).forEach(jt=>{$n[jt]!==void 0&&(Lt[jt]=$n[jt])}),vle.forEach(jt=>{const Wt=e[jt];Wt&&(Lt[jt]=Wt)}),typeof r<"u"&&(Lt.button=Object.assign({autoInsertSpace:r},Lt.button));const an=N9(()=>Lt,Lt,(jt,Wt)=>{const Zn=Object.keys(jt),dr=Object.keys(Wt);return Zn.length!==dr.length||Zn.some(nr=>jt[nr]!==Wt[nr])}),{layer:yn}=p.useContext(Sw),bn=p.useMemo(()=>({prefixCls:$t,csp:Ht,layer:yn?"antd":void 0}),[$t,Ht,yn]);let Zt=p.createElement(p.Fragment,null,p.createElement(gle,{dropdownMatchSelectWidth:m}),t);const _e=p.useMemo(()=>{var jt,Wt,Zn,dr;return aae(((jt=Nw.Form)===null||jt===void 0?void 0:jt.defaultValidateMessages)||{},((Zn=(Wt=an.locale)===null||Wt===void 0?void 0:Wt.Form)===null||Zn===void 0?void 0:Zn.defaultValidateMessages)||{},((dr=an.form)===null||dr===void 0?void 0:dr.validateMessages)||{},(o==null?void 0:o.validateMessages)||{})},[an,o==null?void 0:o.validateMessages]);Object.keys(_e).length>0&&(Zt=p.createElement(cae.Provider,{value:_e},Zt)),l&&(Zt=p.createElement(hae,{locale:l,_ANT_MARK__:dae},Zt)),Zt=p.createElement(sae.Provider,{value:bn},Zt),c&&(Zt=p.createElement(Rae,{size:c},Zt)),Zt=p.createElement(mle,null,Zt);const xt=p.useMemo(()=>{const jt=sn||{},{algorithm:Wt,token:Zn,components:dr,cssVar:nr}=jt,eo=xle(jt,["algorithm","token","components","cssVar"]),Ca=Wt&&(!Array.isArray(Wt)||Wt.length>0)?kN(Wt):n7,qs={};Object.entries(dr||{}).forEach(([Na,ja])=>{const Ut=Object.assign({},ja);"algorithm"in Ut&&(Ut.algorithm===!0?Ut.theme=Ca:(Array.isArray(Ut.algorithm)||typeof Ut.algorithm=="function")&&(Ut.theme=kN(Ut.algorithm)),delete Ut.algorithm),qs[Na]=Ut});const bi=Object.assign(Object.assign({},yg),Zn);return Object.assign(Object.assign({},eo),{theme:Ca,token:bi,components:qs,override:Object.assign({override:bi},qs),cssVar:nr})},[sn]);return w&&(Zt=p.createElement(r7.Provider,{value:xt},Zt)),an.warning&&(Zt=p.createElement(lae.Provider,{value:an.warning},Zt)),_!==void 0&&(Zt=p.createElement(Tae,{disabled:_},Zt)),p.createElement(jw.Provider,{value:an},Zt)},jf=e=>{const t=p.useContext(jw),n=p.useContext(Q9);return p.createElement(_le,Object.assign({parentContext:t,legacyLocale:n},e))};jf.ConfigContext=jw;jf.SizeContext=bg;jf.config=wle;jf.useConfig=Mae;Object.defineProperty(jf,"SizeContext",{get:()=>bg});var y7={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(Fr,function(){var n=1e3,r=6e4,s=36e5,i="millisecond",o="second",l="minute",c="hour",u="day",d="week",h="month",f="quarter",m="year",g="date",x="Invalid Date",b=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,v={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function($){var F=["th","st","nd","rd"],B=$%100;return"["+$+(F[(B-20)%10]||F[B]||F[0])+"]"}},w=function($,F,B){var W=String($);return!W||W.length>=F?$:""+Array(F+1-W.length).join(B)+$},_={s:w,z:function($){var F=-$.utcOffset(),B=Math.abs(F),W=Math.floor(B/60),L=B%60;return(F<=0?"+":"-")+w(W,2,"0")+":"+w(L,2,"0")},m:function $(F,B){if(F.date()<B.date())return-$(B,F);var W=12*(B.year()-F.year())+(B.month()-F.month()),L=F.clone().add(W,h),D=B-L<0,I=F.clone().add(W+(D?-1:1),h);return+(-(W+(B-L)/(D?L-I:I-L))||0)},a:function($){return $<0?Math.ceil($)||0:Math.floor($)},p:function($){return{M:h,y:m,w:d,d:u,D:g,h:c,m:l,s:o,ms:i,Q:f}[$]||String($||"").toLowerCase().replace(/s$/,"")},u:function($){return $===void 0}},S="en",k={};k[S]=v;var C="$isDayjsObject",N=function($){return $ instanceof O||!(!$||!$[C])},T=function $(F,B,W){var L;if(!F)return S;if(typeof F=="string"){var D=F.toLowerCase();k[D]&&(L=D),B&&(k[D]=B,L=D);var I=F.split("-");if(!L&&I.length>1)return $(I[0])}else{var V=F.name;k[V]=F,L=V}return!W&&L&&(S=L),L||!W&&S},E=function($,F){if(N($))return $.clone();var B=typeof F=="object"?F:{};return B.date=$,B.args=arguments,new O(B)},R=_;R.l=T,R.i=N,R.w=function($,F){return E($,{locale:F.$L,utc:F.$u,x:F.$x,$offset:F.$offset})};var O=function(){function $(B){this.$L=T(B.locale,null,!0),this.parse(B),this.$x=this.$x||B.x||{},this[C]=!0}var F=$.prototype;return F.parse=function(B){this.$d=function(W){var L=W.date,D=W.utc;if(L===null)return new Date(NaN);if(R.u(L))return new Date;if(L instanceof Date)return new Date(L);if(typeof L=="string"&&!/Z$/i.test(L)){var I=L.match(b);if(I){var V=I[2]-1||0,H=(I[7]||"0").substring(0,3);return D?new Date(Date.UTC(I[1],V,I[3]||1,I[4]||0,I[5]||0,I[6]||0,H)):new Date(I[1],V,I[3]||1,I[4]||0,I[5]||0,I[6]||0,H)}}return new Date(L)}(B),this.init()},F.init=function(){var B=this.$d;this.$y=B.getFullYear(),this.$M=B.getMonth(),this.$D=B.getDate(),this.$W=B.getDay(),this.$H=B.getHours(),this.$m=B.getMinutes(),this.$s=B.getSeconds(),this.$ms=B.getMilliseconds()},F.$utils=function(){return R},F.isValid=function(){return this.$d.toString()!==x},F.isSame=function(B,W){var L=E(B);return this.startOf(W)<=L&&L<=this.endOf(W)},F.isAfter=function(B,W){return E(B)<this.startOf(W)},F.isBefore=function(B,W){return this.endOf(W)<E(B)},F.$g=function(B,W,L){return R.u(B)?this[W]:this.set(L,B)},F.unix=function(){return Math.floor(this.valueOf()/1e3)},F.valueOf=function(){return this.$d.getTime()},F.startOf=function(B,W){var L=this,D=!!R.u(W)||W,I=R.p(B),V=function(J,de){var we=R.w(L.$u?Date.UTC(L.$y,de,J):new Date(L.$y,de,J),L);return D?we:we.endOf(u)},H=function(J,de){return R.w(L.toDate()[J].apply(L.toDate("s"),(D?[0,0,0,0]:[23,59,59,999]).slice(de)),L)},M=this.$W,Y=this.$M,X=this.$D,K="set"+(this.$u?"UTC":"");switch(I){case m:return D?V(1,0):V(31,11);case h:return D?V(1,Y):V(0,Y+1);case d:var te=this.$locale().weekStart||0,ce=(M<te?M+7:M)-te;return V(D?X-ce:X+(6-ce),Y);case u:case g:return H(K+"Hours",0);case c:return H(K+"Minutes",1);case l:return H(K+"Seconds",2);case o:return H(K+"Milliseconds",3);default:return this.clone()}},F.endOf=function(B){return this.startOf(B,!1)},F.$set=function(B,W){var L,D=R.p(B),I="set"+(this.$u?"UTC":""),V=(L={},L[u]=I+"Date",L[g]=I+"Date",L[h]=I+"Month",L[m]=I+"FullYear",L[c]=I+"Hours",L[l]=I+"Minutes",L[o]=I+"Seconds",L[i]=I+"Milliseconds",L)[D],H=D===u?this.$D+(W-this.$W):W;if(D===h||D===m){var M=this.clone().set(g,1);M.$d[V](H),M.init(),this.$d=M.set(g,Math.min(this.$D,M.daysInMonth())).$d}else V&&this.$d[V](H);return this.init(),this},F.set=function(B,W){return this.clone().$set(B,W)},F.get=function(B){return this[R.p(B)]()},F.add=function(B,W){var L,D=this;B=Number(B);var I=R.p(W),V=function(Y){var X=E(D);return R.w(X.date(X.date()+Math.round(Y*B)),D)};if(I===h)return this.set(h,this.$M+B);if(I===m)return this.set(m,this.$y+B);if(I===u)return V(1);if(I===d)return V(7);var H=(L={},L[l]=r,L[c]=s,L[o]=n,L)[I]||1,M=this.$d.getTime()+B*H;return R.w(M,this)},F.subtract=function(B,W){return this.add(-1*B,W)},F.format=function(B){var W=this,L=this.$locale();if(!this.isValid())return L.invalidDate||x;var D=B||"YYYY-MM-DDTHH:mm:ssZ",I=R.z(this),V=this.$H,H=this.$m,M=this.$M,Y=L.weekdays,X=L.months,K=L.meridiem,te=function(de,we,se,ae){return de&&(de[we]||de(W,D))||se[we].slice(0,ae)},ce=function(de){return R.s(V%12||12,de,"0")},J=K||function(de,we,se){var ae=de<12?"AM":"PM";return se?ae.toLowerCase():ae};return D.replace(y,function(de,we){return we||function(se){switch(se){case"YY":return String(W.$y).slice(-2);case"YYYY":return R.s(W.$y,4,"0");case"M":return M+1;case"MM":return R.s(M+1,2,"0");case"MMM":return te(L.monthsShort,M,X,3);case"MMMM":return te(X,M);case"D":return W.$D;case"DD":return R.s(W.$D,2,"0");case"d":return String(W.$W);case"dd":return te(L.weekdaysMin,W.$W,Y,2);case"ddd":return te(L.weekdaysShort,W.$W,Y,3);case"dddd":return Y[W.$W];case"H":return String(V);case"HH":return R.s(V,2,"0");case"h":return ce(1);case"hh":return ce(2);case"a":return J(V,H,!0);case"A":return J(V,H,!1);case"m":return String(H);case"mm":return R.s(H,2,"0");case"s":return String(W.$s);case"ss":return R.s(W.$s,2,"0");case"SSS":return R.s(W.$ms,3,"0");case"Z":return I}return null}(de)||I.replace(":","")})},F.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},F.diff=function(B,W,L){var D,I=this,V=R.p(W),H=E(B),M=(H.utcOffset()-this.utcOffset())*r,Y=this-H,X=function(){return R.m(I,H)};switch(V){case m:D=X()/12;break;case h:D=X();break;case f:D=X()/3;break;case d:D=(Y-M)/6048e5;break;case u:D=(Y-M)/864e5;break;case c:D=Y/s;break;case l:D=Y/r;break;case o:D=Y/n;break;default:D=Y}return L?D:R.a(D)},F.daysInMonth=function(){return this.endOf(h).$D},F.$locale=function(){return k[this.$L]},F.locale=function(B,W){if(!B)return this.$L;var L=this.clone(),D=T(B,W,!0);return D&&(L.$L=D),L},F.clone=function(){return R.w(this.$d,this)},F.toDate=function(){return new Date(this.valueOf())},F.toJSON=function(){return this.isValid()?this.toISOString():null},F.toISOString=function(){return this.$d.toISOString()},F.toString=function(){return this.$d.toUTCString()},$}(),P=O.prototype;return E.prototype=P,[["$ms",i],["$s",o],["$m",l],["$H",c],["$W",u],["$M",h],["$y",m],["$D",g]].forEach(function($){P[$[1]]=function(F){return this.$g(F,$[0],$[1])}}),E.extend=function($,F){return $.$i||($(F,O,E),$.$i=!0),E},E.locale=T,E.isDayjs=N,E.unix=function($){return E(1e3*$)},E.en=k[S],E.Ls=k,E.p={},E})})(y7);var Sle=y7.exports;const XN=xn(Sle);var b7={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(Fr,function(){return function(n,r,s){var i=r.prototype,o=function(h){return h&&(h.indexOf?h:h.s)},l=function(h,f,m,g,x){var b=h.name?h:h.$locale(),y=o(b[f]),v=o(b[m]),w=y||v.map(function(S){return S.slice(0,g)});if(!x)return w;var _=b.weekStart;return w.map(function(S,k){return w[(k+(_||0))%7]})},c=function(){return s.Ls[s.locale()]},u=function(h,f){return h.formats[f]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(g,x,b){return x||b.slice(1)})}(h.formats[f.toUpperCase()])},d=function(){var h=this;return{months:function(f){return f?f.format("MMMM"):l(h,"months")},monthsShort:function(f){return f?f.format("MMM"):l(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(f){return f?f.format("dddd"):l(h,"weekdays")},weekdaysMin:function(f){return f?f.format("dd"):l(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(f){return f?f.format("ddd"):l(h,"weekdaysShort","weekdays",3)},longDateFormat:function(f){return u(h.$locale(),f)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};i.localeData=function(){return d.bind(this)()},s.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return s.weekdays()},weekdaysShort:function(){return s.weekdaysShort()},weekdaysMin:function(){return s.weekdaysMin()},months:function(){return s.months()},monthsShort:function(){return s.monthsShort()},longDateFormat:function(f){return u(h,f)},meridiem:h.meridiem,ordinal:h.ordinal}},s.months=function(){return l(c(),"months")},s.monthsShort=function(){return l(c(),"monthsShort","months",3)},s.weekdays=function(h){return l(c(),"weekdays",null,null,h)},s.weekdaysShort=function(h){return l(c(),"weekdaysShort","weekdays",3,h)},s.weekdaysMin=function(h){return l(c(),"weekdaysMin","weekdays",2,h)}}})})(b7);var kle=b7.exports;const Cle=xn(kle),ki=(e,t)=>new Un(e).setA(t).toRgbString(),jd=(e,t)=>new Un(e).lighten(t).toHexString(),Nle=e=>{const t=Bh(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]}},jle=(e,t)=>{const n=e||"#000",r=t||"#fff";return{colorBgBase:n,colorTextBase:r,colorText:ki(r,.85),colorTextSecondary:ki(r,.65),colorTextTertiary:ki(r,.45),colorTextQuaternary:ki(r,.25),colorFill:ki(r,.18),colorFillSecondary:ki(r,.12),colorFillTertiary:ki(r,.08),colorFillQuaternary:ki(r,.04),colorBgSolid:ki(r,.95),colorBgSolidHover:ki(r,1),colorBgSolidActive:ki(r,.9),colorBgElevated:jd(n,12),colorBgContainer:jd(n,8),colorBgLayout:jd(n,0),colorBgSpotlight:jd(n,26),colorBgBlur:ki(r,.04),colorBorder:jd(n,26),colorBorderSecondary:jd(n,19)}},Ele=(e,t)=>{const n=Object.keys(E5).map(i=>{const o=Bh(e[i],{theme:"dark"});return Array.from({length:10},()=>1).reduce((l,c,u)=>(l[`${i}-${u+1}`]=o[u],l[`${i}${u+1}`]=o[u],l),{})}).reduce((i,o)=>(i=Object.assign(Object.assign({},i),o),i),{}),r=t??I5(e),s=t7(e,{generateColorPalettes:Nle,generateNeutralColorPalettes:jle});return Object.assign(Object.assign(Object.assign(Object.assign({},r),n),s),{colorPrimaryBg:s.colorPrimaryBorder,colorPrimaryBgHover:s.colorPrimaryBorderHover})},lO={defaultSeed:Eb.token,defaultAlgorithm:I5,darkAlgorithm:Ele};function Ile({children:e}){const t=ul(),[n,r]=p.useState(t.theme);return p.useEffect(()=>t.onThemeChange(r),[t]),a.jsx(jf,{theme:{algorithm:n.mode==="dark"?lO.darkAlgorithm:lO.defaultAlgorithm,token:{colorPrimary:n.colorPrimary,colorBgContainer:n.colorBgContainer,colorText:n.colorText,colorBorder:n.colorBorder}},children:e})}var Gt;(function(e){e.assertEqual=s=>{};function t(s){}e.assertIs=t;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const i={};for(const o of s)i[o]=o;return i},e.getValidEnumValues=s=>{const i=e.objectKeys(s).filter(l=>typeof s[s[l]]!="number"),o={};for(const l of i)o[l]=s[l];return e.objectValues(o)},e.objectValues=s=>e.objectKeys(s).map(function(i){return s[i]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},e.find=(s,i)=>{for(const o of s)if(i(o))return o},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}e.joinValues=r,e.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(Gt||(Gt={}));var cO;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(cO||(cO={}));const Xe=Gt.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Bl=e=>{switch(typeof e){case"undefined":return Xe.undefined;case"string":return Xe.string;case"number":return Number.isNaN(e)?Xe.nan:Xe.number;case"boolean":return Xe.boolean;case"function":return Xe.function;case"bigint":return Xe.bigint;case"symbol":return Xe.symbol;case"object":return Array.isArray(e)?Xe.array:e===null?Xe.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?Xe.promise:typeof Map<"u"&&e instanceof Map?Xe.map:typeof Set<"u"&&e instanceof Set?Xe.set:typeof Date<"u"&&e instanceof Date?Xe.date:Xe.object;default:return Xe.unknown}},ke=Gt.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 nl 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(i){return i.message},r={_errors:[]},s=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let l=r,c=0;for(;c<o.path.length;){const u=o.path[c];c===o.path.length-1?(l[u]=l[u]||{_errors:[]},l[u]._errors.push(n(o))):l[u]=l[u]||{_errors:[]},l=l[u],c++}}};return s(this),r}static assert(t){if(!(t instanceof nl))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Gt.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=n=>n.message){const n={},r=[];for(const s of this.issues)if(s.path.length>0){const i=s.path[0];n[i]=n[i]||[],n[i].push(t(s))}else r.push(t(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}nl.create=e=>new nl(e);const ZN=(e,t)=>{let n;switch(e.code){case ke.invalid_type:e.received===Xe.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case ke.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Gt.jsonStringifyReplacer)}`;break;case ke.unrecognized_keys:n=`Unrecognized key(s) in object: ${Gt.joinValues(e.keys,", ")}`;break;case ke.invalid_union:n="Invalid input";break;case ke.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Gt.joinValues(e.options)}`;break;case ke.invalid_enum_value:n=`Invalid enum value. Expected ${Gt.joinValues(e.options)}, received '${e.received}'`;break;case ke.invalid_arguments:n="Invalid function arguments";break;case ke.invalid_return_type:n="Invalid function return type";break;case ke.invalid_date:n="Invalid date";break;case ke.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}"`:Gt.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case ke.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 ke.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 ke.custom:n="Invalid input";break;case ke.invalid_intersection_types:n="Intersection results could not be merged";break;case ke.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case ke.not_finite:n="Number must be finite";break;default:n=t.defaultError,Gt.assertNever(e)}return{message:n}};let Tle=ZN;function Rle(){return Tle}const Mle=e=>{const{data:t,path:n,errorMaps:r,issueData:s}=e,i=[...n,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let l="";const c=r.filter(u=>!!u).slice().reverse();for(const u of c)l=u(o,{data:t,defaultError:l}).message;return{...s,path:i,message:l}};function Fe(e,t){const n=Rle(),r=Mle({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===ZN?void 0:ZN].filter(s=>!!s)});e.common.issues.push(r)}class ys{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 s of n){if(s.status==="aborted")return mt;s.status==="dirty"&&t.dirty(),r.push(s.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const s of n){const i=await s.key,o=await s.value;r.push({key:i,value:o})}return ys.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const s of n){const{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return mt;i.status==="dirty"&&t.dirty(),o.status==="dirty"&&t.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(r[i.value]=o.value)}return{status:t.value,value:r}}}const mt=Object.freeze({status:"aborted"}),sm=e=>({status:"dirty",value:e}),Gi=e=>({status:"valid",value:e}),uO=e=>e.status==="aborted",dO=e=>e.status==="dirty",zh=e=>e.status==="valid",Ib=e=>typeof Promise<"u"&&e instanceof Promise;var st;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(st||(st={}));class la{constructor(t,n,r,s){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=s}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 hO=(e,t)=>{if(zh(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 nl(e.common.issues);return this._error=n,this._error}}};function kt(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:s}=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:s}:{errorMap:(o,l)=>{const{message:c}=e;return o.code==="invalid_enum_value"?{message:c??l.defaultError}:typeof l.data>"u"?{message:c??r??l.defaultError}:o.code!=="invalid_type"?{message:l.defaultError}:{message:c??n??l.defaultError}},description:s}}class zt{get description(){return this._def.description}_getType(t){return Bl(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:Bl(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new ys,ctx:{common:t.parent.common,data:t.data,parsedType:Bl(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(Ib(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:Bl(t)},s=this._parseSync({data:t,path:r.path,parent:r});return hO(r,s)}"~validate"(t){var r,s;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Bl(t)};if(!this["~standard"].async)try{const i=this._parseSync({data:t,path:[],parent:n});return zh(i)?{value:i.value}:{issues:n.common.issues}}catch(i){(s=(r=i==null?void 0:i.message)==null?void 0:r.toLowerCase())!=null&&s.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:n}).then(i=>zh(i)?{value:i.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:Bl(t)},s=this._parse({data:t,path:r.path,parent:r}),i=await(Ib(s)?s:Promise.resolve(s));return hO(r,i)}refine(t,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,i)=>{const o=t(s),l=()=>i.addIssue({code:ke.custom,...r(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(l(),!1)):o?!0:(l(),!1)})}refinement(t,n){return this._refinement((r,s)=>t(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(t){return new gc({schema:this,typeName:gt.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 Ya.create(this,this._def)}nullable(){return Eu.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return na.create(this)}promise(){return Db.create(this,this._def)}or(t){return Rb.create([this,t],this._def)}and(t){return Mb.create(this,t,this._def)}transform(t){return new gc({...kt(this._def),schema:this,typeName:gt.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new Ab({...kt(this._def),innerType:this,defaultValue:n,typeName:gt.ZodDefault})}brand(){return new k7({typeName:gt.ZodBranded,type:this,...kt(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new $b({...kt(this._def),innerType:this,catchValue:n,typeName:gt.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return M5.create(this,t)}readonly(){return Lb.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Ple=/^c[^\s-]{8,}$/i,Ole=/^[0-9a-z]+$/,Dle=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ale=/^[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,$le=/^[a-z0-9_-]{21}$/i,Lle=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Fle=/^[-+]?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)?)??$/,Ble=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,zle="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ck;const Hle=/^(?:(?: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])$/,Ule=/^(?:(?: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])$/,Wle=/^(([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]))$/,Vle=/^(([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])$/,qle=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Kle=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,w7="((\\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])))",Gle=new RegExp(`^${w7}$`);function _7(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 Yle(e){return new RegExp(`^${_7(e)}$`)}function Xle(e){let t=`${w7}T${_7(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 Zle(e,t){return!!((t==="v4"||!t)&&Hle.test(e)||(t==="v6"||!t)&&Wle.test(e))}function Qle(e,t){if(!Lle.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,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||t&&s.alg!==t)}catch{return!1}}function Jle(e,t){return!!((t==="v4"||!t)&&Ule.test(e)||(t==="v6"||!t)&&Vle.test(e))}class Wa extends zt{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==Xe.string){const i=this._getOrReturnCtx(t);return Fe(i,{code:ke.invalid_type,expected:Xe.string,received:i.parsedType}),mt}const r=new ys;let s;for(const i of this._def.checks)if(i.kind==="min")t.data.length<i.value&&(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")t.data.length>i.value&&(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){const o=t.data.length>i.value,l=t.data.length<i.value;(o||l)&&(s=this._getOrReturnCtx(t,s),o?Fe(s,{code:ke.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):l&&Fe(s,{code:ke.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")Ble.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"email",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")Ck||(Ck=new RegExp(zle,"u")),Ck.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"emoji",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")Ale.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"uuid",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")$le.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"nanoid",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")Ple.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"cuid",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")Ole.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"cuid2",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")Dle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"ulid",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(t.data)}catch{s=this._getOrReturnCtx(t,s),Fe(s,{validation:"url",code:ke.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"regex",code:ke.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?t.data=t.data.trim():i.kind==="includes"?t.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?t.data=t.data.toLowerCase():i.kind==="toUpperCase"?t.data=t.data.toUpperCase():i.kind==="startsWith"?t.data.startsWith(i.value)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?t.data.endsWith(i.value)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?Xle(i).test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?Gle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?Yle(i).test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?Fle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"duration",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?Zle(t.data,i.version)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"ip",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?Qle(t.data,i.alg)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"jwt",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?Jle(t.data,i.version)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"cidr",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?qle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"base64",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?Kle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"base64url",code:ke.invalid_string,message:i.message}),r.dirty()):Gt.assertNever(i);return{status:r.value,value:t.data}}_regex(t,n,r){return this.refinement(s=>t.test(s),{validation:n,code:ke.invalid_string,...st.errToObj(r)})}_addCheck(t){return new Wa({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...st.errToObj(t)})}url(t){return this._addCheck({kind:"url",...st.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...st.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...st.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...st.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...st.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...st.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...st.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...st.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...st.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...st.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...st.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...st.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,...st.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,...st.errToObj(t==null?void 0:t.message)})}duration(t){return this._addCheck({kind:"duration",...st.errToObj(t)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...st.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...st.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...st.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...st.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...st.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...st.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...st.errToObj(n)})}nonempty(t){return this.min(1,st.errToObj(t))}trim(){return new Wa({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Wa({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Wa({...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}}Wa.create=e=>new Wa({checks:[],typeName:gt.ZodString,coerce:(e==null?void 0:e.coerce)??!1,...kt(e)});function ece(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,s=n>r?n:r,i=Number.parseInt(e.toFixed(s).replace(".","")),o=Number.parseInt(t.toFixed(s).replace(".",""));return i%o/10**s}class Hh extends zt{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)!==Xe.number){const i=this._getOrReturnCtx(t);return Fe(i,{code:ke.invalid_type,expected:Xe.number,received:i.parsedType}),mt}let r;const s=new ys;for(const i of this._def.checks)i.kind==="int"?Gt.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?t.data<i.value:t.data<=i.value)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?t.data>i.value:t.data>=i.value)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?ece(t.data,i.value)!==0&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.not_finite,message:i.message}),s.dirty()):Gt.assertNever(i);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,st.toString(n))}gt(t,n){return this.setLimit("min",t,!1,st.toString(n))}lte(t,n){return this.setLimit("max",t,!0,st.toString(n))}lt(t,n){return this.setLimit("max",t,!1,st.toString(n))}setLimit(t,n,r,s){return new Hh({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:st.toString(s)}]})}_addCheck(t){return new Hh({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:st.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:st.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:st.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:st.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:st.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:st.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:st.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:st.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:st.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"&&Gt.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)}}Hh.create=e=>new Hh({checks:[],typeName:gt.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...kt(e)});class wg extends zt{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)!==Xe.bigint)return this._getInvalidInput(t);let r;const s=new ys;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?t.data<i.value:t.data<=i.value)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?t.data>i.value:t.data>=i.value)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?t.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):Gt.assertNever(i);return{status:s.value,value:t.data}}_getInvalidInput(t){const n=this._getOrReturnCtx(t);return Fe(n,{code:ke.invalid_type,expected:Xe.bigint,received:n.parsedType}),mt}gte(t,n){return this.setLimit("min",t,!0,st.toString(n))}gt(t,n){return this.setLimit("min",t,!1,st.toString(n))}lte(t,n){return this.setLimit("max",t,!0,st.toString(n))}lt(t,n){return this.setLimit("max",t,!1,st.toString(n))}setLimit(t,n,r,s){return new wg({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:st.toString(s)}]})}_addCheck(t){return new wg({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:st.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:st.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:st.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:st.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:st.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}}wg.create=e=>new wg({checks:[],typeName:gt.ZodBigInt,coerce:(e==null?void 0:e.coerce)??!1,...kt(e)});class QN extends zt{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Xe.boolean){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.boolean,received:r.parsedType}),mt}return Gi(t.data)}}QN.create=e=>new QN({typeName:gt.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...kt(e)});class Tb extends zt{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Xe.date){const i=this._getOrReturnCtx(t);return Fe(i,{code:ke.invalid_type,expected:Xe.date,received:i.parsedType}),mt}if(Number.isNaN(t.data.getTime())){const i=this._getOrReturnCtx(t);return Fe(i,{code:ke.invalid_date}),mt}const r=new ys;let s;for(const i of this._def.checks)i.kind==="min"?t.data.getTime()<i.value&&(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?t.data.getTime()>i.value&&(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):Gt.assertNever(i);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Tb({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:st.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:st.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}}Tb.create=e=>new Tb({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:gt.ZodDate,...kt(e)});class fO extends zt{_parse(t){if(this._getType(t)!==Xe.symbol){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.symbol,received:r.parsedType}),mt}return Gi(t.data)}}fO.create=e=>new fO({typeName:gt.ZodSymbol,...kt(e)});class JN extends zt{_parse(t){if(this._getType(t)!==Xe.undefined){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.undefined,received:r.parsedType}),mt}return Gi(t.data)}}JN.create=e=>new JN({typeName:gt.ZodUndefined,...kt(e)});class ej extends zt{_parse(t){if(this._getType(t)!==Xe.null){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.null,received:r.parsedType}),mt}return Gi(t.data)}}ej.create=e=>new ej({typeName:gt.ZodNull,...kt(e)});class pO extends zt{constructor(){super(...arguments),this._any=!0}_parse(t){return Gi(t.data)}}pO.create=e=>new pO({typeName:gt.ZodAny,...kt(e)});class tj extends zt{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Gi(t.data)}}tj.create=e=>new tj({typeName:gt.ZodUnknown,...kt(e)});class mc extends zt{_parse(t){const n=this._getOrReturnCtx(t);return Fe(n,{code:ke.invalid_type,expected:Xe.never,received:n.parsedType}),mt}}mc.create=e=>new mc({typeName:gt.ZodNever,...kt(e)});class mO extends zt{_parse(t){if(this._getType(t)!==Xe.undefined){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.void,received:r.parsedType}),mt}return Gi(t.data)}}mO.create=e=>new mO({typeName:gt.ZodVoid,...kt(e)});class na extends zt{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==Xe.array)return Fe(n,{code:ke.invalid_type,expected:Xe.array,received:n.parsedType}),mt;if(s.exactLength!==null){const o=n.data.length>s.exactLength.value,l=n.data.length<s.exactLength.value;(o||l)&&(Fe(n,{code:o?ke.too_big:ke.too_small,minimum:l?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(Fe(n,{code:ke.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(Fe(n,{code:ke.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,l)=>s.type._parseAsync(new la(n,o,n.path,l)))).then(o=>ys.mergeArray(r,o));const i=[...n.data].map((o,l)=>s.type._parseSync(new la(n,o,n.path,l)));return ys.mergeArray(r,i)}get element(){return this._def.type}min(t,n){return new na({...this._def,minLength:{value:t,message:st.toString(n)}})}max(t,n){return new na({...this._def,maxLength:{value:t,message:st.toString(n)}})}length(t,n){return new na({...this._def,exactLength:{value:t,message:st.toString(n)}})}nonempty(t){return this.min(1,t)}}na.create=(e,t)=>new na({type:e,minLength:null,maxLength:null,exactLength:null,typeName:gt.ZodArray,...kt(t)});function Vd(e){if(e instanceof ir){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Ya.create(Vd(r))}return new ir({...e._def,shape:()=>t})}else return e instanceof na?new na({...e._def,type:Vd(e.element)}):e instanceof Ya?Ya.create(Vd(e.unwrap())):e instanceof Eu?Eu.create(Vd(e.unwrap())):e instanceof Nu?Nu.create(e.items.map(t=>Vd(t))):e}class ir extends zt{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=Gt.objectKeys(t);return this._cached={shape:t,keys:n},this._cached}_parse(t){if(this._getType(t)!==Xe.object){const u=this._getOrReturnCtx(t);return Fe(u,{code:ke.invalid_type,expected:Xe.object,received:u.parsedType}),mt}const{status:r,ctx:s}=this._processInputParams(t),{shape:i,keys:o}=this._getCached(),l=[];if(!(this._def.catchall instanceof mc&&this._def.unknownKeys==="strip"))for(const u in s.data)o.includes(u)||l.push(u);const c=[];for(const u of o){const d=i[u],h=s.data[u];c.push({key:{status:"valid",value:u},value:d._parse(new la(s,h,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof mc){const u=this._def.unknownKeys;if(u==="passthrough")for(const d of l)c.push({key:{status:"valid",value:d},value:{status:"valid",value:s.data[d]}});else if(u==="strict")l.length>0&&(Fe(s,{code:ke.unrecognized_keys,keys:l}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const d of l){const h=s.data[d];c.push({key:{status:"valid",value:d},value:u._parse(new la(s,h,s.path,d)),alwaysSet:d in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const d of c){const h=await d.key,f=await d.value;u.push({key:h,value:f,alwaysSet:d.alwaysSet})}return u}).then(u=>ys.mergeObjectSync(r,u)):ys.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(t){return st.errToObj,new ir({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{var i,o;const s=((o=(i=this._def).errorMap)==null?void 0:o.call(i,n,r).message)??r.defaultError;return n.code==="unrecognized_keys"?{message:st.errToObj(t).message??s}:{message:s}}}:{}})}strip(){return new ir({...this._def,unknownKeys:"strip"})}passthrough(){return new ir({...this._def,unknownKeys:"passthrough"})}extend(t){return new ir({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new ir({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:gt.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new ir({...this._def,catchall:t})}pick(t){const n={};for(const r of Gt.objectKeys(t))t[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new ir({...this._def,shape:()=>n})}omit(t){const n={};for(const r of Gt.objectKeys(this.shape))t[r]||(n[r]=this.shape[r]);return new ir({...this._def,shape:()=>n})}deepPartial(){return Vd(this)}partial(t){const n={};for(const r of Gt.objectKeys(this.shape)){const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}return new ir({...this._def,shape:()=>n})}required(t){const n={};for(const r of Gt.objectKeys(this.shape))if(t&&!t[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof Ya;)i=i._def.innerType;n[r]=i}return new ir({...this._def,shape:()=>n})}keyof(){return S7(Gt.objectKeys(this.shape))}}ir.create=(e,t)=>new ir({shape:()=>e,unknownKeys:"strip",catchall:mc.create(),typeName:gt.ZodObject,...kt(t)});ir.strictCreate=(e,t)=>new ir({shape:()=>e,unknownKeys:"strict",catchall:mc.create(),typeName:gt.ZodObject,...kt(t)});ir.lazycreate=(e,t)=>new ir({shape:e,unknownKeys:"strip",catchall:mc.create(),typeName:gt.ZodObject,...kt(t)});class Rb extends zt{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function s(i){for(const l of i)if(l.result.status==="valid")return l.result;for(const l of i)if(l.result.status==="dirty")return n.common.issues.push(...l.ctx.common.issues),l.result;const o=i.map(l=>new nl(l.ctx.common.issues));return Fe(n,{code:ke.invalid_union,unionErrors:o}),mt}if(n.common.async)return Promise.all(r.map(async i=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(s);{let i;const o=[];for(const c of r){const u={...n,common:{...n.common,issues:[]},parent:null},d=c._parseSync({data:n.data,path:n.path,parent:u});if(d.status==="valid")return d;d.status==="dirty"&&!i&&(i={result:d,ctx:u}),u.common.issues.length&&o.push(u.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;const l=o.map(c=>new nl(c));return Fe(n,{code:ke.invalid_union,unionErrors:l}),mt}}get options(){return this._def.options}}Rb.create=(e,t)=>new Rb({options:e,typeName:gt.ZodUnion,...kt(t)});const Fa=e=>e instanceof rj?Fa(e.schema):e instanceof gc?Fa(e.innerType()):e instanceof Ob?[e.value]:e instanceof ju?e.options:e instanceof sj?Gt.objectValues(e.enum):e instanceof Ab?Fa(e._def.innerType):e instanceof JN?[void 0]:e instanceof ej?[null]:e instanceof Ya?[void 0,...Fa(e.unwrap())]:e instanceof Eu?[null,...Fa(e.unwrap())]:e instanceof k7||e instanceof Lb?Fa(e.unwrap()):e instanceof $b?Fa(e._def.innerType):[];class R5 extends zt{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Xe.object)return Fe(n,{code:ke.invalid_type,expected:Xe.object,received:n.parsedType}),mt;const r=this.discriminator,s=n.data[r],i=this.optionsMap.get(s);return i?n.common.async?i._parseAsync({data:n.data,path:n.path,parent:n}):i._parseSync({data:n.data,path:n.path,parent:n}):(Fe(n,{code:ke.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),mt)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const s=new Map;for(const i of n){const o=Fa(i.shape[t]);if(!o.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const l of o){if(s.has(l))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(l)}`);s.set(l,i)}}return new R5({typeName:gt.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...kt(r)})}}function nj(e,t){const n=Bl(e),r=Bl(t);if(e===t)return{valid:!0,data:e};if(n===Xe.object&&r===Xe.object){const s=Gt.objectKeys(t),i=Gt.objectKeys(e).filter(l=>s.indexOf(l)!==-1),o={...e,...t};for(const l of i){const c=nj(e[l],t[l]);if(!c.valid)return{valid:!1};o[l]=c.data}return{valid:!0,data:o}}else if(n===Xe.array&&r===Xe.array){if(e.length!==t.length)return{valid:!1};const s=[];for(let i=0;i<e.length;i++){const o=e[i],l=t[i],c=nj(o,l);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return n===Xe.date&&r===Xe.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}class Mb extends zt{_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=(i,o)=>{if(uO(i)||uO(o))return mt;const l=nj(i.value,o.value);return l.valid?((dO(i)||dO(o))&&n.dirty(),{status:n.value,value:l.data}):(Fe(r,{code:ke.invalid_intersection_types}),mt)};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(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Mb.create=(e,t,n)=>new Mb({left:e,right:t,typeName:gt.ZodIntersection,...kt(n)});class Nu extends zt{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Xe.array)return Fe(r,{code:ke.invalid_type,expected:Xe.array,received:r.parsedType}),mt;if(r.data.length<this._def.items.length)return Fe(r,{code:ke.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),mt;!this._def.rest&&r.data.length>this._def.items.length&&(Fe(r,{code:ke.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const i=[...r.data].map((o,l)=>{const c=this._def.items[l]||this._def.rest;return c?c._parse(new la(r,o,r.path,l)):null}).filter(o=>!!o);return r.common.async?Promise.all(i).then(o=>ys.mergeArray(n,o)):ys.mergeArray(n,i)}get items(){return this._def.items}rest(t){return new Nu({...this._def,rest:t})}}Nu.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Nu({items:e,typeName:gt.ZodTuple,rest:null,...kt(t)})};class Pb extends zt{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!==Xe.object)return Fe(r,{code:ke.invalid_type,expected:Xe.object,received:r.parsedType}),mt;const s=[],i=this._def.keyType,o=this._def.valueType;for(const l in r.data)s.push({key:i._parse(new la(r,l,r.path,l)),value:o._parse(new la(r,r.data[l],r.path,l)),alwaysSet:l in r.data});return r.common.async?ys.mergeObjectAsync(n,s):ys.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof zt?new Pb({keyType:t,valueType:n,typeName:gt.ZodRecord,...kt(r)}):new Pb({keyType:Wa.create(),valueType:t,typeName:gt.ZodRecord,...kt(n)})}}class gO extends zt{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!==Xe.map)return Fe(r,{code:ke.invalid_type,expected:Xe.map,received:r.parsedType}),mt;const s=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map(([l,c],u)=>({key:s._parse(new la(r,l,r.path,[u,"key"])),value:i._parse(new la(r,c,r.path,[u,"value"]))}));if(r.common.async){const l=new Map;return Promise.resolve().then(async()=>{for(const c of o){const u=await c.key,d=await c.value;if(u.status==="aborted"||d.status==="aborted")return mt;(u.status==="dirty"||d.status==="dirty")&&n.dirty(),l.set(u.value,d.value)}return{status:n.value,value:l}})}else{const l=new Map;for(const c of o){const u=c.key,d=c.value;if(u.status==="aborted"||d.status==="aborted")return mt;(u.status==="dirty"||d.status==="dirty")&&n.dirty(),l.set(u.value,d.value)}return{status:n.value,value:l}}}}gO.create=(e,t,n)=>new gO({valueType:t,keyType:e,typeName:gt.ZodMap,...kt(n)});class _g extends zt{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Xe.set)return Fe(r,{code:ke.invalid_type,expected:Xe.set,received:r.parsedType}),mt;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(Fe(r,{code:ke.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(Fe(r,{code:ke.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const i=this._def.valueType;function o(c){const u=new Set;for(const d of c){if(d.status==="aborted")return mt;d.status==="dirty"&&n.dirty(),u.add(d.value)}return{status:n.value,value:u}}const l=[...r.data.values()].map((c,u)=>i._parse(new la(r,c,r.path,u)));return r.common.async?Promise.all(l).then(c=>o(c)):o(l)}min(t,n){return new _g({...this._def,minSize:{value:t,message:st.toString(n)}})}max(t,n){return new _g({...this._def,maxSize:{value:t,message:st.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}_g.create=(e,t)=>new _g({valueType:e,minSize:null,maxSize:null,typeName:gt.ZodSet,...kt(t)});class rj extends zt{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})}}rj.create=(e,t)=>new rj({getter:e,typeName:gt.ZodLazy,...kt(t)});class Ob extends zt{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return Fe(n,{received:n.data,code:ke.invalid_literal,expected:this._def.value}),mt}return{status:"valid",value:t.data}}get value(){return this._def.value}}Ob.create=(e,t)=>new Ob({value:e,typeName:gt.ZodLiteral,...kt(t)});function S7(e,t){return new ju({values:e,typeName:gt.ZodEnum,...kt(t)})}class ju extends zt{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return Fe(n,{expected:Gt.joinValues(r),received:n.parsedType,code:ke.invalid_type}),mt}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 Fe(n,{received:n.data,code:ke.invalid_enum_value,options:r}),mt}return Gi(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 ju.create(t,{...this._def,...n})}exclude(t,n=this._def){return ju.create(this.options.filter(r=>!t.includes(r)),{...this._def,...n})}}ju.create=S7;class sj extends zt{_parse(t){const n=Gt.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Xe.string&&r.parsedType!==Xe.number){const s=Gt.objectValues(n);return Fe(r,{expected:Gt.joinValues(s),received:r.parsedType,code:ke.invalid_type}),mt}if(this._cache||(this._cache=new Set(Gt.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){const s=Gt.objectValues(n);return Fe(r,{received:r.data,code:ke.invalid_enum_value,options:s}),mt}return Gi(t.data)}get enum(){return this._def.values}}sj.create=(e,t)=>new sj({values:e,typeName:gt.ZodNativeEnum,...kt(t)});class Db extends zt{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Xe.promise&&n.common.async===!1)return Fe(n,{code:ke.invalid_type,expected:Xe.promise,received:n.parsedType}),mt;const r=n.parsedType===Xe.promise?n.data:Promise.resolve(n.data);return Gi(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Db.create=(e,t)=>new Db({type:e,typeName:gt.ZodPromise,...kt(t)});class gc extends zt{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===gt.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=this._def.effect||null,i={addIssue:o=>{Fe(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){const o=s.transform(r.data,i);if(r.common.async)return Promise.resolve(o).then(async l=>{if(n.value==="aborted")return mt;const c=await this._def.schema._parseAsync({data:l,path:r.path,parent:r});return c.status==="aborted"?mt:c.status==="dirty"||n.value==="dirty"?sm(c.value):c});{if(n.value==="aborted")return mt;const l=this._def.schema._parseSync({data:o,path:r.path,parent:r});return l.status==="aborted"?mt:l.status==="dirty"||n.value==="dirty"?sm(l.value):l}}if(s.type==="refinement"){const o=l=>{const c=s.refinement(l,i);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return l};if(r.common.async===!1){const l=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return l.status==="aborted"?mt:(l.status==="dirty"&&n.dirty(),o(l.value),{status:n.value,value:l.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(l=>l.status==="aborted"?mt:(l.status==="dirty"&&n.dirty(),o(l.value).then(()=>({status:n.value,value:l.value}))))}if(s.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!zh(o))return mt;const l=s.transform(o.value,i);if(l instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:l}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>zh(o)?Promise.resolve(s.transform(o.value,i)).then(l=>({status:n.value,value:l})):mt);Gt.assertNever(s)}}gc.create=(e,t,n)=>new gc({schema:e,typeName:gt.ZodEffects,effect:t,...kt(n)});gc.createWithPreprocess=(e,t,n)=>new gc({schema:t,effect:{type:"preprocess",transform:e},typeName:gt.ZodEffects,...kt(n)});class Ya extends zt{_parse(t){return this._getType(t)===Xe.undefined?Gi(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Ya.create=(e,t)=>new Ya({innerType:e,typeName:gt.ZodOptional,...kt(t)});class Eu extends zt{_parse(t){return this._getType(t)===Xe.null?Gi(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Eu.create=(e,t)=>new Eu({innerType:e,typeName:gt.ZodNullable,...kt(t)});class Ab extends zt{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===Xe.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Ab.create=(e,t)=>new Ab({innerType:e,typeName:gt.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...kt(t)});class $b extends zt{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Ib(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new nl(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new nl(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}$b.create=(e,t)=>new $b({innerType:e,typeName:gt.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...kt(t)});class xO extends zt{_parse(t){if(this._getType(t)!==Xe.nan){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.nan,received:r.parsedType}),mt}return{status:"valid",value:t.data}}}xO.create=e=>new xO({typeName:gt.ZodNaN,...kt(e)});class k7 extends zt{_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 M5 extends zt{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?mt:i.status==="dirty"?(n.dirty(),sm(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?mt:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(t,n){return new M5({in:t,out:n,typeName:gt.ZodPipeline})}}class Lb extends zt{_parse(t){const n=this._def.innerType._parse(t),r=s=>(zh(s)&&(s.value=Object.freeze(s.value)),s);return Ib(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}}Lb.create=(e,t)=>new Lb({innerType:e,typeName:gt.ZodReadonly,...kt(t)});var gt;(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"})(gt||(gt={}));const j=Wa.create,Q=Hh.create,Re=QN.create,Xa=tj.create;mc.create;const xe=na.create,z=ir.create,tce=Rb.create,Bs=R5.create;Mb.create;Nu.create;const Yi=Pb.create,he=Ob.create,et=ju.create;Db.create;Ya.create;Eu.create;const nce=gc.createWithPreprocess,rce=["head","index"],C7=j().regex(/^[A-Za-z0-9][A-Za-z0-9-]{0,127}$/),Fb=j().regex(/^[1-9][0-9]*$/),Bb=j().regex(/^[A-Za-z0-9_.-]+$/),Sg=j().min(1).max(255).refine(e=>!e.startsWith("-")&&e!=="HEAD"&&!e.startsWith("/")&&!e.endsWith("/")&&!e.endsWith(".")&&!/[\s~^:?*\[\\\x00-\x1f\x7f]/.test(e)&&!e.includes("..")&&!e.includes("@{")&&!e.includes("//")&&e.split("/").every(t=>!t.startsWith(".")&&!t.endsWith(".lock")),"Invalid Git branch"),P5=j().min(1).max(4096).refine(e=>!e.startsWith("/")&&!e.includes("\0")&&!e.split(/[\\/]/).includes("..")),Ew=z({workspaceId:C7,repoId:Fb,owner:Bb,name:Bb,sourceBranch:Sg,defaultBranch:Sg}).strict(),sce=z({repoId:Fb,owner:Bb,name:Bb,defaultBranch:j(),private:Re(),description:j().nullable()}),ice=Ew.extend({initialCommit:j(),head:j(),actualBranch:j().nullable(),branches:xe(j()).optional(),files:xe(z({path:P5,previousPath:j().optional(),comparison:et(rce).optional(),status:j(),added:Q().nonnegative(),removed:Q().nonnegative(),binary:Re(),untracked:Re().optional()})),totalFiles:Q().int().nonnegative().optional(),filesTruncated:Re().optional(),added:Q().nonnegative(),removed:Q().nonnegative(),dirty:Re(),conflicted:Re(),version:j(),measuredAt:Q()}),Ed=z({sessionId:C7});Bs("action",[Ed.extend({action:he("repositories"),page:Q().int().min(1).max(1e3).optional(),search:j().max(100).optional()}).strict(),Ed.extend({action:he("branches"),repoId:Fb,page:Q().int().min(1).max(1e3).optional(),search:j().max(100).optional(),cursor:j().min(1).max(1024).optional()}).strict(),Ed.extend({action:he("bind"),repoId:Fb,branch:Sg}).strict(),Ed.extend({action:he("status")}).strict(),Ed.extend({action:he("intend"),branch:Sg.optional()}).strict(),Ed.extend({action:he("diff"),filePath:P5}).strict()]);z({binding:Ew.nullable().optional(),workspace:ice.nullable().optional(),repositories:xe(sce).optional(),branches:xe(j()).optional(),hasMore:Re().optional(),nextCursor:j().min(1).max(1024).optional(),diff:z({path:P5,patch:j(),binary:Re(),truncated:Re(),notStored:Re().optional()}).optional()});z({threadId:j().min(1),conversationId:j().min(1),workspace:Ew.optional()});new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");z({id:j().min(1),name:j().min(1),baseUrl:j().min(1),apiKey:j().min(1),remark:j().optional(),createdAt:Q(),updatedAt:Q()}).strict();const oce=z({id:j().min(1),name:j().min(1),baseUrl:j().min(1),remark:j().optional(),keyMasked:j(),hasKey:Re(),createdAt:Q(),updatedAt:Q()}).strict();z({activeChannelId:j().nullable(),channels:xe(oce)}).strict();z({}).strict();z({id:j().min(1).optional(),name:j().min(1),baseUrl:j().min(1),apiKey:j().optional(),remark:j().optional()}).strict();z({id:j().min(1)}).strict();z({id:j().min(1).nullable()}).strict();z({channelId:j().min(1).optional(),updatedAt:Q().optional()}).strict().refine(e=>e.updatedAt===void 0||e.channelId!==void 0,{message:"updatedAt requires channelId"});z({channelId:j().nullable(),models:xe(z({id:j().min(1),ownedBy:j().optional()}).strict())}).strict();const ace=["owner"],lce=["agent","owner","user-upload"],N7=z({id:j().min(1),relPath:j().min(1),from:et(lce),label:j().optional(),size:Q().int().nonnegative(),mime:j().min(1),addedAt:Q().int().nonnegative(),lastEditedAt:Q().int().nonnegative().optional(),stale:Re().optional()});z({sessionId:j().min(1),relPath:j().min(1),ttlSeconds:Q().int().positive().nullable().optional(),view:et(["raw","md-rendered"]).optional()});z({url:j().min(1),expiresAt:Q().int().nonnegative().nullable()});z({sessionId:j().min(1),relPath:j().min(1),label:j().optional(),origin:he("agent").optional()});z({entry:N7});z({sessionId:j().min(1),relPath:j().min(1)});z({removed:he(!0)});z({sessionId:j().min(1)});z({entries:xe(N7)});z({attachmentId:j().min(1),url:j().min(1),relPath:j().min(1),sizeBytes:Q().int().nonnegative(),mimeType:j().min(1)});const cce=Bs("type",[z({type:he("persona"),id:j().min(1)}).strict(),z({type:he("chat"),id:j().min(1)}).strict(),z({type:he("*")}).strict()]),uce=et(["read","send","admin"]),O5=z({resource:cce,actions:xe(uce).min(1)}).strict(),dce=z({id:j().min(1),secretHash:j().regex(/^[a-f0-9]{64}$/),displayName:j(),grants:xe(O5),issuedAt:Q().int().nonnegative(),expiresAt:Q().int().positive().optional(),maxUses:Q().int().positive().optional(),usedCount:Q().int().nonnegative(),peerOwnerId:j().min(1).optional(),firstUsedByPeerAt:Q().int().positive().optional(),peerDisplayName:j().optional()}).strict(),hce=dce.omit({secretHash:!0});z({type:he("whoami:ok"),owner:z({id:j(),kind:et(["owner","guest"]),displayName:j(),ownerId:j(),provider:j()}).strict(),capability:hce,grantedPersonas:xe(z({id:j().min(1),displayName:j()}).strict())}).strict();const fce="PEER_LOGIN_EXPIRED";z({selfUrl:j().min(1)});z({type:he("contact:handshake:ok"),owner:z({id:j(),ownerId:j(),provider:j(),displayName:j()}),grants:xe(O5)});const pce=Bs("status",[z({status:he("authorized"),login:j().min(1),source:et(["git","file"])}).strict(),z({status:he("missing")}).strict(),z({status:he("invalid"),message:j().min(1)}).strict(),z({status:he("pending"),authUrl:j().url()}).strict()]);z({token:j().min(1)}).strict();z({returnTo:j().url().optional()}).strict();const mce=z({url:j().url(),bin:j(),sha256:j().regex(/^[0-9a-f]{64}$/),size:Q().int().positive()}),gce={label:"Debian 13"},j7=["node","npm"],xce=["claude","codex","git","lark-cli","pi","pi-mcp-bridge","pi-cliproxyapi-provider","python3","jq","rsync","psql","go","chromium","fonts-wqy-microhei","openssh-server","pnpm","whiteboard-cli","s","supabase-mcp","mcp-server-kibana","aliyun"],vce=z({name:j().min(1),from:j().optional(),version:j().optional(),min:j().optional(),library:Re().optional(),localVersion:j().optional(),artifact:mce.optional(),aptMissing:he(!0).optional(),aptVersion:j().optional()}),D5=j().regex(/^[a-z0-9-]+$/,"连接器名只能是小写字母、数字和短横线"),E7=["proxy","env"],I7=["mcp","cli"],yce=["bearer","lark-sidecar"],T7=["none","shared","personal"],A5=["oauth","fields"],Iw=j().regex(/^[A-Z][A-Z0-9_]*$/,"要填的变量名只能是大写字母、数字和下划线,且以字母开头"),bce=z({name:j().min(1),env:xe(Iw).min(1)}),R7=z({name:D5,kind:et(E7),runner:et(I7),protocol:et(yce).optional(),id:j().min(1),credentialSource:et(T7).optional(),auth:et(A5).optional(),publisherUnionId:j().regex(/^on_[A-Za-z0-9_-]+$/).optional(),fields:xe(Iw).default([]),http:z({url:j().min(1),headers:Yi(j(),j())}).optional()}),M7=["LARKSUITE_CLI_APP_ID","LARKSUITE_CLI_APP_SECRET"];function $5(e){return e.name==="feishu"&&e.runner==="cli"&&e.kind==="env"&&e.credentialSource==="shared"}function wce(e){return e.name==="feishu"&&e.id==="feishu"&&e.runner==="cli"&&e.kind==="proxy"&&e.protocol==="lark-sidecar"&&e.credentialSource==="shared"&&e.auth==="oauth"&&e.fields.length===0}function P7(e){if(!e.credentialSource)return[`连接器 ${e.name} 还没选用谁的账号`];const t=[];return wce(e)?t:e.protocol==="lark-sidecar"&&e.credentialSource==="shared"?["连接器 feishu 的发布者 OAuth 配置不完整,请重新选择账号身份"]:$5(e)?M7.filter(n=>!e.fields.includes(n)).map(n=>`连接器 feishu 的 Lark App Bot 缺少 ${n==="LARKSUITE_CLI_APP_ID"?"App ID":"App Secret"}`):(e.credentialSource==="personal"&&(e.auth?e.auth==="oauth"&&e.kind==="env"?t.push(`连接器 ${e.name} 是进程型(stdio MCP / CLI),只能粘贴 API key,走不了 OAuth`):e.auth==="fields"&&e.fields.length===0&&t.push(`连接器 ${e.name} 要填的变量还没列`):t.push(`连接器 ${e.name} 还没选用户怎么关联账号`)),e.credentialSource==="shared"&&e.fields.length===0&&t.push(`连接器 ${e.name} 选了发布者的账号,但要填的变量还没列`),t)}const _ce=/^([A-Za-z0-9._/-]+)@([A-Za-z0-9._-]+)(?:\?tags=([A-Za-z0-9_,]+))?$/,Sce=["main","master","HEAD","latest"];function kce(e){const t=_ce.exec(e);return!!t&&!Sce.includes(t[2])}function O7(e){var n,r;return j7.includes(e.name)||xce.includes(e.name)?[]:(n=e.from)!=null&&n.startsWith("github:")&&!e.artifact?[`${e.name} 还没钉下载资产(github: 要具体到哪个文件)——重新扫描`]:(r=e.from)!=null&&r.startsWith("go:")&&!kce(e.from.slice(3))?[`${e.name} 还没钉版本(go: 要写成 <module>@<tag>,不收 latest / main 这类移动引用)——重新扫描`]:[]}function L5(e){return e.connectors.filter(t=>t.credentialSource==="shared"&&t.fields.length>0).map(t=>({name:t.name,env:[...t.fields]}))}function Cce(e){return[...new Set([...e.envVars.flatMap(t=>t.env),...L5(e).flatMap(t=>t.env)])]}function Nce(e){const t=new Set(e.connectors.flatMap(n=>n.fields));return[...new Set(e.envVars.flatMap(n=>n.env))].filter(n=>t.has(n)).map(n=>`${n} 同时是环境变量和连接器的字段,只能留一处——重新扫描`)}const jce=e=>{if(!e||typeof e!="object")return e;let t=e;if("clis"in t&&Array.isArray(t.clis)){const{clis:n,...r}=t;t="packages"in r?r:{...r,packages:n}}if("assets"in t&&Array.isArray(t.assets)&&t.assets.length===0){const{assets:n,...r}=t;t=r}if("secrets"in t&&Array.isArray(t.secrets)){const{secrets:n,...r}=t,s=new Set((Array.isArray(r.connectors)?r.connectors:[]).flatMap(o=>Array.isArray(o==null?void 0:o.fields)?o.fields:[])),i=n.map(o=>({...o,env:Array.isArray(o==null?void 0:o.env)?o.env.filter(l=>!s.has(l)):o==null?void 0:o.env})).filter(o=>!Array.isArray(o.env)||o.env.length>0);t={...r,envVars:[...Array.isArray(r.envVars)?r.envVars:[],...i]}}return t},Ece="Publisher test: ",D7=z({version:he(1),entry:j().max(240).regex(/^[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*\.mjs$/).refine(e=>!e.split("/").some(t=>[".",".."].includes(t))),timeoutSeconds:Q().int().min(1).max(600),checks:xe(j().regex(/^[a-z0-9][a-z0-9-]{0,63}$/)).min(1).max(64).refine(e=>new Set(e).size===e.length)}).strict(),A7={test:D7.optional(),packages:xe(vce),envVars:xe(bce).default([]),connectors:xe(R7).default([])};z(A7);const F5=nce(jce,z({version:he(1),...A7}).strict()),Ice=z({target:j().min(1),reason:j().min(1),file:j().min(1),quote:j().min(1)}),Tce=["integration","production"],Hs=et(Tce),xc=j().regex(/^[a-z0-9.-]+(?::[0-9]+)?\/[a-z0-9._/-]+@sha256:[a-f0-9]{64}$/),ij=j().regex(/^[a-f0-9]{40}$/),Rce=j().refine(e=>{try{const t=new URL(e);return t.protocol==="https:"&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname==="/"&&/(^|[.-])int([.-]|$)/.test(t.hostname)}catch{return!1}},"测试验证地址必须明确指向 int HTTPS 环境"),Mce=z({version:he(1),runId:j().regex(/^[A-Za-z0-9_-]{1,128}$/),status:he("passed"),exitCode:he(0),result:z({version:he(1),runId:j().regex(/^[A-Za-z0-9_-]{1,128}$/),checks:xe(z({name:j().regex(/^[a-z0-9][a-z0-9-]{0,63}$/),status:he("passed"),reason:j().max(1024).optional()}).strict()).min(1).max(64)}).strict(),execution:z({image:xc,imageID:j().min(1).max(512),engine:et(["codex","pi"]),podUid:j().min(1).max(512),jobUid:j().min(1).max(512)}).strict()}).strict(),$7=z({status:he("passed"),fingerprint:j().regex(/^[a-f0-9]{64}$/),checks:xe(j().regex(/^[a-z0-9-]+$/)),endpoint:Rce,verifiedAt:j().refine(e=>Number.isFinite(Date.parse(e))),test:Mce.optional()}).strict(),L7=z({engine:j().min(1),model:j(),effort:j(),size:j().min(1),cpu:Q().positive(),taskConcurrency:Q().int().positive(),minPods:Q().int().nonnegative().safe().optional()}).strict(),F7=z({version:he(1),environment:he("integration"),component:he("persona"),image:xc,commit:ij,baseImage:xc,pipelineCommit:ij,repository:j().regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/),config:L7.optional(),verification:$7.refine(e=>e.checks.includes("persona-smoke")),test:D7.optional()}).strict().refine(e=>{if(!e.test)return e.verification.test===void 0;const t=e.verification.test;return["persona-dialogue","persona-task","persona-custom-test"].every(n=>e.verification.checks.includes(n))&&t!==void 0&&t.execution.image===e.image&&t.runId===t.result.runId&&t.result.checks.length===e.test.checks.length&&new Set(t.result.checks.map(n=>n.name)).size===e.test.checks.length&&t.result.checks.every(n=>e.test.checks.includes(n.name))},"Declared publisher acceptance requires complete candidate runtime evidence");z({version:he(1),environment:he("integration"),component:he("base"),image:xc,commit:ij,verification:$7.refine(e=>e.checks.includes("base-smoke"))}).strict();const kg="-cloud",B5=`codex${kg}`,Cg={standard:"default",fast:"priority"},Pce=`claude${kg}`;function B7(e){return e==="codex"||e===B5}const z7="pi",Oce=`${z7}${kg}`;function H7(e){return e===z7||e===Oce}function mu(e){return typeof e=="string"&&e.length>kg.length&&e.endsWith(kg)}const U7=et([Cg.standard,Cg.fast]),z5=["tiny","small","medium","large","xlarge"],Dce=et(z5),zb="medium",Hb=[.5,1,2],Ace=Q().refine(e=>Hb.includes(e),"Unsupported CPU"),oj={tiny:.5,small:1,medium:2,large:2,xlarge:2},W7=z({model:j().optional(),effort:j().optional()}).strict(),Mm=z({personaId:j(),label:j(),model:j().optional(),effort:j().optional(),serviceTier:U7.optional(),public:Re(),iconKey:j().optional(),tool:j().optional(),size:j().optional(),cpu:Q().finite().optional(),taskConcurrency:Q().int().positive().optional(),minPods:Q().int().nonnegative().safe().optional(),cloudEngine:W7.optional(),createdAt:Q(),updatedAt:Q(),cloud:z({gatewayUrl:j().min(1),personaId:j().min(1),publishedByMe:Re().optional(),label:j().optional(),environment:Hs.optional(),expectedImage:xc.optional(),testReleaseId:j().optional()}).strict().optional()}).strict(),$ce=z({name:j().min(1),description:j().optional()}),Lce=z({id:j().min(1)}),V7=z({writableRoots:xe(j()).optional(),denyRead:xe(j()).optional(),network:Re().optional()}).strict(),Fce=z({permissions:z({defaultMode:j().optional(),allow:xe(j()).optional(),deny:xe(j()).optional()}).optional(),sandbox:z({enabled:Re().optional(),autoAllowBashIfSandboxed:Re().optional(),allowUnsandboxedCommands:Re().optional(),excludedCommands:xe(j()).optional(),filesystem:z({denyRead:xe(j()).optional(),allowRead:xe(j()).optional(),denyWrite:xe(j()).optional(),allowWrite:xe(j()).optional()}).optional(),network:z({allowedDomains:xe(j()).optional(),allowLocalBinding:Re().optional()}).optional()}).optional()});Mm.extend({personality:j().optional(),personalityLocal:j().optional(),personalityManaged:Re().optional(),skills:xe($ce).optional(),plugins:xe(Lce).optional(),sandboxSettings:Fce.nullable().optional(),codexSandbox:V7.nullable().optional()});z({slug:j().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/).max(32),label:j().min(1),personality:j(),model:j().optional(),effort:j().optional(),serviceTier:Mm.shape.serviceTier,tool:j().optional(),public:Re().optional(),iconKey:j().optional()}).strict();z({personaId:j().min(1)});z({personaId:j().min(1),patch:z({label:j().min(1).optional(),model:j().optional(),effort:j().optional(),serviceTier:Mm.shape.serviceTier,tool:j().optional(),size:Dce.optional(),cpu:Ace.optional(),taskConcurrency:Mm.shape.taskConcurrency,minPods:Mm.shape.minPods,cloudEngine:W7.optional(),personality:j().optional(),personalityLocal:j().optional(),public:Re().optional(),iconKey:j().nullable().optional(),codexSandbox:V7.optional()}).strict()}).strict();z({version:he(1),manifest:F5}).strict();const Bce=["hard","soft"],q7=et(Bce),zce=et(["scanning","done","failed"]),K7=z({id:j().min(1),manifest:F5,scanSessionId:j().optional(),status:zce,evidence:xe(Ice).default([]),notes:xe(j()).default([]),head:j().min(1).optional(),baseKind:q7.default("hard"),base:j().min(1).optional(),startedAt:Q(),finishedAt:Q().optional(),error:j().optional()}).strict(),H5=z({id:j().min(1).optional(),environment:Hs.optional(),legacy:Re().optional(),head:j().min(1),contentHead:j().min(1),scanId:j().min(1),at:Q(),pushed:Re().optional(),runId:Q().int().positive().optional(),runAttempt:Q().int().positive().optional(),artifactId:Q().int().positive().optional(),verified:F7.optional(),config:L7.optional(),reconfigOf:j().min(1).optional(),workflowVersion:Q().int().positive().optional(),confirmation:z({fingerprint:j().regex(/^[a-f0-9]{64}$/),runId:Q().int().positive(),runAttempt:Q().int().positive(),at:Q()}).strict().optional()}).strict(),Hce=["prepared","main-pushed","dispatching","dispatched","completed","failed"],U5=z({id:j().min(1),releaseId:j().min(1),at:Q(),verified:F7.optional(),phase:et(Hce),expectedMain:j().optional(),runId:Q().int().positive().optional(),runAttempt:Q().int().positive().optional(),error:j().optional()}).strict(),vO=z({channelId:j().min(1),updatedAt:Q()}).strict(),W5=z({integration:vO.nullable().optional(),production:vO.nullable().optional()}).strict();z({version:he(4),engineChannels:W5.optional(),scans:xe(K7),releases:xe(H5),promotions:xe(U5).default([])}).strict();const Uce=z({url:j().min(1),branch:j().min(1),head:j().min(1),dirty:Re(),ahead:Q()}).strict(),ky=z({env:j().min(1),setAt:Q().optional()}).strict(),yO={baseUrl:"CLAWD_ENGINE_BASE_URL",apiKey:"CLAWD_ENGINE_API_KEY"},Wce="模型订阅只写进去一半——重填或改回平台默认";function Ub(e){if(!e)return;const t=r=>e.some(s=>s.env===r&&s.setAt!==void 0),n=[yO.baseUrl,yO.apiKey].filter(t).length;return n===2?"own":n===0?"platform":"partial"}function Vce(e){const t=e.trim();let n;try{n=new URL(t)}catch{throw new Error("订阅地址要以 http:// 或 https:// 开头,形如 https://cpa.example.com")}if(n.protocol!=="http:"&&n.protocol!=="https:"||!n.hostname)throw new Error("订阅地址要以 http:// 或 https:// 开头,形如 https://cpa.example.com");const r=`${n.origin}${n.pathname}`.replace(/\/+$/,"");return r.endsWith("/v1")?r:`${r}/v1`}const qce=["pending","running","done","failed","waiting","skipped"],Kce=et(qce),go="verify",Pm=["build","smoke","deploy",go],Gce=et(Pm),Yce=z({key:Gce,status:Kce,url:j().optional(),jobId:Q().optional(),startedAt:Q().optional(),completedAt:Q().optional(),cliWarnings:xe(j()).optional()}).strict(),Cy=z({runId:Q(),headSha:j().min(1),status:et(["queued","running","completed"]),htmlUrl:j().min(1),jobs:xe(Yce),environment:Hs.optional(),branch:j().optional(),event:j().optional(),runAttempt:Q().int().positive().optional(),conclusion:et(["success","failure"]).optional(),promotionId:j().optional()}).strict();function G7(e,t){return t&&e.head===t.head?t.contentHead:e.head}function Tw(e,t,n){return!e||!t||e.status!=="done"?!1:e.head===G7(t,n)&&!t.dirty}function V5(e,t,n){return!e||!t||e.status!=="done"||!e.head?!1:e.head!==G7(t,n)}function bO(e,t,n){return Tw(e,t,n)||V5(e,t,n)}function Xce(e,t){return!t||!e.head?!1:t.contentHead===e.head||t.at>=e.startedAt}const Y7=["codex","pi","claude"];function hl(e){return Y7.includes(e||"claude")}const X7={codex:"0.163.0",pi:"1.3.0",claude:"0.3.304"},Zce="2.1.304";function Qce(e,t){if(!e||!hl(e)||!t)return null;const n=e==="claude"?Zce:X7[e];return n===t?null:{tool:e,cloud:n,local:t}}function Z7(e){const t=e.tool||"claude",n=t==="claude"?e.cloudEngine??{}:e;return{tool:t,model:n.model??"",effort:n.effort??""}}const Nk=z({runId:Q(),status:Cy.shape.status,conclusion:et(["success","failure"]).optional(),htmlUrl:j().min(1)}).strict(),Jce=z({desired:Q().int().nonnegative().safe(),ready:Q().int().nonnegative().safe(),bound:Q().int().nonnegative().safe(),starting:Q().int().nonnegative().safe(),retiring:Q().int().nonnegative().safe(),observedAt:Q(),error:j().nullable()}).strict(),wO=z({online:Re().optional(),image:xc.optional(),minPods:Q().int().nonnegative().safe().optional(),reservation:Jce.nullable().optional(),reservationError:j().optional()}).strict(),Q7=z({personaId:j().min(1),engineChannels:W5.optional(),github:pce.optional(),publisherFeishuAuth:z({integration:z({connected:Re(),authUrl:j().optional(),error:j().optional()}).strict(),production:z({connected:Re(),authUrl:j().optional(),error:j().optional()}).strict()}).strict().optional(),repo:Uce.optional(),scans:xe(K7).default([]),releases:xe(H5).default([]),promotions:xe(U5).optional(),targets:z({integration:wO.extend({run:Cy.optional(),secrets:xe(ky).optional(),unpublish:Nk.optional()}).optional(),production:wO.extend({run:Cy.optional(),secrets:xe(ky).optional(),unpublish:Nk.optional()}).optional()}).strict().optional(),secrets:xe(ky).optional(),run:Cy.optional(),online:Re().optional(),unpublish:Nk.optional(),historyError:j().optional()}).strict();z({before:Q().nullable()}).strict();Q7.pick({personaId:!0,github:!0,repo:!0,scans:!0,releases:!0,promotions:!0,engineChannels:!0,historyError:!0});Q7.pick({scans:!0});z({environment:Hs,secrets:xe(ky).optional(),engineChannels:W5.optional()}).strict();const eue=e=>e.includes("minPods")?3:2,Ng=1,tue=["engine","model","effort","size","cpu","taskConcurrency","minPods"];function nue(e){const{tool:t,model:n,effort:r}=Z7(e),s=(e.size??"").trim()||zb,i=e.cpu??oj[s]??oj[zb];return{engine:t,model:n.trim(),effort:r.trim(),size:s,cpu:i,taskConcurrency:e.taskConcurrency??Ng,minPods:e.minPods??0}}function J7(e,t){return!e||!t?null:tue.filter(n=>n==="minPods"?(e.minPods??0)!==(t.minPods??0):e[n]!==t[n])}z({sha:j().min(1),actionsUrl:j().min(1),releaseId:j().optional()}).strict();const fx=z({personaId:j().min(1)}).strict();fx.extend({releaseHead:j().min(1).optional(),releaseId:j().min(1).optional(),environment:Hs.optional()}).strict();fx.extend({scanBase:q7.optional()}).strict();fx.extend({scanId:j().min(1)}).strict();fx.extend({releaseId:j().min(1)}).strict();fx.extend({environment:Hs.default("production")}).strict();z({confirmation:H5.shape.confirmation.unwrap()}).strict();z({promotion:U5}).strict();z({personaId:j().min(1),expectedImage:xc}).strict();z({personaId:j().min(1),scanId:j().min(1),patch:z({manifest:F5.optional(),connector:R7.optional()}).strict()}).strict();z({personaId:j().min(1),environment:Hs.default("production"),scanId:j().min(1),name:j().min(1),values:Yi(j(),j())}).strict();z({personaId:j().min(1),environment:Hs.default("production"),channelId:j().min(1).optional(),auth:z({baseUrl:j(),apiKey:j()}).strict().nullable().optional()}).strict().refine(e=>e.channelId!==void 0||e.auth!==void 0,{message:"Either channelId or auth must be provided"});z({personaId:j().min(1),environment:Hs.default("production"),releaseId:j().optional(),jobId:Q()}).strict();const rue="底座已更新,重试仍会用旧底座构建——请重新发布测试环境";z({personaId:j().min(1),kind:et(["package","env","connector"]),item:Yi(j(),Xa()),evidence:z({reason:j().min(1),file:j().min(1),quote:j().min(1)})}).strict();z({personaId:j().min(1),notes:xe(j()).default([])}).strict();const eH="ottin4ttc";function Uh(e){return e.trim().replace(/^git@[^:]+:/,"").replace(/^https?:\/\/[^/]+\//,"").replace(/\.git$/,"")}z({environment:Hs.default("production")}).strict();const sue="LOGIN_EXPIRED",iue=z({deviceId:j().min(1),name:j().min(1),url:j().min(1)});z({type:he("device:list:ok"),devices:xe(iue)});z({deviceId:j().min(1),url:j().min(1).optional(),name:j().optional()});z({type:he("device:connect:ok"),deviceId:j(),name:j(),url:j()});const tH=z({ownerId:j().min(1),provider:j().min(1),displayName:j().min(1),avatarUrl:j().optional(),unionId:j().optional()});z({type:he("auth:login:start:ok"),environment:Hs.optional(),authUrl:j().min(1),state:j().min(1)});z({type:he("auth:getIdentity:ok"),identity:tH.nullable(),deviceId:j().min(1)});z({type:he("auth:logout:ok")});const nH=j().nullable();z({type:he("auth:apiKey:get:ok"),apiKey:j().nullable(),createdAt:j().nullable(),gatewayUrl:nH});z({type:he("auth:apiKey:regenerate:ok"),apiKey:j().min(1),createdAt:j().min(1),gatewayUrl:nH});z({type:he("auth:apiKey:revoke:ok"),revoked:Re()});z({type:he("auth:login:done"),environment:Hs.optional(),identity:tH});z({type:he("auth:login:failed"),environment:Hs.optional(),reason:j()});z({deviceId:j().min(1),remoteAccessAllowed:Re()}).strict();z({type:he("contact:setRemoteAccess:ok"),deviceId:j().min(1),remoteAccessAllowed:Re()}).strict();z({type:he("contact:remote-access-updated"),deviceId:j().min(1),remoteAccessAllowed:Re()}).strict();z({personaId:j().min(1)}).strict();const oue=["connected","missing","reauth"],aue=["link","fill"],lue=z({name:D5,id:j().min(1),kind:et(E7),runner:et(I7),auth:et(A5),status:et(oue),action:et(aue),authUrl:j().optional(),fields:xe(Iw)}).strict();z({connectors:xe(lue)}).strict();z({personaId:j().min(1),name:D5,values:Yi(Iw,j().min(1))}).strict();const cue=z({deviceId:j().min(1),ownerId:j().min(1),provider:j().min(1),displayName:j(),remoteUrl:j().min(1),connectToken:j(),grants:xe(O5),addedAt:Q().int().nonnegative(),pinnedAt:Q().int().nullable().default(null),remoteAccessAllowed:Re().default(!1),note:j().default("")}).strict(),rH=cue;z({deviceId:j().min(1)}).strict();z({type:he("contact:remove:ok"),deviceId:j().min(1)}).strict();z({type:he("contact:list:ok"),contacts:xe(rH)}).strict();z({type:he("contact:added"),contact:rH}).strict();z({type:he("contact:removed"),deviceId:j().min(1)}).strict();z({deviceId:j().min(1),pinned:Re()}).strict();z({deviceId:j().min(1),note:j()}).strict();z({type:he("contact:setNote:ok"),deviceId:j().min(1),note:j()}).strict();z({type:he("contact:pin:ok"),deviceId:j().min(1),pinnedAt:Q().int().nullable()}).strict();z({type:he("contact:pinned"),deviceId:j().min(1),pinnedAt:Q().int().nullable()}).strict();const q5=Bs("kind",[z({kind:he("success"),text:j(),brief:j().optional(),filePaths:xe(j()).optional()}),z({kind:he("failure"),reason:j(),brief:j().optional()})]);z({targetPersona:j().min(1).optional(),dispatchId:j().min(1).optional(),prompt:j(),brief:j().optional(),targetDeviceId:j().min(1).optional(),model:j().min(1).optional(),tool:j().min(1).optional(),sessionLabel:j().min(1).max(60).optional(),meta:Yi(Xa()).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:"follow-ups take only dispatchId; the target device comes from the ledger row (dispatchId + targetDeviceId are mutually exclusive)"}).refine(e=>!(e.tool!==void 0&&e.targetDeviceId!==void 0),{message:"engine override is not supported for cross-device dispatch (tool + targetDeviceId are mutually exclusive)"}).refine(e=>!(e.dispatchId!==void 0&&(e.tool!==void 0||e.model!==void 0)),{message:"a follow-up dispatch cannot change engine or model (dispatchId excludes tool / model); start a new dispatch instead"});z({dispatchId:j().min(1),outcome:q5});const uue=["running","completed","failed"],K5=et(uue),due=z({dispatchId:j().min(1),sourceSessionId:j().min(1),sourcePersonaId:j().min(1).optional(),targetPersonaId:j().min(1),targetDeviceId:j().min(1).optional(),remoteDispatchId:j().min(1).optional(),remoteRound:Q().int().positive().optional(),workerSessionId:j().min(1).optional(),taskText:j(),taskBrief:j().optional(),round:Q().int().positive().optional(),status:K5,outcome:q5.optional(),meta:Yi(Xa()).optional(),createdAt:j().min(1),completedAt:j().min(1).optional(),deliveredAt:j().min(1).optional()});z({sourceSessionId:j().min(1).optional(),relatedSessionId:j().min(1).optional()});z({records:xe(due)});z({dispatchId:j().min(1)});z({type:he("personaDispatch:get:ok"),status:K5,outcome:q5.optional()});const hue=/^[a-z0-9][a-z0-9-]*$/;et(["stopped","starting","running","crashed","invalid"]);const fue=new Set(["localhost","127.0.0.1"]);function pue(e){let t;try{t=new URL(e)}catch{return!1}return!!(t.protocol==="https:"||t.protocol==="http:"&&fue.has(t.hostname))}const a0=z({id:j().regex(hue),name:j().min(1),version:j().min(1),apiVersion:he("1"),runtime:z({startCommand:j().min(1)}).passthrough().optional(),entry:z({url:j().url().refine(pue,{message:"INVALID_URL_SCHEME: only https or http://localhost is allowed"})}).strict().optional()}).passthrough().superRefine((e,t)=>{var s;const n=!!e.runtime,r=!!((s=e.entry)!=null&&s.url);n&&r&&t.addIssue({code:ke.custom,message:"INVALID_MANIFEST: entry.url and runtime cannot coexist"}),!n&&!r&&t.addIssue({code:ke.custom,message:"INVALID_MANIFEST: must have either entry.url or runtime"})}),mue=Bs("kind",[z({kind:he("local"),port:Q().int().min(1).max(65535)}),z({kind:he("hosted"),url:j().url()})]);Bs("state",[z({extId:j(),manifest:a0,state:he("stopped")}),z({extId:j(),manifest:a0,state:he("starting")}),z({extId:j(),manifest:a0,state:he("running"),target:mue}),z({extId:j(),manifest:a0,state:he("crashed")}),z({extId:j(),manifest:Xa().nullable(),state:he("invalid"),invalidReason:j().min(1)})]);z({snapshotHash:j().min(1),version:j().min(1),publishedAt:Q()});const gue=Bs("kind",[z({kind:he("p2p-tunnel"),ownerPrincipalId:j().min(1),extId:j().min(1)})]);Bs("kind",[z({kind:he("p2p-tunnel"),ownerPrincipalId:j().min(1),extId:j().min(1),snapshotHash:j().min(1)})]);z({extId:j().min(1),name:j().min(1),version:j().min(1),contentHash:j().min(1),publishedAt:Q()});const xue=Bs("kind",[z({kind:he("clean")}),z({kind:he("ready-new-version"),fromVersion:j().min(1),toVersion:j().min(1)}),z({kind:he("error-same-hash"),version:j().min(1)}),z({kind:he("error-version-not-bumped"),localVersion:j().min(1),publishedVersion:j().min(1)}),z({kind:he("error-version-regression"),localVersion:j().min(1),publishedVersion:j().min(1)})]);function vue(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return(t>>>0).toString(16).padStart(8,"0")}function G5(e,t){return`${e}-${vue(t)}`}function Y5(e){if(typeof e!="string")return{ok:!1,reason:"version must be a string"};const t=e.split(".");if(t.length!==3)return{ok:!1,reason:`"${e}" — only MAJOR.MINOR.PATCH allowed`};for(const n of t)if(!/^\d+$/.test(n))return{ok:!1,reason:`"${e}" — only numeric segments allowed`};return{ok:!0}}function sH(e,t){const n=_O(e),r=_O(t);for(let s=0;s<3;s++){if(n[s]<r[s])return-1;if(n[s]>r[s])return 1}return 0}function _O(e){const t=Y5(e);if(!t.ok)throw new Error(t.reason);const[n,r,s]=e.split(".").map(i=>parseInt(i,10));return[n,r,s]}z({localManifest:z({name:j().min(1),version:j().min(1),contentHash:j().min(1)}),publishState:Bs("kind",[z({kind:he("unpublished")}),z({kind:he("published"),version:j().min(1),contentHash:j().min(1),publishedAt:Q()})]),check:xue});z({extId:j().min(1),newVersion:j().min(1).nullish()});z({extId:j().min(1)});z({extId:j().min(1),snapshotHash:j().min(1)});z({channelRef:gue,snapshotHash:j().min(1),zipBase64:j().min(1)});z({id:j().min(1),peerDeviceId:j().min(1),senderDeviceId:j().min(1),text:j().min(1),createdAt:Q().int().nonnegative(),readBy:Yi(j().min(1),Q().int().positive()).default({}),origin:z({kind:he("persona"),personaId:j().min(1)}).optional()}).strict();z({peerDeviceId:j().min(1).optional(),id:j().min(1),text:j().min(1),createdAt:Q().int().nonnegative(),origin:z({kind:he("persona"),personaId:j().min(1)}).optional()}).strict();z({peerDeviceId:j().min(1),sinceCreatedAt:Q().int().nonnegative().optional()}).strict();z({peerDeviceId:j().min(1),upToCreatedAt:Q().int().nonnegative()}).strict();z({peerDeviceId:j().min(1).optional(),text:j().min(1)});z({peerDeviceId:j().min(1).optional(),command:j().min(1),timeoutMs:Q().int().positive().optional()}).strict();z({type:he("peerExec:run:ok"),stdout:j(),stderr:j(),exitCode:Q().int().nullable(),timedOut:Re(),stdoutTruncated:Re(),stderrTruncated:Re()}).strict();const iH=Bs("kind",[z({kind:he("at"),at:j().min(1)}),z({kind:he("every"),everyMs:Q().int().positive(),anchorMs:Q().int().nonnegative().optional()}),z({kind:he("cron"),expr:j().min(1),tz:j().min(1).optional()})]),px=j().trim().min(1);z({personaId:px,name:j().min(1),schedule:iH,prompt:j().min(1),targetPersona:j().min(1).optional(),timeoutMs:Q().int().positive().optional()});z({personaId:px,onlyMine:Re().optional()});z({personaId:px,shiftId:j().min(1)});const yue=z({name:j().min(1).optional(),schedule:iH.optional(),prompt:j().min(1).optional(),targetPersona:j().min(1).optional(),timeoutMs:Q().int().positive().optional(),enabled:Re().optional()});z({personaId:px,shiftId:j().min(1),patch:yue});z({personaId:px,shiftId:j().min(1),limit:Q().int().positive().optional()});const Fi="persona-master",X5=z({personaId:j().min(1),deviceId:j().min(1).optional()}),oH=z({id:j().min(1),name:j().min(1),memberPersonas:xe(X5),memberContactDeviceIds:xe(j().min(1)),createdAt:j().min(1),updatedAt:j().min(1)}),aH=j().trim().min(1);z({name:aH,memberPersonas:xe(X5).default([]),memberContactDeviceIds:xe(j().min(1)).default([])});z({channelId:j().min(1),name:aH.optional(),memberPersonas:xe(X5).optional(),memberContactDeviceIds:xe(j().min(1)).optional()});z({channelId:j().min(1)});z({channels:xe(oH)});z({channel:oH});z({ok:he(!0),removedTopics:Q().int().min(0)});const ur=j().trim().min(1),Z5=["master-confirmed","owner-needed"],Q5=["open","resolved"],bue=Z5[0],lH=Z5[1],cH=Q5[0],wue=Q5[1],_ue=et(Z5),Sue=et(Q5),kue=z({id:ur.optional(),resolves:ur.optional(),type:_ue,status:Sue,question:ur,recommendation:ur}).superRefine((e,t)=>{e.type===bue&&e.status!==wue&&t.addIssue({code:ke.custom,path:["status"],message:"master-confirmed decisions must be resolved"})}),Cue=["planning","running","done"],Nue=et(Cue),uH=z({at:j().min(1),actor:j().min(1),action:j().min(1),target:j().optional(),reason:j().min(1),artifacts:xe(ur).optional(),decision:kue.optional()}),jue=z({rejectCount:Q().int().min(0),accepted:Re().default(!1),ordinal:Q().int().min(1).optional(),overrideCount:Q().int().min(0).optional()}),J5=z({id:j().min(1),channelId:j().min(1),title:j(),masterSessionId:j().min(1),goal:j(),boundaries:j(),acceptanceCriteria:xe(j()),activity:xe(uH),lineMeta:Yi(jue),nextLineOrdinal:Q().int().min(1).optional(),state:Nue,createdAt:j().min(1),updatedAt:j().min(1)}),Eue=z({lineId:j().min(1),dispatchId:j().min(1),workerSessionId:j().optional(),assignee:j().min(1),focus:j(),status:K5,acceptance:xe(j()),rejectCount:Q().int().min(0),accepted:Re(),ordinal:Q().int().min(1).nullable()});z({channelId:j().min(1)});z({topicId:j().min(1).optional(),sessionId:j().min(1).optional()}).refine(e=>e.topicId!==void 0||e.sessionId!==void 0,{message:"either topicId or sessionId is required"});z({channelId:j().min(1),title:ur.optional()});z({topicId:j().min(1),title:ur.optional(),goal:ur,boundaries:j(),acceptanceCriteria:xe(ur).min(1)});z({topicId:j().min(1),action:ur,target:ur.optional(),reason:ur,artifacts:xe(ur).optional(),decision:uH.shape.decision});z({topicId:j().min(1),lineId:ur,reason:ur});z({topicId:j().min(1),lineId:ur,reason:ur,artifacts:xe(ur).optional(),watcherVerdict:et(["pass","fail"]),overrideReason:ur.optional()}).refine(e=>e.watcherVerdict!=="fail"||!!e.overrideReason,{message:"watcherVerdict=fail 时必须给 overrideReason(推翻 watcher 的理由)",path:["overrideReason"]});z({topicId:j().min(1),state:et(["done"])});z({topicId:j().min(1),title:ur});z({topicId:j().min(1)});const Iue=J5.extend({lineCount:Q().int().min(0)});z({topics:xe(Iue)});z({topic:J5,lines:xe(Eue)});z({topicId:j().min(1),masterSessionId:j().min(1)});z({rejectCount:Q().int().min(1),needsOwnerAttention:Re()});z({acceptedLines:Q().int().min(1),totalLines:Q().int().min(1),allAccepted:Re(),overrides:Q().int().min(0),needsOwnerAttention:Re()});z({topic:J5});z({ok:he(!0),removedMasterSessionId:j().min(1).nullable(),removedWorkerSessionIds:xe(j().min(1))});const Tue=["ask","allow","deny"],dH=et(Tue),Rue=z({id:j().min(1),desc:j().min(1),action:dH});z({rules:xe(Rue)});z({ruleId:j().min(1)});z({action:dH,desc:j(),source:j().min(1)});const Mue=["created","review-requested"],hH=/^[A-Za-z0-9._-]+$/,Ef=j().min(1).regex(hH),If=j().min(1).regex(hH),mx=Q().int().positive();z({role:et(Mue)});z({owner:Ef,repo:If,number:mx});z({owner:Ef,repo:If,number:mx,expectedHeadSha:j().min(1)});z({owner:Ef,repo:If,number:mx,body:j().min(1)});z({owner:Ef,repo:If,number:mx,ready:Re()});z({owner:Ef,repo:If});z({owner:Ef,repo:If,number:mx,reviewers:xe(j().min(1)).min(1)});z({page:Q().int().min(1).max(1e3).optional(),search:j().max(100).optional()});z({personaId:j().min(1)});z({personaId:j().min(1)});const Pue=["expired","cancelled","access_denied","lark_protocol_error","cloud_unreachable","internal_error"],Oue=et(Pue);z({personaId:j().min(1),appId:j().min(1),appSecret:j().min(1),botName:j().min(1).optional()});const Due=z({chatId:j().min(1),chatName:j().optional(),lastActiveAt:Q().int().optional()}),Aue=z({state:et(["unbound","provisioning","bound","broken"]),appId:j().optional(),botName:j().optional(),brokenReason:j().optional(),qrUrl:j().optional(),provisionId:j().optional(),errorReason:Oue.optional(),groups:xe(Due),needsUpgrade:Re().optional(),upgradeQrUrl:j().optional()});Aue.extend({personaId:j().min(1)});z({});z({onboardingCompletedAt:Q()});const Wh=["claude","codex","pi"];z({});z({tools:xe(z({id:et(Wh),available:Re(),version:j().optional(),path:j().optional()}))});z({});const $ue=z({tool:et(Wh),cwd:j(),toolSessionId:j(),label:j().optional(),createdAt:j(),updatedAt:j(),turns:Q()});z({candidates:xe($ue)});z({});z({registered:Re()});z({tool:et(Wh)});const SO=z({usedPercent:Q(),windowDurationMins:Q().optional(),resetsAt:Q().optional()}).strict(),Lue=Bs("kind",[z({kind:he("claude"),loggedIn:Re(),authMethod:j().optional(),apiProvider:j().optional(),apiKeySource:j().optional(),email:j().optional(),orgName:j().optional(),subscriptionType:j().optional()}).strict(),z({kind:he("codex"),login:Bs("type",[z({type:he("none")}).strict(),z({type:he("apiKey")}).strict(),z({type:he("chatgpt"),email:j(),planType:j()}).strict()]),provider:z({name:j(),baseUrl:j().optional()}).strict(),rateLimits:z({primary:SO.optional(),secondary:SO.optional()}).strict().optional()}).strict(),z({kind:he("pi"),providers:xe(z({id:j(),modelCount:Q(),credential:et(["api_key","oauth"]).optional(),oauthExpiresAt:Q().optional()}).strict())}).strict()]);z({tool:et(Wh),installed:Re(),version:j().optional(),path:j().optional(),account:Lue.optional(),error:j().optional(),modelsLoadedAt:Q().optional()}).strict();const eT="https://cpa-portal-d417.app.clawos.chat";z({apiKey:j().min(1)}).strict();z({ok:he(!0)}).strict();const fH=["cloud-persona-metrics","cloud-persona-conversations"],Fue=et(fH);z({page:Fue}).strict();z({url:j(),expiresAt:Q().int()}).strict();const pH=["ready","session:info","session:status","session:event","session:deleted","session:rewound","session:cleared","session:queue","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","contact:note-updated","org-mesh:progress","channel:changed","inbox:event","friend:reverseTokenOffered","auth:login:done","auth:login:failed","larkBot:state"],Bue="cloud_history_refresh",tT=["idle","running","running-idle","stopped","error","observing"],zue=["task-notification","slash-command","local-command","system-reminder","skill-hint","meta-text","attachment-skills","attachment-deferred-tools","dispatch-task","dispatch-result"];function Rw(e){return e==="dispatch-task"||e==="dispatch-result"}const Hue=["builtin","global","project","plugin"],Uue=["builtin","global","project","policy","plugin"],mH=et(["owner","guest"]);z({id:j().min(1),kind:mH,displayName:j(),feishuUnionId:j().optional()}).strict();const Wue=z({did:j().min(1),displayName:j(),feishuUnionId:j().optional(),principal:mH}).strict(),Vue=et(tT),que=z({inputTokens:Q().int().nonnegative(),outputTokens:Q().int().nonnegative(),cacheReadTokens:Q().int().nonnegative().optional(),cacheCreateTokens:Q().int().nonnegative().optional()}),gH={gitBranch:j().optional(),resolvedModel:j().optional(),resolvedEffort:j().optional(),contextUsage:que.optional(),contextWindowSize:Q().int().positive().optional(),aiLabel:j().optional()},Kue=z(gH),xH=z({value:j(),label:j(),description:j().optional()}),Gue=z({id:j().min(1),label:j().min(1),description:j().optional(),contextWindowSize:Q().int().positive().optional(),default:Re().optional(),efforts:xe(xH).optional(),defaultEffort:j().optional(),group:j().optional()}),Yue=z({id:j().min(1),label:j().min(1),description:j().optional()}),Xue=z({name:j().min(1),type:et(["string","select","toggle"]),label:j().min(1),description:j().optional(),options:xe(xH).optional(),default:Xa().optional(),scope:et(["core","tool-specific"])});z({tool:j().min(1),refresh:Re().optional()});const Zue=z({rewind:Re(),subagents:Re(),tui:Re(),observe:Re(),fileSharing:Re(),fork:Re()});z({tool:j().min(1),toolSessionIdLabel:j().optional(),models:xe(Gue),permissionModes:xe(Yue),configSchema:xe(Xue),features:Zue});const Que=z({tool:j().min(1),pattern:j().min(1),createdAt:j().min(1).optional()});z({cloudEnvironment:Hs.optional(),cloudExpectedImage:xc.optional(),testReleaseId:j().optional(),sessionId:j().min(1),cloudExecutionId:j().min(1).optional(),cloudConversationId:j().min(1).optional(),cloudWorkspace:Ew.optional(),cloudPendingTurns:xe(z({id:j().min(1),text:j(),prepared:Re().optional()})).optional(),cloudBranchIntent:Sg.optional(),cloudGatewaySessionId:j().min(1).optional(),cloudPendingCommand:z({id:j().min(1),text:j(),prepared:Re().optional()}).optional(),cwd:j().min(1),tool:he("claude").or(j().min(1)).default("claude"),toolSessionId:j().optional(),label:j().optional(),model:j().optional(),permissionMode:j().optional(),effort:j().optional(),serviceTier:j().optional(),...gH,aiLabelGeneratedAt:j().optional(),permissionRules:xe(Que).optional(),pinnedAt:Q().int().nonnegative().nullable().optional(),archivedAt:Q().int().nonnegative().nullable().optional(),pinSortOrder:Q().int().nullable().optional(),unreadAt:j().min(1).nullable().optional(),iconKey:j().optional(),forkedFromSessionId:j().min(1).optional(),ephemeral:Re().optional(),deployId:j().min(1).optional(),ownerPersonaId:j().min(1).optional(),projectPath:j().min(1).optional(),chatId:j().min(1).optional(),creatorPrincipalId:j().min(1).optional(),creatorDisplayName:j().min(1).optional(),creatorFeishuUnionId:j().min(1).optional(),originOwnerPrincipalId:j().min(1).optional(),originOwnerPersonaId:j().min(1).optional(),dispatchedFromSessionId:j().min(1).optional(),shiftFiredFromSessionId:j().min(1).optional(),larkChatId:j().min(1).optional(),larkChatName:j().min(1).optional(),larkChatType:et(["p2p","group"]).optional(),createdAt:j().min(1),updatedAt:j().min(1)});const js={turnId:j().min(1).optional(),seq:Q().int().nonnegative().optional(),ts:j().optional(),uuid:j().optional()},Jue=et(zue),ede=z({readCount:Q().int().nonnegative().optional(),searchCount:Q().int().nonnegative().optional(),bashCount:Q().int().nonnegative().optional(),editFileCount:Q().int().nonnegative().optional(),linesAdded:Q().int().nonnegative().optional(),linesRemoved:Q().int().nonnegative().optional(),otherToolCount:Q().int().nonnegative().optional()}),tde=z({oldStart:Q().int().nonnegative(),oldLines:Q().int().nonnegative(),newStart:Q().int().nonnegative(),newLines:Q().int().nonnegative(),lines:xe(j())}),nde=z({agentId:j().optional(),agentType:j().optional(),status:j().optional(),prompt:j().optional(),filePath:j().optional(),structuredPatch:xe(tde).optional(),stats:z({durationMs:Q().int().nonnegative().optional(),tokens:Q().int().nonnegative().optional(),toolUseCount:Q().int().nonnegative().optional(),toolStats:ede.optional()}).optional()}),rde=z({path:j(),content:j(),mtimeMs:Q().optional()}),sde=z({label:j().min(1),description:j().optional()}),vH=z({question:j().min(1),multiSelect:Re(),options:xe(sde).min(1)}),ide=["completed","interrupted"];Bs("kind",[z({...js,kind:he("session_init"),toolSessionId:j().optional()}),z({...js,kind:he("thinking"),text:j(),partialId:j().optional()}),z({...js,kind:he("text"),text:j(),partialId:j().optional()}),z({...js,kind:he("user_text"),text:j(),meta:Jue.optional(),taskId:j().optional(),parentToolUseId:j().optional(),sender:Wue.optional()}),z({...js,kind:he("tool_call"),toolUseId:j(),tool:j(),toolKind:j().optional(),input:Xa()}),z({...js,kind:he("tool_result"),toolUseId:j(),output:Xa().optional(),error:j().optional(),toolResultExtra:nde.optional(),sourceToolAssistantUUID:j().optional(),askQuestionAnswers:Yi(j(),j()).optional()}),z({...js,kind:he("attachment_memories"),memories:xe(rde)}),z({...js,kind:he("permission_request"),requestId:j(),tool:j(),input:Xa(),toolUseId:j().optional()}),z({...js,kind:he("ask_user_question"),toolUseId:j(),questions:xe(vH)}),z({...js,kind:he("turn_end"),durationMs:Q().int().nonnegative().optional(),reason:et(ide).optional(),turnId:j().min(1).optional()}),z({...js,kind:he("subagent_progress"),toolUseId:j(),agentId:j(),status:et(["started","running","completed","failed"]),description:j().optional(),lastToolName:j().optional(),prompt:j().optional(),stats:z({durationMs:Q().int().nonnegative().optional(),tokens:Q().int().nonnegative().optional(),toolUseCount:Q().int().nonnegative().optional()}).optional()}),z({...js,kind:he("error"),message:j()}),z({...js,kind:he("meta_update"),patch:Kue}),z({...js,kind:he("meta-text"),text:j(),metaSource:et(["cc","owner"]).optional()})]);z({cwd:j().min(1).optional(),tool:j().optional(),label:j().optional(),aiLabel:j().optional(),model:j().optional(),permissionMode:j().optional(),effort:j().optional(),serviceTier:U7.optional(),iconKey:j().optional(),forkedFromSessionId:j().min(1).optional(),forkAt:tce([z({messageUuid:j().min(1)}).strict(),z({turnId:j().min(1)}).strict()]).optional(),ephemeral:Re().optional(),ownerPersonaId:j().min(1).optional(),projectPath:j().min(1).optional()}).refine(e=>e.cwd!=null||e.ownerPersonaId!=null||e.projectPath!=null,{message:"cwd / ownerPersonaId / projectPath 至少传一个"});z({path:j().min(1),name:j().min(1),createdAt:j().datetime(),pinnedAt:Q().optional()});z({path:j().min(1),pinnedAt:Q().nullable()});z({path:j().min(1)});z({path:j().min(1).optional(),name:j().min(1).optional()}).refine(e=>e.path!=null||e.name!=null,{message:"path 与 name 至少给一个"});z({cwd:j().min(1),tool:j().min(1),toolSessionId:j().min(1),label:j().optional(),aiLabel:j().optional(),iconKey:j().optional(),createdAt:j().datetime(),updatedAt:j().datetime(),ownerPersonaId:j().min(1).optional()});z({originOnly:Re().optional(),ownerPersonaId:j().min(1).optional(),limit:Q().int().positive().optional(),offset:Q().int().nonnegative().optional()});z({sessionId:j().min(1)});z({sessionId:j().min(1),patch:z({label:j().optional(),tool:j().min(1).optional(),model:j().optional(),permissionMode:j().optional(),effort:j().optional(),cwd:j().optional(),iconKey:j().optional(),ephemeral:he(!1).optional()})});z({id:j().min(1),text:j(),queuedAt:Q(),senderDisplayName:j().optional()});z({sessionId:j().min(1),text:j(),queueWhileRunning:Re().optional()});z({sessionId:j().min(1),id:j().min(1).optional()});z({sessionId:j().min(1),userMessageId:j().min(1),dryRun:Re().optional()});z({canRewind:Re(),error:j().optional(),filesChanged:xe(j()).optional(),insertions:Q().int().nonnegative().optional(),deletions:Q().int().nonnegative().optional()});z({sessionId:j().min(1),userMessageId:j().min(1)});const ode=z({oldStart:Q().int().nonnegative(),oldLines:Q().int().nonnegative(),newStart:Q().int().nonnegative(),newLines:Q().int().nonnegative(),lines:xe(j())}),ade=z({filePath:j().min(1),hunks:xe(ode),insertions:Q().int().nonnegative(),deletions:Q().int().nonnegative(),status:et(["modified","added","deleted"]).optional()});z({canRewind:Re(),error:j().optional(),files:xe(ade),totalInsertions:Q().int().nonnegative(),totalDeletions:Q().int().nonnegative()});z({userMessageIds:xe(j())});z({sessionId:j().min(1),toolSessionId:j().min(1)});z({cwd:j().min(1),toolSessionId:j().min(1),messageUuid:j().min(1).optional(),turnId:j().min(1).optional(),sourceSessionId:j().min(1).optional(),targetCwd:j().min(1).optional()}).refine(e=>!!(e.messageUuid||e.turnId),"messageUuid or turnId required");z({forkedToolSessionId:j().min(1),forkedFilePath:j().min(1)});z({sessionId:j().min(1),toolSessionId:j().min(1),jsonlPath:j().optional()});z({sessionId:j().min(1),afterSeq:Q().int().min(-1)});z({sessionId:j().min(1),permissionRequestId:j().min(1),allow:Re(),permanent:Re().optional(),pattern:j().optional()});z({projectPath:j().min(1)});z({sessionId:j().min(1),limit:Q().int().positive().max(5e3).optional(),offset:Q().int().nonnegative().optional(),snapshotId:j().uuid().optional(),slim:Re().optional(),view:et(["turns","items"]).optional(),cursor:j().min(1).max(16384).optional(),turnId:j().min(1).max(256).optional()}).superRefine((e,t)=>{e.view==="items"&&!e.turnId&&t.addIssue({code:ke.custom,path:["turnId"],message:"items requires turnId"}),e.view&&(e.offset!==void 0||e.slim!==void 0)&&t.addIssue({code:ke.custom,message:"native views do not accept offset or slim"}),!e.view&&(e.cursor!==void 0||e.turnId!==void 0)&&t.addIssue({code:ke.custom,message:"cursor and turnId require a native view"}),e.view==="turns"&&e.turnId!==void 0&&t.addIssue({code:ke.custom,path:["turnId"],message:"turns does not accept turnId"}),e.view&&e.limit!==void 0&&e.limit>100&&t.addIssue({code:ke.custom,path:["limit"],message:"native page limit is 100"})});z({cwd:j().min(1),toolSessionId:j().min(1)});z({cwd:j().min(1),toolSessionId:j().min(1),subagentId:j().min(1)});z({cwd:j().min(1).optional(),path:j().optional(),showHidden:Re().optional()});z({cwd:j().min(1),path:j().min(1)});z({cwd:j().min(1),tool:j().optional()});z({name:j().min(1),source:et(Hue),path:j().optional(),description:j().optional(),plugin:j().optional()});const lde=z({name:j().min(1),source:et(Uue),path:j().optional(),description:j().optional(),whenToUse:j().optional(),plugin:j().optional()});z({cwd:j().min(1),tool:j().optional()});z({agents:xe(lde)});z({sessionId:j().optional()});z({sessionId:j().min(1).optional()});z({sessionId:j().min(1),pinned:Re()});z({sessionId:j().min(1),archived:Re()});z({query:j().min(1),sessionIds:xe(j().min(1)),limit:Q().int().positive().max(50).optional()});const cde=z({sessionId:j().min(1),snippet:j()});z({type:he("session:searchContent"),matches:xe(cde)});z({type:he("peerSession:upsert:ok")});z({sessionId:j().min(1)});z({type:he("peerSession:remove:ok")});z({orderedIds:xe(j().min(1)).min(1)});z({cwd:j().min(1)});z({isGitRoot:Re(),gitRoot:j().nullable()});z({cwd:j().min(1)});z({branch:j().nullable()});z({cwd:j().min(1)});z({branches:xe(j()),head:j().nullable()});const ude=z({cwd:j().min(1),updatedAt:j().min(1)});z({dirs:xe(ude)});z({type:he("session:question"),sessionId:j().min(1),toolUseId:j().min(1),requestId:j().min(1),questions:xe(vH).min(1)});z({type:he("session:question:cleared"),sessionId:j().min(1),toolUseId:j().min(1),answers:Yi(j(),j()).optional()});z({sessionId:j().min(1),toolUseId:j().min(1),answers:Yi(j(),j())});z({ok:he(!0)});z({sessionId:j().min(1),toolUseId:j().min(1)});z({ok:he(!0)});const yH=z({name:j().min(1),version:j().min(1),instanceId:j().min(1),deviceLabel:j().transform(e=>e.trim().slice(0,64)).optional()});z({type:he("auth"),token:j().min(1),scheme:he("bearer").optional(),clientInfo:yH.optional()});z({type:he("auth:ok"),version:j().min(1).optional(),protocolVersion:Q().int().nonnegative().optional()});const dde=z({clientId:j().min(1),connectedAt:Q().int().nonnegative(),self:Re(),clientInfo:yH.optional()});z({type:he("device:connections:ok"),connections:xe(dde)});z({type:he("tunnel:ready"),url:j().min(1),subdomain:j().min(1)});z({type:he("tunnel:exited"),code:Q().int().nullable(),subdomain:j().nullable(),url:j().nullable()});z({type:he("tunnel:unavailable"),reason:j().min(1),failedAt:j().min(1)});const hde=z({sessionId:j().min(1),status:Vue,freshSpawn:Re(),pendingPermissionRequestIds:xe(j().min(1)),pendingQuestionToolUseIds:xe(j().min(1))});z({type:he("info"),version:j(),protocolVersion:Q(),hostname:j(),os:j(),tools:xe(z({id:j(),available:Re()})),runningSessions:xe(hde),tokenRole:et(ace).optional(),isLoopback:Re().optional(),httpBaseUrl:j().optional(),httpToken:j().optional(),daemonSource:et(["ota","packaged"]).optional(),globalCliVersion:j().nullable().optional()});z({});z({method:j().min(1).optional()});const fde=["allowed","conditional","denied"],pde=et(fde),mde=z({name:j().min(1),status:pde,description:j().min(1),args:xe(z({name:j(),required:Re()})).nullable(),argsSchema:Yi(Xa()).optional(),reason:j().optional()});z({type:he("meta:methods"),methods:xe(mde)});const kO=1,gde=z({usedBytes:Q().int().nonnegative(),sizeBytes:Q().int().positive(),measuredAt:Q().int().nonnegative()}).strict();z({volume:gde.nullable()}).strict();const CO=25*1024*1024,nT={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".pdf":"application/pdf",".txt":"text/plain",".md":"text/plain",".markdown":"text/plain",".csv":"text/plain",".log":"text/plain",".json":"application/json",".xml":"application/xml",".yaml":"application/yaml",".yml":"application/yaml",".html":"text/html",".conf":"text/plain",".cfg":"text/plain",".ini":"text/plain",".toml":"text/plain"},bH=new Set([...Object.values(nT),"application/x-yaml"]),wH=[...bH,"text/*",...Object.keys(nT)].join(",");function _H(e,t){const n=t.split(";",1)[0].trim().toLowerCase();if(n===""||n==="application/octet-stream"){const r=e.lastIndexOf("."),s=r>0?e.slice(r).toLowerCase():"";return nT[s]??null}return bH.has(n)||n.startsWith("text/")?n:null}const xde=["daemon","main","renderer"],vde=et(xde),yde=["debug","info","warn","error"],bde=et(yde);z({ts:Q().int(),source:vde,level:bde,msg:j(),ownerPrincipalId:j(),deviceId:j(),appVersion:j(),daemonVersion:j().optional(),os:j(),meta_json:j().optional(),sessionId:j().optional()});z({v:he(1),visitorId:j().min(1),displayName:j(),provider:j(),iat:Q(),exp:Q()});const wde=z({visitorId:j(),displayName:j(),avatarUrl:j().optional(),provider:j(),firstSeen:Q(),lastSeen:Q()});z({visitors:xe(wde)});z({type:he("web:open"),url:j().min(1),expiresAt:Q()});z({ticket:j().min(1)}).strict();z({token:j().min(1),expiresAt:Q()});const _de=/<system-reminder>此消息来自飞书群成员 (.+?)<\/system-reminder>\s*$/,SH=/<system-reminder>此消息来自 (owner|guest):(.+?)<\/system-reminder>\s*$/,kH="clawd-dispatch-task",CH="clawd-dispatch-result",NO=120;function Sde(e){if(!e)return null;const t=e.search(jO(kH)),n=e.search(jO(CH));return t<0&&n<0?null:n<0?"task":t<0?"result":t<n?"task":"result"}function kde(e){if(!e)return[];const t=[];for(const n of["task","result"]){const r=n==="task"?kH:CH,s=new RegExp(`<${r}\\b([^>]*)>([\\s\\S]*?)</${r}>`,"gi");for(let i=s.exec(e);i!==null;i=s.exec(e))t.push({at:i.index,block:Cde(n,i[1]??"",i[2]??"")})}return t.sort((n,r)=>n.at-r.at).map(n=>n.block)}function Cde(e,t,n){var u;const r=Mde(t),s=aj(Rde(jk(n,"detail")??n)),i=(u=jk(n,"brief"))==null?void 0:u.trim(),o=i&&i.length>0?aj(i):Nde(s),l=r.round!==void 0?Number.parseInt(r.round,10):void 0,c=r.status;return{kind:e,dispatchId:r["dispatch-id"]??"",...r.from?{from:r.from}:{},...e==="task"&&l!==void 0&&Number.isFinite(l)?{round:l}:{},...e==="result"&&(c==="success"||c==="failure")?{status:c}:{},brief:o,briefIsDerived:!(i&&i.length>0),detail:s,filePaths:Tde(jk(n,"files"))}}function Nde(e){const t=e.split(/\n\s*\n/).map(r=>r.trim()).find(r=>r.length>0);if(!t)return"";const n=t.replace(/\s+/g," ");return n.length>NO?`${n.slice(0,NO)}…`:n}const jde="clawd-dispatch-task|clawd-dispatch-result|brief|detail|files",Ede=new RegExp(`<\\\\(\\\\*)(/?)(${jde})\\b`,"g");function Ide(e){return aj(e)}function aj(e){return e.replace(Ede,"<$1$2$3")}function jk(e,t){const n=new RegExp(`<${t}>([\\s\\S]*?)</${t}>`,"i").exec(e);return n?n[1]??"":null}function Tde(e){return e?e.split(`
|
|
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 eO=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 s=0,r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(n[r[s]]=e[r[s]]);return n};const $ae={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},Lae={motionBase:!0,motionUnit:!0},Fae={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},o7=(e,t,n)=>{const r=n.getDerivativeToken(e),{override:s}=t,i=eO(t,["override"]);let o=Object.assign(Object.assign({},r),{override:s});return o=i7(o),i&&Object.entries(i).forEach(([l,c])=>{const{theme:u}=c,d=eO(c,["theme"]);let h=d;u&&(h=o7(Object.assign(Object.assign({},o),d),{override:d},u)),o[l]=h}),o};function a7(){const{token:e,hashed:t,theme:n,override:r,cssVar:s}=q.useContext(r7),i=`${Dae}-${t||""}`,o=n||n7,[l,c,u]=Noe(o,[yg,e],{salt:i,override:r,getComputedToken:o7,formatToken:i7,cssVar:s&&{prefix:s.prefix,key:s.key,unitless:$ae,ignore:Lae,preserve:Fae}});return[o,u,t?c:"",l,s]}const Bae=()=>({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"}}),zae=e=>({[`.${e}`]:Object.assign(Object.assign({},Bae()),{[`.${e} .${e}-icon`]:{display:"block"}})}),Hae=(e,t)=>{const[n,r]=a7();return eae({token:r,hashId:"",path:["ant-design-icons",e],nonce:()=>t==null?void 0:t.nonce,layer:{name:"antd"}},()=>zae(e))},Uae=Object.assign({},Sf),{useId:tO}=Uae,Wae=()=>"",Vae=typeof tO>"u"?Wae:tO;function qae(e,t,n){var r;const s=e||{},i=s.inherit===!1||!t?Object.assign(Object.assign({},Eb),{hashed:(r=t==null?void 0:t.hashed)!==null&&r!==void 0?r:Eb.hashed,cssVar:t==null?void 0:t.cssVar}):t,o=Vae();return N9(()=>{var l,c;if(!e)return t;const u=Object.assign({},i.components);Object.keys(e.components||{}).forEach(f=>{u[f]=Object.assign(Object.assign({},u[f]),e.components[f])});const d=`css-var-${o.replace(/:/g,"")}`,h=((l=s.cssVar)!==null&&l!==void 0?l:i.cssVar)&&Object.assign(Object.assign(Object.assign({prefix:n==null?void 0:n.prefixCls},typeof i.cssVar=="object"?i.cssVar:{}),typeof s.cssVar=="object"?s.cssVar:{}),{key:typeof s.cssVar=="object"&&((c=s.cssVar)===null||c===void 0?void 0:c.key)||d});return Object.assign(Object.assign(Object.assign({},i),s),{token:Object.assign(Object.assign({},i.token),s.token),components:u,cssVar:h})},[s,i],(l,c)=>l.some((u,d)=>{const h=c[d];return!eoe(u,h,!0)}))}var Kae=["children"],l7=p.createContext({});function Gae(e){var t=e.children,n=li(e,Kae);return p.createElement(l7.Provider,{value:n},t)}var Yae=function(e){Rr(n,e);var t=I9(n);function n(){return Rn(this,n),t.apply(this,arguments)}return Mn(n,[{key:"render",value:function(){return this.props.children}}]),n}(p.Component);function Xae(e){var t=p.useReducer(function(l){return l+1},0),n=_t(t,2),r=n[1],s=p.useRef(e),i=WN(function(){return s.current}),o=WN(function(l){s.current=typeof l=="function"?l(s.current):l,r()});return[i,o]}var Al="none",r0="appear",s0="enter",i0="leave",nO="none",fo="prepare",ah="start",lh="active",T5="end",c7="prepared";function rO(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 Zae(e,t){var n={animationend:rO("Animation","AnimationEnd"),transitionend:rO("Transition","TransitionEnd")};return e&&("AnimationEvent"in t||delete n.animationend.animation,"TransitionEvent"in t||delete n.transitionend.transition),n}var Qae=Zae(dl(),typeof window<"u"?window:{}),u7={};if(dl()){var Jae=document.createElement("div");u7=Jae.style}var o0={};function d7(e){if(o0[e])return o0[e];var t=Qae[e];if(t)for(var n=Object.keys(t),r=n.length,s=0;s<r;s+=1){var i=n[s];if(Object.prototype.hasOwnProperty.call(t,i)&&i in u7)return o0[e]=t[i],o0[e]}return""}var h7=d7("animationend"),f7=d7("transitionend"),p7=!!(h7&&f7),sO=h7||"animationend",iO=f7||"transitionend";function oO(e,t){if(!e)return null;if(Tn(e)==="object"){var n=t.replace(/-\w/g,function(r){return r[1].toUpperCase()});return e[n]}return"".concat(e,"-").concat(t)}const ele=function(e){var t=p.useRef();function n(s){s&&(s.removeEventListener(iO,e),s.removeEventListener(sO,e))}function r(s){t.current&&t.current!==s&&n(t.current),s&&s!==t.current&&(s.addEventListener(iO,e),s.addEventListener(sO,e),t.current=s)}return p.useEffect(function(){return function(){n(t.current)}},[]),[r,n]};var m7=dl()?p.useLayoutEffect:p.useEffect;const tle=function(){var e=p.useRef(null);function t(){wN.cancel(e.current)}function n(r){var s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:2;t();var i=wN(function(){s<=1?r({isCanceled:function(){return i!==e.current}}):n(r,s-1)});e.current=i}return p.useEffect(function(){return function(){t()}},[]),[n,t]};var nle=[fo,ah,lh,T5],rle=[fo,c7],g7=!1,sle=!0;function x7(e){return e===lh||e===T5}const ile=function(e,t,n){var r=VN(nO),s=_t(r,2),i=s[0],o=s[1],l=tle(),c=_t(l,2),u=c[0],d=c[1];function h(){o(fo,!0)}var f=t?rle:nle;return m7(function(){if(i!==nO&&i!==T5){var m=f.indexOf(i),g=f[m+1],x=n(i);x===g7?o(g,!0):g&&u(function(b){function y(){b.isCanceled()||o(g,!0)}x===!0?y():Promise.resolve(x).then(y)})}},[e,i]),p.useEffect(function(){return function(){d()}},[]),[h,i]};function ole(e,t,n,r){var s=r.motionEnter,i=s===void 0?!0:s,o=r.motionAppear,l=o===void 0?!0:o,c=r.motionLeave,u=c===void 0?!0:c,d=r.motionDeadline,h=r.motionLeaveImmediately,f=r.onAppearPrepare,m=r.onEnterPrepare,g=r.onLeavePrepare,x=r.onAppearStart,b=r.onEnterStart,y=r.onLeaveStart,v=r.onAppearActive,w=r.onEnterActive,_=r.onLeaveActive,S=r.onAppearEnd,k=r.onEnterEnd,C=r.onLeaveEnd,N=r.onVisibleChanged,T=VN(),E=_t(T,2),R=E[0],O=E[1],P=Xae(Al),$=_t(P,2),F=$[0],B=$[1],W=VN(null),L=_t(W,2),D=L[0],I=L[1],V=F(),H=p.useRef(!1),M=p.useRef(null);function Y(){return n()}var X=p.useRef(!1);function K(){B(Al),I(null,!0)}var te=WN(function(De){var Me=F();if(Me!==Al){var We=Y();if(!(De&&!De.deadline&&De.target!==We)){var wt=X.current,Ct;Me===r0&&wt?Ct=S==null?void 0:S(We,De):Me===s0&&wt?Ct=k==null?void 0:k(We,De):Me===i0&&wt&&(Ct=C==null?void 0:C(We,De)),wt&&Ct!==!1&&K()}}}),ce=ele(te),J=_t(ce,1),de=J[0],we=function(Me){switch(Me){case r0:return Ze(Ze(Ze({},fo,f),ah,x),lh,v);case s0:return Ze(Ze(Ze({},fo,m),ah,b),lh,w);case i0:return Ze(Ze(Ze({},fo,g),ah,y),lh,_);default:return{}}},se=p.useMemo(function(){return we(V)},[V]),ae=ile(V,!e,function(De){if(De===fo){var Me=se[fo];return Me?Me(Y()):g7}if(ve in se){var We;I(((We=se[ve])===null||We===void 0?void 0:We.call(se,Y(),null))||null)}return ve===lh&&V!==Al&&(de(Y()),d>0&&(clearTimeout(M.current),M.current=setTimeout(function(){te({deadline:!0})},d))),ve===c7&&K(),sle}),Z=_t(ae,2),fe=Z[0],ve=Z[1],Te=x7(ve);X.current=Te;var Qe=p.useRef(null);m7(function(){if(!(H.current&&Qe.current===t)){O(t);var De=H.current;H.current=!0;var Me;!De&&t&&l&&(Me=r0),De&&t&&i&&(Me=s0),(De&&!t&&u||!De&&h&&!t&&u)&&(Me=i0);var We=we(Me);Me&&(e||We[fo])?(B(Me),fe()):B(Al),Qe.current=t}},[t]),p.useEffect(function(){(V===r0&&!l||V===s0&&!i||V===i0&&!u)&&B(Al)},[l,i,u]),p.useEffect(function(){return function(){H.current=!1,clearTimeout(M.current)}},[]);var ge=p.useRef(!1);p.useEffect(function(){R&&(ge.current=!0),R!==void 0&&V===Al&&((ge.current||R)&&(N==null||N(R)),ge.current=!0)},[R,V]);var Ce=D;return se[fo]&&ve===ah&&(Ce=Pt({transition:"none"},Ce)),[V,ve,Ce,R??t]}function ale(e){var t=e;Tn(e)==="object"&&(t=e.transitionSupport);function n(s,i){return!!(s.motionName&&t&&i!==!1)}var r=p.forwardRef(function(s,i){var o=s.visible,l=o===void 0?!0:o,c=s.removeOnLeave,u=c===void 0?!0:c,d=s.forceRender,h=s.children,f=s.motionName,m=s.leavedClassName,g=s.eventProps,x=p.useContext(l7),b=x.motion,y=n(s,b),v=p.useRef(),w=p.useRef();function _(){try{return v.current instanceof HTMLElement?v.current:Fie(w.current)}catch{return null}}var S=ole(y,l,_,s),k=_t(S,4),C=k[0],N=k[1],T=k[2],E=k[3],R=p.useRef(E);E&&(R.current=!0);var O=p.useCallback(function(L){v.current=L,Uie(i,L)},[i]),P,$=Pt(Pt({},g),{},{visible:l});if(!h)P=null;else if(C===Al)E?P=h(Pt({},$),O):!u&&R.current&&m?P=h(Pt(Pt({},$),{},{className:m}),O):d||!u&&!m?P=h(Pt(Pt({},$),{},{style:{display:"none"}}),O):P=null;else{var F;N===fo?F="prepare":x7(N)?F="active":N===ah&&(F="start");var B=oO(f,"".concat(C,"-").concat(F));P=h(Pt(Pt({},$),{},{className:jie(oO(f,C),Ze(Ze({},B,B&&F),f,typeof f=="string")),style:T}),O)}if(p.isValidElement(P)&&Wie(P)){var W=Vie(P);W||(P=p.cloneElement(P,{ref:O}))}return p.createElement(Yae,{ref:w},P)});return r.displayName="CSSMotion",r}const lle=ale(p7);var qN="add",KN="keep",GN="remove",kk="removed";function cle(e){var t;return e&&Tn(e)==="object"&&"key"in e?t=e:t={key:e},Pt(Pt({},t),{},{key:String(t.key)})}function YN(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return e.map(cle)}function ule(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],n=[],r=0,s=t.length,i=YN(e),o=YN(t);i.forEach(function(u){for(var d=!1,h=r;h<s;h+=1){var f=o[h];if(f.key===u.key){r<h&&(n=n.concat(o.slice(r,h).map(function(m){return Pt(Pt({},m),{},{status:qN})})),r=h),n.push(Pt(Pt({},f),{},{status:KN})),r+=1,d=!0;break}}d||n.push(Pt(Pt({},u),{},{status:GN}))}),r<s&&(n=n.concat(o.slice(r).map(function(u){return Pt(Pt({},u),{},{status:qN})})));var l={};n.forEach(function(u){var d=u.key;l[d]=(l[d]||0)+1});var c=Object.keys(l).filter(function(u){return l[u]>1});return c.forEach(function(u){n=n.filter(function(d){var h=d.key,f=d.status;return h!==u||f!==GN}),n.forEach(function(d){d.key===u&&(d.status=KN)})}),n}var dle=["component","children","onVisibleChanged","onAllRemoved"],hle=["status"],fle=["eventProps","visible","children","motionName","motionAppear","motionEnter","motionLeave","motionLeaveImmediately","motionDeadline","removeOnLeave","leavedClassName","onAppearPrepare","onAppearStart","onAppearActive","onAppearEnd","onEnterStart","onEnterActive","onEnterEnd","onLeaveStart","onLeaveActive","onLeaveEnd"];function ple(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:lle,n=function(r){Rr(i,r);var s=I9(i);function i(){var o;Rn(this,i);for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];return o=s.call.apply(s,[this].concat(c)),Ze(yN(o),"state",{keyEntities:[]}),Ze(yN(o),"removeKey",function(d){o.setState(function(h){var f=h.keyEntities.map(function(m){return m.key!==d?m:Pt(Pt({},m),{},{status:kk})});return{keyEntities:f}},function(){var h=o.state.keyEntities,f=h.filter(function(m){var g=m.status;return g!==kk}).length;f===0&&o.props.onAllRemoved&&o.props.onAllRemoved()})}),o}return Mn(i,[{key:"render",value:function(){var l=this,c=this.state.keyEntities,u=this.props,d=u.component,h=u.children,f=u.onVisibleChanged;u.onAllRemoved;var m=li(u,dle),g=d||p.Fragment,x={};return fle.forEach(function(b){x[b]=m[b],delete m[b]}),delete m.keys,p.createElement(g,m,c.map(function(b,y){var v=b.status,w=li(b,hle),_=v===qN||v===KN;return p.createElement(t,bt({},x,{key:w.key,visible:_,eventProps:w,onVisibleChanged:function(k){f==null||f(k,{key:w.key}),k||l.removeKey(w.key)}}),function(S,k){return h(Pt(Pt({},S),{},{index:y}),k)})}))}}],[{key:"getDerivedStateFromProps",value:function(l,c){var u=l.keys,d=c.keyEntities,h=YN(u),f=ule(d,h);return{keyEntities:f.filter(function(m){var g=d.find(function(x){var b=x.key;return m.key===b});return!(g&&g.status===kk&&m.status===GN)})}}}]),i}(p.Component);return Ze(n,"defaultProps",{component:"div"}),n}ple(p7);const aO=p.createContext(!0);function mle(e){const t=p.useContext(aO),{children:n}=e,[,r]=a7(),{motion:s}=r,i=p.useRef(!1);return i.current||(i.current=t!==s),i.current?p.createElement(aO.Provider,{value:s},p.createElement(Gae,{motion:s},n)):n}const gle=()=>null;var xle=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 s=0,r=Object.getOwnPropertySymbols(e);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(e,r[s])&&(n[r[s]]=e[r[s]]);return n};const vle=["getTargetContainer","getPopupContainer","renderEmpty","input","pagination","form","select","button"];let v7;function yle(){return v7||HN}function ble(e){return Object.keys(e).some(t=>t.endsWith("Color"))}const wle=e=>{const{prefixCls:t,iconPrefixCls:n,theme:r,holderRender:s}=e;t!==void 0&&(v7=t),r&&ble(r)&&Iae(yle(),r)},_le=e=>{const{children:t,csp:n,autoInsertSpaceInButton:r,alert:s,anchor:i,form:o,locale:l,componentSize:c,direction:u,space:d,splitter:h,virtual:f,dropdownMatchSelectWidth:m,popupMatchSelectWidth:g,popupOverflow:x,legacyLocale:b,parentContext:y,iconPrefixCls:v,theme:w,componentDisabled:_,segmented:S,statistic:k,spin:C,calendar:N,carousel:T,cascader:E,collapse:R,typography:O,checkbox:P,descriptions:$,divider:F,drawer:B,skeleton:W,steps:L,image:D,layout:I,list:V,mentions:H,modal:M,progress:Y,result:X,slider:K,breadcrumb:te,menu:ce,pagination:J,input:de,textArea:we,empty:se,badge:ae,radio:Z,rate:fe,switch:ve,transfer:Te,avatar:Qe,message:ge,tag:Ce,table:De,card:Me,tabs:We,timeline:wt,timePicker:Ct,upload:oe,notification:le,tree:pe,colorPicker:Ke,datePicker:Ge,rangePicker:ut,flex:rn,wave:Ve,dropdown:en,warning:ye,tour:Oe,tooltip:dt,popover:Nt,popconfirm:vn,floatButton:be,floatButtonGroup:ne,variant:Ae,inputNumber:nt,treeSelect:rt}=e,Mt=p.useCallback((jt,Wt)=>{const{prefixCls:Zn}=e;if(Wt)return Wt;const dr=Zn||y.getPrefixCls("");return jt?`${dr}-${jt}`:dr},[y.getPrefixCls,e.prefixCls]),$t=v||y.iconPrefixCls||s7,Ht=n||y.csp;Hae($t,Ht);const sn=qae(w,y.theme,{prefixCls:Mt("")}),$n={csp:Ht,autoInsertSpaceInButton:r,alert:s,anchor:i,locale:l||b,direction:u,space:d,splitter:h,virtual:f,popupMatchSelectWidth:g??m,popupOverflow:x,getPrefixCls:Mt,iconPrefixCls:$t,theme:sn,segmented:S,statistic:k,spin:C,calendar:N,carousel:T,cascader:E,collapse:R,typography:O,checkbox:P,descriptions:$,divider:F,drawer:B,skeleton:W,steps:L,image:D,input:de,textArea:we,layout:I,list:V,mentions:H,modal:M,progress:Y,result:X,slider:K,breadcrumb:te,menu:ce,pagination:J,empty:se,badge:ae,radio:Z,rate:fe,switch:ve,transfer:Te,avatar:Qe,message:ge,tag:Ce,table:De,card:Me,tabs:We,timeline:wt,timePicker:Ct,upload:oe,notification:le,tree:pe,colorPicker:Ke,datePicker:Ge,rangePicker:ut,flex:rn,wave:Ve,dropdown:en,warning:ye,tour:Oe,tooltip:dt,popover:Nt,popconfirm:vn,floatButton:be,floatButtonGroup:ne,variant:Ae,inputNumber:nt,treeSelect:rt},Lt=Object.assign({},y);Object.keys($n).forEach(jt=>{$n[jt]!==void 0&&(Lt[jt]=$n[jt])}),vle.forEach(jt=>{const Wt=e[jt];Wt&&(Lt[jt]=Wt)}),typeof r<"u"&&(Lt.button=Object.assign({autoInsertSpace:r},Lt.button));const an=N9(()=>Lt,Lt,(jt,Wt)=>{const Zn=Object.keys(jt),dr=Object.keys(Wt);return Zn.length!==dr.length||Zn.some(nr=>jt[nr]!==Wt[nr])}),{layer:yn}=p.useContext(Sw),bn=p.useMemo(()=>({prefixCls:$t,csp:Ht,layer:yn?"antd":void 0}),[$t,Ht,yn]);let Zt=p.createElement(p.Fragment,null,p.createElement(gle,{dropdownMatchSelectWidth:m}),t);const _e=p.useMemo(()=>{var jt,Wt,Zn,dr;return aae(((jt=Nw.Form)===null||jt===void 0?void 0:jt.defaultValidateMessages)||{},((Zn=(Wt=an.locale)===null||Wt===void 0?void 0:Wt.Form)===null||Zn===void 0?void 0:Zn.defaultValidateMessages)||{},((dr=an.form)===null||dr===void 0?void 0:dr.validateMessages)||{},(o==null?void 0:o.validateMessages)||{})},[an,o==null?void 0:o.validateMessages]);Object.keys(_e).length>0&&(Zt=p.createElement(cae.Provider,{value:_e},Zt)),l&&(Zt=p.createElement(hae,{locale:l,_ANT_MARK__:dae},Zt)),Zt=p.createElement(sae.Provider,{value:bn},Zt),c&&(Zt=p.createElement(Rae,{size:c},Zt)),Zt=p.createElement(mle,null,Zt);const xt=p.useMemo(()=>{const jt=sn||{},{algorithm:Wt,token:Zn,components:dr,cssVar:nr}=jt,eo=xle(jt,["algorithm","token","components","cssVar"]),Ca=Wt&&(!Array.isArray(Wt)||Wt.length>0)?kN(Wt):n7,qs={};Object.entries(dr||{}).forEach(([Na,ja])=>{const Ut=Object.assign({},ja);"algorithm"in Ut&&(Ut.algorithm===!0?Ut.theme=Ca:(Array.isArray(Ut.algorithm)||typeof Ut.algorithm=="function")&&(Ut.theme=kN(Ut.algorithm)),delete Ut.algorithm),qs[Na]=Ut});const bi=Object.assign(Object.assign({},yg),Zn);return Object.assign(Object.assign({},eo),{theme:Ca,token:bi,components:qs,override:Object.assign({override:bi},qs),cssVar:nr})},[sn]);return w&&(Zt=p.createElement(r7.Provider,{value:xt},Zt)),an.warning&&(Zt=p.createElement(lae.Provider,{value:an.warning},Zt)),_!==void 0&&(Zt=p.createElement(Tae,{disabled:_},Zt)),p.createElement(jw.Provider,{value:an},Zt)},jf=e=>{const t=p.useContext(jw),n=p.useContext(Q9);return p.createElement(_le,Object.assign({parentContext:t,legacyLocale:n},e))};jf.ConfigContext=jw;jf.SizeContext=bg;jf.config=wle;jf.useConfig=Mae;Object.defineProperty(jf,"SizeContext",{get:()=>bg});var y7={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(Fr,function(){var n=1e3,r=6e4,s=36e5,i="millisecond",o="second",l="minute",c="hour",u="day",d="week",h="month",f="quarter",m="year",g="date",x="Invalid Date",b=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,v={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function($){var F=["th","st","nd","rd"],B=$%100;return"["+$+(F[(B-20)%10]||F[B]||F[0])+"]"}},w=function($,F,B){var W=String($);return!W||W.length>=F?$:""+Array(F+1-W.length).join(B)+$},_={s:w,z:function($){var F=-$.utcOffset(),B=Math.abs(F),W=Math.floor(B/60),L=B%60;return(F<=0?"+":"-")+w(W,2,"0")+":"+w(L,2,"0")},m:function $(F,B){if(F.date()<B.date())return-$(B,F);var W=12*(B.year()-F.year())+(B.month()-F.month()),L=F.clone().add(W,h),D=B-L<0,I=F.clone().add(W+(D?-1:1),h);return+(-(W+(B-L)/(D?L-I:I-L))||0)},a:function($){return $<0?Math.ceil($)||0:Math.floor($)},p:function($){return{M:h,y:m,w:d,d:u,D:g,h:c,m:l,s:o,ms:i,Q:f}[$]||String($||"").toLowerCase().replace(/s$/,"")},u:function($){return $===void 0}},S="en",k={};k[S]=v;var C="$isDayjsObject",N=function($){return $ instanceof O||!(!$||!$[C])},T=function $(F,B,W){var L;if(!F)return S;if(typeof F=="string"){var D=F.toLowerCase();k[D]&&(L=D),B&&(k[D]=B,L=D);var I=F.split("-");if(!L&&I.length>1)return $(I[0])}else{var V=F.name;k[V]=F,L=V}return!W&&L&&(S=L),L||!W&&S},E=function($,F){if(N($))return $.clone();var B=typeof F=="object"?F:{};return B.date=$,B.args=arguments,new O(B)},R=_;R.l=T,R.i=N,R.w=function($,F){return E($,{locale:F.$L,utc:F.$u,x:F.$x,$offset:F.$offset})};var O=function(){function $(B){this.$L=T(B.locale,null,!0),this.parse(B),this.$x=this.$x||B.x||{},this[C]=!0}var F=$.prototype;return F.parse=function(B){this.$d=function(W){var L=W.date,D=W.utc;if(L===null)return new Date(NaN);if(R.u(L))return new Date;if(L instanceof Date)return new Date(L);if(typeof L=="string"&&!/Z$/i.test(L)){var I=L.match(b);if(I){var V=I[2]-1||0,H=(I[7]||"0").substring(0,3);return D?new Date(Date.UTC(I[1],V,I[3]||1,I[4]||0,I[5]||0,I[6]||0,H)):new Date(I[1],V,I[3]||1,I[4]||0,I[5]||0,I[6]||0,H)}}return new Date(L)}(B),this.init()},F.init=function(){var B=this.$d;this.$y=B.getFullYear(),this.$M=B.getMonth(),this.$D=B.getDate(),this.$W=B.getDay(),this.$H=B.getHours(),this.$m=B.getMinutes(),this.$s=B.getSeconds(),this.$ms=B.getMilliseconds()},F.$utils=function(){return R},F.isValid=function(){return this.$d.toString()!==x},F.isSame=function(B,W){var L=E(B);return this.startOf(W)<=L&&L<=this.endOf(W)},F.isAfter=function(B,W){return E(B)<this.startOf(W)},F.isBefore=function(B,W){return this.endOf(W)<E(B)},F.$g=function(B,W,L){return R.u(B)?this[W]:this.set(L,B)},F.unix=function(){return Math.floor(this.valueOf()/1e3)},F.valueOf=function(){return this.$d.getTime()},F.startOf=function(B,W){var L=this,D=!!R.u(W)||W,I=R.p(B),V=function(J,de){var we=R.w(L.$u?Date.UTC(L.$y,de,J):new Date(L.$y,de,J),L);return D?we:we.endOf(u)},H=function(J,de){return R.w(L.toDate()[J].apply(L.toDate("s"),(D?[0,0,0,0]:[23,59,59,999]).slice(de)),L)},M=this.$W,Y=this.$M,X=this.$D,K="set"+(this.$u?"UTC":"");switch(I){case m:return D?V(1,0):V(31,11);case h:return D?V(1,Y):V(0,Y+1);case d:var te=this.$locale().weekStart||0,ce=(M<te?M+7:M)-te;return V(D?X-ce:X+(6-ce),Y);case u:case g:return H(K+"Hours",0);case c:return H(K+"Minutes",1);case l:return H(K+"Seconds",2);case o:return H(K+"Milliseconds",3);default:return this.clone()}},F.endOf=function(B){return this.startOf(B,!1)},F.$set=function(B,W){var L,D=R.p(B),I="set"+(this.$u?"UTC":""),V=(L={},L[u]=I+"Date",L[g]=I+"Date",L[h]=I+"Month",L[m]=I+"FullYear",L[c]=I+"Hours",L[l]=I+"Minutes",L[o]=I+"Seconds",L[i]=I+"Milliseconds",L)[D],H=D===u?this.$D+(W-this.$W):W;if(D===h||D===m){var M=this.clone().set(g,1);M.$d[V](H),M.init(),this.$d=M.set(g,Math.min(this.$D,M.daysInMonth())).$d}else V&&this.$d[V](H);return this.init(),this},F.set=function(B,W){return this.clone().$set(B,W)},F.get=function(B){return this[R.p(B)]()},F.add=function(B,W){var L,D=this;B=Number(B);var I=R.p(W),V=function(Y){var X=E(D);return R.w(X.date(X.date()+Math.round(Y*B)),D)};if(I===h)return this.set(h,this.$M+B);if(I===m)return this.set(m,this.$y+B);if(I===u)return V(1);if(I===d)return V(7);var H=(L={},L[l]=r,L[c]=s,L[o]=n,L)[I]||1,M=this.$d.getTime()+B*H;return R.w(M,this)},F.subtract=function(B,W){return this.add(-1*B,W)},F.format=function(B){var W=this,L=this.$locale();if(!this.isValid())return L.invalidDate||x;var D=B||"YYYY-MM-DDTHH:mm:ssZ",I=R.z(this),V=this.$H,H=this.$m,M=this.$M,Y=L.weekdays,X=L.months,K=L.meridiem,te=function(de,we,se,ae){return de&&(de[we]||de(W,D))||se[we].slice(0,ae)},ce=function(de){return R.s(V%12||12,de,"0")},J=K||function(de,we,se){var ae=de<12?"AM":"PM";return se?ae.toLowerCase():ae};return D.replace(y,function(de,we){return we||function(se){switch(se){case"YY":return String(W.$y).slice(-2);case"YYYY":return R.s(W.$y,4,"0");case"M":return M+1;case"MM":return R.s(M+1,2,"0");case"MMM":return te(L.monthsShort,M,X,3);case"MMMM":return te(X,M);case"D":return W.$D;case"DD":return R.s(W.$D,2,"0");case"d":return String(W.$W);case"dd":return te(L.weekdaysMin,W.$W,Y,2);case"ddd":return te(L.weekdaysShort,W.$W,Y,3);case"dddd":return Y[W.$W];case"H":return String(V);case"HH":return R.s(V,2,"0");case"h":return ce(1);case"hh":return ce(2);case"a":return J(V,H,!0);case"A":return J(V,H,!1);case"m":return String(H);case"mm":return R.s(H,2,"0");case"s":return String(W.$s);case"ss":return R.s(W.$s,2,"0");case"SSS":return R.s(W.$ms,3,"0");case"Z":return I}return null}(de)||I.replace(":","")})},F.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},F.diff=function(B,W,L){var D,I=this,V=R.p(W),H=E(B),M=(H.utcOffset()-this.utcOffset())*r,Y=this-H,X=function(){return R.m(I,H)};switch(V){case m:D=X()/12;break;case h:D=X();break;case f:D=X()/3;break;case d:D=(Y-M)/6048e5;break;case u:D=(Y-M)/864e5;break;case c:D=Y/s;break;case l:D=Y/r;break;case o:D=Y/n;break;default:D=Y}return L?D:R.a(D)},F.daysInMonth=function(){return this.endOf(h).$D},F.$locale=function(){return k[this.$L]},F.locale=function(B,W){if(!B)return this.$L;var L=this.clone(),D=T(B,W,!0);return D&&(L.$L=D),L},F.clone=function(){return R.w(this.$d,this)},F.toDate=function(){return new Date(this.valueOf())},F.toJSON=function(){return this.isValid()?this.toISOString():null},F.toISOString=function(){return this.$d.toISOString()},F.toString=function(){return this.$d.toUTCString()},$}(),P=O.prototype;return E.prototype=P,[["$ms",i],["$s",o],["$m",l],["$H",c],["$W",u],["$M",h],["$y",m],["$D",g]].forEach(function($){P[$[1]]=function(F){return this.$g(F,$[0],$[1])}}),E.extend=function($,F){return $.$i||($(F,O,E),$.$i=!0),E},E.locale=T,E.isDayjs=N,E.unix=function($){return E(1e3*$)},E.en=k[S],E.Ls=k,E.p={},E})})(y7);var Sle=y7.exports;const XN=xn(Sle);var b7={exports:{}};(function(e,t){(function(n,r){e.exports=r()})(Fr,function(){return function(n,r,s){var i=r.prototype,o=function(h){return h&&(h.indexOf?h:h.s)},l=function(h,f,m,g,x){var b=h.name?h:h.$locale(),y=o(b[f]),v=o(b[m]),w=y||v.map(function(S){return S.slice(0,g)});if(!x)return w;var _=b.weekStart;return w.map(function(S,k){return w[(k+(_||0))%7]})},c=function(){return s.Ls[s.locale()]},u=function(h,f){return h.formats[f]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(g,x,b){return x||b.slice(1)})}(h.formats[f.toUpperCase()])},d=function(){var h=this;return{months:function(f){return f?f.format("MMMM"):l(h,"months")},monthsShort:function(f){return f?f.format("MMM"):l(h,"monthsShort","months",3)},firstDayOfWeek:function(){return h.$locale().weekStart||0},weekdays:function(f){return f?f.format("dddd"):l(h,"weekdays")},weekdaysMin:function(f){return f?f.format("dd"):l(h,"weekdaysMin","weekdays",2)},weekdaysShort:function(f){return f?f.format("ddd"):l(h,"weekdaysShort","weekdays",3)},longDateFormat:function(f){return u(h.$locale(),f)},meridiem:this.$locale().meridiem,ordinal:this.$locale().ordinal}};i.localeData=function(){return d.bind(this)()},s.localeData=function(){var h=c();return{firstDayOfWeek:function(){return h.weekStart||0},weekdays:function(){return s.weekdays()},weekdaysShort:function(){return s.weekdaysShort()},weekdaysMin:function(){return s.weekdaysMin()},months:function(){return s.months()},monthsShort:function(){return s.monthsShort()},longDateFormat:function(f){return u(h,f)},meridiem:h.meridiem,ordinal:h.ordinal}},s.months=function(){return l(c(),"months")},s.monthsShort=function(){return l(c(),"monthsShort","months",3)},s.weekdays=function(h){return l(c(),"weekdays",null,null,h)},s.weekdaysShort=function(h){return l(c(),"weekdaysShort","weekdays",3,h)},s.weekdaysMin=function(h){return l(c(),"weekdaysMin","weekdays",2,h)}}})})(b7);var kle=b7.exports;const Cle=xn(kle),ki=(e,t)=>new Un(e).setA(t).toRgbString(),jd=(e,t)=>new Un(e).lighten(t).toHexString(),Nle=e=>{const t=Bh(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]}},jle=(e,t)=>{const n=e||"#000",r=t||"#fff";return{colorBgBase:n,colorTextBase:r,colorText:ki(r,.85),colorTextSecondary:ki(r,.65),colorTextTertiary:ki(r,.45),colorTextQuaternary:ki(r,.25),colorFill:ki(r,.18),colorFillSecondary:ki(r,.12),colorFillTertiary:ki(r,.08),colorFillQuaternary:ki(r,.04),colorBgSolid:ki(r,.95),colorBgSolidHover:ki(r,1),colorBgSolidActive:ki(r,.9),colorBgElevated:jd(n,12),colorBgContainer:jd(n,8),colorBgLayout:jd(n,0),colorBgSpotlight:jd(n,26),colorBgBlur:ki(r,.04),colorBorder:jd(n,26),colorBorderSecondary:jd(n,19)}},Ele=(e,t)=>{const n=Object.keys(E5).map(i=>{const o=Bh(e[i],{theme:"dark"});return Array.from({length:10},()=>1).reduce((l,c,u)=>(l[`${i}-${u+1}`]=o[u],l[`${i}${u+1}`]=o[u],l),{})}).reduce((i,o)=>(i=Object.assign(Object.assign({},i),o),i),{}),r=t??I5(e),s=t7(e,{generateColorPalettes:Nle,generateNeutralColorPalettes:jle});return Object.assign(Object.assign(Object.assign(Object.assign({},r),n),s),{colorPrimaryBg:s.colorPrimaryBorder,colorPrimaryBgHover:s.colorPrimaryBorderHover})},lO={defaultSeed:Eb.token,defaultAlgorithm:I5,darkAlgorithm:Ele};function Ile({children:e}){const t=ul(),[n,r]=p.useState(t.theme);return p.useEffect(()=>t.onThemeChange(r),[t]),a.jsx(jf,{theme:{algorithm:n.mode==="dark"?lO.darkAlgorithm:lO.defaultAlgorithm,token:{colorPrimary:n.colorPrimary,colorBgContainer:n.colorBgContainer,colorText:n.colorText,colorBorder:n.colorBorder}},children:e})}var Gt;(function(e){e.assertEqual=s=>{};function t(s){}e.assertIs=t;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const i={};for(const o of s)i[o]=o;return i},e.getValidEnumValues=s=>{const i=e.objectKeys(s).filter(l=>typeof s[s[l]]!="number"),o={};for(const l of i)o[l]=s[l];return e.objectValues(o)},e.objectValues=s=>e.objectKeys(s).map(function(i){return s[i]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},e.find=(s,i)=>{for(const o of s)if(i(o))return o},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}e.joinValues=r,e.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(Gt||(Gt={}));var cO;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(cO||(cO={}));const Xe=Gt.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Bl=e=>{switch(typeof e){case"undefined":return Xe.undefined;case"string":return Xe.string;case"number":return Number.isNaN(e)?Xe.nan:Xe.number;case"boolean":return Xe.boolean;case"function":return Xe.function;case"bigint":return Xe.bigint;case"symbol":return Xe.symbol;case"object":return Array.isArray(e)?Xe.array:e===null?Xe.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?Xe.promise:typeof Map<"u"&&e instanceof Map?Xe.map:typeof Set<"u"&&e instanceof Set?Xe.set:typeof Date<"u"&&e instanceof Date?Xe.date:Xe.object;default:return Xe.unknown}},ke=Gt.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 nl 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(i){return i.message},r={_errors:[]},s=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let l=r,c=0;for(;c<o.path.length;){const u=o.path[c];c===o.path.length-1?(l[u]=l[u]||{_errors:[]},l[u]._errors.push(n(o))):l[u]=l[u]||{_errors:[]},l=l[u],c++}}};return s(this),r}static assert(t){if(!(t instanceof nl))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Gt.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=n=>n.message){const n={},r=[];for(const s of this.issues)if(s.path.length>0){const i=s.path[0];n[i]=n[i]||[],n[i].push(t(s))}else r.push(t(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}nl.create=e=>new nl(e);const ZN=(e,t)=>{let n;switch(e.code){case ke.invalid_type:e.received===Xe.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case ke.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Gt.jsonStringifyReplacer)}`;break;case ke.unrecognized_keys:n=`Unrecognized key(s) in object: ${Gt.joinValues(e.keys,", ")}`;break;case ke.invalid_union:n="Invalid input";break;case ke.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Gt.joinValues(e.options)}`;break;case ke.invalid_enum_value:n=`Invalid enum value. Expected ${Gt.joinValues(e.options)}, received '${e.received}'`;break;case ke.invalid_arguments:n="Invalid function arguments";break;case ke.invalid_return_type:n="Invalid function return type";break;case ke.invalid_date:n="Invalid date";break;case ke.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}"`:Gt.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case ke.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 ke.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 ke.custom:n="Invalid input";break;case ke.invalid_intersection_types:n="Intersection results could not be merged";break;case ke.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case ke.not_finite:n="Number must be finite";break;default:n=t.defaultError,Gt.assertNever(e)}return{message:n}};let Tle=ZN;function Rle(){return Tle}const Mle=e=>{const{data:t,path:n,errorMaps:r,issueData:s}=e,i=[...n,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let l="";const c=r.filter(u=>!!u).slice().reverse();for(const u of c)l=u(o,{data:t,defaultError:l}).message;return{...s,path:i,message:l}};function Fe(e,t){const n=Rle(),r=Mle({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===ZN?void 0:ZN].filter(s=>!!s)});e.common.issues.push(r)}class ys{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 s of n){if(s.status==="aborted")return mt;s.status==="dirty"&&t.dirty(),r.push(s.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const s of n){const i=await s.key,o=await s.value;r.push({key:i,value:o})}return ys.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const s of n){const{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return mt;i.status==="dirty"&&t.dirty(),o.status==="dirty"&&t.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(r[i.value]=o.value)}return{status:t.value,value:r}}}const mt=Object.freeze({status:"aborted"}),sm=e=>({status:"dirty",value:e}),Gi=e=>({status:"valid",value:e}),uO=e=>e.status==="aborted",dO=e=>e.status==="dirty",zh=e=>e.status==="valid",Ib=e=>typeof Promise<"u"&&e instanceof Promise;var st;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(st||(st={}));class la{constructor(t,n,r,s){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=s}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 hO=(e,t)=>{if(zh(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 nl(e.common.issues);return this._error=n,this._error}}};function kt(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:s}=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:s}:{errorMap:(o,l)=>{const{message:c}=e;return o.code==="invalid_enum_value"?{message:c??l.defaultError}:typeof l.data>"u"?{message:c??r??l.defaultError}:o.code!=="invalid_type"?{message:l.defaultError}:{message:c??n??l.defaultError}},description:s}}class zt{get description(){return this._def.description}_getType(t){return Bl(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:Bl(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new ys,ctx:{common:t.parent.common,data:t.data,parsedType:Bl(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(Ib(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:Bl(t)},s=this._parseSync({data:t,path:r.path,parent:r});return hO(r,s)}"~validate"(t){var r,s;const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Bl(t)};if(!this["~standard"].async)try{const i=this._parseSync({data:t,path:[],parent:n});return zh(i)?{value:i.value}:{issues:n.common.issues}}catch(i){(s=(r=i==null?void 0:i.message)==null?void 0:r.toLowerCase())!=null&&s.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:n}).then(i=>zh(i)?{value:i.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:Bl(t)},s=this._parse({data:t,path:r.path,parent:r}),i=await(Ib(s)?s:Promise.resolve(s));return hO(r,i)}refine(t,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,i)=>{const o=t(s),l=()=>i.addIssue({code:ke.custom,...r(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(l(),!1)):o?!0:(l(),!1)})}refinement(t,n){return this._refinement((r,s)=>t(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(t){return new gc({schema:this,typeName:gt.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 Ya.create(this,this._def)}nullable(){return Eu.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return na.create(this)}promise(){return Db.create(this,this._def)}or(t){return Rb.create([this,t],this._def)}and(t){return Mb.create(this,t,this._def)}transform(t){return new gc({...kt(this._def),schema:this,typeName:gt.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new Ab({...kt(this._def),innerType:this,defaultValue:n,typeName:gt.ZodDefault})}brand(){return new k7({typeName:gt.ZodBranded,type:this,...kt(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new $b({...kt(this._def),innerType:this,catchValue:n,typeName:gt.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return M5.create(this,t)}readonly(){return Lb.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Ple=/^c[^\s-]{8,}$/i,Ole=/^[0-9a-z]+$/,Dle=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Ale=/^[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,$le=/^[a-z0-9_-]{21}$/i,Lle=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Fle=/^[-+]?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)?)??$/,Ble=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,zle="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ck;const Hle=/^(?:(?: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])$/,Ule=/^(?:(?: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])$/,Wle=/^(([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]))$/,Vle=/^(([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])$/,qle=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Kle=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,w7="((\\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])))",Gle=new RegExp(`^${w7}$`);function _7(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 Yle(e){return new RegExp(`^${_7(e)}$`)}function Xle(e){let t=`${w7}T${_7(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 Zle(e,t){return!!((t==="v4"||!t)&&Hle.test(e)||(t==="v6"||!t)&&Wle.test(e))}function Qle(e,t){if(!Lle.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,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&(s==null?void 0:s.typ)!=="JWT"||!s.alg||t&&s.alg!==t)}catch{return!1}}function Jle(e,t){return!!((t==="v4"||!t)&&Ule.test(e)||(t==="v6"||!t)&&Vle.test(e))}class Wa extends zt{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==Xe.string){const i=this._getOrReturnCtx(t);return Fe(i,{code:ke.invalid_type,expected:Xe.string,received:i.parsedType}),mt}const r=new ys;let s;for(const i of this._def.checks)if(i.kind==="min")t.data.length<i.value&&(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")t.data.length>i.value&&(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){const o=t.data.length>i.value,l=t.data.length<i.value;(o||l)&&(s=this._getOrReturnCtx(t,s),o?Fe(s,{code:ke.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):l&&Fe(s,{code:ke.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")Ble.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"email",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")Ck||(Ck=new RegExp(zle,"u")),Ck.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"emoji",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")Ale.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"uuid",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")$le.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"nanoid",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")Ple.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"cuid",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")Ole.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"cuid2",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")Dle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"ulid",code:ke.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(t.data)}catch{s=this._getOrReturnCtx(t,s),Fe(s,{validation:"url",code:ke.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"regex",code:ke.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?t.data=t.data.trim():i.kind==="includes"?t.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?t.data=t.data.toLowerCase():i.kind==="toUpperCase"?t.data=t.data.toUpperCase():i.kind==="startsWith"?t.data.startsWith(i.value)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?t.data.endsWith(i.value)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?Xle(i).test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?Gle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?Yle(i).test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?Fle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"duration",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?Zle(t.data,i.version)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"ip",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?Qle(t.data,i.alg)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"jwt",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?Jle(t.data,i.version)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"cidr",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?qle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"base64",code:ke.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?Kle.test(t.data)||(s=this._getOrReturnCtx(t,s),Fe(s,{validation:"base64url",code:ke.invalid_string,message:i.message}),r.dirty()):Gt.assertNever(i);return{status:r.value,value:t.data}}_regex(t,n,r){return this.refinement(s=>t.test(s),{validation:n,code:ke.invalid_string,...st.errToObj(r)})}_addCheck(t){return new Wa({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...st.errToObj(t)})}url(t){return this._addCheck({kind:"url",...st.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...st.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...st.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...st.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...st.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...st.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...st.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...st.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...st.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...st.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...st.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...st.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,...st.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,...st.errToObj(t==null?void 0:t.message)})}duration(t){return this._addCheck({kind:"duration",...st.errToObj(t)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...st.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...st.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...st.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...st.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...st.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...st.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...st.errToObj(n)})}nonempty(t){return this.min(1,st.errToObj(t))}trim(){return new Wa({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Wa({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Wa({...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}}Wa.create=e=>new Wa({checks:[],typeName:gt.ZodString,coerce:(e==null?void 0:e.coerce)??!1,...kt(e)});function ece(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,s=n>r?n:r,i=Number.parseInt(e.toFixed(s).replace(".","")),o=Number.parseInt(t.toFixed(s).replace(".",""));return i%o/10**s}class Hh extends zt{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)!==Xe.number){const i=this._getOrReturnCtx(t);return Fe(i,{code:ke.invalid_type,expected:Xe.number,received:i.parsedType}),mt}let r;const s=new ys;for(const i of this._def.checks)i.kind==="int"?Gt.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?t.data<i.value:t.data<=i.value)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?t.data>i.value:t.data>=i.value)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?ece(t.data,i.value)!==0&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.not_finite,message:i.message}),s.dirty()):Gt.assertNever(i);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,st.toString(n))}gt(t,n){return this.setLimit("min",t,!1,st.toString(n))}lte(t,n){return this.setLimit("max",t,!0,st.toString(n))}lt(t,n){return this.setLimit("max",t,!1,st.toString(n))}setLimit(t,n,r,s){return new Hh({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:st.toString(s)}]})}_addCheck(t){return new Hh({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:st.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:st.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:st.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:st.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:st.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:st.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:st.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:st.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:st.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"&&Gt.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)}}Hh.create=e=>new Hh({checks:[],typeName:gt.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...kt(e)});class wg extends zt{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)!==Xe.bigint)return this._getInvalidInput(t);let r;const s=new ys;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?t.data<i.value:t.data<=i.value)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?t.data>i.value:t.data>=i.value)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?t.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),Fe(r,{code:ke.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):Gt.assertNever(i);return{status:s.value,value:t.data}}_getInvalidInput(t){const n=this._getOrReturnCtx(t);return Fe(n,{code:ke.invalid_type,expected:Xe.bigint,received:n.parsedType}),mt}gte(t,n){return this.setLimit("min",t,!0,st.toString(n))}gt(t,n){return this.setLimit("min",t,!1,st.toString(n))}lte(t,n){return this.setLimit("max",t,!0,st.toString(n))}lt(t,n){return this.setLimit("max",t,!1,st.toString(n))}setLimit(t,n,r,s){return new wg({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:st.toString(s)}]})}_addCheck(t){return new wg({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:st.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:st.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:st.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:st.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:st.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}}wg.create=e=>new wg({checks:[],typeName:gt.ZodBigInt,coerce:(e==null?void 0:e.coerce)??!1,...kt(e)});class QN extends zt{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Xe.boolean){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.boolean,received:r.parsedType}),mt}return Gi(t.data)}}QN.create=e=>new QN({typeName:gt.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...kt(e)});class Tb extends zt{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Xe.date){const i=this._getOrReturnCtx(t);return Fe(i,{code:ke.invalid_type,expected:Xe.date,received:i.parsedType}),mt}if(Number.isNaN(t.data.getTime())){const i=this._getOrReturnCtx(t);return Fe(i,{code:ke.invalid_date}),mt}const r=new ys;let s;for(const i of this._def.checks)i.kind==="min"?t.data.getTime()<i.value&&(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?t.data.getTime()>i.value&&(s=this._getOrReturnCtx(t,s),Fe(s,{code:ke.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):Gt.assertNever(i);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Tb({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:st.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:st.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}}Tb.create=e=>new Tb({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:gt.ZodDate,...kt(e)});class fO extends zt{_parse(t){if(this._getType(t)!==Xe.symbol){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.symbol,received:r.parsedType}),mt}return Gi(t.data)}}fO.create=e=>new fO({typeName:gt.ZodSymbol,...kt(e)});class JN extends zt{_parse(t){if(this._getType(t)!==Xe.undefined){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.undefined,received:r.parsedType}),mt}return Gi(t.data)}}JN.create=e=>new JN({typeName:gt.ZodUndefined,...kt(e)});class ej extends zt{_parse(t){if(this._getType(t)!==Xe.null){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.null,received:r.parsedType}),mt}return Gi(t.data)}}ej.create=e=>new ej({typeName:gt.ZodNull,...kt(e)});class pO extends zt{constructor(){super(...arguments),this._any=!0}_parse(t){return Gi(t.data)}}pO.create=e=>new pO({typeName:gt.ZodAny,...kt(e)});class tj extends zt{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Gi(t.data)}}tj.create=e=>new tj({typeName:gt.ZodUnknown,...kt(e)});class mc extends zt{_parse(t){const n=this._getOrReturnCtx(t);return Fe(n,{code:ke.invalid_type,expected:Xe.never,received:n.parsedType}),mt}}mc.create=e=>new mc({typeName:gt.ZodNever,...kt(e)});class mO extends zt{_parse(t){if(this._getType(t)!==Xe.undefined){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.void,received:r.parsedType}),mt}return Gi(t.data)}}mO.create=e=>new mO({typeName:gt.ZodVoid,...kt(e)});class na extends zt{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==Xe.array)return Fe(n,{code:ke.invalid_type,expected:Xe.array,received:n.parsedType}),mt;if(s.exactLength!==null){const o=n.data.length>s.exactLength.value,l=n.data.length<s.exactLength.value;(o||l)&&(Fe(n,{code:o?ke.too_big:ke.too_small,minimum:l?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(Fe(n,{code:ke.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(Fe(n,{code:ke.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,l)=>s.type._parseAsync(new la(n,o,n.path,l)))).then(o=>ys.mergeArray(r,o));const i=[...n.data].map((o,l)=>s.type._parseSync(new la(n,o,n.path,l)));return ys.mergeArray(r,i)}get element(){return this._def.type}min(t,n){return new na({...this._def,minLength:{value:t,message:st.toString(n)}})}max(t,n){return new na({...this._def,maxLength:{value:t,message:st.toString(n)}})}length(t,n){return new na({...this._def,exactLength:{value:t,message:st.toString(n)}})}nonempty(t){return this.min(1,t)}}na.create=(e,t)=>new na({type:e,minLength:null,maxLength:null,exactLength:null,typeName:gt.ZodArray,...kt(t)});function Vd(e){if(e instanceof ir){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Ya.create(Vd(r))}return new ir({...e._def,shape:()=>t})}else return e instanceof na?new na({...e._def,type:Vd(e.element)}):e instanceof Ya?Ya.create(Vd(e.unwrap())):e instanceof Eu?Eu.create(Vd(e.unwrap())):e instanceof Nu?Nu.create(e.items.map(t=>Vd(t))):e}class ir extends zt{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=Gt.objectKeys(t);return this._cached={shape:t,keys:n},this._cached}_parse(t){if(this._getType(t)!==Xe.object){const u=this._getOrReturnCtx(t);return Fe(u,{code:ke.invalid_type,expected:Xe.object,received:u.parsedType}),mt}const{status:r,ctx:s}=this._processInputParams(t),{shape:i,keys:o}=this._getCached(),l=[];if(!(this._def.catchall instanceof mc&&this._def.unknownKeys==="strip"))for(const u in s.data)o.includes(u)||l.push(u);const c=[];for(const u of o){const d=i[u],h=s.data[u];c.push({key:{status:"valid",value:u},value:d._parse(new la(s,h,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof mc){const u=this._def.unknownKeys;if(u==="passthrough")for(const d of l)c.push({key:{status:"valid",value:d},value:{status:"valid",value:s.data[d]}});else if(u==="strict")l.length>0&&(Fe(s,{code:ke.unrecognized_keys,keys:l}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const d of l){const h=s.data[d];c.push({key:{status:"valid",value:d},value:u._parse(new la(s,h,s.path,d)),alwaysSet:d in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const d of c){const h=await d.key,f=await d.value;u.push({key:h,value:f,alwaysSet:d.alwaysSet})}return u}).then(u=>ys.mergeObjectSync(r,u)):ys.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(t){return st.errToObj,new ir({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{var i,o;const s=((o=(i=this._def).errorMap)==null?void 0:o.call(i,n,r).message)??r.defaultError;return n.code==="unrecognized_keys"?{message:st.errToObj(t).message??s}:{message:s}}}:{}})}strip(){return new ir({...this._def,unknownKeys:"strip"})}passthrough(){return new ir({...this._def,unknownKeys:"passthrough"})}extend(t){return new ir({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new ir({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:gt.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new ir({...this._def,catchall:t})}pick(t){const n={};for(const r of Gt.objectKeys(t))t[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new ir({...this._def,shape:()=>n})}omit(t){const n={};for(const r of Gt.objectKeys(this.shape))t[r]||(n[r]=this.shape[r]);return new ir({...this._def,shape:()=>n})}deepPartial(){return Vd(this)}partial(t){const n={};for(const r of Gt.objectKeys(this.shape)){const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}return new ir({...this._def,shape:()=>n})}required(t){const n={};for(const r of Gt.objectKeys(this.shape))if(t&&!t[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof Ya;)i=i._def.innerType;n[r]=i}return new ir({...this._def,shape:()=>n})}keyof(){return S7(Gt.objectKeys(this.shape))}}ir.create=(e,t)=>new ir({shape:()=>e,unknownKeys:"strip",catchall:mc.create(),typeName:gt.ZodObject,...kt(t)});ir.strictCreate=(e,t)=>new ir({shape:()=>e,unknownKeys:"strict",catchall:mc.create(),typeName:gt.ZodObject,...kt(t)});ir.lazycreate=(e,t)=>new ir({shape:e,unknownKeys:"strip",catchall:mc.create(),typeName:gt.ZodObject,...kt(t)});class Rb extends zt{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function s(i){for(const l of i)if(l.result.status==="valid")return l.result;for(const l of i)if(l.result.status==="dirty")return n.common.issues.push(...l.ctx.common.issues),l.result;const o=i.map(l=>new nl(l.ctx.common.issues));return Fe(n,{code:ke.invalid_union,unionErrors:o}),mt}if(n.common.async)return Promise.all(r.map(async i=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(s);{let i;const o=[];for(const c of r){const u={...n,common:{...n.common,issues:[]},parent:null},d=c._parseSync({data:n.data,path:n.path,parent:u});if(d.status==="valid")return d;d.status==="dirty"&&!i&&(i={result:d,ctx:u}),u.common.issues.length&&o.push(u.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;const l=o.map(c=>new nl(c));return Fe(n,{code:ke.invalid_union,unionErrors:l}),mt}}get options(){return this._def.options}}Rb.create=(e,t)=>new Rb({options:e,typeName:gt.ZodUnion,...kt(t)});const Fa=e=>e instanceof rj?Fa(e.schema):e instanceof gc?Fa(e.innerType()):e instanceof Ob?[e.value]:e instanceof ju?e.options:e instanceof sj?Gt.objectValues(e.enum):e instanceof Ab?Fa(e._def.innerType):e instanceof JN?[void 0]:e instanceof ej?[null]:e instanceof Ya?[void 0,...Fa(e.unwrap())]:e instanceof Eu?[null,...Fa(e.unwrap())]:e instanceof k7||e instanceof Lb?Fa(e.unwrap()):e instanceof $b?Fa(e._def.innerType):[];class R5 extends zt{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Xe.object)return Fe(n,{code:ke.invalid_type,expected:Xe.object,received:n.parsedType}),mt;const r=this.discriminator,s=n.data[r],i=this.optionsMap.get(s);return i?n.common.async?i._parseAsync({data:n.data,path:n.path,parent:n}):i._parseSync({data:n.data,path:n.path,parent:n}):(Fe(n,{code:ke.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),mt)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const s=new Map;for(const i of n){const o=Fa(i.shape[t]);if(!o.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const l of o){if(s.has(l))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(l)}`);s.set(l,i)}}return new R5({typeName:gt.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...kt(r)})}}function nj(e,t){const n=Bl(e),r=Bl(t);if(e===t)return{valid:!0,data:e};if(n===Xe.object&&r===Xe.object){const s=Gt.objectKeys(t),i=Gt.objectKeys(e).filter(l=>s.indexOf(l)!==-1),o={...e,...t};for(const l of i){const c=nj(e[l],t[l]);if(!c.valid)return{valid:!1};o[l]=c.data}return{valid:!0,data:o}}else if(n===Xe.array&&r===Xe.array){if(e.length!==t.length)return{valid:!1};const s=[];for(let i=0;i<e.length;i++){const o=e[i],l=t[i],c=nj(o,l);if(!c.valid)return{valid:!1};s.push(c.data)}return{valid:!0,data:s}}else return n===Xe.date&&r===Xe.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}class Mb extends zt{_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=(i,o)=>{if(uO(i)||uO(o))return mt;const l=nj(i.value,o.value);return l.valid?((dO(i)||dO(o))&&n.dirty(),{status:n.value,value:l.data}):(Fe(r,{code:ke.invalid_intersection_types}),mt)};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(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Mb.create=(e,t,n)=>new Mb({left:e,right:t,typeName:gt.ZodIntersection,...kt(n)});class Nu extends zt{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Xe.array)return Fe(r,{code:ke.invalid_type,expected:Xe.array,received:r.parsedType}),mt;if(r.data.length<this._def.items.length)return Fe(r,{code:ke.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),mt;!this._def.rest&&r.data.length>this._def.items.length&&(Fe(r,{code:ke.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const i=[...r.data].map((o,l)=>{const c=this._def.items[l]||this._def.rest;return c?c._parse(new la(r,o,r.path,l)):null}).filter(o=>!!o);return r.common.async?Promise.all(i).then(o=>ys.mergeArray(n,o)):ys.mergeArray(n,i)}get items(){return this._def.items}rest(t){return new Nu({...this._def,rest:t})}}Nu.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Nu({items:e,typeName:gt.ZodTuple,rest:null,...kt(t)})};class Pb extends zt{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!==Xe.object)return Fe(r,{code:ke.invalid_type,expected:Xe.object,received:r.parsedType}),mt;const s=[],i=this._def.keyType,o=this._def.valueType;for(const l in r.data)s.push({key:i._parse(new la(r,l,r.path,l)),value:o._parse(new la(r,r.data[l],r.path,l)),alwaysSet:l in r.data});return r.common.async?ys.mergeObjectAsync(n,s):ys.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof zt?new Pb({keyType:t,valueType:n,typeName:gt.ZodRecord,...kt(r)}):new Pb({keyType:Wa.create(),valueType:t,typeName:gt.ZodRecord,...kt(n)})}}class gO extends zt{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!==Xe.map)return Fe(r,{code:ke.invalid_type,expected:Xe.map,received:r.parsedType}),mt;const s=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map(([l,c],u)=>({key:s._parse(new la(r,l,r.path,[u,"key"])),value:i._parse(new la(r,c,r.path,[u,"value"]))}));if(r.common.async){const l=new Map;return Promise.resolve().then(async()=>{for(const c of o){const u=await c.key,d=await c.value;if(u.status==="aborted"||d.status==="aborted")return mt;(u.status==="dirty"||d.status==="dirty")&&n.dirty(),l.set(u.value,d.value)}return{status:n.value,value:l}})}else{const l=new Map;for(const c of o){const u=c.key,d=c.value;if(u.status==="aborted"||d.status==="aborted")return mt;(u.status==="dirty"||d.status==="dirty")&&n.dirty(),l.set(u.value,d.value)}return{status:n.value,value:l}}}}gO.create=(e,t,n)=>new gO({valueType:t,keyType:e,typeName:gt.ZodMap,...kt(n)});class _g extends zt{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Xe.set)return Fe(r,{code:ke.invalid_type,expected:Xe.set,received:r.parsedType}),mt;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(Fe(r,{code:ke.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(Fe(r,{code:ke.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const i=this._def.valueType;function o(c){const u=new Set;for(const d of c){if(d.status==="aborted")return mt;d.status==="dirty"&&n.dirty(),u.add(d.value)}return{status:n.value,value:u}}const l=[...r.data.values()].map((c,u)=>i._parse(new la(r,c,r.path,u)));return r.common.async?Promise.all(l).then(c=>o(c)):o(l)}min(t,n){return new _g({...this._def,minSize:{value:t,message:st.toString(n)}})}max(t,n){return new _g({...this._def,maxSize:{value:t,message:st.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}_g.create=(e,t)=>new _g({valueType:e,minSize:null,maxSize:null,typeName:gt.ZodSet,...kt(t)});class rj extends zt{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})}}rj.create=(e,t)=>new rj({getter:e,typeName:gt.ZodLazy,...kt(t)});class Ob extends zt{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return Fe(n,{received:n.data,code:ke.invalid_literal,expected:this._def.value}),mt}return{status:"valid",value:t.data}}get value(){return this._def.value}}Ob.create=(e,t)=>new Ob({value:e,typeName:gt.ZodLiteral,...kt(t)});function S7(e,t){return new ju({values:e,typeName:gt.ZodEnum,...kt(t)})}class ju extends zt{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return Fe(n,{expected:Gt.joinValues(r),received:n.parsedType,code:ke.invalid_type}),mt}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 Fe(n,{received:n.data,code:ke.invalid_enum_value,options:r}),mt}return Gi(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 ju.create(t,{...this._def,...n})}exclude(t,n=this._def){return ju.create(this.options.filter(r=>!t.includes(r)),{...this._def,...n})}}ju.create=S7;class sj extends zt{_parse(t){const n=Gt.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Xe.string&&r.parsedType!==Xe.number){const s=Gt.objectValues(n);return Fe(r,{expected:Gt.joinValues(s),received:r.parsedType,code:ke.invalid_type}),mt}if(this._cache||(this._cache=new Set(Gt.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){const s=Gt.objectValues(n);return Fe(r,{received:r.data,code:ke.invalid_enum_value,options:s}),mt}return Gi(t.data)}get enum(){return this._def.values}}sj.create=(e,t)=>new sj({values:e,typeName:gt.ZodNativeEnum,...kt(t)});class Db extends zt{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Xe.promise&&n.common.async===!1)return Fe(n,{code:ke.invalid_type,expected:Xe.promise,received:n.parsedType}),mt;const r=n.parsedType===Xe.promise?n.data:Promise.resolve(n.data);return Gi(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Db.create=(e,t)=>new Db({type:e,typeName:gt.ZodPromise,...kt(t)});class gc extends zt{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===gt.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=this._def.effect||null,i={addIssue:o=>{Fe(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){const o=s.transform(r.data,i);if(r.common.async)return Promise.resolve(o).then(async l=>{if(n.value==="aborted")return mt;const c=await this._def.schema._parseAsync({data:l,path:r.path,parent:r});return c.status==="aborted"?mt:c.status==="dirty"||n.value==="dirty"?sm(c.value):c});{if(n.value==="aborted")return mt;const l=this._def.schema._parseSync({data:o,path:r.path,parent:r});return l.status==="aborted"?mt:l.status==="dirty"||n.value==="dirty"?sm(l.value):l}}if(s.type==="refinement"){const o=l=>{const c=s.refinement(l,i);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return l};if(r.common.async===!1){const l=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return l.status==="aborted"?mt:(l.status==="dirty"&&n.dirty(),o(l.value),{status:n.value,value:l.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(l=>l.status==="aborted"?mt:(l.status==="dirty"&&n.dirty(),o(l.value).then(()=>({status:n.value,value:l.value}))))}if(s.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!zh(o))return mt;const l=s.transform(o.value,i);if(l instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:l}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>zh(o)?Promise.resolve(s.transform(o.value,i)).then(l=>({status:n.value,value:l})):mt);Gt.assertNever(s)}}gc.create=(e,t,n)=>new gc({schema:e,typeName:gt.ZodEffects,effect:t,...kt(n)});gc.createWithPreprocess=(e,t,n)=>new gc({schema:t,effect:{type:"preprocess",transform:e},typeName:gt.ZodEffects,...kt(n)});class Ya extends zt{_parse(t){return this._getType(t)===Xe.undefined?Gi(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Ya.create=(e,t)=>new Ya({innerType:e,typeName:gt.ZodOptional,...kt(t)});class Eu extends zt{_parse(t){return this._getType(t)===Xe.null?Gi(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Eu.create=(e,t)=>new Eu({innerType:e,typeName:gt.ZodNullable,...kt(t)});class Ab extends zt{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===Xe.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Ab.create=(e,t)=>new Ab({innerType:e,typeName:gt.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...kt(t)});class $b extends zt{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Ib(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new nl(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new nl(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}$b.create=(e,t)=>new $b({innerType:e,typeName:gt.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...kt(t)});class xO extends zt{_parse(t){if(this._getType(t)!==Xe.nan){const r=this._getOrReturnCtx(t);return Fe(r,{code:ke.invalid_type,expected:Xe.nan,received:r.parsedType}),mt}return{status:"valid",value:t.data}}}xO.create=e=>new xO({typeName:gt.ZodNaN,...kt(e)});class k7 extends zt{_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 M5 extends zt{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?mt:i.status==="dirty"?(n.dirty(),sm(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?mt:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(t,n){return new M5({in:t,out:n,typeName:gt.ZodPipeline})}}class Lb extends zt{_parse(t){const n=this._def.innerType._parse(t),r=s=>(zh(s)&&(s.value=Object.freeze(s.value)),s);return Ib(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}}Lb.create=(e,t)=>new Lb({innerType:e,typeName:gt.ZodReadonly,...kt(t)});var gt;(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"})(gt||(gt={}));const j=Wa.create,Q=Hh.create,Re=QN.create,Xa=tj.create;mc.create;const xe=na.create,z=ir.create,tce=Rb.create,Bs=R5.create;Mb.create;Nu.create;const Yi=Pb.create,he=Ob.create,et=ju.create;Db.create;Ya.create;Eu.create;const nce=gc.createWithPreprocess,rce=["head","index"],C7=j().regex(/^[A-Za-z0-9][A-Za-z0-9-]{0,127}$/),Fb=j().regex(/^[1-9][0-9]*$/),Bb=j().regex(/^[A-Za-z0-9_.-]+$/),Sg=j().min(1).max(255).refine(e=>!e.startsWith("-")&&e!=="HEAD"&&!e.startsWith("/")&&!e.endsWith("/")&&!e.endsWith(".")&&!/[\s~^:?*\[\\\x00-\x1f\x7f]/.test(e)&&!e.includes("..")&&!e.includes("@{")&&!e.includes("//")&&e.split("/").every(t=>!t.startsWith(".")&&!t.endsWith(".lock")),"Invalid Git branch"),P5=j().min(1).max(4096).refine(e=>!e.startsWith("/")&&!e.includes("\0")&&!e.split(/[\\/]/).includes("..")),Ew=z({workspaceId:C7,repoId:Fb,owner:Bb,name:Bb,sourceBranch:Sg,defaultBranch:Sg}).strict(),sce=z({repoId:Fb,owner:Bb,name:Bb,defaultBranch:j(),private:Re(),description:j().nullable()}),ice=Ew.extend({initialCommit:j(),head:j(),actualBranch:j().nullable(),branches:xe(j()).optional(),files:xe(z({path:P5,previousPath:j().optional(),comparison:et(rce).optional(),status:j(),added:Q().nonnegative(),removed:Q().nonnegative(),binary:Re(),untracked:Re().optional()})),totalFiles:Q().int().nonnegative().optional(),filesTruncated:Re().optional(),added:Q().nonnegative(),removed:Q().nonnegative(),dirty:Re(),conflicted:Re(),version:j(),measuredAt:Q()}),Ed=z({sessionId:C7});Bs("action",[Ed.extend({action:he("repositories"),page:Q().int().min(1).max(1e3).optional(),search:j().max(100).optional()}).strict(),Ed.extend({action:he("branches"),repoId:Fb,page:Q().int().min(1).max(1e3).optional(),search:j().max(100).optional(),cursor:j().min(1).max(1024).optional()}).strict(),Ed.extend({action:he("bind"),repoId:Fb,branch:Sg}).strict(),Ed.extend({action:he("status")}).strict(),Ed.extend({action:he("intend"),branch:Sg.optional()}).strict(),Ed.extend({action:he("diff"),filePath:P5}).strict()]);z({binding:Ew.nullable().optional(),workspace:ice.nullable().optional(),repositories:xe(sce).optional(),branches:xe(j()).optional(),hasMore:Re().optional(),nextCursor:j().min(1).max(1024).optional(),diff:z({path:P5,patch:j(),binary:Re(),truncated:Re(),notStored:Re().optional()}).optional()});z({threadId:j().min(1),conversationId:j().min(1),workspace:Ew.optional()});new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");z({id:j().min(1),name:j().min(1),baseUrl:j().min(1),apiKey:j().min(1),remark:j().optional(),createdAt:Q(),updatedAt:Q()}).strict();const oce=z({id:j().min(1),name:j().min(1),baseUrl:j().min(1),remark:j().optional(),keyMasked:j(),hasKey:Re(),createdAt:Q(),updatedAt:Q()}).strict();z({activeChannelId:j().nullable(),channels:xe(oce)}).strict();z({}).strict();z({id:j().min(1).optional(),name:j().min(1),baseUrl:j().min(1),apiKey:j().optional(),remark:j().optional()}).strict();z({id:j().min(1)}).strict();z({id:j().min(1).nullable()}).strict();z({channelId:j().min(1).optional(),updatedAt:Q().optional()}).strict().refine(e=>e.updatedAt===void 0||e.channelId!==void 0,{message:"updatedAt requires channelId"});z({channelId:j().nullable(),models:xe(z({id:j().min(1),ownedBy:j().optional()}).strict())}).strict();const ace=["owner"],lce=["agent","owner","user-upload"],N7=z({id:j().min(1),relPath:j().min(1),from:et(lce),label:j().optional(),size:Q().int().nonnegative(),mime:j().min(1),addedAt:Q().int().nonnegative(),lastEditedAt:Q().int().nonnegative().optional(),stale:Re().optional()});z({sessionId:j().min(1),relPath:j().min(1),ttlSeconds:Q().int().positive().nullable().optional(),view:et(["raw","md-rendered"]).optional()});z({url:j().min(1),expiresAt:Q().int().nonnegative().nullable()});z({sessionId:j().min(1),relPath:j().min(1),label:j().optional(),origin:he("agent").optional()});z({entry:N7});z({sessionId:j().min(1),relPath:j().min(1)});z({removed:he(!0)});z({sessionId:j().min(1)});z({entries:xe(N7)});z({attachmentId:j().min(1),url:j().min(1),relPath:j().min(1),sizeBytes:Q().int().nonnegative(),mimeType:j().min(1)});const cce=Bs("type",[z({type:he("persona"),id:j().min(1)}).strict(),z({type:he("chat"),id:j().min(1)}).strict(),z({type:he("*")}).strict()]),uce=et(["read","send","admin"]),O5=z({resource:cce,actions:xe(uce).min(1)}).strict(),dce=z({id:j().min(1),secretHash:j().regex(/^[a-f0-9]{64}$/),displayName:j(),grants:xe(O5),issuedAt:Q().int().nonnegative(),expiresAt:Q().int().positive().optional(),maxUses:Q().int().positive().optional(),usedCount:Q().int().nonnegative(),peerOwnerId:j().min(1).optional(),firstUsedByPeerAt:Q().int().positive().optional(),peerDisplayName:j().optional()}).strict(),hce=dce.omit({secretHash:!0});z({type:he("whoami:ok"),owner:z({id:j(),kind:et(["owner","guest"]),displayName:j(),ownerId:j(),provider:j()}).strict(),capability:hce,grantedPersonas:xe(z({id:j().min(1),displayName:j()}).strict())}).strict();const fce="PEER_LOGIN_EXPIRED";z({selfUrl:j().min(1)});z({type:he("contact:handshake:ok"),owner:z({id:j(),ownerId:j(),provider:j(),displayName:j()}),grants:xe(O5)});const pce=Bs("status",[z({status:he("authorized"),login:j().min(1),source:et(["git","file"])}).strict(),z({status:he("missing")}).strict(),z({status:he("invalid"),message:j().min(1)}).strict(),z({status:he("pending"),authUrl:j().url()}).strict()]);z({token:j().min(1)}).strict();z({returnTo:j().url().optional()}).strict();const mce=z({url:j().url(),bin:j(),sha256:j().regex(/^[0-9a-f]{64}$/),size:Q().int().positive()}),gce={label:"Debian 13"},j7=["node","npm"],xce=["claude","codex","git","lark-cli","pi","pi-mcp-bridge","pi-cliproxyapi-provider","python3","jq","rsync","psql","go","chromium","fonts-wqy-microhei","openssh-server","pnpm","whiteboard-cli","s","supabase-mcp","mcp-server-kibana","aliyun"],vce=z({name:j().min(1),from:j().optional(),version:j().optional(),min:j().optional(),library:Re().optional(),localVersion:j().optional(),artifact:mce.optional(),aptMissing:he(!0).optional(),aptVersion:j().optional()}),D5=j().regex(/^[a-z0-9-]+$/,"连接器名只能是小写字母、数字和短横线"),E7=["proxy","env"],I7=["mcp","cli"],yce=["bearer","lark-sidecar"],T7=["none","shared","personal"],A5=["oauth","fields"],Iw=j().regex(/^[A-Z][A-Z0-9_]*$/,"要填的变量名只能是大写字母、数字和下划线,且以字母开头"),bce=z({name:j().min(1),env:xe(Iw).min(1)}),R7=z({name:D5,kind:et(E7),runner:et(I7),protocol:et(yce).optional(),id:j().min(1),credentialSource:et(T7).optional(),auth:et(A5).optional(),publisherUnionId:j().regex(/^on_[A-Za-z0-9_-]+$/).optional(),fields:xe(Iw).default([]),http:z({url:j().min(1),headers:Yi(j(),j())}).optional()}),M7=["LARKSUITE_CLI_APP_ID","LARKSUITE_CLI_APP_SECRET"];function $5(e){return e.name==="feishu"&&e.runner==="cli"&&e.kind==="env"&&e.credentialSource==="shared"}function wce(e){return e.name==="feishu"&&e.id==="feishu"&&e.runner==="cli"&&e.kind==="proxy"&&e.protocol==="lark-sidecar"&&e.credentialSource==="shared"&&e.auth==="oauth"&&e.fields.length===0}function P7(e){if(!e.credentialSource)return[`连接器 ${e.name} 还没选用谁的账号`];const t=[];return wce(e)?t:e.protocol==="lark-sidecar"&&e.credentialSource==="shared"?["连接器 feishu 的发布者 OAuth 配置不完整,请重新选择账号身份"]:$5(e)?M7.filter(n=>!e.fields.includes(n)).map(n=>`连接器 feishu 的 Lark App Bot 缺少 ${n==="LARKSUITE_CLI_APP_ID"?"App ID":"App Secret"}`):(e.credentialSource==="personal"&&(e.auth?e.auth==="oauth"&&e.kind==="env"?t.push(`连接器 ${e.name} 是进程型(stdio MCP / CLI),只能粘贴 API key,走不了 OAuth`):e.auth==="fields"&&e.fields.length===0&&t.push(`连接器 ${e.name} 要填的变量还没列`):t.push(`连接器 ${e.name} 还没选用户怎么关联账号`)),e.credentialSource==="shared"&&e.fields.length===0&&t.push(`连接器 ${e.name} 选了发布者的账号,但要填的变量还没列`),t)}const _ce=/^([A-Za-z0-9._/-]+)@([A-Za-z0-9._-]+)(?:\?tags=([A-Za-z0-9_,]+))?$/,Sce=["main","master","HEAD","latest"];function kce(e){const t=_ce.exec(e);return!!t&&!Sce.includes(t[2])}function O7(e){var n,r;return j7.includes(e.name)||xce.includes(e.name)?[]:(n=e.from)!=null&&n.startsWith("github:")&&!e.artifact?[`${e.name} 还没钉下载资产(github: 要具体到哪个文件)——重新扫描`]:(r=e.from)!=null&&r.startsWith("go:")&&!kce(e.from.slice(3))?[`${e.name} 还没钉版本(go: 要写成 <module>@<tag>,不收 latest / main 这类移动引用)——重新扫描`]:[]}function L5(e){return e.connectors.filter(t=>t.credentialSource==="shared"&&t.fields.length>0).map(t=>({name:t.name,env:[...t.fields]}))}function Cce(e){return[...new Set([...e.envVars.flatMap(t=>t.env),...L5(e).flatMap(t=>t.env)])]}function Nce(e){const t=new Set(e.connectors.flatMap(n=>n.fields));return[...new Set(e.envVars.flatMap(n=>n.env))].filter(n=>t.has(n)).map(n=>`${n} 同时是环境变量和连接器的字段,只能留一处——重新扫描`)}const jce=e=>{if(!e||typeof e!="object")return e;let t=e;if("clis"in t&&Array.isArray(t.clis)){const{clis:n,...r}=t;t="packages"in r?r:{...r,packages:n}}if("assets"in t&&Array.isArray(t.assets)&&t.assets.length===0){const{assets:n,...r}=t;t=r}if("secrets"in t&&Array.isArray(t.secrets)){const{secrets:n,...r}=t,s=new Set((Array.isArray(r.connectors)?r.connectors:[]).flatMap(o=>Array.isArray(o==null?void 0:o.fields)?o.fields:[])),i=n.map(o=>({...o,env:Array.isArray(o==null?void 0:o.env)?o.env.filter(l=>!s.has(l)):o==null?void 0:o.env})).filter(o=>!Array.isArray(o.env)||o.env.length>0);t={...r,envVars:[...Array.isArray(r.envVars)?r.envVars:[],...i]}}return t},Ece="Publisher test: ",D7=z({version:he(1),entry:j().max(240).regex(/^[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*\.mjs$/).refine(e=>!e.split("/").some(t=>[".",".."].includes(t))),timeoutSeconds:Q().int().min(1).max(600),checks:xe(j().regex(/^[a-z0-9][a-z0-9-]{0,63}$/)).min(1).max(64).refine(e=>new Set(e).size===e.length)}).strict(),A7={test:D7.optional(),packages:xe(vce),envVars:xe(bce).default([]),connectors:xe(R7).default([])};z(A7);const F5=nce(jce,z({version:he(1),...A7}).strict()),Ice=z({target:j().min(1),reason:j().min(1),file:j().min(1),quote:j().min(1)}),Tce=["integration","production"],Hs=et(Tce),xc=j().regex(/^[a-z0-9.-]+(?::[0-9]+)?\/[a-z0-9._/-]+@sha256:[a-f0-9]{64}$/),ij=j().regex(/^[a-f0-9]{40}$/),Rce=j().refine(e=>{try{const t=new URL(e);return t.protocol==="https:"&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname==="/"&&/(^|[.-])int([.-]|$)/.test(t.hostname)}catch{return!1}},"测试验证地址必须明确指向 int HTTPS 环境"),Mce=z({version:he(1),runId:j().regex(/^[A-Za-z0-9_-]{1,128}$/),status:he("passed"),exitCode:he(0),result:z({version:he(1),runId:j().regex(/^[A-Za-z0-9_-]{1,128}$/),checks:xe(z({name:j().regex(/^[a-z0-9][a-z0-9-]{0,63}$/),status:he("passed"),reason:j().max(1024).optional()}).strict()).min(1).max(64)}).strict(),execution:z({image:xc,imageID:j().min(1).max(512),engine:et(["codex","pi"]),podUid:j().min(1).max(512),jobUid:j().min(1).max(512)}).strict()}).strict(),$7=z({status:he("passed"),fingerprint:j().regex(/^[a-f0-9]{64}$/),checks:xe(j().regex(/^[a-z0-9-]+$/)),endpoint:Rce,verifiedAt:j().refine(e=>Number.isFinite(Date.parse(e))),test:Mce.optional()}).strict(),L7=z({engine:j().min(1),model:j(),effort:j(),size:j().min(1),cpu:Q().positive(),taskConcurrency:Q().int().positive(),minPods:Q().int().nonnegative().safe().optional()}).strict(),F7=z({version:he(1),environment:he("integration"),component:he("persona"),image:xc,commit:ij,baseImage:xc,pipelineCommit:ij,repository:j().regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/),config:L7.optional(),verification:$7.refine(e=>e.checks.includes("persona-smoke")),test:D7.optional()}).strict().refine(e=>{if(!e.test)return e.verification.test===void 0;const t=e.verification.test;return["persona-dialogue","persona-task","persona-custom-test"].every(n=>e.verification.checks.includes(n))&&t!==void 0&&t.execution.image===e.image&&t.runId===t.result.runId&&t.result.checks.length===e.test.checks.length&&new Set(t.result.checks.map(n=>n.name)).size===e.test.checks.length&&t.result.checks.every(n=>e.test.checks.includes(n.name))},"Declared publisher acceptance requires complete candidate runtime evidence");z({version:he(1),environment:he("integration"),component:he("base"),image:xc,commit:ij,verification:$7.refine(e=>e.checks.includes("base-smoke"))}).strict();const kg="-cloud",B5=`codex${kg}`,Cg={standard:"default",fast:"priority"},Pce=`claude${kg}`;function B7(e){return e==="codex"||e===B5}const z7="pi",Oce=`${z7}${kg}`;function H7(e){return e===z7||e===Oce}function mu(e){return typeof e=="string"&&e.length>kg.length&&e.endsWith(kg)}const U7=et([Cg.standard,Cg.fast]),z5=["tiny","small","medium","large","xlarge"],Dce=et(z5),zb="medium",Hb=[.5,1,2],Ace=Q().refine(e=>Hb.includes(e),"Unsupported CPU"),oj={tiny:.5,small:1,medium:2,large:2,xlarge:2},W7=z({model:j().optional(),effort:j().optional()}).strict(),Mm=z({personaId:j(),label:j(),model:j().optional(),effort:j().optional(),serviceTier:U7.optional(),public:Re(),iconKey:j().optional(),tool:j().optional(),size:j().optional(),cpu:Q().finite().optional(),taskConcurrency:Q().int().positive().optional(),minPods:Q().int().nonnegative().safe().optional(),cloudEngine:W7.optional(),createdAt:Q(),updatedAt:Q(),cloud:z({gatewayUrl:j().min(1),personaId:j().min(1),publishedByMe:Re().optional(),label:j().optional(),environment:Hs.optional(),expectedImage:xc.optional(),testReleaseId:j().optional()}).strict().optional()}).strict(),$ce=z({name:j().min(1),description:j().optional()}),Lce=z({id:j().min(1)}),V7=z({writableRoots:xe(j()).optional(),denyRead:xe(j()).optional(),network:Re().optional()}).strict(),Fce=z({permissions:z({defaultMode:j().optional(),allow:xe(j()).optional(),deny:xe(j()).optional()}).optional(),sandbox:z({enabled:Re().optional(),autoAllowBashIfSandboxed:Re().optional(),allowUnsandboxedCommands:Re().optional(),excludedCommands:xe(j()).optional(),filesystem:z({denyRead:xe(j()).optional(),allowRead:xe(j()).optional(),denyWrite:xe(j()).optional(),allowWrite:xe(j()).optional()}).optional(),network:z({allowedDomains:xe(j()).optional(),allowLocalBinding:Re().optional()}).optional()}).optional()});Mm.extend({personality:j().optional(),personalityLocal:j().optional(),personalityManaged:Re().optional(),skills:xe($ce).optional(),plugins:xe(Lce).optional(),sandboxSettings:Fce.nullable().optional(),codexSandbox:V7.nullable().optional()});z({slug:j().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/).max(32),label:j().min(1),personality:j(),model:j().optional(),effort:j().optional(),serviceTier:Mm.shape.serviceTier,tool:j().optional(),public:Re().optional(),iconKey:j().optional()}).strict();z({personaId:j().min(1)});z({personaId:j().min(1),patch:z({label:j().min(1).optional(),model:j().optional(),effort:j().optional(),serviceTier:Mm.shape.serviceTier,tool:j().optional(),size:Dce.optional(),cpu:Ace.optional(),taskConcurrency:Mm.shape.taskConcurrency,minPods:Mm.shape.minPods,cloudEngine:W7.optional(),personality:j().optional(),personalityLocal:j().optional(),public:Re().optional(),iconKey:j().nullable().optional(),codexSandbox:V7.optional()}).strict()}).strict();z({version:he(1),manifest:F5}).strict();const Bce=["hard","soft"],q7=et(Bce),zce=et(["scanning","done","failed"]),K7=z({id:j().min(1),manifest:F5,scanSessionId:j().optional(),status:zce,evidence:xe(Ice).default([]),notes:xe(j()).default([]),head:j().min(1).optional(),baseKind:q7.default("hard"),base:j().min(1).optional(),startedAt:Q(),finishedAt:Q().optional(),error:j().optional()}).strict(),H5=z({id:j().min(1).optional(),environment:Hs.optional(),legacy:Re().optional(),head:j().min(1),contentHead:j().min(1),scanId:j().min(1),at:Q(),pushed:Re().optional(),runId:Q().int().positive().optional(),runAttempt:Q().int().positive().optional(),artifactId:Q().int().positive().optional(),verified:F7.optional(),config:L7.optional(),reconfigOf:j().min(1).optional(),workflowVersion:Q().int().positive().optional(),confirmation:z({fingerprint:j().regex(/^[a-f0-9]{64}$/),runId:Q().int().positive(),runAttempt:Q().int().positive(),at:Q()}).strict().optional()}).strict(),Hce=["prepared","main-pushed","dispatching","dispatched","completed","failed"],U5=z({id:j().min(1),releaseId:j().min(1),at:Q(),verified:F7.optional(),phase:et(Hce),expectedMain:j().optional(),runId:Q().int().positive().optional(),runAttempt:Q().int().positive().optional(),error:j().optional()}).strict(),vO=z({channelId:j().min(1),updatedAt:Q()}).strict(),W5=z({integration:vO.nullable().optional(),production:vO.nullable().optional()}).strict();z({version:he(4),engineChannels:W5.optional(),scans:xe(K7),releases:xe(H5),promotions:xe(U5).default([])}).strict();const Uce=z({url:j().min(1),branch:j().min(1),head:j().min(1),dirty:Re(),ahead:Q()}).strict(),ky=z({env:j().min(1),setAt:Q().optional()}).strict(),yO={baseUrl:"CLAWD_ENGINE_BASE_URL",apiKey:"CLAWD_ENGINE_API_KEY"},Wce="模型订阅只写进去一半——重填或改回平台默认";function Ub(e){if(!e)return;const t=r=>e.some(s=>s.env===r&&s.setAt!==void 0),n=[yO.baseUrl,yO.apiKey].filter(t).length;return n===2?"own":n===0?"platform":"partial"}function Vce(e){const t=e.trim();let n;try{n=new URL(t)}catch{throw new Error("订阅地址要以 http:// 或 https:// 开头,形如 https://cpa.example.com")}if(n.protocol!=="http:"&&n.protocol!=="https:"||!n.hostname)throw new Error("订阅地址要以 http:// 或 https:// 开头,形如 https://cpa.example.com");const r=`${n.origin}${n.pathname}`.replace(/\/+$/,"");return r.endsWith("/v1")?r:`${r}/v1`}const qce=["pending","running","done","failed","waiting","skipped"],Kce=et(qce),go="verify",Pm=["build","smoke","deploy",go],Gce=et(Pm),Yce=z({key:Gce,status:Kce,url:j().optional(),jobId:Q().optional(),startedAt:Q().optional(),completedAt:Q().optional(),cliWarnings:xe(j()).optional()}).strict(),Cy=z({runId:Q(),headSha:j().min(1),status:et(["queued","running","completed"]),htmlUrl:j().min(1),jobs:xe(Yce),environment:Hs.optional(),branch:j().optional(),event:j().optional(),runAttempt:Q().int().positive().optional(),conclusion:et(["success","failure"]).optional(),promotionId:j().optional()}).strict();function G7(e,t){return t&&e.head===t.head?t.contentHead:e.head}function Tw(e,t,n){return!e||!t||e.status!=="done"?!1:e.head===G7(t,n)&&!t.dirty}function V5(e,t,n){return!e||!t||e.status!=="done"||!e.head?!1:e.head!==G7(t,n)}function bO(e,t,n){return Tw(e,t,n)||V5(e,t,n)}function Xce(e,t){return!t||!e.head?!1:t.contentHead===e.head||t.at>=e.startedAt}const Y7=["codex","pi","claude"];function hl(e){return Y7.includes(e||"claude")}const X7={codex:"0.163.0",pi:"1.3.0",claude:"0.3.304"},Zce="2.1.304";function Qce(e,t){if(!e||!hl(e)||!t)return null;const n=e==="claude"?Zce:X7[e];return n===t?null:{tool:e,cloud:n,local:t}}function Z7(e){const t=e.tool||"claude",n=t==="claude"?e.cloudEngine??{}:e;return{tool:t,model:n.model??"",effort:n.effort??""}}const Nk=z({runId:Q(),status:Cy.shape.status,conclusion:et(["success","failure"]).optional(),htmlUrl:j().min(1)}).strict(),Jce=z({desired:Q().int().nonnegative().safe(),ready:Q().int().nonnegative().safe(),bound:Q().int().nonnegative().safe(),starting:Q().int().nonnegative().safe(),retiring:Q().int().nonnegative().safe(),observedAt:Q(),error:j().nullable()}).strict(),wO=z({online:Re().optional(),image:xc.optional(),minPods:Q().int().nonnegative().safe().optional(),reservation:Jce.nullable().optional(),reservationError:j().optional()}).strict(),Q7=z({personaId:j().min(1),engineChannels:W5.optional(),github:pce.optional(),publisherFeishuAuth:z({integration:z({connected:Re(),authUrl:j().optional(),error:j().optional()}).strict(),production:z({connected:Re(),authUrl:j().optional(),error:j().optional()}).strict()}).strict().optional(),repo:Uce.optional(),scans:xe(K7).default([]),releases:xe(H5).default([]),promotions:xe(U5).optional(),targets:z({integration:wO.extend({run:Cy.optional(),secrets:xe(ky).optional(),unpublish:Nk.optional()}).optional(),production:wO.extend({run:Cy.optional(),secrets:xe(ky).optional(),unpublish:Nk.optional()}).optional()}).strict().optional(),secrets:xe(ky).optional(),run:Cy.optional(),online:Re().optional(),unpublish:Nk.optional(),historyError:j().optional()}).strict();z({before:Q().nullable()}).strict();Q7.pick({personaId:!0,github:!0,repo:!0,scans:!0,releases:!0,promotions:!0,engineChannels:!0,historyError:!0});Q7.pick({scans:!0});z({environment:Hs,secrets:xe(ky).optional(),engineChannels:W5.optional()}).strict();const eue=e=>e.includes("minPods")?3:2,Ng=1,tue=["engine","model","effort","size","cpu","taskConcurrency","minPods"];function nue(e){const{tool:t,model:n,effort:r}=Z7(e),s=(e.size??"").trim()||zb,i=e.cpu??oj[s]??oj[zb];return{engine:t,model:n.trim(),effort:r.trim(),size:s,cpu:i,taskConcurrency:e.taskConcurrency??Ng,minPods:e.minPods??0}}function J7(e,t){return!e||!t?null:tue.filter(n=>n==="minPods"?(e.minPods??0)!==(t.minPods??0):e[n]!==t[n])}z({sha:j().min(1),actionsUrl:j().min(1),releaseId:j().optional()}).strict();const fx=z({personaId:j().min(1)}).strict();fx.extend({releaseHead:j().min(1).optional(),releaseId:j().min(1).optional(),environment:Hs.optional()}).strict();fx.extend({scanBase:q7.optional()}).strict();fx.extend({scanId:j().min(1)}).strict();fx.extend({releaseId:j().min(1)}).strict();fx.extend({environment:Hs.default("production")}).strict();z({confirmation:H5.shape.confirmation.unwrap()}).strict();z({promotion:U5}).strict();z({personaId:j().min(1),expectedImage:xc}).strict();z({personaId:j().min(1),scanId:j().min(1),patch:z({manifest:F5.optional(),connector:R7.optional()}).strict()}).strict();z({personaId:j().min(1),environment:Hs.default("production"),scanId:j().min(1),name:j().min(1),values:Yi(j(),j())}).strict();z({personaId:j().min(1),environment:Hs.default("production"),channelId:j().min(1).optional(),auth:z({baseUrl:j(),apiKey:j()}).strict().nullable().optional()}).strict().refine(e=>e.channelId!==void 0||e.auth!==void 0,{message:"Either channelId or auth must be provided"});z({personaId:j().min(1),environment:Hs.default("production"),releaseId:j().optional(),jobId:Q()}).strict();const rue="底座已更新,重试仍会用旧底座构建——请重新发布测试环境";z({personaId:j().min(1),kind:et(["package","env","connector"]),item:Yi(j(),Xa()),evidence:z({reason:j().min(1),file:j().min(1),quote:j().min(1)})}).strict();z({personaId:j().min(1),notes:xe(j()).default([])}).strict();const eH="ottin4ttc";function Uh(e){return e.trim().replace(/^git@[^:]+:/,"").replace(/^https?:\/\/[^/]+\//,"").replace(/\.git$/,"")}z({environment:Hs.default("production")}).strict();const sue="LOGIN_EXPIRED",iue=z({deviceId:j().min(1),name:j().min(1),url:j().min(1)});z({type:he("device:list:ok"),devices:xe(iue)});z({deviceId:j().min(1),url:j().min(1).optional(),name:j().optional()});z({type:he("device:connect:ok"),deviceId:j(),name:j(),url:j()});const tH=z({ownerId:j().min(1),provider:j().min(1),displayName:j().min(1),avatarUrl:j().optional(),unionId:j().optional()});z({type:he("auth:login:start:ok"),environment:Hs.optional(),authUrl:j().min(1),state:j().min(1)});z({type:he("auth:getIdentity:ok"),identity:tH.nullable(),deviceId:j().min(1)});z({type:he("auth:logout:ok")});const nH=j().nullable();z({type:he("auth:apiKey:get:ok"),apiKey:j().nullable(),createdAt:j().nullable(),gatewayUrl:nH});z({type:he("auth:apiKey:regenerate:ok"),apiKey:j().min(1),createdAt:j().min(1),gatewayUrl:nH});z({type:he("auth:apiKey:revoke:ok"),revoked:Re()});z({type:he("auth:login:done"),environment:Hs.optional(),identity:tH});z({type:he("auth:login:failed"),environment:Hs.optional(),reason:j()});z({deviceId:j().min(1),remoteAccessAllowed:Re()}).strict();z({type:he("contact:setRemoteAccess:ok"),deviceId:j().min(1),remoteAccessAllowed:Re()}).strict();z({type:he("contact:remote-access-updated"),deviceId:j().min(1),remoteAccessAllowed:Re()}).strict();z({personaId:j().min(1)}).strict();const oue=["connected","missing","reauth"],aue=["link","fill"],lue=z({name:D5,id:j().min(1),kind:et(E7),runner:et(I7),auth:et(A5),status:et(oue),action:et(aue),authUrl:j().optional(),fields:xe(Iw)}).strict();z({connectors:xe(lue)}).strict();z({personaId:j().min(1),name:D5,values:Yi(Iw,j().min(1))}).strict();const cue=z({deviceId:j().min(1),ownerId:j().min(1),provider:j().min(1),displayName:j(),remoteUrl:j().min(1),connectToken:j(),grants:xe(O5),addedAt:Q().int().nonnegative(),pinnedAt:Q().int().nullable().default(null),remoteAccessAllowed:Re().default(!1),note:j().default("")}).strict(),rH=cue;z({deviceId:j().min(1)}).strict();z({type:he("contact:remove:ok"),deviceId:j().min(1)}).strict();z({type:he("contact:list:ok"),contacts:xe(rH)}).strict();z({type:he("contact:added"),contact:rH}).strict();z({type:he("contact:removed"),deviceId:j().min(1)}).strict();z({deviceId:j().min(1),pinned:Re()}).strict();z({deviceId:j().min(1),note:j()}).strict();z({type:he("contact:setNote:ok"),deviceId:j().min(1),note:j()}).strict();z({type:he("contact:pin:ok"),deviceId:j().min(1),pinnedAt:Q().int().nullable()}).strict();z({type:he("contact:pinned"),deviceId:j().min(1),pinnedAt:Q().int().nullable()}).strict();const q5=Bs("kind",[z({kind:he("success"),text:j(),brief:j().optional(),filePaths:xe(j()).optional()}),z({kind:he("failure"),reason:j(),brief:j().optional()})]);z({targetPersona:j().min(1).optional(),dispatchId:j().min(1).optional(),prompt:j(),brief:j().optional(),targetDeviceId:j().min(1).optional(),model:j().min(1).optional(),tool:j().min(1).optional(),sessionLabel:j().min(1).max(60).optional(),meta:Yi(Xa()).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:"follow-ups take only dispatchId; the target device comes from the ledger row (dispatchId + targetDeviceId are mutually exclusive)"}).refine(e=>!(e.tool!==void 0&&e.targetDeviceId!==void 0),{message:"engine override is not supported for cross-device dispatch (tool + targetDeviceId are mutually exclusive)"}).refine(e=>!(e.dispatchId!==void 0&&(e.tool!==void 0||e.model!==void 0)),{message:"a follow-up dispatch cannot change engine or model (dispatchId excludes tool / model); start a new dispatch instead"});z({dispatchId:j().min(1),outcome:q5});const uue=["running","completed","failed"],K5=et(uue),due=z({dispatchId:j().min(1),sourceSessionId:j().min(1),sourcePersonaId:j().min(1).optional(),targetPersonaId:j().min(1),targetDeviceId:j().min(1).optional(),remoteDispatchId:j().min(1).optional(),remoteRound:Q().int().positive().optional(),workerSessionId:j().min(1).optional(),taskText:j(),taskBrief:j().optional(),round:Q().int().positive().optional(),status:K5,outcome:q5.optional(),meta:Yi(Xa()).optional(),createdAt:j().min(1),completedAt:j().min(1).optional(),deliveredAt:j().min(1).optional()});z({sourceSessionId:j().min(1).optional(),relatedSessionId:j().min(1).optional()});z({records:xe(due)});z({dispatchId:j().min(1)});z({type:he("personaDispatch:get:ok"),status:K5,outcome:q5.optional()});const hue=/^[a-z0-9][a-z0-9-]*$/;et(["stopped","starting","running","crashed","invalid"]);const fue=new Set(["localhost","127.0.0.1"]);function pue(e){let t;try{t=new URL(e)}catch{return!1}return!!(t.protocol==="https:"||t.protocol==="http:"&&fue.has(t.hostname))}const a0=z({id:j().regex(hue),name:j().min(1),version:j().min(1),apiVersion:he("1"),runtime:z({startCommand:j().min(1)}).passthrough().optional(),entry:z({url:j().url().refine(pue,{message:"INVALID_URL_SCHEME: only https or http://localhost is allowed"})}).strict().optional()}).passthrough().superRefine((e,t)=>{var s;const n=!!e.runtime,r=!!((s=e.entry)!=null&&s.url);n&&r&&t.addIssue({code:ke.custom,message:"INVALID_MANIFEST: entry.url and runtime cannot coexist"}),!n&&!r&&t.addIssue({code:ke.custom,message:"INVALID_MANIFEST: must have either entry.url or runtime"})}),mue=Bs("kind",[z({kind:he("local"),port:Q().int().min(1).max(65535)}),z({kind:he("hosted"),url:j().url()})]);Bs("state",[z({extId:j(),manifest:a0,state:he("stopped")}),z({extId:j(),manifest:a0,state:he("starting")}),z({extId:j(),manifest:a0,state:he("running"),target:mue}),z({extId:j(),manifest:a0,state:he("crashed")}),z({extId:j(),manifest:Xa().nullable(),state:he("invalid"),invalidReason:j().min(1)})]);z({snapshotHash:j().min(1),version:j().min(1),publishedAt:Q()});const gue=Bs("kind",[z({kind:he("p2p-tunnel"),ownerPrincipalId:j().min(1),extId:j().min(1)})]);Bs("kind",[z({kind:he("p2p-tunnel"),ownerPrincipalId:j().min(1),extId:j().min(1),snapshotHash:j().min(1)})]);z({extId:j().min(1),name:j().min(1),version:j().min(1),contentHash:j().min(1),publishedAt:Q()});const xue=Bs("kind",[z({kind:he("clean")}),z({kind:he("ready-new-version"),fromVersion:j().min(1),toVersion:j().min(1)}),z({kind:he("error-same-hash"),version:j().min(1)}),z({kind:he("error-version-not-bumped"),localVersion:j().min(1),publishedVersion:j().min(1)}),z({kind:he("error-version-regression"),localVersion:j().min(1),publishedVersion:j().min(1)})]);function vue(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return(t>>>0).toString(16).padStart(8,"0")}function G5(e,t){return`${e}-${vue(t)}`}function Y5(e){if(typeof e!="string")return{ok:!1,reason:"version must be a string"};const t=e.split(".");if(t.length!==3)return{ok:!1,reason:`"${e}" — only MAJOR.MINOR.PATCH allowed`};for(const n of t)if(!/^\d+$/.test(n))return{ok:!1,reason:`"${e}" — only numeric segments allowed`};return{ok:!0}}function sH(e,t){const n=_O(e),r=_O(t);for(let s=0;s<3;s++){if(n[s]<r[s])return-1;if(n[s]>r[s])return 1}return 0}function _O(e){const t=Y5(e);if(!t.ok)throw new Error(t.reason);const[n,r,s]=e.split(".").map(i=>parseInt(i,10));return[n,r,s]}z({localManifest:z({name:j().min(1),version:j().min(1),contentHash:j().min(1)}),publishState:Bs("kind",[z({kind:he("unpublished")}),z({kind:he("published"),version:j().min(1),contentHash:j().min(1),publishedAt:Q()})]),check:xue});z({extId:j().min(1),newVersion:j().min(1).nullish()});z({extId:j().min(1)});z({extId:j().min(1),snapshotHash:j().min(1)});z({channelRef:gue,snapshotHash:j().min(1),zipBase64:j().min(1)});z({id:j().min(1),peerDeviceId:j().min(1),senderDeviceId:j().min(1),text:j().min(1),createdAt:Q().int().nonnegative(),readBy:Yi(j().min(1),Q().int().positive()).default({}),origin:z({kind:he("persona"),personaId:j().min(1)}).optional()}).strict();z({peerDeviceId:j().min(1).optional(),id:j().min(1),text:j().min(1),createdAt:Q().int().nonnegative(),origin:z({kind:he("persona"),personaId:j().min(1)}).optional()}).strict();z({peerDeviceId:j().min(1),sinceCreatedAt:Q().int().nonnegative().optional()}).strict();z({peerDeviceId:j().min(1),upToCreatedAt:Q().int().nonnegative()}).strict();z({peerDeviceId:j().min(1).optional(),text:j().min(1)});z({peerDeviceId:j().min(1).optional(),command:j().min(1),timeoutMs:Q().int().positive().optional()}).strict();z({type:he("peerExec:run:ok"),stdout:j(),stderr:j(),exitCode:Q().int().nullable(),timedOut:Re(),stdoutTruncated:Re(),stderrTruncated:Re()}).strict();const iH=Bs("kind",[z({kind:he("at"),at:j().min(1)}),z({kind:he("every"),everyMs:Q().int().positive(),anchorMs:Q().int().nonnegative().optional()}),z({kind:he("cron"),expr:j().min(1),tz:j().min(1).optional()})]),px=j().trim().min(1);z({personaId:px,name:j().min(1),schedule:iH,prompt:j().min(1),targetPersona:j().min(1).optional(),timeoutMs:Q().int().positive().optional()});z({personaId:px,onlyMine:Re().optional()});z({personaId:px,shiftId:j().min(1)});const yue=z({name:j().min(1).optional(),schedule:iH.optional(),prompt:j().min(1).optional(),targetPersona:j().min(1).optional(),timeoutMs:Q().int().positive().optional(),enabled:Re().optional()});z({personaId:px,shiftId:j().min(1),patch:yue});z({personaId:px,shiftId:j().min(1),limit:Q().int().positive().optional()});const Fi="persona-master",X5=z({personaId:j().min(1),deviceId:j().min(1).optional()}),oH=z({id:j().min(1),name:j().min(1),memberPersonas:xe(X5),memberContactDeviceIds:xe(j().min(1)),createdAt:j().min(1),updatedAt:j().min(1)}),aH=j().trim().min(1);z({name:aH,memberPersonas:xe(X5).default([]),memberContactDeviceIds:xe(j().min(1)).default([])});z({channelId:j().min(1),name:aH.optional(),memberPersonas:xe(X5).optional(),memberContactDeviceIds:xe(j().min(1)).optional()});z({channelId:j().min(1)});z({channels:xe(oH)});z({channel:oH});z({ok:he(!0),removedTopics:Q().int().min(0)});const ur=j().trim().min(1),Z5=["master-confirmed","owner-needed"],Q5=["open","resolved"],bue=Z5[0],lH=Z5[1],cH=Q5[0],wue=Q5[1],_ue=et(Z5),Sue=et(Q5),kue=z({id:ur.optional(),resolves:ur.optional(),type:_ue,status:Sue,question:ur,recommendation:ur}).superRefine((e,t)=>{e.type===bue&&e.status!==wue&&t.addIssue({code:ke.custom,path:["status"],message:"master-confirmed decisions must be resolved"})}),Cue=["planning","running","done"],Nue=et(Cue),uH=z({at:j().min(1),actor:j().min(1),action:j().min(1),target:j().optional(),reason:j().min(1),artifacts:xe(ur).optional(),decision:kue.optional()}),jue=z({rejectCount:Q().int().min(0),accepted:Re().default(!1),ordinal:Q().int().min(1).optional(),overrideCount:Q().int().min(0).optional()}),J5=z({id:j().min(1),channelId:j().min(1),title:j(),masterSessionId:j().min(1),goal:j(),boundaries:j(),acceptanceCriteria:xe(j()),activity:xe(uH),lineMeta:Yi(jue),nextLineOrdinal:Q().int().min(1).optional(),state:Nue,createdAt:j().min(1),updatedAt:j().min(1)}),Eue=z({lineId:j().min(1),dispatchId:j().min(1),workerSessionId:j().optional(),assignee:j().min(1),focus:j(),status:K5,acceptance:xe(j()),rejectCount:Q().int().min(0),accepted:Re(),ordinal:Q().int().min(1).nullable()});z({channelId:j().min(1)});z({topicId:j().min(1).optional(),sessionId:j().min(1).optional()}).refine(e=>e.topicId!==void 0||e.sessionId!==void 0,{message:"either topicId or sessionId is required"});z({channelId:j().min(1),title:ur.optional()});z({topicId:j().min(1),title:ur.optional(),goal:ur,boundaries:j(),acceptanceCriteria:xe(ur).min(1)});z({topicId:j().min(1),action:ur,target:ur.optional(),reason:ur,artifacts:xe(ur).optional(),decision:uH.shape.decision});z({topicId:j().min(1),lineId:ur,reason:ur});z({topicId:j().min(1),lineId:ur,reason:ur,artifacts:xe(ur).optional(),watcherVerdict:et(["pass","fail"]),overrideReason:ur.optional()}).refine(e=>e.watcherVerdict!=="fail"||!!e.overrideReason,{message:"watcherVerdict=fail 时必须给 overrideReason(推翻 watcher 的理由)",path:["overrideReason"]});z({topicId:j().min(1),state:et(["done"])});z({topicId:j().min(1),title:ur});z({topicId:j().min(1)});const Iue=J5.extend({lineCount:Q().int().min(0)});z({topics:xe(Iue)});z({topic:J5,lines:xe(Eue)});z({topicId:j().min(1),masterSessionId:j().min(1)});z({rejectCount:Q().int().min(1),needsOwnerAttention:Re()});z({acceptedLines:Q().int().min(1),totalLines:Q().int().min(1),allAccepted:Re(),overrides:Q().int().min(0),needsOwnerAttention:Re()});z({topic:J5});z({ok:he(!0),removedMasterSessionId:j().min(1).nullable(),removedWorkerSessionIds:xe(j().min(1))});const Tue=["ask","allow","deny"],dH=et(Tue),Rue=z({id:j().min(1),desc:j().min(1),action:dH});z({rules:xe(Rue)});z({ruleId:j().min(1)});z({action:dH,desc:j(),source:j().min(1)});const Mue=["created","review-requested"],hH=/^[A-Za-z0-9._-]+$/,Ef=j().min(1).regex(hH),If=j().min(1).regex(hH),mx=Q().int().positive();z({role:et(Mue)});z({owner:Ef,repo:If,number:mx});z({owner:Ef,repo:If,number:mx,expectedHeadSha:j().min(1)});z({owner:Ef,repo:If,number:mx,body:j().min(1)});z({owner:Ef,repo:If,number:mx,ready:Re()});z({owner:Ef,repo:If});z({owner:Ef,repo:If,number:mx,reviewers:xe(j().min(1)).min(1)});z({page:Q().int().min(1).max(1e3).optional(),search:j().max(100).optional()});z({personaId:j().min(1)});z({personaId:j().min(1)});const Pue=["expired","cancelled","access_denied","lark_protocol_error","cloud_unreachable","internal_error"],Oue=et(Pue);z({personaId:j().min(1),appId:j().min(1),appSecret:j().min(1),botName:j().min(1).optional()});const Due=z({chatId:j().min(1),chatName:j().optional(),lastActiveAt:Q().int().optional()}),Aue=z({state:et(["unbound","provisioning","bound","broken"]),appId:j().optional(),botName:j().optional(),brokenReason:j().optional(),qrUrl:j().optional(),provisionId:j().optional(),errorReason:Oue.optional(),groups:xe(Due),needsUpgrade:Re().optional(),upgradeQrUrl:j().optional()});Aue.extend({personaId:j().min(1)});z({});z({onboardingCompletedAt:Q()});const Wh=["claude","codex","pi"];z({});z({tools:xe(z({id:et(Wh),available:Re(),version:j().optional(),path:j().optional()}))});z({});const $ue=z({tool:et(Wh),cwd:j(),toolSessionId:j(),label:j().optional(),createdAt:j(),updatedAt:j(),turns:Q()});z({candidates:xe($ue)});z({});z({registered:Re()});z({tool:et(Wh)});const SO=z({usedPercent:Q(),windowDurationMins:Q().optional(),resetsAt:Q().optional()}).strict(),Lue=Bs("kind",[z({kind:he("claude"),loggedIn:Re(),authMethod:j().optional(),apiProvider:j().optional(),apiKeySource:j().optional(),email:j().optional(),orgName:j().optional(),subscriptionType:j().optional()}).strict(),z({kind:he("codex"),login:Bs("type",[z({type:he("none")}).strict(),z({type:he("apiKey")}).strict(),z({type:he("chatgpt"),email:j(),planType:j()}).strict()]),provider:z({name:j(),baseUrl:j().optional()}).strict(),rateLimits:z({primary:SO.optional(),secondary:SO.optional()}).strict().optional()}).strict(),z({kind:he("pi"),providers:xe(z({id:j(),modelCount:Q(),credential:et(["api_key","oauth"]).optional(),oauthExpiresAt:Q().optional()}).strict())}).strict()]);z({tool:et(Wh),installed:Re(),version:j().optional(),path:j().optional(),account:Lue.optional(),error:j().optional(),modelsLoadedAt:Q().optional()}).strict();const eT="https://cpa-portal-d417.app.clawos.chat";z({apiKey:j().min(1)}).strict();z({ok:he(!0)}).strict();const fH=["cloud-persona-metrics","cloud-persona-conversations","cloud-persona-schedules"],Fue=et(fH);z({page:Fue}).strict();z({url:j(),expiresAt:Q().int()}).strict();const pH=["ready","session:info","session:status","session:event","session:deleted","session:rewound","session:cleared","session:queue","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","contact:note-updated","org-mesh:progress","channel:changed","inbox:event","friend:reverseTokenOffered","auth:login:done","auth:login:failed","larkBot:state"],Bue="cloud_history_refresh",tT=["idle","running","running-idle","stopped","error","observing"],zue=["task-notification","slash-command","local-command","system-reminder","skill-hint","meta-text","attachment-skills","attachment-deferred-tools","dispatch-task","dispatch-result"];function Rw(e){return e==="dispatch-task"||e==="dispatch-result"}const Hue=["builtin","global","project","plugin"],Uue=["builtin","global","project","policy","plugin"],mH=et(["owner","guest"]);z({id:j().min(1),kind:mH,displayName:j(),feishuUnionId:j().optional()}).strict();const Wue=z({did:j().min(1),displayName:j(),feishuUnionId:j().optional(),principal:mH}).strict(),Vue=et(tT),que=z({inputTokens:Q().int().nonnegative(),outputTokens:Q().int().nonnegative(),cacheReadTokens:Q().int().nonnegative().optional(),cacheCreateTokens:Q().int().nonnegative().optional()}),gH={gitBranch:j().optional(),resolvedModel:j().optional(),resolvedEffort:j().optional(),contextUsage:que.optional(),contextWindowSize:Q().int().positive().optional(),aiLabel:j().optional()},Kue=z(gH),xH=z({value:j(),label:j(),description:j().optional()}),Gue=z({id:j().min(1),label:j().min(1),description:j().optional(),contextWindowSize:Q().int().positive().optional(),default:Re().optional(),efforts:xe(xH).optional(),defaultEffort:j().optional(),group:j().optional()}),Yue=z({id:j().min(1),label:j().min(1),description:j().optional()}),Xue=z({name:j().min(1),type:et(["string","select","toggle"]),label:j().min(1),description:j().optional(),options:xe(xH).optional(),default:Xa().optional(),scope:et(["core","tool-specific"])});z({tool:j().min(1),refresh:Re().optional()});const Zue=z({rewind:Re(),subagents:Re(),tui:Re(),observe:Re(),fileSharing:Re(),fork:Re()});z({tool:j().min(1),toolSessionIdLabel:j().optional(),models:xe(Gue),permissionModes:xe(Yue),configSchema:xe(Xue),features:Zue});const Que=z({tool:j().min(1),pattern:j().min(1),createdAt:j().min(1).optional()});z({cloudEnvironment:Hs.optional(),cloudExpectedImage:xc.optional(),testReleaseId:j().optional(),sessionId:j().min(1),cloudExecutionId:j().min(1).optional(),cloudConversationId:j().min(1).optional(),cloudWorkspace:Ew.optional(),cloudPendingTurns:xe(z({id:j().min(1),text:j(),prepared:Re().optional()})).optional(),cloudBranchIntent:Sg.optional(),cloudGatewaySessionId:j().min(1).optional(),cloudPendingCommand:z({id:j().min(1),text:j(),prepared:Re().optional()}).optional(),cwd:j().min(1),tool:he("claude").or(j().min(1)).default("claude"),toolSessionId:j().optional(),label:j().optional(),model:j().optional(),permissionMode:j().optional(),effort:j().optional(),serviceTier:j().optional(),...gH,aiLabelGeneratedAt:j().optional(),permissionRules:xe(Que).optional(),pinnedAt:Q().int().nonnegative().nullable().optional(),archivedAt:Q().int().nonnegative().nullable().optional(),pinSortOrder:Q().int().nullable().optional(),unreadAt:j().min(1).nullable().optional(),iconKey:j().optional(),forkedFromSessionId:j().min(1).optional(),ephemeral:Re().optional(),deployId:j().min(1).optional(),ownerPersonaId:j().min(1).optional(),projectPath:j().min(1).optional(),chatId:j().min(1).optional(),creatorPrincipalId:j().min(1).optional(),creatorDisplayName:j().min(1).optional(),creatorFeishuUnionId:j().min(1).optional(),originOwnerPrincipalId:j().min(1).optional(),originOwnerPersonaId:j().min(1).optional(),dispatchedFromSessionId:j().min(1).optional(),shiftFiredFromSessionId:j().min(1).optional(),larkChatId:j().min(1).optional(),larkChatName:j().min(1).optional(),larkChatType:et(["p2p","group"]).optional(),createdAt:j().min(1),updatedAt:j().min(1)});const js={turnId:j().min(1).optional(),seq:Q().int().nonnegative().optional(),ts:j().optional(),uuid:j().optional()},Jue=et(zue),ede=z({readCount:Q().int().nonnegative().optional(),searchCount:Q().int().nonnegative().optional(),bashCount:Q().int().nonnegative().optional(),editFileCount:Q().int().nonnegative().optional(),linesAdded:Q().int().nonnegative().optional(),linesRemoved:Q().int().nonnegative().optional(),otherToolCount:Q().int().nonnegative().optional()}),tde=z({oldStart:Q().int().nonnegative(),oldLines:Q().int().nonnegative(),newStart:Q().int().nonnegative(),newLines:Q().int().nonnegative(),lines:xe(j())}),nde=z({agentId:j().optional(),agentType:j().optional(),status:j().optional(),prompt:j().optional(),filePath:j().optional(),structuredPatch:xe(tde).optional(),stats:z({durationMs:Q().int().nonnegative().optional(),tokens:Q().int().nonnegative().optional(),toolUseCount:Q().int().nonnegative().optional(),toolStats:ede.optional()}).optional()}),rde=z({path:j(),content:j(),mtimeMs:Q().optional()}),sde=z({label:j().min(1),description:j().optional()}),vH=z({question:j().min(1),multiSelect:Re(),options:xe(sde).min(1)}),ide=["completed","interrupted"];Bs("kind",[z({...js,kind:he("session_init"),toolSessionId:j().optional()}),z({...js,kind:he("thinking"),text:j(),partialId:j().optional()}),z({...js,kind:he("text"),text:j(),partialId:j().optional()}),z({...js,kind:he("user_text"),text:j(),meta:Jue.optional(),taskId:j().optional(),parentToolUseId:j().optional(),sender:Wue.optional()}),z({...js,kind:he("tool_call"),toolUseId:j(),tool:j(),toolKind:j().optional(),input:Xa()}),z({...js,kind:he("tool_result"),toolUseId:j(),output:Xa().optional(),error:j().optional(),toolResultExtra:nde.optional(),sourceToolAssistantUUID:j().optional(),askQuestionAnswers:Yi(j(),j()).optional()}),z({...js,kind:he("attachment_memories"),memories:xe(rde)}),z({...js,kind:he("permission_request"),requestId:j(),tool:j(),input:Xa(),toolUseId:j().optional()}),z({...js,kind:he("ask_user_question"),toolUseId:j(),questions:xe(vH)}),z({...js,kind:he("turn_end"),durationMs:Q().int().nonnegative().optional(),reason:et(ide).optional(),turnId:j().min(1).optional()}),z({...js,kind:he("subagent_progress"),toolUseId:j(),agentId:j(),status:et(["started","running","completed","failed"]),description:j().optional(),lastToolName:j().optional(),prompt:j().optional(),stats:z({durationMs:Q().int().nonnegative().optional(),tokens:Q().int().nonnegative().optional(),toolUseCount:Q().int().nonnegative().optional()}).optional()}),z({...js,kind:he("error"),message:j()}),z({...js,kind:he("meta_update"),patch:Kue}),z({...js,kind:he("meta-text"),text:j(),metaSource:et(["cc","owner"]).optional()})]);z({cwd:j().min(1).optional(),tool:j().optional(),label:j().optional(),aiLabel:j().optional(),model:j().optional(),permissionMode:j().optional(),effort:j().optional(),serviceTier:U7.optional(),iconKey:j().optional(),forkedFromSessionId:j().min(1).optional(),forkAt:tce([z({messageUuid:j().min(1)}).strict(),z({turnId:j().min(1)}).strict()]).optional(),ephemeral:Re().optional(),ownerPersonaId:j().min(1).optional(),projectPath:j().min(1).optional()}).refine(e=>e.cwd!=null||e.ownerPersonaId!=null||e.projectPath!=null,{message:"cwd / ownerPersonaId / projectPath 至少传一个"});z({path:j().min(1),name:j().min(1),createdAt:j().datetime(),pinnedAt:Q().optional()});z({path:j().min(1),pinnedAt:Q().nullable()});z({path:j().min(1)});z({path:j().min(1).optional(),name:j().min(1).optional()}).refine(e=>e.path!=null||e.name!=null,{message:"path 与 name 至少给一个"});z({cwd:j().min(1),tool:j().min(1),toolSessionId:j().min(1),label:j().optional(),aiLabel:j().optional(),iconKey:j().optional(),createdAt:j().datetime(),updatedAt:j().datetime(),ownerPersonaId:j().min(1).optional()});z({originOnly:Re().optional(),ownerPersonaId:j().min(1).optional(),limit:Q().int().positive().optional(),offset:Q().int().nonnegative().optional()});z({sessionId:j().min(1)});z({sessionId:j().min(1),patch:z({label:j().optional(),tool:j().min(1).optional(),model:j().optional(),permissionMode:j().optional(),effort:j().optional(),cwd:j().optional(),iconKey:j().optional(),ephemeral:he(!1).optional()})});z({id:j().min(1),text:j(),queuedAt:Q(),senderDisplayName:j().optional()});z({sessionId:j().min(1),text:j(),queueWhileRunning:Re().optional()});z({sessionId:j().min(1),id:j().min(1).optional()});z({sessionId:j().min(1),userMessageId:j().min(1),dryRun:Re().optional()});z({canRewind:Re(),error:j().optional(),filesChanged:xe(j()).optional(),insertions:Q().int().nonnegative().optional(),deletions:Q().int().nonnegative().optional()});z({sessionId:j().min(1),userMessageId:j().min(1)});const ode=z({oldStart:Q().int().nonnegative(),oldLines:Q().int().nonnegative(),newStart:Q().int().nonnegative(),newLines:Q().int().nonnegative(),lines:xe(j())}),ade=z({filePath:j().min(1),hunks:xe(ode),insertions:Q().int().nonnegative(),deletions:Q().int().nonnegative(),status:et(["modified","added","deleted"]).optional()});z({canRewind:Re(),error:j().optional(),files:xe(ade),totalInsertions:Q().int().nonnegative(),totalDeletions:Q().int().nonnegative()});z({userMessageIds:xe(j())});z({sessionId:j().min(1),toolSessionId:j().min(1)});z({cwd:j().min(1),toolSessionId:j().min(1),messageUuid:j().min(1).optional(),turnId:j().min(1).optional(),sourceSessionId:j().min(1).optional(),targetCwd:j().min(1).optional()}).refine(e=>!!(e.messageUuid||e.turnId),"messageUuid or turnId required");z({forkedToolSessionId:j().min(1),forkedFilePath:j().min(1)});z({sessionId:j().min(1),toolSessionId:j().min(1),jsonlPath:j().optional()});z({sessionId:j().min(1),afterSeq:Q().int().min(-1)});z({sessionId:j().min(1),permissionRequestId:j().min(1),allow:Re(),permanent:Re().optional(),pattern:j().optional()});z({projectPath:j().min(1)});z({sessionId:j().min(1),limit:Q().int().positive().max(5e3).optional(),offset:Q().int().nonnegative().optional(),snapshotId:j().uuid().optional(),slim:Re().optional(),view:et(["turns","items"]).optional(),cursor:j().min(1).max(16384).optional(),turnId:j().min(1).max(256).optional()}).superRefine((e,t)=>{e.view==="items"&&!e.turnId&&t.addIssue({code:ke.custom,path:["turnId"],message:"items requires turnId"}),e.view&&(e.offset!==void 0||e.slim!==void 0)&&t.addIssue({code:ke.custom,message:"native views do not accept offset or slim"}),!e.view&&(e.cursor!==void 0||e.turnId!==void 0)&&t.addIssue({code:ke.custom,message:"cursor and turnId require a native view"}),e.view==="turns"&&e.turnId!==void 0&&t.addIssue({code:ke.custom,path:["turnId"],message:"turns does not accept turnId"}),e.view&&e.limit!==void 0&&e.limit>100&&t.addIssue({code:ke.custom,path:["limit"],message:"native page limit is 100"})});z({cwd:j().min(1),toolSessionId:j().min(1)});z({cwd:j().min(1),toolSessionId:j().min(1),subagentId:j().min(1)});z({cwd:j().min(1).optional(),path:j().optional(),showHidden:Re().optional()});z({cwd:j().min(1),path:j().min(1)});z({cwd:j().min(1),tool:j().optional()});z({name:j().min(1),source:et(Hue),path:j().optional(),description:j().optional(),plugin:j().optional()});const lde=z({name:j().min(1),source:et(Uue),path:j().optional(),description:j().optional(),whenToUse:j().optional(),plugin:j().optional()});z({cwd:j().min(1),tool:j().optional()});z({agents:xe(lde)});z({sessionId:j().optional()});z({sessionId:j().min(1).optional()});z({sessionId:j().min(1),pinned:Re()});z({sessionId:j().min(1),archived:Re()});z({query:j().min(1),sessionIds:xe(j().min(1)),limit:Q().int().positive().max(50).optional()});const cde=z({sessionId:j().min(1),snippet:j()});z({type:he("session:searchContent"),matches:xe(cde)});z({type:he("peerSession:upsert:ok")});z({sessionId:j().min(1)});z({type:he("peerSession:remove:ok")});z({orderedIds:xe(j().min(1)).min(1)});z({cwd:j().min(1)});z({isGitRoot:Re(),gitRoot:j().nullable()});z({cwd:j().min(1)});z({branch:j().nullable()});z({cwd:j().min(1)});z({branches:xe(j()),head:j().nullable()});const ude=z({cwd:j().min(1),updatedAt:j().min(1)});z({dirs:xe(ude)});z({type:he("session:question"),sessionId:j().min(1),toolUseId:j().min(1),requestId:j().min(1),questions:xe(vH).min(1)});z({type:he("session:question:cleared"),sessionId:j().min(1),toolUseId:j().min(1),answers:Yi(j(),j()).optional()});z({sessionId:j().min(1),toolUseId:j().min(1),answers:Yi(j(),j())});z({ok:he(!0)});z({sessionId:j().min(1),toolUseId:j().min(1)});z({ok:he(!0)});const yH=z({name:j().min(1),version:j().min(1),instanceId:j().min(1),deviceLabel:j().transform(e=>e.trim().slice(0,64)).optional()});z({type:he("auth"),token:j().min(1),scheme:he("bearer").optional(),clientInfo:yH.optional()});z({type:he("auth:ok"),version:j().min(1).optional(),protocolVersion:Q().int().nonnegative().optional()});const dde=z({clientId:j().min(1),connectedAt:Q().int().nonnegative(),self:Re(),clientInfo:yH.optional()});z({type:he("device:connections:ok"),connections:xe(dde)});z({type:he("tunnel:ready"),url:j().min(1),subdomain:j().min(1)});z({type:he("tunnel:exited"),code:Q().int().nullable(),subdomain:j().nullable(),url:j().nullable()});z({type:he("tunnel:unavailable"),reason:j().min(1),failedAt:j().min(1)});const hde=z({sessionId:j().min(1),status:Vue,freshSpawn:Re(),pendingPermissionRequestIds:xe(j().min(1)),pendingQuestionToolUseIds:xe(j().min(1))});z({type:he("info"),version:j(),protocolVersion:Q(),hostname:j(),os:j(),tools:xe(z({id:j(),available:Re()})),runningSessions:xe(hde),tokenRole:et(ace).optional(),isLoopback:Re().optional(),httpBaseUrl:j().optional(),httpToken:j().optional(),daemonSource:et(["ota","packaged"]).optional(),globalCliVersion:j().nullable().optional()});z({});z({method:j().min(1).optional()});const fde=["allowed","conditional","denied"],pde=et(fde),mde=z({name:j().min(1),status:pde,description:j().min(1),args:xe(z({name:j(),required:Re()})).nullable(),argsSchema:Yi(Xa()).optional(),reason:j().optional()});z({type:he("meta:methods"),methods:xe(mde)});const kO=1,gde=z({usedBytes:Q().int().nonnegative(),sizeBytes:Q().int().positive(),measuredAt:Q().int().nonnegative()}).strict();z({volume:gde.nullable()}).strict();const CO=25*1024*1024,nT={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".pdf":"application/pdf",".txt":"text/plain",".md":"text/plain",".markdown":"text/plain",".csv":"text/plain",".log":"text/plain",".json":"application/json",".xml":"application/xml",".yaml":"application/yaml",".yml":"application/yaml",".html":"text/html",".conf":"text/plain",".cfg":"text/plain",".ini":"text/plain",".toml":"text/plain"},bH=new Set([...Object.values(nT),"application/x-yaml"]),wH=[...bH,"text/*",...Object.keys(nT)].join(",");function _H(e,t){const n=t.split(";",1)[0].trim().toLowerCase();if(n===""||n==="application/octet-stream"){const r=e.lastIndexOf("."),s=r>0?e.slice(r).toLowerCase():"";return nT[s]??null}return bH.has(n)||n.startsWith("text/")?n:null}const xde=["daemon","main","renderer"],vde=et(xde),yde=["debug","info","warn","error"],bde=et(yde);z({ts:Q().int(),source:vde,level:bde,msg:j(),ownerPrincipalId:j(),deviceId:j(),appVersion:j(),daemonVersion:j().optional(),os:j(),meta_json:j().optional(),sessionId:j().optional()});z({v:he(1),visitorId:j().min(1),displayName:j(),provider:j(),iat:Q(),exp:Q()});const wde=z({visitorId:j(),displayName:j(),avatarUrl:j().optional(),provider:j(),firstSeen:Q(),lastSeen:Q()});z({visitors:xe(wde)});z({type:he("web:open"),url:j().min(1),expiresAt:Q()});z({ticket:j().min(1)}).strict();z({token:j().min(1),expiresAt:Q()});const _de=/<system-reminder>此消息来自飞书群成员 (.+?)<\/system-reminder>\s*$/,SH=/<system-reminder>此消息来自 (owner|guest):(.+?)<\/system-reminder>\s*$/,kH="clawd-dispatch-task",CH="clawd-dispatch-result",NO=120;function Sde(e){if(!e)return null;const t=e.search(jO(kH)),n=e.search(jO(CH));return t<0&&n<0?null:n<0?"task":t<0?"result":t<n?"task":"result"}function kde(e){if(!e)return[];const t=[];for(const n of["task","result"]){const r=n==="task"?kH:CH,s=new RegExp(`<${r}\\b([^>]*)>([\\s\\S]*?)</${r}>`,"gi");for(let i=s.exec(e);i!==null;i=s.exec(e))t.push({at:i.index,block:Cde(n,i[1]??"",i[2]??"")})}return t.sort((n,r)=>n.at-r.at).map(n=>n.block)}function Cde(e,t,n){var u;const r=Mde(t),s=aj(Rde(jk(n,"detail")??n)),i=(u=jk(n,"brief"))==null?void 0:u.trim(),o=i&&i.length>0?aj(i):Nde(s),l=r.round!==void 0?Number.parseInt(r.round,10):void 0,c=r.status;return{kind:e,dispatchId:r["dispatch-id"]??"",...r.from?{from:r.from}:{},...e==="task"&&l!==void 0&&Number.isFinite(l)?{round:l}:{},...e==="result"&&(c==="success"||c==="failure")?{status:c}:{},brief:o,briefIsDerived:!(i&&i.length>0),detail:s,filePaths:Tde(jk(n,"files"))}}function Nde(e){const t=e.split(/\n\s*\n/).map(r=>r.trim()).find(r=>r.length>0);if(!t)return"";const n=t.replace(/\s+/g," ");return n.length>NO?`${n.slice(0,NO)}…`:n}const jde="clawd-dispatch-task|clawd-dispatch-result|brief|detail|files",Ede=new RegExp(`<\\\\(\\\\*)(/?)(${jde})\\b`,"g");function Ide(e){return aj(e)}function aj(e){return e.replace(Ede,"<$1$2$3")}function jk(e,t){const n=new RegExp(`<${t}>([\\s\\S]*?)</${t}>`,"i").exec(e);return n?n[1]??"":null}function Tde(e){return e?e.split(`
|
|
96
96
|
`).map(t=>t.trim()).filter(t=>t.startsWith("- ")).map(t=>t.slice(2).trim()).filter(t=>t.length>0):[]}function Rde(e){return e.replace(/^\n/,"").replace(/\n$/,"")}function jO(e){return new RegExp(`<${e}\\b[^>]*>`,"i")}function Mde(e){const t={},n=/([a-z-]+)="([^"]*)"/gi;for(let r=n.exec(e);r!==null;r=n.exec(e))t[r[1]]=Pde(r[2]??"");return t}function Pde(e){return e.replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}/**
|
|
97
97
|
* @license lucide-react v0.577.0 - ISC
|
|
98
98
|
*
|
|
@@ -931,7 +931,7 @@ https://fb.me/react-async-component-lifecycle-hooks`)}if(typeof e.getDerivedStat
|
|
|
931
931
|
`)}var aS="Tabs",[$Je]=ya(aS,[s_]),mee=s_(),[LJe,g3]=$Je(aS),gee=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:s,defaultValue:i,orientation:o="horizontal",dir:l,activationMode:c="automatic",...u}=e,d=GT(l),[h,f]=ed({prop:r,onChange:s,defaultProp:i??"",caller:aS});return a.jsx(LJe,{scope:n,baseId:_o(),value:h,onValueChange:f,orientation:o,dir:d,activationMode:c,children:a.jsx(hn.div,{dir:d,"data-orientation":o,...u,ref:t})})});gee.displayName=aS;var xee="TabsList",vee=p.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...s}=e,i=g3(xee,n),o=mee(n);return a.jsx(uV,{asChild:!0,...o,orientation:i.orientation,dir:i.dir,loop:r,children:a.jsx(hn.div,{role:"tablist","aria-orientation":i.orientation,...s,ref:t})})});vee.displayName=xee;var yee="TabsTrigger",bee=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:s=!1,...i}=e,o=g3(yee,n),l=mee(n),c=See(o.baseId,r),u=kee(o.baseId,r),d=r===o.value;return a.jsx(dV,{asChild:!0,...l,focusable:!s,active:d,children:a.jsx(hn.button,{type:"button",role:"tab","aria-selected":d,"aria-controls":u,"data-state":d?"active":"inactive","data-disabled":s?"":void 0,disabled:s,id:c,...i,ref:t,onMouseDown:ot(e.onMouseDown,h=>{!s&&h.button===0&&h.ctrlKey===!1?o.onValueChange(r):h.preventDefault()}),onKeyDown:ot(e.onKeyDown,h=>{[" ","Enter"].includes(h.key)&&o.onValueChange(r)}),onFocus:ot(e.onFocus,()=>{const h=o.activationMode!=="manual";!d&&!s&&h&&o.onValueChange(r)})})})});bee.displayName=yee;var wee="TabsContent",_ee=p.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:s,children:i,...o}=e,l=g3(wee,n),c=See(l.baseId,r),u=kee(l.baseId,r),d=r===l.value,h=p.useRef(d);return p.useEffect(()=>{const f=requestAnimationFrame(()=>h.current=!1);return()=>cancelAnimationFrame(f)},[]),a.jsx(Xi,{present:s||d,children:({present:f})=>a.jsx(hn.div,{"data-state":d?"active":"inactive","data-orientation":l.orientation,role:"tabpanel","aria-labelledby":c,hidden:!f,id:u,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:h.current?"0s":void 0},children:f&&i})})});_ee.displayName=wee;function See(e,t){return`${e}-trigger-${t}`}function kee(e,t){return`${e}-content-${t}`}var FJe=gee,Cee=vee,Nee=bee,jee=_ee;const BJe=FJe,Eee=p.forwardRef(({className:e,...t},n)=>a.jsx(Cee,{ref:n,className:ee("inline-flex items-center gap-1 border-b border-border bg-transparent",e),...t}));Eee.displayName=Cee.displayName;const eb=p.forwardRef(({className:e,...t},n)=>a.jsx(Nee,{ref:n,className:ee("inline-flex items-center justify-center whitespace-nowrap px-3 py-2 text-[13px] font-medium","text-text-300 hover:text-text-100 transition-colors","border-b-2 border-transparent -mb-px","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent","disabled:pointer-events-none disabled:opacity-50","data-[state=active]:text-text-100 data-[state=active]:border-accent",e),...t}));eb.displayName=Nee.displayName;const zJe=p.forwardRef(({className:e,...t},n)=>a.jsx(jee,{ref:n,className:ee("flex-1 focus-visible:outline-none",e),...t}));zJe.displayName=jee.displayName;function Iee({state:e,className:t="w-4 h-4"}){return e==="merged"?a.jsx(im,{className:`${t} text-purple-500 shrink-0`}):e==="draft"?a.jsx(Jhe,{className:`${t} text-text-400 shrink-0`}):a.jsx(cT,{className:`${t} text-emerald-600 shrink-0`})}function Tee({rollup:e}){if(e==="none")return null;const t=e==="failure"?"bg-red-500":e==="pending"?"bg-amber-400 animate-pulse":"bg-emerald-500";return a.jsx("span",{className:`inline-block w-[7px] h-[7px] rounded-full ${t}`})}function Ree({additions:e,deletions:t}){return a.jsxs("span",{className:"font-mono text-[11px] tabular-nums",children:[a.jsxs("span",{className:"text-emerald-600",children:["+",e.toLocaleString()]})," ",a.jsxs("span",{className:"text-red-500",children:["−",t.toLocaleString()]})]})}function Q0(e){return`${e.owner}/${e.repo}#${e.number}`}function aB({pr:e,selected:t,onClick:n}){return a.jsx("button",{type:"button",onClick:n,className:["w-full text-left px-3 py-2.5 rounded-lg transition-colors cursor-pointer border",t?"bg-bg-200 border-border":"border-transparent hover:bg-bg-200/60"].join(" "),children:a.jsxs("div",{className:"flex items-start gap-2.5",children:[a.jsx(Iee,{state:e.state,className:"w-4 h-4 mt-[3px]"}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-baseline gap-2",children:[a.jsx("span",{className:"text-[13px] text-text-100 font-medium truncate leading-snug",children:e.title}),a.jsx("span",{className:"ml-auto text-[11px] text-text-500 shrink-0 tabular-nums",children:j_(e.updatedAt)})]}),a.jsxs("div",{className:"flex items-center gap-1.5 mt-1 text-[11px] text-text-400 min-w-0",children:[a.jsx(Tee,{rollup:e.checksRollup}),a.jsxs("span",{className:"shrink-0 tabular-nums","data-testid":"pr-list-number",children:["#",e.number]}),a.jsxs("span",{className:"truncate",children:[e.repo,a.jsxs("span",{className:"text-text-500",children:[" · ",e.headRef]})]}),a.jsx("span",{className:"ml-auto shrink-0",children:a.jsx(Ree,{additions:e.additions,deletions:e.deletions})})]})]})]})})}function lB({title:e,count:t}){return a.jsxs("div",{className:"flex items-center px-3 pb-1.5 pt-1",children:[a.jsx("span",{className:"text-[11px] font-medium text-text-400 uppercase tracking-wide",children:e}),a.jsx("span",{className:"ml-1.5 text-[11px] text-text-500 tabular-nums",children:t})]})}function HJe(e){const{tab:t,query:n}=e,r=l=>n.trim()===""||(l.title+l.repo+l.headRef).toLowerCase().includes(n.toLowerCase()),s=t==="mine"?[]:e.reviewRequested.filter(r),i=t==="reviewing"?[]:e.created.filter(r),o=s.length===0&&i.length===0;return a.jsxs("div",{className:"w-[clamp(360px,26vw,500px)] shrink-0 border-r border-border flex flex-col bg-bg-50",children:[a.jsxs("div",{className:"px-3 pt-2 shrink-0",children:[a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(BJe,{value:t,onValueChange:l=>e.onTabChange(l),className:"flex-1 min-w-0",children:a.jsxs(Eee,{className:"w-full",children:[a.jsx(eb,{value:"all",children:"全部"}),a.jsx(eb,{value:"reviewing",children:"正在审查"}),a.jsx(eb,{value:"mine",children:"由我创建"})]})}),a.jsx("button",{type:"button",onClick:()=>{e.loading||e.onRefresh()},disabled:e.loading,"aria-label":"刷新列表",title:"刷新",className:"inline-flex items-center justify-center h-7 w-7 rounded-md text-text-400 hover:bg-bg-200 hover:text-text-100 disabled:opacity-50 transition-colors cursor-pointer shrink-0",children:a.jsx(No,{className:["w-3.5 h-3.5",e.loading?"animate-spin":""].join(" ")})})]}),a.jsxs("div",{className:"relative mt-2.5 mb-1",children:[a.jsx(ui,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-text-400"}),a.jsx(br,{value:n,onChange:l=>e.onQueryChange(l.target.value),placeholder:"搜索 Pull Request",className:"pl-8 h-8 text-[13px]"})]})]}),a.jsxs("div",{className:"flex-1 overflow-auto px-2 py-2 space-y-3",children:[s.length>0&&a.jsxs("div",{children:[a.jsx(lB,{title:"请求评审",count:s.length}),a.jsx("div",{className:"space-y-px",children:s.map(l=>a.jsx(aB,{pr:l,selected:Q0(l)===e.selectedKey,onClick:()=>e.onSelect(l)},Q0(l)))})]}),i.length>0&&a.jsxs("div",{children:[a.jsx(lB,{title:"由我创建",count:i.length}),a.jsx("div",{className:"space-y-px",children:i.map(l=>a.jsx(aB,{pr:l,selected:Q0(l)===e.selectedKey,onClick:()=>e.onSelect(l)},Q0(l)))})]}),o&&a.jsx("div",{className:"px-3 py-12 text-center text-[13px] text-text-400",children:"没有匹配的 Pull Request"})]})]})}function cB({trigger:e,title:t,prompt:n,personas:r,onEnsurePersonas:s,busy:i,onPick:o,testId:l,open:c,onOpenChange:u}){return a.jsxs(I_,{...c!==void 0?{open:c}:{},onOpenChange:d=>{d&&r===null&&s(),u==null||u(d)},children:[a.jsx(T_,{asChild:!0,children:e}),a.jsx(zx,{align:"end",className:"w-[380px] p-0","data-testid":l,children:a.jsxs("div",{className:"flex flex-col",children:[a.jsx("div",{className:"px-4 pt-3 pb-2 text-[12px] font-medium text-text-100",children:t}),a.jsx("div",{className:"px-4 pb-2",children:a.jsx("pre",{className:"text-[11px] leading-relaxed bg-bg-200 rounded-md p-2.5 whitespace-pre-wrap text-text-300 max-h-[150px] overflow-auto font-mono",children:n})}),a.jsxs("div",{className:"border-t border-border p-1.5",children:[r===null&&a.jsx("div",{className:"px-2.5 py-2 text-[12px] text-text-400",children:"加载 persona…"}),r!==null&&r.length===0&&a.jsx("div",{className:"px-2.5 py-2 text-[12px] text-text-400",children:"没有可用的 persona"}),(r??[]).map(d=>a.jsx("button",{type:"button",disabled:i,onClick:()=>o(d.personaId),className:"w-full text-left text-[13px] px-2.5 py-2 rounded-md hover:bg-bg-200 text-text-100 cursor-pointer disabled:opacity-50",children:d.label||d.personaId},d.personaId))]})]})})]})}function Zp({label:e,children:t}){return a.jsxs("div",{className:"flex gap-4 py-2 border-b border-border/60 last:border-b-0",children:[a.jsx("span",{className:"w-[56px] shrink-0 text-[12px] text-text-400 leading-6",children:e}),a.jsx("div",{className:"flex-1 min-w-0 text-[13px] text-text-100 leading-6",children:t})]})}function UJe(e){const{api:t,detail:n}=e,[r,s]=p.useState(!1),[i,o]=p.useState(null),[l,c]=p.useState(null),[u,d]=p.useState(!1),[h,f]=p.useState(""),[m,g]=p.useState(null),[x,b]=p.useState(null),[y,v]=p.useState(!1),[w,_]=p.useState(!1),S=Xm(n);p.useEffect(()=>{s(!1),o(null),c(null),f(""),b(null),v(!1),_(!1)},[S]);const k=`https://github.com/${n.owner}/${n.repo}/pull/${n.number}`,C={owner:n.owner,repo:n.repo,number:n.number},N=n.checksRollup==="success"||n.checksRollup==="none",T=n.mergeable==="mergeable"&&n.state==="open"&&N,E=()=>{t.personaList().then(L=>g(L.personas??[])).catch(L=>{o(L instanceof Error?L.message:String(L))})},R=()=>{m===null&&E(),v(!0)},O=async L=>{d(!0),o(null);try{await L()}catch(D){o(D instanceof Error?D.message:String(D))}finally{d(!1)}},P=()=>{h.trim()===""||u||O(async()=>{await t.githubPrComment({...C,body:h.trim()}),f(""),e.onRefreshDetail()})},$=xi(P),F=()=>O(async()=>{const L=await t.githubPrMerge({...C,expectedHeadSha:n.headSha});s(!1),L.merged?(c("已合并"),e.onRefreshList()):c("PR 有新提交,已刷新详情,请确认后再合并"),e.onRefreshDetail()}),B=n.checksRollup==="failure"?"text-red-500":n.checksRollup==="pending"?"text-amber-500":"text-emerald-600",W=n.checksRollup==="failure"?`${n.checks.filter(L=>L.conclusion==="failure").length} 项失败`:n.checksRollup==="pending"?"进行中":n.checksRollup==="none"?"未配置":"全部通过";return a.jsxs("div",{className:"flex flex-col h-full min-w-0 bg-bg-100",children:[a.jsxs("div",{className:"flex items-center gap-2 px-6 h-[52px] border-b border-border shrink-0",children:[a.jsx(Iee,{state:n.state,className:"w-4 h-4"}),a.jsxs("span",{className:"text-[13px] text-text-300 truncate",children:[n.owner,"/",n.repo,a.jsxs("span",{className:"tabular-nums","data-testid":"pr-detail-number",children:[" ","#",n.number]})]}),a.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[a.jsx(Be,{variant:"ghost",size:"sm",asChild:!0,children:a.jsxs("a",{href:`${k}/files`,target:"_blank",rel:"noreferrer",children:[a.jsx(Ur,{className:"w-3.5 h-3.5 mr-1.5"})," 代码"]})}),a.jsx(cB,{testId:"pr-detail-chat-popover",open:w,onOpenChange:_,trigger:a.jsxs(Be,{variant:"outline",size:"sm",children:[a.jsx(zH,{className:"w-3.5 h-3.5 mr-1.5"})," 聊天"]}),title:"选择 persona 处理此 PR",prompt:iB(n),personas:m,onEnsurePersonas:E,busy:u,onPick:L=>{_(!1),O(()=>e.onOpenChat(L,iB(n),`PR #${n.number}`))}}),r?a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(Be,{size:"sm",disabled:u,onClick:()=>void F(),children:"确认 squash 合并"}),a.jsx(Be,{variant:"ghost",size:"sm",onClick:()=>s(!1),children:"取消"})]}):n.mergeable==="conflicting"?a.jsx(di,{delayDuration:200,children:a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:a.jsx("span",{className:"inline-flex","data-testid":"pr-detail-merge-tooltip-anchor",children:a.jsxs(Be,{size:"sm",disabled:!0,children:[a.jsx(im,{className:"w-3.5 h-3.5 mr-1.5"}),"合并"]})})}),a.jsx(gi,{side:"bottom",align:"end",className:"px-2.5 py-1.5",children:a.jsxs("button",{type:"button","data-testid":"pr-detail-merge-conflict-hint",onClick:R,className:"inline-flex items-center gap-1 text-[12px] font-medium text-red-500 cursor-pointer",children:[a.jsx(In,{className:"w-3.5 h-3.5 shrink-0"}),"有合并冲突",a.jsx("span",{className:"text-red-500/70",children:"·"}),a.jsx("span",{className:"underline decoration-red-500/40 underline-offset-2",children:"点击聊天修复"})]})})]})}):a.jsxs(Be,{size:"sm",disabled:!T||u,onClick:()=>s(!0),children:[a.jsx(im,{className:"w-3.5 h-3.5 mr-1.5"}),n.state==="merged"?"已合并":"合并"]})]})]}),a.jsx("div",{className:"flex-1 overflow-auto",children:a.jsxs("div",{className:"max-w-[880px] mx-auto px-6 py-6",children:[a.jsx("h1",{className:"text-[20px] font-semibold text-text-100 leading-snug tracking-[-0.01em]",children:n.title}),a.jsxs("div",{className:"mt-1.5 text-[12px] text-text-400",children:[n.author," 创建 · 更新于 ",j_(n.updatedAt)]}),i&&a.jsxs("div",{className:"mt-4 flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/25 px-3.5 py-2.5 text-[13px] text-red-500",children:[a.jsx(Jt,{className:"w-4 h-4 shrink-0"}),a.jsx("span",{className:"min-w-0 break-all",children:i}),a.jsx("button",{type:"button",className:"ml-auto shrink-0 text-[12px] underline cursor-pointer",onClick:()=>o(null),children:"知道了"})]}),l&&a.jsxs("div",{className:"mt-4 flex items-center gap-2 rounded-lg bg-purple-500/10 border border-purple-500/25 px-3.5 py-2.5 text-[13px] text-purple-600",children:[a.jsx(im,{className:"w-4 h-4 shrink-0"})," ",l]}),n.state==="merged"&&!l&&a.jsxs("div",{className:"mt-4 flex items-center gap-2 rounded-lg bg-purple-500/10 border border-purple-500/25 px-3.5 py-2.5 text-[13px] text-purple-600",children:[a.jsx(im,{className:"w-4 h-4"})," 该拉取请求已合并"]}),a.jsxs("div",{className:"mt-5 rounded-xl border border-border bg-bg-100 px-4",children:[a.jsx(Zp,{label:"分支",children:a.jsxs("span",{className:"inline-flex items-center gap-1.5 flex-wrap",children:[a.jsx("code",{className:"bg-bg-200 rounded-md px-1.5 py-0.5 text-[12px] font-mono",children:n.headRef}),a.jsx("span",{className:"text-text-400",children:"→"}),a.jsx("code",{className:"bg-bg-200 rounded-md px-1.5 py-0.5 text-[12px] font-mono",children:n.baseRef}),a.jsx("span",{className:"ml-1",children:a.jsx(Ree,{additions:n.additions,deletions:n.deletions})})]})}),a.jsx(Zp,{label:"审查者",children:a.jsxs("span",{className:"inline-flex items-center gap-1.5 flex-wrap",children:[n.reviewers.length===0&&a.jsx("span",{className:"text-text-400",children:"尚无"}),n.reviewers.map(L=>a.jsx("span",{className:"bg-bg-200 rounded-full px-2.5 py-0.5 text-[12px] text-text-200",children:L},L)),a.jsxs(I_,{onOpenChange:L=>{L&&x===null&&t.githubCollaborators({owner:n.owner,repo:n.repo}).then(D=>b(D.logins)).catch(D=>{b([]),o(D instanceof Error?D.message:String(D))})},children:[a.jsx(T_,{asChild:!0,children:a.jsx("button",{type:"button",className:"text-[12px] text-accent hover:underline cursor-pointer",children:"+ 请求"})}),a.jsxs(zx,{align:"start",className:"w-[220px] p-1.5",children:[a.jsx("div",{className:"text-[11px] text-text-400 px-2 pt-1 pb-1.5",children:"请求审查"}),x===null&&a.jsx("div",{className:"px-2 py-1.5 text-[12px] text-text-400",children:"加载中…"}),(x??[]).filter(L=>!n.reviewers.includes(L)).map(L=>a.jsx("button",{type:"button",disabled:u,onClick:()=>void O(async()=>{await t.githubPrRequestReviewers({...C,reviewers:[L]}),e.onRefreshDetail()}),className:"w-full text-left text-[13px] px-2 py-1.5 rounded-md hover:bg-bg-200 text-text-100 cursor-pointer disabled:opacity-50",children:L},L))]})]})]})}),a.jsx(Zp,{label:"评论",children:n.commentCount===0?a.jsx("span",{className:"text-text-400",children:"无评论"}):`${n.commentCount} 条`}),a.jsx(Zp,{label:"检查",children:a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsxs("span",{className:`inline-flex items-center gap-1.5 font-medium ${B}`,children:[a.jsx(Tee,{rollup:n.checksRollup}),W]}),n.checks.length>0&&a.jsx("div",{className:"flex flex-col gap-0.5",children:n.checks.map(L=>a.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[12px] text-text-300",children:[L.conclusion==="success"&&a.jsx(Xt,{className:"w-3.5 h-3.5 text-emerald-600"}),L.conclusion==="failure"&&a.jsx(Jt,{className:"w-3.5 h-3.5 text-red-500"}),L.conclusion==="pending"&&a.jsx(No,{className:"w-3.5 h-3.5 text-amber-500 animate-spin [animation-duration:2.5s]"}),L.name]},L.name))})]})}),a.jsx(Zp,{label:"状态",children:n.state==="merged"||n.state==="closed"?a.jsx("span",{className:n.state==="merged"?"text-purple-600":"text-text-400",children:n.state==="merged"?"已合并":"已关闭"}):a.jsxs("span",{className:"inline-flex items-center gap-2",children:[a.jsxs(Gr,{children:[a.jsx(Yr,{asChild:!0,children:a.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 text-[13px] text-text-100 hover:text-accent cursor-pointer",children:[a.jsx(ghe,{className:"w-3.5 h-3.5 text-emerald-600"}),n.state==="draft"?"草稿":"可供审查",a.jsx(Qt,{className:"w-3 h-3 text-text-400"})]})}),a.jsxs(Pr,{align:"start",children:[a.jsx(Et,{disabled:n.state==="open",onSelect:()=>void O(async()=>{await t.githubPrSetReady({...C,ready:!0}),e.onRefreshDetail()}),children:"可供审查"}),a.jsx(Et,{disabled:n.state==="draft",onSelect:()=>void O(async()=>{await t.githubPrSetReady({...C,ready:!1}),e.onRefreshDetail()}),children:"转为草稿"})]})]}),n.mergeable==="conflicting"&&a.jsx(cB,{testId:"pr-detail-conflict-popover",open:y,onOpenChange:v,trigger:a.jsxs("button",{type:"button","data-testid":"pr-detail-conflict-fix",title:"选 persona 开会话解决这个 PR 的冲突",className:"inline-flex items-center gap-1 rounded-md bg-red-500/10 px-2 py-0.5 text-[12px] font-medium text-red-500 hover:bg-red-500/20 cursor-pointer transition-colors",children:[a.jsx(In,{className:"w-3.5 h-3.5 shrink-0"}),"有合并冲突",a.jsx("span",{className:"text-red-500/70",children:"·"}),a.jsx("span",{className:"underline decoration-red-500/40 underline-offset-2",children:"点击聊天修复"})]}),title:"选择 persona 解决此 PR 的冲突",prompt:oB(n),personas:m,onEnsurePersonas:E,busy:u,onPick:L=>{v(!1),O(()=>e.onOpenChat(L,oB(n),`PR #${n.number} 冲突`))}})]})})]}),a.jsxs("div",{className:"mt-6",children:[a.jsx("div",{className:"text-[12px] font-medium text-text-400 mb-2.5",children:"描述"}),n.body.trim()===""?a.jsx("div",{className:"text-[13px] text-text-400",children:"(无描述)"}):a.jsx("div",{className:"assistant-markdown text-[13px] leading-relaxed break-words",children:a.jsx(Bu,{components:ol,children:n.body})})]})]})}),a.jsx("div",{className:"border-t border-border px-6 py-3.5 shrink-0",children:a.jsxs("div",{className:"max-w-[880px] mx-auto flex items-end gap-2",children:[a.jsx(br,{value:h,placeholder:"留下评论",onChange:L=>f(L.target.value),className:"flex-1","data-testid":"pr-comment-input",...$}),a.jsx(Be,{size:"sm",variant:"outline",disabled:h.trim()===""||u,onClick:P,children:"发送"})]})})]})}function WJe({kind:e,onRecheck:t,checking:n}){return a.jsx("div",{className:"flex h-full bg-bg-100 items-center justify-center",children:a.jsxs("div",{className:"max-w-[400px] text-center px-6",children:[a.jsx("div",{className:"mx-auto w-12 h-12 rounded-xl bg-bg-200 flex items-center justify-center",children:a.jsx(cT,{className:"w-6 h-6 text-text-400"})}),a.jsx("h2",{className:"mt-4 text-[16px] font-semibold text-text-100",children:e==="missing"?"需要安装 GitHub CLI":"还没关联 GitHub"}),a.jsx("p",{className:"mt-2 text-[13px] text-text-300 leading-relaxed",children:e==="missing"?"PR 收件箱通过本机 gh CLI 访问 GitHub,凭据用你在 clawd 关联的 GitHub 账号。":"PR 收件箱用你在 clawd 关联的 GitHub 账号(设置 → 账号里的那份)。在这里关联一次就行。"}),e==="missing"?a.jsx("pre",{className:"mt-4 bg-bg-200 rounded-lg px-4 py-3 text-[13px] font-mono text-text-100 text-left",children:"brew install gh"}):a.jsx("div",{className:"mt-4 text-left",children:a.jsx(fI,{onAuthorized:t})}),a.jsxs(Be,{variant:"outline",size:"sm",className:"mt-4",disabled:n,onClick:t,children:[a.jsx(No,{className:["w-3.5 h-3.5 mr-1.5",n?"animate-spin":""].join(" ")}),"重新检测"]})]})})}function VJe({api:e,focused:t,onOpenChat:n}){const[r,s]=p.useState(null),[i,o]=p.useState(!0),[l,c]=p.useState(null),u=async()=>{o(!0),c(null);try{s(await e.githubStatus())}catch(C){c(C instanceof Error?C.message:String(C))}finally{o(!1)}};p.useEffect(()=>{u()},[e]);const d=(r==null?void 0:r.installed)===!0&&r.authenticated===!0,h=OJe(e,d),[f,m]=p.useState("all"),[g,x]=p.useState(""),[b,y]=p.useState(null),v=AJe(e,b,t),w=p.useRef(t);p.useEffect(()=>{!w.current&&t&&d&&!h.loading&&h.refresh(),w.current=t},[t,d,h.loading,h.refresh]);const _=h.reviewRequested[0]??h.created[0];p.useEffect(()=>{b===null&&_&&y({owner:_.owner,repo:_.repo,number:_.number})},[b,_]);const S=h.error??v.error;if(p.useEffect(()=>{S&&u()},[S]),!d)return i&&r===null?a.jsx("div",{className:"p-6 text-text-300 text-[13px]",children:"检测 GitHub CLI…"}):l?a.jsxs("div",{className:"p-6 text-[13px]",children:[a.jsxs("span",{className:"text-red-500",children:["gh 探测失败:",l]}),a.jsx(Be,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>void u(),children:"重试"})]}):a.jsx(WJe,{kind:r!=null&&r.installed?"unauthenticated":"missing",onRecheck:()=>void u(),checking:i});const k=b?Xm(b):null;return a.jsxs("div",{className:"flex h-full w-full min-w-0 bg-bg-100 text-text-100 overflow-hidden",children:[a.jsx(HJe,{created:h.created,reviewRequested:h.reviewRequested,tab:f,onTabChange:m,query:g,onQueryChange:x,selectedKey:k,onSelect:C=>y({owner:C.owner,repo:C.repo,number:C.number}),loading:h.loading,onRefresh:()=>void h.refresh()}),a.jsx("div",{className:"flex-1 min-w-0",children:h.error?a.jsxs("div",{className:"p-6 text-[13px]",children:[a.jsxs("span",{className:"text-red-500",children:["加载 PR 失败:",h.error]}),a.jsx(Be,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>void h.refresh(),children:"重试"})]}):v.detail?a.jsx(UJe,{api:e,detail:v.detail,onRefreshDetail:()=>void v.refresh(),onRefreshList:()=>void h.refresh(),onOpenChat:n}):v.error?a.jsxs("div",{className:"p-6 text-[13px]",children:[a.jsxs("span",{className:"text-red-500",children:["加载详情失败:",v.error]}),a.jsx(Be,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>void v.refresh(),children:"重试"})]}):b&&v.loading?a.jsx("div",{className:"p-6 text-text-300 text-[13px]",children:"加载详情…"}):b?a.jsx("div",{className:"p-6 text-[13px] text-text-400",children:"该 Pull Request 不存在或不可见(可能已被删除)。请在列表刷新后重新选择。"}):a.jsx("div",{className:"h-full flex items-center justify-center text-text-400 text-[13px]",children:"选择一个 Pull Request 查看详情"})})]})}const uB=Symbol("never-ran");function qJe(e,t,n){const[r,s]=p.useState(null),[i,o]=p.useState([]),[l,c]=p.useState(t!==null),[u,d]=p.useState(null),h=p.useCallback(async()=>{if(!t){s(null),o([]),c(!1);return}c(!0),d(null);try{const m=await new qt(e).topicGet({topicId:t});s((m==null?void 0:m.topic)??null),o(Array.isArray(m==null?void 0:m.lines)?m.lines:[])}catch(m){d(m instanceof Error?m.message:String(m))}finally{c(!1)}},[e,t]),f=p.useRef(uB);return p.useEffect(()=>{const m=f.current===void 0&&n!==void 0,g=f.current===uB;f.current=n,(g||!m)&&h()},[h,n]),p.useEffect(()=>{if(!(!e||!t))return e.on("channel:changed",m=>{(m==null?void 0:m.topicId)===t&&h()})},[e,t,h]),{topic:r,lines:i,loading:l,error:u,refresh:h}}const KJe={pending:"等您拍板","owner-resolved":"您已拍板","master-handled":"Master 代办"},GJe={pending:"bg-warning/15 text-warning","owner-resolved":"bg-success-dim text-success","master-handled":"bg-bg-200 text-text-400"},YJe=["代老板确认","需要老板拍板","按老板决定"];function Mee(e){for(const t of YJe){const n=e.replace(new RegExp(`^\\s*${t}(?:\\s*[::]|\\s+)\\s*`),"");if(n&&n!==e)return n}return e}function XJe(e){const t=new Map;for(const s of e)s.decision.id&&t.set(s.decision.id,s);const n=new Map,r=new Set;for(const s of e){const i=s.decision.resolves?t.get(s.decision.resolves):void 0;!i||i===s||n.has(i)||(n.set(i,s),r.add(s))}return e.filter(s=>!r.has(s)).map(s=>({asked:s,answer:n.get(s)}))}function ZJe(e){var n;const t=((n=e.answer)==null?void 0:n.decision)??e.asked.decision;return t.status===cH?"pending":t.type===lH?"owner-resolved":"master-handled"}function c2(e){return a.jsxs("div",{"data-decision-field":e.field,className:"flex gap-2.5",children:[a.jsx("dt",{"data-decision-label":e.field,className:`mt-px h-fit shrink-0 rounded px-1.5 py-0.5 text-[11px] font-medium ${e.tone}`,children:e.label}),a.jsx("dd",{"data-decision-body":!0,className:"min-w-0 flex-1 text-[13px] leading-relaxed text-text-100",children:e.text})]})}function QJe({row:e,index:t,onOpenChat:n}){const[r,s]=p.useState(!1),{asked:i,answer:o}=e,l=ZJe(e),c=l==="pending",u=`decision-detail-${t}`;return a.jsxs("li",{className:"border-b border-border last:border-b-0",children:[a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsxs("button",{type:"button","data-testid":`decision-row-${t}`,"data-decision-status":(o==null?void 0:o.decision.status)??i.decision.status,"data-decision-state":l,onClick:()=>s(!r),"aria-expanded":r,"aria-controls":u,className:"flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded px-2 py-2 text-left hover:bg-text-100/5",children:[a.jsx(Qt,{className:`size-3 shrink-0 text-text-400 transition-transform ${r?"":"-rotate-90"}`}),a.jsx("span",{"data-decision-title":!0,className:`min-w-0 truncate text-[13px] ${c?"font-medium text-text-100":"text-text-200"}`,children:Mee(i.action)}),a.jsx("span",{"data-decision-state-tag":l,className:`shrink-0 rounded-full px-2 py-0.5 text-[11px] font-medium ${GJe[l]}`,children:KJe[l]}),a.jsx("span",{className:"flex-1"})]}),a.jsx("div",{className:"shrink-0 pr-2",children:c&&n&&a.jsxs("button",{type:"button","data-testid":`decision-open-chat-${t}`,onClick:n,className:"inline-flex cursor-pointer items-center gap-1 rounded-md border border-warning/40 px-2 py-1 text-[11px] font-medium text-warning transition-colors hover:bg-warning/15 hover:border-warning/60",children:[a.jsx(KH,{className:"size-3"}),"去回复"]})})]}),r&&a.jsxs("div",{id:u,"data-decision-detail":!0,className:"px-2 pb-3 pl-7",children:[a.jsxs("dl",{className:"space-y-1.5",children:[a.jsx(c2,{field:"question",label:"问题",tone:"bg-text-100/10 text-text-100",text:i.decision.question}),a.jsx(c2,{field:"recommendation",label:"建议",tone:"bg-success-dim text-success",text:i.decision.recommendation}),o&&a.jsx(c2,{field:"conclusion",label:"结论",tone:"bg-warning-dim text-warning",text:o.decision.recommendation})]}),a.jsxs("div",{"data-decision-field":"reason",className:"mt-2 rounded border border-border px-2.5 py-2 text-[12px] leading-relaxed text-text-300",children:[i.reason,o&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mx-1.5 text-text-400",children:"·"}),o.reason]})]}),a.jsxs("div",{"data-testid":`decision-meta-${t}`,className:"mt-2 text-[11px] text-text-400",children:[a.jsx("span",{className:"font-mono",children:i.at.slice(11,19)||i.at}),o&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mx-1",children:"→"}),a.jsx("span",{className:"font-mono",children:o.at.slice(11,19)||o.at})]}),a.jsx("span",{className:"mx-1.5",children:"·"}),i.actor,i.target&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"mx-1.5",children:"·"}),a.jsx("span",{className:"font-mono",children:i.target})]})]})]})]})}function JJe({activity:e,onOpenChat:t}){const n=XJe(e.filter(r=>!!r.decision));return n.length===0?a.jsx("div",{"data-testid":"topic-activity-empty",className:"py-8 text-center text-[12px] text-text-400",children:"目前没有需要复盘或拍板的决策"}):a.jsx("ul",{"data-testid":"topic-activity",className:"overflow-hidden rounded-lg border border-border bg-surface-card",children:n.map((r,s)=>a.jsx(QJe,{row:r,index:s,onOpenChat:t},`${r.asked.at}-${s}`))})}const eet=60;function tet(e,t){const n=e.replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t)}…`:n}function net(e,t={}){const n=t.questionMaxChars??eet,r=e.filter(c=>c.answer.trim().length>0);if(r.length===0)return"";const s=r.map((c,u)=>[`${t.includeIds&&c.id?`【${u+1} · ${c.id}】`:`【${u+1}】`}${c.title}`,`- 原问:${tet(c.question,n)}`,`- 我的答复:${c.answer.trim()}`].join(`
|
|
932
932
|
`)),i=`以下是我对 ${r.length} 条待拍板决策的答复:`,o=e.length-r.length,l=o>0?[`另有 ${o} 条我这次没答,先放着。`]:[];return[i,...s,...l].join(`
|
|
933
933
|
|
|
934
|
-
`)}const pI=new Map;function J0(e){var t;return((t=e.decision)==null?void 0:t.id)??e.at}function mI(e){return pI.get(e)??{}}function Pee(e,t){Object.values(t).some(r=>r.trim().length>0)?pI.set(e,t):pI.delete(e)}function ret(e,t){const n={...mI(e)};for(const r of t)delete n[r];Pee(e,n)}const set="同意你的建议,按建议执行。";function iet({entries:e,titleOf:t,drafts:n,onChange:r,onSend:s,onClose:i,onCollapse:o}){const[l,c]=p.useState({}),u=m=>{var g,x;return{...(g=m.decision)!=null&&g.id?{id:m.decision.id}:{},title:t(m.action),question:((x=m.decision)==null?void 0:x.question)??"",answer:n[J0(m)]??""}},d=net(e.map(u),{includeIds:!0}),h=e.filter(m=>(n[J0(m)]??"").trim().length>0).map(J0),f=(m,g)=>r({...n,[m]:g});return a.jsxs(m_,{testid:"batch-reply-panel",children:[a.jsx(g_,{title:"批量回复",...o?{onCollapse:o}:{},collapseLabel:"collapse batch reply",collapseTitle:"收起批量回复"}),a.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[a.jsx(KH,{className:"size-3.5 shrink-0 text-warning"}),a.jsxs("span",{className:"rounded-full bg-warning/15 px-2 py-0.5 text-[11px] font-medium text-warning",children:["待回复 ",e.length," 条"]}),a.jsx("span",{className:"flex-1"}),a.jsx("button",{type:"button","data-testid":"batch-reply-close","aria-label":"返回话题入口",onClick:i,className:"cursor-pointer rounded p-1 text-text-400 hover:bg-text-100/10 hover:text-text-200",children:a.jsx(Jt,{className:"size-3.5"})})]}),a.jsx("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-3",children:e.map((m,g)=>{var v,w;const x=J0(m),b=n[x]??"",y=l[x]??!1;return a.jsxs("div",{"data-testid":`batch-reply-item-${g}`,className:"rounded-lg border border-border bg-surface-card p-3",children:[a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsxs("span",{className:"mt-px shrink-0 font-mono text-[11px] text-text-400",children:["【",g+1,"】"]}),a.jsx("span",{className:"min-w-0 flex-1 text-[13px] font-medium text-text-100",children:t(m.action)})]}),a.jsxs("dl",{className:"mt-2 space-y-1.5",children:[a.jsxs("div",{"data-decision-field":"question",className:"flex gap-2.5",children:[a.jsx("dt",{className:"mt-px h-fit shrink-0 rounded bg-text-100/10 px-1.5 py-0.5 text-[11px] font-medium text-text-100",children:"问题"}),a.jsx("dd",{className:"min-w-0 flex-1 text-[12px] leading-relaxed text-text-200",children:(v=m.decision)==null?void 0:v.question})]}),a.jsxs("div",{"data-decision-field":"recommendation",className:"flex gap-2.5",children:[a.jsx("dt",{className:"mt-px h-fit shrink-0 rounded bg-success-dim px-1.5 py-0.5 text-[11px] font-medium text-success",children:"建议"}),a.jsx("dd",{className:"min-w-0 flex-1 text-[12px] leading-relaxed text-text-200",children:(w=m.decision)==null?void 0:w.recommendation})]})]}),a.jsxs("button",{type:"button","data-testid":`batch-reply-reason-toggle-${g}`,onClick:()=>c(_=>({..._,[x]:!y})),"aria-expanded":y,"aria-controls":`batch-reply-reason-${g}`,className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[11px] text-text-400 hover:text-text-200",children:[a.jsx(Qt,{className:`size-3 transition-transform ${y?"":"-rotate-90"}`}),"理由"]}),y&&a.jsx("div",{id:`batch-reply-reason-${g}`,"data-decision-field":"reason",className:"mt-1.5 rounded border border-border px-2.5 py-2 text-[12px] leading-relaxed text-text-300",children:m.reason}),a.jsxs("div",{className:"mt-1.5 text-[11px] text-text-400",children:[m.target?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"font-mono",children:m.target}),a.jsx("span",{className:"mx-1.5",children:"·"})]}):null,a.jsx("span",{className:"font-mono",children:m.at.slice(11,16)})]}),a.jsxs("div",{className:"mt-2 flex items-start gap-2",children:[a.jsx("textarea",{"data-testid":`batch-reply-input-${g}`,value:b,onChange:_=>f(x,_.target.value),rows:2,placeholder:"您的答复…(留空 = 这条先不答)",className:"min-w-0 flex-1 resize-none rounded-md border border-border bg-bg-100 px-2 py-1.5 text-[12px] leading-relaxed text-text-100 outline-none placeholder:text-text-400 focus:border-accent"}),a.jsx("button",{type:"button","data-testid":`batch-reply-accept-${g}`,onClick:()=>f(x,set),className:"shrink-0 cursor-pointer rounded-md border border-success/40 px-2 py-1 text-[11px] font-medium text-success hover:bg-success-dim",children:"采纳建议"})]})]},x)})}),a.jsxs("div",{className:"shrink-0 border-t border-border p-3",children:[a.jsxs("details",{className:"mb-2 rounded-md border border-border px-2 py-1.5",children:[a.jsx("summary",{className:"cursor-pointer text-[11px] text-text-400",children:"预览拼接结果(发送后填进对话框的就是这段)"}),a.jsx("pre",{"data-testid":"batch-reply-preview",className:"mt-2 max-h-40 overflow-auto whitespace-pre-wrap text-[11px] leading-relaxed text-text-200",children:d||"(还没填任何一条)"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("span",{"data-testid":"batch-reply-progress",className:"text-[11px] text-text-400",children:["已填 ",h.length," / ",e.length]}),a.jsx("span",{className:"flex-1"}),a.jsxs("button",{type:"button","data-testid":"batch-reply-send",disabled:h.length===0,onClick:()=>s(d,h),className:"inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-[12px] font-medium text-accent-contrast transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-40",children:[a.jsx(Dw,{className:"size-3.5"}),"发送"]})]})]})]})}function oet({onClose:e}){return a.jsxs(m_,{testid:"batch-reply-panel",children:[a.jsx(g_,{title:"批量回复"}),a.jsx("div",{className:"p-3",children:a.jsx(dh,{testid:"batch-reply-back",icon:a.jsx(Jt,{className:"size-4"}),label:"没有待拍板的决策,返回",onClick:e})})]})}function aet({topicId:e,api:t,sessions:n,focused:r,onNewSession:s,onOpenConfig:i}){var k;const o=Yn(),[l,c]=p.useState(null),u=(k=n.find(C=>C.sessionId===l))==null?void 0:k.updatedAt,{topic:d,loading:h,error:f}=qJe(o,e,u);p.useEffect(()=>{c((d==null?void 0:d.masterSessionId)??null)},[d==null?void 0:d.masterSessionId]);const m=LR(),[g,x]=p.useState("info"),[b,y]=p.useState(()=>mI(e)),v=p.useMemo(()=>((d==null?void 0:d.activity)??[]).filter(C=>{var N;return((N=C.decision)==null?void 0:N.status)===cH&&C.decision.type===lH}),[d==null?void 0:d.activity]),w=p.useMemo(()=>({title:"话题",leadingEntries:a.jsx(dh,{testid:"topic-decisions-entry",icon:a.jsx(Cfe,{className:"w-3.5 h-3.5"}),label:"决策",...v.length>0?{meta:String(v.length)}:{},onClick:()=>x("decisions")})}),[v.length]);if(h&&!d)return a.jsx("div",{className:"p-6 text-[13px] text-text-400",children:"加载话题中…"});if(f||!d)return a.jsxs("div",{"data-testid":"topic-workspace-error",className:"p-6 text-[13px] text-text-400",children:["话题打不开:",f??"未找到该话题"]});const _=n.find(C=>C.sessionId===d.masterSessionId),S=Ww(d.title,_??null);return a.jsxs("div",{className:"flex h-full flex-col","data-testid":"topic-workspace",children:[m.container&&g!=="info"?os.createPortal(g==="batch"?v.length>0?a.jsx(iet,{entries:v,titleOf:Mee,drafts:b,onChange:C=>{y(C),Pee(e,C)},onSend:(C,N)=>{x("info"),d.masterSessionId&&eTe(d.masterSessionId,C),ret(e,N),y(mI(e))},onClose:()=>x("decisions"),...m.onCollapse?{onCollapse:m.onCollapse}:{}}):a.jsx(oet,{onClose:()=>x("decisions")}):a.jsxs(m_,{testid:"topic-decisions-panel",children:[a.jsx(g_,{title:"决策",onBack:()=>x("info"),...m.onCollapse?{onCollapse:m.onCollapse}:{},collapseTitle:"收起话题"}),a.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-3",children:a.jsx(JJe,{activity:d.activity,onOpenChat:()=>x("batch")})})]}),m.container):null,a.jsx("div",{"data-testid":"topic-workspace-header",className:"flex shrink-0 items-center gap-3 border-b border-border/60 px-4 py-2.5",children:a.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold text-text-100",title:S,children:S})}),a.jsx("div",{className:"flex min-h-0 flex-1",children:a.jsx("div",{"data-testid":"topic-workspace-chat-pane",className:"flex min-h-0 min-w-0 flex-1",children:_?a.jsx($G,{container:g==="info"?m.container:null,...m.onCollapse?{onCollapse:m.onCollapse}:{},hostExtras:w,children:a.jsx(mM,{api:t,session:_,focused:r,totalPanes:1,onFocus:()=>{},onClose:()=>{},onNewSession:s,onOpenConfig:i,hideHeader:!0})}):a.jsxs("div",{"data-testid":"topic-workspace-no-session",className:"p-6 text-[13px] text-text-400",children:["这个话题的 Master 会话(",d.masterSessionId,")不在当前会话列表里 —— 可能还没同步过来,或已被删除。"]})})})]})}function cet(e){const t=e.focused?"":"hidden";return a.jsx("div",{className:["flex flex-col h-full w-full absolute inset-0",t].join(" "),children:a.jsx(STe,{enabled:e.focused,children:uet(e)})})}function uet(e){var n;const{tab:t}=e;switch(t.kind){case"session":{const r=e.sessions.find(s=>s.sessionId===t.sid);if(!r)return null;if(r.originOwnerPrincipalId){const s=e.clientPool.getRemoteForDevice(r.originOwnerPrincipalId);return s?a.jsx(ZDe,{client:s,session:r,remoteSessions:e.remoteSessionsByOwnerId.get(r.originOwnerPrincipalId)??[],hasLoadedForOwner:e.remoteSessionsByOwnerId.has(r.originOwnerPrincipalId),focused:e.focused,totalPanes:1,onFocus:()=>{},onClose:()=>{},...e.onMirrorOrphan?{onMirrorOrphan:e.onMirrorOrphan}:{}}):null}return a.jsx(mM,{api:e.api,session:r,focused:e.focused,totalPanes:1,onFocus:()=>{},onClose:()=>{},onNewSession:s=>e.onNewSession(s),onOpenConfig:e.onOpenMobileConfig,onFork:s=>e.onFork(r,s)})}case"dm":{const r=e.contacts.find(o=>o.deviceId===t.peerDeviceId),s=r||(n=e.visitorContacts)==null?void 0:n.find(o=>o.deviceId===t.peerDeviceId),i=r??s;return!i||!e.myOwnerPrincipalId?a.jsx(tW,{api:e.api,onSelect:e.onSelectCwdForNew}):a.jsx(xDe,{contact:i,im:e.im,selfPrincipalId:e.myOwnerPrincipalId,selfDisplayName:e.myOwnerDisplayName,readOnly:s!==void 0})}case"topic":return a.jsx(aet,{topicId:t.topicId,api:e.api,sessions:e.sessions,focused:e.focused,onNewSession:e.onNewSession,onOpenConfig:e.onOpenMobileConfig});case"ext":return a.jsx(SDe,{client:e.client,extId:t.extId,updateInfo:e.extensionUpdateInfo,onApplyUpdate:e.onApplyExtensionUpdate});case"shift":return a.jsx(PJe,{api:e.api,sessions:e.sessions,focused:e.focused});case"prs":return a.jsx(VJe,{api:e.api,focused:e.focused,onOpenChat:e.onOpenPrChat});case"exts":return a.jsx(a.Fragment,{children:e.extensionsListNode??null});case"landing":return a.jsx(a.Fragment,{children:e.landingNode??null});case"deploy":return a.jsx(nDe,{personaId:t.personaId,api:e.api,...e.cloud?{cloud:e.cloud}:{}});case"deploy-history":return a.jsx(oDe,{personaId:t.personaId,initialHead:t.head})}}function det(e){const{view:t}=e;if(t.tabs.length===0)return a.jsx(tW,{api:e.api,onSelect:e.onSelectCwdForNew});const n=r=>{var s;switch(r.kind){case"session":{const i=e.sessions.find(o=>o.sessionId===r.sid);return(i==null?void 0:i.label)||(i==null?void 0:i.aiLabel)||(i==null?void 0:i.larkChatName)||(i==null?void 0:i.larkChatId)||(i==null?void 0:i.cwd)||r.sid.slice(0,8)}case"dm":{const i=e.contacts.find(o=>o.deviceId===r.peerDeviceId)??((s=e.visitorContacts)==null?void 0:s.find(o=>o.deviceId===r.peerDeviceId));return(i==null?void 0:i.displayName)||`DM ${r.peerDeviceId.slice(0,8)}`}case"ext":return r.extId;case"topic":{const i=e.topics.find(l=>l.id===r.topicId),o=i?e.sessions.find(l=>l.sessionId===i.masterSessionId)??null:null;return Ww((i==null?void 0:i.title)??"",o)}case"shift":return"Shift";case"prs":return"Pull Request";case"exts":return"Extensions";case"landing":return"新对话";case"deploy":return"发布到云上";case"deploy-history":return"发布历史"}};return a.jsxs("div",{className:"flex flex-col h-full w-full",children:[a.jsx(H1e,{tabs:t.tabs,focused:t.focused,onFocus:e.onFocusTab,onClose:e.onCloseTab,onCloseOthers:e.onCloseOtherTabs,onCloseAll:e.onCloseAllTabs,onReorder:e.onReorderTab,labelForTab:n,awaitingIds:e.awaitingIds,runningIds:e.runningIds,unreadIds:e.unreadIds,unreadDmPeerDeviceIds:e.unreadDmPeerDeviceIds,pendingIndex:e.pendingTabIndex}),a.jsx("div",{className:"flex-1 relative",children:t.tabs.map((r,s)=>a.jsx(cet,{tab:r,focused:s===t.focused,sessions:e.sessions,contacts:e.contacts,visitorContacts:e.visitorContacts,remoteSessionsByOwnerId:e.remoteSessionsByOwnerId,clientPool:e.clientPool,client:e.client,im:e.im,api:e.api,myOwnerPrincipalId:e.myOwnerPrincipalId,myOwnerDisplayName:e.myOwnerDisplayName,...e.cloud?{cloud:e.cloud}:{},onSelectCwdForNew:e.onSelectCwdForNew,onNewSession:e.onNewSession,onOpenPrChat:e.onOpenPrChat,onFork:e.onFork,onOpenMobileConfig:e.onOpenMobileConfig,...e.onMirrorOrphan?{onMirrorOrphan:e.onMirrorOrphan}:{},extensionUpdateInfo:e.extensionUpdateInfo,onApplyExtensionUpdate:e.onApplyExtensionUpdate,extensionsListNode:e.extensionsListNode,landingNode:e.landingNode},Pg(r)))})]})}function Oee(e){const[t,n]=p.useState({ownerPrincipalId:null,ownerId:null,ownerProvider:null,ownerDisplayName:null});return p.useEffect(()=>{let r=!1;const s=async()=>{try{const o=await e.request("whoami",{});if(r)return;n({ownerPrincipalId:o.owner.id,ownerId:o.owner.ownerId,ownerProvider:o.owner.provider,ownerDisplayName:o.owner.displayName})}catch{}};s();const i=e.on("daemon:connected",()=>{s()});return()=>{r=!0,i()}},[e]),t}function het(e){const t=Yn(),n=Oee(t),r=Nx();p.useEffect(()=>{r&&n.ownerPrincipalId!=null&&r.setIdentity({ownerPrincipalId:n.ownerPrincipalId,deviceId:n.ownerPrincipalId,appVersion:e,os:fet()})},[r,n.ownerPrincipalId,e])}function fet(){return typeof navigator<"u"&&navigator.userAgent?navigator.userAgent.slice(0,80):"unknown-renderer"}function pet(e,t,n="production"){const[r,s]=p.useState(void 0),[i,o]=p.useState(null),[l,c]=p.useState(null),[u,d]=p.useState(0);p.useEffect(()=>{if(!t){s(void 0),o(null),c(null);return}let g=!1;return(async()=>{try{const x=await e.request("auth:apiKey:get",n==="production"?{}:{environment:n});if(g)return;s(x.apiKey),o(x.gatewayUrl??null),c(null)}catch(x){g||(s(void 0),c(x instanceof Error?x.message:String(x)))}})(),()=>{g=!0}},[e,t,u,n]);const h=p.useCallback(async()=>{const g=await e.request("auth:apiKey:regenerate",n==="production"?{}:{environment:n});s(g.apiKey),o(g.gatewayUrl??null),c(null)},[e,n]),f=p.useCallback(async()=>{await e.request("auth:apiKey:revoke",n==="production"?{}:{environment:n}),s(null),c(null)},[e,n]),m=p.useCallback(()=>{c(null),s(void 0),d(g=>g+1)},[]);return{apiKey:r,gatewayUrl:i,loadError:l,regenerate:h,revoke:f,reload:m}}const dB="<persona-id>";function hB({value:e,label:t,testId:n,mono:r=!0}){const[s,i]=p.useState(!1),o=async()=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)}catch{}};return a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("code",{"data-testid":n,className:`flex-1 min-w-0 truncate rounded-md border border-border bg-bg-50 px-2 py-1.5 text-xs text-text-200 ${r?"font-mono":""}`,children:e}),a.jsx("button",{type:"button","aria-label":`复制${t}`,"data-testid":`${n}-copy`,onClick:o,className:"shrink-0 rounded-md border border-border p-1.5 text-text-400 hover:bg-bg-100 transition-colors",children:s?a.jsx(Xt,{className:"size-3.5 text-green-500"}):a.jsx(va,{className:"size-3.5"})})]})}function fB({loggedIn:e,apiKey:t,gatewayUrl:n,onRegenerate:r,onRevoke:s,personaId:i,loadError:o=null,onReload:l}){const[c,u]=p.useState(!1),[d,h]=p.useState(!1),[f,m]=p.useState(!1),[g,x]=p.useState(null),[b,y]=p.useState(!1),v=i??dB,w=async()=>{m(!0),x(null);try{await r(),u(!1)}catch(S){x(S instanceof Error?S.message:String(S))}finally{m(!1)}},_=async()=>{if(s){m(!0),x(null);try{await s(),h(!1)}catch(S){x(S instanceof Error?S.message:String(S))}finally{m(!1)}}};return e?a.jsxs("div",{className:"space-y-2","data-testid":"cloud-api-key-card",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-text-300",children:[a.jsx(Eg,{className:"size-3.5"}),"云 persona 调用 key"]}),o?a.jsxs("button",{type:"button","data-testid":"cloud-api-key-reload",onClick:()=>l==null?void 0:l(),className:"shrink-0 inline-flex items-center gap-1 rounded-md bg-bg-200 px-2.5 py-1 text-xs font-medium text-text-200 hover:bg-bg-300 transition-colors",children:[a.jsx(No,{className:"size-3"}),"重试"]}):a.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[a.jsxs("button",{type:"button","data-testid":"cloud-api-key-action",disabled:f||t===void 0,onClick:()=>t?u(!0):void w(),className:"inline-flex items-center gap-1 rounded-md bg-bg-200 px-2.5 py-1 text-xs font-medium text-text-200 hover:bg-bg-300 transition-colors disabled:opacity-50",children:[t?a.jsx(No,{className:"size-3"}):null,f?"处理中…":t?"重新生成":"生成"]}),t&&s?a.jsxs("button",{type:"button","data-testid":"cloud-api-key-revoke",disabled:f,onClick:()=>h(!0),className:"inline-flex items-center gap-1 rounded-md bg-bg-200 px-2.5 py-1 text-xs font-medium text-text-200 hover:bg-bg-300 transition-colors disabled:opacity-50",children:[a.jsx(ws,{className:"size-3"}),"撤销"]}):null]})]}),o&&a.jsxs("p",{"data-testid":"cloud-api-key-load-error",className:"text-xs text-text-400",children:["读不到你的 key(",o,")。",a.jsx("strong",{children:"这不代表你没有"})," —— 先重试, 别急着生成新的,生成会把可能还在用的那把顶掉。"]}),!o&&t===void 0&&a.jsx("p",{"data-testid":"cloud-api-key-loading",className:"text-xs text-text-400",children:"读取中…"}),t===null&&a.jsx("p",{"data-testid":"cloud-api-key-empty",className:"text-xs text-text-400",children:"还没生成。生成后可以用任意 OpenAI 兼容的客户端访问云上的 persona。"}),t&&a.jsxs("div",{className:"space-y-2",children:[a.jsx(hB,{value:t,label:"key",testId:"cloud-api-key-value"}),n?a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button","data-testid":"cloud-api-key-usage-toggle","aria-expanded":b,onClick:()=>y(S=>!S),className:"inline-flex items-center gap-1 text-xs text-text-400 hover:text-text-200 transition-colors",children:[b?a.jsx(Qt,{className:"size-3"}):a.jsx(tr,{className:"size-3"}),"调用地址与示例"]}),b&&a.jsxs(a.Fragment,{children:[a.jsx(hB,{value:D_(n,v),label:"调用地址",testId:"cloud-api-key-base-url"}),a.jsx(C1,{label:"chat curl",testId:"cloud-api-key-sample-chat",curl:DE({gatewayUrl:n,personaId:v,apiKey:t,prompt:"hello",entry:"chat"})}),a.jsx(C1,{label:"task curl",testId:"cloud-api-key-sample-task",curl:DE({gatewayUrl:n,personaId:v,apiKey:t,prompt:"hello",entry:"task"})}),a.jsx("p",{className:"text-xs text-text-400",children:i?a.jsx(a.Fragment,{children:"这把 key 对这台 gateway 上挂着的每个云 persona 都有效,不只这一个。"}):a.jsxs(a.Fragment,{children:["把 ",a.jsx("code",{className:"font-mono",children:dB})," 换成要访问的 persona 名字(= 它的仓库名)。这把 key 对这台 gateway 上挂着的 persona 都有效。"]})})]})]}):a.jsxs("p",{"data-testid":"cloud-api-key-no-gateway",className:"text-xs text-text-400",children:["key 可以用了,但",a.jsx("strong",{children:"调用地址还没配"}),"(管理员在中心配"," ",a.jsx("code",{className:"font-mono",children:"PERSONA_CLOUD_GATEWAY_URL"}),")。 配好之后这里会自动出现地址和示例。"]})]}),g&&a.jsx("p",{"data-testid":"cloud-api-key-error",className:"text-xs text-red-500",children:g}),a.jsx(us,{open:c,onOpenChange:S=>{S||(u(!1),x(null))},children:a.jsxs(Wr,{className:"max-w-sm","data-testid":"cloud-api-key-confirm",children:[a.jsxs(zs,{children:[a.jsx(Vr,{children:"重新生成调用 key"}),a.jsxs(hi,{children:["一个人只有一把 key。生成新的之后,",a.jsx("strong",{children:"旧的立刻失效"}),",所有正在用旧 key 的地方都要换成新的。"]})]}),g&&a.jsx("p",{"data-testid":"cloud-api-key-confirm-error",className:"text-xs text-red-500",children:g}),a.jsxs(pa,{children:[a.jsx("button",{type:"button","data-testid":"cloud-api-key-confirm-cancel",disabled:f,onClick:()=>{u(!1),x(null)},className:"px-3 py-1.5 rounded-md bg-bg-200 text-text-200 text-xs font-medium hover:bg-bg-300 transition-colors disabled:opacity-50",children:"取消"}),a.jsx("button",{type:"button","data-testid":"cloud-api-key-confirm-ok",disabled:f,onClick:()=>void w(),className:"px-3 py-1.5 rounded-md bg-accent text-white text-xs font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:f?"生成中…":"生成新的"})]})]})}),a.jsx(us,{open:d,onOpenChange:S=>{S||(h(!1),x(null))},children:a.jsxs(Wr,{className:"max-w-sm","data-testid":"cloud-api-key-revoke-confirm",children:[a.jsxs(zs,{children:[a.jsx(Vr,{children:"撤销调用 key"}),a.jsxs(hi,{children:["撤销后这把 key ",a.jsx("strong",{children:"立刻失效、不会自动补新的"}),":粘到别处的那份不再能用; 开着的云 persona 会话下一条消息发不出去(正在跑的那一轮会跑完)。要再用,回来点「生成」。"]})]}),g&&a.jsx("p",{"data-testid":"cloud-api-key-revoke-error",className:"text-xs text-red-500",children:g}),a.jsxs(pa,{children:[a.jsx("button",{type:"button","data-testid":"cloud-api-key-revoke-cancel",disabled:f,onClick:()=>{h(!1),x(null)},className:"px-3 py-1.5 rounded-md bg-bg-200 text-text-200 text-xs font-medium hover:bg-bg-300 transition-colors disabled:opacity-50",children:"取消"}),a.jsx("button",{type:"button","data-testid":"cloud-api-key-revoke-ok",disabled:f,onClick:()=>void _(),className:"px-3 py-1.5 rounded-md bg-red-600 text-white text-xs font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:f?"撤销中…":"撤销"})]})]})})]}):a.jsxs("div",{className:"space-y-1.5","data-testid":"cloud-api-key-card",children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-text-300",children:[a.jsx(Eg,{className:"size-3.5"}),"云 persona 调用 key"]}),a.jsx("p",{"data-testid":"cloud-api-key-need-login",className:"text-xs text-text-400",children:"先登录飞书才能生成 —— 这把 key 的身份就是你的飞书账号。"})]})}const met={"cloud-persona-metrics":{title:"云 persona 运行状况",description:"云上 persona 现在有几个 Pod 在跑、成功率、失败原因、每段耗时,可按用法和版本筛。"},"cloud-persona-conversations":{title:"云 persona 对话记录",description:"别人跟你的云 persona 聊了什么、它是怎么做的;每轮聊完几秒后可看。"}};function get({tunnelReady:e,onOpen:t}){const[n,r]=p.useState(null),[s,i]=p.useState(null),o=async l=>{r(l),i(null);try{await t(l)}catch(c){i({page:l,message:c.message})}finally{r(null)}};return a.jsxs("div",{className:"space-y-3","data-testid":"settings-dashboard",children:[a.jsx("p",{className:"text-[13px] text-text-300",children:"看板在浏览器里打开,链接 24 小时内有效,过期了回这里再点一次。"}),e?null:a.jsx("p",{className:"rounded-md border border-border bg-bg-50 px-3 py-2 text-[12px] text-text-300","data-testid":"settings-dashboard-no-tunnel",children:"本机的公网地址还没连上(tunnel),暂时打不开;连上后这里会自动变成可点。"}),a.jsx("ul",{className:"divide-y divide-border rounded-lg border border-border",children:fH.map(l=>({page:l,...met[l]})).map(l=>a.jsxs("li",{className:"flex items-start gap-4 px-4 py-3","data-testid":`settings-dashboard-${l.page}`,children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("div",{className:"text-sm font-medium text-text-100",children:l.title}),a.jsx("div",{className:"mt-0.5 text-[12px] text-text-400",children:l.description}),(s==null?void 0:s.page)===l.page?a.jsxs("div",{className:"mt-1 text-[12px] text-destructive",children:["打不开:",s.message]}):null]}),a.jsxs(Be,{variant:"outline",size:"sm",disabled:!e||n!==null,onClick:()=>void o(l.page),"data-testid":`settings-dashboard-open-${l.page}`,children:[n===l.page?a.jsx(it,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):a.jsx(Ur,{className:"mr-1.5 h-3.5 w-3.5"}),"在浏览器打开"]})]},l.page))})]})}function xet(e,t){return e!=null&&t!=null&&t===e.ownerId}async function Dee(e){try{const t=await e();window.open(t,"_blank","noopener")}catch{}}const vet={sidebar:{wrap:"px-3 py-2 border-b shrink-0 flex flex-col gap-1.5",wrapLoggedOut:"border-border",wrapLoggedIn:"border-border",skeleton:"px-3 py-2 border-b border-border shrink-0",hint:"text-[11px] text-text-400 leading-snug",error:"text-[11px] text-error leading-snug",primaryBtn:"w-full px-2 py-1.5 text-xs rounded border border-border bg-bg-50 hover:bg-text-100/5 text-text-200 hover:text-text-100 transition-colors disabled:opacity-50",logoutBtn:"px-2 py-1 text-[11px] rounded border border-border text-text-400 hover:bg-text-100/5 hover:text-text-100 transition-colors disabled:opacity-50 shrink-0",avatar:"h-7 w-7 rounded-full shrink-0",avatarFallback:"flex h-7 w-7 items-center justify-center rounded-full bg-bg-200 text-xs text-text-200 shrink-0",name:"truncate text-xs text-text-100",sub:"truncate text-[10px] text-text-400",activating:"text-[11px] text-text-400 leading-snug animate-pulse"},settings:{wrap:"rounded-lg border bg-surface-card px-4 py-3 flex flex-col gap-2",wrapLoggedOut:"border-warning/50",wrapLoggedIn:"border-border",skeleton:"rounded-lg border border-border bg-surface-card px-4 py-3",hint:"text-[13px] text-text-200 leading-snug",error:"text-xs text-error",primaryBtn:"self-start inline-flex items-center justify-center whitespace-nowrap rounded-md h-8 px-3 text-xs font-medium bg-accent text-accent-contrast hover:bg-accent-hover 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",logoutBtn:"cursor-pointer whitespace-nowrap text-xs text-text-400 underline decoration-dotted underline-offset-4 hover:text-accent disabled:opacity-50 shrink-0",avatar:"h-8 w-8 rounded-full shrink-0",avatarFallback:"flex h-8 w-8 items-center justify-center rounded-full bg-bg-200 text-sm text-text-200 shrink-0",name:"truncate text-sm text-text-100",sub:"truncate font-mono text-[11px] text-text-400",activating:"text-xs text-text-400 leading-snug animate-pulse"}};function pB(e){const{identity:t,loading:n,error:r,active:s=!1,onLogin:i,onLogout:o,variant:l="sidebar"}=e,c=vet[l],[u,d]=p.useState(!1),h=p.useCallback(async()=>{d(!0);try{await Dee(i)}finally{d(!1)}},[i]),f=p.useCallback(async()=>{d(!0);try{await o()}finally{d(!1)}},[o]);return n?a.jsx("div",{className:c.skeleton,"data-testid":"feishu-login-card",children:a.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-bg-100"})}):t?a.jsxs("div",{className:ee(c.wrap,c.wrapLoggedIn),"data-testid":"feishu-login-card",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[t.avatarUrl?a.jsx("img",{src:t.avatarUrl,alt:"",className:c.avatar}):a.jsx("div",{className:c.avatarFallback,children:t.displayName.slice(0,1)}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("div",{className:c.name,"data-testid":"feishu-login-name",children:t.displayName}),a.jsx("div",{className:c.sub,children:t.ownerId})]}),a.jsx("button",{type:"button",disabled:u,onClick:()=>void f(),"data-testid":"feishu-logout-button",className:c.logoutBtn,children:"登出"})]}),r?a.jsxs("p",{className:c.error,"data-testid":"feishu-login-error",children:["登录失败:",r]}):null,s?null:a.jsx("p",{className:c.activating,"data-testid":"feishu-restart-hint",children:"登录成功,身份生效中…"})]}):a.jsxs("div",{className:ee(c.wrap,c.wrapLoggedOut),"data-testid":"feishu-login-card",children:[a.jsx("p",{className:c.hint,children:"登录后远程连接将使用你的飞书身份,联系人能看到你的真实姓名"}),r?a.jsxs("p",{className:c.error,"data-testid":"feishu-login-error",children:["登录失败:",r]}):null,a.jsx("button",{type:"button",disabled:u,onClick:()=>void h(),"data-testid":"feishu-login-button",className:c.primaryBtn,children:u?"请在浏览器中完成授权…":"飞书登录"})]})}function yet(e){const[t,n]=p.useState(e.isOpen?{kind:"connected",url:""}:{kind:"connecting"});return p.useEffect(()=>{const r=e.on("ready",c=>{const u=c;n(d=>({kind:"connected",url:d.kind==="connected"?d.url:"",mode:d.kind==="connected"?d.mode:void 0,daemonVersion:u.version,protocolVersion:u.protocolVersion,daemonSource:u.daemonSource,globalCliVersion:u.globalCliVersion,onboardingCompletedAt:u.onboardingCompletedAt}))}),s=e.on("daemon:connected",c=>{const u=c;n(d=>({kind:"connected",url:u.url,mode:u.mode,daemonVersion:d.kind==="connected"?d.daemonVersion:void 0,protocolVersion:d.kind==="connected"?d.protocolVersion:void 0,daemonSource:d.kind==="connected"?d.daemonSource:void 0,globalCliVersion:d.kind==="connected"?d.globalCliVersion:void 0,onboardingCompletedAt:d.kind==="connected"?d.onboardingCompletedAt:void 0}))}),i=e.on("daemon:disconnected",c=>{const u=(c==null?void 0:c.reason)??"";/auth failed|auth timeout|auth required|auth handshake timeout/i.test(u)?n({kind:"auth-failed",reason:u}):n({kind:"disconnected",reason:u})}),o=e.on("daemon:reconnecting",c=>{const u=c;n({kind:"reconnecting",attempt:u.attempt,nextDelayMs:u.nextDelayMs,scheduledAt:u.scheduledAt??Date.now()})}),l=e.on("daemon:version-mismatch",c=>{const u=c;n({kind:"version-mismatch",daemonProtocol:u.daemonProtocol,supportedProtocol:u.supportedProtocol})});return()=>{r(),s(),i(),o(),l()}},[e]),t}function bet(e,t){p.useEffect(()=>{const n=t.notifier,r=u=>{const d=u;if(!d)return;const h=d.tool??"";n==null||n.notify({title:"Permission required",body:h?`${h} requires approval`:"Tool requires approval",kind:"permission"})},s=u=>{var f;const d=u;((f=d==null?void 0:d.event)==null?void 0:f.kind)==="turn_end"&&(n==null||n.notify({title:"Turn complete",body:"Claude finished a reply",kind:"turn-end"}))},i=()=>{n==null||n.notify({title:"Question pending",body:"Claude is asking a question",kind:"permission"})},o=e.on("permission:request",r),l=e.on("session:event",s),c=e.on("session:question",i);return()=>{o(),l(),c()}},[e,t])}function wet(e){const t=Ws(),n=ha(e.kind==="connected"?"sessions":""),r=p.useCallback(async()=>{t.setData("sessions",s=>s??[])},[t]);return{sessions:n??[],loading:!1,loaded:n!==void 0,error:null,refresh:r}}const _et=new Set(tT);function ket(e){return typeof e=="string"&&_et.has(e)}function Cet(e,t,n,r){let s=!1;const i=async()=>{try{const c=await e.request("info");if(s)return;const u=new Map;for(const d of c.runningSessions??[])n.current.has(d.sessionId)&&u.set(d.sessionId,d.status);r(d=>{const h=new Map(d);for(const[f,m]of u)h.has(f)||h.set(f,m);return h})}catch{}for(const c of t)e.request("session:subscribe",{sessionId:c}).catch(()=>{})};i();const o=e.on("session:status",c=>{const u=c;if(typeof u.sessionId!="string"||!n.current.has(u.sessionId)||!ket(u.status))return;const d=u.sessionId,h=u.status;r(f=>{if(f.get(d)===h)return f;const g=new Map(f);return g.set(d,h),g})}),l=e.on("daemon:connected",()=>{i()});return()=>{s=!0,o(),l()}}function Aee(e,t){const[n,r]=p.useState(new Map),s=p.useMemo(()=>e.map(h=>`${h.originOwnerPrincipalId??""}::${h.sid}`).sort().join("|"),[e]),i=p.useMemo(()=>{const h=new Map;for(const f of e){const m=f.originOwnerPrincipalId;let g=h.get(m);g||(g=new Set,h.set(m,g)),g.add(f.sid)}return h},[s]),o=p.useCallback(h=>t.onOwnersChanged(h),[t]),l=p.useCallback(()=>t.listRemoteDeviceIds().sort().join("|"),[t]),c=p.useCallback(()=>"",[]),u=p.useSyncExternalStore(o,l,c),d=p.useRef(new Map);return p.useEffect(()=>{for(const[h,f]of i){let m=d.current.get(h);m||(m={current:new Set},d.current.set(h,m)),m.current=f}for(const h of Array.from(d.current.keys()))i.has(h)||d.current.delete(h)}),p.useEffect(()=>{if(i.size===0)return;const h=[];for(const[f,m]of i){const g=f===null?t.local:t.getRemoteForDevice(f);if(!g)continue;const x=d.current.get(f);x&&h.push(Cet(g,m,x,r))}return()=>{for(const f of h)f()}},[t,s,u]),p.useMemo(()=>{const h=new Map;for(const[f,m]of n)h.set(f,LG({sessionStatus:m}));return h},[n])}function Qp(){return{realPermIds:new Set,realQuestionIds:new Set,realPopupKinds:new Set}}function Net(e){return e.realPermIds.size+e.realQuestionIds.size+e.realPopupKinds.size>0}function jet(e){return typeof e.toolUseId=="string"&&e.toolUseId.length>0?e.toolUseId:typeof e.requestId=="string"&&e.requestId.length>0?e.requestId:null}function mB(e){if(!Array.isArray(e))return[];const t=[];for(const n of e)typeof n=="string"&&n.length>0&&t.push(n);return t}function Eet(e,t,n){let r=!1;const s=async()=>{try{const h=await e.request("info");if(r)return;const f=new Map;for(const m of h.runningSessions??[])t.current.has(m.sessionId)&&f.set(m.sessionId,{perm:mB(m.pendingPermissionRequestIds),question:mB(m.pendingQuestionToolUseIds)});n(m=>{const g=new Map(m);for(const x of t.current){const b=g.get(x)??Qp(),y=f.get(x)??{perm:[],question:[]},v=new Set(b.realPermIds);for(const _ of y.perm)v.add(_);const w=new Set(b.realQuestionIds);for(const _ of y.question)w.add(_);g.set(x,{realPermIds:v,realQuestionIds:w,realPopupKinds:new Set(b.realPopupKinds)})}return g})}catch{}};s();const i=e.on("permission:request",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId))return;const m=jet(f);if(!m)return;const g=f.sessionId;n(x=>{const b=x.get(g)??Qp();if(b.realPermIds.has(m))return x;const y=new Set(b.realPermIds);y.add(m);const v=new Map(x);return v.set(g,{...b,realPermIds:y}),v})}),o=e.on("session:event",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId))return;const m=f.event;if(!m||m.kind!=="tool_result")return;const g=m.toolUseId;if(typeof g!="string"||g.length===0)return;const x=f.sessionId;n(b=>{const y=b.get(x);if(!y||!y.realPermIds.has(g))return b;const v=new Set(y.realPermIds);v.delete(g);const w=new Map(b);return w.set(x,{...y,realPermIds:v}),w})}),l=e.on("session:question",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId)||typeof f.toolUseId!="string"||f.toolUseId.length===0)return;const m=f.sessionId,g=f.toolUseId;n(x=>{const b=x.get(m)??Qp();if(b.realQuestionIds.has(g))return x;const y=new Set(b.realQuestionIds);y.add(g);const v=new Map(x);return v.set(m,{...b,realQuestionIds:y}),v})}),c=e.on("session:question:cleared",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId)||typeof f.toolUseId!="string"||f.toolUseId.length===0)return;const m=f.sessionId,g=f.toolUseId;n(x=>{const b=x.get(m);if(!b||!b.realQuestionIds.has(g))return x;const y=new Set(b.realQuestionIds);y.delete(g);const v=new Map(x);return v.set(m,{...b,realQuestionIds:y}),v})}),u=e.on("session:control",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId)||typeof f.popupKind!="string"||f.popupKind.length===0)return;const m=f.sessionId,g=f.popupKind;f.kind==="popup_open"?n(x=>{const b=x.get(m)??Qp();if(b.realPopupKinds.has(g))return x;const y=new Set(b.realPopupKinds);y.add(g);const v=new Map(x);return v.set(m,{...b,realPopupKinds:y}),v}):f.kind==="popup_close"&&n(x=>{const b=x.get(m);if(!b||!b.realPopupKinds.has(g))return x;const y=new Set(b.realPopupKinds);y.delete(g);const v=new Map(x);return v.set(m,{...b,realPopupKinds:y}),v})}),d=e.on("daemon:connected",()=>{n(h=>{let f=!1;const m=new Map(h);for(const g of t.current)m.has(g)&&(m.set(g,Qp()),f=!0);return f?m:h}),s()});return()=>{r=!0,i(),o(),l(),c(),u(),d()}}function $ee(e,t){const[n,r]=p.useState(new Map),s=p.useMemo(()=>e.map(h=>`${h.originOwnerPrincipalId??""}::${h.sid}`).sort().join("|"),[e]),i=p.useMemo(()=>{const h=new Map;for(const f of e){const m=f.originOwnerPrincipalId;let g=h.get(m);g||(g=new Set,h.set(m,g)),g.add(f.sid)}return h},[s]),o=p.useCallback(h=>t.onOwnersChanged(h),[t]),l=p.useCallback(()=>t.listRemoteDeviceIds().sort().join("|"),[t]),c=p.useCallback(()=>"",[]),u=p.useSyncExternalStore(o,l,c),d=p.useRef(new Map);return p.useEffect(()=>{for(const[h,f]of i){let m=d.current.get(h);m||(m={current:new Set},d.current.set(h,m)),m.current=f}for(const h of Array.from(d.current.keys()))i.has(h)||d.current.delete(h)}),p.useEffect(()=>{if(i.size===0)return;const h=[];for(const[f]of i){const m=f===null?t.local:t.getRemoteForDevice(f);if(!m)continue;const g=d.current.get(f);g&&h.push(Eet(m,g,r))}return()=>{for(const f of h)f()}},[t,s,u]),p.useMemo(()=>{const h=new Set;for(const f of e){const m=n.get(f.sid);m&&Net(m)&&h.add(f.sid)}return h},[n,s])}function Iet(e){const{entries:t,sessions:n,activeId:r,pool:s}=e,[i,o]=p.useState(new Map),l=p.useMemo(()=>t.map(v=>`${v.originOwnerPrincipalId??""}::${v.sid}`).sort().join("|"),[t]),c=p.useMemo(()=>{const v=new Map;for(const w of t)v.set(w.sid,w.originOwnerPrincipalId);return v},[l]),u=p.useCallback(v=>s.onOwnersChanged(v),[s]),d=p.useCallback(()=>s.listRemoteDeviceIds().sort().join("|"),[s]),h=p.useCallback(()=>"",[]),f=p.useSyncExternalStore(u,d,h),m=p.useRef(new Map);p.useEffect(()=>{const v=new Map;for(const w of t){if(!w.originOwnerPrincipalId)continue;let _=v.get(w.originOwnerPrincipalId);_||(_=new Set,v.set(w.originOwnerPrincipalId,_)),_.add(w.sid)}m.current=v}),p.useEffect(()=>{const v=new Set;for(const _ of t)_.originOwnerPrincipalId&&v.add(_.originOwnerPrincipalId);if(v.size===0)return;const w=[];for(const _ of v){const S=s.getRemoteForDevice(_);S&&w.push(S.on("session:info",k=>{var E;const C=k;if(typeof C.sessionId!="string")return;const N=C.sessionId;if(!((E=m.current.get(_))!=null&&E.has(N)))return;const T=typeof C.unreadAt=="string"&&C.unreadAt?C.unreadAt:null;o(R=>{if(R.get(N)===T)return R;const O=new Map(R);return O.set(N,T),O})}))}return()=>{for(const _ of w)_()}},[s,l,f]);const g=p.useMemo(()=>{const v=new Map;for(const w of n)typeof w.unreadAt=="string"&&w.unreadAt&&c.has(w.sessionId)&&v.set(w.sessionId,w.unreadAt);for(const[w,_]of i)c.has(w)&&(_===null?v.delete(w):v.set(w,_));return v},[n,i,c]),x=p.useRef(new Set),[b,y]=p.useState(new Set);return p.useEffect(()=>{if(!r)return;const v=g.get(r);if(!v)return;const w=`${r}::${v}`;if(x.current.has(w))return;const _=c.get(r),S=_?s.getRemoteForDevice(_):s.local;S&&(x.current.add(w),S.request("session:markRead",{sessionId:r}).catch(()=>{}),y(k=>new Set(k).add(w)))},[r,g,c,s,f]),p.useMemo(()=>{const v=new Set;for(const[w,_]of g)w!==r&&(b.has(`${w}::${_}`)||v.add(w));return v},[g,r,b])}function lS(e,t){return e.larkChatId!=null||e.originOwnerPrincipalId||e.ownerPersonaId||!t||!e.creatorPrincipalId?!0:e.creatorPrincipalId===t}function av(e){return e.label||e.aiLabel||e.larkChatName||e.larkChatId||e.cwd.split("/").filter(Boolean).pop()||e.sessionId.slice(0,8)}function Tet(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function ym(e,t){const n=ul(),[r,s]=p.useState(t),[i,o]=p.useState(!1);p.useEffect(()=>{let c=!1;return o(!1),(async()=>{try{const u=await n.kv.get(e);if(c)return;const d=Tet(u);typeof d=="boolean"&&s(d)}catch{}finally{c||o(!0)}})(),()=>{c=!0}},[n,e]);const l=p.useCallback(c=>{s(c),n.kv.set(e,c).catch(()=>{})},[n,e]);return[r,l,i]}function Ret(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function bf(e,t){const n=ul(),[r,s]=p.useState(t),[i,o]=p.useState(!1);p.useEffect(()=>{let c=!1;return o(!1),(async()=>{try{const u=await n.kv.get(e);if(c)return;const d=Ret(u);typeof d=="string"&&s(d)}catch{}finally{c||o(!0)}})(),()=>{c=!0}},[n,e]);const l=p.useCallback(c=>{s(c),n.kv.set(e,c).catch(()=>{})},[n,e]);return[r,l,i]}const Met="clawd:sidebar:projects:expanded";function Pet(e){if(!e)return[];try{const t=JSON.parse(e);if(Array.isArray(t))return t.filter(n=>typeof n=="string")}catch{}return[e]}function Oet(){const[e,t]=bf(Met,""),n=p.useMemo(()=>new Set(Pet(e)),[e]);return{expandedPaths:n,toggleProject:s=>{const i=new Set(n);i.has(s)?i.delete(s):i.add(s),t(JSON.stringify([...i]))}}}const Det="clawd:sidebar:channels:collapsed";function Aet(e){if(!e)return[];try{const t=JSON.parse(e);if(Array.isArray(t))return t.filter(n=>typeof n=="string")}catch{}return[]}function $et(){const[e,t]=bf(Det,""),n=p.useMemo(()=>new Set(Aet(e)),[e]);return{collapsedChannelIds:n,toggleChannel:s=>{const i=new Set(n);i.has(s)?i.delete(s):i.add(s),t(JSON.stringify([...i]))}}}function lv(e){return e.forkedFromSessionId??e.dispatchedFromSessionId??e.shiftFiredFromSessionId}function cS(e,t){return e.updatedAt<t.updatedAt?1:e.updatedAt>t.updatedAt?-1:0}function Sc(e){e=e.filter(i=>!i.ephemeral&&i.deployId===void 0&&i.testReleaseId===void 0);const t=new Map;for(const i of e)t.set(i.sessionId,i);const n=new Map,r=[];for(const i of e){const o=lv(i);if(o&&t.has(o)){const l=n.get(o)??[];l.push(i),n.set(o,l)}else r.push(i)}const s=i=>{const l=[...n.get(i.sessionId)??[]].sort(cS);return{session:i,children:l.map(s)}};return[...r].sort(Fet).map(s)}function ey(e,t){const n=new Map;for(const o of e){const l=lv(o);if(!l)continue;const c=n.get(l)??[];c.push(o.sessionId),n.set(l,c)}const r=[],s=new Set([t]),i=[t];for(;i.length>0;){const o=i.pop(),l=n.get(o)??[];for(const c of l)s.has(c)||(s.add(c),r.push(c),i.push(c))}return r}function uS(e){return[...e].sort((t,n)=>cS(t.session,n.session))}function Let(e,t){return t.awaitingIds.has(e)?0:t.runningIds.has(e)?1:t.unreadIds.has(e)?2:3}function Lee(e,t){let n=Let(e.session.sessionId,t);for(const r of e.children)n=Math.min(n,Lee(r,t));return n}function Fee(e,t){const n=new Map;for(const r of e)n.set(r,Lee(r,t));return[...e].sort((r,s)=>{const i=n.get(r)-n.get(s);return i!==0?i:cS(r.session,s.session)})}function Fet(e,t){const n=typeof e.pinnedAt=="number",r=typeof t.pinnedAt=="number";if(n&&r){const s=typeof e.pinSortOrder=="number",i=typeof t.pinSortOrder=="number";return s&&i?e.pinSortOrder-t.pinSortOrder:s?-1:i?1:t.pinnedAt-e.pinnedAt}return n?-1:r?1:cS(e,t)}const gB={awaiting:3,unread:2,running:1};function Bet(e,t){return t.awaitingIds.has(e)?"awaiting":t.unreadIds.has(e)?"unread":t.runningIds.has(e)?"running":null}function x3(e,t){let n=null;for(const r of e){const s=[Bet(r.session.sessionId,t),x3(r.children,t)];for(const i of s)i&&(!n||gB[i]>gB[n])&&(n=i)}return n}function Bee(e,t){if(e.projectPath&&t.includes(e.projectPath))return e.projectPath;let n=null;for(const r of t)(e.cwd===r||e.cwd.startsWith(r.endsWith("/")?r:r+"/"))&&(n===null||r.length>n.length)&&(n=r);return n}function v3(e){return!e.ephemeral}function xB(e){return v3(e)&&e.ownerPersonaId!==Fi}function zet(e,t){let n=e;const r=new Set([n.sessionId]);let s=e.archivedAt==null?null:e;for(;;){const i=lv(n);if(!i)return s;const o=t.get(i);if(!o||r.has(o.sessionId))return s;r.add(o.sessionId),n=o,n.archivedAt!=null&&(s=n)}}function Het(e,t){let n=e;const r=new Set([n.sessionId]);for(;;){const s=lv(n);if(!s)return n;const i=t.get(s);if(!i||r.has(i.sessionId))return n;r.add(i.sessionId),n=i}}function Zm(e){const t=new Map(e.map(i=>[i.sessionId,i])),n=[],r=[],s=new Map;for(const i of e){const o=zet(i,t);if(o==null)n.push(i);else if(i.sessionId===o.sessionId)r.push(i);else{const l=s.get(o.sessionId)??[];l.push(i),s.set(o.sessionId,l)}}return{visible:n,archivedRoots:r,archivedChildrenByRoot:s}}function dS(e,t,n,r){const s=n&&n.length>0?new Map(e.map(i=>[i.sessionId,i])):null;return e.filter(i=>i.chatId!==void 0||r!=null&&r.has(i.sessionId)||i.deployId!==void 0||i.testReleaseId!==void 0||s&&n&&Bee(Het(i,s),n)!==null?!1:lS(i,t))}function u2(e,t,n,r,s){const{visible:i}=Zm(e);return uS(Sc(dS(i,t,r,s))).filter(l=>l.session.pinnedAt==null).map(l=>l.session).slice(n)}function zee(e,t,n){const r=dS(e,t),s=Sc(r),i=new Map;for(const o of s){if(o.session.pinnedAt!=null)continue;const l=Bee(o.session,n);if(!l)continue;const c=i.get(l)??[];c.push(o),i.set(l,c)}for(const o of i.values())o.sort((l,c)=>c.session.updatedAt>l.session.updatedAt?1:-1);return i}const tb=p.createContext(null);function Uet(){const e=p.useContext(tb);if(!e)throw new Error("SessionTreeCollapsedContext.Provider missing — wrap SessionTreeNode tree with <SessionTreeCollapsedContext.Provider value={useSessionTreeCollapsed()}>");return e}function gI({tool:e,className:t}){const n=xTe(e);return a.jsx("span",{"data-testid":n?`session-icon-${e}`:"session-icon-default","aria-label":n?DR(e):"未知引擎",className:ee("w-3.5 h-3.5 shrink-0 inline-flex items-center justify-center",nf(e),t),children:a.jsx(rf,{tool:e,className:"w-full h-full"})})}function Hee({sessionId:e,hasUnread:t,running:n=!1,awaitingUser:r=!1,style:s}){return r?a.jsx(rT,{"data-testid":`awaiting-dot-${e}`,style:s,className:"w-3 h-3 text-warning shrink-0 animate-pulse",strokeWidth:2.25,"aria-label":"awaiting user"}):t?a.jsx("span",{"data-testid":`unread-dot-${e}`,style:s,className:"w-2 h-2 rounded-full bg-error shrink-0","aria-label":"unread"}):n?a.jsx("span",{"data-testid":`running-dot-${e}`,style:s,className:"w-2 h-2 rounded-full bg-success shrink-0 animate-pulse","aria-label":"running"}):null}function Uee({open:e,initialLabel:t,placeholder:n,onSubmit:r,onCancel:s,title:i="Edit session",fieldLabel:o="Label",testId:l="session-edit-dialog",requireNonEmpty:c=!1}){const[u,d]=p.useState(t);p.useEffect(()=>{e&&d(t)},[e,t]);const h=u.trim(),f=c&&h==="",m=()=>{f||r({label:h})},g=xi(m,s);return e?os.createPortal(a.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:s,"data-testid":`${l}-overlay`,children:a.jsxs("div",{"data-testid":l,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:x=>x.stopPropagation(),children:[a.jsx("div",{className:"text-[15px] font-semibold text-text-100",children:i}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:o}),a.jsx("input",{autoFocus:!0,type:"text",value:u,onChange:x=>d(x.target.value),...g,placeholder:n,"data-testid":`${l}-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"})]}),a.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[a.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"}),a.jsx("button",{type:"button",onClick:m,disabled:f,"data-testid":`${l}-save`,className:"px-4 py-1.5 text-[12px] font-medium text-bg-0 rounded-lg bg-text-100 hover:bg-text-200 transition-colors cursor-pointer disabled:cursor-not-allowed disabled:opacity-40",children:"Save"})]})]})}),document.body):null}const Wet={held:!1,indexBySessionId:new Map},Wee=p.createContext(Wet);function Vet(){return p.useContext(Wee)}const qet=Array.from({length:9},(e,t)=>({id:`switch-session-${t+1}`,combo:{key:String(t+1),mod:!0},label:`切换到第 ${t+1} 个会话`,group:"会话",desktopOnly:!0,hiddenInList:!0})),Vee=[{id:"new-session",combo:{key:"n",mod:!0},label:"新建任务",description:"打开快捷新建弹窗",group:"通用",desktopOnly:!0},{id:"open-search",combo:{key:"k",mod:!0},label:"全局搜索",description:"搜会话内容 / persona / 联系人",group:"通用",desktopOnly:!0},{id:"search-tab-prev",combo:{key:"ArrowLeft",mod:!0},label:"搜索:上一组",description:"搜索浮层里切到左边那个 tab(会话 / persona / 联系人)",group:"通用"},{id:"search-tab-next",combo:{key:"ArrowRight",mod:!0},label:"搜索:下一组",description:"搜索浮层里切到右边那个 tab",group:"通用"},...qet,{id:"archive-session",combo:{key:"Backspace",mod:!0,shift:!0},label:"归档当前会话",description:"归档当前聊天区的会话,Enter 确认 / Esc 取消",group:"会话",desktopOnly:!0},{id:"tab-prev",combo:{key:"ArrowLeft",mod:!0,shift:!0},label:"上一个标签页",description:"连按快速移动,停下或松开修饰键后切换",group:"标签页"},{id:"tab-next",combo:{key:"ArrowRight",mod:!0,shift:!0},label:"下一个标签页",description:"连按快速移动,停下或松开修饰键后切换",group:"标签页"},{id:"close-tab",combo:{key:"w",mod:!0},label:"关闭当前标签页",description:"关闭当前聚焦的标签页",group:"标签页",desktopOnly:!0},{id:"toggle-hive",combo:{key:"h",mod:!0,shift:!0},label:"Hive 看板",description:"全屏看所有 agent 在干什么;Esc 或点任意行退出",group:"通用"},{id:"quit-app",combo:{key:"q",mod:!0},label:"退出 clawd",description:"退出应用,由 Electron 默认菜单处理",group:"通用",desktopOnly:!0,displayOnly:!0},{id:"send-message",combo:{key:"Enter"},label:"发送消息",description:"在输入框中发送当前内容",group:"输入",displayOnly:!0},{id:"newline",combo:{key:"Enter",shift:!0},label:"换行",description:"在输入框中插入换行",group:"输入",displayOnly:!0},{id:"interrupt",combo:{key:"Escape"},label:"打断回复",description:"打断当前回复;2 秒内按两次停止任务",group:"输入",displayOnly:!0}],Ket=Vee.filter(e=>!e.displayOnly),Get={ArrowLeft:"←",ArrowRight:"→",ArrowUp:"↑",ArrowDown:"↓",Escape:"Esc"};function d2(e,t){const n=e.key==="Enter"||e.key==="Backspace"?t?{Enter:"⏎",Backspace:"⌫"}[e.key]:e.key:Get[e.key]??e.key.toUpperCase();if(t)return`${e.alt?"⌥":""}${e.shift?"⇧":""}${e.mod?"⌘":""}${n}`;const r=[];return e.mod&&r.push("Ctrl"),e.alt&&r.push("Alt"),e.shift&&r.push("Shift"),r.push(n),r.join("+")}function qee(e){const t=[];let n=!1;for(const r of Vee){if(r.hiddenInList){!n&&r.id.startsWith("switch-session-")&&(t.push({id:"switch-session",label:"快速切换会话",description:"按 sidebar 置顶 + 最近顺序直达第 1-9 个会话",group:"会话",keys:[d2({key:"1",mod:!0},e),"…",d2({key:"9",mod:!0},e)],desktopOnly:!0}),n=!0);continue}t.push({id:r.id,label:r.label,description:r.description,group:r.group,keys:[d2(r.combo,e)],desktopOnly:r.desktopOnly})}return t}const Kee=["通用","会话","标签页","输入"];function Yet(e){if(!e||typeof e!="object")return!1;const t=e;return t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable===!0}function Xet(e,t,n){if(e.isComposing||e.keyCode===229)return null;for(const r of t){const s=r.combo;if(e.key.toLowerCase()!==s.key.toLowerCase())continue;const i=n?e.metaKey:e.ctrlKey,o=n?e.ctrlKey:e.metaKey;if(!(!!s.mod!==i||o||!!s.shift!==e.shiftKey||!!s.alt!==e.altKey||!(s.mod||s.alt)&&Yet(e.target)))return r}return null}function cv(){return/Mac|iP(hone|od|ad)/.test(navigator.platform)}function Zet(e){const t=p.useRef(e);p.useEffect(()=>{t.current=e}),p.useEffect(()=>{const n=cv(),r=s=>{const i=Xet(s,Ket,n);if(!i)return;const o=t.current[i.id];o&&(s.preventDefault(),o())};return window.addEventListener("keydown",r,!0),()=>window.removeEventListener("keydown",r,!0)},[])}const Gee=10,Qet=20,Jet=16,vB=20,yB=60,Yee=4,Xee=Gee,Zee=Yee;function ty({testId:e,label:t,children:n}){return a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:a.jsx("span",{"data-testid":e,role:"img","aria-label":t,tabIndex:0,className:"inline-flex shrink-0",children:n})}),a.jsx(gi,{side:"bottom",children:t})]})}function ett({session:e,active:t,hasUnread:n,running:r=!1,awaitingUser:s=!1,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,quickAction:d,depth:h=0,chevron:f,showCopyResume:m=!0,contactDisplayName:g,ownerPrincipalId:x,creatorDisplayName:b,dispatchedFromSessionTitle:y}){const[v,w]=p.useState(!1),_=Vet(),S=_.held?_.indexBySessionId.get(e.sessionId):void 0,k=!!e.pinnedAt,C=h===0,N=h===0&&!!u,T=Gee+h*Qet;let E=null;d==="pin"&&C&&c?E={icon:k?a.jsx(qb,{className:"w-4 h-4"}):a.jsx(Ig,{className:"w-4 h-4"}),label:k?"取消置顶":"置顶",run:()=>c(e.sessionId,!k)}:d==="archive"&&N&&u?E={icon:a.jsx(Iu,{className:"w-4 h-4"}),label:"归档",run:()=>u(e.sessionId,!0)}:d==="rename"&&o&&(E={icon:a.jsx(Mu,{className:"w-4 h-4"}),label:"重命名",run:()=>w(!0)});const R=p.useCallback(async()=>{const B=AG(e);if(B)try{await navigator.clipboard.writeText(B)}catch{}},[e]),O=av(e),P=e.originOwnerPrincipalId,$=P?`@${g??`…${P.slice(-8)}`}`:null,F=!!(e.ownerPersonaId&&x&&e.creatorPrincipalId&&e.creatorPrincipalId!==x&&!e.larkChatId&&!e.shiftFiredFromSessionId&&!e.dispatchedFromSessionId);return a.jsxs(a.Fragment,{children:[a.jsxs("div",{"data-testid":`session-item-${e.sessionId}`,onClick:i,style:{paddingLeft:T,display:"grid",gridTemplateColumns:f?`${Jet}px ${vB}px 1fr auto ${yB}px`:`${vB}px 1fr auto ${yB}px`,gridTemplateAreas:f?'"chev icon name dot time"':'"icon name dot time"',columnGap:`${Yee}px`,alignItems:"center"},className:ee("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?a.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,a.jsx("div",{style:{gridArea:"chev"},className:"flex items-center justify-center",children:f??null}),a.jsx("div",{style:{gridArea:"icon"},className:"flex items-center justify-center",children:a.jsx(gI,{tool:e.tool})}),a.jsxs("div",{style:{gridArea:"name"},className:"flex items-center gap-1 min-w-0",children:[a.jsxs(di,{delayDuration:200,skipDelayDuration:100,children:[e.dispatchedFromSessionId?a.jsx(ty,{testId:`dispatched-icon-${e.sessionId}`,label:`来自【${y??"另一会话"}】dispatch`,children:a.jsx(oT,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,e.shiftFiredFromSessionId?a.jsx(ty,{testId:`shift-fired-icon-${e.sessionId}`,label:"定时任务",children:a.jsx(jH,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,e.larkChatId?a.jsx(ty,{testId:`lark-chat-icon-${e.sessionId}`,label:e.larkChatType==="p2p"?"来自飞书DM":"来自飞书群",children:a.jsx(hT,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,F?a.jsx(ty,{testId:`guest-created-icon-${e.sessionId}`,label:b?`${b}创建`:"其他人创建",children:a.jsx(XH,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null]}),a.jsx("span",{"data-testid":`session-title-${e.sessionId}`,className:ee("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:O}),$?a.jsx("span",{"data-testid":`session-mirror-chip-${e.sessionId}`,title:`在 ${$.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:$}):null]}),a.jsx(Hee,{sessionId:e.sessionId,hasUnread:n,running:r,awaitingUser:s,style:{gridArea:"dot"}}),S!=null?a.jsx("span",{style:{gridArea:"time"},"data-testid":`session-quick-switch-badge-${e.sessionId}`,className:"text-right shrink-0 transition-opacity duration-150 group-hover:opacity-0",children:a.jsx("span",{className:"inline-flex items-center justify-center h-[18px] px-1.5 rounded-[5px] border border-border bg-bg-200/70 text-[11px] text-text-200 font-medium leading-none",children:cv()?`⌘${S}`:`Ctrl+${S}`})}):a.jsx("span",{style:{gridArea:"time"},className:ee("text-[11px] text-text-400/70 text-right shrink-0","transition-opacity duration-150 group-hover:opacity-0"),children:e.updatedAt?tM(e.updatedAt):""}),o||l||c||u?a.jsxs("div",{className:"absolute right-2 top-[3px] flex items-center opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100 transition-opacity",children:[E?a.jsx(di,{delayDuration:200,skipDelayDuration:100,children:a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:a.jsx("button",{type:"button",onClick:B=>{B.stopPropagation(),E.run()},className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors cursor-pointer","aria-label":E.label,"data-testid":`quick-action-${d}-${e.sessionId}`,children:E.icon})}),a.jsx(gi,{side:"bottom",children:E.label})]})}):null,a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button",onClick:B=>B.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:a.jsx(ca,{className:"w-4 h-4"})})}),a.jsxs(Pr,{align:"end",onClick:B=>B.stopPropagation(),children:[c&&C&&a.jsxs(Et,{onSelect:()=>c(e.sessionId,!k),"data-testid":`session-${k?"unpin":"pin"}-${e.sessionId}`,children:[k?a.jsx(qb,{className:"w-3 h-3 mr-2 text-text-400"}):a.jsx(Ig,{className:"w-3 h-3 mr-2 text-text-400"}),k?"Unpin":"Pin"]}),N&&u&&a.jsxs(Et,{onSelect:()=>u(e.sessionId,!0),"data-testid":`session-archive-${e.sessionId}`,children:[a.jsx(Iu,{className:"w-3 h-3 mr-2 text-text-400"}),"Archive"]}),o&&a.jsxs(Et,{onSelect:()=>w(!0),"data-testid":`session-rename-${e.sessionId}`,children:[a.jsx(Mu,{className:"w-3 h-3 mr-2 text-text-400"}),"Rename"]}),m&&e.toolSessionId?a.jsxs(Et,{onSelect:()=>void R(),"data-testid":`session-copy-resume-${e.sessionId}`,children:[a.jsx(va,{className:"w-3 h-3 mr-2 text-text-400"}),"Copy Resume Command"]}):null,(c||o||m&&e.toolSessionId)&&l&&a.jsx(ma,{}),l&&a.jsxs(Et,{onSelect:()=>void l(e.sessionId),className:"text-destructive focus:text-destructive focus:bg-destructive/10","data-testid":`session-delete-${e.sessionId}`,children:[a.jsx(ws,{className:"w-3 h-3 mr-2"}),"Delete"]})]})]})]}):null]}),o?a.jsx(Uee,{open:v,initialLabel:e.label??"",placeholder:e.cwd.split("/").pop()||"",onSubmit:B=>{o(e.sessionId,B),w(!1)},onCancel:()=>w(!1)}):null]})}function Zu({node:e,depth:t=0,activeId:n,unreadIds:r,runningIds:s,awaitingIds:i,onSelect:o,onEdit:l,onDelete:c,onPin:u,onArchive:d,quickAction:h,getContactDisplayName:f,showCopyResume:m,ownerPrincipalId:g,getCreatorDisplayName:x,getSessionDisplayName:b,parentSession:y}){const v=e.children.length>0,{isCollapsed:w,toggle:_}=Uet(),S=!w(e.session.sessionId),k=p.useCallback(N=>{N.stopPropagation(),_(e.session.sessionId)},[_,e.session.sessionId]),C=v?a.jsx("button",{type:"button",onClick:k,"data-testid":`session-chevron-${e.session.sessionId}`,"aria-label":S?"collapse":"expand","aria-expanded":S,className:"shrink-0 flex items-center justify-center w-4 h-4 text-text-400 hover:text-text-100 cursor-pointer",children:S?a.jsx(Qt,{className:"w-3 h-3"}):a.jsx(tr,{className:"w-3 h-3"})}):null;return a.jsxs("div",{"data-testid":`session-tree-node-${e.session.sessionId}`,children:[a.jsx(ett,{session:e.session,active:n===e.session.sessionId,hasUnread:(r==null?void 0:r.has(e.session.sessionId))??!1,running:(s==null?void 0:s.has(e.session.sessionId))??!1,awaitingUser:(i==null?void 0:i.has(e.session.sessionId))??!1,onSelect:()=>o(e.session.sessionId),onEdit:l,onDelete:c,onPin:u,onArchive:d,quickAction:h,showCopyResume:m,ownerPrincipalId:g,creatorDisplayName:e.session.creatorPrincipalId?x==null?void 0:x(e.session.creatorPrincipalId):void 0,dispatchedFromSessionTitle:e.session.dispatchedFromSessionId?(b==null?void 0:b(e.session.dispatchedFromSessionId))??((y==null?void 0:y.sessionId)===e.session.dispatchedFromSessionId?av(y):void 0):void 0,depth:t,chevron:C,contactDisplayName:e.session.originOwnerPrincipalId?f==null?void 0:f(e.session.originOwnerPrincipalId):void 0}),v&&S?a.jsx("div",{"data-testid":`session-tree-children-${e.session.sessionId}`,children:e.children.map(N=>a.jsx(Zu,{node:N,depth:t+1,activeId:n,unreadIds:r,runningIds:s,awaitingIds:i,onSelect:o,onEdit:l,onDelete:c,onPin:u,onArchive:d,quickAction:h,getContactDisplayName:f,showCopyResume:m,ownerPrincipalId:g,getCreatorDisplayName:x,getSessionDisplayName:b,parentSession:e.session},N.session.sessionId))}):null]})}const bB=5,h2="hidden group-hover:inline-flex group-has-[[data-state=open]]:inline-flex p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",ttt="group-hover:hidden group-has-[[data-state=open]]:hidden";function xI(){return a.jsx("span",{className:"shrink-0 w-2 h-2 rounded-full bg-blue-500"})}function Qee({nodes:e,depth:t,activeId:n,unreadIds:r,onSelect:s}){return a.jsx(a.Fragment,{children:e.map(i=>a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`project-session-child-${i.session.sessionId}`,className:`flex items-center gap-1.5 pr-2 py-[5px] mx-1 rounded-md cursor-pointer ${n===i.session.sessionId?"bg-text-100/10":"hover:bg-text-100/5"}`,style:{paddingLeft:36+t*12},onClick:()=>s(i.session.sessionId),children:[a.jsx("span",{className:"flex-1 min-w-0 truncate text-[13px] text-text-200",children:i.session.label??i.session.aiLabel??i.session.sessionId}),r.has(i.session.sessionId)?a.jsx(xI,{}):null]}),a.jsx(Qee,{nodes:i.children,depth:t+1,activeId:n,unreadIds:r,onSelect:s})]},i.session.sessionId))})}function Jee({project:e,nodes:t,expanded:n,onToggle:r,activeId:s,unreadIds:i,onSelect:o,onPin:l,onNewInProject:c,getPersonaDisplayName:u,onTogglePinProject:d,onRevealProject:h}){const[f,m]=p.useState(!1),g=f?t:t.slice(0,bB),x=t.filter(v=>i.has(v.session.sessionId)).length,b=!!(d||h),y=e.pinnedAt!=null;return a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`project-row-${e.name}`,title:e.path,style:{paddingLeft:Xee,gap:Zee},className:"group flex items-center pr-3 py-[5px] mx-1 rounded-md cursor-pointer hover:bg-text-100/5",onClick:r,children:[n?a.jsx(Vh,{className:"w-4 h-4 shrink-0 text-accent"}):a.jsx(jg,{className:"w-4 h-4 shrink-0 text-text-300"}),a.jsx("span",{className:"flex-1 min-w-0 truncate text-[13px] text-text-100",children:e.name}),b?a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button",title:"更多","data-testid":`project-more-${e.name}`,onClick:v=>v.stopPropagation(),className:h2,children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsxs(Pr,{align:"start",children:[d&&a.jsxs(Et,{"data-testid":`project-menu-pin-${e.name}`,onSelect:()=>d(e),children:[y?a.jsx(qb,{className:"w-3.5 h-3.5"}):a.jsx(Ig,{className:"w-3.5 h-3.5"}),y?"取消置顶":"置顶"]}),h&&a.jsxs(a.Fragment,{children:[a.jsx(ma,{}),a.jsxs(Et,{"data-testid":`project-menu-reveal-${e.name}`,onSelect:()=>h(e.path),children:[a.jsx(Vh,{className:"w-3.5 h-3.5"}),"在 Finder 中显示"]})]})]})]}):a.jsx("button",{type:"button",title:"更多","data-testid":`project-more-${e.name}`,onClick:v=>v.stopPropagation(),className:h2,children:a.jsx(ca,{className:"w-3.5 h-3.5"})}),c&&a.jsx("button",{type:"button",title:"在此项目中新建会话","data-testid":`project-new-${e.name}`,onClick:v=>{v.stopPropagation(),c(e.path)},className:h2,children:a.jsx(GH,{className:"w-3.5 h-3.5"})}),!n&&x>0&&a.jsx("span",{"data-testid":`project-unread-${e.name}`,className:ttt,children:a.jsx(xI,{})})]}),n&&a.jsxs(a.Fragment,{children:[g.map(v=>{const w=v.session,_=w.ownerPersonaId?(u==null?void 0:u(w.ownerPersonaId))??w.ownerPersonaId:null;return a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`project-session-row-${w.sessionId}`,className:`group flex items-center gap-1.5 pl-9 pr-2 py-[5px] mx-1 rounded-md cursor-pointer ${s===w.sessionId?"bg-text-100/10":"hover:bg-text-100/5"}`,onClick:()=>o(w.sessionId),children:[a.jsx("span",{className:"flex-1 min-w-0 truncate text-[13px] text-text-200",children:w.label??w.aiLabel??w.sessionId}),_&&a.jsxs("span",{className:"shrink-0 text-[11px] text-text-400 group-hover:hidden",children:["· ",_]}),a.jsx("span",{className:"hidden group-hover:flex items-center gap-0.5 shrink-0",children:a.jsx("button",{type:"button",title:"置顶","data-testid":`project-session-pin-${w.sessionId}`,onClick:S=>{S.stopPropagation(),l==null||l(w.sessionId,!0)},className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(Ig,{className:"w-3.5 h-3.5"})})}),i.has(w.sessionId)?a.jsx("span",{className:"shrink-0 group-hover:hidden",children:a.jsx(xI,{})}):null]}),a.jsx(Qee,{nodes:v.children,depth:0,activeId:s,unreadIds:i,onSelect:o})]},w.sessionId)}),t.length===0&&a.jsx("div",{"data-testid":`project-sessions-empty-${e.name}`,className:"pl-9 pr-2 py-1 text-[11px] text-text-400 italic",children:"还没有会话"}),!f&&t.length>bB&&a.jsxs("button",{type:"button","data-testid":`project-sessions-show-more-${e.name}`,onClick:()=>m(!0),className:"flex items-center gap-1 pl-9 py-1 text-[12px] text-text-400 hover:text-text-200 cursor-pointer",children:["展开显示 ",a.jsx(Qt,{className:"w-3 h-3"})]})]})]})}const ete={running:{cls:"text-blue-500",Icon:it,spin:!0,label:"进行中 · worker 正在跑"},"awaiting-review":{cls:"text-amber-500",Icon:afe,label:"待核验 · 已交付,等 Master 结论"},accepted:{cls:"text-emerald-500",Icon:Xt,label:"合格 · Master 判过"},failed:{cls:"text-red-500",Icon:In,label:"失败 · worker 回报没做成"}},ntt="还没交付 · worker 已停手";function tte(e){return e.rejectCount>0&&e.stage!=="accepted"}function rtt(e){const t=e.stage?ete[e.stage].label:ntt,n=tte(e)?`被打回过 ${e.rejectCount} 次`:"";return[t,n].filter(Boolean).join(" · ")}function stt({node:e}){const{progress:t}=e,n=tte(t),r=t.stage?ete[t.stage]:null;if(!r&&!n)return null;const s=r==null?void 0:r.Icon,i=rtt(t);return a.jsx(di,{delayDuration:200,children:a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:a.jsxs("span",{"data-testid":`line-progress-${e.sessionId}`,"data-stage":t.stage??"none",role:"img","aria-label":i,title:"",tabIndex:0,className:`inline-flex shrink-0 items-center gap-0.5 text-[11px] font-medium ${(r==null?void 0:r.cls)??""}`,children:[s?a.jsx(s,{className:`h-3.5 w-3.5 ${r!=null&&r.spin?"animate-spin":""}`}):null,n?a.jsxs("span",{className:"text-red-500",children:["×",t.rejectCount]}):null]})}),a.jsx(gi,{side:"bottom",children:i})]})})}function itt({node:e}){return e.ordinal===null?null:a.jsxs("span",{"data-testid":`line-ordinal-${e.sessionId}`,title:`线 ${e.ordinal}(${e.lineId})`,className:"shrink-0 tabular-nums text-[11px] text-text-400",children:["#",e.ordinal]})}function ott({node:e,active:t,onSelect:n}){return a.jsxs("div",{"data-testid":`topic-session-row-${e.sessionId}`,...t?{"aria-current":"true"}:{},title:`${e.lineId} · ${e.label}`,onClick:n,className:`group mx-1 flex cursor-pointer items-center gap-1.5 rounded-md py-[5px] pl-[46px] pr-2 ${t?"bg-text-100/10":"hover:bg-text-100/5"}`,children:[a.jsx(itt,{node:e}),a.jsx(stt,{node:e}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-text-200",children:e.label}),a.jsx("span",{className:"shrink-0 truncate text-[11px] text-text-400",children:e.assignee})]})}function att({title:e,onConfirm:t,onCancel:n}){return a.jsx("div",{role:"dialog","aria-modal":"true","data-testid":"topic-delete-confirm",className:"fixed inset-0 z-[10000] flex items-center justify-center bg-black/40",onClick:n,children:a.jsxs("div",{className:"w-[92%] max-w-sm rounded-lg border border-border bg-bg-0 p-4 shadow-xl",onClick:r=>r.stopPropagation(),children:[a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(ws,{className:"mt-0.5 h-5 w-5 shrink-0 text-red-500"}),a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"text-[14px] text-text-100",children:["删除话题「",a.jsx("span",{className:"break-all font-medium",children:e}),"」?"]}),a.jsx("div",{className:"mt-1 text-[12px] leading-snug text-text-400",children:"这个话题名下的会话会一并删掉:Master 会话,以及它派出去的 worker 会话。"})]})]}),a.jsxs("div",{className:"mt-3 flex items-center justify-end gap-2",children:[a.jsx("button",{type:"button","data-testid":"topic-delete-confirm-cancel",onClick:n,className:"h-8 cursor-pointer rounded-md px-3 text-[12px] text-text-300 hover:bg-text-100/5",children:"取消"}),a.jsx("button",{type:"button","data-testid":"topic-delete-confirm-ok",onClick:t,className:"h-8 cursor-pointer rounded-md bg-red-500 px-3 text-[12px] font-medium text-white hover:opacity-90",children:"删除"})]})]})})}function nte({topic:e,expanded:t,activeSessionId:n,hasUnread:r,running:s,onToggle:i,onSelectTopic:o,onSelectSession:l,onArchiveTopic:c,onRenameTopic:u,onDeleteTopic:d,onPinTopic:h,variant:f="tree"}){const[m,g]=p.useState(!1),[x,b]=p.useState(!1),y=e.title,v=!!(u||h||d),w=()=>{o(),t||i()};return a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`topic-row-${e.topicId}`,...n===e.masterSessionId?{"aria-current":"true"}:{},title:y,onClick:w,...f==="pinned"?{style:{paddingLeft:Xee,gap:Zee}}:{},className:`group mx-1 flex cursor-pointer items-center rounded-md py-[5px] pr-2 ${f==="pinned"?"":"gap-1.5 pl-6"} ${n===e.masterSessionId?"bg-text-100/10":"hover:bg-text-100/5"}`,children:[f==="pinned"?a.jsx("button",{type:"button","aria-label":t?"收起话题":"展开话题","aria-expanded":t,"data-testid":`topic-toggle-${e.topicId}`,onClick:_=>{_.stopPropagation(),i()},className:"shrink-0 rounded hover:bg-text-100/10",children:a.jsx(AH,{"data-testid":`topic-hash-${e.topicId}`,className:`h-4 w-4 ${t?"text-accent":"text-text-300"}`})}):a.jsx("button",{type:"button","aria-label":t?"收起话题":"展开话题","aria-expanded":t,"data-testid":`topic-toggle-${e.topicId}`,onClick:_=>{_.stopPropagation(),i()},className:"shrink-0 rounded p-0.5 text-text-300 hover:bg-text-100/10 hover:text-text-100",children:t?a.jsx(Qt,{className:"h-3.5 w-3.5"}):a.jsx(tr,{className:"h-3.5 w-3.5"})}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-text-100",children:y}),a.jsx(Hee,{sessionId:e.masterSessionId,hasUnread:r,running:s}),(c||v)&&a.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 opacity-0 focus-within:opacity-100 group-hover:opacity-100 has-[[data-state=open]]:opacity-100",children:[c&&a.jsx("button",{type:"button","aria-label":`归档话题 ${y}`,title:"归档","data-testid":`topic-archive-${e.topicId}`,onClick:_=>{_.stopPropagation(),c(e.topicId)},className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(Iu,{className:"h-3.5 w-3.5"})}),v&&a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":`话题操作 ${y}`,"data-testid":`topic-menu-${e.topicId}`,onClick:_=>_.stopPropagation(),className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(ca,{className:"h-3.5 w-3.5"})})}),a.jsxs(Pr,{align:"end",onClick:_=>_.stopPropagation(),children:[u&&a.jsxs(Et,{"data-testid":`topic-rename-${e.topicId}`,onSelect:()=>g(!0),children:[a.jsx(Mu,{className:"mr-2 h-3 w-3 text-text-400"}),"重命名"]}),h&&a.jsxs(Et,{"data-testid":`topic-${e.pinned?"unpin":"pin"}-${e.topicId}`,onSelect:()=>h(e.topicId,!e.pinned),children:[e.pinned?a.jsx(qb,{className:"mr-2 h-3 w-3 text-text-400"}):a.jsx(Ig,{className:"mr-2 h-3 w-3 text-text-400"}),e.pinned?"取消置顶":"置顶"]}),d&&(u||h)&&a.jsx(ma,{}),d&&a.jsxs(Et,{"data-testid":`topic-delete-${e.topicId}`,onSelect:()=>b(!0),className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[a.jsx(ws,{className:"mr-2 h-3 w-3"}),"删除"]})]})]})]})]}),u&&a.jsx(Uee,{open:m,initialLabel:y,title:"重命名话题",fieldLabel:"话题名",testId:"topic-rename-dialog",requireNonEmpty:!0,onSubmit:({label:_})=>{u(e.topicId,_),g(!1)},onCancel:()=>g(!1)}),d&&x&&a.jsx(att,{title:y,onConfirm:()=>{b(!1),d(e.topicId)},onCancel:()=>b(!1)}),t&&a.jsxs(a.Fragment,{children:[e.sessions.map(_=>a.jsx(ott,{node:_,active:n===_.sessionId,onSelect:()=>l(_.sessionId)},_.sessionId)),e.sessions.length===0&&a.jsx("div",{"data-testid":`topic-sessions-empty-${e.topicId}`,className:"py-1 pl-[46px] pr-2 text-[11px] italic text-text-400",children:"还没有派线"})]})]})}function rte({status:e}){return e===null?null:e==="running"?a.jsx(it,{"data-testid":"sidebar-status-running",className:"w-3 h-3 shrink-0 text-emerald-500 animate-spin"}):e==="awaiting"?a.jsx("span",{"data-testid":"sidebar-status-awaiting",className:"w-2 h-2 shrink-0 rounded-full bg-amber-400 animate-pulse"}):a.jsx("span",{"data-testid":"sidebar-status-unread",className:"w-2 h-2 shrink-0 rounded-full bg-blue-500"})}function ltt({title:e,testId:t,expanded:n,onToggle:r,aggregate:s=null,trailing:i}){return a.jsxs("div",{className:"group flex items-center gap-1 pl-3 pr-2 pt-3 pb-1 select-none","data-testid":t,children:[a.jsxs("button",{type:"button","data-testid":`${t}-toggle`,onClick:r,className:"flex items-center gap-1 text-[12px] text-text-400 hover:text-text-200",children:[e,a.jsx(tr,{className:`w-3 h-3 transition-transform ${n?"rotate-90":""}`})]}),!n&&a.jsx(rte,{status:s}),a.jsx("div",{className:"flex-1"}),a.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 focus-within:opacity-100 has-[[data-state=open]]:opacity-100",children:i})]})}function ctt(e){const{sortableId:t,...n}=e,{attributes:r,listeners:s,setNodeRef:i,transform:o,transition:l,isDragging:c}=jW({id:t});return a.jsx("div",{ref:i,style:{transform:Gh.Transform.toString(o),transition:l,opacity:c?.4:void 0},...r,...s,children:a.jsx(Zu,{...n})})}function utt({sessions:e,activeId:t,awaitingIds:n,runningIds:r,unreadIds:s,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,onReorderPins:d,ownerPrincipalId:h,getContactDisplayName:f,getCreatorDisplayName:m,getSessionDisplayName:g,expanded:x,onToggleExpanded:b,projectPaths:y,pinnedProjects:v=[],pinnedTopics:w=[],expandedTopicIds:_,onToggleTopic:S,onSelectTopic:k,onArchiveTopic:C,onRenameTopic:N,onDeleteTopic:T,onPinTopic:E,expandedProjectPaths:R,onToggleProject:O,onNewInProject:P,getPersonaDisplayName:$,onTogglePinProject:F,onRevealProject:B}){const W=p.useMemo(()=>e.filter(se=>lS(se,h)),[e,h]),L=p.useMemo(()=>Sc(W),[W]),D=p.useMemo(()=>new Set(L.map(se=>se.session.sessionId)),[L]),I=p.useMemo(()=>L.filter(se=>typeof se.session.pinnedAt=="number"),[L]),V=p.useMemo(()=>W.filter(se=>typeof se.pinnedAt=="number"&&!D.has(se.sessionId)).map(se=>({session:se,children:[]})),[W,D]),H=p.useMemo(()=>I.filter(se=>!se.session.originOwnerPrincipalId).map(se=>se.session.sessionId),[I]),[M,Y]=p.useState(null);p.useEffect(()=>{if(M==null)return;if(!(M.length===H.length&&M.every(Z=>H.includes(Z)))){Y(null);return}M.every((Z,fe)=>Z===H[fe])&&Y(null)},[H,M]);const X=M??H,K=p.useMemo(()=>{const se=new Map,ae=[];for(const fe of I)fe.session.originOwnerPrincipalId?ae.push(fe):se.set(fe.session.sessionId,fe);return[...X.map(fe=>se.get(fe)).filter(fe=>!!fe),...ae,...V]},[I,X,V]),te=oW(iW(qw,{activationConstraint:{distance:4}})),ce=se=>{if(!d)return;const{active:ae,over:Z}=se;if(!Z||ae.id===Z.id)return;const fe=X.indexOf(String(ae.id)),ve=X.indexOf(String(Z.id));if(fe<0||ve<0)return;const Te=AT(X,fe,ve);Y(Te),d(Te)},J=p.useMemo(()=>[...v].sort((se,ae)=>(se.pinnedAt??0)-(ae.pinnedAt??0)),[v]),de=p.useMemo(()=>J.length>0?zee(e,h,y??[]):new Map,[J,e,h,y]);if(K.length===0&&J.length===0&&w.length===0)return null;const we=se=>({node:se,depth:0,activeId:t,unreadIds:s,runningIds:r,awaitingIds:n,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,getContactDisplayName:f,getCreatorDisplayName:m,getSessionDisplayName:g,ownerPrincipalId:h});return a.jsxs(a.Fragment,{children:[a.jsx(ltt,{title:"置顶",testId:"sidebar-section-pinned-header",expanded:x,onToggle:b,aggregate:x?null:x3([...K,...J.flatMap(se=>de.get(se.path)??[])],{awaitingIds:n,unreadIds:s,runningIds:r})}),x&&a.jsxs("div",{"data-testid":"sidebar-section-pinned",className:"flex flex-col px-1",children:[d?a.jsx("div",{"data-testid":"pinned-dnd-context",children:a.jsx(wW,{sensors:te,collisionDetection:aW,onDragEnd:ce,children:a.jsx(CW,{items:X,strategy:T0e,children:K.map(se=>se.session.originOwnerPrincipalId||!H.includes(se.session.sessionId)?a.jsx(Zu,{...we(se)},se.session.sessionId):a.jsx(ctt,{sortableId:se.session.sessionId,...we(se)},se.session.sessionId))})})}):a.jsx("div",{"data-testid":"pinned-static-list",children:K.map(se=>a.jsx(Zu,{...we(se)},se.session.sessionId))}),J.map(se=>a.jsx(Jee,{project:se,nodes:de.get(se.path)??[],expanded:(R==null?void 0:R.has(se.path))??!1,onToggle:()=>O==null?void 0:O(se.path),activeId:t,unreadIds:s,onSelect:i,onPin:c,onNewInProject:P,getPersonaDisplayName:$,onTogglePinProject:F,onRevealProject:B},se.path)),w.map(se=>a.jsx(nte,{variant:"pinned",topic:se,expanded:(_==null?void 0:_.has(se.topicId))??!1,activeSessionId:t,hasUnread:s.has(se.masterSessionId),running:r.has(se.masterSessionId),onToggle:()=>S==null?void 0:S(se.topicId),onSelectTopic:()=>k==null?void 0:k(se.topicId,se.masterSessionId),onSelectSession:ae=>i(ae),...C?{onArchiveTopic:C}:{},...N?{onRenameTopic:N}:{},...T?{onDeleteTopic:T}:{},...E?{onPinTopic:E}:{}},se.topicId))]})]})}const wB=5;function dtt({sessions:e,activeId:t,unreadIds:n,onSelect:r,onPin:s,ownerPrincipalId:i,projectPaths:o,projects:l,expandedPaths:c,onToggleProject:u,onNewInProject:d,onRefresh:h,onCreateProject:f,getPersonaDisplayName:m,onTogglePinProject:g,onRevealProject:x}){const[b,y]=p.useState(!1),v=p.useMemo(()=>o??l.map(C=>C.path),[o,l]),w=p.useMemo(()=>zee(e,i,v),[e,i,v]),_=p.useMemo(()=>l.filter(C=>C.pinnedAt==null),[l]),S=!!(h||f);if(l.length===0&&!S)return null;const k=b?_:_.slice(0,wB);return a.jsxs("div",{"data-testid":"sidebar-section-projects",children:[a.jsxs("div",{className:"group flex items-center gap-1 pl-3 pr-2 pt-3 pb-1 select-none",children:[a.jsx("span",{className:"text-[12px] text-text-400",children:"项目"}),a.jsx("div",{className:"flex-1"}),(h||f)&&a.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 focus-within:opacity-100 has-[[data-state=open]]:opacity-100",children:a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"projects actions","data-testid":"projects-section-menu",className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsxs(Pr,{align:"start",children:[h&&a.jsxs(Et,{"data-testid":"projects-refresh",onSelect:()=>h(),children:[a.jsx(No,{className:"w-3.5 h-3.5"}),"刷新"]}),f&&a.jsxs(Et,{"data-testid":"projects-new",onSelect:()=>f(),children:[a.jsx(bs,{className:"w-3.5 h-3.5"}),"新建项目…"]})]})]})})]}),l.length===0&&a.jsx("div",{"data-testid":"projects-empty",className:"pl-3 pr-2 py-1 text-[11px] text-text-400 italic select-none",children:"还没有项目"}),k.map(C=>a.jsx(Jee,{project:C,nodes:w.get(C.path)??[],expanded:c.has(C.path),onToggle:()=>u(C.path),activeId:t,unreadIds:n,onSelect:r,onPin:s,onNewInProject:d,getPersonaDisplayName:m,onTogglePinProject:g,onRevealProject:x},C.path)),!b&&_.length>wB&&a.jsxs("button",{type:"button","data-testid":"projects-show-more",onClick:()=>y(!0),className:"flex items-center gap-1 pl-3 py-1 text-[12px] text-text-400 hover:text-text-200 cursor-pointer",children:["展开显示 ",a.jsx(Qt,{className:"w-3 h-3"})]})]})}const _B=new Set;function htt({tree:e,expandedTopicIds:t,collapsedChannelIds:n,activeSessionId:r,onToggleTopic:s,onToggleChannel:i,onSelectTopic:o,onSelectSession:l,onCreateChannel:c,onCreateTopic:u,onEditChannel:d,onDeleteChannel:h,channelError:f,onArchiveTopic:m,onRenameTopic:g,onDeleteTopic:x,onPinTopic:b,unreadIds:y=_B,runningIds:v=_B}){return a.jsxs("div",{"data-testid":"sidebar-section-channels",children:[a.jsxs("div",{className:"group flex select-none items-center gap-1 pb-1 pl-3 pr-2 pt-3",children:[a.jsx("span",{className:"text-[12px] text-text-400",children:"频道"}),a.jsx("div",{className:"flex-1"}),a.jsx("div",{className:"flex items-center gap-0.5 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:a.jsx("button",{type:"button","aria-label":"新建频道","data-testid":"channels-new",onClick:c,className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(bs,{className:"h-3.5 w-3.5"})})})]}),e.length===0&&a.jsx("div",{"data-testid":"channels-empty",className:"select-none py-1 pl-3 pr-2 text-[11px] italic text-text-400",children:"还没有频道"}),e.map(w=>a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`channel-row-${w.channelId}`,title:w.name,role:"button",tabIndex:0,"aria-expanded":!n.has(w.channelId),onClick:()=>i(w.channelId),onKeyDown:_=>{_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),i(w.channelId))},className:"group mx-1 flex cursor-pointer items-center gap-2.5 rounded-md px-3 py-[5px] text-text-100 hover:bg-text-100/5",children:[a.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center ${n.has(w.channelId)?"text-text-300":"text-accent"}`,children:a.jsx(AH,{className:"h-4 w-4"})}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px]",children:w.name}),a.jsxs("span",{className:"hidden shrink-0 items-center gap-0.5 group-hover:flex",children:[a.jsx("button",{type:"button","aria-label":"新建话题",title:`在「${w.name}」下新建话题`,"data-testid":`channel-create-topic-${w.channelId}`,onClick:_=>{_.stopPropagation(),u(w.channelId)},className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(bs,{className:"h-3.5 w-3.5"})}),a.jsx("button",{type:"button","aria-label":`编辑频道 ${w.name}`,"data-testid":`channel-edit-${w.channelId}`,onClick:_=>{_.stopPropagation(),d(w.channelId)},className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(Mu,{className:"h-3.5 w-3.5"})}),a.jsx("button",{type:"button","aria-label":`删除频道 ${w.name}`,"data-testid":`channel-delete-${w.channelId}`,onClick:_=>{_.stopPropagation(),h(w.channelId)},className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-red-500",children:a.jsx(ws,{className:"h-3.5 w-3.5"})})]})]}),(f==null?void 0:f.channelId)===w.channelId&&a.jsx("div",{"data-testid":`channel-error-${w.channelId}`,role:"alert",className:"py-1 pl-11 pr-2 text-[11px] leading-snug text-red-500",children:f.message}),!n.has(w.channelId)&&a.jsxs(a.Fragment,{children:[w.topics.map(_=>a.jsx(nte,{topic:_,expanded:t.has(_.topicId),activeSessionId:r,hasUnread:y.has(_.masterSessionId),running:v.has(_.masterSessionId),onToggle:()=>s(_.topicId),onSelectTopic:()=>o(_.topicId,_.masterSessionId),onSelectSession:l,...m?{onArchiveTopic:m}:{},...g?{onRenameTopic:g}:{},...x?{onDeleteTopic:x}:{},...b?{onPinTopic:b}:{}},_.topicId)),w.topics.length===0&&a.jsx("div",{"data-testid":`channel-topics-empty-${w.channelId}`,className:"select-none py-1 pl-6 pr-2 text-[11px] italic text-text-400",children:"还没有话题"})]})]},w.channelId))]})}const ftt=[10,25,50],ptt="clawd:recents:sort",mtt=[["priority","优先级"],["recency","最近更新"]],gtt="clawd:recents:quick-action",SB=[["pin","置顶"],["archive","归档"],["rename","重命名"]];function xtt({sessions:e,activeId:t,awaitingIds:n,runningIds:r,unreadIds:s,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,ownerPrincipalId:d,getContactDisplayName:h,getCreatorDisplayName:f,getSessionDisplayName:m,projectPaths:g,topicSessionIds:x,bulkArchiveHintCount:b,onDismissBulkHint:y,onBulkArchive:v,bulkArchiveAvailable:w,sortMode:_="priority",onChangeSortMode:S,quickAction:k,onChangeQuickAction:C}){var O;const N=p.useMemo(()=>dS(e,d,g,x),[e,d,g,x]),T=p.useMemo(()=>Sc(N),[N]),E=((O=SB.find(([P])=>P===k))==null?void 0:O[0])??"archive",R=p.useMemo(()=>(_==="recency"?uS(T):Fee(T,{awaitingIds:n,runningIds:r,unreadIds:s})).filter($=>$.session.pinnedAt==null),[T,_,n,r,s]);return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"group flex items-center gap-1 pl-3 pr-2 pt-3 pb-1 select-none",children:[a.jsx("span",{className:"text-[12px] text-text-400",children:"最近"}),a.jsx("div",{className:"flex-1"}),a.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 focus-within:opacity-100 has-[[data-state=open]]:opacity-100",children:a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"recents actions","data-testid":"recents-section-menu",className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsxs(Pr,{align:"start",children:[v&&a.jsxs(a.Fragment,{children:[a.jsx(uc,{children:"批量归档"}),ftt.map(P=>a.jsxs(Et,{"data-testid":`recents-bulk-archive-${P}`,disabled:w?!w(P):!1,onSelect:()=>v(P),children:["只保留最近 ",P," 个"]},P)),a.jsx(ma,{})]}),a.jsx(uc,{children:"聊天排序方式"}),mtt.map(([P,$])=>a.jsxs(Et,{"data-testid":`recents-sort-${P}`,onSelect:()=>S==null?void 0:S(P),children:[a.jsx(Xt,{className:ee("w-3.5 h-3.5 mr-2",_===P?"":"invisible")}),$]},P)),a.jsx(ma,{}),a.jsx(uc,{children:"行内快捷操作"}),SB.map(([P,$])=>a.jsxs(Et,{"data-testid":`recents-quick-action-${P}`,onSelect:()=>C==null?void 0:C(P),children:[a.jsx(Xt,{className:ee("w-3.5 h-3.5 mr-2",E===P?"":"invisible")}),$]},P))]})]})})]}),b!=null&&v&&a.jsxs("div",{"data-testid":"recents-bulk-hint",className:"mx-2 mb-1 px-3 py-2 rounded-md bg-bg-50 border border-border text-[12px] text-text-300",children:["最近会话较多,只保留最近 10 个,其余归档?",a.jsxs("div",{className:"mt-1.5 flex gap-2",children:[a.jsxs("button",{type:"button","data-testid":"recents-bulk-hint-accept",onClick:()=>v(10),className:"px-2 py-0.5 rounded bg-accent text-white text-[11px]",children:["归档 ",b," 个"]}),a.jsx("button",{type:"button","data-testid":"recents-bulk-hint-dismiss",onClick:y,className:"px-2 py-0.5 rounded bg-bg-200 text-text-200 text-[11px]",children:"忽略"})]})]}),a.jsx("div",{"data-testid":"sidebar-section-recents",className:"flex flex-col px-1",children:R.length===0?a.jsx("div",{"data-testid":"sidebar-section-recents-empty",className:"px-3 py-2 text-[11px] text-text-400 italic",children:"还没有会话"}):R.map(P=>a.jsx(Zu,{node:P,depth:0,activeId:t,unreadIds:s,runningIds:r,awaitingIds:n,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,quickAction:E,getContactDisplayName:h,getCreatorDisplayName:f,getSessionDisplayName:m,ownerPrincipalId:d},P.session.sessionId))})]})}const vtt="clawd:sidebar:section:pinned",kB=new Set;function zd({kind:e,icon:t,label:n,active:r,trailing:s,onClick:i}){return a.jsxs("div",{"data-testid":`sidebar-entry-${e}`,className:`group flex items-center gap-2.5 px-3 py-[5px] mx-1 rounded-md cursor-pointer text-text-100 ${r?"bg-text-100/10":"hover:bg-text-100/5"}`,onClick:i,children:[a.jsx("span",{className:"w-4 h-4 shrink-0 text-text-300 inline-flex items-center justify-center",children:t}),a.jsx("span",{className:"flex-1 text-[13px]",children:n}),s]})}function ytt(e){const{onNewPersona:t,onReorderPins:n,onFixedEntryClick:r,activeEntry:s,peopleUnreadCount:i,channelTree:o,expandedTopicIds:l,onToggleTopic:c,onSelectTopic:u,onCreateChannel:d,onCreateTopic:h,onEditChannel:f,onDeleteChannel:m,channelError:g,onArchiveTopic:x,onRenameTopic:b,onDeleteTopic:y,onPinTopic:v,pinnedTopics:w,topicSessionIds:_,footer:S,width:k=288,onResizeStart:C,floating:N=!1,onCollapse:T,onOpenSearch:E,onOpenHive:R,projects:O=[],onNewInProject:P,onRefreshProjects:$,onCreateProject:F,getPersonaDisplayName:B,onPatchProject:W,onRevealProject:L,...D}=e,[I,V]=ym(vtt,!0),H=p.useMemo(()=>O.map(J=>J.path),[O]),{expandedPaths:M,toggleProject:Y}=Oet(),{collapsedChannelIds:X,toggleChannel:K}=$et(),te=p.useMemo(()=>O.filter(J=>J.pinnedAt!=null),[O]),ce=W?{onTogglePinProject:J=>W(J.path,{pinnedAt:J.pinnedAt!=null?null:Date.now()}),...L?{onRevealProject:L}:{}}:{};return a.jsxs("div",{"data-testid":"app-sidebar-nav",className:`relative flex flex-col h-full shrink-0 bg-bg-50/60 ${N?"border border-border rounded-xl overflow-hidden":"border-r border-border-strong"}`,style:{width:k},children:[C&&a.jsx("div",{"data-testid":"sidebar-resize-handle",onPointerDown:C,className:"absolute right-0 top-0 h-full w-1 z-10 cursor-col-resize hover:bg-accent/40 active:bg-accent/60"}),a.jsxs("div",{className:"flex items-center px-4 pt-3 pb-2 shrink-0",children:[a.jsx("div",{className:"flex-1 text-[15px] font-semibold text-text-100",children:"clawd"}),R&&a.jsx("button",{type:"button","aria-label":"Hive 看板",title:"Hive 看板 ⌘⇧H","data-testid":"sidebar-hive",onClick:R,className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(vfe,{className:"w-4 h-4"})}),a.jsx("button",{type:"button","aria-label":"搜索",title:"搜索 ⌘K","data-testid":"sidebar-search",onClick:E,className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(ui,{className:"w-4 h-4"})}),a.jsx("button",{type:"button","aria-label":"collapse sidebar","data-testid":"sidebar-collapse",onClick:T,className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(WH,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto pb-2",children:[a.jsxs("div",{className:"flex flex-col gap-px pb-1",children:[a.jsx(zd,{kind:"new",icon:a.jsx(GH,{className:"w-4 h-4"}),label:"新对话",active:s==="new",onClick:()=>r("new")}),a.jsx(zd,{kind:"persona",icon:a.jsx(ra,{className:"w-4 h-4"}),label:"persona",active:s==="persona",onClick:()=>r("persona"),trailing:a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"persona actions","data-testid":"sidebar-persona-menu",onClick:J=>J.stopPropagation(),className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10 opacity-0 group-hover:opacity-100 focus:opacity-100 data-[state=open]:opacity-100",children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsx(Pr,{align:"end",onClick:J=>J.stopPropagation(),children:a.jsxs(Et,{"data-testid":"sidebar-persona-new",onSelect:t,children:[a.jsx(bs,{className:"w-3.5 h-3.5 mr-2"}),"新建 persona"]})})]})}),a.jsx(zd,{kind:"people",icon:a.jsx(fT,{className:"w-4 h-4"}),label:"联系人",active:s==="people",onClick:()=>r("people"),trailing:a.jsx(a.Fragment,{children:i>0&&a.jsx("span",{"data-testid":"sidebar-people-unread",className:"shrink-0 min-w-4 h-4 px-1 inline-flex items-center justify-center rounded-full bg-blue-500 text-white text-[10px] leading-none",children:i})})}),a.jsx(zd,{kind:"prs",icon:a.jsx(cT,{className:"w-4 h-4"}),label:"Pull Request",active:s==="prs",onClick:()=>r("prs")}),a.jsx(zd,{kind:"shift",icon:a.jsx(ihe,{className:"w-4 h-4"}),label:"已安排",active:s==="shift",onClick:()=>r("shift")}),a.jsx(zd,{kind:"exts",icon:a.jsx(ape,{className:"w-4 h-4"}),label:"插件",active:s==="exts",onClick:()=>r("exts")})]}),a.jsx(utt,{...D,expanded:I,onToggleExpanded:()=>V(!I),onReorderPins:n,projectPaths:H,pinnedProjects:te,expandedProjectPaths:M,onToggleProject:Y,onNewInProject:P,getPersonaDisplayName:B,...ce,pinnedTopics:w,expandedTopicIds:l??kB,...c?{onToggleTopic:c}:{},...u?{onSelectTopic:u}:{},...x?{onArchiveTopic:x}:{},...b?{onRenameTopic:b}:{},...y?{onDeleteTopic:y}:{},...v?{onPinTopic:v}:{}}),P&&a.jsx(dtt,{...D,projectPaths:H,projects:O,expandedPaths:M,onToggleProject:Y,onNewInProject:P,onRefresh:$,onCreateProject:F,getPersonaDisplayName:B,...ce}),c&&u&&d&&h&&f&&m&&a.jsx(htt,{tree:o??[],expandedTopicIds:l??kB,collapsedChannelIds:X,activeSessionId:D.activeId,onToggleTopic:c,onToggleChannel:K,onSelectTopic:u,onSelectSession:D.onSelect,onCreateChannel:d,onCreateTopic:h,onEditChannel:f,onDeleteChannel:m,channelError:g??null,unreadIds:D.unreadIds,runningIds:D.runningIds,...x?{onArchiveTopic:x}:{},...b?{onRenameTopic:b}:{},...y?{onDeleteTopic:y}:{},...v?{onPinTopic:v}:{}}),a.jsx(xtt,{...D,projectPaths:H,..._?{topicSessionIds:_}:{}})]}),S&&a.jsx("div",{className:"shrink-0 border-t border-border-strong",children:S})]})}const W1={online:0,offline:1},btt=new Set;function CB(e,t){if(e.pinnedAt!=null||t.pinnedAt!=null)return e.pinnedAt==null?1:t.pinnedAt==null?-1:t.pinnedAt-e.pinnedAt;if(e.hasUnread!==t.hasUnread)return e.hasUnread?-1:1;const n=W1[e.presence],r=W1[t.presence];return n!==r?n-r:e.displayName.localeCompare(t.displayName)}function y3(e,t,n=[],r=btt){const s=new Map;for(const c of e){const u=`${c.provider}:${c.ownerId}`,d=s.get(u);d?d.push(c):s.set(u,[c])}const i=[...s.entries()].map(([c,u])=>{const d=[...u].sort((f,m)=>{const g=r.has(f.deviceId),x=r.has(m.deviceId);if(g!==x)return g?-1:1;const b=W1[t.get(f.deviceId)??"offline"],y=W1[t.get(m.deviceId)??"offline"];return b!==y?b-y:f.deviceId.localeCompare(m.deviceId)}),h=d.map(f=>f.pinnedAt).filter(f=>f!=null);return{key:c,displayName:d[0].displayName||d[0].deviceId,devices:d,presence:d.some(f=>t.get(f.deviceId)==="online")?"online":"offline",pinnedAt:h.length>0?Math.max(...h):null,hasUnread:d.some(f=>r.has(f.deviceId)),disconnected:!1}}),o=new Set(e.map(c=>c.deviceId)),l=n.filter(c=>!c.devices.some(u=>o.has(u.deviceId))).map(c=>({key:c.unionId,displayName:c.displayName||c.unionId,devices:[],presence:"offline",pinnedAt:null,hasUnread:!1,disconnected:!0})).sort((c,u)=>c.displayName.localeCompare(u.displayName));return{pinned:i.filter(c=>c.pinnedAt!=null).sort(CB),main:i.filter(c=>c.pinnedAt==null).sort(CB),disconnected:l}}function wtt({device:e,onConnect:t}){const[n,r]=p.useState(!1),[s,i]=p.useState(null);return a.jsxs("div",{"data-testid":`people-public-device-${e.deviceId}`,className:"group flex flex-col px-2 py-1.5 rounded-md hover:bg-text-100/5",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-200/60 text-text-300",children:a.jsx(fT,{className:"w-3.5 h-3.5"})}),a.jsx("span",{className:"flex-1 truncate text-[12.5px] text-text-200",children:e.name}),t&&a.jsx("button",{type:"button",disabled:n,className:"px-2 py-0.5 rounded border border-border hover:bg-text-100/5 text-[11px] text-text-400 opacity-0 group-hover:opacity-100 disabled:opacity-100 disabled:cursor-default",onClick:()=>{r(!0),i(null),t({deviceId:e.deviceId,url:e.url,name:e.name}).catch(o=>i(o instanceof Error?o.message:String(o))).finally(()=>r(!1))},children:n?"连接中…":"连接"})]}),s&&a.jsx("div",{"data-testid":`people-public-device-${e.deviceId}-error`,className:"pl-8 pt-0.5 text-[11px] text-red-500 truncate",children:s})]})}function _tt({presence:e}){return a.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full ring-2 ring-bg-100 ${e==="online"?"bg-emerald-400":"bg-slate-400"}`})}function Stt({person:e,selectedDeviceId:t,onSelect:n,onHover:r,onHoverEnd:s}){if(e.disconnected)return a.jsxs("div",{"data-testid":`people-list-placeholder-${e.key}`,className:"flex items-center gap-2 px-2 py-1.5 rounded-md opacity-55",title:"同组成员,还没连上——对方启动 clawd 后会自动出现",children:[a.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-200/40 text-text-400 shrink-0",children:a.jsx(qh,{className:"w-3.5 h-3.5"})}),a.jsx("span",{className:"flex-1 truncate text-[13px] text-text-400",children:e.displayName}),a.jsx("span",{className:"shrink-0 text-[10px] text-text-500",children:"未连接"})]});const i=e.devices[0],o=e.devices.some(l=>l.deviceId===t);return a.jsxs("div",{"data-testid":`people-list-row-${i.deviceId}`,className:`flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer ${o?"bg-text-100/10":"hover:bg-text-100/5"}`,onClick:()=>n(i.deviceId),onMouseEnter:r?()=>r(i.deviceId):void 0,onMouseLeave:s,children:[a.jsxs("span",{className:"relative shrink-0",children:[a.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-200/60 text-text-300",children:a.jsx(qh,{className:"w-3.5 h-3.5"})}),a.jsx(_tt,{presence:e.presence})]}),a.jsx("span",{className:"flex-1 truncate text-[13px] text-text-100",children:e.displayName}),e.devices.length>1&&a.jsxs("span",{"data-testid":`people-list-row-${i.deviceId}-device-count`,className:"shrink-0 text-[10px] text-text-500 tabular-nums",title:`${e.devices.length} 台设备(在卡片里看)`,children:[e.devices.length," 台"]}),e.hasUnread&&a.jsx("span",{"data-testid":`people-list-row-${i.deviceId}-unread`,"aria-label":"unread",className:"w-2 h-2 rounded-full bg-error shrink-0"}),a.jsx(tr,{"aria-hidden":"true","data-testid":`people-list-row-${i.deviceId}-more`,className:`w-3.5 h-3.5 shrink-0 transition-colors ${o?"text-text-300":"text-text-500/60"}`})]})}function ktt({contacts:e,presenceByDeviceId:t,selectedDeviceId:n,onSelect:r,onHover:s,onHoverEnd:i,publicDevices:o,onConnectPublicDevice:l,visitors:c=[],visitorUnreadIds:u,onOpenVisitor:d,orgMeshProgress:h,orgPeers:f,unreadDeviceIds:m}){const{pinned:g,main:x,disconnected:b}=y3(e,t,f,m),y=w=>a.jsx(Stt,{person:w,selectedDeviceId:n,onSelect:r,onHover:s,onHoverEnd:i},w.key),v=g.length===0&&x.length===0&&b.length===0;return a.jsxs("div",{className:"w-[248px] shrink-0 h-full border-r border-border overflow-y-auto px-2 py-3",children:[a.jsx("div",{className:"px-2 pb-2",children:a.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"联系人"})}),h&&a.jsxs("div",{className:"px-2 pb-2","data-testid":"people-org-mesh-progress",children:[a.jsxs("div",{className:"flex items-center justify-between text-[11px] text-text-400",children:[a.jsx("span",{children:"正在连接同事…"}),a.jsxs("span",{className:"tabular-nums",children:[h.done,"/",h.total]})]}),a.jsx("div",{className:"mt-1 h-0.5 w-full overflow-hidden rounded-full bg-text-100/10",children:a.jsx("div",{className:"h-full bg-text-400/60 transition-[width] duration-300",style:{width:`${h.total>0?Math.round(h.done/h.total*100):0}%`}})}),h.failed>0&&a.jsxs("div",{className:"mt-0.5 text-[10px] text-text-500",children:[h.failed," 台没连上(对方不在线,之后会自动补上)"]})]}),g.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex flex-col gap-px","data-testid":"people-list-pinned",children:g.map(y)}),a.jsx("div",{className:"mx-2 my-2 border-t border-border","data-testid":"people-list-pinned-divider"})]}),a.jsxs("div",{className:"flex flex-col gap-px",children:[x.map(y),b.map(y),v&&a.jsx("div",{className:"px-2 py-2 text-[12px] text-text-400 italic",children:"还没有联系人"})]}),c.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"px-2 pt-4 pb-1 text-[11px] text-text-400",children:"访客"}),a.jsx("div",{className:"flex flex-col gap-px",children:c.map(w=>a.jsxs("div",{role:"button",tabIndex:0,"data-testid":`people-visitor-row-${w.deviceId}`,className:"flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer hover:bg-text-100/5",onClick:()=>d==null?void 0:d(w.deviceId),onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),d==null||d(w.deviceId))},children:[a.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-200/60 text-text-300 shrink-0",children:a.jsx(qh,{className:"w-3.5 h-3.5"})}),a.jsx("span",{className:"flex-1 truncate text-[13px] text-text-100",children:w.displayName||w.deviceId}),(u==null?void 0:u.has(w.deviceId))&&a.jsx("span",{"data-testid":`people-visitor-unread-${w.deviceId}`,className:"w-2 h-2 rounded-full bg-error shrink-0"})]},w.deviceId))})]}),o.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"px-2 pt-4 pb-1 text-[11px] text-text-400",children:"公共设备"}),a.jsx("div",{className:"flex flex-col gap-px",children:o.map(w=>a.jsx(wtt,{device:w,onConnect:l},w.deviceId))})]})]})}function Ctt({items:e,onInstall:t,onOpen:n}){return a.jsxs("div",{"data-testid":"person-extensions-list",className:"flex flex-col",children:[a.jsxs("header",{className:"flex items-center gap-1 pl-2 py-1 text-[10px] uppercase tracking-wider text-text-400",children:[a.jsx(Pw,{className:"w-3 h-3"}),"Extensions",a.jsx("span",{className:"ml-auto pr-2 text-[10px] tabular-nums",children:e.length})]}),a.jsx("ul",{className:"flex flex-col",children:e.map(r=>a.jsx(Ntt,{item:r,onInstall:t,onOpen:n},r.extId))})]})}function Ntt({item:e,onInstall:t,onOpen:n}){const s=e.state.kind==="installed-up-to-date"||e.state.kind==="installed-with-update";return a.jsxs("li",{"data-testid":"person-extension-row","data-ext-id":e.extId,"data-state":e.state.kind,role:s?"button":void 0,tabIndex:s?0:-1,onClick:s?()=>n==null?void 0:n(e.extId):void 0,className:ee("group flex items-center gap-1.5 px-2 py-1.5 rounded",s&&"cursor-pointer hover:bg-text-100/5"),children:[a.jsx(Pw,{className:"h-3.5 w-3.5 shrink-0 text-text-400","aria-hidden":!0}),a.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-1.5",children:[a.jsx("span",{className:"truncate text-[13px] text-text-100",children:e.name}),a.jsxs("span",{className:"shrink-0 text-[10px] text-text-400 tabular-nums",children:["v",e.publishedVersion]})]}),a.jsx(jtt,{item:e,onInstall:t})]})}function jtt({item:e,onInstall:t}){const n=e.state;return n.kind==="not-installed"?a.jsxs("button",{type:"button",onClick:r=>{r.stopPropagation(),t==null||t(e.extId)},"data-testid":"install-button",className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] font-medium bg-accent/10 hover:bg-accent/20 text-accent border border-accent/30 transition-colors",children:[a.jsx(OH,{className:"w-2.5 h-2.5"}),"安装"]}):n.kind==="installing"?a.jsxs("span",{"data-testid":"installing-indicator",className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] text-text-400 bg-bg-100 border border-border",children:[a.jsx(it,{className:"w-2.5 h-2.5 animate-spin"}),"装中"]}):n.kind==="installed-up-to-date"?a.jsxs("span",{"data-testid":"installed-chip",className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] text-success border border-success/30 bg-success/5",children:[a.jsx(ci,{className:"w-2.5 h-2.5"}),"已装"]}):n.kind==="installed-with-update"?a.jsxs("span",{"data-testid":"update-available-chip",className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] text-warning border border-warning/30 bg-warning/5",children:[a.jsx(RH,{className:"w-2.5 h-2.5"}),"有新版"]}):n.kind==="install-failed"?a.jsxs("span",{"data-testid":"install-failed-chip",title:n.reason,className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] text-error border border-error/30 bg-error/5",children:[a.jsx(In,{className:"w-2.5 h-2.5"}),"失败"]}):null}function vI({starred:e,onToggle:t,testid:n,revealClass:r="group-hover:opacity-100"}){return a.jsx("button",{type:"button","data-testid":n,title:e?"取消收藏":"收藏","aria-label":e?"取消收藏":"收藏","aria-pressed":e,onClick:s=>{s.stopPropagation(),t()},className:`p-0.5 rounded shrink-0 hover:bg-text-100/10 ${e?"text-amber-500":`text-text-400 opacity-0 ${r} focus-visible:opacity-100`}`,children:a.jsx(cj,{className:"w-3.5 h-3.5",fill:e?"currentColor":"none"})})}function Jp({children:e,first:t}){return a.jsx("div",{className:`px-3 ${t?"pt-3":"pt-4"} pb-2 text-[12px] text-text-400`,children:e})}function Ett({personas:e,rootsByPersonaId:t,sets:n,selectedPersonaId:r,onHoverPersona:s,onSelectPersona:i,onNewPersona:o,favorites:l}){const c=(l==null?void 0:l.filter)==="starred",u=c?e.filter(b=>l.isFavorite(b.personaId)):e,d=u.filter(b=>!b.cloud),h=u.filter(b=>b.cloud),f=new Set(e.flatMap(b=>b.cloud?[b.cloud.personaId]:[])),m=l?e.filter(b=>l.isFavorite(b.personaId)).length+l.contactFavorites.length:0,g=b=>{var w;const y=t.get(b.personaId)??[],v=!b.cloud&&f.has(b.personaId);return a.jsxs("div",{"data-testid":`persona-list-row-${b.personaId}`,onMouseEnter:()=>s(b.personaId),onMouseLeave:()=>s(null),onClick:()=>i(b.personaId),className:`group flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer ${r===b.personaId?"bg-text-100/10":"hover:bg-text-100/5"}`,children:[a.jsx(rf,{tool:b.tool,className:`w-4 h-4 shrink-0 ${nf(b.tool)}`}),(w=b.cloud)!=null&&w.label&&b.cloud.label!==b.label?a.jsxs("span",{className:"flex-1 min-w-0 flex flex-col leading-tight",children:[a.jsx("span",{className:"truncate text-[13px] text-text-100",children:b.label}),a.jsx("span",{"data-testid":`persona-list-subtitle-${b.personaId}`,className:"truncate text-[11px] text-text-400",children:b.cloud.label})]}):a.jsx("span",{className:"flex-1 truncate text-[13px] text-text-100",children:b.label}),v&&a.jsx("span",{"data-testid":`persona-list-cloud-mark-${b.personaId}`,title:"已上云","aria-label":"已上云",className:"shrink-0 text-text-400",children:a.jsx(Mw,{className:"w-3.5 h-3.5"})}),l&&a.jsx(vI,{starred:l.isFavorite(b.personaId),onToggle:()=>l.onToggle(b),testid:`persona-list-star-${b.personaId}`}),a.jsx(rte,{status:x3(y,n)}),y.length>0&&a.jsx("span",{"data-testid":`persona-list-count-${b.personaId}`,className:"shrink-0 text-[10px] text-text-400 tabular-nums",children:y.length})]},b.personaId)},x=b=>{const y=`${b.deviceId}::${b.personaId}`;return a.jsxs("div",{"data-testid":`persona-list-contact-row-${y}`,onClick:()=>l==null?void 0:l.onOpenContact(b.deviceId),className:"group flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer hover:bg-text-100/5",children:[a.jsx(rf,{tool:b.tool,className:`w-4 h-4 shrink-0 ${nf(b.tool)}`}),a.jsxs("span",{className:"flex-1 truncate text-[13px] text-text-100",children:[b.label,a.jsxs("span",{className:"ml-1 text-[11px] text-text-400",children:["· ",b.contactName]})]}),a.jsx(vI,{starred:!0,onToggle:()=>l==null?void 0:l.onToggleContact(b),testid:`persona-list-contact-star-${y}`})]},y)};return a.jsxs("div",{"data-testid":"persona-list-column",className:"w-[248px] h-full overflow-y-auto",children:[l&&a.jsx("div",{className:"px-2 pt-2.5 pb-1",children:a.jsx("div",{role:"tablist",className:"flex p-0.5 rounded-md bg-text-100/5 text-[12px]",children:["all","starred"].map(b=>a.jsx("button",{type:"button",role:"tab","aria-selected":l.filter===b,"data-testid":`persona-list-filter-${b}`,onClick:()=>l.onFilterChange(b),className:`flex-1 flex items-center justify-center gap-1 py-1 rounded ${l.filter===b?"bg-bg-100 shadow-sm text-text-100":"text-text-400 hover:text-text-200"}`,children:b==="all"?"全部":a.jsxs(a.Fragment,{children:[a.jsx(cj,{className:"w-3 h-3",fill:l.filter===b?"currentColor":"none"}),"收藏",m>0&&a.jsx("span",{"data-testid":"persona-list-favorite-count",className:"tabular-nums text-text-400",children:m})]})},b))})}),c?m===0?a.jsxs("div",{"data-testid":"persona-list-favorites-empty",className:"px-4 py-10 text-center text-[12px] text-text-400 leading-relaxed",children:[a.jsx(cj,{className:"w-5 h-5 mx-auto mb-2 opacity-60"}),"还没有收藏",a.jsx("br",{}),"在「全部」里 hover persona 行点 ☆;",a.jsx("br",{}),"联系人的 persona 在「人」→ 联系人卡片里点 ☆"]}):a.jsxs(a.Fragment,{children:[d.length>0&&a.jsxs("div",{"data-testid":"persona-list-group-local",children:[a.jsx(Jp,{first:!0,children:"我的 persona"}),a.jsx("div",{className:"flex flex-col px-1",children:d.map(g)})]}),h.length>0&&a.jsxs("div",{"data-testid":"persona-list-group-cloud",children:[a.jsx(Jp,{first:d.length===0,children:"云上"}),a.jsx("div",{className:"flex flex-col px-1",children:h.map(g)})]}),l.contactFavorites.length>0&&a.jsxs("div",{"data-testid":"persona-list-group-contact",children:[a.jsx(Jp,{first:d.length===0&&h.length===0,children:"联系人的"}),a.jsx("div",{className:"flex flex-col px-1",children:l.contactFavorites.map(x)})]})]}):a.jsxs(a.Fragment,{children:[a.jsx(Jp,{first:!0,children:"我的 persona"}),a.jsxs("div",{className:"flex flex-col px-1",children:[d.length===0&&a.jsx("div",{"data-testid":"persona-list-empty",className:"px-3 py-2 text-[11px] text-text-400 italic",children:"还没有 persona"}),d.map(g)]}),a.jsx("div",{className:"px-1 pt-2",children:a.jsxs("button",{type:"button","data-testid":"persona-list-new",onClick:o,className:"w-full flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[12px] text-text-400 hover:text-text-200 hover:bg-text-100/5",children:[a.jsx(bs,{className:"w-3.5 h-3.5"}),"新建 persona"]})}),h.length>0&&a.jsxs("div",{"data-testid":"persona-list-group-cloud",children:[a.jsx(Jp,{children:"云上"}),a.jsx("div",{className:"flex flex-col px-1",children:h.map(g)})]})]})]})}function Itt({device:e,active:t,online:n,onSelect:r,onSetNote:s}){const[i,o]=p.useState(!1),[l,c]=p.useState(e.note??""),u=()=>{o(!1);const d=l.trim();d!==(e.note??"")&&(s==null||s(e.deviceId,d))};return a.jsxs("div",{"data-testid":`contact-detail-device-${e.deviceId}`,className:ee("group flex items-center gap-2 rounded-md px-2 py-1.5",t?"bg-text-100/10":"hover:bg-text-100/5"),children:[a.jsx("span",{className:ee("h-1.5 w-1.5 shrink-0 rounded-full",n?"bg-emerald-400":"bg-slate-400")}),i?a.jsx("input",{autoFocus:!0,"data-testid":`contact-detail-device-${e.deviceId}-note-input`,className:"flex-1 rounded border border-border bg-transparent px-1 py-0.5 text-[12px] text-text-100 outline-none",placeholder:"备注这台设备,例如「老王的 MacBook」",value:l,onChange:d=>c(d.target.value),onBlur:u,onKeyDown:d=>{d.key==="Enter"&&u(),d.key==="Escape"&&(c(e.note??""),o(!1))}}):a.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col items-start text-left",onClick:()=>!t&&(r==null?void 0:r(e.deviceId)),children:[a.jsx("span",{className:ee("w-full truncate text-[12px]",e.note?"text-text-100":"text-text-400 italic"),children:e.note||"未备注"}),a.jsx("span",{className:"w-full truncate font-mono text-[10px] text-text-500",children:e.deviceId})]}),!i&&a.jsxs(a.Fragment,{children:[t&&a.jsx("span",{className:"shrink-0 text-[10px] text-text-400",children:"当前"}),s&&a.jsx("button",{type:"button","aria-label":"备注这台设备","data-testid":`contact-detail-device-${e.deviceId}-note-edit`,className:"shrink-0 rounded p-1 text-text-400 opacity-0 hover:bg-text-100/10 group-hover:opacity-100",onClick:()=>{c(e.note??""),o(!0)},children:a.jsx(Mu,{className:"h-3 w-3"})})]})]})}function Ttt({contact:e,personDevices:t,onSelectDevice:n,onSetDeviceNote:r,presenceByDeviceId:s,personas:i,personasLoading:o=!1,personasError:l=null,onRetryPersonas:c,onReconnect:u,sessions:d,extensions:h,activeSessionId:f,awaitingIds:m,runningIds:g,unreadIds:x,onMessage:b,onPin:y,onSetRemoteAccess:v,onRemove:w,onCreateSession:_,onSelectSession:S,onDeleteSession:k,onEditSession:C,onInstallExtension:N,onOpenInstalledExtension:T,isPersonaFavorite:E,onTogglePersonaFavorite:R}){const O=aTe(e),[P,$]=p.useState(null),F=L=>{$(null);try{const D=_(L);D&&D.catch(I=>$(I instanceof Error?I.message:String(I)))}catch(D){$(D instanceof Error?D.message:String(D))}},B=p.useMemo(()=>{const L=new Map;for(const I of d){if(!I.ownerPersonaId)continue;const V=L.get(I.ownerPersonaId);V?V.push(I):L.set(I.ownerPersonaId,[I])}const D=new Map;for(const[I,V]of L)V.sort((H,M)=>M.updatedAt>H.updatedAt?1:-1),D.set(I,Sc(V));return D},[d]),W=p.useMemo(()=>new Map(d.map(L=>[L.sessionId,av(L)])),[d]);return a.jsxs("div",{className:"max-w-[560px] px-8 py-8","data-testid":"contact-detail",children:[a.jsxs("div",{className:"group flex items-center gap-3 mb-6","data-testid":"contact-detail-header",children:[a.jsx("span",{className:"inline-flex shrink-0 items-center justify-center w-11 h-11 rounded-full bg-slate-200/60 text-text-300",children:a.jsx(qh,{className:"w-5 h-5"})}),a.jsx("div",{className:"flex-1 min-w-0",children:a.jsx("div",{className:"text-[16px] font-semibold text-text-100 truncate",children:e.displayName||e.deviceId})}),a.jsxs("button",{type:"button","data-testid":"contact-detail-message",className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md border border-border hover:bg-text-100/5 text-[12.5px] text-text-100",onClick:b,children:[a.jsx($fe,{className:"w-3.5 h-3.5"}),"消息"]}),a.jsxs(Gr,{children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"contact actions","data-testid":"contact-detail-menu",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(ca,{className:"w-4 h-4"})})}),a.jsxs(Pr,{align:"end",children:[a.jsx(Et,{onSelect:()=>y(e.pinnedAt==null),children:e.pinnedAt==null?"置顶联系人":"取消置顶"}),a.jsx(Et,{onSelect:w,children:"移除联系人"})]})]})]}),a.jsx(Rtt,{allowed:e.remoteAccessAllowed,onChange:v}),t&&t.length>1&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"mb-2 text-[12px] text-text-400",children:["该联系人的设备(",t.length," 台)"]}),a.jsx("div",{className:"mb-6 flex flex-col gap-px","data-testid":"contact-detail-devices",children:t.map(L=>a.jsx(Itt,{device:L,active:L.deviceId===e.deviceId,online:(s==null?void 0:s.get(L.deviceId))==="online",onSelect:n,onSetNote:r},L.deviceId))})]}),a.jsx("div",{className:"mb-2 text-[12px] text-text-400",children:"分享的 persona"}),P&&a.jsx("div",{"data-testid":"contact-detail-create-session-error",className:"mb-2 rounded border border-error/40 bg-error-dim px-2 py-1 text-[11px] text-error",children:Mtt(P)}),O!=="ok"?a.jsx(Att,{variant:O,onReconnect:u}):a.jsxs(a.Fragment,{children:[o&&i.length===0&&a.jsx("div",{"data-testid":"contact-detail-personas-loading",className:"flex flex-col gap-2",children:[0,1].map(L=>a.jsxs("div",{className:"border border-border rounded-lg overflow-hidden",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border/60",children:[a.jsx("span",{className:"w-3.5 h-3.5 shrink-0 rounded-full bg-text-100/10 animate-pulse"}),a.jsx("span",{className:"h-3 w-24 rounded bg-text-100/10 animate-pulse"})]}),a.jsx("div",{className:"px-3 py-2",children:a.jsx("span",{className:"block h-3 w-40 rounded bg-text-100/10 animate-pulse"})})]},L))}),!o&&l&&a.jsxs("div",{"data-testid":"contact-detail-personas-error",className:"mb-2 rounded-lg border border-error/40 bg-error-dim px-3 py-2.5 text-[12px] text-error",children:[a.jsx("div",{children:Ott(l)}),c&&a.jsxs("button",{type:"button","data-testid":"contact-detail-personas-retry",className:"mt-1.5 inline-flex items-center gap-1 rounded border border-error/40 px-2 py-0.5 text-[11.5px] hover:bg-error/10",onClick:c,children:[a.jsx(Tf,{className:"w-3 h-3"}),"重试"]})]}),!o&&!l&&i.length===0&&a.jsx("div",{"data-testid":"contact-detail-no-personas",className:"text-[12px] text-text-400 italic border border-dashed border-border rounded-lg px-4 py-5 text-center",children:"对方还没有分享 persona"})]}),a.jsx("div",{className:"flex flex-col gap-2",children:i.map(L=>{const D=B.get(L.personaId)??[];return a.jsxs("div",{"data-testid":`persona-block-${L.personaId}`,className:"group/pblock border border-border rounded-lg bg-bg-100 overflow-hidden",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border/60",children:[a.jsx(rf,{tool:L.tool,className:`w-3.5 h-3.5 shrink-0 ${nf(L.tool)}`}),a.jsx("span",{className:"flex-1 text-[13px] text-text-100 truncate",children:L.label}),E&&R&&a.jsx(vI,{starred:E(L.personaId),onToggle:()=>R(L),testid:`persona-block-star-${L.personaId}`,revealClass:"group-hover/pblock:opacity-100"}),a.jsx("button",{type:"button",title:"新建会话","data-testid":`persona-block-add-${L.personaId}`,className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10 opacity-0 group-hover/pblock:opacity-100",onClick:()=>F(L.personaId),children:a.jsx(bs,{className:"w-3.5 h-3.5"})})]}),a.jsxs("div",{className:"py-1 px-1",children:[D.map(I=>a.jsx(Zu,{node:I,depth:0,showCopyResume:!1,activeId:f,unreadIds:x,runningIds:g,awaitingIds:m,onSelect:S,onEdit:C?(V,H)=>C(V,H):void 0,onDelete:k,getSessionDisplayName:V=>W.get(V)},I.session.sessionId)),D.length===0&&a.jsxs("button",{type:"button","data-testid":`persona-block-empty-${L.personaId}`,onClick:()=>F(L.personaId),className:"w-full flex items-center gap-1.5 pl-[33px] pr-1.5 py-1.5 rounded text-[11.5px] text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors",children:[a.jsx(bs,{className:"w-3 h-3"}),"点击新建会话"]})]})]},L.personaId)})}),h.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"mt-6 mb-2 text-[12px] text-text-400",children:"发布的插件"}),a.jsx(Ctt,{items:h,onInstall:N,onOpen:T})]})]})}function Rtt({allowed:e,onChange:t}){const[n,r]=p.useState(!1),[s,i]=p.useState(null),[o,l]=p.useState(null),c=o??e,u=d=>{n||(l(d),r(!0),i(null),t(d).catch(h=>{i(h instanceof Error?h.message:String(h)),l(null)}).finally(()=>r(!1)))};return a.jsxs("section",{className:"mb-6 rounded-lg border border-border px-3 py-2.5",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c?a.jsx(_pe,{className:"h-4 w-4 shrink-0 text-success"}):a.jsx(kpe,{className:"h-4 w-4 shrink-0 text-text-400"}),a.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"允许远程操作我的设备"})]}),a.jsx($tt,{checked:c,disabled:n,onChange:u,testid:"contact-remote-access-toggle"})]}),a.jsx("p",{className:"mt-1.5 text-[11px] text-text-400 leading-relaxed",children:c?"对方的 persona 可在你的设备上跑命令、反向访问文件——以你的账户权限执行,无目录级限制,等同于给对方开一个 shell。撤销授权立即失效。":"对方将无法远程操作你的设备(跨设备 exec 与 SSH 反向访问都被拒)。"}),s&&a.jsx("div",{"data-testid":"contact-remote-access-error",className:"mt-2 rounded border border-error/40 bg-error-dim px-2 py-1 text-[11px] text-error",children:s})]})}function Mtt(e){return/404|not found|unreachable|timeout|ECONN|failed to fetch|network|not open|closed/i.test(e)?"对方设备当前不在线,无法新建会话":`新建会话失败:${e}`}function Ptt(e){return/PEER_LOGIN_EXPIRED/i.test(e)?"对方设备登录已过期,请让对方在 ClawOS 中重新登录后重试":/LOGIN_EXPIRED/i.test(e)?"本机登录已过期,请重新登录后重试":/404|DEVICE_UNREACHABLE|not found|unreachable|timeout|ECONN|failed to fetch|network|not open|closed/i.test(e)?"对方设备当前不在线,请让对方启动 ClawOS 后重试":`重新连接失败:${e}`}function Ott(e){return/TOKEN_EXPIRED/i.test(e)?"连接凭证已过期,重新连接即可恢复":/UNAUTHORIZED|FORBIDDEN/i.test(e)?"对方拒绝了访问(对方版本过旧或未授权)":/timeout|unreachable|ECONN|not open|closed|failed to fetch|network/i.test(e)?"对方设备不可达(可能不在线),稍后重试":`拉取失败:${e}`}const Dtt={broken:"建联未完成,无法获取对方分享的 persona",expired:"连接凭证已过期,重新连接即可恢复"};function Att({variant:e="broken",onReconnect:t}){const[n,r]=p.useState(!1),[s,i]=p.useState(null),o=()=>{n||!t||(r(!0),i(null),t().catch(l=>{const c=l instanceof Error?l.message:String(l);i(Ptt(c))}).finally(()=>r(!1)))};return a.jsxs("div",{"data-testid":"contact-detail-broken-link","data-variant":e,className:"rounded-lg border border-dashed border-border px-4 py-4 text-center",children:[a.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-[12.5px] text-text-200",children:[a.jsx(_fe,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),Dtt[e]]}),t&&a.jsxs("button",{type:"button","data-testid":"contact-detail-reconnect",disabled:n,onClick:o,className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md border border-border hover:bg-text-100/5 text-[12.5px] text-text-100 disabled:opacity-50",children:[a.jsx(Tf,{className:ee("w-3.5 h-3.5",n&&"animate-spin")}),n?"重新连接中…":"重新连接"]}),s&&a.jsx("div",{"data-testid":"contact-detail-reconnect-error",className:"mt-2 rounded border border-error/40 bg-error-dim px-2 py-1 text-[11px] text-error text-left",children:s})]})}function $tt({checked:e,disabled:t,onChange:n,testid:r}){return a.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:t,onClick:()=>n(!e),"data-testid":r,className:ee("relative inline-flex h-6 w-11 shrink-0 rounded-full transition-colors disabled:opacity-50",e?"bg-accent":"bg-bg-300"),children:a.jsx("span",{className:ee("inline-block h-5 w-5 rounded-full bg-bg-0 shadow transition-transform",e?"translate-x-[22px]":"translate-x-0.5"),style:{marginTop:2}})})}const Ltt=150,Ftt=250;function ste(e,t={}){const{openDelayMs:n=Ltt,closeDelayMs:r=Ftt,initialPinned:s=null}=t,[i,o]=p.useState(null),[l,c]=p.useState(null),u=p.useRef(null),d=p.useCallback(()=>{u.current!=null&&(clearTimeout(u.current),u.current=null)},[]),h=p.useCallback((y,v)=>{d(),u.current=setTimeout(()=>{u.current=null,o(y),y!=null&&c(w=>w==null?w:y)},v)},[d]);p.useEffect(()=>{if(d(),!e){o(null),c(null);return}s!=null&&(c(s),o(s))},[e,d]),p.useEffect(()=>d,[d]);const f=p.useCallback(y=>h(y,n),[h,n]),m=p.useCallback(()=>{document.querySelector("[data-radix-popper-content-wrapper]")||document.querySelector("[data-radix-focus-guard]")||h(null,r)},[h,r]),g=p.useCallback(()=>d(),[d]),x=p.useCallback(y=>{d();const v=l===y?null:y;c(v),o(v)},[d,l]),b=p.useCallback(()=>{d(),c(null),o(null)},[d]);return{selected:l??i,pinned:l,onHoverEnter:f,onHoverLeave:m,onCardEnter:g,onToggle:x,clear:b}}const Btt=6e4,ztt=5e3;function Htt(e){return e.startsWith("wss://")?"https://"+e.slice(6):e.startsWith("ws://")?"http://"+e.slice(5):e.startsWith("https://")||e.startsWith("http://")?e:null}function f2(e){const t=Htt(e);if(!t)return null;try{const n=new URL(t);return`${n.protocol}//${n.host}/healthz`}catch{return null}}const Utt=6;async function Wtt(e,t,n){let r=0;const s=Array.from({length:Math.min(t,e.length)},async()=>{for(;;){const i=r++;if(i>=e.length)return;await n(e[i])}});await Promise.all(s)}function Vtt(e,t={}){const n=t.intervalMs??Btt,r=t.timeoutMs??ztt,s=t.maxConcurrent??Utt,i=t.enabled??!0,[o,l]=p.useState(new Map),c=p.useRef(e);c.current=e;const u=p.useRef(t.fetchImpl??(typeof fetch<"u"?fetch:void 0));u.current=t.fetchImpl??(typeof fetch<"u"?fetch:void 0);const d=p.useRef(t.isPageHidden??(()=>typeof document<"u"&&document.visibilityState==="hidden"));d.current=t.isPageHidden??(()=>typeof document<"u"&&document.visibilityState==="hidden"),p.useEffect(()=>{l(m=>{const g=new Set(e.filter(y=>y.remoteUrl&&f2(y.remoteUrl)!==null).map(y=>y.deviceId));let x=!1;const b=new Map;for(const[y,v]of m)g.has(y)?b.set(y,v):x=!0;return x?b:m})},[e]);const h=p.useMemo(()=>e.filter(m=>m.remoteUrl&&f2(m.remoteUrl)!==null).map(m=>m.deviceId).sort().join("|"),[e]),f=p.useRef(()=>Promise.resolve());return p.useEffect(()=>{let m=!1;const g=async()=>{const b=u.current;if(!b){Pe("presence","tick skip: no fetch impl");return}if(d.current()){Pe("presence","tick skip: page hidden");return}const y=c.current.map(w=>({id:w.deviceId,remoteUrl:w.remoteUrl,healthz:w.remoteUrl?f2(w.remoteUrl):null})),v=y.map(w=>!w.remoteUrl||!w.healthz?null:{id:w.id,url:w.healthz}).filter(w=>w!==null);Pe("presence","tick",{rawCount:y.length,rawContacts:y,targetCount:v.length,targets:v}),v.length!==0&&await Wtt(v,s,async({id:w,url:_})=>{const S=new AbortController,k=setTimeout(()=>S.abort(),r);let C;try{C=(await b(_,{signal:S.signal,method:"GET"})).ok?"online":"offline"}catch{C="offline"}finally{clearTimeout(k)}m||l(N=>{if(N.get(w)===C)return N;const T=new Map(N);return T.set(w,C),T})})};if(f.current=g,!i)return()=>{m=!0,f.current=()=>Promise.resolve()};const x=setInterval(()=>{g()},n);return()=>{m=!0,clearInterval(x),f.current=()=>Promise.resolve()}},[n,r,s,i]),p.useEffect(()=>{i&&(Pe("presence","ownerKey change / enabled → trigger tick",{ownerKey:h,contactsLen:c.current.length}),f.current())},[h,i]),o}function qtt(e){const[t,n]=p.useState(null);return p.useEffect(()=>{const r=e.on("org-mesh:progress",i=>{const o=i;if(!(typeof o.total!="number"||typeof o.done!="number")){if(!o.active){n(null);return}n({total:o.total,done:o.done,connected:o.connected??0,failed:o.failed??0,active:!0})}}),s=e.on("daemon:disconnected",()=>n(null));return()=>{r(),s()}},[e]),t}function Ktt(e,t){const[n,r]=p.useState([]);return p.useEffect(()=>{if(!t)return;let s=!1;return e.request("org:peers",{}).then(i=>{if(s)return;const o=i==null?void 0:i.peers;r(Array.isArray(o)?o:[])}).catch(()=>{s||r([])}),()=>{s=!0}},[e,t]),n}function Gtt(e){var w,_;const{open:t,onClose:n,contacts:r,remoteGated:s,onEnsureContactLoaded:i,sidebarWidth:o=288,insetTop:l=0,insetBottom:c=0}=e,u=l>0||c>0,d=Vtt(r,{enabled:t}),h=qtt(e.client),f=Ktt(e.client,t),m=p.useMemo(()=>y3(r,d,void 0,e.unreadDeviceIds),[r,d,e.unreadDeviceIds]),g=ste(t,{initialPinned:e.initialSelectedId??null}),x=g.selected,b=r.find(S=>S.deviceId===x)??null,y=p.useMemo(()=>{var S;return b?((S=[...m.pinned,...m.main].find(k=>k.devices.some(C=>C.deviceId===b.deviceId)))==null?void 0:S.devices)??[b]:[]},[m,b]);p.useEffect(()=>{if(!t)return;const S=k=>{k.key==="Escape"&&(k.defaultPrevented||document.querySelector("[data-radix-focus-guard]")||n())};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[t,n]);const v=p.useRef(null);return p.useEffect(()=>{const S=v.current;v.current=x,!(s||x==null||x===S)&&i(x)},[x,s,i]),t?a.jsxs(a.Fragment,{children:[a.jsx("div",{"data-testid":"people-flyout-mask",className:"absolute inset-y-0 left-0 md:left-[var(--sidebar-w)] right-0 z-30 bg-black/10",style:{"--sidebar-w":`${o}px`},onClick:n}),a.jsxs("div",{"data-testid":"people-flyout",role:"dialog","aria-label":"联系人",className:"absolute left-0 md:left-[var(--sidebar-w)] z-40 flex pointer-events-none",style:{"--sidebar-w":`${o}px`,top:l,bottom:c},children:[a.jsx("div",{className:`h-full bg-bg-100 border-border shadow-xl pointer-events-auto ${u?"border rounded-xl overflow-hidden":"border-l"}`,children:s?a.jsx("div",{"data-testid":"people-flyout-gate",className:"w-[248px] h-full overflow-y-auto p-4 border-r border-border",children:e.loginCardNode}):a.jsxs("div",{className:"h-full flex flex-col",children:[a.jsx("div",{className:"w-[248px] shrink-0 border-r border-border",children:e.loginCardNode}),e.onAddContact&&a.jsx("div",{className:"w-[248px] shrink-0 border-r border-border px-2 pt-2",children:a.jsxs("button",{type:"button","data-testid":"people-add-contact",onClick:e.onAddContact,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-[12.5px] text-text-200 hover:bg-text-100/5 hover:text-text-100 transition-colors",children:[a.jsx(Vpe,{className:"w-3.5 h-3.5 shrink-0 text-text-300"}),"添加联系人"]})}),a.jsx("div",{className:"flex-1 min-h-0",children:a.jsx(ktt,{contacts:r,presenceByDeviceId:d,selectedDeviceId:x,onSelect:g.onToggle,onHover:g.onHoverEnter,onHoverEnd:g.onHoverLeave,publicDevices:e.publicDevices,onConnectPublicDevice:e.onConnectPublicDevice,visitors:e.visitors,visitorUnreadIds:e.visitorUnreadIds,onOpenVisitor:e.onOpenVisitor,unreadDeviceIds:e.unreadDeviceIds,orgMeshProgress:h,orgPeers:f})})]})}),b&&a.jsxs("div",{"data-testid":"people-flyout-card",onMouseEnter:g.onCardEnter,onMouseLeave:g.onHoverLeave,className:`self-start mt-6 ml-2 w-[520px] max-h-[calc(100%-3rem)] overflow-y-auto rounded-xl border border-border bg-bg-100 shadow-2xl pointer-events-auto ${Mx}`,children:[a.jsx("div",{className:"flex justify-end px-2 pt-2",children:a.jsx("button",{type:"button","aria-label":"close contact card","data-testid":"people-flyout-card-close",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",onClick:g.clear,children:a.jsx(Jt,{className:"w-4 h-4"})})}),a.jsx(Ttt,{contact:b,personas:e.personasByOwnerId.get(b.deviceId)??[],personasLoading:((w=e.personaLoadingOwnerIds)==null?void 0:w.has(b.deviceId))??!e.personasByOwnerId.has(b.deviceId),personasError:((_=e.personaErrorByOwnerId)==null?void 0:_.get(b.deviceId))??null,onRetryPersonas:e.onRetryPersonas?()=>e.onRetryPersonas(b.deviceId):void 0,onReconnect:e.onReconnectContact?()=>e.onReconnectContact(b):void 0,sessions:e.sessionsByOwnerId.get(b.deviceId)??[],extensions:e.extensionsByOwnerId.get(b.deviceId)??[],personDevices:y,presenceByDeviceId:d,onSelectDevice:g.onToggle,onSetDeviceNote:e.onSetContactNote,activeSessionId:e.activeSessionId,awaitingIds:e.awaitingIds,runningIds:e.runningIds,unreadIds:e.unreadIds,onMessage:()=>e.onMessage(b.deviceId),onPin:S=>e.onPinContact(b.deviceId,S),onSetRemoteAccess:S=>e.onSetContactRemoteAccess(b,S),onRemove:()=>e.onRemoveContact(b),onCreateSession:S=>e.onCreateRemoteSession(b.deviceId,S),onSelectSession:e.onSelectSession,...e.isRemotePersonaFavorite&&e.onToggleRemotePersonaFavorite?{isPersonaFavorite:S=>e.isRemotePersonaFavorite(b.deviceId,S),onTogglePersonaFavorite:S=>e.onToggleRemotePersonaFavorite(b.deviceId,S)}:{},onDeleteSession:e.onDeleteRemoteSession?S=>e.onDeleteRemoteSession(b.deviceId,S):void 0,onEditSession:e.onEditRemoteSession?(S,k)=>e.onEditRemoteSession(b.deviceId,S,k):void 0,onInstallExtension:e.onInstallExtension?S=>{const k=(e.extensionsByOwnerId.get(b.deviceId)??[]).find(C=>C.extId===S);e.onInstallExtension(b.deviceId,S,k==null?void 0:k.publishedHash)}:void 0,onOpenInstalledExtension:e.onOpenInstalledExtension?S=>e.onOpenInstalledExtension(b.deviceId,S):void 0})]})]})]}):null}const ny=(e,t)=>e.personaId===t.personaId&&e.deviceId===t.deviceId,NB=e=>`${e.deviceId??""}::${e.personaId}`;function jB(e){return e.some(t=>!t.deviceId&&t.personaId===Fi)?e:[{personaId:Fi},...e]}function Ytt({open:e,mode:t,initial:n,personas:r,contactGroups:s,onExpandContact:i,onSubmit:o,onCancel:l,submitting:c,error:u}){const[d,h]=p.useState(""),[f,m]=p.useState(""),[g,x]=p.useState([]),[b,y]=p.useState([]),[v,w]=p.useState(()=>new Set),_=JSON.stringify(n??null),S=p.useRef(n);S.current=n;const k=p.useRef(i);k.current=i,p.useEffect(()=>{if(!e)return;const D=S.current;h((D==null?void 0:D.name)??""),x(jB((D==null?void 0:D.memberPersonas)??[])),y((D==null?void 0:D.memberContactDeviceIds)??[]),m("");const I=new Set(((D==null?void 0:D.memberPersonas)??[]).map(V=>V.deviceId).filter(V=>!!V));w(I);for(const V of I)k.current(V)},[e,_]);const C=D=>{w(I=>{const V=new Set(I);return V.has(D)?V.delete(D):V.add(D),V}),v.has(D)||i(D)},N=f.trim().toLowerCase(),T=D=>!N||D.label.toLowerCase().includes(N)||D.id.toLowerCase().includes(N),E=p.useMemo(()=>r.filter(T),[r,N]),R=p.useMemo(()=>s.map(D=>{const I=!N||D.displayName.toLowerCase().includes(N),V=!!N&&!I&&!D.personas,H=I?D.personas??[]:(D.personas??[]).filter(T);return{g:D,shown:H,nameHit:I,unsearchable:V}}).filter(D=>D.nameHit||D.unsearchable||D.shown.length>0),[s,N]),O=d.trim(),P=g.filter(D=>D.deviceId||D.personaId!==Fi).length,$=O.length>0&&P>0&&!c,F=()=>{$&&o({name:O,memberPersonas:jB(g),memberContactDeviceIds:b})},B=xi(F,l),W=D=>{!D.deviceId&&D.personaId===Fi||x(I=>I.some(V=>ny(V,D))?I.filter(V=>!ny(V,D)):[...I,D])},L=D=>{y(I=>I.includes(D)?I.filter(V=>V!==D):[...I,D])};return e?os.createPortal(a.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:l,"data-testid":"channel-dialog-overlay",children:a.jsxs("div",{"data-testid":"channel-dialog",className:"w-[440px] 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:D=>D.stopPropagation(),children:[a.jsx("div",{className:"text-[15px] font-semibold text-text-100",children:t==="create"?"新建频道":"编辑频道"}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:"频道名"}),a.jsx("input",{autoFocus:!0,type:"text",value:d,disabled:c,onChange:D=>h(D.target.value),...B,placeholder:"clawd 开发","data-testid":"channel-dialog-name",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 disabled:opacity-60"})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-1",children:[a.jsx("label",{className:"block text-[12px] font-semibold text-text-200",children:"成员(Master 之外至少 1 个 persona)"}),a.jsxs("span",{className:"text-[11px] text-text-400",children:["已选 ",P+b.length]})]}),a.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 mb-2 border border-bg-300 rounded-lg",children:[a.jsx(ui,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),a.jsx("input",{value:f,onChange:D=>m(D.target.value),placeholder:"搜索 persona / 联系人…","data-testid":"channel-dialog-search",className:"w-full bg-transparent text-[13px] text-text-100 outline-none placeholder:text-text-500"}),f&&a.jsx("button",{type:"button","aria-label":"清空搜索",onClick:()=>m(""),className:"p-0.5 rounded text-text-400 hover:bg-text-100/10",children:a.jsx(Jt,{className:"w-3 h-3"})})]}),a.jsxs("div",{className:"max-h-72 overflow-y-auto pr-1 flex flex-col gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] font-medium text-text-400 mb-0.5",children:"我的 persona"}),E.length===0?a.jsx("div",{className:"px-1 py-1 text-[11px] text-text-400 italic",children:"没有匹配的 persona"}):E.map(D=>{const I=D.id===Fi,V={personaId:D.id};return a.jsxs("label",{title:I?"频道必须有 Master 才能操盘,不能取消":void 0,className:`flex items-center gap-2 px-1 py-1 rounded text-[13px] text-text-100 hover:bg-text-100/5 ${I?"cursor-default":"cursor-pointer"}`,children:[a.jsx("input",{type:"checkbox","data-testid":`member-persona-${D.id}`,checked:I||g.some(H=>ny(H,V)),disabled:I,onChange:()=>W(V)}),a.jsx(ra,{className:"w-3.5 h-3.5 shrink-0 text-text-300"}),a.jsx("span",{className:"shrink-0",children:D.label}),a.jsx("span",{className:"text-[11px] text-text-400 truncate",children:D.id}),I&&a.jsx("span",{"data-testid":"member-persona-master-required",className:"ml-auto shrink-0 text-[11px] text-text-400",children:"必选"})]},D.id)})]}),R.map(({g:D,shown:I,unsearchable:V})=>{const H=v.has(D.deviceId),M=g.filter(ce=>ce.deviceId===D.deviceId),Y=D.personas?M.filter(ce=>!D.personas.some(J=>J.id===ce.personaId)):M,X=!!D.errorText||!!D.loading,K=D.personas?X?"不在最近拿到的名单里":"对方已取消分享":D.loading?"读取中":D.errorText?"当前不可达":"未连上对方",te=M.length+(b.includes(D.deviceId)?1:0);return a.jsxs("div",{children:[a.jsxs("button",{type:"button","data-testid":`contact-group-${D.deviceId}`,onClick:()=>C(D.deviceId),className:"w-full flex items-center gap-1.5 px-1 py-1 rounded hover:bg-text-100/5 cursor-pointer",children:[H?a.jsx(Qt,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}):a.jsx(tr,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),a.jsx(qh,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),a.jsx("span",{className:"text-[12px] font-medium text-text-200",children:D.displayName}),H&&D.loading&&a.jsx("span",{className:"text-[11px] text-text-500",children:"读取 persona…"}),H&&!D.loading&&D.errorText&&a.jsx("span",{className:"text-[11px] text-red-500",children:D.errorText}),H&&!D.loading&&!D.errorText&&D.brokenLink&&a.jsx("span",{className:"text-[11px] text-text-500",children:"未连上"}),!H&&V&&a.jsx("span",{className:"text-[11px] text-text-500",children:"未展开,搜不到他的 persona"}),te>0&&a.jsxs("span",{className:"ml-auto shrink-0 text-[11px] text-text-400",children:["已选 ",te]})]}),H&&a.jsxs("div",{className:"pl-2 border-l border-bg-300 ml-2.5",children:[a.jsxs("label",{className:"flex items-center gap-2 px-1 py-1 rounded text-[13px] text-text-100 hover:bg-text-100/5 cursor-pointer",children:[a.jsx("input",{type:"checkbox","data-testid":`member-contact-${D.deviceId}`,checked:b.includes(D.deviceId),onChange:()=>L(D.deviceId)}),a.jsx(zH,{className:"w-3.5 h-3.5 shrink-0 text-text-300"}),a.jsx("span",{className:"shrink-0",children:"本人"}),a.jsx("span",{className:"text-[11px] text-text-400",children:"可发消息"})]}),I.map(ce=>{const J={personaId:ce.id,deviceId:D.deviceId};return a.jsxs("label",{className:"flex items-center gap-2 px-1 py-1 rounded text-[13px] text-text-100 hover:bg-text-100/5 cursor-pointer",children:[a.jsx("input",{type:"checkbox","data-testid":`member-persona-${D.deviceId}--${ce.id}`,checked:g.some(de=>ny(de,J)),onChange:()=>W(J)}),a.jsx(ra,{className:"w-3.5 h-3.5 shrink-0 text-text-300"}),a.jsx("span",{className:"shrink-0",children:ce.label}),a.jsx("span",{className:"text-[11px] text-text-400 truncate",children:ce.id})]},NB(J))}),Y.map(ce=>a.jsxs("label",{title:"名单里有它,但现在拉不到对方的 persona 列表",className:"flex items-center gap-2 px-1 py-1 rounded text-[13px] text-text-300 hover:bg-text-100/5 cursor-pointer",children:[a.jsx("input",{type:"checkbox","data-testid":`member-persona-${D.deviceId}--${ce.personaId}`,checked:!0,onChange:()=>W(ce)}),a.jsx(ra,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),a.jsx("span",{className:"shrink-0 truncate",children:ce.personaId}),a.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-text-400",children:K})]},NB(ce))),D.personas&&I.length===0&&Y.length===0&&a.jsx("div",{className:"px-1 py-1 text-[11px] text-text-400 italic",children:N?"他名下没有匹配的 persona":"未公开任何 persona"}),!D.personas&&D.loading&&a.jsx("div",{className:"px-1 py-1 text-[11px] text-text-400 italic",children:"读取中…"}),!D.personas&&!D.loading&&D.brokenLink&&a.jsx("div",{className:"px-1 py-1 text-[11px] text-text-400 italic",children:"和他的连接没建好,去「联系人」里重新连接后才能选他的 persona"})]})]},D.deviceId)})]}),u&&a.jsx("div",{className:"mt-1.5 text-[11px] text-red-500","data-testid":"channel-dialog-error",children:u})]}),a.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[a.jsx("button",{type:"button",onClick:l,className:"px-4 py-1.5 text-[12px] text-text-300 rounded-lg hover:bg-text-100/5 transition-colors cursor-pointer",children:"取消"}),a.jsx("button",{type:"button",onClick:F,disabled:!$,"data-testid":"channel-dialog-submit",className:"px-4 py-1.5 text-[12px] font-medium text-bg-0 rounded-lg bg-text-100 hover:bg-text-200 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",children:c?"保存中…":t==="create"?"创建":"保存"})]})]})}),document.body):null}function Xtt(e){const[t,n]=p.useState([]),[r,s]=p.useState(!0),[i,o]=p.useState(null),l=p.useCallback(async()=>{if(!e){s(!1);return}s(!0),o(null);try{const u=await new qt(e).channelList();n(Array.isArray(u==null?void 0:u.channels)?u.channels:[])}catch(u){o(u instanceof Error?u.message:String(u))}finally{s(!1)}},[e]);p.useEffect(()=>{l()},[l]),p.useEffect(()=>{if(e)return e.on("channel:changed",u=>{u!=null&&u.topicId||l()})},[e,l]);const c=p.useCallback(async u=>{o(null);try{const d=await u(new qt(e));return await l(),d}catch(d){throw o(d instanceof Error?d.message:String(d)),d}},[e,l]);return{channels:t,loading:r,error:i,refresh:l,create:u=>c(async d=>(await d.channelCreate(u)).channel),update:async u=>{await c(d=>d.channelUpdate(u))},remove:async u=>{await c(d=>d.channelDelete({channelId:u}))}}}const EB={topicsByChannel:{},linesByTopic:{}};function Ztt(e,t){const n={},r=new Set;for(const i of t){const o=e.topicsByChannel[i];if(o){n[i]=o;for(const l of o)r.add(l.id)}}const s={};for(const[i,o]of Object.entries(e.linesByTopic))r.has(i)&&(s[i]=o);return{topicsByChannel:n,linesByTopic:s}}function Qtt(e,t,n,r){const[s,i]=p.useState(EB),[o,l]=p.useState(0),[c,u]=p.useState(null),d=p.useRef(0),h=t.map(g=>g.id).join(",");p.useEffect(()=>{const g=++d.current,x=h===""?[]:h.split(",");if(!e||x.length===0){i(EB),u(h);return}i(b=>Ztt(b,x)),Promise.all(x.map(async b=>{const y=await e.topicList({channelId:b}).then(v=>Array.isArray(v==null?void 0:v.topics)?v.topics:[],v=>(Pe("app","topicList failed",{channelId:b,err:String(v)}),null));y===null||d.current!==g||(i(v=>({...v,topicsByChannel:{...v.topicsByChannel,[b]:y}})),await Promise.all(y.map(async v=>{const w=await e.topicGet({topicId:v.id}).then(_=>Array.isArray(_==null?void 0:_.lines)?_.lines:[],_=>(Pe("app","topicGet failed",{topicId:v.id,err:String(_)}),null));w===null||d.current!==g||i(_=>({..._,linesByTopic:{..._.linesByTopic,[v.id]:w}}))})))})).then(()=>{d.current===g&&u(h)})},[e,h,o]);const f=p.useRef({});p.useEffect(()=>{const g=new Set;for(const v of Object.values(s.topicsByChannel))for(const w of v)g.add(w.masterSessionId);const x={};for(const v of n)g.has(v.sessionId)&&(x[v.sessionId]=v.updatedAt);const b=f.current;f.current=x,Object.keys(x).some(v=>b[v]!==void 0&&b[v]!==x[v])&&l(v=>v+1)},[n,s.topicsByChannel]);const m=p.useCallback(()=>l(g=>g+1),[]);return p.useEffect(()=>{if(r)return r.on("channel:changed",()=>m())},[r,m]),{topicsByChannel:s.topicsByChannel,linesByTopic:s.linesByTopic,loaded:c===h,reload:m}}function Jtt(e){const t=new Map(e.records.map(i=>[i.dispatchId,i])),n=new Set(e.sessions.map(i=>i.sessionId)),r=new Map(e.personas.filter(i=>i.label).map(i=>[i.personaId,i.label])),s=new Map(e.contacts.filter(i=>i.displayName).map(i=>[i.deviceId,i.displayName]));return(i,o,l)=>{const c=t.get(i),u=c!==void 0&&c.workerSessionId===l,d=(u?c.sourcePersonaId:c==null?void 0:c.targetPersonaId)??o,h=u?c.sourceSessionId:c==null?void 0:c.workerSessionId,f=h&&n.has(h)?h:void 0,m=u||c==null?void 0:c.targetDeviceId,g=m?s.get(m):void 0,x=m?"remote-device":h&&!f?"session-gone":void 0;if(!d)return;const b=r.get(d),y=e.lineIndex.get(i);return{...y?{line:y}:{},persona:b?{id:d,label:b}:{id:d},...m?{device:g?{id:m,displayName:g}:{id:m}}:{},...f?{sessionId:f}:{},...x?{unreachable:x}:{}}}}const IB=[];function ent(e,t,n){const[r,s]=p.useState(null),i=p.useRef(0);return p.useEffect(()=>{const o=++i.current;!e||!t||e.personaDispatchList({relatedSessionId:t}).then(l=>{i.current===o&&s({sessionId:t,records:Array.isArray(l==null?void 0:l.records)?l.records:IB})},l=>{i.current===o&&Pe("app","personaDispatchList failed",{sessionId:t,err:String(l)})})},[e,t,n]),r&&r.sessionId===t?r.records:IB}function tnt(e){const t=!hl(e.tool),n=e.menu!==void 0,r=`${ite} ${ote(t)} ${n?"rounded-l px-2":"rounded px-2"}`,s=a.jsxs("button",{type:"button","aria-label":"发布到云上","aria-disabled":t||void 0,title:t?void 0:"发布到云上","data-testid":"persona-detail-deploy",onClick:t?void 0:e.onDeploy,className:r,children:[a.jsx(Mw,{className:"size-3.5"}),"发布到云上"]}),i=t?a.jsx(di,{delayDuration:200,children:a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:s}),a.jsx(gi,{side:"bottom",align:"end",className:"max-w-[240px] leading-relaxed",children:"云上只跑 codex / pi / claude 引擎的 persona。把下方的「引擎」改成其中一个之后就能发布。"})]})}):s;return n?a.jsxs("span",{className:"inline-flex",children:[i,e.menu]}):i}const ite="inline-flex items-center gap-1 border py-1 text-xs font-medium transition-colors",ote=e=>e?"cursor-not-allowed border-border bg-transparent text-text-400":"border-accent/50 bg-accent-dim text-accent hover:bg-accent hover:text-accent-contrast",nnt=e=>{const n=!hl(e)?"border-border bg-transparent text-text-400 hover:bg-text-100-dim/40":ote(!1);return`${ite} ${n} -ml-px rounded-r px-1`};function rnt({persona:e,roots:t,activeSessionId:n,awaitingIds:r,runningIds:s,unreadIds:i,onCreateSession:o,createSessionBlockedReason:l,onOpenSettings:c,onDeployToCloud:u,deployStatus:d,deployHistory:h,onDelete:f,onSelectSession:m,onEditSession:g,onDeleteSession:x,ownerPrincipalId:b,getCreatorDisplayName:y,getSessionDisplayName:v,settings:w,connectors:_,cloudApiKey:S,cloudLarkBot:k}){return a.jsxs("div",{"data-testid":"persona-detail",children:[a.jsxs("div",{className:"flex items-center gap-3 px-5 pb-4 border-b border-border",children:[a.jsx("span",{className:"inline-flex shrink-0 items-center justify-center w-10 h-10 rounded-full bg-bg-200",children:a.jsx(rf,{tool:e.tool,className:`w-5 h-5 ${nf(e.tool)}`})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"text-[15px] font-medium text-text-100 truncate",children:e.label}),a.jsxs("div",{className:"text-[12px] text-text-400",children:[t.length," 个会话",e.cloud&&a.jsx("span",{"data-testid":"persona-detail-cloud-badge",className:"ml-1.5 px-1.5 py-0.5 rounded bg-text-100/10 text-[11px]",children:"云上"})]})]}),o&&a.jsxs("button",{type:"button","data-testid":"persona-detail-new-session",onClick:o,disabled:l!==void 0,title:l,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-accent text-accent-contrast hover:bg-accent-hover text-[12.5px] font-medium disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-accent",children:[a.jsx(bs,{className:"w-3.5 h-3.5"}),"新建会话"]}),u&&a.jsxs("div",{className:"relative",children:[a.jsx(tnt,{tool:e.tool,onDeploy:u,...h!==void 0?{menu:h}:{}}),a.jsx("div",{className:"absolute right-0 top-full mt-0.5 whitespace-nowrap",children:d})]}),w||!c?null:a.jsx("button",{type:"button","aria-label":"人格设置",title:"人格设置","data-testid":"persona-detail-settings",onClick:c,className:"p-1.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(Aw,{className:"w-4 h-4"})}),f&&a.jsx("button",{type:"button","aria-label":"删除人格",title:"删除人格","data-testid":"persona-detail-delete",onClick:f,className:"p-1.5 rounded text-text-400 hover:text-error hover:bg-text-100/10",children:a.jsx(ws,{className:"w-4 h-4"})})]}),w?a.jsx("div",{className:"border-b border-border",children:w}):null,S?a.jsx("div",{className:"border-b border-border px-3 py-3",children:S}):null,k?a.jsx("div",{className:"border-b border-border",children:k}):null,_?a.jsx("div",{className:"border-b border-border",children:_}):null,a.jsxs("div",{className:"px-3 py-3",children:[a.jsx("div",{className:"px-2 pb-1.5 text-text-400 text-sm",children:"会话"}),t.length===0?o?a.jsxs("button",{type:"button","data-testid":"persona-detail-no-sessions",onClick:o,disabled:l!==void 0,title:l,className:"w-full flex items-center gap-1.5 pl-[33px] pr-3 py-2 rounded text-[12px] text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:text-text-400 disabled:hover:bg-transparent",children:[a.jsx(bs,{className:"w-3 h-3"}),"点击新建会话"]}):a.jsx("div",{"data-testid":"persona-detail-no-sessions-readonly",className:"pl-[33px] pr-3 py-2 text-[12px] text-text-400",children:"话题的 Master 会话会出现在这里"}):t.map(C=>a.jsx(Zu,{node:C,depth:0,activeId:n,unreadIds:i,runningIds:s,awaitingIds:r,onSelect:m,onEdit:g,onDelete:x,ownerPrincipalId:b,getCreatorDisplayName:y,getSessionDisplayName:v},C.session.sessionId))]})]})}function snt(e){const{open:t,onClose:n,sidebarWidth:r=288,insetTop:s=0,insetBottom:i=0,personas:o,sessions:l}=e,c=ste(t,{initialPinned:e.initialSelectedId??null}),u=c.selected,d=p.useMemo(()=>{const x=new Map;for(const y of l){if(!y.ownerPersonaId)continue;const v=x.get(y.ownerPersonaId);v?v.push(y):x.set(y.ownerPersonaId,[y])}const b=new Map;for(const[y,v]of x)b.set(y,uS(Sc(v)));return b},[l]);if(p.useEffect(()=>{if(!t)return;const x=b=>{b.key==="Escape"&&(b.defaultPrevented||document.querySelector("[data-radix-focus-guard]")||n())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[t,n]),!t)return null;const h=o.find(x=>x.personaId===u)??null,f=s>0||i>0,m=(x,b)=>{var y,v,w,_,S,k;return a.jsx(rnt,{persona:x,roots:d.get(x.personaId)??[],activeSessionId:e.activeSessionId,awaitingIds:e.awaitingIds,runningIds:e.runningIds,unreadIds:e.unreadIds,...x.personaId===Fi?{}:{onCreateSession:()=>e.onCreateSession(x.personaId)},...x.cloud?{}:{onOpenSettings:()=>e.onOpenPersonaSettings(x.personaId),onDelete:()=>e.onDeletePersona(x.personaId),...e.onDeployPersona?{onDeployToCloud:()=>{var C;return(C=e.onDeployPersona)==null?void 0:C.call(e,x.personaId)},deployStatus:(y=e.renderDeployStatus)==null?void 0:y.call(e,x.personaId),deployHistory:(v=e.renderDeployHistory)==null?void 0:v.call(e,x.personaId)}:{}},onSelectSession:e.onSelectSession,onEditSession:e.onEditSession,onDeleteSession:e.onDeleteSession,ownerPrincipalId:e.ownerPrincipalId,getCreatorDisplayName:e.getCreatorDisplayName,getSessionDisplayName:e.getSessionDisplayName,settings:x.cloud||(w=e.renderSettings)==null?void 0:w.call(e,x.personaId),connectors:b.connectors,...b.blockedReason?{createSessionBlockedReason:b.blockedReason}:{},cloudApiKey:x.cloud?(_=e.renderCloudApiKey)==null?void 0:_.call(e,x.cloud.personaId):void 0,cloudLarkBot:(S=x.cloud)!=null&&S.publishedByMe?(k=e.renderCloudLarkBot)==null?void 0:k.call(e,x.personaId):void 0})},g=h&&(h.cloud&&e.renderCloudConnectors?e.renderCloudConnectors(h.personaId,x=>m(h,x)):m(h,{connectors:void 0,blockedReason:null}));return a.jsxs(a.Fragment,{children:[a.jsx("div",{"data-testid":"persona-flyout-mask",className:"absolute inset-y-0 right-0 z-30 bg-black/10",style:{left:r},onClick:n}),a.jsxs("div",{"data-testid":"persona-flyout",role:"dialog","aria-label":"persona",className:"absolute z-40 flex pointer-events-none",style:{left:r,top:s,bottom:i},children:[a.jsx("div",{className:`h-full bg-bg-100 border-border shadow-xl pointer-events-auto ${f?"border rounded-xl overflow-hidden":"border-l border-r"}`,children:a.jsx(Ett,{personas:o,rootsByPersonaId:d,sets:{awaitingIds:e.awaitingIds,unreadIds:e.unreadIds,runningIds:e.runningIds},selectedPersonaId:u,onHoverPersona:x=>x==null?c.onHoverLeave():c.onHoverEnter(x),onSelectPersona:c.onToggle,onNewPersona:e.onNewPersona,favorites:e.favorites})}),h&&a.jsxs("div",{"data-testid":"persona-flyout-card",onMouseEnter:c.onCardEnter,onMouseLeave:c.onHoverLeave,className:`self-start mt-6 ml-2 w-[520px] max-h-[calc(100%-3rem)] overflow-y-auto rounded-xl border border-border bg-bg-100 shadow-2xl pointer-events-auto ${Mx}`,children:[a.jsx("div",{className:"flex justify-end px-2 pt-2",children:a.jsx("button",{type:"button","aria-label":"close persona card","data-testid":"persona-flyout-card-close",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",onClick:c.clear,children:a.jsx(Jt,{className:"w-4 h-4"})})}),g]})]})]})}const int="clawd:persona:favorites",ont="clawd:persona:filter";function ry(e,t){return t?`${t}::${e}`:e}function ant(e){if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>!!n&&typeof n=="object"&&typeof n.personaId=="string"):[]}catch{return[]}}function lnt(){const[e,t]=bf(int,""),[n,r]=bf(ont,"all"),s=p.useMemo(()=>ant(e),[e]),i=p.useMemo(()=>new Set(s.map(l=>ry(l.personaId,l.deviceId))),[s]);return{favorites:s,isFavorite:(l,c)=>i.has(ry(l,c)),toggleFavorite:l=>{const c=ry(l.personaId,l.deviceId),u=i.has(c)?s.filter(d=>ry(d.personaId,d.deviceId)!==c):[...s,l];t(JSON.stringify(u))},filter:n==="starred"?"starred":"all",setFilter:r}}const cnt="clawd:sidebar:collapsed",TB=100,p2=250,nu=8,unt=28,m2=nu+unt+4;function dnt({hasUnread:e,onExpand:t,onMouseEnter:n,onMouseLeave:r}){return a.jsx("div",{"data-testid":"sidebar-collapsed-handle-wrap",className:"absolute left-2 top-2 z-50",onMouseEnter:n,onMouseLeave:r,children:a.jsxs("button",{type:"button","aria-label":"expand sidebar","data-testid":"sidebar-collapsed-handle",onClick:t,className:"relative p-1.5 rounded-md text-text-300 hover:text-text-100 hover:bg-text-100/10",children:[a.jsx(WH,{className:"w-4 h-4"}),e&&a.jsx("span",{"data-testid":"sidebar-collapsed-unread",className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500"})]})})}function hnt({onExpand:e,onMouseEnter:t,onMouseLeave:n}){return a.jsx("div",{"data-testid":"session-info-handle-wrap",className:"absolute right-2 top-2 z-50",onMouseEnter:t,onMouseLeave:n,children:a.jsx("button",{type:"button","aria-label":"expand session info","data-testid":"session-info-handle",onClick:e,className:"p-1.5 rounded-md text-text-300 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(Vb,{className:"w-4 h-4"})})})}function fnt(e){const[t,n]=p.useState([]),[r,s]=p.useState(!0),[i,o]=p.useState(null),l=p.useCallback(async()=>{s(!0);try{const c=await e.request("extension.list",{});n(c.extensions),o(null)}catch(c){o(c.message)}finally{s(!1)}},[e]);return p.useEffect(()=>{let c=!1;return(async()=>{try{const u=await e.request("extension.list",{});if(c)return;n(u.extensions),o(null)}catch(u){if(c)return;o(u.message)}finally{c||s(!1)}})(),()=>{c=!0}},[e]),{extensions:t,loading:r,error:i,refresh:l}}function pnt({title:e,hint:t,testId:n}){return a.jsxs("div",{"data-testid":n,className:"flex flex-1 flex-col items-center justify-center px-6 py-8 gap-1 text-center",children:[a.jsx("div",{className:"text-[13px] text-text-300",children:e}),a.jsx("div",{className:"text-[11px] text-text-400/70",children:t})]})}function mnt(e){return e.state==="invalid"&&e.invalidReason?e.invalidReason:e.state==="starting"?`v${e.version} · starting…`:e.state==="running"?`v${e.version} · running`:e.state==="crashed"?`v${e.version} · crashed`:`v${e.version}`}function gnt({extensions:e,activeExtId:t,onImport:n,onOpen:r,onClose:s,onUninstall:i,onPublishSettings:o}){const l=p.useRef(null),c=()=>{var d;return(d=l.current)==null?void 0:d.click()},u=d=>{var f;const h=(f=d.target.files)==null?void 0:f[0];d.target.value="",h&&n(h)};return a.jsxs("div",{className:"h-full flex flex-col","data-testid":"sidebar-panel-extensions",children:[a.jsxs("div",{className:"px-3 py-2 border-b border-border shrink-0 flex items-center justify-between",children:[a.jsx("h2",{className:"text-sm font-semibold text-text-100",children:"Extensions"}),a.jsxs("button",{type:"button",onClick:c,"data-testid":"extensions-import-button",className:"flex items-center gap-1 px-2 py-1 text-xs rounded border border-border bg-bg-50 hover:bg-text-100/5 text-text-200 hover:text-text-100 transition-colors",children:[a.jsx(bs,{className:"h-3.5 w-3.5"}),"Import"]}),a.jsx("input",{ref:l,type:"file",accept:".zip,.clawos-ext,application/zip",onChange:u,className:"hidden","data-testid":"extensions-import-input"})]}),a.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2 flex flex-col gap-0.5",children:e.length===0?a.jsx(pnt,{testId:"sidebar-panel-extensions-empty",title:"No extensions yet",hint:"Import a .zip to add one"}):e.map(d=>{const h=t===d.extId,f=d.state==="invalid",m=d.state==="running"||d.state==="starting";return a.jsxs("div",{role:"button",tabIndex:f?-1:0,"data-testid":`extension-row-${d.extId}`,"aria-current":h?"page":void 0,onClick:()=>{f||r(d.extId)},className:ee("group/row flex items-center gap-2 px-2 py-1.5 rounded-md","text-[13px] cursor-pointer transition-colors",f&&"cursor-not-allowed opacity-60",h?"bg-text-100/5 text-text-100":"text-text-200 hover:text-text-100 hover:bg-text-100/5"),children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"truncate",children:d.name}),a.jsx("div",{className:"text-[11px] text-text-400/80 truncate",children:mnt(d)})]}),a.jsxs(Gr,{children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button",onClick:g=>g.stopPropagation(),"data-testid":`extension-row-${d.extId}-menu`,className:ee("p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10","opacity-0 group-hover/row:opacity-100 focus:opacity-100 transition-opacity"),children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsxs(Pr,{align:"end",children:[m?a.jsxs(Et,{onSelect:()=>s(d.extId),children:[a.jsx(Lpe,{className:"w-3.5 h-3.5 mr-2"}),"Stop"]}):!f&&a.jsxs(Et,{onSelect:()=>r(d.extId),children:[a.jsx(rpe,{className:"w-3.5 h-3.5 mr-2"}),"Open"]}),!f&&d.externalUrl?a.jsxs(Et,{"data-testid":`extension-row-${d.extId}-open-external`,onSelect:()=>{window.open(d.externalUrl,"_blank","noopener,noreferrer")},children:[a.jsx(Ur,{className:"w-3.5 h-3.5 mr-2"}),"Open in browser"]}):null,!f&&o?a.jsxs(Et,{onSelect:()=>o(d.extId),children:[a.jsx(Aw,{className:"w-3.5 h-3.5 mr-2"}),"Publish settings…"]}):null,a.jsxs(Et,{onSelect:()=>i(d.extId),children:[a.jsx(ws,{className:"w-3.5 h-3.5 mr-2"}),"Uninstall"]})]})]})]},d.extId)})})]})}function xnt({localManifest:e,publishState:t,check:n,onPublishFirst:r,onPublishUpdate:s,onUnpublish:i}){const[o,l]=p.useState(""),c=t.kind==="published"?t.version:null,u=n.kind==="error-version-not-bumped"&&c!==null&&vnt(o,c),d=()=>{if(n.kind==="error-version-not-bumped"){if(!u)return;s==null||s(o);return}n.kind==="ready-new-version"&&(s==null||s())};return a.jsxs("section",{className:"rounded-lg border border-border bg-bg-50 p-4 flex flex-col gap-3","data-testid":"publish-extension-toggle",children:[a.jsxs("header",{className:"flex items-center gap-2",children:[t.kind==="published"?a.jsx(uT,{className:"w-4 h-4 text-success","aria-hidden":!0}):a.jsx(Rfe,{className:"w-4 h-4 text-text-400","aria-hidden":!0}),a.jsx("h3",{className:"text-sm font-medium text-text-100",children:"公开此 Extension"}),t.kind==="published"?a.jsx(cc,{className:"bg-success-dim text-success border-success/30",children:"已公开"}):a.jsx(cc,{className:"bg-bg-200 text-text-400 border-border",children:"未公开"})]}),a.jsx("p",{className:"text-[12px] text-text-400 leading-relaxed",children:"公开后,所有连接到你的 People 用户都能在你的视图里看到并安装这个 extension。"}),a.jsx(bnt,{localManifest:e,publishState:t,check:n}),n.kind==="error-version-not-bumped"&&c?a.jsx(ynt,{publishedVersion:c,value:o,onChange:l,onSubmit:d}):null,a.jsx("footer",{className:"flex items-center justify-end gap-2 pt-1",children:t.kind==="unpublished"?a.jsxs(Be,{size:"sm",onClick:r,"data-testid":"publish-first",children:["公开 v",e.version]}):a.jsxs(a.Fragment,{children:[a.jsx(Be,{size:"sm",variant:"outline",onClick:i,"data-testid":"unpublish",children:"取消公开"}),a.jsx(Be,{size:"sm",disabled:n.kind==="ready-new-version"?!1:n.kind==="error-version-not-bumped"?!u:!0,onClick:d,"data-testid":"publish-update",children:n.kind==="ready-new-version"?`发布 v${n.toVersion}`:n.kind==="error-version-not-bumped"&&u?`发布 v${o}`:"发布新版本"})]})})]})}function vnt(e,t){if(!Y5(e).ok)return!1;try{return sH(e,t)>0}catch{return!1}}function ynt({publishedVersion:e,value:t,onChange:n,onSubmit:r}){const s=xi(r),i=Y5(t).ok;let o=null;if(t&&i)try{sH(t,e)<=0&&(o=`必须 > ${e}`)}catch{}const l=t!==""&&!i,c=l||o!==null;return a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsxs("label",{htmlFor:"publish-extension-new-version",className:"text-[11px] text-text-300",children:["新版本号(必须 > 已发布 v",e,")"]}),a.jsx("input",{id:"publish-extension-new-version",type:"text",inputMode:"decimal",autoComplete:"off",spellCheck:!1,value:t,onChange:u=>n(u.target.value),...s,placeholder:e,"data-testid":"publish-extension-new-version-input",className:ee("rounded-md border bg-bg-0 px-2.5 py-1.5 text-[13px] font-mono text-text-100","placeholder:text-text-400/60 focus:outline-none focus:ring-2",c?"border-error/40 focus:ring-error/30":"border-border focus:ring-accent/30")}),c?a.jsx("span",{className:"text-[11px] text-error","data-testid":"publish-extension-new-version-error",children:l?"格式:MAJOR.MINOR.PATCH,仅数字":o}):null]})}function bnt({localManifest:e,publishState:t,check:n}){if(t.kind==="unpublished")return a.jsx(Hd,{kind:"info",icon:Ru,label:`本地版本 v${e.version} · hash ${g2(e.contentHash)}`});const r=a.jsx(Hd,{kind:"info",icon:ci,label:`已发布 v${t.version} · hash ${g2(t.contentHash)} · ${t.publishedAt}`});return n.kind==="clean"?r:n.kind==="ready-new-version"?a.jsxs(a.Fragment,{children:[r,a.jsx(Hd,{kind:"info",icon:Ru,label:`检测到本地新内容 v${n.toVersion} · hash ${g2(e.contentHash)} → 可发布`})]}):n.kind==="error-same-hash"?a.jsxs(a.Fragment,{children:[r,a.jsx(Hd,{kind:"warn",icon:In,label:`本地内容未变化,仍是 v${n.version},无需发布`})]}):n.kind==="error-version-not-bumped"?a.jsxs(a.Fragment,{children:[r,a.jsx(Hd,{kind:"error",icon:In,label:`本地内容已变化,但 manifest.version 仍是 ${n.localVersion}。在下面输入新版本号(必须 > ${n.publishedVersion}),daemon 会帮你改写 manifest 并发布。`})]}):n.kind==="error-version-regression"?a.jsxs(a.Fragment,{children:[r,a.jsx(Hd,{kind:"error",icon:In,label:`manifest.version (${n.localVersion}) 低于已发布版本 ${n.publishedVersion},不允许版本倒退。`})]}):r}function Hd({kind:e,icon:t,label:n}){const r=e==="error"?"bg-error-dim text-error border-error/30":e==="warn"?"bg-warning-dim text-warning border-warning/30":"bg-bg-100 text-text-300 border-border";return a.jsxs("div",{className:ee("flex items-start gap-2 rounded-md border px-2.5 py-1.5 text-[12px]",r),children:[a.jsx(t,{className:"w-3.5 h-3.5 shrink-0 mt-0.5","aria-hidden":!0}),a.jsx("span",{className:"leading-snug",children:n})]})}function g2(e){return e.length>8?e.slice(0,8):e}function wnt({open:e,extId:t,client:n,onClose:r,onUninstalled:s}){const[i,o]=p.useState(null),[l,c]=p.useState(null),[u,d]=p.useState(!1),h=p.useCallback(async()=>{try{const x=await n.request("extension.publish:status",{extId:t});o(x),c(null)}catch(x){c(x.message)}},[n,t]);p.useEffect(()=>{if(!e)return;h();const x=window.setInterval(()=>void h(),5e3);return()=>window.clearInterval(x)},[e,h]);const f=p.useCallback(async x=>{if(!u){d(!0);try{const b={extId:t};x&&(b.newVersion=x),await n.request("extension.publish",b),await h()}catch(b){c(b.message)}finally{d(!1)}}},[u,n,t,h]),m=p.useCallback(async()=>{if(!u){d(!0);try{await n.request("extension.unpublish",{extId:t}),await h()}catch(x){c(x.message)}finally{d(!1)}}},[u,n,t,h]),g=p.useCallback(async()=>{if(!u&&window.confirm(`卸载 extension "${t}"?`)){d(!0);try{await n.request("extension.uninstall",{extId:t}),s==null||s(t),r()}catch(x){c(x.message)}finally{d(!1)}}},[u,n,t,s,r]);return a.jsx(us,{open:e,onOpenChange:x=>!x&&r(),children:a.jsxs(Wr,{className:"max-w-lg","data-testid":"extension-publish-dialog",children:[a.jsx(zs,{children:a.jsx(Vr,{children:"Extension 设置"})}),a.jsxs("div",{className:"flex flex-col gap-3",children:[l?a.jsx("div",{className:"rounded-md border border-error/30 bg-error-dim text-error text-[12px] px-3 py-2",children:l}):null,i?a.jsx(xnt,{localManifest:i.localManifest,publishState:i.publishState,check:i.check,onPublishFirst:()=>void f(),onPublishUpdate:x=>void f(x),onUnpublish:()=>void m()}):a.jsx("div",{className:"text-[12px] text-text-400 px-2 py-4",children:"加载中…"}),a.jsx("hr",{className:"border-border"}),a.jsxs(Be,{variant:"destructive",onClick:()=>void g(),disabled:u,"data-testid":"extension-uninstall",children:[a.jsx(ws,{className:"w-3.5 h-3.5 mr-1.5"}),"删除并卸载"]})]})]})})}function _nt({client:e,activeExtId:t,onOpenInMain:n,onExtensionsMutated:r}){const{extensions:s,refresh:i}=fnt(e),{httpBaseUrl:o,httpToken:l}=Rx(),c=p.useCallback(async x=>{if(!o||!l)throw new Error("daemon HTTP not ready (missing httpBaseUrl/httpToken)");const b=await fetch(`${o}/extensions/import`,{method:"POST",headers:{Authorization:`Bearer ${l}`,"Content-Type":"application/zip"},body:x});if(!b.ok){const v=await b.json().catch(()=>null);throw new Error(v!=null&&v.code?`${v.code}: ${v.message??""}`:`HTTP ${b.status}`)}const{extId:y}=await b.json();await i(),r==null||r(),n(y)},[o,l,i,n,r]),u=p.useCallback(x=>{n(x)},[n]),d=p.useCallback(async x=>{await e.request("extension.close",{extId:x}),await i(),r==null||r()},[e,i,r]),h=p.useCallback(async x=>{await e.request("extension.uninstall",{extId:x}),await i(),r==null||r()},[e,i,r]),f=s.map(x=>{var y;if(x.state==="invalid")return{extId:x.extId,name:x.extId,version:"0.0.0",state:"invalid",invalidReason:x.invalidReason};let b;return x.state==="running"?b=x.target.kind==="local"?`http://127.0.0.1:${x.target.port}/`:x.target.url:(y=x.manifest.entry)!=null&&y.url&&(b=x.manifest.entry.url),{extId:x.extId,name:x.manifest.name,version:x.manifest.version,state:x.state,...b?{externalUrl:b}:{}}}),[m,g]=p.useState(null);return a.jsxs(a.Fragment,{children:[a.jsx(gnt,{extensions:f,activeExtId:t,onImport:c,onOpen:u,onClose:d,onUninstall:h,onPublishSettings:x=>g(x)}),m!==null?a.jsx(wnt,{open:!0,extId:m,client:e,onClose:()=>g(null),onUninstalled:()=>{i(),r==null||r()}}):null]})}function Snt(e,t){const n=new Map;for(const[r,s]of e){let i=0;for(const o of s){if(t.has(o.senderDeviceId))continue;knt(o.readBy,t)<o.createdAt&&i++}n.set(r,i)}return n}function knt(e,t){let n=0;for(const r of t){const s=e[r];s!==void 0&&s>n&&(n=s)}return n}function RB(e,t,n){const r=e.get(t)??[],s=r.findIndex(l=>l.id===n.id);let i;s<0?i=[...r,n].sort((l,c)=>l.createdAt-c.createdAt):(i=[...r],i[s]=n);const o=new Map(e);return o.set(t,i),o}function Cnt(){const e=globalThis.crypto;return e!=null&&e.randomUUID?e.randomUUID():"m_"+Math.random().toString(36).slice(2)+Date.now().toString(36)}function x2(e){return e==="connected"?"connected":e==="connecting"?"connecting":e==="disconnected"||e==="revoked"?"offline":"unknown"}const Nnt=[];function jnt(e,t,n="",r=Nnt){const[s,i]=p.useState(new Map),[o,l]=p.useState(new Map),c=p.useRef(new Set),u=p.useRef(new Set),d=p.useRef(new Set),h=p.useRef(new Map),f=p.useRef(null),m=p.useRef(null);p.useEffect(()=>{const _=e.local.on("inbox:event",S=>{const k=S;!(k!=null&&k.message)||!k.peerDeviceId||i(C=>RB(C,k.peerDeviceId,k.message))});return()=>_()},[e]),p.useEffect(()=>{const _=new Set(t.map(S=>S.deviceId));for(const[S,k]of h.current)_.has(S)||(k(),h.current.delete(S),e.disposeRemoteForDevice(S),c.current.delete(S),d.current.delete(S),u.current.delete(S),l(C=>{if(!C.has(S))return C;const N=new Map(C);return N.delete(S),N}),i(C=>{if(!C.has(S))return C;const N=new Map(C);return N.delete(S),N}));queueMicrotask(()=>{var S,k;for(const C of t)u.current.has(C.deviceId)&&!d.current.has(C.deviceId)&&((S=f.current)==null||S.call(f,C.deviceId)),c.current.has(C.deviceId)||(k=m.current)==null||k.call(m,C.deviceId)})},[t,e]),p.useEffect(()=>{queueMicrotask(()=>{var _;for(const S of r)c.current.has(S)||(_=m.current)==null||_.call(m,S)})},[r]),p.useEffect(()=>{const _=h.current;return()=>{for(const S of _.values())S();_.clear()}},[]);const g=p.useCallback(async function(S){if(!c.current.has(S)){c.current.add(S);try{const k=await e.local.request("inbox:list",{peerDeviceId:S}),C=Array.isArray(k==null?void 0:k.messages)?k.messages:[];C.length>0&&i(N=>{let T=N;for(const E of C)T=RB(T,S,E);return T})}catch(k){Pe("useIm","local list failed",{deviceId:S,error:k.message})}}},[e]);p.useEffect(()=>{m.current=g},[g]);const x=p.useCallback(async function(S){const k=t.find(E=>E.deviceId===S);if(!k||(u.current.add(S),await g(S),d.current.has(S)))return;const C=e.ensureRemoteForDevice(S,k.remoteUrl??"",k.connectToken);if(!C){l(E=>E.get(S)==="offline"?E:new Map(E).set(S,"offline"));return}d.current.add(S);const N=x2(C.getStatus());l(E=>new Map(E).set(S,N));const T=C.on("status",E=>{l(R=>new Map(R).set(S,x2(E)))});h.current.set(S,T)},[t,e,g]);p.useEffect(()=>{f.current=x},[x]);const b=p.useCallback(async(_,S)=>{const k=e.getRemoteForDevice(_),C=k?x2(k.getStatus()):"unknown";if(!k||C!=="connected")throw new Error("peer offline / not connected");const N=Cnt(),T=Date.now();await Promise.all([e.local.request("inbox:postMessage",{peerDeviceId:_,id:N,text:S,createdAt:T}),k.request("inbox:postMessage",{id:N,text:S,createdAt:T})])},[e]),y=p.useCallback(async(_,S)=>{try{await e.local.request("inbox:markRead",{peerDeviceId:_,upToCreatedAt:S})}catch(k){Pe("useIm","markRead failed",{deviceId:_,upToCreatedAt:S,error:k.message})}},[e]),v=p.useMemo(()=>new Set([n]),[n]),w=p.useMemo(()=>n===""?new Map:Snt(s,v),[s,v,n]);return p.useMemo(()=>({messagesByPeerDeviceId:s,statusByPeerDeviceId:o,unreadByPeer:w,ensurePeerLoaded:x,sendMessage:b,markRead:y}),[s,o,w,x,b,y])}function Ent(e,t){const[n,r]=p.useState(()=>new Map),[s,i]=p.useState(()=>new Map),o=e.filter(v=>Bf(v)),l=e.map(v=>v.connectToken&&v.remoteUrl?`${v.deviceId}::${v.remoteUrl}::${v.connectToken}`:`${v.deviceId}::broken`).sort().join("|"),c=p.useRef(new Map),u=p.useRef(new Map),d=p.useRef(new Set),h=p.useRef(new Set),[f,m]=p.useState(()=>new Set),g=p.useRef(new Map),x=p.useCallback(async v=>{const w=c.current.get(v);if(!w||h.current.has(v))return;const _=t.ensureRemoteForDevice(v,w.remoteUrl,w.token);if(_){_.getStatus()==="disconnected"&&_.start(),h.current.add(v),m(new Set(h.current));try{const S=await _.request("persona:list",{}),k=Array.isArray(S==null?void 0:S.personas)?S.personas:[];r(C=>{const N=new Map(C);return N.set(v,k),N}),i(C=>{if(!C.has(v))return C;const N=new Map(C);return N.delete(v),N})}catch(S){r(k=>{if(!k.has(v))return k;const C=new Map(k);return C.delete(v),C}),i(k=>{const C=new Map(k);return C.set(v,S instanceof Error?S.message:String(S)),C})}finally{h.current.delete(v),m(new Set(h.current))}}},[t]),b=p.useCallback(v=>{if(g.current.has(v))return;const w=c.current.get(v);if(!w)return;const _=t.ensureRemoteForDevice(v,w.remoteUrl,w.token);if(!_)return;const S=_.on("daemon:connected",()=>{x(v)});g.current.set(v,S)},[t,x]);p.useEffect(()=>{var N;const v=c.current,w=u.current,_=new Map,S=new Set,k=[],C=[];for(const T of o){const E={remoteUrl:T.remoteUrl,token:T.connectToken},R=v.get(T.deviceId);R&&(R.remoteUrl!==E.remoteUrl||R.token!==E.token)&&k.push(T.deviceId),!R&&w.get(T.deviceId)===!1&&C.push(T.deviceId),_.set(T.deviceId,E),S.add(T.deviceId)}c.current=_,u.current=new Map(e.map(T=>[T.deviceId,S.has(T.deviceId)])),r(T=>{let E=!1;const R=new Map;for(const[O,P]of T)S.has(O)?R.set(O,P):E=!0;return E?R:T}),i(T=>{let E=!1;const R=new Map;for(const[O,P]of T)S.has(O)?R.set(O,P):E=!0;return E?R:T});for(const T of[...d.current])S.has(T)||d.current.delete(T);for(const[T,E]of g.current)S.has(T)||(E(),g.current.delete(T));for(const T of k)(N=g.current.get(T))==null||N(),g.current.delete(T),t.disposeRemoteForDevice(T),d.current.has(T)&&(b(T),x(T));for(const T of C)d.current.add(T),b(T),x(T)},[l]),p.useEffect(()=>{const v=g.current;return()=>{for(const w of v.values())w();v.clear()}},[]);const y=p.useCallback(async v=>{c.current.get(v)&&(d.current.add(v),b(v),await x(v))},[b,x]);return{byOwnerId:n,loadingOwnerIds:f,errorByOwnerId:s,ensureLoaded:y}}function Int(e,t,n){const[r,s]=p.useState(()=>new Map),[i,o]=p.useState([]),l=p.useRef(new Map),c=p.useRef(new Set),u=p.useRef(new Set),d=p.useRef(new Map),h=e.filter(y=>Bf(y)),f=h.map(y=>`${y.deviceId}::${y.remoteUrl}::${y.connectToken}`).sort().join("|"),m=p.useCallback(async y=>{const v=l.current.get(y);if(!v||u.current.has(y))return;const w=t.ensureRemoteForDevice(y,v.remoteUrl,v.token);if(w){u.current.add(y);try{const _=await w.request("extension.list-published",{}),S=Array.isArray(_==null?void 0:_.extensions)?_.extensions:[];s(k=>{const C=new Map(k);return C.set(y,S),C})}catch{}finally{u.current.delete(y)}}},[t]),g=p.useCallback(async()=>{try{const y=await n.request("extension.list",{});o(Array.isArray(y==null?void 0:y.extensions)?y.extensions:[])}catch{}},[n]);p.useEffect(()=>(g(),n.on("daemon:connected",()=>{g()})),[n,g]),p.useEffect(()=>{const y=new Map,v=new Set;for(const w of h)y.set(w.deviceId,{remoteUrl:w.remoteUrl,token:w.connectToken}),v.add(w.deviceId);l.current=y,s(w=>{let _=!1;const S=new Map;for(const[k,C]of w)v.has(k)?S.set(k,C):_=!0;return _?S:w});for(const w of[...c.current])v.has(w)||c.current.delete(w);for(const[w,_]of d.current)v.has(w)||(_(),d.current.delete(w))},[f]),p.useEffect(()=>{const y=d.current;return()=>{for(const v of y.values())v();y.clear()}},[]);const x=p.useCallback(async y=>{const v=l.current.get(y);if(v){if(c.current.add(y),!d.current.has(y)){const w=t.ensureRemoteForDevice(y,v.remoteUrl,v.token);if(w){const _=w.on("daemon:connected",()=>{m(y)});d.current.set(y,_)}}await m(y)}},[t,m]);return{byOwnerId:p.useMemo(()=>Tnt(r,i),[r,i]),localExtensions:i,ensureLoaded:x,refreshLocal:g}}function Tnt(e,t){const n=new Map;for(const[r,s]of e){const i=s.map(o=>{const l=G5(o.extId,r),c=t.find(h=>h.extId===l&&h.state!=="invalid"),u=c&&c.state!=="invalid"?c.manifest.version:null,d={extId:o.extId,name:o.name,publishedVersion:o.version,publishedHash:o.contentHash};return u?u===o.version?{...d,state:{kind:"installed-up-to-date",installedVersion:u}}:{...d,state:{kind:"installed-with-update",installedVersion:u}}:{...d,state:{kind:"not-installed"}}});n.set(r,i)}return n}function yI(e,t){const{ownerPersonaId:n,projectPath:r,...s}=e;return{...s,originOwnerPrincipalId:t,...n?{originOwnerPersonaId:n}:{}}}function Rnt(e,t){const n=Ws(),[r,s]=p.useState(()=>new Map),i=e.filter(v=>Bf(v)),o=i.map(v=>`${v.deviceId}::${v.remoteUrl}::${v.connectToken}`).sort().join("|"),l=p.useRef(new Map),c=p.useRef(new Set),u=p.useRef(new Map),d=p.useRef(new Map),h=p.useCallback(v=>{const w=(u.current.get(v)??0)+1;return u.current.set(v,w),w},[]),f=p.useCallback((v,w)=>u.current.get(v)===w,[]),m=p.useCallback(async v=>{const w=l.current.get(v);if(!w)return;const _=t.ensureRemoteForDevice(v,w.remoteUrl,w.token);if(!_)return;const S=h(v);try{const k=await _.request("session:list",{});if(!f(v,S))return;const C=Array.isArray(k==null?void 0:k.sessions)?k.sessions:[];s(O=>{const P=new Map(O);return P.set(v,C),P});const N=C.map(O=>yI(O,v)),T=new Set(C.map(O=>O.sessionId)),R=(n.read("sessions")??[]).filter(O=>O.originOwnerPrincipalId===v&&!T.has(O.sessionId)).map(O=>O.sessionId);n.setData("sessions",O=>{const P=(O??[]).filter($=>!R.includes($.sessionId));for(const $ of N){const F=P.findIndex(B=>B.sessionId===$.sessionId);F>=0?P[F]=$:P.unshift($)}return P});for(const O of R)try{await t.local.request("peerSession:remove",{sessionId:O})}catch(P){Pe("mirror","peerSession:remove (reconcile) failed",O,P)}for(const O of N)try{await t.local.request("peerSession:upsert",O)}catch(P){Pe("mirror","peerSession:upsert failed",O.sessionId,P)}}catch{}},[t,h,f,n]),g=p.useCallback((v,w)=>{const _=w;if(!(_!=null&&_.sessionId)||_.chatId!==void 0)return;s(k=>{const C=k.get(v);if(!C)return k;const N=C.findIndex(R=>R.sessionId===_.sessionId);if(N<0)return k;const T=C.slice();T[N]=_;const E=new Map(k);return E.set(v,T),E});const S=yI(_,v);n.setData("sessions",k=>{const C=k??[],N=C.findIndex(E=>E.sessionId===S.sessionId);if(N<0)return C;const T=C.slice();return T[N]=S,T})},[n]);p.useEffect(()=>{const v=new Map,w=new Set;for(const _ of i)v.set(_.deviceId,{remoteUrl:_.remoteUrl,token:_.connectToken}),w.add(_.deviceId);l.current=v,s(_=>{let S=!1;const k=new Map;for(const[C,N]of _)w.has(C)?k.set(C,N):S=!0;return S?k:_});for(const _ of[...c.current])w.has(_)||c.current.delete(_);for(const[_,S]of d.current)w.has(_)||(S(),d.current.delete(_))},[o]),p.useEffect(()=>{const v=d.current;return()=>{for(const w of v.values())w();v.clear()}},[]);const x=p.useCallback(async v=>{const w=l.current.get(v);if(w){if(c.current.add(v),!d.current.has(v)){const _=t.ensureRemoteForDevice(v,w.remoteUrl,w.token);if(_){const S=_.on("daemon:connected",()=>{m(v)}),k=_.on("session:info",C=>{g(v,C)});d.current.set(v,()=>{S(),k()})}}await m(v)}},[t,m,g]),b=p.useCallback((v,w)=>{s(_=>{const S=new Map(_),k=S.get(v);if(!k)return S.set(v,[w]),S;const C=k.findIndex(N=>N.sessionId===w.sessionId);if(C>=0){const N=k.slice();N[C]=w,S.set(v,N)}else S.set(v,[w,...k]);return S})},[]),y=p.useCallback((v,w)=>{s(_=>{const S=_.get(v);if(!S)return _;const k=S.filter(N=>N.sessionId!==w);if(k.length===S.length)return _;const C=new Map(_);return C.set(v,k),C})},[]);return{byOwnerId:r,ensureLoaded:x,upsertSession:b,removeSession:y}}function Mnt(e){return e.map(t=>({deviceId:t.deviceId,ownerId:t.ownerId,provider:t.provider,displayName:t.displayName,remoteUrl:t.remoteUrl,connectToken:t.connectToken,grants:t.grants,addedAt:t.addedAt,pinnedAt:t.pinnedAt,remoteAccessAllowed:t.remoteAccessAllowed,note:t.note}))}function Pnt(e){const[t,n]=p.useState([]),[r,s]=p.useState(!0);p.useEffect(()=>{let d=!1;(async()=>{try{const b=await e.request("contact:list");if(d)return;n(Array.isArray(b==null?void 0:b.contacts)?b.contacts:[])}catch{if(d)return;n([])}finally{d||s(!1)}})();const h=e.on("contact:added",b=>{const y=b.contact;y&&n(v=>{const w=v.findIndex(S=>S.deviceId===y.deviceId);if(w<0)return[...v,y];const _=[...v];return _[w]=y,_})}),f=e.on("contact:removed",b=>{const y=b.deviceId;y&&n(v=>v.filter(w=>w.deviceId!==y))}),m=e.on("contact:pinned",b=>{const{deviceId:y,pinnedAt:v}=b;typeof y=="string"&&n(w=>{const _=w.findIndex(k=>k.deviceId===y);if(_<0)return w;const S=w.slice();return S[_]={...S[_],pinnedAt:v??null},S})}),g=e.on("contact:remote-access-updated",b=>{const{deviceId:y,remoteAccessAllowed:v}=b;typeof y!="string"||typeof v!="boolean"||n(w=>{const _=w.findIndex(k=>k.deviceId===y);if(_<0)return w;const S=w.slice();return S[_]={...S[_],remoteAccessAllowed:v},S})}),x=e.on("contact:note-updated",b=>{const{deviceId:y,note:v}=b;typeof y!="string"||typeof v!="string"||n(w=>{const _=w.findIndex(k=>k.deviceId===y);if(_<0)return w;const S=w.slice();return S[_]={...S[_],note:v},S})});return()=>{d=!0,h(),f(),m(),g(),x()}},[e]);const i=p.useCallback(async d=>{await e.request("contact:remove",{deviceId:d})},[e]),o=p.useCallback(async(d,h)=>{await e.request("contact:pin",{deviceId:d,pinned:h})},[e]),l=p.useCallback(async(d,h)=>{await e.request("contact:setRemoteAccess",{deviceId:d,remoteAccessAllowed:h.remoteAccessAllowed})},[e]),c=p.useCallback(async(d,h)=>{await e.request("contact:setNote",{deviceId:d,note:h})},[e]);return{contacts:p.useMemo(()=>Mnt(t),[t]),loading:r,remove:i,pin:o,setRemoteAccess:l,setNote:c}}function Ont(e,t){const[n,r]=p.useState([]),s=p.useCallback(async()=>{try{const i=await e.request("visitor:list",{});r(Array.isArray(i==null?void 0:i.visitors)?i.visitors:[])}catch{r([])}},[e]);return p.useEffect(()=>{if(!t){r([]);return}return s(),e.on("daemon:connected",()=>{s()})},[t,s,e]),{visitors:n}}function Dnt(e){const[t,n]=p.useState(null);return p.useEffect(()=>{const r=[e.on("ready",s=>{const i=s.tunnelUrl;i&&n(i)}),e.on("tunnel:ready",s=>{n(s.url??null)}),e.on("tunnel:exited",()=>n(null)),e.on("tunnel:unavailable",()=>n(null))];return()=>r.forEach(s=>s())},[e]),t}const Ant=5e3;function $nt(e,t){const[n,r]=p.useState([]);return p.useEffect(()=>{if(!t)return;let s=!0;const i=async()=>{try{const l=await e.request("device:connections");s&&r(l.connections)}catch{}};i();const o=setInterval(()=>void i(),Ant);return()=>{s=!1,clearInterval(o)}},[e,t]),n}function Lnt(e,t){const[n,r]=p.useState([]),[s,i]=p.useState(!1),[o,l]=p.useState(null),c=p.useCallback(async()=>{i(!0),l(null);try{const d=await e.request("device:list",{});r(Array.isArray(d==null?void 0:d.devices)?d.devices:[])}catch(d){l(d.message)}finally{i(!1)}},[e]);p.useEffect(()=>{if(t)return c(),e.on("daemon:connected",()=>{c()})},[t,c,e]);const u=p.useCallback(async d=>e.request("device:connect",{...d}),[e]);return{devices:n,loading:s,error:o,loadDevices:c,connect:u}}function Fnt(e,t,n){return e.filter(r=>r.deviceId!==t&&!n.has(r.deviceId))}const Bnt="visitor-";function b3(e){return`${Bnt}${e}`}function znt(e){return{deviceId:b3(e.visitorId),ownerId:e.visitorId,provider:e.provider,displayName:e.displayName,remoteUrl:"",connectToken:"",grants:[],addedAt:e.firstSeen,pinnedAt:null,remoteAccessAllowed:!1,note:""}}function MB(e,t){const n=new Map;for(const r of e)n.set(r.deviceId,r.displayName);for(const r of t)n.set(b3(r.visitorId),r.displayName);return n}const bI="clawos://device/";function Hnt(e){const t=e.trim();if(!t)return null;if(t.startsWith(bI)){const n=t.slice(bI.length).trim();return n?{deviceId:n}:null}return t.startsWith("dev-")?{deviceId:t}:t.startsWith("on_")?{deviceId:t}:null}function Unt(e){return`${bI}${e.deviceId}`}function Wnt({open:e,onClose:t,connect:n,myDeviceLink:r,onLogin:s}){const[i,o]=p.useState(""),[l,c]=p.useState(null),[u,d]=p.useState(null),[h,f]=p.useState(!1),[m,g]=p.useState(!1),x=u!=null&&u.includes(sue)&&!u.includes(fce),b=async()=>{if(s){g(!0);try{const k=await s();window.open(k,"_blank","noopener")}catch{}finally{g(!1)}}},y=async()=>{if(r)try{await navigator.clipboard.writeText(r),f(!0),setTimeout(()=>f(!1),1500)}catch{}},v=()=>{o(""),c(null),d(null)},w=async k=>{c(k.deviceId),d(null);try{await n(k),t(),v()}catch(C){d(C.message)}finally{c(null)}},_=()=>{const k=Hnt(i);if(!k){d("标识格式不对(应为 clawos://device/… 或 on_ 开头的 union_id)");return}w({deviceId:k.deviceId})},S=xi(()=>{l!==null||!i.trim()||_()});return a.jsx(us,{open:e,onOpenChange:k=>{k||(t(),v())},children:a.jsxs(Wr,{children:[a.jsxs(zs,{children:[a.jsx(Vr,{children:"添加联系人"}),a.jsx(hi,{children:"输入对方的设备标识连接——连上后互为联系人。公共设备在 People 列表里直接连。"})]}),a.jsxs("label",{className:"block mb-3",children:[a.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-text-300 mb-1",children:[a.jsx(BH,{className:"h-3.5 w-3.5"}),"输入对方的设备标识"]}),a.jsx("textarea",{value:i,onChange:k=>o(k.target.value),...S,placeholder:"clawos://device/on_… 或 on_…","data-testid":"dev-link-input",className:"block w-full mt-1 h-16 font-mono text-xs bg-bg-50 border border-border rounded p-2"})]}),a.jsx("button",{type:"button",onClick:_,disabled:l!==null||!i.trim(),"data-testid":"dev-link-connect",className:"px-3 py-1.5 bg-primary text-primary-foreground rounded disabled:opacity-50",children:l!==null?"连接中…":"连接"}),u&&(x?a.jsxs("div",{className:"mt-2 flex items-center gap-2","data-testid":"dev-connect-login-expired",children:[a.jsx("p",{className:"flex-1 text-xs text-destructive",children:"登录已失效,重新登录后再点「连接」"}),s&&a.jsx("button",{type:"button",disabled:m,onClick:()=>void b(),"data-testid":"dev-connect-relogin",className:"shrink-0 px-2 py-1 text-xs rounded border border-border bg-bg-50 hover:bg-text-100/5 text-text-200 hover:text-text-100 transition-colors disabled:opacity-50",children:m?"请在浏览器完成授权…":"重新登录"})]}):a.jsx("p",{className:"text-xs text-destructive mt-2","data-testid":"dev-connect-error",children:u})),r!==void 0&&a.jsxs("div",{className:"mt-4 pt-3 border-t border-border",children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-text-300 mb-1.5",children:[a.jsx($w,{className:"h-3.5 w-3.5"}),"我的设备标识"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("code",{"data-testid":"my-device-link",className:"flex-1 min-w-0 truncate font-mono text-[11px] text-text-200 bg-bg-50 border border-border rounded px-2 py-1.5",title:r,children:r}),a.jsxs("button",{type:"button",onClick:()=>void y(),"data-testid":"my-device-link-copy","aria-label":"复制标识",className:"shrink-0 flex items-center gap-1 px-2 py-1.5 rounded border border-border bg-bg-50 hover:bg-text-100/5 text-xs text-text-200",children:[h?a.jsx(Xt,{className:"h-3.5 w-3.5"}):a.jsx(va,{className:"h-3.5 w-3.5"}),h?"已复制":"复制"]})]}),a.jsx("p",{className:"text-[11px] text-text-400 mt-1.5",children:"把这个标识发给对方,对方添加你即可(需你的 daemon 在线并已开 tunnel)。"})]})]})})}class Vnt{constructor(t,n){Gs(this,"remotes",new Map);Gs(this,"ownersListeners",new Set);this.local=t,this.selfIdentity=n}ensureRemoteForDevice(t,n,r){if(!n||!r)return null;const s=this.remotes.get(t);if(s)return s;const i=CT({url:n,authToken:r,clientInfo:jT(),backoffMs:()=>-1,...this.selfIdentity?{selfIdentity:this.selfIdentity}:{}});return i.start(),this.remotes.set(t,i),this.notifyOwnersChanged(),i}getRemoteForDevice(t){return this.remotes.get(t)??null}disposeRemoteForDevice(t){const n=this.remotes.get(t);n&&(n.stop(),this.remotes.delete(t),this.notifyOwnersChanged())}disposeAll(){if(this.remotes.size!==0){for(const[,t]of this.remotes)t.stop();this.remotes.clear(),this.notifyOwnersChanged()}}listRemoteDeviceIds(){return Array.from(this.remotes.keys())}onOwnersChanged(t){return this.ownersListeners.add(t),()=>{this.ownersListeners.delete(t)}}notifyOwnersChanged(){for(const t of this.ownersListeners)t()}}const PB="clawd:sidebar:tree-collapsed";function qnt(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function Knt(e){const t=qnt(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 Gnt(){const e=ul(),[t,n]=p.useState(()=>new Set),r=p.useRef(t);r.current=t,p.useEffect(()=>{let c=!1;return(async()=>{try{const u=await e.kv.get(PB);if(c)return;n(Knt(u))}catch{}})(),()=>{c=!0}},[e]);const s=p.useCallback(c=>{e.kv.set(PB,[...c]).catch(()=>{})},[e]),i=p.useCallback(c=>r.current.has(c),[]),o=p.useCallback(c=>{n(u=>{const d=new Set(u);return d.has(c)?d.delete(c):d.add(c),s(d),d})},[s]),l=p.useCallback(c=>{n(u=>{let d=!1;const h=new Set;for(const f of u)c.has(f)?h.add(f):d=!0;return d?(s(h),h):u})},[s]);return{isCollapsed:i,toggle:o,prune:l}}const OB="clawd:sidebar:px",Ynt=280,Xnt=480,Znt=288;function ate(e){return Math.min(Xnt,Math.max(Ynt,e))}function Qnt(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function Jnt(e){const t=Qnt(e);return typeof t=="number"&&Number.isFinite(t)?ate(t):null}function ert(){const e=ul(),[t,n]=p.useState(Znt),r=p.useRef(t);r.current=t,p.useEffect(()=>{let o=!1;return(async()=>{try{const l=await e.kv.get(OB);if(o)return;const c=Jnt(l);c!=null&&n(c)}catch{}})(),()=>{o=!0}},[e]);const s=p.useRef(null);p.useEffect(()=>()=>{var o;return(o=s.current)==null?void 0:o.call(s)},[]);const i=p.useCallback(o=>{var x;o.preventDefault();const l=o.currentTarget;try{(x=l==null?void 0:l.setPointerCapture)==null||x.call(l,o.pointerId)}catch{}const c=o.clientX,u=r.current;let d=u;const h=document.body.style.userSelect;document.body.style.userSelect="none";const f=b=>{d=ate(u+(b.clientX-c)),n(d)},m=b=>{document.removeEventListener("pointermove",f),document.removeEventListener("pointerup",g),document.removeEventListener("pointercancel",g),document.body.style.userSelect=h,s.current=null,b&&e.kv.set(OB,d).catch(()=>{})},g=()=>m(!0);document.addEventListener("pointermove",f),document.addEventListener("pointerup",g),document.addEventListener("pointercancel",g),s.current=()=>m(!1)},[e]);return{width:t,onDragStart:i}}function trt(e,t){const n=Math.max(0,e.scheduledAt+e.nextDelayMs-t);return n<=0?`daemon 断开,正在尝试第 ${e.attempt} 次重连…`:`daemon 断开,第 ${e.attempt} 次重连,${Math.ceil(n/1e3)}s 后自动重试`}function lte(e){const[t,n]=p.useState(()=>Date.now());return p.useEffect(()=>{n(Date.now());const r=setInterval(()=>n(Date.now()),500);return()=>clearInterval(r)},[e.attempt,e.scheduledAt]),trt(e,t)}function nrt({state:e,onRetryNow:t}){if(e.kind==="reconnecting")return a.jsx(rrt,{state:e,onRetryNow:t});const n=srt(e);return n?a.jsxs("div",{"data-testid":"connection-banner","data-state":e.kind,className:ee("flex items-center gap-2 px-4 h-8 shrink-0 text-[12px] border-b",n.className),children:[a.jsx(n.Icon,{className:ee("w-3.5 h-3.5 shrink-0",n.iconClassName),"aria-hidden":"true"}),a.jsx("span",{className:"truncate",children:n.label})]}):null}function rrt({state:e,onRetryNow:t}){const[n,r]=p.useState(!1),s=lte(e),i=async()=>{if(!(!t||n)){r(!0);try{await t()}finally{r(!1)}}};return a.jsxs("div",{"data-testid":"connection-banner","data-state":"reconnecting",className:"flex items-center gap-2 px-4 h-8 shrink-0 text-[12px] border-b bg-warning-dim text-warning border-warning/30",children:[a.jsx(it,{className:"w-3.5 h-3.5 shrink-0 animate-spin","aria-hidden":"true"}),a.jsx("span",{className:"truncate flex-1",children:s}),t?a.jsxs("button",{type:"button",onClick:()=>void i(),disabled:n,"data-testid":"connection-banner-retry",className:ee("inline-flex items-center gap-1 px-2 h-6 rounded-sm text-[11px] font-medium","bg-warning/10 hover:bg-warning/20 text-warning border border-warning/30","disabled:opacity-50 disabled:cursor-not-allowed transition-colors"),children:[a.jsx(Tf,{className:ee("w-3 h-3",n&&"animate-spin"),"aria-hidden":"true"}),"立即重试"]}):null]})}function srt(e){switch(e.kind){case"connecting":return{Icon:it,iconClassName:"animate-spin",label:"正在连接 clawd daemon…",className:"bg-warning-dim text-warning border-warning/30"};case"disconnected":return{Icon:Xpe,label:e.reason?`daemon 未连接:${e.reason}`:"daemon 未连接",className:"bg-error-dim text-error border-error/30"};case"version-mismatch":return{Icon:Tg,label:`daemon 协议版本 v${e.daemonProtocol} 高于 extension 支持 v${e.supportedProtocol},请升级 extension`,className:"bg-warning-dim text-warning border-warning/30"};case"connected":case"idle":case"reconnecting":default:return null}}function irt(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function ort(e){const t=irt(e);if(!t||typeof t!="object"||Array.isArray(t))return null;const{tool:n,model:r,effort:s,ownerPersonaId:i}=t;return n!=="claude"&&n!=="codex"&&n!=="pi"||r!==null&&typeof r!="string"||s!==null&&typeof s!="string"||typeof i!="string"||i===""?null:{tool:n,model:r,effort:s,ownerPersonaId:i}}const DB="butler-quick-compose/last-used";function art(){const e=ul(),t=p.useRef(null);p.useEffect(()=>{let r=!1;return(async()=>{try{const s=await e.kv.get(DB);if(r)return;t.current=ort(s)}catch{}})(),()=>{r=!0}},[e]);const n=p.useCallback(r=>{t.current=r,e.kv.set(DB,r).catch(()=>{})},[e]);return{lastUsedRef:t,save:n}}const sy=e=>({personaId:e,connectors:null,loading:e!==null,error:null});function w3(e,t){const[n,r]=p.useState(()=>sy(t)),s=p.useRef(t);p.useLayoutEffect(()=>{s.current=t},[t]);const i=p.useRef(0),o=p.useCallback(async()=>{if(t===null||!e||t!==s.current)return;const c=++i.current;r(u=>u.personaId===t?{...u,loading:!0}:sy(t));try{const u=await e.cloudConnectorsList(t);if(c!==i.current)return;r({personaId:t,connectors:u.connectors,loading:!1,error:null})}catch(u){if(c!==i.current)return;const d=u instanceof Error?u.message:String(u);r(h=>({personaId:t,connectors:h.personaId===t?h.connectors:null,loading:!1,error:d}))}},[e,t]);p.useEffect(()=>(t===null?r(sy(null)):o(),()=>{i.current++}),[o,t]);const l=n.personaId===t?n:sy(t);return{active:t!==null,connectors:l.connectors,loading:l.loading,error:l.error,reload:o}}function hS(e){if(!e.active)return null;if(e.error)return"查不到连接器授权状态,刷新一下再试";if(e.connectors===null)return"正在确认连接器授权…";const t=e.connectors.filter(n=>n.status!=="connected").map(n=>n.name);return t.length>0?`还要先授权:${t.join("、")}`:null}function cte(e){const t=hS(e);return t===null?null:e.connectors===null&&!e.error?t:`${t} · 在 persona 卡片的「连接器」里处理`}function lrt({api:e,projects:t,value:n,readOnly:r=!1,onChange:s,onProjectCreated:i}){const[o,l]=p.useState(!1),[c,u]=p.useState(!1),[d,h]=p.useState(""),f=n?t.find(g=>g.path===n)??null:null,m=p.useMemo(()=>t.filter(g=>g.name.toLowerCase().includes(d.trim().toLowerCase())),[t,d]);return r?a.jsxs("span",{"data-testid":"new-session-project-chip-readonly",className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-bg-200 text-[12px] text-text-300 cursor-default select-none",children:[a.jsx(jg,{className:"w-3.5 h-3.5"}),(f==null?void 0:f.name)??n]}):a.jsxs(Fx,{open:o,onOpenChange:g=>{l(g),g||(u(!1),h(""))},children:[a.jsx(Bx,{asChild:!0,children:a.jsx(Ux,{icon:Vh,value:f?f.name:null,placeholder:"项目",selected:!!n,onOpen:()=>l(!0),testid:"new-session-project-chip"})}),a.jsx(Wf,{side:"top",align:"start",sideOffset:8,collisionPadding:8,className:"z-[10001] w-[300px] max-w-[calc(100vw-16px)] rounded-xl border border-bg-300 bg-bg-0 shadow-lg p-1 flex flex-col","data-testid":"new-session-project-popover",children:c?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"px-2.5 py-1.5 text-[11px] text-text-400",children:"选择项目目录"}),a.jsx(eW,{api:e,onSelect:g=>{(async()=>{try{const{project:x}=await e.projectCreate({path:g});s(x.path),i==null||i()}catch{return}l(!1),u(!1)})()}})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 border-b border-bg-300 mb-1",children:[a.jsx(ui,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),a.jsx("input",{autoFocus:!0,value:d,onChange:g=>h(g.target.value),placeholder:"搜索项目","data-testid":"new-session-project-search",className:"flex-1 bg-transparent text-[13px] text-text-200 placeholder:text-text-400/60 focus:outline-none"})]}),a.jsxs("div",{className:"max-h-[220px] overflow-y-auto",children:[m.map(g=>a.jsxs("button",{type:"button",title:g.path,"data-testid":`new-session-project-option-${g.name}`,onClick:()=>{s(g.path),l(!1)},className:"w-full flex items-center gap-2 text-left px-2.5 py-1.5 text-[13px] text-text-200 hover:bg-text-100/5 rounded-md",children:[a.jsx(jg,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),a.jsx("span",{className:"flex-1 truncate",children:g.name}),n===g.path&&a.jsx(Xt,{className:"w-3.5 h-3.5 text-text-200 shrink-0"})]},g.path)),m.length===0&&a.jsx("div",{className:"px-3 py-2 text-[12px] text-text-400 italic",children:"没有匹配的项目"})]}),a.jsxs("div",{className:"border-t border-bg-300 mt-1 pt-1",children:[a.jsxs("button",{type:"button","data-testid":"new-session-project-new",onClick:()=>u(!0),className:"w-full flex items-center gap-2 text-left px-2.5 py-1.5 text-[13px] text-text-200 hover:bg-text-100/5 rounded-md",children:[a.jsx(bs,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),"新建项目"]}),a.jsxs("button",{type:"button","data-testid":"new-session-project-none",onClick:()=>{s(null),l(!1)},className:"w-full flex items-center gap-2 text-left px-2.5 py-1.5 text-[13px] text-text-200 hover:bg-text-100/5 rounded-md",children:[a.jsx(Jt,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),"不在项目中工作"]})]})]})})]})}function crt({list:e,value:t,onChange:n}){const r=t?e.models.find(s=>s.id===t)??null:null;return a.jsx(fM,{testid:"new-session-model",list:e,current:t??"",side:"top",onSelect:s=>n(s===t?null:s),contentClassName:"z-[10001] w-[280px] max-h-[360px]",trigger:s=>a.jsx(Ux,{icon:aT,value:(r==null?void 0:r.label)??t,placeholder:"模型",selected:!!t,onOpen:s,testid:"new-session-model-chip"})})}function urt({options:e,value:t,onChange:n}){const[r,s]=p.useState(!1),i=t?e.find(l=>l.value===t)??null:null,o=e.length===0;return a.jsxs(Fx,{open:r,onOpenChange:s,children:[a.jsx(Bx,{asChild:!0,children:a.jsx(Ux,{icon:lT,value:(i==null?void 0:i.label)??null,placeholder:"思考强度",selected:!!i,onOpen:()=>s(!0),testid:"new-session-effort-chip"})}),o?null:a.jsx(Wf,{side:"top",align:"start",sideOffset:8,className:"z-[10001] w-[280px] max-h-[360px] overflow-y-auto rounded-xl border border-bg-300 bg-bg-0 shadow-lg p-1","data-testid":"new-session-effort-popover",children:e.map(l=>{const c=l.value===t;return a.jsxs("button",{type:"button",onClick:()=>{n(c?null:l.value),s(!1)},className:"w-full text-left px-3 py-2 text-[12px] hover:bg-text-100/5 rounded-md "+(c?"text-text-100 font-medium":"text-text-300"),"data-testid":`new-session-effort-option-${l.value||"default"}`,children:[a.jsx("div",{children:l.label}),l.description?a.jsx("div",{className:"text-[11px] text-text-400 mt-0.5",children:l.description}):null]},l.value||"default")})})]})}function ute({personas:e,loading:t,value:n,onChange:r,allowNone:s=!0}){const[i,o]=p.useState(!1),l=n?e.find(f=>f.personaId===n)??null:null,c=(l==null?void 0:l.name)??null,u=l==null?void 0:l.tool,d=t?"loading…":e.length===0?"无可用 persona":"persona",h=t||e.length===0;return a.jsxs(Fx,{open:i,onOpenChange:o,children:[a.jsx(Bx,{asChild:!0,children:a.jsx(Ux,{icon:l?void 0:yhe,prefixNode:l?a.jsx(gI,{tool:u,className:"w-3.5 h-3.5 mr-1"}):void 0,value:c,placeholder:d,selected:!!n,disabled:h,onOpen:()=>o(!0),testid:"new-session-persona-chip"})}),a.jsxs(Wf,{side:"top",align:"start",sideOffset:8,className:"z-[10001] w-[260px] max-h-[320px] overflow-y-auto rounded-xl border border-bg-300 bg-bg-0 shadow-lg p-1","data-testid":"new-session-persona-popover",children:[s?a.jsx("button",{type:"button",onClick:()=>{r(null),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] hover:bg-text-100/5 rounded-md "+(n===null?"text-text-100 font-medium":"text-text-300"),"data-testid":"new-session-persona-option-none",children:"无 persona"}):null,e.map(f=>a.jsxs("button",{type:"button",onClick:()=>{r(f.personaId),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] hover:bg-text-100/5 rounded-md flex items-center gap-2 "+(n===f.personaId?"text-text-100 font-medium":"text-text-300"),"data-testid":`new-session-persona-option-${f.personaId}`,children:[a.jsx(gI,{tool:f.tool,className:"w-3.5 h-3.5 shrink-0"}),f.name]},f.personaId))]})]})}const Js="persona-clawd-butler";function drt({kind:e,repo:t,requirement:n}){const r=["新建 persona",`类型:${e==="coding"?"编码":"普通"}`];return e==="coding"&&r.push(`仓库:${(t??"").trim()}`),r.push(`需求:${n.trim()}`),r.join(`
|
|
934
|
+
`)}const pI=new Map;function J0(e){var t;return((t=e.decision)==null?void 0:t.id)??e.at}function mI(e){return pI.get(e)??{}}function Pee(e,t){Object.values(t).some(r=>r.trim().length>0)?pI.set(e,t):pI.delete(e)}function ret(e,t){const n={...mI(e)};for(const r of t)delete n[r];Pee(e,n)}const set="同意你的建议,按建议执行。";function iet({entries:e,titleOf:t,drafts:n,onChange:r,onSend:s,onClose:i,onCollapse:o}){const[l,c]=p.useState({}),u=m=>{var g,x;return{...(g=m.decision)!=null&&g.id?{id:m.decision.id}:{},title:t(m.action),question:((x=m.decision)==null?void 0:x.question)??"",answer:n[J0(m)]??""}},d=net(e.map(u),{includeIds:!0}),h=e.filter(m=>(n[J0(m)]??"").trim().length>0).map(J0),f=(m,g)=>r({...n,[m]:g});return a.jsxs(m_,{testid:"batch-reply-panel",children:[a.jsx(g_,{title:"批量回复",...o?{onCollapse:o}:{},collapseLabel:"collapse batch reply",collapseTitle:"收起批量回复"}),a.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:[a.jsx(KH,{className:"size-3.5 shrink-0 text-warning"}),a.jsxs("span",{className:"rounded-full bg-warning/15 px-2 py-0.5 text-[11px] font-medium text-warning",children:["待回复 ",e.length," 条"]}),a.jsx("span",{className:"flex-1"}),a.jsx("button",{type:"button","data-testid":"batch-reply-close","aria-label":"返回话题入口",onClick:i,className:"cursor-pointer rounded p-1 text-text-400 hover:bg-text-100/10 hover:text-text-200",children:a.jsx(Jt,{className:"size-3.5"})})]}),a.jsx("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-3",children:e.map((m,g)=>{var v,w;const x=J0(m),b=n[x]??"",y=l[x]??!1;return a.jsxs("div",{"data-testid":`batch-reply-item-${g}`,className:"rounded-lg border border-border bg-surface-card p-3",children:[a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsxs("span",{className:"mt-px shrink-0 font-mono text-[11px] text-text-400",children:["【",g+1,"】"]}),a.jsx("span",{className:"min-w-0 flex-1 text-[13px] font-medium text-text-100",children:t(m.action)})]}),a.jsxs("dl",{className:"mt-2 space-y-1.5",children:[a.jsxs("div",{"data-decision-field":"question",className:"flex gap-2.5",children:[a.jsx("dt",{className:"mt-px h-fit shrink-0 rounded bg-text-100/10 px-1.5 py-0.5 text-[11px] font-medium text-text-100",children:"问题"}),a.jsx("dd",{className:"min-w-0 flex-1 text-[12px] leading-relaxed text-text-200",children:(v=m.decision)==null?void 0:v.question})]}),a.jsxs("div",{"data-decision-field":"recommendation",className:"flex gap-2.5",children:[a.jsx("dt",{className:"mt-px h-fit shrink-0 rounded bg-success-dim px-1.5 py-0.5 text-[11px] font-medium text-success",children:"建议"}),a.jsx("dd",{className:"min-w-0 flex-1 text-[12px] leading-relaxed text-text-200",children:(w=m.decision)==null?void 0:w.recommendation})]})]}),a.jsxs("button",{type:"button","data-testid":`batch-reply-reason-toggle-${g}`,onClick:()=>c(_=>({..._,[x]:!y})),"aria-expanded":y,"aria-controls":`batch-reply-reason-${g}`,className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[11px] text-text-400 hover:text-text-200",children:[a.jsx(Qt,{className:`size-3 transition-transform ${y?"":"-rotate-90"}`}),"理由"]}),y&&a.jsx("div",{id:`batch-reply-reason-${g}`,"data-decision-field":"reason",className:"mt-1.5 rounded border border-border px-2.5 py-2 text-[12px] leading-relaxed text-text-300",children:m.reason}),a.jsxs("div",{className:"mt-1.5 text-[11px] text-text-400",children:[m.target?a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"font-mono",children:m.target}),a.jsx("span",{className:"mx-1.5",children:"·"})]}):null,a.jsx("span",{className:"font-mono",children:m.at.slice(11,16)})]}),a.jsxs("div",{className:"mt-2 flex items-start gap-2",children:[a.jsx("textarea",{"data-testid":`batch-reply-input-${g}`,value:b,onChange:_=>f(x,_.target.value),rows:2,placeholder:"您的答复…(留空 = 这条先不答)",className:"min-w-0 flex-1 resize-none rounded-md border border-border bg-bg-100 px-2 py-1.5 text-[12px] leading-relaxed text-text-100 outline-none placeholder:text-text-400 focus:border-accent"}),a.jsx("button",{type:"button","data-testid":`batch-reply-accept-${g}`,onClick:()=>f(x,set),className:"shrink-0 cursor-pointer rounded-md border border-success/40 px-2 py-1 text-[11px] font-medium text-success hover:bg-success-dim",children:"采纳建议"})]})]},x)})}),a.jsxs("div",{className:"shrink-0 border-t border-border p-3",children:[a.jsxs("details",{className:"mb-2 rounded-md border border-border px-2 py-1.5",children:[a.jsx("summary",{className:"cursor-pointer text-[11px] text-text-400",children:"预览拼接结果(发送后填进对话框的就是这段)"}),a.jsx("pre",{"data-testid":"batch-reply-preview",className:"mt-2 max-h-40 overflow-auto whitespace-pre-wrap text-[11px] leading-relaxed text-text-200",children:d||"(还没填任何一条)"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("span",{"data-testid":"batch-reply-progress",className:"text-[11px] text-text-400",children:["已填 ",h.length," / ",e.length]}),a.jsx("span",{className:"flex-1"}),a.jsxs("button",{type:"button","data-testid":"batch-reply-send",disabled:h.length===0,onClick:()=>s(d,h),className:"inline-flex cursor-pointer items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-[12px] font-medium text-accent-contrast transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-40",children:[a.jsx(Dw,{className:"size-3.5"}),"发送"]})]})]})]})}function oet({onClose:e}){return a.jsxs(m_,{testid:"batch-reply-panel",children:[a.jsx(g_,{title:"批量回复"}),a.jsx("div",{className:"p-3",children:a.jsx(dh,{testid:"batch-reply-back",icon:a.jsx(Jt,{className:"size-4"}),label:"没有待拍板的决策,返回",onClick:e})})]})}function aet({topicId:e,api:t,sessions:n,focused:r,onNewSession:s,onOpenConfig:i}){var k;const o=Yn(),[l,c]=p.useState(null),u=(k=n.find(C=>C.sessionId===l))==null?void 0:k.updatedAt,{topic:d,loading:h,error:f}=qJe(o,e,u);p.useEffect(()=>{c((d==null?void 0:d.masterSessionId)??null)},[d==null?void 0:d.masterSessionId]);const m=LR(),[g,x]=p.useState("info"),[b,y]=p.useState(()=>mI(e)),v=p.useMemo(()=>((d==null?void 0:d.activity)??[]).filter(C=>{var N;return((N=C.decision)==null?void 0:N.status)===cH&&C.decision.type===lH}),[d==null?void 0:d.activity]),w=p.useMemo(()=>({title:"话题",leadingEntries:a.jsx(dh,{testid:"topic-decisions-entry",icon:a.jsx(Cfe,{className:"w-3.5 h-3.5"}),label:"决策",...v.length>0?{meta:String(v.length)}:{},onClick:()=>x("decisions")})}),[v.length]);if(h&&!d)return a.jsx("div",{className:"p-6 text-[13px] text-text-400",children:"加载话题中…"});if(f||!d)return a.jsxs("div",{"data-testid":"topic-workspace-error",className:"p-6 text-[13px] text-text-400",children:["话题打不开:",f??"未找到该话题"]});const _=n.find(C=>C.sessionId===d.masterSessionId),S=Ww(d.title,_??null);return a.jsxs("div",{className:"flex h-full flex-col","data-testid":"topic-workspace",children:[m.container&&g!=="info"?os.createPortal(g==="batch"?v.length>0?a.jsx(iet,{entries:v,titleOf:Mee,drafts:b,onChange:C=>{y(C),Pee(e,C)},onSend:(C,N)=>{x("info"),d.masterSessionId&&eTe(d.masterSessionId,C),ret(e,N),y(mI(e))},onClose:()=>x("decisions"),...m.onCollapse?{onCollapse:m.onCollapse}:{}}):a.jsx(oet,{onClose:()=>x("decisions")}):a.jsxs(m_,{testid:"topic-decisions-panel",children:[a.jsx(g_,{title:"决策",onBack:()=>x("info"),...m.onCollapse?{onCollapse:m.onCollapse}:{},collapseTitle:"收起话题"}),a.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-3",children:a.jsx(JJe,{activity:d.activity,onOpenChat:()=>x("batch")})})]}),m.container):null,a.jsx("div",{"data-testid":"topic-workspace-header",className:"flex shrink-0 items-center gap-3 border-b border-border/60 px-4 py-2.5",children:a.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] font-semibold text-text-100",title:S,children:S})}),a.jsx("div",{className:"flex min-h-0 flex-1",children:a.jsx("div",{"data-testid":"topic-workspace-chat-pane",className:"flex min-h-0 min-w-0 flex-1",children:_?a.jsx($G,{container:g==="info"?m.container:null,...m.onCollapse?{onCollapse:m.onCollapse}:{},hostExtras:w,children:a.jsx(mM,{api:t,session:_,focused:r,totalPanes:1,onFocus:()=>{},onClose:()=>{},onNewSession:s,onOpenConfig:i,hideHeader:!0})}):a.jsxs("div",{"data-testid":"topic-workspace-no-session",className:"p-6 text-[13px] text-text-400",children:["这个话题的 Master 会话(",d.masterSessionId,")不在当前会话列表里 —— 可能还没同步过来,或已被删除。"]})})})]})}function cet(e){const t=e.focused?"":"hidden";return a.jsx("div",{className:["flex flex-col h-full w-full absolute inset-0",t].join(" "),children:a.jsx(STe,{enabled:e.focused,children:uet(e)})})}function uet(e){var n;const{tab:t}=e;switch(t.kind){case"session":{const r=e.sessions.find(s=>s.sessionId===t.sid);if(!r)return null;if(r.originOwnerPrincipalId){const s=e.clientPool.getRemoteForDevice(r.originOwnerPrincipalId);return s?a.jsx(ZDe,{client:s,session:r,remoteSessions:e.remoteSessionsByOwnerId.get(r.originOwnerPrincipalId)??[],hasLoadedForOwner:e.remoteSessionsByOwnerId.has(r.originOwnerPrincipalId),focused:e.focused,totalPanes:1,onFocus:()=>{},onClose:()=>{},...e.onMirrorOrphan?{onMirrorOrphan:e.onMirrorOrphan}:{}}):null}return a.jsx(mM,{api:e.api,session:r,focused:e.focused,totalPanes:1,onFocus:()=>{},onClose:()=>{},onNewSession:s=>e.onNewSession(s),onOpenConfig:e.onOpenMobileConfig,onFork:s=>e.onFork(r,s)})}case"dm":{const r=e.contacts.find(o=>o.deviceId===t.peerDeviceId),s=r||(n=e.visitorContacts)==null?void 0:n.find(o=>o.deviceId===t.peerDeviceId),i=r??s;return!i||!e.myOwnerPrincipalId?a.jsx(tW,{api:e.api,onSelect:e.onSelectCwdForNew}):a.jsx(xDe,{contact:i,im:e.im,selfPrincipalId:e.myOwnerPrincipalId,selfDisplayName:e.myOwnerDisplayName,readOnly:s!==void 0})}case"topic":return a.jsx(aet,{topicId:t.topicId,api:e.api,sessions:e.sessions,focused:e.focused,onNewSession:e.onNewSession,onOpenConfig:e.onOpenMobileConfig});case"ext":return a.jsx(SDe,{client:e.client,extId:t.extId,updateInfo:e.extensionUpdateInfo,onApplyUpdate:e.onApplyExtensionUpdate});case"shift":return a.jsx(PJe,{api:e.api,sessions:e.sessions,focused:e.focused});case"prs":return a.jsx(VJe,{api:e.api,focused:e.focused,onOpenChat:e.onOpenPrChat});case"exts":return a.jsx(a.Fragment,{children:e.extensionsListNode??null});case"landing":return a.jsx(a.Fragment,{children:e.landingNode??null});case"deploy":return a.jsx(nDe,{personaId:t.personaId,api:e.api,...e.cloud?{cloud:e.cloud}:{}});case"deploy-history":return a.jsx(oDe,{personaId:t.personaId,initialHead:t.head})}}function det(e){const{view:t}=e;if(t.tabs.length===0)return a.jsx(tW,{api:e.api,onSelect:e.onSelectCwdForNew});const n=r=>{var s;switch(r.kind){case"session":{const i=e.sessions.find(o=>o.sessionId===r.sid);return(i==null?void 0:i.label)||(i==null?void 0:i.aiLabel)||(i==null?void 0:i.larkChatName)||(i==null?void 0:i.larkChatId)||(i==null?void 0:i.cwd)||r.sid.slice(0,8)}case"dm":{const i=e.contacts.find(o=>o.deviceId===r.peerDeviceId)??((s=e.visitorContacts)==null?void 0:s.find(o=>o.deviceId===r.peerDeviceId));return(i==null?void 0:i.displayName)||`DM ${r.peerDeviceId.slice(0,8)}`}case"ext":return r.extId;case"topic":{const i=e.topics.find(l=>l.id===r.topicId),o=i?e.sessions.find(l=>l.sessionId===i.masterSessionId)??null:null;return Ww((i==null?void 0:i.title)??"",o)}case"shift":return"Shift";case"prs":return"Pull Request";case"exts":return"Extensions";case"landing":return"新对话";case"deploy":return"发布到云上";case"deploy-history":return"发布历史"}};return a.jsxs("div",{className:"flex flex-col h-full w-full",children:[a.jsx(H1e,{tabs:t.tabs,focused:t.focused,onFocus:e.onFocusTab,onClose:e.onCloseTab,onCloseOthers:e.onCloseOtherTabs,onCloseAll:e.onCloseAllTabs,onReorder:e.onReorderTab,labelForTab:n,awaitingIds:e.awaitingIds,runningIds:e.runningIds,unreadIds:e.unreadIds,unreadDmPeerDeviceIds:e.unreadDmPeerDeviceIds,pendingIndex:e.pendingTabIndex}),a.jsx("div",{className:"flex-1 relative",children:t.tabs.map((r,s)=>a.jsx(cet,{tab:r,focused:s===t.focused,sessions:e.sessions,contacts:e.contacts,visitorContacts:e.visitorContacts,remoteSessionsByOwnerId:e.remoteSessionsByOwnerId,clientPool:e.clientPool,client:e.client,im:e.im,api:e.api,myOwnerPrincipalId:e.myOwnerPrincipalId,myOwnerDisplayName:e.myOwnerDisplayName,...e.cloud?{cloud:e.cloud}:{},onSelectCwdForNew:e.onSelectCwdForNew,onNewSession:e.onNewSession,onOpenPrChat:e.onOpenPrChat,onFork:e.onFork,onOpenMobileConfig:e.onOpenMobileConfig,...e.onMirrorOrphan?{onMirrorOrphan:e.onMirrorOrphan}:{},extensionUpdateInfo:e.extensionUpdateInfo,onApplyExtensionUpdate:e.onApplyExtensionUpdate,extensionsListNode:e.extensionsListNode,landingNode:e.landingNode},Pg(r)))})]})}function Oee(e){const[t,n]=p.useState({ownerPrincipalId:null,ownerId:null,ownerProvider:null,ownerDisplayName:null});return p.useEffect(()=>{let r=!1;const s=async()=>{try{const o=await e.request("whoami",{});if(r)return;n({ownerPrincipalId:o.owner.id,ownerId:o.owner.ownerId,ownerProvider:o.owner.provider,ownerDisplayName:o.owner.displayName})}catch{}};s();const i=e.on("daemon:connected",()=>{s()});return()=>{r=!0,i()}},[e]),t}function het(e){const t=Yn(),n=Oee(t),r=Nx();p.useEffect(()=>{r&&n.ownerPrincipalId!=null&&r.setIdentity({ownerPrincipalId:n.ownerPrincipalId,deviceId:n.ownerPrincipalId,appVersion:e,os:fet()})},[r,n.ownerPrincipalId,e])}function fet(){return typeof navigator<"u"&&navigator.userAgent?navigator.userAgent.slice(0,80):"unknown-renderer"}function pet(e,t,n="production"){const[r,s]=p.useState(void 0),[i,o]=p.useState(null),[l,c]=p.useState(null),[u,d]=p.useState(0);p.useEffect(()=>{if(!t){s(void 0),o(null),c(null);return}let g=!1;return(async()=>{try{const x=await e.request("auth:apiKey:get",n==="production"?{}:{environment:n});if(g)return;s(x.apiKey),o(x.gatewayUrl??null),c(null)}catch(x){g||(s(void 0),c(x instanceof Error?x.message:String(x)))}})(),()=>{g=!0}},[e,t,u,n]);const h=p.useCallback(async()=>{const g=await e.request("auth:apiKey:regenerate",n==="production"?{}:{environment:n});s(g.apiKey),o(g.gatewayUrl??null),c(null)},[e,n]),f=p.useCallback(async()=>{await e.request("auth:apiKey:revoke",n==="production"?{}:{environment:n}),s(null),c(null)},[e,n]),m=p.useCallback(()=>{c(null),s(void 0),d(g=>g+1)},[]);return{apiKey:r,gatewayUrl:i,loadError:l,regenerate:h,revoke:f,reload:m}}const dB="<persona-id>";function hB({value:e,label:t,testId:n,mono:r=!0}){const[s,i]=p.useState(!1),o=async()=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)}catch{}};return a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("code",{"data-testid":n,className:`flex-1 min-w-0 truncate rounded-md border border-border bg-bg-50 px-2 py-1.5 text-xs text-text-200 ${r?"font-mono":""}`,children:e}),a.jsx("button",{type:"button","aria-label":`复制${t}`,"data-testid":`${n}-copy`,onClick:o,className:"shrink-0 rounded-md border border-border p-1.5 text-text-400 hover:bg-bg-100 transition-colors",children:s?a.jsx(Xt,{className:"size-3.5 text-green-500"}):a.jsx(va,{className:"size-3.5"})})]})}function fB({loggedIn:e,apiKey:t,gatewayUrl:n,onRegenerate:r,onRevoke:s,personaId:i,loadError:o=null,onReload:l}){const[c,u]=p.useState(!1),[d,h]=p.useState(!1),[f,m]=p.useState(!1),[g,x]=p.useState(null),[b,y]=p.useState(!1),v=i??dB,w=async()=>{m(!0),x(null);try{await r(),u(!1)}catch(S){x(S instanceof Error?S.message:String(S))}finally{m(!1)}},_=async()=>{if(s){m(!0),x(null);try{await s(),h(!1)}catch(S){x(S instanceof Error?S.message:String(S))}finally{m(!1)}}};return e?a.jsxs("div",{className:"space-y-2","data-testid":"cloud-api-key-card",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-text-300",children:[a.jsx(Eg,{className:"size-3.5"}),"云 persona 调用 key"]}),o?a.jsxs("button",{type:"button","data-testid":"cloud-api-key-reload",onClick:()=>l==null?void 0:l(),className:"shrink-0 inline-flex items-center gap-1 rounded-md bg-bg-200 px-2.5 py-1 text-xs font-medium text-text-200 hover:bg-bg-300 transition-colors",children:[a.jsx(No,{className:"size-3"}),"重试"]}):a.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[a.jsxs("button",{type:"button","data-testid":"cloud-api-key-action",disabled:f||t===void 0,onClick:()=>t?u(!0):void w(),className:"inline-flex items-center gap-1 rounded-md bg-bg-200 px-2.5 py-1 text-xs font-medium text-text-200 hover:bg-bg-300 transition-colors disabled:opacity-50",children:[t?a.jsx(No,{className:"size-3"}):null,f?"处理中…":t?"重新生成":"生成"]}),t&&s?a.jsxs("button",{type:"button","data-testid":"cloud-api-key-revoke",disabled:f,onClick:()=>h(!0),className:"inline-flex items-center gap-1 rounded-md bg-bg-200 px-2.5 py-1 text-xs font-medium text-text-200 hover:bg-bg-300 transition-colors disabled:opacity-50",children:[a.jsx(ws,{className:"size-3"}),"撤销"]}):null]})]}),o&&a.jsxs("p",{"data-testid":"cloud-api-key-load-error",className:"text-xs text-text-400",children:["读不到你的 key(",o,")。",a.jsx("strong",{children:"这不代表你没有"})," —— 先重试, 别急着生成新的,生成会把可能还在用的那把顶掉。"]}),!o&&t===void 0&&a.jsx("p",{"data-testid":"cloud-api-key-loading",className:"text-xs text-text-400",children:"读取中…"}),t===null&&a.jsx("p",{"data-testid":"cloud-api-key-empty",className:"text-xs text-text-400",children:"还没生成。生成后可以用任意 OpenAI 兼容的客户端访问云上的 persona。"}),t&&a.jsxs("div",{className:"space-y-2",children:[a.jsx(hB,{value:t,label:"key",testId:"cloud-api-key-value"}),n?a.jsxs(a.Fragment,{children:[a.jsxs("button",{type:"button","data-testid":"cloud-api-key-usage-toggle","aria-expanded":b,onClick:()=>y(S=>!S),className:"inline-flex items-center gap-1 text-xs text-text-400 hover:text-text-200 transition-colors",children:[b?a.jsx(Qt,{className:"size-3"}):a.jsx(tr,{className:"size-3"}),"调用地址与示例"]}),b&&a.jsxs(a.Fragment,{children:[a.jsx(hB,{value:D_(n,v),label:"调用地址",testId:"cloud-api-key-base-url"}),a.jsx(C1,{label:"chat curl",testId:"cloud-api-key-sample-chat",curl:DE({gatewayUrl:n,personaId:v,apiKey:t,prompt:"hello",entry:"chat"})}),a.jsx(C1,{label:"task curl",testId:"cloud-api-key-sample-task",curl:DE({gatewayUrl:n,personaId:v,apiKey:t,prompt:"hello",entry:"task"})}),a.jsx("p",{className:"text-xs text-text-400",children:i?a.jsx(a.Fragment,{children:"这把 key 对这台 gateway 上挂着的每个云 persona 都有效,不只这一个。"}):a.jsxs(a.Fragment,{children:["把 ",a.jsx("code",{className:"font-mono",children:dB})," 换成要访问的 persona 名字(= 它的仓库名)。这把 key 对这台 gateway 上挂着的 persona 都有效。"]})})]})]}):a.jsxs("p",{"data-testid":"cloud-api-key-no-gateway",className:"text-xs text-text-400",children:["key 可以用了,但",a.jsx("strong",{children:"调用地址还没配"}),"(管理员在中心配"," ",a.jsx("code",{className:"font-mono",children:"PERSONA_CLOUD_GATEWAY_URL"}),")。 配好之后这里会自动出现地址和示例。"]})]}),g&&a.jsx("p",{"data-testid":"cloud-api-key-error",className:"text-xs text-red-500",children:g}),a.jsx(us,{open:c,onOpenChange:S=>{S||(u(!1),x(null))},children:a.jsxs(Wr,{className:"max-w-sm","data-testid":"cloud-api-key-confirm",children:[a.jsxs(zs,{children:[a.jsx(Vr,{children:"重新生成调用 key"}),a.jsxs(hi,{children:["一个人只有一把 key。生成新的之后,",a.jsx("strong",{children:"旧的立刻失效"}),",所有正在用旧 key 的地方都要换成新的。"]})]}),g&&a.jsx("p",{"data-testid":"cloud-api-key-confirm-error",className:"text-xs text-red-500",children:g}),a.jsxs(pa,{children:[a.jsx("button",{type:"button","data-testid":"cloud-api-key-confirm-cancel",disabled:f,onClick:()=>{u(!1),x(null)},className:"px-3 py-1.5 rounded-md bg-bg-200 text-text-200 text-xs font-medium hover:bg-bg-300 transition-colors disabled:opacity-50",children:"取消"}),a.jsx("button",{type:"button","data-testid":"cloud-api-key-confirm-ok",disabled:f,onClick:()=>void w(),className:"px-3 py-1.5 rounded-md bg-accent text-white text-xs font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:f?"生成中…":"生成新的"})]})]})}),a.jsx(us,{open:d,onOpenChange:S=>{S||(h(!1),x(null))},children:a.jsxs(Wr,{className:"max-w-sm","data-testid":"cloud-api-key-revoke-confirm",children:[a.jsxs(zs,{children:[a.jsx(Vr,{children:"撤销调用 key"}),a.jsxs(hi,{children:["撤销后这把 key ",a.jsx("strong",{children:"立刻失效、不会自动补新的"}),":粘到别处的那份不再能用; 开着的云 persona 会话下一条消息发不出去(正在跑的那一轮会跑完)。要再用,回来点「生成」。"]})]}),g&&a.jsx("p",{"data-testid":"cloud-api-key-revoke-error",className:"text-xs text-red-500",children:g}),a.jsxs(pa,{children:[a.jsx("button",{type:"button","data-testid":"cloud-api-key-revoke-cancel",disabled:f,onClick:()=>{h(!1),x(null)},className:"px-3 py-1.5 rounded-md bg-bg-200 text-text-200 text-xs font-medium hover:bg-bg-300 transition-colors disabled:opacity-50",children:"取消"}),a.jsx("button",{type:"button","data-testid":"cloud-api-key-revoke-ok",disabled:f,onClick:()=>void _(),className:"px-3 py-1.5 rounded-md bg-red-600 text-white text-xs font-medium hover:opacity-90 transition-opacity disabled:opacity-50",children:f?"撤销中…":"撤销"})]})]})})]}):a.jsxs("div",{className:"space-y-1.5","data-testid":"cloud-api-key-card",children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-text-300",children:[a.jsx(Eg,{className:"size-3.5"}),"云 persona 调用 key"]}),a.jsx("p",{"data-testid":"cloud-api-key-need-login",className:"text-xs text-text-400",children:"先登录飞书才能生成 —— 这把 key 的身份就是你的飞书账号。"})]})}const met={"cloud-persona-metrics":{title:"云 persona 运行状况",description:"云上 persona 现在有几个 Pod 在跑、成功率、失败原因、每段耗时,可按用法和版本筛。"},"cloud-persona-conversations":{title:"云 persona 对话记录",description:"别人跟你的云 persona 聊了什么、它是怎么做的;每轮聊完几秒后可看。"},"cloud-persona-schedules":{title:"云 persona 定时任务",description:"使用者在你的云 persona 里建了哪些定时任务、下次什么时候跑、最近跑得怎么样。"}};function get({tunnelReady:e,onOpen:t}){const[n,r]=p.useState(null),[s,i]=p.useState(null),o=async l=>{r(l),i(null);try{await t(l)}catch(c){i({page:l,message:c.message})}finally{r(null)}};return a.jsxs("div",{className:"space-y-3","data-testid":"settings-dashboard",children:[a.jsx("p",{className:"text-[13px] text-text-300",children:"看板在浏览器里打开,链接 24 小时内有效,过期了回这里再点一次。"}),e?null:a.jsx("p",{className:"rounded-md border border-border bg-bg-50 px-3 py-2 text-[12px] text-text-300","data-testid":"settings-dashboard-no-tunnel",children:"本机的公网地址还没连上(tunnel),暂时打不开;连上后这里会自动变成可点。"}),a.jsx("ul",{className:"divide-y divide-border rounded-lg border border-border",children:fH.map(l=>({page:l,...met[l]})).map(l=>a.jsxs("li",{className:"flex items-start gap-4 px-4 py-3","data-testid":`settings-dashboard-${l.page}`,children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("div",{className:"text-sm font-medium text-text-100",children:l.title}),a.jsx("div",{className:"mt-0.5 text-[12px] text-text-400",children:l.description}),(s==null?void 0:s.page)===l.page?a.jsxs("div",{className:"mt-1 text-[12px] text-destructive",children:["打不开:",s.message]}):null]}),a.jsxs(Be,{variant:"outline",size:"sm",disabled:!e||n!==null,onClick:()=>void o(l.page),"data-testid":`settings-dashboard-open-${l.page}`,children:[n===l.page?a.jsx(it,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):a.jsx(Ur,{className:"mr-1.5 h-3.5 w-3.5"}),"在浏览器打开"]})]},l.page))})]})}function xet(e,t){return e!=null&&t!=null&&t===e.ownerId}async function Dee(e){try{const t=await e();window.open(t,"_blank","noopener")}catch{}}const vet={sidebar:{wrap:"px-3 py-2 border-b shrink-0 flex flex-col gap-1.5",wrapLoggedOut:"border-border",wrapLoggedIn:"border-border",skeleton:"px-3 py-2 border-b border-border shrink-0",hint:"text-[11px] text-text-400 leading-snug",error:"text-[11px] text-error leading-snug",primaryBtn:"w-full px-2 py-1.5 text-xs rounded border border-border bg-bg-50 hover:bg-text-100/5 text-text-200 hover:text-text-100 transition-colors disabled:opacity-50",logoutBtn:"px-2 py-1 text-[11px] rounded border border-border text-text-400 hover:bg-text-100/5 hover:text-text-100 transition-colors disabled:opacity-50 shrink-0",avatar:"h-7 w-7 rounded-full shrink-0",avatarFallback:"flex h-7 w-7 items-center justify-center rounded-full bg-bg-200 text-xs text-text-200 shrink-0",name:"truncate text-xs text-text-100",sub:"truncate text-[10px] text-text-400",activating:"text-[11px] text-text-400 leading-snug animate-pulse"},settings:{wrap:"rounded-lg border bg-surface-card px-4 py-3 flex flex-col gap-2",wrapLoggedOut:"border-warning/50",wrapLoggedIn:"border-border",skeleton:"rounded-lg border border-border bg-surface-card px-4 py-3",hint:"text-[13px] text-text-200 leading-snug",error:"text-xs text-error",primaryBtn:"self-start inline-flex items-center justify-center whitespace-nowrap rounded-md h-8 px-3 text-xs font-medium bg-accent text-accent-contrast hover:bg-accent-hover 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",logoutBtn:"cursor-pointer whitespace-nowrap text-xs text-text-400 underline decoration-dotted underline-offset-4 hover:text-accent disabled:opacity-50 shrink-0",avatar:"h-8 w-8 rounded-full shrink-0",avatarFallback:"flex h-8 w-8 items-center justify-center rounded-full bg-bg-200 text-sm text-text-200 shrink-0",name:"truncate text-sm text-text-100",sub:"truncate font-mono text-[11px] text-text-400",activating:"text-xs text-text-400 leading-snug animate-pulse"}};function pB(e){const{identity:t,loading:n,error:r,active:s=!1,onLogin:i,onLogout:o,variant:l="sidebar"}=e,c=vet[l],[u,d]=p.useState(!1),h=p.useCallback(async()=>{d(!0);try{await Dee(i)}finally{d(!1)}},[i]),f=p.useCallback(async()=>{d(!0);try{await o()}finally{d(!1)}},[o]);return n?a.jsx("div",{className:c.skeleton,"data-testid":"feishu-login-card",children:a.jsx("div",{className:"h-8 w-full animate-pulse rounded bg-bg-100"})}):t?a.jsxs("div",{className:ee(c.wrap,c.wrapLoggedIn),"data-testid":"feishu-login-card",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[t.avatarUrl?a.jsx("img",{src:t.avatarUrl,alt:"",className:c.avatar}):a.jsx("div",{className:c.avatarFallback,children:t.displayName.slice(0,1)}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("div",{className:c.name,"data-testid":"feishu-login-name",children:t.displayName}),a.jsx("div",{className:c.sub,children:t.ownerId})]}),a.jsx("button",{type:"button",disabled:u,onClick:()=>void f(),"data-testid":"feishu-logout-button",className:c.logoutBtn,children:"登出"})]}),r?a.jsxs("p",{className:c.error,"data-testid":"feishu-login-error",children:["登录失败:",r]}):null,s?null:a.jsx("p",{className:c.activating,"data-testid":"feishu-restart-hint",children:"登录成功,身份生效中…"})]}):a.jsxs("div",{className:ee(c.wrap,c.wrapLoggedOut),"data-testid":"feishu-login-card",children:[a.jsx("p",{className:c.hint,children:"登录后远程连接将使用你的飞书身份,联系人能看到你的真实姓名"}),r?a.jsxs("p",{className:c.error,"data-testid":"feishu-login-error",children:["登录失败:",r]}):null,a.jsx("button",{type:"button",disabled:u,onClick:()=>void h(),"data-testid":"feishu-login-button",className:c.primaryBtn,children:u?"请在浏览器中完成授权…":"飞书登录"})]})}function yet(e){const[t,n]=p.useState(e.isOpen?{kind:"connected",url:""}:{kind:"connecting"});return p.useEffect(()=>{const r=e.on("ready",c=>{const u=c;n(d=>({kind:"connected",url:d.kind==="connected"?d.url:"",mode:d.kind==="connected"?d.mode:void 0,daemonVersion:u.version,protocolVersion:u.protocolVersion,daemonSource:u.daemonSource,globalCliVersion:u.globalCliVersion,onboardingCompletedAt:u.onboardingCompletedAt}))}),s=e.on("daemon:connected",c=>{const u=c;n(d=>({kind:"connected",url:u.url,mode:u.mode,daemonVersion:d.kind==="connected"?d.daemonVersion:void 0,protocolVersion:d.kind==="connected"?d.protocolVersion:void 0,daemonSource:d.kind==="connected"?d.daemonSource:void 0,globalCliVersion:d.kind==="connected"?d.globalCliVersion:void 0,onboardingCompletedAt:d.kind==="connected"?d.onboardingCompletedAt:void 0}))}),i=e.on("daemon:disconnected",c=>{const u=(c==null?void 0:c.reason)??"";/auth failed|auth timeout|auth required|auth handshake timeout/i.test(u)?n({kind:"auth-failed",reason:u}):n({kind:"disconnected",reason:u})}),o=e.on("daemon:reconnecting",c=>{const u=c;n({kind:"reconnecting",attempt:u.attempt,nextDelayMs:u.nextDelayMs,scheduledAt:u.scheduledAt??Date.now()})}),l=e.on("daemon:version-mismatch",c=>{const u=c;n({kind:"version-mismatch",daemonProtocol:u.daemonProtocol,supportedProtocol:u.supportedProtocol})});return()=>{r(),s(),i(),o(),l()}},[e]),t}function bet(e,t){p.useEffect(()=>{const n=t.notifier,r=u=>{const d=u;if(!d)return;const h=d.tool??"";n==null||n.notify({title:"Permission required",body:h?`${h} requires approval`:"Tool requires approval",kind:"permission"})},s=u=>{var f;const d=u;((f=d==null?void 0:d.event)==null?void 0:f.kind)==="turn_end"&&(n==null||n.notify({title:"Turn complete",body:"Claude finished a reply",kind:"turn-end"}))},i=()=>{n==null||n.notify({title:"Question pending",body:"Claude is asking a question",kind:"permission"})},o=e.on("permission:request",r),l=e.on("session:event",s),c=e.on("session:question",i);return()=>{o(),l(),c()}},[e,t])}function wet(e){const t=Ws(),n=ha(e.kind==="connected"?"sessions":""),r=p.useCallback(async()=>{t.setData("sessions",s=>s??[])},[t]);return{sessions:n??[],loading:!1,loaded:n!==void 0,error:null,refresh:r}}const _et=new Set(tT);function ket(e){return typeof e=="string"&&_et.has(e)}function Cet(e,t,n,r){let s=!1;const i=async()=>{try{const c=await e.request("info");if(s)return;const u=new Map;for(const d of c.runningSessions??[])n.current.has(d.sessionId)&&u.set(d.sessionId,d.status);r(d=>{const h=new Map(d);for(const[f,m]of u)h.has(f)||h.set(f,m);return h})}catch{}for(const c of t)e.request("session:subscribe",{sessionId:c}).catch(()=>{})};i();const o=e.on("session:status",c=>{const u=c;if(typeof u.sessionId!="string"||!n.current.has(u.sessionId)||!ket(u.status))return;const d=u.sessionId,h=u.status;r(f=>{if(f.get(d)===h)return f;const g=new Map(f);return g.set(d,h),g})}),l=e.on("daemon:connected",()=>{i()});return()=>{s=!0,o(),l()}}function Aee(e,t){const[n,r]=p.useState(new Map),s=p.useMemo(()=>e.map(h=>`${h.originOwnerPrincipalId??""}::${h.sid}`).sort().join("|"),[e]),i=p.useMemo(()=>{const h=new Map;for(const f of e){const m=f.originOwnerPrincipalId;let g=h.get(m);g||(g=new Set,h.set(m,g)),g.add(f.sid)}return h},[s]),o=p.useCallback(h=>t.onOwnersChanged(h),[t]),l=p.useCallback(()=>t.listRemoteDeviceIds().sort().join("|"),[t]),c=p.useCallback(()=>"",[]),u=p.useSyncExternalStore(o,l,c),d=p.useRef(new Map);return p.useEffect(()=>{for(const[h,f]of i){let m=d.current.get(h);m||(m={current:new Set},d.current.set(h,m)),m.current=f}for(const h of Array.from(d.current.keys()))i.has(h)||d.current.delete(h)}),p.useEffect(()=>{if(i.size===0)return;const h=[];for(const[f,m]of i){const g=f===null?t.local:t.getRemoteForDevice(f);if(!g)continue;const x=d.current.get(f);x&&h.push(Cet(g,m,x,r))}return()=>{for(const f of h)f()}},[t,s,u]),p.useMemo(()=>{const h=new Map;for(const[f,m]of n)h.set(f,LG({sessionStatus:m}));return h},[n])}function Qp(){return{realPermIds:new Set,realQuestionIds:new Set,realPopupKinds:new Set}}function Net(e){return e.realPermIds.size+e.realQuestionIds.size+e.realPopupKinds.size>0}function jet(e){return typeof e.toolUseId=="string"&&e.toolUseId.length>0?e.toolUseId:typeof e.requestId=="string"&&e.requestId.length>0?e.requestId:null}function mB(e){if(!Array.isArray(e))return[];const t=[];for(const n of e)typeof n=="string"&&n.length>0&&t.push(n);return t}function Eet(e,t,n){let r=!1;const s=async()=>{try{const h=await e.request("info");if(r)return;const f=new Map;for(const m of h.runningSessions??[])t.current.has(m.sessionId)&&f.set(m.sessionId,{perm:mB(m.pendingPermissionRequestIds),question:mB(m.pendingQuestionToolUseIds)});n(m=>{const g=new Map(m);for(const x of t.current){const b=g.get(x)??Qp(),y=f.get(x)??{perm:[],question:[]},v=new Set(b.realPermIds);for(const _ of y.perm)v.add(_);const w=new Set(b.realQuestionIds);for(const _ of y.question)w.add(_);g.set(x,{realPermIds:v,realQuestionIds:w,realPopupKinds:new Set(b.realPopupKinds)})}return g})}catch{}};s();const i=e.on("permission:request",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId))return;const m=jet(f);if(!m)return;const g=f.sessionId;n(x=>{const b=x.get(g)??Qp();if(b.realPermIds.has(m))return x;const y=new Set(b.realPermIds);y.add(m);const v=new Map(x);return v.set(g,{...b,realPermIds:y}),v})}),o=e.on("session:event",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId))return;const m=f.event;if(!m||m.kind!=="tool_result")return;const g=m.toolUseId;if(typeof g!="string"||g.length===0)return;const x=f.sessionId;n(b=>{const y=b.get(x);if(!y||!y.realPermIds.has(g))return b;const v=new Set(y.realPermIds);v.delete(g);const w=new Map(b);return w.set(x,{...y,realPermIds:v}),w})}),l=e.on("session:question",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId)||typeof f.toolUseId!="string"||f.toolUseId.length===0)return;const m=f.sessionId,g=f.toolUseId;n(x=>{const b=x.get(m)??Qp();if(b.realQuestionIds.has(g))return x;const y=new Set(b.realQuestionIds);y.add(g);const v=new Map(x);return v.set(m,{...b,realQuestionIds:y}),v})}),c=e.on("session:question:cleared",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId)||typeof f.toolUseId!="string"||f.toolUseId.length===0)return;const m=f.sessionId,g=f.toolUseId;n(x=>{const b=x.get(m);if(!b||!b.realQuestionIds.has(g))return x;const y=new Set(b.realQuestionIds);y.delete(g);const v=new Map(x);return v.set(m,{...b,realQuestionIds:y}),v})}),u=e.on("session:control",h=>{const f=h;if(!f||typeof f.sessionId!="string"||!t.current.has(f.sessionId)||typeof f.popupKind!="string"||f.popupKind.length===0)return;const m=f.sessionId,g=f.popupKind;f.kind==="popup_open"?n(x=>{const b=x.get(m)??Qp();if(b.realPopupKinds.has(g))return x;const y=new Set(b.realPopupKinds);y.add(g);const v=new Map(x);return v.set(m,{...b,realPopupKinds:y}),v}):f.kind==="popup_close"&&n(x=>{const b=x.get(m);if(!b||!b.realPopupKinds.has(g))return x;const y=new Set(b.realPopupKinds);y.delete(g);const v=new Map(x);return v.set(m,{...b,realPopupKinds:y}),v})}),d=e.on("daemon:connected",()=>{n(h=>{let f=!1;const m=new Map(h);for(const g of t.current)m.has(g)&&(m.set(g,Qp()),f=!0);return f?m:h}),s()});return()=>{r=!0,i(),o(),l(),c(),u(),d()}}function $ee(e,t){const[n,r]=p.useState(new Map),s=p.useMemo(()=>e.map(h=>`${h.originOwnerPrincipalId??""}::${h.sid}`).sort().join("|"),[e]),i=p.useMemo(()=>{const h=new Map;for(const f of e){const m=f.originOwnerPrincipalId;let g=h.get(m);g||(g=new Set,h.set(m,g)),g.add(f.sid)}return h},[s]),o=p.useCallback(h=>t.onOwnersChanged(h),[t]),l=p.useCallback(()=>t.listRemoteDeviceIds().sort().join("|"),[t]),c=p.useCallback(()=>"",[]),u=p.useSyncExternalStore(o,l,c),d=p.useRef(new Map);return p.useEffect(()=>{for(const[h,f]of i){let m=d.current.get(h);m||(m={current:new Set},d.current.set(h,m)),m.current=f}for(const h of Array.from(d.current.keys()))i.has(h)||d.current.delete(h)}),p.useEffect(()=>{if(i.size===0)return;const h=[];for(const[f]of i){const m=f===null?t.local:t.getRemoteForDevice(f);if(!m)continue;const g=d.current.get(f);g&&h.push(Eet(m,g,r))}return()=>{for(const f of h)f()}},[t,s,u]),p.useMemo(()=>{const h=new Set;for(const f of e){const m=n.get(f.sid);m&&Net(m)&&h.add(f.sid)}return h},[n,s])}function Iet(e){const{entries:t,sessions:n,activeId:r,pool:s}=e,[i,o]=p.useState(new Map),l=p.useMemo(()=>t.map(v=>`${v.originOwnerPrincipalId??""}::${v.sid}`).sort().join("|"),[t]),c=p.useMemo(()=>{const v=new Map;for(const w of t)v.set(w.sid,w.originOwnerPrincipalId);return v},[l]),u=p.useCallback(v=>s.onOwnersChanged(v),[s]),d=p.useCallback(()=>s.listRemoteDeviceIds().sort().join("|"),[s]),h=p.useCallback(()=>"",[]),f=p.useSyncExternalStore(u,d,h),m=p.useRef(new Map);p.useEffect(()=>{const v=new Map;for(const w of t){if(!w.originOwnerPrincipalId)continue;let _=v.get(w.originOwnerPrincipalId);_||(_=new Set,v.set(w.originOwnerPrincipalId,_)),_.add(w.sid)}m.current=v}),p.useEffect(()=>{const v=new Set;for(const _ of t)_.originOwnerPrincipalId&&v.add(_.originOwnerPrincipalId);if(v.size===0)return;const w=[];for(const _ of v){const S=s.getRemoteForDevice(_);S&&w.push(S.on("session:info",k=>{var E;const C=k;if(typeof C.sessionId!="string")return;const N=C.sessionId;if(!((E=m.current.get(_))!=null&&E.has(N)))return;const T=typeof C.unreadAt=="string"&&C.unreadAt?C.unreadAt:null;o(R=>{if(R.get(N)===T)return R;const O=new Map(R);return O.set(N,T),O})}))}return()=>{for(const _ of w)_()}},[s,l,f]);const g=p.useMemo(()=>{const v=new Map;for(const w of n)typeof w.unreadAt=="string"&&w.unreadAt&&c.has(w.sessionId)&&v.set(w.sessionId,w.unreadAt);for(const[w,_]of i)c.has(w)&&(_===null?v.delete(w):v.set(w,_));return v},[n,i,c]),x=p.useRef(new Set),[b,y]=p.useState(new Set);return p.useEffect(()=>{if(!r)return;const v=g.get(r);if(!v)return;const w=`${r}::${v}`;if(x.current.has(w))return;const _=c.get(r),S=_?s.getRemoteForDevice(_):s.local;S&&(x.current.add(w),S.request("session:markRead",{sessionId:r}).catch(()=>{}),y(k=>new Set(k).add(w)))},[r,g,c,s,f]),p.useMemo(()=>{const v=new Set;for(const[w,_]of g)w!==r&&(b.has(`${w}::${_}`)||v.add(w));return v},[g,r,b])}function lS(e,t){return e.larkChatId!=null||e.originOwnerPrincipalId||e.ownerPersonaId||!t||!e.creatorPrincipalId?!0:e.creatorPrincipalId===t}function av(e){return e.label||e.aiLabel||e.larkChatName||e.larkChatId||e.cwd.split("/").filter(Boolean).pop()||e.sessionId.slice(0,8)}function Tet(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function ym(e,t){const n=ul(),[r,s]=p.useState(t),[i,o]=p.useState(!1);p.useEffect(()=>{let c=!1;return o(!1),(async()=>{try{const u=await n.kv.get(e);if(c)return;const d=Tet(u);typeof d=="boolean"&&s(d)}catch{}finally{c||o(!0)}})(),()=>{c=!0}},[n,e]);const l=p.useCallback(c=>{s(c),n.kv.set(e,c).catch(()=>{})},[n,e]);return[r,l,i]}function Ret(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function bf(e,t){const n=ul(),[r,s]=p.useState(t),[i,o]=p.useState(!1);p.useEffect(()=>{let c=!1;return o(!1),(async()=>{try{const u=await n.kv.get(e);if(c)return;const d=Ret(u);typeof d=="string"&&s(d)}catch{}finally{c||o(!0)}})(),()=>{c=!0}},[n,e]);const l=p.useCallback(c=>{s(c),n.kv.set(e,c).catch(()=>{})},[n,e]);return[r,l,i]}const Met="clawd:sidebar:projects:expanded";function Pet(e){if(!e)return[];try{const t=JSON.parse(e);if(Array.isArray(t))return t.filter(n=>typeof n=="string")}catch{}return[e]}function Oet(){const[e,t]=bf(Met,""),n=p.useMemo(()=>new Set(Pet(e)),[e]);return{expandedPaths:n,toggleProject:s=>{const i=new Set(n);i.has(s)?i.delete(s):i.add(s),t(JSON.stringify([...i]))}}}const Det="clawd:sidebar:channels:collapsed";function Aet(e){if(!e)return[];try{const t=JSON.parse(e);if(Array.isArray(t))return t.filter(n=>typeof n=="string")}catch{}return[]}function $et(){const[e,t]=bf(Det,""),n=p.useMemo(()=>new Set(Aet(e)),[e]);return{collapsedChannelIds:n,toggleChannel:s=>{const i=new Set(n);i.has(s)?i.delete(s):i.add(s),t(JSON.stringify([...i]))}}}function lv(e){return e.forkedFromSessionId??e.dispatchedFromSessionId??e.shiftFiredFromSessionId}function cS(e,t){return e.updatedAt<t.updatedAt?1:e.updatedAt>t.updatedAt?-1:0}function Sc(e){e=e.filter(i=>!i.ephemeral&&i.deployId===void 0&&i.testReleaseId===void 0);const t=new Map;for(const i of e)t.set(i.sessionId,i);const n=new Map,r=[];for(const i of e){const o=lv(i);if(o&&t.has(o)){const l=n.get(o)??[];l.push(i),n.set(o,l)}else r.push(i)}const s=i=>{const l=[...n.get(i.sessionId)??[]].sort(cS);return{session:i,children:l.map(s)}};return[...r].sort(Fet).map(s)}function ey(e,t){const n=new Map;for(const o of e){const l=lv(o);if(!l)continue;const c=n.get(l)??[];c.push(o.sessionId),n.set(l,c)}const r=[],s=new Set([t]),i=[t];for(;i.length>0;){const o=i.pop(),l=n.get(o)??[];for(const c of l)s.has(c)||(s.add(c),r.push(c),i.push(c))}return r}function uS(e){return[...e].sort((t,n)=>cS(t.session,n.session))}function Let(e,t){return t.awaitingIds.has(e)?0:t.runningIds.has(e)?1:t.unreadIds.has(e)?2:3}function Lee(e,t){let n=Let(e.session.sessionId,t);for(const r of e.children)n=Math.min(n,Lee(r,t));return n}function Fee(e,t){const n=new Map;for(const r of e)n.set(r,Lee(r,t));return[...e].sort((r,s)=>{const i=n.get(r)-n.get(s);return i!==0?i:cS(r.session,s.session)})}function Fet(e,t){const n=typeof e.pinnedAt=="number",r=typeof t.pinnedAt=="number";if(n&&r){const s=typeof e.pinSortOrder=="number",i=typeof t.pinSortOrder=="number";return s&&i?e.pinSortOrder-t.pinSortOrder:s?-1:i?1:t.pinnedAt-e.pinnedAt}return n?-1:r?1:cS(e,t)}const gB={awaiting:3,unread:2,running:1};function Bet(e,t){return t.awaitingIds.has(e)?"awaiting":t.unreadIds.has(e)?"unread":t.runningIds.has(e)?"running":null}function x3(e,t){let n=null;for(const r of e){const s=[Bet(r.session.sessionId,t),x3(r.children,t)];for(const i of s)i&&(!n||gB[i]>gB[n])&&(n=i)}return n}function Bee(e,t){if(e.projectPath&&t.includes(e.projectPath))return e.projectPath;let n=null;for(const r of t)(e.cwd===r||e.cwd.startsWith(r.endsWith("/")?r:r+"/"))&&(n===null||r.length>n.length)&&(n=r);return n}function v3(e){return!e.ephemeral}function xB(e){return v3(e)&&e.ownerPersonaId!==Fi}function zet(e,t){let n=e;const r=new Set([n.sessionId]);let s=e.archivedAt==null?null:e;for(;;){const i=lv(n);if(!i)return s;const o=t.get(i);if(!o||r.has(o.sessionId))return s;r.add(o.sessionId),n=o,n.archivedAt!=null&&(s=n)}}function Het(e,t){let n=e;const r=new Set([n.sessionId]);for(;;){const s=lv(n);if(!s)return n;const i=t.get(s);if(!i||r.has(i.sessionId))return n;r.add(i.sessionId),n=i}}function Zm(e){const t=new Map(e.map(i=>[i.sessionId,i])),n=[],r=[],s=new Map;for(const i of e){const o=zet(i,t);if(o==null)n.push(i);else if(i.sessionId===o.sessionId)r.push(i);else{const l=s.get(o.sessionId)??[];l.push(i),s.set(o.sessionId,l)}}return{visible:n,archivedRoots:r,archivedChildrenByRoot:s}}function dS(e,t,n,r){const s=n&&n.length>0?new Map(e.map(i=>[i.sessionId,i])):null;return e.filter(i=>i.chatId!==void 0||r!=null&&r.has(i.sessionId)||i.deployId!==void 0||i.testReleaseId!==void 0||s&&n&&Bee(Het(i,s),n)!==null?!1:lS(i,t))}function u2(e,t,n,r,s){const{visible:i}=Zm(e);return uS(Sc(dS(i,t,r,s))).filter(l=>l.session.pinnedAt==null).map(l=>l.session).slice(n)}function zee(e,t,n){const r=dS(e,t),s=Sc(r),i=new Map;for(const o of s){if(o.session.pinnedAt!=null)continue;const l=Bee(o.session,n);if(!l)continue;const c=i.get(l)??[];c.push(o),i.set(l,c)}for(const o of i.values())o.sort((l,c)=>c.session.updatedAt>l.session.updatedAt?1:-1);return i}const tb=p.createContext(null);function Uet(){const e=p.useContext(tb);if(!e)throw new Error("SessionTreeCollapsedContext.Provider missing — wrap SessionTreeNode tree with <SessionTreeCollapsedContext.Provider value={useSessionTreeCollapsed()}>");return e}function gI({tool:e,className:t}){const n=xTe(e);return a.jsx("span",{"data-testid":n?`session-icon-${e}`:"session-icon-default","aria-label":n?DR(e):"未知引擎",className:ee("w-3.5 h-3.5 shrink-0 inline-flex items-center justify-center",nf(e),t),children:a.jsx(rf,{tool:e,className:"w-full h-full"})})}function Hee({sessionId:e,hasUnread:t,running:n=!1,awaitingUser:r=!1,style:s}){return r?a.jsx(rT,{"data-testid":`awaiting-dot-${e}`,style:s,className:"w-3 h-3 text-warning shrink-0 animate-pulse",strokeWidth:2.25,"aria-label":"awaiting user"}):t?a.jsx("span",{"data-testid":`unread-dot-${e}`,style:s,className:"w-2 h-2 rounded-full bg-error shrink-0","aria-label":"unread"}):n?a.jsx("span",{"data-testid":`running-dot-${e}`,style:s,className:"w-2 h-2 rounded-full bg-success shrink-0 animate-pulse","aria-label":"running"}):null}function Uee({open:e,initialLabel:t,placeholder:n,onSubmit:r,onCancel:s,title:i="Edit session",fieldLabel:o="Label",testId:l="session-edit-dialog",requireNonEmpty:c=!1}){const[u,d]=p.useState(t);p.useEffect(()=>{e&&d(t)},[e,t]);const h=u.trim(),f=c&&h==="",m=()=>{f||r({label:h})},g=xi(m,s);return e?os.createPortal(a.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:s,"data-testid":`${l}-overlay`,children:a.jsxs("div",{"data-testid":l,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:x=>x.stopPropagation(),children:[a.jsx("div",{className:"text-[15px] font-semibold text-text-100",children:i}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:o}),a.jsx("input",{autoFocus:!0,type:"text",value:u,onChange:x=>d(x.target.value),...g,placeholder:n,"data-testid":`${l}-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"})]}),a.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[a.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"}),a.jsx("button",{type:"button",onClick:m,disabled:f,"data-testid":`${l}-save`,className:"px-4 py-1.5 text-[12px] font-medium text-bg-0 rounded-lg bg-text-100 hover:bg-text-200 transition-colors cursor-pointer disabled:cursor-not-allowed disabled:opacity-40",children:"Save"})]})]})}),document.body):null}const Wet={held:!1,indexBySessionId:new Map},Wee=p.createContext(Wet);function Vet(){return p.useContext(Wee)}const qet=Array.from({length:9},(e,t)=>({id:`switch-session-${t+1}`,combo:{key:String(t+1),mod:!0},label:`切换到第 ${t+1} 个会话`,group:"会话",desktopOnly:!0,hiddenInList:!0})),Vee=[{id:"new-session",combo:{key:"n",mod:!0},label:"新建任务",description:"打开快捷新建弹窗",group:"通用",desktopOnly:!0},{id:"open-search",combo:{key:"k",mod:!0},label:"全局搜索",description:"搜会话内容 / persona / 联系人",group:"通用",desktopOnly:!0},{id:"search-tab-prev",combo:{key:"ArrowLeft",mod:!0},label:"搜索:上一组",description:"搜索浮层里切到左边那个 tab(会话 / persona / 联系人)",group:"通用"},{id:"search-tab-next",combo:{key:"ArrowRight",mod:!0},label:"搜索:下一组",description:"搜索浮层里切到右边那个 tab",group:"通用"},...qet,{id:"archive-session",combo:{key:"Backspace",mod:!0,shift:!0},label:"归档当前会话",description:"归档当前聊天区的会话,Enter 确认 / Esc 取消",group:"会话",desktopOnly:!0},{id:"tab-prev",combo:{key:"ArrowLeft",mod:!0,shift:!0},label:"上一个标签页",description:"连按快速移动,停下或松开修饰键后切换",group:"标签页"},{id:"tab-next",combo:{key:"ArrowRight",mod:!0,shift:!0},label:"下一个标签页",description:"连按快速移动,停下或松开修饰键后切换",group:"标签页"},{id:"close-tab",combo:{key:"w",mod:!0},label:"关闭当前标签页",description:"关闭当前聚焦的标签页",group:"标签页",desktopOnly:!0},{id:"toggle-hive",combo:{key:"h",mod:!0,shift:!0},label:"Hive 看板",description:"全屏看所有 agent 在干什么;Esc 或点任意行退出",group:"通用"},{id:"quit-app",combo:{key:"q",mod:!0},label:"退出 clawd",description:"退出应用,由 Electron 默认菜单处理",group:"通用",desktopOnly:!0,displayOnly:!0},{id:"send-message",combo:{key:"Enter"},label:"发送消息",description:"在输入框中发送当前内容",group:"输入",displayOnly:!0},{id:"newline",combo:{key:"Enter",shift:!0},label:"换行",description:"在输入框中插入换行",group:"输入",displayOnly:!0},{id:"interrupt",combo:{key:"Escape"},label:"打断回复",description:"打断当前回复;2 秒内按两次停止任务",group:"输入",displayOnly:!0}],Ket=Vee.filter(e=>!e.displayOnly),Get={ArrowLeft:"←",ArrowRight:"→",ArrowUp:"↑",ArrowDown:"↓",Escape:"Esc"};function d2(e,t){const n=e.key==="Enter"||e.key==="Backspace"?t?{Enter:"⏎",Backspace:"⌫"}[e.key]:e.key:Get[e.key]??e.key.toUpperCase();if(t)return`${e.alt?"⌥":""}${e.shift?"⇧":""}${e.mod?"⌘":""}${n}`;const r=[];return e.mod&&r.push("Ctrl"),e.alt&&r.push("Alt"),e.shift&&r.push("Shift"),r.push(n),r.join("+")}function qee(e){const t=[];let n=!1;for(const r of Vee){if(r.hiddenInList){!n&&r.id.startsWith("switch-session-")&&(t.push({id:"switch-session",label:"快速切换会话",description:"按 sidebar 置顶 + 最近顺序直达第 1-9 个会话",group:"会话",keys:[d2({key:"1",mod:!0},e),"…",d2({key:"9",mod:!0},e)],desktopOnly:!0}),n=!0);continue}t.push({id:r.id,label:r.label,description:r.description,group:r.group,keys:[d2(r.combo,e)],desktopOnly:r.desktopOnly})}return t}const Kee=["通用","会话","标签页","输入"];function Yet(e){if(!e||typeof e!="object")return!1;const t=e;return t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable===!0}function Xet(e,t,n){if(e.isComposing||e.keyCode===229)return null;for(const r of t){const s=r.combo;if(e.key.toLowerCase()!==s.key.toLowerCase())continue;const i=n?e.metaKey:e.ctrlKey,o=n?e.ctrlKey:e.metaKey;if(!(!!s.mod!==i||o||!!s.shift!==e.shiftKey||!!s.alt!==e.altKey||!(s.mod||s.alt)&&Yet(e.target)))return r}return null}function cv(){return/Mac|iP(hone|od|ad)/.test(navigator.platform)}function Zet(e){const t=p.useRef(e);p.useEffect(()=>{t.current=e}),p.useEffect(()=>{const n=cv(),r=s=>{const i=Xet(s,Ket,n);if(!i)return;const o=t.current[i.id];o&&(s.preventDefault(),o())};return window.addEventListener("keydown",r,!0),()=>window.removeEventListener("keydown",r,!0)},[])}const Gee=10,Qet=20,Jet=16,vB=20,yB=60,Yee=4,Xee=Gee,Zee=Yee;function ty({testId:e,label:t,children:n}){return a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:a.jsx("span",{"data-testid":e,role:"img","aria-label":t,tabIndex:0,className:"inline-flex shrink-0",children:n})}),a.jsx(gi,{side:"bottom",children:t})]})}function ett({session:e,active:t,hasUnread:n,running:r=!1,awaitingUser:s=!1,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,quickAction:d,depth:h=0,chevron:f,showCopyResume:m=!0,contactDisplayName:g,ownerPrincipalId:x,creatorDisplayName:b,dispatchedFromSessionTitle:y}){const[v,w]=p.useState(!1),_=Vet(),S=_.held?_.indexBySessionId.get(e.sessionId):void 0,k=!!e.pinnedAt,C=h===0,N=h===0&&!!u,T=Gee+h*Qet;let E=null;d==="pin"&&C&&c?E={icon:k?a.jsx(qb,{className:"w-4 h-4"}):a.jsx(Ig,{className:"w-4 h-4"}),label:k?"取消置顶":"置顶",run:()=>c(e.sessionId,!k)}:d==="archive"&&N&&u?E={icon:a.jsx(Iu,{className:"w-4 h-4"}),label:"归档",run:()=>u(e.sessionId,!0)}:d==="rename"&&o&&(E={icon:a.jsx(Mu,{className:"w-4 h-4"}),label:"重命名",run:()=>w(!0)});const R=p.useCallback(async()=>{const B=AG(e);if(B)try{await navigator.clipboard.writeText(B)}catch{}},[e]),O=av(e),P=e.originOwnerPrincipalId,$=P?`@${g??`…${P.slice(-8)}`}`:null,F=!!(e.ownerPersonaId&&x&&e.creatorPrincipalId&&e.creatorPrincipalId!==x&&!e.larkChatId&&!e.shiftFiredFromSessionId&&!e.dispatchedFromSessionId);return a.jsxs(a.Fragment,{children:[a.jsxs("div",{"data-testid":`session-item-${e.sessionId}`,onClick:i,style:{paddingLeft:T,display:"grid",gridTemplateColumns:f?`${Jet}px ${vB}px 1fr auto ${yB}px`:`${vB}px 1fr auto ${yB}px`,gridTemplateAreas:f?'"chev icon name dot time"':'"icon name dot time"',columnGap:`${Yee}px`,alignItems:"center"},className:ee("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?a.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,a.jsx("div",{style:{gridArea:"chev"},className:"flex items-center justify-center",children:f??null}),a.jsx("div",{style:{gridArea:"icon"},className:"flex items-center justify-center",children:a.jsx(gI,{tool:e.tool})}),a.jsxs("div",{style:{gridArea:"name"},className:"flex items-center gap-1 min-w-0",children:[a.jsxs(di,{delayDuration:200,skipDelayDuration:100,children:[e.dispatchedFromSessionId?a.jsx(ty,{testId:`dispatched-icon-${e.sessionId}`,label:`来自【${y??"另一会话"}】dispatch`,children:a.jsx(oT,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,e.shiftFiredFromSessionId?a.jsx(ty,{testId:`shift-fired-icon-${e.sessionId}`,label:"定时任务",children:a.jsx(jH,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,e.larkChatId?a.jsx(ty,{testId:`lark-chat-icon-${e.sessionId}`,label:e.larkChatType==="p2p"?"来自飞书DM":"来自飞书群",children:a.jsx(hT,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null,F?a.jsx(ty,{testId:`guest-created-icon-${e.sessionId}`,label:b?`${b}创建`:"其他人创建",children:a.jsx(XH,{"aria-hidden":"true",className:"w-3 h-3 text-accent",strokeWidth:2.25})}):null]}),a.jsx("span",{"data-testid":`session-title-${e.sessionId}`,className:ee("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:O}),$?a.jsx("span",{"data-testid":`session-mirror-chip-${e.sessionId}`,title:`在 ${$.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:$}):null]}),a.jsx(Hee,{sessionId:e.sessionId,hasUnread:n,running:r,awaitingUser:s,style:{gridArea:"dot"}}),S!=null?a.jsx("span",{style:{gridArea:"time"},"data-testid":`session-quick-switch-badge-${e.sessionId}`,className:"text-right shrink-0 transition-opacity duration-150 group-hover:opacity-0",children:a.jsx("span",{className:"inline-flex items-center justify-center h-[18px] px-1.5 rounded-[5px] border border-border bg-bg-200/70 text-[11px] text-text-200 font-medium leading-none",children:cv()?`⌘${S}`:`Ctrl+${S}`})}):a.jsx("span",{style:{gridArea:"time"},className:ee("text-[11px] text-text-400/70 text-right shrink-0","transition-opacity duration-150 group-hover:opacity-0"),children:e.updatedAt?tM(e.updatedAt):""}),o||l||c||u?a.jsxs("div",{className:"absolute right-2 top-[3px] flex items-center opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100 transition-opacity",children:[E?a.jsx(di,{delayDuration:200,skipDelayDuration:100,children:a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:a.jsx("button",{type:"button",onClick:B=>{B.stopPropagation(),E.run()},className:"flex items-center justify-center w-7 h-7 rounded-md text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors cursor-pointer","aria-label":E.label,"data-testid":`quick-action-${d}-${e.sessionId}`,children:E.icon})}),a.jsx(gi,{side:"bottom",children:E.label})]})}):null,a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button",onClick:B=>B.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:a.jsx(ca,{className:"w-4 h-4"})})}),a.jsxs(Pr,{align:"end",onClick:B=>B.stopPropagation(),children:[c&&C&&a.jsxs(Et,{onSelect:()=>c(e.sessionId,!k),"data-testid":`session-${k?"unpin":"pin"}-${e.sessionId}`,children:[k?a.jsx(qb,{className:"w-3 h-3 mr-2 text-text-400"}):a.jsx(Ig,{className:"w-3 h-3 mr-2 text-text-400"}),k?"Unpin":"Pin"]}),N&&u&&a.jsxs(Et,{onSelect:()=>u(e.sessionId,!0),"data-testid":`session-archive-${e.sessionId}`,children:[a.jsx(Iu,{className:"w-3 h-3 mr-2 text-text-400"}),"Archive"]}),o&&a.jsxs(Et,{onSelect:()=>w(!0),"data-testid":`session-rename-${e.sessionId}`,children:[a.jsx(Mu,{className:"w-3 h-3 mr-2 text-text-400"}),"Rename"]}),m&&e.toolSessionId?a.jsxs(Et,{onSelect:()=>void R(),"data-testid":`session-copy-resume-${e.sessionId}`,children:[a.jsx(va,{className:"w-3 h-3 mr-2 text-text-400"}),"Copy Resume Command"]}):null,(c||o||m&&e.toolSessionId)&&l&&a.jsx(ma,{}),l&&a.jsxs(Et,{onSelect:()=>void l(e.sessionId),className:"text-destructive focus:text-destructive focus:bg-destructive/10","data-testid":`session-delete-${e.sessionId}`,children:[a.jsx(ws,{className:"w-3 h-3 mr-2"}),"Delete"]})]})]})]}):null]}),o?a.jsx(Uee,{open:v,initialLabel:e.label??"",placeholder:e.cwd.split("/").pop()||"",onSubmit:B=>{o(e.sessionId,B),w(!1)},onCancel:()=>w(!1)}):null]})}function Zu({node:e,depth:t=0,activeId:n,unreadIds:r,runningIds:s,awaitingIds:i,onSelect:o,onEdit:l,onDelete:c,onPin:u,onArchive:d,quickAction:h,getContactDisplayName:f,showCopyResume:m,ownerPrincipalId:g,getCreatorDisplayName:x,getSessionDisplayName:b,parentSession:y}){const v=e.children.length>0,{isCollapsed:w,toggle:_}=Uet(),S=!w(e.session.sessionId),k=p.useCallback(N=>{N.stopPropagation(),_(e.session.sessionId)},[_,e.session.sessionId]),C=v?a.jsx("button",{type:"button",onClick:k,"data-testid":`session-chevron-${e.session.sessionId}`,"aria-label":S?"collapse":"expand","aria-expanded":S,className:"shrink-0 flex items-center justify-center w-4 h-4 text-text-400 hover:text-text-100 cursor-pointer",children:S?a.jsx(Qt,{className:"w-3 h-3"}):a.jsx(tr,{className:"w-3 h-3"})}):null;return a.jsxs("div",{"data-testid":`session-tree-node-${e.session.sessionId}`,children:[a.jsx(ett,{session:e.session,active:n===e.session.sessionId,hasUnread:(r==null?void 0:r.has(e.session.sessionId))??!1,running:(s==null?void 0:s.has(e.session.sessionId))??!1,awaitingUser:(i==null?void 0:i.has(e.session.sessionId))??!1,onSelect:()=>o(e.session.sessionId),onEdit:l,onDelete:c,onPin:u,onArchive:d,quickAction:h,showCopyResume:m,ownerPrincipalId:g,creatorDisplayName:e.session.creatorPrincipalId?x==null?void 0:x(e.session.creatorPrincipalId):void 0,dispatchedFromSessionTitle:e.session.dispatchedFromSessionId?(b==null?void 0:b(e.session.dispatchedFromSessionId))??((y==null?void 0:y.sessionId)===e.session.dispatchedFromSessionId?av(y):void 0):void 0,depth:t,chevron:C,contactDisplayName:e.session.originOwnerPrincipalId?f==null?void 0:f(e.session.originOwnerPrincipalId):void 0}),v&&S?a.jsx("div",{"data-testid":`session-tree-children-${e.session.sessionId}`,children:e.children.map(N=>a.jsx(Zu,{node:N,depth:t+1,activeId:n,unreadIds:r,runningIds:s,awaitingIds:i,onSelect:o,onEdit:l,onDelete:c,onPin:u,onArchive:d,quickAction:h,getContactDisplayName:f,showCopyResume:m,ownerPrincipalId:g,getCreatorDisplayName:x,getSessionDisplayName:b,parentSession:e.session},N.session.sessionId))}):null]})}const bB=5,h2="hidden group-hover:inline-flex group-has-[[data-state=open]]:inline-flex p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",ttt="group-hover:hidden group-has-[[data-state=open]]:hidden";function xI(){return a.jsx("span",{className:"shrink-0 w-2 h-2 rounded-full bg-blue-500"})}function Qee({nodes:e,depth:t,activeId:n,unreadIds:r,onSelect:s}){return a.jsx(a.Fragment,{children:e.map(i=>a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`project-session-child-${i.session.sessionId}`,className:`flex items-center gap-1.5 pr-2 py-[5px] mx-1 rounded-md cursor-pointer ${n===i.session.sessionId?"bg-text-100/10":"hover:bg-text-100/5"}`,style:{paddingLeft:36+t*12},onClick:()=>s(i.session.sessionId),children:[a.jsx("span",{className:"flex-1 min-w-0 truncate text-[13px] text-text-200",children:i.session.label??i.session.aiLabel??i.session.sessionId}),r.has(i.session.sessionId)?a.jsx(xI,{}):null]}),a.jsx(Qee,{nodes:i.children,depth:t+1,activeId:n,unreadIds:r,onSelect:s})]},i.session.sessionId))})}function Jee({project:e,nodes:t,expanded:n,onToggle:r,activeId:s,unreadIds:i,onSelect:o,onPin:l,onNewInProject:c,getPersonaDisplayName:u,onTogglePinProject:d,onRevealProject:h}){const[f,m]=p.useState(!1),g=f?t:t.slice(0,bB),x=t.filter(v=>i.has(v.session.sessionId)).length,b=!!(d||h),y=e.pinnedAt!=null;return a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`project-row-${e.name}`,title:e.path,style:{paddingLeft:Xee,gap:Zee},className:"group flex items-center pr-3 py-[5px] mx-1 rounded-md cursor-pointer hover:bg-text-100/5",onClick:r,children:[n?a.jsx(Vh,{className:"w-4 h-4 shrink-0 text-accent"}):a.jsx(jg,{className:"w-4 h-4 shrink-0 text-text-300"}),a.jsx("span",{className:"flex-1 min-w-0 truncate text-[13px] text-text-100",children:e.name}),b?a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button",title:"更多","data-testid":`project-more-${e.name}`,onClick:v=>v.stopPropagation(),className:h2,children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsxs(Pr,{align:"start",children:[d&&a.jsxs(Et,{"data-testid":`project-menu-pin-${e.name}`,onSelect:()=>d(e),children:[y?a.jsx(qb,{className:"w-3.5 h-3.5"}):a.jsx(Ig,{className:"w-3.5 h-3.5"}),y?"取消置顶":"置顶"]}),h&&a.jsxs(a.Fragment,{children:[a.jsx(ma,{}),a.jsxs(Et,{"data-testid":`project-menu-reveal-${e.name}`,onSelect:()=>h(e.path),children:[a.jsx(Vh,{className:"w-3.5 h-3.5"}),"在 Finder 中显示"]})]})]})]}):a.jsx("button",{type:"button",title:"更多","data-testid":`project-more-${e.name}`,onClick:v=>v.stopPropagation(),className:h2,children:a.jsx(ca,{className:"w-3.5 h-3.5"})}),c&&a.jsx("button",{type:"button",title:"在此项目中新建会话","data-testid":`project-new-${e.name}`,onClick:v=>{v.stopPropagation(),c(e.path)},className:h2,children:a.jsx(GH,{className:"w-3.5 h-3.5"})}),!n&&x>0&&a.jsx("span",{"data-testid":`project-unread-${e.name}`,className:ttt,children:a.jsx(xI,{})})]}),n&&a.jsxs(a.Fragment,{children:[g.map(v=>{const w=v.session,_=w.ownerPersonaId?(u==null?void 0:u(w.ownerPersonaId))??w.ownerPersonaId:null;return a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`project-session-row-${w.sessionId}`,className:`group flex items-center gap-1.5 pl-9 pr-2 py-[5px] mx-1 rounded-md cursor-pointer ${s===w.sessionId?"bg-text-100/10":"hover:bg-text-100/5"}`,onClick:()=>o(w.sessionId),children:[a.jsx("span",{className:"flex-1 min-w-0 truncate text-[13px] text-text-200",children:w.label??w.aiLabel??w.sessionId}),_&&a.jsxs("span",{className:"shrink-0 text-[11px] text-text-400 group-hover:hidden",children:["· ",_]}),a.jsx("span",{className:"hidden group-hover:flex items-center gap-0.5 shrink-0",children:a.jsx("button",{type:"button",title:"置顶","data-testid":`project-session-pin-${w.sessionId}`,onClick:S=>{S.stopPropagation(),l==null||l(w.sessionId,!0)},className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(Ig,{className:"w-3.5 h-3.5"})})}),i.has(w.sessionId)?a.jsx("span",{className:"shrink-0 group-hover:hidden",children:a.jsx(xI,{})}):null]}),a.jsx(Qee,{nodes:v.children,depth:0,activeId:s,unreadIds:i,onSelect:o})]},w.sessionId)}),t.length===0&&a.jsx("div",{"data-testid":`project-sessions-empty-${e.name}`,className:"pl-9 pr-2 py-1 text-[11px] text-text-400 italic",children:"还没有会话"}),!f&&t.length>bB&&a.jsxs("button",{type:"button","data-testid":`project-sessions-show-more-${e.name}`,onClick:()=>m(!0),className:"flex items-center gap-1 pl-9 py-1 text-[12px] text-text-400 hover:text-text-200 cursor-pointer",children:["展开显示 ",a.jsx(Qt,{className:"w-3 h-3"})]})]})]})}const ete={running:{cls:"text-blue-500",Icon:it,spin:!0,label:"进行中 · worker 正在跑"},"awaiting-review":{cls:"text-amber-500",Icon:afe,label:"待核验 · 已交付,等 Master 结论"},accepted:{cls:"text-emerald-500",Icon:Xt,label:"合格 · Master 判过"},failed:{cls:"text-red-500",Icon:In,label:"失败 · worker 回报没做成"}},ntt="还没交付 · worker 已停手";function tte(e){return e.rejectCount>0&&e.stage!=="accepted"}function rtt(e){const t=e.stage?ete[e.stage].label:ntt,n=tte(e)?`被打回过 ${e.rejectCount} 次`:"";return[t,n].filter(Boolean).join(" · ")}function stt({node:e}){const{progress:t}=e,n=tte(t),r=t.stage?ete[t.stage]:null;if(!r&&!n)return null;const s=r==null?void 0:r.Icon,i=rtt(t);return a.jsx(di,{delayDuration:200,children:a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:a.jsxs("span",{"data-testid":`line-progress-${e.sessionId}`,"data-stage":t.stage??"none",role:"img","aria-label":i,title:"",tabIndex:0,className:`inline-flex shrink-0 items-center gap-0.5 text-[11px] font-medium ${(r==null?void 0:r.cls)??""}`,children:[s?a.jsx(s,{className:`h-3.5 w-3.5 ${r!=null&&r.spin?"animate-spin":""}`}):null,n?a.jsxs("span",{className:"text-red-500",children:["×",t.rejectCount]}):null]})}),a.jsx(gi,{side:"bottom",children:i})]})})}function itt({node:e}){return e.ordinal===null?null:a.jsxs("span",{"data-testid":`line-ordinal-${e.sessionId}`,title:`线 ${e.ordinal}(${e.lineId})`,className:"shrink-0 tabular-nums text-[11px] text-text-400",children:["#",e.ordinal]})}function ott({node:e,active:t,onSelect:n}){return a.jsxs("div",{"data-testid":`topic-session-row-${e.sessionId}`,...t?{"aria-current":"true"}:{},title:`${e.lineId} · ${e.label}`,onClick:n,className:`group mx-1 flex cursor-pointer items-center gap-1.5 rounded-md py-[5px] pl-[46px] pr-2 ${t?"bg-text-100/10":"hover:bg-text-100/5"}`,children:[a.jsx(itt,{node:e}),a.jsx(stt,{node:e}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-text-200",children:e.label}),a.jsx("span",{className:"shrink-0 truncate text-[11px] text-text-400",children:e.assignee})]})}function att({title:e,onConfirm:t,onCancel:n}){return a.jsx("div",{role:"dialog","aria-modal":"true","data-testid":"topic-delete-confirm",className:"fixed inset-0 z-[10000] flex items-center justify-center bg-black/40",onClick:n,children:a.jsxs("div",{className:"w-[92%] max-w-sm rounded-lg border border-border bg-bg-0 p-4 shadow-xl",onClick:r=>r.stopPropagation(),children:[a.jsxs("div",{className:"flex items-start gap-2",children:[a.jsx(ws,{className:"mt-0.5 h-5 w-5 shrink-0 text-red-500"}),a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"text-[14px] text-text-100",children:["删除话题「",a.jsx("span",{className:"break-all font-medium",children:e}),"」?"]}),a.jsx("div",{className:"mt-1 text-[12px] leading-snug text-text-400",children:"这个话题名下的会话会一并删掉:Master 会话,以及它派出去的 worker 会话。"})]})]}),a.jsxs("div",{className:"mt-3 flex items-center justify-end gap-2",children:[a.jsx("button",{type:"button","data-testid":"topic-delete-confirm-cancel",onClick:n,className:"h-8 cursor-pointer rounded-md px-3 text-[12px] text-text-300 hover:bg-text-100/5",children:"取消"}),a.jsx("button",{type:"button","data-testid":"topic-delete-confirm-ok",onClick:t,className:"h-8 cursor-pointer rounded-md bg-red-500 px-3 text-[12px] font-medium text-white hover:opacity-90",children:"删除"})]})]})})}function nte({topic:e,expanded:t,activeSessionId:n,hasUnread:r,running:s,onToggle:i,onSelectTopic:o,onSelectSession:l,onArchiveTopic:c,onRenameTopic:u,onDeleteTopic:d,onPinTopic:h,variant:f="tree"}){const[m,g]=p.useState(!1),[x,b]=p.useState(!1),y=e.title,v=!!(u||h||d),w=()=>{o(),t||i()};return a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`topic-row-${e.topicId}`,...n===e.masterSessionId?{"aria-current":"true"}:{},title:y,onClick:w,...f==="pinned"?{style:{paddingLeft:Xee,gap:Zee}}:{},className:`group mx-1 flex cursor-pointer items-center rounded-md py-[5px] pr-2 ${f==="pinned"?"":"gap-1.5 pl-6"} ${n===e.masterSessionId?"bg-text-100/10":"hover:bg-text-100/5"}`,children:[f==="pinned"?a.jsx("button",{type:"button","aria-label":t?"收起话题":"展开话题","aria-expanded":t,"data-testid":`topic-toggle-${e.topicId}`,onClick:_=>{_.stopPropagation(),i()},className:"shrink-0 rounded hover:bg-text-100/10",children:a.jsx(AH,{"data-testid":`topic-hash-${e.topicId}`,className:`h-4 w-4 ${t?"text-accent":"text-text-300"}`})}):a.jsx("button",{type:"button","aria-label":t?"收起话题":"展开话题","aria-expanded":t,"data-testid":`topic-toggle-${e.topicId}`,onClick:_=>{_.stopPropagation(),i()},className:"shrink-0 rounded p-0.5 text-text-300 hover:bg-text-100/10 hover:text-text-100",children:t?a.jsx(Qt,{className:"h-3.5 w-3.5"}):a.jsx(tr,{className:"h-3.5 w-3.5"})}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-text-100",children:y}),a.jsx(Hee,{sessionId:e.masterSessionId,hasUnread:r,running:s}),(c||v)&&a.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 opacity-0 focus-within:opacity-100 group-hover:opacity-100 has-[[data-state=open]]:opacity-100",children:[c&&a.jsx("button",{type:"button","aria-label":`归档话题 ${y}`,title:"归档","data-testid":`topic-archive-${e.topicId}`,onClick:_=>{_.stopPropagation(),c(e.topicId)},className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(Iu,{className:"h-3.5 w-3.5"})}),v&&a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":`话题操作 ${y}`,"data-testid":`topic-menu-${e.topicId}`,onClick:_=>_.stopPropagation(),className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(ca,{className:"h-3.5 w-3.5"})})}),a.jsxs(Pr,{align:"end",onClick:_=>_.stopPropagation(),children:[u&&a.jsxs(Et,{"data-testid":`topic-rename-${e.topicId}`,onSelect:()=>g(!0),children:[a.jsx(Mu,{className:"mr-2 h-3 w-3 text-text-400"}),"重命名"]}),h&&a.jsxs(Et,{"data-testid":`topic-${e.pinned?"unpin":"pin"}-${e.topicId}`,onSelect:()=>h(e.topicId,!e.pinned),children:[e.pinned?a.jsx(qb,{className:"mr-2 h-3 w-3 text-text-400"}):a.jsx(Ig,{className:"mr-2 h-3 w-3 text-text-400"}),e.pinned?"取消置顶":"置顶"]}),d&&(u||h)&&a.jsx(ma,{}),d&&a.jsxs(Et,{"data-testid":`topic-delete-${e.topicId}`,onSelect:()=>b(!0),className:"text-destructive focus:bg-destructive/10 focus:text-destructive",children:[a.jsx(ws,{className:"mr-2 h-3 w-3"}),"删除"]})]})]})]})]}),u&&a.jsx(Uee,{open:m,initialLabel:y,title:"重命名话题",fieldLabel:"话题名",testId:"topic-rename-dialog",requireNonEmpty:!0,onSubmit:({label:_})=>{u(e.topicId,_),g(!1)},onCancel:()=>g(!1)}),d&&x&&a.jsx(att,{title:y,onConfirm:()=>{b(!1),d(e.topicId)},onCancel:()=>b(!1)}),t&&a.jsxs(a.Fragment,{children:[e.sessions.map(_=>a.jsx(ott,{node:_,active:n===_.sessionId,onSelect:()=>l(_.sessionId)},_.sessionId)),e.sessions.length===0&&a.jsx("div",{"data-testid":`topic-sessions-empty-${e.topicId}`,className:"py-1 pl-[46px] pr-2 text-[11px] italic text-text-400",children:"还没有派线"})]})]})}function rte({status:e}){return e===null?null:e==="running"?a.jsx(it,{"data-testid":"sidebar-status-running",className:"w-3 h-3 shrink-0 text-emerald-500 animate-spin"}):e==="awaiting"?a.jsx("span",{"data-testid":"sidebar-status-awaiting",className:"w-2 h-2 shrink-0 rounded-full bg-amber-400 animate-pulse"}):a.jsx("span",{"data-testid":"sidebar-status-unread",className:"w-2 h-2 shrink-0 rounded-full bg-blue-500"})}function ltt({title:e,testId:t,expanded:n,onToggle:r,aggregate:s=null,trailing:i}){return a.jsxs("div",{className:"group flex items-center gap-1 pl-3 pr-2 pt-3 pb-1 select-none","data-testid":t,children:[a.jsxs("button",{type:"button","data-testid":`${t}-toggle`,onClick:r,className:"flex items-center gap-1 text-[12px] text-text-400 hover:text-text-200",children:[e,a.jsx(tr,{className:`w-3 h-3 transition-transform ${n?"rotate-90":""}`})]}),!n&&a.jsx(rte,{status:s}),a.jsx("div",{className:"flex-1"}),a.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 focus-within:opacity-100 has-[[data-state=open]]:opacity-100",children:i})]})}function ctt(e){const{sortableId:t,...n}=e,{attributes:r,listeners:s,setNodeRef:i,transform:o,transition:l,isDragging:c}=jW({id:t});return a.jsx("div",{ref:i,style:{transform:Gh.Transform.toString(o),transition:l,opacity:c?.4:void 0},...r,...s,children:a.jsx(Zu,{...n})})}function utt({sessions:e,activeId:t,awaitingIds:n,runningIds:r,unreadIds:s,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,onReorderPins:d,ownerPrincipalId:h,getContactDisplayName:f,getCreatorDisplayName:m,getSessionDisplayName:g,expanded:x,onToggleExpanded:b,projectPaths:y,pinnedProjects:v=[],pinnedTopics:w=[],expandedTopicIds:_,onToggleTopic:S,onSelectTopic:k,onArchiveTopic:C,onRenameTopic:N,onDeleteTopic:T,onPinTopic:E,expandedProjectPaths:R,onToggleProject:O,onNewInProject:P,getPersonaDisplayName:$,onTogglePinProject:F,onRevealProject:B}){const W=p.useMemo(()=>e.filter(se=>lS(se,h)),[e,h]),L=p.useMemo(()=>Sc(W),[W]),D=p.useMemo(()=>new Set(L.map(se=>se.session.sessionId)),[L]),I=p.useMemo(()=>L.filter(se=>typeof se.session.pinnedAt=="number"),[L]),V=p.useMemo(()=>W.filter(se=>typeof se.pinnedAt=="number"&&!D.has(se.sessionId)).map(se=>({session:se,children:[]})),[W,D]),H=p.useMemo(()=>I.filter(se=>!se.session.originOwnerPrincipalId).map(se=>se.session.sessionId),[I]),[M,Y]=p.useState(null);p.useEffect(()=>{if(M==null)return;if(!(M.length===H.length&&M.every(Z=>H.includes(Z)))){Y(null);return}M.every((Z,fe)=>Z===H[fe])&&Y(null)},[H,M]);const X=M??H,K=p.useMemo(()=>{const se=new Map,ae=[];for(const fe of I)fe.session.originOwnerPrincipalId?ae.push(fe):se.set(fe.session.sessionId,fe);return[...X.map(fe=>se.get(fe)).filter(fe=>!!fe),...ae,...V]},[I,X,V]),te=oW(iW(qw,{activationConstraint:{distance:4}})),ce=se=>{if(!d)return;const{active:ae,over:Z}=se;if(!Z||ae.id===Z.id)return;const fe=X.indexOf(String(ae.id)),ve=X.indexOf(String(Z.id));if(fe<0||ve<0)return;const Te=AT(X,fe,ve);Y(Te),d(Te)},J=p.useMemo(()=>[...v].sort((se,ae)=>(se.pinnedAt??0)-(ae.pinnedAt??0)),[v]),de=p.useMemo(()=>J.length>0?zee(e,h,y??[]):new Map,[J,e,h,y]);if(K.length===0&&J.length===0&&w.length===0)return null;const we=se=>({node:se,depth:0,activeId:t,unreadIds:s,runningIds:r,awaitingIds:n,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,getContactDisplayName:f,getCreatorDisplayName:m,getSessionDisplayName:g,ownerPrincipalId:h});return a.jsxs(a.Fragment,{children:[a.jsx(ltt,{title:"置顶",testId:"sidebar-section-pinned-header",expanded:x,onToggle:b,aggregate:x?null:x3([...K,...J.flatMap(se=>de.get(se.path)??[])],{awaitingIds:n,unreadIds:s,runningIds:r})}),x&&a.jsxs("div",{"data-testid":"sidebar-section-pinned",className:"flex flex-col px-1",children:[d?a.jsx("div",{"data-testid":"pinned-dnd-context",children:a.jsx(wW,{sensors:te,collisionDetection:aW,onDragEnd:ce,children:a.jsx(CW,{items:X,strategy:T0e,children:K.map(se=>se.session.originOwnerPrincipalId||!H.includes(se.session.sessionId)?a.jsx(Zu,{...we(se)},se.session.sessionId):a.jsx(ctt,{sortableId:se.session.sessionId,...we(se)},se.session.sessionId))})})}):a.jsx("div",{"data-testid":"pinned-static-list",children:K.map(se=>a.jsx(Zu,{...we(se)},se.session.sessionId))}),J.map(se=>a.jsx(Jee,{project:se,nodes:de.get(se.path)??[],expanded:(R==null?void 0:R.has(se.path))??!1,onToggle:()=>O==null?void 0:O(se.path),activeId:t,unreadIds:s,onSelect:i,onPin:c,onNewInProject:P,getPersonaDisplayName:$,onTogglePinProject:F,onRevealProject:B},se.path)),w.map(se=>a.jsx(nte,{variant:"pinned",topic:se,expanded:(_==null?void 0:_.has(se.topicId))??!1,activeSessionId:t,hasUnread:s.has(se.masterSessionId),running:r.has(se.masterSessionId),onToggle:()=>S==null?void 0:S(se.topicId),onSelectTopic:()=>k==null?void 0:k(se.topicId,se.masterSessionId),onSelectSession:ae=>i(ae),...C?{onArchiveTopic:C}:{},...N?{onRenameTopic:N}:{},...T?{onDeleteTopic:T}:{},...E?{onPinTopic:E}:{}},se.topicId))]})]})}const wB=5;function dtt({sessions:e,activeId:t,unreadIds:n,onSelect:r,onPin:s,ownerPrincipalId:i,projectPaths:o,projects:l,expandedPaths:c,onToggleProject:u,onNewInProject:d,onRefresh:h,onCreateProject:f,getPersonaDisplayName:m,onTogglePinProject:g,onRevealProject:x}){const[b,y]=p.useState(!1),v=p.useMemo(()=>o??l.map(C=>C.path),[o,l]),w=p.useMemo(()=>zee(e,i,v),[e,i,v]),_=p.useMemo(()=>l.filter(C=>C.pinnedAt==null),[l]),S=!!(h||f);if(l.length===0&&!S)return null;const k=b?_:_.slice(0,wB);return a.jsxs("div",{"data-testid":"sidebar-section-projects",children:[a.jsxs("div",{className:"group flex items-center gap-1 pl-3 pr-2 pt-3 pb-1 select-none",children:[a.jsx("span",{className:"text-[12px] text-text-400",children:"项目"}),a.jsx("div",{className:"flex-1"}),(h||f)&&a.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 focus-within:opacity-100 has-[[data-state=open]]:opacity-100",children:a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"projects actions","data-testid":"projects-section-menu",className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsxs(Pr,{align:"start",children:[h&&a.jsxs(Et,{"data-testid":"projects-refresh",onSelect:()=>h(),children:[a.jsx(No,{className:"w-3.5 h-3.5"}),"刷新"]}),f&&a.jsxs(Et,{"data-testid":"projects-new",onSelect:()=>f(),children:[a.jsx(bs,{className:"w-3.5 h-3.5"}),"新建项目…"]})]})]})})]}),l.length===0&&a.jsx("div",{"data-testid":"projects-empty",className:"pl-3 pr-2 py-1 text-[11px] text-text-400 italic select-none",children:"还没有项目"}),k.map(C=>a.jsx(Jee,{project:C,nodes:w.get(C.path)??[],expanded:c.has(C.path),onToggle:()=>u(C.path),activeId:t,unreadIds:n,onSelect:r,onPin:s,onNewInProject:d,getPersonaDisplayName:m,onTogglePinProject:g,onRevealProject:x},C.path)),!b&&_.length>wB&&a.jsxs("button",{type:"button","data-testid":"projects-show-more",onClick:()=>y(!0),className:"flex items-center gap-1 pl-3 py-1 text-[12px] text-text-400 hover:text-text-200 cursor-pointer",children:["展开显示 ",a.jsx(Qt,{className:"w-3 h-3"})]})]})}const _B=new Set;function htt({tree:e,expandedTopicIds:t,collapsedChannelIds:n,activeSessionId:r,onToggleTopic:s,onToggleChannel:i,onSelectTopic:o,onSelectSession:l,onCreateChannel:c,onCreateTopic:u,onEditChannel:d,onDeleteChannel:h,channelError:f,onArchiveTopic:m,onRenameTopic:g,onDeleteTopic:x,onPinTopic:b,unreadIds:y=_B,runningIds:v=_B}){return a.jsxs("div",{"data-testid":"sidebar-section-channels",children:[a.jsxs("div",{className:"group flex select-none items-center gap-1 pb-1 pl-3 pr-2 pt-3",children:[a.jsx("span",{className:"text-[12px] text-text-400",children:"频道"}),a.jsx("div",{className:"flex-1"}),a.jsx("div",{className:"flex items-center gap-0.5 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:a.jsx("button",{type:"button","aria-label":"新建频道","data-testid":"channels-new",onClick:c,className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(bs,{className:"h-3.5 w-3.5"})})})]}),e.length===0&&a.jsx("div",{"data-testid":"channels-empty",className:"select-none py-1 pl-3 pr-2 text-[11px] italic text-text-400",children:"还没有频道"}),e.map(w=>a.jsxs("div",{children:[a.jsxs("div",{"data-testid":`channel-row-${w.channelId}`,title:w.name,role:"button",tabIndex:0,"aria-expanded":!n.has(w.channelId),onClick:()=>i(w.channelId),onKeyDown:_=>{_.key!=="Enter"&&_.key!==" "||(_.preventDefault(),i(w.channelId))},className:"group mx-1 flex cursor-pointer items-center gap-2.5 rounded-md px-3 py-[5px] text-text-100 hover:bg-text-100/5",children:[a.jsx("span",{className:`inline-flex h-4 w-4 shrink-0 items-center justify-center ${n.has(w.channelId)?"text-text-300":"text-accent"}`,children:a.jsx(AH,{className:"h-4 w-4"})}),a.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px]",children:w.name}),a.jsxs("span",{className:"hidden shrink-0 items-center gap-0.5 group-hover:flex",children:[a.jsx("button",{type:"button","aria-label":"新建话题",title:`在「${w.name}」下新建话题`,"data-testid":`channel-create-topic-${w.channelId}`,onClick:_=>{_.stopPropagation(),u(w.channelId)},className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(bs,{className:"h-3.5 w-3.5"})}),a.jsx("button",{type:"button","aria-label":`编辑频道 ${w.name}`,"data-testid":`channel-edit-${w.channelId}`,onClick:_=>{_.stopPropagation(),d(w.channelId)},className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-text-100",children:a.jsx(Mu,{className:"h-3.5 w-3.5"})}),a.jsx("button",{type:"button","aria-label":`删除频道 ${w.name}`,"data-testid":`channel-delete-${w.channelId}`,onClick:_=>{_.stopPropagation(),h(w.channelId)},className:"rounded p-0.5 text-text-400 hover:bg-text-100/10 hover:text-red-500",children:a.jsx(ws,{className:"h-3.5 w-3.5"})})]})]}),(f==null?void 0:f.channelId)===w.channelId&&a.jsx("div",{"data-testid":`channel-error-${w.channelId}`,role:"alert",className:"py-1 pl-11 pr-2 text-[11px] leading-snug text-red-500",children:f.message}),!n.has(w.channelId)&&a.jsxs(a.Fragment,{children:[w.topics.map(_=>a.jsx(nte,{topic:_,expanded:t.has(_.topicId),activeSessionId:r,hasUnread:y.has(_.masterSessionId),running:v.has(_.masterSessionId),onToggle:()=>s(_.topicId),onSelectTopic:()=>o(_.topicId,_.masterSessionId),onSelectSession:l,...m?{onArchiveTopic:m}:{},...g?{onRenameTopic:g}:{},...x?{onDeleteTopic:x}:{},...b?{onPinTopic:b}:{}},_.topicId)),w.topics.length===0&&a.jsx("div",{"data-testid":`channel-topics-empty-${w.channelId}`,className:"select-none py-1 pl-6 pr-2 text-[11px] italic text-text-400",children:"还没有话题"})]})]},w.channelId))]})}const ftt=[10,25,50],ptt="clawd:recents:sort",mtt=[["priority","优先级"],["recency","最近更新"]],gtt="clawd:recents:quick-action",SB=[["pin","置顶"],["archive","归档"],["rename","重命名"]];function xtt({sessions:e,activeId:t,awaitingIds:n,runningIds:r,unreadIds:s,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,ownerPrincipalId:d,getContactDisplayName:h,getCreatorDisplayName:f,getSessionDisplayName:m,projectPaths:g,topicSessionIds:x,bulkArchiveHintCount:b,onDismissBulkHint:y,onBulkArchive:v,bulkArchiveAvailable:w,sortMode:_="priority",onChangeSortMode:S,quickAction:k,onChangeQuickAction:C}){var O;const N=p.useMemo(()=>dS(e,d,g,x),[e,d,g,x]),T=p.useMemo(()=>Sc(N),[N]),E=((O=SB.find(([P])=>P===k))==null?void 0:O[0])??"archive",R=p.useMemo(()=>(_==="recency"?uS(T):Fee(T,{awaitingIds:n,runningIds:r,unreadIds:s})).filter($=>$.session.pinnedAt==null),[T,_,n,r,s]);return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"group flex items-center gap-1 pl-3 pr-2 pt-3 pb-1 select-none",children:[a.jsx("span",{className:"text-[12px] text-text-400",children:"最近"}),a.jsx("div",{className:"flex-1"}),a.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 focus-within:opacity-100 has-[[data-state=open]]:opacity-100",children:a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"recents actions","data-testid":"recents-section-menu",className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsxs(Pr,{align:"start",children:[v&&a.jsxs(a.Fragment,{children:[a.jsx(uc,{children:"批量归档"}),ftt.map(P=>a.jsxs(Et,{"data-testid":`recents-bulk-archive-${P}`,disabled:w?!w(P):!1,onSelect:()=>v(P),children:["只保留最近 ",P," 个"]},P)),a.jsx(ma,{})]}),a.jsx(uc,{children:"聊天排序方式"}),mtt.map(([P,$])=>a.jsxs(Et,{"data-testid":`recents-sort-${P}`,onSelect:()=>S==null?void 0:S(P),children:[a.jsx(Xt,{className:ee("w-3.5 h-3.5 mr-2",_===P?"":"invisible")}),$]},P)),a.jsx(ma,{}),a.jsx(uc,{children:"行内快捷操作"}),SB.map(([P,$])=>a.jsxs(Et,{"data-testid":`recents-quick-action-${P}`,onSelect:()=>C==null?void 0:C(P),children:[a.jsx(Xt,{className:ee("w-3.5 h-3.5 mr-2",E===P?"":"invisible")}),$]},P))]})]})})]}),b!=null&&v&&a.jsxs("div",{"data-testid":"recents-bulk-hint",className:"mx-2 mb-1 px-3 py-2 rounded-md bg-bg-50 border border-border text-[12px] text-text-300",children:["最近会话较多,只保留最近 10 个,其余归档?",a.jsxs("div",{className:"mt-1.5 flex gap-2",children:[a.jsxs("button",{type:"button","data-testid":"recents-bulk-hint-accept",onClick:()=>v(10),className:"px-2 py-0.5 rounded bg-accent text-white text-[11px]",children:["归档 ",b," 个"]}),a.jsx("button",{type:"button","data-testid":"recents-bulk-hint-dismiss",onClick:y,className:"px-2 py-0.5 rounded bg-bg-200 text-text-200 text-[11px]",children:"忽略"})]})]}),a.jsx("div",{"data-testid":"sidebar-section-recents",className:"flex flex-col px-1",children:R.length===0?a.jsx("div",{"data-testid":"sidebar-section-recents-empty",className:"px-3 py-2 text-[11px] text-text-400 italic",children:"还没有会话"}):R.map(P=>a.jsx(Zu,{node:P,depth:0,activeId:t,unreadIds:s,runningIds:r,awaitingIds:n,onSelect:i,onEdit:o,onDelete:l,onPin:c,onArchive:u,quickAction:E,getContactDisplayName:h,getCreatorDisplayName:f,getSessionDisplayName:m,ownerPrincipalId:d},P.session.sessionId))})]})}const vtt="clawd:sidebar:section:pinned",kB=new Set;function zd({kind:e,icon:t,label:n,active:r,trailing:s,onClick:i}){return a.jsxs("div",{"data-testid":`sidebar-entry-${e}`,className:`group flex items-center gap-2.5 px-3 py-[5px] mx-1 rounded-md cursor-pointer text-text-100 ${r?"bg-text-100/10":"hover:bg-text-100/5"}`,onClick:i,children:[a.jsx("span",{className:"w-4 h-4 shrink-0 text-text-300 inline-flex items-center justify-center",children:t}),a.jsx("span",{className:"flex-1 text-[13px]",children:n}),s]})}function ytt(e){const{onNewPersona:t,onReorderPins:n,onFixedEntryClick:r,activeEntry:s,peopleUnreadCount:i,channelTree:o,expandedTopicIds:l,onToggleTopic:c,onSelectTopic:u,onCreateChannel:d,onCreateTopic:h,onEditChannel:f,onDeleteChannel:m,channelError:g,onArchiveTopic:x,onRenameTopic:b,onDeleteTopic:y,onPinTopic:v,pinnedTopics:w,topicSessionIds:_,footer:S,width:k=288,onResizeStart:C,floating:N=!1,onCollapse:T,onOpenSearch:E,onOpenHive:R,projects:O=[],onNewInProject:P,onRefreshProjects:$,onCreateProject:F,getPersonaDisplayName:B,onPatchProject:W,onRevealProject:L,...D}=e,[I,V]=ym(vtt,!0),H=p.useMemo(()=>O.map(J=>J.path),[O]),{expandedPaths:M,toggleProject:Y}=Oet(),{collapsedChannelIds:X,toggleChannel:K}=$et(),te=p.useMemo(()=>O.filter(J=>J.pinnedAt!=null),[O]),ce=W?{onTogglePinProject:J=>W(J.path,{pinnedAt:J.pinnedAt!=null?null:Date.now()}),...L?{onRevealProject:L}:{}}:{};return a.jsxs("div",{"data-testid":"app-sidebar-nav",className:`relative flex flex-col h-full shrink-0 bg-bg-50/60 ${N?"border border-border rounded-xl overflow-hidden":"border-r border-border-strong"}`,style:{width:k},children:[C&&a.jsx("div",{"data-testid":"sidebar-resize-handle",onPointerDown:C,className:"absolute right-0 top-0 h-full w-1 z-10 cursor-col-resize hover:bg-accent/40 active:bg-accent/60"}),a.jsxs("div",{className:"flex items-center px-4 pt-3 pb-2 shrink-0",children:[a.jsx("div",{className:"flex-1 text-[15px] font-semibold text-text-100",children:"clawd"}),R&&a.jsx("button",{type:"button","aria-label":"Hive 看板",title:"Hive 看板 ⌘⇧H","data-testid":"sidebar-hive",onClick:R,className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(vfe,{className:"w-4 h-4"})}),a.jsx("button",{type:"button","aria-label":"搜索",title:"搜索 ⌘K","data-testid":"sidebar-search",onClick:E,className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(ui,{className:"w-4 h-4"})}),a.jsx("button",{type:"button","aria-label":"collapse sidebar","data-testid":"sidebar-collapse",onClick:T,className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(WH,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto pb-2",children:[a.jsxs("div",{className:"flex flex-col gap-px pb-1",children:[a.jsx(zd,{kind:"new",icon:a.jsx(GH,{className:"w-4 h-4"}),label:"新对话",active:s==="new",onClick:()=>r("new")}),a.jsx(zd,{kind:"persona",icon:a.jsx(ra,{className:"w-4 h-4"}),label:"persona",active:s==="persona",onClick:()=>r("persona"),trailing:a.jsxs(Gr,{modal:!1,children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"persona actions","data-testid":"sidebar-persona-menu",onClick:J=>J.stopPropagation(),className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10 opacity-0 group-hover:opacity-100 focus:opacity-100 data-[state=open]:opacity-100",children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsx(Pr,{align:"end",onClick:J=>J.stopPropagation(),children:a.jsxs(Et,{"data-testid":"sidebar-persona-new",onSelect:t,children:[a.jsx(bs,{className:"w-3.5 h-3.5 mr-2"}),"新建 persona"]})})]})}),a.jsx(zd,{kind:"people",icon:a.jsx(fT,{className:"w-4 h-4"}),label:"联系人",active:s==="people",onClick:()=>r("people"),trailing:a.jsx(a.Fragment,{children:i>0&&a.jsx("span",{"data-testid":"sidebar-people-unread",className:"shrink-0 min-w-4 h-4 px-1 inline-flex items-center justify-center rounded-full bg-blue-500 text-white text-[10px] leading-none",children:i})})}),a.jsx(zd,{kind:"prs",icon:a.jsx(cT,{className:"w-4 h-4"}),label:"Pull Request",active:s==="prs",onClick:()=>r("prs")}),a.jsx(zd,{kind:"shift",icon:a.jsx(ihe,{className:"w-4 h-4"}),label:"已安排",active:s==="shift",onClick:()=>r("shift")}),a.jsx(zd,{kind:"exts",icon:a.jsx(ape,{className:"w-4 h-4"}),label:"插件",active:s==="exts",onClick:()=>r("exts")})]}),a.jsx(utt,{...D,expanded:I,onToggleExpanded:()=>V(!I),onReorderPins:n,projectPaths:H,pinnedProjects:te,expandedProjectPaths:M,onToggleProject:Y,onNewInProject:P,getPersonaDisplayName:B,...ce,pinnedTopics:w,expandedTopicIds:l??kB,...c?{onToggleTopic:c}:{},...u?{onSelectTopic:u}:{},...x?{onArchiveTopic:x}:{},...b?{onRenameTopic:b}:{},...y?{onDeleteTopic:y}:{},...v?{onPinTopic:v}:{}}),P&&a.jsx(dtt,{...D,projectPaths:H,projects:O,expandedPaths:M,onToggleProject:Y,onNewInProject:P,onRefresh:$,onCreateProject:F,getPersonaDisplayName:B,...ce}),c&&u&&d&&h&&f&&m&&a.jsx(htt,{tree:o??[],expandedTopicIds:l??kB,collapsedChannelIds:X,activeSessionId:D.activeId,onToggleTopic:c,onToggleChannel:K,onSelectTopic:u,onSelectSession:D.onSelect,onCreateChannel:d,onCreateTopic:h,onEditChannel:f,onDeleteChannel:m,channelError:g??null,unreadIds:D.unreadIds,runningIds:D.runningIds,...x?{onArchiveTopic:x}:{},...b?{onRenameTopic:b}:{},...y?{onDeleteTopic:y}:{},...v?{onPinTopic:v}:{}}),a.jsx(xtt,{...D,projectPaths:H,..._?{topicSessionIds:_}:{}})]}),S&&a.jsx("div",{className:"shrink-0 border-t border-border-strong",children:S})]})}const W1={online:0,offline:1},btt=new Set;function CB(e,t){if(e.pinnedAt!=null||t.pinnedAt!=null)return e.pinnedAt==null?1:t.pinnedAt==null?-1:t.pinnedAt-e.pinnedAt;if(e.hasUnread!==t.hasUnread)return e.hasUnread?-1:1;const n=W1[e.presence],r=W1[t.presence];return n!==r?n-r:e.displayName.localeCompare(t.displayName)}function y3(e,t,n=[],r=btt){const s=new Map;for(const c of e){const u=`${c.provider}:${c.ownerId}`,d=s.get(u);d?d.push(c):s.set(u,[c])}const i=[...s.entries()].map(([c,u])=>{const d=[...u].sort((f,m)=>{const g=r.has(f.deviceId),x=r.has(m.deviceId);if(g!==x)return g?-1:1;const b=W1[t.get(f.deviceId)??"offline"],y=W1[t.get(m.deviceId)??"offline"];return b!==y?b-y:f.deviceId.localeCompare(m.deviceId)}),h=d.map(f=>f.pinnedAt).filter(f=>f!=null);return{key:c,displayName:d[0].displayName||d[0].deviceId,devices:d,presence:d.some(f=>t.get(f.deviceId)==="online")?"online":"offline",pinnedAt:h.length>0?Math.max(...h):null,hasUnread:d.some(f=>r.has(f.deviceId)),disconnected:!1}}),o=new Set(e.map(c=>c.deviceId)),l=n.filter(c=>!c.devices.some(u=>o.has(u.deviceId))).map(c=>({key:c.unionId,displayName:c.displayName||c.unionId,devices:[],presence:"offline",pinnedAt:null,hasUnread:!1,disconnected:!0})).sort((c,u)=>c.displayName.localeCompare(u.displayName));return{pinned:i.filter(c=>c.pinnedAt!=null).sort(CB),main:i.filter(c=>c.pinnedAt==null).sort(CB),disconnected:l}}function wtt({device:e,onConnect:t}){const[n,r]=p.useState(!1),[s,i]=p.useState(null);return a.jsxs("div",{"data-testid":`people-public-device-${e.deviceId}`,className:"group flex flex-col px-2 py-1.5 rounded-md hover:bg-text-100/5",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-200/60 text-text-300",children:a.jsx(fT,{className:"w-3.5 h-3.5"})}),a.jsx("span",{className:"flex-1 truncate text-[12.5px] text-text-200",children:e.name}),t&&a.jsx("button",{type:"button",disabled:n,className:"px-2 py-0.5 rounded border border-border hover:bg-text-100/5 text-[11px] text-text-400 opacity-0 group-hover:opacity-100 disabled:opacity-100 disabled:cursor-default",onClick:()=>{r(!0),i(null),t({deviceId:e.deviceId,url:e.url,name:e.name}).catch(o=>i(o instanceof Error?o.message:String(o))).finally(()=>r(!1))},children:n?"连接中…":"连接"})]}),s&&a.jsx("div",{"data-testid":`people-public-device-${e.deviceId}-error`,className:"pl-8 pt-0.5 text-[11px] text-red-500 truncate",children:s})]})}function _tt({presence:e}){return a.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2 h-2 rounded-full ring-2 ring-bg-100 ${e==="online"?"bg-emerald-400":"bg-slate-400"}`})}function Stt({person:e,selectedDeviceId:t,onSelect:n,onHover:r,onHoverEnd:s}){if(e.disconnected)return a.jsxs("div",{"data-testid":`people-list-placeholder-${e.key}`,className:"flex items-center gap-2 px-2 py-1.5 rounded-md opacity-55",title:"同组成员,还没连上——对方启动 clawd 后会自动出现",children:[a.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-200/40 text-text-400 shrink-0",children:a.jsx(qh,{className:"w-3.5 h-3.5"})}),a.jsx("span",{className:"flex-1 truncate text-[13px] text-text-400",children:e.displayName}),a.jsx("span",{className:"shrink-0 text-[10px] text-text-500",children:"未连接"})]});const i=e.devices[0],o=e.devices.some(l=>l.deviceId===t);return a.jsxs("div",{"data-testid":`people-list-row-${i.deviceId}`,className:`flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer ${o?"bg-text-100/10":"hover:bg-text-100/5"}`,onClick:()=>n(i.deviceId),onMouseEnter:r?()=>r(i.deviceId):void 0,onMouseLeave:s,children:[a.jsxs("span",{className:"relative shrink-0",children:[a.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-200/60 text-text-300",children:a.jsx(qh,{className:"w-3.5 h-3.5"})}),a.jsx(_tt,{presence:e.presence})]}),a.jsx("span",{className:"flex-1 truncate text-[13px] text-text-100",children:e.displayName}),e.devices.length>1&&a.jsxs("span",{"data-testid":`people-list-row-${i.deviceId}-device-count`,className:"shrink-0 text-[10px] text-text-500 tabular-nums",title:`${e.devices.length} 台设备(在卡片里看)`,children:[e.devices.length," 台"]}),e.hasUnread&&a.jsx("span",{"data-testid":`people-list-row-${i.deviceId}-unread`,"aria-label":"unread",className:"w-2 h-2 rounded-full bg-error shrink-0"}),a.jsx(tr,{"aria-hidden":"true","data-testid":`people-list-row-${i.deviceId}-more`,className:`w-3.5 h-3.5 shrink-0 transition-colors ${o?"text-text-300":"text-text-500/60"}`})]})}function ktt({contacts:e,presenceByDeviceId:t,selectedDeviceId:n,onSelect:r,onHover:s,onHoverEnd:i,publicDevices:o,onConnectPublicDevice:l,visitors:c=[],visitorUnreadIds:u,onOpenVisitor:d,orgMeshProgress:h,orgPeers:f,unreadDeviceIds:m}){const{pinned:g,main:x,disconnected:b}=y3(e,t,f,m),y=w=>a.jsx(Stt,{person:w,selectedDeviceId:n,onSelect:r,onHover:s,onHoverEnd:i},w.key),v=g.length===0&&x.length===0&&b.length===0;return a.jsxs("div",{className:"w-[248px] shrink-0 h-full border-r border-border overflow-y-auto px-2 py-3",children:[a.jsx("div",{className:"px-2 pb-2",children:a.jsx("span",{className:"text-[14px] font-semibold text-text-100",children:"联系人"})}),h&&a.jsxs("div",{className:"px-2 pb-2","data-testid":"people-org-mesh-progress",children:[a.jsxs("div",{className:"flex items-center justify-between text-[11px] text-text-400",children:[a.jsx("span",{children:"正在连接同事…"}),a.jsxs("span",{className:"tabular-nums",children:[h.done,"/",h.total]})]}),a.jsx("div",{className:"mt-1 h-0.5 w-full overflow-hidden rounded-full bg-text-100/10",children:a.jsx("div",{className:"h-full bg-text-400/60 transition-[width] duration-300",style:{width:`${h.total>0?Math.round(h.done/h.total*100):0}%`}})}),h.failed>0&&a.jsxs("div",{className:"mt-0.5 text-[10px] text-text-500",children:[h.failed," 台没连上(对方不在线,之后会自动补上)"]})]}),g.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"flex flex-col gap-px","data-testid":"people-list-pinned",children:g.map(y)}),a.jsx("div",{className:"mx-2 my-2 border-t border-border","data-testid":"people-list-pinned-divider"})]}),a.jsxs("div",{className:"flex flex-col gap-px",children:[x.map(y),b.map(y),v&&a.jsx("div",{className:"px-2 py-2 text-[12px] text-text-400 italic",children:"还没有联系人"})]}),c.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"px-2 pt-4 pb-1 text-[11px] text-text-400",children:"访客"}),a.jsx("div",{className:"flex flex-col gap-px",children:c.map(w=>a.jsxs("div",{role:"button",tabIndex:0,"data-testid":`people-visitor-row-${w.deviceId}`,className:"flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer hover:bg-text-100/5",onClick:()=>d==null?void 0:d(w.deviceId),onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),d==null||d(w.deviceId))},children:[a.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-slate-200/60 text-text-300 shrink-0",children:a.jsx(qh,{className:"w-3.5 h-3.5"})}),a.jsx("span",{className:"flex-1 truncate text-[13px] text-text-100",children:w.displayName||w.deviceId}),(u==null?void 0:u.has(w.deviceId))&&a.jsx("span",{"data-testid":`people-visitor-unread-${w.deviceId}`,className:"w-2 h-2 rounded-full bg-error shrink-0"})]},w.deviceId))})]}),o.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"px-2 pt-4 pb-1 text-[11px] text-text-400",children:"公共设备"}),a.jsx("div",{className:"flex flex-col gap-px",children:o.map(w=>a.jsx(wtt,{device:w,onConnect:l},w.deviceId))})]})]})}function Ctt({items:e,onInstall:t,onOpen:n}){return a.jsxs("div",{"data-testid":"person-extensions-list",className:"flex flex-col",children:[a.jsxs("header",{className:"flex items-center gap-1 pl-2 py-1 text-[10px] uppercase tracking-wider text-text-400",children:[a.jsx(Pw,{className:"w-3 h-3"}),"Extensions",a.jsx("span",{className:"ml-auto pr-2 text-[10px] tabular-nums",children:e.length})]}),a.jsx("ul",{className:"flex flex-col",children:e.map(r=>a.jsx(Ntt,{item:r,onInstall:t,onOpen:n},r.extId))})]})}function Ntt({item:e,onInstall:t,onOpen:n}){const s=e.state.kind==="installed-up-to-date"||e.state.kind==="installed-with-update";return a.jsxs("li",{"data-testid":"person-extension-row","data-ext-id":e.extId,"data-state":e.state.kind,role:s?"button":void 0,tabIndex:s?0:-1,onClick:s?()=>n==null?void 0:n(e.extId):void 0,className:ee("group flex items-center gap-1.5 px-2 py-1.5 rounded",s&&"cursor-pointer hover:bg-text-100/5"),children:[a.jsx(Pw,{className:"h-3.5 w-3.5 shrink-0 text-text-400","aria-hidden":!0}),a.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-1.5",children:[a.jsx("span",{className:"truncate text-[13px] text-text-100",children:e.name}),a.jsxs("span",{className:"shrink-0 text-[10px] text-text-400 tabular-nums",children:["v",e.publishedVersion]})]}),a.jsx(jtt,{item:e,onInstall:t})]})}function jtt({item:e,onInstall:t}){const n=e.state;return n.kind==="not-installed"?a.jsxs("button",{type:"button",onClick:r=>{r.stopPropagation(),t==null||t(e.extId)},"data-testid":"install-button",className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] font-medium bg-accent/10 hover:bg-accent/20 text-accent border border-accent/30 transition-colors",children:[a.jsx(OH,{className:"w-2.5 h-2.5"}),"安装"]}):n.kind==="installing"?a.jsxs("span",{"data-testid":"installing-indicator",className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] text-text-400 bg-bg-100 border border-border",children:[a.jsx(it,{className:"w-2.5 h-2.5 animate-spin"}),"装中"]}):n.kind==="installed-up-to-date"?a.jsxs("span",{"data-testid":"installed-chip",className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] text-success border border-success/30 bg-success/5",children:[a.jsx(ci,{className:"w-2.5 h-2.5"}),"已装"]}):n.kind==="installed-with-update"?a.jsxs("span",{"data-testid":"update-available-chip",className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] text-warning border border-warning/30 bg-warning/5",children:[a.jsx(RH,{className:"w-2.5 h-2.5"}),"有新版"]}):n.kind==="install-failed"?a.jsxs("span",{"data-testid":"install-failed-chip",title:n.reason,className:"shrink-0 inline-flex items-center gap-1 px-1.5 h-5 rounded-sm text-[10px] text-error border border-error/30 bg-error/5",children:[a.jsx(In,{className:"w-2.5 h-2.5"}),"失败"]}):null}function vI({starred:e,onToggle:t,testid:n,revealClass:r="group-hover:opacity-100"}){return a.jsx("button",{type:"button","data-testid":n,title:e?"取消收藏":"收藏","aria-label":e?"取消收藏":"收藏","aria-pressed":e,onClick:s=>{s.stopPropagation(),t()},className:`p-0.5 rounded shrink-0 hover:bg-text-100/10 ${e?"text-amber-500":`text-text-400 opacity-0 ${r} focus-visible:opacity-100`}`,children:a.jsx(cj,{className:"w-3.5 h-3.5",fill:e?"currentColor":"none"})})}function Jp({children:e,first:t}){return a.jsx("div",{className:`px-3 ${t?"pt-3":"pt-4"} pb-2 text-[12px] text-text-400`,children:e})}function Ett({personas:e,rootsByPersonaId:t,sets:n,selectedPersonaId:r,onHoverPersona:s,onSelectPersona:i,onNewPersona:o,favorites:l}){const c=(l==null?void 0:l.filter)==="starred",u=c?e.filter(b=>l.isFavorite(b.personaId)):e,d=u.filter(b=>!b.cloud),h=u.filter(b=>b.cloud),f=new Set(e.flatMap(b=>b.cloud?[b.cloud.personaId]:[])),m=l?e.filter(b=>l.isFavorite(b.personaId)).length+l.contactFavorites.length:0,g=b=>{var w;const y=t.get(b.personaId)??[],v=!b.cloud&&f.has(b.personaId);return a.jsxs("div",{"data-testid":`persona-list-row-${b.personaId}`,onMouseEnter:()=>s(b.personaId),onMouseLeave:()=>s(null),onClick:()=>i(b.personaId),className:`group flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer ${r===b.personaId?"bg-text-100/10":"hover:bg-text-100/5"}`,children:[a.jsx(rf,{tool:b.tool,className:`w-4 h-4 shrink-0 ${nf(b.tool)}`}),(w=b.cloud)!=null&&w.label&&b.cloud.label!==b.label?a.jsxs("span",{className:"flex-1 min-w-0 flex flex-col leading-tight",children:[a.jsx("span",{className:"truncate text-[13px] text-text-100",children:b.label}),a.jsx("span",{"data-testid":`persona-list-subtitle-${b.personaId}`,className:"truncate text-[11px] text-text-400",children:b.cloud.label})]}):a.jsx("span",{className:"flex-1 truncate text-[13px] text-text-100",children:b.label}),v&&a.jsx("span",{"data-testid":`persona-list-cloud-mark-${b.personaId}`,title:"已上云","aria-label":"已上云",className:"shrink-0 text-text-400",children:a.jsx(Mw,{className:"w-3.5 h-3.5"})}),l&&a.jsx(vI,{starred:l.isFavorite(b.personaId),onToggle:()=>l.onToggle(b),testid:`persona-list-star-${b.personaId}`}),a.jsx(rte,{status:x3(y,n)}),y.length>0&&a.jsx("span",{"data-testid":`persona-list-count-${b.personaId}`,className:"shrink-0 text-[10px] text-text-400 tabular-nums",children:y.length})]},b.personaId)},x=b=>{const y=`${b.deviceId}::${b.personaId}`;return a.jsxs("div",{"data-testid":`persona-list-contact-row-${y}`,onClick:()=>l==null?void 0:l.onOpenContact(b.deviceId),className:"group flex items-center gap-2 px-2 py-1.5 rounded-md cursor-pointer hover:bg-text-100/5",children:[a.jsx(rf,{tool:b.tool,className:`w-4 h-4 shrink-0 ${nf(b.tool)}`}),a.jsxs("span",{className:"flex-1 truncate text-[13px] text-text-100",children:[b.label,a.jsxs("span",{className:"ml-1 text-[11px] text-text-400",children:["· ",b.contactName]})]}),a.jsx(vI,{starred:!0,onToggle:()=>l==null?void 0:l.onToggleContact(b),testid:`persona-list-contact-star-${y}`})]},y)};return a.jsxs("div",{"data-testid":"persona-list-column",className:"w-[248px] h-full overflow-y-auto",children:[l&&a.jsx("div",{className:"px-2 pt-2.5 pb-1",children:a.jsx("div",{role:"tablist",className:"flex p-0.5 rounded-md bg-text-100/5 text-[12px]",children:["all","starred"].map(b=>a.jsx("button",{type:"button",role:"tab","aria-selected":l.filter===b,"data-testid":`persona-list-filter-${b}`,onClick:()=>l.onFilterChange(b),className:`flex-1 flex items-center justify-center gap-1 py-1 rounded ${l.filter===b?"bg-bg-100 shadow-sm text-text-100":"text-text-400 hover:text-text-200"}`,children:b==="all"?"全部":a.jsxs(a.Fragment,{children:[a.jsx(cj,{className:"w-3 h-3",fill:l.filter===b?"currentColor":"none"}),"收藏",m>0&&a.jsx("span",{"data-testid":"persona-list-favorite-count",className:"tabular-nums text-text-400",children:m})]})},b))})}),c?m===0?a.jsxs("div",{"data-testid":"persona-list-favorites-empty",className:"px-4 py-10 text-center text-[12px] text-text-400 leading-relaxed",children:[a.jsx(cj,{className:"w-5 h-5 mx-auto mb-2 opacity-60"}),"还没有收藏",a.jsx("br",{}),"在「全部」里 hover persona 行点 ☆;",a.jsx("br",{}),"联系人的 persona 在「人」→ 联系人卡片里点 ☆"]}):a.jsxs(a.Fragment,{children:[d.length>0&&a.jsxs("div",{"data-testid":"persona-list-group-local",children:[a.jsx(Jp,{first:!0,children:"我的 persona"}),a.jsx("div",{className:"flex flex-col px-1",children:d.map(g)})]}),h.length>0&&a.jsxs("div",{"data-testid":"persona-list-group-cloud",children:[a.jsx(Jp,{first:d.length===0,children:"云上"}),a.jsx("div",{className:"flex flex-col px-1",children:h.map(g)})]}),l.contactFavorites.length>0&&a.jsxs("div",{"data-testid":"persona-list-group-contact",children:[a.jsx(Jp,{first:d.length===0&&h.length===0,children:"联系人的"}),a.jsx("div",{className:"flex flex-col px-1",children:l.contactFavorites.map(x)})]})]}):a.jsxs(a.Fragment,{children:[a.jsx(Jp,{first:!0,children:"我的 persona"}),a.jsxs("div",{className:"flex flex-col px-1",children:[d.length===0&&a.jsx("div",{"data-testid":"persona-list-empty",className:"px-3 py-2 text-[11px] text-text-400 italic",children:"还没有 persona"}),d.map(g)]}),a.jsx("div",{className:"px-1 pt-2",children:a.jsxs("button",{type:"button","data-testid":"persona-list-new",onClick:o,className:"w-full flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[12px] text-text-400 hover:text-text-200 hover:bg-text-100/5",children:[a.jsx(bs,{className:"w-3.5 h-3.5"}),"新建 persona"]})}),h.length>0&&a.jsxs("div",{"data-testid":"persona-list-group-cloud",children:[a.jsx(Jp,{children:"云上"}),a.jsx("div",{className:"flex flex-col px-1",children:h.map(g)})]})]})]})}function Itt({device:e,active:t,online:n,onSelect:r,onSetNote:s}){const[i,o]=p.useState(!1),[l,c]=p.useState(e.note??""),u=()=>{o(!1);const d=l.trim();d!==(e.note??"")&&(s==null||s(e.deviceId,d))};return a.jsxs("div",{"data-testid":`contact-detail-device-${e.deviceId}`,className:ee("group flex items-center gap-2 rounded-md px-2 py-1.5",t?"bg-text-100/10":"hover:bg-text-100/5"),children:[a.jsx("span",{className:ee("h-1.5 w-1.5 shrink-0 rounded-full",n?"bg-emerald-400":"bg-slate-400")}),i?a.jsx("input",{autoFocus:!0,"data-testid":`contact-detail-device-${e.deviceId}-note-input`,className:"flex-1 rounded border border-border bg-transparent px-1 py-0.5 text-[12px] text-text-100 outline-none",placeholder:"备注这台设备,例如「老王的 MacBook」",value:l,onChange:d=>c(d.target.value),onBlur:u,onKeyDown:d=>{d.key==="Enter"&&u(),d.key==="Escape"&&(c(e.note??""),o(!1))}}):a.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 flex-col items-start text-left",onClick:()=>!t&&(r==null?void 0:r(e.deviceId)),children:[a.jsx("span",{className:ee("w-full truncate text-[12px]",e.note?"text-text-100":"text-text-400 italic"),children:e.note||"未备注"}),a.jsx("span",{className:"w-full truncate font-mono text-[10px] text-text-500",children:e.deviceId})]}),!i&&a.jsxs(a.Fragment,{children:[t&&a.jsx("span",{className:"shrink-0 text-[10px] text-text-400",children:"当前"}),s&&a.jsx("button",{type:"button","aria-label":"备注这台设备","data-testid":`contact-detail-device-${e.deviceId}-note-edit`,className:"shrink-0 rounded p-1 text-text-400 opacity-0 hover:bg-text-100/10 group-hover:opacity-100",onClick:()=>{c(e.note??""),o(!0)},children:a.jsx(Mu,{className:"h-3 w-3"})})]})]})}function Ttt({contact:e,personDevices:t,onSelectDevice:n,onSetDeviceNote:r,presenceByDeviceId:s,personas:i,personasLoading:o=!1,personasError:l=null,onRetryPersonas:c,onReconnect:u,sessions:d,extensions:h,activeSessionId:f,awaitingIds:m,runningIds:g,unreadIds:x,onMessage:b,onPin:y,onSetRemoteAccess:v,onRemove:w,onCreateSession:_,onSelectSession:S,onDeleteSession:k,onEditSession:C,onInstallExtension:N,onOpenInstalledExtension:T,isPersonaFavorite:E,onTogglePersonaFavorite:R}){const O=aTe(e),[P,$]=p.useState(null),F=L=>{$(null);try{const D=_(L);D&&D.catch(I=>$(I instanceof Error?I.message:String(I)))}catch(D){$(D instanceof Error?D.message:String(D))}},B=p.useMemo(()=>{const L=new Map;for(const I of d){if(!I.ownerPersonaId)continue;const V=L.get(I.ownerPersonaId);V?V.push(I):L.set(I.ownerPersonaId,[I])}const D=new Map;for(const[I,V]of L)V.sort((H,M)=>M.updatedAt>H.updatedAt?1:-1),D.set(I,Sc(V));return D},[d]),W=p.useMemo(()=>new Map(d.map(L=>[L.sessionId,av(L)])),[d]);return a.jsxs("div",{className:"max-w-[560px] px-8 py-8","data-testid":"contact-detail",children:[a.jsxs("div",{className:"group flex items-center gap-3 mb-6","data-testid":"contact-detail-header",children:[a.jsx("span",{className:"inline-flex shrink-0 items-center justify-center w-11 h-11 rounded-full bg-slate-200/60 text-text-300",children:a.jsx(qh,{className:"w-5 h-5"})}),a.jsx("div",{className:"flex-1 min-w-0",children:a.jsx("div",{className:"text-[16px] font-semibold text-text-100 truncate",children:e.displayName||e.deviceId})}),a.jsxs("button",{type:"button","data-testid":"contact-detail-message",className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md border border-border hover:bg-text-100/5 text-[12.5px] text-text-100",onClick:b,children:[a.jsx($fe,{className:"w-3.5 h-3.5"}),"消息"]}),a.jsxs(Gr,{children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button","aria-label":"contact actions","data-testid":"contact-detail-menu",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(ca,{className:"w-4 h-4"})})}),a.jsxs(Pr,{align:"end",children:[a.jsx(Et,{onSelect:()=>y(e.pinnedAt==null),children:e.pinnedAt==null?"置顶联系人":"取消置顶"}),a.jsx(Et,{onSelect:w,children:"移除联系人"})]})]})]}),a.jsx(Rtt,{allowed:e.remoteAccessAllowed,onChange:v}),t&&t.length>1&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"mb-2 text-[12px] text-text-400",children:["该联系人的设备(",t.length," 台)"]}),a.jsx("div",{className:"mb-6 flex flex-col gap-px","data-testid":"contact-detail-devices",children:t.map(L=>a.jsx(Itt,{device:L,active:L.deviceId===e.deviceId,online:(s==null?void 0:s.get(L.deviceId))==="online",onSelect:n,onSetNote:r},L.deviceId))})]}),a.jsx("div",{className:"mb-2 text-[12px] text-text-400",children:"分享的 persona"}),P&&a.jsx("div",{"data-testid":"contact-detail-create-session-error",className:"mb-2 rounded border border-error/40 bg-error-dim px-2 py-1 text-[11px] text-error",children:Mtt(P)}),O!=="ok"?a.jsx(Att,{variant:O,onReconnect:u}):a.jsxs(a.Fragment,{children:[o&&i.length===0&&a.jsx("div",{"data-testid":"contact-detail-personas-loading",className:"flex flex-col gap-2",children:[0,1].map(L=>a.jsxs("div",{className:"border border-border rounded-lg overflow-hidden",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border/60",children:[a.jsx("span",{className:"w-3.5 h-3.5 shrink-0 rounded-full bg-text-100/10 animate-pulse"}),a.jsx("span",{className:"h-3 w-24 rounded bg-text-100/10 animate-pulse"})]}),a.jsx("div",{className:"px-3 py-2",children:a.jsx("span",{className:"block h-3 w-40 rounded bg-text-100/10 animate-pulse"})})]},L))}),!o&&l&&a.jsxs("div",{"data-testid":"contact-detail-personas-error",className:"mb-2 rounded-lg border border-error/40 bg-error-dim px-3 py-2.5 text-[12px] text-error",children:[a.jsx("div",{children:Ott(l)}),c&&a.jsxs("button",{type:"button","data-testid":"contact-detail-personas-retry",className:"mt-1.5 inline-flex items-center gap-1 rounded border border-error/40 px-2 py-0.5 text-[11.5px] hover:bg-error/10",onClick:c,children:[a.jsx(Tf,{className:"w-3 h-3"}),"重试"]})]}),!o&&!l&&i.length===0&&a.jsx("div",{"data-testid":"contact-detail-no-personas",className:"text-[12px] text-text-400 italic border border-dashed border-border rounded-lg px-4 py-5 text-center",children:"对方还没有分享 persona"})]}),a.jsx("div",{className:"flex flex-col gap-2",children:i.map(L=>{const D=B.get(L.personaId)??[];return a.jsxs("div",{"data-testid":`persona-block-${L.personaId}`,className:"group/pblock border border-border rounded-lg bg-bg-100 overflow-hidden",children:[a.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border/60",children:[a.jsx(rf,{tool:L.tool,className:`w-3.5 h-3.5 shrink-0 ${nf(L.tool)}`}),a.jsx("span",{className:"flex-1 text-[13px] text-text-100 truncate",children:L.label}),E&&R&&a.jsx(vI,{starred:E(L.personaId),onToggle:()=>R(L),testid:`persona-block-star-${L.personaId}`,revealClass:"group-hover/pblock:opacity-100"}),a.jsx("button",{type:"button",title:"新建会话","data-testid":`persona-block-add-${L.personaId}`,className:"p-0.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10 opacity-0 group-hover/pblock:opacity-100",onClick:()=>F(L.personaId),children:a.jsx(bs,{className:"w-3.5 h-3.5"})})]}),a.jsxs("div",{className:"py-1 px-1",children:[D.map(I=>a.jsx(Zu,{node:I,depth:0,showCopyResume:!1,activeId:f,unreadIds:x,runningIds:g,awaitingIds:m,onSelect:S,onEdit:C?(V,H)=>C(V,H):void 0,onDelete:k,getSessionDisplayName:V=>W.get(V)},I.session.sessionId)),D.length===0&&a.jsxs("button",{type:"button","data-testid":`persona-block-empty-${L.personaId}`,onClick:()=>F(L.personaId),className:"w-full flex items-center gap-1.5 pl-[33px] pr-1.5 py-1.5 rounded text-[11.5px] text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors",children:[a.jsx(bs,{className:"w-3 h-3"}),"点击新建会话"]})]})]},L.personaId)})}),h.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"mt-6 mb-2 text-[12px] text-text-400",children:"发布的插件"}),a.jsx(Ctt,{items:h,onInstall:N,onOpen:T})]})]})}function Rtt({allowed:e,onChange:t}){const[n,r]=p.useState(!1),[s,i]=p.useState(null),[o,l]=p.useState(null),c=o??e,u=d=>{n||(l(d),r(!0),i(null),t(d).catch(h=>{i(h instanceof Error?h.message:String(h)),l(null)}).finally(()=>r(!1)))};return a.jsxs("section",{className:"mb-6 rounded-lg border border-border px-3 py-2.5",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c?a.jsx(_pe,{className:"h-4 w-4 shrink-0 text-success"}):a.jsx(kpe,{className:"h-4 w-4 shrink-0 text-text-400"}),a.jsx("span",{className:"text-[13px] font-medium text-text-100",children:"允许远程操作我的设备"})]}),a.jsx($tt,{checked:c,disabled:n,onChange:u,testid:"contact-remote-access-toggle"})]}),a.jsx("p",{className:"mt-1.5 text-[11px] text-text-400 leading-relaxed",children:c?"对方的 persona 可在你的设备上跑命令、反向访问文件——以你的账户权限执行,无目录级限制,等同于给对方开一个 shell。撤销授权立即失效。":"对方将无法远程操作你的设备(跨设备 exec 与 SSH 反向访问都被拒)。"}),s&&a.jsx("div",{"data-testid":"contact-remote-access-error",className:"mt-2 rounded border border-error/40 bg-error-dim px-2 py-1 text-[11px] text-error",children:s})]})}function Mtt(e){return/404|not found|unreachable|timeout|ECONN|failed to fetch|network|not open|closed/i.test(e)?"对方设备当前不在线,无法新建会话":`新建会话失败:${e}`}function Ptt(e){return/PEER_LOGIN_EXPIRED/i.test(e)?"对方设备登录已过期,请让对方在 ClawOS 中重新登录后重试":/LOGIN_EXPIRED/i.test(e)?"本机登录已过期,请重新登录后重试":/404|DEVICE_UNREACHABLE|not found|unreachable|timeout|ECONN|failed to fetch|network|not open|closed/i.test(e)?"对方设备当前不在线,请让对方启动 ClawOS 后重试":`重新连接失败:${e}`}function Ott(e){return/TOKEN_EXPIRED/i.test(e)?"连接凭证已过期,重新连接即可恢复":/UNAUTHORIZED|FORBIDDEN/i.test(e)?"对方拒绝了访问(对方版本过旧或未授权)":/timeout|unreachable|ECONN|not open|closed|failed to fetch|network/i.test(e)?"对方设备不可达(可能不在线),稍后重试":`拉取失败:${e}`}const Dtt={broken:"建联未完成,无法获取对方分享的 persona",expired:"连接凭证已过期,重新连接即可恢复"};function Att({variant:e="broken",onReconnect:t}){const[n,r]=p.useState(!1),[s,i]=p.useState(null),o=()=>{n||!t||(r(!0),i(null),t().catch(l=>{const c=l instanceof Error?l.message:String(l);i(Ptt(c))}).finally(()=>r(!1)))};return a.jsxs("div",{"data-testid":"contact-detail-broken-link","data-variant":e,className:"rounded-lg border border-dashed border-border px-4 py-4 text-center",children:[a.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-[12.5px] text-text-200",children:[a.jsx(_fe,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),Dtt[e]]}),t&&a.jsxs("button",{type:"button","data-testid":"contact-detail-reconnect",disabled:n,onClick:o,className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md border border-border hover:bg-text-100/5 text-[12.5px] text-text-100 disabled:opacity-50",children:[a.jsx(Tf,{className:ee("w-3.5 h-3.5",n&&"animate-spin")}),n?"重新连接中…":"重新连接"]}),s&&a.jsx("div",{"data-testid":"contact-detail-reconnect-error",className:"mt-2 rounded border border-error/40 bg-error-dim px-2 py-1 text-[11px] text-error text-left",children:s})]})}function $tt({checked:e,disabled:t,onChange:n,testid:r}){return a.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:t,onClick:()=>n(!e),"data-testid":r,className:ee("relative inline-flex h-6 w-11 shrink-0 rounded-full transition-colors disabled:opacity-50",e?"bg-accent":"bg-bg-300"),children:a.jsx("span",{className:ee("inline-block h-5 w-5 rounded-full bg-bg-0 shadow transition-transform",e?"translate-x-[22px]":"translate-x-0.5"),style:{marginTop:2}})})}const Ltt=150,Ftt=250;function ste(e,t={}){const{openDelayMs:n=Ltt,closeDelayMs:r=Ftt,initialPinned:s=null}=t,[i,o]=p.useState(null),[l,c]=p.useState(null),u=p.useRef(null),d=p.useCallback(()=>{u.current!=null&&(clearTimeout(u.current),u.current=null)},[]),h=p.useCallback((y,v)=>{d(),u.current=setTimeout(()=>{u.current=null,o(y),y!=null&&c(w=>w==null?w:y)},v)},[d]);p.useEffect(()=>{if(d(),!e){o(null),c(null);return}s!=null&&(c(s),o(s))},[e,d]),p.useEffect(()=>d,[d]);const f=p.useCallback(y=>h(y,n),[h,n]),m=p.useCallback(()=>{document.querySelector("[data-radix-popper-content-wrapper]")||document.querySelector("[data-radix-focus-guard]")||h(null,r)},[h,r]),g=p.useCallback(()=>d(),[d]),x=p.useCallback(y=>{d();const v=l===y?null:y;c(v),o(v)},[d,l]),b=p.useCallback(()=>{d(),c(null),o(null)},[d]);return{selected:l??i,pinned:l,onHoverEnter:f,onHoverLeave:m,onCardEnter:g,onToggle:x,clear:b}}const Btt=6e4,ztt=5e3;function Htt(e){return e.startsWith("wss://")?"https://"+e.slice(6):e.startsWith("ws://")?"http://"+e.slice(5):e.startsWith("https://")||e.startsWith("http://")?e:null}function f2(e){const t=Htt(e);if(!t)return null;try{const n=new URL(t);return`${n.protocol}//${n.host}/healthz`}catch{return null}}const Utt=6;async function Wtt(e,t,n){let r=0;const s=Array.from({length:Math.min(t,e.length)},async()=>{for(;;){const i=r++;if(i>=e.length)return;await n(e[i])}});await Promise.all(s)}function Vtt(e,t={}){const n=t.intervalMs??Btt,r=t.timeoutMs??ztt,s=t.maxConcurrent??Utt,i=t.enabled??!0,[o,l]=p.useState(new Map),c=p.useRef(e);c.current=e;const u=p.useRef(t.fetchImpl??(typeof fetch<"u"?fetch:void 0));u.current=t.fetchImpl??(typeof fetch<"u"?fetch:void 0);const d=p.useRef(t.isPageHidden??(()=>typeof document<"u"&&document.visibilityState==="hidden"));d.current=t.isPageHidden??(()=>typeof document<"u"&&document.visibilityState==="hidden"),p.useEffect(()=>{l(m=>{const g=new Set(e.filter(y=>y.remoteUrl&&f2(y.remoteUrl)!==null).map(y=>y.deviceId));let x=!1;const b=new Map;for(const[y,v]of m)g.has(y)?b.set(y,v):x=!0;return x?b:m})},[e]);const h=p.useMemo(()=>e.filter(m=>m.remoteUrl&&f2(m.remoteUrl)!==null).map(m=>m.deviceId).sort().join("|"),[e]),f=p.useRef(()=>Promise.resolve());return p.useEffect(()=>{let m=!1;const g=async()=>{const b=u.current;if(!b){Pe("presence","tick skip: no fetch impl");return}if(d.current()){Pe("presence","tick skip: page hidden");return}const y=c.current.map(w=>({id:w.deviceId,remoteUrl:w.remoteUrl,healthz:w.remoteUrl?f2(w.remoteUrl):null})),v=y.map(w=>!w.remoteUrl||!w.healthz?null:{id:w.id,url:w.healthz}).filter(w=>w!==null);Pe("presence","tick",{rawCount:y.length,rawContacts:y,targetCount:v.length,targets:v}),v.length!==0&&await Wtt(v,s,async({id:w,url:_})=>{const S=new AbortController,k=setTimeout(()=>S.abort(),r);let C;try{C=(await b(_,{signal:S.signal,method:"GET"})).ok?"online":"offline"}catch{C="offline"}finally{clearTimeout(k)}m||l(N=>{if(N.get(w)===C)return N;const T=new Map(N);return T.set(w,C),T})})};if(f.current=g,!i)return()=>{m=!0,f.current=()=>Promise.resolve()};const x=setInterval(()=>{g()},n);return()=>{m=!0,clearInterval(x),f.current=()=>Promise.resolve()}},[n,r,s,i]),p.useEffect(()=>{i&&(Pe("presence","ownerKey change / enabled → trigger tick",{ownerKey:h,contactsLen:c.current.length}),f.current())},[h,i]),o}function qtt(e){const[t,n]=p.useState(null);return p.useEffect(()=>{const r=e.on("org-mesh:progress",i=>{const o=i;if(!(typeof o.total!="number"||typeof o.done!="number")){if(!o.active){n(null);return}n({total:o.total,done:o.done,connected:o.connected??0,failed:o.failed??0,active:!0})}}),s=e.on("daemon:disconnected",()=>n(null));return()=>{r(),s()}},[e]),t}function Ktt(e,t){const[n,r]=p.useState([]);return p.useEffect(()=>{if(!t)return;let s=!1;return e.request("org:peers",{}).then(i=>{if(s)return;const o=i==null?void 0:i.peers;r(Array.isArray(o)?o:[])}).catch(()=>{s||r([])}),()=>{s=!0}},[e,t]),n}function Gtt(e){var w,_;const{open:t,onClose:n,contacts:r,remoteGated:s,onEnsureContactLoaded:i,sidebarWidth:o=288,insetTop:l=0,insetBottom:c=0}=e,u=l>0||c>0,d=Vtt(r,{enabled:t}),h=qtt(e.client),f=Ktt(e.client,t),m=p.useMemo(()=>y3(r,d,void 0,e.unreadDeviceIds),[r,d,e.unreadDeviceIds]),g=ste(t,{initialPinned:e.initialSelectedId??null}),x=g.selected,b=r.find(S=>S.deviceId===x)??null,y=p.useMemo(()=>{var S;return b?((S=[...m.pinned,...m.main].find(k=>k.devices.some(C=>C.deviceId===b.deviceId)))==null?void 0:S.devices)??[b]:[]},[m,b]);p.useEffect(()=>{if(!t)return;const S=k=>{k.key==="Escape"&&(k.defaultPrevented||document.querySelector("[data-radix-focus-guard]")||n())};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[t,n]);const v=p.useRef(null);return p.useEffect(()=>{const S=v.current;v.current=x,!(s||x==null||x===S)&&i(x)},[x,s,i]),t?a.jsxs(a.Fragment,{children:[a.jsx("div",{"data-testid":"people-flyout-mask",className:"absolute inset-y-0 left-0 md:left-[var(--sidebar-w)] right-0 z-30 bg-black/10",style:{"--sidebar-w":`${o}px`},onClick:n}),a.jsxs("div",{"data-testid":"people-flyout",role:"dialog","aria-label":"联系人",className:"absolute left-0 md:left-[var(--sidebar-w)] z-40 flex pointer-events-none",style:{"--sidebar-w":`${o}px`,top:l,bottom:c},children:[a.jsx("div",{className:`h-full bg-bg-100 border-border shadow-xl pointer-events-auto ${u?"border rounded-xl overflow-hidden":"border-l"}`,children:s?a.jsx("div",{"data-testid":"people-flyout-gate",className:"w-[248px] h-full overflow-y-auto p-4 border-r border-border",children:e.loginCardNode}):a.jsxs("div",{className:"h-full flex flex-col",children:[a.jsx("div",{className:"w-[248px] shrink-0 border-r border-border",children:e.loginCardNode}),e.onAddContact&&a.jsx("div",{className:"w-[248px] shrink-0 border-r border-border px-2 pt-2",children:a.jsxs("button",{type:"button","data-testid":"people-add-contact",onClick:e.onAddContact,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-[12.5px] text-text-200 hover:bg-text-100/5 hover:text-text-100 transition-colors",children:[a.jsx(Vpe,{className:"w-3.5 h-3.5 shrink-0 text-text-300"}),"添加联系人"]})}),a.jsx("div",{className:"flex-1 min-h-0",children:a.jsx(ktt,{contacts:r,presenceByDeviceId:d,selectedDeviceId:x,onSelect:g.onToggle,onHover:g.onHoverEnter,onHoverEnd:g.onHoverLeave,publicDevices:e.publicDevices,onConnectPublicDevice:e.onConnectPublicDevice,visitors:e.visitors,visitorUnreadIds:e.visitorUnreadIds,onOpenVisitor:e.onOpenVisitor,unreadDeviceIds:e.unreadDeviceIds,orgMeshProgress:h,orgPeers:f})})]})}),b&&a.jsxs("div",{"data-testid":"people-flyout-card",onMouseEnter:g.onCardEnter,onMouseLeave:g.onHoverLeave,className:`self-start mt-6 ml-2 w-[520px] max-h-[calc(100%-3rem)] overflow-y-auto rounded-xl border border-border bg-bg-100 shadow-2xl pointer-events-auto ${Mx}`,children:[a.jsx("div",{className:"flex justify-end px-2 pt-2",children:a.jsx("button",{type:"button","aria-label":"close contact card","data-testid":"people-flyout-card-close",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",onClick:g.clear,children:a.jsx(Jt,{className:"w-4 h-4"})})}),a.jsx(Ttt,{contact:b,personas:e.personasByOwnerId.get(b.deviceId)??[],personasLoading:((w=e.personaLoadingOwnerIds)==null?void 0:w.has(b.deviceId))??!e.personasByOwnerId.has(b.deviceId),personasError:((_=e.personaErrorByOwnerId)==null?void 0:_.get(b.deviceId))??null,onRetryPersonas:e.onRetryPersonas?()=>e.onRetryPersonas(b.deviceId):void 0,onReconnect:e.onReconnectContact?()=>e.onReconnectContact(b):void 0,sessions:e.sessionsByOwnerId.get(b.deviceId)??[],extensions:e.extensionsByOwnerId.get(b.deviceId)??[],personDevices:y,presenceByDeviceId:d,onSelectDevice:g.onToggle,onSetDeviceNote:e.onSetContactNote,activeSessionId:e.activeSessionId,awaitingIds:e.awaitingIds,runningIds:e.runningIds,unreadIds:e.unreadIds,onMessage:()=>e.onMessage(b.deviceId),onPin:S=>e.onPinContact(b.deviceId,S),onSetRemoteAccess:S=>e.onSetContactRemoteAccess(b,S),onRemove:()=>e.onRemoveContact(b),onCreateSession:S=>e.onCreateRemoteSession(b.deviceId,S),onSelectSession:e.onSelectSession,...e.isRemotePersonaFavorite&&e.onToggleRemotePersonaFavorite?{isPersonaFavorite:S=>e.isRemotePersonaFavorite(b.deviceId,S),onTogglePersonaFavorite:S=>e.onToggleRemotePersonaFavorite(b.deviceId,S)}:{},onDeleteSession:e.onDeleteRemoteSession?S=>e.onDeleteRemoteSession(b.deviceId,S):void 0,onEditSession:e.onEditRemoteSession?(S,k)=>e.onEditRemoteSession(b.deviceId,S,k):void 0,onInstallExtension:e.onInstallExtension?S=>{const k=(e.extensionsByOwnerId.get(b.deviceId)??[]).find(C=>C.extId===S);e.onInstallExtension(b.deviceId,S,k==null?void 0:k.publishedHash)}:void 0,onOpenInstalledExtension:e.onOpenInstalledExtension?S=>e.onOpenInstalledExtension(b.deviceId,S):void 0})]})]})]}):null}const ny=(e,t)=>e.personaId===t.personaId&&e.deviceId===t.deviceId,NB=e=>`${e.deviceId??""}::${e.personaId}`;function jB(e){return e.some(t=>!t.deviceId&&t.personaId===Fi)?e:[{personaId:Fi},...e]}function Ytt({open:e,mode:t,initial:n,personas:r,contactGroups:s,onExpandContact:i,onSubmit:o,onCancel:l,submitting:c,error:u}){const[d,h]=p.useState(""),[f,m]=p.useState(""),[g,x]=p.useState([]),[b,y]=p.useState([]),[v,w]=p.useState(()=>new Set),_=JSON.stringify(n??null),S=p.useRef(n);S.current=n;const k=p.useRef(i);k.current=i,p.useEffect(()=>{if(!e)return;const D=S.current;h((D==null?void 0:D.name)??""),x(jB((D==null?void 0:D.memberPersonas)??[])),y((D==null?void 0:D.memberContactDeviceIds)??[]),m("");const I=new Set(((D==null?void 0:D.memberPersonas)??[]).map(V=>V.deviceId).filter(V=>!!V));w(I);for(const V of I)k.current(V)},[e,_]);const C=D=>{w(I=>{const V=new Set(I);return V.has(D)?V.delete(D):V.add(D),V}),v.has(D)||i(D)},N=f.trim().toLowerCase(),T=D=>!N||D.label.toLowerCase().includes(N)||D.id.toLowerCase().includes(N),E=p.useMemo(()=>r.filter(T),[r,N]),R=p.useMemo(()=>s.map(D=>{const I=!N||D.displayName.toLowerCase().includes(N),V=!!N&&!I&&!D.personas,H=I?D.personas??[]:(D.personas??[]).filter(T);return{g:D,shown:H,nameHit:I,unsearchable:V}}).filter(D=>D.nameHit||D.unsearchable||D.shown.length>0),[s,N]),O=d.trim(),P=g.filter(D=>D.deviceId||D.personaId!==Fi).length,$=O.length>0&&P>0&&!c,F=()=>{$&&o({name:O,memberPersonas:jB(g),memberContactDeviceIds:b})},B=xi(F,l),W=D=>{!D.deviceId&&D.personaId===Fi||x(I=>I.some(V=>ny(V,D))?I.filter(V=>!ny(V,D)):[...I,D])},L=D=>{y(I=>I.includes(D)?I.filter(V=>V!==D):[...I,D])};return e?os.createPortal(a.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:l,"data-testid":"channel-dialog-overlay",children:a.jsxs("div",{"data-testid":"channel-dialog",className:"w-[440px] 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:D=>D.stopPropagation(),children:[a.jsx("div",{className:"text-[15px] font-semibold text-text-100",children:t==="create"?"新建频道":"编辑频道"}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-[12px] font-semibold text-text-200 mb-1",children:"频道名"}),a.jsx("input",{autoFocus:!0,type:"text",value:d,disabled:c,onChange:D=>h(D.target.value),...B,placeholder:"clawd 开发","data-testid":"channel-dialog-name",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 disabled:opacity-60"})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-1",children:[a.jsx("label",{className:"block text-[12px] font-semibold text-text-200",children:"成员(Master 之外至少 1 个 persona)"}),a.jsxs("span",{className:"text-[11px] text-text-400",children:["已选 ",P+b.length]})]}),a.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 mb-2 border border-bg-300 rounded-lg",children:[a.jsx(ui,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),a.jsx("input",{value:f,onChange:D=>m(D.target.value),placeholder:"搜索 persona / 联系人…","data-testid":"channel-dialog-search",className:"w-full bg-transparent text-[13px] text-text-100 outline-none placeholder:text-text-500"}),f&&a.jsx("button",{type:"button","aria-label":"清空搜索",onClick:()=>m(""),className:"p-0.5 rounded text-text-400 hover:bg-text-100/10",children:a.jsx(Jt,{className:"w-3 h-3"})})]}),a.jsxs("div",{className:"max-h-72 overflow-y-auto pr-1 flex flex-col gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] font-medium text-text-400 mb-0.5",children:"我的 persona"}),E.length===0?a.jsx("div",{className:"px-1 py-1 text-[11px] text-text-400 italic",children:"没有匹配的 persona"}):E.map(D=>{const I=D.id===Fi,V={personaId:D.id};return a.jsxs("label",{title:I?"频道必须有 Master 才能操盘,不能取消":void 0,className:`flex items-center gap-2 px-1 py-1 rounded text-[13px] text-text-100 hover:bg-text-100/5 ${I?"cursor-default":"cursor-pointer"}`,children:[a.jsx("input",{type:"checkbox","data-testid":`member-persona-${D.id}`,checked:I||g.some(H=>ny(H,V)),disabled:I,onChange:()=>W(V)}),a.jsx(ra,{className:"w-3.5 h-3.5 shrink-0 text-text-300"}),a.jsx("span",{className:"shrink-0",children:D.label}),a.jsx("span",{className:"text-[11px] text-text-400 truncate",children:D.id}),I&&a.jsx("span",{"data-testid":"member-persona-master-required",className:"ml-auto shrink-0 text-[11px] text-text-400",children:"必选"})]},D.id)})]}),R.map(({g:D,shown:I,unsearchable:V})=>{const H=v.has(D.deviceId),M=g.filter(ce=>ce.deviceId===D.deviceId),Y=D.personas?M.filter(ce=>!D.personas.some(J=>J.id===ce.personaId)):M,X=!!D.errorText||!!D.loading,K=D.personas?X?"不在最近拿到的名单里":"对方已取消分享":D.loading?"读取中":D.errorText?"当前不可达":"未连上对方",te=M.length+(b.includes(D.deviceId)?1:0);return a.jsxs("div",{children:[a.jsxs("button",{type:"button","data-testid":`contact-group-${D.deviceId}`,onClick:()=>C(D.deviceId),className:"w-full flex items-center gap-1.5 px-1 py-1 rounded hover:bg-text-100/5 cursor-pointer",children:[H?a.jsx(Qt,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}):a.jsx(tr,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),a.jsx(qh,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),a.jsx("span",{className:"text-[12px] font-medium text-text-200",children:D.displayName}),H&&D.loading&&a.jsx("span",{className:"text-[11px] text-text-500",children:"读取 persona…"}),H&&!D.loading&&D.errorText&&a.jsx("span",{className:"text-[11px] text-red-500",children:D.errorText}),H&&!D.loading&&!D.errorText&&D.brokenLink&&a.jsx("span",{className:"text-[11px] text-text-500",children:"未连上"}),!H&&V&&a.jsx("span",{className:"text-[11px] text-text-500",children:"未展开,搜不到他的 persona"}),te>0&&a.jsxs("span",{className:"ml-auto shrink-0 text-[11px] text-text-400",children:["已选 ",te]})]}),H&&a.jsxs("div",{className:"pl-2 border-l border-bg-300 ml-2.5",children:[a.jsxs("label",{className:"flex items-center gap-2 px-1 py-1 rounded text-[13px] text-text-100 hover:bg-text-100/5 cursor-pointer",children:[a.jsx("input",{type:"checkbox","data-testid":`member-contact-${D.deviceId}`,checked:b.includes(D.deviceId),onChange:()=>L(D.deviceId)}),a.jsx(zH,{className:"w-3.5 h-3.5 shrink-0 text-text-300"}),a.jsx("span",{className:"shrink-0",children:"本人"}),a.jsx("span",{className:"text-[11px] text-text-400",children:"可发消息"})]}),I.map(ce=>{const J={personaId:ce.id,deviceId:D.deviceId};return a.jsxs("label",{className:"flex items-center gap-2 px-1 py-1 rounded text-[13px] text-text-100 hover:bg-text-100/5 cursor-pointer",children:[a.jsx("input",{type:"checkbox","data-testid":`member-persona-${D.deviceId}--${ce.id}`,checked:g.some(de=>ny(de,J)),onChange:()=>W(J)}),a.jsx(ra,{className:"w-3.5 h-3.5 shrink-0 text-text-300"}),a.jsx("span",{className:"shrink-0",children:ce.label}),a.jsx("span",{className:"text-[11px] text-text-400 truncate",children:ce.id})]},NB(J))}),Y.map(ce=>a.jsxs("label",{title:"名单里有它,但现在拉不到对方的 persona 列表",className:"flex items-center gap-2 px-1 py-1 rounded text-[13px] text-text-300 hover:bg-text-100/5 cursor-pointer",children:[a.jsx("input",{type:"checkbox","data-testid":`member-persona-${D.deviceId}--${ce.personaId}`,checked:!0,onChange:()=>W(ce)}),a.jsx(ra,{className:"w-3.5 h-3.5 shrink-0 text-text-400"}),a.jsx("span",{className:"shrink-0 truncate",children:ce.personaId}),a.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-text-400",children:K})]},NB(ce))),D.personas&&I.length===0&&Y.length===0&&a.jsx("div",{className:"px-1 py-1 text-[11px] text-text-400 italic",children:N?"他名下没有匹配的 persona":"未公开任何 persona"}),!D.personas&&D.loading&&a.jsx("div",{className:"px-1 py-1 text-[11px] text-text-400 italic",children:"读取中…"}),!D.personas&&!D.loading&&D.brokenLink&&a.jsx("div",{className:"px-1 py-1 text-[11px] text-text-400 italic",children:"和他的连接没建好,去「联系人」里重新连接后才能选他的 persona"})]})]},D.deviceId)})]}),u&&a.jsx("div",{className:"mt-1.5 text-[11px] text-red-500","data-testid":"channel-dialog-error",children:u})]}),a.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[a.jsx("button",{type:"button",onClick:l,className:"px-4 py-1.5 text-[12px] text-text-300 rounded-lg hover:bg-text-100/5 transition-colors cursor-pointer",children:"取消"}),a.jsx("button",{type:"button",onClick:F,disabled:!$,"data-testid":"channel-dialog-submit",className:"px-4 py-1.5 text-[12px] font-medium text-bg-0 rounded-lg bg-text-100 hover:bg-text-200 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",children:c?"保存中…":t==="create"?"创建":"保存"})]})]})}),document.body):null}function Xtt(e){const[t,n]=p.useState([]),[r,s]=p.useState(!0),[i,o]=p.useState(null),l=p.useCallback(async()=>{if(!e){s(!1);return}s(!0),o(null);try{const u=await new qt(e).channelList();n(Array.isArray(u==null?void 0:u.channels)?u.channels:[])}catch(u){o(u instanceof Error?u.message:String(u))}finally{s(!1)}},[e]);p.useEffect(()=>{l()},[l]),p.useEffect(()=>{if(e)return e.on("channel:changed",u=>{u!=null&&u.topicId||l()})},[e,l]);const c=p.useCallback(async u=>{o(null);try{const d=await u(new qt(e));return await l(),d}catch(d){throw o(d instanceof Error?d.message:String(d)),d}},[e,l]);return{channels:t,loading:r,error:i,refresh:l,create:u=>c(async d=>(await d.channelCreate(u)).channel),update:async u=>{await c(d=>d.channelUpdate(u))},remove:async u=>{await c(d=>d.channelDelete({channelId:u}))}}}const EB={topicsByChannel:{},linesByTopic:{}};function Ztt(e,t){const n={},r=new Set;for(const i of t){const o=e.topicsByChannel[i];if(o){n[i]=o;for(const l of o)r.add(l.id)}}const s={};for(const[i,o]of Object.entries(e.linesByTopic))r.has(i)&&(s[i]=o);return{topicsByChannel:n,linesByTopic:s}}function Qtt(e,t,n,r){const[s,i]=p.useState(EB),[o,l]=p.useState(0),[c,u]=p.useState(null),d=p.useRef(0),h=t.map(g=>g.id).join(",");p.useEffect(()=>{const g=++d.current,x=h===""?[]:h.split(",");if(!e||x.length===0){i(EB),u(h);return}i(b=>Ztt(b,x)),Promise.all(x.map(async b=>{const y=await e.topicList({channelId:b}).then(v=>Array.isArray(v==null?void 0:v.topics)?v.topics:[],v=>(Pe("app","topicList failed",{channelId:b,err:String(v)}),null));y===null||d.current!==g||(i(v=>({...v,topicsByChannel:{...v.topicsByChannel,[b]:y}})),await Promise.all(y.map(async v=>{const w=await e.topicGet({topicId:v.id}).then(_=>Array.isArray(_==null?void 0:_.lines)?_.lines:[],_=>(Pe("app","topicGet failed",{topicId:v.id,err:String(_)}),null));w===null||d.current!==g||i(_=>({..._,linesByTopic:{..._.linesByTopic,[v.id]:w}}))})))})).then(()=>{d.current===g&&u(h)})},[e,h,o]);const f=p.useRef({});p.useEffect(()=>{const g=new Set;for(const v of Object.values(s.topicsByChannel))for(const w of v)g.add(w.masterSessionId);const x={};for(const v of n)g.has(v.sessionId)&&(x[v.sessionId]=v.updatedAt);const b=f.current;f.current=x,Object.keys(x).some(v=>b[v]!==void 0&&b[v]!==x[v])&&l(v=>v+1)},[n,s.topicsByChannel]);const m=p.useCallback(()=>l(g=>g+1),[]);return p.useEffect(()=>{if(r)return r.on("channel:changed",()=>m())},[r,m]),{topicsByChannel:s.topicsByChannel,linesByTopic:s.linesByTopic,loaded:c===h,reload:m}}function Jtt(e){const t=new Map(e.records.map(i=>[i.dispatchId,i])),n=new Set(e.sessions.map(i=>i.sessionId)),r=new Map(e.personas.filter(i=>i.label).map(i=>[i.personaId,i.label])),s=new Map(e.contacts.filter(i=>i.displayName).map(i=>[i.deviceId,i.displayName]));return(i,o,l)=>{const c=t.get(i),u=c!==void 0&&c.workerSessionId===l,d=(u?c.sourcePersonaId:c==null?void 0:c.targetPersonaId)??o,h=u?c.sourceSessionId:c==null?void 0:c.workerSessionId,f=h&&n.has(h)?h:void 0,m=u||c==null?void 0:c.targetDeviceId,g=m?s.get(m):void 0,x=m?"remote-device":h&&!f?"session-gone":void 0;if(!d)return;const b=r.get(d),y=e.lineIndex.get(i);return{...y?{line:y}:{},persona:b?{id:d,label:b}:{id:d},...m?{device:g?{id:m,displayName:g}:{id:m}}:{},...f?{sessionId:f}:{},...x?{unreachable:x}:{}}}}const IB=[];function ent(e,t,n){const[r,s]=p.useState(null),i=p.useRef(0);return p.useEffect(()=>{const o=++i.current;!e||!t||e.personaDispatchList({relatedSessionId:t}).then(l=>{i.current===o&&s({sessionId:t,records:Array.isArray(l==null?void 0:l.records)?l.records:IB})},l=>{i.current===o&&Pe("app","personaDispatchList failed",{sessionId:t,err:String(l)})})},[e,t,n]),r&&r.sessionId===t?r.records:IB}function tnt(e){const t=!hl(e.tool),n=e.menu!==void 0,r=`${ite} ${ote(t)} ${n?"rounded-l px-2":"rounded px-2"}`,s=a.jsxs("button",{type:"button","aria-label":"发布到云上","aria-disabled":t||void 0,title:t?void 0:"发布到云上","data-testid":"persona-detail-deploy",onClick:t?void 0:e.onDeploy,className:r,children:[a.jsx(Mw,{className:"size-3.5"}),"发布到云上"]}),i=t?a.jsx(di,{delayDuration:200,children:a.jsxs(Zi,{children:[a.jsx(Qi,{asChild:!0,children:s}),a.jsx(gi,{side:"bottom",align:"end",className:"max-w-[240px] leading-relaxed",children:"云上只跑 codex / pi / claude 引擎的 persona。把下方的「引擎」改成其中一个之后就能发布。"})]})}):s;return n?a.jsxs("span",{className:"inline-flex",children:[i,e.menu]}):i}const ite="inline-flex items-center gap-1 border py-1 text-xs font-medium transition-colors",ote=e=>e?"cursor-not-allowed border-border bg-transparent text-text-400":"border-accent/50 bg-accent-dim text-accent hover:bg-accent hover:text-accent-contrast",nnt=e=>{const n=!hl(e)?"border-border bg-transparent text-text-400 hover:bg-text-100-dim/40":ote(!1);return`${ite} ${n} -ml-px rounded-r px-1`};function rnt({persona:e,roots:t,activeSessionId:n,awaitingIds:r,runningIds:s,unreadIds:i,onCreateSession:o,createSessionBlockedReason:l,onOpenSettings:c,onDeployToCloud:u,deployStatus:d,deployHistory:h,onDelete:f,onSelectSession:m,onEditSession:g,onDeleteSession:x,ownerPrincipalId:b,getCreatorDisplayName:y,getSessionDisplayName:v,settings:w,connectors:_,cloudApiKey:S,cloudLarkBot:k}){return a.jsxs("div",{"data-testid":"persona-detail",children:[a.jsxs("div",{className:"flex items-center gap-3 px-5 pb-4 border-b border-border",children:[a.jsx("span",{className:"inline-flex shrink-0 items-center justify-center w-10 h-10 rounded-full bg-bg-200",children:a.jsx(rf,{tool:e.tool,className:`w-5 h-5 ${nf(e.tool)}`})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"text-[15px] font-medium text-text-100 truncate",children:e.label}),a.jsxs("div",{className:"text-[12px] text-text-400",children:[t.length," 个会话",e.cloud&&a.jsx("span",{"data-testid":"persona-detail-cloud-badge",className:"ml-1.5 px-1.5 py-0.5 rounded bg-text-100/10 text-[11px]",children:"云上"})]})]}),o&&a.jsxs("button",{type:"button","data-testid":"persona-detail-new-session",onClick:o,disabled:l!==void 0,title:l,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-accent text-accent-contrast hover:bg-accent-hover text-[12.5px] font-medium disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-accent",children:[a.jsx(bs,{className:"w-3.5 h-3.5"}),"新建会话"]}),u&&a.jsxs("div",{className:"relative",children:[a.jsx(tnt,{tool:e.tool,onDeploy:u,...h!==void 0?{menu:h}:{}}),a.jsx("div",{className:"absolute right-0 top-full mt-0.5 whitespace-nowrap",children:d})]}),w||!c?null:a.jsx("button",{type:"button","aria-label":"人格设置",title:"人格设置","data-testid":"persona-detail-settings",onClick:c,className:"p-1.5 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(Aw,{className:"w-4 h-4"})}),f&&a.jsx("button",{type:"button","aria-label":"删除人格",title:"删除人格","data-testid":"persona-detail-delete",onClick:f,className:"p-1.5 rounded text-text-400 hover:text-error hover:bg-text-100/10",children:a.jsx(ws,{className:"w-4 h-4"})})]}),w?a.jsx("div",{className:"border-b border-border",children:w}):null,S?a.jsx("div",{className:"border-b border-border px-3 py-3",children:S}):null,k?a.jsx("div",{className:"border-b border-border",children:k}):null,_?a.jsx("div",{className:"border-b border-border",children:_}):null,a.jsxs("div",{className:"px-3 py-3",children:[a.jsx("div",{className:"px-2 pb-1.5 text-text-400 text-sm",children:"会话"}),t.length===0?o?a.jsxs("button",{type:"button","data-testid":"persona-detail-no-sessions",onClick:o,disabled:l!==void 0,title:l,className:"w-full flex items-center gap-1.5 pl-[33px] pr-3 py-2 rounded text-[12px] text-text-400 hover:text-text-100 hover:bg-text-100/5 transition-colors disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:text-text-400 disabled:hover:bg-transparent",children:[a.jsx(bs,{className:"w-3 h-3"}),"点击新建会话"]}):a.jsx("div",{"data-testid":"persona-detail-no-sessions-readonly",className:"pl-[33px] pr-3 py-2 text-[12px] text-text-400",children:"话题的 Master 会话会出现在这里"}):t.map(C=>a.jsx(Zu,{node:C,depth:0,activeId:n,unreadIds:i,runningIds:s,awaitingIds:r,onSelect:m,onEdit:g,onDelete:x,ownerPrincipalId:b,getCreatorDisplayName:y,getSessionDisplayName:v},C.session.sessionId))]})]})}function snt(e){const{open:t,onClose:n,sidebarWidth:r=288,insetTop:s=0,insetBottom:i=0,personas:o,sessions:l}=e,c=ste(t,{initialPinned:e.initialSelectedId??null}),u=c.selected,d=p.useMemo(()=>{const x=new Map;for(const y of l){if(!y.ownerPersonaId)continue;const v=x.get(y.ownerPersonaId);v?v.push(y):x.set(y.ownerPersonaId,[y])}const b=new Map;for(const[y,v]of x)b.set(y,uS(Sc(v)));return b},[l]);if(p.useEffect(()=>{if(!t)return;const x=b=>{b.key==="Escape"&&(b.defaultPrevented||document.querySelector("[data-radix-focus-guard]")||n())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[t,n]),!t)return null;const h=o.find(x=>x.personaId===u)??null,f=s>0||i>0,m=(x,b)=>{var y,v,w,_,S,k;return a.jsx(rnt,{persona:x,roots:d.get(x.personaId)??[],activeSessionId:e.activeSessionId,awaitingIds:e.awaitingIds,runningIds:e.runningIds,unreadIds:e.unreadIds,...x.personaId===Fi?{}:{onCreateSession:()=>e.onCreateSession(x.personaId)},...x.cloud?{}:{onOpenSettings:()=>e.onOpenPersonaSettings(x.personaId),onDelete:()=>e.onDeletePersona(x.personaId),...e.onDeployPersona?{onDeployToCloud:()=>{var C;return(C=e.onDeployPersona)==null?void 0:C.call(e,x.personaId)},deployStatus:(y=e.renderDeployStatus)==null?void 0:y.call(e,x.personaId),deployHistory:(v=e.renderDeployHistory)==null?void 0:v.call(e,x.personaId)}:{}},onSelectSession:e.onSelectSession,onEditSession:e.onEditSession,onDeleteSession:e.onDeleteSession,ownerPrincipalId:e.ownerPrincipalId,getCreatorDisplayName:e.getCreatorDisplayName,getSessionDisplayName:e.getSessionDisplayName,settings:x.cloud||(w=e.renderSettings)==null?void 0:w.call(e,x.personaId),connectors:b.connectors,...b.blockedReason?{createSessionBlockedReason:b.blockedReason}:{},cloudApiKey:x.cloud?(_=e.renderCloudApiKey)==null?void 0:_.call(e,x.cloud.personaId):void 0,cloudLarkBot:(S=x.cloud)!=null&&S.publishedByMe?(k=e.renderCloudLarkBot)==null?void 0:k.call(e,x.personaId):void 0})},g=h&&(h.cloud&&e.renderCloudConnectors?e.renderCloudConnectors(h.personaId,x=>m(h,x)):m(h,{connectors:void 0,blockedReason:null}));return a.jsxs(a.Fragment,{children:[a.jsx("div",{"data-testid":"persona-flyout-mask",className:"absolute inset-y-0 right-0 z-30 bg-black/10",style:{left:r},onClick:n}),a.jsxs("div",{"data-testid":"persona-flyout",role:"dialog","aria-label":"persona",className:"absolute z-40 flex pointer-events-none",style:{left:r,top:s,bottom:i},children:[a.jsx("div",{className:`h-full bg-bg-100 border-border shadow-xl pointer-events-auto ${f?"border rounded-xl overflow-hidden":"border-l border-r"}`,children:a.jsx(Ett,{personas:o,rootsByPersonaId:d,sets:{awaitingIds:e.awaitingIds,unreadIds:e.unreadIds,runningIds:e.runningIds},selectedPersonaId:u,onHoverPersona:x=>x==null?c.onHoverLeave():c.onHoverEnter(x),onSelectPersona:c.onToggle,onNewPersona:e.onNewPersona,favorites:e.favorites})}),h&&a.jsxs("div",{"data-testid":"persona-flyout-card",onMouseEnter:c.onCardEnter,onMouseLeave:c.onHoverLeave,className:`self-start mt-6 ml-2 w-[520px] max-h-[calc(100%-3rem)] overflow-y-auto rounded-xl border border-border bg-bg-100 shadow-2xl pointer-events-auto ${Mx}`,children:[a.jsx("div",{className:"flex justify-end px-2 pt-2",children:a.jsx("button",{type:"button","aria-label":"close persona card","data-testid":"persona-flyout-card-close",className:"p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10",onClick:c.clear,children:a.jsx(Jt,{className:"w-4 h-4"})})}),g]})]})]})}const int="clawd:persona:favorites",ont="clawd:persona:filter";function ry(e,t){return t?`${t}::${e}`:e}function ant(e){if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>!!n&&typeof n=="object"&&typeof n.personaId=="string"):[]}catch{return[]}}function lnt(){const[e,t]=bf(int,""),[n,r]=bf(ont,"all"),s=p.useMemo(()=>ant(e),[e]),i=p.useMemo(()=>new Set(s.map(l=>ry(l.personaId,l.deviceId))),[s]);return{favorites:s,isFavorite:(l,c)=>i.has(ry(l,c)),toggleFavorite:l=>{const c=ry(l.personaId,l.deviceId),u=i.has(c)?s.filter(d=>ry(d.personaId,d.deviceId)!==c):[...s,l];t(JSON.stringify(u))},filter:n==="starred"?"starred":"all",setFilter:r}}const cnt="clawd:sidebar:collapsed",TB=100,p2=250,nu=8,unt=28,m2=nu+unt+4;function dnt({hasUnread:e,onExpand:t,onMouseEnter:n,onMouseLeave:r}){return a.jsx("div",{"data-testid":"sidebar-collapsed-handle-wrap",className:"absolute left-2 top-2 z-50",onMouseEnter:n,onMouseLeave:r,children:a.jsxs("button",{type:"button","aria-label":"expand sidebar","data-testid":"sidebar-collapsed-handle",onClick:t,className:"relative p-1.5 rounded-md text-text-300 hover:text-text-100 hover:bg-text-100/10",children:[a.jsx(WH,{className:"w-4 h-4"}),e&&a.jsx("span",{"data-testid":"sidebar-collapsed-unread",className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-blue-500"})]})})}function hnt({onExpand:e,onMouseEnter:t,onMouseLeave:n}){return a.jsx("div",{"data-testid":"session-info-handle-wrap",className:"absolute right-2 top-2 z-50",onMouseEnter:t,onMouseLeave:n,children:a.jsx("button",{type:"button","aria-label":"expand session info","data-testid":"session-info-handle",onClick:e,className:"p-1.5 rounded-md text-text-300 hover:text-text-100 hover:bg-text-100/10",children:a.jsx(Vb,{className:"w-4 h-4"})})})}function fnt(e){const[t,n]=p.useState([]),[r,s]=p.useState(!0),[i,o]=p.useState(null),l=p.useCallback(async()=>{s(!0);try{const c=await e.request("extension.list",{});n(c.extensions),o(null)}catch(c){o(c.message)}finally{s(!1)}},[e]);return p.useEffect(()=>{let c=!1;return(async()=>{try{const u=await e.request("extension.list",{});if(c)return;n(u.extensions),o(null)}catch(u){if(c)return;o(u.message)}finally{c||s(!1)}})(),()=>{c=!0}},[e]),{extensions:t,loading:r,error:i,refresh:l}}function pnt({title:e,hint:t,testId:n}){return a.jsxs("div",{"data-testid":n,className:"flex flex-1 flex-col items-center justify-center px-6 py-8 gap-1 text-center",children:[a.jsx("div",{className:"text-[13px] text-text-300",children:e}),a.jsx("div",{className:"text-[11px] text-text-400/70",children:t})]})}function mnt(e){return e.state==="invalid"&&e.invalidReason?e.invalidReason:e.state==="starting"?`v${e.version} · starting…`:e.state==="running"?`v${e.version} · running`:e.state==="crashed"?`v${e.version} · crashed`:`v${e.version}`}function gnt({extensions:e,activeExtId:t,onImport:n,onOpen:r,onClose:s,onUninstall:i,onPublishSettings:o}){const l=p.useRef(null),c=()=>{var d;return(d=l.current)==null?void 0:d.click()},u=d=>{var f;const h=(f=d.target.files)==null?void 0:f[0];d.target.value="",h&&n(h)};return a.jsxs("div",{className:"h-full flex flex-col","data-testid":"sidebar-panel-extensions",children:[a.jsxs("div",{className:"px-3 py-2 border-b border-border shrink-0 flex items-center justify-between",children:[a.jsx("h2",{className:"text-sm font-semibold text-text-100",children:"Extensions"}),a.jsxs("button",{type:"button",onClick:c,"data-testid":"extensions-import-button",className:"flex items-center gap-1 px-2 py-1 text-xs rounded border border-border bg-bg-50 hover:bg-text-100/5 text-text-200 hover:text-text-100 transition-colors",children:[a.jsx(bs,{className:"h-3.5 w-3.5"}),"Import"]}),a.jsx("input",{ref:l,type:"file",accept:".zip,.clawos-ext,application/zip",onChange:u,className:"hidden","data-testid":"extensions-import-input"})]}),a.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2 flex flex-col gap-0.5",children:e.length===0?a.jsx(pnt,{testId:"sidebar-panel-extensions-empty",title:"No extensions yet",hint:"Import a .zip to add one"}):e.map(d=>{const h=t===d.extId,f=d.state==="invalid",m=d.state==="running"||d.state==="starting";return a.jsxs("div",{role:"button",tabIndex:f?-1:0,"data-testid":`extension-row-${d.extId}`,"aria-current":h?"page":void 0,onClick:()=>{f||r(d.extId)},className:ee("group/row flex items-center gap-2 px-2 py-1.5 rounded-md","text-[13px] cursor-pointer transition-colors",f&&"cursor-not-allowed opacity-60",h?"bg-text-100/5 text-text-100":"text-text-200 hover:text-text-100 hover:bg-text-100/5"),children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"truncate",children:d.name}),a.jsx("div",{className:"text-[11px] text-text-400/80 truncate",children:mnt(d)})]}),a.jsxs(Gr,{children:[a.jsx(Yr,{asChild:!0,children:a.jsx("button",{type:"button",onClick:g=>g.stopPropagation(),"data-testid":`extension-row-${d.extId}-menu`,className:ee("p-1 rounded text-text-400 hover:text-text-100 hover:bg-text-100/10","opacity-0 group-hover/row:opacity-100 focus:opacity-100 transition-opacity"),children:a.jsx(ca,{className:"w-3.5 h-3.5"})})}),a.jsxs(Pr,{align:"end",children:[m?a.jsxs(Et,{onSelect:()=>s(d.extId),children:[a.jsx(Lpe,{className:"w-3.5 h-3.5 mr-2"}),"Stop"]}):!f&&a.jsxs(Et,{onSelect:()=>r(d.extId),children:[a.jsx(rpe,{className:"w-3.5 h-3.5 mr-2"}),"Open"]}),!f&&d.externalUrl?a.jsxs(Et,{"data-testid":`extension-row-${d.extId}-open-external`,onSelect:()=>{window.open(d.externalUrl,"_blank","noopener,noreferrer")},children:[a.jsx(Ur,{className:"w-3.5 h-3.5 mr-2"}),"Open in browser"]}):null,!f&&o?a.jsxs(Et,{onSelect:()=>o(d.extId),children:[a.jsx(Aw,{className:"w-3.5 h-3.5 mr-2"}),"Publish settings…"]}):null,a.jsxs(Et,{onSelect:()=>i(d.extId),children:[a.jsx(ws,{className:"w-3.5 h-3.5 mr-2"}),"Uninstall"]})]})]})]},d.extId)})})]})}function xnt({localManifest:e,publishState:t,check:n,onPublishFirst:r,onPublishUpdate:s,onUnpublish:i}){const[o,l]=p.useState(""),c=t.kind==="published"?t.version:null,u=n.kind==="error-version-not-bumped"&&c!==null&&vnt(o,c),d=()=>{if(n.kind==="error-version-not-bumped"){if(!u)return;s==null||s(o);return}n.kind==="ready-new-version"&&(s==null||s())};return a.jsxs("section",{className:"rounded-lg border border-border bg-bg-50 p-4 flex flex-col gap-3","data-testid":"publish-extension-toggle",children:[a.jsxs("header",{className:"flex items-center gap-2",children:[t.kind==="published"?a.jsx(uT,{className:"w-4 h-4 text-success","aria-hidden":!0}):a.jsx(Rfe,{className:"w-4 h-4 text-text-400","aria-hidden":!0}),a.jsx("h3",{className:"text-sm font-medium text-text-100",children:"公开此 Extension"}),t.kind==="published"?a.jsx(cc,{className:"bg-success-dim text-success border-success/30",children:"已公开"}):a.jsx(cc,{className:"bg-bg-200 text-text-400 border-border",children:"未公开"})]}),a.jsx("p",{className:"text-[12px] text-text-400 leading-relaxed",children:"公开后,所有连接到你的 People 用户都能在你的视图里看到并安装这个 extension。"}),a.jsx(bnt,{localManifest:e,publishState:t,check:n}),n.kind==="error-version-not-bumped"&&c?a.jsx(ynt,{publishedVersion:c,value:o,onChange:l,onSubmit:d}):null,a.jsx("footer",{className:"flex items-center justify-end gap-2 pt-1",children:t.kind==="unpublished"?a.jsxs(Be,{size:"sm",onClick:r,"data-testid":"publish-first",children:["公开 v",e.version]}):a.jsxs(a.Fragment,{children:[a.jsx(Be,{size:"sm",variant:"outline",onClick:i,"data-testid":"unpublish",children:"取消公开"}),a.jsx(Be,{size:"sm",disabled:n.kind==="ready-new-version"?!1:n.kind==="error-version-not-bumped"?!u:!0,onClick:d,"data-testid":"publish-update",children:n.kind==="ready-new-version"?`发布 v${n.toVersion}`:n.kind==="error-version-not-bumped"&&u?`发布 v${o}`:"发布新版本"})]})})]})}function vnt(e,t){if(!Y5(e).ok)return!1;try{return sH(e,t)>0}catch{return!1}}function ynt({publishedVersion:e,value:t,onChange:n,onSubmit:r}){const s=xi(r),i=Y5(t).ok;let o=null;if(t&&i)try{sH(t,e)<=0&&(o=`必须 > ${e}`)}catch{}const l=t!==""&&!i,c=l||o!==null;return a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsxs("label",{htmlFor:"publish-extension-new-version",className:"text-[11px] text-text-300",children:["新版本号(必须 > 已发布 v",e,")"]}),a.jsx("input",{id:"publish-extension-new-version",type:"text",inputMode:"decimal",autoComplete:"off",spellCheck:!1,value:t,onChange:u=>n(u.target.value),...s,placeholder:e,"data-testid":"publish-extension-new-version-input",className:ee("rounded-md border bg-bg-0 px-2.5 py-1.5 text-[13px] font-mono text-text-100","placeholder:text-text-400/60 focus:outline-none focus:ring-2",c?"border-error/40 focus:ring-error/30":"border-border focus:ring-accent/30")}),c?a.jsx("span",{className:"text-[11px] text-error","data-testid":"publish-extension-new-version-error",children:l?"格式:MAJOR.MINOR.PATCH,仅数字":o}):null]})}function bnt({localManifest:e,publishState:t,check:n}){if(t.kind==="unpublished")return a.jsx(Hd,{kind:"info",icon:Ru,label:`本地版本 v${e.version} · hash ${g2(e.contentHash)}`});const r=a.jsx(Hd,{kind:"info",icon:ci,label:`已发布 v${t.version} · hash ${g2(t.contentHash)} · ${t.publishedAt}`});return n.kind==="clean"?r:n.kind==="ready-new-version"?a.jsxs(a.Fragment,{children:[r,a.jsx(Hd,{kind:"info",icon:Ru,label:`检测到本地新内容 v${n.toVersion} · hash ${g2(e.contentHash)} → 可发布`})]}):n.kind==="error-same-hash"?a.jsxs(a.Fragment,{children:[r,a.jsx(Hd,{kind:"warn",icon:In,label:`本地内容未变化,仍是 v${n.version},无需发布`})]}):n.kind==="error-version-not-bumped"?a.jsxs(a.Fragment,{children:[r,a.jsx(Hd,{kind:"error",icon:In,label:`本地内容已变化,但 manifest.version 仍是 ${n.localVersion}。在下面输入新版本号(必须 > ${n.publishedVersion}),daemon 会帮你改写 manifest 并发布。`})]}):n.kind==="error-version-regression"?a.jsxs(a.Fragment,{children:[r,a.jsx(Hd,{kind:"error",icon:In,label:`manifest.version (${n.localVersion}) 低于已发布版本 ${n.publishedVersion},不允许版本倒退。`})]}):r}function Hd({kind:e,icon:t,label:n}){const r=e==="error"?"bg-error-dim text-error border-error/30":e==="warn"?"bg-warning-dim text-warning border-warning/30":"bg-bg-100 text-text-300 border-border";return a.jsxs("div",{className:ee("flex items-start gap-2 rounded-md border px-2.5 py-1.5 text-[12px]",r),children:[a.jsx(t,{className:"w-3.5 h-3.5 shrink-0 mt-0.5","aria-hidden":!0}),a.jsx("span",{className:"leading-snug",children:n})]})}function g2(e){return e.length>8?e.slice(0,8):e}function wnt({open:e,extId:t,client:n,onClose:r,onUninstalled:s}){const[i,o]=p.useState(null),[l,c]=p.useState(null),[u,d]=p.useState(!1),h=p.useCallback(async()=>{try{const x=await n.request("extension.publish:status",{extId:t});o(x),c(null)}catch(x){c(x.message)}},[n,t]);p.useEffect(()=>{if(!e)return;h();const x=window.setInterval(()=>void h(),5e3);return()=>window.clearInterval(x)},[e,h]);const f=p.useCallback(async x=>{if(!u){d(!0);try{const b={extId:t};x&&(b.newVersion=x),await n.request("extension.publish",b),await h()}catch(b){c(b.message)}finally{d(!1)}}},[u,n,t,h]),m=p.useCallback(async()=>{if(!u){d(!0);try{await n.request("extension.unpublish",{extId:t}),await h()}catch(x){c(x.message)}finally{d(!1)}}},[u,n,t,h]),g=p.useCallback(async()=>{if(!u&&window.confirm(`卸载 extension "${t}"?`)){d(!0);try{await n.request("extension.uninstall",{extId:t}),s==null||s(t),r()}catch(x){c(x.message)}finally{d(!1)}}},[u,n,t,s,r]);return a.jsx(us,{open:e,onOpenChange:x=>!x&&r(),children:a.jsxs(Wr,{className:"max-w-lg","data-testid":"extension-publish-dialog",children:[a.jsx(zs,{children:a.jsx(Vr,{children:"Extension 设置"})}),a.jsxs("div",{className:"flex flex-col gap-3",children:[l?a.jsx("div",{className:"rounded-md border border-error/30 bg-error-dim text-error text-[12px] px-3 py-2",children:l}):null,i?a.jsx(xnt,{localManifest:i.localManifest,publishState:i.publishState,check:i.check,onPublishFirst:()=>void f(),onPublishUpdate:x=>void f(x),onUnpublish:()=>void m()}):a.jsx("div",{className:"text-[12px] text-text-400 px-2 py-4",children:"加载中…"}),a.jsx("hr",{className:"border-border"}),a.jsxs(Be,{variant:"destructive",onClick:()=>void g(),disabled:u,"data-testid":"extension-uninstall",children:[a.jsx(ws,{className:"w-3.5 h-3.5 mr-1.5"}),"删除并卸载"]})]})]})})}function _nt({client:e,activeExtId:t,onOpenInMain:n,onExtensionsMutated:r}){const{extensions:s,refresh:i}=fnt(e),{httpBaseUrl:o,httpToken:l}=Rx(),c=p.useCallback(async x=>{if(!o||!l)throw new Error("daemon HTTP not ready (missing httpBaseUrl/httpToken)");const b=await fetch(`${o}/extensions/import`,{method:"POST",headers:{Authorization:`Bearer ${l}`,"Content-Type":"application/zip"},body:x});if(!b.ok){const v=await b.json().catch(()=>null);throw new Error(v!=null&&v.code?`${v.code}: ${v.message??""}`:`HTTP ${b.status}`)}const{extId:y}=await b.json();await i(),r==null||r(),n(y)},[o,l,i,n,r]),u=p.useCallback(x=>{n(x)},[n]),d=p.useCallback(async x=>{await e.request("extension.close",{extId:x}),await i(),r==null||r()},[e,i,r]),h=p.useCallback(async x=>{await e.request("extension.uninstall",{extId:x}),await i(),r==null||r()},[e,i,r]),f=s.map(x=>{var y;if(x.state==="invalid")return{extId:x.extId,name:x.extId,version:"0.0.0",state:"invalid",invalidReason:x.invalidReason};let b;return x.state==="running"?b=x.target.kind==="local"?`http://127.0.0.1:${x.target.port}/`:x.target.url:(y=x.manifest.entry)!=null&&y.url&&(b=x.manifest.entry.url),{extId:x.extId,name:x.manifest.name,version:x.manifest.version,state:x.state,...b?{externalUrl:b}:{}}}),[m,g]=p.useState(null);return a.jsxs(a.Fragment,{children:[a.jsx(gnt,{extensions:f,activeExtId:t,onImport:c,onOpen:u,onClose:d,onUninstall:h,onPublishSettings:x=>g(x)}),m!==null?a.jsx(wnt,{open:!0,extId:m,client:e,onClose:()=>g(null),onUninstalled:()=>{i(),r==null||r()}}):null]})}function Snt(e,t){const n=new Map;for(const[r,s]of e){let i=0;for(const o of s){if(t.has(o.senderDeviceId))continue;knt(o.readBy,t)<o.createdAt&&i++}n.set(r,i)}return n}function knt(e,t){let n=0;for(const r of t){const s=e[r];s!==void 0&&s>n&&(n=s)}return n}function RB(e,t,n){const r=e.get(t)??[],s=r.findIndex(l=>l.id===n.id);let i;s<0?i=[...r,n].sort((l,c)=>l.createdAt-c.createdAt):(i=[...r],i[s]=n);const o=new Map(e);return o.set(t,i),o}function Cnt(){const e=globalThis.crypto;return e!=null&&e.randomUUID?e.randomUUID():"m_"+Math.random().toString(36).slice(2)+Date.now().toString(36)}function x2(e){return e==="connected"?"connected":e==="connecting"?"connecting":e==="disconnected"||e==="revoked"?"offline":"unknown"}const Nnt=[];function jnt(e,t,n="",r=Nnt){const[s,i]=p.useState(new Map),[o,l]=p.useState(new Map),c=p.useRef(new Set),u=p.useRef(new Set),d=p.useRef(new Set),h=p.useRef(new Map),f=p.useRef(null),m=p.useRef(null);p.useEffect(()=>{const _=e.local.on("inbox:event",S=>{const k=S;!(k!=null&&k.message)||!k.peerDeviceId||i(C=>RB(C,k.peerDeviceId,k.message))});return()=>_()},[e]),p.useEffect(()=>{const _=new Set(t.map(S=>S.deviceId));for(const[S,k]of h.current)_.has(S)||(k(),h.current.delete(S),e.disposeRemoteForDevice(S),c.current.delete(S),d.current.delete(S),u.current.delete(S),l(C=>{if(!C.has(S))return C;const N=new Map(C);return N.delete(S),N}),i(C=>{if(!C.has(S))return C;const N=new Map(C);return N.delete(S),N}));queueMicrotask(()=>{var S,k;for(const C of t)u.current.has(C.deviceId)&&!d.current.has(C.deviceId)&&((S=f.current)==null||S.call(f,C.deviceId)),c.current.has(C.deviceId)||(k=m.current)==null||k.call(m,C.deviceId)})},[t,e]),p.useEffect(()=>{queueMicrotask(()=>{var _;for(const S of r)c.current.has(S)||(_=m.current)==null||_.call(m,S)})},[r]),p.useEffect(()=>{const _=h.current;return()=>{for(const S of _.values())S();_.clear()}},[]);const g=p.useCallback(async function(S){if(!c.current.has(S)){c.current.add(S);try{const k=await e.local.request("inbox:list",{peerDeviceId:S}),C=Array.isArray(k==null?void 0:k.messages)?k.messages:[];C.length>0&&i(N=>{let T=N;for(const E of C)T=RB(T,S,E);return T})}catch(k){Pe("useIm","local list failed",{deviceId:S,error:k.message})}}},[e]);p.useEffect(()=>{m.current=g},[g]);const x=p.useCallback(async function(S){const k=t.find(E=>E.deviceId===S);if(!k||(u.current.add(S),await g(S),d.current.has(S)))return;const C=e.ensureRemoteForDevice(S,k.remoteUrl??"",k.connectToken);if(!C){l(E=>E.get(S)==="offline"?E:new Map(E).set(S,"offline"));return}d.current.add(S);const N=x2(C.getStatus());l(E=>new Map(E).set(S,N));const T=C.on("status",E=>{l(R=>new Map(R).set(S,x2(E)))});h.current.set(S,T)},[t,e,g]);p.useEffect(()=>{f.current=x},[x]);const b=p.useCallback(async(_,S)=>{const k=e.getRemoteForDevice(_),C=k?x2(k.getStatus()):"unknown";if(!k||C!=="connected")throw new Error("peer offline / not connected");const N=Cnt(),T=Date.now();await Promise.all([e.local.request("inbox:postMessage",{peerDeviceId:_,id:N,text:S,createdAt:T}),k.request("inbox:postMessage",{id:N,text:S,createdAt:T})])},[e]),y=p.useCallback(async(_,S)=>{try{await e.local.request("inbox:markRead",{peerDeviceId:_,upToCreatedAt:S})}catch(k){Pe("useIm","markRead failed",{deviceId:_,upToCreatedAt:S,error:k.message})}},[e]),v=p.useMemo(()=>new Set([n]),[n]),w=p.useMemo(()=>n===""?new Map:Snt(s,v),[s,v,n]);return p.useMemo(()=>({messagesByPeerDeviceId:s,statusByPeerDeviceId:o,unreadByPeer:w,ensurePeerLoaded:x,sendMessage:b,markRead:y}),[s,o,w,x,b,y])}function Ent(e,t){const[n,r]=p.useState(()=>new Map),[s,i]=p.useState(()=>new Map),o=e.filter(v=>Bf(v)),l=e.map(v=>v.connectToken&&v.remoteUrl?`${v.deviceId}::${v.remoteUrl}::${v.connectToken}`:`${v.deviceId}::broken`).sort().join("|"),c=p.useRef(new Map),u=p.useRef(new Map),d=p.useRef(new Set),h=p.useRef(new Set),[f,m]=p.useState(()=>new Set),g=p.useRef(new Map),x=p.useCallback(async v=>{const w=c.current.get(v);if(!w||h.current.has(v))return;const _=t.ensureRemoteForDevice(v,w.remoteUrl,w.token);if(_){_.getStatus()==="disconnected"&&_.start(),h.current.add(v),m(new Set(h.current));try{const S=await _.request("persona:list",{}),k=Array.isArray(S==null?void 0:S.personas)?S.personas:[];r(C=>{const N=new Map(C);return N.set(v,k),N}),i(C=>{if(!C.has(v))return C;const N=new Map(C);return N.delete(v),N})}catch(S){r(k=>{if(!k.has(v))return k;const C=new Map(k);return C.delete(v),C}),i(k=>{const C=new Map(k);return C.set(v,S instanceof Error?S.message:String(S)),C})}finally{h.current.delete(v),m(new Set(h.current))}}},[t]),b=p.useCallback(v=>{if(g.current.has(v))return;const w=c.current.get(v);if(!w)return;const _=t.ensureRemoteForDevice(v,w.remoteUrl,w.token);if(!_)return;const S=_.on("daemon:connected",()=>{x(v)});g.current.set(v,S)},[t,x]);p.useEffect(()=>{var N;const v=c.current,w=u.current,_=new Map,S=new Set,k=[],C=[];for(const T of o){const E={remoteUrl:T.remoteUrl,token:T.connectToken},R=v.get(T.deviceId);R&&(R.remoteUrl!==E.remoteUrl||R.token!==E.token)&&k.push(T.deviceId),!R&&w.get(T.deviceId)===!1&&C.push(T.deviceId),_.set(T.deviceId,E),S.add(T.deviceId)}c.current=_,u.current=new Map(e.map(T=>[T.deviceId,S.has(T.deviceId)])),r(T=>{let E=!1;const R=new Map;for(const[O,P]of T)S.has(O)?R.set(O,P):E=!0;return E?R:T}),i(T=>{let E=!1;const R=new Map;for(const[O,P]of T)S.has(O)?R.set(O,P):E=!0;return E?R:T});for(const T of[...d.current])S.has(T)||d.current.delete(T);for(const[T,E]of g.current)S.has(T)||(E(),g.current.delete(T));for(const T of k)(N=g.current.get(T))==null||N(),g.current.delete(T),t.disposeRemoteForDevice(T),d.current.has(T)&&(b(T),x(T));for(const T of C)d.current.add(T),b(T),x(T)},[l]),p.useEffect(()=>{const v=g.current;return()=>{for(const w of v.values())w();v.clear()}},[]);const y=p.useCallback(async v=>{c.current.get(v)&&(d.current.add(v),b(v),await x(v))},[b,x]);return{byOwnerId:n,loadingOwnerIds:f,errorByOwnerId:s,ensureLoaded:y}}function Int(e,t,n){const[r,s]=p.useState(()=>new Map),[i,o]=p.useState([]),l=p.useRef(new Map),c=p.useRef(new Set),u=p.useRef(new Set),d=p.useRef(new Map),h=e.filter(y=>Bf(y)),f=h.map(y=>`${y.deviceId}::${y.remoteUrl}::${y.connectToken}`).sort().join("|"),m=p.useCallback(async y=>{const v=l.current.get(y);if(!v||u.current.has(y))return;const w=t.ensureRemoteForDevice(y,v.remoteUrl,v.token);if(w){u.current.add(y);try{const _=await w.request("extension.list-published",{}),S=Array.isArray(_==null?void 0:_.extensions)?_.extensions:[];s(k=>{const C=new Map(k);return C.set(y,S),C})}catch{}finally{u.current.delete(y)}}},[t]),g=p.useCallback(async()=>{try{const y=await n.request("extension.list",{});o(Array.isArray(y==null?void 0:y.extensions)?y.extensions:[])}catch{}},[n]);p.useEffect(()=>(g(),n.on("daemon:connected",()=>{g()})),[n,g]),p.useEffect(()=>{const y=new Map,v=new Set;for(const w of h)y.set(w.deviceId,{remoteUrl:w.remoteUrl,token:w.connectToken}),v.add(w.deviceId);l.current=y,s(w=>{let _=!1;const S=new Map;for(const[k,C]of w)v.has(k)?S.set(k,C):_=!0;return _?S:w});for(const w of[...c.current])v.has(w)||c.current.delete(w);for(const[w,_]of d.current)v.has(w)||(_(),d.current.delete(w))},[f]),p.useEffect(()=>{const y=d.current;return()=>{for(const v of y.values())v();y.clear()}},[]);const x=p.useCallback(async y=>{const v=l.current.get(y);if(v){if(c.current.add(y),!d.current.has(y)){const w=t.ensureRemoteForDevice(y,v.remoteUrl,v.token);if(w){const _=w.on("daemon:connected",()=>{m(y)});d.current.set(y,_)}}await m(y)}},[t,m]);return{byOwnerId:p.useMemo(()=>Tnt(r,i),[r,i]),localExtensions:i,ensureLoaded:x,refreshLocal:g}}function Tnt(e,t){const n=new Map;for(const[r,s]of e){const i=s.map(o=>{const l=G5(o.extId,r),c=t.find(h=>h.extId===l&&h.state!=="invalid"),u=c&&c.state!=="invalid"?c.manifest.version:null,d={extId:o.extId,name:o.name,publishedVersion:o.version,publishedHash:o.contentHash};return u?u===o.version?{...d,state:{kind:"installed-up-to-date",installedVersion:u}}:{...d,state:{kind:"installed-with-update",installedVersion:u}}:{...d,state:{kind:"not-installed"}}});n.set(r,i)}return n}function yI(e,t){const{ownerPersonaId:n,projectPath:r,...s}=e;return{...s,originOwnerPrincipalId:t,...n?{originOwnerPersonaId:n}:{}}}function Rnt(e,t){const n=Ws(),[r,s]=p.useState(()=>new Map),i=e.filter(v=>Bf(v)),o=i.map(v=>`${v.deviceId}::${v.remoteUrl}::${v.connectToken}`).sort().join("|"),l=p.useRef(new Map),c=p.useRef(new Set),u=p.useRef(new Map),d=p.useRef(new Map),h=p.useCallback(v=>{const w=(u.current.get(v)??0)+1;return u.current.set(v,w),w},[]),f=p.useCallback((v,w)=>u.current.get(v)===w,[]),m=p.useCallback(async v=>{const w=l.current.get(v);if(!w)return;const _=t.ensureRemoteForDevice(v,w.remoteUrl,w.token);if(!_)return;const S=h(v);try{const k=await _.request("session:list",{});if(!f(v,S))return;const C=Array.isArray(k==null?void 0:k.sessions)?k.sessions:[];s(O=>{const P=new Map(O);return P.set(v,C),P});const N=C.map(O=>yI(O,v)),T=new Set(C.map(O=>O.sessionId)),R=(n.read("sessions")??[]).filter(O=>O.originOwnerPrincipalId===v&&!T.has(O.sessionId)).map(O=>O.sessionId);n.setData("sessions",O=>{const P=(O??[]).filter($=>!R.includes($.sessionId));for(const $ of N){const F=P.findIndex(B=>B.sessionId===$.sessionId);F>=0?P[F]=$:P.unshift($)}return P});for(const O of R)try{await t.local.request("peerSession:remove",{sessionId:O})}catch(P){Pe("mirror","peerSession:remove (reconcile) failed",O,P)}for(const O of N)try{await t.local.request("peerSession:upsert",O)}catch(P){Pe("mirror","peerSession:upsert failed",O.sessionId,P)}}catch{}},[t,h,f,n]),g=p.useCallback((v,w)=>{const _=w;if(!(_!=null&&_.sessionId)||_.chatId!==void 0)return;s(k=>{const C=k.get(v);if(!C)return k;const N=C.findIndex(R=>R.sessionId===_.sessionId);if(N<0)return k;const T=C.slice();T[N]=_;const E=new Map(k);return E.set(v,T),E});const S=yI(_,v);n.setData("sessions",k=>{const C=k??[],N=C.findIndex(E=>E.sessionId===S.sessionId);if(N<0)return C;const T=C.slice();return T[N]=S,T})},[n]);p.useEffect(()=>{const v=new Map,w=new Set;for(const _ of i)v.set(_.deviceId,{remoteUrl:_.remoteUrl,token:_.connectToken}),w.add(_.deviceId);l.current=v,s(_=>{let S=!1;const k=new Map;for(const[C,N]of _)w.has(C)?k.set(C,N):S=!0;return S?k:_});for(const _ of[...c.current])w.has(_)||c.current.delete(_);for(const[_,S]of d.current)w.has(_)||(S(),d.current.delete(_))},[o]),p.useEffect(()=>{const v=d.current;return()=>{for(const w of v.values())w();v.clear()}},[]);const x=p.useCallback(async v=>{const w=l.current.get(v);if(w){if(c.current.add(v),!d.current.has(v)){const _=t.ensureRemoteForDevice(v,w.remoteUrl,w.token);if(_){const S=_.on("daemon:connected",()=>{m(v)}),k=_.on("session:info",C=>{g(v,C)});d.current.set(v,()=>{S(),k()})}}await m(v)}},[t,m,g]),b=p.useCallback((v,w)=>{s(_=>{const S=new Map(_),k=S.get(v);if(!k)return S.set(v,[w]),S;const C=k.findIndex(N=>N.sessionId===w.sessionId);if(C>=0){const N=k.slice();N[C]=w,S.set(v,N)}else S.set(v,[w,...k]);return S})},[]),y=p.useCallback((v,w)=>{s(_=>{const S=_.get(v);if(!S)return _;const k=S.filter(N=>N.sessionId!==w);if(k.length===S.length)return _;const C=new Map(_);return C.set(v,k),C})},[]);return{byOwnerId:r,ensureLoaded:x,upsertSession:b,removeSession:y}}function Mnt(e){return e.map(t=>({deviceId:t.deviceId,ownerId:t.ownerId,provider:t.provider,displayName:t.displayName,remoteUrl:t.remoteUrl,connectToken:t.connectToken,grants:t.grants,addedAt:t.addedAt,pinnedAt:t.pinnedAt,remoteAccessAllowed:t.remoteAccessAllowed,note:t.note}))}function Pnt(e){const[t,n]=p.useState([]),[r,s]=p.useState(!0);p.useEffect(()=>{let d=!1;(async()=>{try{const b=await e.request("contact:list");if(d)return;n(Array.isArray(b==null?void 0:b.contacts)?b.contacts:[])}catch{if(d)return;n([])}finally{d||s(!1)}})();const h=e.on("contact:added",b=>{const y=b.contact;y&&n(v=>{const w=v.findIndex(S=>S.deviceId===y.deviceId);if(w<0)return[...v,y];const _=[...v];return _[w]=y,_})}),f=e.on("contact:removed",b=>{const y=b.deviceId;y&&n(v=>v.filter(w=>w.deviceId!==y))}),m=e.on("contact:pinned",b=>{const{deviceId:y,pinnedAt:v}=b;typeof y=="string"&&n(w=>{const _=w.findIndex(k=>k.deviceId===y);if(_<0)return w;const S=w.slice();return S[_]={...S[_],pinnedAt:v??null},S})}),g=e.on("contact:remote-access-updated",b=>{const{deviceId:y,remoteAccessAllowed:v}=b;typeof y!="string"||typeof v!="boolean"||n(w=>{const _=w.findIndex(k=>k.deviceId===y);if(_<0)return w;const S=w.slice();return S[_]={...S[_],remoteAccessAllowed:v},S})}),x=e.on("contact:note-updated",b=>{const{deviceId:y,note:v}=b;typeof y!="string"||typeof v!="string"||n(w=>{const _=w.findIndex(k=>k.deviceId===y);if(_<0)return w;const S=w.slice();return S[_]={...S[_],note:v},S})});return()=>{d=!0,h(),f(),m(),g(),x()}},[e]);const i=p.useCallback(async d=>{await e.request("contact:remove",{deviceId:d})},[e]),o=p.useCallback(async(d,h)=>{await e.request("contact:pin",{deviceId:d,pinned:h})},[e]),l=p.useCallback(async(d,h)=>{await e.request("contact:setRemoteAccess",{deviceId:d,remoteAccessAllowed:h.remoteAccessAllowed})},[e]),c=p.useCallback(async(d,h)=>{await e.request("contact:setNote",{deviceId:d,note:h})},[e]);return{contacts:p.useMemo(()=>Mnt(t),[t]),loading:r,remove:i,pin:o,setRemoteAccess:l,setNote:c}}function Ont(e,t){const[n,r]=p.useState([]),s=p.useCallback(async()=>{try{const i=await e.request("visitor:list",{});r(Array.isArray(i==null?void 0:i.visitors)?i.visitors:[])}catch{r([])}},[e]);return p.useEffect(()=>{if(!t){r([]);return}return s(),e.on("daemon:connected",()=>{s()})},[t,s,e]),{visitors:n}}function Dnt(e){const[t,n]=p.useState(null);return p.useEffect(()=>{const r=[e.on("ready",s=>{const i=s.tunnelUrl;i&&n(i)}),e.on("tunnel:ready",s=>{n(s.url??null)}),e.on("tunnel:exited",()=>n(null)),e.on("tunnel:unavailable",()=>n(null))];return()=>r.forEach(s=>s())},[e]),t}const Ant=5e3;function $nt(e,t){const[n,r]=p.useState([]);return p.useEffect(()=>{if(!t)return;let s=!0;const i=async()=>{try{const l=await e.request("device:connections");s&&r(l.connections)}catch{}};i();const o=setInterval(()=>void i(),Ant);return()=>{s=!1,clearInterval(o)}},[e,t]),n}function Lnt(e,t){const[n,r]=p.useState([]),[s,i]=p.useState(!1),[o,l]=p.useState(null),c=p.useCallback(async()=>{i(!0),l(null);try{const d=await e.request("device:list",{});r(Array.isArray(d==null?void 0:d.devices)?d.devices:[])}catch(d){l(d.message)}finally{i(!1)}},[e]);p.useEffect(()=>{if(t)return c(),e.on("daemon:connected",()=>{c()})},[t,c,e]);const u=p.useCallback(async d=>e.request("device:connect",{...d}),[e]);return{devices:n,loading:s,error:o,loadDevices:c,connect:u}}function Fnt(e,t,n){return e.filter(r=>r.deviceId!==t&&!n.has(r.deviceId))}const Bnt="visitor-";function b3(e){return`${Bnt}${e}`}function znt(e){return{deviceId:b3(e.visitorId),ownerId:e.visitorId,provider:e.provider,displayName:e.displayName,remoteUrl:"",connectToken:"",grants:[],addedAt:e.firstSeen,pinnedAt:null,remoteAccessAllowed:!1,note:""}}function MB(e,t){const n=new Map;for(const r of e)n.set(r.deviceId,r.displayName);for(const r of t)n.set(b3(r.visitorId),r.displayName);return n}const bI="clawos://device/";function Hnt(e){const t=e.trim();if(!t)return null;if(t.startsWith(bI)){const n=t.slice(bI.length).trim();return n?{deviceId:n}:null}return t.startsWith("dev-")?{deviceId:t}:t.startsWith("on_")?{deviceId:t}:null}function Unt(e){return`${bI}${e.deviceId}`}function Wnt({open:e,onClose:t,connect:n,myDeviceLink:r,onLogin:s}){const[i,o]=p.useState(""),[l,c]=p.useState(null),[u,d]=p.useState(null),[h,f]=p.useState(!1),[m,g]=p.useState(!1),x=u!=null&&u.includes(sue)&&!u.includes(fce),b=async()=>{if(s){g(!0);try{const k=await s();window.open(k,"_blank","noopener")}catch{}finally{g(!1)}}},y=async()=>{if(r)try{await navigator.clipboard.writeText(r),f(!0),setTimeout(()=>f(!1),1500)}catch{}},v=()=>{o(""),c(null),d(null)},w=async k=>{c(k.deviceId),d(null);try{await n(k),t(),v()}catch(C){d(C.message)}finally{c(null)}},_=()=>{const k=Hnt(i);if(!k){d("标识格式不对(应为 clawos://device/… 或 on_ 开头的 union_id)");return}w({deviceId:k.deviceId})},S=xi(()=>{l!==null||!i.trim()||_()});return a.jsx(us,{open:e,onOpenChange:k=>{k||(t(),v())},children:a.jsxs(Wr,{children:[a.jsxs(zs,{children:[a.jsx(Vr,{children:"添加联系人"}),a.jsx(hi,{children:"输入对方的设备标识连接——连上后互为联系人。公共设备在 People 列表里直接连。"})]}),a.jsxs("label",{className:"block mb-3",children:[a.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-text-300 mb-1",children:[a.jsx(BH,{className:"h-3.5 w-3.5"}),"输入对方的设备标识"]}),a.jsx("textarea",{value:i,onChange:k=>o(k.target.value),...S,placeholder:"clawos://device/on_… 或 on_…","data-testid":"dev-link-input",className:"block w-full mt-1 h-16 font-mono text-xs bg-bg-50 border border-border rounded p-2"})]}),a.jsx("button",{type:"button",onClick:_,disabled:l!==null||!i.trim(),"data-testid":"dev-link-connect",className:"px-3 py-1.5 bg-primary text-primary-foreground rounded disabled:opacity-50",children:l!==null?"连接中…":"连接"}),u&&(x?a.jsxs("div",{className:"mt-2 flex items-center gap-2","data-testid":"dev-connect-login-expired",children:[a.jsx("p",{className:"flex-1 text-xs text-destructive",children:"登录已失效,重新登录后再点「连接」"}),s&&a.jsx("button",{type:"button",disabled:m,onClick:()=>void b(),"data-testid":"dev-connect-relogin",className:"shrink-0 px-2 py-1 text-xs rounded border border-border bg-bg-50 hover:bg-text-100/5 text-text-200 hover:text-text-100 transition-colors disabled:opacity-50",children:m?"请在浏览器完成授权…":"重新登录"})]}):a.jsx("p",{className:"text-xs text-destructive mt-2","data-testid":"dev-connect-error",children:u})),r!==void 0&&a.jsxs("div",{className:"mt-4 pt-3 border-t border-border",children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-text-300 mb-1.5",children:[a.jsx($w,{className:"h-3.5 w-3.5"}),"我的设备标识"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("code",{"data-testid":"my-device-link",className:"flex-1 min-w-0 truncate font-mono text-[11px] text-text-200 bg-bg-50 border border-border rounded px-2 py-1.5",title:r,children:r}),a.jsxs("button",{type:"button",onClick:()=>void y(),"data-testid":"my-device-link-copy","aria-label":"复制标识",className:"shrink-0 flex items-center gap-1 px-2 py-1.5 rounded border border-border bg-bg-50 hover:bg-text-100/5 text-xs text-text-200",children:[h?a.jsx(Xt,{className:"h-3.5 w-3.5"}):a.jsx(va,{className:"h-3.5 w-3.5"}),h?"已复制":"复制"]})]}),a.jsx("p",{className:"text-[11px] text-text-400 mt-1.5",children:"把这个标识发给对方,对方添加你即可(需你的 daemon 在线并已开 tunnel)。"})]})]})})}class Vnt{constructor(t,n){Gs(this,"remotes",new Map);Gs(this,"ownersListeners",new Set);this.local=t,this.selfIdentity=n}ensureRemoteForDevice(t,n,r){if(!n||!r)return null;const s=this.remotes.get(t);if(s)return s;const i=CT({url:n,authToken:r,clientInfo:jT(),backoffMs:()=>-1,...this.selfIdentity?{selfIdentity:this.selfIdentity}:{}});return i.start(),this.remotes.set(t,i),this.notifyOwnersChanged(),i}getRemoteForDevice(t){return this.remotes.get(t)??null}disposeRemoteForDevice(t){const n=this.remotes.get(t);n&&(n.stop(),this.remotes.delete(t),this.notifyOwnersChanged())}disposeAll(){if(this.remotes.size!==0){for(const[,t]of this.remotes)t.stop();this.remotes.clear(),this.notifyOwnersChanged()}}listRemoteDeviceIds(){return Array.from(this.remotes.keys())}onOwnersChanged(t){return this.ownersListeners.add(t),()=>{this.ownersListeners.delete(t)}}notifyOwnersChanged(){for(const t of this.ownersListeners)t()}}const PB="clawd:sidebar:tree-collapsed";function qnt(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function Knt(e){const t=qnt(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 Gnt(){const e=ul(),[t,n]=p.useState(()=>new Set),r=p.useRef(t);r.current=t,p.useEffect(()=>{let c=!1;return(async()=>{try{const u=await e.kv.get(PB);if(c)return;n(Knt(u))}catch{}})(),()=>{c=!0}},[e]);const s=p.useCallback(c=>{e.kv.set(PB,[...c]).catch(()=>{})},[e]),i=p.useCallback(c=>r.current.has(c),[]),o=p.useCallback(c=>{n(u=>{const d=new Set(u);return d.has(c)?d.delete(c):d.add(c),s(d),d})},[s]),l=p.useCallback(c=>{n(u=>{let d=!1;const h=new Set;for(const f of u)c.has(f)?h.add(f):d=!0;return d?(s(h),h):u})},[s]);return{isCollapsed:i,toggle:o,prune:l}}const OB="clawd:sidebar:px",Ynt=280,Xnt=480,Znt=288;function ate(e){return Math.min(Xnt,Math.max(Ynt,e))}function Qnt(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function Jnt(e){const t=Qnt(e);return typeof t=="number"&&Number.isFinite(t)?ate(t):null}function ert(){const e=ul(),[t,n]=p.useState(Znt),r=p.useRef(t);r.current=t,p.useEffect(()=>{let o=!1;return(async()=>{try{const l=await e.kv.get(OB);if(o)return;const c=Jnt(l);c!=null&&n(c)}catch{}})(),()=>{o=!0}},[e]);const s=p.useRef(null);p.useEffect(()=>()=>{var o;return(o=s.current)==null?void 0:o.call(s)},[]);const i=p.useCallback(o=>{var x;o.preventDefault();const l=o.currentTarget;try{(x=l==null?void 0:l.setPointerCapture)==null||x.call(l,o.pointerId)}catch{}const c=o.clientX,u=r.current;let d=u;const h=document.body.style.userSelect;document.body.style.userSelect="none";const f=b=>{d=ate(u+(b.clientX-c)),n(d)},m=b=>{document.removeEventListener("pointermove",f),document.removeEventListener("pointerup",g),document.removeEventListener("pointercancel",g),document.body.style.userSelect=h,s.current=null,b&&e.kv.set(OB,d).catch(()=>{})},g=()=>m(!0);document.addEventListener("pointermove",f),document.addEventListener("pointerup",g),document.addEventListener("pointercancel",g),s.current=()=>m(!1)},[e]);return{width:t,onDragStart:i}}function trt(e,t){const n=Math.max(0,e.scheduledAt+e.nextDelayMs-t);return n<=0?`daemon 断开,正在尝试第 ${e.attempt} 次重连…`:`daemon 断开,第 ${e.attempt} 次重连,${Math.ceil(n/1e3)}s 后自动重试`}function lte(e){const[t,n]=p.useState(()=>Date.now());return p.useEffect(()=>{n(Date.now());const r=setInterval(()=>n(Date.now()),500);return()=>clearInterval(r)},[e.attempt,e.scheduledAt]),trt(e,t)}function nrt({state:e,onRetryNow:t}){if(e.kind==="reconnecting")return a.jsx(rrt,{state:e,onRetryNow:t});const n=srt(e);return n?a.jsxs("div",{"data-testid":"connection-banner","data-state":e.kind,className:ee("flex items-center gap-2 px-4 h-8 shrink-0 text-[12px] border-b",n.className),children:[a.jsx(n.Icon,{className:ee("w-3.5 h-3.5 shrink-0",n.iconClassName),"aria-hidden":"true"}),a.jsx("span",{className:"truncate",children:n.label})]}):null}function rrt({state:e,onRetryNow:t}){const[n,r]=p.useState(!1),s=lte(e),i=async()=>{if(!(!t||n)){r(!0);try{await t()}finally{r(!1)}}};return a.jsxs("div",{"data-testid":"connection-banner","data-state":"reconnecting",className:"flex items-center gap-2 px-4 h-8 shrink-0 text-[12px] border-b bg-warning-dim text-warning border-warning/30",children:[a.jsx(it,{className:"w-3.5 h-3.5 shrink-0 animate-spin","aria-hidden":"true"}),a.jsx("span",{className:"truncate flex-1",children:s}),t?a.jsxs("button",{type:"button",onClick:()=>void i(),disabled:n,"data-testid":"connection-banner-retry",className:ee("inline-flex items-center gap-1 px-2 h-6 rounded-sm text-[11px] font-medium","bg-warning/10 hover:bg-warning/20 text-warning border border-warning/30","disabled:opacity-50 disabled:cursor-not-allowed transition-colors"),children:[a.jsx(Tf,{className:ee("w-3 h-3",n&&"animate-spin"),"aria-hidden":"true"}),"立即重试"]}):null]})}function srt(e){switch(e.kind){case"connecting":return{Icon:it,iconClassName:"animate-spin",label:"正在连接 clawd daemon…",className:"bg-warning-dim text-warning border-warning/30"};case"disconnected":return{Icon:Xpe,label:e.reason?`daemon 未连接:${e.reason}`:"daemon 未连接",className:"bg-error-dim text-error border-error/30"};case"version-mismatch":return{Icon:Tg,label:`daemon 协议版本 v${e.daemonProtocol} 高于 extension 支持 v${e.supportedProtocol},请升级 extension`,className:"bg-warning-dim text-warning border-warning/30"};case"connected":case"idle":case"reconnecting":default:return null}}function irt(e){return e&&typeof e=="object"&&"value"in e?e.value:e}function ort(e){const t=irt(e);if(!t||typeof t!="object"||Array.isArray(t))return null;const{tool:n,model:r,effort:s,ownerPersonaId:i}=t;return n!=="claude"&&n!=="codex"&&n!=="pi"||r!==null&&typeof r!="string"||s!==null&&typeof s!="string"||typeof i!="string"||i===""?null:{tool:n,model:r,effort:s,ownerPersonaId:i}}const DB="butler-quick-compose/last-used";function art(){const e=ul(),t=p.useRef(null);p.useEffect(()=>{let r=!1;return(async()=>{try{const s=await e.kv.get(DB);if(r)return;t.current=ort(s)}catch{}})(),()=>{r=!0}},[e]);const n=p.useCallback(r=>{t.current=r,e.kv.set(DB,r).catch(()=>{})},[e]);return{lastUsedRef:t,save:n}}const sy=e=>({personaId:e,connectors:null,loading:e!==null,error:null});function w3(e,t){const[n,r]=p.useState(()=>sy(t)),s=p.useRef(t);p.useLayoutEffect(()=>{s.current=t},[t]);const i=p.useRef(0),o=p.useCallback(async()=>{if(t===null||!e||t!==s.current)return;const c=++i.current;r(u=>u.personaId===t?{...u,loading:!0}:sy(t));try{const u=await e.cloudConnectorsList(t);if(c!==i.current)return;r({personaId:t,connectors:u.connectors,loading:!1,error:null})}catch(u){if(c!==i.current)return;const d=u instanceof Error?u.message:String(u);r(h=>({personaId:t,connectors:h.personaId===t?h.connectors:null,loading:!1,error:d}))}},[e,t]);p.useEffect(()=>(t===null?r(sy(null)):o(),()=>{i.current++}),[o,t]);const l=n.personaId===t?n:sy(t);return{active:t!==null,connectors:l.connectors,loading:l.loading,error:l.error,reload:o}}function hS(e){if(!e.active)return null;if(e.error)return"查不到连接器授权状态,刷新一下再试";if(e.connectors===null)return"正在确认连接器授权…";const t=e.connectors.filter(n=>n.status!=="connected").map(n=>n.name);return t.length>0?`还要先授权:${t.join("、")}`:null}function cte(e){const t=hS(e);return t===null?null:e.connectors===null&&!e.error?t:`${t} · 在 persona 卡片的「连接器」里处理`}function lrt({api:e,projects:t,value:n,readOnly:r=!1,onChange:s,onProjectCreated:i}){const[o,l]=p.useState(!1),[c,u]=p.useState(!1),[d,h]=p.useState(""),f=n?t.find(g=>g.path===n)??null:null,m=p.useMemo(()=>t.filter(g=>g.name.toLowerCase().includes(d.trim().toLowerCase())),[t,d]);return r?a.jsxs("span",{"data-testid":"new-session-project-chip-readonly",className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md bg-bg-200 text-[12px] text-text-300 cursor-default select-none",children:[a.jsx(jg,{className:"w-3.5 h-3.5"}),(f==null?void 0:f.name)??n]}):a.jsxs(Fx,{open:o,onOpenChange:g=>{l(g),g||(u(!1),h(""))},children:[a.jsx(Bx,{asChild:!0,children:a.jsx(Ux,{icon:Vh,value:f?f.name:null,placeholder:"项目",selected:!!n,onOpen:()=>l(!0),testid:"new-session-project-chip"})}),a.jsx(Wf,{side:"top",align:"start",sideOffset:8,collisionPadding:8,className:"z-[10001] w-[300px] max-w-[calc(100vw-16px)] rounded-xl border border-bg-300 bg-bg-0 shadow-lg p-1 flex flex-col","data-testid":"new-session-project-popover",children:c?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"px-2.5 py-1.5 text-[11px] text-text-400",children:"选择项目目录"}),a.jsx(eW,{api:e,onSelect:g=>{(async()=>{try{const{project:x}=await e.projectCreate({path:g});s(x.path),i==null||i()}catch{return}l(!1),u(!1)})()}})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 border-b border-bg-300 mb-1",children:[a.jsx(ui,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),a.jsx("input",{autoFocus:!0,value:d,onChange:g=>h(g.target.value),placeholder:"搜索项目","data-testid":"new-session-project-search",className:"flex-1 bg-transparent text-[13px] text-text-200 placeholder:text-text-400/60 focus:outline-none"})]}),a.jsxs("div",{className:"max-h-[220px] overflow-y-auto",children:[m.map(g=>a.jsxs("button",{type:"button",title:g.path,"data-testid":`new-session-project-option-${g.name}`,onClick:()=>{s(g.path),l(!1)},className:"w-full flex items-center gap-2 text-left px-2.5 py-1.5 text-[13px] text-text-200 hover:bg-text-100/5 rounded-md",children:[a.jsx(jg,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),a.jsx("span",{className:"flex-1 truncate",children:g.name}),n===g.path&&a.jsx(Xt,{className:"w-3.5 h-3.5 text-text-200 shrink-0"})]},g.path)),m.length===0&&a.jsx("div",{className:"px-3 py-2 text-[12px] text-text-400 italic",children:"没有匹配的项目"})]}),a.jsxs("div",{className:"border-t border-bg-300 mt-1 pt-1",children:[a.jsxs("button",{type:"button","data-testid":"new-session-project-new",onClick:()=>u(!0),className:"w-full flex items-center gap-2 text-left px-2.5 py-1.5 text-[13px] text-text-200 hover:bg-text-100/5 rounded-md",children:[a.jsx(bs,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),"新建项目"]}),a.jsxs("button",{type:"button","data-testid":"new-session-project-none",onClick:()=>{s(null),l(!1)},className:"w-full flex items-center gap-2 text-left px-2.5 py-1.5 text-[13px] text-text-200 hover:bg-text-100/5 rounded-md",children:[a.jsx(Jt,{className:"w-3.5 h-3.5 text-text-400 shrink-0"}),"不在项目中工作"]})]})]})})]})}function crt({list:e,value:t,onChange:n}){const r=t?e.models.find(s=>s.id===t)??null:null;return a.jsx(fM,{testid:"new-session-model",list:e,current:t??"",side:"top",onSelect:s=>n(s===t?null:s),contentClassName:"z-[10001] w-[280px] max-h-[360px]",trigger:s=>a.jsx(Ux,{icon:aT,value:(r==null?void 0:r.label)??t,placeholder:"模型",selected:!!t,onOpen:s,testid:"new-session-model-chip"})})}function urt({options:e,value:t,onChange:n}){const[r,s]=p.useState(!1),i=t?e.find(l=>l.value===t)??null:null,o=e.length===0;return a.jsxs(Fx,{open:r,onOpenChange:s,children:[a.jsx(Bx,{asChild:!0,children:a.jsx(Ux,{icon:lT,value:(i==null?void 0:i.label)??null,placeholder:"思考强度",selected:!!i,onOpen:()=>s(!0),testid:"new-session-effort-chip"})}),o?null:a.jsx(Wf,{side:"top",align:"start",sideOffset:8,className:"z-[10001] w-[280px] max-h-[360px] overflow-y-auto rounded-xl border border-bg-300 bg-bg-0 shadow-lg p-1","data-testid":"new-session-effort-popover",children:e.map(l=>{const c=l.value===t;return a.jsxs("button",{type:"button",onClick:()=>{n(c?null:l.value),s(!1)},className:"w-full text-left px-3 py-2 text-[12px] hover:bg-text-100/5 rounded-md "+(c?"text-text-100 font-medium":"text-text-300"),"data-testid":`new-session-effort-option-${l.value||"default"}`,children:[a.jsx("div",{children:l.label}),l.description?a.jsx("div",{className:"text-[11px] text-text-400 mt-0.5",children:l.description}):null]},l.value||"default")})})]})}function ute({personas:e,loading:t,value:n,onChange:r,allowNone:s=!0}){const[i,o]=p.useState(!1),l=n?e.find(f=>f.personaId===n)??null:null,c=(l==null?void 0:l.name)??null,u=l==null?void 0:l.tool,d=t?"loading…":e.length===0?"无可用 persona":"persona",h=t||e.length===0;return a.jsxs(Fx,{open:i,onOpenChange:o,children:[a.jsx(Bx,{asChild:!0,children:a.jsx(Ux,{icon:l?void 0:yhe,prefixNode:l?a.jsx(gI,{tool:u,className:"w-3.5 h-3.5 mr-1"}):void 0,value:c,placeholder:d,selected:!!n,disabled:h,onOpen:()=>o(!0),testid:"new-session-persona-chip"})}),a.jsxs(Wf,{side:"top",align:"start",sideOffset:8,className:"z-[10001] w-[260px] max-h-[320px] overflow-y-auto rounded-xl border border-bg-300 bg-bg-0 shadow-lg p-1","data-testid":"new-session-persona-popover",children:[s?a.jsx("button",{type:"button",onClick:()=>{r(null),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] hover:bg-text-100/5 rounded-md "+(n===null?"text-text-100 font-medium":"text-text-300"),"data-testid":"new-session-persona-option-none",children:"无 persona"}):null,e.map(f=>a.jsxs("button",{type:"button",onClick:()=>{r(f.personaId),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] hover:bg-text-100/5 rounded-md flex items-center gap-2 "+(n===f.personaId?"text-text-100 font-medium":"text-text-300"),"data-testid":`new-session-persona-option-${f.personaId}`,children:[a.jsx(gI,{tool:f.tool,className:"w-3.5 h-3.5 shrink-0"}),f.name]},f.personaId))]})]})}const Js="persona-clawd-butler";function drt({kind:e,repo:t,requirement:n}){const r=["新建 persona",`类型:${e==="coding"?"编码":"普通"}`];return e==="coding"&&r.push(`仓库:${(t??"").trim()}`),r.push(`需求:${n.trim()}`),r.join(`
|
|
935
935
|
`)}function hrt({open:e,onOpenChange:t,onCreate:n,api:r,projects:s=[],presetProject:i=null,onProjectsChanged:o}){var vn,be;const[l,c]=p.useState(""),[u,d]=p.useState(i),[h,f]=p.useState("claude"),[m,g]=p.useState(null),[x,b]=p.useState(null),[y,v]=p.useState(Js),[w,_]=p.useState(!1),[S,k]=p.useState("idle"),[C,N]=p.useState(null),T=p.useRef(null),E=p.useRef(Js),R=p.useRef(!1),O=p.useRef(!1),P=p.useRef(null),$=p.useRef(null),F=p.useRef(null),{attachments:B,addFiles:W,removeAttachment:L,clearAttachments:D}=IG({httpBaseUrl:null,httpToken:null,sessionId:null}),[I,V]=p.useState(null),[H,M]=p.useState(!1),{lastUsedRef:Y,save:X}=art(),K=N_(),{capabilities:te}=ko(h),ce=O_(h),J=ce.models,de=p.useMemo(()=>A_(m,J,(te==null?void 0:te.configSchema)??[]).options,[m,J,te==null?void 0:te.configSchema]),we=p.useMemo(()=>K.personas.filter(ne=>ne.personaId!==Fi).map(ne=>({personaId:ne.personaId,name:ne.label,tool:ne.tool})),[K.personas]),[se,ae]=p.useState(0),[Z,fe]=p.useState(!1),ve=p.useRef(!1);p.useEffect(()=>{var nt;if(!e)return;const ne=Y.current;P.current=ne,R.current=!1,O.current=!1;const Ae=(ne==null?void 0:ne.ownerPersonaId)??Js;E.current=Ae,c(""),d(i??null),f((ne==null?void 0:ne.tool)??"claude"),g((ne==null?void 0:ne.model)??null),b((ne==null?void 0:ne.effort)??null),v(Ae),_(!1),k("idle"),N(null),T.current=null,D(),V(null),M(!1),ae(0),fe(!1),(nt=$.current)==null||nt.focus()},[e,i]),p.useEffect(()=>{if(!e||!K.loaded||E.current===null)return;const ne=E.current,Ae=K.personas.find(rt=>rt.personaId===ne);if(Ae){R.current||(!P.current&&!O.current&&(f(qy(Ae.tool)),g(Ae.model??null),b(Ae.effort??null)),R.current=!0);return}if(K.personas.length===0)return;const nt=K.personas.find(rt=>rt.personaId===Js);E.current=Js,v(Js),(P.current||!O.current)&&(f(qy(nt==null?void 0:nt.tool)),g((nt==null?void 0:nt.model)??null),b((nt==null?void 0:nt.effort)??null)),R.current=!0},[e,K.loaded,K.personas]);const Te=p.useCallback(ne=>{if(O.current=!0,!ne){E.current=null,v(null);return}const Ae=K.personas.find(nt=>nt.personaId===ne);E.current=ne,v(ne),f(qy(Ae==null?void 0:Ae.tool)),g((Ae==null?void 0:Ae.model)??null),b((Ae==null?void 0:Ae.effort)??null)},[K.personas]);p.useEffect(()=>{!e||u||E.current===null&&(E.current=Js,v(Js))},[e,u]),p.useEffect(()=>{!e||!m||J.length===0||J.some(ne=>ne.id===m)||g(null)},[e,m,J]),p.useEffect(()=>{!e||!x||de.length===0||de.some(ne=>ne.value===x)||b(null)},[e,x,de]);const Qe=y?K.personas.find(ne=>ne.personaId===y):void 0,ge=!!(Qe!=null&&Qe.cloud),Ce=w3(r,e&&ge?y:null),De=hS(Ce),Me=cte(Ce),We=B.some(ne=>ne.status==="done"),wt=!!(l.trim()||We)&&De===null,Ct=p.useMemo(()=>{const ne=l.match(/^@(\S*)$/);return ne?ne[1]:null},[l]),oe=p.useMemo(()=>K.personas.filter(ne=>ne.personaId!==Fi).map(ne=>({kind:"persona",persona:{personaId:ne.personaId,label:ne.label}})),[K.personas]),le=p.useMemo(()=>Ct!==null?AR(oe,Ct):[],[oe,Ct]),pe=Ct!==null&&!Z&&le.length>0;p.useEffect(()=>{ae(0)},[Ct]),p.useEffect(()=>{fe(!1)},[l]),p.useEffect(()=>{ae(ne=>Math.min(ne,Math.max(0,le.length-1)))},[le.length]);const Ke=p.useCallback(ne=>{ne.kind==="persona"&&(c(`@persona/${ne.persona.personaId} `),fe(!1),setTimeout(()=>{var Ae;return(Ae=$.current)==null?void 0:Ae.focus()},0))},[]),Ge=p.useCallback(async()=>{var Ae,nt;if(!wt||S==="creating")return;k("creating"),N(null);const ne=Bq(l)??((Ae=B.find(rt=>rt.status==="done"))==null?void 0:Ae.fileName)??"新建 session";try{if(!T.current){const{sessionId:$t}=await n({...u&&!y?{cwd:u}:{},...y?{ownerPersonaId:y}:{},...u&&y?{projectPath:u}:{},aiLabel:ne,...ge?{}:{tool:h,model:m??void 0,effort:x??void 0}});T.current=$t}await r.sessionSubscribe(T.current);const rt=u?`<related-dir>${u}</related-dir>
|
|
936
936
|
|
|
937
937
|
${l.trim()}`:l.trim(),Mt=wq(rt,B);await r.sessionSend(T.current,Mt),X({tool:h,model:m,effort:x,ownerPersonaId:y??Js}),w?(c(""),D(),T.current=null,k("idle"),(nt=$.current)==null||nt.focus()):t(!1)}catch(rt){const Mt=rt.message??String(rt);T.current?(k("messageError"),N(`session 已创建,首条消息发送失败:${Mt}`)):(k("createError"),N(`创建失败:${Mt}`))}},[wt,S,l,u,h,m,x,y,ge,B,w,D,X,n,t,r]),ut=xi(Ge),rn=p.useCallback(ne=>{const Ae=ne.nativeEvent,nt=OR({compositionActive:ve.current,nativeIsComposing:!!Ae.isComposing,keyCode:Ae.keyCode});if(pe&&!nt){const rt=le.length;if(ne.key==="ArrowDown"){rt>0&&ae(Mt=>(Mt+1)%rt),ne.preventDefault();return}if(ne.key==="ArrowUp"){rt>0&&ae(Mt=>(Mt-1+rt)%rt),ne.preventDefault();return}if(ne.key==="Enter"||ne.key==="Tab"){const Mt=Math.min(se,Math.max(0,rt-1)),$t=rt>0?le[Mt]:void 0;$t&&Ke($t),ne.preventDefault();return}if(ne.key==="Escape"){fe(!0),ne.preventDefault(),ne.stopPropagation();return}}ut.onKeyDown(ne)},[pe,le,se,Ke,ut]);p.useEffect(()=>{if(!e)return;const ne=Ae=>{Ae.key==="Escape"&&t(!1)};return window.addEventListener("keydown",ne),()=>window.removeEventListener("keydown",ne)},[e,t]);const Ve=p.useCallback(ne=>{ne.target.files&&W(ne.target.files),ne.target.value=""},[W]),en=p.useCallback(ne=>{const Ae=Array.from(ne.clipboardData.items).map(nt=>nt.getAsFile()).filter(nt=>!!(nt&&nt.type.startsWith("image/")));Ae.length!==0&&(ne.preventDefault(),W(Ae))},[W]),ye=p.useCallback(ne=>{ne.preventDefault(),M(!0)},[]),Oe=p.useCallback(()=>M(!1),[]),dt=p.useCallback(ne=>{ne.preventDefault(),M(!1),ne.dataTransfer.files.length>0&&W(ne.dataTransfer.files)},[W]),Nt=p.useCallback(ne=>{ne.previewUrl&&V({url:ne.previewUrl,name:ne.fileName})},[]);return e?os.createPortal(a.jsxs("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center bg-bg-0/40 backdrop-blur-[2px]",onClick:()=>t(!1),"data-testid":"butler-quick-overlay",children:[a.jsxs("div",{"data-testid":"butler-quick-dialog",className:ee("relative w-[560px] max-w-[calc(100vw-32px)] max-h-[80vh] rounded-2xl overflow-hidden flex flex-col border bg-bg-0 transition-colors",H?"border-accent/60 bg-accent/5":"border-text-100/[0.12]"),style:{boxShadow:"0 12px 40px rgba(0, 0, 0, 0.04)"},onClick:ne=>ne.stopPropagation(),onDragOver:ye,onDragLeave:Oe,onDrop:dt,children:[a.jsx("input",{ref:F,type:"file",multiple:!0,accept:wH,hidden:!0,onChange:Ve,"data-testid":"butler-quick-attachment-file"}),a.jsx("button",{type:"button",onClick:()=>t(!1),className:"absolute top-3 right-3 p-1 rounded-md hover:bg-text-100/5 text-text-400 z-10 cursor-pointer","aria-label":"close","data-testid":"butler-quick-close",children:a.jsx(Jt,{className:"w-4 h-4"})}),a.jsx("div",{className:"px-5 pt-4 pr-12 text-[15px] font-semibold text-text-100",children:"新建任务"}),a.jsxs("div",{className:"px-5 pt-2 pb-3 flex-1 overflow-y-auto flex flex-col gap-2",children:[a.jsx(EG,{attachments:B,onRemove:L,onOpenPreview:Nt}),a.jsx("textarea",{ref:$,value:l,onChange:ne=>c(ne.target.value),onCompositionStart:()=>{ve.current=!0,ut.onCompositionStart()},onCompositionEnd:()=>{setTimeout(()=>{ve.current=!1},0),ut.onCompositionEnd()},onKeyDown:rn,onPaste:en,placeholder:"想干啥?","data-testid":"butler-quick-content",rows:6,className:"w-full text-[14px] bg-transparent text-text-200 placeholder:text-text-400/60 focus:outline-none resize-none min-h-[180px] max-h-[360px]"})]}),a.jsx("div",{className:"relative",children:pe?a.jsx(Wj,{query:Ct??"",entries:le,activeIndex:se,onActiveIndexChange:ae,onSelect:Ke}):null}),a.jsxs("div",{className:"px-5 py-3 flex flex-wrap gap-2",children:[a.jsx(lrt,{api:r,projects:s,value:u,readOnly:i!=null,onChange:d,onProjectCreated:o}),!ge&&a.jsxs(a.Fragment,{children:[a.jsx(zDe,{value:h,onChange:ne=>{O.current=!0,f(ne),g(null),b(null)}}),a.jsx(crt,{list:ce,value:m,onChange:ne=>{O.current=!0,g(ne),b(null)}}),a.jsx(urt,{options:de,value:x,onChange:ne=>{O.current=!0,b(ne)}})]}),a.jsx(ute,{personas:we,loading:!K.loaded,value:y,onChange:Te,allowNone:u!=null})]}),u&&a.jsx("div",{className:"px-5 pb-2 text-[11px] text-text-400","data-testid":"butler-quick-project-hint",children:y?`${((vn=we.find(ne=>ne.personaId===y))==null?void 0:vn.name)??y} 将在项目 ${((be=s.find(ne=>ne.path===u))==null?void 0:be.name)??u} 中工作(人格保留,项目目录可读写)`:`将在 ${u} 下新建纯项目会话(无 persona)`}),Me&&a.jsxs("div",{className:"flex items-center gap-2 px-5 pb-2 text-[11px] text-text-400",children:[a.jsx("span",{"data-testid":"butler-quick-cloud-gate",children:Me}),(Ce.connectors!==null||Ce.error!==null)&&a.jsx("button",{type:"button","data-testid":"butler-quick-cloud-gate-recheck",disabled:Ce.loading,onClick:()=>void Ce.reload(),className:"shrink-0 text-accent hover:underline disabled:opacity-50 disabled:no-underline",children:Ce.loading?"检查中…":"重新检查"})]}),C?a.jsx("div",{className:"px-5 pb-2 text-[11px] text-destructive","data-testid":"butler-quick-error",children:C}):null,a.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-t border-bg-300",children:[a.jsx("button",{type:"button",onClick:()=>{var ne;return(ne=F.current)==null?void 0:ne.click()},"data-testid":"butler-quick-attach","aria-label":"attach files",disabled:S==="creating",className:ee("flex h-7 w-7 shrink-0 items-center justify-center rounded-md transition-colors",S==="creating"?"cursor-default text-text-400/50":"cursor-pointer text-text-400 hover:bg-text-100/5 hover:text-text-200"),children:a.jsx(VH,{className:"h-4 w-4"})}),a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-text-300 cursor-pointer select-none",children:[a.jsx("input",{type:"checkbox",checked:w,onChange:ne=>_(ne.target.checked),"data-testid":"butler-quick-keep-creating"}),"继续创建"]}),a.jsx("button",{type:"button",onClick:()=>void Ge(),disabled:!wt||S==="creating","data-testid":"butler-quick-submit",className:"px-4 py-1.5 text-[12px] font-medium text-bg-0 rounded-lg bg-text-100 hover:bg-text-200 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer",children:S==="creating"?"创建中…":S==="messageError"?"重发消息":"开始"})]})]})]}),I?a.jsx(MG,{url:I.url,fileName:I.name,onClose:()=>V(null)}):null]}),document.body):null}const frt=[{icon:Rg,text:"根据我的历史会话,建议我建哪些专属 persona"},{icon:Lw,text:"介绍一下你能帮我做什么"},{icon:DH,text:"clawd 有哪些功能,带我过一遍"}],prt=[{icon:Rg,text:"把昨天所有会话总结成一份日报"},{icon:Lw,text:"看看有哪些没跑完的任务"},{icon:DH,text:"整理一下我的 persona 列表"}],dte="clawd:landing:draft";function fS(){try{const e=window.localStorage.getItem(dte);if(!e)return{byPersona:{}};const t=JSON.parse(e);if(!t||typeof t!="object")return{byPersona:{}};const n=t;return{...typeof n.personaId=="string"?{personaId:n.personaId}:{},byPersona:n.byPersona&&typeof n.byPersona=="object"?n.byPersona:{}}}catch{return{byPersona:{}}}}function hte(e){try{window.localStorage.setItem(dte,JSON.stringify(e))}catch{}}function mrt(){return fS().personaId??null}function AB(e){hte({...fS(),personaId:e})}function grt(e){return fS().byPersona[e]??{}}function xrt(e,t){const n=fS();hte({...n,byPersona:{...n.byPersona,[e]:{...n.byPersona[e],...t}}})}function $B(e,t,n){const r=grt(e);return{model:r.model??t,effort:r.effort??n,permissionMode:r.permissionMode??""}}function vrt({firstRun:e,personas:t,personasLoading:n,initialPersonaId:r,api:s,modelList:i,modes:o=[],configSchema:l=[],defaultsByPersonaId:c={},onCreate:u}){var N,T;const d=e?frt:prt,[h,f]=p.useState(()=>e?r:mrt()??r),m=((N=c[h])==null?void 0:N.model)??"",g=((T=c[h])==null?void 0:T.effort)??"",[x,b]=p.useState(()=>$B(h,m,g)),y=t.find(E=>E.personaId===h)??null,v=w3(s,y!=null&&y.cloud?h:null),w=hS(v)!==null,_=cte(v);p.useEffect(()=>{t.length!==0&&(t.some(E=>E.personaId===h)||f(r))},[t,h,r]),p.useEffect(()=>{b($B(h,m,g))},[h,m,g]);const S=E=>{f(E),AB(E)},k=E=>{b(R=>({...R,...E})),xrt(h,E)},C=E=>{const R=E.trim();!R||w||(AB(h),u({personaId:h,text:R,config:x}))};return a.jsxs("div",{"data-testid":"new-session-landing",className:"flex-1 h-full flex flex-col bg-bg-100",children:[a.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center px-6",children:[a.jsxs("h1",{className:"text-[22px] font-semibold text-text-100 tracking-tight mb-8 text-center",children:["我们应该让",(y==null?void 0:y.name)??"ta","做些什么?"]}),a.jsx("div",{className:"flex flex-wrap gap-2 justify-center max-w-2xl",children:d.map(E=>a.jsxs("button",{type:"button","data-testid":"landing-chip",onClick:()=>C(E.text),disabled:w,..._?{title:_}:{},className:"flex items-center gap-2 rounded-xl border border-border bg-bg-0 px-4 py-3 text-[13px] text-text-200 hover:bg-text-100/5 transition-colors text-left disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bg-0",children:[a.jsx(E.icon,{className:"w-4 h-4 text-accent shrink-0"}),E.text]},E.text))})]}),a.jsx(OG,{...s?{api:s}:{},cwd:"",sessionKey:null,placeholder:"随心输入",onSend:C,disabled:w,className:`border-t-0 pb-8 ${Mx}`,aboveSlot:a.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[a.jsx(ute,{personas:t,loading:n,value:h,onChange:E=>{E&&S(E)},allowNone:!1}),_&&a.jsx("span",{"data-testid":"landing-cloud-gate",className:"min-w-0 truncate text-[11px] text-text-400",title:_,children:_}),_&&(v.connectors!==null||v.error!==null)&&a.jsx("button",{type:"button","data-testid":"landing-cloud-gate-recheck",disabled:v.loading,onClick:()=>void v.reload(),className:"shrink-0 text-[11px] text-accent hover:underline disabled:opacity-50 disabled:no-underline",children:v.loading?"检查中…":"重新检查"})]}),configSlot:a.jsx(fZ,{...i?{modelList:i}:{},modes:o,configSchema:l,model:x.model,effort:x.effort,permissionMode:x.permissionMode,onPatch:E=>k(E)})})]})}function fte(e){const[t,n]=p.useState(null),[r,s]=p.useState(!1),[i,o]=p.useState(!1),[l,c]=p.useState(null),[u,d]=p.useState(!1),[h,f]=p.useState(!1),[m,g]=p.useState(null),[x,b]=p.useState("idle"),y=p.useCallback(async()=>{if(e){s(!0),o(!1);try{n((await e.toolsProbe()).tools)}catch{o(!0)}finally{s(!1)}}},[e]),v=p.useCallback(async()=>{if(e){d(!0),f(!1);try{c((await e.sessionExternalScan()).candidates)}catch{f(!0)}finally{d(!1)}}},[e]),w=p.useCallback(async k=>{if(!e)return;let C=0,N=0;g({done:0,total:k.length,failed:0});for(const T of k){try{await e.sessionImportExternal({tool:T.tool,cwd:T.cwd,toolSessionId:T.toolSessionId,aiLabel:T.label??`${T.tool} 会话`,iconKey:"reading",createdAt:T.createdAt,updatedAt:T.updatedAt})}catch{N+=1}C+=1,g({done:C,total:k.length,failed:N})}},[e]),_=p.useCallback(async()=>{if(e){b("sending");try{await e.onboardingIosInterest(),b("registered")}catch{b("error")}}},[e]),S=p.useCallback(async()=>{e&&await e.onboardingComplete()},[e]);return{probeResult:t,probing:r,probeError:i,probe:y,candidates:l,scanning:u,scanError:h,scan:v,importProgress:m,importSessions:w,iosState:x,registerIos:_,complete:S}}function yrt(e){const t=Ws(),[n,r]=p.useState(!1),[s,i]=p.useState(!1),[o,l]=p.useState(null),c=p.useCallback(async u=>{if(e){r(!0),l(null),i(!1);try{await e.engineConnectPool(u);const d=await e.capabilitiesGet("codex");t.setData("capabilities/codex",()=>d),i(!0)}catch(d){l((d instanceof Error?d.message:String(d)).replace(/^[A-Z_]+: /,""))}finally{r(!1)}}},[e,t]);return{connecting:n,connected:s,error:o,connect:c}}const pte={env:"环境检查",login:"飞书登录",pool:"接入号池",import:"历史会话",mobile:"手机 App",done:"完成"},brt=["env","login","import","mobile","done"].map(e=>pte[e]);function wrt({step:e,steps:t=brt,children:n}){return a.jsx("div",{"data-testid":"onboarding-wizard",className:"h-screen flex flex-col items-center justify-center bg-bg-100 px-6",children:a.jsxs("div",{className:"w-full max-w-2xl",children:[a.jsx("div",{className:"flex items-center gap-2 mb-8 justify-center",children:t.map((r,s)=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:ee("flex items-center gap-1.5 text-[13px] whitespace-nowrap",s===e?"text-text-100 font-medium":s<e?"text-text-300":"text-text-500"),children:[a.jsx("span",{className:ee("w-5 h-5 rounded-full flex items-center justify-center text-[11px]",s<e?"bg-success/15 text-success":s===e?"bg-accent text-accent-contrast":"bg-text-100/5"),children:s<e?a.jsx(Xt,{className:"w-3 h-3"}):s+1}),r]}),s<t.length-1&&a.jsx("div",{className:"w-8 h-px bg-border"})]},r))}),a.jsx("div",{className:"rounded-2xl border border-border bg-bg-0 p-8 shadow-sm",children:n})]})})}function wf({disabled:e,onClick:t,children:n,testid:r}){return a.jsx("button",{type:"button","data-testid":r,disabled:e,onClick:t,className:ee("px-5 py-2 rounded-lg text-sm transition-colors",e?"bg-text-100/5 text-text-500 cursor-not-allowed":"bg-accent text-accent-contrast hover:bg-accent-hover"),children:n})}const _rt="https://static.clawos.chat/clawos/clawd-mobile/prod/clawd-mobile-latest.apk",Srt={claude:{label:"Claude Code",installHint:"npm install -g @anthropic-ai/claude-code"},codex:{label:"Codex",installHint:"npm install -g @openai/codex"},pi:{label:"pi",installHint:"npm install -g @earendil-works/pi-coding-agent"}},mte={INVALID_CODE:"INVALID_CODE"};function krt(e,t){return CT({url:e,authToken:t,clientInfo:jT()})}function Crt(e){return e.startsWith("wss://")?e:e.startsWith("https://")?`wss://${e.slice(8)}`:null}async function Nrt(e,t={}){var l,c;const{url:n,token:r}=NT(e),s=Crt(n);if(!r||!s)throw new Error(mte.INVALID_CODE);const o=(t.makeClient??krt)(s,r);o.start();try{const u=await o.request("whoami"),d=(l=u.owner)==null?void 0:l.id;if(!d)throw new Error("whoami: missing owner.id");return{deviceId:d,displayName:((c=u.owner)==null?void 0:c.displayName)||d,wssUrl:s,token:r}}finally{o.stop()}}function wI({api:e,probe:t=Nrt,className:n}){const[r,s]=p.useState(""),[i,o]=p.useState({kind:"idle"}),l=i.kind==="connecting"||i.kind==="ok",c=async()=>{o({kind:"connecting"});try{const d=await t(r);o({kind:"ok",host:d}),await e.pair(d)}catch(d){const h=d.message;o({kind:"error",message:h===mte.INVALID_CODE?"connect-code 无效——去主机的「设备」面板重新复制":"连接失败:主机不在线或凭证已失效"})}},u=xi(()=>{!r||l||c()});return a.jsxs("div",{className:ee("flex flex-col gap-3 py-1",n),children:[a.jsxs("div",{className:"flex gap-2",children:[a.jsx(br,{placeholder:"wss://xxxx.tunnel.clawos.chat#token=…",value:r,"data-testid":"remote-hosts-code-input",onChange:d=>{s(d.target.value),o({kind:"idle"})},...u,disabled:l}),a.jsx(Be,{onClick:()=>void c(),disabled:!r||l,"data-testid":"remote-hosts-connect-btn",children:i.kind==="connecting"?a.jsx(it,{className:"h-4 w-4 animate-spin"}):"连接"})]}),i.kind==="connecting"&&a.jsx("div",{className:"text-center text-xs text-text-300",children:"正在连接主机…"}),i.kind==="ok"&&a.jsxs("div",{"data-testid":"remote-pair-ok",className:"flex items-center justify-center gap-1.5 text-xs text-emerald-500",children:[a.jsx(Xt,{className:"h-3.5 w-3.5"})," 已连接「",i.host.displayName,"」——即将重启进入主界面"]}),i.kind==="error"&&a.jsxs("div",{"data-testid":"remote-pair-error",className:"flex items-center justify-center gap-1.5 text-xs text-destructive",children:[a.jsx(xa,{className:"h-3.5 w-3.5"})," ",i.message]}),a.jsx("div",{className:"text-center text-[11px] text-text-400",children:"在主机的 clawd 里打开「设备」,复制 connect-code 粘贴到这里"})]})}function jrt({probes:e,probing:t,probeError:n,onRecheck:r,onNext:s,remoteHosts:i,pairProbe:o}){const l=(e??[]).some(d=>d.available),[c,u]=p.useState(!1);return a.jsxs("div",{"data-testid":"onboarding-env-step",children:[a.jsx("h2",{className:"text-xl font-semibold text-text-100 mb-1",children:"欢迎使用 clawd"}),a.jsx("p",{className:"text-sm text-text-400 mb-6",children:"clawd 把你的 AI 编程工具变成一支随叫随到的分身团队。先确认本机环境:"}),a.jsx("div",{className:"space-y-2 mb-6",children:e===null&&n?a.jsxs("div",{"data-testid":"onboarding-env-error",className:"flex items-center gap-2 rounded-lg border border-error/30 bg-error-dim px-4 py-3 text-sm text-text-200",children:[a.jsx(In,{className:"w-4 h-4 text-error"})," 检测失败,请点「重新检测」重试"]}):e===null?a.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border px-4 py-3 text-sm text-text-400",children:[a.jsx(it,{className:"w-4 h-4 animate-spin"})," 正在检测…"]}):e.map(d=>{const h=Srt[d.id];return a.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border px-4 py-3",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[d.available?a.jsx(ci,{className:"w-4.5 h-4.5 text-success"}):a.jsx(sT,{className:"w-4.5 h-4.5 text-text-500"}),a.jsx("span",{className:"text-sm text-text-100",children:h.label})]}),d.available?a.jsx("span",{className:"text-xs text-text-400 font-mono",children:d.version?`v${d.version}`:"已安装"}):a.jsx("code",{className:"text-[11px] text-text-400 bg-text-100/5 rounded px-2 py-1 font-mono",children:h.installHint})]},d.id)})}),e!==null&&!l&&a.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-warning-dim px-4 py-3 mb-6",children:[a.jsx(In,{className:"w-4 h-4 text-warning mt-0.5 shrink-0"}),a.jsx("p",{className:"text-[13px] text-text-200 leading-relaxed",children:"未检测到任何 AI 编程工具。clawd 需要 Claude Code 或 Codex 至少一个才能工作——用上面的命令安装任意一个后点「重新检测」。"})]}),i&&(e!==null||n)&&a.jsx("div",{className:"mb-6",children:l?a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button","data-testid":"onboarding-env-remote-entry","data-variant":"link",onClick:()=>u(d=>!d),className:"text-[13px] text-text-400 hover:text-accent underline underline-offset-2 transition-colors",children:"这台电脑不装工具?连接我的另一台电脑 →"}),c&&a.jsxs("div",{className:"mt-3 rounded-xl border border-accent bg-bg-50 p-4",children:[a.jsx("div",{className:"text-sm font-medium text-text-100",children:"连接我的另一台电脑"}),a.jsx(wI,{api:i,probe:o})]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[a.jsx("div",{className:"h-px flex-1 bg-border"}),a.jsx("span",{className:"text-[11px] text-text-500",children:"或者"}),a.jsx("div",{className:"h-px flex-1 bg-border"})]}),a.jsxs("div",{className:ee("rounded-xl border p-4 transition-colors",c?"border-accent bg-bg-50":"border-border"),children:[a.jsxs("button",{type:"button","data-testid":"onboarding-env-remote-entry","data-variant":"card",onClick:()=>u(d=>!d),className:"group flex w-full items-center gap-3 text-left",children:[a.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-text-100/5 text-text-200 shrink-0",children:a.jsx(rhe,{className:"w-4.5 h-4.5"})}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("div",{className:"text-sm font-medium text-text-100",children:"连接我的另一台电脑"}),a.jsx("div",{className:"mt-0.5 text-xs text-text-400 leading-relaxed",children:"本机不跑 daemon,把这台电脑当作主机的远程界面——主机上的工具、persona、会话全部直接可用,无需在这里装任何东西"})]}),a.jsx(tr,{className:ee("w-4 h-4 text-text-400 shrink-0 transition-transform",c&&"rotate-90")})]}),c&&a.jsx(wI,{api:i,probe:o,className:"mt-2"})]})]})}),a.jsxs("div",{className:"flex justify-end gap-3",children:[(e!==null&&!l||n)&&a.jsxs("button",{type:"button","data-testid":"onboarding-env-recheck",disabled:t,onClick:r,className:"px-4 py-2 rounded-lg text-sm text-text-200 border border-border hover:bg-text-100/5 transition-colors flex items-center gap-1.5",children:[a.jsx(No,{className:"w-3.5 h-3.5"})," 重新检测"]}),a.jsx(wf,{testid:"onboarding-env-next",disabled:!l,onClick:s,children:"继续"})]})]})}function Ert({identity:e,error:t,onLogin:n,onNext:r}){const[s,i]=p.useState(!1),o=e!=null,l=async()=>{i(!0);try{const c=await n();window.open(c,"_blank","noopener")}catch{i(!1)}};return a.jsxs("div",{"data-testid":"onboarding-login-step",children:[a.jsx("h2",{className:"text-xl font-semibold text-text-100 mb-1",children:"用飞书登录"}),a.jsx("p",{className:"text-sm text-text-400 mb-6",children:"登录后才能使用远程连接、跨设备派活和飞书 Bot——你的飞书名字也会成为分身们对你的称呼。"}),a.jsx("div",{className:"rounded-xl border border-border px-6 py-8 mb-6 flex flex-col items-center gap-4",children:o?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"w-14 h-14 rounded-full bg-accent text-accent-contrast flex items-center justify-center text-lg font-medium",children:e.displayName.trim().charAt(0)||"我"}),a.jsxs("div",{className:"text-center",children:[a.jsx("div",{"data-testid":"onboarding-login-name",className:"text-sm font-medium text-text-100",children:e.displayName}),a.jsx("div",{className:"text-xs text-text-400 mt-0.5",children:"已登录"})]})]}):s&&!t?a.jsxs(a.Fragment,{children:[a.jsx(it,{className:"w-8 h-8 text-text-300 animate-spin"}),a.jsx("p",{className:"text-[13px] text-text-400 text-center",children:"已在浏览器打开授权页,完成后会自动回到这里…"})]}):a.jsxs(a.Fragment,{children:[t&&a.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-error-dim px-4 py-2.5 self-stretch",children:[a.jsx(In,{className:"w-4 h-4 text-error mt-0.5 shrink-0"}),a.jsx("p",{"data-testid":"onboarding-login-error",className:"text-[13px] text-text-200",children:t})]}),a.jsx("button",{type:"button","data-testid":"onboarding-login-button",onClick:()=>void l(),className:"px-5 py-2.5 rounded-lg text-sm bg-accent text-accent-contrast hover:bg-accent-hover transition-colors",children:t?"重新登录":"用飞书登录"}),a.jsx("p",{className:"text-xs text-text-500",children:"将在浏览器中打开 TTC 统一认证"})]})}),a.jsx("div",{className:"flex justify-end",children:a.jsx(wf,{testid:"onboarding-login-next",disabled:!o,onClick:r,children:"继续"})})]})}function Irt(e){const t=e.trim();if(!t)return null;const n=/CPA_KEY=["']?([^\s"';]+)/.exec(t);return n?n[1]:/\s/.test(t)?null:t}function Trt({codexVersion:e,portalUrl:t,onConnect:n,connecting:r,connected:s,error:i}){const[o,l]=p.useState(""),[c,u]=p.useState(!1),d=Irt(o),h=!s||c,f=r?"connecting":i?"failed":s?"ok":"ready",m=async()=>{!d||r||(await n(d),l(""),u(!1))};return a.jsx("div",{"data-testid":"pool-connect-card",className:"rounded-lg border border-border bg-surface-card",children:a.jsxs("div",{className:"space-y-3 px-4 py-3",children:[a.jsx("div",{className:"text-[13px] leading-snug text-text-200",children:"Codex 的订阅统一走公司代理,每人一把专属 key——去自助台领一把,贴回来,clawd 帮你把 Codex 指过去。"}),a.jsxs("div",{"data-testid":"pool-codex-row","data-state":f,className:ee("rounded-lg border px-4 py-3",f==="failed"?"border-error/40":"border-border"),children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[f==="ok"?a.jsx(ci,{className:"w-4.5 h-4.5 text-success shrink-0"}):f==="failed"?a.jsx(sT,{className:"w-4.5 h-4.5 text-error shrink-0"}):f==="connecting"?a.jsx(it,{className:"w-4.5 h-4.5 text-text-400 animate-spin shrink-0"}):a.jsx(ci,{className:"w-4.5 h-4.5 text-text-500 shrink-0"}),a.jsx("span",{className:"text-sm text-text-100",children:"Codex"}),e&&a.jsxs("span",{className:"text-xs text-text-400 font-mono",children:["v",e]})]}),a.jsx("span",{className:ee("text-xs shrink-0",f==="ok"?"text-success":f==="failed"?"text-error":"text-text-400"),children:f==="ok"?"已接入":f==="failed"?"接入失败":f==="connecting"?"接入中…":"就绪"})]}),f==="failed"&&i&&a.jsx("div",{"data-testid":"pool-connect-error",className:"mt-1.5 pl-7 text-xs text-error break-all",children:i})]}),h&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[a.jsxs(Be,{type:"button",size:"sm",variant:"outline",onClick:()=>window.open(t,"_blank","noopener"),disabled:r,children:[a.jsx(Ur,{className:"size-3.5 mr-1.5"}),"打开自助台领 key"]}),a.jsx("span",{className:"text-xs text-text-400",children:"飞书登录 → 待管理员开通 → 「生成 API Key」→ 复制"})]}),a.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:g=>{g.preventDefault(),m()},children:[a.jsx(br,{type:"password",autoComplete:"off",placeholder:"把 Key 贴到这里(sk-…,整条一键命令也行)","aria-label":"号池 API Key",value:o,onChange:g=>l(g.target.value),className:"min-w-0 flex-1 font-mono text-xs",disabled:r}),a.jsx(Be,{type:"submit",size:"sm",disabled:r||!d,children:r?a.jsxs(a.Fragment,{children:[a.jsx(it,{className:"size-3.5 mr-1.5 animate-spin"})," 正在接入…"]}):"接入"}),o.trim()&&!d&&a.jsxs("div",{className:"flex items-center gap-1.5 w-full text-xs text-text-400",children:[a.jsx(In,{className:"w-3.5 h-3.5 shrink-0"})," 没看出 key——贴 sk- 开头那串,或者自助台给的整条一键命令"]})]})]}),s&&!c&&a.jsxs("div",{className:"flex items-center gap-2 text-xs text-text-400",children:[a.jsx("span",{children:"已接入。模型选择器里现在能选到号池的模型。"}),a.jsx("button",{type:"button",onClick:()=>u(!0),className:"ml-auto cursor-pointer whitespace-nowrap underline decoration-dotted underline-offset-4 hover:text-accent",children:"换一把 key"})]})]})})}function Rrt({onNext:e,...t}){return a.jsxs("div",{"data-testid":"onboarding-pool-step",children:[a.jsx("h2",{className:"text-xl font-semibold text-text-100 mb-1",children:"接入团队号池"}),a.jsx("p",{className:"text-sm text-text-400 mb-6",children:"在自助台领一把专属 key,clawd 就把本机的 Codex 订阅指到公司代理。「待开通」要等管理员的话,可以先跳过,之后在设置 → 账号里接。"}),a.jsx("div",{className:"mb-6",children:a.jsx(Trt,{...t})}),a.jsxs("div",{className:"flex justify-end items-center gap-4",children:[a.jsx("button",{type:"button","data-testid":"onboarding-pool-skip",onClick:e,disabled:t.connecting,className:"text-[13px] text-text-400 hover:text-text-200 underline underline-offset-2 transition-colors disabled:opacity-50",children:"稍后再说"}),a.jsx(wf,{testid:"onboarding-pool-next",disabled:!t.connected,onClick:e,children:"继续"})]})]})}const Mrt=30*24*60*60*1e3;function gte(e,t=Date.now()){return e.filter(n=>Date.parse(n.updatedAt)>=t-Mrt)}function xte({candidates:e,scanError:t,onRetryScan:n,progress:r,onChoose:s,onNext:i}){const o=(e??[]).filter(f=>f.tool==="claude"),l=(e??[]).filter(f=>f.tool==="codex"),c=new Set((e??[]).map(f=>f.cwd)).size,u=(e??[]).reduce((f,m)=>f===null||m.createdAt<f?m.createdAt:f,null),d=r!==null&&r.done<r.total,h=r!==null&&r.done>=r.total;return a.jsxs("div",{"data-testid":"onboarding-import-step",children:[a.jsx("h2",{className:"text-xl font-semibold text-text-100 mb-1",children:"把过去的会话接进来"}),a.jsx("p",{className:"text-sm text-text-400 mb-6",children:"clawd 可以把你本机已有的 AI 会话关联进侧边栏——不复制不搬家,只建引用。"}),r===null&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"rounded-xl border border-border px-5 py-4 mb-6 space-y-2",children:e===null&&t?a.jsxs("div",{"data-testid":"onboarding-scan-error",className:"flex items-center justify-between gap-2 py-1",children:[a.jsxs("span",{className:"flex items-center gap-2 text-sm text-text-200",children:[a.jsx(In,{className:"w-4 h-4 text-error"})," 扫描失败"]}),a.jsx("button",{type:"button","data-testid":"onboarding-scan-retry",onClick:n,className:"text-[13px] text-accent hover:underline",children:"重试扫描"})]}):e===null?a.jsxs("div",{className:"flex items-center gap-2 text-sm text-text-400 py-2",children:[a.jsx(it,{className:"w-4 h-4 animate-spin"})," 正在扫描本机会话…"]}):e.length===0?a.jsx("div",{className:"text-sm text-text-400 py-2",children:"没发现可关联的历史会话,直接继续就好。"}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-text-200",children:"Claude Code 会话"}),a.jsxs("span",{className:"text-text-100 font-medium",children:[o.length," 个"]})]}),l.length>0&&a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:"text-text-200",children:"Codex 会话"}),a.jsxs("span",{className:"text-text-100 font-medium",children:[l.length," 个"]})]}),a.jsxs("div",{className:"pt-2 border-t border-border text-xs text-text-400",children:["来自 ",c," 个项目",u?` · 最早 ${u.slice(0,7)}`:""]})]})}),e!==null&&e.length>0?a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsx("button",{type:"button","data-testid":"onboarding-import-all",onClick:()=>s("all"),className:"rounded-lg bg-accent text-accent-contrast px-4 py-2.5 text-sm hover:bg-accent-hover transition-colors",children:"全部关联"}),a.jsx("button",{type:"button","data-testid":"onboarding-import-recent30",onClick:()=>s("recent30"),className:"rounded-lg border border-border px-4 py-2.5 text-sm text-text-200 hover:bg-text-100/5 transition-colors",children:"只要最近 30 天"}),a.jsx("button",{type:"button","data-testid":"onboarding-import-skip",onClick:()=>s("skip"),className:"text-[13px] text-text-500 hover:text-text-300 py-1.5 transition-colors",children:"跳过,以后让管家帮我导"})]}):e!==null?a.jsx("div",{className:"flex justify-end",children:a.jsx(wf,{testid:"onboarding-import-next",onClick:i,children:"继续"})}):a.jsx("div",{className:"flex justify-center",children:a.jsx("button",{type:"button","data-testid":"onboarding-import-skip",onClick:()=>s("skip"),className:"text-[13px] text-text-500 hover:text-text-300 py-1.5 transition-colors",children:"跳过,以后让管家帮我导"})})]}),d&&r&&a.jsxs("div",{className:"py-4","data-testid":"onboarding-import-running",children:[a.jsxs("div",{className:"flex items-center justify-between text-sm mb-2",children:[a.jsx("span",{className:"text-text-200",children:"正在关联…"}),a.jsxs("span",{className:"text-text-400 tabular-nums",children:[r.done," / ",r.total]})]}),a.jsx("div",{className:"h-1.5 rounded-full bg-text-100/5 overflow-hidden",children:a.jsx("div",{className:"h-full bg-accent rounded-full transition-all duration-200",style:{width:`${r.total?Math.round(r.done/r.total*100):0}%`}})})]}),h&&r&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"rounded-xl border border-border px-5 py-6 mb-6 flex flex-col items-center gap-2","data-testid":"onboarding-import-done",children:[a.jsx(ci,{className:"w-8 h-8 text-success"}),a.jsxs("div",{className:"text-sm text-text-100",children:["已关联 ",r.done-r.failed," 个会话"]}),r.failed>0&&a.jsxs("div",{className:"text-xs text-text-400",children:[r.failed," 个失败(可稍后让管家重试)"]})]}),a.jsx("div",{className:"flex justify-end",children:a.jsx(wf,{testid:"onboarding-import-next",onClick:i,children:"继续"})})]})]})}function Prt({iosState:e,onIosInterest:t,onNext:n}){const[r,s]=p.useState(null);return p.useEffect(()=>{let i=!1;return ad.toDataURL(_rt,{width:160,margin:1}).then(o=>{i||s(o)}),()=>{i=!0}},[]),a.jsxs("div",{"data-testid":"onboarding-mobile-step",children:[a.jsx("h2",{className:"text-xl font-semibold text-text-100 mb-1",children:"手机上也带着分身团队"}),a.jsx("p",{className:"text-sm text-text-400 mb-6",children:"装个手机端,随时查看任务进展、给分身派活。"}),a.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-6",children:[a.jsxs("div",{className:"rounded-xl border border-border px-5 py-5 flex flex-col items-center gap-3",children:[a.jsx("div",{className:"text-sm font-medium text-text-100",children:"Android"}),r?a.jsx("img",{src:r,alt:"Android 下载二维码",className:"w-[132px] h-[132px] rounded-md"}):a.jsx("div",{className:"w-[132px] h-[132px] rounded-md bg-text-100/5"}),a.jsx("p",{className:"text-xs text-text-400 text-center",children:"手机扫码直接下载安装"})]}),a.jsxs("div",{className:"rounded-xl border border-border px-5 py-5 flex flex-col items-center justify-center gap-3",children:[a.jsx("div",{className:"text-sm font-medium text-text-100",children:"iOS"}),e==="registered"?a.jsxs(a.Fragment,{children:[a.jsx(ci,{className:"w-8 h-8 text-success"}),a.jsxs("p",{"data-testid":"onboarding-ios-registered",className:"text-xs text-text-400 text-center leading-relaxed",children:["已登记。David 会通过飞书联系你,",a.jsx("br",{}),"提供苹果邮箱后即可加入 TestFlight。"]})]}):a.jsxs(a.Fragment,{children:[a.jsxs("p",{className:"text-xs text-text-400 text-center leading-relaxed",children:["iOS 版通过 TestFlight 邀请制分发,",a.jsx("br",{}),"登记后 David 会通过飞书联系你。"]}),e==="error"&&a.jsxs("p",{"data-testid":"onboarding-ios-error",className:"text-[11px] text-error flex items-center gap-1",children:[a.jsx(In,{className:"w-3 h-3"})," 登记失败,请重试"]}),a.jsxs("button",{type:"button","data-testid":"onboarding-ios-register",disabled:e==="sending",onClick:t,className:"px-4 py-2 rounded-lg text-sm border border-border text-text-200 hover:bg-text-100/5 transition-colors flex items-center gap-1.5",children:[e==="sending"&&a.jsx(it,{className:"w-3.5 h-3.5 animate-spin"}),e==="error"?"重试登记":"我想要 iOS 版"]})]})]})]}),a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("button",{type:"button","data-testid":"onboarding-mobile-skip",onClick:n,className:"text-[13px] text-text-500 hover:text-text-300 transition-colors",children:"稍后再说"}),a.jsx(wf,{testid:"onboarding-mobile-next",onClick:n,children:"继续"})]})]})}const Ort=`
|