@fieldwangai/agentflow 0.1.114 → 0.1.115

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.
@@ -39,9 +39,9 @@ var OL=Object.defineProperty;var DL=(e,t,n)=>t in e?OL(e,t,{enumerable:!0,config
39
39
  Error generating stack: `+o.message+`
40
40
  `+o.stack}return{value:e,source:t,stack:s,digest:null}}function vy(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function rx(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var FO=typeof WeakMap=="function"?WeakMap:Map;function LA(e,t,n){n=Zi(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){Fh||(Fh=!0,px=r),rx(e,t)},n}function OA(e,t,n){n=Zi(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var s=t.value;n.payload=function(){return r(s)},n.callback=function(){rx(e,t)}}var o=e.stateNode;return o!==null&&typeof o.componentDidCatch=="function"&&(n.callback=function(){rx(e,t),typeof r!="function"&&(Ko===null?Ko=new Set([this]):Ko.add(this));var a=t.stack;this.componentDidCatch(t.value,{componentStack:a!==null?a:""})}),n}function _N(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new FO;var s=new Set;r.set(t,s)}else s=r.get(t),s===void 0&&(s=new Set,r.set(t,s));s.has(n)||(s.add(n),e=ZO.bind(null,e,t,n),t.then(e,e))}function EN(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function AN(e,t,n,r,s){return e.mode&1?(e.flags|=65536,e.lanes=s,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=Zi(-1,1),t.tag=2,Vo(n,t,1))),n.lanes|=1),e)}var zO=uo.ReactCurrentOwner,Ur=!1;function Mr(e,t,n,r){t.child=e===null?fA(t,null,n,r):bc(t,e.child,n,r)}function PN(e,t,n,r,s){n=n.render;var o=t.ref;return ac(t,s),r=sk(e,t,n,r,o,s),n=ik(),e!==null&&!Ur?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~s,oo(e,t,s)):(Cn&&n&&qb(t),t.flags|=1,Mr(e,t,r,s),t.child)}function IN(e,t,n,r,s){if(e===null){var o=n.type;return typeof o=="function"&&!mk(o)&&o.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=o,DA(e,t,o,r,s)):(e=sh(n.type,null,r,t,t.mode,s),e.ref=t.ref,e.return=t,t.child=e)}if(o=e.child,!(e.lanes&s)){var a=o.memoizedProps;if(n=n.compare,n=n!==null?n:vd,n(a,r)&&e.ref===t.ref)return oo(e,t,s)}return t.flags|=1,e=Uo(o,r),e.ref=t.ref,e.return=t,t.child=e}function DA(e,t,n,r,s){if(e!==null){var o=e.memoizedProps;if(vd(o,r)&&e.ref===t.ref)if(Ur=!1,t.pendingProps=r=o,(e.lanes&s)!==0)e.flags&131072&&(Ur=!0);else return t.lanes=e.lanes,oo(e,t,s)}return sx(e,t,n,r,s)}function FA(e,t,n){var r=t.pendingProps,s=r.children,o=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},hn(Xl,is),is|=n;else{if(!(n&1073741824))return e=o!==null?o.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,hn(Xl,is),is|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=o!==null?o.baseLanes:n,hn(Xl,is),is|=r}else o!==null?(r=o.baseLanes|n,t.memoizedState=null):r=n,hn(Xl,is),is|=r;return Mr(e,t,s,n),t.child}function zA(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function sx(e,t,n,r,s){var o=Xr(n)?Ha:_r.current;return o=wc(t,o),ac(t,s),n=sk(e,t,n,r,o,s),r=ik(),e!==null&&!Ur?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~s,oo(e,t,s)):(Cn&&r&&qb(t),t.flags|=1,Mr(e,t,n,s),t.child)}function RN(e,t,n,r,s){if(Xr(n)){var o=!0;Ah(t)}else o=!1;if(ac(t,s),t.stateNode===null)th(e,t),$A(t,n,r),nx(t,n,r,s),r=!0;else if(e===null){var a=t.stateNode,l=t.memoizedProps;a.props=l;var c=a.context,u=n.contextType;typeof u=="object"&&u!==null?u=Is(u):(u=Xr(n)?Ha:_r.current,u=wc(t,u));var d=n.getDerivedStateFromProps,f=typeof d=="function"||typeof a.getSnapshotBeforeUpdate=="function";f||typeof a.UNSAFE_componentWillReceiveProps!="function"&&typeof a.componentWillReceiveProps!="function"||(l!==r||c!==u)&&CN(t,a,r,u),Po=!1;var p=t.memoizedState;a.state=p,Mh(t,r,a,s),c=t.memoizedState,l!==r||p!==c||Jr.current||Po?(typeof d=="function"&&(tx(t,n,d,r),c=t.memoizedState),(l=Po||jN(t,n,l,r,p,c,u))?(f||typeof a.UNSAFE_componentWillMount!="function"&&typeof a.componentWillMount!="function"||(typeof a.componentWillMount=="function"&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount=="function"&&a.UNSAFE_componentWillMount()),typeof a.componentDidMount=="function"&&(t.flags|=4194308)):(typeof a.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),a.props=r,a.state=c,a.context=u,r=l):(typeof a.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{a=t.stateNode,hA(e,t),l=t.memoizedProps,u=t.type===t.elementType?l:Vs(t.type,l),a.props=u,f=t.pendingProps,p=a.context,c=n.contextType,typeof c=="object"&&c!==null?c=Is(c):(c=Xr(n)?Ha:_r.current,c=wc(t,c));var h=n.getDerivedStateFromProps;(d=typeof h=="function"||typeof a.getSnapshotBeforeUpdate=="function")||typeof a.UNSAFE_componentWillReceiveProps!="function"&&typeof a.componentWillReceiveProps!="function"||(l!==f||p!==c)&&CN(t,a,r,c),Po=!1,p=t.memoizedState,a.state=p,Mh(t,r,a,s);var y=t.memoizedState;l!==f||p!==y||Jr.current||Po?(typeof h=="function"&&(tx(t,n,h,r),y=t.memoizedState),(u=Po||jN(t,n,u,r,p,y,c)||!1)?(d||typeof a.UNSAFE_componentWillUpdate!="function"&&typeof a.componentWillUpdate!="function"||(typeof a.componentWillUpdate=="function"&&a.componentWillUpdate(r,y,c),typeof a.UNSAFE_componentWillUpdate=="function"&&a.UNSAFE_componentWillUpdate(r,y,c)),typeof a.componentDidUpdate=="function"&&(t.flags|=4),typeof a.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof a.componentDidUpdate!="function"||l===e.memoizedProps&&p===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!="function"||l===e.memoizedProps&&p===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=y),a.props=r,a.state=y,a.context=c,r=u):(typeof a.componentDidUpdate!="function"||l===e.memoizedProps&&p===e.memoizedState||(t.flags|=4),typeof a.getSnapshotBeforeUpdate!="function"||l===e.memoizedProps&&p===e.memoizedState||(t.flags|=1024),r=!1)}return ix(e,t,n,r,o,s)}function ix(e,t,n,r,s,o){zA(e,t);var a=(t.flags&128)!==0;if(!r&&!a)return s&&yN(t,n,!1),oo(e,t,o);r=t.stateNode,zO.current=t;var l=a&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&a?(t.child=bc(t,e.child,null,o),t.child=bc(t,null,l,o)):Mr(e,t,l,o),t.memoizedState=r.state,s&&yN(t,n,!0),t.child}function BA(e){var t=e.stateNode;t.pendingContext?gN(e,t.pendingContext,t.pendingContext!==t.context):t.context&&gN(e,t.context,!1),ek(e,t.containerInfo)}function TN(e,t,n,r,s){return xc(),Yb(s),t.flags|=256,Mr(e,t,n,r),t.child}var ox={dehydrated:null,treeContext:null,retryLane:0};function ax(e){return{baseLanes:e,cachePool:null,transitions:null}}function HA(e,t,n){var r=t.pendingProps,s=Rn.current,o=!1,a=(t.flags&128)!==0,l;if((l=a)||(l=e!==null&&e.memoizedState===null?!1:(s&2)!==0),l?(o=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(s|=1),hn(Rn,s&1),e===null)return Zw(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(a=r.children,e=r.fallback,o?(r=t.mode,o=t.child,a={mode:"hidden",children:a},!(r&1)&&o!==null?(o.childLanes=0,o.pendingProps=a):o=Dm(a,r,0,null),e=La(e,r,n,null),o.return=t,e.return=t,o.sibling=e,t.child=o,t.child.memoizedState=ax(n),t.memoizedState=ox,e):lk(t,a));if(s=e.memoizedState,s!==null&&(l=s.dehydrated,l!==null))return BO(e,t,a,r,l,s,n);if(o){o=r.fallback,a=t.mode,s=e.child,l=s.sibling;var c={mode:"hidden",children:r.children};return!(a&1)&&t.child!==s?(r=t.child,r.childLanes=0,r.pendingProps=c,t.deletions=null):(r=Uo(s,c),r.subtreeFlags=s.subtreeFlags&14680064),l!==null?o=Uo(l,o):(o=La(o,a,n,null),o.flags|=2),o.return=t,r.return=t,r.sibling=o,t.child=r,r=o,o=t.child,a=e.child.memoizedState,a=a===null?ax(n):{baseLanes:a.baseLanes|n,cachePool:null,transitions:a.transitions},o.memoizedState=a,o.childLanes=e.childLanes&~n,t.memoizedState=ox,r}return o=e.child,e=o.sibling,r=Uo(o,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function lk(e,t){return t=Dm({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function fp(e,t,n,r){return r!==null&&Yb(r),bc(t,e.child,null,n),e=lk(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function BO(e,t,n,r,s,o,a){if(n)return t.flags&256?(t.flags&=-257,r=vy(Error(Ae(422))),fp(e,t,a,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(o=r.fallback,s=t.mode,r=Dm({mode:"visible",children:r.children},s,0,null),o=La(o,s,a,null),o.flags|=2,r.return=t,o.return=t,r.sibling=o,t.child=r,t.mode&1&&bc(t,e.child,null,a),t.child.memoizedState=ax(a),t.memoizedState=ox,o);if(!(t.mode&1))return fp(e,t,a,null);if(s.data==="$!"){if(r=s.nextSibling&&s.nextSibling.dataset,r)var l=r.dgst;return r=l,o=Error(Ae(419)),r=vy(o,r,void 0),fp(e,t,a,r)}if(l=(a&e.childLanes)!==0,Ur||l){if(r=pr,r!==null){switch(a&-a){case 4:s=2;break;case 16:s=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:s=32;break;case 536870912:s=268435456;break;default:s=0}s=s&(r.suspendedLanes|a)?0:s,s!==0&&s!==o.retryLane&&(o.retryLane=s,io(e,s),Zs(r,e,s,-1))}return hk(),r=vy(Error(Ae(421))),fp(e,t,a,r)}return s.data==="$?"?(t.flags|=128,t.child=e.child,t=eD.bind(null,e),s._reactRetry=t,null):(e=o.treeContext,ls=Wo(s.nextSibling),us=t,Cn=!0,Us=null,e!==null&&(js[Cs++]=Yi,js[Cs++]=Gi,js[Cs++]=Wa,Yi=e.id,Gi=e.overflow,Wa=t),t=lk(t,r.children),t.flags|=4096,t)}function MN(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),ex(e.return,t,n)}function Sy(e,t,n,r,s){var o=e.memoizedState;o===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:s}:(o.isBackwards=t,o.rendering=null,o.renderingStartTime=0,o.last=r,o.tail=n,o.tailMode=s)}function WA(e,t,n){var r=t.pendingProps,s=r.revealOrder,o=r.tail;if(Mr(e,t,r.children,n),r=Rn.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&MN(e,n,t);else if(e.tag===19)MN(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(hn(Rn,r),!(t.mode&1))t.memoizedState=null;else switch(s){case"forwards":for(n=t.child,s=null;n!==null;)e=n.alternate,e!==null&&$h(e)===null&&(s=n),n=n.sibling;n=s,n===null?(s=t.child,t.child=null):(s=n.sibling,n.sibling=null),Sy(t,!1,s,n,o);break;case"backwards":for(n=null,s=t.child,t.child=null;s!==null;){if(e=s.alternate,e!==null&&$h(e)===null){t.child=s;break}e=s.sibling,s.sibling=n,n=s,s=e}Sy(t,!0,n,null,o);break;case"together":Sy(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function th(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function oo(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),Ka|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(Ae(153));if(t.child!==null){for(e=t.child,n=Uo(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=Uo(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function HO(e,t,n){switch(t.tag){case 3:BA(t),xc();break;case 5:mA(t);break;case 1:Xr(t.type)&&Ah(t);break;case 4:ek(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,s=t.memoizedProps.value;hn(Rh,r._currentValue),r._currentValue=s;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(hn(Rn,Rn.current&1),t.flags|=128,null):n&t.child.childLanes?HA(e,t,n):(hn(Rn,Rn.current&1),e=oo(e,t,n),e!==null?e.sibling:null);hn(Rn,Rn.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return WA(e,t,n);t.flags|=128}if(s=t.memoizedState,s!==null&&(s.rendering=null,s.tail=null,s.lastEffect=null),hn(Rn,Rn.current),r)break;return null;case 22:case 23:return t.lanes=0,FA(e,t,n)}return oo(e,t,n)}var VA,lx,KA,qA;VA=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};lx=function(){};KA=function(e,t,n,r){var s=e.memoizedProps;if(s!==r){e=t.stateNode,Ia(ji.current);var o=null;switch(n){case"input":s=Pw(e,s),r=Pw(e,r),o=[];break;case"select":s=$n({},s,{value:void 0}),r=$n({},r,{value:void 0}),o=[];break;case"textarea":s=Tw(e,s),r=Tw(e,r),o=[];break;default:typeof s.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=_h)}$w(n,r);var a;n=null;for(u in s)if(!r.hasOwnProperty(u)&&s.hasOwnProperty(u)&&s[u]!=null)if(u==="style"){var l=s[u];for(a in l)l.hasOwnProperty(a)&&(n||(n={}),n[a]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(md.hasOwnProperty(u)?o||(o=[]):(o=o||[]).push(u,null));for(u in r){var c=r[u];if(l=s!=null?s[u]:void 0,r.hasOwnProperty(u)&&c!==l&&(c!=null||l!=null))if(u==="style")if(l){for(a in l)!l.hasOwnProperty(a)||c&&c.hasOwnProperty(a)||(n||(n={}),n[a]="");for(a in c)c.hasOwnProperty(a)&&l[a]!==c[a]&&(n||(n={}),n[a]=c[a])}else n||(o||(o=[]),o.push(u,n)),n=c;else u==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,l=l?l.__html:void 0,c!=null&&l!==c&&(o=o||[]).push(u,c)):u==="children"?typeof c!="string"&&typeof c!="number"||(o=o||[]).push(u,""+c):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(md.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&bn("scroll",e),o||l===c||(o=[])):(o=o||[]).push(u,c))}n&&(o=o||[]).push("style",n);var u=o;(t.updateQueue=u)&&(t.flags|=4)}};qA=function(e,t,n,r){n!==r&&(t.flags|=4)};function Nu(e,t){if(!Cn)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Sr(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var s=e.child;s!==null;)n|=s.lanes|s.childLanes,r|=s.subtreeFlags&14680064,r|=s.flags&14680064,s.return=e,s=s.sibling;else for(s=e.child;s!==null;)n|=s.lanes|s.childLanes,r|=s.subtreeFlags,r|=s.flags,s.return=e,s=s.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function WO(e,t,n){var r=t.pendingProps;switch(Ub(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Sr(t),null;case 1:return Xr(t.type)&&Eh(),Sr(t),null;case 3:return r=t.stateNode,kc(),vn(Jr),vn(_r),nk(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(up(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Us!==null&&(gx(Us),Us=null))),lx(e,t),Sr(t),null;case 5:tk(t);var s=Ia(_d.current);if(n=t.type,e!==null&&t.stateNode!=null)KA(e,t,n,r,s),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(Ae(166));return Sr(t),null}if(e=Ia(ji.current),up(t)){r=t.stateNode,n=t.type;var o=t.memoizedProps;switch(r[wi]=t,r[jd]=o,e=(t.mode&1)!==0,n){case"dialog":bn("cancel",r),bn("close",r);break;case"iframe":case"object":case"embed":bn("load",r);break;case"video":case"audio":for(s=0;s<zu.length;s++)bn(zu[s],r);break;case"source":bn("error",r);break;case"img":case"image":case"link":bn("error",r),bn("load",r);break;case"details":bn("toggle",r);break;case"input":W0(r,o),bn("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!o.multiple},bn("invalid",r);break;case"textarea":K0(r,o),bn("invalid",r)}$w(n,o),s=null;for(var a in o)if(o.hasOwnProperty(a)){var l=o[a];a==="children"?typeof l=="string"?r.textContent!==l&&(o.suppressHydrationWarning!==!0&&cp(r.textContent,l,e),s=["children",l]):typeof l=="number"&&r.textContent!==""+l&&(o.suppressHydrationWarning!==!0&&cp(r.textContent,l,e),s=["children",""+l]):md.hasOwnProperty(a)&&l!=null&&a==="onScroll"&&bn("scroll",r)}switch(n){case"input":tp(r),V0(r,o,!0);break;case"textarea":tp(r),q0(r);break;case"select":case"option":break;default:typeof o.onClick=="function"&&(r.onclick=_h)}r=s,t.updateQueue=r,r!==null&&(t.flags|=4)}else{a=s.nodeType===9?s:s.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=bE(n)),e==="http://www.w3.org/1999/xhtml"?n==="script"?(e=a.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=a.createElement(n,{is:r.is}):(e=a.createElement(n),n==="select"&&(a=e,r.multiple?a.multiple=!0:r.size&&(a.size=r.size))):e=a.createElementNS(e,n),e[wi]=t,e[jd]=r,VA(e,t,!1,!1),t.stateNode=e;e:{switch(a=Lw(n,r),n){case"dialog":bn("cancel",e),bn("close",e),s=r;break;case"iframe":case"object":case"embed":bn("load",e),s=r;break;case"video":case"audio":for(s=0;s<zu.length;s++)bn(zu[s],e);s=r;break;case"source":bn("error",e),s=r;break;case"img":case"image":case"link":bn("error",e),bn("load",e),s=r;break;case"details":bn("toggle",e),s=r;break;case"input":W0(e,r),s=Pw(e,r),bn("invalid",e);break;case"option":s=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},s=$n({},r,{value:void 0}),bn("invalid",e);break;case"textarea":K0(e,r),s=Tw(e,r),bn("invalid",e);break;default:s=r}$w(n,s),l=s;for(o in l)if(l.hasOwnProperty(o)){var c=l[o];o==="style"?SE(e,c):o==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&kE(e,c)):o==="children"?typeof c=="string"?(n!=="textarea"||c!=="")&&gd(e,c):typeof c=="number"&&gd(e,""+c):o!=="suppressContentEditableWarning"&&o!=="suppressHydrationWarning"&&o!=="autoFocus"&&(md.hasOwnProperty(o)?c!=null&&o==="onScroll"&&bn("scroll",e):c!=null&&Rb(e,o,c,a))}switch(n){case"input":tp(e),V0(e,r,!1);break;case"textarea":tp(e),q0(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Jo(r.value));break;case"select":e.multiple=!!r.multiple,o=r.value,o!=null?rc(e,!!r.multiple,o,!1):r.defaultValue!=null&&rc(e,!!r.multiple,r.defaultValue,!0);break;default:typeof s.onClick=="function"&&(e.onclick=_h)}switch(n){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return Sr(t),null;case 6:if(e&&t.stateNode!=null)qA(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(Ae(166));if(n=Ia(_d.current),Ia(ji.current),up(t)){if(r=t.stateNode,n=t.memoizedProps,r[wi]=t,(o=r.nodeValue!==n)&&(e=us,e!==null))switch(e.tag){case 3:cp(r.nodeValue,n,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&cp(r.nodeValue,n,(e.mode&1)!==0)}o&&(t.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[wi]=t,t.stateNode=r}return Sr(t),null;case 13:if(vn(Rn),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Cn&&ls!==null&&t.mode&1&&!(t.flags&128))uA(),xc(),t.flags|=98560,o=!1;else if(o=up(t),r!==null&&r.dehydrated!==null){if(e===null){if(!o)throw Error(Ae(318));if(o=t.memoizedState,o=o!==null?o.dehydrated:null,!o)throw Error(Ae(317));o[wi]=t}else xc(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Sr(t),o=!1}else Us!==null&&(gx(Us),Us=null),o=!0;if(!o)return t.flags&65536?t:null}return t.flags&128?(t.lanes=n,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||Rn.current&1?nr===0&&(nr=3):hk())),t.updateQueue!==null&&(t.flags|=4),Sr(t),null);case 4:return kc(),lx(e,t),e===null&&Sd(t.stateNode.containerInfo),Sr(t),null;case 10:return Xb(t.type._context),Sr(t),null;case 17:return Xr(t.type)&&Eh(),Sr(t),null;case 19:if(vn(Rn),o=t.memoizedState,o===null)return Sr(t),null;if(r=(t.flags&128)!==0,a=o.rendering,a===null)if(r)Nu(o,!1);else{if(nr!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(a=$h(e),a!==null){for(t.flags|=128,Nu(o,!1),r=a.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=n,n=t.child;n!==null;)o=n,e=r,o.flags&=14680066,a=o.alternate,a===null?(o.childLanes=0,o.lanes=e,o.child=null,o.subtreeFlags=0,o.memoizedProps=null,o.memoizedState=null,o.updateQueue=null,o.dependencies=null,o.stateNode=null):(o.childLanes=a.childLanes,o.lanes=a.lanes,o.child=a.child,o.subtreeFlags=0,o.deletions=null,o.memoizedProps=a.memoizedProps,o.memoizedState=a.memoizedState,o.updateQueue=a.updateQueue,o.type=a.type,e=a.dependencies,o.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),n=n.sibling;return hn(Rn,Rn.current&1|2),t.child}e=e.sibling}o.tail!==null&&Wn()>Sc&&(t.flags|=128,r=!0,Nu(o,!1),t.lanes=4194304)}else{if(!r)if(e=$h(a),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Nu(o,!0),o.tail===null&&o.tailMode==="hidden"&&!a.alternate&&!Cn)return Sr(t),null}else 2*Wn()-o.renderingStartTime>Sc&&n!==1073741824&&(t.flags|=128,r=!0,Nu(o,!1),t.lanes=4194304);o.isBackwards?(a.sibling=t.child,t.child=a):(n=o.last,n!==null?n.sibling=a:t.child=a,o.last=a)}return o.tail!==null?(t=o.tail,o.rendering=t,o.tail=t.sibling,o.renderingStartTime=Wn(),t.sibling=null,n=Rn.current,hn(Rn,r?n&1|2:n&1),t):(Sr(t),null);case 22:case 23:return pk(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?is&1073741824&&(Sr(t),t.subtreeFlags&6&&(t.flags|=8192)):Sr(t),null;case 24:return null;case 25:return null}throw Error(Ae(156,t.tag))}function VO(e,t){switch(Ub(t),t.tag){case 1:return Xr(t.type)&&Eh(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return kc(),vn(Jr),vn(_r),nk(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return tk(t),null;case 13:if(vn(Rn),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(Ae(340));xc()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return vn(Rn),null;case 4:return kc(),null;case 10:return Xb(t.type._context),null;case 22:case 23:return pk(),null;case 24:return null;default:return null}}var pp=!1,Nr=!1,KO=typeof WeakSet=="function"?WeakSet:Set,Qe=null;function Jl(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){Fn(e,t,r)}else n.current=null}function cx(e,t,n){try{n()}catch(r){Fn(e,t,r)}}var $N=!1;function qO(e,t){if(qw=Nh,e=XE(),Kb(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var s=r.anchorOffset,o=r.focusNode;r=r.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break e}var a=0,l=-1,c=-1,u=0,d=0,f=e,p=null;t:for(;;){for(var h;f!==n||s!==0&&f.nodeType!==3||(l=a+s),f!==o||r!==0&&f.nodeType!==3||(c=a+r),f.nodeType===3&&(a+=f.nodeValue.length),(h=f.firstChild)!==null;)p=f,f=h;for(;;){if(f===e)break t;if(p===n&&++u===s&&(l=a),p===o&&++d===r&&(c=a),(h=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=h}n=l===-1||c===-1?null:{start:l,end:c}}else n=null}n=n||{start:0,end:0}}else n=null;for(Uw={focusedElem:e,selectionRange:n},Nh=!1,Qe=t;Qe!==null;)if(t=Qe,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,Qe=e;else for(;Qe!==null;){t=Qe;try{var y=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(y!==null){var k=y.memoizedProps,b=y.memoizedState,g=t.stateNode,v=g.getSnapshotBeforeUpdate(t.elementType===t.type?k:Vs(t.type,k),b);g.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var w=t.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(Ae(163))}}catch(N){Fn(t,t.return,N)}if(e=t.sibling,e!==null){e.return=t.return,Qe=e;break}Qe=t.return}return y=$N,$N=!1,y}function td(e,t,n){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var s=r=r.next;do{if((s.tag&e)===e){var o=s.destroy;s.destroy=void 0,o!==void 0&&cx(t,n,o)}s=s.next}while(s!==r)}}function Lm(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function ux(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function UA(e){var t=e.alternate;t!==null&&(e.alternate=null,UA(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[wi],delete t[jd],delete t[Jw],delete t[EO],delete t[AO])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function YA(e){return e.tag===5||e.tag===3||e.tag===4}function LN(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||YA(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function dx(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=_h));else if(r!==4&&(e=e.child,e!==null))for(dx(e,t,n),e=e.sibling;e!==null;)dx(e,t,n),e=e.sibling}function fx(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(fx(e,t,n),e=e.sibling;e!==null;)fx(e,t,n),e=e.sibling}var mr=null,Ks=!1;function So(e,t,n){for(n=n.child;n!==null;)GA(e,t,n),n=n.sibling}function GA(e,t,n){if(Ni&&typeof Ni.onCommitFiberUnmount=="function")try{Ni.onCommitFiberUnmount(Em,n)}catch{}switch(n.tag){case 5:Nr||Jl(n,t);case 6:var r=mr,s=Ks;mr=null,So(e,t,n),mr=r,Ks=s,mr!==null&&(Ks?(e=mr,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):mr.removeChild(n.stateNode));break;case 18:mr!==null&&(Ks?(e=mr,n=n.stateNode,e.nodeType===8?gy(e.parentNode,n):e.nodeType===1&&gy(e,n),bd(e)):gy(mr,n.stateNode));break;case 4:r=mr,s=Ks,mr=n.stateNode.containerInfo,Ks=!0,So(e,t,n),mr=r,Ks=s;break;case 0:case 11:case 14:case 15:if(!Nr&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){s=r=r.next;do{var o=s,a=o.destroy;o=o.tag,a!==void 0&&(o&2||o&4)&&cx(n,t,a),s=s.next}while(s!==r)}So(e,t,n);break;case 1:if(!Nr&&(Jl(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(l){Fn(n,t,l)}So(e,t,n);break;case 21:So(e,t,n);break;case 22:n.mode&1?(Nr=(r=Nr)||n.memoizedState!==null,So(e,t,n),Nr=r):So(e,t,n);break;default:So(e,t,n)}}function ON(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new KO),t.forEach(function(r){var s=tD.bind(null,e,r);n.has(r)||(n.add(r),r.then(s,s))})}}function Bs(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var s=n[r];try{var o=e,a=t,l=a;e:for(;l!==null;){switch(l.tag){case 5:mr=l.stateNode,Ks=!1;break e;case 3:mr=l.stateNode.containerInfo,Ks=!0;break e;case 4:mr=l.stateNode.containerInfo,Ks=!0;break e}l=l.return}if(mr===null)throw Error(Ae(160));GA(o,a,s),mr=null,Ks=!1;var c=s.alternate;c!==null&&(c.return=null),s.return=null}catch(u){Fn(s,t,u)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)JA(t,e),t=t.sibling}function JA(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Bs(t,e),di(e),r&4){try{td(3,e,e.return),Lm(3,e)}catch(k){Fn(e,e.return,k)}try{td(5,e,e.return)}catch(k){Fn(e,e.return,k)}}break;case 1:Bs(t,e),di(e),r&512&&n!==null&&Jl(n,n.return);break;case 5:if(Bs(t,e),di(e),r&512&&n!==null&&Jl(n,n.return),e.flags&32){var s=e.stateNode;try{gd(s,"")}catch(k){Fn(e,e.return,k)}}if(r&4&&(s=e.stateNode,s!=null)){var o=e.memoizedProps,a=n!==null?n.memoizedProps:o,l=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{l==="input"&&o.type==="radio"&&o.name!=null&&wE(s,o),Lw(l,a);var u=Lw(l,o);for(a=0;a<c.length;a+=2){var d=c[a],f=c[a+1];d==="style"?SE(s,f):d==="dangerouslySetInnerHTML"?kE(s,f):d==="children"?gd(s,f):Rb(s,d,f,u)}switch(l){case"input":Iw(s,o);break;case"textarea":xE(s,o);break;case"select":var p=s._wrapperState.wasMultiple;s._wrapperState.wasMultiple=!!o.multiple;var h=o.value;h!=null?rc(s,!!o.multiple,h,!1):p!==!!o.multiple&&(o.defaultValue!=null?rc(s,!!o.multiple,o.defaultValue,!0):rc(s,!!o.multiple,o.multiple?[]:"",!1))}s[jd]=o}catch(k){Fn(e,e.return,k)}}break;case 6:if(Bs(t,e),di(e),r&4){if(e.stateNode===null)throw Error(Ae(162));s=e.stateNode,o=e.memoizedProps;try{s.nodeValue=o}catch(k){Fn(e,e.return,k)}}break;case 3:if(Bs(t,e),di(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{bd(t.containerInfo)}catch(k){Fn(e,e.return,k)}break;case 4:Bs(t,e),di(e);break;case 13:Bs(t,e),di(e),s=e.child,s.flags&8192&&(o=s.memoizedState!==null,s.stateNode.isHidden=o,!o||s.alternate!==null&&s.alternate.memoizedState!==null||(dk=Wn())),r&4&&ON(e);break;case 22:if(d=n!==null&&n.memoizedState!==null,e.mode&1?(Nr=(u=Nr)||d,Bs(t,e),Nr=u):Bs(t,e),di(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!d&&e.mode&1)for(Qe=e,d=e.child;d!==null;){for(f=Qe=d;Qe!==null;){switch(p=Qe,h=p.child,p.tag){case 0:case 11:case 14:case 15:td(4,p,p.return);break;case 1:Jl(p,p.return);var y=p.stateNode;if(typeof y.componentWillUnmount=="function"){r=p,n=p.return;try{t=r,y.props=t.memoizedProps,y.state=t.memoizedState,y.componentWillUnmount()}catch(k){Fn(r,n,k)}}break;case 5:Jl(p,p.return);break;case 22:if(p.memoizedState!==null){FN(f);continue}}h!==null?(h.return=p,Qe=h):FN(f)}d=d.sibling}e:for(d=null,f=e;;){if(f.tag===5){if(d===null){d=f;try{s=f.stateNode,u?(o=s.style,typeof o.setProperty=="function"?o.setProperty("display","none","important"):o.display="none"):(l=f.stateNode,c=f.memoizedProps.style,a=c!=null&&c.hasOwnProperty("display")?c.display:null,l.style.display=vE("display",a))}catch(k){Fn(e,e.return,k)}}}else if(f.tag===6){if(d===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(k){Fn(e,e.return,k)}}else if((f.tag!==22&&f.tag!==23||f.memoizedState===null||f===e)&&f.child!==null){f.child.return=f,f=f.child;continue}if(f===e)break e;for(;f.sibling===null;){if(f.return===null||f.return===e)break e;d===f&&(d=null),f=f.return}d===f&&(d=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:Bs(t,e),di(e),r&4&&ON(e);break;case 21:break;default:Bs(t,e),di(e)}}function di(e){var t=e.flags;if(t&2){try{e:{for(var n=e.return;n!==null;){if(YA(n)){var r=n;break e}n=n.return}throw Error(Ae(160))}switch(r.tag){case 5:var s=r.stateNode;r.flags&32&&(gd(s,""),r.flags&=-33);var o=LN(e);fx(e,o,s);break;case 3:case 4:var a=r.stateNode.containerInfo,l=LN(e);dx(e,l,a);break;default:throw Error(Ae(161))}}catch(c){Fn(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function UO(e,t,n){Qe=e,XA(e)}function XA(e,t,n){for(var r=(e.mode&1)!==0;Qe!==null;){var s=Qe,o=s.child;if(s.tag===22&&r){var a=s.memoizedState!==null||pp;if(!a){var l=s.alternate,c=l!==null&&l.memoizedState!==null||Nr;l=pp;var u=Nr;if(pp=a,(Nr=c)&&!u)for(Qe=s;Qe!==null;)a=Qe,c=a.child,a.tag===22&&a.memoizedState!==null?zN(s):c!==null?(c.return=a,Qe=c):zN(s);for(;o!==null;)Qe=o,XA(o),o=o.sibling;Qe=s,pp=l,Nr=u}DN(e)}else s.subtreeFlags&8772&&o!==null?(o.return=s,Qe=o):DN(e)}}function DN(e){for(;Qe!==null;){var t=Qe;if(t.flags&8772){var n=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:Nr||Lm(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!Nr)if(n===null)r.componentDidMount();else{var s=t.elementType===t.type?n.memoizedProps:Vs(t.type,n.memoizedProps);r.componentDidUpdate(s,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var o=t.updateQueue;o!==null&&vN(t,o,r);break;case 3:var a=t.updateQueue;if(a!==null){if(n=null,t.child!==null)switch(t.child.tag){case 5:n=t.child.stateNode;break;case 1:n=t.child.stateNode}vN(t,a,n)}break;case 5:var l=t.stateNode;if(n===null&&t.flags&4){n=l;var c=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&n.focus();break;case"img":c.src&&(n.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var u=t.alternate;if(u!==null){var d=u.memoizedState;if(d!==null){var f=d.dehydrated;f!==null&&bd(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(Ae(163))}Nr||t.flags&512&&ux(t)}catch(p){Fn(t,t.return,p)}}if(t===e){Qe=null;break}if(n=t.sibling,n!==null){n.return=t.return,Qe=n;break}Qe=t.return}}function FN(e){for(;Qe!==null;){var t=Qe;if(t===e){Qe=null;break}var n=t.sibling;if(n!==null){n.return=t.return,Qe=n;break}Qe=t.return}}function zN(e){for(;Qe!==null;){var t=Qe;try{switch(t.tag){case 0:case 11:case 15:var n=t.return;try{Lm(4,t)}catch(c){Fn(t,n,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var s=t.return;try{r.componentDidMount()}catch(c){Fn(t,s,c)}}var o=t.return;try{ux(t)}catch(c){Fn(t,o,c)}break;case 5:var a=t.return;try{ux(t)}catch(c){Fn(t,a,c)}}}catch(c){Fn(t,t.return,c)}if(t===e){Qe=null;break}var l=t.sibling;if(l!==null){l.return=t.return,Qe=l;break}Qe=t.return}}var YO=Math.ceil,Dh=uo.ReactCurrentDispatcher,ck=uo.ReactCurrentOwner,Ps=uo.ReactCurrentBatchConfig,Kt=0,pr=null,Yn=null,gr=0,is=0,Xl=oa(0),nr=0,Id=null,Ka=0,Om=0,uk=0,nd=null,Kr=null,dk=0,Sc=1/0,Ki=null,Fh=!1,px=null,Ko=null,hp=!1,Oo=null,zh=0,rd=0,hx=null,nh=-1,rh=0;function Lr(){return Kt&6?Wn():nh!==-1?nh:nh=Wn()}function qo(e){return e.mode&1?Kt&2&&gr!==0?gr&-gr:IO.transition!==null?(rh===0&&(rh=$E()),rh):(e=sn,e!==0||(e=window.event,e=e===void 0?16:HE(e.type)),e):1}function Zs(e,t,n,r){if(50<rd)throw rd=0,hx=null,Error(Ae(185));nf(e,n,r),(!(Kt&2)||e!==pr)&&(e===pr&&(!(Kt&2)&&(Om|=n),nr===4&&To(e,gr)),Qr(e,r),n===1&&Kt===0&&!(t.mode&1)&&(Sc=Wn()+500,Tm&&aa()))}function Qr(e,t){var n=e.callbackNode;I2(e,t);var r=Sh(e,e===pr?gr:0);if(r===0)n!==null&&G0(n),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(n!=null&&G0(n),t===1)e.tag===0?PO(BN.bind(null,e)):aA(BN.bind(null,e)),CO(function(){!(Kt&6)&&aa()}),n=null;else{switch(LE(r)){case 1:n=Ob;break;case 4:n=TE;break;case 16:n=vh;break;case 536870912:n=ME;break;default:n=vh}n=iP(n,QA.bind(null,e))}e.callbackPriority=t,e.callbackNode=n}}function QA(e,t){if(nh=-1,rh=0,Kt&6)throw Error(Ae(327));var n=e.callbackNode;if(lc()&&e.callbackNode!==n)return null;var r=Sh(e,e===pr?gr:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Bh(e,r);else{t=r;var s=Kt;Kt|=2;var o=eP();(pr!==e||gr!==t)&&(Ki=null,Sc=Wn()+500,$a(e,t));do try{XO();break}catch(l){ZA(e,l)}while(!0);Jb(),Dh.current=o,Kt=s,Yn!==null?t=0:(pr=null,gr=0,t=nr)}if(t!==0){if(t===2&&(s=Bw(e),s!==0&&(r=s,t=mx(e,s))),t===1)throw n=Id,$a(e,0),To(e,r),Qr(e,Wn()),n;if(t===6)To(e,r);else{if(s=e.current.alternate,!(r&30)&&!GO(s)&&(t=Bh(e,r),t===2&&(o=Bw(e),o!==0&&(r=o,t=mx(e,o))),t===1))throw n=Id,$a(e,0),To(e,r),Qr(e,Wn()),n;switch(e.finishedWork=s,e.finishedLanes=r,t){case 0:case 1:throw Error(Ae(345));case 2:Sa(e,Kr,Ki);break;case 3:if(To(e,r),(r&130023424)===r&&(t=dk+500-Wn(),10<t)){if(Sh(e,0)!==0)break;if(s=e.suspendedLanes,(s&r)!==r){Lr(),e.pingedLanes|=e.suspendedLanes&s;break}e.timeoutHandle=Gw(Sa.bind(null,e,Kr,Ki),t);break}Sa(e,Kr,Ki);break;case 4:if(To(e,r),(r&4194240)===r)break;for(t=e.eventTimes,s=-1;0<r;){var a=31-Qs(r);o=1<<a,a=t[a],a>s&&(s=a),r&=~o}if(r=s,r=Wn()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*YO(r/1960))-r,10<r){e.timeoutHandle=Gw(Sa.bind(null,e,Kr,Ki),r);break}Sa(e,Kr,Ki);break;case 5:Sa(e,Kr,Ki);break;default:throw Error(Ae(329))}}}return Qr(e,Wn()),e.callbackNode===n?QA.bind(null,e):null}function mx(e,t){var n=nd;return e.current.memoizedState.isDehydrated&&($a(e,t).flags|=256),e=Bh(e,t),e!==2&&(t=Kr,Kr=n,t!==null&&gx(t)),e}function gx(e){Kr===null?Kr=e:Kr.push.apply(Kr,e)}function GO(e){for(var t=e;;){if(t.flags&16384){var n=t.updateQueue;if(n!==null&&(n=n.stores,n!==null))for(var r=0;r<n.length;r++){var s=n[r],o=s.getSnapshot;s=s.value;try{if(!ti(o(),s))return!1}catch{return!1}}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function To(e,t){for(t&=~uk,t&=~Om,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var n=31-Qs(t),r=1<<n;e[n]=-1,t&=~r}}function BN(e){if(Kt&6)throw Error(Ae(327));lc();var t=Sh(e,0);if(!(t&1))return Qr(e,Wn()),null;var n=Bh(e,t);if(e.tag!==0&&n===2){var r=Bw(e);r!==0&&(t=r,n=mx(e,r))}if(n===1)throw n=Id,$a(e,0),To(e,t),Qr(e,Wn()),n;if(n===6)throw Error(Ae(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,Sa(e,Kr,Ki),Qr(e,Wn()),null}function fk(e,t){var n=Kt;Kt|=1;try{return e(t)}finally{Kt=n,Kt===0&&(Sc=Wn()+500,Tm&&aa())}}function qa(e){Oo!==null&&Oo.tag===0&&!(Kt&6)&&lc();var t=Kt;Kt|=1;var n=Ps.transition,r=sn;try{if(Ps.transition=null,sn=1,e)return e()}finally{sn=r,Ps.transition=n,Kt=t,!(Kt&6)&&aa()}}function pk(){is=Xl.current,vn(Xl)}function $a(e,t){e.finishedWork=null,e.finishedLanes=0;var n=e.timeoutHandle;if(n!==-1&&(e.timeoutHandle=-1,jO(n)),Yn!==null)for(n=Yn.return;n!==null;){var r=n;switch(Ub(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Eh();break;case 3:kc(),vn(Jr),vn(_r),nk();break;case 5:tk(r);break;case 4:kc();break;case 13:vn(Rn);break;case 19:vn(Rn);break;case 10:Xb(r.type._context);break;case 22:case 23:pk()}n=n.return}if(pr=e,Yn=e=Uo(e.current,null),gr=is=t,nr=0,Id=null,uk=Om=Ka=0,Kr=nd=null,Pa!==null){for(t=0;t<Pa.length;t++)if(n=Pa[t],r=n.interleaved,r!==null){n.interleaved=null;var s=r.next,o=n.pending;if(o!==null){var a=o.next;o.next=s,r.next=a}n.pending=r}Pa=null}return e}function ZA(e,t){do{var n=Yn;try{if(Jb(),Zp.current=Oh,Lh){for(var r=Mn.memoizedState;r!==null;){var s=r.queue;s!==null&&(s.pending=null),r=r.next}Lh=!1}if(Va=0,ur=tr=Mn=null,ed=!1,Ed=0,ck.current=null,n===null||n.return===null){nr=1,Id=t,Yn=null;break}e:{var o=e,a=n.return,l=n,c=t;if(t=gr,l.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,d=l,f=d.tag;if(!(d.mode&1)&&(f===0||f===11||f===15)){var p=d.alternate;p?(d.updateQueue=p.updateQueue,d.memoizedState=p.memoizedState,d.lanes=p.lanes):(d.updateQueue=null,d.memoizedState=null)}var h=EN(a);if(h!==null){h.flags&=-257,AN(h,a,l,o,t),h.mode&1&&_N(o,u,t),t=h,c=u;var y=t.updateQueue;if(y===null){var k=new Set;k.add(c),t.updateQueue=k}else y.add(c);break e}else{if(!(t&1)){_N(o,u,t),hk();break e}c=Error(Ae(426))}}else if(Cn&&l.mode&1){var b=EN(a);if(b!==null){!(b.flags&65536)&&(b.flags|=256),AN(b,a,l,o,t),Yb(vc(c,l));break e}}o=c=vc(c,l),nr!==4&&(nr=2),nd===null?nd=[o]:nd.push(o),o=a;do{switch(o.tag){case 3:o.flags|=65536,t&=-t,o.lanes|=t;var g=LA(o,c,t);kN(o,g);break e;case 1:l=c;var v=o.type,w=o.stateNode;if(!(o.flags&128)&&(typeof v.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(Ko===null||!Ko.has(w)))){o.flags|=65536,t&=-t,o.lanes|=t;var N=OA(o,l,t);kN(o,N);break e}}o=o.return}while(o!==null)}nP(n)}catch(j){t=j,Yn===n&&n!==null&&(Yn=n=n.return);continue}break}while(!0)}function eP(){var e=Dh.current;return Dh.current=Oh,e===null?Oh:e}function hk(){(nr===0||nr===3||nr===2)&&(nr=4),pr===null||!(Ka&268435455)&&!(Om&268435455)||To(pr,gr)}function Bh(e,t){var n=Kt;Kt|=2;var r=eP();(pr!==e||gr!==t)&&(Ki=null,$a(e,t));do try{JO();break}catch(s){ZA(e,s)}while(!0);if(Jb(),Kt=n,Dh.current=r,Yn!==null)throw Error(Ae(261));return pr=null,gr=0,nr}function JO(){for(;Yn!==null;)tP(Yn)}function XO(){for(;Yn!==null&&!v2();)tP(Yn)}function tP(e){var t=sP(e.alternate,e,is);e.memoizedProps=e.pendingProps,t===null?nP(e):Yn=t,ck.current=null}function nP(e){var t=e;do{var n=t.alternate;if(e=t.return,t.flags&32768){if(n=VO(n,t),n!==null){n.flags&=32767,Yn=n;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{nr=6,Yn=null;return}}else if(n=WO(n,t,is),n!==null){Yn=n;return}if(t=t.sibling,t!==null){Yn=t;return}Yn=t=e}while(t!==null);nr===0&&(nr=5)}function Sa(e,t,n){var r=sn,s=Ps.transition;try{Ps.transition=null,sn=1,QO(e,t,n,r)}finally{Ps.transition=s,sn=r}return null}function QO(e,t,n,r){do lc();while(Oo!==null);if(Kt&6)throw Error(Ae(327));n=e.finishedWork;var s=e.finishedLanes;if(n===null)return null;if(e.finishedWork=null,e.finishedLanes=0,n===e.current)throw Error(Ae(177));e.callbackNode=null,e.callbackPriority=0;var o=n.lanes|n.childLanes;if(R2(e,o),e===pr&&(Yn=pr=null,gr=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||hp||(hp=!0,iP(vh,function(){return lc(),null})),o=(n.flags&15990)!==0,n.subtreeFlags&15990||o){o=Ps.transition,Ps.transition=null;var a=sn;sn=1;var l=Kt;Kt|=4,ck.current=null,qO(e,n),JA(n,e),wO(Uw),Nh=!!qw,Uw=qw=null,e.current=n,UO(n),S2(),Kt=l,sn=a,Ps.transition=o}else e.current=n;if(hp&&(hp=!1,Oo=e,zh=s),o=e.pendingLanes,o===0&&(Ko=null),C2(n.stateNode),Qr(e,Wn()),t!==null)for(r=e.onRecoverableError,n=0;n<t.length;n++)s=t[n],r(s.value,{componentStack:s.stack,digest:s.digest});if(Fh)throw Fh=!1,e=px,px=null,e;return zh&1&&e.tag!==0&&lc(),o=e.pendingLanes,o&1?e===hx?rd++:(rd=0,hx=e):rd=0,aa(),null}function lc(){if(Oo!==null){var e=LE(zh),t=Ps.transition,n=sn;try{if(Ps.transition=null,sn=16>e?16:e,Oo===null)var r=!1;else{if(e=Oo,Oo=null,zh=0,Kt&6)throw Error(Ae(331));var s=Kt;for(Kt|=4,Qe=e.current;Qe!==null;){var o=Qe,a=o.child;if(Qe.flags&16){var l=o.deletions;if(l!==null){for(var c=0;c<l.length;c++){var u=l[c];for(Qe=u;Qe!==null;){var d=Qe;switch(d.tag){case 0:case 11:case 15:td(8,d,o)}var f=d.child;if(f!==null)f.return=d,Qe=f;else for(;Qe!==null;){d=Qe;var p=d.sibling,h=d.return;if(UA(d),d===u){Qe=null;break}if(p!==null){p.return=h,Qe=p;break}Qe=h}}}var y=o.alternate;if(y!==null){var k=y.child;if(k!==null){y.child=null;do{var b=k.sibling;k.sibling=null,k=b}while(k!==null)}}Qe=o}}if(o.subtreeFlags&2064&&a!==null)a.return=o,Qe=a;else e:for(;Qe!==null;){if(o=Qe,o.flags&2048)switch(o.tag){case 0:case 11:case 15:td(9,o,o.return)}var g=o.sibling;if(g!==null){g.return=o.return,Qe=g;break e}Qe=o.return}}var v=e.current;for(Qe=v;Qe!==null;){a=Qe;var w=a.child;if(a.subtreeFlags&2064&&w!==null)w.return=a,Qe=w;else e:for(a=v;Qe!==null;){if(l=Qe,l.flags&2048)try{switch(l.tag){case 0:case 11:case 15:Lm(9,l)}}catch(j){Fn(l,l.return,j)}if(l===a){Qe=null;break e}var N=l.sibling;if(N!==null){N.return=l.return,Qe=N;break e}Qe=l.return}}if(Kt=s,aa(),Ni&&typeof Ni.onPostCommitFiberRoot=="function")try{Ni.onPostCommitFiberRoot(Em,e)}catch{}r=!0}return r}finally{sn=n,Ps.transition=t}}return!1}function HN(e,t,n){t=vc(n,t),t=LA(e,t,1),e=Vo(e,t,1),t=Lr(),e!==null&&(nf(e,1,t),Qr(e,t))}function Fn(e,t,n){if(e.tag===3)HN(e,e,n);else for(;t!==null;){if(t.tag===3){HN(t,e,n);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Ko===null||!Ko.has(r))){e=vc(n,e),e=OA(t,e,1),t=Vo(t,e,1),e=Lr(),t!==null&&(nf(t,1,e),Qr(t,e));break}}t=t.return}}function ZO(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),t=Lr(),e.pingedLanes|=e.suspendedLanes&n,pr===e&&(gr&n)===n&&(nr===4||nr===3&&(gr&130023424)===gr&&500>Wn()-dk?$a(e,0):uk|=n),Qr(e,t)}function rP(e,t){t===0&&(e.mode&1?(t=sp,sp<<=1,!(sp&130023424)&&(sp=4194304)):t=1);var n=Lr();e=io(e,t),e!==null&&(nf(e,t,n),Qr(e,n))}function eD(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),rP(e,n)}function tD(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,s=e.memoizedState;s!==null&&(n=s.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(Ae(314))}r!==null&&r.delete(t),rP(e,n)}var sP;sP=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Jr.current)Ur=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return Ur=!1,HO(e,t,n);Ur=!!(e.flags&131072)}else Ur=!1,Cn&&t.flags&1048576&&lA(t,Ih,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;th(e,t),e=t.pendingProps;var s=wc(t,_r.current);ac(t,n),s=sk(null,t,r,e,s,n);var o=ik();return t.flags|=1,typeof s=="object"&&s!==null&&typeof s.render=="function"&&s.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Xr(r)?(o=!0,Ah(t)):o=!1,t.memoizedState=s.state!==null&&s.state!==void 0?s.state:null,Zb(t),s.updater=$m,t.stateNode=s,s._reactInternals=t,nx(t,r,e,n),t=ix(null,t,r,!0,o,n)):(t.tag=0,Cn&&o&&qb(t),Mr(null,t,s,n),t=t.child),t;case 16:r=t.elementType;e:{switch(th(e,t),e=t.pendingProps,s=r._init,r=s(r._payload),t.type=r,s=t.tag=rD(r),e=Vs(r,e),s){case 0:t=sx(null,t,r,e,n);break e;case 1:t=RN(null,t,r,e,n);break e;case 11:t=PN(null,t,r,e,n);break e;case 14:t=IN(null,t,r,Vs(r.type,e),n);break e}throw Error(Ae(306,r,""))}return t;case 0:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Vs(r,s),sx(e,t,r,s,n);case 1:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Vs(r,s),RN(e,t,r,s,n);case 3:e:{if(BA(t),e===null)throw Error(Ae(387));r=t.pendingProps,o=t.memoizedState,s=o.element,hA(e,t),Mh(t,r,null,n);var a=t.memoizedState;if(r=a.element,o.isDehydrated)if(o={element:r,isDehydrated:!1,cache:a.cache,pendingSuspenseBoundaries:a.pendingSuspenseBoundaries,transitions:a.transitions},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){s=vc(Error(Ae(423)),t),t=TN(e,t,r,n,s);break e}else if(r!==s){s=vc(Error(Ae(424)),t),t=TN(e,t,r,n,s);break e}else for(ls=Wo(t.stateNode.containerInfo.firstChild),us=t,Cn=!0,Us=null,n=fA(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(xc(),r===s){t=oo(e,t,n);break e}Mr(e,t,r,n)}t=t.child}return t;case 5:return mA(t),e===null&&Zw(t),r=t.type,s=t.pendingProps,o=e!==null?e.memoizedProps:null,a=s.children,Yw(r,s)?a=null:o!==null&&Yw(r,o)&&(t.flags|=32),zA(e,t),Mr(e,t,a,n),t.child;case 6:return e===null&&Zw(t),null;case 13:return HA(e,t,n);case 4:return ek(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=bc(t,null,r,n):Mr(e,t,r,n),t.child;case 11:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Vs(r,s),PN(e,t,r,s,n);case 7:return Mr(e,t,t.pendingProps,n),t.child;case 8:return Mr(e,t,t.pendingProps.children,n),t.child;case 12:return Mr(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,s=t.pendingProps,o=t.memoizedProps,a=s.value,hn(Rh,r._currentValue),r._currentValue=a,o!==null)if(ti(o.value,a)){if(o.children===s.children&&!Jr.current){t=oo(e,t,n);break e}}else for(o=t.child,o!==null&&(o.return=t);o!==null;){var l=o.dependencies;if(l!==null){a=o.child;for(var c=l.firstContext;c!==null;){if(c.context===r){if(o.tag===1){c=Zi(-1,n&-n),c.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var d=u.pending;d===null?c.next=c:(c.next=d.next,d.next=c),u.pending=c}}o.lanes|=n,c=o.alternate,c!==null&&(c.lanes|=n),ex(o.return,n,t),l.lanes|=n;break}c=c.next}}else if(o.tag===10)a=o.type===t.type?null:o.child;else if(o.tag===18){if(a=o.return,a===null)throw Error(Ae(341));a.lanes|=n,l=a.alternate,l!==null&&(l.lanes|=n),ex(a,n,t),a=o.sibling}else a=o.child;if(a!==null)a.return=o;else for(a=o;a!==null;){if(a===t){a=null;break}if(o=a.sibling,o!==null){o.return=a.return,a=o;break}a=a.return}o=a}Mr(e,t,s.children,n),t=t.child}return t;case 9:return s=t.type,r=t.pendingProps.children,ac(t,n),s=Is(s),r=r(s),t.flags|=1,Mr(e,t,r,n),t.child;case 14:return r=t.type,s=Vs(r,t.pendingProps),s=Vs(r.type,s),IN(e,t,r,s,n);case 15:return DA(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,s=t.pendingProps,s=t.elementType===r?s:Vs(r,s),th(e,t),t.tag=1,Xr(r)?(e=!0,Ah(t)):e=!1,ac(t,n),$A(t,r,s),nx(t,r,s,n),ix(null,t,r,!0,e,n);case 19:return WA(e,t,n);case 22:return FA(e,t,n)}throw Error(Ae(156,t.tag))};function iP(e,t){return RE(e,t)}function nD(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function As(e,t,n,r){return new nD(e,t,n,r)}function mk(e){return e=e.prototype,!(!e||!e.isReactComponent)}function rD(e){if(typeof e=="function")return mk(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Mb)return 11;if(e===$b)return 14}return 2}function Uo(e,t){var n=e.alternate;return n===null?(n=As(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function sh(e,t,n,r,s,o){var a=2;if(r=e,typeof e=="function")mk(e)&&(a=1);else if(typeof e=="string")a=5;else e:switch(e){case Bl:return La(n.children,s,o,t);case Tb:a=8,s|=8;break;case Cw:return e=As(12,n,t,s|2),e.elementType=Cw,e.lanes=o,e;case _w:return e=As(13,n,t,s),e.elementType=_w,e.lanes=o,e;case Ew:return e=As(19,n,t,s),e.elementType=Ew,e.lanes=o,e;case mE:return Dm(n,s,o,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case pE:a=10;break e;case hE:a=9;break e;case Mb:a=11;break e;case $b:a=14;break e;case Ao:a=16,r=null;break e}throw Error(Ae(130,e==null?e:typeof e,""))}return t=As(a,n,t,s),t.elementType=e,t.type=r,t.lanes=o,t}function La(e,t,n,r){return e=As(7,e,r,t),e.lanes=n,e}function Dm(e,t,n,r){return e=As(22,e,r,t),e.elementType=mE,e.lanes=n,e.stateNode={isHidden:!1},e}function Ny(e,t,n){return e=As(6,e,null,t),e.lanes=n,e}function jy(e,t,n){return t=As(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function sD(e,t,n,r,s){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=iy(0),this.expirationTimes=iy(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=iy(0),this.identifierPrefix=r,this.onRecoverableError=s,this.mutableSourceEagerHydrationData=null}function gk(e,t,n,r,s,o,a,l,c){return e=new sD(e,t,n,l,c),t===1?(t=1,o===!0&&(t|=8)):t=0,o=As(3,null,null,t),e.current=o,o.stateNode=e,o.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},Zb(o),e}function iD(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:zl,key:r==null?null:""+r,children:e,containerInfo:t,implementation:n}}function oP(e){if(!e)return Xo;e=e._reactInternals;e:{if(il(e)!==e||e.tag!==1)throw Error(Ae(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(Xr(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(Ae(171))}if(e.tag===1){var n=e.type;if(Xr(n))return oA(e,n,t)}return t}function aP(e,t,n,r,s,o,a,l,c){return e=gk(n,r,!0,e,s,o,a,l,c),e.context=oP(null),n=e.current,r=Lr(),s=qo(n),o=Zi(r,s),o.callback=t??null,Vo(n,o,s),e.current.lanes=s,nf(e,s,r),Qr(e,r),e}function Fm(e,t,n,r){var s=t.current,o=Lr(),a=qo(s);return n=oP(n),t.context===null?t.context=n:t.pendingContext=n,t=Zi(o,a),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=Vo(s,t,a),e!==null&&(Zs(e,s,a,o),Qp(e,s,a)),a}function Hh(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 5:return e.child.stateNode;default:return e.child.stateNode}}function WN(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function yk(e,t){WN(e,t),(e=e.alternate)&&WN(e,t)}function oD(){return null}var lP=typeof reportError=="function"?reportError:function(e){console.error(e)};function wk(e){this._internalRoot=e}zm.prototype.render=wk.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(Ae(409));Fm(e,t,null,null)};zm.prototype.unmount=wk.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;qa(function(){Fm(null,e,null,null)}),t[so]=null}};function zm(e){this._internalRoot=e}zm.prototype.unstable_scheduleHydration=function(e){if(e){var t=FE();e={blockedOn:null,target:e,priority:t};for(var n=0;n<Ro.length&&t!==0&&t<Ro[n].priority;n++);Ro.splice(n,0,e),n===0&&BE(e)}};function xk(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Bm(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function VN(){}function aD(e,t,n,r,s){if(s){if(typeof r=="function"){var o=r;r=function(){var u=Hh(a);o.call(u)}}var a=aP(t,r,e,0,null,!1,!1,"",VN);return e._reactRootContainer=a,e[so]=a.current,Sd(e.nodeType===8?e.parentNode:e),qa(),a}for(;s=e.lastChild;)e.removeChild(s);if(typeof r=="function"){var l=r;r=function(){var u=Hh(c);l.call(u)}}var c=gk(e,0,!1,null,null,!1,!1,"",VN);return e._reactRootContainer=c,e[so]=c.current,Sd(e.nodeType===8?e.parentNode:e),qa(function(){Fm(t,c,n,r)}),c}function Hm(e,t,n,r,s){var o=n._reactRootContainer;if(o){var a=o;if(typeof s=="function"){var l=s;s=function(){var c=Hh(a);l.call(c)}}Fm(t,a,e,s)}else a=aD(n,t,e,s,r);return Hh(a)}OE=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var n=Fu(t.pendingLanes);n!==0&&(Db(t,n|1),Qr(t,Wn()),!(Kt&6)&&(Sc=Wn()+500,aa()))}break;case 13:qa(function(){var r=io(e,1);if(r!==null){var s=Lr();Zs(r,e,1,s)}}),yk(e,1)}};Fb=function(e){if(e.tag===13){var t=io(e,134217728);if(t!==null){var n=Lr();Zs(t,e,134217728,n)}yk(e,134217728)}};DE=function(e){if(e.tag===13){var t=qo(e),n=io(e,t);if(n!==null){var r=Lr();Zs(n,e,t,r)}yk(e,t)}};FE=function(){return sn};zE=function(e,t){var n=sn;try{return sn=e,t()}finally{sn=n}};Dw=function(e,t,n){switch(t){case"input":if(Iw(e,n),t=n.name,n.type==="radio"&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll("input[name="+JSON.stringify(""+t)+'][type="radio"]'),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var s=Rm(r);if(!s)throw Error(Ae(90));yE(r),Iw(r,s)}}}break;case"textarea":xE(e,n);break;case"select":t=n.value,t!=null&&rc(e,!!n.multiple,t,!1)}};CE=fk;_E=qa;var lD={usingClientEntryPoint:!1,Events:[sf,Kl,Rm,NE,jE,fk]},ju={findFiberByHostInstance:Aa,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},cD={bundleType:ju.bundleType,version:ju.version,rendererPackageName:ju.rendererPackageName,rendererConfig:ju.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:uo.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=PE(e),e===null?null:e.stateNode},findFiberByHostInstance:ju.findFiberByHostInstance||oD,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var mp=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!mp.isDisabled&&mp.supportsFiber)try{Em=mp.inject(cD),Ni=mp}catch{}}hs.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=lD;hs.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!xk(t))throw Error(Ae(200));return iD(e,t,null,n)};hs.createRoot=function(e,t){if(!xk(e))throw Error(Ae(299));var n=!1,r="",s=lP;return t!=null&&(t.unstable_strictMode===!0&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(s=t.onRecoverableError)),t=gk(e,1,!1,null,null,n,!1,r,s),e[so]=t.current,Sd(e.nodeType===8?e.parentNode:e),new wk(t)};hs.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(Ae(188)):(e=Object.keys(e).join(","),Error(Ae(268,e)));return e=PE(t),e=e===null?null:e.stateNode,e};hs.flushSync=function(e){return qa(e)};hs.hydrate=function(e,t,n){if(!Bm(t))throw Error(Ae(200));return Hm(null,e,t,!0,n)};hs.hydrateRoot=function(e,t,n){if(!xk(e))throw Error(Ae(405));var r=n!=null&&n.hydratedSources||null,s=!1,o="",a=lP;if(n!=null&&(n.unstable_strictMode===!0&&(s=!0),n.identifierPrefix!==void 0&&(o=n.identifierPrefix),n.onRecoverableError!==void 0&&(a=n.onRecoverableError)),t=aP(t,null,e,1,n??null,s,!1,o,a),e[so]=t.current,Sd(e),r)for(e=0;e<r.length;e++)n=r[e],s=n._getVersion,s=s(n._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[n,s]:t.mutableSourceEagerHydrationData.push(n,s);return new zm(t)};hs.render=function(e,t,n){if(!Bm(t))throw Error(Ae(200));return Hm(null,e,t,!1,n)};hs.unmountComponentAtNode=function(e){if(!Bm(e))throw Error(Ae(40));return e._reactRootContainer?(qa(function(){Hm(null,null,e,!1,function(){e._reactRootContainer=null,e[so]=null})}),!0):!1};hs.unstable_batchedUpdates=fk;hs.unstable_renderSubtreeIntoContainer=function(e,t,n,r){if(!Bm(n))throw Error(Ae(200));if(e==null||e._reactInternals===void 0)throw Error(Ae(38));return Hm(e,t,n,!1,r)};hs.version="18.3.1-next-f1338f8080-20240426";function cP(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(cP)}catch(e){console.error(e)}}cP(),cE.exports=hs;var cr=cE.exports,KN=cr;Nw.createRoot=KN.createRoot,Nw.hydrateRoot=KN.hydrateRoot;const uP=m.createContext(null);function yx(e){let t=e||"/";return t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t||"/"}function uD(){const e=yx(window.location.pathname);return e==="/"?(window.history.replaceState({},"","/projects"),"/projects"):e}function dD({children:e}){const[t,n]=m.useState(uD);m.useEffect(()=>{const o=()=>n(yx(window.location.pathname));return window.addEventListener("popstate",o),()=>window.removeEventListener("popstate",o)},[]);const r=m.useCallback(o=>{const a=o.startsWith("/")?o:`/${o}`;let l;try{l=new URL(a,window.location.origin)}catch{l=new URL("/",window.location.origin)}const c=yx(l.pathname),u=l.search||"";window.history.pushState({},"",c+u),n(c)},[]),s=m.useMemo(()=>({path:t,navigate:r}),[t,r]);return i.jsx(uP.Provider,{value:s,children:e})}function si(){const e=m.useContext(uP);if(!e)throw new Error("useRoute must be used within RouteProvider");return e}function fD(){if(console&&console.warn){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];typeof t[0]=="string"&&(t[0]=`react-i18next:: ${t[0]}`),console.warn(...t)}}const qN={};function wx(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];typeof t[0]=="string"&&qN[t[0]]||(typeof t[0]=="string"&&(qN[t[0]]=new Date),fD(...t))}const dP=(e,t)=>()=>{if(e.isInitialized)t();else{const n=()=>{setTimeout(()=>{e.off("initialized",n)},0),t()};e.on("initialized",n)}};function UN(e,t,n){e.loadNamespaces(t,dP(e,n))}function YN(e,t,n,r){typeof n=="string"&&(n=[n]),n.forEach(s=>{e.options.ns.indexOf(s)<0&&e.options.ns.push(s)}),e.loadLanguages(t,dP(e,r))}function pD(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const r=t.languages[0],s=t.options?t.options.fallbackLng:!1,o=t.languages[t.languages.length-1];if(r.toLowerCase()==="cimode")return!0;const a=(l,c)=>{const u=t.services.backendConnector.state[`${l}|${c}`];return u===-1||u===2};return n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&t.services.backendConnector.backend&&t.isLanguageChangingTo&&!a(t.isLanguageChangingTo,e)?!1:!!(t.hasResourceBundle(r,e)||!t.services.backendConnector.backend||t.options.resources&&!t.options.partialBundledLanguages||a(r,e)&&(!s||a(o,e)))}function hD(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};return!t.languages||!t.languages.length?(wx("i18n.languages were undefined or empty",t.languages),!0):t.options.ignoreJSONStructure!==void 0?t.hasLoadedNamespace(e,{lng:n.lng,precheck:(s,o)=>{if(n.bindI18n&&n.bindI18n.indexOf("languageChanging")>-1&&s.services.backendConnector.backend&&s.isLanguageChangingTo&&!o(s.isLanguageChangingTo,e))return!1}}):pD(e,t,n)}const mD=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,gD={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},yD=e=>gD[e],wD=e=>e.replace(mD,yD);let xx={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:wD};function xD(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};xx={...xx,...e}}function bD(){return xx}let fP;function kD(e){fP=e}function vD(){return fP}const SD={type:"3rdParty",init(e){xD(e.options.react),kD(e)}},ND=m.createContext();class jD{constructor(){this.usedNamespaces={}}addUsedNamespaces(t){t.forEach(n=>{this.usedNamespaces[n]||(this.usedNamespaces[n]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const CD=(e,t)=>{const n=m.useRef();return m.useEffect(()=>{n.current=e},[e,t]),n.current};function Fr(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const{i18n:n}=t,{i18n:r,defaultNS:s}=m.useContext(ND)||{},o=n||r||vD();if(o&&!o.reportNamespaces&&(o.reportNamespaces=new jD),!o){wx("You will need to pass in an i18next instance by using initReactI18next");const w=(j,C)=>typeof C=="string"?C:C&&typeof C=="object"&&typeof C.defaultValue=="string"?C.defaultValue:Array.isArray(j)?j[j.length-1]:j,N=[w,{},!1];return N.t=w,N.i18n={},N.ready=!1,N}o.options.react&&o.options.react.wait!==void 0&&wx("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...bD(),...o.options.react,...t},{useSuspense:l,keyPrefix:c}=a;let u=e||s||o.options&&o.options.defaultNS;u=typeof u=="string"?[u]:u||["translation"],o.reportNamespaces.addUsedNamespaces&&o.reportNamespaces.addUsedNamespaces(u);const d=(o.isInitialized||o.initializedStoreOnce)&&u.every(w=>hD(w,o,a));function f(){return o.getFixedT(t.lng||null,a.nsMode==="fallback"?u:u[0],c)}const[p,h]=m.useState(f);let y=u.join();t.lng&&(y=`${t.lng}${y}`);const k=CD(y),b=m.useRef(!0);m.useEffect(()=>{const{bindI18n:w,bindI18nStore:N}=a;b.current=!0,!d&&!l&&(t.lng?YN(o,t.lng,u,()=>{b.current&&h(f)}):UN(o,u,()=>{b.current&&h(f)})),d&&k&&k!==y&&b.current&&h(f);function j(){b.current&&h(f)}return w&&o&&o.on(w,j),N&&o&&o.store.on(N,j),()=>{b.current=!1,w&&o&&w.split(" ").forEach(C=>o.off(C,j)),N&&o&&N.split(" ").forEach(C=>o.store.off(C,j))}},[o,y]);const g=m.useRef(!0);m.useEffect(()=>{b.current&&!g.current&&h(f),g.current=!1},[o,c]);const v=[p,o,d];if(v.t=p,v.i18n=o,v.ready=d,d||!d&&!l)return v;throw new Promise(w=>{t.lng?YN(o,t.lng,u,()=>w()):UN(o,u,()=>w())})}const pP="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2032%2032'%20fill='none'%20role='img'%20aria-label='AgentFlow'%3e%3ctitle%3eAgentFlow%3c/title%3e%3crect%20width='32'%20height='32'%20rx='9'%20fill='%23131313'/%3e%3crect%20x='4.5'%20y='11'%20width='10.5'%20height='10'%20rx='3'%20fill='%232a2a2a'%20stroke='%237c4dff'%20stroke-width='1.2'/%3e%3cpath%20d='M15.25%2014.25C17.8%2012.2%2019.2%209.8%2022.25%209.25'%20stroke='%23cdbdff'%20stroke-width='1.65'%20stroke-linecap='round'%20/%3e%3cpath%20d='M15.25%2017.75C17.8%2019.8%2019.2%2022.2%2022.25%2022.75'%20stroke='%237c4dff'%20stroke-width='1.65'%20stroke-linecap='round'%20opacity='0.92'%20/%3e%3crect%20x='21.75'%20y='6'%20width='7.25'%20height='7'%20rx='2.25'%20fill='%23353534'%20stroke='%23e8deff'%20stroke-width='0.95'%20opacity='0.95'/%3e%3crect%20x='21.75'%20y='19'%20width='7.25'%20height='7'%20rx='2.25'%20fill='%23353534'%20stroke='%239ecaff'%20stroke-width='0.95'%20opacity='0.9'/%3e%3c/svg%3e",_D=[{to:"/projects",labelKey:"common:nav.projects",icon:"folder_open"},{to:"/workspaces",label:"知识库",icon:"folder_managed"},{to:"/nodes",labelKey:"common:nav.nodes",icon:"account_tree"},{to:"/my-flows",labelKey:"common:nav.myFlows",icon:"schema"},{to:"/skills",labelKey:"common:nav.skills",icon:"extension"},{to:"/mcps",labelKey:"common:nav.mcps",icon:"hub"},{to:"/node-studio",label:"节点编辑器",icon:"draw"},{to:"/schedules",label:"定时任务",icon:"event_busy"},{to:"/admin/usage",label:"管理看板",icon:"query_stats",adminOnly:!0},{to:"/feedback",labelKey:"common:nav.feedback",icon:"rate_review"},{to:"/settings",labelKey:"common:nav.settings",icon:"settings"}],ED=[{href:"https://agentflow-hub.com",icon:"hub",labelKey:"common:links.hub"},{href:"https://docs.agentflow-hub.com",icon:"menu_book",labelKey:"common:links.docs"},{href:"https://github.com/pproject-github/agentflow",icon:"code",labelKey:"common:links.github"}];function AD(e,t){return t==="/projects"?e==="/projects"||e==="/":t==="/nodes"?e==="/nodes"||e==="/my-nodes":e===t||e.startsWith(t+"/")}function PD({authUser:e,onLogout:t}){const{path:n,navigate:r}=si(),{t:s}=Fr(),[o,a]=m.useState(!1);return m.useEffect(()=>{let l=!1;return fetch("/api/ui-context").then(c=>c.json()).then(c=>{l||a(!!c.hideCommunityLinks)}).catch(()=>{}),()=>{l=!0}},[]),i.jsxs("aside",{className:"af-sidebar","aria-label":s("flow:sidebar.mainNav"),children:[i.jsxs("div",{className:"af-brand",children:[i.jsx("div",{className:"af-brand-mark","aria-hidden":!0,children:i.jsx("img",{src:pP,alt:"",width:"36",height:"36",decoding:"async"})}),i.jsxs("div",{children:[i.jsx("h1",{className:"af-brand-title",children:"Agentflow"}),i.jsx("p",{className:"af-brand-tag",children:"Orchestration Engine"})]})]}),i.jsx("nav",{className:"af-nav",children:_D.filter(l=>!l.adminOnly||(e==null?void 0:e.isAdmin)).map(l=>i.jsxs("button",{type:"button",className:"af-nav-link"+(AD(n,l.to)?" af-nav-link--active":""),onClick:()=>r(l.to),children:[i.jsx("span",{className:"material-symbols-outlined",children:l.icon}),i.jsx("span",{children:l.label||s(l.labelKey)})]},l.to))}),i.jsxs("div",{className:"af-sidebar-footer",children:[i.jsxs("div",{className:"af-sidebar-user",title:(e==null?void 0:e.username)||(e==null?void 0:e.userId)||"",children:[i.jsx("span",{className:"material-symbols-outlined",children:"person"}),i.jsx("span",{children:(e==null?void 0:e.username)||(e==null?void 0:e.userId)||""}),e!=null&&e.isAdmin?i.jsx("span",{className:"af-sidebar-admin-badge",children:"Admin"}):null,i.jsx("button",{type:"button",className:"af-sidebar-logout",onClick:t,"aria-label":"Logout",title:"Logout",children:i.jsx("span",{className:"material-symbols-outlined",children:"logout"})})]}),!o&&ED.map(l=>{const c=s(l.labelKey);return i.jsx("a",{className:"af-sidebar-ext",href:l.href,target:"_blank",rel:"noopener noreferrer","aria-label":c,title:c,children:i.jsx("span",{className:"material-symbols-outlined",children:l.icon})},l.href)})]})]})}const ID="agentflow.pipelineRecent",RD=15;function TD(e){try{const t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function MD(){if(typeof localStorage>"u")return[];const e=localStorage.getItem(ID);return e?TD(e).filter(t=>t&&typeof t.flowId=="string"&&(t.flowSource==="user"||t.flowSource==="builtin"||t.flowSource==="admin"||t.flowSource==="workspace")&&t.kind==="opened"&&typeof t.at=="number"):[]}function $D(e,t){const n=e.filter(r=>r.id===t);return n.length===0||n.some(r=>(r.source??"user")==="user")?"user":n.some(r=>r.source==="workspace")?"workspace":n.some(r=>r.source==="admin")?"admin":n.some(r=>r.source==="builtin")?"builtin":n[0].source??"user"}function GN(e,t){const n=Date.now(),r=Math.max(0,n-e),s=Math.floor(r/1e3);if(s<60)return t("flow:time.justNow");const o=Math.floor(s/60);if(o<60)return t("flow:time.minutesAgo",{n:o});const a=Math.floor(o/60);if(a<24)return t("flow:time.hoursAgo",{n:a});const l=new Date(e),c=new Date,u=new Date(c);if(u.setDate(u.getDate()-1),l.toDateString()===u.toDateString())return t("flow:time.yesterday");const d=Math.floor(a/24);return d<7?t("flow:time.daysAgo",{n:d}):`${l.getMonth()+1}/${l.getDate()}`}function LD(e,t,n){const r=[];for(const s of e)!s||typeof s.flowId!="string"||typeof s.at!="number"||r.push({flowId:s.flowId,flowSource:$D(n,s.flowId),kind:"executed",at:s.at});for(const s of t)r.push({flowId:s.flowId,flowSource:s.flowSource,kind:"opened",at:s.at});return r.sort((s,o)=>o.at-s.at),r.slice(0,RD)}var os=Uint8Array,Ql=Uint16Array,OD=Int32Array,hP=new os([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),mP=new os([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),DD=new os([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),gP=function(e,t){for(var n=new Ql(31),r=0;r<31;++r)n[r]=t+=1<<e[r-1];for(var s=new OD(n[30]),r=1;r<30;++r)for(var o=n[r];o<n[r+1];++o)s[o]=o-n[r]<<5|r;return{b:n,r:s}},yP=gP(hP,2),wP=yP.b,FD=yP.r;wP[28]=258,FD[258]=28;var zD=gP(mP,0),BD=zD.b,bx=new Ql(32768);for(var kn=0;kn<32768;++kn){var No=(kn&43690)>>1|(kn&21845)<<1;No=(No&52428)>>2|(No&13107)<<2,No=(No&61680)>>4|(No&3855)<<4,bx[kn]=((No&65280)>>8|(No&255)<<8)>>1}var sd=function(e,t,n){for(var r=e.length,s=0,o=new Ql(t);s<r;++s)e[s]&&++o[e[s]-1];var a=new Ql(t);for(s=1;s<t;++s)a[s]=a[s-1]+o[s-1]<<1;var l;if(n){l=new Ql(1<<t);var c=15-t;for(s=0;s<r;++s)if(e[s])for(var u=s<<4|e[s],d=t-e[s],f=a[e[s]-1]++<<d,p=f|(1<<d)-1;f<=p;++f)l[bx[f]>>c]=u}else for(l=new Ql(r),s=0;s<r;++s)e[s]&&(l[s]=bx[a[e[s]-1]++]>>15-e[s]);return l},af=new os(288);for(var kn=0;kn<144;++kn)af[kn]=8;for(var kn=144;kn<256;++kn)af[kn]=9;for(var kn=256;kn<280;++kn)af[kn]=7;for(var kn=280;kn<288;++kn)af[kn]=8;var xP=new os(32);for(var kn=0;kn<32;++kn)xP[kn]=5;var HD=sd(af,9,1),WD=sd(xP,5,1),Cy=function(e){for(var t=e[0],n=1;n<e.length;++n)e[n]>t&&(t=e[n]);return t},Hs=function(e,t,n){var r=t/8|0;return(e[r]|e[r+1]<<8)>>(t&7)&n},_y=function(e,t){var n=t/8|0;return(e[n]|e[n+1]<<8|e[n+2]<<16)>>(t&7)},VD=function(e){return(e+7)/8|0},bk=function(e,t,n){return(t==null||t<0)&&(t=0),(n==null||n>e.length)&&(n=e.length),new os(e.subarray(t,n))},KD=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Ns=function(e,t,n){var r=new Error(t||KD[e]);if(r.code=e,Error.captureStackTrace&&Error.captureStackTrace(r,Ns),!n)throw r;return r},qD=function(e,t,n,r){var s=e.length,o=r?r.length:0;if(!s||t.f&&!t.l)return n||new os(0);var a=!n,l=a||t.i!=2,c=t.i;a&&(n=new os(s*3));var u=function(ce){var de=n.length;if(ce>de){var me=new os(Math.max(de*2,ce));me.set(n),n=me}},d=t.f||0,f=t.p||0,p=t.b||0,h=t.l,y=t.d,k=t.m,b=t.n,g=s*8;do{if(!h){d=Hs(e,f,1);var v=Hs(e,f+1,3);if(f+=3,v)if(v==1)h=HD,y=WD,k=9,b=5;else if(v==2){var C=Hs(e,f,31)+257,P=Hs(e,f+10,15)+4,I=C+Hs(e,f+5,31)+1;f+=14;for(var z=new os(I),$=new os(19),L=0;L<P;++L)$[DD[L]]=Hs(e,f+L*3,7);f+=P*3;for(var F=Cy($),O=(1<<F)-1,M=sd($,F,1),L=0;L<I;){var K=M[Hs(e,f,O)];f+=K&15;var w=K>>4;if(w<16)z[L++]=w;else{var H=0,D=0;for(w==16?(D=3+Hs(e,f,3),f+=2,H=z[L-1]):w==17?(D=3+Hs(e,f,7),f+=3):w==18&&(D=11+Hs(e,f,127),f+=7);D--;)z[L++]=H}}var T=z.subarray(0,C),W=z.subarray(C);k=Cy(T),b=Cy(W),h=sd(T,k,1),y=sd(W,b,1)}else Ns(1);else{var w=VD(f)+4,N=e[w-4]|e[w-3]<<8,j=w+N;if(j>s){c&&Ns(0);break}l&&u(p+N),n.set(e.subarray(w,j),p),t.b=p+=N,t.p=f=j*8,t.f=d;continue}if(f>g){c&&Ns(0);break}}l&&u(p+131072);for(var E=(1<<k)-1,Q=(1<<b)-1,V=f;;V=f){var H=h[_y(e,f)&E],B=H>>4;if(f+=H&15,f>g){c&&Ns(0);break}if(H||Ns(2),B<256)n[p++]=B;else if(B==256){V=f,h=null;break}else{var se=B-254;if(B>264){var L=B-257,ue=hP[L];se=Hs(e,f,(1<<ue)-1)+wP[L],f+=ue}var G=y[_y(e,f)&Q],ee=G>>4;G||Ns(3),f+=G&15;var W=BD[ee];if(ee>3){var ue=mP[ee];W+=_y(e,f)&(1<<ue)-1,f+=ue}if(f>g){c&&Ns(0);break}l&&u(p+131072);var te=p+se;if(p<W){var ne=o-W,Z=Math.min(W,te);for(ne+p<0&&Ns(3);p<Z;++p)n[p]=r[ne+p]}for(;p<te;++p)n[p]=n[p-W]}}t.l=h,t.p=V,t.b=p,t.f=d,h&&(d=1,t.m=k,t.d=y,t.n=b)}while(!d);return p!=n.length&&a?bk(n,0,p):n.subarray(0,p)},UD=new os(0),xi=function(e,t){return e[t]|e[t+1]<<8},Ys=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},Ey=function(e,t){return Ys(e,t)+Ys(e,t+4)*4294967296};function YD(e,t){return qD(e,{i:2},t&&t.out,t&&t.dictionary)}var kx=typeof TextDecoder<"u"&&new TextDecoder,GD=0;try{kx.decode(UD,{stream:!0}),GD=1}catch{}var JD=function(e){for(var t="",n=0;;){var r=e[n++],s=(r>127)+(r>223)+(r>239);if(n+s>e.length)return{s:t,r:bk(e,n-1)};s?s==3?(r=((r&15)<<18|(e[n++]&63)<<12|(e[n++]&63)<<6|e[n++]&63)-65536,t+=String.fromCharCode(55296|r>>10,56320|r&1023)):s&1?t+=String.fromCharCode((r&31)<<6|e[n++]&63):t+=String.fromCharCode((r&15)<<12|(e[n++]&63)<<6|e[n++]&63):t+=String.fromCharCode(r)}};function XD(e,t){if(t){for(var n="",r=0;r<e.length;r+=16384)n+=String.fromCharCode.apply(null,e.subarray(r,r+16384));return n}else{if(kx)return kx.decode(e);var s=JD(e),o=s.s,n=s.r;return n.length&&Ns(8),o}}var QD=function(e,t){return t+30+xi(e,t+26)+xi(e,t+28)},ZD=function(e,t,n){var r=xi(e,t+28),s=XD(e.subarray(t+46,t+46+r),!(xi(e,t+8)&2048)),o=t+46+r,a=Ys(e,t+20),l=n&&a==4294967295?eF(e,o):[a,Ys(e,t+24),Ys(e,t+42)],c=l[0],u=l[1],d=l[2];return[xi(e,t+10),c,u,s,o+xi(e,t+30)+xi(e,t+32),d]},eF=function(e,t){for(;xi(e,t)!=1;t+=4+xi(e,t+2));return[Ey(e,t+12),Ey(e,t+4),Ey(e,t+20)]};function tF(e,t){for(var n={},r=e.length-22;Ys(e,r)!=101010256;--r)(!r||e.length-r>65558)&&Ns(13);var s=xi(e,r+8);if(!s)return{};var o=Ys(e,r+16),a=o==4294967295||s==65535;if(a){var l=Ys(e,r-12);a=Ys(e,l)==101075792,a&&(s=Ys(e,l+32),o=Ys(e,l+48))}for(var c=0;c<s;++c){var u=ZD(e,o,a),d=u[0],f=u[1],p=u[2],h=u[3],y=u[4],k=u[5],b=QD(e,k);o=y,d?d==8?n[h]=YD(e.subarray(b,b+f),{out:new os(p)}):Ns(14,"unknown compression type "+d):n[h]=bk(e,b,b+f)}return n}const nF=8*1024*1024,rF=500;function sF(e){if(e==null||typeof e!="string")return null;let t=e.replace(/\\/g,"/").replace(/^\uFEFF/,"");for(;t.startsWith("/");)t=t.slice(1);if(!t||t.includes("\0")||/^[a-zA-Z]:/.test(t))return null;const n=t.split("/").filter(r=>r.length>0);for(const r of n)if(r==="."||r==="..")return null;return n.join("/")}function iF(e){return e?e.split("/").some(n=>n==="__MACOSX"||n.startsWith("._")):!0}function oF(e){const t=e.toLowerCase();if(t==="flow.yaml"||t==="flow.yml")return"";const n="/flow.yaml",r="/flow.yml";let s=null;if(t.endsWith(n))s=e.slice(0,-n.length);else if(t.endsWith(r))s=e.slice(0,-r.length);else return null;return s.includes("/")?null:s}const aF=/^[a-zA-Z][a-zA-Z0-9_-]*$/;async function lF(e){try{const t=new Uint8Array(await e.arrayBuffer()),n=tF(t),r=new Map;let s=0,o=0;for(const[c,u]of Object.entries(n)){if(c.endsWith("/"))continue;const d=sF(c);if(!d||iF(d))continue;const f=(u==null?void 0:u.length)??0;if(s+=f,s>nF||(o+=1,o>rF))return null;r.set(d,f)}if(r.size===0)return null;const a=new Set;for(const c of r.keys()){const u=oF(c);u!==null&&a.add(u)}if(a.size!==1)return null;const[l]=[...a];if(l==="")return null;for(const c of r.keys())if(!(c===l||c.startsWith(`${l}/`)))return null;return aF.test(l)?l:null}catch{return null}}const Ay=/^[a-zA-Z][a-zA-Z0-9_-]*$/;function cF({file:e,onClose:t,onImported:n}){const{t:r}=Fr(),s=m.useId(),o=m.useRef(null),a=m.useRef(null),[l,c]=m.useState(""),[u,d]=m.useState("user"),[f,p]=m.useState(!1),[h,y]=m.useState(""),[k,b]=m.useState(null),g=k??e;m.useEffect(()=>{const j=requestAnimationFrame(()=>{var C;return(C=o.current)==null?void 0:C.focus()});return()=>cancelAnimationFrame(j)},[]),m.useEffect(()=>{let j=!1;return(async()=>{const C=g.name||"",P=C.toLowerCase();let I="";if(P.endsWith(".zip")){if(I=await lF(g)||"",!I){const z=C.replace(/\.zip$/i,"");Ay.test(z)&&(I=z)}}else if(P.endsWith(".yaml")||P.endsWith(".yml")){const z=C.replace(/\.ya?ml$/i,"");Ay.test(z)&&(I=z)}j||c(I)})(),()=>{j=!0}},[g]);const v=l.trim(),w=v.length>0&&Ay.test(v);async function N(j){if(j.preventDefault(),!(!w||f)){p(!0),y("");try{const C=new FormData;C.set("flowId",v),C.set("targetSpace",u),C.set("file",g,g.name);const P=await fetch("/api/flows/import",{method:"POST",body:C}),I=await P.json().catch(()=>({}));if(!P.ok){y(typeof I.error=="string"?I.error:r("project:importModal.importFailed"));return}n({id:I.flowId,source:I.flowSource??"user"})}catch(C){y(String((C==null?void 0:C.message)||C))}finally{p(!1)}}}return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:j=>{j.target===j.currentTarget&&t()},children:i.jsxs("div",{ref:o,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":s,tabIndex:-1,onMouseDown:j=>j.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:s,className:"af-shortcuts-panel__title",children:r("project:importModal.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":r("project:importModal.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:N,children:[i.jsx("p",{className:"af-new-pipeline-lead",children:r("project:importModal.lead",{filename:g.name})}),i.jsx("input",{ref:a,type:"file",className:"af-import-file-input",accept:".yaml,.yml,.zip,application/zip","aria-hidden":!0,tabIndex:-1,onChange:j=>{var P;const C=(P=j.target.files)==null?void 0:P[0];C&&b(C),j.target.value=""}}),i.jsxs("label",{className:"af-pipeline-drawer-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:r("project:importModal.nameLabel")}),i.jsx("input",{className:"af-new-pipeline-input",type:"text",name:"importFlowId",autoComplete:"off",spellCheck:!1,placeholder:r("project:importModal.namePlaceholder"),value:l,onChange:j=>c(j.target.value),"aria-invalid":v.length>0&&!w}),i.jsx("span",{className:"af-pipeline-drawer-muted af-new-pipeline-hint",children:r("project:importModal.nameHint")})]}),i.jsx("div",{className:"af-import-repick",children:i.jsx("button",{type:"button",className:"af-btn-secondary af-import-repick-btn",onClick:()=>{var j;return(j=a.current)==null?void 0:j.click()},children:r("project:importModal.changeFile")})}),h?i.jsx("p",{className:"af-err af-new-pipeline-err",children:h}):null,i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:f,children:r("project:importModal.cancel")}),i.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!w||f,children:r(f?"project:importModal.importing":"project:importModal.importAndOpen")})]})]})]})})}const uF=/^[a-zA-Z][a-zA-Z0-9_-]*$/,JN="af:newPipelineGuide";function dF({open:e,onClose:t,onCreated:n}){const{t:r}=Fr(),s=m.useId(),o=m.useRef(null),[a,l]=m.useState(""),[c,u]=m.useState(""),[d,f]=m.useState("user"),[p,h]=m.useState(!1),[y,k]=m.useState(""),[b,g]=m.useState(!1);m.useEffect(()=>{if(!e)return;l(""),u(""),f("user"),k(""),h(!1),localStorage.getItem(JN)==="true"&&g(!0);const P=requestAnimationFrame(()=>{var I;return(I=o.current)==null?void 0:I.focus()});return()=>cancelAnimationFrame(P)},[e]);const v=()=>{localStorage.removeItem(JN),g(!1)};if(!e)return null;const w=a.trim(),N=w.length>0&&uF.test(w);async function j(C){if(C.preventDefault(),!(!N||p)){h(!0),k(""),v();try{const P=await fetch("/api/flows",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:w,description:c.trim(),targetSpace:d})}),I=await P.json().catch(()=>({}));if(!P.ok){k(typeof I.error=="string"?I.error:r("project:newPipelineModal.createFailed"));return}n({id:I.flowId,source:I.flowSource??"user"})}catch(P){k(String((P==null?void 0:P.message)||P))}finally{h(!1)}}}return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:C=>{C.target===C.currentTarget&&(v(),t())},children:i.jsxs("div",{ref:o,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":s,tabIndex:-1,onMouseDown:C=>C.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:s,className:"af-shortcuts-panel__title",children:r("project:newPipelineModal.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:()=>{v(),t()},"aria-label":r("project:newPipelineModal.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),b?i.jsx("div",{className:"af-new-pipeline-guide",children:i.jsxs("div",{className:"af-new-pipeline-guide-content",children:[i.jsx("span",{className:"material-symbols-outlined af-new-pipeline-guide-icon",children:"lightbulb"}),i.jsxs("div",{className:"af-new-pipeline-guide-text",children:[i.jsx("p",{children:i.jsx("strong",{children:r("onboarding:newPipeline.guideTitle")})}),i.jsx("p",{children:r("onboarding:newPipeline.guideDesc")})]}),i.jsx("button",{type:"button",className:"af-new-pipeline-guide-close",onClick:v,children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]})}):null,i.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:j,children:[i.jsx("p",{className:"af-new-pipeline-lead",children:r("project:newPipelineModal.lead")}),i.jsxs("label",{className:"af-pipeline-drawer-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:r("project:newPipelineModal.nameLabel")}),i.jsx("input",{className:"af-new-pipeline-input",type:"text",name:"pipelineName",autoComplete:"off",spellCheck:!1,placeholder:r("project:newPipelineModal.namePlaceholder"),value:a,onChange:C=>l(C.target.value),"aria-invalid":w.length>0&&!N}),i.jsx("span",{className:"af-pipeline-drawer-muted af-new-pipeline-hint",children:r(b?"onboarding:newPipeline.nameHintGuide":"project:newPipelineModal.nameHint")})]}),i.jsxs("label",{className:"af-pipeline-drawer-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:r("project:newPipelineModal.descLabel")}),i.jsx("textarea",{className:"af-pipeline-drawer-textarea af-new-pipeline-textarea",name:"pipelineDescription",rows:3,placeholder:r(b?"onboarding:newPipeline.descPlaceholderGuide":"project:newPipelineModal.descPlaceholder"),value:c,onChange:C=>u(C.target.value)}),b?i.jsx("span",{className:"af-pipeline-drawer-muted af-new-pipeline-guide-hint",children:r("onboarding:newPipeline.descHintGuide")}):null]}),y?i.jsx("p",{className:"af-err af-new-pipeline-err",children:y}):null,i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:()=>{v(),t()},disabled:p,children:r("project:newPipelineModal.cancel")}),i.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!N||p,children:r(p?"project:newPipelineModal.creating":b?"onboarding:newPipeline.createGuide":"project:newPipelineModal.createAndOpen")})]})]})]})})}const bP="agentflow.pipelineViewPreference";function kP(e,t="user",n=!1){return`${String(t||"user")}:${String(e||"")}:${n?"archived":"active"}`}function vP(){if(typeof localStorage>"u")return{};try{const e=JSON.parse(localStorage.getItem(bP)||"{}");return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function fF(e){if(!(typeof localStorage>"u"))try{localStorage.setItem(bP,JSON.stringify(e))}catch{}}function kk(e){return e==="display"?"display":"workspace"}function pF(e){const t=String(e||"").toLowerCase();return t==="builtin"||t==="admin"}function SP(e,t){const n=kk(t);return n==="pipeline"&&pF(e==null?void 0:e.source)?"workspace":n}function hF(e){return(e==null?void 0:e.hasPipeline)!==!1&&(e==null?void 0:e.hasFlow)!==!1&&(e==null?void 0:e.flowYaml)!==!1}function mF(e,t,n,r=!1){if(!e)return;const s=vP();s[kP(e,t,r)]={view:kk(n),at:Date.now()},fF(s)}function gF(e,t="workspace"){if(!(e!=null&&e.id))return kk(t);const r=vP()[kP(e.id,e.source??"user",!!e.archived)],s=SP(e,(r==null?void 0:r.view)||t);return s==="pipeline"&&!hF(e)?"workspace":s}function yF(e,t="workspace"){var s;const n=SP(e,t);if(!(e!=null&&e.id))return n==="display"?"/workspace?view=display":"/workspace";const r=new URLSearchParams({flowId:e.id,flowSource:e.source??"user"});return(s=e.collaboration)!=null&&s.id&&r.set("workspaceId",e.collaboration.id),e.archived&&r.set("archived","1"),n==="display"&&r.set("view","display"),`/workspace?${r.toString()}`}function gp(e,t="workspace"){return yF(e,gF(e,t))}function wF(e,t){const n=String(e||"").split(/[.-]/).map(o=>Number.parseInt(o,10)),r=String(t||"").split(/[.-]/).map(o=>Number.parseInt(o,10)),s=Math.max(n.length,r.length);for(let o=0;o<s;o+=1){const a=Number.isFinite(n[o])?n[o]:0,l=Number.isFinite(r[o])?r[o]:0;if(a!==l)return a>l?1:-1}return 0}function vx(e){return String((e==null?void 0:e.version)||"").trim()}function xF(e){const t=vx(e),n=[(e==null?void 0:e.agent)||"codex",(e==null?void 0:e.kind)||"skill"];return t&&n.push(`v${t}`),n.join(" · ")}function bF({onChanged:e,canManage:t=!1}){const[n,r]=m.useState({available:!1,version:"",loggedIn:!1,user:"",error:""}),[s,o]=m.useState([]),[a,l]=m.useState(""),[c,u]=m.useState(""),[d,f]=m.useState("keyword"),[p,h]=m.useState([]),[y,k]=m.useState({}),[b,g]=m.useState(""),[v,w]=m.useState(""),[N,j]=m.useState(""),C=m.useCallback(async()=>{w("");try{const[F,O]=await Promise.all([fetch("/api/skillhub/status"),fetch("/api/skillhub/list?target=agentflow&agent=codex")]),M=await F.json().catch(()=>({}));F.ok&&r({available:!!M.available,version:typeof M.version=="string"?M.version:"",loggedIn:!!M.loggedIn,user:typeof M.user=="string"?M.user:"",error:typeof M.error=="string"?M.error:""});const K=await O.json().catch(()=>({}));if(!O.ok)throw new Error(typeof K.error=="string"?K.error:"HTTP "+O.status);o(Array.isArray(K.skills)?K.skills:[]),l(typeof K.skillsRoot=="string"?K.skillsRoot:""),k({})}catch(F){w(String(F.message||F))}},[]);m.useEffect(()=>{C()},[C]);const P=m.useCallback(async()=>{const F=c.trim();if(F){g("search"),w(""),j("");try{const O=await fetch(`/api/skillhub/search?q=${encodeURIComponent(F)}&mode=${encodeURIComponent(d)}`),M=await O.json().catch(()=>({}));if(!O.ok)throw new Error(typeof M.error=="string"?M.error:"HTTP "+O.status);h(Array.isArray(M.items)?M.items:[])}catch(O){w(String(O.message||O))}finally{g("")}}},[c,d]),I=m.useCallback(async(F,O=!1)=>{if(!t)return;const M=F&&typeof F=="object"?F:null,K=String(M?M.slug||M.name||M.collection||M.skillId||M.id:F||"").trim();if(K){g(`install:${K}`),w(""),j("");try{const H=M?{slug:M.slug||"",skillId:M.skillId||"",collection:M.collection||"",collectionName:M.collection&&M.name||"",target:"agentflow",agent:"codex",force:O}:{slug:K,target:"agentflow",agent:"codex",force:O},D=await fetch("/api/skillhub/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(H)}),T=await D.json().catch(()=>({}));if(!D.ok)throw new Error(typeof T.error=="string"?T.error:"HTTP "+D.status);j(O?`已更新 ${K}`:`已安装 ${K}`),await C(),typeof e=="function"&&await e()}catch(H){w(String(H.message||H))}finally{g("")}}},[t,C,e]),z=m.useCallback(async()=>{if(t&&s.length!==0){g("check-updates"),w(""),j("");try{const F=await Promise.all(s.map(async K=>{const H=String(K.name||"").trim();if(!H)return null;try{const D=await fetch(`/api/skillhub/search?q=${encodeURIComponent(H)}&mode=keyword`),T=await D.json().catch(()=>({}));if(!D.ok)throw new Error(typeof T.error=="string"?T.error:"HTTP "+D.status);const W=Array.isArray(T.items)?T.items:[],E=W.find(se=>se.slug===H||se.name===H||se.id===H)||W[0],Q=vx(K),V=String((E==null?void 0:E.version)||"").trim();let B="unknown";return E?Q&&V?B=wF(Q,V)<0?"update":"current":V&&(B="remote-only"):B="missing",[H,{state:B,latestVersion:V,installedVersion:Q,summary:(E==null?void 0:E.summary)||""}]}catch(D){return[H,{state:"error",error:String(D.message||D),installedVersion:vx(K)}]}})),O={};for(const K of F)K&&(O[K[0]]=K[1]);k(O);const M=Object.values(O).filter(K=>K.state==="update").length;j(M>0?`发现 ${M} 个可更新 skill`:"已检查,暂无明确可更新项")}finally{g("")}}},[t,s]),$=m.useCallback(async F=>{if(!t)return;const O=String(F||"").trim();if(O){g(`uninstall:${O}`),w(""),j("");try{const M=await fetch("/api/skillhub/uninstall",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:O,target:"agentflow",agent:"codex"})}),K=await M.json().catch(()=>({}));if(!M.ok)throw new Error(typeof K.error=="string"?K.error:"HTTP "+M.status);j(`已卸载 ${O}`),await C(),typeof e=="function"&&await e()}catch(M){w(String(M.message||M))}finally{g("")}}},[t,C,e]),L=m.useCallback(async()=>{if(t){g("update-cli"),w(""),j("");try{const F=await fetch("/api/skillhub/update",{method:"POST"}),O=await F.json().catch(()=>({}));if(!F.ok)throw new Error(typeof O.error=="string"?O.error:"HTTP "+F.status);j("SkillHub CLI 已更新"),await C()}catch(F){w(String(F.message||F))}finally{g("")}}},[t,C]);return i.jsxs("section",{className:"af-set-card af-set-card--span-all af-set-skillhub",children:[i.jsxs("div",{className:"af-set-card-head af-set-card-head--spread",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"af-set-h2",children:"SkillHub"}),i.jsx("p",{className:"af-set-p af-set-p--tight",children:t?"搜索、安装、更新和卸载 AgentFlow 共享 skills。":"查看 AgentFlow 共享 skills;使用时在 Workspace 中通过 Load Skills 加载。"}),a?i.jsxs("p",{className:"af-set-hint af-set-hint--inline",children:["Skills Root:",i.jsx("code",{children:a})]}):null]}),i.jsxs("div",{className:"af-set-skillhub-head-actions",children:[i.jsxs("div",{className:"af-set-skillhub-status",children:[i.jsx("span",{className:"material-symbols-outlined af-set-icon--tertiary",children:"extension"}),i.jsx("span",{children:n.loggedIn?`已登录 ${n.user}`:"未登录 SkillHub"}),i.jsx("span",{className:"af-set-badge"+(n.available?" af-set-badge--ok":" af-set-badge--err"),children:n.available?`v${n.version}`:"not found"})]}),i.jsxs("div",{className:"af-set-skillhub-toolbar",children:[i.jsx("button",{type:"button",className:"af-set-btn-mini",onClick:C,disabled:!!b,children:"刷新"}),i.jsx("button",{type:"button",className:"af-set-btn-mini",onClick:z,disabled:!t||!!b||s.length===0,children:b==="check-updates"?"检查中…":"检查更新"}),i.jsx("button",{type:"button",className:"af-set-btn-mini",onClick:L,disabled:!t||!!b,children:b==="update-cli"?"更新中…":"更新 CLI"})]})]})]}),i.jsxs("div",{className:"af-set-skillhub-search",children:[i.jsxs("select",{className:"af-set-input af-set-input--sm af-set-skillhub-search-mode",value:d,onChange:F=>{f(F.target.value),h([])},children:[i.jsx("option",{value:"keyword",children:"关键词"}),i.jsx("option",{value:"skillId",children:"Skill ID"}),i.jsx("option",{value:"collectionId",children:"Collection ID"})]}),i.jsx("input",{className:"af-set-input af-set-input--sm",value:c,onChange:F=>u(F.target.value),onKeyDown:F=>{F.key==="Enter"&&P()},placeholder:d==="collectionId"?"输入 collection id,例如 1":d==="skillId"?"输入 skill id":"搜索 skill slug / 关键词,例如 android、issue-tracker"}),i.jsxs("button",{type:"button",className:"af-set-btn-add",onClick:()=>P(),disabled:!c.trim()||b==="search",children:[i.jsx("span",{className:"material-symbols-outlined",children:"search"}),b==="search"?"搜索中…":"搜索"]})]}),v?i.jsx("p",{className:"af-err af-set-hint af-set-hint--inline",children:v}):null,N?i.jsx("p",{className:"af-set-hint af-set-hint--inline",children:N}):null,i.jsxs("div",{className:"af-set-skillhub-grid",children:[i.jsxs("div",{className:"af-set-skillhub-pane",children:[i.jsxs("div",{className:"af-set-skillhub-pane-head",children:[i.jsx("h3",{children:"已安装"}),i.jsx("span",{children:s.length})]}),i.jsx("div",{className:"af-set-skillhub-list",children:s.length===0?i.jsx("div",{className:"af-set-skillhub-empty",children:"暂无 AgentFlow 共享 skills"}):s.map(F=>{const O=y[F.name],M=!O||O.state==="update"||O.state==="remote-only"||O.state==="unknown"||O.state==="error",K=b===`install:${F.name}`?"更新中…":(O==null?void 0:O.state)==="current"?"已最新":(O==null?void 0:O.state)==="update"&&O.latestVersion?`更新到 v${O.latestVersion}`:(O==null?void 0:O.state)==="remote-only"&&O.latestVersion?`安装 v${O.latestVersion}`:"重装";return i.jsxs("div",{className:"af-set-skillhub-item",children:[i.jsxs("div",{children:[i.jsx("div",{className:"af-set-skillhub-title",children:F.displayName||F.name}),i.jsx("div",{className:"af-set-skillhub-meta",children:xF(F)}),i.jsx("div",{className:"af-set-skillhub-version-row",children:O?O.state==="update"?i.jsxs("span",{className:"af-set-skillhub-version af-set-skillhub-version--warn",children:["可更新 ",O.installedVersion?`v${O.installedVersion} -> `:"","v",O.latestVersion]}):O.state==="current"?i.jsxs("span",{className:"af-set-skillhub-version af-set-skillhub-version--ok",children:["已最新 v",O.latestVersion||O.installedVersion]}):O.state==="remote-only"?i.jsxs("span",{className:"af-set-skillhub-version af-set-skillhub-version--muted",children:["远端 v",O.latestVersion,",本地版本未知"]}):O.state==="missing"?i.jsx("span",{className:"af-set-skillhub-version af-set-skillhub-version--muted",children:"未找到远端匹配项"}):O.state==="error"?i.jsx("span",{className:"af-set-skillhub-version af-set-skillhub-version--err",children:"检查失败"}):i.jsx("span",{className:"af-set-skillhub-version af-set-skillhub-version--muted",children:"状态未知"}):i.jsx("span",{className:"af-set-skillhub-version af-set-skillhub-version--muted",children:"未检查远端版本"})})]}),i.jsxs("div",{className:"af-set-skillhub-actions",children:[i.jsx("button",{type:"button",className:"af-set-btn-mini",onClick:()=>I(F.name,!0),disabled:!t||!!b||!M,children:K}),i.jsx("button",{type:"button",className:"af-set-btn-mini af-set-btn-mini--danger",onClick:()=>$(F.name),disabled:!t||!!b,children:"卸载"})]})]},`${F.agent}:${F.path}:${F.name}`)})})]}),i.jsxs("div",{className:"af-set-skillhub-pane",children:[i.jsxs("div",{className:"af-set-skillhub-pane-head",children:[i.jsx("h3",{children:"搜索结果"}),i.jsx("span",{children:p.length})]}),i.jsx("div",{className:"af-set-skillhub-list",children:p.length===0?i.jsx("div",{className:"af-set-skillhub-empty",children:"输入关键词后搜索 SkillHub"}):p.map(F=>{const O=F.slug||F.name,M=F.kind==="collection"||F.collection,K=!M&&s.some(H=>H.name===O||H.name===F.name);return i.jsxs("div",{className:"af-set-skillhub-item",children:[i.jsxs("div",{children:[i.jsx("div",{className:"af-set-skillhub-title",children:F.name||O}),i.jsxs("div",{className:"af-set-skillhub-meta",children:[M?`collection:${F.collection}`:O,F.skillId?` · id:${F.skillId}`:"",F.version?` · ${F.version}`:""]}),F.summary?i.jsx("p",{className:"af-set-skillhub-summary",children:F.summary}):null]}),i.jsx("button",{type:"button",className:K?"af-set-btn-mini":"af-set-btn-add af-set-btn-add--compact",onClick:()=>I(F,K),disabled:!t||!!b,children:K?"更新":M?"安装合集":"安装"})]},F.id||O)})})]})]})]})}function Oa(e){return(Array.isArray(e==null?void 0:e.collections)?e.collections:[]).filter(n=>n&&typeof n=="object").map(n=>({id:String(n.id||n.name||"").trim(),name:String(n.name||n.id||"").trim(),skillKeys:Array.from(new Set((Array.isArray(n.skillKeys)?n.skillKeys:[]).map(r=>String(r||"").trim()).filter(Boolean))),builtin:!!n.builtin,createdAt:Number.isFinite(n.createdAt)?Number(n.createdAt):Date.now(),updatedAt:Number.isFinite(n.updatedAt)?Number(n.updatedAt):Date.now()})).filter(n=>n.id&&n.name)}function kF(e){return{version:1,collections:Oa({collections:e})}}function vF(e){const t=String(e||"").trim(),n=t.indexOf(":");return n>=0?t.slice(n+1).trim():t}function NP(e){const t=new Map,n=new Map;for(const r of Array.isArray(e)?e:[])r!=null&&r.key&&t.set(r.key,r.key),r!=null&&r.name&&(r!=null&&r.key)&&!n.has(r.name)&&n.set(r.name,r.key);return r=>{const s=String(r||"").trim();return s&&(t.get(s)||n.get(vF(s)))||""}}function Qo(e,t){const n=NP(t);return Array.from(new Set((Array.isArray(e==null?void 0:e.skillKeys)?e.skillKeys:[]).map(r=>n(r)).filter(Boolean)))}function SF(e,t){const n=new Set(Array.isArray(e)?e:[]);for(const r of Array.isArray(t)?t:[])r&&n.add(r);return Array.from(n)}function NF(e,t){const n=new Set(Array.isArray(t)?t:[]);return(Array.isArray(e)?e:[]).filter(r=>!n.has(r))}function jF(e,t,n){const r=Qo(e,n);if(r.length===0)return"empty";const s=r.filter(o=>t.has(o)).length;return s===0?"none":s===r.length?"all":"partial"}function CF(e,t,n){const r=String(e).trim().toLowerCase(),s=Oa({collections:n}).find(o=>o.id===r||o.name.toLowerCase()===r);return Qo(s,t)}function _F(e,t,n,r){const s=(Array.isArray(n)?n:[]).map(u=>u.key).filter(Boolean),o=String(t).trim().toLowerCase(),a=Oa({collections:r}),l=CF(t,n,r),c=l.length>0?l:s;if(!e)return c;try{const u=localStorage.getItem(e);if(u!==null){const d=JSON.parse(u);if(Array.isArray(d)){const f=NP(n),p=Array.from(new Set(d.map(f).filter(Boolean)));if(s.length>0&&p.length===s.length)return c;const h=new Set(p),y=new Set(l),k=l.length>0&&l.every(g=>h.has(g)),b=a.some(g=>{if(!g.builtin||g.id===o||g.name.toLowerCase()===o)return!1;const v=Qo(g,n);return v.length>0&&v.every(w=>h.has(w))});return l.length>0&&b&&!k?c:p}}}catch{}return c}function Al(e){return e==="builtin"?"af-proj-badge af-proj-badge--builtin":e==="secondary"?"af-proj-badge af-proj-badge--secondary":e==="primary"?"af-proj-badge af-proj-badge--primary":e==="muted"?"af-proj-badge af-proj-badge--muted":"af-proj-badge"}function EF(e){const t=e??"user";return t==="builtin"||t==="admin"?"af-project-card af-project-card--builtin":"af-project-card"}function AF(e){return e==="executed"?"material-symbols-outlined af-act-icon af-act-icon--executed":"material-symbols-outlined af-act-icon af-act-icon--opened"}function Sx(e,t){return e==="builtin"?{label:t("project:sourceBadge.builtin"),tone:"builtin"}:e==="admin"?{label:t("project:sourceBadge.builtin"),tone:"builtin"}:e==="workspace"?{label:t("project:sourceBadge.workspace"),tone:"secondary"}:{label:t("project:sourceBadge.user"),tone:"primary"}}function jP(e){var n;if((n=e.collaboration)!=null&&n.role&&e.collaboration.role!=="owner")return`共享 Project / ${e.collaboration.ownerUsername||e.collaboration.ownerId} / ${e.id}`;const t=e.source??"user";return t==="builtin"?`builtin/pipelines / ${e.id}`:t==="admin"?`admin builtin / ${e.ownerUserId||"-"} / ${e.id}`:t==="workspace"?e.archived?`.workspace/agentflow/pipelines/_archived / ${e.id}`:`.workspace/agentflow/pipelines / ${e.id}`:e.archived?`~/agentflow/pipelines/_archived / ${e.id}`:`~/agentflow/pipelines / ${e.id}`}const PF="project:defaultCardDesc";function CP(e,t){const n=e.description!=null?String(e.description).trim():"";return n!==""?n:t(PF)}function IF(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Bn({children:e,className:t="",query:n}){const r=n.trim(),s=String(e);if(!r)return i.jsx("span",{className:t,children:s});const o=new RegExp(`(${IF(r)})`,"gi"),a=s.split(o);return i.jsx("span",{className:t,children:a.map((l,c)=>c%2===1?i.jsx("mark",{className:"af-search-hit",children:l},c):i.jsx("span",{children:l},c))})}function RF(e,t,n){const r=[String(e.id),CP(e,n),jP(e),Sx(e.source,n).label];return e.archived&&r.push(n("project:archived")),r.join(`
41
41
  `).toLowerCase()}function TF(e,t,n){return t?RF(e,t,n).includes(t):!0}function MF(e,t){const n=e.trim().toLowerCase();if(!n)return!0;const r=String(t.flowId).toLowerCase(),s=String(t.flowSource??"user").toLowerCase();return r.includes(n)||s.includes(n)}function Py(e,t){const n=e.trim().toLowerCase();return n?t.filter(Boolean).join(`
42
- `).toLowerCase().includes(n):!0}function XN(e,t){return e==="flow"?t("project:resourceSource.flow"):e==="marketplace"?t("project:resourceSource.marketplace"):e==="project"?t("project:resourceSource.global"):e||t("project:resourceSource.global")}function QN(e){return e!=null&&e.packageDir?e.packageDir:`marketplace/flow-snippets / ${(e==null?void 0:e.id)||""}`}const $F=["all","agent","control","provide","marketplace"],LF=["all","agent","control","provide"],_P="agentflow.projects.activityPanelOpen",Nx="agentflow.projects.activitySelected";function OF(){if(typeof localStorage>"u")return!0;const e=localStorage.getItem(_P);return e!=="0"}function ZN(e){return`${(e==null?void 0:e.flowSource)||"user"}:${(e==null?void 0:e.flowId)||""}`}function DF(){return typeof localStorage>"u"?"":localStorage.getItem(Nx)||""}function yp(e){return!e||typeof e!="object"?[]:Object.entries(e).map(([t,n])=>({key:t,...n&&typeof n=="object"?n:{}}))}function Hn(e){return(e==null?void 0:e.key)||`${(e==null?void 0:e.id)||(e==null?void 0:e.name)||""}:${(e==null?void 0:e.source)||""}:${(e==null?void 0:e.packageId)||""}`}function FF(e,t){if((e==null?void 0:e.source)!=="marketplace")return!1;const n=String((e==null?void 0:e.ownerUserId)||(e==null?void 0:e.createdBy)||"").trim();return n?new Set([String((t==null?void 0:t.userId)||"").trim(),String((t==null?void 0:t.username)||"").trim()].filter(Boolean)).has(n):!0}function jo(e){return`${(e==null?void 0:e.id)||""}:${(e==null?void 0:e.version)||""}:${(e==null?void 0:e.packageDir)||""}`}function EP(e){var n;const t=(n=e==null?void 0:e.snippet)==null?void 0:n.instances;return Array.isArray(t)?t.filter(r=>r&&typeof r=="object"):t&&typeof t=="object"?Object.entries(t).map(([r,s])=>({...s&&typeof s=="object"?s:{},instanceId:(s==null?void 0:s.instanceId)||r})):[]}function AP(e){var n;const t=(n=e==null?void 0:e.snippet)==null?void 0:n.edges;return Array.isArray(t)?t.filter(r=>r&&typeof r=="object"):[]}function jx(e,t){return String((e==null?void 0:e.instanceId)||(e==null?void 0:e.id)||(e==null?void 0:e.nodeId)||`node_${t+1}`)}function ej(e,t){return String((e==null?void 0:e.label)||(e==null?void 0:e.displayName)||(e==null?void 0:e.name)||jx(e,t))}function zF(e){return String((e==null?void 0:e.definitionId)||(e==null?void 0:e.type)||(e==null?void 0:e.runtimeType)||"").replace(/^marketplace:/,"")}function tj(e,t){return String(t==="source"?(e==null?void 0:e.source)||(e==null?void 0:e.from)||(e==null?void 0:e.sourceId)||(e==null?void 0:e.fromNode)||(e==null?void 0:e.fromInstanceId)||"":(e==null?void 0:e.target)||(e==null?void 0:e.to)||(e==null?void 0:e.targetId)||(e==null?void 0:e.toNode)||(e==null?void 0:e.toInstanceId)||"")}function BF(e){const t=(e==null?void 0:e.sourceHandle)||(e==null?void 0:e.fromHandle)||(e==null?void 0:e.output)||(e==null?void 0:e.outputName),n=(e==null?void 0:e.targetHandle)||(e==null?void 0:e.toHandle)||(e==null?void 0:e.input)||(e==null?void 0:e.inputName);return t&&n?`${t} -> ${n}`:String(t||n||"")}function Iy(e,t=16){const n=String(e||"").trim();return n.length<=t?n:`${n.slice(0,t-1)}…`}function HF(e){const t=Number(e==null?void 0:e.x),n=Number(e==null?void 0:e.y);return!Number.isFinite(t)||!Number.isFinite(n)?null:{x:t,y:n}}function WF(e,t){const n=e.map(d=>d.id),r=new Set(n),s=new Map(n.map(d=>[d,0])),o=new Map(n.map(d=>[d,[]]));t.forEach(d=>{var f;!r.has(d.sourceId)||!r.has(d.targetId)||(s.set(d.targetId,(s.get(d.targetId)||0)+1),(f=o.get(d.sourceId))==null||f.push(d.targetId))});const a=new Map,l=n.filter(d=>(s.get(d)||0)===0);l.length===0&&n[0]&&l.push(n[0]),l.forEach(d=>a.set(d,0));for(let d=0;d<l.length;d+=1){const f=l[d],p=(a.get(f)||0)+1;for(const h of o.get(f)||[])(!a.has(h)||p>a.get(h))&&(a.set(h,p),l.push(h))}n.forEach((d,f)=>{a.has(d)||a.set(d,f%3)});const c=new Map,u=new Map;return n.forEach(d=>{const f=a.get(d)||0,p=c.get(f)||0;c.set(f,p+1),u.set(d,{x:f*190,y:p*86})}),u}function VF(e){var k,b,g,v;const t=EP(e),n=AP(e),r=new Map(t.map((w,N)=>[jx(w,N),ej(w,N)])),s=t.map((w,N)=>({id:jx(w,N),title:ej(w,N),meta:zF(w)})),o=n.map((w,N)=>{const j=tj(w,"source"),C=tj(w,"target");return{key:(w==null?void 0:w.id)||`${j}-${C}-${N}`,sourceId:j,targetId:C,source:r.get(j)||j||"?",target:r.get(C)||C||"?",label:BF(w)}}),a=(b=(k=e==null?void 0:e.snippet)==null?void 0:k.ui)!=null&&b.nodePositions&&typeof e.snippet.ui.nodePositions=="object"?e.snippet.ui.nodePositions:{},l=(v=(g=e==null?void 0:e.snippet)==null?void 0:g.ui)!=null&&v.nodeSizes&&typeof e.snippet.ui.nodeSizes=="object"?e.snippet.ui.nodeSizes:{},c=WF(s,o),u=s.map(w=>{const N=HF(a[w.id])||c.get(w.id)||{x:0,y:0},j=l[w.id]&&typeof l[w.id]=="object"?l[w.id]:{},C=Number(j.width),P=Number(j.height),I=Math.max(132,Math.min(210,Number.isFinite(C)?C*.62:150)),z=Math.max(48,Math.min(76,Number.isFinite(P)?P*.46:54));return{...w,x:N.x,y:N.y,width:I,height:z}}),d=new Map(u.map(w=>[w.id,w])),f=o.map(w=>{const N=d.get(w.sourceId),j=d.get(w.targetId);if(!N||!j)return null;const C=N.x+N.width,P=N.y+N.height/2,I=j.x,z=j.y+j.height/2,$=Math.max(48,Math.abs(I-C)*.45);return{...w,path:`M ${C} ${P} C ${C+$} ${P}, ${I-$} ${z}, ${I} ${z}`,labelX:(C+I)/2,labelY:(P+z)/2}}).filter(Boolean),p=u.reduce((w,N)=>({minX:Math.min(w.minX,N.x),minY:Math.min(w.minY,N.y),maxX:Math.max(w.maxX,N.x+N.width),maxY:Math.max(w.maxY,N.y+N.height)}),{minX:0,minY:0,maxX:420,maxY:220}),h=36,y=`${p.minX-h} ${p.minY-h} ${Math.max(360,p.maxX-p.minX+h*2)} ${Math.max(180,p.maxY-p.minY+h*2)}`;return{nodes:s,edges:o,diagram:{nodes:u,edges:f,viewBox:y}}}function Pl({resourceKind:e="",authUser:t=null}){var Pe,xt,Lt,qt,zn,On;const{t:n}=Fr(),{navigate:r,path:s}=si(),o=!!(t!=null&&t.isAdmin),[a,l]=m.useState(e||"all"),[c,u]=m.useState([]),[d,f]=m.useState([]),[p,h]=m.useState([]),[y,k]=m.useState([]),[b,g]=m.useState([]),[v,w]=m.useState(""),[N,j]=m.useState(!1),[C,P]=m.useState([]),[I,z]=m.useState(""),[$,L]=m.useState(""),[F,O]=m.useState(!1),[M,K]=m.useState(!1),[H,D]=m.useState(!1),[T,W]=m.useState(null),[E,Q]=m.useState(!1),[V,B]=m.useState(""),[se,ue]=m.useState(OF),[G,ee]=m.useState(DF),[te,ne]=m.useState("all"),[Z,ce]=m.useState(""),[de,me]=m.useState("overview"),[$e,Ce]=m.useState({}),[_e,Be]=m.useState(""),[ot,yt]=m.useState({}),[Te,st]=m.useState(""),[gt,xe]=m.useState(""),[Fe,lt]=m.useState({}),[oe,ke]=m.useState(""),[Ke,Ue]=m.useState(""),[be,Ht]=m.useState(""),[Qt,jt]=m.useState(""),[yn,on]=m.useState(""),[re,Re]=m.useState(!1),[Je,Ze]=m.useState(""),[Tt,At]=m.useState({hiddenBuiltins:[],promoted:[]}),Vn=m.useRef(0),Sn=m.useRef(0),xr=m.useRef(0),wn=m.useCallback(async()=>{var pe,Oe;const q=++Sn.current;z("");try{const Ee=await fetch("/api/flows");if(q!==Sn.current)return;if(!Ee.ok)throw new Error("HTTP "+Ee.status);const et=await Ee.json();if(q!==Sn.current)return;u(Array.isArray(et)?et:[])}catch(Ee){if(q!==Sn.current)return;u([]),z(String(Ee.message||Ee))}try{const Ee=await fetch("/api/pipeline-recent-runs");if(q!==Sn.current)return;if(Ee.ok){const et=await Ee.json();if(q!==Sn.current)return;P(Array.isArray(et.runs)?et.runs:[])}else P([])}catch{if(q!==Sn.current)return;P([])}if(t!=null&&t.isAdmin)try{const Ee=await fetch("/api/admin/builtin-flows");if(q!==Sn.current)return;const et=await Ee.json().catch(()=>({}));Ee.ok&&At({hiddenBuiltins:Array.isArray((pe=et==null?void 0:et.config)==null?void 0:pe.hiddenBuiltins)?et.config.hiddenBuiltins:[],promoted:Array.isArray((Oe=et==null?void 0:et.config)==null?void 0:Oe.promoted)?et.config.promoted:[]})}catch{if(q!==Sn.current)return;At({hiddenBuiltins:[],promoted:[]})}else At({hiddenBuiltins:[],promoted:[]});O(!0)},[t==null?void 0:t.isAdmin]),Xn=m.useCallback(async(q,pe)=>{if(!(t!=null&&t.isAdmin)||!(q!=null&&q.id))return;const Oe=`${pe}:${q.source}:${q.id}`;Ze(Oe),z("");try{const Ee=await fetch("/api/admin/builtin-flows",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:pe,flowId:q.id,ownerUserId:q.ownerUserId||t.userId})}),et=await Ee.json().catch(()=>({}));if(!Ee.ok)throw new Error(et.error||"更新内置配置失败");await wn()}catch(Ee){z(String(Ee.message||Ee))}finally{Ze("")}},[t==null?void 0:t.isAdmin,t==null?void 0:t.userId,wn]),Kn=m.useCallback(async()=>{const q=++xr.current;L(""),K(!1);const pe="/api/nodes",Oe=e==="my-flows"?"/api/marketplace/flow-snippets?scope=owned":"/api/marketplace/flow-snippets";f([]),k([]),ce("");try{const[Ee,et,Nn,kt]=await Promise.all([fetch(pe),fetch("/api/skills"),fetch("/api/skill-collections"),fetch(Oe)]),Ut=await Ee.json().catch(()=>({})),jn=await et.json().catch(()=>({})),go=await Nn.json().catch(()=>({})),at=await kt.json().catch(()=>({}));if(!Ee.ok)throw new Error(Ut.error||"Nodes HTTP "+Ee.status);if(!et.ok)throw new Error(jn.error||"Skills HTTP "+et.status);if(!Nn.ok)throw new Error(go.error||"Collections HTTP "+Nn.status);if(!kt.ok)throw new Error(at.error||"Flow snippets HTTP "+kt.status);if(q!==xr.current)return;f(Array.isArray(Ut.nodes)?Ut.nodes:Array.isArray(Ut)?Ut:[]),h(Array.isArray(jn.skills)?jn.skills:[]),g(Oa(go)),k(Array.isArray(at.snippets)?at.snippets:[])}catch(Ee){if(q!==xr.current)return;f([]),h([]),k([]),g([]),L(String(Ee.message||Ee))}finally{if(q!==xr.current)return;K(!0)}},[e]);m.useEffect(()=>{O(!1),wn(),Kn()},[wn,Kn]),m.useEffect(()=>{try{localStorage.setItem(_P,se?"1":"0")}catch{}},[se]),m.useEffect(()=>{try{G?localStorage.setItem(Nx,G):localStorage.removeItem(Nx)}catch{}},[G]),m.useEffect(()=>{let q=!1;return fetch("/api/ui-context").then(pe=>pe.json()).then(pe=>{q||Re(!!pe.hideCommunityLinks)}).catch(()=>{}),()=>{q=!0}},[]);const hr=m.useCallback(async q=>{if(!o)return;const pe=Oa({collections:q});j(!0),L("");try{const Oe=await fetch("/api/skill-collections",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(kF(pe))}),Ee=await Oe.json().catch(()=>({}));if(!Oe.ok)throw new Error(Ee.error||"Collections HTTP "+Oe.status);g(Oa(Ee))}catch(Oe){L(String(Oe.message||Oe))}finally{j(!1)}},[o]),ts=m.useCallback(()=>{if(!o)return;const q=v.trim();if(!q)return;const pe=q.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"collection",Oe=new Set(b.map(kt=>kt.id));let Ee=pe,et=2;for(;Oe.has(Ee);)Ee=`${pe}-${et++}`;const Nn=Date.now();hr([...b,{id:Ee,name:q,skillKeys:[],createdAt:Nn,updatedAt:Nn}]),w(""),ne(`collection:${Ee}`)},[o,v,hr,b]),Ar=m.useCallback(q=>{if(!o)return;const pe=b.find(Ee=>Ee.id===q);if(pe!=null&&pe.builtin)return;const Oe=b.filter(Ee=>Ee.id!==q);te===`collection:${q}`&&ne("all"),hr(Oe)},[o,te,hr,b]),gs=m.useCallback((q,pe,Oe)=>{if(!o)return;const Ee=String(pe||"").trim();if(!Ee)return;const et=Date.now(),Nn=b.map(kt=>{if(kt.id!==q)return kt;const Ut=new Set(kt.skillKeys||[]);return Oe?Ut.add(Ee):Ut.delete(Ee),{...kt,skillKeys:Array.from(Ut),updatedAt:et}});hr(Nn)},[o,hr,b]),ys=m.useCallback(async q=>{const pe=q==null?void 0:q.packageId,Oe=q==null?void 0:q.version;if(!pe||!Oe||!window.confirm(n("project:deleteMyNodeConfirm",{id:pe,version:Oe})))return;const Ee=Hn(q);Ue(Ee),Ht(""),L("");try{const et=new URLSearchParams({id:pe,version:Oe}),Nn=await fetch(`/api/marketplace/node?${et.toString()}`,{method:"DELETE"}),kt=await Nn.json().catch(()=>({}));if(!Nn.ok||(kt==null?void 0:kt.ok)===!1){const Ut=Array.isArray(kt==null?void 0:kt.usage)&&kt.usage.length>0?` ${n("project:deleteMyNodeUsedBy",{count:kt.usage.length})}`:"";throw new Error(((kt==null?void 0:kt.error)||"Delete failed")+Ut)}Ht(n("project:deleteMyNodeSuccess",{id:pe,version:Oe})),yt(Ut=>{const jn={...Ut};return delete jn[Ee],jn}),lt(Ut=>{const jn={};for(const[go,at]of Object.entries(Ut))go.startsWith(`${Ee}:`)||(jn[go]=at);return jn}),ce(""),await Kn()}catch(et){Ht(String(et.message||et))}finally{Ue("")}},[Kn,n]),cn=m.useCallback(async q=>{const pe=q==null?void 0:q.id,Oe=(q==null?void 0:q.version)||"1.0.0";if(!pe||!Oe||!window.confirm(n("project:deleteMyFlowConfirm",{id:pe,version:Oe})))return;const Ee=jo(q);jt(Ee),on(""),L("");try{const et=new URLSearchParams({id:pe,version:Oe}),Nn=await fetch(`/api/marketplace/flow-snippet?${et.toString()}`,{method:"DELETE"}),kt=await Nn.json().catch(()=>({}));if(!Nn.ok||(kt==null?void 0:kt.ok)===!1)throw new Error((kt==null?void 0:kt.error)||"Delete failed");on(n("project:deleteMyFlowSuccess",{id:pe,version:Oe})),ce(""),await Kn()}catch(et){on(String(et.message||et))}finally{jt("")}},[Kn,n]);m.useEffect(()=>{if(e==="nodes"||e==="my-nodes"||e==="my-flows"||e==="skills"){l(e),ne("all"),ce(""),me("overview");return}l(q=>q==="archived"?"archived":"all")},[e]),m.useEffect(()=>{if(s!=="/projects"&&s!=="/")return;const q=new URLSearchParams(window.location.search),pe=q.get("tab");let Oe=!1;if(pe==="nodes"){r("/nodes");return}if(pe==="my-nodes"){r("/my-nodes");return}if(pe==="my-flows"){r("/my-flows");return}if(pe==="skills"){r("/skills");return}if(pe==="archived"?(l("archived"),q.delete("tab"),Oe=!0):pe&&(l("all"),q.delete("tab"),Oe=!0),q.get("new")==="1"&&(D(!0),q.delete("new"),Oe=!0),Oe){const Ee=q.toString();window.history.replaceState({},"",Ee?`/projects?${Ee}`:"/projects")}},[s,r]);const rr=m.useMemo(()=>LD(C,MD(),c),[C,c,s]),Pr=m.useMemo(()=>rr.filter(q=>MF(V,q)),[rr,V]),dn=V.trim().toLowerCase(),Qn=m.useMemo(()=>a==="archived"?c.filter(q=>q.archived):c.filter(q=>!q.archived),[c,a]),br=m.useMemo(()=>Qn.filter(q=>TF(q,dn,n)),[Qn,dn,n]),sr=m.useMemo(()=>new Set((Tt.promoted||[]).map(q=>String((q==null?void 0:q.id)||"").trim()).filter(Boolean)),[Tt.promoted]),Ct=m.useMemo(()=>(Tt.hiddenBuiltins||[]).map(q=>String(q||"").trim()).filter(Boolean),[Tt.hiddenBuiltins]),Gt=a==="nodes"||a==="my-nodes",_t=a==="my-nodes",le=a==="my-flows",ve=m.useMemo(()=>d.filter(q=>_t&&!FF(q,t)?!1:(te==="all"||(te==="marketplace"?q.source==="marketplace":q.type===te))&&Py(V,[q.id,q.label,q.displayName,q.description,q.type,q.source,q.packageId,q.version])),[t,d,_t,V,te]),it=m.useMemo(()=>{const q=new Map;for(const pe of b)q.set(pe.id,new Set(Qo(pe,p)));return q},[p,b]),Dt=m.useMemo(()=>[{id:"all",label:"全部"},...b.map(q=>{var pe;return{id:`collection:${q.id}`,label:q.name,count:((pe=it.get(q.id))==null?void 0:pe.size)||0,collection:q}}),{id:"ungrouped",label:"未分组"}],[it,b]),Jt=m.useMemo(()=>p.filter(q=>{var Ee;const pe=Hn(q);let Oe=te==="all";if(te.startsWith("collection:")){const et=te.slice(11);Oe=!!((Ee=it.get(et))!=null&&Ee.has(pe))}else te==="ungrouped"&&(Oe=!Array.from(it.values()).some(et=>et.has(pe)));return Oe&&Py(V,[q.name,q.id,q.description,q.sourceLabel,q.source,q.path])}),[p,V,te,it]),tn=m.useMemo(()=>y.filter(q=>Py(V,[q.id,q.name,q.displayName,q.description,q.version,q.packageDir,Array.isArray(q.tags)?q.tags.join(" "):""])),[y,V]),Zn=Gt||le||a==="skills",mt=m.useMemo(()=>ve.find(q=>Hn(q)===Z)||ve[0]||null,[ve,Z]),nn=m.useMemo(()=>Jt.find(q=>Hn(q)===Z)||Jt[0]||null,[Jt,Z]),Wt=m.useMemo(()=>tn.find(q=>jo(q)===Z)||tn[0]||null,[tn,Z]),kr=nn?$e[Hn(nn)]:null,tt=mt?ot[Hn(mt)]:null,Ln=mt&&gt?Fe[`${Hn(mt)}:${gt}`]:null,$i=n(Gt?"project:searchNodes":le?"project:searchFlows":a==="skills"?"project:searchSkills":"project:searchPipelines");m.useEffect(()=>{if(a!=="skills"||!nn)return;const q=Hn(nn);if($e[q])return;let pe=!1;return Be(q),fetch(`/api/skills/detail?key=${encodeURIComponent(q)}`).then(Oe=>Oe.json().then(Ee=>({ok:Oe.ok,json:Ee}))).then(({ok:Oe,json:Ee})=>{pe||Oe&&Ee.skill&&Ce(et=>({...et,[q]:Ee.skill}))}).catch(()=>{}).finally(()=>{pe||Be("")}),()=>{pe=!0}},[a,nn,$e]),m.useEffect(()=>{if(!Gt||!mt)return;const q=Hn(mt);if(ot[q])return;let pe=!1;return st(q),fetch(`/api/nodes/detail?id=${encodeURIComponent(mt.id)}`).then(Oe=>Oe.json().then(Ee=>({ok:Oe.ok,json:Ee}))).then(({ok:Oe,json:Ee})=>{pe||Oe&&yt(et=>({...et,[q]:Ee}))}).catch(()=>{}).finally(()=>{pe||st("")}),()=>{pe=!0}},[Gt,mt,ot]),m.useEffect(()=>{if(!Gt)return;const q=Array.isArray(tt==null?void 0:tt.files)?tt.files:[];xe(pe=>{var Oe;return pe&&q.some(Ee=>Ee.path===pe)?pe:((Oe=q[0])==null?void 0:Oe.path)||""})},[Gt,tt]),m.useEffect(()=>{if(!Gt||!mt||!gt)return;const q=`${Hn(mt)}:${gt}`;if(Fe[q])return;let pe=!1;return ke(q),fetch(`/api/nodes/file?id=${encodeURIComponent(mt.id)}&path=${encodeURIComponent(gt)}`).then(Oe=>Oe.json().then(Ee=>({ok:Oe.ok,json:Ee}))).then(({ok:Oe,json:Ee})=>{pe||Oe&&lt(et=>({...et,[q]:Ee}))}).catch(()=>{}).finally(()=>{pe||ke("")}),()=>{pe=!0}},[Gt,mt,gt,Fe]),m.useEffect(()=>{Ht("")},[Z,a]);const zr=q=>{r(gp(q,"workspace"))},mo=q=>{ee(ZN(q)),r(gp({id:q.flowId,source:q.flowSource,archived:!!q.archived},"workspace"))},ai=m.useCallback(q=>{var pe,Oe;q.preventDefault(),q.stopPropagation(),(Oe=(pe=q.dataTransfer)==null?void 0:pe.types)!=null&&Oe.includes("Files")&&(Vn.current+=1,Q(!0))},[]),Ts=m.useCallback(q=>{q.preventDefault(),q.stopPropagation(),Vn.current-=1,Vn.current<=0&&(Vn.current=0,Q(!1))},[]),ie=m.useCallback(q=>{q.preventDefault(),q.stopPropagation()},[]),Se=m.useCallback(q=>{var Ee,et;q.preventDefault(),q.stopPropagation(),Vn.current=0,Q(!1);const pe=(et=(Ee=q.dataTransfer)==null?void 0:Ee.files)==null?void 0:et[0];if(!pe)return;const Oe=pe.name.toLowerCase();!Oe.endsWith(".yaml")&&!Oe.endsWith(".yml")&&!Oe.endsWith(".zip")||W(pe)},[]);return i.jsxs("div",{className:"af-projects"+(E?" af-projects--drop-target":""),onDragEnter:ai,onDragLeave:Ts,onDragOver:ie,onDrop:Se,children:[i.jsxs("header",{className:"af-projects-top",children:[e?i.jsx("div",{className:"af-projects-tabs af-projects-tabs--empty","aria-hidden":!0}):i.jsxs("div",{className:"af-projects-tabs",children:[i.jsx("button",{type:"button",className:a==="all"?"af-tab af-tab--active":"af-tab",onClick:()=>l("all"),children:n("project:all")}),i.jsx("button",{type:"button",className:a==="archived"?"af-tab af-tab--active":"af-tab",onClick:()=>l("archived"),children:n("project:archived")})]}),i.jsxs("div",{className:"af-projects-top-right",children:[i.jsxs("div",{className:"af-search-wrap",children:[i.jsx("span",{className:"material-symbols-outlined af-search-icon",children:"search"}),i.jsx("input",{className:"af-search"+(V.trim()?" af-search--has-clear":""),type:"search",placeholder:$i,"aria-label":$i,autoComplete:"off",value:V,onChange:q=>B(q.target.value),onKeyDown:q=>{q.key==="Escape"&&(B(""),q.currentTarget.blur())}}),V.trim()?i.jsx("button",{type:"button",className:"af-search-clear","aria-label":"Clear search",onClick:()=>B(""),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),Zn?i.jsx("button",{type:"button",className:"af-btn-primary af-create-btn",onClick:()=>Kn(),children:n("project:refreshResources")}):i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"af-icon-btn"+(se?" af-icon-btn--active":""),"aria-label":n("flow:palette.toggleRecentActivity"),"aria-expanded":se,"aria-controls":"af-recent-activity-panel",onClick:()=>ue(q=>!q),children:i.jsx("span",{className:"material-symbols-outlined",children:"notifications"})}),i.jsx("button",{type:"button",className:"af-btn-primary af-create-btn",onClick:()=>D(!0),children:n("project:createNew")})]})]})]}),i.jsxs("div",{className:"af-projects-body",children:[i.jsxs("section",{className:"af-projects-main",children:[i.jsxs("header",{className:"af-projects-section-head",children:[i.jsx("h2",{className:"af-projects-h2",children:n(a==="my-nodes"?"project:myNodes":a==="my-flows"?"project:myFlows":a==="nodes"?"project:nodes":a==="skills"?"project:globalSkills":a==="archived"?"project:archivedPipelines":"project:activeProjects")}),i.jsx("p",{className:"af-projects-sub",children:dn?n("project:filterResult",{count:a==="nodes"||a==="my-nodes"?ve.length:a==="my-flows"?tn.length:a==="skills"?Jt.length:br.length}):a==="my-nodes"?n("project:myNodesHint",{count:ve.length}):a==="my-flows"?n("project:myFlowsHint",{count:tn.length}):a==="nodes"?n("project:nodesHint",{count:d.length}):a==="skills"?n("project:skillsHint",{count:p.length}):n(a==="archived"?"project:archivedHint":"project:activeHint")}),I?i.jsx("p",{className:"af-err af-projects-api-hint",children:I}):null,$&&Zn?i.jsx("p",{className:"af-err af-projects-api-hint",children:$}):null]}),Zn?i.jsxs("div",{className:"af-resource-toolbar",children:[a==="skills"?i.jsx(bF,{onChanged:Kn,canManage:!!(t!=null&&t.isAdmin)}):null,i.jsxs("div",{className:"af-resource-purpose",children:[i.jsx("span",{className:"material-symbols-outlined",children:le?"schema":Gt?_t?"deployed_code":"account_tree":"extension"}),i.jsxs("div",{children:[i.jsx("h3",{children:n(le?"project:myFlowsPurposeTitle":_t?"project:myNodesPurposeTitle":Gt?"project:nodesPurposeTitle":"project:skillsPurposeTitle")}),i.jsx("p",{children:n(le?"project:myFlowsPurposeDesc":_t?"project:myNodesPurposeDesc":Gt?"project:nodesPurposeDesc":"project:skillsPurposeDesc")})]})]}),le?null:i.jsxs(i.Fragment,{children:[Gt?i.jsxs("div",{className:"af-resource-filter-row",children:[i.jsx("button",{type:"button",className:"af-resource-filter"+(_t?"":" af-resource-filter--active"),onClick:()=>{l("nodes"),ne("all"),ce("")},children:n("project:nodeScopeAll")}),i.jsx("button",{type:"button",className:"af-resource-filter"+(_t?" af-resource-filter--active":""),onClick:()=>{l("my-nodes"),ne("all"),ce("")},children:n("project:nodeScopeMine")})]}):null,i.jsx("div",{className:"af-resource-filter-row",children:(Gt?(_t?LF:$F).map(q=>({id:q,label:n(`project:resourceFilter.${q}`)})):Dt).map(q=>q.collection?i.jsxs("span",{className:"af-resource-filter-chip"+(te===q.id?" af-resource-filter-chip--active":""),children:[i.jsxs("button",{type:"button",className:"af-resource-filter af-resource-filter--embedded",onClick:()=>{ne(q.id),ce("")},children:[q.label,i.jsx("em",{children:q.count}),q.collection.builtin?i.jsx("strong",{children:"built-in"}):null]}),o&&!q.collection.builtin?i.jsx("button",{type:"button",className:"af-resource-filter-chip__delete",disabled:N,"aria-label":`删除 ${q.collection.name}`,onClick:()=>Ar(q.collection.id),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})}):null]},q.id):i.jsx("button",{type:"button",className:"af-resource-filter"+(te===q.id?" af-resource-filter--active":""),onClick:()=>{ne(q.id),ce("")},children:q.label},q.id))})]}),a==="skills"&&o?i.jsx("div",{className:"af-skill-collections-manager",children:i.jsxs("div",{className:"af-skill-collections-create",children:[i.jsx("input",{className:"af-set-input af-set-input--sm",value:v,onChange:q=>w(q.target.value),onKeyDown:q=>{q.key==="Enter"&&ts()},placeholder:"新建 skill collection"}),i.jsxs("button",{type:"button",className:"af-set-btn-add af-set-btn-add--compact",disabled:!v.trim()||N,onClick:()=>ts(),children:[i.jsx("span",{className:"material-symbols-outlined",children:"add"}),"新建"]})]})}):null]}):null,Gt?i.jsx("div",{className:"af-resource-grid",children:ve.length>0?ve.map(q=>i.jsxs("button",{type:"button",className:"af-resource-card"+(mt&&Hn(q)===Hn(mt)?" af-resource-card--active":""),onClick:()=>ce(Hn(q)),children:[i.jsxs("div",{className:"af-resource-card-head",children:[i.jsx("span",{className:Al(q.type==="control"?"secondary":q.type==="provide"?"primary":"muted"),children:i.jsx(Bn,{query:V,children:q.type||"node"})}),i.jsx("span",{className:"af-resource-source",children:i.jsx(Bn,{query:V,children:XN(q.source,n)})})]}),i.jsx("h3",{className:"af-project-title",children:i.jsx(Bn,{query:V,children:q.label||q.displayName||q.id})}),i.jsx("p",{className:"af-project-desc",children:i.jsx(Bn,{query:V,children:q.description||n("project:noDescription")})}),i.jsxs("div",{className:"af-resource-meta-row",children:[i.jsx("span",{children:i.jsx(Bn,{query:V,children:q.id})}),i.jsx("span",{children:n("project:nodeSlots",{inputs:Object.keys(q.inputs||{}).length,outputs:Object.keys(q.outputs||{}).length})})]}),q.packageId?i.jsxs("div",{className:"af-project-path",children:[i.jsx("span",{className:"material-symbols-outlined af-path-icon",children:"deployed_code"}),i.jsx("span",{className:"af-path-text",children:i.jsx(Bn,{query:V,children:`${q.packageId}${q.version?` / ${q.version}`:""}`})})]}):null]},`${q.id}:${q.source||""}:${q.packageId||""}`)):M?i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:dn?n("project:noNodeMatch",{query:V.trim()}):n(_t?"project:noMyNodes":"project:noNodes")})}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:loadingResources")})})}):le?i.jsx("div",{className:"af-resource-grid",children:tn.length>0?tn.map(q=>{const pe=EP(q),Oe=AP(q),Ee=Number.isFinite(Number(q.nodeCount))?Number(q.nodeCount):pe.length,et=Number.isFinite(Number(q.edgeCount))?Number(q.edgeCount):Oe.length;return i.jsxs("button",{type:"button",className:"af-resource-card"+(Wt&&jo(q)===jo(Wt)?" af-resource-card--active":""),onClick:()=>ce(jo(q)),children:[i.jsxs("div",{className:"af-resource-card-head",children:[i.jsx("span",{className:Al("primary"),children:i.jsx(Bn,{query:V,children:q.version?`v${q.version}`:"flow"})}),i.jsx("span",{className:"af-resource-source",children:n("project:flowSnippet")})]}),i.jsx("h3",{className:"af-project-title",children:i.jsx(Bn,{query:V,children:q.displayName||q.name||q.id})}),i.jsx("p",{className:"af-project-desc",children:i.jsx(Bn,{query:V,children:q.description||n("project:noDescription")})}),i.jsxs("div",{className:"af-resource-meta-row",children:[i.jsx("span",{children:n("project:flowSnippetNodes",{nodes:Ee,edges:et})}),i.jsx("span",{children:i.jsx(Bn,{query:V,children:q.id})})]}),i.jsxs("div",{className:"af-project-path",children:[i.jsx("span",{className:"material-symbols-outlined af-path-icon",children:"schema"}),i.jsx("span",{className:"af-path-text",children:i.jsx(Bn,{query:V,children:QN(q)})})]})]},jo(q))}):M?i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:dn?n("project:noFlowSnippetMatch",{query:V.trim()}):n("project:noMyFlows")})}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:loadingResources")})})}):a==="skills"?i.jsx("div",{className:"af-resource-grid",children:Jt.length>0?Jt.map(q=>{const pe=Hn(q),Oe=b.filter(Ee=>{var et;return(et=it.get(Ee.id))==null?void 0:et.has(pe)});return i.jsxs("button",{type:"button",className:"af-resource-card"+(nn&&pe===Hn(nn)?" af-resource-card--active":""),onClick:()=>ce(pe),children:[i.jsxs("div",{className:"af-resource-card-head",children:[i.jsx("span",{className:Al(q.source==="builtin"?"muted":"primary"),children:i.jsx(Bn,{query:V,children:q.sourceLabel||q.source||"skill"})}),i.jsx("span",{className:"af-resource-source",children:n("project:skill")})]}),i.jsx("h3",{className:"af-project-title",children:i.jsx(Bn,{query:V,children:q.name||q.id})}),i.jsx("p",{className:"af-project-desc",children:i.jsx(Bn,{query:V,children:q.description||n("project:noDescription")})}),i.jsxs("div",{className:"af-project-path",children:[i.jsx("span",{className:"material-symbols-outlined af-path-icon",children:"extension"}),i.jsx("span",{className:"af-path-text",children:i.jsx(Bn,{query:V,children:q.path||q.key||""})})]}),i.jsxs("div",{className:"af-skill-card-collections",children:[Oe.slice(0,3).map(Ee=>i.jsx("span",{children:Ee.name},Ee.id)),Oe.length===0?i.jsx("span",{className:"af-skill-card-collection-empty",children:"未分组"}):null]})]},q.key||`${q.source}:${q.name}`)}):M?i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:dn?n("project:noSkillMatch",{query:V.trim()}):n("project:noSkills")})}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:loadingResources")})})}):i.jsxs(i.Fragment,{children:[t!=null&&t.isAdmin&&a==="all"&&Ct.length>0?i.jsxs("div",{className:"af-project-admin-panel",children:[i.jsxs("div",{children:[i.jsx("strong",{children:"已隐藏内置"}),i.jsx("span",{children:"这些包内置流水线不会出现在普通项目列表中。"})]}),i.jsx("div",{className:"af-project-admin-hidden-list",children:Ct.map(q=>{const pe=Je===`show-builtin:builtin:${q}`;return i.jsxs("button",{type:"button",disabled:pe,onClick:()=>Xn({id:q,source:"builtin"},"show-builtin"),children:[i.jsx("span",{children:q}),i.jsx("em",{children:pe?"恢复中":"恢复"})]},q)})})]}):null,i.jsxs("div",{className:"af-project-grid",children:[br.length>0?br.map(q=>{var Nn,kt;const pe=(t==null?void 0:t.isAdmin)&&q.source==="user"&&!q.archived&&!sr.has(q.id),Oe=(t==null?void 0:t.isAdmin)&&q.source==="admin",Ee=(t==null?void 0:t.isAdmin)&&q.source==="builtin",et=Je.endsWith(`:${q.source}:${q.id}`);return i.jsx("div",{className:EF(q.source),role:"button",tabIndex:0,onClick:()=>zr(q),onKeyDown:Ut=>{(Ut.key==="Enter"||Ut.key===" ")&&(Ut.preventDefault(),zr(q))},children:i.jsxs("div",{className:"af-project-card-body",children:[i.jsx("span",{className:Al(Sx(q.source,n).tone),children:i.jsx(Bn,{query:V,children:Sx(q.source,n).label})}),q.source==="workspace"&&((Nn=q.collaboration)!=null&&Nn.role)?i.jsx("span",{className:Al(q.collaboration.role==="owner"?"primary":"muted"),children:q.collaboration.role==="owner"?"我创建的":`${q.collaboration.ownerUsername||q.collaboration.ownerId} 分享`}):null,q.archived?i.jsx("span",{className:Al("muted"),children:i.jsx(Bn,{query:V,children:n("project:archived")})}):null,i.jsx("h3",{className:"af-project-title",children:i.jsx(Bn,{query:V,children:q.id})}),i.jsx("p",{className:"af-project-desc",children:i.jsx(Bn,{query:V,children:CP(q,n)})}),i.jsxs("div",{className:"af-project-path",children:[i.jsx("span",{className:"material-symbols-outlined af-path-icon",children:"database"}),i.jsx("span",{className:"af-path-text",children:i.jsx(Bn,{query:V,children:jP(q)})})]}),t!=null&&t.isAdmin?i.jsxs("div",{className:"af-project-admin-actions",onClick:Ut=>Ut.stopPropagation(),onKeyDown:Ut=>Ut.stopPropagation(),children:[pe?i.jsx("button",{type:"button",disabled:et,onClick:()=>Xn(q,"promote"),children:"设为内置"}):null,Oe?i.jsx("button",{type:"button",disabled:et,onClick:()=>Xn(q,"unpromote"),children:"取消内置"}):null,Ee?i.jsx("button",{type:"button",disabled:et,onClick:()=>Xn(q,"hide-builtin"),children:"隐藏内置"}):null]}):null]})},`${q.id}:${q.source??"user"}:${q.archived?"a":""}:${((kt=q.collaboration)==null?void 0:kt.id)||"own"}`)}):F?Qn.length===0?i.jsxs("div",{className:"af-projects-empty-block",children:[i.jsx("p",{className:"af-projects-empty",children:a==="archived"?n("project:noArchived"):c.length>0?n("project:noActive"):n(I?"project:loadFailed":"project:noPipelines")}),!I&&c.length===0&&a==="all"?i.jsx("p",{className:"af-projects-empty-hint",children:n("project:emptyHint",{code1:"agentflow ui",code2:".agentflow/pipelines"})}):null]}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:noMatch",{query:V.trim()})})}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:loadingPipelines")})}),i.jsxs("button",{type:"button",className:"af-project-add",onClick:()=>D(!0),children:[i.jsx("span",{className:"material-symbols-outlined af-project-add-icon",children:"add_circle"}),i.jsx("span",{className:"af-project-add-label",children:n("project:newPipeline")})]}),re?null:i.jsxs("a",{className:"af-hub-card",href:"https://agentflow-hub.com",target:"_blank",rel:"noopener noreferrer",children:[i.jsx("div",{className:"af-hub-card__glow","aria-hidden":!0}),i.jsxs("span",{className:"af-hub-card__eyebrow",children:[i.jsx("span",{className:"material-symbols-outlined af-hub-card__eyebrow-icon",children:"hub"}),n("project:hubCard.eyebrow")]}),i.jsx("h3",{className:"af-hub-card__title",children:n("project:hubCard.title")}),i.jsx("p",{className:"af-hub-card__desc",children:n("project:hubCard.desc")}),i.jsxs("span",{className:"af-hub-card__cta",children:[n("project:hubCard.cta"),i.jsx("span",{className:"material-symbols-outlined af-hub-card__cta-icon",children:"arrow_outward"})]}),i.jsx("code",{className:"af-hub-card__cli",children:n("project:hubCard.cliHint")})]})]})]})]}),Zn?i.jsx("aside",{className:"af-resource-detail","aria-label":n(Gt?"project:nodeDetail":le?"project:flowDetail":"project:skillDetail"),children:Gt&&mt?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-resource-detail-head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"account_tree"}),i.jsxs("div",{children:[i.jsx("h3",{children:mt.label||mt.displayName||mt.id}),i.jsx("p",{children:mt.id})]})]}),i.jsx("div",{className:"af-resource-detail-tabs",children:["overview","schema","runtime","files","usage"].map(q=>i.jsx("button",{type:"button",className:"af-resource-detail-tab"+(de===q?" af-resource-detail-tab--active":""),onClick:()=>me(q),children:n(`project:nodeDetailTabs.${q}`)},q))}),Te===Hn(mt)?i.jsx("p",{className:"af-resource-detail-desc",children:n("project:loadingResources")}):de==="overview"?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"af-resource-detail-desc",children:mt.description||((Pe=tt==null?void 0:tt.node)==null?void 0:Pe.description)||n("project:noDescription")}),i.jsxs("dl",{className:"af-resource-detail-kv",children:[i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailType")}),i.jsx("dd",{children:mt.type||((xt=tt==null?void 0:tt.node)==null?void 0:xt.type)||"node"})]}),i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailSource")}),i.jsx("dd",{children:XN(mt.source,n)})]}),mt.packageId?i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailPackage")}),i.jsx("dd",{children:mt.packageId})]}):null,mt.version?i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailVersion")}),i.jsx("dd",{children:mt.version})]}):null,mt.packageDir||tt!=null&&tt.baseDir?i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailPath")}),i.jsx("dd",{children:mt.packageDir||(tt==null?void 0:tt.baseDir)})]}):null,i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailEditable")}),i.jsx("dd",{children:(tt==null?void 0:tt.readOnly)===!1?n("project:editable"):n("project:readOnly")})]})]}),_t&&mt.source==="marketplace"?i.jsxs("div",{className:"af-resource-detail-section af-resource-danger-zone",children:[i.jsx("h4",{children:n("project:myNodeManagement")}),i.jsx("p",{children:n("project:deleteMyNodeHint")}),i.jsxs("button",{type:"button",className:"af-btn-secondary af-btn-danger",disabled:Ke===Hn(mt),onClick:()=>ys(mt),children:[i.jsx("span",{className:"material-symbols-outlined",children:"delete"}),Ke===Hn(mt)?n("project:deletingMyNode"):n("project:deleteMyNode")]}),be?i.jsx("p",{className:"af-resource-action-message",children:be}):null]}):null,i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:resourceMeaning")}),i.jsx("p",{children:n("project:nodesMeaning")})]})]}):de==="schema"?i.jsxs("div",{className:"af-resource-detail-section af-resource-detail-section--plain",children:[i.jsx("h4",{children:n("project:nodeSchema")}),i.jsxs("div",{className:"af-resource-slot-group",children:[i.jsx("span",{children:n("project:nodeInputs")}),yp(((Lt=tt==null?void 0:tt.node)==null?void 0:Lt.inputs)||mt.inputs).length>0?yp(((qt=tt==null?void 0:tt.node)==null?void 0:qt.inputs)||mt.inputs).map(q=>i.jsxs("code",{children:[q.name||q.key,q.type?`: ${q.type}`:""]},q.key)):i.jsx("em",{children:n("project:noSlots")})]}),i.jsxs("div",{className:"af-resource-slot-group",children:[i.jsx("span",{children:n("project:nodeOutputs")}),yp(((zn=tt==null?void 0:tt.node)==null?void 0:zn.outputs)||mt.outputs).length>0?yp(((On=tt==null?void 0:tt.node)==null?void 0:On.outputs)||mt.outputs).map(q=>i.jsxs("code",{children:[q.name||q.key,q.type?`: ${q.type}`:""]},q.key)):i.jsx("em",{children:n("project:noSlots")})]})]}):de==="runtime"?i.jsxs("div",{className:"af-resource-detail-section af-resource-detail-section--plain",children:[i.jsx("h4",{children:n("project:nodeRuntime")}),tt!=null&&tt.runtime?i.jsx("pre",{className:"af-resource-skill-preview",children:JSON.stringify(tt.runtime,null,2)}):i.jsx("p",{children:n("project:noRuntimeManifest")}),tt!=null&&tt.body?i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"af-resource-detail-subtitle",children:n("project:nodeBody")}),i.jsx("pre",{className:"af-resource-skill-preview",children:tt.body})]}):i.jsx("p",{children:n("project:noNodeBody")})]}):de==="files"?i.jsxs("div",{className:"af-resource-detail-section af-resource-detail-section--plain",children:[i.jsx("h4",{children:n("project:nodeFiles")}),Array.isArray(tt==null?void 0:tt.files)&&tt.files.length>0?i.jsxs("div",{className:"af-node-file-browser",children:[i.jsx("div",{className:"af-node-file-list",children:tt.files.map(q=>i.jsxs("button",{type:"button",className:"af-node-file-item"+(gt===q.path?" af-node-file-item--active":""),onClick:()=>xe(q.path),children:[i.jsx("span",{className:"material-symbols-outlined",children:"description"}),i.jsx("span",{children:q.path})]},q.path))}),i.jsxs("pre",{className:"af-resource-skill-preview",children:[oe===`${Hn(mt)}:${gt}`?n("project:loadingResources"):Ln!=null&&Ln.binary?n("project:binaryFile"):(Ln==null?void 0:Ln.content)||n("project:selectNodeFile"),Ln!=null&&Ln.truncated?`
42
+ `).toLowerCase().includes(n):!0}function XN(e,t){return e==="flow"?t("project:resourceSource.flow"):e==="marketplace"?t("project:resourceSource.marketplace"):e==="project"?t("project:resourceSource.global"):e||t("project:resourceSource.global")}function QN(e){return e!=null&&e.packageDir?e.packageDir:`marketplace/flow-snippets / ${(e==null?void 0:e.id)||""}`}const $F=["all","agent","control","provide","marketplace"],LF=["all","agent","control","provide"],_P="agentflow.projects.activityPanelOpen",Nx="agentflow.projects.activitySelected";function OF(){if(typeof localStorage>"u")return!0;const e=localStorage.getItem(_P);return e!=="0"}function ZN(e){return`${(e==null?void 0:e.flowSource)||"user"}:${(e==null?void 0:e.flowId)||""}`}function DF(){return typeof localStorage>"u"?"":localStorage.getItem(Nx)||""}function yp(e){return!e||typeof e!="object"?[]:Object.entries(e).map(([t,n])=>({key:t,...n&&typeof n=="object"?n:{}}))}function Hn(e){return(e==null?void 0:e.key)||`${(e==null?void 0:e.id)||(e==null?void 0:e.name)||""}:${(e==null?void 0:e.source)||""}:${(e==null?void 0:e.packageId)||""}`}function FF(e,t){if((e==null?void 0:e.source)!=="marketplace")return!1;const n=String((e==null?void 0:e.ownerUserId)||(e==null?void 0:e.createdBy)||"").trim();return n?new Set([String((t==null?void 0:t.userId)||"").trim(),String((t==null?void 0:t.username)||"").trim()].filter(Boolean)).has(n):!0}function jo(e){return`${(e==null?void 0:e.id)||""}:${(e==null?void 0:e.version)||""}:${(e==null?void 0:e.packageDir)||""}`}function EP(e){var n;const t=(n=e==null?void 0:e.snippet)==null?void 0:n.instances;return Array.isArray(t)?t.filter(r=>r&&typeof r=="object"):t&&typeof t=="object"?Object.entries(t).map(([r,s])=>({...s&&typeof s=="object"?s:{},instanceId:(s==null?void 0:s.instanceId)||r})):[]}function AP(e){var n;const t=(n=e==null?void 0:e.snippet)==null?void 0:n.edges;return Array.isArray(t)?t.filter(r=>r&&typeof r=="object"):[]}function jx(e,t){return String((e==null?void 0:e.instanceId)||(e==null?void 0:e.id)||(e==null?void 0:e.nodeId)||`node_${t+1}`)}function ej(e,t){return String((e==null?void 0:e.label)||(e==null?void 0:e.displayName)||(e==null?void 0:e.name)||jx(e,t))}function zF(e){return String((e==null?void 0:e.definitionId)||(e==null?void 0:e.type)||(e==null?void 0:e.runtimeType)||"").replace(/^marketplace:/,"")}function tj(e,t){return String(t==="source"?(e==null?void 0:e.source)||(e==null?void 0:e.from)||(e==null?void 0:e.sourceId)||(e==null?void 0:e.fromNode)||(e==null?void 0:e.fromInstanceId)||"":(e==null?void 0:e.target)||(e==null?void 0:e.to)||(e==null?void 0:e.targetId)||(e==null?void 0:e.toNode)||(e==null?void 0:e.toInstanceId)||"")}function BF(e){const t=(e==null?void 0:e.sourceHandle)||(e==null?void 0:e.fromHandle)||(e==null?void 0:e.output)||(e==null?void 0:e.outputName),n=(e==null?void 0:e.targetHandle)||(e==null?void 0:e.toHandle)||(e==null?void 0:e.input)||(e==null?void 0:e.inputName);return t&&n?`${t} -> ${n}`:String(t||n||"")}function Iy(e,t=16){const n=String(e||"").trim();return n.length<=t?n:`${n.slice(0,t-1)}…`}function HF(e){const t=Number(e==null?void 0:e.x),n=Number(e==null?void 0:e.y);return!Number.isFinite(t)||!Number.isFinite(n)?null:{x:t,y:n}}function WF(e,t){const n=e.map(d=>d.id),r=new Set(n),s=new Map(n.map(d=>[d,0])),o=new Map(n.map(d=>[d,[]]));t.forEach(d=>{var f;!r.has(d.sourceId)||!r.has(d.targetId)||(s.set(d.targetId,(s.get(d.targetId)||0)+1),(f=o.get(d.sourceId))==null||f.push(d.targetId))});const a=new Map,l=n.filter(d=>(s.get(d)||0)===0);l.length===0&&n[0]&&l.push(n[0]),l.forEach(d=>a.set(d,0));for(let d=0;d<l.length;d+=1){const f=l[d],p=(a.get(f)||0)+1;for(const h of o.get(f)||[])(!a.has(h)||p>a.get(h))&&(a.set(h,p),l.push(h))}n.forEach((d,f)=>{a.has(d)||a.set(d,f%3)});const c=new Map,u=new Map;return n.forEach(d=>{const f=a.get(d)||0,p=c.get(f)||0;c.set(f,p+1),u.set(d,{x:f*190,y:p*86})}),u}function VF(e){var k,b,g,v;const t=EP(e),n=AP(e),r=new Map(t.map((w,N)=>[jx(w,N),ej(w,N)])),s=t.map((w,N)=>({id:jx(w,N),title:ej(w,N),meta:zF(w)})),o=n.map((w,N)=>{const j=tj(w,"source"),C=tj(w,"target");return{key:(w==null?void 0:w.id)||`${j}-${C}-${N}`,sourceId:j,targetId:C,source:r.get(j)||j||"?",target:r.get(C)||C||"?",label:BF(w)}}),a=(b=(k=e==null?void 0:e.snippet)==null?void 0:k.ui)!=null&&b.nodePositions&&typeof e.snippet.ui.nodePositions=="object"?e.snippet.ui.nodePositions:{},l=(v=(g=e==null?void 0:e.snippet)==null?void 0:g.ui)!=null&&v.nodeSizes&&typeof e.snippet.ui.nodeSizes=="object"?e.snippet.ui.nodeSizes:{},c=WF(s,o),u=s.map(w=>{const N=HF(a[w.id])||c.get(w.id)||{x:0,y:0},j=l[w.id]&&typeof l[w.id]=="object"?l[w.id]:{},C=Number(j.width),P=Number(j.height),I=Math.max(132,Math.min(210,Number.isFinite(C)?C*.62:150)),z=Math.max(48,Math.min(76,Number.isFinite(P)?P*.46:54));return{...w,x:N.x,y:N.y,width:I,height:z}}),d=new Map(u.map(w=>[w.id,w])),f=o.map(w=>{const N=d.get(w.sourceId),j=d.get(w.targetId);if(!N||!j)return null;const C=N.x+N.width,P=N.y+N.height/2,I=j.x,z=j.y+j.height/2,$=Math.max(48,Math.abs(I-C)*.45);return{...w,path:`M ${C} ${P} C ${C+$} ${P}, ${I-$} ${z}, ${I} ${z}`,labelX:(C+I)/2,labelY:(P+z)/2}}).filter(Boolean),p=u.reduce((w,N)=>({minX:Math.min(w.minX,N.x),minY:Math.min(w.minY,N.y),maxX:Math.max(w.maxX,N.x+N.width),maxY:Math.max(w.maxY,N.y+N.height)}),{minX:0,minY:0,maxX:420,maxY:220}),h=36,y=`${p.minX-h} ${p.minY-h} ${Math.max(360,p.maxX-p.minX+h*2)} ${Math.max(180,p.maxY-p.minY+h*2)}`;return{nodes:s,edges:o,diagram:{nodes:u,edges:f,viewBox:y}}}function Pl({resourceKind:e="",authUser:t=null}){var Pe,xt,Lt,qt,zn,On;const{t:n}=Fr(),{navigate:r,path:s}=si(),o=!!(t!=null&&t.isAdmin),[a,l]=m.useState(e||"all"),[c,u]=m.useState([]),[d,f]=m.useState([]),[p,h]=m.useState([]),[y,k]=m.useState([]),[b,g]=m.useState([]),[v,w]=m.useState(""),[N,j]=m.useState(!1),[C,P]=m.useState([]),[I,z]=m.useState(""),[$,L]=m.useState(""),[F,O]=m.useState(!1),[M,K]=m.useState(!1),[H,D]=m.useState(!1),[T,W]=m.useState(null),[E,Q]=m.useState(!1),[V,B]=m.useState(""),[se,ue]=m.useState(OF),[G,ee]=m.useState(DF),[te,ne]=m.useState("all"),[Z,ce]=m.useState(""),[de,me]=m.useState("overview"),[$e,Ce]=m.useState({}),[_e,Be]=m.useState(""),[ot,yt]=m.useState({}),[Te,st]=m.useState(""),[gt,xe]=m.useState(""),[Fe,lt]=m.useState({}),[oe,ke]=m.useState(""),[Ke,Ue]=m.useState(""),[be,Ht]=m.useState(""),[Qt,jt]=m.useState(""),[yn,on]=m.useState(""),[re,Re]=m.useState(!1),[Je,Ze]=m.useState(""),[Tt,At]=m.useState({hiddenBuiltins:[],promoted:[]}),Vn=m.useRef(0),Sn=m.useRef(0),xr=m.useRef(0),wn=m.useCallback(async()=>{var he,Oe;const q=++Sn.current;z("");try{const Ee=await fetch("/api/flows");if(q!==Sn.current)return;if(!Ee.ok)throw new Error("HTTP "+Ee.status);const et=await Ee.json();if(q!==Sn.current)return;u(Array.isArray(et)?et:[])}catch(Ee){if(q!==Sn.current)return;u([]),z(String(Ee.message||Ee))}try{const Ee=await fetch("/api/pipeline-recent-runs");if(q!==Sn.current)return;if(Ee.ok){const et=await Ee.json();if(q!==Sn.current)return;P(Array.isArray(et.runs)?et.runs:[])}else P([])}catch{if(q!==Sn.current)return;P([])}if(t!=null&&t.isAdmin)try{const Ee=await fetch("/api/admin/builtin-flows");if(q!==Sn.current)return;const et=await Ee.json().catch(()=>({}));Ee.ok&&At({hiddenBuiltins:Array.isArray((he=et==null?void 0:et.config)==null?void 0:he.hiddenBuiltins)?et.config.hiddenBuiltins:[],promoted:Array.isArray((Oe=et==null?void 0:et.config)==null?void 0:Oe.promoted)?et.config.promoted:[]})}catch{if(q!==Sn.current)return;At({hiddenBuiltins:[],promoted:[]})}else At({hiddenBuiltins:[],promoted:[]});O(!0)},[t==null?void 0:t.isAdmin]),Xn=m.useCallback(async(q,he)=>{if(!(t!=null&&t.isAdmin)||!(q!=null&&q.id))return;const Oe=`${he}:${q.source}:${q.id}`;Ze(Oe),z("");try{const Ee=await fetch("/api/admin/builtin-flows",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:he,flowId:q.id,ownerUserId:q.ownerUserId||t.userId})}),et=await Ee.json().catch(()=>({}));if(!Ee.ok)throw new Error(et.error||"更新内置配置失败");await wn()}catch(Ee){z(String(Ee.message||Ee))}finally{Ze("")}},[t==null?void 0:t.isAdmin,t==null?void 0:t.userId,wn]),Kn=m.useCallback(async()=>{const q=++xr.current;L(""),K(!1);const he="/api/nodes",Oe=e==="my-flows"?"/api/marketplace/flow-snippets?scope=owned":"/api/marketplace/flow-snippets";f([]),k([]),ce("");try{const[Ee,et,Nn,kt]=await Promise.all([fetch(he),fetch("/api/skills"),fetch("/api/skill-collections"),fetch(Oe)]),Ut=await Ee.json().catch(()=>({})),jn=await et.json().catch(()=>({})),go=await Nn.json().catch(()=>({})),at=await kt.json().catch(()=>({}));if(!Ee.ok)throw new Error(Ut.error||"Nodes HTTP "+Ee.status);if(!et.ok)throw new Error(jn.error||"Skills HTTP "+et.status);if(!Nn.ok)throw new Error(go.error||"Collections HTTP "+Nn.status);if(!kt.ok)throw new Error(at.error||"Flow snippets HTTP "+kt.status);if(q!==xr.current)return;f(Array.isArray(Ut.nodes)?Ut.nodes:Array.isArray(Ut)?Ut:[]),h(Array.isArray(jn.skills)?jn.skills:[]),g(Oa(go)),k(Array.isArray(at.snippets)?at.snippets:[])}catch(Ee){if(q!==xr.current)return;f([]),h([]),k([]),g([]),L(String(Ee.message||Ee))}finally{if(q!==xr.current)return;K(!0)}},[e]);m.useEffect(()=>{O(!1),wn(),Kn()},[wn,Kn]),m.useEffect(()=>{try{localStorage.setItem(_P,se?"1":"0")}catch{}},[se]),m.useEffect(()=>{try{G?localStorage.setItem(Nx,G):localStorage.removeItem(Nx)}catch{}},[G]),m.useEffect(()=>{let q=!1;return fetch("/api/ui-context").then(he=>he.json()).then(he=>{q||Re(!!he.hideCommunityLinks)}).catch(()=>{}),()=>{q=!0}},[]);const hr=m.useCallback(async q=>{if(!o)return;const he=Oa({collections:q});j(!0),L("");try{const Oe=await fetch("/api/skill-collections",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(kF(he))}),Ee=await Oe.json().catch(()=>({}));if(!Oe.ok)throw new Error(Ee.error||"Collections HTTP "+Oe.status);g(Oa(Ee))}catch(Oe){L(String(Oe.message||Oe))}finally{j(!1)}},[o]),ts=m.useCallback(()=>{if(!o)return;const q=v.trim();if(!q)return;const he=q.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"collection",Oe=new Set(b.map(kt=>kt.id));let Ee=he,et=2;for(;Oe.has(Ee);)Ee=`${he}-${et++}`;const Nn=Date.now();hr([...b,{id:Ee,name:q,skillKeys:[],createdAt:Nn,updatedAt:Nn}]),w(""),ne(`collection:${Ee}`)},[o,v,hr,b]),Ar=m.useCallback(q=>{if(!o)return;const he=b.find(Ee=>Ee.id===q);if(he!=null&&he.builtin)return;const Oe=b.filter(Ee=>Ee.id!==q);te===`collection:${q}`&&ne("all"),hr(Oe)},[o,te,hr,b]),gs=m.useCallback((q,he,Oe)=>{if(!o)return;const Ee=String(he||"").trim();if(!Ee)return;const et=Date.now(),Nn=b.map(kt=>{if(kt.id!==q)return kt;const Ut=new Set(kt.skillKeys||[]);return Oe?Ut.add(Ee):Ut.delete(Ee),{...kt,skillKeys:Array.from(Ut),updatedAt:et}});hr(Nn)},[o,hr,b]),ys=m.useCallback(async q=>{const he=q==null?void 0:q.packageId,Oe=q==null?void 0:q.version;if(!he||!Oe||!window.confirm(n("project:deleteMyNodeConfirm",{id:he,version:Oe})))return;const Ee=Hn(q);Ue(Ee),Ht(""),L("");try{const et=new URLSearchParams({id:he,version:Oe}),Nn=await fetch(`/api/marketplace/node?${et.toString()}`,{method:"DELETE"}),kt=await Nn.json().catch(()=>({}));if(!Nn.ok||(kt==null?void 0:kt.ok)===!1){const Ut=Array.isArray(kt==null?void 0:kt.usage)&&kt.usage.length>0?` ${n("project:deleteMyNodeUsedBy",{count:kt.usage.length})}`:"";throw new Error(((kt==null?void 0:kt.error)||"Delete failed")+Ut)}Ht(n("project:deleteMyNodeSuccess",{id:he,version:Oe})),yt(Ut=>{const jn={...Ut};return delete jn[Ee],jn}),lt(Ut=>{const jn={};for(const[go,at]of Object.entries(Ut))go.startsWith(`${Ee}:`)||(jn[go]=at);return jn}),ce(""),await Kn()}catch(et){Ht(String(et.message||et))}finally{Ue("")}},[Kn,n]),cn=m.useCallback(async q=>{const he=q==null?void 0:q.id,Oe=(q==null?void 0:q.version)||"1.0.0";if(!he||!Oe||!window.confirm(n("project:deleteMyFlowConfirm",{id:he,version:Oe})))return;const Ee=jo(q);jt(Ee),on(""),L("");try{const et=new URLSearchParams({id:he,version:Oe}),Nn=await fetch(`/api/marketplace/flow-snippet?${et.toString()}`,{method:"DELETE"}),kt=await Nn.json().catch(()=>({}));if(!Nn.ok||(kt==null?void 0:kt.ok)===!1)throw new Error((kt==null?void 0:kt.error)||"Delete failed");on(n("project:deleteMyFlowSuccess",{id:he,version:Oe})),ce(""),await Kn()}catch(et){on(String(et.message||et))}finally{jt("")}},[Kn,n]);m.useEffect(()=>{if(e==="nodes"||e==="my-nodes"||e==="my-flows"||e==="skills"){l(e),ne("all"),ce(""),me("overview");return}l(q=>q==="archived"?"archived":"all")},[e]),m.useEffect(()=>{if(s!=="/projects"&&s!=="/")return;const q=new URLSearchParams(window.location.search),he=q.get("tab");let Oe=!1;if(he==="nodes"){r("/nodes");return}if(he==="my-nodes"){r("/my-nodes");return}if(he==="my-flows"){r("/my-flows");return}if(he==="skills"){r("/skills");return}if(he==="archived"?(l("archived"),q.delete("tab"),Oe=!0):he&&(l("all"),q.delete("tab"),Oe=!0),q.get("new")==="1"&&(D(!0),q.delete("new"),Oe=!0),Oe){const Ee=q.toString();window.history.replaceState({},"",Ee?`/projects?${Ee}`:"/projects")}},[s,r]);const rr=m.useMemo(()=>LD(C,MD(),c),[C,c,s]),Pr=m.useMemo(()=>rr.filter(q=>MF(V,q)),[rr,V]),dn=V.trim().toLowerCase(),Qn=m.useMemo(()=>a==="archived"?c.filter(q=>q.archived):c.filter(q=>!q.archived),[c,a]),br=m.useMemo(()=>Qn.filter(q=>TF(q,dn,n)),[Qn,dn,n]),sr=m.useMemo(()=>new Set((Tt.promoted||[]).map(q=>String((q==null?void 0:q.id)||"").trim()).filter(Boolean)),[Tt.promoted]),Ct=m.useMemo(()=>(Tt.hiddenBuiltins||[]).map(q=>String(q||"").trim()).filter(Boolean),[Tt.hiddenBuiltins]),Gt=a==="nodes"||a==="my-nodes",_t=a==="my-nodes",le=a==="my-flows",ve=m.useMemo(()=>d.filter(q=>_t&&!FF(q,t)?!1:(te==="all"||(te==="marketplace"?q.source==="marketplace":q.type===te))&&Py(V,[q.id,q.label,q.displayName,q.description,q.type,q.source,q.packageId,q.version])),[t,d,_t,V,te]),it=m.useMemo(()=>{const q=new Map;for(const he of b)q.set(he.id,new Set(Qo(he,p)));return q},[p,b]),Dt=m.useMemo(()=>[{id:"all",label:"全部"},...b.map(q=>{var he;return{id:`collection:${q.id}`,label:q.name,count:((he=it.get(q.id))==null?void 0:he.size)||0,collection:q}}),{id:"ungrouped",label:"未分组"}],[it,b]),Jt=m.useMemo(()=>p.filter(q=>{var Ee;const he=Hn(q);let Oe=te==="all";if(te.startsWith("collection:")){const et=te.slice(11);Oe=!!((Ee=it.get(et))!=null&&Ee.has(he))}else te==="ungrouped"&&(Oe=!Array.from(it.values()).some(et=>et.has(he)));return Oe&&Py(V,[q.name,q.id,q.description,q.sourceLabel,q.source,q.path])}),[p,V,te,it]),tn=m.useMemo(()=>y.filter(q=>Py(V,[q.id,q.name,q.displayName,q.description,q.version,q.packageDir,Array.isArray(q.tags)?q.tags.join(" "):""])),[y,V]),Zn=Gt||le||a==="skills",mt=m.useMemo(()=>ve.find(q=>Hn(q)===Z)||ve[0]||null,[ve,Z]),nn=m.useMemo(()=>Jt.find(q=>Hn(q)===Z)||Jt[0]||null,[Jt,Z]),Wt=m.useMemo(()=>tn.find(q=>jo(q)===Z)||tn[0]||null,[tn,Z]),kr=nn?$e[Hn(nn)]:null,tt=mt?ot[Hn(mt)]:null,Ln=mt&&gt?Fe[`${Hn(mt)}:${gt}`]:null,$i=n(Gt?"project:searchNodes":le?"project:searchFlows":a==="skills"?"project:searchSkills":"project:searchPipelines");m.useEffect(()=>{if(a!=="skills"||!nn)return;const q=Hn(nn);if($e[q])return;let he=!1;return Be(q),fetch(`/api/skills/detail?key=${encodeURIComponent(q)}`).then(Oe=>Oe.json().then(Ee=>({ok:Oe.ok,json:Ee}))).then(({ok:Oe,json:Ee})=>{he||Oe&&Ee.skill&&Ce(et=>({...et,[q]:Ee.skill}))}).catch(()=>{}).finally(()=>{he||Be("")}),()=>{he=!0}},[a,nn,$e]),m.useEffect(()=>{if(!Gt||!mt)return;const q=Hn(mt);if(ot[q])return;let he=!1;return st(q),fetch(`/api/nodes/detail?id=${encodeURIComponent(mt.id)}`).then(Oe=>Oe.json().then(Ee=>({ok:Oe.ok,json:Ee}))).then(({ok:Oe,json:Ee})=>{he||Oe&&yt(et=>({...et,[q]:Ee}))}).catch(()=>{}).finally(()=>{he||st("")}),()=>{he=!0}},[Gt,mt,ot]),m.useEffect(()=>{if(!Gt)return;const q=Array.isArray(tt==null?void 0:tt.files)?tt.files:[];xe(he=>{var Oe;return he&&q.some(Ee=>Ee.path===he)?he:((Oe=q[0])==null?void 0:Oe.path)||""})},[Gt,tt]),m.useEffect(()=>{if(!Gt||!mt||!gt)return;const q=`${Hn(mt)}:${gt}`;if(Fe[q])return;let he=!1;return ke(q),fetch(`/api/nodes/file?id=${encodeURIComponent(mt.id)}&path=${encodeURIComponent(gt)}`).then(Oe=>Oe.json().then(Ee=>({ok:Oe.ok,json:Ee}))).then(({ok:Oe,json:Ee})=>{he||Oe&&lt(et=>({...et,[q]:Ee}))}).catch(()=>{}).finally(()=>{he||ke("")}),()=>{he=!0}},[Gt,mt,gt,Fe]),m.useEffect(()=>{Ht("")},[Z,a]);const zr=q=>{r(gp(q,"workspace"))},mo=q=>{ee(ZN(q)),r(gp({id:q.flowId,source:q.flowSource,archived:!!q.archived},"workspace"))},ai=m.useCallback(q=>{var he,Oe;q.preventDefault(),q.stopPropagation(),(Oe=(he=q.dataTransfer)==null?void 0:he.types)!=null&&Oe.includes("Files")&&(Vn.current+=1,Q(!0))},[]),Ts=m.useCallback(q=>{q.preventDefault(),q.stopPropagation(),Vn.current-=1,Vn.current<=0&&(Vn.current=0,Q(!1))},[]),ie=m.useCallback(q=>{q.preventDefault(),q.stopPropagation()},[]),Se=m.useCallback(q=>{var Ee,et;q.preventDefault(),q.stopPropagation(),Vn.current=0,Q(!1);const he=(et=(Ee=q.dataTransfer)==null?void 0:Ee.files)==null?void 0:et[0];if(!he)return;const Oe=he.name.toLowerCase();!Oe.endsWith(".yaml")&&!Oe.endsWith(".yml")&&!Oe.endsWith(".zip")||W(he)},[]);return i.jsxs("div",{className:"af-projects"+(E?" af-projects--drop-target":""),onDragEnter:ai,onDragLeave:Ts,onDragOver:ie,onDrop:Se,children:[i.jsxs("header",{className:"af-projects-top",children:[e?i.jsx("div",{className:"af-projects-tabs af-projects-tabs--empty","aria-hidden":!0}):i.jsxs("div",{className:"af-projects-tabs",children:[i.jsx("button",{type:"button",className:a==="all"?"af-tab af-tab--active":"af-tab",onClick:()=>l("all"),children:n("project:all")}),i.jsx("button",{type:"button",className:a==="archived"?"af-tab af-tab--active":"af-tab",onClick:()=>l("archived"),children:n("project:archived")})]}),i.jsxs("div",{className:"af-projects-top-right",children:[i.jsxs("div",{className:"af-search-wrap",children:[i.jsx("span",{className:"material-symbols-outlined af-search-icon",children:"search"}),i.jsx("input",{className:"af-search"+(V.trim()?" af-search--has-clear":""),type:"search",placeholder:$i,"aria-label":$i,autoComplete:"off",value:V,onChange:q=>B(q.target.value),onKeyDown:q=>{q.key==="Escape"&&(B(""),q.currentTarget.blur())}}),V.trim()?i.jsx("button",{type:"button",className:"af-search-clear","aria-label":"Clear search",onClick:()=>B(""),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),Zn?i.jsx("button",{type:"button",className:"af-btn-primary af-create-btn",onClick:()=>Kn(),children:n("project:refreshResources")}):i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"af-icon-btn"+(se?" af-icon-btn--active":""),"aria-label":n("flow:palette.toggleRecentActivity"),"aria-expanded":se,"aria-controls":"af-recent-activity-panel",onClick:()=>ue(q=>!q),children:i.jsx("span",{className:"material-symbols-outlined",children:"notifications"})}),i.jsx("button",{type:"button",className:"af-btn-primary af-create-btn",onClick:()=>D(!0),children:n("project:createNew")})]})]})]}),i.jsxs("div",{className:"af-projects-body",children:[i.jsxs("section",{className:"af-projects-main",children:[i.jsxs("header",{className:"af-projects-section-head",children:[i.jsx("h2",{className:"af-projects-h2",children:n(a==="my-nodes"?"project:myNodes":a==="my-flows"?"project:myFlows":a==="nodes"?"project:nodes":a==="skills"?"project:globalSkills":a==="archived"?"project:archivedPipelines":"project:activeProjects")}),i.jsx("p",{className:"af-projects-sub",children:dn?n("project:filterResult",{count:a==="nodes"||a==="my-nodes"?ve.length:a==="my-flows"?tn.length:a==="skills"?Jt.length:br.length}):a==="my-nodes"?n("project:myNodesHint",{count:ve.length}):a==="my-flows"?n("project:myFlowsHint",{count:tn.length}):a==="nodes"?n("project:nodesHint",{count:d.length}):a==="skills"?n("project:skillsHint",{count:p.length}):n(a==="archived"?"project:archivedHint":"project:activeHint")}),I?i.jsx("p",{className:"af-err af-projects-api-hint",children:I}):null,$&&Zn?i.jsx("p",{className:"af-err af-projects-api-hint",children:$}):null]}),Zn?i.jsxs("div",{className:"af-resource-toolbar",children:[a==="skills"?i.jsx(bF,{onChanged:Kn,canManage:!!(t!=null&&t.isAdmin)}):null,i.jsxs("div",{className:"af-resource-purpose",children:[i.jsx("span",{className:"material-symbols-outlined",children:le?"schema":Gt?_t?"deployed_code":"account_tree":"extension"}),i.jsxs("div",{children:[i.jsx("h3",{children:n(le?"project:myFlowsPurposeTitle":_t?"project:myNodesPurposeTitle":Gt?"project:nodesPurposeTitle":"project:skillsPurposeTitle")}),i.jsx("p",{children:n(le?"project:myFlowsPurposeDesc":_t?"project:myNodesPurposeDesc":Gt?"project:nodesPurposeDesc":"project:skillsPurposeDesc")})]})]}),le?null:i.jsxs(i.Fragment,{children:[Gt?i.jsxs("div",{className:"af-resource-filter-row",children:[i.jsx("button",{type:"button",className:"af-resource-filter"+(_t?"":" af-resource-filter--active"),onClick:()=>{l("nodes"),ne("all"),ce("")},children:n("project:nodeScopeAll")}),i.jsx("button",{type:"button",className:"af-resource-filter"+(_t?" af-resource-filter--active":""),onClick:()=>{l("my-nodes"),ne("all"),ce("")},children:n("project:nodeScopeMine")})]}):null,i.jsx("div",{className:"af-resource-filter-row",children:(Gt?(_t?LF:$F).map(q=>({id:q,label:n(`project:resourceFilter.${q}`)})):Dt).map(q=>q.collection?i.jsxs("span",{className:"af-resource-filter-chip"+(te===q.id?" af-resource-filter-chip--active":""),children:[i.jsxs("button",{type:"button",className:"af-resource-filter af-resource-filter--embedded",onClick:()=>{ne(q.id),ce("")},children:[q.label,i.jsx("em",{children:q.count}),q.collection.builtin?i.jsx("strong",{children:"built-in"}):null]}),o&&!q.collection.builtin?i.jsx("button",{type:"button",className:"af-resource-filter-chip__delete",disabled:N,"aria-label":`删除 ${q.collection.name}`,onClick:()=>Ar(q.collection.id),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})}):null]},q.id):i.jsx("button",{type:"button",className:"af-resource-filter"+(te===q.id?" af-resource-filter--active":""),onClick:()=>{ne(q.id),ce("")},children:q.label},q.id))})]}),a==="skills"&&o?i.jsx("div",{className:"af-skill-collections-manager",children:i.jsxs("div",{className:"af-skill-collections-create",children:[i.jsx("input",{className:"af-set-input af-set-input--sm",value:v,onChange:q=>w(q.target.value),onKeyDown:q=>{q.key==="Enter"&&ts()},placeholder:"新建 skill collection"}),i.jsxs("button",{type:"button",className:"af-set-btn-add af-set-btn-add--compact",disabled:!v.trim()||N,onClick:()=>ts(),children:[i.jsx("span",{className:"material-symbols-outlined",children:"add"}),"新建"]})]})}):null]}):null,Gt?i.jsx("div",{className:"af-resource-grid",children:ve.length>0?ve.map(q=>i.jsxs("button",{type:"button",className:"af-resource-card"+(mt&&Hn(q)===Hn(mt)?" af-resource-card--active":""),onClick:()=>ce(Hn(q)),children:[i.jsxs("div",{className:"af-resource-card-head",children:[i.jsx("span",{className:Al(q.type==="control"?"secondary":q.type==="provide"?"primary":"muted"),children:i.jsx(Bn,{query:V,children:q.type||"node"})}),i.jsx("span",{className:"af-resource-source",children:i.jsx(Bn,{query:V,children:XN(q.source,n)})})]}),i.jsx("h3",{className:"af-project-title",children:i.jsx(Bn,{query:V,children:q.label||q.displayName||q.id})}),i.jsx("p",{className:"af-project-desc",children:i.jsx(Bn,{query:V,children:q.description||n("project:noDescription")})}),i.jsxs("div",{className:"af-resource-meta-row",children:[i.jsx("span",{children:i.jsx(Bn,{query:V,children:q.id})}),i.jsx("span",{children:n("project:nodeSlots",{inputs:Object.keys(q.inputs||{}).length,outputs:Object.keys(q.outputs||{}).length})})]}),q.packageId?i.jsxs("div",{className:"af-project-path",children:[i.jsx("span",{className:"material-symbols-outlined af-path-icon",children:"deployed_code"}),i.jsx("span",{className:"af-path-text",children:i.jsx(Bn,{query:V,children:`${q.packageId}${q.version?` / ${q.version}`:""}`})})]}):null]},`${q.id}:${q.source||""}:${q.packageId||""}`)):M?i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:dn?n("project:noNodeMatch",{query:V.trim()}):n(_t?"project:noMyNodes":"project:noNodes")})}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:loadingResources")})})}):le?i.jsx("div",{className:"af-resource-grid",children:tn.length>0?tn.map(q=>{const he=EP(q),Oe=AP(q),Ee=Number.isFinite(Number(q.nodeCount))?Number(q.nodeCount):he.length,et=Number.isFinite(Number(q.edgeCount))?Number(q.edgeCount):Oe.length;return i.jsxs("button",{type:"button",className:"af-resource-card"+(Wt&&jo(q)===jo(Wt)?" af-resource-card--active":""),onClick:()=>ce(jo(q)),children:[i.jsxs("div",{className:"af-resource-card-head",children:[i.jsx("span",{className:Al("primary"),children:i.jsx(Bn,{query:V,children:q.version?`v${q.version}`:"flow"})}),i.jsx("span",{className:"af-resource-source",children:n("project:flowSnippet")})]}),i.jsx("h3",{className:"af-project-title",children:i.jsx(Bn,{query:V,children:q.displayName||q.name||q.id})}),i.jsx("p",{className:"af-project-desc",children:i.jsx(Bn,{query:V,children:q.description||n("project:noDescription")})}),i.jsxs("div",{className:"af-resource-meta-row",children:[i.jsx("span",{children:n("project:flowSnippetNodes",{nodes:Ee,edges:et})}),i.jsx("span",{children:i.jsx(Bn,{query:V,children:q.id})})]}),i.jsxs("div",{className:"af-project-path",children:[i.jsx("span",{className:"material-symbols-outlined af-path-icon",children:"schema"}),i.jsx("span",{className:"af-path-text",children:i.jsx(Bn,{query:V,children:QN(q)})})]})]},jo(q))}):M?i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:dn?n("project:noFlowSnippetMatch",{query:V.trim()}):n("project:noMyFlows")})}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:loadingResources")})})}):a==="skills"?i.jsx("div",{className:"af-resource-grid",children:Jt.length>0?Jt.map(q=>{const he=Hn(q),Oe=b.filter(Ee=>{var et;return(et=it.get(Ee.id))==null?void 0:et.has(he)});return i.jsxs("button",{type:"button",className:"af-resource-card"+(nn&&he===Hn(nn)?" af-resource-card--active":""),onClick:()=>ce(he),children:[i.jsxs("div",{className:"af-resource-card-head",children:[i.jsx("span",{className:Al(q.source==="builtin"?"muted":"primary"),children:i.jsx(Bn,{query:V,children:q.sourceLabel||q.source||"skill"})}),i.jsx("span",{className:"af-resource-source",children:n("project:skill")})]}),i.jsx("h3",{className:"af-project-title",children:i.jsx(Bn,{query:V,children:q.name||q.id})}),i.jsx("p",{className:"af-project-desc",children:i.jsx(Bn,{query:V,children:q.description||n("project:noDescription")})}),i.jsxs("div",{className:"af-project-path",children:[i.jsx("span",{className:"material-symbols-outlined af-path-icon",children:"extension"}),i.jsx("span",{className:"af-path-text",children:i.jsx(Bn,{query:V,children:q.path||q.key||""})})]}),i.jsxs("div",{className:"af-skill-card-collections",children:[Oe.slice(0,3).map(Ee=>i.jsx("span",{children:Ee.name},Ee.id)),Oe.length===0?i.jsx("span",{className:"af-skill-card-collection-empty",children:"未分组"}):null]})]},q.key||`${q.source}:${q.name}`)}):M?i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:dn?n("project:noSkillMatch",{query:V.trim()}):n("project:noSkills")})}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:loadingResources")})})}):i.jsxs(i.Fragment,{children:[t!=null&&t.isAdmin&&a==="all"&&Ct.length>0?i.jsxs("div",{className:"af-project-admin-panel",children:[i.jsxs("div",{children:[i.jsx("strong",{children:"已隐藏内置"}),i.jsx("span",{children:"这些包内置流水线不会出现在普通项目列表中。"})]}),i.jsx("div",{className:"af-project-admin-hidden-list",children:Ct.map(q=>{const he=Je===`show-builtin:builtin:${q}`;return i.jsxs("button",{type:"button",disabled:he,onClick:()=>Xn({id:q,source:"builtin"},"show-builtin"),children:[i.jsx("span",{children:q}),i.jsx("em",{children:he?"恢复中":"恢复"})]},q)})})]}):null,i.jsxs("div",{className:"af-project-grid",children:[br.length>0?br.map(q=>{var Nn,kt;const he=(t==null?void 0:t.isAdmin)&&q.source==="user"&&!q.archived&&!sr.has(q.id),Oe=(t==null?void 0:t.isAdmin)&&q.source==="admin",Ee=(t==null?void 0:t.isAdmin)&&q.source==="builtin",et=Je.endsWith(`:${q.source}:${q.id}`);return i.jsx("div",{className:EF(q.source),role:"button",tabIndex:0,onClick:()=>zr(q),onKeyDown:Ut=>{(Ut.key==="Enter"||Ut.key===" ")&&(Ut.preventDefault(),zr(q))},children:i.jsxs("div",{className:"af-project-card-body",children:[i.jsx("span",{className:Al(Sx(q.source,n).tone),children:i.jsx(Bn,{query:V,children:Sx(q.source,n).label})}),q.source==="workspace"&&((Nn=q.collaboration)!=null&&Nn.role)?i.jsx("span",{className:Al(q.collaboration.role==="owner"?"primary":"muted"),children:q.collaboration.role==="owner"?"我创建的":`${q.collaboration.ownerUsername||q.collaboration.ownerId} 分享`}):null,q.archived?i.jsx("span",{className:Al("muted"),children:i.jsx(Bn,{query:V,children:n("project:archived")})}):null,i.jsx("h3",{className:"af-project-title",children:i.jsx(Bn,{query:V,children:q.id})}),i.jsx("p",{className:"af-project-desc",children:i.jsx(Bn,{query:V,children:CP(q,n)})}),i.jsxs("div",{className:"af-project-path",children:[i.jsx("span",{className:"material-symbols-outlined af-path-icon",children:"database"}),i.jsx("span",{className:"af-path-text",children:i.jsx(Bn,{query:V,children:jP(q)})})]}),t!=null&&t.isAdmin?i.jsxs("div",{className:"af-project-admin-actions",onClick:Ut=>Ut.stopPropagation(),onKeyDown:Ut=>Ut.stopPropagation(),children:[he?i.jsx("button",{type:"button",disabled:et,onClick:()=>Xn(q,"promote"),children:"设为内置"}):null,Oe?i.jsx("button",{type:"button",disabled:et,onClick:()=>Xn(q,"unpromote"),children:"取消内置"}):null,Ee?i.jsx("button",{type:"button",disabled:et,onClick:()=>Xn(q,"hide-builtin"),children:"隐藏内置"}):null]}):null]})},`${q.id}:${q.source??"user"}:${q.archived?"a":""}:${((kt=q.collaboration)==null?void 0:kt.id)||"own"}`)}):F?Qn.length===0?i.jsxs("div",{className:"af-projects-empty-block",children:[i.jsx("p",{className:"af-projects-empty",children:a==="archived"?n("project:noArchived"):c.length>0?n("project:noActive"):n(I?"project:loadFailed":"project:noPipelines")}),!I&&c.length===0&&a==="all"?i.jsx("p",{className:"af-projects-empty-hint",children:n("project:emptyHint",{code1:"agentflow ui",code2:".agentflow/pipelines"})}):null]}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:noMatch",{query:V.trim()})})}):i.jsx("div",{className:"af-projects-empty-block",children:i.jsx("p",{className:"af-projects-empty",children:n("project:loadingPipelines")})}),i.jsxs("button",{type:"button",className:"af-project-add",onClick:()=>D(!0),children:[i.jsx("span",{className:"material-symbols-outlined af-project-add-icon",children:"add_circle"}),i.jsx("span",{className:"af-project-add-label",children:n("project:newPipeline")})]}),re?null:i.jsxs("a",{className:"af-hub-card",href:"https://agentflow-hub.com",target:"_blank",rel:"noopener noreferrer",children:[i.jsx("div",{className:"af-hub-card__glow","aria-hidden":!0}),i.jsxs("span",{className:"af-hub-card__eyebrow",children:[i.jsx("span",{className:"material-symbols-outlined af-hub-card__eyebrow-icon",children:"hub"}),n("project:hubCard.eyebrow")]}),i.jsx("h3",{className:"af-hub-card__title",children:n("project:hubCard.title")}),i.jsx("p",{className:"af-hub-card__desc",children:n("project:hubCard.desc")}),i.jsxs("span",{className:"af-hub-card__cta",children:[n("project:hubCard.cta"),i.jsx("span",{className:"material-symbols-outlined af-hub-card__cta-icon",children:"arrow_outward"})]}),i.jsx("code",{className:"af-hub-card__cli",children:n("project:hubCard.cliHint")})]})]})]})]}),Zn?i.jsx("aside",{className:"af-resource-detail","aria-label":n(Gt?"project:nodeDetail":le?"project:flowDetail":"project:skillDetail"),children:Gt&&mt?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-resource-detail-head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"account_tree"}),i.jsxs("div",{children:[i.jsx("h3",{children:mt.label||mt.displayName||mt.id}),i.jsx("p",{children:mt.id})]})]}),i.jsx("div",{className:"af-resource-detail-tabs",children:["overview","schema","runtime","files","usage"].map(q=>i.jsx("button",{type:"button",className:"af-resource-detail-tab"+(de===q?" af-resource-detail-tab--active":""),onClick:()=>me(q),children:n(`project:nodeDetailTabs.${q}`)},q))}),Te===Hn(mt)?i.jsx("p",{className:"af-resource-detail-desc",children:n("project:loadingResources")}):de==="overview"?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"af-resource-detail-desc",children:mt.description||((Pe=tt==null?void 0:tt.node)==null?void 0:Pe.description)||n("project:noDescription")}),i.jsxs("dl",{className:"af-resource-detail-kv",children:[i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailType")}),i.jsx("dd",{children:mt.type||((xt=tt==null?void 0:tt.node)==null?void 0:xt.type)||"node"})]}),i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailSource")}),i.jsx("dd",{children:XN(mt.source,n)})]}),mt.packageId?i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailPackage")}),i.jsx("dd",{children:mt.packageId})]}):null,mt.version?i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailVersion")}),i.jsx("dd",{children:mt.version})]}):null,mt.packageDir||tt!=null&&tt.baseDir?i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailPath")}),i.jsx("dd",{children:mt.packageDir||(tt==null?void 0:tt.baseDir)})]}):null,i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailEditable")}),i.jsx("dd",{children:(tt==null?void 0:tt.readOnly)===!1?n("project:editable"):n("project:readOnly")})]})]}),_t&&mt.source==="marketplace"?i.jsxs("div",{className:"af-resource-detail-section af-resource-danger-zone",children:[i.jsx("h4",{children:n("project:myNodeManagement")}),i.jsx("p",{children:n("project:deleteMyNodeHint")}),i.jsxs("button",{type:"button",className:"af-btn-secondary af-btn-danger",disabled:Ke===Hn(mt),onClick:()=>ys(mt),children:[i.jsx("span",{className:"material-symbols-outlined",children:"delete"}),Ke===Hn(mt)?n("project:deletingMyNode"):n("project:deleteMyNode")]}),be?i.jsx("p",{className:"af-resource-action-message",children:be}):null]}):null,i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:resourceMeaning")}),i.jsx("p",{children:n("project:nodesMeaning")})]})]}):de==="schema"?i.jsxs("div",{className:"af-resource-detail-section af-resource-detail-section--plain",children:[i.jsx("h4",{children:n("project:nodeSchema")}),i.jsxs("div",{className:"af-resource-slot-group",children:[i.jsx("span",{children:n("project:nodeInputs")}),yp(((Lt=tt==null?void 0:tt.node)==null?void 0:Lt.inputs)||mt.inputs).length>0?yp(((qt=tt==null?void 0:tt.node)==null?void 0:qt.inputs)||mt.inputs).map(q=>i.jsxs("code",{children:[q.name||q.key,q.type?`: ${q.type}`:""]},q.key)):i.jsx("em",{children:n("project:noSlots")})]}),i.jsxs("div",{className:"af-resource-slot-group",children:[i.jsx("span",{children:n("project:nodeOutputs")}),yp(((zn=tt==null?void 0:tt.node)==null?void 0:zn.outputs)||mt.outputs).length>0?yp(((On=tt==null?void 0:tt.node)==null?void 0:On.outputs)||mt.outputs).map(q=>i.jsxs("code",{children:[q.name||q.key,q.type?`: ${q.type}`:""]},q.key)):i.jsx("em",{children:n("project:noSlots")})]})]}):de==="runtime"?i.jsxs("div",{className:"af-resource-detail-section af-resource-detail-section--plain",children:[i.jsx("h4",{children:n("project:nodeRuntime")}),tt!=null&&tt.runtime?i.jsx("pre",{className:"af-resource-skill-preview",children:JSON.stringify(tt.runtime,null,2)}):i.jsx("p",{children:n("project:noRuntimeManifest")}),tt!=null&&tt.body?i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"af-resource-detail-subtitle",children:n("project:nodeBody")}),i.jsx("pre",{className:"af-resource-skill-preview",children:tt.body})]}):i.jsx("p",{children:n("project:noNodeBody")})]}):de==="files"?i.jsxs("div",{className:"af-resource-detail-section af-resource-detail-section--plain",children:[i.jsx("h4",{children:n("project:nodeFiles")}),Array.isArray(tt==null?void 0:tt.files)&&tt.files.length>0?i.jsxs("div",{className:"af-node-file-browser",children:[i.jsx("div",{className:"af-node-file-list",children:tt.files.map(q=>i.jsxs("button",{type:"button",className:"af-node-file-item"+(gt===q.path?" af-node-file-item--active":""),onClick:()=>xe(q.path),children:[i.jsx("span",{className:"material-symbols-outlined",children:"description"}),i.jsx("span",{children:q.path})]},q.path))}),i.jsxs("pre",{className:"af-resource-skill-preview",children:[oe===`${Hn(mt)}:${gt}`?n("project:loadingResources"):Ln!=null&&Ln.binary?n("project:binaryFile"):(Ln==null?void 0:Ln.content)||n("project:selectNodeFile"),Ln!=null&&Ln.truncated?`
43
43
 
44
- ${n("project:fileTruncated")}`:""]})]}):i.jsx("p",{children:n("project:noNodeFiles")})]}):i.jsxs("div",{className:"af-resource-detail-section af-resource-detail-section--plain",children:[i.jsx("h4",{children:n("project:nodeUsage")}),Array.isArray(tt==null?void 0:tt.usage)&&tt.usage.length>0?i.jsx("div",{className:"af-node-usage-list",children:tt.usage.map(q=>i.jsxs("div",{className:"af-node-usage-item",children:[i.jsx("strong",{children:q.flowId}),i.jsxs("span",{children:[q.flowSource,q.archived?` · ${n("project:archived")}`:""]}),i.jsx("em",{children:q.instances.map(pe=>pe.label||pe.instanceId).join(", ")})]},`${q.flowSource}:${q.flowId}:${q.archived?"a":""}`))}):i.jsx("p",{children:n("project:noNodeUsage")})]})]}):le&&Wt?(()=>{const q=VF(Wt);return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-resource-detail-head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"schema"}),i.jsxs("div",{children:[i.jsx("h3",{children:Wt.displayName||Wt.name||Wt.id}),i.jsx("p",{children:Wt.id})]})]}),i.jsx("p",{className:"af-resource-detail-desc",children:Wt.description||n("project:noDescription")}),i.jsxs("dl",{className:"af-resource-detail-kv",children:[i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailVersion")}),i.jsx("dd",{children:Wt.version||"1.0.0"})]}),i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailPath")}),i.jsx("dd",{children:QN(Wt)})]}),i.jsxs("div",{children:[i.jsx("dt",{children:n("project:flowSnippetScale")}),i.jsx("dd",{children:n("project:flowSnippetNodes",{nodes:Number.isFinite(Number(Wt.nodeCount))?Number(Wt.nodeCount):q.nodes.length,edges:Number.isFinite(Number(Wt.edgeCount))?Number(Wt.edgeCount):q.edges.length})})]})]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:resourceMeaning")}),i.jsx("p",{children:n("project:myFlowsMeaning")})]}),i.jsxs("div",{className:"af-resource-detail-section af-resource-danger-zone",children:[i.jsx("h4",{children:n("project:myFlowManagement")}),i.jsx("p",{children:n("project:deleteMyFlowHint")}),i.jsxs("button",{type:"button",className:"af-btn-secondary af-btn-danger",disabled:Qt===jo(Wt),onClick:()=>cn(Wt),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"}),Qt===jo(Wt)?n("project:deletingMyFlow"):n("project:deleteMyFlow")]}),yn?i.jsx("p",{className:"af-resource-action-message",children:yn}):null]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:flowSnippetPreview")}),q.diagram.nodes.length>0?i.jsx("div",{className:"af-flow-snippet-map",children:i.jsxs("svg",{viewBox:q.diagram.viewBox,role:"img","aria-label":n("project:flowSnippetPreview"),children:[i.jsx("defs",{children:i.jsx("marker",{id:"af-flow-snippet-arrow",markerWidth:"8",markerHeight:"8",refX:"7",refY:"4",orient:"auto",markerUnits:"strokeWidth",children:i.jsx("path",{d:"M 0 0 L 8 4 L 0 8 z"})})}),i.jsx("g",{className:"af-flow-snippet-map__edges",children:q.diagram.edges.map(pe=>i.jsxs("g",{children:[i.jsx("path",{d:pe.path}),pe.label?i.jsx("text",{x:pe.labelX,y:pe.labelY-5,textAnchor:"middle",children:Iy(pe.label,18)}):null]},pe.key))}),i.jsx("g",{className:"af-flow-snippet-map__nodes",children:q.diagram.nodes.map((pe,Oe)=>i.jsxs("g",{transform:`translate(${pe.x} ${pe.y})`,children:[i.jsx("rect",{width:pe.width,height:pe.height,rx:"10"}),i.jsx("circle",{cx:"19",cy:pe.height/2,r:"12"}),i.jsx("text",{className:"af-flow-snippet-map__node-index",x:"19",y:pe.height/2+4,textAnchor:"middle",children:Oe+1}),i.jsx("text",{className:"af-flow-snippet-map__node-title",x:"40",y:pe.height/2-3,children:Iy(pe.title)}),i.jsx("text",{className:"af-flow-snippet-map__node-meta",x:"40",y:pe.height/2+16,children:Iy(pe.meta||pe.id,20)})]},pe.id))})]})}):i.jsx("p",{className:"af-resource-detail-desc",children:n("project:noFlowSnippetPreview")}),i.jsxs("details",{className:"af-flow-snippet-json",children:[i.jsx("summary",{children:n("project:flowSnippetJson")}),i.jsx("pre",{className:"af-resource-skill-preview",children:JSON.stringify(Wt.snippet||{},null,2)})]})]})]})})():a==="skills"&&nn?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-resource-detail-head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"extension"}),i.jsxs("div",{children:[i.jsx("h3",{children:nn.name||nn.id}),i.jsx("p",{children:nn.sourceLabel||nn.source})]})]}),i.jsx("p",{className:"af-resource-detail-desc",children:nn.description||n("project:noDescription")}),i.jsxs("dl",{className:"af-resource-detail-kv",children:[i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailSource")}),i.jsx("dd",{children:nn.sourceLabel||nn.source})]}),i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailPath")}),i.jsx("dd",{children:nn.path||nn.key})]})]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:"Collections"}),b.length===0?i.jsx("p",{children:"暂无 collection。可在左侧新建后再添加。"}):i.jsx("div",{className:"af-skill-detail-collections",children:b.map(q=>{const pe=Hn(nn),Oe=it.get(q.id)||new Set,Ee=Oe.has(pe);return i.jsxs("label",{className:"af-composer-skill-option af-skill-detail-collection-option",children:[i.jsx("input",{type:"checkbox",checked:Ee,disabled:N||!o,onChange:et=>gs(q.id,pe,et.target.checked)}),i.jsxs("span",{className:"af-composer-skill-option-main",children:[i.jsx("span",{className:"af-composer-skill-option-title",children:q.name}),i.jsxs("span",{className:"af-composer-skill-option-desc",children:[Oe.size," skills"]})]})]},q.id)})})]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:resourceMeaning")}),i.jsx("p",{children:n("project:skillsMeaning")})]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:skillPreview")}),i.jsx("pre",{className:"af-resource-skill-preview",children:_e===Hn(nn)?n("project:loadingResources"):(kr==null?void 0:kr.body)||(kr==null?void 0:kr.content)||n("project:skillPreviewEmpty")})]})]}):i.jsx("p",{className:"af-activity-empty",children:n("project:selectResource")})}):i.jsxs("aside",{id:"af-recent-activity-panel",className:"af-activity"+(se?"":" af-activity--hidden"),"aria-hidden":!se,"aria-label":n("project:recentActivity"),children:[i.jsxs("h2",{className:"af-activity-title",children:[i.jsx("span",{className:"af-activity-bullet"}),n("project:recentActivity")]}),i.jsx("div",{className:"af-activity-list",children:Pr.length===0?i.jsx("p",{className:"af-activity-empty",children:rr.length===0?n("project:noRecentActivity"):n("project:noMatchRecent")}):Pr.map(q=>{const pe=G===ZN(q);return i.jsxs("button",{type:"button",className:"af-activity-row af-activity-row--action"+(pe?" af-activity-row--active":""),"aria-current":pe?"page":void 0,onClick:()=>mo(q),children:[i.jsxs("div",{className:"af-activity-row-top",children:[i.jsx("h4",{className:"af-activity-name",children:i.jsx(Bn,{query:V,children:q.flowId})}),i.jsx("span",{className:"af-activity-time",children:GN(q.at,n)})]}),i.jsxs("div",{className:"af-activity-meta",children:[i.jsx("span",{className:AF(q.kind),children:q.kind==="executed"?"play_arrow":"visibility"}),i.jsxs("p",{className:"af-activity-text",children:[q.kind==="executed"?n("project:recentRun"):n("project:recentOpen")," · ",GN(q.at,n)]})]})]},`${q.kind}-${q.flowId}-${q.flowSource}-${q.at}`)})})]})]}),i.jsx(dF,{open:H,onClose:()=>D(!1),onCreated:async q=>{D(!1),await wn();const pe=q.source??"user";r(gp({id:q.id,source:pe},"workspace"))}}),T?i.jsx(cF,{file:T,onClose:()=>W(null),onImported:async q=>{W(null),await wn();const pe=q.source??"user";r(gp({id:q.id,source:pe},"workspace"))}},`${T.name}-${T.size}-${T.lastModified}`):null]})}function Jn(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Jn(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var KF={value:()=>{}};function Wm(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new ih(n)}function ih(e){this._=e}function qF(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",s=n.indexOf(".");if(s>=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}ih.prototype=Wm.prototype={constructor:ih,on:function(e,t){var n=this._,r=qF(e+"",n),s,o=-1,a=r.length;if(arguments.length<2){for(;++o<a;)if((s=(e=r[o]).type)&&(s=UF(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<a;)if(s=(e=r[o]).type)n[s]=nj(n[s],e.name,t);else if(t==null)for(s in n)n[s]=nj(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new ih(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),r=0,s,o;r<s;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],r=0,s=o.length;r<s;++r)o[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],s=0,o=r.length;s<o;++s)r[s].value.apply(t,n)}};function UF(e,t){for(var n=0,r=e.length,s;n<r;++n)if((s=e[n]).name===t)return s.value}function nj(e,t,n){for(var r=0,s=e.length;r<s;++r)if(e[r].name===t){e[r]=KF,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var Cx="http://www.w3.org/1999/xhtml";const rj={svg:"http://www.w3.org/2000/svg",xhtml:Cx,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Vm(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rj.hasOwnProperty(t)?{space:rj[t],local:e}:e}function YF(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===Cx&&t.documentElement.namespaceURI===Cx?t.createElement(e):t.createElementNS(n,e)}}function GF(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function PP(e){var t=Vm(e);return(t.local?GF:YF)(t)}function JF(){}function vk(e){return e==null?JF:function(){return this.querySelector(e)}}function XF(e){typeof e!="function"&&(e=vk(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var o=t[s],a=o.length,l=r[s]=new Array(a),c,u,d=0;d<a;++d)(c=o[d])&&(u=e.call(c,c.__data__,d,o))&&("__data__"in c&&(u.__data__=c.__data__),l[d]=u);return new ps(r,this._parents)}function QF(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function ZF(){return[]}function IP(e){return e==null?ZF:function(){return this.querySelectorAll(e)}}function ez(e){return function(){return QF(e.apply(this,arguments))}}function tz(e){typeof e=="function"?e=ez(e):e=IP(e);for(var t=this._groups,n=t.length,r=[],s=[],o=0;o<n;++o)for(var a=t[o],l=a.length,c,u=0;u<l;++u)(c=a[u])&&(r.push(e.call(c,c.__data__,u,a)),s.push(c));return new ps(r,s)}function RP(e){return function(){return this.matches(e)}}function TP(e){return function(t){return t.matches(e)}}var nz=Array.prototype.find;function rz(e){return function(){return nz.call(this.children,e)}}function sz(){return this.firstElementChild}function iz(e){return this.select(e==null?sz:rz(typeof e=="function"?e:TP(e)))}var oz=Array.prototype.filter;function az(){return Array.from(this.children)}function lz(e){return function(){return oz.call(this.children,e)}}function cz(e){return this.selectAll(e==null?az:lz(typeof e=="function"?e:TP(e)))}function uz(e){typeof e!="function"&&(e=RP(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var o=t[s],a=o.length,l=r[s]=[],c,u=0;u<a;++u)(c=o[u])&&e.call(c,c.__data__,u,o)&&l.push(c);return new ps(r,this._parents)}function MP(e){return new Array(e.length)}function dz(){return new ps(this._enter||this._groups.map(MP),this._parents)}function Wh(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Wh.prototype={constructor:Wh,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function fz(e){return function(){return e}}function pz(e,t,n,r,s,o){for(var a=0,l,c=t.length,u=o.length;a<u;++a)(l=t[a])?(l.__data__=o[a],r[a]=l):n[a]=new Wh(e,o[a]);for(;a<c;++a)(l=t[a])&&(s[a]=l)}function hz(e,t,n,r,s,o,a){var l,c,u=new Map,d=t.length,f=o.length,p=new Array(d),h;for(l=0;l<d;++l)(c=t[l])&&(p[l]=h=a.call(c,c.__data__,l,t)+"",u.has(h)?s[l]=c:u.set(h,c));for(l=0;l<f;++l)h=a.call(e,o[l],l,o)+"",(c=u.get(h))?(r[l]=c,c.__data__=o[l],u.delete(h)):n[l]=new Wh(e,o[l]);for(l=0;l<d;++l)(c=t[l])&&u.get(p[l])===c&&(s[l]=c)}function mz(e){return e.__data__}function gz(e,t){if(!arguments.length)return Array.from(this,mz);var n=t?hz:pz,r=this._parents,s=this._groups;typeof e!="function"&&(e=fz(e));for(var o=s.length,a=new Array(o),l=new Array(o),c=new Array(o),u=0;u<o;++u){var d=r[u],f=s[u],p=f.length,h=yz(e.call(d,d&&d.__data__,u,r)),y=h.length,k=l[u]=new Array(y),b=a[u]=new Array(y),g=c[u]=new Array(p);n(d,f,k,b,g,h,t);for(var v=0,w=0,N,j;v<y;++v)if(N=k[v]){for(v>=w&&(w=v+1);!(j=b[w])&&++w<y;);N._next=j||null}}return a=new ps(a,r),a._enter=l,a._exit=c,a}function yz(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function wz(){return new ps(this._exit||this._groups.map(MP),this._parents)}function xz(e,t,n){var r=this.enter(),s=this,o=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?o.remove():n(o),r&&s?r.merge(s).order():s}function bz(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,s=n.length,o=r.length,a=Math.min(s,o),l=new Array(s),c=0;c<a;++c)for(var u=n[c],d=r[c],f=u.length,p=l[c]=new Array(f),h,y=0;y<f;++y)(h=u[y]||d[y])&&(p[y]=h);for(;c<s;++c)l[c]=n[c];return new ps(l,this._parents)}function kz(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],s=r.length-1,o=r[s],a;--s>=0;)(a=r[s])&&(o&&a.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(a,o),o=a);return this}function vz(e){e||(e=Sz);function t(f,p){return f&&p?e(f.__data__,p.__data__):!f-!p}for(var n=this._groups,r=n.length,s=new Array(r),o=0;o<r;++o){for(var a=n[o],l=a.length,c=s[o]=new Array(l),u,d=0;d<l;++d)(u=a[d])&&(c[d]=u);c.sort(t)}return new ps(s,this._parents).order()}function Sz(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Nz(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function jz(){return Array.from(this)}function Cz(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,o=r.length;s<o;++s){var a=r[s];if(a)return a}return null}function _z(){let e=0;for(const t of this)++e;return e}function Ez(){return!this.node()}function Az(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var s=t[n],o=0,a=s.length,l;o<a;++o)(l=s[o])&&e.call(l,l.__data__,o,s);return this}function Pz(e){return function(){this.removeAttribute(e)}}function Iz(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Rz(e,t){return function(){this.setAttribute(e,t)}}function Tz(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Mz(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function $z(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Lz(e,t){var n=Vm(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Iz:Pz:typeof t=="function"?n.local?$z:Mz:n.local?Tz:Rz)(n,t))}function $P(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Oz(e){return function(){this.style.removeProperty(e)}}function Dz(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Fz(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function zz(e,t,n){return arguments.length>1?this.each((t==null?Oz:typeof t=="function"?Fz:Dz)(e,t,n??"")):Nc(this.node(),e)}function Nc(e,t){return e.style.getPropertyValue(t)||$P(e).getComputedStyle(e,null).getPropertyValue(t)}function Bz(e){return function(){delete this[e]}}function Hz(e,t){return function(){this[e]=t}}function Wz(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Vz(e,t){return arguments.length>1?this.each((t==null?Bz:typeof t=="function"?Wz:Hz)(e,t)):this.node()[e]}function LP(e){return e.trim().split(/^|\s+/)}function Sk(e){return e.classList||new OP(e)}function OP(e){this._node=e,this._names=LP(e.getAttribute("class")||"")}OP.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function DP(e,t){for(var n=Sk(e),r=-1,s=t.length;++r<s;)n.add(t[r])}function FP(e,t){for(var n=Sk(e),r=-1,s=t.length;++r<s;)n.remove(t[r])}function Kz(e){return function(){DP(this,e)}}function qz(e){return function(){FP(this,e)}}function Uz(e,t){return function(){(t.apply(this,arguments)?DP:FP)(this,e)}}function Yz(e,t){var n=LP(e+"");if(arguments.length<2){for(var r=Sk(this.node()),s=-1,o=n.length;++s<o;)if(!r.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?Uz:t?Kz:qz)(n,t))}function Gz(){this.textContent=""}function Jz(e){return function(){this.textContent=e}}function Xz(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function Qz(e){return arguments.length?this.each(e==null?Gz:(typeof e=="function"?Xz:Jz)(e)):this.node().textContent}function Zz(){this.innerHTML=""}function e3(e){return function(){this.innerHTML=e}}function t3(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function n3(e){return arguments.length?this.each(e==null?Zz:(typeof e=="function"?t3:e3)(e)):this.node().innerHTML}function r3(){this.nextSibling&&this.parentNode.appendChild(this)}function s3(){return this.each(r3)}function i3(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function o3(){return this.each(i3)}function a3(e){var t=typeof e=="function"?e:PP(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function l3(){return null}function c3(e,t){var n=typeof e=="function"?e:PP(e),r=t==null?l3:typeof t=="function"?t:vk(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function u3(){var e=this.parentNode;e&&e.removeChild(this)}function d3(){return this.each(u3)}function f3(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function p3(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function h3(e){return this.select(e?p3:f3)}function m3(e){return arguments.length?this.property("__data__",e):this.node().__data__}function g3(e){return function(t){e.call(this,t,this.__data__)}}function y3(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function w3(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,o;n<s;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++r]=o;++r?t.length=r:delete this.__on}}}function x3(e,t,n){return function(){var r=this.__on,s,o=g3(t);if(r){for(var a=0,l=r.length;a<l;++a)if((s=r[a]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=o,s.options=n),s.value=t;return}}this.addEventListener(e.type,o,n),s={type:e.type,name:e.name,value:t,listener:o,options:n},r?r.push(s):this.__on=[s]}}function b3(e,t,n){var r=y3(e+""),s,o=r.length,a;if(arguments.length<2){var l=this.node().__on;if(l){for(var c=0,u=l.length,d;c<u;++c)for(s=0,d=l[c];s<o;++s)if((a=r[s]).type===d.type&&a.name===d.name)return d.value}return}for(l=t?x3:w3,s=0;s<o;++s)this.each(l(r[s],t,n));return this}function zP(e,t,n){var r=$P(e),s=r.CustomEvent;typeof s=="function"?s=new s(t,n):(s=r.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function k3(e,t){return function(){return zP(this,e,t)}}function v3(e,t){return function(){return zP(this,e,t.apply(this,arguments))}}function S3(e,t){return this.each((typeof t=="function"?v3:k3)(e,t))}function*N3(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,o=r.length,a;s<o;++s)(a=r[s])&&(yield a)}var BP=[null];function ps(e,t){this._groups=e,this._parents=t}function lf(){return new ps([[document.documentElement]],BP)}function j3(){return this}ps.prototype=lf.prototype={constructor:ps,select:XF,selectAll:tz,selectChild:iz,selectChildren:cz,filter:uz,data:gz,enter:dz,exit:wz,join:xz,merge:bz,selection:j3,order:kz,sort:vz,call:Nz,nodes:jz,node:Cz,size:_z,empty:Ez,each:Az,attr:Lz,style:zz,property:Vz,classed:Yz,text:Qz,html:n3,raise:s3,lower:o3,append:a3,insert:c3,remove:d3,clone:h3,datum:m3,on:b3,dispatch:S3,[Symbol.iterator]:N3};function as(e){return typeof e=="string"?new ps([[document.querySelector(e)]],[document.documentElement]):new ps([[e]],BP)}function C3(e){let t;for(;t=e.sourceEvent;)e=t;return e}function qs(e,t){if(e=C3(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const _3={passive:!1},Rd={capture:!0,passive:!1};function Ry(e){e.stopImmediatePropagation()}function cc(e){e.preventDefault(),e.stopImmediatePropagation()}function HP(e){var t=e.document.documentElement,n=as(e).on("dragstart.drag",cc,Rd);"onselectstart"in t?n.on("selectstart.drag",cc,Rd):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function WP(e,t){var n=e.document.documentElement,r=as(e).on("dragstart.drag",null);t&&(r.on("click.drag",cc,Rd),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const wp=e=>()=>e;function _x(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:o,x:a,y:l,dx:c,dy:u,dispatch:d}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:a,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:d}})}_x.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function E3(e){return!e.ctrlKey&&!e.button}function A3(){return this.parentNode}function P3(e,t){return t??{x:e.x,y:e.y}}function I3(){return navigator.maxTouchPoints||"ontouchstart"in this}function VP(){var e=E3,t=A3,n=P3,r=I3,s={},o=Wm("start","drag","end"),a=0,l,c,u,d,f=0;function p(N){N.on("mousedown.drag",h).filter(r).on("touchstart.drag",b).on("touchmove.drag",g,_3).on("touchend.drag touchcancel.drag",v).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(N,j){if(!(d||!e.call(this,N,j))){var C=w(this,t.call(this,N,j),N,j,"mouse");C&&(as(N.view).on("mousemove.drag",y,Rd).on("mouseup.drag",k,Rd),HP(N.view),Ry(N),u=!1,l=N.clientX,c=N.clientY,C("start",N))}}function y(N){if(cc(N),!u){var j=N.clientX-l,C=N.clientY-c;u=j*j+C*C>f}s.mouse("drag",N)}function k(N){as(N.view).on("mousemove.drag mouseup.drag",null),WP(N.view,u),cc(N),s.mouse("end",N)}function b(N,j){if(e.call(this,N,j)){var C=N.changedTouches,P=t.call(this,N,j),I=C.length,z,$;for(z=0;z<I;++z)($=w(this,P,N,j,C[z].identifier,C[z]))&&(Ry(N),$("start",N,C[z]))}}function g(N){var j=N.changedTouches,C=j.length,P,I;for(P=0;P<C;++P)(I=s[j[P].identifier])&&(cc(N),I("drag",N,j[P]))}function v(N){var j=N.changedTouches,C=j.length,P,I;for(d&&clearTimeout(d),d=setTimeout(function(){d=null},500),P=0;P<C;++P)(I=s[j[P].identifier])&&(Ry(N),I("end",N,j[P]))}function w(N,j,C,P,I,z){var $=o.copy(),L=qs(z||C,j),F,O,M;if((M=n.call(N,new _x("beforestart",{sourceEvent:C,target:p,identifier:I,active:a,x:L[0],y:L[1],dx:0,dy:0,dispatch:$}),P))!=null)return F=M.x-L[0]||0,O=M.y-L[1]||0,function K(H,D,T){var W=L,E;switch(H){case"start":s[I]=K,E=a++;break;case"end":delete s[I],--a;case"drag":L=qs(T||D,j),E=a;break}$.call(H,N,new _x(H,{sourceEvent:D,subject:M,target:p,identifier:I,active:E,x:L[0]+F,y:L[1]+O,dx:L[0]-W[0],dy:L[1]-W[1],dispatch:$}),P)}}return p.filter=function(N){return arguments.length?(e=typeof N=="function"?N:wp(!!N),p):e},p.container=function(N){return arguments.length?(t=typeof N=="function"?N:wp(N),p):t},p.subject=function(N){return arguments.length?(n=typeof N=="function"?N:wp(N),p):n},p.touchable=function(N){return arguments.length?(r=typeof N=="function"?N:wp(!!N),p):r},p.on=function(){var N=o.on.apply(o,arguments);return N===o?p:N},p.clickDistance=function(N){return arguments.length?(f=(N=+N)*N,p):Math.sqrt(f)},p}function Nk(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function KP(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function cf(){}var Td=.7,Vh=1/Td,uc="\\s*([+-]?\\d+)\\s*",Md="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ci="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",R3=/^#([0-9a-f]{3,8})$/,T3=new RegExp(`^rgb\\(${uc},${uc},${uc}\\)$`),M3=new RegExp(`^rgb\\(${Ci},${Ci},${Ci}\\)$`),$3=new RegExp(`^rgba\\(${uc},${uc},${uc},${Md}\\)$`),L3=new RegExp(`^rgba\\(${Ci},${Ci},${Ci},${Md}\\)$`),O3=new RegExp(`^hsl\\(${Md},${Ci},${Ci}\\)$`),D3=new RegExp(`^hsla\\(${Md},${Ci},${Ci},${Md}\\)$`),sj={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Nk(cf,Ua,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:ij,formatHex:ij,formatHex8:F3,formatHsl:z3,formatRgb:oj,toString:oj});function ij(){return this.rgb().formatHex()}function F3(){return this.rgb().formatHex8()}function z3(){return qP(this).formatHsl()}function oj(){return this.rgb().formatRgb()}function Ua(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=R3.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?aj(t):n===3?new Yr(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?xp(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?xp(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=T3.exec(e))?new Yr(t[1],t[2],t[3],1):(t=M3.exec(e))?new Yr(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$3.exec(e))?xp(t[1],t[2],t[3],t[4]):(t=L3.exec(e))?xp(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=O3.exec(e))?uj(t[1],t[2]/100,t[3]/100,1):(t=D3.exec(e))?uj(t[1],t[2]/100,t[3]/100,t[4]):sj.hasOwnProperty(e)?aj(sj[e]):e==="transparent"?new Yr(NaN,NaN,NaN,0):null}function aj(e){return new Yr(e>>16&255,e>>8&255,e&255,1)}function xp(e,t,n,r){return r<=0&&(e=t=n=NaN),new Yr(e,t,n,r)}function B3(e){return e instanceof cf||(e=Ua(e)),e?(e=e.rgb(),new Yr(e.r,e.g,e.b,e.opacity)):new Yr}function Ex(e,t,n,r){return arguments.length===1?B3(e):new Yr(e,t,n,r??1)}function Yr(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Nk(Yr,Ex,KP(cf,{brighter(e){return e=e==null?Vh:Math.pow(Vh,e),new Yr(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Td:Math.pow(Td,e),new Yr(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Yr(Da(this.r),Da(this.g),Da(this.b),Kh(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:lj,formatHex:lj,formatHex8:H3,formatRgb:cj,toString:cj}));function lj(){return`#${Ra(this.r)}${Ra(this.g)}${Ra(this.b)}`}function H3(){return`#${Ra(this.r)}${Ra(this.g)}${Ra(this.b)}${Ra((isNaN(this.opacity)?1:this.opacity)*255)}`}function cj(){const e=Kh(this.opacity);return`${e===1?"rgb(":"rgba("}${Da(this.r)}, ${Da(this.g)}, ${Da(this.b)}${e===1?")":`, ${e})`}`}function Kh(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Da(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Ra(e){return e=Da(e),(e<16?"0":"")+e.toString(16)}function uj(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Gs(e,t,n,r)}function qP(e){if(e instanceof Gs)return new Gs(e.h,e.s,e.l,e.opacity);if(e instanceof cf||(e=Ua(e)),!e)return new Gs;if(e instanceof Gs)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),o=Math.max(t,n,r),a=NaN,l=o-s,c=(o+s)/2;return l?(t===o?a=(n-r)/l+(n<r)*6:n===o?a=(r-t)/l+2:a=(t-n)/l+4,l/=c<.5?o+s:2-o-s,a*=60):l=c>0&&c<1?0:a,new Gs(a,l,c,e.opacity)}function W3(e,t,n,r){return arguments.length===1?qP(e):new Gs(e,t,n,r??1)}function Gs(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Nk(Gs,W3,KP(cf,{brighter(e){return e=e==null?Vh:Math.pow(Vh,e),new Gs(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Td:Math.pow(Td,e),new Gs(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Yr(Ty(e>=240?e-240:e+120,s,r),Ty(e,s,r),Ty(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Gs(dj(this.h),bp(this.s),bp(this.l),Kh(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Kh(this.opacity);return`${e===1?"hsl(":"hsla("}${dj(this.h)}, ${bp(this.s)*100}%, ${bp(this.l)*100}%${e===1?")":`, ${e})`}`}}));function dj(e){return e=(e||0)%360,e<0?e+360:e}function bp(e){return Math.max(0,Math.min(1,e||0))}function Ty(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const jk=e=>()=>e;function V3(e,t){return function(n){return e+n*t}}function K3(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function q3(e){return(e=+e)==1?UP:function(t,n){return n-t?K3(t,n,e):jk(isNaN(t)?n:t)}}function UP(e,t){var n=t-e;return n?V3(e,n):jk(isNaN(e)?t:e)}const qh=function e(t){var n=q3(t);function r(s,o){var a=n((s=Ex(s)).r,(o=Ex(o)).r),l=n(s.g,o.g),c=n(s.b,o.b),u=UP(s.opacity,o.opacity);return function(d){return s.r=a(d),s.g=l(d),s.b=c(d),s.opacity=u(d),s+""}}return r.gamma=e,r}(1);function U3(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),s;return function(o){for(s=0;s<n;++s)r[s]=e[s]*(1-o)+t[s]*o;return r}}function Y3(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function G3(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,s=new Array(r),o=new Array(n),a;for(a=0;a<r;++a)s[a]=id(e[a],t[a]);for(;a<n;++a)o[a]=t[a];return function(l){for(a=0;a<r;++a)o[a]=s[a](l);return o}}function J3(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function gi(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function X3(e,t){var n={},r={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=id(e[s],t[s]):r[s]=t[s];return function(o){for(s in n)r[s]=n[s](o);return r}}var Ax=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,My=new RegExp(Ax.source,"g");function Q3(e){return function(){return e}}function Z3(e){return function(t){return e(t)+""}}function YP(e,t){var n=Ax.lastIndex=My.lastIndex=0,r,s,o,a=-1,l=[],c=[];for(e=e+"",t=t+"";(r=Ax.exec(e))&&(s=My.exec(t));)(o=s.index)>n&&(o=t.slice(n,o),l[a]?l[a]+=o:l[++a]=o),(r=r[0])===(s=s[0])?l[a]?l[a]+=s:l[++a]=s:(l[++a]=null,c.push({i:a,x:gi(r,s)})),n=My.lastIndex;return n<t.length&&(o=t.slice(n),l[a]?l[a]+=o:l[++a]=o),l.length<2?c[0]?Z3(c[0].x):Q3(t):(t=c.length,function(u){for(var d=0,f;d<t;++d)l[(f=c[d]).i]=f.x(u);return l.join("")})}function id(e,t){var n=typeof t,r;return t==null||n==="boolean"?jk(t):(n==="number"?gi:n==="string"?(r=Ua(t))?(t=r,qh):YP:t instanceof Ua?qh:t instanceof Date?J3:Y3(t)?U3:Array.isArray(t)?G3:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?X3:gi)(e,t)}var fj=180/Math.PI,Px={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function GP(e,t,n,r,s,o){var a,l,c;return(a=Math.sqrt(e*e+t*t))&&(e/=a,t/=a),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(l=Math.sqrt(n*n+r*r))&&(n/=l,r/=l,c/=l),e*r<t*n&&(e=-e,t=-t,c=-c,a=-a),{translateX:s,translateY:o,rotate:Math.atan2(t,e)*fj,skewX:Math.atan(c)*fj,scaleX:a,scaleY:l}}var kp;function eB(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Px:GP(t.a,t.b,t.c,t.d,t.e,t.f)}function tB(e){return e==null||(kp||(kp=document.createElementNS("http://www.w3.org/2000/svg","g")),kp.setAttribute("transform",e),!(e=kp.transform.baseVal.consolidate()))?Px:(e=e.matrix,GP(e.a,e.b,e.c,e.d,e.e,e.f))}function JP(e,t,n,r){function s(u){return u.length?u.pop()+" ":""}function o(u,d,f,p,h,y){if(u!==f||d!==p){var k=h.push("translate(",null,t,null,n);y.push({i:k-4,x:gi(u,f)},{i:k-2,x:gi(d,p)})}else(f||p)&&h.push("translate("+f+t+p+n)}function a(u,d,f,p){u!==d?(u-d>180?d+=360:d-u>180&&(u+=360),p.push({i:f.push(s(f)+"rotate(",null,r)-2,x:gi(u,d)})):d&&f.push(s(f)+"rotate("+d+r)}function l(u,d,f,p){u!==d?p.push({i:f.push(s(f)+"skewX(",null,r)-2,x:gi(u,d)}):d&&f.push(s(f)+"skewX("+d+r)}function c(u,d,f,p,h,y){if(u!==f||d!==p){var k=h.push(s(h)+"scale(",null,",",null,")");y.push({i:k-4,x:gi(u,f)},{i:k-2,x:gi(d,p)})}else(f!==1||p!==1)&&h.push(s(h)+"scale("+f+","+p+")")}return function(u,d){var f=[],p=[];return u=e(u),d=e(d),o(u.translateX,u.translateY,d.translateX,d.translateY,f,p),a(u.rotate,d.rotate,f,p),l(u.skewX,d.skewX,f,p),c(u.scaleX,u.scaleY,d.scaleX,d.scaleY,f,p),u=d=null,function(h){for(var y=-1,k=p.length,b;++y<k;)f[(b=p[y]).i]=b.x(h);return f.join("")}}}var nB=JP(eB,"px, ","px)","deg)"),rB=JP(tB,", ",")",")"),sB=1e-12;function pj(e){return((e=Math.exp(e))+1/e)/2}function iB(e){return((e=Math.exp(e))-1/e)/2}function oB(e){return((e=Math.exp(2*e))-1)/(e+1)}const oh=function e(t,n,r){function s(o,a){var l=o[0],c=o[1],u=o[2],d=a[0],f=a[1],p=a[2],h=d-l,y=f-c,k=h*h+y*y,b,g;if(k<sB)g=Math.log(p/u)/t,b=function(P){return[l+P*h,c+P*y,u*Math.exp(t*P*g)]};else{var v=Math.sqrt(k),w=(p*p-u*u+r*k)/(2*u*n*v),N=(p*p-u*u-r*k)/(2*p*n*v),j=Math.log(Math.sqrt(w*w+1)-w),C=Math.log(Math.sqrt(N*N+1)-N);g=(C-j)/t,b=function(P){var I=P*g,z=pj(j),$=u/(n*v)*(z*oB(t*I+j)-iB(j));return[l+$*h,c+$*y,u*z/pj(t*I+j)]}}return b.duration=g*1e3*t/Math.SQRT2,b}return s.rho=function(o){var a=Math.max(.001,+o),l=a*a,c=l*l;return e(a,l,c)},s}(Math.SQRT2,2,4);var jc=0,Bu=0,Cu=0,XP=1e3,Uh,Hu,Yh=0,Ya=0,Km=0,$d=typeof performance=="object"&&performance.now?performance:Date,QP=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Ck(){return Ya||(QP(aB),Ya=$d.now()+Km)}function aB(){Ya=0}function Gh(){this._call=this._time=this._next=null}Gh.prototype=ZP.prototype={constructor:Gh,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Ck():+n)+(t==null?0:+t),!this._next&&Hu!==this&&(Hu?Hu._next=this:Uh=this,Hu=this),this._call=e,this._time=n,Ix()},stop:function(){this._call&&(this._call=null,this._time=1/0,Ix())}};function ZP(e,t,n){var r=new Gh;return r.restart(e,t,n),r}function lB(){Ck(),++jc;for(var e=Uh,t;e;)(t=Ya-e._time)>=0&&e._call.call(void 0,t),e=e._next;--jc}function hj(){Ya=(Yh=$d.now())+Km,jc=Bu=0;try{lB()}finally{jc=0,uB(),Ya=0}}function cB(){var e=$d.now(),t=e-Yh;t>XP&&(Km-=t,Yh=e)}function uB(){for(var e,t=Uh,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Uh=n);Hu=e,Ix(r)}function Ix(e){if(!jc){Bu&&(Bu=clearTimeout(Bu));var t=e-Ya;t>24?(e<1/0&&(Bu=setTimeout(hj,e-$d.now()-Km)),Cu&&(Cu=clearInterval(Cu))):(Cu||(Yh=$d.now(),Cu=setInterval(cB,XP)),jc=1,QP(hj))}}function mj(e,t,n){var r=new Gh;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var dB=Wm("start","end","cancel","interrupt"),fB=[],eI=0,gj=1,Rx=2,ah=3,yj=4,Tx=5,lh=6;function qm(e,t,n,r,s,o){var a=e.__transition;if(!a)e.__transition={};else if(n in a)return;pB(e,n,{name:t,index:r,group:s,on:dB,tween:fB,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:eI})}function _k(e,t){var n=ii(e,t);if(n.state>eI)throw new Error("too late; already scheduled");return n}function Ti(e,t){var n=ii(e,t);if(n.state>ah)throw new Error("too late; already running");return n}function ii(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function pB(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=ZP(o,0,n.time);function o(u){n.state=gj,n.timer.restart(a,n.delay,n.time),n.delay<=u&&a(u-n.delay)}function a(u){var d,f,p,h;if(n.state!==gj)return c();for(d in r)if(h=r[d],h.name===n.name){if(h.state===ah)return mj(a);h.state===yj?(h.state=lh,h.timer.stop(),h.on.call("interrupt",e,e.__data__,h.index,h.group),delete r[d]):+d<t&&(h.state=lh,h.timer.stop(),h.on.call("cancel",e,e.__data__,h.index,h.group),delete r[d])}if(mj(function(){n.state===ah&&(n.state=yj,n.timer.restart(l,n.delay,n.time),l(u))}),n.state=Rx,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Rx){for(n.state=ah,s=new Array(p=n.tween.length),d=0,f=-1;d<p;++d)(h=n.tween[d].value.call(e,e.__data__,n.index,n.group))&&(s[++f]=h);s.length=f+1}}function l(u){for(var d=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(c),n.state=Tx,1),f=-1,p=s.length;++f<p;)s[f].call(e,d);n.state===Tx&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=lh,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function ch(e,t){var n=e.__transition,r,s,o=!0,a;if(n){t=t==null?null:t+"";for(a in n){if((r=n[a]).name!==t){o=!1;continue}s=r.state>Rx&&r.state<Tx,r.state=lh,r.timer.stop(),r.on.call(s?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[a]}o&&delete e.__transition}}function hB(e){return this.each(function(){ch(this,e)})}function mB(e,t){var n,r;return function(){var s=Ti(this,e),o=s.tween;if(o!==n){r=n=o;for(var a=0,l=r.length;a<l;++a)if(r[a].name===t){r=r.slice(),r.splice(a,1);break}}s.tween=r}}function gB(e,t,n){var r,s;if(typeof n!="function")throw new Error;return function(){var o=Ti(this,e),a=o.tween;if(a!==r){s=(r=a).slice();for(var l={name:t,value:n},c=0,u=s.length;c<u;++c)if(s[c].name===t){s[c]=l;break}c===u&&s.push(l)}o.tween=s}}function yB(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=ii(this.node(),n).tween,s=0,o=r.length,a;s<o;++s)if((a=r[s]).name===e)return a.value;return null}return this.each((t==null?mB:gB)(n,e,t))}function Ek(e,t,n){var r=e._id;return e.each(function(){var s=Ti(this,r);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return ii(s,r).value[t]}}function tI(e,t){var n;return(typeof t=="number"?gi:t instanceof Ua?qh:(n=Ua(t))?(t=n,qh):YP)(e,t)}function wB(e){return function(){this.removeAttribute(e)}}function xB(e){return function(){this.removeAttributeNS(e.space,e.local)}}function bB(e,t,n){var r,s=n+"",o;return function(){var a=this.getAttribute(e);return a===s?null:a===r?o:o=t(r=a,n)}}function kB(e,t,n){var r,s=n+"",o;return function(){var a=this.getAttributeNS(e.space,e.local);return a===s?null:a===r?o:o=t(r=a,n)}}function vB(e,t,n){var r,s,o;return function(){var a,l=n(this),c;return l==null?void this.removeAttribute(e):(a=this.getAttribute(e),c=l+"",a===c?null:a===r&&c===s?o:(s=c,o=t(r=a,l)))}}function SB(e,t,n){var r,s,o;return function(){var a,l=n(this),c;return l==null?void this.removeAttributeNS(e.space,e.local):(a=this.getAttributeNS(e.space,e.local),c=l+"",a===c?null:a===r&&c===s?o:(s=c,o=t(r=a,l)))}}function NB(e,t){var n=Vm(e),r=n==="transform"?rB:tI;return this.attrTween(e,typeof t=="function"?(n.local?SB:vB)(n,r,Ek(this,"attr."+e,t)):t==null?(n.local?xB:wB)(n):(n.local?kB:bB)(n,r,t))}function jB(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function CB(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function _B(e,t){var n,r;function s(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&CB(e,o)),n}return s._value=t,s}function EB(e,t){var n,r;function s(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&jB(e,o)),n}return s._value=t,s}function AB(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=Vm(e);return this.tween(n,(r.local?_B:EB)(r,t))}function PB(e,t){return function(){_k(this,e).delay=+t.apply(this,arguments)}}function IB(e,t){return t=+t,function(){_k(this,e).delay=t}}function RB(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?PB:IB)(t,e)):ii(this.node(),t).delay}function TB(e,t){return function(){Ti(this,e).duration=+t.apply(this,arguments)}}function MB(e,t){return t=+t,function(){Ti(this,e).duration=t}}function $B(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?TB:MB)(t,e)):ii(this.node(),t).duration}function LB(e,t){if(typeof t!="function")throw new Error;return function(){Ti(this,e).ease=t}}function OB(e){var t=this._id;return arguments.length?this.each(LB(t,e)):ii(this.node(),t).ease}function DB(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ti(this,e).ease=n}}function FB(e){if(typeof e!="function")throw new Error;return this.each(DB(this._id,e))}function zB(e){typeof e!="function"&&(e=RP(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var o=t[s],a=o.length,l=r[s]=[],c,u=0;u<a;++u)(c=o[u])&&e.call(c,c.__data__,u,o)&&l.push(c);return new ao(r,this._parents,this._name,this._id)}function BB(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,s=n.length,o=Math.min(r,s),a=new Array(r),l=0;l<o;++l)for(var c=t[l],u=n[l],d=c.length,f=a[l]=new Array(d),p,h=0;h<d;++h)(p=c[h]||u[h])&&(f[h]=p);for(;l<r;++l)a[l]=t[l];return new ao(a,this._parents,this._name,this._id)}function HB(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function WB(e,t,n){var r,s,o=HB(t)?_k:Ti;return function(){var a=o(this,e),l=a.on;l!==r&&(s=(r=l).copy()).on(t,n),a.on=s}}function VB(e,t){var n=this._id;return arguments.length<2?ii(this.node(),n).on.on(e):this.each(WB(n,e,t))}function KB(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function qB(){return this.on("end.remove",KB(this._id))}function UB(e){var t=this._name,n=this._id;typeof e!="function"&&(e=vk(e));for(var r=this._groups,s=r.length,o=new Array(s),a=0;a<s;++a)for(var l=r[a],c=l.length,u=o[a]=new Array(c),d,f,p=0;p<c;++p)(d=l[p])&&(f=e.call(d,d.__data__,p,l))&&("__data__"in d&&(f.__data__=d.__data__),u[p]=f,qm(u[p],t,n,p,u,ii(d,n)));return new ao(o,this._parents,t,n)}function YB(e){var t=this._name,n=this._id;typeof e!="function"&&(e=IP(e));for(var r=this._groups,s=r.length,o=[],a=[],l=0;l<s;++l)for(var c=r[l],u=c.length,d,f=0;f<u;++f)if(d=c[f]){for(var p=e.call(d,d.__data__,f,c),h,y=ii(d,n),k=0,b=p.length;k<b;++k)(h=p[k])&&qm(h,t,n,k,p,y);o.push(p),a.push(d)}return new ao(o,a,t,n)}var GB=lf.prototype.constructor;function JB(){return new GB(this._groups,this._parents)}function XB(e,t){var n,r,s;return function(){var o=Nc(this,e),a=(this.style.removeProperty(e),Nc(this,e));return o===a?null:o===n&&a===r?s:s=t(n=o,r=a)}}function nI(e){return function(){this.style.removeProperty(e)}}function QB(e,t,n){var r,s=n+"",o;return function(){var a=Nc(this,e);return a===s?null:a===r?o:o=t(r=a,n)}}function ZB(e,t,n){var r,s,o;return function(){var a=Nc(this,e),l=n(this),c=l+"";return l==null&&(c=l=(this.style.removeProperty(e),Nc(this,e))),a===c?null:a===r&&c===s?o:(s=c,o=t(r=a,l))}}function eH(e,t){var n,r,s,o="style."+t,a="end."+o,l;return function(){var c=Ti(this,e),u=c.on,d=c.value[o]==null?l||(l=nI(t)):void 0;(u!==n||s!==d)&&(r=(n=u).copy()).on(a,s=d),c.on=r}}function tH(e,t,n){var r=(e+="")=="transform"?nB:tI;return t==null?this.styleTween(e,XB(e,r)).on("end.style."+e,nI(e)):typeof t=="function"?this.styleTween(e,ZB(e,r,Ek(this,"style."+e,t))).each(eH(this._id,e)):this.styleTween(e,QB(e,r,t),n).on("end.style."+e,null)}function nH(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function rH(e,t,n){var r,s;function o(){var a=t.apply(this,arguments);return a!==s&&(r=(s=a)&&nH(e,a,n)),r}return o._value=t,o}function sH(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,rH(e,t,n??""))}function iH(e){return function(){this.textContent=e}}function oH(e){return function(){var t=e(this);this.textContent=t??""}}function aH(e){return this.tween("text",typeof e=="function"?oH(Ek(this,"text",e)):iH(e==null?"":e+""))}function lH(e){return function(t){this.textContent=e.call(this,t)}}function cH(e){var t,n;function r(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&lH(s)),t}return r._value=e,r}function uH(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,cH(e))}function dH(){for(var e=this._name,t=this._id,n=rI(),r=this._groups,s=r.length,o=0;o<s;++o)for(var a=r[o],l=a.length,c,u=0;u<l;++u)if(c=a[u]){var d=ii(c,t);qm(c,e,n,u,a,{time:d.time+d.delay+d.duration,delay:0,duration:d.duration,ease:d.ease})}return new ao(r,this._parents,e,n)}function fH(){var e,t,n=this,r=n._id,s=n.size();return new Promise(function(o,a){var l={value:a},c={value:function(){--s===0&&o()}};n.each(function(){var u=Ti(this,r),d=u.on;d!==e&&(t=(e=d).copy(),t._.cancel.push(l),t._.interrupt.push(l),t._.end.push(c)),u.on=t}),s===0&&o()})}var pH=0;function ao(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function rI(){return++pH}var Hi=lf.prototype;ao.prototype={constructor:ao,select:UB,selectAll:YB,selectChild:Hi.selectChild,selectChildren:Hi.selectChildren,filter:zB,merge:BB,selection:JB,transition:dH,call:Hi.call,nodes:Hi.nodes,node:Hi.node,size:Hi.size,empty:Hi.empty,each:Hi.each,on:VB,attr:NB,attrTween:AB,style:tH,styleTween:sH,text:aH,textTween:uH,remove:qB,tween:yB,delay:RB,duration:$B,ease:OB,easeVarying:FB,end:fH,[Symbol.iterator]:Hi[Symbol.iterator]};function hH(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var mH={time:null,delay:0,duration:250,ease:hH};function gH(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function yH(e){var t,n;e instanceof ao?(t=e._id,e=e._name):(t=rI(),(n=mH).time=Ck(),e=e==null?null:e+"");for(var r=this._groups,s=r.length,o=0;o<s;++o)for(var a=r[o],l=a.length,c,u=0;u<l;++u)(c=a[u])&&qm(c,e,t,u,a,n||gH(c,t));return new ao(r,this._parents,e,t)}lf.prototype.interrupt=hB;lf.prototype.transition=yH;const vp=e=>()=>e;function wH(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Ji(e,t,n){this.k=e,this.x=t,this.y=n}Ji.prototype={constructor:Ji,scale:function(e){return e===1?this:new Ji(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Ji(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Um=new Ji(1,0,0);sI.prototype=Ji.prototype;function sI(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Um;return e.__zoom}function $y(e){e.stopImmediatePropagation()}function _u(e){e.preventDefault(),e.stopImmediatePropagation()}function xH(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function bH(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function wj(){return this.__zoom||Um}function kH(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function vH(){return navigator.maxTouchPoints||"ontouchstart"in this}function SH(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],a=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),a>o?(o+a)/2:Math.min(0,o)||Math.max(0,a))}function iI(){var e=xH,t=bH,n=SH,r=kH,s=vH,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],l=250,c=oh,u=Wm("start","zoom","end"),d,f,p,h=500,y=150,k=0,b=10;function g(M){M.property("__zoom",wj).on("wheel.zoom",I,{passive:!1}).on("mousedown.zoom",z).on("dblclick.zoom",$).filter(s).on("touchstart.zoom",L).on("touchmove.zoom",F).on("touchend.zoom touchcancel.zoom",O).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(M,K,H,D){var T=M.selection?M.selection():M;T.property("__zoom",wj),M!==T?j(M,K,H,D):T.interrupt().each(function(){C(this,arguments).event(D).start().zoom(null,typeof K=="function"?K.apply(this,arguments):K).end()})},g.scaleBy=function(M,K,H,D){g.scaleTo(M,function(){var T=this.__zoom.k,W=typeof K=="function"?K.apply(this,arguments):K;return T*W},H,D)},g.scaleTo=function(M,K,H,D){g.transform(M,function(){var T=t.apply(this,arguments),W=this.__zoom,E=H==null?N(T):typeof H=="function"?H.apply(this,arguments):H,Q=W.invert(E),V=typeof K=="function"?K.apply(this,arguments):K;return n(w(v(W,V),E,Q),T,a)},H,D)},g.translateBy=function(M,K,H,D){g.transform(M,function(){return n(this.__zoom.translate(typeof K=="function"?K.apply(this,arguments):K,typeof H=="function"?H.apply(this,arguments):H),t.apply(this,arguments),a)},null,D)},g.translateTo=function(M,K,H,D,T){g.transform(M,function(){var W=t.apply(this,arguments),E=this.__zoom,Q=D==null?N(W):typeof D=="function"?D.apply(this,arguments):D;return n(Um.translate(Q[0],Q[1]).scale(E.k).translate(typeof K=="function"?-K.apply(this,arguments):-K,typeof H=="function"?-H.apply(this,arguments):-H),W,a)},D,T)};function v(M,K){return K=Math.max(o[0],Math.min(o[1],K)),K===M.k?M:new Ji(K,M.x,M.y)}function w(M,K,H){var D=K[0]-H[0]*M.k,T=K[1]-H[1]*M.k;return D===M.x&&T===M.y?M:new Ji(M.k,D,T)}function N(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function j(M,K,H,D){M.on("start.zoom",function(){C(this,arguments).event(D).start()}).on("interrupt.zoom end.zoom",function(){C(this,arguments).event(D).end()}).tween("zoom",function(){var T=this,W=arguments,E=C(T,W).event(D),Q=t.apply(T,W),V=H==null?N(Q):typeof H=="function"?H.apply(T,W):H,B=Math.max(Q[1][0]-Q[0][0],Q[1][1]-Q[0][1]),se=T.__zoom,ue=typeof K=="function"?K.apply(T,W):K,G=c(se.invert(V).concat(B/se.k),ue.invert(V).concat(B/ue.k));return function(ee){if(ee===1)ee=ue;else{var te=G(ee),ne=B/te[2];ee=new Ji(ne,V[0]-te[0]*ne,V[1]-te[1]*ne)}E.zoom(null,ee)}})}function C(M,K,H){return!H&&M.__zooming||new P(M,K)}function P(M,K){this.that=M,this.args=K,this.active=0,this.sourceEvent=null,this.extent=t.apply(M,K),this.taps=0}P.prototype={event:function(M){return M&&(this.sourceEvent=M),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(M,K){return this.mouse&&M!=="mouse"&&(this.mouse[1]=K.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=K.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=K.invert(this.touch1[0])),this.that.__zoom=K,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var K=as(this.that).datum();u.call(M,this.that,new wH(M,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:u}),K)}};function I(M,...K){if(!e.apply(this,arguments))return;var H=C(this,K).event(M),D=this.__zoom,T=Math.max(o[0],Math.min(o[1],D.k*Math.pow(2,r.apply(this,arguments)))),W=qs(M);if(H.wheel)(H.mouse[0][0]!==W[0]||H.mouse[0][1]!==W[1])&&(H.mouse[1]=D.invert(H.mouse[0]=W)),clearTimeout(H.wheel);else{if(D.k===T)return;H.mouse=[W,D.invert(W)],ch(this),H.start()}_u(M),H.wheel=setTimeout(E,y),H.zoom("mouse",n(w(v(D,T),H.mouse[0],H.mouse[1]),H.extent,a));function E(){H.wheel=null,H.end()}}function z(M,...K){if(p||!e.apply(this,arguments))return;var H=M.currentTarget,D=C(this,K,!0).event(M),T=as(M.view).on("mousemove.zoom",V,!0).on("mouseup.zoom",B,!0),W=qs(M,H),E=M.clientX,Q=M.clientY;HP(M.view),$y(M),D.mouse=[W,this.__zoom.invert(W)],ch(this),D.start();function V(se){if(_u(se),!D.moved){var ue=se.clientX-E,G=se.clientY-Q;D.moved=ue*ue+G*G>k}D.event(se).zoom("mouse",n(w(D.that.__zoom,D.mouse[0]=qs(se,H),D.mouse[1]),D.extent,a))}function B(se){T.on("mousemove.zoom mouseup.zoom",null),WP(se.view,D.moved),_u(se),D.event(se).end()}}function $(M,...K){if(e.apply(this,arguments)){var H=this.__zoom,D=qs(M.changedTouches?M.changedTouches[0]:M,this),T=H.invert(D),W=H.k*(M.shiftKey?.5:2),E=n(w(v(H,W),D,T),t.apply(this,K),a);_u(M),l>0?as(this).transition().duration(l).call(j,E,D,M):as(this).call(g.transform,E,D,M)}}function L(M,...K){if(e.apply(this,arguments)){var H=M.touches,D=H.length,T=C(this,K,M.changedTouches.length===D).event(M),W,E,Q,V;for($y(M),E=0;E<D;++E)Q=H[E],V=qs(Q,this),V=[V,this.__zoom.invert(V),Q.identifier],T.touch0?!T.touch1&&T.touch0[2]!==V[2]&&(T.touch1=V,T.taps=0):(T.touch0=V,W=!0,T.taps=1+!!d);d&&(d=clearTimeout(d)),W&&(T.taps<2&&(f=V[0],d=setTimeout(function(){d=null},h)),ch(this),T.start())}}function F(M,...K){if(this.__zooming){var H=C(this,K).event(M),D=M.changedTouches,T=D.length,W,E,Q,V;for(_u(M),W=0;W<T;++W)E=D[W],Q=qs(E,this),H.touch0&&H.touch0[2]===E.identifier?H.touch0[0]=Q:H.touch1&&H.touch1[2]===E.identifier&&(H.touch1[0]=Q);if(E=H.that.__zoom,H.touch1){var B=H.touch0[0],se=H.touch0[1],ue=H.touch1[0],G=H.touch1[1],ee=(ee=ue[0]-B[0])*ee+(ee=ue[1]-B[1])*ee,te=(te=G[0]-se[0])*te+(te=G[1]-se[1])*te;E=v(E,Math.sqrt(ee/te)),Q=[(B[0]+ue[0])/2,(B[1]+ue[1])/2],V=[(se[0]+G[0])/2,(se[1]+G[1])/2]}else if(H.touch0)Q=H.touch0[0],V=H.touch0[1];else return;H.zoom("touch",n(w(E,Q,V),H.extent,a))}}function O(M,...K){if(this.__zooming){var H=C(this,K).event(M),D=M.changedTouches,T=D.length,W,E;for($y(M),p&&clearTimeout(p),p=setTimeout(function(){p=null},h),W=0;W<T;++W)E=D[W],H.touch0&&H.touch0[2]===E.identifier?delete H.touch0:H.touch1&&H.touch1[2]===E.identifier&&delete H.touch1;if(H.touch1&&!H.touch0&&(H.touch0=H.touch1,delete H.touch1),H.touch0)H.touch0[1]=this.__zoom.invert(H.touch0[0]);else if(H.end(),H.taps===2&&(E=qs(E,this),Math.hypot(f[0]-E[0],f[1]-E[1])<b)){var Q=as(this).on("dblclick.zoom");Q&&Q.apply(this,arguments)}}}return g.wheelDelta=function(M){return arguments.length?(r=typeof M=="function"?M:vp(+M),g):r},g.filter=function(M){return arguments.length?(e=typeof M=="function"?M:vp(!!M),g):e},g.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:vp(!!M),g):s},g.extent=function(M){return arguments.length?(t=typeof M=="function"?M:vp([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),g):t},g.scaleExtent=function(M){return arguments.length?(o[0]=+M[0],o[1]=+M[1],g):[o[0],o[1]]},g.translateExtent=function(M){return arguments.length?(a[0][0]=+M[0][0],a[1][0]=+M[1][0],a[0][1]=+M[0][1],a[1][1]=+M[1][1],g):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},g.constrain=function(M){return arguments.length?(n=M,g):n},g.duration=function(M){return arguments.length?(l=+M,g):l},g.interpolate=function(M){return arguments.length?(c=M,g):c},g.on=function(){var M=u.on.apply(u,arguments);return M===u?g:M},g.clickDistance=function(M){return arguments.length?(k=(M=+M)*M,g):Math.sqrt(k)},g.tapDistance=function(M){return arguments.length?(b=+M,g):b},g}const Ii={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},Ld=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],oI=["Enter"," ","Escape"],aI={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Cc;(function(e){e.Strict="strict",e.Loose="loose"})(Cc||(Cc={}));var Fa;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Fa||(Fa={}));var Od;(function(e){e.Partial="partial",e.Full="full"})(Od||(Od={}));const lI={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Mo;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Mo||(Mo={}));var bi;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(bi||(bi={}));var qe;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(qe||(qe={}));const xj={[qe.Left]:qe.Right,[qe.Right]:qe.Left,[qe.Top]:qe.Bottom,[qe.Bottom]:qe.Top};function cI(e){return e===null?null:e?"valid":"invalid"}const uI=e=>"id"in e&&"source"in e&&"target"in e,NH=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Ak=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),uf=(e,t=[0,0])=>{const{width:n,height:r}=fo(e),s=e.origin??t,o=n*s[0],a=r*s[1];return{x:e.position.x-o,y:e.position.y-a}},jH=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const o=typeof s=="string";let a=!t.nodeLookup&&!o?s:void 0;t.nodeLookup&&(a=o?t.nodeLookup.get(s):Ak(s)?s:t.nodeLookup.get(s.id));const l=a?Jh(a,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Ym(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Gm(n)},df=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=Ym(n,Jh(s)),r=!0)}),r?Gm(n):{x:0,y:0,width:0,height:0}},Pk=(e,t,[n,r,s]=[0,0,1],o=!1,a=!1)=>{const l={...pf(t,[n,r,s]),width:t.width/s,height:t.height/s},c=[];for(const u of e.values()){const{measured:d,selectable:f=!0,hidden:p=!1}=u;if(a&&!f||p)continue;const h=d.width??u.width??u.initialWidth??null,y=d.height??u.height??u.initialHeight??null,k=Dd(l,Ec(u)),b=(h??0)*(y??0),g=o&&k>0;(!u.internals.handleBounds||g||k>=b||u.dragging)&&c.push(u)}return c},CH=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function _H(e,t){const n=new Map,r=t!=null&&t.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!s.hidden)&&(!r||r.has(s.id))&&n.set(s.id,s)}),n}async function EH({nodes:e,width:t,height:n,panZoom:r,minZoom:s,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const l=_H(e,a),c=df(l),u=Ik(c,t,n,(a==null?void 0:a.minZoom)??s,(a==null?void 0:a.maxZoom)??o,(a==null?void 0:a.padding)??.1);return await r.setViewport(u,{duration:a==null?void 0:a.duration,ease:a==null?void 0:a.ease,interpolate:a==null?void 0:a.interpolate}),Promise.resolve(!0)}function dI({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:s,onError:o}){const a=n.get(e),l=a.parentId?n.get(a.parentId):void 0,{x:c,y:u}=l?l.internals.positionAbsolute:{x:0,y:0},d=a.origin??r;let f=a.extent||s;if(a.extent==="parent"&&!a.expandParent)if(!l)o==null||o("005",Ii.error005());else{const h=l.measured.width,y=l.measured.height;h&&y&&(f=[[c,u],[c+h,u+y]])}else l&&Ac(a.extent)&&(f=[[a.extent[0][0]+c,a.extent[0][1]+u],[a.extent[1][0]+c,a.extent[1][1]+u]]);const p=Ac(f)?Ga(t,f,a.measured):t;return(a.measured.width===void 0||a.measured.height===void 0)&&(o==null||o("015",Ii.error015())),{position:{x:p.x-c+(a.measured.width??0)*d[0],y:p.y-u+(a.measured.height??0)*d[1]},positionAbsolute:p}}async function AH({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:s}){const o=new Set(e.map(p=>p.id)),a=[];for(const p of n){if(p.deletable===!1)continue;const h=o.has(p.id),y=!h&&p.parentId&&a.find(k=>k.id===p.parentId);(h||y)&&a.push(p)}const l=new Set(t.map(p=>p.id)),c=r.filter(p=>p.deletable!==!1),d=CH(a,c);for(const p of c)l.has(p.id)&&!d.find(y=>y.id===p.id)&&d.push(p);if(!s)return{edges:d,nodes:a};const f=await s({nodes:a,edges:d});return typeof f=="boolean"?f?{edges:d,nodes:a}:{edges:[],nodes:[]}:f}const _c=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Ga=(e={x:0,y:0},t,n)=>({x:_c(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:_c(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function fI(e,t,n){const{width:r,height:s}=fo(n),{x:o,y:a}=n.internals.positionAbsolute;return Ga(e,[[o,a],[o+r,a+s]],t)}const bj=(e,t,n)=>e<t?_c(Math.abs(e-t),1,t)/t:e>n?-_c(Math.abs(e-n),1,t)/t:0,pI=(e,t,n=15,r=40)=>{const s=bj(e.x,r,t.width-r)*n,o=bj(e.y,r,t.height-r)*n;return[s,o]},Ym=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Mx=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),Gm=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Ec=(e,t=[0,0])=>{var s,o;const{x:n,y:r}=Ak(e)?e.internals.positionAbsolute:uf(e,t);return{x:n,y:r,width:((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0,height:((o=e.measured)==null?void 0:o.height)??e.height??e.initialHeight??0}},Jh=(e,t=[0,0])=>{var s,o;const{x:n,y:r}=Ak(e)?e.internals.positionAbsolute:uf(e,t);return{x:n,y:r,x2:n+(((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0),y2:r+(((o=e.measured)==null?void 0:o.height)??e.height??e.initialHeight??0)}},hI=(e,t)=>Gm(Ym(Mx(e),Mx(t))),Dd=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},kj=e=>Js(e.width)&&Js(e.height)&&Js(e.x)&&Js(e.y),Js=e=>!isNaN(e)&&isFinite(e),PH=(e,t)=>{},ff=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),pf=({x:e,y:t},[n,r,s],o=!1,a=[1,1])=>{const l={x:(e-n)/s,y:(t-r)/s};return o?ff(l,a):l},Xh=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r});function Il(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function IH(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=Il(e,n),s=Il(e,t);return{top:r,right:s,bottom:r,left:s,x:s*2,y:r*2}}if(typeof e=="object"){const r=Il(e.top??e.y??0,n),s=Il(e.bottom??e.y??0,n),o=Il(e.left??e.x??0,t),a=Il(e.right??e.x??0,t);return{top:r,right:a,bottom:s,left:o,x:o+a,y:r+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function RH(e,t,n,r,s,o){const{x:a,y:l}=Xh(e,[t,n,r]),{x:c,y:u}=Xh({x:e.x+e.width,y:e.y+e.height},[t,n,r]),d=s-c,f=o-u;return{left:Math.floor(a),top:Math.floor(l),right:Math.floor(d),bottom:Math.floor(f)}}const Ik=(e,t,n,r,s,o)=>{const a=IH(o,t,n),l=(t-a.x)/e.width,c=(n-a.y)/e.height,u=Math.min(l,c),d=_c(u,r,s),f=e.x+e.width/2,p=e.y+e.height/2,h=t/2-f*d,y=n/2-p*d,k=RH(e,h,y,d,t,n),b={left:Math.min(k.left-a.left,0),top:Math.min(k.top-a.top,0),right:Math.min(k.right-a.right,0),bottom:Math.min(k.bottom-a.bottom,0)};return{x:h-b.left+b.right,y:y-b.top+b.bottom,zoom:d}},Fd=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function Ac(e){return e!=null&&e!=="parent"}function fo(e){var t,n;return{width:((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth??0,height:((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight??0}}function mI(e){var t,n;return(((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth)!==void 0&&(((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight)!==void 0}function gI(e,t={width:0,height:0},n,r,s){const o={...e},a=r.get(n);if(a){const l=a.origin||s;o.x+=a.internals.positionAbsolute.x-(t.width??0)*l[0],o.y+=a.internals.positionAbsolute.y-(t.height??0)*l[1]}return o}function vj(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function TH(){let e,t;return{promise:new Promise((r,s)=>{e=r,t=s}),resolve:e,reject:t}}function MH(e){return{...aI,...e||{}}}function od(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:s}){const{x:o,y:a}=Xs(e),l=pf({x:o-((s==null?void 0:s.left)??0),y:a-((s==null?void 0:s.top)??0)},r),{x:c,y:u}=n?ff(l,t):l;return{xSnapped:c,ySnapped:u,...l}}const Rk=e=>({width:e.offsetWidth,height:e.offsetHeight}),yI=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},$H=["INPUT","SELECT","TEXTAREA"];function wI(e){var r,s;const t=((s=(r=e.composedPath)==null?void 0:r.call(e))==null?void 0:s[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:$H.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const xI=e=>"clientX"in e,Xs=(e,t)=>{var o,a;const n=xI(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,s=n?e.clientY:(a=e.touches)==null?void 0:a[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Sj=(e,t,n,r,s)=>{const o=t.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const l=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:s,position:a.getAttribute("data-handlepos"),x:(l.left-n.left)/r,y:(l.top-n.top)/r,...Rk(a)}})};function bI({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:s,sourceControlY:o,targetControlX:a,targetControlY:l}){const c=e*.125+s*.375+a*.375+n*.125,u=t*.125+o*.375+l*.375+r*.125,d=Math.abs(c-e),f=Math.abs(u-t);return[c,u,d,f]}function Sp(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Nj({pos:e,x1:t,y1:n,x2:r,y2:s,c:o}){switch(e){case qe.Left:return[t-Sp(t-r,o),n];case qe.Right:return[t+Sp(r-t,o),n];case qe.Top:return[t,n-Sp(n-s,o)];case qe.Bottom:return[t,n+Sp(s-n,o)]}}function kI({sourceX:e,sourceY:t,sourcePosition:n=qe.Bottom,targetX:r,targetY:s,targetPosition:o=qe.Top,curvature:a=.25}){const[l,c]=Nj({pos:n,x1:e,y1:t,x2:r,y2:s,c:a}),[u,d]=Nj({pos:o,x1:r,y1:s,x2:e,y2:t,c:a}),[f,p,h,y]=bI({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:l,sourceControlY:c,targetControlX:u,targetControlY:d});return[`M${e},${t} C${l},${c} ${u},${d} ${r},${s}`,f,p,h,y]}function vI({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,o=n<e?n+s:n-s,a=Math.abs(r-t)/2,l=r<t?r+a:r-a;return[o,l,s,a]}function LH({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:s=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const a=s&&n?r+1e3:r,l=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return a+l}function OH({sourceNode:e,targetNode:t,width:n,height:r,transform:s}){const o=Ym(Jh(e),Jh(t));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const a={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:r/s[2]};return Dd(a,Gm(o))>0}const DH=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,FH=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),uh=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||DH;let s;return uI(e)?s={...e}:s={...e,id:r(e)},FH(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))};function SI({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,o,a,l]=vI({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,o,a,l]}const jj={[qe.Left]:{x:-1,y:0},[qe.Right]:{x:1,y:0},[qe.Top]:{x:0,y:-1},[qe.Bottom]:{x:0,y:1}},zH=({source:e,sourcePosition:t=qe.Bottom,target:n})=>t===qe.Left||t===qe.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},Cj=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function BH({source:e,sourcePosition:t=qe.Bottom,target:n,targetPosition:r=qe.Top,center:s,offset:o,stepPosition:a}){const l=jj[t],c=jj[r],u={x:e.x+l.x*o,y:e.y+l.y*o},d={x:n.x+c.x*o,y:n.y+c.y*o},f=zH({source:u,sourcePosition:t,target:d}),p=f.x!==0?"x":"y",h=f[p];let y=[],k,b;const g={x:0,y:0},v={x:0,y:0},[,,w,N]=vI({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[p]*c[p]===-1){p==="x"?(k=s.x??u.x+(d.x-u.x)*a,b=s.y??(u.y+d.y)/2):(k=s.x??(u.x+d.x)/2,b=s.y??u.y+(d.y-u.y)*a);const I=[{x:k,y:u.y},{x:k,y:d.y}],z=[{x:u.x,y:b},{x:d.x,y:b}];l[p]===h?y=p==="x"?I:z:y=p==="x"?z:I}else{const I=[{x:u.x,y:d.y}],z=[{x:d.x,y:u.y}];if(p==="x"?y=l.x===h?z:I:y=l.y===h?I:z,t===r){const M=Math.abs(e[p]-n[p]);if(M<=o){const K=Math.min(o-1,o-M);l[p]===h?g[p]=(u[p]>e[p]?-1:1)*K:v[p]=(d[p]>n[p]?-1:1)*K}}if(t!==r){const M=p==="x"?"y":"x",K=l[p]===c[M],H=u[M]>d[M],D=u[M]<d[M];(l[p]===1&&(!K&&H||K&&D)||l[p]!==1&&(!K&&D||K&&H))&&(y=p==="x"?I:z)}const $={x:u.x+g.x,y:u.y+g.y},L={x:d.x+v.x,y:d.y+v.y},F=Math.max(Math.abs($.x-y[0].x),Math.abs(L.x-y[0].x)),O=Math.max(Math.abs($.y-y[0].y),Math.abs(L.y-y[0].y));F>=O?(k=($.x+L.x)/2,b=y[0].y):(k=y[0].x,b=($.y+L.y)/2)}const j={x:u.x+g.x,y:u.y+g.y},C={x:d.x+v.x,y:d.y+v.y};return[[e,...j.x!==y[0].x||j.y!==y[0].y?[j]:[],...y,...C.x!==y[y.length-1].x||C.y!==y[y.length-1].y?[C]:[],n],k,b,w,N]}function HH(e,t,n,r){const s=Math.min(Cj(e,t)/2,Cj(t,n)/2,r),{x:o,y:a}=t;if(e.x===o&&o===n.x||e.y===a&&a===n.y)return`L${o} ${a}`;if(e.y===a){const u=e.x<n.x?-1:1,d=e.y<n.y?1:-1;return`L ${o+s*u},${a}Q ${o},${a} ${o},${a+s*d}`}const l=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${o},${a+s*c}Q ${o},${a} ${o+s*l},${a}`}function $x({sourceX:e,sourceY:t,sourcePosition:n=qe.Bottom,targetX:r,targetY:s,targetPosition:o=qe.Top,borderRadius:a=5,centerX:l,centerY:c,offset:u=20,stepPosition:d=.5}){const[f,p,h,y,k]=BH({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:s},targetPosition:o,center:{x:l,y:c},offset:u,stepPosition:d});let b=`M${f[0].x} ${f[0].y}`;for(let g=1;g<f.length-1;g++)b+=HH(f[g-1],f[g],f[g+1],a);return b+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[b,p,h,y,k]}function _j(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function WH(e){var f;const{sourceNode:t,targetNode:n}=e;if(!_j(t)||!_j(n))return null;const r=t.internals.handleBounds||Ej(t.handles),s=n.internals.handleBounds||Ej(n.handles),o=Aj((r==null?void 0:r.source)??[],e.sourceHandle),a=Aj(e.connectionMode===Cc.Strict?(s==null?void 0:s.target)??[]:((s==null?void 0:s.target)??[]).concat((s==null?void 0:s.source)??[]),e.targetHandle);if(!o||!a)return(f=e.onError)==null||f.call(e,"008",Ii.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=(o==null?void 0:o.position)||qe.Bottom,c=(a==null?void 0:a.position)||qe.Top,u=Ja(t,o,l),d=Ja(n,a,c);return{sourceX:u.x,sourceY:u.y,targetX:d.x,targetY:d.y,sourcePosition:l,targetPosition:c}}function Ej(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function Ja(e,t,n=qe.Left,r=!1){const s=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,o=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:a,height:l}=t??fo(e);if(r)return{x:s+a/2,y:o+l/2};switch((t==null?void 0:t.position)??n){case qe.Top:return{x:s+a/2,y:o};case qe.Right:return{x:s+a,y:o+l/2};case qe.Bottom:return{x:s+a/2,y:o+l};case qe.Left:return{x:s,y:o+l/2}}}function Aj(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function Lx(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function VH(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:s}){const o=new Set;return e.reduce((a,l)=>([l.markerStart||r,l.markerEnd||s].forEach(c=>{if(c&&typeof c=="object"){const u=Lx(c,t);o.has(u)||(a.push({id:u,color:c.color||n,...c}),o.add(u))}}),a),[]).sort((a,l)=>a.id.localeCompare(l.id))}const NI=1e3,KH=10,Tk={nodeOrigin:[0,0],nodeExtent:Ld,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},qH={...Tk,checkEquality:!0};function Mk(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function UH(e,t,n){const r=Mk(Tk,n);for(const s of e.values())if(s.parentId)Lk(s,e,t,r);else{const o=uf(s,r.nodeOrigin),a=Ac(s.extent)?s.extent:r.nodeExtent,l=Ga(o,a,fo(s));s.internals.positionAbsolute=l}}function YH(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],r=[];for(const s of e.handles){const o={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(o):s.type==="target"&&r.push(o)}return{source:n,target:r}}function $k(e){return e==="manual"}function Ox(e,t,n,r={}){var d,f;const s=Mk(qH,r),o={i:0},a=new Map(t),l=s!=null&&s.elevateNodesOnSelect&&!$k(s.zIndexMode)?NI:0;let c=e.length>0,u=!1;t.clear(),n.clear();for(const p of e){let h=a.get(p.id);if(s.checkEquality&&p===(h==null?void 0:h.internals.userNode))t.set(p.id,h);else{const y=uf(p,s.nodeOrigin),k=Ac(p.extent)?p.extent:s.nodeExtent,b=Ga(y,k,fo(p));h={...s.defaults,...p,measured:{width:(d=p.measured)==null?void 0:d.width,height:(f=p.measured)==null?void 0:f.height},internals:{positionAbsolute:b,handleBounds:YH(p,h),z:jI(p,l,s.zIndexMode),userNode:p}},t.set(p.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(c=!1),p.parentId&&Lk(h,t,n,r,o),u||(u=p.selected??!1)}return{nodesInitialized:c,hasSelectedNodes:u}}function GH(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function Lk(e,t,n,r,s){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:l,zIndexMode:c}=Mk(Tk,r),u=e.parentId,d=t.get(u);if(!d){console.warn(`Parent node ${u} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}GH(e,n),s&&!d.parentId&&d.internals.rootParentIndex===void 0&&c==="auto"&&(d.internals.rootParentIndex=++s.i,d.internals.z=d.internals.z+s.i*KH),s&&d.internals.rootParentIndex!==void 0&&(s.i=d.internals.rootParentIndex);const f=o&&!$k(c)?NI:0,{x:p,y:h,z:y}=JH(e,d,a,l,f,c),{positionAbsolute:k}=e.internals,b=p!==k.x||h!==k.y;(b||y!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:b?{x:p,y:h}:k,z:y}})}function jI(e,t,n){const r=Js(e.zIndex)?e.zIndex:0;return $k(n)?r:r+(e.selected?t:0)}function JH(e,t,n,r,s,o){const{x:a,y:l}=t.internals.positionAbsolute,c=fo(e),u=uf(e,n),d=Ac(e.extent)?Ga(u,e.extent,c):u;let f=Ga({x:a+d.x,y:l+d.y},r,c);e.extent==="parent"&&(f=fI(f,c,t));const p=jI(e,s,o),h=t.internals.z??0;return{x:f.x,y:f.y,z:h>=p?h+1:p}}function Ok(e,t,n,r=[0,0]){var a;const s=[],o=new Map;for(const l of e){const c=t.get(l.parentId);if(!c)continue;const u=((a=o.get(l.parentId))==null?void 0:a.expandedRect)??Ec(c),d=hI(u,l.rect);o.set(l.parentId,{expandedRect:d,parent:c})}return o.size>0&&o.forEach(({expandedRect:l,parent:c},u)=>{var w;const d=c.internals.positionAbsolute,f=fo(c),p=c.origin??r,h=l.x<d.x?Math.round(Math.abs(d.x-l.x)):0,y=l.y<d.y?Math.round(Math.abs(d.y-l.y)):0,k=Math.max(f.width,Math.round(l.width)),b=Math.max(f.height,Math.round(l.height)),g=(k-f.width)*p[0],v=(b-f.height)*p[1];(h>0||y>0||g||v)&&(s.push({id:u,type:"position",position:{x:c.position.x-h+g,y:c.position.y-y+v}}),(w=n.get(u))==null||w.forEach(N=>{e.some(j=>j.id===N.id)||s.push({id:N.id,type:"position",position:{x:N.position.x+h,y:N.position.y+y}})})),(f.width<l.width||f.height<l.height||h||y)&&s.push({id:u,type:"dimensions",setAttributes:!0,dimensions:{width:k+(h?p[0]*h-g:0),height:b+(y?p[1]*y-v:0)}})}),s}function XH(e,t,n,r,s,o,a){const l=r==null?void 0:r.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const u=[],d=window.getComputedStyle(l),{m22:f}=new window.DOMMatrixReadOnly(d.transform),p=[];for(const h of e.values()){const y=t.get(h.id);if(!y)continue;if(y.hidden){t.set(y.id,{...y,internals:{...y.internals,handleBounds:void 0}}),c=!0;continue}const k=Rk(h.nodeElement),b=y.measured.width!==k.width||y.measured.height!==k.height;if(!!(k.width&&k.height&&(b||!y.internals.handleBounds||h.force))){const v=h.nodeElement.getBoundingClientRect(),w=Ac(y.extent)?y.extent:o;let{positionAbsolute:N}=y.internals;y.parentId&&y.extent==="parent"?N=fI(N,k,t.get(y.parentId)):w&&(N=Ga(N,w,k));const j={...y,measured:k,internals:{...y.internals,positionAbsolute:N,handleBounds:{source:Sj("source",h.nodeElement,v,f,y.id),target:Sj("target",h.nodeElement,v,f,y.id)}}};t.set(y.id,j),y.parentId&&Lk(j,t,n,{nodeOrigin:s,zIndexMode:a}),c=!0,b&&(u.push({id:y.id,type:"dimensions",dimensions:k}),y.expandParent&&y.parentId&&p.push({id:y.id,parentId:y.parentId,rect:Ec(j,s)}))}}if(p.length>0){const h=Ok(p,t,n,s);u.push(...h)}return{changes:u,updatedInternals:c}}async function QH({delta:e,panZoom:t,transform:n,translateExtent:r,width:s,height:o}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const a=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,o]],r),l=!!a&&(a.x!==n[0]||a.y!==n[1]||a.k!==n[2]);return Promise.resolve(l)}function Pj(e,t,n,r,s,o){let a=s;const l=r.get(a)||new Map;r.set(a,l.set(n,t)),a=`${s}-${e}`;const c=r.get(a)||new Map;if(r.set(a,c.set(n,t)),o){a=`${s}-${e}-${o}`;const u=r.get(a)||new Map;r.set(a,u.set(n,t))}}function CI(e,t,n){e.clear(),t.clear();for(const r of n){const{source:s,target:o,sourceHandle:a=null,targetHandle:l=null}=r,c={edgeId:r.id,source:s,target:o,sourceHandle:a,targetHandle:l},u=`${s}-${a}--${o}-${l}`,d=`${o}-${l}--${s}-${a}`;Pj("source",c,d,e,s,a),Pj("target",c,u,e,o,l),t.set(r.id,r)}}function _I(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:_I(n,t):!1}function Ij(e,t,n){var s;let r=e;do{if((s=r==null?void 0:r.matches)!=null&&s.call(r,t))return!0;if(r===n)return!1;r=r==null?void 0:r.parentElement}while(r);return!1}function ZH(e,t,n,r){const s=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!_I(a,e))&&(a.draggable||t&&typeof a.draggable>"u")){const l=e.get(o);l&&s.set(o,{id:o,position:l.position||{x:0,y:0},distance:{x:n.x-l.internals.positionAbsolute.x,y:n.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return s}function Ly({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){var a,l,c;const s=[];for(const[u,d]of t){const f=(a=n.get(u))==null?void 0:a.internals.userNode;f&&s.push({...f,position:d.position,dragging:r})}if(!e)return[s[0],s];const o=(l=n.get(e))==null?void 0:l.internals.userNode;return[o?{...o,position:((c=t.get(e))==null?void 0:c.position)||o.position,dragging:r}:s[0],s]}function e4({dragItems:e,snapGrid:t,x:n,y:r}){const s=e.values().next().value;if(!s)return null;const o={x:n-s.distance.x,y:r-s.distance.y},a=ff(o,t);return{x:a.x-o.x,y:a.y-o.y}}function t4({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:s}){let o={x:null,y:null},a=0,l=new Map,c=!1,u={x:0,y:0},d=null,f=!1,p=null,h=!1,y=!1,k=null;function b({noDragClassName:v,handleSelector:w,domNode:N,isSelectable:j,nodeId:C,nodeClickDistance:P=0}){p=as(N);function I({x:F,y:O}){const{nodeLookup:M,nodeExtent:K,snapGrid:H,snapToGrid:D,nodeOrigin:T,onNodeDrag:W,onSelectionDrag:E,onError:Q,updateNodePositions:V}=t();o={x:F,y:O};let B=!1;const se=l.size>1,ue=se&&K?Mx(df(l)):null,G=se&&D?e4({dragItems:l,snapGrid:H,x:F,y:O}):null;for(const[ee,te]of l){if(!M.has(ee))continue;let ne={x:F-te.distance.x,y:O-te.distance.y};D&&(ne=G?{x:Math.round(ne.x+G.x),y:Math.round(ne.y+G.y)}:ff(ne,H));let Z=null;if(se&&K&&!te.extent&&ue){const{positionAbsolute:me}=te.internals,$e=me.x-ue.x+K[0][0],Ce=me.x+te.measured.width-ue.x2+K[1][0],_e=me.y-ue.y+K[0][1],Be=me.y+te.measured.height-ue.y2+K[1][1];Z=[[$e,_e],[Ce,Be]]}const{position:ce,positionAbsolute:de}=dI({nodeId:ee,nextPosition:ne,nodeLookup:M,nodeExtent:Z||K,nodeOrigin:T,onError:Q});B=B||te.position.x!==ce.x||te.position.y!==ce.y,te.position=ce,te.internals.positionAbsolute=de}if(y=y||B,!!B&&(V(l,!0),k&&(r||W||!C&&E))){const[ee,te]=Ly({nodeId:C,dragItems:l,nodeLookup:M});r==null||r(k,l,ee,te),W==null||W(k,ee,te),C||E==null||E(k,te)}}async function z(){if(!d)return;const{transform:F,panBy:O,autoPanSpeed:M,autoPanOnNodeDrag:K}=t();if(!K){c=!1,cancelAnimationFrame(a);return}const[H,D]=pI(u,d,M);(H!==0||D!==0)&&(o.x=(o.x??0)-H/F[2],o.y=(o.y??0)-D/F[2],await O({x:H,y:D})&&I(o)),a=requestAnimationFrame(z)}function $(F){var se;const{nodeLookup:O,multiSelectionActive:M,nodesDraggable:K,transform:H,snapGrid:D,snapToGrid:T,selectNodesOnDrag:W,onNodeDragStart:E,onSelectionDragStart:Q,unselectNodesAndEdges:V}=t();f=!0,(!W||!j)&&!M&&C&&((se=O.get(C))!=null&&se.selected||V()),j&&W&&C&&(e==null||e(C));const B=od(F.sourceEvent,{transform:H,snapGrid:D,snapToGrid:T,containerBounds:d});if(o=B,l=ZH(O,K,B,C),l.size>0&&(n||E||!C&&Q)){const[ue,G]=Ly({nodeId:C,dragItems:l,nodeLookup:O});n==null||n(F.sourceEvent,l,ue,G),E==null||E(F.sourceEvent,ue,G),C||Q==null||Q(F.sourceEvent,G)}}const L=VP().clickDistance(P).on("start",F=>{const{domNode:O,nodeDragThreshold:M,transform:K,snapGrid:H,snapToGrid:D}=t();d=(O==null?void 0:O.getBoundingClientRect())||null,h=!1,y=!1,k=F.sourceEvent,M===0&&$(F),o=od(F.sourceEvent,{transform:K,snapGrid:H,snapToGrid:D,containerBounds:d}),u=Xs(F.sourceEvent,d)}).on("drag",F=>{const{autoPanOnNodeDrag:O,transform:M,snapGrid:K,snapToGrid:H,nodeDragThreshold:D,nodeLookup:T}=t(),W=od(F.sourceEvent,{transform:M,snapGrid:K,snapToGrid:H,containerBounds:d});if(k=F.sourceEvent,(F.sourceEvent.type==="touchmove"&&F.sourceEvent.touches.length>1||C&&!T.has(C))&&(h=!0),!h){if(!c&&O&&f&&(c=!0,z()),!f){const E=Xs(F.sourceEvent,d),Q=E.x-u.x,V=E.y-u.y;Math.sqrt(Q*Q+V*V)>D&&$(F)}(o.x!==W.xSnapped||o.y!==W.ySnapped)&&l&&f&&(u=Xs(F.sourceEvent,d),I(W))}}).on("end",F=>{if(!(!f||h)&&(c=!1,f=!1,cancelAnimationFrame(a),l.size>0)){const{nodeLookup:O,updateNodePositions:M,onNodeDragStop:K,onSelectionDragStop:H}=t();if(y&&(M(l,!1),y=!1),s||K||!C&&H){const[D,T]=Ly({nodeId:C,dragItems:l,nodeLookup:O,dragging:!1});s==null||s(F.sourceEvent,l,D,T),K==null||K(F.sourceEvent,D,T),C||H==null||H(F.sourceEvent,T)}}}).filter(F=>{const O=F.target;return!F.button&&(!v||!Ij(O,`.${v}`,N))&&(!w||Ij(O,w,N))});p.call(L)}function g(){p==null||p.on(".drag",null)}return{update:b,destroy:g}}function n4(e,t,n){const r=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const o of t.values())Dd(s,Ec(o))>0&&r.push(o);return r}const r4=250;function s4(e,t,n,r){var l,c;let s=[],o=1/0;const a=n4(e,n,t+r4);for(const u of a){const d=[...((l=u.internals.handleBounds)==null?void 0:l.source)??[],...((c=u.internals.handleBounds)==null?void 0:c.target)??[]];for(const f of d){if(r.nodeId===f.nodeId&&r.type===f.type&&r.id===f.id)continue;const{x:p,y:h}=Ja(u,f,f.position,!0),y=Math.sqrt(Math.pow(p-e.x,2)+Math.pow(h-e.y,2));y>t||(y<o?(s=[{...f,x:p,y:h}],o=y):y===o&&s.push({...f,x:p,y:h}))}}if(!s.length)return null;if(s.length>1){const u=r.type==="source"?"target":"source";return s.find(d=>d.type===u)??s[0]}return s[0]}function EI(e,t,n,r,s,o=!1){var u,d,f;const a=r.get(e);if(!a)return null;const l=s==="strict"?(u=a.internals.handleBounds)==null?void 0:u[t]:[...((d=a.internals.handleBounds)==null?void 0:d.source)??[],...((f=a.internals.handleBounds)==null?void 0:f.target)??[]],c=(n?l==null?void 0:l.find(p=>p.id===n):l==null?void 0:l[0])??null;return c&&o?{...c,...Ja(a,c,c.position,!0)}:c}function AI(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function i4(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const PI=()=>!0;function o4(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:s,edgeUpdaterType:o,isTarget:a,domNode:l,nodeLookup:c,lib:u,autoPanOnConnect:d,flowId:f,panBy:p,cancelConnection:h,onConnectStart:y,onConnect:k,onConnectEnd:b,isValidConnection:g=PI,onReconnectEnd:v,updateConnection:w,getTransform:N,getFromHandle:j,autoPanSpeed:C,dragThreshold:P=1,handleDomNode:I}){const z=yI(e.target);let $=0,L;const{x:F,y:O}=Xs(e),M=AI(o,I),K=l==null?void 0:l.getBoundingClientRect();let H=!1;if(!K||!M)return;const D=EI(s,M,r,c,t);if(!D)return;let T=Xs(e,K),W=!1,E=null,Q=!1,V=null;function B(){if(!d||!K)return;const[ce,de]=pI(T,K,C);p({x:ce,y:de}),$=requestAnimationFrame(B)}const se={...D,nodeId:s,type:M,position:D.position},ue=c.get(s);let ee={inProgress:!0,isValid:null,from:Ja(ue,se,qe.Left,!0),fromHandle:se,fromPosition:se.position,fromNode:ue,to:T,toHandle:null,toPosition:xj[se.position],toNode:null,pointer:T};function te(){H=!0,w(ee),y==null||y(e,{nodeId:s,handleId:r,handleType:M})}P===0&&te();function ne(ce){if(!H){const{x:Be,y:ot}=Xs(ce),yt=Be-F,Te=ot-O;if(!(yt*yt+Te*Te>P*P))return;te()}if(!j()||!se){Z(ce);return}const de=N();T=Xs(ce,K),L=s4(pf(T,de,!1,[1,1]),n,c,se),W||(B(),W=!0);const me=II(ce,{handle:L,connectionMode:t,fromNodeId:s,fromHandleId:r,fromType:a?"target":"source",isValidConnection:g,doc:z,lib:u,flowId:f,nodeLookup:c});V=me.handleDomNode,E=me.connection,Q=i4(!!L,me.isValid);const $e=c.get(s),Ce=$e?Ja($e,se,qe.Left,!0):ee.from,_e={...ee,from:Ce,isValid:Q,to:me.toHandle&&Q?Xh({x:me.toHandle.x,y:me.toHandle.y},de):T,toHandle:me.toHandle,toPosition:Q&&me.toHandle?me.toHandle.position:xj[se.position],toNode:me.toHandle?c.get(me.toHandle.nodeId):null,pointer:T};w(_e),ee=_e}function Z(ce){if(!("touches"in ce&&ce.touches.length>0)){if(H){(L||V)&&E&&Q&&(k==null||k(E));const{inProgress:de,...me}=ee,$e={...me,toPosition:ee.toHandle?ee.toPosition:null};b==null||b(ce,$e),o&&(v==null||v(ce,$e))}h(),cancelAnimationFrame($),W=!1,Q=!1,E=null,V=null,z.removeEventListener("mousemove",ne),z.removeEventListener("mouseup",Z),z.removeEventListener("touchmove",ne),z.removeEventListener("touchend",Z)}}z.addEventListener("mousemove",ne),z.addEventListener("mouseup",Z),z.addEventListener("touchmove",ne),z.addEventListener("touchend",Z)}function II(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:s,fromType:o,doc:a,lib:l,flowId:c,isValidConnection:u=PI,nodeLookup:d}){const f=o==="target",p=t?a.querySelector(`.${l}-flow__handle[data-id="${c}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:h,y}=Xs(e),k=a.elementFromPoint(h,y),b=k!=null&&k.classList.contains(`${l}-flow__handle`)?k:p,g={handleDomNode:b,isValid:!1,connection:null,toHandle:null};if(b){const v=AI(void 0,b),w=b.getAttribute("data-nodeid"),N=b.getAttribute("data-handleid"),j=b.classList.contains("connectable"),C=b.classList.contains("connectableend");if(!w||!v)return g;const P={source:f?w:r,sourceHandle:f?N:s,target:f?r:w,targetHandle:f?s:N};g.connection=P;const z=j&&C&&(n===Cc.Strict?f&&v==="source"||!f&&v==="target":w!==r||N!==s);g.isValid=z&&u(P),g.toHandle=EI(w,v,N,d,n,!0)}return g}const Dx={onPointerDown:o4,isValid:II};function a4({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const s=as(e);function o({translateExtent:l,width:c,height:u,zoomStep:d=1,pannable:f=!0,zoomable:p=!0,inversePan:h=!1}){const y=w=>{if(w.sourceEvent.type!=="wheel"||!t)return;const N=n(),j=w.sourceEvent.ctrlKey&&Fd()?10:1,C=-w.sourceEvent.deltaY*(w.sourceEvent.deltaMode===1?.05:w.sourceEvent.deltaMode?1:.002)*d,P=N[2]*Math.pow(2,C*j);t.scaleTo(P)};let k=[0,0];const b=w=>{(w.sourceEvent.type==="mousedown"||w.sourceEvent.type==="touchstart")&&(k=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY])},g=w=>{const N=n();if(w.sourceEvent.type!=="mousemove"&&w.sourceEvent.type!=="touchmove"||!t)return;const j=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY],C=[j[0]-k[0],j[1]-k[1]];k=j;const P=r()*Math.max(N[2],Math.log(N[2]))*(h?-1:1),I={x:N[0]-C[0]*P,y:N[1]-C[1]*P},z=[[0,0],[c,u]];t.setViewportConstrained({x:I.x,y:I.y,zoom:N[2]},z,l)},v=iI().on("start",b).on("zoom",f?g:null).on("zoom.wheel",p?y:null);s.call(v,{})}function a(){s.on("zoom",null)}return{update:o,destroy:a,pointer:qs}}const Jm=e=>({x:e.x,y:e.y,zoom:e.k}),Oy=({x:e,y:t,zoom:n})=>Um.translate(e,t).scale(n),Zl=(e,t)=>e.target.closest(`.${t}`),RI=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),l4=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Dy=(e,t=0,n=l4,r=()=>{})=>{const s=typeof t=="number"&&t>0;return s||r(),s?e.transition().duration(t).ease(n).on("end",r):e},TI=e=>{const t=e.ctrlKey&&Fd()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function c4({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:s,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:u}){return d=>{if(Zl(d,t))return d.ctrlKey&&d.preventDefault(),!1;d.preventDefault(),d.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(d.ctrlKey&&a){const b=qs(d),g=TI(d),v=f*Math.pow(2,g);r.scaleTo(n,v,b,d);return}const p=d.deltaMode===1?20:1;let h=s===Fa.Vertical?0:d.deltaX*p,y=s===Fa.Horizontal?0:d.deltaY*p;!Fd()&&d.shiftKey&&s!==Fa.Vertical&&(h=d.deltaY*p,y=0),r.translateBy(n,-(h/f)*o,-(y/f)*o,{internal:!0});const k=Jm(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c==null||c(d,k),e.panScrollTimeout=setTimeout(()=>{u==null||u(d,k),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l==null||l(d,k))}}function u4({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,s){const o=r.type==="wheel",a=!t&&o&&!r.ctrlKey,l=Zl(r,e);if(r.ctrlKey&&o&&l&&r.preventDefault(),a||l)return null;r.preventDefault(),n.call(this,r,s)}}function d4({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{var o,a,l;if((o=r.sourceEvent)!=null&&o.internal)return;const s=Jm(r.transform);e.mouseButton=((a=r.sourceEvent)==null?void 0:a.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=s,((l=r.sourceEvent)==null?void 0:l.type)==="mousedown"&&t(!0),n&&(n==null||n(r.sourceEvent,s))}}function f4({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:s}){return o=>{var a,l;e.usedRightMouseButton=!!(n&&RI(t,e.mouseButton??0)),(a=o.sourceEvent)!=null&&a.sync||r([o.transform.x,o.transform.y,o.transform.k]),s&&!((l=o.sourceEvent)!=null&&l.internal)&&(s==null||s(o.sourceEvent,Jm(o.transform)))}}function p4({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:s,onPaneContextMenu:o}){return a=>{var l;if(!((l=a.sourceEvent)!=null&&l.internal)&&(e.isZoomingOrPanning=!1,o&&RI(t,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),s)){const c=Jm(a.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(a.sourceEvent,c)},n?150:0)}}}function h4({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:s,zoomOnDoubleClick:o,userSelectionActive:a,noWheelClassName:l,noPanClassName:c,lib:u,connectionInProgress:d}){return f=>{var b;const p=e||t,h=n&&f.ctrlKey,y=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(Zl(f,`${u}-flow__node`)||Zl(f,`${u}-flow__edge`)))return!0;if(!r&&!p&&!s&&!o&&!n||a||d&&!y||Zl(f,l)&&y||Zl(f,c)&&(!y||s&&y&&!e)||!n&&f.ctrlKey&&y)return!1;if(!n&&f.type==="touchstart"&&((b=f.touches)==null?void 0:b.length)>1)return f.preventDefault(),!1;if(!p&&!s&&!h&&y||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const k=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||y)&&k}}function m4({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:s,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:l,onDraggingChange:c}){const u={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},d=e.getBoundingClientRect(),f=iI().scaleExtent([t,n]).translateExtent(r),p=as(e).call(f);v({x:s.x,y:s.y,zoom:_c(s.zoom,t,n)},[[0,0],[d.width,d.height]],r);const h=p.on("wheel.zoom"),y=p.on("dblclick.zoom");f.wheelDelta(TI);function k(L,F){return p?new Promise(O=>{f==null||f.interpolate((F==null?void 0:F.interpolate)==="linear"?id:oh).transform(Dy(p,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>O(!0)),L)}):Promise.resolve(!1)}function b({noWheelClassName:L,noPanClassName:F,onPaneContextMenu:O,userSelectionActive:M,panOnScroll:K,panOnDrag:H,panOnScrollMode:D,panOnScrollSpeed:T,preventScrolling:W,zoomOnPinch:E,zoomOnScroll:Q,zoomOnDoubleClick:V,zoomActivationKeyPressed:B,lib:se,onTransformChange:ue,connectionInProgress:G,paneClickDistance:ee,selectionOnDrag:te}){M&&!u.isZoomingOrPanning&&g();const ne=K&&!B&&!M;f.clickDistance(te?1/0:!Js(ee)||ee<0?0:ee);const Z=ne?c4({zoomPanValues:u,noWheelClassName:L,d3Selection:p,d3Zoom:f,panOnScrollMode:D,panOnScrollSpeed:T,zoomOnPinch:E,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:l}):u4({noWheelClassName:L,preventScrolling:W,d3ZoomHandler:h});if(p.on("wheel.zoom",Z,{passive:!1}),!M){const de=d4({zoomPanValues:u,onDraggingChange:c,onPanZoomStart:a});f.on("start",de);const me=f4({zoomPanValues:u,panOnDrag:H,onPaneContextMenu:!!O,onPanZoom:o,onTransformChange:ue});f.on("zoom",me);const $e=p4({zoomPanValues:u,panOnDrag:H,panOnScroll:K,onPaneContextMenu:O,onPanZoomEnd:l,onDraggingChange:c});f.on("end",$e)}const ce=h4({zoomActivationKeyPressed:B,panOnDrag:H,zoomOnScroll:Q,panOnScroll:K,zoomOnDoubleClick:V,zoomOnPinch:E,userSelectionActive:M,noPanClassName:F,noWheelClassName:L,lib:se,connectionInProgress:G});f.filter(ce),V?p.on("dblclick.zoom",y):p.on("dblclick.zoom",null)}function g(){f.on("zoom",null)}async function v(L,F,O){const M=Oy(L),K=f==null?void 0:f.constrain()(M,F,O);return K&&await k(K),new Promise(H=>H(K))}async function w(L,F){const O=Oy(L);return await k(O,F),new Promise(M=>M(O))}function N(L){if(p){const F=Oy(L),O=p.property("__zoom");(O.k!==L.zoom||O.x!==L.x||O.y!==L.y)&&(f==null||f.transform(p,F,null,{sync:!0}))}}function j(){const L=p?sI(p.node()):{x:0,y:0,k:1};return{x:L.x,y:L.y,zoom:L.k}}function C(L,F){return p?new Promise(O=>{f==null||f.interpolate((F==null?void 0:F.interpolate)==="linear"?id:oh).scaleTo(Dy(p,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>O(!0)),L)}):Promise.resolve(!1)}function P(L,F){return p?new Promise(O=>{f==null||f.interpolate((F==null?void 0:F.interpolate)==="linear"?id:oh).scaleBy(Dy(p,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>O(!0)),L)}):Promise.resolve(!1)}function I(L){f==null||f.scaleExtent(L)}function z(L){f==null||f.translateExtent(L)}function $(L){const F=!Js(L)||L<0?0:L;f==null||f.clickDistance(F)}return{update:b,destroy:g,setViewport:w,setViewportConstrained:v,getViewport:j,scaleTo:C,scaleBy:P,setScaleExtent:I,setTranslateExtent:z,syncViewport:N,setClickDistance:$}}var Pc;(function(e){e.Line="line",e.Handle="handle"})(Pc||(Pc={}));function g4({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:s,affectsY:o}){const a=e-t,l=n-r,c=[a>0?1:a<0?-1:0,l>0?1:l<0?-1:0];return a&&s&&(c[0]=c[0]*-1),l&&o&&(c[1]=c[1]*-1),c}function Rj(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:s}}function Co(e,t){return Math.max(0,t-e)}function _o(e,t){return Math.max(0,e-t)}function Np(e,t,n){return Math.max(0,t-e,e-n)}function Tj(e,t){return e?!t:t}function y4(e,t,n,r,s,o,a,l){let{affectsX:c,affectsY:u}=t;const{isHorizontal:d,isVertical:f}=t,p=d&&f,{xSnapped:h,ySnapped:y}=n,{minWidth:k,maxWidth:b,minHeight:g,maxHeight:v}=r,{x:w,y:N,width:j,height:C,aspectRatio:P}=e;let I=Math.floor(d?h-e.pointerX:0),z=Math.floor(f?y-e.pointerY:0);const $=j+(c?-I:I),L=C+(u?-z:z),F=-o[0]*j,O=-o[1]*C;let M=Np($,k,b),K=Np(L,g,v);if(a){let T=0,W=0;c&&I<0?T=Co(w+I+F,a[0][0]):!c&&I>0&&(T=_o(w+$+F,a[1][0])),u&&z<0?W=Co(N+z+O,a[0][1]):!u&&z>0&&(W=_o(N+L+O,a[1][1])),M=Math.max(M,T),K=Math.max(K,W)}if(l){let T=0,W=0;c&&I>0?T=_o(w+I,l[0][0]):!c&&I<0&&(T=Co(w+$,l[1][0])),u&&z>0?W=_o(N+z,l[0][1]):!u&&z<0&&(W=Co(N+L,l[1][1])),M=Math.max(M,T),K=Math.max(K,W)}if(s){if(d){const T=Np($/P,g,v)*P;if(M=Math.max(M,T),a){let W=0;!c&&!u||c&&!u&&p?W=_o(N+O+$/P,a[1][1])*P:W=Co(N+O+(c?I:-I)/P,a[0][1])*P,M=Math.max(M,W)}if(l){let W=0;!c&&!u||c&&!u&&p?W=Co(N+$/P,l[1][1])*P:W=_o(N+(c?I:-I)/P,l[0][1])*P,M=Math.max(M,W)}}if(f){const T=Np(L*P,k,b)/P;if(K=Math.max(K,T),a){let W=0;!c&&!u||u&&!c&&p?W=_o(w+L*P+F,a[1][0])/P:W=Co(w+(u?z:-z)*P+F,a[0][0])/P,K=Math.max(K,W)}if(l){let W=0;!c&&!u||u&&!c&&p?W=Co(w+L*P,l[1][0])/P:W=_o(w+(u?z:-z)*P,l[0][0])/P,K=Math.max(K,W)}}}z=z+(z<0?K:-K),I=I+(I<0?M:-M),s&&(p?$>L*P?z=(Tj(c,u)?-I:I)/P:I=(Tj(c,u)?-z:z)*P:d?(z=I/P,u=c):(I=z*P,c=u));const H=c?w+I:w,D=u?N+z:N;return{width:j+(c?-I:I),height:C+(u?-z:z),x:o[0]*I*(c?-1:1)+H,y:o[1]*z*(u?-1:1)+D}}const MI={width:0,height:0,x:0,y:0},w4={...MI,pointerX:0,pointerY:0,aspectRatio:1};function x4(e){return[[0,0],[e.measured.width,e.measured.height]]}function b4(e,t,n){const r=t.position.x+e.position.x,s=t.position.y+e.position.y,o=e.measured.width??0,a=e.measured.height??0,l=n[0]*o,c=n[1]*a;return[[r-l,s-c],[r+o-l,s+a-c]]}function k4({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:s}){const o=as(e);let a={controlDirection:Rj("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:u,boundaries:d,keepAspectRatio:f,resizeDirection:p,onResizeStart:h,onResize:y,onResizeEnd:k,shouldResize:b}){let g={...MI},v={...w4};a={boundaries:d,resizeDirection:p,keepAspectRatio:f,controlDirection:Rj(u)};let w,N=null,j=[],C,P,I,z=!1;const $=VP().on("start",L=>{const{nodeLookup:F,transform:O,snapGrid:M,snapToGrid:K,nodeOrigin:H,paneDomNode:D}=n();if(w=F.get(t),!w)return;N=(D==null?void 0:D.getBoundingClientRect())??null;const{xSnapped:T,ySnapped:W}=od(L.sourceEvent,{transform:O,snapGrid:M,snapToGrid:K,containerBounds:N});g={width:w.measured.width??0,height:w.measured.height??0,x:w.position.x??0,y:w.position.y??0},v={...g,pointerX:T,pointerY:W,aspectRatio:g.width/g.height},C=void 0,w.parentId&&(w.extent==="parent"||w.expandParent)&&(C=F.get(w.parentId),P=C&&w.extent==="parent"?x4(C):void 0),j=[],I=void 0;for(const[E,Q]of F)if(Q.parentId===t&&(j.push({id:E,position:{...Q.position},extent:Q.extent}),Q.extent==="parent"||Q.expandParent)){const V=b4(Q,w,Q.origin??H);I?I=[[Math.min(V[0][0],I[0][0]),Math.min(V[0][1],I[0][1])],[Math.max(V[1][0],I[1][0]),Math.max(V[1][1],I[1][1])]]:I=V}h==null||h(L,{...g})}).on("drag",L=>{const{transform:F,snapGrid:O,snapToGrid:M,nodeOrigin:K}=n(),H=od(L.sourceEvent,{transform:F,snapGrid:O,snapToGrid:M,containerBounds:N}),D=[];if(!w)return;const{x:T,y:W,width:E,height:Q}=g,V={},B=w.origin??K,{width:se,height:ue,x:G,y:ee}=y4(v,a.controlDirection,H,a.boundaries,a.keepAspectRatio,B,P,I),te=se!==E,ne=ue!==Q,Z=G!==T&&te,ce=ee!==W&&ne;if(!Z&&!ce&&!te&&!ne)return;if((Z||ce||B[0]===1||B[1]===1)&&(V.x=Z?G:g.x,V.y=ce?ee:g.y,g.x=V.x,g.y=V.y,j.length>0)){const Ce=G-T,_e=ee-W;for(const Be of j)Be.position={x:Be.position.x-Ce+B[0]*(se-E),y:Be.position.y-_e+B[1]*(ue-Q)},D.push(Be)}if((te||ne)&&(V.width=te&&(!a.resizeDirection||a.resizeDirection==="horizontal")?se:g.width,V.height=ne&&(!a.resizeDirection||a.resizeDirection==="vertical")?ue:g.height,g.width=V.width,g.height=V.height),C&&w.expandParent){const Ce=B[0]*(V.width??0);V.x&&V.x<Ce&&(g.x=Ce,v.x=v.x-(V.x-Ce));const _e=B[1]*(V.height??0);V.y&&V.y<_e&&(g.y=_e,v.y=v.y-(V.y-_e))}const de=g4({width:g.width,prevWidth:E,height:g.height,prevHeight:Q,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),me={...g,direction:de};(b==null?void 0:b(L,me))!==!1&&(z=!0,y==null||y(L,me),r(V,D))}).on("end",L=>{z&&(k==null||k(L,{...g}),s==null||s({...g}),z=!1)});o.call($)}function c(){o.on(".drag",null)}return{update:l,destroy:c}}var $I={exports:{}},LI={},OI={exports:{}},DI={};/**
44
+ ${n("project:fileTruncated")}`:""]})]}):i.jsx("p",{children:n("project:noNodeFiles")})]}):i.jsxs("div",{className:"af-resource-detail-section af-resource-detail-section--plain",children:[i.jsx("h4",{children:n("project:nodeUsage")}),Array.isArray(tt==null?void 0:tt.usage)&&tt.usage.length>0?i.jsx("div",{className:"af-node-usage-list",children:tt.usage.map(q=>i.jsxs("div",{className:"af-node-usage-item",children:[i.jsx("strong",{children:q.flowId}),i.jsxs("span",{children:[q.flowSource,q.archived?` · ${n("project:archived")}`:""]}),i.jsx("em",{children:q.instances.map(he=>he.label||he.instanceId).join(", ")})]},`${q.flowSource}:${q.flowId}:${q.archived?"a":""}`))}):i.jsx("p",{children:n("project:noNodeUsage")})]})]}):le&&Wt?(()=>{const q=VF(Wt);return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-resource-detail-head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"schema"}),i.jsxs("div",{children:[i.jsx("h3",{children:Wt.displayName||Wt.name||Wt.id}),i.jsx("p",{children:Wt.id})]})]}),i.jsx("p",{className:"af-resource-detail-desc",children:Wt.description||n("project:noDescription")}),i.jsxs("dl",{className:"af-resource-detail-kv",children:[i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailVersion")}),i.jsx("dd",{children:Wt.version||"1.0.0"})]}),i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailPath")}),i.jsx("dd",{children:QN(Wt)})]}),i.jsxs("div",{children:[i.jsx("dt",{children:n("project:flowSnippetScale")}),i.jsx("dd",{children:n("project:flowSnippetNodes",{nodes:Number.isFinite(Number(Wt.nodeCount))?Number(Wt.nodeCount):q.nodes.length,edges:Number.isFinite(Number(Wt.edgeCount))?Number(Wt.edgeCount):q.edges.length})})]})]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:resourceMeaning")}),i.jsx("p",{children:n("project:myFlowsMeaning")})]}),i.jsxs("div",{className:"af-resource-detail-section af-resource-danger-zone",children:[i.jsx("h4",{children:n("project:myFlowManagement")}),i.jsx("p",{children:n("project:deleteMyFlowHint")}),i.jsxs("button",{type:"button",className:"af-btn-secondary af-btn-danger",disabled:Qt===jo(Wt),onClick:()=>cn(Wt),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"}),Qt===jo(Wt)?n("project:deletingMyFlow"):n("project:deleteMyFlow")]}),yn?i.jsx("p",{className:"af-resource-action-message",children:yn}):null]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:flowSnippetPreview")}),q.diagram.nodes.length>0?i.jsx("div",{className:"af-flow-snippet-map",children:i.jsxs("svg",{viewBox:q.diagram.viewBox,role:"img","aria-label":n("project:flowSnippetPreview"),children:[i.jsx("defs",{children:i.jsx("marker",{id:"af-flow-snippet-arrow",markerWidth:"8",markerHeight:"8",refX:"7",refY:"4",orient:"auto",markerUnits:"strokeWidth",children:i.jsx("path",{d:"M 0 0 L 8 4 L 0 8 z"})})}),i.jsx("g",{className:"af-flow-snippet-map__edges",children:q.diagram.edges.map(he=>i.jsxs("g",{children:[i.jsx("path",{d:he.path}),he.label?i.jsx("text",{x:he.labelX,y:he.labelY-5,textAnchor:"middle",children:Iy(he.label,18)}):null]},he.key))}),i.jsx("g",{className:"af-flow-snippet-map__nodes",children:q.diagram.nodes.map((he,Oe)=>i.jsxs("g",{transform:`translate(${he.x} ${he.y})`,children:[i.jsx("rect",{width:he.width,height:he.height,rx:"10"}),i.jsx("circle",{cx:"19",cy:he.height/2,r:"12"}),i.jsx("text",{className:"af-flow-snippet-map__node-index",x:"19",y:he.height/2+4,textAnchor:"middle",children:Oe+1}),i.jsx("text",{className:"af-flow-snippet-map__node-title",x:"40",y:he.height/2-3,children:Iy(he.title)}),i.jsx("text",{className:"af-flow-snippet-map__node-meta",x:"40",y:he.height/2+16,children:Iy(he.meta||he.id,20)})]},he.id))})]})}):i.jsx("p",{className:"af-resource-detail-desc",children:n("project:noFlowSnippetPreview")}),i.jsxs("details",{className:"af-flow-snippet-json",children:[i.jsx("summary",{children:n("project:flowSnippetJson")}),i.jsx("pre",{className:"af-resource-skill-preview",children:JSON.stringify(Wt.snippet||{},null,2)})]})]})]})})():a==="skills"&&nn?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-resource-detail-head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"extension"}),i.jsxs("div",{children:[i.jsx("h3",{children:nn.name||nn.id}),i.jsx("p",{children:nn.sourceLabel||nn.source})]})]}),i.jsx("p",{className:"af-resource-detail-desc",children:nn.description||n("project:noDescription")}),i.jsxs("dl",{className:"af-resource-detail-kv",children:[i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailSource")}),i.jsx("dd",{children:nn.sourceLabel||nn.source})]}),i.jsxs("div",{children:[i.jsx("dt",{children:n("project:detailPath")}),i.jsx("dd",{children:nn.path||nn.key})]})]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:"Collections"}),b.length===0?i.jsx("p",{children:"暂无 collection。可在左侧新建后再添加。"}):i.jsx("div",{className:"af-skill-detail-collections",children:b.map(q=>{const he=Hn(nn),Oe=it.get(q.id)||new Set,Ee=Oe.has(he);return i.jsxs("label",{className:"af-composer-skill-option af-skill-detail-collection-option",children:[i.jsx("input",{type:"checkbox",checked:Ee,disabled:N||!o,onChange:et=>gs(q.id,he,et.target.checked)}),i.jsxs("span",{className:"af-composer-skill-option-main",children:[i.jsx("span",{className:"af-composer-skill-option-title",children:q.name}),i.jsxs("span",{className:"af-composer-skill-option-desc",children:[Oe.size," skills"]})]})]},q.id)})})]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:resourceMeaning")}),i.jsx("p",{children:n("project:skillsMeaning")})]}),i.jsxs("div",{className:"af-resource-detail-section",children:[i.jsx("h4",{children:n("project:skillPreview")}),i.jsx("pre",{className:"af-resource-skill-preview",children:_e===Hn(nn)?n("project:loadingResources"):(kr==null?void 0:kr.body)||(kr==null?void 0:kr.content)||n("project:skillPreviewEmpty")})]})]}):i.jsx("p",{className:"af-activity-empty",children:n("project:selectResource")})}):i.jsxs("aside",{id:"af-recent-activity-panel",className:"af-activity"+(se?"":" af-activity--hidden"),"aria-hidden":!se,"aria-label":n("project:recentActivity"),children:[i.jsxs("h2",{className:"af-activity-title",children:[i.jsx("span",{className:"af-activity-bullet"}),n("project:recentActivity")]}),i.jsx("div",{className:"af-activity-list",children:Pr.length===0?i.jsx("p",{className:"af-activity-empty",children:rr.length===0?n("project:noRecentActivity"):n("project:noMatchRecent")}):Pr.map(q=>{const he=G===ZN(q);return i.jsxs("button",{type:"button",className:"af-activity-row af-activity-row--action"+(he?" af-activity-row--active":""),"aria-current":he?"page":void 0,onClick:()=>mo(q),children:[i.jsxs("div",{className:"af-activity-row-top",children:[i.jsx("h4",{className:"af-activity-name",children:i.jsx(Bn,{query:V,children:q.flowId})}),i.jsx("span",{className:"af-activity-time",children:GN(q.at,n)})]}),i.jsxs("div",{className:"af-activity-meta",children:[i.jsx("span",{className:AF(q.kind),children:q.kind==="executed"?"play_arrow":"visibility"}),i.jsxs("p",{className:"af-activity-text",children:[q.kind==="executed"?n("project:recentRun"):n("project:recentOpen")," · ",GN(q.at,n)]})]})]},`${q.kind}-${q.flowId}-${q.flowSource}-${q.at}`)})})]})]}),i.jsx(dF,{open:H,onClose:()=>D(!1),onCreated:async q=>{D(!1),await wn();const he=q.source??"user";r(gp({id:q.id,source:he},"workspace"))}}),T?i.jsx(cF,{file:T,onClose:()=>W(null),onImported:async q=>{W(null),await wn();const he=q.source??"user";r(gp({id:q.id,source:he},"workspace"))}},`${T.name}-${T.size}-${T.lastModified}`):null]})}function Jn(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,r;n<e.length;n++)(r=Jn(e[n]))!==""&&(t+=(t&&" ")+r);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var KF={value:()=>{}};function Wm(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new ih(n)}function ih(e){this._=e}function qF(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",s=n.indexOf(".");if(s>=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}ih.prototype=Wm.prototype={constructor:ih,on:function(e,t){var n=this._,r=qF(e+"",n),s,o=-1,a=r.length;if(arguments.length<2){for(;++o<a;)if((s=(e=r[o]).type)&&(s=UF(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<a;)if(s=(e=r[o]).type)n[s]=nj(n[s],e.name,t);else if(t==null)for(s in n)n[s]=nj(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new ih(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),r=0,s,o;r<s;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],r=0,s=o.length;r<s;++r)o[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],s=0,o=r.length;s<o;++s)r[s].value.apply(t,n)}};function UF(e,t){for(var n=0,r=e.length,s;n<r;++n)if((s=e[n]).name===t)return s.value}function nj(e,t,n){for(var r=0,s=e.length;r<s;++r)if(e[r].name===t){e[r]=KF,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var Cx="http://www.w3.org/1999/xhtml";const rj={svg:"http://www.w3.org/2000/svg",xhtml:Cx,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Vm(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),rj.hasOwnProperty(t)?{space:rj[t],local:e}:e}function YF(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===Cx&&t.documentElement.namespaceURI===Cx?t.createElement(e):t.createElementNS(n,e)}}function GF(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function PP(e){var t=Vm(e);return(t.local?GF:YF)(t)}function JF(){}function vk(e){return e==null?JF:function(){return this.querySelector(e)}}function XF(e){typeof e!="function"&&(e=vk(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var o=t[s],a=o.length,l=r[s]=new Array(a),c,u,d=0;d<a;++d)(c=o[d])&&(u=e.call(c,c.__data__,d,o))&&("__data__"in c&&(u.__data__=c.__data__),l[d]=u);return new ps(r,this._parents)}function QF(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function ZF(){return[]}function IP(e){return e==null?ZF:function(){return this.querySelectorAll(e)}}function ez(e){return function(){return QF(e.apply(this,arguments))}}function tz(e){typeof e=="function"?e=ez(e):e=IP(e);for(var t=this._groups,n=t.length,r=[],s=[],o=0;o<n;++o)for(var a=t[o],l=a.length,c,u=0;u<l;++u)(c=a[u])&&(r.push(e.call(c,c.__data__,u,a)),s.push(c));return new ps(r,s)}function RP(e){return function(){return this.matches(e)}}function TP(e){return function(t){return t.matches(e)}}var nz=Array.prototype.find;function rz(e){return function(){return nz.call(this.children,e)}}function sz(){return this.firstElementChild}function iz(e){return this.select(e==null?sz:rz(typeof e=="function"?e:TP(e)))}var oz=Array.prototype.filter;function az(){return Array.from(this.children)}function lz(e){return function(){return oz.call(this.children,e)}}function cz(e){return this.selectAll(e==null?az:lz(typeof e=="function"?e:TP(e)))}function uz(e){typeof e!="function"&&(e=RP(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var o=t[s],a=o.length,l=r[s]=[],c,u=0;u<a;++u)(c=o[u])&&e.call(c,c.__data__,u,o)&&l.push(c);return new ps(r,this._parents)}function MP(e){return new Array(e.length)}function dz(){return new ps(this._enter||this._groups.map(MP),this._parents)}function Wh(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Wh.prototype={constructor:Wh,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function fz(e){return function(){return e}}function pz(e,t,n,r,s,o){for(var a=0,l,c=t.length,u=o.length;a<u;++a)(l=t[a])?(l.__data__=o[a],r[a]=l):n[a]=new Wh(e,o[a]);for(;a<c;++a)(l=t[a])&&(s[a]=l)}function hz(e,t,n,r,s,o,a){var l,c,u=new Map,d=t.length,f=o.length,p=new Array(d),h;for(l=0;l<d;++l)(c=t[l])&&(p[l]=h=a.call(c,c.__data__,l,t)+"",u.has(h)?s[l]=c:u.set(h,c));for(l=0;l<f;++l)h=a.call(e,o[l],l,o)+"",(c=u.get(h))?(r[l]=c,c.__data__=o[l],u.delete(h)):n[l]=new Wh(e,o[l]);for(l=0;l<d;++l)(c=t[l])&&u.get(p[l])===c&&(s[l]=c)}function mz(e){return e.__data__}function gz(e,t){if(!arguments.length)return Array.from(this,mz);var n=t?hz:pz,r=this._parents,s=this._groups;typeof e!="function"&&(e=fz(e));for(var o=s.length,a=new Array(o),l=new Array(o),c=new Array(o),u=0;u<o;++u){var d=r[u],f=s[u],p=f.length,h=yz(e.call(d,d&&d.__data__,u,r)),y=h.length,k=l[u]=new Array(y),b=a[u]=new Array(y),g=c[u]=new Array(p);n(d,f,k,b,g,h,t);for(var v=0,w=0,N,j;v<y;++v)if(N=k[v]){for(v>=w&&(w=v+1);!(j=b[w])&&++w<y;);N._next=j||null}}return a=new ps(a,r),a._enter=l,a._exit=c,a}function yz(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function wz(){return new ps(this._exit||this._groups.map(MP),this._parents)}function xz(e,t,n){var r=this.enter(),s=this,o=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?o.remove():n(o),r&&s?r.merge(s).order():s}function bz(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,s=n.length,o=r.length,a=Math.min(s,o),l=new Array(s),c=0;c<a;++c)for(var u=n[c],d=r[c],f=u.length,p=l[c]=new Array(f),h,y=0;y<f;++y)(h=u[y]||d[y])&&(p[y]=h);for(;c<s;++c)l[c]=n[c];return new ps(l,this._parents)}function kz(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],s=r.length-1,o=r[s],a;--s>=0;)(a=r[s])&&(o&&a.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(a,o),o=a);return this}function vz(e){e||(e=Sz);function t(f,p){return f&&p?e(f.__data__,p.__data__):!f-!p}for(var n=this._groups,r=n.length,s=new Array(r),o=0;o<r;++o){for(var a=n[o],l=a.length,c=s[o]=new Array(l),u,d=0;d<l;++d)(u=a[d])&&(c[d]=u);c.sort(t)}return new ps(s,this._parents).order()}function Sz(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Nz(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function jz(){return Array.from(this)}function Cz(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,o=r.length;s<o;++s){var a=r[s];if(a)return a}return null}function _z(){let e=0;for(const t of this)++e;return e}function Ez(){return!this.node()}function Az(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var s=t[n],o=0,a=s.length,l;o<a;++o)(l=s[o])&&e.call(l,l.__data__,o,s);return this}function Pz(e){return function(){this.removeAttribute(e)}}function Iz(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Rz(e,t){return function(){this.setAttribute(e,t)}}function Tz(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Mz(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function $z(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Lz(e,t){var n=Vm(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?Iz:Pz:typeof t=="function"?n.local?$z:Mz:n.local?Tz:Rz)(n,t))}function $P(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Oz(e){return function(){this.style.removeProperty(e)}}function Dz(e,t,n){return function(){this.style.setProperty(e,t,n)}}function Fz(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function zz(e,t,n){return arguments.length>1?this.each((t==null?Oz:typeof t=="function"?Fz:Dz)(e,t,n??"")):Nc(this.node(),e)}function Nc(e,t){return e.style.getPropertyValue(t)||$P(e).getComputedStyle(e,null).getPropertyValue(t)}function Bz(e){return function(){delete this[e]}}function Hz(e,t){return function(){this[e]=t}}function Wz(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function Vz(e,t){return arguments.length>1?this.each((t==null?Bz:typeof t=="function"?Wz:Hz)(e,t)):this.node()[e]}function LP(e){return e.trim().split(/^|\s+/)}function Sk(e){return e.classList||new OP(e)}function OP(e){this._node=e,this._names=LP(e.getAttribute("class")||"")}OP.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function DP(e,t){for(var n=Sk(e),r=-1,s=t.length;++r<s;)n.add(t[r])}function FP(e,t){for(var n=Sk(e),r=-1,s=t.length;++r<s;)n.remove(t[r])}function Kz(e){return function(){DP(this,e)}}function qz(e){return function(){FP(this,e)}}function Uz(e,t){return function(){(t.apply(this,arguments)?DP:FP)(this,e)}}function Yz(e,t){var n=LP(e+"");if(arguments.length<2){for(var r=Sk(this.node()),s=-1,o=n.length;++s<o;)if(!r.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?Uz:t?Kz:qz)(n,t))}function Gz(){this.textContent=""}function Jz(e){return function(){this.textContent=e}}function Xz(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function Qz(e){return arguments.length?this.each(e==null?Gz:(typeof e=="function"?Xz:Jz)(e)):this.node().textContent}function Zz(){this.innerHTML=""}function e3(e){return function(){this.innerHTML=e}}function t3(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function n3(e){return arguments.length?this.each(e==null?Zz:(typeof e=="function"?t3:e3)(e)):this.node().innerHTML}function r3(){this.nextSibling&&this.parentNode.appendChild(this)}function s3(){return this.each(r3)}function i3(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function o3(){return this.each(i3)}function a3(e){var t=typeof e=="function"?e:PP(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function l3(){return null}function c3(e,t){var n=typeof e=="function"?e:PP(e),r=t==null?l3:typeof t=="function"?t:vk(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function u3(){var e=this.parentNode;e&&e.removeChild(this)}function d3(){return this.each(u3)}function f3(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function p3(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function h3(e){return this.select(e?p3:f3)}function m3(e){return arguments.length?this.property("__data__",e):this.node().__data__}function g3(e){return function(t){e.call(this,t,this.__data__)}}function y3(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function w3(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,o;n<s;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++r]=o;++r?t.length=r:delete this.__on}}}function x3(e,t,n){return function(){var r=this.__on,s,o=g3(t);if(r){for(var a=0,l=r.length;a<l;++a)if((s=r[a]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=o,s.options=n),s.value=t;return}}this.addEventListener(e.type,o,n),s={type:e.type,name:e.name,value:t,listener:o,options:n},r?r.push(s):this.__on=[s]}}function b3(e,t,n){var r=y3(e+""),s,o=r.length,a;if(arguments.length<2){var l=this.node().__on;if(l){for(var c=0,u=l.length,d;c<u;++c)for(s=0,d=l[c];s<o;++s)if((a=r[s]).type===d.type&&a.name===d.name)return d.value}return}for(l=t?x3:w3,s=0;s<o;++s)this.each(l(r[s],t,n));return this}function zP(e,t,n){var r=$P(e),s=r.CustomEvent;typeof s=="function"?s=new s(t,n):(s=r.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function k3(e,t){return function(){return zP(this,e,t)}}function v3(e,t){return function(){return zP(this,e,t.apply(this,arguments))}}function S3(e,t){return this.each((typeof t=="function"?v3:k3)(e,t))}function*N3(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,o=r.length,a;s<o;++s)(a=r[s])&&(yield a)}var BP=[null];function ps(e,t){this._groups=e,this._parents=t}function lf(){return new ps([[document.documentElement]],BP)}function j3(){return this}ps.prototype=lf.prototype={constructor:ps,select:XF,selectAll:tz,selectChild:iz,selectChildren:cz,filter:uz,data:gz,enter:dz,exit:wz,join:xz,merge:bz,selection:j3,order:kz,sort:vz,call:Nz,nodes:jz,node:Cz,size:_z,empty:Ez,each:Az,attr:Lz,style:zz,property:Vz,classed:Yz,text:Qz,html:n3,raise:s3,lower:o3,append:a3,insert:c3,remove:d3,clone:h3,datum:m3,on:b3,dispatch:S3,[Symbol.iterator]:N3};function as(e){return typeof e=="string"?new ps([[document.querySelector(e)]],[document.documentElement]):new ps([[e]],BP)}function C3(e){let t;for(;t=e.sourceEvent;)e=t;return e}function qs(e,t){if(e=C3(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const _3={passive:!1},Rd={capture:!0,passive:!1};function Ry(e){e.stopImmediatePropagation()}function cc(e){e.preventDefault(),e.stopImmediatePropagation()}function HP(e){var t=e.document.documentElement,n=as(e).on("dragstart.drag",cc,Rd);"onselectstart"in t?n.on("selectstart.drag",cc,Rd):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function WP(e,t){var n=e.document.documentElement,r=as(e).on("dragstart.drag",null);t&&(r.on("click.drag",cc,Rd),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const wp=e=>()=>e;function _x(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:o,x:a,y:l,dx:c,dy:u,dispatch:d}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:a,enumerable:!0,configurable:!0},y:{value:l,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:d}})}_x.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function E3(e){return!e.ctrlKey&&!e.button}function A3(){return this.parentNode}function P3(e,t){return t??{x:e.x,y:e.y}}function I3(){return navigator.maxTouchPoints||"ontouchstart"in this}function VP(){var e=E3,t=A3,n=P3,r=I3,s={},o=Wm("start","drag","end"),a=0,l,c,u,d,f=0;function p(N){N.on("mousedown.drag",h).filter(r).on("touchstart.drag",b).on("touchmove.drag",g,_3).on("touchend.drag touchcancel.drag",v).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function h(N,j){if(!(d||!e.call(this,N,j))){var C=w(this,t.call(this,N,j),N,j,"mouse");C&&(as(N.view).on("mousemove.drag",y,Rd).on("mouseup.drag",k,Rd),HP(N.view),Ry(N),u=!1,l=N.clientX,c=N.clientY,C("start",N))}}function y(N){if(cc(N),!u){var j=N.clientX-l,C=N.clientY-c;u=j*j+C*C>f}s.mouse("drag",N)}function k(N){as(N.view).on("mousemove.drag mouseup.drag",null),WP(N.view,u),cc(N),s.mouse("end",N)}function b(N,j){if(e.call(this,N,j)){var C=N.changedTouches,P=t.call(this,N,j),I=C.length,z,$;for(z=0;z<I;++z)($=w(this,P,N,j,C[z].identifier,C[z]))&&(Ry(N),$("start",N,C[z]))}}function g(N){var j=N.changedTouches,C=j.length,P,I;for(P=0;P<C;++P)(I=s[j[P].identifier])&&(cc(N),I("drag",N,j[P]))}function v(N){var j=N.changedTouches,C=j.length,P,I;for(d&&clearTimeout(d),d=setTimeout(function(){d=null},500),P=0;P<C;++P)(I=s[j[P].identifier])&&(Ry(N),I("end",N,j[P]))}function w(N,j,C,P,I,z){var $=o.copy(),L=qs(z||C,j),F,O,M;if((M=n.call(N,new _x("beforestart",{sourceEvent:C,target:p,identifier:I,active:a,x:L[0],y:L[1],dx:0,dy:0,dispatch:$}),P))!=null)return F=M.x-L[0]||0,O=M.y-L[1]||0,function K(H,D,T){var W=L,E;switch(H){case"start":s[I]=K,E=a++;break;case"end":delete s[I],--a;case"drag":L=qs(T||D,j),E=a;break}$.call(H,N,new _x(H,{sourceEvent:D,subject:M,target:p,identifier:I,active:E,x:L[0]+F,y:L[1]+O,dx:L[0]-W[0],dy:L[1]-W[1],dispatch:$}),P)}}return p.filter=function(N){return arguments.length?(e=typeof N=="function"?N:wp(!!N),p):e},p.container=function(N){return arguments.length?(t=typeof N=="function"?N:wp(N),p):t},p.subject=function(N){return arguments.length?(n=typeof N=="function"?N:wp(N),p):n},p.touchable=function(N){return arguments.length?(r=typeof N=="function"?N:wp(!!N),p):r},p.on=function(){var N=o.on.apply(o,arguments);return N===o?p:N},p.clickDistance=function(N){return arguments.length?(f=(N=+N)*N,p):Math.sqrt(f)},p}function Nk(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function KP(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function cf(){}var Td=.7,Vh=1/Td,uc="\\s*([+-]?\\d+)\\s*",Md="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ci="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",R3=/^#([0-9a-f]{3,8})$/,T3=new RegExp(`^rgb\\(${uc},${uc},${uc}\\)$`),M3=new RegExp(`^rgb\\(${Ci},${Ci},${Ci}\\)$`),$3=new RegExp(`^rgba\\(${uc},${uc},${uc},${Md}\\)$`),L3=new RegExp(`^rgba\\(${Ci},${Ci},${Ci},${Md}\\)$`),O3=new RegExp(`^hsl\\(${Md},${Ci},${Ci}\\)$`),D3=new RegExp(`^hsla\\(${Md},${Ci},${Ci},${Md}\\)$`),sj={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Nk(cf,Ua,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:ij,formatHex:ij,formatHex8:F3,formatHsl:z3,formatRgb:oj,toString:oj});function ij(){return this.rgb().formatHex()}function F3(){return this.rgb().formatHex8()}function z3(){return qP(this).formatHsl()}function oj(){return this.rgb().formatRgb()}function Ua(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=R3.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?aj(t):n===3?new Yr(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?xp(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?xp(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=T3.exec(e))?new Yr(t[1],t[2],t[3],1):(t=M3.exec(e))?new Yr(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=$3.exec(e))?xp(t[1],t[2],t[3],t[4]):(t=L3.exec(e))?xp(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=O3.exec(e))?uj(t[1],t[2]/100,t[3]/100,1):(t=D3.exec(e))?uj(t[1],t[2]/100,t[3]/100,t[4]):sj.hasOwnProperty(e)?aj(sj[e]):e==="transparent"?new Yr(NaN,NaN,NaN,0):null}function aj(e){return new Yr(e>>16&255,e>>8&255,e&255,1)}function xp(e,t,n,r){return r<=0&&(e=t=n=NaN),new Yr(e,t,n,r)}function B3(e){return e instanceof cf||(e=Ua(e)),e?(e=e.rgb(),new Yr(e.r,e.g,e.b,e.opacity)):new Yr}function Ex(e,t,n,r){return arguments.length===1?B3(e):new Yr(e,t,n,r??1)}function Yr(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Nk(Yr,Ex,KP(cf,{brighter(e){return e=e==null?Vh:Math.pow(Vh,e),new Yr(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Td:Math.pow(Td,e),new Yr(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new Yr(Da(this.r),Da(this.g),Da(this.b),Kh(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:lj,formatHex:lj,formatHex8:H3,formatRgb:cj,toString:cj}));function lj(){return`#${Ra(this.r)}${Ra(this.g)}${Ra(this.b)}`}function H3(){return`#${Ra(this.r)}${Ra(this.g)}${Ra(this.b)}${Ra((isNaN(this.opacity)?1:this.opacity)*255)}`}function cj(){const e=Kh(this.opacity);return`${e===1?"rgb(":"rgba("}${Da(this.r)}, ${Da(this.g)}, ${Da(this.b)}${e===1?")":`, ${e})`}`}function Kh(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Da(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Ra(e){return e=Da(e),(e<16?"0":"")+e.toString(16)}function uj(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new Gs(e,t,n,r)}function qP(e){if(e instanceof Gs)return new Gs(e.h,e.s,e.l,e.opacity);if(e instanceof cf||(e=Ua(e)),!e)return new Gs;if(e instanceof Gs)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),o=Math.max(t,n,r),a=NaN,l=o-s,c=(o+s)/2;return l?(t===o?a=(n-r)/l+(n<r)*6:n===o?a=(r-t)/l+2:a=(t-n)/l+4,l/=c<.5?o+s:2-o-s,a*=60):l=c>0&&c<1?0:a,new Gs(a,l,c,e.opacity)}function W3(e,t,n,r){return arguments.length===1?qP(e):new Gs(e,t,n,r??1)}function Gs(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Nk(Gs,W3,KP(cf,{brighter(e){return e=e==null?Vh:Math.pow(Vh,e),new Gs(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Td:Math.pow(Td,e),new Gs(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new Yr(Ty(e>=240?e-240:e+120,s,r),Ty(e,s,r),Ty(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new Gs(dj(this.h),bp(this.s),bp(this.l),Kh(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Kh(this.opacity);return`${e===1?"hsl(":"hsla("}${dj(this.h)}, ${bp(this.s)*100}%, ${bp(this.l)*100}%${e===1?")":`, ${e})`}`}}));function dj(e){return e=(e||0)%360,e<0?e+360:e}function bp(e){return Math.max(0,Math.min(1,e||0))}function Ty(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const jk=e=>()=>e;function V3(e,t){return function(n){return e+n*t}}function K3(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function q3(e){return(e=+e)==1?UP:function(t,n){return n-t?K3(t,n,e):jk(isNaN(t)?n:t)}}function UP(e,t){var n=t-e;return n?V3(e,n):jk(isNaN(e)?t:e)}const qh=function e(t){var n=q3(t);function r(s,o){var a=n((s=Ex(s)).r,(o=Ex(o)).r),l=n(s.g,o.g),c=n(s.b,o.b),u=UP(s.opacity,o.opacity);return function(d){return s.r=a(d),s.g=l(d),s.b=c(d),s.opacity=u(d),s+""}}return r.gamma=e,r}(1);function U3(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,r=t.slice(),s;return function(o){for(s=0;s<n;++s)r[s]=e[s]*(1-o)+t[s]*o;return r}}function Y3(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function G3(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,s=new Array(r),o=new Array(n),a;for(a=0;a<r;++a)s[a]=id(e[a],t[a]);for(;a<n;++a)o[a]=t[a];return function(l){for(a=0;a<r;++a)o[a]=s[a](l);return o}}function J3(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function gi(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function X3(e,t){var n={},r={},s;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(s in t)s in e?n[s]=id(e[s],t[s]):r[s]=t[s];return function(o){for(s in n)r[s]=n[s](o);return r}}var Ax=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,My=new RegExp(Ax.source,"g");function Q3(e){return function(){return e}}function Z3(e){return function(t){return e(t)+""}}function YP(e,t){var n=Ax.lastIndex=My.lastIndex=0,r,s,o,a=-1,l=[],c=[];for(e=e+"",t=t+"";(r=Ax.exec(e))&&(s=My.exec(t));)(o=s.index)>n&&(o=t.slice(n,o),l[a]?l[a]+=o:l[++a]=o),(r=r[0])===(s=s[0])?l[a]?l[a]+=s:l[++a]=s:(l[++a]=null,c.push({i:a,x:gi(r,s)})),n=My.lastIndex;return n<t.length&&(o=t.slice(n),l[a]?l[a]+=o:l[++a]=o),l.length<2?c[0]?Z3(c[0].x):Q3(t):(t=c.length,function(u){for(var d=0,f;d<t;++d)l[(f=c[d]).i]=f.x(u);return l.join("")})}function id(e,t){var n=typeof t,r;return t==null||n==="boolean"?jk(t):(n==="number"?gi:n==="string"?(r=Ua(t))?(t=r,qh):YP:t instanceof Ua?qh:t instanceof Date?J3:Y3(t)?U3:Array.isArray(t)?G3:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?X3:gi)(e,t)}var fj=180/Math.PI,Px={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function GP(e,t,n,r,s,o){var a,l,c;return(a=Math.sqrt(e*e+t*t))&&(e/=a,t/=a),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(l=Math.sqrt(n*n+r*r))&&(n/=l,r/=l,c/=l),e*r<t*n&&(e=-e,t=-t,c=-c,a=-a),{translateX:s,translateY:o,rotate:Math.atan2(t,e)*fj,skewX:Math.atan(c)*fj,scaleX:a,scaleY:l}}var kp;function eB(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?Px:GP(t.a,t.b,t.c,t.d,t.e,t.f)}function tB(e){return e==null||(kp||(kp=document.createElementNS("http://www.w3.org/2000/svg","g")),kp.setAttribute("transform",e),!(e=kp.transform.baseVal.consolidate()))?Px:(e=e.matrix,GP(e.a,e.b,e.c,e.d,e.e,e.f))}function JP(e,t,n,r){function s(u){return u.length?u.pop()+" ":""}function o(u,d,f,p,h,y){if(u!==f||d!==p){var k=h.push("translate(",null,t,null,n);y.push({i:k-4,x:gi(u,f)},{i:k-2,x:gi(d,p)})}else(f||p)&&h.push("translate("+f+t+p+n)}function a(u,d,f,p){u!==d?(u-d>180?d+=360:d-u>180&&(u+=360),p.push({i:f.push(s(f)+"rotate(",null,r)-2,x:gi(u,d)})):d&&f.push(s(f)+"rotate("+d+r)}function l(u,d,f,p){u!==d?p.push({i:f.push(s(f)+"skewX(",null,r)-2,x:gi(u,d)}):d&&f.push(s(f)+"skewX("+d+r)}function c(u,d,f,p,h,y){if(u!==f||d!==p){var k=h.push(s(h)+"scale(",null,",",null,")");y.push({i:k-4,x:gi(u,f)},{i:k-2,x:gi(d,p)})}else(f!==1||p!==1)&&h.push(s(h)+"scale("+f+","+p+")")}return function(u,d){var f=[],p=[];return u=e(u),d=e(d),o(u.translateX,u.translateY,d.translateX,d.translateY,f,p),a(u.rotate,d.rotate,f,p),l(u.skewX,d.skewX,f,p),c(u.scaleX,u.scaleY,d.scaleX,d.scaleY,f,p),u=d=null,function(h){for(var y=-1,k=p.length,b;++y<k;)f[(b=p[y]).i]=b.x(h);return f.join("")}}}var nB=JP(eB,"px, ","px)","deg)"),rB=JP(tB,", ",")",")"),sB=1e-12;function pj(e){return((e=Math.exp(e))+1/e)/2}function iB(e){return((e=Math.exp(e))-1/e)/2}function oB(e){return((e=Math.exp(2*e))-1)/(e+1)}const oh=function e(t,n,r){function s(o,a){var l=o[0],c=o[1],u=o[2],d=a[0],f=a[1],p=a[2],h=d-l,y=f-c,k=h*h+y*y,b,g;if(k<sB)g=Math.log(p/u)/t,b=function(P){return[l+P*h,c+P*y,u*Math.exp(t*P*g)]};else{var v=Math.sqrt(k),w=(p*p-u*u+r*k)/(2*u*n*v),N=(p*p-u*u-r*k)/(2*p*n*v),j=Math.log(Math.sqrt(w*w+1)-w),C=Math.log(Math.sqrt(N*N+1)-N);g=(C-j)/t,b=function(P){var I=P*g,z=pj(j),$=u/(n*v)*(z*oB(t*I+j)-iB(j));return[l+$*h,c+$*y,u*z/pj(t*I+j)]}}return b.duration=g*1e3*t/Math.SQRT2,b}return s.rho=function(o){var a=Math.max(.001,+o),l=a*a,c=l*l;return e(a,l,c)},s}(Math.SQRT2,2,4);var jc=0,Bu=0,Cu=0,XP=1e3,Uh,Hu,Yh=0,Ya=0,Km=0,$d=typeof performance=="object"&&performance.now?performance:Date,QP=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Ck(){return Ya||(QP(aB),Ya=$d.now()+Km)}function aB(){Ya=0}function Gh(){this._call=this._time=this._next=null}Gh.prototype=ZP.prototype={constructor:Gh,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Ck():+n)+(t==null?0:+t),!this._next&&Hu!==this&&(Hu?Hu._next=this:Uh=this,Hu=this),this._call=e,this._time=n,Ix()},stop:function(){this._call&&(this._call=null,this._time=1/0,Ix())}};function ZP(e,t,n){var r=new Gh;return r.restart(e,t,n),r}function lB(){Ck(),++jc;for(var e=Uh,t;e;)(t=Ya-e._time)>=0&&e._call.call(void 0,t),e=e._next;--jc}function hj(){Ya=(Yh=$d.now())+Km,jc=Bu=0;try{lB()}finally{jc=0,uB(),Ya=0}}function cB(){var e=$d.now(),t=e-Yh;t>XP&&(Km-=t,Yh=e)}function uB(){for(var e,t=Uh,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Uh=n);Hu=e,Ix(r)}function Ix(e){if(!jc){Bu&&(Bu=clearTimeout(Bu));var t=e-Ya;t>24?(e<1/0&&(Bu=setTimeout(hj,e-$d.now()-Km)),Cu&&(Cu=clearInterval(Cu))):(Cu||(Yh=$d.now(),Cu=setInterval(cB,XP)),jc=1,QP(hj))}}function mj(e,t,n){var r=new Gh;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var dB=Wm("start","end","cancel","interrupt"),fB=[],eI=0,gj=1,Rx=2,ah=3,yj=4,Tx=5,lh=6;function qm(e,t,n,r,s,o){var a=e.__transition;if(!a)e.__transition={};else if(n in a)return;pB(e,n,{name:t,index:r,group:s,on:dB,tween:fB,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:eI})}function _k(e,t){var n=ii(e,t);if(n.state>eI)throw new Error("too late; already scheduled");return n}function Ti(e,t){var n=ii(e,t);if(n.state>ah)throw new Error("too late; already running");return n}function ii(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function pB(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=ZP(o,0,n.time);function o(u){n.state=gj,n.timer.restart(a,n.delay,n.time),n.delay<=u&&a(u-n.delay)}function a(u){var d,f,p,h;if(n.state!==gj)return c();for(d in r)if(h=r[d],h.name===n.name){if(h.state===ah)return mj(a);h.state===yj?(h.state=lh,h.timer.stop(),h.on.call("interrupt",e,e.__data__,h.index,h.group),delete r[d]):+d<t&&(h.state=lh,h.timer.stop(),h.on.call("cancel",e,e.__data__,h.index,h.group),delete r[d])}if(mj(function(){n.state===ah&&(n.state=yj,n.timer.restart(l,n.delay,n.time),l(u))}),n.state=Rx,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Rx){for(n.state=ah,s=new Array(p=n.tween.length),d=0,f=-1;d<p;++d)(h=n.tween[d].value.call(e,e.__data__,n.index,n.group))&&(s[++f]=h);s.length=f+1}}function l(u){for(var d=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(c),n.state=Tx,1),f=-1,p=s.length;++f<p;)s[f].call(e,d);n.state===Tx&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=lh,n.timer.stop(),delete r[t];for(var u in r)return;delete e.__transition}}function ch(e,t){var n=e.__transition,r,s,o=!0,a;if(n){t=t==null?null:t+"";for(a in n){if((r=n[a]).name!==t){o=!1;continue}s=r.state>Rx&&r.state<Tx,r.state=lh,r.timer.stop(),r.on.call(s?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[a]}o&&delete e.__transition}}function hB(e){return this.each(function(){ch(this,e)})}function mB(e,t){var n,r;return function(){var s=Ti(this,e),o=s.tween;if(o!==n){r=n=o;for(var a=0,l=r.length;a<l;++a)if(r[a].name===t){r=r.slice(),r.splice(a,1);break}}s.tween=r}}function gB(e,t,n){var r,s;if(typeof n!="function")throw new Error;return function(){var o=Ti(this,e),a=o.tween;if(a!==r){s=(r=a).slice();for(var l={name:t,value:n},c=0,u=s.length;c<u;++c)if(s[c].name===t){s[c]=l;break}c===u&&s.push(l)}o.tween=s}}function yB(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=ii(this.node(),n).tween,s=0,o=r.length,a;s<o;++s)if((a=r[s]).name===e)return a.value;return null}return this.each((t==null?mB:gB)(n,e,t))}function Ek(e,t,n){var r=e._id;return e.each(function(){var s=Ti(this,r);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return ii(s,r).value[t]}}function tI(e,t){var n;return(typeof t=="number"?gi:t instanceof Ua?qh:(n=Ua(t))?(t=n,qh):YP)(e,t)}function wB(e){return function(){this.removeAttribute(e)}}function xB(e){return function(){this.removeAttributeNS(e.space,e.local)}}function bB(e,t,n){var r,s=n+"",o;return function(){var a=this.getAttribute(e);return a===s?null:a===r?o:o=t(r=a,n)}}function kB(e,t,n){var r,s=n+"",o;return function(){var a=this.getAttributeNS(e.space,e.local);return a===s?null:a===r?o:o=t(r=a,n)}}function vB(e,t,n){var r,s,o;return function(){var a,l=n(this),c;return l==null?void this.removeAttribute(e):(a=this.getAttribute(e),c=l+"",a===c?null:a===r&&c===s?o:(s=c,o=t(r=a,l)))}}function SB(e,t,n){var r,s,o;return function(){var a,l=n(this),c;return l==null?void this.removeAttributeNS(e.space,e.local):(a=this.getAttributeNS(e.space,e.local),c=l+"",a===c?null:a===r&&c===s?o:(s=c,o=t(r=a,l)))}}function NB(e,t){var n=Vm(e),r=n==="transform"?rB:tI;return this.attrTween(e,typeof t=="function"?(n.local?SB:vB)(n,r,Ek(this,"attr."+e,t)):t==null?(n.local?xB:wB)(n):(n.local?kB:bB)(n,r,t))}function jB(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function CB(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function _B(e,t){var n,r;function s(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&CB(e,o)),n}return s._value=t,s}function EB(e,t){var n,r;function s(){var o=t.apply(this,arguments);return o!==r&&(n=(r=o)&&jB(e,o)),n}return s._value=t,s}function AB(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var r=Vm(e);return this.tween(n,(r.local?_B:EB)(r,t))}function PB(e,t){return function(){_k(this,e).delay=+t.apply(this,arguments)}}function IB(e,t){return t=+t,function(){_k(this,e).delay=t}}function RB(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?PB:IB)(t,e)):ii(this.node(),t).delay}function TB(e,t){return function(){Ti(this,e).duration=+t.apply(this,arguments)}}function MB(e,t){return t=+t,function(){Ti(this,e).duration=t}}function $B(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?TB:MB)(t,e)):ii(this.node(),t).duration}function LB(e,t){if(typeof t!="function")throw new Error;return function(){Ti(this,e).ease=t}}function OB(e){var t=this._id;return arguments.length?this.each(LB(t,e)):ii(this.node(),t).ease}function DB(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Ti(this,e).ease=n}}function FB(e){if(typeof e!="function")throw new Error;return this.each(DB(this._id,e))}function zB(e){typeof e!="function"&&(e=RP(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var o=t[s],a=o.length,l=r[s]=[],c,u=0;u<a;++u)(c=o[u])&&e.call(c,c.__data__,u,o)&&l.push(c);return new ao(r,this._parents,this._name,this._id)}function BB(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,s=n.length,o=Math.min(r,s),a=new Array(r),l=0;l<o;++l)for(var c=t[l],u=n[l],d=c.length,f=a[l]=new Array(d),p,h=0;h<d;++h)(p=c[h]||u[h])&&(f[h]=p);for(;l<r;++l)a[l]=t[l];return new ao(a,this._parents,this._name,this._id)}function HB(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function WB(e,t,n){var r,s,o=HB(t)?_k:Ti;return function(){var a=o(this,e),l=a.on;l!==r&&(s=(r=l).copy()).on(t,n),a.on=s}}function VB(e,t){var n=this._id;return arguments.length<2?ii(this.node(),n).on.on(e):this.each(WB(n,e,t))}function KB(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function qB(){return this.on("end.remove",KB(this._id))}function UB(e){var t=this._name,n=this._id;typeof e!="function"&&(e=vk(e));for(var r=this._groups,s=r.length,o=new Array(s),a=0;a<s;++a)for(var l=r[a],c=l.length,u=o[a]=new Array(c),d,f,p=0;p<c;++p)(d=l[p])&&(f=e.call(d,d.__data__,p,l))&&("__data__"in d&&(f.__data__=d.__data__),u[p]=f,qm(u[p],t,n,p,u,ii(d,n)));return new ao(o,this._parents,t,n)}function YB(e){var t=this._name,n=this._id;typeof e!="function"&&(e=IP(e));for(var r=this._groups,s=r.length,o=[],a=[],l=0;l<s;++l)for(var c=r[l],u=c.length,d,f=0;f<u;++f)if(d=c[f]){for(var p=e.call(d,d.__data__,f,c),h,y=ii(d,n),k=0,b=p.length;k<b;++k)(h=p[k])&&qm(h,t,n,k,p,y);o.push(p),a.push(d)}return new ao(o,a,t,n)}var GB=lf.prototype.constructor;function JB(){return new GB(this._groups,this._parents)}function XB(e,t){var n,r,s;return function(){var o=Nc(this,e),a=(this.style.removeProperty(e),Nc(this,e));return o===a?null:o===n&&a===r?s:s=t(n=o,r=a)}}function nI(e){return function(){this.style.removeProperty(e)}}function QB(e,t,n){var r,s=n+"",o;return function(){var a=Nc(this,e);return a===s?null:a===r?o:o=t(r=a,n)}}function ZB(e,t,n){var r,s,o;return function(){var a=Nc(this,e),l=n(this),c=l+"";return l==null&&(c=l=(this.style.removeProperty(e),Nc(this,e))),a===c?null:a===r&&c===s?o:(s=c,o=t(r=a,l))}}function eH(e,t){var n,r,s,o="style."+t,a="end."+o,l;return function(){var c=Ti(this,e),u=c.on,d=c.value[o]==null?l||(l=nI(t)):void 0;(u!==n||s!==d)&&(r=(n=u).copy()).on(a,s=d),c.on=r}}function tH(e,t,n){var r=(e+="")=="transform"?nB:tI;return t==null?this.styleTween(e,XB(e,r)).on("end.style."+e,nI(e)):typeof t=="function"?this.styleTween(e,ZB(e,r,Ek(this,"style."+e,t))).each(eH(this._id,e)):this.styleTween(e,QB(e,r,t),n).on("end.style."+e,null)}function nH(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function rH(e,t,n){var r,s;function o(){var a=t.apply(this,arguments);return a!==s&&(r=(s=a)&&nH(e,a,n)),r}return o._value=t,o}function sH(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,rH(e,t,n??""))}function iH(e){return function(){this.textContent=e}}function oH(e){return function(){var t=e(this);this.textContent=t??""}}function aH(e){return this.tween("text",typeof e=="function"?oH(Ek(this,"text",e)):iH(e==null?"":e+""))}function lH(e){return function(t){this.textContent=e.call(this,t)}}function cH(e){var t,n;function r(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&lH(s)),t}return r._value=e,r}function uH(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,cH(e))}function dH(){for(var e=this._name,t=this._id,n=rI(),r=this._groups,s=r.length,o=0;o<s;++o)for(var a=r[o],l=a.length,c,u=0;u<l;++u)if(c=a[u]){var d=ii(c,t);qm(c,e,n,u,a,{time:d.time+d.delay+d.duration,delay:0,duration:d.duration,ease:d.ease})}return new ao(r,this._parents,e,n)}function fH(){var e,t,n=this,r=n._id,s=n.size();return new Promise(function(o,a){var l={value:a},c={value:function(){--s===0&&o()}};n.each(function(){var u=Ti(this,r),d=u.on;d!==e&&(t=(e=d).copy(),t._.cancel.push(l),t._.interrupt.push(l),t._.end.push(c)),u.on=t}),s===0&&o()})}var pH=0;function ao(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function rI(){return++pH}var Hi=lf.prototype;ao.prototype={constructor:ao,select:UB,selectAll:YB,selectChild:Hi.selectChild,selectChildren:Hi.selectChildren,filter:zB,merge:BB,selection:JB,transition:dH,call:Hi.call,nodes:Hi.nodes,node:Hi.node,size:Hi.size,empty:Hi.empty,each:Hi.each,on:VB,attr:NB,attrTween:AB,style:tH,styleTween:sH,text:aH,textTween:uH,remove:qB,tween:yB,delay:RB,duration:$B,ease:OB,easeVarying:FB,end:fH,[Symbol.iterator]:Hi[Symbol.iterator]};function hH(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var mH={time:null,delay:0,duration:250,ease:hH};function gH(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function yH(e){var t,n;e instanceof ao?(t=e._id,e=e._name):(t=rI(),(n=mH).time=Ck(),e=e==null?null:e+"");for(var r=this._groups,s=r.length,o=0;o<s;++o)for(var a=r[o],l=a.length,c,u=0;u<l;++u)(c=a[u])&&qm(c,e,t,u,a,n||gH(c,t));return new ao(r,this._parents,e,t)}lf.prototype.interrupt=hB;lf.prototype.transition=yH;const vp=e=>()=>e;function wH(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:s}})}function Ji(e,t,n){this.k=e,this.x=t,this.y=n}Ji.prototype={constructor:Ji,scale:function(e){return e===1?this:new Ji(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Ji(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Um=new Ji(1,0,0);sI.prototype=Ji.prototype;function sI(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Um;return e.__zoom}function $y(e){e.stopImmediatePropagation()}function _u(e){e.preventDefault(),e.stopImmediatePropagation()}function xH(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function bH(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function wj(){return this.__zoom||Um}function kH(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function vH(){return navigator.maxTouchPoints||"ontouchstart"in this}function SH(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],o=e.invertY(t[0][1])-n[0][1],a=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),a>o?(o+a)/2:Math.min(0,o)||Math.max(0,a))}function iI(){var e=xH,t=bH,n=SH,r=kH,s=vH,o=[0,1/0],a=[[-1/0,-1/0],[1/0,1/0]],l=250,c=oh,u=Wm("start","zoom","end"),d,f,p,h=500,y=150,k=0,b=10;function g(M){M.property("__zoom",wj).on("wheel.zoom",I,{passive:!1}).on("mousedown.zoom",z).on("dblclick.zoom",$).filter(s).on("touchstart.zoom",L).on("touchmove.zoom",F).on("touchend.zoom touchcancel.zoom",O).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(M,K,H,D){var T=M.selection?M.selection():M;T.property("__zoom",wj),M!==T?j(M,K,H,D):T.interrupt().each(function(){C(this,arguments).event(D).start().zoom(null,typeof K=="function"?K.apply(this,arguments):K).end()})},g.scaleBy=function(M,K,H,D){g.scaleTo(M,function(){var T=this.__zoom.k,W=typeof K=="function"?K.apply(this,arguments):K;return T*W},H,D)},g.scaleTo=function(M,K,H,D){g.transform(M,function(){var T=t.apply(this,arguments),W=this.__zoom,E=H==null?N(T):typeof H=="function"?H.apply(this,arguments):H,Q=W.invert(E),V=typeof K=="function"?K.apply(this,arguments):K;return n(w(v(W,V),E,Q),T,a)},H,D)},g.translateBy=function(M,K,H,D){g.transform(M,function(){return n(this.__zoom.translate(typeof K=="function"?K.apply(this,arguments):K,typeof H=="function"?H.apply(this,arguments):H),t.apply(this,arguments),a)},null,D)},g.translateTo=function(M,K,H,D,T){g.transform(M,function(){var W=t.apply(this,arguments),E=this.__zoom,Q=D==null?N(W):typeof D=="function"?D.apply(this,arguments):D;return n(Um.translate(Q[0],Q[1]).scale(E.k).translate(typeof K=="function"?-K.apply(this,arguments):-K,typeof H=="function"?-H.apply(this,arguments):-H),W,a)},D,T)};function v(M,K){return K=Math.max(o[0],Math.min(o[1],K)),K===M.k?M:new Ji(K,M.x,M.y)}function w(M,K,H){var D=K[0]-H[0]*M.k,T=K[1]-H[1]*M.k;return D===M.x&&T===M.y?M:new Ji(M.k,D,T)}function N(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function j(M,K,H,D){M.on("start.zoom",function(){C(this,arguments).event(D).start()}).on("interrupt.zoom end.zoom",function(){C(this,arguments).event(D).end()}).tween("zoom",function(){var T=this,W=arguments,E=C(T,W).event(D),Q=t.apply(T,W),V=H==null?N(Q):typeof H=="function"?H.apply(T,W):H,B=Math.max(Q[1][0]-Q[0][0],Q[1][1]-Q[0][1]),se=T.__zoom,ue=typeof K=="function"?K.apply(T,W):K,G=c(se.invert(V).concat(B/se.k),ue.invert(V).concat(B/ue.k));return function(ee){if(ee===1)ee=ue;else{var te=G(ee),ne=B/te[2];ee=new Ji(ne,V[0]-te[0]*ne,V[1]-te[1]*ne)}E.zoom(null,ee)}})}function C(M,K,H){return!H&&M.__zooming||new P(M,K)}function P(M,K){this.that=M,this.args=K,this.active=0,this.sourceEvent=null,this.extent=t.apply(M,K),this.taps=0}P.prototype={event:function(M){return M&&(this.sourceEvent=M),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(M,K){return this.mouse&&M!=="mouse"&&(this.mouse[1]=K.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=K.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=K.invert(this.touch1[0])),this.that.__zoom=K,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var K=as(this.that).datum();u.call(M,this.that,new wH(M,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:u}),K)}};function I(M,...K){if(!e.apply(this,arguments))return;var H=C(this,K).event(M),D=this.__zoom,T=Math.max(o[0],Math.min(o[1],D.k*Math.pow(2,r.apply(this,arguments)))),W=qs(M);if(H.wheel)(H.mouse[0][0]!==W[0]||H.mouse[0][1]!==W[1])&&(H.mouse[1]=D.invert(H.mouse[0]=W)),clearTimeout(H.wheel);else{if(D.k===T)return;H.mouse=[W,D.invert(W)],ch(this),H.start()}_u(M),H.wheel=setTimeout(E,y),H.zoom("mouse",n(w(v(D,T),H.mouse[0],H.mouse[1]),H.extent,a));function E(){H.wheel=null,H.end()}}function z(M,...K){if(p||!e.apply(this,arguments))return;var H=M.currentTarget,D=C(this,K,!0).event(M),T=as(M.view).on("mousemove.zoom",V,!0).on("mouseup.zoom",B,!0),W=qs(M,H),E=M.clientX,Q=M.clientY;HP(M.view),$y(M),D.mouse=[W,this.__zoom.invert(W)],ch(this),D.start();function V(se){if(_u(se),!D.moved){var ue=se.clientX-E,G=se.clientY-Q;D.moved=ue*ue+G*G>k}D.event(se).zoom("mouse",n(w(D.that.__zoom,D.mouse[0]=qs(se,H),D.mouse[1]),D.extent,a))}function B(se){T.on("mousemove.zoom mouseup.zoom",null),WP(se.view,D.moved),_u(se),D.event(se).end()}}function $(M,...K){if(e.apply(this,arguments)){var H=this.__zoom,D=qs(M.changedTouches?M.changedTouches[0]:M,this),T=H.invert(D),W=H.k*(M.shiftKey?.5:2),E=n(w(v(H,W),D,T),t.apply(this,K),a);_u(M),l>0?as(this).transition().duration(l).call(j,E,D,M):as(this).call(g.transform,E,D,M)}}function L(M,...K){if(e.apply(this,arguments)){var H=M.touches,D=H.length,T=C(this,K,M.changedTouches.length===D).event(M),W,E,Q,V;for($y(M),E=0;E<D;++E)Q=H[E],V=qs(Q,this),V=[V,this.__zoom.invert(V),Q.identifier],T.touch0?!T.touch1&&T.touch0[2]!==V[2]&&(T.touch1=V,T.taps=0):(T.touch0=V,W=!0,T.taps=1+!!d);d&&(d=clearTimeout(d)),W&&(T.taps<2&&(f=V[0],d=setTimeout(function(){d=null},h)),ch(this),T.start())}}function F(M,...K){if(this.__zooming){var H=C(this,K).event(M),D=M.changedTouches,T=D.length,W,E,Q,V;for(_u(M),W=0;W<T;++W)E=D[W],Q=qs(E,this),H.touch0&&H.touch0[2]===E.identifier?H.touch0[0]=Q:H.touch1&&H.touch1[2]===E.identifier&&(H.touch1[0]=Q);if(E=H.that.__zoom,H.touch1){var B=H.touch0[0],se=H.touch0[1],ue=H.touch1[0],G=H.touch1[1],ee=(ee=ue[0]-B[0])*ee+(ee=ue[1]-B[1])*ee,te=(te=G[0]-se[0])*te+(te=G[1]-se[1])*te;E=v(E,Math.sqrt(ee/te)),Q=[(B[0]+ue[0])/2,(B[1]+ue[1])/2],V=[(se[0]+G[0])/2,(se[1]+G[1])/2]}else if(H.touch0)Q=H.touch0[0],V=H.touch0[1];else return;H.zoom("touch",n(w(E,Q,V),H.extent,a))}}function O(M,...K){if(this.__zooming){var H=C(this,K).event(M),D=M.changedTouches,T=D.length,W,E;for($y(M),p&&clearTimeout(p),p=setTimeout(function(){p=null},h),W=0;W<T;++W)E=D[W],H.touch0&&H.touch0[2]===E.identifier?delete H.touch0:H.touch1&&H.touch1[2]===E.identifier&&delete H.touch1;if(H.touch1&&!H.touch0&&(H.touch0=H.touch1,delete H.touch1),H.touch0)H.touch0[1]=this.__zoom.invert(H.touch0[0]);else if(H.end(),H.taps===2&&(E=qs(E,this),Math.hypot(f[0]-E[0],f[1]-E[1])<b)){var Q=as(this).on("dblclick.zoom");Q&&Q.apply(this,arguments)}}}return g.wheelDelta=function(M){return arguments.length?(r=typeof M=="function"?M:vp(+M),g):r},g.filter=function(M){return arguments.length?(e=typeof M=="function"?M:vp(!!M),g):e},g.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:vp(!!M),g):s},g.extent=function(M){return arguments.length?(t=typeof M=="function"?M:vp([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),g):t},g.scaleExtent=function(M){return arguments.length?(o[0]=+M[0],o[1]=+M[1],g):[o[0],o[1]]},g.translateExtent=function(M){return arguments.length?(a[0][0]=+M[0][0],a[1][0]=+M[1][0],a[0][1]=+M[0][1],a[1][1]=+M[1][1],g):[[a[0][0],a[0][1]],[a[1][0],a[1][1]]]},g.constrain=function(M){return arguments.length?(n=M,g):n},g.duration=function(M){return arguments.length?(l=+M,g):l},g.interpolate=function(M){return arguments.length?(c=M,g):c},g.on=function(){var M=u.on.apply(u,arguments);return M===u?g:M},g.clickDistance=function(M){return arguments.length?(k=(M=+M)*M,g):Math.sqrt(k)},g.tapDistance=function(M){return arguments.length?(b=+M,g):b},g}const Ii={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:r})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:r}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},Ld=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],oI=["Enter"," ","Escape"],aI={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var Cc;(function(e){e.Strict="strict",e.Loose="loose"})(Cc||(Cc={}));var Fa;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(Fa||(Fa={}));var Od;(function(e){e.Partial="partial",e.Full="full"})(Od||(Od={}));const lI={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var Mo;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(Mo||(Mo={}));var bi;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(bi||(bi={}));var qe;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(qe||(qe={}));const xj={[qe.Left]:qe.Right,[qe.Right]:qe.Left,[qe.Top]:qe.Bottom,[qe.Bottom]:qe.Top};function cI(e){return e===null?null:e?"valid":"invalid"}const uI=e=>"id"in e&&"source"in e&&"target"in e,NH=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Ak=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),uf=(e,t=[0,0])=>{const{width:n,height:r}=fo(e),s=e.origin??t,o=n*s[0],a=r*s[1];return{x:e.position.x-o,y:e.position.y-a}},jH=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const o=typeof s=="string";let a=!t.nodeLookup&&!o?s:void 0;t.nodeLookup&&(a=o?t.nodeLookup.get(s):Ak(s)?s:t.nodeLookup.get(s.id));const l=a?Jh(a,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Ym(r,l)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Gm(n)},df=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},r=!1;return e.forEach(s=>{(t.filter===void 0||t.filter(s))&&(n=Ym(n,Jh(s)),r=!0)}),r?Gm(n):{x:0,y:0,width:0,height:0}},Pk=(e,t,[n,r,s]=[0,0,1],o=!1,a=!1)=>{const l={...pf(t,[n,r,s]),width:t.width/s,height:t.height/s},c=[];for(const u of e.values()){const{measured:d,selectable:f=!0,hidden:p=!1}=u;if(a&&!f||p)continue;const h=d.width??u.width??u.initialWidth??null,y=d.height??u.height??u.initialHeight??null,k=Dd(l,Ec(u)),b=(h??0)*(y??0),g=o&&k>0;(!u.internals.handleBounds||g||k>=b||u.dragging)&&c.push(u)}return c},CH=(e,t)=>{const n=new Set;return e.forEach(r=>{n.add(r.id)}),t.filter(r=>n.has(r.source)||n.has(r.target))};function _H(e,t){const n=new Map,r=t!=null&&t.nodes?new Set(t.nodes.map(s=>s.id)):null;return e.forEach(s=>{s.measured.width&&s.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!s.hidden)&&(!r||r.has(s.id))&&n.set(s.id,s)}),n}async function EH({nodes:e,width:t,height:n,panZoom:r,minZoom:s,maxZoom:o},a){if(e.size===0)return Promise.resolve(!0);const l=_H(e,a),c=df(l),u=Ik(c,t,n,(a==null?void 0:a.minZoom)??s,(a==null?void 0:a.maxZoom)??o,(a==null?void 0:a.padding)??.1);return await r.setViewport(u,{duration:a==null?void 0:a.duration,ease:a==null?void 0:a.ease,interpolate:a==null?void 0:a.interpolate}),Promise.resolve(!0)}function dI({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:r=[0,0],nodeExtent:s,onError:o}){const a=n.get(e),l=a.parentId?n.get(a.parentId):void 0,{x:c,y:u}=l?l.internals.positionAbsolute:{x:0,y:0},d=a.origin??r;let f=a.extent||s;if(a.extent==="parent"&&!a.expandParent)if(!l)o==null||o("005",Ii.error005());else{const h=l.measured.width,y=l.measured.height;h&&y&&(f=[[c,u],[c+h,u+y]])}else l&&Ac(a.extent)&&(f=[[a.extent[0][0]+c,a.extent[0][1]+u],[a.extent[1][0]+c,a.extent[1][1]+u]]);const p=Ac(f)?Ga(t,f,a.measured):t;return(a.measured.width===void 0||a.measured.height===void 0)&&(o==null||o("015",Ii.error015())),{position:{x:p.x-c+(a.measured.width??0)*d[0],y:p.y-u+(a.measured.height??0)*d[1]},positionAbsolute:p}}async function AH({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:r,onBeforeDelete:s}){const o=new Set(e.map(p=>p.id)),a=[];for(const p of n){if(p.deletable===!1)continue;const h=o.has(p.id),y=!h&&p.parentId&&a.find(k=>k.id===p.parentId);(h||y)&&a.push(p)}const l=new Set(t.map(p=>p.id)),c=r.filter(p=>p.deletable!==!1),d=CH(a,c);for(const p of c)l.has(p.id)&&!d.find(y=>y.id===p.id)&&d.push(p);if(!s)return{edges:d,nodes:a};const f=await s({nodes:a,edges:d});return typeof f=="boolean"?f?{edges:d,nodes:a}:{edges:[],nodes:[]}:f}const _c=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),Ga=(e={x:0,y:0},t,n)=>({x:_c(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:_c(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function fI(e,t,n){const{width:r,height:s}=fo(n),{x:o,y:a}=n.internals.positionAbsolute;return Ga(e,[[o,a],[o+r,a+s]],t)}const bj=(e,t,n)=>e<t?_c(Math.abs(e-t),1,t)/t:e>n?-_c(Math.abs(e-n),1,t)/t:0,pI=(e,t,n=15,r=40)=>{const s=bj(e.x,r,t.width-r)*n,o=bj(e.y,r,t.height-r)*n;return[s,o]},Ym=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),Mx=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),Gm=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),Ec=(e,t=[0,0])=>{var s,o;const{x:n,y:r}=Ak(e)?e.internals.positionAbsolute:uf(e,t);return{x:n,y:r,width:((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0,height:((o=e.measured)==null?void 0:o.height)??e.height??e.initialHeight??0}},Jh=(e,t=[0,0])=>{var s,o;const{x:n,y:r}=Ak(e)?e.internals.positionAbsolute:uf(e,t);return{x:n,y:r,x2:n+(((s=e.measured)==null?void 0:s.width)??e.width??e.initialWidth??0),y2:r+(((o=e.measured)==null?void 0:o.height)??e.height??e.initialHeight??0)}},hI=(e,t)=>Gm(Ym(Mx(e),Mx(t))),Dd=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},kj=e=>Js(e.width)&&Js(e.height)&&Js(e.x)&&Js(e.y),Js=e=>!isNaN(e)&&isFinite(e),PH=(e,t)=>{},ff=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),pf=({x:e,y:t},[n,r,s],o=!1,a=[1,1])=>{const l={x:(e-n)/s,y:(t-r)/s};return o?ff(l,a):l},Xh=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r});function Il(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function IH(e,t,n){if(typeof e=="string"||typeof e=="number"){const r=Il(e,n),s=Il(e,t);return{top:r,right:s,bottom:r,left:s,x:s*2,y:r*2}}if(typeof e=="object"){const r=Il(e.top??e.y??0,n),s=Il(e.bottom??e.y??0,n),o=Il(e.left??e.x??0,t),a=Il(e.right??e.x??0,t);return{top:r,right:a,bottom:s,left:o,x:o+a,y:r+s}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function RH(e,t,n,r,s,o){const{x:a,y:l}=Xh(e,[t,n,r]),{x:c,y:u}=Xh({x:e.x+e.width,y:e.y+e.height},[t,n,r]),d=s-c,f=o-u;return{left:Math.floor(a),top:Math.floor(l),right:Math.floor(d),bottom:Math.floor(f)}}const Ik=(e,t,n,r,s,o)=>{const a=IH(o,t,n),l=(t-a.x)/e.width,c=(n-a.y)/e.height,u=Math.min(l,c),d=_c(u,r,s),f=e.x+e.width/2,p=e.y+e.height/2,h=t/2-f*d,y=n/2-p*d,k=RH(e,h,y,d,t,n),b={left:Math.min(k.left-a.left,0),top:Math.min(k.top-a.top,0),right:Math.min(k.right-a.right,0),bottom:Math.min(k.bottom-a.bottom,0)};return{x:h-b.left+b.right,y:y-b.top+b.bottom,zoom:d}},Fd=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function Ac(e){return e!=null&&e!=="parent"}function fo(e){var t,n;return{width:((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth??0,height:((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight??0}}function mI(e){var t,n;return(((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth)!==void 0&&(((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight)!==void 0}function gI(e,t={width:0,height:0},n,r,s){const o={...e},a=r.get(n);if(a){const l=a.origin||s;o.x+=a.internals.positionAbsolute.x-(t.width??0)*l[0],o.y+=a.internals.positionAbsolute.y-(t.height??0)*l[1]}return o}function vj(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function TH(){let e,t;return{promise:new Promise((r,s)=>{e=r,t=s}),resolve:e,reject:t}}function MH(e){return{...aI,...e||{}}}function od(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:r,containerBounds:s}){const{x:o,y:a}=Xs(e),l=pf({x:o-((s==null?void 0:s.left)??0),y:a-((s==null?void 0:s.top)??0)},r),{x:c,y:u}=n?ff(l,t):l;return{xSnapped:c,ySnapped:u,...l}}const Rk=e=>({width:e.offsetWidth,height:e.offsetHeight}),yI=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},$H=["INPUT","SELECT","TEXTAREA"];function wI(e){var r,s;const t=((s=(r=e.composedPath)==null?void 0:r.call(e))==null?void 0:s[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:$H.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const xI=e=>"clientX"in e,Xs=(e,t)=>{var o,a;const n=xI(e),r=n?e.clientX:(o=e.touches)==null?void 0:o[0].clientX,s=n?e.clientY:(a=e.touches)==null?void 0:a[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Sj=(e,t,n,r,s)=>{const o=t.querySelectorAll(`.${e}`);return!o||!o.length?null:Array.from(o).map(a=>{const l=a.getBoundingClientRect();return{id:a.getAttribute("data-handleid"),type:e,nodeId:s,position:a.getAttribute("data-handlepos"),x:(l.left-n.left)/r,y:(l.top-n.top)/r,...Rk(a)}})};function bI({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:s,sourceControlY:o,targetControlX:a,targetControlY:l}){const c=e*.125+s*.375+a*.375+n*.125,u=t*.125+o*.375+l*.375+r*.125,d=Math.abs(c-e),f=Math.abs(u-t);return[c,u,d,f]}function Sp(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Nj({pos:e,x1:t,y1:n,x2:r,y2:s,c:o}){switch(e){case qe.Left:return[t-Sp(t-r,o),n];case qe.Right:return[t+Sp(r-t,o),n];case qe.Top:return[t,n-Sp(n-s,o)];case qe.Bottom:return[t,n+Sp(s-n,o)]}}function kI({sourceX:e,sourceY:t,sourcePosition:n=qe.Bottom,targetX:r,targetY:s,targetPosition:o=qe.Top,curvature:a=.25}){const[l,c]=Nj({pos:n,x1:e,y1:t,x2:r,y2:s,c:a}),[u,d]=Nj({pos:o,x1:r,y1:s,x2:e,y2:t,c:a}),[f,p,h,y]=bI({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:l,sourceControlY:c,targetControlX:u,targetControlY:d});return[`M${e},${t} C${l},${c} ${u},${d} ${r},${s}`,f,p,h,y]}function vI({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,o=n<e?n+s:n-s,a=Math.abs(r-t)/2,l=r<t?r+a:r-a;return[o,l,s,a]}function LH({sourceNode:e,targetNode:t,selected:n=!1,zIndex:r=0,elevateOnSelect:s=!1,zIndexMode:o="basic"}){if(o==="manual")return r;const a=s&&n?r+1e3:r,l=Math.max(e.parentId||s&&e.selected?e.internals.z:0,t.parentId||s&&t.selected?t.internals.z:0);return a+l}function OH({sourceNode:e,targetNode:t,width:n,height:r,transform:s}){const o=Ym(Jh(e),Jh(t));o.x===o.x2&&(o.x2+=1),o.y===o.y2&&(o.y2+=1);const a={x:-s[0]/s[2],y:-s[1]/s[2],width:n/s[2],height:r/s[2]};return Dd(a,Gm(o))>0}const DH=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`xy-edge__${e}${t||""}-${n}${r||""}`,FH=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),uh=(e,t,n={})=>{if(!e.source||!e.target)return t;const r=n.getEdgeId||DH;let s;return uI(e)?s={...e}:s={...e,id:r(e)},FH(s,t)?t:(s.sourceHandle===null&&delete s.sourceHandle,s.targetHandle===null&&delete s.targetHandle,t.concat(s))};function SI({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,o,a,l]=vI({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,o,a,l]}const jj={[qe.Left]:{x:-1,y:0},[qe.Right]:{x:1,y:0},[qe.Top]:{x:0,y:-1},[qe.Bottom]:{x:0,y:1}},zH=({source:e,sourcePosition:t=qe.Bottom,target:n})=>t===qe.Left||t===qe.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},Cj=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function BH({source:e,sourcePosition:t=qe.Bottom,target:n,targetPosition:r=qe.Top,center:s,offset:o,stepPosition:a}){const l=jj[t],c=jj[r],u={x:e.x+l.x*o,y:e.y+l.y*o},d={x:n.x+c.x*o,y:n.y+c.y*o},f=zH({source:u,sourcePosition:t,target:d}),p=f.x!==0?"x":"y",h=f[p];let y=[],k,b;const g={x:0,y:0},v={x:0,y:0},[,,w,N]=vI({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(l[p]*c[p]===-1){p==="x"?(k=s.x??u.x+(d.x-u.x)*a,b=s.y??(u.y+d.y)/2):(k=s.x??(u.x+d.x)/2,b=s.y??u.y+(d.y-u.y)*a);const I=[{x:k,y:u.y},{x:k,y:d.y}],z=[{x:u.x,y:b},{x:d.x,y:b}];l[p]===h?y=p==="x"?I:z:y=p==="x"?z:I}else{const I=[{x:u.x,y:d.y}],z=[{x:d.x,y:u.y}];if(p==="x"?y=l.x===h?z:I:y=l.y===h?I:z,t===r){const M=Math.abs(e[p]-n[p]);if(M<=o){const K=Math.min(o-1,o-M);l[p]===h?g[p]=(u[p]>e[p]?-1:1)*K:v[p]=(d[p]>n[p]?-1:1)*K}}if(t!==r){const M=p==="x"?"y":"x",K=l[p]===c[M],H=u[M]>d[M],D=u[M]<d[M];(l[p]===1&&(!K&&H||K&&D)||l[p]!==1&&(!K&&D||K&&H))&&(y=p==="x"?I:z)}const $={x:u.x+g.x,y:u.y+g.y},L={x:d.x+v.x,y:d.y+v.y},F=Math.max(Math.abs($.x-y[0].x),Math.abs(L.x-y[0].x)),O=Math.max(Math.abs($.y-y[0].y),Math.abs(L.y-y[0].y));F>=O?(k=($.x+L.x)/2,b=y[0].y):(k=y[0].x,b=($.y+L.y)/2)}const j={x:u.x+g.x,y:u.y+g.y},C={x:d.x+v.x,y:d.y+v.y};return[[e,...j.x!==y[0].x||j.y!==y[0].y?[j]:[],...y,...C.x!==y[y.length-1].x||C.y!==y[y.length-1].y?[C]:[],n],k,b,w,N]}function HH(e,t,n,r){const s=Math.min(Cj(e,t)/2,Cj(t,n)/2,r),{x:o,y:a}=t;if(e.x===o&&o===n.x||e.y===a&&a===n.y)return`L${o} ${a}`;if(e.y===a){const u=e.x<n.x?-1:1,d=e.y<n.y?1:-1;return`L ${o+s*u},${a}Q ${o},${a} ${o},${a+s*d}`}const l=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${o},${a+s*c}Q ${o},${a} ${o+s*l},${a}`}function $x({sourceX:e,sourceY:t,sourcePosition:n=qe.Bottom,targetX:r,targetY:s,targetPosition:o=qe.Top,borderRadius:a=5,centerX:l,centerY:c,offset:u=20,stepPosition:d=.5}){const[f,p,h,y,k]=BH({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:s},targetPosition:o,center:{x:l,y:c},offset:u,stepPosition:d});let b=`M${f[0].x} ${f[0].y}`;for(let g=1;g<f.length-1;g++)b+=HH(f[g-1],f[g],f[g+1],a);return b+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[b,p,h,y,k]}function _j(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function WH(e){var f;const{sourceNode:t,targetNode:n}=e;if(!_j(t)||!_j(n))return null;const r=t.internals.handleBounds||Ej(t.handles),s=n.internals.handleBounds||Ej(n.handles),o=Aj((r==null?void 0:r.source)??[],e.sourceHandle),a=Aj(e.connectionMode===Cc.Strict?(s==null?void 0:s.target)??[]:((s==null?void 0:s.target)??[]).concat((s==null?void 0:s.source)??[]),e.targetHandle);if(!o||!a)return(f=e.onError)==null||f.call(e,"008",Ii.error008(o?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const l=(o==null?void 0:o.position)||qe.Bottom,c=(a==null?void 0:a.position)||qe.Top,u=Ja(t,o,l),d=Ja(n,a,c);return{sourceX:u.x,sourceY:u.y,targetX:d.x,targetY:d.y,sourcePosition:l,targetPosition:c}}function Ej(e){if(!e)return null;const t=[],n=[];for(const r of e)r.width=r.width??1,r.height=r.height??1,r.type==="source"?t.push(r):r.type==="target"&&n.push(r);return{source:t,target:n}}function Ja(e,t,n=qe.Left,r=!1){const s=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,o=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:a,height:l}=t??fo(e);if(r)return{x:s+a/2,y:o+l/2};switch((t==null?void 0:t.position)??n){case qe.Top:return{x:s+a/2,y:o};case qe.Right:return{x:s+a,y:o+l/2};case qe.Bottom:return{x:s+a/2,y:o+l};case qe.Left:return{x:s,y:o+l/2}}}function Aj(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function Lx(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`:""}function VH(e,{id:t,defaultColor:n,defaultMarkerStart:r,defaultMarkerEnd:s}){const o=new Set;return e.reduce((a,l)=>([l.markerStart||r,l.markerEnd||s].forEach(c=>{if(c&&typeof c=="object"){const u=Lx(c,t);o.has(u)||(a.push({id:u,color:c.color||n,...c}),o.add(u))}}),a),[]).sort((a,l)=>a.id.localeCompare(l.id))}const NI=1e3,KH=10,Tk={nodeOrigin:[0,0],nodeExtent:Ld,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},qH={...Tk,checkEquality:!0};function Mk(e,t){const n={...e};for(const r in t)t[r]!==void 0&&(n[r]=t[r]);return n}function UH(e,t,n){const r=Mk(Tk,n);for(const s of e.values())if(s.parentId)Lk(s,e,t,r);else{const o=uf(s,r.nodeOrigin),a=Ac(s.extent)?s.extent:r.nodeExtent,l=Ga(o,a,fo(s));s.internals.positionAbsolute=l}}function YH(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],r=[];for(const s of e.handles){const o={id:s.id,width:s.width??1,height:s.height??1,nodeId:e.id,x:s.x,y:s.y,position:s.position,type:s.type};s.type==="source"?n.push(o):s.type==="target"&&r.push(o)}return{source:n,target:r}}function $k(e){return e==="manual"}function Ox(e,t,n,r={}){var d,f;const s=Mk(qH,r),o={i:0},a=new Map(t),l=s!=null&&s.elevateNodesOnSelect&&!$k(s.zIndexMode)?NI:0;let c=e.length>0,u=!1;t.clear(),n.clear();for(const p of e){let h=a.get(p.id);if(s.checkEquality&&p===(h==null?void 0:h.internals.userNode))t.set(p.id,h);else{const y=uf(p,s.nodeOrigin),k=Ac(p.extent)?p.extent:s.nodeExtent,b=Ga(y,k,fo(p));h={...s.defaults,...p,measured:{width:(d=p.measured)==null?void 0:d.width,height:(f=p.measured)==null?void 0:f.height},internals:{positionAbsolute:b,handleBounds:YH(p,h),z:jI(p,l,s.zIndexMode),userNode:p}},t.set(p.id,h)}(h.measured===void 0||h.measured.width===void 0||h.measured.height===void 0)&&!h.hidden&&(c=!1),p.parentId&&Lk(h,t,n,r,o),u||(u=p.selected??!1)}return{nodesInitialized:c,hasSelectedNodes:u}}function GH(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function Lk(e,t,n,r,s){const{elevateNodesOnSelect:o,nodeOrigin:a,nodeExtent:l,zIndexMode:c}=Mk(Tk,r),u=e.parentId,d=t.get(u);if(!d){console.warn(`Parent node ${u} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}GH(e,n),s&&!d.parentId&&d.internals.rootParentIndex===void 0&&c==="auto"&&(d.internals.rootParentIndex=++s.i,d.internals.z=d.internals.z+s.i*KH),s&&d.internals.rootParentIndex!==void 0&&(s.i=d.internals.rootParentIndex);const f=o&&!$k(c)?NI:0,{x:p,y:h,z:y}=JH(e,d,a,l,f,c),{positionAbsolute:k}=e.internals,b=p!==k.x||h!==k.y;(b||y!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:b?{x:p,y:h}:k,z:y}})}function jI(e,t,n){const r=Js(e.zIndex)?e.zIndex:0;return $k(n)?r:r+(e.selected?t:0)}function JH(e,t,n,r,s,o){const{x:a,y:l}=t.internals.positionAbsolute,c=fo(e),u=uf(e,n),d=Ac(e.extent)?Ga(u,e.extent,c):u;let f=Ga({x:a+d.x,y:l+d.y},r,c);e.extent==="parent"&&(f=fI(f,c,t));const p=jI(e,s,o),h=t.internals.z??0;return{x:f.x,y:f.y,z:h>=p?h+1:p}}function Ok(e,t,n,r=[0,0]){var a;const s=[],o=new Map;for(const l of e){const c=t.get(l.parentId);if(!c)continue;const u=((a=o.get(l.parentId))==null?void 0:a.expandedRect)??Ec(c),d=hI(u,l.rect);o.set(l.parentId,{expandedRect:d,parent:c})}return o.size>0&&o.forEach(({expandedRect:l,parent:c},u)=>{var w;const d=c.internals.positionAbsolute,f=fo(c),p=c.origin??r,h=l.x<d.x?Math.round(Math.abs(d.x-l.x)):0,y=l.y<d.y?Math.round(Math.abs(d.y-l.y)):0,k=Math.max(f.width,Math.round(l.width)),b=Math.max(f.height,Math.round(l.height)),g=(k-f.width)*p[0],v=(b-f.height)*p[1];(h>0||y>0||g||v)&&(s.push({id:u,type:"position",position:{x:c.position.x-h+g,y:c.position.y-y+v}}),(w=n.get(u))==null||w.forEach(N=>{e.some(j=>j.id===N.id)||s.push({id:N.id,type:"position",position:{x:N.position.x+h,y:N.position.y+y}})})),(f.width<l.width||f.height<l.height||h||y)&&s.push({id:u,type:"dimensions",setAttributes:!0,dimensions:{width:k+(h?p[0]*h-g:0),height:b+(y?p[1]*y-v:0)}})}),s}function XH(e,t,n,r,s,o,a){const l=r==null?void 0:r.querySelector(".xyflow__viewport");let c=!1;if(!l)return{changes:[],updatedInternals:c};const u=[],d=window.getComputedStyle(l),{m22:f}=new window.DOMMatrixReadOnly(d.transform),p=[];for(const h of e.values()){const y=t.get(h.id);if(!y)continue;if(y.hidden){t.set(y.id,{...y,internals:{...y.internals,handleBounds:void 0}}),c=!0;continue}const k=Rk(h.nodeElement),b=y.measured.width!==k.width||y.measured.height!==k.height;if(!!(k.width&&k.height&&(b||!y.internals.handleBounds||h.force))){const v=h.nodeElement.getBoundingClientRect(),w=Ac(y.extent)?y.extent:o;let{positionAbsolute:N}=y.internals;y.parentId&&y.extent==="parent"?N=fI(N,k,t.get(y.parentId)):w&&(N=Ga(N,w,k));const j={...y,measured:k,internals:{...y.internals,positionAbsolute:N,handleBounds:{source:Sj("source",h.nodeElement,v,f,y.id),target:Sj("target",h.nodeElement,v,f,y.id)}}};t.set(y.id,j),y.parentId&&Lk(j,t,n,{nodeOrigin:s,zIndexMode:a}),c=!0,b&&(u.push({id:y.id,type:"dimensions",dimensions:k}),y.expandParent&&y.parentId&&p.push({id:y.id,parentId:y.parentId,rect:Ec(j,s)}))}}if(p.length>0){const h=Ok(p,t,n,s);u.push(...h)}return{changes:u,updatedInternals:c}}async function QH({delta:e,panZoom:t,transform:n,translateExtent:r,width:s,height:o}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const a=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[s,o]],r),l=!!a&&(a.x!==n[0]||a.y!==n[1]||a.k!==n[2]);return Promise.resolve(l)}function Pj(e,t,n,r,s,o){let a=s;const l=r.get(a)||new Map;r.set(a,l.set(n,t)),a=`${s}-${e}`;const c=r.get(a)||new Map;if(r.set(a,c.set(n,t)),o){a=`${s}-${e}-${o}`;const u=r.get(a)||new Map;r.set(a,u.set(n,t))}}function CI(e,t,n){e.clear(),t.clear();for(const r of n){const{source:s,target:o,sourceHandle:a=null,targetHandle:l=null}=r,c={edgeId:r.id,source:s,target:o,sourceHandle:a,targetHandle:l},u=`${s}-${a}--${o}-${l}`,d=`${o}-${l}--${s}-${a}`;Pj("source",c,d,e,s,a),Pj("target",c,u,e,o,l),t.set(r.id,r)}}function _I(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:_I(n,t):!1}function Ij(e,t,n){var s;let r=e;do{if((s=r==null?void 0:r.matches)!=null&&s.call(r,t))return!0;if(r===n)return!1;r=r==null?void 0:r.parentElement}while(r);return!1}function ZH(e,t,n,r){const s=new Map;for(const[o,a]of e)if((a.selected||a.id===r)&&(!a.parentId||!_I(a,e))&&(a.draggable||t&&typeof a.draggable>"u")){const l=e.get(o);l&&s.set(o,{id:o,position:l.position||{x:0,y:0},distance:{x:n.x-l.internals.positionAbsolute.x,y:n.y-l.internals.positionAbsolute.y},extent:l.extent,parentId:l.parentId,origin:l.origin,expandParent:l.expandParent,internals:{positionAbsolute:l.internals.positionAbsolute||{x:0,y:0}},measured:{width:l.measured.width??0,height:l.measured.height??0}})}return s}function Ly({nodeId:e,dragItems:t,nodeLookup:n,dragging:r=!0}){var a,l,c;const s=[];for(const[u,d]of t){const f=(a=n.get(u))==null?void 0:a.internals.userNode;f&&s.push({...f,position:d.position,dragging:r})}if(!e)return[s[0],s];const o=(l=n.get(e))==null?void 0:l.internals.userNode;return[o?{...o,position:((c=t.get(e))==null?void 0:c.position)||o.position,dragging:r}:s[0],s]}function e4({dragItems:e,snapGrid:t,x:n,y:r}){const s=e.values().next().value;if(!s)return null;const o={x:n-s.distance.x,y:r-s.distance.y},a=ff(o,t);return{x:a.x-o.x,y:a.y-o.y}}function t4({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:r,onDragStop:s}){let o={x:null,y:null},a=0,l=new Map,c=!1,u={x:0,y:0},d=null,f=!1,p=null,h=!1,y=!1,k=null;function b({noDragClassName:v,handleSelector:w,domNode:N,isSelectable:j,nodeId:C,nodeClickDistance:P=0}){p=as(N);function I({x:F,y:O}){const{nodeLookup:M,nodeExtent:K,snapGrid:H,snapToGrid:D,nodeOrigin:T,onNodeDrag:W,onSelectionDrag:E,onError:Q,updateNodePositions:V}=t();o={x:F,y:O};let B=!1;const se=l.size>1,ue=se&&K?Mx(df(l)):null,G=se&&D?e4({dragItems:l,snapGrid:H,x:F,y:O}):null;for(const[ee,te]of l){if(!M.has(ee))continue;let ne={x:F-te.distance.x,y:O-te.distance.y};D&&(ne=G?{x:Math.round(ne.x+G.x),y:Math.round(ne.y+G.y)}:ff(ne,H));let Z=null;if(se&&K&&!te.extent&&ue){const{positionAbsolute:me}=te.internals,$e=me.x-ue.x+K[0][0],Ce=me.x+te.measured.width-ue.x2+K[1][0],_e=me.y-ue.y+K[0][1],Be=me.y+te.measured.height-ue.y2+K[1][1];Z=[[$e,_e],[Ce,Be]]}const{position:ce,positionAbsolute:de}=dI({nodeId:ee,nextPosition:ne,nodeLookup:M,nodeExtent:Z||K,nodeOrigin:T,onError:Q});B=B||te.position.x!==ce.x||te.position.y!==ce.y,te.position=ce,te.internals.positionAbsolute=de}if(y=y||B,!!B&&(V(l,!0),k&&(r||W||!C&&E))){const[ee,te]=Ly({nodeId:C,dragItems:l,nodeLookup:M});r==null||r(k,l,ee,te),W==null||W(k,ee,te),C||E==null||E(k,te)}}async function z(){if(!d)return;const{transform:F,panBy:O,autoPanSpeed:M,autoPanOnNodeDrag:K}=t();if(!K){c=!1,cancelAnimationFrame(a);return}const[H,D]=pI(u,d,M);(H!==0||D!==0)&&(o.x=(o.x??0)-H/F[2],o.y=(o.y??0)-D/F[2],await O({x:H,y:D})&&I(o)),a=requestAnimationFrame(z)}function $(F){var se;const{nodeLookup:O,multiSelectionActive:M,nodesDraggable:K,transform:H,snapGrid:D,snapToGrid:T,selectNodesOnDrag:W,onNodeDragStart:E,onSelectionDragStart:Q,unselectNodesAndEdges:V}=t();f=!0,(!W||!j)&&!M&&C&&((se=O.get(C))!=null&&se.selected||V()),j&&W&&C&&(e==null||e(C));const B=od(F.sourceEvent,{transform:H,snapGrid:D,snapToGrid:T,containerBounds:d});if(o=B,l=ZH(O,K,B,C),l.size>0&&(n||E||!C&&Q)){const[ue,G]=Ly({nodeId:C,dragItems:l,nodeLookup:O});n==null||n(F.sourceEvent,l,ue,G),E==null||E(F.sourceEvent,ue,G),C||Q==null||Q(F.sourceEvent,G)}}const L=VP().clickDistance(P).on("start",F=>{const{domNode:O,nodeDragThreshold:M,transform:K,snapGrid:H,snapToGrid:D}=t();d=(O==null?void 0:O.getBoundingClientRect())||null,h=!1,y=!1,k=F.sourceEvent,M===0&&$(F),o=od(F.sourceEvent,{transform:K,snapGrid:H,snapToGrid:D,containerBounds:d}),u=Xs(F.sourceEvent,d)}).on("drag",F=>{const{autoPanOnNodeDrag:O,transform:M,snapGrid:K,snapToGrid:H,nodeDragThreshold:D,nodeLookup:T}=t(),W=od(F.sourceEvent,{transform:M,snapGrid:K,snapToGrid:H,containerBounds:d});if(k=F.sourceEvent,(F.sourceEvent.type==="touchmove"&&F.sourceEvent.touches.length>1||C&&!T.has(C))&&(h=!0),!h){if(!c&&O&&f&&(c=!0,z()),!f){const E=Xs(F.sourceEvent,d),Q=E.x-u.x,V=E.y-u.y;Math.sqrt(Q*Q+V*V)>D&&$(F)}(o.x!==W.xSnapped||o.y!==W.ySnapped)&&l&&f&&(u=Xs(F.sourceEvent,d),I(W))}}).on("end",F=>{if(!(!f||h)&&(c=!1,f=!1,cancelAnimationFrame(a),l.size>0)){const{nodeLookup:O,updateNodePositions:M,onNodeDragStop:K,onSelectionDragStop:H}=t();if(y&&(M(l,!1),y=!1),s||K||!C&&H){const[D,T]=Ly({nodeId:C,dragItems:l,nodeLookup:O,dragging:!1});s==null||s(F.sourceEvent,l,D,T),K==null||K(F.sourceEvent,D,T),C||H==null||H(F.sourceEvent,T)}}}).filter(F=>{const O=F.target;return!F.button&&(!v||!Ij(O,`.${v}`,N))&&(!w||Ij(O,w,N))});p.call(L)}function g(){p==null||p.on(".drag",null)}return{update:b,destroy:g}}function n4(e,t,n){const r=[],s={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const o of t.values())Dd(s,Ec(o))>0&&r.push(o);return r}const r4=250;function s4(e,t,n,r){var l,c;let s=[],o=1/0;const a=n4(e,n,t+r4);for(const u of a){const d=[...((l=u.internals.handleBounds)==null?void 0:l.source)??[],...((c=u.internals.handleBounds)==null?void 0:c.target)??[]];for(const f of d){if(r.nodeId===f.nodeId&&r.type===f.type&&r.id===f.id)continue;const{x:p,y:h}=Ja(u,f,f.position,!0),y=Math.sqrt(Math.pow(p-e.x,2)+Math.pow(h-e.y,2));y>t||(y<o?(s=[{...f,x:p,y:h}],o=y):y===o&&s.push({...f,x:p,y:h}))}}if(!s.length)return null;if(s.length>1){const u=r.type==="source"?"target":"source";return s.find(d=>d.type===u)??s[0]}return s[0]}function EI(e,t,n,r,s,o=!1){var u,d,f;const a=r.get(e);if(!a)return null;const l=s==="strict"?(u=a.internals.handleBounds)==null?void 0:u[t]:[...((d=a.internals.handleBounds)==null?void 0:d.source)??[],...((f=a.internals.handleBounds)==null?void 0:f.target)??[]],c=(n?l==null?void 0:l.find(p=>p.id===n):l==null?void 0:l[0])??null;return c&&o?{...c,...Ja(a,c,c.position,!0)}:c}function AI(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function i4(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const PI=()=>!0;function o4(e,{connectionMode:t,connectionRadius:n,handleId:r,nodeId:s,edgeUpdaterType:o,isTarget:a,domNode:l,nodeLookup:c,lib:u,autoPanOnConnect:d,flowId:f,panBy:p,cancelConnection:h,onConnectStart:y,onConnect:k,onConnectEnd:b,isValidConnection:g=PI,onReconnectEnd:v,updateConnection:w,getTransform:N,getFromHandle:j,autoPanSpeed:C,dragThreshold:P=1,handleDomNode:I}){const z=yI(e.target);let $=0,L;const{x:F,y:O}=Xs(e),M=AI(o,I),K=l==null?void 0:l.getBoundingClientRect();let H=!1;if(!K||!M)return;const D=EI(s,M,r,c,t);if(!D)return;let T=Xs(e,K),W=!1,E=null,Q=!1,V=null;function B(){if(!d||!K)return;const[ce,de]=pI(T,K,C);p({x:ce,y:de}),$=requestAnimationFrame(B)}const se={...D,nodeId:s,type:M,position:D.position},ue=c.get(s);let ee={inProgress:!0,isValid:null,from:Ja(ue,se,qe.Left,!0),fromHandle:se,fromPosition:se.position,fromNode:ue,to:T,toHandle:null,toPosition:xj[se.position],toNode:null,pointer:T};function te(){H=!0,w(ee),y==null||y(e,{nodeId:s,handleId:r,handleType:M})}P===0&&te();function ne(ce){if(!H){const{x:Be,y:ot}=Xs(ce),yt=Be-F,Te=ot-O;if(!(yt*yt+Te*Te>P*P))return;te()}if(!j()||!se){Z(ce);return}const de=N();T=Xs(ce,K),L=s4(pf(T,de,!1,[1,1]),n,c,se),W||(B(),W=!0);const me=II(ce,{handle:L,connectionMode:t,fromNodeId:s,fromHandleId:r,fromType:a?"target":"source",isValidConnection:g,doc:z,lib:u,flowId:f,nodeLookup:c});V=me.handleDomNode,E=me.connection,Q=i4(!!L,me.isValid);const $e=c.get(s),Ce=$e?Ja($e,se,qe.Left,!0):ee.from,_e={...ee,from:Ce,isValid:Q,to:me.toHandle&&Q?Xh({x:me.toHandle.x,y:me.toHandle.y},de):T,toHandle:me.toHandle,toPosition:Q&&me.toHandle?me.toHandle.position:xj[se.position],toNode:me.toHandle?c.get(me.toHandle.nodeId):null,pointer:T};w(_e),ee=_e}function Z(ce){if(!("touches"in ce&&ce.touches.length>0)){if(H){(L||V)&&E&&Q&&(k==null||k(E));const{inProgress:de,...me}=ee,$e={...me,toPosition:ee.toHandle?ee.toPosition:null};b==null||b(ce,$e),o&&(v==null||v(ce,$e))}h(),cancelAnimationFrame($),W=!1,Q=!1,E=null,V=null,z.removeEventListener("mousemove",ne),z.removeEventListener("mouseup",Z),z.removeEventListener("touchmove",ne),z.removeEventListener("touchend",Z)}}z.addEventListener("mousemove",ne),z.addEventListener("mouseup",Z),z.addEventListener("touchmove",ne),z.addEventListener("touchend",Z)}function II(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:s,fromType:o,doc:a,lib:l,flowId:c,isValidConnection:u=PI,nodeLookup:d}){const f=o==="target",p=t?a.querySelector(`.${l}-flow__handle[data-id="${c}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:h,y}=Xs(e),k=a.elementFromPoint(h,y),b=k!=null&&k.classList.contains(`${l}-flow__handle`)?k:p,g={handleDomNode:b,isValid:!1,connection:null,toHandle:null};if(b){const v=AI(void 0,b),w=b.getAttribute("data-nodeid"),N=b.getAttribute("data-handleid"),j=b.classList.contains("connectable"),C=b.classList.contains("connectableend");if(!w||!v)return g;const P={source:f?w:r,sourceHandle:f?N:s,target:f?r:w,targetHandle:f?s:N};g.connection=P;const z=j&&C&&(n===Cc.Strict?f&&v==="source"||!f&&v==="target":w!==r||N!==s);g.isValid=z&&u(P),g.toHandle=EI(w,v,N,d,n,!0)}return g}const Dx={onPointerDown:o4,isValid:II};function a4({domNode:e,panZoom:t,getTransform:n,getViewScale:r}){const s=as(e);function o({translateExtent:l,width:c,height:u,zoomStep:d=1,pannable:f=!0,zoomable:p=!0,inversePan:h=!1}){const y=w=>{if(w.sourceEvent.type!=="wheel"||!t)return;const N=n(),j=w.sourceEvent.ctrlKey&&Fd()?10:1,C=-w.sourceEvent.deltaY*(w.sourceEvent.deltaMode===1?.05:w.sourceEvent.deltaMode?1:.002)*d,P=N[2]*Math.pow(2,C*j);t.scaleTo(P)};let k=[0,0];const b=w=>{(w.sourceEvent.type==="mousedown"||w.sourceEvent.type==="touchstart")&&(k=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY])},g=w=>{const N=n();if(w.sourceEvent.type!=="mousemove"&&w.sourceEvent.type!=="touchmove"||!t)return;const j=[w.sourceEvent.clientX??w.sourceEvent.touches[0].clientX,w.sourceEvent.clientY??w.sourceEvent.touches[0].clientY],C=[j[0]-k[0],j[1]-k[1]];k=j;const P=r()*Math.max(N[2],Math.log(N[2]))*(h?-1:1),I={x:N[0]-C[0]*P,y:N[1]-C[1]*P},z=[[0,0],[c,u]];t.setViewportConstrained({x:I.x,y:I.y,zoom:N[2]},z,l)},v=iI().on("start",b).on("zoom",f?g:null).on("zoom.wheel",p?y:null);s.call(v,{})}function a(){s.on("zoom",null)}return{update:o,destroy:a,pointer:qs}}const Jm=e=>({x:e.x,y:e.y,zoom:e.k}),Oy=({x:e,y:t,zoom:n})=>Um.translate(e,t).scale(n),Zl=(e,t)=>e.target.closest(`.${t}`),RI=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),l4=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,Dy=(e,t=0,n=l4,r=()=>{})=>{const s=typeof t=="number"&&t>0;return s||r(),s?e.transition().duration(t).ease(n).on("end",r):e},TI=e=>{const t=e.ctrlKey&&Fd()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function c4({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:r,panOnScrollMode:s,panOnScrollSpeed:o,zoomOnPinch:a,onPanZoomStart:l,onPanZoom:c,onPanZoomEnd:u}){return d=>{if(Zl(d,t))return d.ctrlKey&&d.preventDefault(),!1;d.preventDefault(),d.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(d.ctrlKey&&a){const b=qs(d),g=TI(d),v=f*Math.pow(2,g);r.scaleTo(n,v,b,d);return}const p=d.deltaMode===1?20:1;let h=s===Fa.Vertical?0:d.deltaX*p,y=s===Fa.Horizontal?0:d.deltaY*p;!Fd()&&d.shiftKey&&s!==Fa.Vertical&&(h=d.deltaY*p,y=0),r.translateBy(n,-(h/f)*o,-(y/f)*o,{internal:!0});const k=Jm(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c==null||c(d,k),e.panScrollTimeout=setTimeout(()=>{u==null||u(d,k),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,l==null||l(d,k))}}function u4({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(r,s){const o=r.type==="wheel",a=!t&&o&&!r.ctrlKey,l=Zl(r,e);if(r.ctrlKey&&o&&l&&r.preventDefault(),a||l)return null;r.preventDefault(),n.call(this,r,s)}}function d4({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return r=>{var o,a,l;if((o=r.sourceEvent)!=null&&o.internal)return;const s=Jm(r.transform);e.mouseButton=((a=r.sourceEvent)==null?void 0:a.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=s,((l=r.sourceEvent)==null?void 0:l.type)==="mousedown"&&t(!0),n&&(n==null||n(r.sourceEvent,s))}}function f4({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:r,onPanZoom:s}){return o=>{var a,l;e.usedRightMouseButton=!!(n&&RI(t,e.mouseButton??0)),(a=o.sourceEvent)!=null&&a.sync||r([o.transform.x,o.transform.y,o.transform.k]),s&&!((l=o.sourceEvent)!=null&&l.internal)&&(s==null||s(o.sourceEvent,Jm(o.transform)))}}function p4({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:r,onPanZoomEnd:s,onPaneContextMenu:o}){return a=>{var l;if(!((l=a.sourceEvent)!=null&&l.internal)&&(e.isZoomingOrPanning=!1,o&&RI(t,e.mouseButton??0)&&!e.usedRightMouseButton&&a.sourceEvent&&o(a.sourceEvent),e.usedRightMouseButton=!1,r(!1),s)){const c=Jm(a.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{s==null||s(a.sourceEvent,c)},n?150:0)}}}function h4({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:r,panOnScroll:s,zoomOnDoubleClick:o,userSelectionActive:a,noWheelClassName:l,noPanClassName:c,lib:u,connectionInProgress:d}){return f=>{var b;const p=e||t,h=n&&f.ctrlKey,y=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(Zl(f,`${u}-flow__node`)||Zl(f,`${u}-flow__edge`)))return!0;if(!r&&!p&&!s&&!o&&!n||a||d&&!y||Zl(f,l)&&y||Zl(f,c)&&(!y||s&&y&&!e)||!n&&f.ctrlKey&&y)return!1;if(!n&&f.type==="touchstart"&&((b=f.touches)==null?void 0:b.length)>1)return f.preventDefault(),!1;if(!p&&!s&&!h&&y||!r&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(r)&&!r.includes(f.button)&&f.type==="mousedown")return!1;const k=Array.isArray(r)&&r.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||y)&&k}}function m4({domNode:e,minZoom:t,maxZoom:n,translateExtent:r,viewport:s,onPanZoom:o,onPanZoomStart:a,onPanZoomEnd:l,onDraggingChange:c}){const u={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},d=e.getBoundingClientRect(),f=iI().scaleExtent([t,n]).translateExtent(r),p=as(e).call(f);v({x:s.x,y:s.y,zoom:_c(s.zoom,t,n)},[[0,0],[d.width,d.height]],r);const h=p.on("wheel.zoom"),y=p.on("dblclick.zoom");f.wheelDelta(TI);function k(L,F){return p?new Promise(O=>{f==null||f.interpolate((F==null?void 0:F.interpolate)==="linear"?id:oh).transform(Dy(p,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>O(!0)),L)}):Promise.resolve(!1)}function b({noWheelClassName:L,noPanClassName:F,onPaneContextMenu:O,userSelectionActive:M,panOnScroll:K,panOnDrag:H,panOnScrollMode:D,panOnScrollSpeed:T,preventScrolling:W,zoomOnPinch:E,zoomOnScroll:Q,zoomOnDoubleClick:V,zoomActivationKeyPressed:B,lib:se,onTransformChange:ue,connectionInProgress:G,paneClickDistance:ee,selectionOnDrag:te}){M&&!u.isZoomingOrPanning&&g();const ne=K&&!B&&!M;f.clickDistance(te?1/0:!Js(ee)||ee<0?0:ee);const Z=ne?c4({zoomPanValues:u,noWheelClassName:L,d3Selection:p,d3Zoom:f,panOnScrollMode:D,panOnScrollSpeed:T,zoomOnPinch:E,onPanZoomStart:a,onPanZoom:o,onPanZoomEnd:l}):u4({noWheelClassName:L,preventScrolling:W,d3ZoomHandler:h});if(p.on("wheel.zoom",Z,{passive:!1}),!M){const de=d4({zoomPanValues:u,onDraggingChange:c,onPanZoomStart:a});f.on("start",de);const me=f4({zoomPanValues:u,panOnDrag:H,onPaneContextMenu:!!O,onPanZoom:o,onTransformChange:ue});f.on("zoom",me);const $e=p4({zoomPanValues:u,panOnDrag:H,panOnScroll:K,onPaneContextMenu:O,onPanZoomEnd:l,onDraggingChange:c});f.on("end",$e)}const ce=h4({zoomActivationKeyPressed:B,panOnDrag:H,zoomOnScroll:Q,panOnScroll:K,zoomOnDoubleClick:V,zoomOnPinch:E,userSelectionActive:M,noPanClassName:F,noWheelClassName:L,lib:se,connectionInProgress:G});f.filter(ce),V?p.on("dblclick.zoom",y):p.on("dblclick.zoom",null)}function g(){f.on("zoom",null)}async function v(L,F,O){const M=Oy(L),K=f==null?void 0:f.constrain()(M,F,O);return K&&await k(K),new Promise(H=>H(K))}async function w(L,F){const O=Oy(L);return await k(O,F),new Promise(M=>M(O))}function N(L){if(p){const F=Oy(L),O=p.property("__zoom");(O.k!==L.zoom||O.x!==L.x||O.y!==L.y)&&(f==null||f.transform(p,F,null,{sync:!0}))}}function j(){const L=p?sI(p.node()):{x:0,y:0,k:1};return{x:L.x,y:L.y,zoom:L.k}}function C(L,F){return p?new Promise(O=>{f==null||f.interpolate((F==null?void 0:F.interpolate)==="linear"?id:oh).scaleTo(Dy(p,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>O(!0)),L)}):Promise.resolve(!1)}function P(L,F){return p?new Promise(O=>{f==null||f.interpolate((F==null?void 0:F.interpolate)==="linear"?id:oh).scaleBy(Dy(p,F==null?void 0:F.duration,F==null?void 0:F.ease,()=>O(!0)),L)}):Promise.resolve(!1)}function I(L){f==null||f.scaleExtent(L)}function z(L){f==null||f.translateExtent(L)}function $(L){const F=!Js(L)||L<0?0:L;f==null||f.clickDistance(F)}return{update:b,destroy:g,setViewport:w,setViewportConstrained:v,getViewport:j,scaleTo:C,scaleBy:P,setScaleExtent:I,setTranslateExtent:z,syncViewport:N,setClickDistance:$}}var Pc;(function(e){e.Line="line",e.Handle="handle"})(Pc||(Pc={}));function g4({width:e,prevWidth:t,height:n,prevHeight:r,affectsX:s,affectsY:o}){const a=e-t,l=n-r,c=[a>0?1:a<0?-1:0,l>0?1:l<0?-1:0];return a&&s&&(c[0]=c[0]*-1),l&&o&&(c[1]=c[1]*-1),c}function Rj(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),r=e.includes("left"),s=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:r,affectsY:s}}function Co(e,t){return Math.max(0,t-e)}function _o(e,t){return Math.max(0,e-t)}function Np(e,t,n){return Math.max(0,t-e,e-n)}function Tj(e,t){return e?!t:t}function y4(e,t,n,r,s,o,a,l){let{affectsX:c,affectsY:u}=t;const{isHorizontal:d,isVertical:f}=t,p=d&&f,{xSnapped:h,ySnapped:y}=n,{minWidth:k,maxWidth:b,minHeight:g,maxHeight:v}=r,{x:w,y:N,width:j,height:C,aspectRatio:P}=e;let I=Math.floor(d?h-e.pointerX:0),z=Math.floor(f?y-e.pointerY:0);const $=j+(c?-I:I),L=C+(u?-z:z),F=-o[0]*j,O=-o[1]*C;let M=Np($,k,b),K=Np(L,g,v);if(a){let T=0,W=0;c&&I<0?T=Co(w+I+F,a[0][0]):!c&&I>0&&(T=_o(w+$+F,a[1][0])),u&&z<0?W=Co(N+z+O,a[0][1]):!u&&z>0&&(W=_o(N+L+O,a[1][1])),M=Math.max(M,T),K=Math.max(K,W)}if(l){let T=0,W=0;c&&I>0?T=_o(w+I,l[0][0]):!c&&I<0&&(T=Co(w+$,l[1][0])),u&&z>0?W=_o(N+z,l[0][1]):!u&&z<0&&(W=Co(N+L,l[1][1])),M=Math.max(M,T),K=Math.max(K,W)}if(s){if(d){const T=Np($/P,g,v)*P;if(M=Math.max(M,T),a){let W=0;!c&&!u||c&&!u&&p?W=_o(N+O+$/P,a[1][1])*P:W=Co(N+O+(c?I:-I)/P,a[0][1])*P,M=Math.max(M,W)}if(l){let W=0;!c&&!u||c&&!u&&p?W=Co(N+$/P,l[1][1])*P:W=_o(N+(c?I:-I)/P,l[0][1])*P,M=Math.max(M,W)}}if(f){const T=Np(L*P,k,b)/P;if(K=Math.max(K,T),a){let W=0;!c&&!u||u&&!c&&p?W=_o(w+L*P+F,a[1][0])/P:W=Co(w+(u?z:-z)*P+F,a[0][0])/P,K=Math.max(K,W)}if(l){let W=0;!c&&!u||u&&!c&&p?W=Co(w+L*P,l[1][0])/P:W=_o(w+(u?z:-z)*P,l[0][0])/P,K=Math.max(K,W)}}}z=z+(z<0?K:-K),I=I+(I<0?M:-M),s&&(p?$>L*P?z=(Tj(c,u)?-I:I)/P:I=(Tj(c,u)?-z:z)*P:d?(z=I/P,u=c):(I=z*P,c=u));const H=c?w+I:w,D=u?N+z:N;return{width:j+(c?-I:I),height:C+(u?-z:z),x:o[0]*I*(c?-1:1)+H,y:o[1]*z*(u?-1:1)+D}}const MI={width:0,height:0,x:0,y:0},w4={...MI,pointerX:0,pointerY:0,aspectRatio:1};function x4(e){return[[0,0],[e.measured.width,e.measured.height]]}function b4(e,t,n){const r=t.position.x+e.position.x,s=t.position.y+e.position.y,o=e.measured.width??0,a=e.measured.height??0,l=n[0]*o,c=n[1]*a;return[[r-l,s-c],[r+o-l,s+a-c]]}function k4({domNode:e,nodeId:t,getStoreItems:n,onChange:r,onEnd:s}){const o=as(e);let a={controlDirection:Rj("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function l({controlPosition:u,boundaries:d,keepAspectRatio:f,resizeDirection:p,onResizeStart:h,onResize:y,onResizeEnd:k,shouldResize:b}){let g={...MI},v={...w4};a={boundaries:d,resizeDirection:p,keepAspectRatio:f,controlDirection:Rj(u)};let w,N=null,j=[],C,P,I,z=!1;const $=VP().on("start",L=>{const{nodeLookup:F,transform:O,snapGrid:M,snapToGrid:K,nodeOrigin:H,paneDomNode:D}=n();if(w=F.get(t),!w)return;N=(D==null?void 0:D.getBoundingClientRect())??null;const{xSnapped:T,ySnapped:W}=od(L.sourceEvent,{transform:O,snapGrid:M,snapToGrid:K,containerBounds:N});g={width:w.measured.width??0,height:w.measured.height??0,x:w.position.x??0,y:w.position.y??0},v={...g,pointerX:T,pointerY:W,aspectRatio:g.width/g.height},C=void 0,w.parentId&&(w.extent==="parent"||w.expandParent)&&(C=F.get(w.parentId),P=C&&w.extent==="parent"?x4(C):void 0),j=[],I=void 0;for(const[E,Q]of F)if(Q.parentId===t&&(j.push({id:E,position:{...Q.position},extent:Q.extent}),Q.extent==="parent"||Q.expandParent)){const V=b4(Q,w,Q.origin??H);I?I=[[Math.min(V[0][0],I[0][0]),Math.min(V[0][1],I[0][1])],[Math.max(V[1][0],I[1][0]),Math.max(V[1][1],I[1][1])]]:I=V}h==null||h(L,{...g})}).on("drag",L=>{const{transform:F,snapGrid:O,snapToGrid:M,nodeOrigin:K}=n(),H=od(L.sourceEvent,{transform:F,snapGrid:O,snapToGrid:M,containerBounds:N}),D=[];if(!w)return;const{x:T,y:W,width:E,height:Q}=g,V={},B=w.origin??K,{width:se,height:ue,x:G,y:ee}=y4(v,a.controlDirection,H,a.boundaries,a.keepAspectRatio,B,P,I),te=se!==E,ne=ue!==Q,Z=G!==T&&te,ce=ee!==W&&ne;if(!Z&&!ce&&!te&&!ne)return;if((Z||ce||B[0]===1||B[1]===1)&&(V.x=Z?G:g.x,V.y=ce?ee:g.y,g.x=V.x,g.y=V.y,j.length>0)){const Ce=G-T,_e=ee-W;for(const Be of j)Be.position={x:Be.position.x-Ce+B[0]*(se-E),y:Be.position.y-_e+B[1]*(ue-Q)},D.push(Be)}if((te||ne)&&(V.width=te&&(!a.resizeDirection||a.resizeDirection==="horizontal")?se:g.width,V.height=ne&&(!a.resizeDirection||a.resizeDirection==="vertical")?ue:g.height,g.width=V.width,g.height=V.height),C&&w.expandParent){const Ce=B[0]*(V.width??0);V.x&&V.x<Ce&&(g.x=Ce,v.x=v.x-(V.x-Ce));const _e=B[1]*(V.height??0);V.y&&V.y<_e&&(g.y=_e,v.y=v.y-(V.y-_e))}const de=g4({width:g.width,prevWidth:E,height:g.height,prevHeight:Q,affectsX:a.controlDirection.affectsX,affectsY:a.controlDirection.affectsY}),me={...g,direction:de};(b==null?void 0:b(L,me))!==!1&&(z=!0,y==null||y(L,me),r(V,D))}).on("end",L=>{z&&(k==null||k(L,{...g}),s==null||s({...g}),z=!1)});o.call($)}function c(){o.on(".drag",null)}return{update:l,destroy:c}}var $I={exports:{}},LI={},OI={exports:{}},DI={};/**
45
45
  * @license React
46
46
  * use-sync-external-store-shim.production.js
47
47
  *
@@ -62,7 +62,7 @@ ${n("project:fileTruncated")}`:""]})]}):i.jsx("p",{children:n("project:noNodeFil
62
62
 
63
63
  `,`
64
64
  +`).split(`
65
- `)),d=u.reduce((f,p)=>f.concat(...p),[]);return[u,d]}return[[],[]]},[e]);return m.useEffect(()=>{const c=(t==null?void 0:t.target)??zj,u=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const d=h=>{var b,g;if(s.current=h.ctrlKey||h.metaKey||h.shiftKey||h.altKey,(!s.current||s.current&&!u)&&wI(h))return!1;const k=Hj(h.code,l);if(o.current.add(h[k]),Bj(a,o.current,!1)){const v=((g=(b=h.composedPath)==null?void 0:b.call(h))==null?void 0:g[0])||h.target,w=(v==null?void 0:v.nodeName)==="BUTTON"||(v==null?void 0:v.nodeName)==="A";t.preventDefault!==!1&&(s.current||!w)&&h.preventDefault(),r(!0)}},f=h=>{const y=Hj(h.code,l);Bj(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(h[y]),h.key==="Meta"&&o.current.clear(),s.current=!1},p=()=>{o.current.clear(),r(!1)};return c==null||c.addEventListener("keydown",d),c==null||c.addEventListener("keyup",f),window.addEventListener("blur",p),window.addEventListener("contextmenu",p),()=>{c==null||c.removeEventListener("keydown",d),c==null||c.removeEventListener("keyup",f),window.removeEventListener("blur",p),window.removeEventListener("contextmenu",p)}}},[e,r]),n}function Bj(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Hj(e,t){return t.includes(e)?"code":"key"}const d5=()=>{const e=gn();return m.useMemo(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:r}=e.getState();return r?r.scaleTo(t,n):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[r,s,o],panZoom:a}=e.getState();return a?(await a.setViewport({x:t.x??r,y:t.y??s,zoom:t.zoom??o},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,r]=e.getState().transform;return{x:t,y:n,zoom:r}},setCenter:async(t,n,r)=>e.getState().setCenter(t,n,r),fitBounds:async(t,n)=>{const{width:r,height:s,minZoom:o,maxZoom:a,panZoom:l}=e.getState(),c=Ik(t,r,s,o,a,(n==null?void 0:n.padding)??.1);return l?(await l.setViewport(c,{duration:n==null?void 0:n.duration,ease:n==null?void 0:n.ease,interpolate:n==null?void 0:n.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:r,snapGrid:s,snapToGrid:o,domNode:a}=e.getState();if(!a)return t;const{x:l,y:c}=a.getBoundingClientRect(),u={x:t.x-l,y:t.y-c},d=n.snapGrid??s,f=n.snapToGrid??o;return pf(u,r,f,d)},flowToScreenPosition:t=>{const{transform:n,domNode:r}=e.getState();if(!r)return t;const{x:s,y:o}=r.getBoundingClientRect(),a=Xh(t,n);return{x:a.x+s,y:a.y+o}}}),[])};function KI(e,t){const n=[],r=new Map,s=[];for(const o of e)if(o.type==="add"){s.push(o);continue}else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const a=r.get(o.id);a?a.push(o):r.set(o.id,[o])}for(const o of t){const a=r.get(o.id);if(!a){n.push(o);continue}if(a[0].type==="remove")continue;if(a[0].type==="replace"){n.push({...a[0].item});continue}const l={...o};for(const c of a)f5(c,l);n.push(l)}return s.length&&s.forEach(o=>{o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item})}),n}function f5(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function ad(e,t){return KI(e,t)}function Qh(e,t){return KI(e,t)}function Na(e,t){return{id:e,type:"select",selected:t}}function ec(e,t=new Set,n=!1){const r=[];for(const[s,o]of e){const a=t.has(s);!(o.selected===void 0&&!a)&&o.selected!==a&&(n&&(o.selected=a),r.push(Na(o.id,a)))}return r}function Wj({items:e=[],lookup:t}){var s;const n=[],r=new Map(e.map(o=>[o.id,o]));for(const[o,a]of e.entries()){const l=t.get(a.id),c=((s=l==null?void 0:l.internals)==null?void 0:s.userNode)??l;c!==void 0&&c!==a&&n.push({id:a.id,item:a,type:"replace"}),c===void 0&&n.push({item:a,type:"add",index:o})}for(const[o]of t)r.get(o)===void 0&&n.push({id:o,type:"remove"});return n}function Vj(e){return{id:e.id,type:"remove"}}const Kj=e=>NH(e),p5=e=>uI(e);function qI(e){return m.forwardRef(e)}function qj(e){const[t,n]=m.useState(BigInt(0)),[r]=m.useState(()=>h5(()=>n(s=>s+BigInt(1))));return Fx(()=>{const s=r.get();s.length&&(e(s),r.reset())},[t]),r}function h5(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const UI=m.createContext(null);function m5({children:e}){const t=gn(),n=m.useCallback(l=>{const{nodes:c=[],setNodes:u,hasDefaultNodes:d,onNodesChange:f,nodeLookup:p,fitViewQueued:h,onNodesChangeMiddlewareMap:y}=t.getState();let k=c;for(const g of l)k=typeof g=="function"?g(k):g;let b=Wj({items:k,lookup:p});for(const g of y.values())b=g(b);d&&u(k),b.length>0?f==null||f(b):h&&window.requestAnimationFrame(()=>{const{fitViewQueued:g,nodes:v,setNodes:w}=t.getState();g&&w(v)})},[]),r=qj(n),s=m.useCallback(l=>{const{edges:c=[],setEdges:u,hasDefaultEdges:d,onEdgesChange:f,edgeLookup:p}=t.getState();let h=c;for(const y of l)h=typeof y=="function"?y(h):y;d?u(h):f&&f(Wj({items:h,lookup:p}))},[]),o=qj(s),a=m.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return i.jsx(UI.Provider,{value:a,children:e})}function g5(){const e=m.useContext(UI);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const y5=e=>!!e.panZoom;function Fc(){const e=d5(),t=gn(),n=g5(),r=Bt(y5),s=m.useMemo(()=>{const o=f=>t.getState().nodeLookup.get(f),a=f=>{n.nodeQueue.push(f)},l=f=>{n.edgeQueue.push(f)},c=f=>{var g,v;const{nodeLookup:p,nodeOrigin:h}=t.getState(),y=Kj(f)?f:p.get(f.id),k=y.parentId?gI(y.position,y.measured,y.parentId,p,h):y.position,b={...y,position:k,width:((g=y.measured)==null?void 0:g.width)??y.width,height:((v=y.measured)==null?void 0:v.height)??y.height};return Ec(b)},u=(f,p,h={replace:!1})=>{a(y=>y.map(k=>{if(k.id===f){const b=typeof p=="function"?p(k):p;return h.replace&&Kj(b)?b:{...k,...b}}return k}))},d=(f,p,h={replace:!1})=>{l(y=>y.map(k=>{if(k.id===f){const b=typeof p=="function"?p(k):p;return h.replace&&p5(b)?b:{...k,...b}}return k}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>{var p;return(p=o(f))==null?void 0:p.internals.userNode},getInternalNode:o,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(p=>({...p}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:a,setEdges:l,addNodes:f=>{const p=Array.isArray(f)?f:[f];n.nodeQueue.push(h=>[...h,...p])},addEdges:f=>{const p=Array.isArray(f)?f:[f];n.edgeQueue.push(h=>[...h,...p])},toObject:()=>{const{nodes:f=[],edges:p=[],transform:h}=t.getState(),[y,k,b]=h;return{nodes:f.map(g=>({...g})),edges:p.map(g=>({...g})),viewport:{x:y,y:k,zoom:b}}},deleteElements:async({nodes:f=[],edges:p=[]})=>{const{nodes:h,edges:y,onNodesDelete:k,onEdgesDelete:b,triggerNodeChanges:g,triggerEdgeChanges:v,onDelete:w,onBeforeDelete:N}=t.getState(),{nodes:j,edges:C}=await AH({nodesToRemove:f,edgesToRemove:p,nodes:h,edges:y,onBeforeDelete:N}),P=C.length>0,I=j.length>0;if(P){const z=C.map(Vj);b==null||b(C),v(z)}if(I){const z=j.map(Vj);k==null||k(j),g(z)}return(I||P)&&(w==null||w({nodes:j,edges:C})),{deletedNodes:j,deletedEdges:C}},getIntersectingNodes:(f,p=!0,h)=>{const y=kj(f),k=y?f:c(f),b=h!==void 0;return k?(h||t.getState().nodes).filter(g=>{const v=t.getState().nodeLookup.get(g.id);if(v&&!y&&(g.id===f.id||!v.internals.positionAbsolute))return!1;const w=Ec(b?g:v),N=Dd(w,k);return p&&N>0||N>=w.width*w.height||N>=k.width*k.height}):[]},isNodeIntersecting:(f,p,h=!0)=>{const k=kj(f)?f:c(f);if(!k)return!1;const b=Dd(k,p);return h&&b>0||b>=p.width*p.height||b>=k.width*k.height},updateNode:u,updateNodeData:(f,p,h={replace:!1})=>{u(f,y=>{const k=typeof p=="function"?p(y):p;return h.replace?{...y,data:k}:{...y,data:{...y.data,...k}}},h)},updateEdge:d,updateEdgeData:(f,p,h={replace:!1})=>{d(f,y=>{const k=typeof p=="function"?p(y):p;return h.replace?{...y,data:k}:{...y,data:{...y.data,...k}}},h)},getNodesBounds:f=>{const{nodeLookup:p,nodeOrigin:h}=t.getState();return jH(f,{nodeLookup:p,nodeOrigin:h})},getHandleConnections:({type:f,id:p,nodeId:h})=>{var y;return Array.from(((y=t.getState().connectionLookup.get(`${h}-${f}${p?`-${p}`:""}`))==null?void 0:y.values())??[])},getNodeConnections:({type:f,handleId:p,nodeId:h})=>{var y;return Array.from(((y=t.getState().connectionLookup.get(`${h}${f?p?`-${f}-${p}`:`-${f}`:""}`))==null?void 0:y.values())??[])},fitView:async f=>{const p=t.getState().fitViewResolver??TH();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:p}),n.nodeQueue.push(h=>[...h]),p.promise}}},[]);return m.useMemo(()=>({...s,...e,viewportInitialized:r}),[r])}const Uj=e=>e.selected,w5=typeof window<"u"?window:void 0;function x5({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=gn(),{deleteElements:r}=Fc(),s=zd(e,{actInsideInputWithModifier:!1}),o=zd(t,{target:w5});m.useEffect(()=>{if(s){const{edges:a,nodes:l}=n.getState();r({nodes:l.filter(Uj),edges:a.filter(Uj)}),n.setState({nodesSelectionActive:!1})}},[s]),m.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])}function b5(e){const t=gn();m.useEffect(()=>{const n=()=>{var s,o,a,l;if(!e.current||!(((o=(s=e.current).checkVisibility)==null?void 0:o.call(s))??!0))return!1;const r=Rk(e.current);(r.height===0||r.width===0)&&((l=(a=t.getState()).onError)==null||l.call(a,"004",Ii.error004())),t.setState({width:r.width||500,height:r.height||500})};if(e.current){n(),window.addEventListener("resize",n);const r=new ResizeObserver(()=>n());return r.observe(e.current),()=>{window.removeEventListener("resize",n),r&&e.current&&r.unobserve(e.current)}}},[])}const eg={position:"absolute",width:"100%",height:"100%",top:0,left:0},k5=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function v5({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:r=!1,panOnScrollSpeed:s=.5,panOnScrollMode:o=Fa.Free,zoomOnDoubleClick:a=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:u,minZoom:d,maxZoom:f,zoomActivationKeyCode:p,preventScrolling:h=!0,children:y,noWheelClassName:k,noPanClassName:b,onViewportChange:g,isControlledViewport:v,paneClickDistance:w,selectionOnDrag:N}){const j=gn(),C=m.useRef(null),{userSelectionActive:P,lib:I,connectionInProgress:z}=Bt(k5,_n),$=zd(p),L=m.useRef();b5(C);const F=m.useCallback(O=>{g==null||g({x:O[0],y:O[1],zoom:O[2]}),v||j.setState({transform:O})},[g,v]);return m.useEffect(()=>{if(C.current){L.current=m4({domNode:C.current,minZoom:d,maxZoom:f,translateExtent:u,viewport:c,onDraggingChange:H=>j.setState(D=>D.paneDragging===H?D:{paneDragging:H}),onPanZoomStart:(H,D)=>{const{onViewportChangeStart:T,onMoveStart:W}=j.getState();W==null||W(H,D),T==null||T(D)},onPanZoom:(H,D)=>{const{onViewportChange:T,onMove:W}=j.getState();W==null||W(H,D),T==null||T(D)},onPanZoomEnd:(H,D)=>{const{onViewportChangeEnd:T,onMoveEnd:W}=j.getState();W==null||W(H,D),T==null||T(D)}});const{x:O,y:M,zoom:K}=L.current.getViewport();return j.setState({panZoom:L.current,transform:[O,M,K],domNode:C.current.closest(".react-flow")}),()=>{var H;(H=L.current)==null||H.destroy()}}},[]),m.useEffect(()=>{var O;(O=L.current)==null||O.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:r,panOnScrollSpeed:s,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:l,zoomActivationKeyPressed:$,preventScrolling:h,noPanClassName:b,userSelectionActive:P,noWheelClassName:k,lib:I,onTransformChange:F,connectionInProgress:z,selectionOnDrag:N,paneClickDistance:w})},[e,t,n,r,s,o,a,l,$,h,b,P,k,I,F,z,N,w]),i.jsx("div",{className:"react-flow__renderer",ref:C,style:eg,children:y})}const S5=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function N5(){const{userSelectionActive:e,userSelectionRect:t}=Bt(S5,_n);return e&&t?i.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const zy=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},j5=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function C5({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Od.Full,panOnDrag:r,paneClickDistance:s,selectionOnDrag:o,onSelectionStart:a,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:u,onPaneScroll:d,onPaneMouseEnter:f,onPaneMouseMove:p,onPaneMouseLeave:h,children:y}){const k=gn(),{userSelectionActive:b,elementsSelectable:g,dragging:v,connectionInProgress:w}=Bt(j5,_n),N=g&&(e||b),j=m.useRef(null),C=m.useRef(),P=m.useRef(new Set),I=m.useRef(new Set),z=m.useRef(!1),$=T=>{if(z.current||w){z.current=!1;return}c==null||c(T),k.getState().resetSelectedElements(),k.setState({nodesSelectionActive:!1})},L=T=>{if(Array.isArray(r)&&(r!=null&&r.includes(2))){T.preventDefault();return}u==null||u(T)},F=d?T=>d(T):void 0,O=T=>{z.current&&(T.stopPropagation(),z.current=!1)},M=T=>{var ue,G;const{domNode:W}=k.getState();if(C.current=W==null?void 0:W.getBoundingClientRect(),!C.current)return;const E=T.target===j.current;if(!E&&!!T.target.closest(".nokey")||!e||!(o&&E||t)||T.button!==0||!T.isPrimary)return;(G=(ue=T.target)==null?void 0:ue.setPointerCapture)==null||G.call(ue,T.pointerId),z.current=!1;const{x:B,y:se}=Xs(T.nativeEvent,C.current);k.setState({userSelectionRect:{width:0,height:0,startX:B,startY:se,x:B,y:se}}),E||(T.stopPropagation(),T.preventDefault())},K=T=>{const{userSelectionRect:W,transform:E,nodeLookup:Q,edgeLookup:V,connectionLookup:B,triggerNodeChanges:se,triggerEdgeChanges:ue,defaultEdgeOptions:G,resetSelectedElements:ee}=k.getState();if(!C.current||!W)return;const{x:te,y:ne}=Xs(T.nativeEvent,C.current),{startX:Z,startY:ce}=W;if(!z.current){const _e=t?0:s;if(Math.hypot(te-Z,ne-ce)<=_e)return;ee(),a==null||a(T)}z.current=!0;const de={startX:Z,startY:ce,x:te<Z?te:Z,y:ne<ce?ne:ce,width:Math.abs(te-Z),height:Math.abs(ne-ce)},me=P.current,$e=I.current;P.current=new Set(Pk(Q,de,E,n===Od.Partial,!0).map(_e=>_e.id)),I.current=new Set;const Ce=(G==null?void 0:G.selectable)??!0;for(const _e of P.current){const Be=B.get(_e);if(Be)for(const{edgeId:ot}of Be.values()){const yt=V.get(ot);yt&&(yt.selectable??Ce)&&I.current.add(ot)}}if(!vj(me,P.current)){const _e=ec(Q,P.current,!0);se(_e)}if(!vj($e,I.current)){const _e=ec(V,I.current);ue(_e)}k.setState({userSelectionRect:de,userSelectionActive:!0,nodesSelectionActive:!1})},H=T=>{var W,E;T.button===0&&((E=(W=T.target)==null?void 0:W.releasePointerCapture)==null||E.call(W,T.pointerId),!b&&T.target===j.current&&k.getState().userSelectionRect&&($==null||$(T)),k.setState({userSelectionActive:!1,userSelectionRect:null}),z.current&&(l==null||l(T),k.setState({nodesSelectionActive:P.current.size>0})))},D=r===!0||Array.isArray(r)&&r.includes(0);return i.jsxs("div",{className:Jn(["react-flow__pane",{draggable:D,dragging:v,selection:e}]),onClick:N?void 0:zy($,j),onContextMenu:zy(L,j),onWheel:zy(F,j),onPointerEnter:N?void 0:f,onPointerMove:N?K:p,onPointerUp:N?H:void 0,onPointerDownCapture:N?M:void 0,onClickCapture:N?O:void 0,onPointerLeave:h,ref:j,style:eg,children:[y,i.jsx(N5,{})]})}function zx({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:l,onError:c}=t.getState(),u=l.get(e);if(!u){c==null||c("012",Ii.error012(e));return}t.setState({nodesSelectionActive:!1}),u.selected?(n||u.selected&&a)&&(o({nodes:[u],edges:[]}),requestAnimationFrame(()=>{var d;return(d=r==null?void 0:r.current)==null?void 0:d.blur()})):s([e])}function YI({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:o,nodeClickDistance:a}){const l=gn(),[c,u]=m.useState(!1),d=m.useRef();return m.useEffect(()=>{d.current=t4({getStoreItems:()=>l.getState(),onNodeMouseDown:f=>{zx({id:f,store:l,nodeRef:e})},onDragStart:()=>{u(!0)},onDragStop:()=>{u(!1)}})},[]),m.useEffect(()=>{if(!(t||!e.current||!d.current))return d.current.update({noDragClassName:n,handleSelector:r,domNode:e.current,isSelectable:o,nodeId:s,nodeClickDistance:a}),()=>{var f;(f=d.current)==null||f.destroy()}},[n,r,t,o,e,s,a]),c}const _5=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function GI(){const e=gn();return m.useCallback(n=>{const{nodeExtent:r,snapToGrid:s,snapGrid:o,nodesDraggable:a,onError:l,updateNodePositions:c,nodeLookup:u,nodeOrigin:d}=e.getState(),f=new Map,p=_5(a),h=s?o[0]:5,y=s?o[1]:5,k=n.direction.x*h*n.factor,b=n.direction.y*y*n.factor;for(const[,g]of u){if(!p(g))continue;let v={x:g.internals.positionAbsolute.x+k,y:g.internals.positionAbsolute.y+b};s&&(v=ff(v,o));const{position:w,positionAbsolute:N}=dI({nodeId:g.id,nextPosition:v,nodeLookup:u,nodeExtent:r,nodeOrigin:d,onError:l});g.position=w,g.internals.positionAbsolute=N,f.set(g.id,g)}c(f)},[])}const Dk=m.createContext(null),E5=Dk.Provider;Dk.Consumer;const JI=()=>m.useContext(Dk),A5=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),P5=(e,t,n)=>r=>{const{connectionClickStartHandle:s,connectionMode:o,connection:a}=r,{fromHandle:l,toHandle:c,isValid:u}=a,d=(c==null?void 0:c.nodeId)===e&&(c==null?void 0:c.id)===t&&(c==null?void 0:c.type)===n;return{connectingFrom:(l==null?void 0:l.nodeId)===e&&(l==null?void 0:l.id)===t&&(l==null?void 0:l.type)===n,connectingTo:d,clickConnecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.id)===t&&(s==null?void 0:s.type)===n,isPossibleEndHandle:o===Cc.Strict?(l==null?void 0:l.type)!==n:e!==(l==null?void 0:l.nodeId)||t!==(l==null?void 0:l.id),connectionInProcess:!!l,clickConnectionInProcess:!!s,valid:d&&u}};function I5({type:e="source",position:t=qe.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,id:a,onConnect:l,children:c,className:u,onMouseDown:d,onTouchStart:f,...p},h){var K,H;const y=a||null,k=e==="target",b=gn(),g=JI(),{connectOnClick:v,noPanClassName:w,rfId:N}=Bt(A5,_n),{connectingFrom:j,connectingTo:C,clickConnecting:P,isPossibleEndHandle:I,connectionInProcess:z,clickConnectionInProcess:$,valid:L}=Bt(P5(g,y,e),_n);g||(H=(K=b.getState()).onError)==null||H.call(K,"010",Ii.error010());const F=D=>{const{defaultEdgeOptions:T,onConnect:W,hasDefaultEdges:E}=b.getState(),Q={...T,...D};if(E){const{edges:V,setEdges:B}=b.getState();B(uh(Q,V))}W==null||W(Q),l==null||l(Q)},O=D=>{if(!g)return;const T=xI(D.nativeEvent);if(s&&(T&&D.button===0||!T)){const W=b.getState();Dx.onPointerDown(D.nativeEvent,{handleDomNode:D.currentTarget,autoPanOnConnect:W.autoPanOnConnect,connectionMode:W.connectionMode,connectionRadius:W.connectionRadius,domNode:W.domNode,nodeLookup:W.nodeLookup,lib:W.lib,isTarget:k,handleId:y,nodeId:g,flowId:W.rfId,panBy:W.panBy,cancelConnection:W.cancelConnection,onConnectStart:W.onConnectStart,onConnectEnd:(...E)=>{var Q,V;return(V=(Q=b.getState()).onConnectEnd)==null?void 0:V.call(Q,...E)},updateConnection:W.updateConnection,onConnect:F,isValidConnection:n||((...E)=>{var Q,V;return((V=(Q=b.getState()).isValidConnection)==null?void 0:V.call(Q,...E))??!0}),getTransform:()=>b.getState().transform,getFromHandle:()=>b.getState().connection.fromHandle,autoPanSpeed:W.autoPanSpeed,dragThreshold:W.connectionDragThreshold})}T?d==null||d(D):f==null||f(D)},M=D=>{const{onClickConnectStart:T,onClickConnectEnd:W,connectionClickStartHandle:E,connectionMode:Q,isValidConnection:V,lib:B,rfId:se,nodeLookup:ue,connection:G}=b.getState();if(!g||!E&&!s)return;if(!E){T==null||T(D.nativeEvent,{nodeId:g,handleId:y,handleType:e}),b.setState({connectionClickStartHandle:{nodeId:g,type:e,id:y}});return}const ee=yI(D.target),te=n||V,{connection:ne,isValid:Z}=Dx.isValid(D.nativeEvent,{handle:{nodeId:g,id:y,type:e},connectionMode:Q,fromNodeId:E.nodeId,fromHandleId:E.id||null,fromType:E.type,isValidConnection:te,flowId:se,doc:ee,lib:B,nodeLookup:ue});Z&&ne&&F(ne);const ce=structuredClone(G);delete ce.inProgress,ce.toPosition=ce.toHandle?ce.toHandle.position:null,W==null||W(D,ce),b.setState({connectionClickStartHandle:null})};return i.jsx("div",{"data-handleid":y,"data-nodeid":g,"data-handlepos":t,"data-id":`${N}-${g}-${y}-${e}`,className:Jn(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",w,u,{source:!k,target:k,connectable:r,connectablestart:s,connectableend:o,clickconnecting:P,connectingfrom:j,connectingto:C,valid:L,connectionindicator:r&&(!z||I)&&(z||$?o:s)}]),onMouseDown:O,onTouchStart:O,onClick:v?M:void 0,ref:h,...p,children:c})}const Gn=m.memo(qI(I5));function R5({data:e,isConnectable:t,sourcePosition:n=qe.Bottom}){return i.jsxs(i.Fragment,{children:[e==null?void 0:e.label,i.jsx(Gn,{type:"source",position:n,isConnectable:t})]})}function T5({data:e,isConnectable:t,targetPosition:n=qe.Top,sourcePosition:r=qe.Bottom}){return i.jsxs(i.Fragment,{children:[i.jsx(Gn,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,i.jsx(Gn,{type:"source",position:r,isConnectable:t})]})}function M5(){return null}function $5({data:e,isConnectable:t,targetPosition:n=qe.Top}){return i.jsxs(i.Fragment,{children:[i.jsx(Gn,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label]})}const Zh={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Yj={input:R5,default:T5,output:$5,group:M5};function L5(e){var t,n,r,s;return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??((t=e.style)==null?void 0:t.width),height:e.height??e.initialHeight??((n=e.style)==null?void 0:n.height)}:{width:e.width??((r=e.style)==null?void 0:r.width),height:e.height??((s=e.style)==null?void 0:s.height)}}const O5=e=>{const{width:t,height:n,x:r,y:s}=df(e.nodeLookup,{filter:o=>!!o.selected});return{width:Js(t)?t:null,height:Js(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${s}px)`}};function D5({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=gn(),{width:s,height:o,transformString:a,userSelectionActive:l}=Bt(O5,_n),c=GI(),u=m.useRef(null);m.useEffect(()=>{var h;n||(h=u.current)==null||h.focus({preventScroll:!0})},[n]);const d=!l&&s!==null&&o!==null;if(YI({nodeRef:u,disabled:!d}),!d)return null;const f=e?h=>{const y=r.getState().nodes.filter(k=>k.selected);e(h,y)}:void 0,p=h=>{Object.prototype.hasOwnProperty.call(Zh,h.key)&&(h.preventDefault(),c({direction:Zh[h.key],factor:h.shiftKey?4:1}))};return i.jsx("div",{className:Jn(["react-flow__nodesselection","react-flow__container",t]),style:{transform:a},children:i.jsx("div",{ref:u,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:p,style:{width:s,height:o}})})}const Gj=typeof window<"u"?window:void 0,F5=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function XI({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:a,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:u,selectionOnDrag:d,selectionMode:f,onSelectionStart:p,onSelectionEnd:h,multiSelectionKeyCode:y,panActivationKeyCode:k,zoomActivationKeyCode:b,elementsSelectable:g,zoomOnScroll:v,zoomOnPinch:w,panOnScroll:N,panOnScrollSpeed:j,panOnScrollMode:C,zoomOnDoubleClick:P,panOnDrag:I,defaultViewport:z,translateExtent:$,minZoom:L,maxZoom:F,preventScrolling:O,onSelectionContextMenu:M,noWheelClassName:K,noPanClassName:H,disableKeyboardA11y:D,onViewportChange:T,isControlledViewport:W}){const{nodesSelectionActive:E,userSelectionActive:Q}=Bt(F5,_n),V=zd(u,{target:Gj}),B=zd(k,{target:Gj}),se=B||I,ue=B||N,G=d&&se!==!0,ee=V||Q||G;return x5({deleteKeyCode:c,multiSelectionKeyCode:y}),i.jsx(v5,{onPaneContextMenu:o,elementsSelectable:g,zoomOnScroll:v,zoomOnPinch:w,panOnScroll:ue,panOnScrollSpeed:j,panOnScrollMode:C,zoomOnDoubleClick:P,panOnDrag:!V&&se,defaultViewport:z,translateExtent:$,minZoom:L,maxZoom:F,zoomActivationKeyCode:b,preventScrolling:O,noWheelClassName:K,noPanClassName:H,onViewportChange:T,isControlledViewport:W,paneClickDistance:l,selectionOnDrag:G,children:i.jsxs(C5,{onSelectionStart:p,onSelectionEnd:h,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:se,isSelecting:!!ee,selectionMode:f,selectionKeyPressed:V,paneClickDistance:l,selectionOnDrag:G,children:[e,E&&i.jsx(D5,{onSelectionContextMenu:M,noPanClassName:H,disableKeyboardA11y:D})]})})}XI.displayName="FlowRenderer";const z5=m.memo(XI),B5=e=>t=>e?Pk(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function H5(e){return Bt(m.useCallback(B5(e),[e]),_n)}const W5=e=>e.updateNodeInternals;function V5(){const e=Bt(W5),[t]=m.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const r=new Map;n.forEach(s=>{const o=s.target.getAttribute("data-id");r.set(o,{id:o,nodeElement:s.target,force:!0})}),e(r)}));return m.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function K5({node:e,nodeType:t,hasDimensions:n,resizeObserver:r}){const s=gn(),o=m.useRef(null),a=m.useRef(null),l=m.useRef(e.sourcePosition),c=m.useRef(e.targetPosition),u=m.useRef(t),d=n&&!!e.internals.handleBounds;return m.useEffect(()=>{o.current&&!e.hidden&&(!d||a.current!==o.current)&&(a.current&&(r==null||r.unobserve(a.current)),r==null||r.observe(o.current),a.current=o.current)},[d,e.hidden]),m.useEffect(()=>()=>{a.current&&(r==null||r.unobserve(a.current),a.current=null)},[]),m.useEffect(()=>{if(o.current){const f=u.current!==t,p=l.current!==e.sourcePosition,h=c.current!==e.targetPosition;(f||p||h)&&(u.current=t,l.current=e.sourcePosition,c.current=e.targetPosition,s.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:o.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),o}function q5({id:e,onClick:t,onMouseEnter:n,onMouseMove:r,onMouseLeave:s,onContextMenu:o,onDoubleClick:a,nodesDraggable:l,elementsSelectable:c,nodesConnectable:u,nodesFocusable:d,resizeObserver:f,noDragClassName:p,noPanClassName:h,disableKeyboardA11y:y,rfId:k,nodeTypes:b,nodeClickDistance:g,onError:v}){const{node:w,internals:N,isParent:j}=Bt(te=>{const ne=te.nodeLookup.get(e),Z=te.parentLookup.has(e);return{node:ne,internals:ne.internals,isParent:Z}},_n);let C=w.type||"default",P=(b==null?void 0:b[C])||Yj[C];P===void 0&&(v==null||v("003",Ii.error003(C)),C="default",P=(b==null?void 0:b.default)||Yj.default);const I=!!(w.draggable||l&&typeof w.draggable>"u"),z=!!(w.selectable||c&&typeof w.selectable>"u"),$=!!(w.connectable||u&&typeof w.connectable>"u"),L=!!(w.focusable||d&&typeof w.focusable>"u"),F=gn(),O=mI(w),M=K5({node:w,nodeType:C,hasDimensions:O,resizeObserver:f}),K=YI({nodeRef:M,disabled:w.hidden||!I,noDragClassName:p,handleSelector:w.dragHandle,nodeId:e,isSelectable:z,nodeClickDistance:g}),H=GI();if(w.hidden)return null;const D=fo(w),T=L5(w),W=z||I||t||n||r||s,E=n?te=>n(te,{...N.userNode}):void 0,Q=r?te=>r(te,{...N.userNode}):void 0,V=s?te=>s(te,{...N.userNode}):void 0,B=o?te=>o(te,{...N.userNode}):void 0,se=a?te=>a(te,{...N.userNode}):void 0,ue=te=>{const{selectNodesOnDrag:ne,nodeDragThreshold:Z}=F.getState();z&&(!ne||!I||Z>0)&&zx({id:e,store:F,nodeRef:M}),t&&t(te,{...N.userNode})},G=te=>{if(!(wI(te.nativeEvent)||y)){if(oI.includes(te.key)&&z){const ne=te.key==="Escape";zx({id:e,store:F,unselect:ne,nodeRef:M})}else if(I&&w.selected&&Object.prototype.hasOwnProperty.call(Zh,te.key)){te.preventDefault();const{ariaLabelConfig:ne}=F.getState();F.setState({ariaLiveMessage:ne["node.a11yDescription.ariaLiveMessage"]({direction:te.key.replace("Arrow","").toLowerCase(),x:~~N.positionAbsolute.x,y:~~N.positionAbsolute.y})}),H({direction:Zh[te.key],factor:te.shiftKey?4:1})}}},ee=()=>{var $e;if(y||!(($e=M.current)!=null&&$e.matches(":focus-visible")))return;const{transform:te,width:ne,height:Z,autoPanOnNodeFocus:ce,setCenter:de}=F.getState();if(!ce)return;Pk(new Map([[e,w]]),{x:0,y:0,width:ne,height:Z},te,!0).length>0||de(w.position.x+D.width/2,w.position.y+D.height/2,{zoom:te[2]})};return i.jsx("div",{className:Jn(["react-flow__node",`react-flow__node-${C}`,{[h]:I},w.className,{selected:w.selected,selectable:z,parent:j,draggable:I,dragging:K}]),ref:M,style:{zIndex:N.z,transform:`translate(${N.positionAbsolute.x}px,${N.positionAbsolute.y}px)`,pointerEvents:W?"all":"none",visibility:O?"visible":"hidden",...w.style,...T},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:E,onMouseMove:Q,onMouseLeave:V,onContextMenu:B,onClick:ue,onDoubleClick:se,onKeyDown:L?G:void 0,tabIndex:L?0:void 0,onFocus:L?ee:void 0,role:w.ariaRole??(L?"group":void 0),"aria-roledescription":"node","aria-describedby":y?void 0:`${HI}-${k}`,"aria-label":w.ariaLabel,...w.domAttributes,children:i.jsx(E5,{value:e,children:i.jsx(P,{id:e,data:w.data,type:C,positionAbsoluteX:N.positionAbsolute.x,positionAbsoluteY:N.positionAbsolute.y,selected:w.selected??!1,selectable:z,draggable:I,deletable:w.deletable??!0,isConnectable:$,sourcePosition:w.sourcePosition,targetPosition:w.targetPosition,dragging:K,dragHandle:w.dragHandle,zIndex:N.z,parentId:w.parentId,...D})})})}var U5=m.memo(q5);const Y5=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function QI(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,onError:o}=Bt(Y5,_n),a=H5(e.onlyRenderVisibleElements),l=V5();return i.jsx("div",{className:"react-flow__nodes",style:eg,children:a.map(c=>i.jsx(U5,{id:c,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:l,nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,nodeClickDistance:e.nodeClickDistance,onError:o},c))})}QI.displayName="NodeRenderer";const G5=m.memo(QI);function J5(e){return Bt(m.useCallback(n=>{if(!e)return n.edges.map(s=>s.id);const r=[];if(n.width&&n.height)for(const s of n.edges){const o=n.nodeLookup.get(s.source),a=n.nodeLookup.get(s.target);o&&a&&OH({sourceNode:o,targetNode:a,width:n.width,height:n.height,transform:n.transform})&&r.push(s.id)}return r},[e]),_n)}const X5=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return i.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Q5=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return i.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Jj={[bi.Arrow]:X5,[bi.ArrowClosed]:Q5};function Z5(e){const t=gn();return m.useMemo(()=>{var s,o;return Object.prototype.hasOwnProperty.call(Jj,e)?Jj[e]:((o=(s=t.getState()).onError)==null||o.call(s,"009",Ii.error009(e)),null)},[e])}const eW=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:o="strokeWidth",strokeWidth:a,orient:l="auto-start-reverse"})=>{const c=Z5(t);return c?i.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:l,refX:"0",refY:"0",children:i.jsx(c,{color:n,strokeWidth:a})}):null},ZI=({defaultColor:e,rfId:t})=>{const n=Bt(o=>o.edges),r=Bt(o=>o.defaultEdgeOptions),s=m.useMemo(()=>VH(n,{id:t,defaultColor:e,defaultMarkerStart:r==null?void 0:r.markerStart,defaultMarkerEnd:r==null?void 0:r.markerEnd}),[n,r,t,e]);return s.length?i.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:i.jsx("defs",{children:s.map(o=>i.jsx(eW,{id:o.id,type:o.type,color:o.color,width:o.width,height:o.height,markerUnits:o.markerUnits,strokeWidth:o.strokeWidth,orient:o.orient},o.id))})}):null};ZI.displayName="MarkerDefinitions";var tW=m.memo(ZI);function eR({x:e,y:t,label:n,labelStyle:r,labelShowBg:s=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:l=2,children:c,className:u,...d}){const[f,p]=m.useState({x:1,y:0,width:0,height:0}),h=Jn(["react-flow__edge-textwrapper",u]),y=m.useRef(null);return m.useEffect(()=>{if(y.current){const k=y.current.getBBox();p({x:k.x,y:k.y,width:k.width,height:k.height})}},[n]),n?i.jsxs("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:h,visibility:f.width?"visible":"hidden",...d,children:[s&&i.jsx("rect",{width:f.width+2*a[0],x:-a[0],y:-a[1],height:f.height+2*a[1],className:"react-flow__edge-textbg",style:o,rx:l,ry:l}),i.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:y,style:r,children:n}),c]}):null}eR.displayName="EdgeText";const nW=m.memo(eR);function tg({path:e,labelX:t,labelY:n,label:r,labelStyle:s,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:u=20,...d}){return i.jsxs(i.Fragment,{children:[i.jsx("path",{...d,d:e,fill:"none",className:Jn(["react-flow__edge-path",d.className])}),u?i.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:u,className:"react-flow__edge-interaction"}):null,r&&Js(t)&&Js(n)?i.jsx(nW,{x:t,y:n,label:r,labelStyle:s,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Xj({pos:e,x1:t,y1:n,x2:r,y2:s}){return e===qe.Left||e===qe.Right?[.5*(t+r),n]:[t,.5*(n+s)]}function tR({sourceX:e,sourceY:t,sourcePosition:n=qe.Bottom,targetX:r,targetY:s,targetPosition:o=qe.Top}){const[a,l]=Xj({pos:n,x1:e,y1:t,x2:r,y2:s}),[c,u]=Xj({pos:o,x1:r,y1:s,x2:e,y2:t}),[d,f,p,h]=bI({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:l,targetControlX:c,targetControlY:u});return[`M${e},${t} C${a},${l} ${c},${u} ${r},${s}`,d,f,p,h]}function nR(e){return m.memo(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:a,targetPosition:l,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:k,markerStart:b,interactionWidth:g})=>{const[v,w,N]=tR({sourceX:n,sourceY:r,sourcePosition:a,targetX:s,targetY:o,targetPosition:l}),j=e.isInternal?void 0:t;return i.jsx(tg,{id:j,path:v,labelX:w,labelY:N,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:k,markerStart:b,interactionWidth:g})})}const rW=nR({isInternal:!1}),rR=nR({isInternal:!0});rW.displayName="SimpleBezierEdge";rR.displayName="SimpleBezierEdgeInternal";function sR(e){return m.memo(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:p,sourcePosition:h=qe.Bottom,targetPosition:y=qe.Top,markerEnd:k,markerStart:b,pathOptions:g,interactionWidth:v})=>{const[w,N,j]=$x({sourceX:n,sourceY:r,sourcePosition:h,targetX:s,targetY:o,targetPosition:y,borderRadius:g==null?void 0:g.borderRadius,offset:g==null?void 0:g.offset,stepPosition:g==null?void 0:g.stepPosition}),C=e.isInternal?void 0:t;return i.jsx(tg,{id:C,path:w,labelX:N,labelY:j,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:p,markerEnd:k,markerStart:b,interactionWidth:v})})}const iR=sR({isInternal:!1}),oR=sR({isInternal:!0});iR.displayName="SmoothStepEdge";oR.displayName="SmoothStepEdgeInternal";function aR(e){return m.memo(({id:t,...n})=>{var s;const r=e.isInternal?void 0:t;return i.jsx(iR,{...n,id:r,pathOptions:m.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(s=n.pathOptions)==null?void 0:s.offset])})})}const sW=aR({isInternal:!1}),lR=aR({isInternal:!0});sW.displayName="StepEdge";lR.displayName="StepEdgeInternal";function cR(e){return m.memo(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:p,markerEnd:h,markerStart:y,interactionWidth:k})=>{const[b,g,v]=SI({sourceX:n,sourceY:r,targetX:s,targetY:o}),w=e.isInternal?void 0:t;return i.jsx(tg,{id:w,path:b,labelX:g,labelY:v,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:p,markerEnd:h,markerStart:y,interactionWidth:k})})}const iW=cR({isInternal:!1}),uR=cR({isInternal:!0});iW.displayName="StraightEdge";uR.displayName="StraightEdgeInternal";function dR(e){return m.memo(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:a=qe.Bottom,targetPosition:l=qe.Top,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:k,markerStart:b,pathOptions:g,interactionWidth:v})=>{const[w,N,j]=kI({sourceX:n,sourceY:r,sourcePosition:a,targetX:s,targetY:o,targetPosition:l,curvature:g==null?void 0:g.curvature}),C=e.isInternal?void 0:t;return i.jsx(tg,{id:C,path:w,labelX:N,labelY:j,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:k,markerStart:b,interactionWidth:v})})}const oW=dR({isInternal:!1}),fR=dR({isInternal:!0});oW.displayName="BezierEdge";fR.displayName="BezierEdgeInternal";const Qj={default:fR,straight:uR,step:lR,smoothstep:oR,simplebezier:rR},Zj={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},aW=(e,t,n)=>n===qe.Left?e-t:n===qe.Right?e+t:e,lW=(e,t,n)=>n===qe.Top?e-t:n===qe.Bottom?e+t:e,e1="react-flow__edgeupdater";function t1({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:o,onMouseOut:a,type:l}){return i.jsx("circle",{onMouseDown:s,onMouseEnter:o,onMouseOut:a,className:Jn([e1,`${e1}-${l}`]),cx:aW(t,r,e),cy:lW(n,r,e),r,stroke:"transparent",fill:"transparent"})}function cW({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:r,sourceY:s,targetX:o,targetY:a,sourcePosition:l,targetPosition:c,onReconnect:u,onReconnectStart:d,onReconnectEnd:f,setReconnecting:p,setUpdateHover:h}){const y=gn(),k=(N,j)=>{if(N.button!==0)return;const{autoPanOnConnect:C,domNode:P,connectionMode:I,connectionRadius:z,lib:$,onConnectStart:L,cancelConnection:F,nodeLookup:O,rfId:M,panBy:K,updateConnection:H}=y.getState(),D=j.type==="target",T=(Q,V)=>{p(!1),f==null||f(Q,n,j.type,V)},W=Q=>u==null?void 0:u(n,Q),E=(Q,V)=>{p(!0),d==null||d(N,n,j.type),L==null||L(Q,V)};Dx.onPointerDown(N.nativeEvent,{autoPanOnConnect:C,connectionMode:I,connectionRadius:z,domNode:P,handleId:j.id,nodeId:j.nodeId,nodeLookup:O,isTarget:D,edgeUpdaterType:j.type,lib:$,flowId:M,cancelConnection:F,panBy:K,isValidConnection:(...Q)=>{var V,B;return((B=(V=y.getState()).isValidConnection)==null?void 0:B.call(V,...Q))??!0},onConnect:W,onConnectStart:E,onConnectEnd:(...Q)=>{var V,B;return(B=(V=y.getState()).onConnectEnd)==null?void 0:B.call(V,...Q)},onReconnectEnd:T,updateConnection:H,getTransform:()=>y.getState().transform,getFromHandle:()=>y.getState().connection.fromHandle,dragThreshold:y.getState().connectionDragThreshold,handleDomNode:N.currentTarget})},b=N=>k(N,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),g=N=>k(N,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),v=()=>h(!0),w=()=>h(!1);return i.jsxs(i.Fragment,{children:[(e===!0||e==="source")&&i.jsx(t1,{position:l,centerX:r,centerY:s,radius:t,onMouseDown:b,onMouseEnter:v,onMouseOut:w,type:"source"}),(e===!0||e==="target")&&i.jsx(t1,{position:c,centerX:o,centerY:a,radius:t,onMouseDown:g,onMouseEnter:v,onMouseOut:w,type:"target"})]})}function uW({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:r,onClick:s,onDoubleClick:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:u,reconnectRadius:d,onReconnect:f,onReconnectStart:p,onReconnectEnd:h,rfId:y,edgeTypes:k,noPanClassName:b,onError:g,disableKeyboardA11y:v}){let w=Bt(de=>de.edgeLookup.get(e));const N=Bt(de=>de.defaultEdgeOptions);w=N?{...N,...w}:w;let j=w.type||"default",C=(k==null?void 0:k[j])||Qj[j];C===void 0&&(g==null||g("011",Ii.error011(j)),j="default",C=(k==null?void 0:k.default)||Qj.default);const P=!!(w.focusable||t&&typeof w.focusable>"u"),I=typeof f<"u"&&(w.reconnectable||n&&typeof w.reconnectable>"u"),z=!!(w.selectable||r&&typeof w.selectable>"u"),$=m.useRef(null),[L,F]=m.useState(!1),[O,M]=m.useState(!1),K=gn(),{zIndex:H,sourceX:D,sourceY:T,targetX:W,targetY:E,sourcePosition:Q,targetPosition:V}=Bt(m.useCallback(de=>{const me=de.nodeLookup.get(w.source),$e=de.nodeLookup.get(w.target);if(!me||!$e)return{zIndex:w.zIndex,...Zj};const Ce=WH({id:e,sourceNode:me,targetNode:$e,sourceHandle:w.sourceHandle||null,targetHandle:w.targetHandle||null,connectionMode:de.connectionMode,onError:g});return{zIndex:LH({selected:w.selected,zIndex:w.zIndex,sourceNode:me,targetNode:$e,elevateOnSelect:de.elevateEdgesOnSelect,zIndexMode:de.zIndexMode}),...Ce||Zj}},[w.source,w.target,w.sourceHandle,w.targetHandle,w.selected,w.zIndex]),_n),B=m.useMemo(()=>w.markerStart?`url('#${Lx(w.markerStart,y)}')`:void 0,[w.markerStart,y]),se=m.useMemo(()=>w.markerEnd?`url('#${Lx(w.markerEnd,y)}')`:void 0,[w.markerEnd,y]);if(w.hidden||D===null||T===null||W===null||E===null)return null;const ue=de=>{var _e;const{addSelectedEdges:me,unselectNodesAndEdges:$e,multiSelectionActive:Ce}=K.getState();z&&(K.setState({nodesSelectionActive:!1}),w.selected&&Ce?($e({nodes:[],edges:[w]}),(_e=$.current)==null||_e.blur()):me([e])),s&&s(de,w)},G=o?de=>{o(de,{...w})}:void 0,ee=a?de=>{a(de,{...w})}:void 0,te=l?de=>{l(de,{...w})}:void 0,ne=c?de=>{c(de,{...w})}:void 0,Z=u?de=>{u(de,{...w})}:void 0,ce=de=>{var me;if(!v&&oI.includes(de.key)&&z){const{unselectNodesAndEdges:$e,addSelectedEdges:Ce}=K.getState();de.key==="Escape"?((me=$.current)==null||me.blur(),$e({edges:[w]})):Ce([e])}};return i.jsx("svg",{style:{zIndex:H},children:i.jsxs("g",{className:Jn(["react-flow__edge",`react-flow__edge-${j}`,w.className,b,{selected:w.selected,animated:w.animated,inactive:!z&&!s,updating:L,selectable:z}]),onClick:ue,onDoubleClick:G,onContextMenu:ee,onMouseEnter:te,onMouseMove:ne,onMouseLeave:Z,onKeyDown:P?ce:void 0,tabIndex:P?0:void 0,role:w.ariaRole??(P?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":w.ariaLabel===null?void 0:w.ariaLabel||`Edge from ${w.source} to ${w.target}`,"aria-describedby":P?`${WI}-${y}`:void 0,ref:$,...w.domAttributes,children:[!O&&i.jsx(C,{id:e,source:w.source,target:w.target,type:w.type,selected:w.selected,animated:w.animated,selectable:z,deletable:w.deletable??!0,label:w.label,labelStyle:w.labelStyle,labelShowBg:w.labelShowBg,labelBgStyle:w.labelBgStyle,labelBgPadding:w.labelBgPadding,labelBgBorderRadius:w.labelBgBorderRadius,sourceX:D,sourceY:T,targetX:W,targetY:E,sourcePosition:Q,targetPosition:V,data:w.data,style:w.style,sourceHandleId:w.sourceHandle,targetHandleId:w.targetHandle,markerStart:B,markerEnd:se,pathOptions:"pathOptions"in w?w.pathOptions:void 0,interactionWidth:w.interactionWidth}),I&&i.jsx(cW,{edge:w,isReconnectable:I,reconnectRadius:d,onReconnect:f,onReconnectStart:p,onReconnectEnd:h,sourceX:D,sourceY:T,targetX:W,targetY:E,sourcePosition:Q,targetPosition:V,setUpdateHover:F,setReconnecting:M})]})})}var dW=m.memo(uW);const fW=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function pR({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:r,noPanClassName:s,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:u,onEdgeClick:d,reconnectRadius:f,onEdgeDoubleClick:p,onReconnectStart:h,onReconnectEnd:y,disableKeyboardA11y:k}){const{edgesFocusable:b,edgesReconnectable:g,elementsSelectable:v,onError:w}=Bt(fW,_n),N=J5(t);return i.jsxs("div",{className:"react-flow__edges",children:[i.jsx(tW,{defaultColor:e,rfId:n}),N.map(j=>i.jsx(dW,{id:j,edgesFocusable:b,edgesReconnectable:g,elementsSelectable:v,noPanClassName:s,onReconnect:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:u,onClick:d,reconnectRadius:f,onDoubleClick:p,onReconnectStart:h,onReconnectEnd:y,rfId:n,onError:w,edgeTypes:r,disableKeyboardA11y:k},j))]})}pR.displayName="EdgeRenderer";const pW=m.memo(pR),hW=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function mW({children:e}){const t=Bt(hW);return i.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function gW(e){const t=Fc(),n=m.useRef(!1);m.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const yW=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function wW(e){const t=Bt(yW),n=gn();return m.useEffect(()=>{e&&(t==null||t(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function xW(e){return e.connection.inProgress?{...e.connection,to:pf(e.connection.to,e.transform)}:{...e.connection}}function bW(e){return xW}function kW(e){const t=bW();return Bt(t,_n)}const vW=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function SW({containerStyle:e,style:t,type:n,component:r}){const{nodesConnectable:s,width:o,height:a,isValid:l,inProgress:c}=Bt(vW,_n);return!(o&&s&&c)?null:i.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:i.jsx("g",{className:Jn(["react-flow__connection",cI(l)]),children:i.jsx(hR,{style:t,type:n,CustomComponent:r,isValid:l})})})}const hR=({style:e,type:t=Mo.Bezier,CustomComponent:n,isValid:r})=>{const{inProgress:s,from:o,fromNode:a,fromHandle:l,fromPosition:c,to:u,toNode:d,toHandle:f,toPosition:p,pointer:h}=kW();if(!s)return;if(n)return i.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:a,fromHandle:l,fromX:o.x,fromY:o.y,toX:u.x,toY:u.y,fromPosition:c,toPosition:p,connectionStatus:cI(r),toNode:d,toHandle:f,pointer:h});let y="";const k={sourceX:o.x,sourceY:o.y,sourcePosition:c,targetX:u.x,targetY:u.y,targetPosition:p};switch(t){case Mo.Bezier:[y]=kI(k);break;case Mo.SimpleBezier:[y]=tR(k);break;case Mo.Step:[y]=$x({...k,borderRadius:0});break;case Mo.SmoothStep:[y]=$x(k);break;default:[y]=SI(k)}return i.jsx("path",{d:y,fill:"none",className:"react-flow__connection-path",style:e})};hR.displayName="ConnectionLine";const NW={};function n1(e=NW){m.useRef(e),gn(),m.useEffect(()=>{},[e])}function jW(){gn(),m.useRef(!1),m.useEffect(()=>{},[])}function mR({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:r,onEdgeClick:s,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:d,onSelectionContextMenu:f,onSelectionStart:p,onSelectionEnd:h,connectionLineType:y,connectionLineStyle:k,connectionLineComponent:b,connectionLineContainerStyle:g,selectionKeyCode:v,selectionOnDrag:w,selectionMode:N,multiSelectionKeyCode:j,panActivationKeyCode:C,zoomActivationKeyCode:P,deleteKeyCode:I,onlyRenderVisibleElements:z,elementsSelectable:$,defaultViewport:L,translateExtent:F,minZoom:O,maxZoom:M,preventScrolling:K,defaultMarkerColor:H,zoomOnScroll:D,zoomOnPinch:T,panOnScroll:W,panOnScrollSpeed:E,panOnScrollMode:Q,zoomOnDoubleClick:V,panOnDrag:B,onPaneClick:se,onPaneMouseEnter:ue,onPaneMouseMove:G,onPaneMouseLeave:ee,onPaneScroll:te,onPaneContextMenu:ne,paneClickDistance:Z,nodeClickDistance:ce,onEdgeContextMenu:de,onEdgeMouseEnter:me,onEdgeMouseMove:$e,onEdgeMouseLeave:Ce,reconnectRadius:_e,onReconnect:Be,onReconnectStart:ot,onReconnectEnd:yt,noDragClassName:Te,noWheelClassName:st,noPanClassName:gt,disableKeyboardA11y:xe,nodeExtent:Fe,rfId:lt,viewport:oe,onViewportChange:ke}){return n1(e),n1(t),jW(),gW(n),wW(oe),i.jsx(z5,{onPaneClick:se,onPaneMouseEnter:ue,onPaneMouseMove:G,onPaneMouseLeave:ee,onPaneContextMenu:ne,onPaneScroll:te,paneClickDistance:Z,deleteKeyCode:I,selectionKeyCode:v,selectionOnDrag:w,selectionMode:N,onSelectionStart:p,onSelectionEnd:h,multiSelectionKeyCode:j,panActivationKeyCode:C,zoomActivationKeyCode:P,elementsSelectable:$,zoomOnScroll:D,zoomOnPinch:T,zoomOnDoubleClick:V,panOnScroll:W,panOnScrollSpeed:E,panOnScrollMode:Q,panOnDrag:B,defaultViewport:L,translateExtent:F,minZoom:O,maxZoom:M,onSelectionContextMenu:f,preventScrolling:K,noDragClassName:Te,noWheelClassName:st,noPanClassName:gt,disableKeyboardA11y:xe,onViewportChange:ke,isControlledViewport:!!oe,children:i.jsxs(mW,{children:[i.jsx(pW,{edgeTypes:t,onEdgeClick:s,onEdgeDoubleClick:a,onReconnect:Be,onReconnectStart:ot,onReconnectEnd:yt,onlyRenderVisibleElements:z,onEdgeContextMenu:de,onEdgeMouseEnter:me,onEdgeMouseMove:$e,onEdgeMouseLeave:Ce,reconnectRadius:_e,defaultMarkerColor:H,noPanClassName:gt,disableKeyboardA11y:xe,rfId:lt}),i.jsx(SW,{style:k,type:y,component:b,containerStyle:g}),i.jsx("div",{className:"react-flow__edgelabel-renderer"}),i.jsx(G5,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:d,nodeClickDistance:ce,onlyRenderVisibleElements:z,noPanClassName:gt,noDragClassName:Te,disableKeyboardA11y:xe,nodeExtent:Fe,rfId:lt}),i.jsx("div",{className:"react-flow__viewport-portal"})]})})}mR.displayName="GraphView";const CW=m.memo(mR),r1=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:o,fitView:a,fitViewOptions:l,minZoom:c=.5,maxZoom:u=2,nodeOrigin:d,nodeExtent:f,zIndexMode:p="basic"}={})=>{const h=new Map,y=new Map,k=new Map,b=new Map,g=r??t??[],v=n??e??[],w=d??[0,0],N=f??Ld;CI(k,b,g);const{nodesInitialized:j}=Ox(v,h,y,{nodeOrigin:w,nodeExtent:N,zIndexMode:p});let C=[0,0,1];if(a&&s&&o){const P=df(h,{filter:L=>!!((L.width||L.initialWidth)&&(L.height||L.initialHeight))}),{x:I,y:z,zoom:$}=Ik(P,s,o,c,u,(l==null?void 0:l.padding)??.1);C=[I,z,$]}return{rfId:"1",width:s??0,height:o??0,transform:C,nodes:v,nodesInitialized:j,nodeLookup:h,parentLookup:y,edges:g,edgeLookup:b,connectionLookup:k,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:u,translateExtent:Ld,nodeExtent:N,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Cc.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:w,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:a??!1,fitViewOptions:l,fitViewResolver:null,connection:{...lI},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:PH,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:aI,zIndexMode:p,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},_W=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:p})=>q4((h,y)=>{async function k(){const{nodeLookup:b,panZoom:g,fitViewOptions:v,fitViewResolver:w,width:N,height:j,minZoom:C,maxZoom:P}=y();g&&(await EH({nodes:b,width:N,height:j,panZoom:g,minZoom:C,maxZoom:P},v),w==null||w.resolve(!0),h({fitViewResolver:null}))}return{...r1({nodes:e,edges:t,width:s,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:u,nodeOrigin:d,nodeExtent:f,defaultNodes:n,defaultEdges:r,zIndexMode:p}),setNodes:b=>{const{nodeLookup:g,parentLookup:v,nodeOrigin:w,elevateNodesOnSelect:N,fitViewQueued:j,zIndexMode:C,nodesSelectionActive:P}=y(),{nodesInitialized:I,hasSelectedNodes:z}=Ox(b,g,v,{nodeOrigin:w,nodeExtent:f,elevateNodesOnSelect:N,checkEquality:!0,zIndexMode:C}),$=P&&z;j&&I?(k(),h({nodes:b,nodesInitialized:I,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:$})):h({nodes:b,nodesInitialized:I,nodesSelectionActive:$})},setEdges:b=>{const{connectionLookup:g,edgeLookup:v}=y();CI(g,v,b),h({edges:b})},setDefaultNodesAndEdges:(b,g)=>{if(b){const{setNodes:v}=y();v(b),h({hasDefaultNodes:!0})}if(g){const{setEdges:v}=y();v(g),h({hasDefaultEdges:!0})}},updateNodeInternals:b=>{const{triggerNodeChanges:g,nodeLookup:v,parentLookup:w,domNode:N,nodeOrigin:j,nodeExtent:C,debug:P,fitViewQueued:I,zIndexMode:z}=y(),{changes:$,updatedInternals:L}=XH(b,v,w,N,j,C,z);L&&(UH(v,w,{nodeOrigin:j,nodeExtent:C,zIndexMode:z}),I?(k(),h({fitViewQueued:!1,fitViewOptions:void 0})):h({}),($==null?void 0:$.length)>0&&(P&&console.log("React Flow: trigger node changes",$),g==null||g($)))},updateNodePositions:(b,g=!1)=>{const v=[];let w=[];const{nodeLookup:N,triggerNodeChanges:j,connection:C,updateConnection:P,onNodesChangeMiddlewareMap:I}=y();for(const[z,$]of b){const L=N.get(z),F=!!(L!=null&&L.expandParent&&(L!=null&&L.parentId)&&($!=null&&$.position)),O={id:z,type:"position",position:F?{x:Math.max(0,$.position.x),y:Math.max(0,$.position.y)}:$.position,dragging:g};if(L&&C.inProgress&&C.fromNode.id===L.id){const M=Ja(L,C.fromHandle,qe.Left,!0);P({...C,from:M})}F&&L.parentId&&v.push({id:z,parentId:L.parentId,rect:{...$.internals.positionAbsolute,width:$.measured.width??0,height:$.measured.height??0}}),w.push(O)}if(v.length>0){const{parentLookup:z,nodeOrigin:$}=y(),L=Ok(v,N,z,$);w.push(...L)}for(const z of I.values())w=z(w);j(w)},triggerNodeChanges:b=>{const{onNodesChange:g,setNodes:v,nodes:w,hasDefaultNodes:N,debug:j}=y();if(b!=null&&b.length){if(N){const C=ad(b,w);v(C)}j&&console.log("React Flow: trigger node changes",b),g==null||g(b)}},triggerEdgeChanges:b=>{const{onEdgesChange:g,setEdges:v,edges:w,hasDefaultEdges:N,debug:j}=y();if(b!=null&&b.length){if(N){const C=Qh(b,w);v(C)}j&&console.log("React Flow: trigger edge changes",b),g==null||g(b)}},addSelectedNodes:b=>{const{multiSelectionActive:g,edgeLookup:v,nodeLookup:w,triggerNodeChanges:N,triggerEdgeChanges:j}=y();if(g){const C=b.map(P=>Na(P,!0));N(C);return}N(ec(w,new Set([...b]),!0)),j(ec(v))},addSelectedEdges:b=>{const{multiSelectionActive:g,edgeLookup:v,nodeLookup:w,triggerNodeChanges:N,triggerEdgeChanges:j}=y();if(g){const C=b.map(P=>Na(P,!0));j(C);return}j(ec(v,new Set([...b]))),N(ec(w,new Set,!0))},unselectNodesAndEdges:({nodes:b,edges:g}={})=>{const{edges:v,nodes:w,nodeLookup:N,triggerNodeChanges:j,triggerEdgeChanges:C}=y(),P=b||w,I=g||v,z=[];for(const L of P){if(!L.selected)continue;const F=N.get(L.id);F&&(F.selected=!1),z.push(Na(L.id,!1))}const $=[];for(const L of I)L.selected&&$.push(Na(L.id,!1));j(z),C($)},setMinZoom:b=>{const{panZoom:g,maxZoom:v}=y();g==null||g.setScaleExtent([b,v]),h({minZoom:b})},setMaxZoom:b=>{const{panZoom:g,minZoom:v}=y();g==null||g.setScaleExtent([v,b]),h({maxZoom:b})},setTranslateExtent:b=>{var g;(g=y().panZoom)==null||g.setTranslateExtent(b),h({translateExtent:b})},resetSelectedElements:()=>{const{edges:b,nodes:g,triggerNodeChanges:v,triggerEdgeChanges:w,elementsSelectable:N}=y();if(!N)return;const j=g.reduce((P,I)=>I.selected?[...P,Na(I.id,!1)]:P,[]),C=b.reduce((P,I)=>I.selected?[...P,Na(I.id,!1)]:P,[]);v(j),w(C)},setNodeExtent:b=>{const{nodes:g,nodeLookup:v,parentLookup:w,nodeOrigin:N,elevateNodesOnSelect:j,nodeExtent:C,zIndexMode:P}=y();b[0][0]===C[0][0]&&b[0][1]===C[0][1]&&b[1][0]===C[1][0]&&b[1][1]===C[1][1]||(Ox(g,v,w,{nodeOrigin:N,nodeExtent:b,elevateNodesOnSelect:j,checkEquality:!1,zIndexMode:P}),h({nodeExtent:b}))},panBy:b=>{const{transform:g,width:v,height:w,panZoom:N,translateExtent:j}=y();return QH({delta:b,panZoom:N,transform:g,translateExtent:j,width:v,height:w})},setCenter:async(b,g,v)=>{const{width:w,height:N,maxZoom:j,panZoom:C}=y();if(!C)return Promise.resolve(!1);const P=typeof(v==null?void 0:v.zoom)<"u"?v.zoom:j;return await C.setViewport({x:w/2-b*P,y:N/2-g*P,zoom:P},{duration:v==null?void 0:v.duration,ease:v==null?void 0:v.ease,interpolate:v==null?void 0:v.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{h({connection:{...lI}})},updateConnection:b=>{h({connection:b})},reset:()=>h({...r1()})}},Object.is);function Fk({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:r,initialWidth:s,initialHeight:o,initialMinZoom:a,initialMaxZoom:l,initialFitViewOptions:c,fitView:u,nodeOrigin:d,nodeExtent:f,zIndexMode:p,children:h}){const[y]=m.useState(()=>_W({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:o,fitView:u,minZoom:a,maxZoom:l,fitViewOptions:c,nodeOrigin:d,nodeExtent:f,zIndexMode:p}));return i.jsx(U4,{value:y,children:i.jsx(m5,{children:h})})}function EW({children:e,nodes:t,edges:n,defaultNodes:r,defaultEdges:s,width:o,height:a,fitView:l,fitViewOptions:c,minZoom:u,maxZoom:d,nodeOrigin:f,nodeExtent:p,zIndexMode:h}){return m.useContext(Qm)?i.jsx(i.Fragment,{children:e}):i.jsx(Fk,{initialNodes:t,initialEdges:n,defaultNodes:r,defaultEdges:s,initialWidth:o,initialHeight:a,fitView:l,initialFitViewOptions:c,initialMinZoom:u,initialMaxZoom:d,nodeOrigin:f,nodeExtent:p,zIndexMode:h,children:e})}const AW={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function PW({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:o,edgeTypes:a,onNodeClick:l,onEdgeClick:c,onInit:u,onMove:d,onMoveStart:f,onMoveEnd:p,onConnect:h,onConnectStart:y,onConnectEnd:k,onClickConnectStart:b,onClickConnectEnd:g,onNodeMouseEnter:v,onNodeMouseMove:w,onNodeMouseLeave:N,onNodeContextMenu:j,onNodeDoubleClick:C,onNodeDragStart:P,onNodeDrag:I,onNodeDragStop:z,onNodesDelete:$,onEdgesDelete:L,onDelete:F,onSelectionChange:O,onSelectionDragStart:M,onSelectionDrag:K,onSelectionDragStop:H,onSelectionContextMenu:D,onSelectionStart:T,onSelectionEnd:W,onBeforeDelete:E,connectionMode:Q,connectionLineType:V=Mo.Bezier,connectionLineStyle:B,connectionLineComponent:se,connectionLineContainerStyle:ue,deleteKeyCode:G="Backspace",selectionKeyCode:ee="Shift",selectionOnDrag:te=!1,selectionMode:ne=Od.Full,panActivationKeyCode:Z="Space",multiSelectionKeyCode:ce=Fd()?"Meta":"Control",zoomActivationKeyCode:de=Fd()?"Meta":"Control",snapToGrid:me,snapGrid:$e,onlyRenderVisibleElements:Ce=!1,selectNodesOnDrag:_e,nodesDraggable:Be,autoPanOnNodeFocus:ot,nodesConnectable:yt,nodesFocusable:Te,nodeOrigin:st=VI,edgesFocusable:gt,edgesReconnectable:xe,elementsSelectable:Fe=!0,defaultViewport:lt=o5,minZoom:oe=.5,maxZoom:ke=2,translateExtent:Ke=Ld,preventScrolling:Ue=!0,nodeExtent:be,defaultMarkerColor:Ht="#b1b1b7",zoomOnScroll:Qt=!0,zoomOnPinch:jt=!0,panOnScroll:yn=!1,panOnScrollSpeed:on=.5,panOnScrollMode:re=Fa.Free,zoomOnDoubleClick:Re=!0,panOnDrag:Je=!0,onPaneClick:Ze,onPaneMouseEnter:Tt,onPaneMouseMove:At,onPaneMouseLeave:Vn,onPaneScroll:Sn,onPaneContextMenu:xr,paneClickDistance:wn=1,nodeClickDistance:Xn=0,children:Kn,onReconnect:hr,onReconnectStart:ts,onReconnectEnd:Ar,onEdgeContextMenu:gs,onEdgeDoubleClick:ys,onEdgeMouseEnter:cn,onEdgeMouseMove:rr,onEdgeMouseLeave:Pr,reconnectRadius:dn=10,onNodesChange:Qn,onEdgesChange:br,noDragClassName:sr="nodrag",noWheelClassName:Ct="nowheel",noPanClassName:Gt="nopan",fitView:_t,fitViewOptions:le,connectOnClick:ve,attributionPosition:it,proOptions:Dt,defaultEdgeOptions:Jt,elevateNodesOnSelect:tn=!0,elevateEdgesOnSelect:Zn=!1,disableKeyboardA11y:mt=!1,autoPanOnConnect:nn,autoPanOnNodeDrag:Wt,autoPanSpeed:kr,connectionRadius:tt,isValidConnection:Ln,onError:$i,style:zr,id:mo,nodeDragThreshold:ai,connectionDragThreshold:Ts,viewport:ie,onViewportChange:Se,width:Pe,height:xt,colorMode:Lt="light",debug:qt,onScroll:zn,ariaLabelConfig:On,zIndexMode:q="basic",...pe},Oe){const Ee=mo||"1",et=u5(Lt),Nn=m.useCallback(kt=>{kt.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),zn==null||zn(kt)},[zn]);return i.jsx("div",{"data-testid":"rf__wrapper",...pe,onScroll:Nn,style:{...zr,...AW},ref:Oe,className:Jn(["react-flow",s,et]),id:mo,role:"application",children:i.jsxs(EW,{nodes:e,edges:t,width:Pe,height:xt,fitView:_t,fitViewOptions:le,minZoom:oe,maxZoom:ke,nodeOrigin:st,nodeExtent:be,zIndexMode:q,children:[i.jsx(c5,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:h,onConnectStart:y,onConnectEnd:k,onClickConnectStart:b,onClickConnectEnd:g,nodesDraggable:Be,autoPanOnNodeFocus:ot,nodesConnectable:yt,nodesFocusable:Te,edgesFocusable:gt,edgesReconnectable:xe,elementsSelectable:Fe,elevateNodesOnSelect:tn,elevateEdgesOnSelect:Zn,minZoom:oe,maxZoom:ke,nodeExtent:be,onNodesChange:Qn,onEdgesChange:br,snapToGrid:me,snapGrid:$e,connectionMode:Q,translateExtent:Ke,connectOnClick:ve,defaultEdgeOptions:Jt,fitView:_t,fitViewOptions:le,onNodesDelete:$,onEdgesDelete:L,onDelete:F,onNodeDragStart:P,onNodeDrag:I,onNodeDragStop:z,onSelectionDrag:K,onSelectionDragStart:M,onSelectionDragStop:H,onMove:d,onMoveStart:f,onMoveEnd:p,noPanClassName:Gt,nodeOrigin:st,rfId:Ee,autoPanOnConnect:nn,autoPanOnNodeDrag:Wt,autoPanSpeed:kr,onError:$i,connectionRadius:tt,isValidConnection:Ln,selectNodesOnDrag:_e,nodeDragThreshold:ai,connectionDragThreshold:Ts,onBeforeDelete:E,debug:qt,ariaLabelConfig:On,zIndexMode:q}),i.jsx(CW,{onInit:u,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:v,onNodeMouseMove:w,onNodeMouseLeave:N,onNodeContextMenu:j,onNodeDoubleClick:C,nodeTypes:o,edgeTypes:a,connectionLineType:V,connectionLineStyle:B,connectionLineComponent:se,connectionLineContainerStyle:ue,selectionKeyCode:ee,selectionOnDrag:te,selectionMode:ne,deleteKeyCode:G,multiSelectionKeyCode:ce,panActivationKeyCode:Z,zoomActivationKeyCode:de,onlyRenderVisibleElements:Ce,defaultViewport:lt,translateExtent:Ke,minZoom:oe,maxZoom:ke,preventScrolling:Ue,zoomOnScroll:Qt,zoomOnPinch:jt,zoomOnDoubleClick:Re,panOnScroll:yn,panOnScrollSpeed:on,panOnScrollMode:re,panOnDrag:Je,onPaneClick:Ze,onPaneMouseEnter:Tt,onPaneMouseMove:At,onPaneMouseLeave:Vn,onPaneScroll:Sn,onPaneContextMenu:xr,paneClickDistance:wn,nodeClickDistance:Xn,onSelectionContextMenu:D,onSelectionStart:T,onSelectionEnd:W,onReconnect:hr,onReconnectStart:ts,onReconnectEnd:Ar,onEdgeContextMenu:gs,onEdgeDoubleClick:ys,onEdgeMouseEnter:cn,onEdgeMouseMove:rr,onEdgeMouseLeave:Pr,reconnectRadius:dn,defaultMarkerColor:Ht,noDragClassName:sr,noWheelClassName:Ct,noPanClassName:Gt,rfId:Ee,disableKeyboardA11y:mt,nodeExtent:be,viewport:ie,onViewportChange:Se}),i.jsx(i5,{onSelectionChange:O}),Kn,i.jsx(e5,{proOptions:Dt,position:it}),i.jsx(Z4,{rfId:Ee,disableKeyboardA11y:mt})]})})}var gR=qI(PW);function IW(){const e=gn();return m.useCallback(t=>{const{domNode:n,updateNodeInternals:r}=e.getState(),s=Array.isArray(t)?t:[t],o=new Map;s.forEach(a=>{const l=n==null?void 0:n.querySelector(`.react-flow__node[data-id="${a}"]`);l&&o.set(a,{id:a,nodeElement:l,force:!0})}),requestAnimationFrame(()=>r(o,{triggerFitView:!1}))},[])}function RW(e){const[t,n]=m.useState(e),r=m.useCallback(s=>n(o=>ad(s,o)),[]);return[t,n,r]}function TW(e){const[t,n]=m.useState(e),r=m.useCallback(s=>n(o=>Qh(s,o)),[]);return[t,n,r]}function MW({dimensions:e,lineWidth:t,variant:n,className:r}){return i.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Jn(["react-flow__background-pattern",n,r])})}function $W({radius:e,className:t}){return i.jsx("circle",{cx:e,cy:e,r:e,className:Jn(["react-flow__background-pattern","dots",t])})}var Yo;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Yo||(Yo={}));const LW={[Yo.Dots]:1,[Yo.Lines]:1,[Yo.Cross]:6},OW=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function yR({id:e,variant:t=Yo.Dots,gap:n=20,size:r,lineWidth:s=1,offset:o=0,color:a,bgColor:l,style:c,className:u,patternClassName:d}){const f=m.useRef(null),{transform:p,patternId:h}=Bt(OW,_n),y=r||LW[t],k=t===Yo.Dots,b=t===Yo.Cross,g=Array.isArray(n)?n:[n,n],v=[g[0]*p[2]||1,g[1]*p[2]||1],w=y*p[2],N=Array.isArray(o)?o:[o,o],j=b?[w,w]:v,C=[N[0]*p[2]||1+j[0]/2,N[1]*p[2]||1+j[1]/2],P=`${h}${e||""}`;return i.jsxs("svg",{className:Jn(["react-flow__background",u]),style:{...c,...eg,"--xy-background-color-props":l,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[i.jsx("pattern",{id:P,x:p[0]%v[0],y:p[1]%v[1],width:v[0],height:v[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${C[0]},-${C[1]})`,children:k?i.jsx($W,{radius:w/2,className:d}):i.jsx(MW,{dimensions:j,lineWidth:s,variant:t,className:d})}),i.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${P})`})]})}yR.displayName="Background";const wR=m.memo(yR);function DW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:i.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function FW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:i.jsx("path",{d:"M0 0h32v4.2H0z"})})}function zW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:i.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function BW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:i.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function HW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:i.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Cp({children:e,className:t,...n}){return i.jsx("button",{type:"button",className:Jn(["react-flow__controls-button",t]),...n,children:e})}const WW=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function xR({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:o,onZoomOut:a,onFitView:l,onInteractiveChange:c,className:u,children:d,position:f="bottom-left",orientation:p="vertical","aria-label":h}){const y=gn(),{isInteractive:k,minZoomReached:b,maxZoomReached:g,ariaLabelConfig:v}=Bt(WW,_n),{zoomIn:w,zoomOut:N,fitView:j}=Fc(),C=()=>{w(),o==null||o()},P=()=>{N(),a==null||a()},I=()=>{j(s),l==null||l()},z=()=>{y.setState({nodesDraggable:!k,nodesConnectable:!k,elementsSelectable:!k}),c==null||c(!k)},$=p==="horizontal"?"horizontal":"vertical";return i.jsxs(Zm,{className:Jn(["react-flow__controls",$,u]),position:f,style:e,"data-testid":"rf__controls","aria-label":h??v["controls.ariaLabel"],children:[t&&i.jsxs(i.Fragment,{children:[i.jsx(Cp,{onClick:C,className:"react-flow__controls-zoomin",title:v["controls.zoomIn.ariaLabel"],"aria-label":v["controls.zoomIn.ariaLabel"],disabled:g,children:i.jsx(DW,{})}),i.jsx(Cp,{onClick:P,className:"react-flow__controls-zoomout",title:v["controls.zoomOut.ariaLabel"],"aria-label":v["controls.zoomOut.ariaLabel"],disabled:b,children:i.jsx(FW,{})})]}),n&&i.jsx(Cp,{className:"react-flow__controls-fitview",onClick:I,title:v["controls.fitView.ariaLabel"],"aria-label":v["controls.fitView.ariaLabel"],children:i.jsx(zW,{})}),r&&i.jsx(Cp,{className:"react-flow__controls-interactive",onClick:z,title:v["controls.interactive.ariaLabel"],"aria-label":v["controls.interactive.ariaLabel"],children:k?i.jsx(HW,{}):i.jsx(BW,{})}),d]})}xR.displayName="Controls";m.memo(xR);function VW({id:e,x:t,y:n,width:r,height:s,style:o,color:a,strokeColor:l,strokeWidth:c,className:u,borderRadius:d,shapeRendering:f,selected:p,onClick:h}){const{background:y,backgroundColor:k}=o||{},b=a||y||k;return i.jsx("rect",{className:Jn(["react-flow__minimap-node",{selected:p},u]),x:t,y:n,rx:d,ry:d,width:r,height:s,style:{fill:b,stroke:l,strokeWidth:c},shapeRendering:f,onClick:h?g=>h(g,e):void 0})}const KW=m.memo(VW),qW=e=>e.nodes.map(t=>t.id),By=e=>e instanceof Function?e:()=>e;function UW({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s,nodeComponent:o=KW,onClick:a}){const l=Bt(qW,_n),c=By(t),u=By(e),d=By(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return i.jsx(i.Fragment,{children:l.map(p=>i.jsx(GW,{id:p,nodeColorFunc:c,nodeStrokeColorFunc:u,nodeClassNameFunc:d,nodeBorderRadius:r,nodeStrokeWidth:s,NodeComponent:o,onClick:a,shapeRendering:f},p))})}function YW({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:r,nodeBorderRadius:s,nodeStrokeWidth:o,shapeRendering:a,NodeComponent:l,onClick:c}){const{node:u,x:d,y:f,width:p,height:h}=Bt(y=>{const k=y.nodeLookup.get(e);if(!k)return{node:void 0,x:0,y:0,width:0,height:0};const b=k.internals.userNode,{x:g,y:v}=k.internals.positionAbsolute,{width:w,height:N}=fo(b);return{node:b,x:g,y:v,width:w,height:N}},_n);return!u||u.hidden||!mI(u)?null:i.jsx(l,{x:d,y:f,width:p,height:h,style:u.style,selected:!!u.selected,className:r(u),color:t(u),borderRadius:s,strokeColor:n(u),strokeWidth:o,shapeRendering:a,onClick:c,id:u.id})}const GW=m.memo(YW);var JW=m.memo(UW);const XW=200,QW=150,ZW=e=>!e.hidden,e6=e=>{const t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?hI(df(e.nodeLookup,{filter:ZW}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},t6="react-flow__minimap-desc";function bR({style:e,className:t,nodeStrokeColor:n,nodeColor:r,nodeClassName:s="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:l,bgColor:c,maskColor:u,maskStrokeColor:d,maskStrokeWidth:f,position:p="bottom-right",onClick:h,onNodeClick:y,pannable:k=!1,zoomable:b=!1,ariaLabel:g,inversePan:v,zoomStep:w=1,offsetScale:N=5}){const j=gn(),C=m.useRef(null),{boundingRect:P,viewBB:I,rfId:z,panZoom:$,translateExtent:L,flowWidth:F,flowHeight:O,ariaLabelConfig:M}=Bt(e6,_n),K=(e==null?void 0:e.width)??XW,H=(e==null?void 0:e.height)??QW,D=P.width/K,T=P.height/H,W=Math.max(D,T),E=W*K,Q=W*H,V=N*W,B=P.x-(E-P.width)/2-V,se=P.y-(Q-P.height)/2-V,ue=E+V*2,G=Q+V*2,ee=`${t6}-${z}`,te=m.useRef(0),ne=m.useRef();te.current=W,m.useEffect(()=>{if(C.current&&$)return ne.current=a4({domNode:C.current,panZoom:$,getTransform:()=>j.getState().transform,getViewScale:()=>te.current}),()=>{var me;(me=ne.current)==null||me.destroy()}},[$]),m.useEffect(()=>{var me;(me=ne.current)==null||me.update({translateExtent:L,width:F,height:O,inversePan:v,pannable:k,zoomStep:w,zoomable:b})},[k,b,v,w,L,F,O]);const Z=h?me=>{var _e;const[$e,Ce]=((_e=ne.current)==null?void 0:_e.pointer(me))||[0,0];h(me,{x:$e,y:Ce})}:void 0,ce=y?m.useCallback((me,$e)=>{const Ce=j.getState().nodeLookup.get($e).internals.userNode;y(me,Ce)},[]):void 0,de=g??M["minimap.ariaLabel"];return i.jsx(Zm,{position:p,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-stroke-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*W:void 0,"--xy-minimap-node-background-color-props":typeof r=="string"?r:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof a=="number"?a:void 0},className:Jn(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:i.jsxs("svg",{width:K,height:H,viewBox:`${B} ${se} ${ue} ${G}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":ee,ref:C,onClick:Z,children:[de&&i.jsx("title",{id:ee,children:de}),i.jsx(JW,{onClick:ce,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:s,nodeStrokeWidth:a,nodeComponent:l}),i.jsx("path",{className:"react-flow__minimap-mask",d:`M${B-V},${se-V}h${ue+V*2}v${G+V*2}h${-ue-V*2}z
65
+ `)),d=u.reduce((f,p)=>f.concat(...p),[]);return[u,d]}return[[],[]]},[e]);return m.useEffect(()=>{const c=(t==null?void 0:t.target)??zj,u=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const d=h=>{var b,g;if(s.current=h.ctrlKey||h.metaKey||h.shiftKey||h.altKey,(!s.current||s.current&&!u)&&wI(h))return!1;const k=Hj(h.code,l);if(o.current.add(h[k]),Bj(a,o.current,!1)){const v=((g=(b=h.composedPath)==null?void 0:b.call(h))==null?void 0:g[0])||h.target,w=(v==null?void 0:v.nodeName)==="BUTTON"||(v==null?void 0:v.nodeName)==="A";t.preventDefault!==!1&&(s.current||!w)&&h.preventDefault(),r(!0)}},f=h=>{const y=Hj(h.code,l);Bj(a,o.current,!0)?(r(!1),o.current.clear()):o.current.delete(h[y]),h.key==="Meta"&&o.current.clear(),s.current=!1},p=()=>{o.current.clear(),r(!1)};return c==null||c.addEventListener("keydown",d),c==null||c.addEventListener("keyup",f),window.addEventListener("blur",p),window.addEventListener("contextmenu",p),()=>{c==null||c.removeEventListener("keydown",d),c==null||c.removeEventListener("keyup",f),window.removeEventListener("blur",p),window.removeEventListener("contextmenu",p)}}},[e,r]),n}function Bj(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function Hj(e,t){return t.includes(e)?"code":"key"}const d5=()=>{const e=gn();return m.useMemo(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:r}=e.getState();return r?r.scaleTo(t,n):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[r,s,o],panZoom:a}=e.getState();return a?(await a.setViewport({x:t.x??r,y:t.y??s,zoom:t.zoom??o},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,r]=e.getState().transform;return{x:t,y:n,zoom:r}},setCenter:async(t,n,r)=>e.getState().setCenter(t,n,r),fitBounds:async(t,n)=>{const{width:r,height:s,minZoom:o,maxZoom:a,panZoom:l}=e.getState(),c=Ik(t,r,s,o,a,(n==null?void 0:n.padding)??.1);return l?(await l.setViewport(c,{duration:n==null?void 0:n.duration,ease:n==null?void 0:n.ease,interpolate:n==null?void 0:n.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:r,snapGrid:s,snapToGrid:o,domNode:a}=e.getState();if(!a)return t;const{x:l,y:c}=a.getBoundingClientRect(),u={x:t.x-l,y:t.y-c},d=n.snapGrid??s,f=n.snapToGrid??o;return pf(u,r,f,d)},flowToScreenPosition:t=>{const{transform:n,domNode:r}=e.getState();if(!r)return t;const{x:s,y:o}=r.getBoundingClientRect(),a=Xh(t,n);return{x:a.x+s,y:a.y+o}}}),[])};function KI(e,t){const n=[],r=new Map,s=[];for(const o of e)if(o.type==="add"){s.push(o);continue}else if(o.type==="remove"||o.type==="replace")r.set(o.id,[o]);else{const a=r.get(o.id);a?a.push(o):r.set(o.id,[o])}for(const o of t){const a=r.get(o.id);if(!a){n.push(o);continue}if(a[0].type==="remove")continue;if(a[0].type==="replace"){n.push({...a[0].item});continue}const l={...o};for(const c of a)f5(c,l);n.push(l)}return s.length&&s.forEach(o=>{o.index!==void 0?n.splice(o.index,0,{...o.item}):n.push({...o.item})}),n}function f5(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function ad(e,t){return KI(e,t)}function Qh(e,t){return KI(e,t)}function Na(e,t){return{id:e,type:"select",selected:t}}function ec(e,t=new Set,n=!1){const r=[];for(const[s,o]of e){const a=t.has(s);!(o.selected===void 0&&!a)&&o.selected!==a&&(n&&(o.selected=a),r.push(Na(o.id,a)))}return r}function Wj({items:e=[],lookup:t}){var s;const n=[],r=new Map(e.map(o=>[o.id,o]));for(const[o,a]of e.entries()){const l=t.get(a.id),c=((s=l==null?void 0:l.internals)==null?void 0:s.userNode)??l;c!==void 0&&c!==a&&n.push({id:a.id,item:a,type:"replace"}),c===void 0&&n.push({item:a,type:"add",index:o})}for(const[o]of t)r.get(o)===void 0&&n.push({id:o,type:"remove"});return n}function Vj(e){return{id:e.id,type:"remove"}}const Kj=e=>NH(e),p5=e=>uI(e);function qI(e){return m.forwardRef(e)}function qj(e){const[t,n]=m.useState(BigInt(0)),[r]=m.useState(()=>h5(()=>n(s=>s+BigInt(1))));return Fx(()=>{const s=r.get();s.length&&(e(s),r.reset())},[t]),r}function h5(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const UI=m.createContext(null);function m5({children:e}){const t=gn(),n=m.useCallback(l=>{const{nodes:c=[],setNodes:u,hasDefaultNodes:d,onNodesChange:f,nodeLookup:p,fitViewQueued:h,onNodesChangeMiddlewareMap:y}=t.getState();let k=c;for(const g of l)k=typeof g=="function"?g(k):g;let b=Wj({items:k,lookup:p});for(const g of y.values())b=g(b);d&&u(k),b.length>0?f==null||f(b):h&&window.requestAnimationFrame(()=>{const{fitViewQueued:g,nodes:v,setNodes:w}=t.getState();g&&w(v)})},[]),r=qj(n),s=m.useCallback(l=>{const{edges:c=[],setEdges:u,hasDefaultEdges:d,onEdgesChange:f,edgeLookup:p}=t.getState();let h=c;for(const y of l)h=typeof y=="function"?y(h):y;d?u(h):f&&f(Wj({items:h,lookup:p}))},[]),o=qj(s),a=m.useMemo(()=>({nodeQueue:r,edgeQueue:o}),[]);return i.jsx(UI.Provider,{value:a,children:e})}function g5(){const e=m.useContext(UI);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const y5=e=>!!e.panZoom;function Fc(){const e=d5(),t=gn(),n=g5(),r=Bt(y5),s=m.useMemo(()=>{const o=f=>t.getState().nodeLookup.get(f),a=f=>{n.nodeQueue.push(f)},l=f=>{n.edgeQueue.push(f)},c=f=>{var g,v;const{nodeLookup:p,nodeOrigin:h}=t.getState(),y=Kj(f)?f:p.get(f.id),k=y.parentId?gI(y.position,y.measured,y.parentId,p,h):y.position,b={...y,position:k,width:((g=y.measured)==null?void 0:g.width)??y.width,height:((v=y.measured)==null?void 0:v.height)??y.height};return Ec(b)},u=(f,p,h={replace:!1})=>{a(y=>y.map(k=>{if(k.id===f){const b=typeof p=="function"?p(k):p;return h.replace&&Kj(b)?b:{...k,...b}}return k}))},d=(f,p,h={replace:!1})=>{l(y=>y.map(k=>{if(k.id===f){const b=typeof p=="function"?p(k):p;return h.replace&&p5(b)?b:{...k,...b}}return k}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>{var p;return(p=o(f))==null?void 0:p.internals.userNode},getInternalNode:o,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(p=>({...p}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:a,setEdges:l,addNodes:f=>{const p=Array.isArray(f)?f:[f];n.nodeQueue.push(h=>[...h,...p])},addEdges:f=>{const p=Array.isArray(f)?f:[f];n.edgeQueue.push(h=>[...h,...p])},toObject:()=>{const{nodes:f=[],edges:p=[],transform:h}=t.getState(),[y,k,b]=h;return{nodes:f.map(g=>({...g})),edges:p.map(g=>({...g})),viewport:{x:y,y:k,zoom:b}}},deleteElements:async({nodes:f=[],edges:p=[]})=>{const{nodes:h,edges:y,onNodesDelete:k,onEdgesDelete:b,triggerNodeChanges:g,triggerEdgeChanges:v,onDelete:w,onBeforeDelete:N}=t.getState(),{nodes:j,edges:C}=await AH({nodesToRemove:f,edgesToRemove:p,nodes:h,edges:y,onBeforeDelete:N}),P=C.length>0,I=j.length>0;if(P){const z=C.map(Vj);b==null||b(C),v(z)}if(I){const z=j.map(Vj);k==null||k(j),g(z)}return(I||P)&&(w==null||w({nodes:j,edges:C})),{deletedNodes:j,deletedEdges:C}},getIntersectingNodes:(f,p=!0,h)=>{const y=kj(f),k=y?f:c(f),b=h!==void 0;return k?(h||t.getState().nodes).filter(g=>{const v=t.getState().nodeLookup.get(g.id);if(v&&!y&&(g.id===f.id||!v.internals.positionAbsolute))return!1;const w=Ec(b?g:v),N=Dd(w,k);return p&&N>0||N>=w.width*w.height||N>=k.width*k.height}):[]},isNodeIntersecting:(f,p,h=!0)=>{const k=kj(f)?f:c(f);if(!k)return!1;const b=Dd(k,p);return h&&b>0||b>=p.width*p.height||b>=k.width*k.height},updateNode:u,updateNodeData:(f,p,h={replace:!1})=>{u(f,y=>{const k=typeof p=="function"?p(y):p;return h.replace?{...y,data:k}:{...y,data:{...y.data,...k}}},h)},updateEdge:d,updateEdgeData:(f,p,h={replace:!1})=>{d(f,y=>{const k=typeof p=="function"?p(y):p;return h.replace?{...y,data:k}:{...y,data:{...y.data,...k}}},h)},getNodesBounds:f=>{const{nodeLookup:p,nodeOrigin:h}=t.getState();return jH(f,{nodeLookup:p,nodeOrigin:h})},getHandleConnections:({type:f,id:p,nodeId:h})=>{var y;return Array.from(((y=t.getState().connectionLookup.get(`${h}-${f}${p?`-${p}`:""}`))==null?void 0:y.values())??[])},getNodeConnections:({type:f,handleId:p,nodeId:h})=>{var y;return Array.from(((y=t.getState().connectionLookup.get(`${h}${f?p?`-${f}-${p}`:`-${f}`:""}`))==null?void 0:y.values())??[])},fitView:async f=>{const p=t.getState().fitViewResolver??TH();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:p}),n.nodeQueue.push(h=>[...h]),p.promise}}},[]);return m.useMemo(()=>({...s,...e,viewportInitialized:r}),[r])}const Uj=e=>e.selected,w5=typeof window<"u"?window:void 0;function x5({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=gn(),{deleteElements:r}=Fc(),s=zd(e,{actInsideInputWithModifier:!1}),o=zd(t,{target:w5});m.useEffect(()=>{if(s){const{edges:a,nodes:l}=n.getState();r({nodes:l.filter(Uj),edges:a.filter(Uj)}),n.setState({nodesSelectionActive:!1})}},[s]),m.useEffect(()=>{n.setState({multiSelectionActive:o})},[o])}function b5(e){const t=gn();m.useEffect(()=>{const n=()=>{var s,o,a,l;if(!e.current||!(((o=(s=e.current).checkVisibility)==null?void 0:o.call(s))??!0))return!1;const r=Rk(e.current);(r.height===0||r.width===0)&&((l=(a=t.getState()).onError)==null||l.call(a,"004",Ii.error004())),t.setState({width:r.width||500,height:r.height||500})};if(e.current){n(),window.addEventListener("resize",n);const r=new ResizeObserver(()=>n());return r.observe(e.current),()=>{window.removeEventListener("resize",n),r&&e.current&&r.unobserve(e.current)}}},[])}const eg={position:"absolute",width:"100%",height:"100%",top:0,left:0},k5=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function v5({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:r=!1,panOnScrollSpeed:s=.5,panOnScrollMode:o=Fa.Free,zoomOnDoubleClick:a=!0,panOnDrag:l=!0,defaultViewport:c,translateExtent:u,minZoom:d,maxZoom:f,zoomActivationKeyCode:p,preventScrolling:h=!0,children:y,noWheelClassName:k,noPanClassName:b,onViewportChange:g,isControlledViewport:v,paneClickDistance:w,selectionOnDrag:N}){const j=gn(),C=m.useRef(null),{userSelectionActive:P,lib:I,connectionInProgress:z}=Bt(k5,_n),$=zd(p),L=m.useRef();b5(C);const F=m.useCallback(O=>{g==null||g({x:O[0],y:O[1],zoom:O[2]}),v||j.setState({transform:O})},[g,v]);return m.useEffect(()=>{if(C.current){L.current=m4({domNode:C.current,minZoom:d,maxZoom:f,translateExtent:u,viewport:c,onDraggingChange:H=>j.setState(D=>D.paneDragging===H?D:{paneDragging:H}),onPanZoomStart:(H,D)=>{const{onViewportChangeStart:T,onMoveStart:W}=j.getState();W==null||W(H,D),T==null||T(D)},onPanZoom:(H,D)=>{const{onViewportChange:T,onMove:W}=j.getState();W==null||W(H,D),T==null||T(D)},onPanZoomEnd:(H,D)=>{const{onViewportChangeEnd:T,onMoveEnd:W}=j.getState();W==null||W(H,D),T==null||T(D)}});const{x:O,y:M,zoom:K}=L.current.getViewport();return j.setState({panZoom:L.current,transform:[O,M,K],domNode:C.current.closest(".react-flow")}),()=>{var H;(H=L.current)==null||H.destroy()}}},[]),m.useEffect(()=>{var O;(O=L.current)==null||O.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:r,panOnScrollSpeed:s,panOnScrollMode:o,zoomOnDoubleClick:a,panOnDrag:l,zoomActivationKeyPressed:$,preventScrolling:h,noPanClassName:b,userSelectionActive:P,noWheelClassName:k,lib:I,onTransformChange:F,connectionInProgress:z,selectionOnDrag:N,paneClickDistance:w})},[e,t,n,r,s,o,a,l,$,h,b,P,k,I,F,z,N,w]),i.jsx("div",{className:"react-flow__renderer",ref:C,style:eg,children:y})}const S5=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function N5(){const{userSelectionActive:e,userSelectionRect:t}=Bt(S5,_n);return e&&t?i.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const zy=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},j5=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function C5({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Od.Full,panOnDrag:r,paneClickDistance:s,selectionOnDrag:o,onSelectionStart:a,onSelectionEnd:l,onPaneClick:c,onPaneContextMenu:u,onPaneScroll:d,onPaneMouseEnter:f,onPaneMouseMove:p,onPaneMouseLeave:h,children:y}){const k=gn(),{userSelectionActive:b,elementsSelectable:g,dragging:v,connectionInProgress:w}=Bt(j5,_n),N=g&&(e||b),j=m.useRef(null),C=m.useRef(),P=m.useRef(new Set),I=m.useRef(new Set),z=m.useRef(!1),$=T=>{if(z.current||w){z.current=!1;return}c==null||c(T),k.getState().resetSelectedElements(),k.setState({nodesSelectionActive:!1})},L=T=>{if(Array.isArray(r)&&(r!=null&&r.includes(2))){T.preventDefault();return}u==null||u(T)},F=d?T=>d(T):void 0,O=T=>{z.current&&(T.stopPropagation(),z.current=!1)},M=T=>{var ue,G;const{domNode:W}=k.getState();if(C.current=W==null?void 0:W.getBoundingClientRect(),!C.current)return;const E=T.target===j.current;if(!E&&!!T.target.closest(".nokey")||!e||!(o&&E||t)||T.button!==0||!T.isPrimary)return;(G=(ue=T.target)==null?void 0:ue.setPointerCapture)==null||G.call(ue,T.pointerId),z.current=!1;const{x:B,y:se}=Xs(T.nativeEvent,C.current);k.setState({userSelectionRect:{width:0,height:0,startX:B,startY:se,x:B,y:se}}),E||(T.stopPropagation(),T.preventDefault())},K=T=>{const{userSelectionRect:W,transform:E,nodeLookup:Q,edgeLookup:V,connectionLookup:B,triggerNodeChanges:se,triggerEdgeChanges:ue,defaultEdgeOptions:G,resetSelectedElements:ee}=k.getState();if(!C.current||!W)return;const{x:te,y:ne}=Xs(T.nativeEvent,C.current),{startX:Z,startY:ce}=W;if(!z.current){const _e=t?0:s;if(Math.hypot(te-Z,ne-ce)<=_e)return;ee(),a==null||a(T)}z.current=!0;const de={startX:Z,startY:ce,x:te<Z?te:Z,y:ne<ce?ne:ce,width:Math.abs(te-Z),height:Math.abs(ne-ce)},me=P.current,$e=I.current;P.current=new Set(Pk(Q,de,E,n===Od.Partial,!0).map(_e=>_e.id)),I.current=new Set;const Ce=(G==null?void 0:G.selectable)??!0;for(const _e of P.current){const Be=B.get(_e);if(Be)for(const{edgeId:ot}of Be.values()){const yt=V.get(ot);yt&&(yt.selectable??Ce)&&I.current.add(ot)}}if(!vj(me,P.current)){const _e=ec(Q,P.current,!0);se(_e)}if(!vj($e,I.current)){const _e=ec(V,I.current);ue(_e)}k.setState({userSelectionRect:de,userSelectionActive:!0,nodesSelectionActive:!1})},H=T=>{var W,E;T.button===0&&((E=(W=T.target)==null?void 0:W.releasePointerCapture)==null||E.call(W,T.pointerId),!b&&T.target===j.current&&k.getState().userSelectionRect&&($==null||$(T)),k.setState({userSelectionActive:!1,userSelectionRect:null}),z.current&&(l==null||l(T),k.setState({nodesSelectionActive:P.current.size>0})))},D=r===!0||Array.isArray(r)&&r.includes(0);return i.jsxs("div",{className:Jn(["react-flow__pane",{draggable:D,dragging:v,selection:e}]),onClick:N?void 0:zy($,j),onContextMenu:zy(L,j),onWheel:zy(F,j),onPointerEnter:N?void 0:f,onPointerMove:N?K:p,onPointerUp:N?H:void 0,onPointerDownCapture:N?M:void 0,onClickCapture:N?O:void 0,onPointerLeave:h,ref:j,style:eg,children:[y,i.jsx(N5,{})]})}function zx({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:o,multiSelectionActive:a,nodeLookup:l,onError:c}=t.getState(),u=l.get(e);if(!u){c==null||c("012",Ii.error012(e));return}t.setState({nodesSelectionActive:!1}),u.selected?(n||u.selected&&a)&&(o({nodes:[u],edges:[]}),requestAnimationFrame(()=>{var d;return(d=r==null?void 0:r.current)==null?void 0:d.blur()})):s([e])}function YI({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:o,nodeClickDistance:a}){const l=gn(),[c,u]=m.useState(!1),d=m.useRef();return m.useEffect(()=>{d.current=t4({getStoreItems:()=>l.getState(),onNodeMouseDown:f=>{zx({id:f,store:l,nodeRef:e})},onDragStart:()=>{u(!0)},onDragStop:()=>{u(!1)}})},[]),m.useEffect(()=>{if(!(t||!e.current||!d.current))return d.current.update({noDragClassName:n,handleSelector:r,domNode:e.current,isSelectable:o,nodeId:s,nodeClickDistance:a}),()=>{var f;(f=d.current)==null||f.destroy()}},[n,r,t,o,e,s,a]),c}const _5=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function GI(){const e=gn();return m.useCallback(n=>{const{nodeExtent:r,snapToGrid:s,snapGrid:o,nodesDraggable:a,onError:l,updateNodePositions:c,nodeLookup:u,nodeOrigin:d}=e.getState(),f=new Map,p=_5(a),h=s?o[0]:5,y=s?o[1]:5,k=n.direction.x*h*n.factor,b=n.direction.y*y*n.factor;for(const[,g]of u){if(!p(g))continue;let v={x:g.internals.positionAbsolute.x+k,y:g.internals.positionAbsolute.y+b};s&&(v=ff(v,o));const{position:w,positionAbsolute:N}=dI({nodeId:g.id,nextPosition:v,nodeLookup:u,nodeExtent:r,nodeOrigin:d,onError:l});g.position=w,g.internals.positionAbsolute=N,f.set(g.id,g)}c(f)},[])}const Dk=m.createContext(null),E5=Dk.Provider;Dk.Consumer;const JI=()=>m.useContext(Dk),A5=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),P5=(e,t,n)=>r=>{const{connectionClickStartHandle:s,connectionMode:o,connection:a}=r,{fromHandle:l,toHandle:c,isValid:u}=a,d=(c==null?void 0:c.nodeId)===e&&(c==null?void 0:c.id)===t&&(c==null?void 0:c.type)===n;return{connectingFrom:(l==null?void 0:l.nodeId)===e&&(l==null?void 0:l.id)===t&&(l==null?void 0:l.type)===n,connectingTo:d,clickConnecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.id)===t&&(s==null?void 0:s.type)===n,isPossibleEndHandle:o===Cc.Strict?(l==null?void 0:l.type)!==n:e!==(l==null?void 0:l.nodeId)||t!==(l==null?void 0:l.id),connectionInProcess:!!l,clickConnectionInProcess:!!s,valid:d&&u}};function I5({type:e="source",position:t=qe.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:o=!0,id:a,onConnect:l,children:c,className:u,onMouseDown:d,onTouchStart:f,...p},h){var K,H;const y=a||null,k=e==="target",b=gn(),g=JI(),{connectOnClick:v,noPanClassName:w,rfId:N}=Bt(A5,_n),{connectingFrom:j,connectingTo:C,clickConnecting:P,isPossibleEndHandle:I,connectionInProcess:z,clickConnectionInProcess:$,valid:L}=Bt(P5(g,y,e),_n);g||(H=(K=b.getState()).onError)==null||H.call(K,"010",Ii.error010());const F=D=>{const{defaultEdgeOptions:T,onConnect:W,hasDefaultEdges:E}=b.getState(),Q={...T,...D};if(E){const{edges:V,setEdges:B}=b.getState();B(uh(Q,V))}W==null||W(Q),l==null||l(Q)},O=D=>{if(!g)return;const T=xI(D.nativeEvent);if(s&&(T&&D.button===0||!T)){const W=b.getState();Dx.onPointerDown(D.nativeEvent,{handleDomNode:D.currentTarget,autoPanOnConnect:W.autoPanOnConnect,connectionMode:W.connectionMode,connectionRadius:W.connectionRadius,domNode:W.domNode,nodeLookup:W.nodeLookup,lib:W.lib,isTarget:k,handleId:y,nodeId:g,flowId:W.rfId,panBy:W.panBy,cancelConnection:W.cancelConnection,onConnectStart:W.onConnectStart,onConnectEnd:(...E)=>{var Q,V;return(V=(Q=b.getState()).onConnectEnd)==null?void 0:V.call(Q,...E)},updateConnection:W.updateConnection,onConnect:F,isValidConnection:n||((...E)=>{var Q,V;return((V=(Q=b.getState()).isValidConnection)==null?void 0:V.call(Q,...E))??!0}),getTransform:()=>b.getState().transform,getFromHandle:()=>b.getState().connection.fromHandle,autoPanSpeed:W.autoPanSpeed,dragThreshold:W.connectionDragThreshold})}T?d==null||d(D):f==null||f(D)},M=D=>{const{onClickConnectStart:T,onClickConnectEnd:W,connectionClickStartHandle:E,connectionMode:Q,isValidConnection:V,lib:B,rfId:se,nodeLookup:ue,connection:G}=b.getState();if(!g||!E&&!s)return;if(!E){T==null||T(D.nativeEvent,{nodeId:g,handleId:y,handleType:e}),b.setState({connectionClickStartHandle:{nodeId:g,type:e,id:y}});return}const ee=yI(D.target),te=n||V,{connection:ne,isValid:Z}=Dx.isValid(D.nativeEvent,{handle:{nodeId:g,id:y,type:e},connectionMode:Q,fromNodeId:E.nodeId,fromHandleId:E.id||null,fromType:E.type,isValidConnection:te,flowId:se,doc:ee,lib:B,nodeLookup:ue});Z&&ne&&F(ne);const ce=structuredClone(G);delete ce.inProgress,ce.toPosition=ce.toHandle?ce.toHandle.position:null,W==null||W(D,ce),b.setState({connectionClickStartHandle:null})};return i.jsx("div",{"data-handleid":y,"data-nodeid":g,"data-handlepos":t,"data-id":`${N}-${g}-${y}-${e}`,className:Jn(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",w,u,{source:!k,target:k,connectable:r,connectablestart:s,connectableend:o,clickconnecting:P,connectingfrom:j,connectingto:C,valid:L,connectionindicator:r&&(!z||I)&&(z||$?o:s)}]),onMouseDown:O,onTouchStart:O,onClick:v?M:void 0,ref:h,...p,children:c})}const Gn=m.memo(qI(I5));function R5({data:e,isConnectable:t,sourcePosition:n=qe.Bottom}){return i.jsxs(i.Fragment,{children:[e==null?void 0:e.label,i.jsx(Gn,{type:"source",position:n,isConnectable:t})]})}function T5({data:e,isConnectable:t,targetPosition:n=qe.Top,sourcePosition:r=qe.Bottom}){return i.jsxs(i.Fragment,{children:[i.jsx(Gn,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,i.jsx(Gn,{type:"source",position:r,isConnectable:t})]})}function M5(){return null}function $5({data:e,isConnectable:t,targetPosition:n=qe.Top}){return i.jsxs(i.Fragment,{children:[i.jsx(Gn,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label]})}const Zh={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},Yj={input:R5,default:T5,output:$5,group:M5};function L5(e){var t,n,r,s;return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??((t=e.style)==null?void 0:t.width),height:e.height??e.initialHeight??((n=e.style)==null?void 0:n.height)}:{width:e.width??((r=e.style)==null?void 0:r.width),height:e.height??((s=e.style)==null?void 0:s.height)}}const O5=e=>{const{width:t,height:n,x:r,y:s}=df(e.nodeLookup,{filter:o=>!!o.selected});return{width:Js(t)?t:null,height:Js(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${s}px)`}};function D5({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=gn(),{width:s,height:o,transformString:a,userSelectionActive:l}=Bt(O5,_n),c=GI(),u=m.useRef(null);m.useEffect(()=>{var h;n||(h=u.current)==null||h.focus({preventScroll:!0})},[n]);const d=!l&&s!==null&&o!==null;if(YI({nodeRef:u,disabled:!d}),!d)return null;const f=e?h=>{const y=r.getState().nodes.filter(k=>k.selected);e(h,y)}:void 0,p=h=>{Object.prototype.hasOwnProperty.call(Zh,h.key)&&(h.preventDefault(),c({direction:Zh[h.key],factor:h.shiftKey?4:1}))};return i.jsx("div",{className:Jn(["react-flow__nodesselection","react-flow__container",t]),style:{transform:a},children:i.jsx("div",{ref:u,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:p,style:{width:s,height:o}})})}const Gj=typeof window<"u"?window:void 0,F5=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function XI({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:a,paneClickDistance:l,deleteKeyCode:c,selectionKeyCode:u,selectionOnDrag:d,selectionMode:f,onSelectionStart:p,onSelectionEnd:h,multiSelectionKeyCode:y,panActivationKeyCode:k,zoomActivationKeyCode:b,elementsSelectable:g,zoomOnScroll:v,zoomOnPinch:w,panOnScroll:N,panOnScrollSpeed:j,panOnScrollMode:C,zoomOnDoubleClick:P,panOnDrag:I,defaultViewport:z,translateExtent:$,minZoom:L,maxZoom:F,preventScrolling:O,onSelectionContextMenu:M,noWheelClassName:K,noPanClassName:H,disableKeyboardA11y:D,onViewportChange:T,isControlledViewport:W}){const{nodesSelectionActive:E,userSelectionActive:Q}=Bt(F5,_n),V=zd(u,{target:Gj}),B=zd(k,{target:Gj}),se=B||I,ue=B||N,G=d&&se!==!0,ee=V||Q||G;return x5({deleteKeyCode:c,multiSelectionKeyCode:y}),i.jsx(v5,{onPaneContextMenu:o,elementsSelectable:g,zoomOnScroll:v,zoomOnPinch:w,panOnScroll:ue,panOnScrollSpeed:j,panOnScrollMode:C,zoomOnDoubleClick:P,panOnDrag:!V&&se,defaultViewport:z,translateExtent:$,minZoom:L,maxZoom:F,zoomActivationKeyCode:b,preventScrolling:O,noWheelClassName:K,noPanClassName:H,onViewportChange:T,isControlledViewport:W,paneClickDistance:l,selectionOnDrag:G,children:i.jsxs(C5,{onSelectionStart:p,onSelectionEnd:h,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:o,onPaneScroll:a,panOnDrag:se,isSelecting:!!ee,selectionMode:f,selectionKeyPressed:V,paneClickDistance:l,selectionOnDrag:G,children:[e,E&&i.jsx(D5,{onSelectionContextMenu:M,noPanClassName:H,disableKeyboardA11y:D})]})})}XI.displayName="FlowRenderer";const z5=m.memo(XI),B5=e=>t=>e?Pk(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function H5(e){return Bt(m.useCallback(B5(e),[e]),_n)}const W5=e=>e.updateNodeInternals;function V5(){const e=Bt(W5),[t]=m.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const r=new Map;n.forEach(s=>{const o=s.target.getAttribute("data-id");r.set(o,{id:o,nodeElement:s.target,force:!0})}),e(r)}));return m.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function K5({node:e,nodeType:t,hasDimensions:n,resizeObserver:r}){const s=gn(),o=m.useRef(null),a=m.useRef(null),l=m.useRef(e.sourcePosition),c=m.useRef(e.targetPosition),u=m.useRef(t),d=n&&!!e.internals.handleBounds;return m.useEffect(()=>{o.current&&!e.hidden&&(!d||a.current!==o.current)&&(a.current&&(r==null||r.unobserve(a.current)),r==null||r.observe(o.current),a.current=o.current)},[d,e.hidden]),m.useEffect(()=>()=>{a.current&&(r==null||r.unobserve(a.current),a.current=null)},[]),m.useEffect(()=>{if(o.current){const f=u.current!==t,p=l.current!==e.sourcePosition,h=c.current!==e.targetPosition;(f||p||h)&&(u.current=t,l.current=e.sourcePosition,c.current=e.targetPosition,s.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:o.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),o}function q5({id:e,onClick:t,onMouseEnter:n,onMouseMove:r,onMouseLeave:s,onContextMenu:o,onDoubleClick:a,nodesDraggable:l,elementsSelectable:c,nodesConnectable:u,nodesFocusable:d,resizeObserver:f,noDragClassName:p,noPanClassName:h,disableKeyboardA11y:y,rfId:k,nodeTypes:b,nodeClickDistance:g,onError:v}){const{node:w,internals:N,isParent:j}=Bt(te=>{const ne=te.nodeLookup.get(e),Z=te.parentLookup.has(e);return{node:ne,internals:ne.internals,isParent:Z}},_n);let C=w.type||"default",P=(b==null?void 0:b[C])||Yj[C];P===void 0&&(v==null||v("003",Ii.error003(C)),C="default",P=(b==null?void 0:b.default)||Yj.default);const I=!!(w.draggable||l&&typeof w.draggable>"u"),z=!!(w.selectable||c&&typeof w.selectable>"u"),$=!!(w.connectable||u&&typeof w.connectable>"u"),L=!!(w.focusable||d&&typeof w.focusable>"u"),F=gn(),O=mI(w),M=K5({node:w,nodeType:C,hasDimensions:O,resizeObserver:f}),K=YI({nodeRef:M,disabled:w.hidden||!I,noDragClassName:p,handleSelector:w.dragHandle,nodeId:e,isSelectable:z,nodeClickDistance:g}),H=GI();if(w.hidden)return null;const D=fo(w),T=L5(w),W=z||I||t||n||r||s,E=n?te=>n(te,{...N.userNode}):void 0,Q=r?te=>r(te,{...N.userNode}):void 0,V=s?te=>s(te,{...N.userNode}):void 0,B=o?te=>o(te,{...N.userNode}):void 0,se=a?te=>a(te,{...N.userNode}):void 0,ue=te=>{const{selectNodesOnDrag:ne,nodeDragThreshold:Z}=F.getState();z&&(!ne||!I||Z>0)&&zx({id:e,store:F,nodeRef:M}),t&&t(te,{...N.userNode})},G=te=>{if(!(wI(te.nativeEvent)||y)){if(oI.includes(te.key)&&z){const ne=te.key==="Escape";zx({id:e,store:F,unselect:ne,nodeRef:M})}else if(I&&w.selected&&Object.prototype.hasOwnProperty.call(Zh,te.key)){te.preventDefault();const{ariaLabelConfig:ne}=F.getState();F.setState({ariaLiveMessage:ne["node.a11yDescription.ariaLiveMessage"]({direction:te.key.replace("Arrow","").toLowerCase(),x:~~N.positionAbsolute.x,y:~~N.positionAbsolute.y})}),H({direction:Zh[te.key],factor:te.shiftKey?4:1})}}},ee=()=>{var $e;if(y||!(($e=M.current)!=null&&$e.matches(":focus-visible")))return;const{transform:te,width:ne,height:Z,autoPanOnNodeFocus:ce,setCenter:de}=F.getState();if(!ce)return;Pk(new Map([[e,w]]),{x:0,y:0,width:ne,height:Z},te,!0).length>0||de(w.position.x+D.width/2,w.position.y+D.height/2,{zoom:te[2]})};return i.jsx("div",{className:Jn(["react-flow__node",`react-flow__node-${C}`,{[h]:I},w.className,{selected:w.selected,selectable:z,parent:j,draggable:I,dragging:K}]),ref:M,style:{zIndex:N.z,transform:`translate(${N.positionAbsolute.x}px,${N.positionAbsolute.y}px)`,pointerEvents:W?"all":"none",visibility:O?"visible":"hidden",...w.style,...T},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:E,onMouseMove:Q,onMouseLeave:V,onContextMenu:B,onClick:ue,onDoubleClick:se,onKeyDown:L?G:void 0,tabIndex:L?0:void 0,onFocus:L?ee:void 0,role:w.ariaRole??(L?"group":void 0),"aria-roledescription":"node","aria-describedby":y?void 0:`${HI}-${k}`,"aria-label":w.ariaLabel,...w.domAttributes,children:i.jsx(E5,{value:e,children:i.jsx(P,{id:e,data:w.data,type:C,positionAbsoluteX:N.positionAbsolute.x,positionAbsoluteY:N.positionAbsolute.y,selected:w.selected??!1,selectable:z,draggable:I,deletable:w.deletable??!0,isConnectable:$,sourcePosition:w.sourcePosition,targetPosition:w.targetPosition,dragging:K,dragHandle:w.dragHandle,zIndex:N.z,parentId:w.parentId,...D})})})}var U5=m.memo(q5);const Y5=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function QI(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,onError:o}=Bt(Y5,_n),a=H5(e.onlyRenderVisibleElements),l=V5();return i.jsx("div",{className:"react-flow__nodes",style:eg,children:a.map(c=>i.jsx(U5,{id:c,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:l,nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,nodeClickDistance:e.nodeClickDistance,onError:o},c))})}QI.displayName="NodeRenderer";const G5=m.memo(QI);function J5(e){return Bt(m.useCallback(n=>{if(!e)return n.edges.map(s=>s.id);const r=[];if(n.width&&n.height)for(const s of n.edges){const o=n.nodeLookup.get(s.source),a=n.nodeLookup.get(s.target);o&&a&&OH({sourceNode:o,targetNode:a,width:n.width,height:n.height,transform:n.transform})&&r.push(s.id)}return r},[e]),_n)}const X5=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return i.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},Q5=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return i.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},Jj={[bi.Arrow]:X5,[bi.ArrowClosed]:Q5};function Z5(e){const t=gn();return m.useMemo(()=>{var s,o;return Object.prototype.hasOwnProperty.call(Jj,e)?Jj[e]:((o=(s=t.getState()).onError)==null||o.call(s,"009",Ii.error009(e)),null)},[e])}const eW=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:o="strokeWidth",strokeWidth:a,orient:l="auto-start-reverse"})=>{const c=Z5(t);return c?i.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:o,orient:l,refX:"0",refY:"0",children:i.jsx(c,{color:n,strokeWidth:a})}):null},ZI=({defaultColor:e,rfId:t})=>{const n=Bt(o=>o.edges),r=Bt(o=>o.defaultEdgeOptions),s=m.useMemo(()=>VH(n,{id:t,defaultColor:e,defaultMarkerStart:r==null?void 0:r.markerStart,defaultMarkerEnd:r==null?void 0:r.markerEnd}),[n,r,t,e]);return s.length?i.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:i.jsx("defs",{children:s.map(o=>i.jsx(eW,{id:o.id,type:o.type,color:o.color,width:o.width,height:o.height,markerUnits:o.markerUnits,strokeWidth:o.strokeWidth,orient:o.orient},o.id))})}):null};ZI.displayName="MarkerDefinitions";var tW=m.memo(ZI);function eR({x:e,y:t,label:n,labelStyle:r,labelShowBg:s=!0,labelBgStyle:o,labelBgPadding:a=[2,4],labelBgBorderRadius:l=2,children:c,className:u,...d}){const[f,p]=m.useState({x:1,y:0,width:0,height:0}),h=Jn(["react-flow__edge-textwrapper",u]),y=m.useRef(null);return m.useEffect(()=>{if(y.current){const k=y.current.getBBox();p({x:k.x,y:k.y,width:k.width,height:k.height})}},[n]),n?i.jsxs("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:h,visibility:f.width?"visible":"hidden",...d,children:[s&&i.jsx("rect",{width:f.width+2*a[0],x:-a[0],y:-a[1],height:f.height+2*a[1],className:"react-flow__edge-textbg",style:o,rx:l,ry:l}),i.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:y,style:r,children:n}),c]}):null}eR.displayName="EdgeText";const nW=m.memo(eR);function tg({path:e,labelX:t,labelY:n,label:r,labelStyle:s,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c,interactionWidth:u=20,...d}){return i.jsxs(i.Fragment,{children:[i.jsx("path",{...d,d:e,fill:"none",className:Jn(["react-flow__edge-path",d.className])}),u?i.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:u,className:"react-flow__edge-interaction"}):null,r&&Js(t)&&Js(n)?i.jsx(nW,{x:t,y:n,label:r,labelStyle:s,labelShowBg:o,labelBgStyle:a,labelBgPadding:l,labelBgBorderRadius:c}):null]})}function Xj({pos:e,x1:t,y1:n,x2:r,y2:s}){return e===qe.Left||e===qe.Right?[.5*(t+r),n]:[t,.5*(n+s)]}function tR({sourceX:e,sourceY:t,sourcePosition:n=qe.Bottom,targetX:r,targetY:s,targetPosition:o=qe.Top}){const[a,l]=Xj({pos:n,x1:e,y1:t,x2:r,y2:s}),[c,u]=Xj({pos:o,x1:r,y1:s,x2:e,y2:t}),[d,f,p,h]=bI({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:a,sourceControlY:l,targetControlX:c,targetControlY:u});return[`M${e},${t} C${a},${l} ${c},${u} ${r},${s}`,d,f,p,h]}function nR(e){return m.memo(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:a,targetPosition:l,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:k,markerStart:b,interactionWidth:g})=>{const[v,w,N]=tR({sourceX:n,sourceY:r,sourcePosition:a,targetX:s,targetY:o,targetPosition:l}),j=e.isInternal?void 0:t;return i.jsx(tg,{id:j,path:v,labelX:w,labelY:N,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:k,markerStart:b,interactionWidth:g})})}const rW=nR({isInternal:!1}),rR=nR({isInternal:!0});rW.displayName="SimpleBezierEdge";rR.displayName="SimpleBezierEdgeInternal";function sR(e){return m.memo(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:p,sourcePosition:h=qe.Bottom,targetPosition:y=qe.Top,markerEnd:k,markerStart:b,pathOptions:g,interactionWidth:v})=>{const[w,N,j]=$x({sourceX:n,sourceY:r,sourcePosition:h,targetX:s,targetY:o,targetPosition:y,borderRadius:g==null?void 0:g.borderRadius,offset:g==null?void 0:g.offset,stepPosition:g==null?void 0:g.stepPosition}),C=e.isInternal?void 0:t;return i.jsx(tg,{id:C,path:w,labelX:N,labelY:j,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:p,markerEnd:k,markerStart:b,interactionWidth:v})})}const iR=sR({isInternal:!1}),oR=sR({isInternal:!0});iR.displayName="SmoothStepEdge";oR.displayName="SmoothStepEdgeInternal";function aR(e){return m.memo(({id:t,...n})=>{var s;const r=e.isInternal?void 0:t;return i.jsx(iR,{...n,id:r,pathOptions:m.useMemo(()=>{var o;return{borderRadius:0,offset:(o=n.pathOptions)==null?void 0:o.offset}},[(s=n.pathOptions)==null?void 0:s.offset])})})}const sW=aR({isInternal:!1}),lR=aR({isInternal:!0});sW.displayName="StepEdge";lR.displayName="StepEdgeInternal";function cR(e){return m.memo(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:p,markerEnd:h,markerStart:y,interactionWidth:k})=>{const[b,g,v]=SI({sourceX:n,sourceY:r,targetX:s,targetY:o}),w=e.isInternal?void 0:t;return i.jsx(tg,{id:w,path:b,labelX:g,labelY:v,label:a,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:p,markerEnd:h,markerStart:y,interactionWidth:k})})}const iW=cR({isInternal:!1}),uR=cR({isInternal:!0});iW.displayName="StraightEdge";uR.displayName="StraightEdgeInternal";function dR(e){return m.memo(({id:t,sourceX:n,sourceY:r,targetX:s,targetY:o,sourcePosition:a=qe.Bottom,targetPosition:l=qe.Top,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:k,markerStart:b,pathOptions:g,interactionWidth:v})=>{const[w,N,j]=kI({sourceX:n,sourceY:r,sourcePosition:a,targetX:s,targetY:o,targetPosition:l,curvature:g==null?void 0:g.curvature}),C=e.isInternal?void 0:t;return i.jsx(tg,{id:C,path:w,labelX:N,labelY:j,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:p,labelBgBorderRadius:h,style:y,markerEnd:k,markerStart:b,interactionWidth:v})})}const oW=dR({isInternal:!1}),fR=dR({isInternal:!0});oW.displayName="BezierEdge";fR.displayName="BezierEdgeInternal";const Qj={default:fR,straight:uR,step:lR,smoothstep:oR,simplebezier:rR},Zj={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},aW=(e,t,n)=>n===qe.Left?e-t:n===qe.Right?e+t:e,lW=(e,t,n)=>n===qe.Top?e-t:n===qe.Bottom?e+t:e,e1="react-flow__edgeupdater";function t1({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:o,onMouseOut:a,type:l}){return i.jsx("circle",{onMouseDown:s,onMouseEnter:o,onMouseOut:a,className:Jn([e1,`${e1}-${l}`]),cx:aW(t,r,e),cy:lW(n,r,e),r,stroke:"transparent",fill:"transparent"})}function cW({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:r,sourceY:s,targetX:o,targetY:a,sourcePosition:l,targetPosition:c,onReconnect:u,onReconnectStart:d,onReconnectEnd:f,setReconnecting:p,setUpdateHover:h}){const y=gn(),k=(N,j)=>{if(N.button!==0)return;const{autoPanOnConnect:C,domNode:P,connectionMode:I,connectionRadius:z,lib:$,onConnectStart:L,cancelConnection:F,nodeLookup:O,rfId:M,panBy:K,updateConnection:H}=y.getState(),D=j.type==="target",T=(Q,V)=>{p(!1),f==null||f(Q,n,j.type,V)},W=Q=>u==null?void 0:u(n,Q),E=(Q,V)=>{p(!0),d==null||d(N,n,j.type),L==null||L(Q,V)};Dx.onPointerDown(N.nativeEvent,{autoPanOnConnect:C,connectionMode:I,connectionRadius:z,domNode:P,handleId:j.id,nodeId:j.nodeId,nodeLookup:O,isTarget:D,edgeUpdaterType:j.type,lib:$,flowId:M,cancelConnection:F,panBy:K,isValidConnection:(...Q)=>{var V,B;return((B=(V=y.getState()).isValidConnection)==null?void 0:B.call(V,...Q))??!0},onConnect:W,onConnectStart:E,onConnectEnd:(...Q)=>{var V,B;return(B=(V=y.getState()).onConnectEnd)==null?void 0:B.call(V,...Q)},onReconnectEnd:T,updateConnection:H,getTransform:()=>y.getState().transform,getFromHandle:()=>y.getState().connection.fromHandle,dragThreshold:y.getState().connectionDragThreshold,handleDomNode:N.currentTarget})},b=N=>k(N,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),g=N=>k(N,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),v=()=>h(!0),w=()=>h(!1);return i.jsxs(i.Fragment,{children:[(e===!0||e==="source")&&i.jsx(t1,{position:l,centerX:r,centerY:s,radius:t,onMouseDown:b,onMouseEnter:v,onMouseOut:w,type:"source"}),(e===!0||e==="target")&&i.jsx(t1,{position:c,centerX:o,centerY:a,radius:t,onMouseDown:g,onMouseEnter:v,onMouseOut:w,type:"target"})]})}function uW({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:r,onClick:s,onDoubleClick:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:u,reconnectRadius:d,onReconnect:f,onReconnectStart:p,onReconnectEnd:h,rfId:y,edgeTypes:k,noPanClassName:b,onError:g,disableKeyboardA11y:v}){let w=Bt(de=>de.edgeLookup.get(e));const N=Bt(de=>de.defaultEdgeOptions);w=N?{...N,...w}:w;let j=w.type||"default",C=(k==null?void 0:k[j])||Qj[j];C===void 0&&(g==null||g("011",Ii.error011(j)),j="default",C=(k==null?void 0:k.default)||Qj.default);const P=!!(w.focusable||t&&typeof w.focusable>"u"),I=typeof f<"u"&&(w.reconnectable||n&&typeof w.reconnectable>"u"),z=!!(w.selectable||r&&typeof w.selectable>"u"),$=m.useRef(null),[L,F]=m.useState(!1),[O,M]=m.useState(!1),K=gn(),{zIndex:H,sourceX:D,sourceY:T,targetX:W,targetY:E,sourcePosition:Q,targetPosition:V}=Bt(m.useCallback(de=>{const me=de.nodeLookup.get(w.source),$e=de.nodeLookup.get(w.target);if(!me||!$e)return{zIndex:w.zIndex,...Zj};const Ce=WH({id:e,sourceNode:me,targetNode:$e,sourceHandle:w.sourceHandle||null,targetHandle:w.targetHandle||null,connectionMode:de.connectionMode,onError:g});return{zIndex:LH({selected:w.selected,zIndex:w.zIndex,sourceNode:me,targetNode:$e,elevateOnSelect:de.elevateEdgesOnSelect,zIndexMode:de.zIndexMode}),...Ce||Zj}},[w.source,w.target,w.sourceHandle,w.targetHandle,w.selected,w.zIndex]),_n),B=m.useMemo(()=>w.markerStart?`url('#${Lx(w.markerStart,y)}')`:void 0,[w.markerStart,y]),se=m.useMemo(()=>w.markerEnd?`url('#${Lx(w.markerEnd,y)}')`:void 0,[w.markerEnd,y]);if(w.hidden||D===null||T===null||W===null||E===null)return null;const ue=de=>{var _e;const{addSelectedEdges:me,unselectNodesAndEdges:$e,multiSelectionActive:Ce}=K.getState();z&&(K.setState({nodesSelectionActive:!1}),w.selected&&Ce?($e({nodes:[],edges:[w]}),(_e=$.current)==null||_e.blur()):me([e])),s&&s(de,w)},G=o?de=>{o(de,{...w})}:void 0,ee=a?de=>{a(de,{...w})}:void 0,te=l?de=>{l(de,{...w})}:void 0,ne=c?de=>{c(de,{...w})}:void 0,Z=u?de=>{u(de,{...w})}:void 0,ce=de=>{var me;if(!v&&oI.includes(de.key)&&z){const{unselectNodesAndEdges:$e,addSelectedEdges:Ce}=K.getState();de.key==="Escape"?((me=$.current)==null||me.blur(),$e({edges:[w]})):Ce([e])}};return i.jsx("svg",{style:{zIndex:H},children:i.jsxs("g",{className:Jn(["react-flow__edge",`react-flow__edge-${j}`,w.className,b,{selected:w.selected,animated:w.animated,inactive:!z&&!s,updating:L,selectable:z}]),onClick:ue,onDoubleClick:G,onContextMenu:ee,onMouseEnter:te,onMouseMove:ne,onMouseLeave:Z,onKeyDown:P?ce:void 0,tabIndex:P?0:void 0,role:w.ariaRole??(P?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":w.ariaLabel===null?void 0:w.ariaLabel||`Edge from ${w.source} to ${w.target}`,"aria-describedby":P?`${WI}-${y}`:void 0,ref:$,...w.domAttributes,children:[!O&&i.jsx(C,{id:e,source:w.source,target:w.target,type:w.type,selected:w.selected,animated:w.animated,selectable:z,deletable:w.deletable??!0,label:w.label,labelStyle:w.labelStyle,labelShowBg:w.labelShowBg,labelBgStyle:w.labelBgStyle,labelBgPadding:w.labelBgPadding,labelBgBorderRadius:w.labelBgBorderRadius,sourceX:D,sourceY:T,targetX:W,targetY:E,sourcePosition:Q,targetPosition:V,data:w.data,style:w.style,sourceHandleId:w.sourceHandle,targetHandleId:w.targetHandle,markerStart:B,markerEnd:se,pathOptions:"pathOptions"in w?w.pathOptions:void 0,interactionWidth:w.interactionWidth}),I&&i.jsx(cW,{edge:w,isReconnectable:I,reconnectRadius:d,onReconnect:f,onReconnectStart:p,onReconnectEnd:h,sourceX:D,sourceY:T,targetX:W,targetY:E,sourcePosition:Q,targetPosition:V,setUpdateHover:F,setReconnecting:M})]})})}var dW=m.memo(uW);const fW=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function pR({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:r,noPanClassName:s,onReconnect:o,onEdgeContextMenu:a,onEdgeMouseEnter:l,onEdgeMouseMove:c,onEdgeMouseLeave:u,onEdgeClick:d,reconnectRadius:f,onEdgeDoubleClick:p,onReconnectStart:h,onReconnectEnd:y,disableKeyboardA11y:k}){const{edgesFocusable:b,edgesReconnectable:g,elementsSelectable:v,onError:w}=Bt(fW,_n),N=J5(t);return i.jsxs("div",{className:"react-flow__edges",children:[i.jsx(tW,{defaultColor:e,rfId:n}),N.map(j=>i.jsx(dW,{id:j,edgesFocusable:b,edgesReconnectable:g,elementsSelectable:v,noPanClassName:s,onReconnect:o,onContextMenu:a,onMouseEnter:l,onMouseMove:c,onMouseLeave:u,onClick:d,reconnectRadius:f,onDoubleClick:p,onReconnectStart:h,onReconnectEnd:y,rfId:n,onError:w,edgeTypes:r,disableKeyboardA11y:k},j))]})}pR.displayName="EdgeRenderer";const pW=m.memo(pR),hW=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function mW({children:e}){const t=Bt(hW);return i.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function gW(e){const t=Fc(),n=m.useRef(!1);m.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const yW=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function wW(e){const t=Bt(yW),n=gn();return m.useEffect(()=>{e&&(t==null||t(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function xW(e){return e.connection.inProgress?{...e.connection,to:pf(e.connection.to,e.transform)}:{...e.connection}}function bW(e){return xW}function kW(e){const t=bW();return Bt(t,_n)}const vW=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function SW({containerStyle:e,style:t,type:n,component:r}){const{nodesConnectable:s,width:o,height:a,isValid:l,inProgress:c}=Bt(vW,_n);return!(o&&s&&c)?null:i.jsx("svg",{style:e,width:o,height:a,className:"react-flow__connectionline react-flow__container",children:i.jsx("g",{className:Jn(["react-flow__connection",cI(l)]),children:i.jsx(hR,{style:t,type:n,CustomComponent:r,isValid:l})})})}const hR=({style:e,type:t=Mo.Bezier,CustomComponent:n,isValid:r})=>{const{inProgress:s,from:o,fromNode:a,fromHandle:l,fromPosition:c,to:u,toNode:d,toHandle:f,toPosition:p,pointer:h}=kW();if(!s)return;if(n)return i.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:a,fromHandle:l,fromX:o.x,fromY:o.y,toX:u.x,toY:u.y,fromPosition:c,toPosition:p,connectionStatus:cI(r),toNode:d,toHandle:f,pointer:h});let y="";const k={sourceX:o.x,sourceY:o.y,sourcePosition:c,targetX:u.x,targetY:u.y,targetPosition:p};switch(t){case Mo.Bezier:[y]=kI(k);break;case Mo.SimpleBezier:[y]=tR(k);break;case Mo.Step:[y]=$x({...k,borderRadius:0});break;case Mo.SmoothStep:[y]=$x(k);break;default:[y]=SI(k)}return i.jsx("path",{d:y,fill:"none",className:"react-flow__connection-path",style:e})};hR.displayName="ConnectionLine";const NW={};function n1(e=NW){m.useRef(e),gn(),m.useEffect(()=>{},[e])}function jW(){gn(),m.useRef(!1),m.useEffect(()=>{},[])}function mR({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:r,onEdgeClick:s,onNodeDoubleClick:o,onEdgeDoubleClick:a,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:d,onSelectionContextMenu:f,onSelectionStart:p,onSelectionEnd:h,connectionLineType:y,connectionLineStyle:k,connectionLineComponent:b,connectionLineContainerStyle:g,selectionKeyCode:v,selectionOnDrag:w,selectionMode:N,multiSelectionKeyCode:j,panActivationKeyCode:C,zoomActivationKeyCode:P,deleteKeyCode:I,onlyRenderVisibleElements:z,elementsSelectable:$,defaultViewport:L,translateExtent:F,minZoom:O,maxZoom:M,preventScrolling:K,defaultMarkerColor:H,zoomOnScroll:D,zoomOnPinch:T,panOnScroll:W,panOnScrollSpeed:E,panOnScrollMode:Q,zoomOnDoubleClick:V,panOnDrag:B,onPaneClick:se,onPaneMouseEnter:ue,onPaneMouseMove:G,onPaneMouseLeave:ee,onPaneScroll:te,onPaneContextMenu:ne,paneClickDistance:Z,nodeClickDistance:ce,onEdgeContextMenu:de,onEdgeMouseEnter:me,onEdgeMouseMove:$e,onEdgeMouseLeave:Ce,reconnectRadius:_e,onReconnect:Be,onReconnectStart:ot,onReconnectEnd:yt,noDragClassName:Te,noWheelClassName:st,noPanClassName:gt,disableKeyboardA11y:xe,nodeExtent:Fe,rfId:lt,viewport:oe,onViewportChange:ke}){return n1(e),n1(t),jW(),gW(n),wW(oe),i.jsx(z5,{onPaneClick:se,onPaneMouseEnter:ue,onPaneMouseMove:G,onPaneMouseLeave:ee,onPaneContextMenu:ne,onPaneScroll:te,paneClickDistance:Z,deleteKeyCode:I,selectionKeyCode:v,selectionOnDrag:w,selectionMode:N,onSelectionStart:p,onSelectionEnd:h,multiSelectionKeyCode:j,panActivationKeyCode:C,zoomActivationKeyCode:P,elementsSelectable:$,zoomOnScroll:D,zoomOnPinch:T,zoomOnDoubleClick:V,panOnScroll:W,panOnScrollSpeed:E,panOnScrollMode:Q,panOnDrag:B,defaultViewport:L,translateExtent:F,minZoom:O,maxZoom:M,onSelectionContextMenu:f,preventScrolling:K,noDragClassName:Te,noWheelClassName:st,noPanClassName:gt,disableKeyboardA11y:xe,onViewportChange:ke,isControlledViewport:!!oe,children:i.jsxs(mW,{children:[i.jsx(pW,{edgeTypes:t,onEdgeClick:s,onEdgeDoubleClick:a,onReconnect:Be,onReconnectStart:ot,onReconnectEnd:yt,onlyRenderVisibleElements:z,onEdgeContextMenu:de,onEdgeMouseEnter:me,onEdgeMouseMove:$e,onEdgeMouseLeave:Ce,reconnectRadius:_e,defaultMarkerColor:H,noPanClassName:gt,disableKeyboardA11y:xe,rfId:lt}),i.jsx(SW,{style:k,type:y,component:b,containerStyle:g}),i.jsx("div",{className:"react-flow__edgelabel-renderer"}),i.jsx(G5,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:o,onNodeMouseEnter:l,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:d,nodeClickDistance:ce,onlyRenderVisibleElements:z,noPanClassName:gt,noDragClassName:Te,disableKeyboardA11y:xe,nodeExtent:Fe,rfId:lt}),i.jsx("div",{className:"react-flow__viewport-portal"})]})})}mR.displayName="GraphView";const CW=m.memo(mR),r1=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:o,fitView:a,fitViewOptions:l,minZoom:c=.5,maxZoom:u=2,nodeOrigin:d,nodeExtent:f,zIndexMode:p="basic"}={})=>{const h=new Map,y=new Map,k=new Map,b=new Map,g=r??t??[],v=n??e??[],w=d??[0,0],N=f??Ld;CI(k,b,g);const{nodesInitialized:j}=Ox(v,h,y,{nodeOrigin:w,nodeExtent:N,zIndexMode:p});let C=[0,0,1];if(a&&s&&o){const P=df(h,{filter:L=>!!((L.width||L.initialWidth)&&(L.height||L.initialHeight))}),{x:I,y:z,zoom:$}=Ik(P,s,o,c,u,(l==null?void 0:l.padding)??.1);C=[I,z,$]}return{rfId:"1",width:s??0,height:o??0,transform:C,nodes:v,nodesInitialized:j,nodeLookup:h,parentLookup:y,edges:g,edgeLookup:b,connectionLookup:k,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:u,translateExtent:Ld,nodeExtent:N,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:Cc.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:w,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:a??!1,fitViewOptions:l,fitViewResolver:null,connection:{...lI},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:PH,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:aI,zIndexMode:p,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},_W=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:p})=>q4((h,y)=>{async function k(){const{nodeLookup:b,panZoom:g,fitViewOptions:v,fitViewResolver:w,width:N,height:j,minZoom:C,maxZoom:P}=y();g&&(await EH({nodes:b,width:N,height:j,panZoom:g,minZoom:C,maxZoom:P},v),w==null||w.resolve(!0),h({fitViewResolver:null}))}return{...r1({nodes:e,edges:t,width:s,height:o,fitView:a,fitViewOptions:l,minZoom:c,maxZoom:u,nodeOrigin:d,nodeExtent:f,defaultNodes:n,defaultEdges:r,zIndexMode:p}),setNodes:b=>{const{nodeLookup:g,parentLookup:v,nodeOrigin:w,elevateNodesOnSelect:N,fitViewQueued:j,zIndexMode:C,nodesSelectionActive:P}=y(),{nodesInitialized:I,hasSelectedNodes:z}=Ox(b,g,v,{nodeOrigin:w,nodeExtent:f,elevateNodesOnSelect:N,checkEquality:!0,zIndexMode:C}),$=P&&z;j&&I?(k(),h({nodes:b,nodesInitialized:I,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:$})):h({nodes:b,nodesInitialized:I,nodesSelectionActive:$})},setEdges:b=>{const{connectionLookup:g,edgeLookup:v}=y();CI(g,v,b),h({edges:b})},setDefaultNodesAndEdges:(b,g)=>{if(b){const{setNodes:v}=y();v(b),h({hasDefaultNodes:!0})}if(g){const{setEdges:v}=y();v(g),h({hasDefaultEdges:!0})}},updateNodeInternals:b=>{const{triggerNodeChanges:g,nodeLookup:v,parentLookup:w,domNode:N,nodeOrigin:j,nodeExtent:C,debug:P,fitViewQueued:I,zIndexMode:z}=y(),{changes:$,updatedInternals:L}=XH(b,v,w,N,j,C,z);L&&(UH(v,w,{nodeOrigin:j,nodeExtent:C,zIndexMode:z}),I?(k(),h({fitViewQueued:!1,fitViewOptions:void 0})):h({}),($==null?void 0:$.length)>0&&(P&&console.log("React Flow: trigger node changes",$),g==null||g($)))},updateNodePositions:(b,g=!1)=>{const v=[];let w=[];const{nodeLookup:N,triggerNodeChanges:j,connection:C,updateConnection:P,onNodesChangeMiddlewareMap:I}=y();for(const[z,$]of b){const L=N.get(z),F=!!(L!=null&&L.expandParent&&(L!=null&&L.parentId)&&($!=null&&$.position)),O={id:z,type:"position",position:F?{x:Math.max(0,$.position.x),y:Math.max(0,$.position.y)}:$.position,dragging:g};if(L&&C.inProgress&&C.fromNode.id===L.id){const M=Ja(L,C.fromHandle,qe.Left,!0);P({...C,from:M})}F&&L.parentId&&v.push({id:z,parentId:L.parentId,rect:{...$.internals.positionAbsolute,width:$.measured.width??0,height:$.measured.height??0}}),w.push(O)}if(v.length>0){const{parentLookup:z,nodeOrigin:$}=y(),L=Ok(v,N,z,$);w.push(...L)}for(const z of I.values())w=z(w);j(w)},triggerNodeChanges:b=>{const{onNodesChange:g,setNodes:v,nodes:w,hasDefaultNodes:N,debug:j}=y();if(b!=null&&b.length){if(N){const C=ad(b,w);v(C)}j&&console.log("React Flow: trigger node changes",b),g==null||g(b)}},triggerEdgeChanges:b=>{const{onEdgesChange:g,setEdges:v,edges:w,hasDefaultEdges:N,debug:j}=y();if(b!=null&&b.length){if(N){const C=Qh(b,w);v(C)}j&&console.log("React Flow: trigger edge changes",b),g==null||g(b)}},addSelectedNodes:b=>{const{multiSelectionActive:g,edgeLookup:v,nodeLookup:w,triggerNodeChanges:N,triggerEdgeChanges:j}=y();if(g){const C=b.map(P=>Na(P,!0));N(C);return}N(ec(w,new Set([...b]),!0)),j(ec(v))},addSelectedEdges:b=>{const{multiSelectionActive:g,edgeLookup:v,nodeLookup:w,triggerNodeChanges:N,triggerEdgeChanges:j}=y();if(g){const C=b.map(P=>Na(P,!0));j(C);return}j(ec(v,new Set([...b]))),N(ec(w,new Set,!0))},unselectNodesAndEdges:({nodes:b,edges:g}={})=>{const{edges:v,nodes:w,nodeLookup:N,triggerNodeChanges:j,triggerEdgeChanges:C}=y(),P=b||w,I=g||v,z=[];for(const L of P){if(!L.selected)continue;const F=N.get(L.id);F&&(F.selected=!1),z.push(Na(L.id,!1))}const $=[];for(const L of I)L.selected&&$.push(Na(L.id,!1));j(z),C($)},setMinZoom:b=>{const{panZoom:g,maxZoom:v}=y();g==null||g.setScaleExtent([b,v]),h({minZoom:b})},setMaxZoom:b=>{const{panZoom:g,minZoom:v}=y();g==null||g.setScaleExtent([v,b]),h({maxZoom:b})},setTranslateExtent:b=>{var g;(g=y().panZoom)==null||g.setTranslateExtent(b),h({translateExtent:b})},resetSelectedElements:()=>{const{edges:b,nodes:g,triggerNodeChanges:v,triggerEdgeChanges:w,elementsSelectable:N}=y();if(!N)return;const j=g.reduce((P,I)=>I.selected?[...P,Na(I.id,!1)]:P,[]),C=b.reduce((P,I)=>I.selected?[...P,Na(I.id,!1)]:P,[]);v(j),w(C)},setNodeExtent:b=>{const{nodes:g,nodeLookup:v,parentLookup:w,nodeOrigin:N,elevateNodesOnSelect:j,nodeExtent:C,zIndexMode:P}=y();b[0][0]===C[0][0]&&b[0][1]===C[0][1]&&b[1][0]===C[1][0]&&b[1][1]===C[1][1]||(Ox(g,v,w,{nodeOrigin:N,nodeExtent:b,elevateNodesOnSelect:j,checkEquality:!1,zIndexMode:P}),h({nodeExtent:b}))},panBy:b=>{const{transform:g,width:v,height:w,panZoom:N,translateExtent:j}=y();return QH({delta:b,panZoom:N,transform:g,translateExtent:j,width:v,height:w})},setCenter:async(b,g,v)=>{const{width:w,height:N,maxZoom:j,panZoom:C}=y();if(!C)return Promise.resolve(!1);const P=typeof(v==null?void 0:v.zoom)<"u"?v.zoom:j;return await C.setViewport({x:w/2-b*P,y:N/2-g*P,zoom:P},{duration:v==null?void 0:v.duration,ease:v==null?void 0:v.ease,interpolate:v==null?void 0:v.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{h({connection:{...lI}})},updateConnection:b=>{h({connection:b})},reset:()=>h({...r1()})}},Object.is);function Fk({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:r,initialWidth:s,initialHeight:o,initialMinZoom:a,initialMaxZoom:l,initialFitViewOptions:c,fitView:u,nodeOrigin:d,nodeExtent:f,zIndexMode:p,children:h}){const[y]=m.useState(()=>_W({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:s,height:o,fitView:u,minZoom:a,maxZoom:l,fitViewOptions:c,nodeOrigin:d,nodeExtent:f,zIndexMode:p}));return i.jsx(U4,{value:y,children:i.jsx(m5,{children:h})})}function EW({children:e,nodes:t,edges:n,defaultNodes:r,defaultEdges:s,width:o,height:a,fitView:l,fitViewOptions:c,minZoom:u,maxZoom:d,nodeOrigin:f,nodeExtent:p,zIndexMode:h}){return m.useContext(Qm)?i.jsx(i.Fragment,{children:e}):i.jsx(Fk,{initialNodes:t,initialEdges:n,defaultNodes:r,defaultEdges:s,initialWidth:o,initialHeight:a,fitView:l,initialFitViewOptions:c,initialMinZoom:u,initialMaxZoom:d,nodeOrigin:f,nodeExtent:p,zIndexMode:h,children:e})}const AW={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function PW({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:o,edgeTypes:a,onNodeClick:l,onEdgeClick:c,onInit:u,onMove:d,onMoveStart:f,onMoveEnd:p,onConnect:h,onConnectStart:y,onConnectEnd:k,onClickConnectStart:b,onClickConnectEnd:g,onNodeMouseEnter:v,onNodeMouseMove:w,onNodeMouseLeave:N,onNodeContextMenu:j,onNodeDoubleClick:C,onNodeDragStart:P,onNodeDrag:I,onNodeDragStop:z,onNodesDelete:$,onEdgesDelete:L,onDelete:F,onSelectionChange:O,onSelectionDragStart:M,onSelectionDrag:K,onSelectionDragStop:H,onSelectionContextMenu:D,onSelectionStart:T,onSelectionEnd:W,onBeforeDelete:E,connectionMode:Q,connectionLineType:V=Mo.Bezier,connectionLineStyle:B,connectionLineComponent:se,connectionLineContainerStyle:ue,deleteKeyCode:G="Backspace",selectionKeyCode:ee="Shift",selectionOnDrag:te=!1,selectionMode:ne=Od.Full,panActivationKeyCode:Z="Space",multiSelectionKeyCode:ce=Fd()?"Meta":"Control",zoomActivationKeyCode:de=Fd()?"Meta":"Control",snapToGrid:me,snapGrid:$e,onlyRenderVisibleElements:Ce=!1,selectNodesOnDrag:_e,nodesDraggable:Be,autoPanOnNodeFocus:ot,nodesConnectable:yt,nodesFocusable:Te,nodeOrigin:st=VI,edgesFocusable:gt,edgesReconnectable:xe,elementsSelectable:Fe=!0,defaultViewport:lt=o5,minZoom:oe=.5,maxZoom:ke=2,translateExtent:Ke=Ld,preventScrolling:Ue=!0,nodeExtent:be,defaultMarkerColor:Ht="#b1b1b7",zoomOnScroll:Qt=!0,zoomOnPinch:jt=!0,panOnScroll:yn=!1,panOnScrollSpeed:on=.5,panOnScrollMode:re=Fa.Free,zoomOnDoubleClick:Re=!0,panOnDrag:Je=!0,onPaneClick:Ze,onPaneMouseEnter:Tt,onPaneMouseMove:At,onPaneMouseLeave:Vn,onPaneScroll:Sn,onPaneContextMenu:xr,paneClickDistance:wn=1,nodeClickDistance:Xn=0,children:Kn,onReconnect:hr,onReconnectStart:ts,onReconnectEnd:Ar,onEdgeContextMenu:gs,onEdgeDoubleClick:ys,onEdgeMouseEnter:cn,onEdgeMouseMove:rr,onEdgeMouseLeave:Pr,reconnectRadius:dn=10,onNodesChange:Qn,onEdgesChange:br,noDragClassName:sr="nodrag",noWheelClassName:Ct="nowheel",noPanClassName:Gt="nopan",fitView:_t,fitViewOptions:le,connectOnClick:ve,attributionPosition:it,proOptions:Dt,defaultEdgeOptions:Jt,elevateNodesOnSelect:tn=!0,elevateEdgesOnSelect:Zn=!1,disableKeyboardA11y:mt=!1,autoPanOnConnect:nn,autoPanOnNodeDrag:Wt,autoPanSpeed:kr,connectionRadius:tt,isValidConnection:Ln,onError:$i,style:zr,id:mo,nodeDragThreshold:ai,connectionDragThreshold:Ts,viewport:ie,onViewportChange:Se,width:Pe,height:xt,colorMode:Lt="light",debug:qt,onScroll:zn,ariaLabelConfig:On,zIndexMode:q="basic",...he},Oe){const Ee=mo||"1",et=u5(Lt),Nn=m.useCallback(kt=>{kt.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),zn==null||zn(kt)},[zn]);return i.jsx("div",{"data-testid":"rf__wrapper",...he,onScroll:Nn,style:{...zr,...AW},ref:Oe,className:Jn(["react-flow",s,et]),id:mo,role:"application",children:i.jsxs(EW,{nodes:e,edges:t,width:Pe,height:xt,fitView:_t,fitViewOptions:le,minZoom:oe,maxZoom:ke,nodeOrigin:st,nodeExtent:be,zIndexMode:q,children:[i.jsx(c5,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:h,onConnectStart:y,onConnectEnd:k,onClickConnectStart:b,onClickConnectEnd:g,nodesDraggable:Be,autoPanOnNodeFocus:ot,nodesConnectable:yt,nodesFocusable:Te,edgesFocusable:gt,edgesReconnectable:xe,elementsSelectable:Fe,elevateNodesOnSelect:tn,elevateEdgesOnSelect:Zn,minZoom:oe,maxZoom:ke,nodeExtent:be,onNodesChange:Qn,onEdgesChange:br,snapToGrid:me,snapGrid:$e,connectionMode:Q,translateExtent:Ke,connectOnClick:ve,defaultEdgeOptions:Jt,fitView:_t,fitViewOptions:le,onNodesDelete:$,onEdgesDelete:L,onDelete:F,onNodeDragStart:P,onNodeDrag:I,onNodeDragStop:z,onSelectionDrag:K,onSelectionDragStart:M,onSelectionDragStop:H,onMove:d,onMoveStart:f,onMoveEnd:p,noPanClassName:Gt,nodeOrigin:st,rfId:Ee,autoPanOnConnect:nn,autoPanOnNodeDrag:Wt,autoPanSpeed:kr,onError:$i,connectionRadius:tt,isValidConnection:Ln,selectNodesOnDrag:_e,nodeDragThreshold:ai,connectionDragThreshold:Ts,onBeforeDelete:E,debug:qt,ariaLabelConfig:On,zIndexMode:q}),i.jsx(CW,{onInit:u,onNodeClick:l,onEdgeClick:c,onNodeMouseEnter:v,onNodeMouseMove:w,onNodeMouseLeave:N,onNodeContextMenu:j,onNodeDoubleClick:C,nodeTypes:o,edgeTypes:a,connectionLineType:V,connectionLineStyle:B,connectionLineComponent:se,connectionLineContainerStyle:ue,selectionKeyCode:ee,selectionOnDrag:te,selectionMode:ne,deleteKeyCode:G,multiSelectionKeyCode:ce,panActivationKeyCode:Z,zoomActivationKeyCode:de,onlyRenderVisibleElements:Ce,defaultViewport:lt,translateExtent:Ke,minZoom:oe,maxZoom:ke,preventScrolling:Ue,zoomOnScroll:Qt,zoomOnPinch:jt,zoomOnDoubleClick:Re,panOnScroll:yn,panOnScrollSpeed:on,panOnScrollMode:re,panOnDrag:Je,onPaneClick:Ze,onPaneMouseEnter:Tt,onPaneMouseMove:At,onPaneMouseLeave:Vn,onPaneScroll:Sn,onPaneContextMenu:xr,paneClickDistance:wn,nodeClickDistance:Xn,onSelectionContextMenu:D,onSelectionStart:T,onSelectionEnd:W,onReconnect:hr,onReconnectStart:ts,onReconnectEnd:Ar,onEdgeContextMenu:gs,onEdgeDoubleClick:ys,onEdgeMouseEnter:cn,onEdgeMouseMove:rr,onEdgeMouseLeave:Pr,reconnectRadius:dn,defaultMarkerColor:Ht,noDragClassName:sr,noWheelClassName:Ct,noPanClassName:Gt,rfId:Ee,disableKeyboardA11y:mt,nodeExtent:be,viewport:ie,onViewportChange:Se}),i.jsx(i5,{onSelectionChange:O}),Kn,i.jsx(e5,{proOptions:Dt,position:it}),i.jsx(Z4,{rfId:Ee,disableKeyboardA11y:mt})]})})}var gR=qI(PW);function IW(){const e=gn();return m.useCallback(t=>{const{domNode:n,updateNodeInternals:r}=e.getState(),s=Array.isArray(t)?t:[t],o=new Map;s.forEach(a=>{const l=n==null?void 0:n.querySelector(`.react-flow__node[data-id="${a}"]`);l&&o.set(a,{id:a,nodeElement:l,force:!0})}),requestAnimationFrame(()=>r(o,{triggerFitView:!1}))},[])}function RW(e){const[t,n]=m.useState(e),r=m.useCallback(s=>n(o=>ad(s,o)),[]);return[t,n,r]}function TW(e){const[t,n]=m.useState(e),r=m.useCallback(s=>n(o=>Qh(s,o)),[]);return[t,n,r]}function MW({dimensions:e,lineWidth:t,variant:n,className:r}){return i.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Jn(["react-flow__background-pattern",n,r])})}function $W({radius:e,className:t}){return i.jsx("circle",{cx:e,cy:e,r:e,className:Jn(["react-flow__background-pattern","dots",t])})}var Yo;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Yo||(Yo={}));const LW={[Yo.Dots]:1,[Yo.Lines]:1,[Yo.Cross]:6},OW=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function yR({id:e,variant:t=Yo.Dots,gap:n=20,size:r,lineWidth:s=1,offset:o=0,color:a,bgColor:l,style:c,className:u,patternClassName:d}){const f=m.useRef(null),{transform:p,patternId:h}=Bt(OW,_n),y=r||LW[t],k=t===Yo.Dots,b=t===Yo.Cross,g=Array.isArray(n)?n:[n,n],v=[g[0]*p[2]||1,g[1]*p[2]||1],w=y*p[2],N=Array.isArray(o)?o:[o,o],j=b?[w,w]:v,C=[N[0]*p[2]||1+j[0]/2,N[1]*p[2]||1+j[1]/2],P=`${h}${e||""}`;return i.jsxs("svg",{className:Jn(["react-flow__background",u]),style:{...c,...eg,"--xy-background-color-props":l,"--xy-background-pattern-color-props":a},ref:f,"data-testid":"rf__background",children:[i.jsx("pattern",{id:P,x:p[0]%v[0],y:p[1]%v[1],width:v[0],height:v[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${C[0]},-${C[1]})`,children:k?i.jsx($W,{radius:w/2,className:d}):i.jsx(MW,{dimensions:j,lineWidth:s,variant:t,className:d})}),i.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${P})`})]})}yR.displayName="Background";const wR=m.memo(yR);function DW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:i.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function FW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:i.jsx("path",{d:"M0 0h32v4.2H0z"})})}function zW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:i.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function BW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:i.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function HW(){return i.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:i.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Cp({children:e,className:t,...n}){return i.jsx("button",{type:"button",className:Jn(["react-flow__controls-button",t]),...n,children:e})}const WW=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function xR({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:o,onZoomOut:a,onFitView:l,onInteractiveChange:c,className:u,children:d,position:f="bottom-left",orientation:p="vertical","aria-label":h}){const y=gn(),{isInteractive:k,minZoomReached:b,maxZoomReached:g,ariaLabelConfig:v}=Bt(WW,_n),{zoomIn:w,zoomOut:N,fitView:j}=Fc(),C=()=>{w(),o==null||o()},P=()=>{N(),a==null||a()},I=()=>{j(s),l==null||l()},z=()=>{y.setState({nodesDraggable:!k,nodesConnectable:!k,elementsSelectable:!k}),c==null||c(!k)},$=p==="horizontal"?"horizontal":"vertical";return i.jsxs(Zm,{className:Jn(["react-flow__controls",$,u]),position:f,style:e,"data-testid":"rf__controls","aria-label":h??v["controls.ariaLabel"],children:[t&&i.jsxs(i.Fragment,{children:[i.jsx(Cp,{onClick:C,className:"react-flow__controls-zoomin",title:v["controls.zoomIn.ariaLabel"],"aria-label":v["controls.zoomIn.ariaLabel"],disabled:g,children:i.jsx(DW,{})}),i.jsx(Cp,{onClick:P,className:"react-flow__controls-zoomout",title:v["controls.zoomOut.ariaLabel"],"aria-label":v["controls.zoomOut.ariaLabel"],disabled:b,children:i.jsx(FW,{})})]}),n&&i.jsx(Cp,{className:"react-flow__controls-fitview",onClick:I,title:v["controls.fitView.ariaLabel"],"aria-label":v["controls.fitView.ariaLabel"],children:i.jsx(zW,{})}),r&&i.jsx(Cp,{className:"react-flow__controls-interactive",onClick:z,title:v["controls.interactive.ariaLabel"],"aria-label":v["controls.interactive.ariaLabel"],children:k?i.jsx(HW,{}):i.jsx(BW,{})}),d]})}xR.displayName="Controls";m.memo(xR);function VW({id:e,x:t,y:n,width:r,height:s,style:o,color:a,strokeColor:l,strokeWidth:c,className:u,borderRadius:d,shapeRendering:f,selected:p,onClick:h}){const{background:y,backgroundColor:k}=o||{},b=a||y||k;return i.jsx("rect",{className:Jn(["react-flow__minimap-node",{selected:p},u]),x:t,y:n,rx:d,ry:d,width:r,height:s,style:{fill:b,stroke:l,strokeWidth:c},shapeRendering:f,onClick:h?g=>h(g,e):void 0})}const KW=m.memo(VW),qW=e=>e.nodes.map(t=>t.id),By=e=>e instanceof Function?e:()=>e;function UW({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s,nodeComponent:o=KW,onClick:a}){const l=Bt(qW,_n),c=By(t),u=By(e),d=By(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return i.jsx(i.Fragment,{children:l.map(p=>i.jsx(GW,{id:p,nodeColorFunc:c,nodeStrokeColorFunc:u,nodeClassNameFunc:d,nodeBorderRadius:r,nodeStrokeWidth:s,NodeComponent:o,onClick:a,shapeRendering:f},p))})}function YW({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:r,nodeBorderRadius:s,nodeStrokeWidth:o,shapeRendering:a,NodeComponent:l,onClick:c}){const{node:u,x:d,y:f,width:p,height:h}=Bt(y=>{const k=y.nodeLookup.get(e);if(!k)return{node:void 0,x:0,y:0,width:0,height:0};const b=k.internals.userNode,{x:g,y:v}=k.internals.positionAbsolute,{width:w,height:N}=fo(b);return{node:b,x:g,y:v,width:w,height:N}},_n);return!u||u.hidden||!mI(u)?null:i.jsx(l,{x:d,y:f,width:p,height:h,style:u.style,selected:!!u.selected,className:r(u),color:t(u),borderRadius:s,strokeColor:n(u),strokeWidth:o,shapeRendering:a,onClick:c,id:u.id})}const GW=m.memo(YW);var JW=m.memo(UW);const XW=200,QW=150,ZW=e=>!e.hidden,e6=e=>{const t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?hI(df(e.nodeLookup,{filter:ZW}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},t6="react-flow__minimap-desc";function bR({style:e,className:t,nodeStrokeColor:n,nodeColor:r,nodeClassName:s="",nodeBorderRadius:o=5,nodeStrokeWidth:a,nodeComponent:l,bgColor:c,maskColor:u,maskStrokeColor:d,maskStrokeWidth:f,position:p="bottom-right",onClick:h,onNodeClick:y,pannable:k=!1,zoomable:b=!1,ariaLabel:g,inversePan:v,zoomStep:w=1,offsetScale:N=5}){const j=gn(),C=m.useRef(null),{boundingRect:P,viewBB:I,rfId:z,panZoom:$,translateExtent:L,flowWidth:F,flowHeight:O,ariaLabelConfig:M}=Bt(e6,_n),K=(e==null?void 0:e.width)??XW,H=(e==null?void 0:e.height)??QW,D=P.width/K,T=P.height/H,W=Math.max(D,T),E=W*K,Q=W*H,V=N*W,B=P.x-(E-P.width)/2-V,se=P.y-(Q-P.height)/2-V,ue=E+V*2,G=Q+V*2,ee=`${t6}-${z}`,te=m.useRef(0),ne=m.useRef();te.current=W,m.useEffect(()=>{if(C.current&&$)return ne.current=a4({domNode:C.current,panZoom:$,getTransform:()=>j.getState().transform,getViewScale:()=>te.current}),()=>{var me;(me=ne.current)==null||me.destroy()}},[$]),m.useEffect(()=>{var me;(me=ne.current)==null||me.update({translateExtent:L,width:F,height:O,inversePan:v,pannable:k,zoomStep:w,zoomable:b})},[k,b,v,w,L,F,O]);const Z=h?me=>{var _e;const[$e,Ce]=((_e=ne.current)==null?void 0:_e.pointer(me))||[0,0];h(me,{x:$e,y:Ce})}:void 0,ce=y?m.useCallback((me,$e)=>{const Ce=j.getState().nodeLookup.get($e).internals.userNode;y(me,Ce)},[]):void 0,de=g??M["minimap.ariaLabel"];return i.jsx(Zm,{position:p,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-stroke-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*W:void 0,"--xy-minimap-node-background-color-props":typeof r=="string"?r:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof a=="number"?a:void 0},className:Jn(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:i.jsxs("svg",{width:K,height:H,viewBox:`${B} ${se} ${ue} ${G}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":ee,ref:C,onClick:Z,children:[de&&i.jsx("title",{id:ee,children:de}),i.jsx(JW,{onClick:ce,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:o,nodeClassName:s,nodeStrokeWidth:a,nodeComponent:l}),i.jsx("path",{className:"react-flow__minimap-mask",d:`M${B-V},${se-V}h${ue+V*2}v${G+V*2}h${-ue-V*2}z
66
66
  M${I.x},${I.y}h${I.width}v${I.height}h${-I.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}bR.displayName="MiniMap";m.memo(bR);const n6=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,r6={[Pc.Line]:"right",[Pc.Handle]:"bottom-right"};function s6({nodeId:e,position:t,variant:n=Pc.Handle,className:r,style:s=void 0,children:o,color:a,minWidth:l=10,minHeight:c=10,maxWidth:u=Number.MAX_VALUE,maxHeight:d=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:p,autoScale:h=!0,shouldResize:y,onResizeStart:k,onResize:b,onResizeEnd:g}){const v=JI(),w=typeof e=="string"?e:v,N=gn(),j=m.useRef(null),C=n===Pc.Handle,P=Bt(m.useCallback(n6(C&&h),[C,h]),_n),I=m.useRef(null),z=t??r6[n];m.useEffect(()=>{if(!(!j.current||!w))return I.current||(I.current=k4({domNode:j.current,nodeId:w,getStoreItems:()=>{const{nodeLookup:L,transform:F,snapGrid:O,snapToGrid:M,nodeOrigin:K,domNode:H}=N.getState();return{nodeLookup:L,transform:F,snapGrid:O,snapToGrid:M,nodeOrigin:K,paneDomNode:H}},onChange:(L,F)=>{const{triggerNodeChanges:O,nodeLookup:M,parentLookup:K,nodeOrigin:H}=N.getState(),D=[],T={x:L.x,y:L.y},W=M.get(w);if(W&&W.expandParent&&W.parentId){const E=W.origin??H,Q=L.width??W.measured.width??0,V=L.height??W.measured.height??0,B={id:W.id,parentId:W.parentId,rect:{width:Q,height:V,...gI({x:L.x??W.position.x,y:L.y??W.position.y},{width:Q,height:V},W.parentId,M,E)}},se=Ok([B],M,K,H);D.push(...se),T.x=L.x?Math.max(E[0]*Q,L.x):void 0,T.y=L.y?Math.max(E[1]*V,L.y):void 0}if(T.x!==void 0&&T.y!==void 0){const E={id:w,type:"position",position:{...T}};D.push(E)}if(L.width!==void 0&&L.height!==void 0){const Q={id:w,type:"dimensions",resizing:!0,setAttributes:p?p==="horizontal"?"width":"height":!0,dimensions:{width:L.width,height:L.height}};D.push(Q)}for(const E of F){const Q={...E,type:"position"};D.push(Q)}O(D)},onEnd:({width:L,height:F})=>{const O={id:w,type:"dimensions",resizing:!1,dimensions:{width:L,height:F}};N.getState().triggerNodeChanges([O])}})),I.current.update({controlPosition:z,boundaries:{minWidth:l,minHeight:c,maxWidth:u,maxHeight:d},keepAspectRatio:f,resizeDirection:p,onResizeStart:k,onResize:b,onResizeEnd:g,shouldResize:y}),()=>{var L;(L=I.current)==null||L.destroy()}},[z,l,c,u,d,f,k,b,g,y]);const $=z.split("-");return i.jsx("div",{className:Jn(["react-flow__resize-control","nodrag",...$,n,r]),ref:j,style:{...s,scale:P,...a&&{[C?"backgroundColor":"borderColor"]:a}},children:o})}const zk=m.memo(s6),i6="modulepreload",o6=function(e){return"/"+e},s1={},a6=function(t,n,r){let s=Promise.resolve();if(n&&n.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),l=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));s=Promise.allSettled(n.map(c=>{if(c=o6(c),c in s1)return;s1[c]=!0;const u=c.endsWith(".css"),d=u?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${d}`))return;const f=document.createElement("link");if(f.rel=u?"stylesheet":i6,u||(f.as="script"),f.crossOrigin="",f.href=c,l&&f.setAttribute("nonce",l),document.head.appendChild(f),u)return new Promise((p,h)=>{f.addEventListener("load",p),f.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${c}`)))})}))}function o(a){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=a,window.dispatchEvent(l),!l.defaultPrevented)throw a}return s.then(a=>{for(const l of a||[])l.status==="rejected"&&o(l.reason);return t().catch(o)})};function l6(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const c6=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,u6=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,d6={};function i1(e,t){return(d6.jsx?u6:c6).test(e)}const f6=/[ \t\n\f\r]/g;function p6(e){return typeof e=="object"?e.type==="text"?o1(e.value):!1:o1(e)}function o1(e){return e.replace(f6,"")===""}class hf{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}hf.prototype.normal={};hf.prototype.property={};hf.prototype.space=void 0;function kR(e,t){const n={},r={};for(const s of e)Object.assign(n,s.property),Object.assign(r,s.normal);return new hf(n,r,t)}function Bx(e){return e.toLowerCase()}class es{constructor(t,n){this.attribute=n,this.property=t}}es.prototype.attribute="";es.prototype.booleanish=!1;es.prototype.boolean=!1;es.prototype.commaOrSpaceSeparated=!1;es.prototype.commaSeparated=!1;es.prototype.defined=!1;es.prototype.mustUseProperty=!1;es.prototype.number=!1;es.prototype.overloadedBoolean=!1;es.prototype.property="";es.prototype.spaceSeparated=!1;es.prototype.space=void 0;let h6=0;const St=ol(),Un=ol(),Hx=ol(),Ie=ol(),pn=ol(),dc=ol(),ss=ol();function ol(){return 2**++h6}const Wx=Object.freeze(Object.defineProperty({__proto__:null,boolean:St,booleanish:Un,commaOrSpaceSeparated:ss,commaSeparated:dc,number:Ie,overloadedBoolean:Hx,spaceSeparated:pn},Symbol.toStringTag,{value:"Module"})),Hy=Object.keys(Wx);class Bk extends es{constructor(t,n,r,s){let o=-1;if(super(t,n),a1(this,"space",s),typeof r=="number")for(;++o<Hy.length;){const a=Hy[o];a1(this,Hy[o],(r&Wx[a])===Wx[a])}}}Bk.prototype.defined=!0;function a1(e,t,n){n&&(e[t]=n)}function zc(e){const t={},n={};for(const[r,s]of Object.entries(e.properties)){const o=new Bk(r,e.transform(e.attributes||{},r),s,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(o.mustUseProperty=!0),t[r]=o,n[Bx(r)]=r,n[Bx(o.attribute)]=r}return new hf(t,n,e.space)}const vR=zc({properties:{ariaActiveDescendant:null,ariaAtomic:Un,ariaAutoComplete:null,ariaBusy:Un,ariaChecked:Un,ariaColCount:Ie,ariaColIndex:Ie,ariaColSpan:Ie,ariaControls:pn,ariaCurrent:null,ariaDescribedBy:pn,ariaDetails:null,ariaDisabled:Un,ariaDropEffect:pn,ariaErrorMessage:null,ariaExpanded:Un,ariaFlowTo:pn,ariaGrabbed:Un,ariaHasPopup:null,ariaHidden:Un,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:pn,ariaLevel:Ie,ariaLive:null,ariaModal:Un,ariaMultiLine:Un,ariaMultiSelectable:Un,ariaOrientation:null,ariaOwns:pn,ariaPlaceholder:null,ariaPosInSet:Ie,ariaPressed:Un,ariaReadOnly:Un,ariaRelevant:null,ariaRequired:Un,ariaRoleDescription:pn,ariaRowCount:Ie,ariaRowIndex:Ie,ariaRowSpan:Ie,ariaSelected:Un,ariaSetSize:Ie,ariaSort:null,ariaValueMax:Ie,ariaValueMin:Ie,ariaValueNow:Ie,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function SR(e,t){return t in e?e[t]:t}function NR(e,t){return SR(e,t.toLowerCase())}const m6=zc({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:dc,acceptCharset:pn,accessKey:pn,action:null,allow:null,allowFullScreen:St,allowPaymentRequest:St,allowUserMedia:St,alt:null,as:null,async:St,autoCapitalize:null,autoComplete:pn,autoFocus:St,autoPlay:St,blocking:pn,capture:null,charSet:null,checked:St,cite:null,className:pn,cols:Ie,colSpan:null,content:null,contentEditable:Un,controls:St,controlsList:pn,coords:Ie|dc,crossOrigin:null,data:null,dateTime:null,decoding:null,default:St,defer:St,dir:null,dirName:null,disabled:St,download:Hx,draggable:Un,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:St,formTarget:null,headers:pn,height:Ie,hidden:Hx,high:Ie,href:null,hrefLang:null,htmlFor:pn,httpEquiv:pn,id:null,imageSizes:null,imageSrcSet:null,inert:St,inputMode:null,integrity:null,is:null,isMap:St,itemId:null,itemProp:pn,itemRef:pn,itemScope:St,itemType:pn,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:St,low:Ie,manifest:null,max:null,maxLength:Ie,media:null,method:null,min:null,minLength:Ie,multiple:St,muted:St,name:null,nonce:null,noModule:St,noValidate:St,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:St,optimum:Ie,pattern:null,ping:pn,placeholder:null,playsInline:St,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:St,referrerPolicy:null,rel:pn,required:St,reversed:St,rows:Ie,rowSpan:Ie,sandbox:pn,scope:null,scoped:St,seamless:St,selected:St,shadowRootClonable:St,shadowRootDelegatesFocus:St,shadowRootMode:null,shape:null,size:Ie,sizes:null,slot:null,span:Ie,spellCheck:Un,src:null,srcDoc:null,srcLang:null,srcSet:null,start:Ie,step:null,style:null,tabIndex:Ie,target:null,title:null,translate:null,type:null,typeMustMatch:St,useMap:null,value:Un,width:Ie,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:pn,axis:null,background:null,bgColor:null,border:Ie,borderColor:null,bottomMargin:Ie,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:St,declare:St,event:null,face:null,frame:null,frameBorder:null,hSpace:Ie,leftMargin:Ie,link:null,longDesc:null,lowSrc:null,marginHeight:Ie,marginWidth:Ie,noResize:St,noHref:St,noShade:St,noWrap:St,object:null,profile:null,prompt:null,rev:null,rightMargin:Ie,rules:null,scheme:null,scrolling:Un,standby:null,summary:null,text:null,topMargin:Ie,valueType:null,version:null,vAlign:null,vLink:null,vSpace:Ie,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:St,disableRemotePlayback:St,prefix:null,property:null,results:Ie,security:null,unselectable:null},space:"html",transform:NR}),g6=zc({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:ss,accentHeight:Ie,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:Ie,amplitude:Ie,arabicForm:null,ascent:Ie,attributeName:null,attributeType:null,azimuth:Ie,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:Ie,by:null,calcMode:null,capHeight:Ie,className:pn,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:Ie,diffuseConstant:Ie,direction:null,display:null,dur:null,divisor:Ie,dominantBaseline:null,download:St,dx:null,dy:null,edgeMode:null,editable:null,elevation:Ie,enableBackground:null,end:null,event:null,exponent:Ie,externalResourcesRequired:null,fill:null,fillOpacity:Ie,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:dc,g2:dc,glyphName:dc,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:Ie,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:Ie,horizOriginX:Ie,horizOriginY:Ie,id:null,ideographic:Ie,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:Ie,k:Ie,k1:Ie,k2:Ie,k3:Ie,k4:Ie,kernelMatrix:ss,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:Ie,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:Ie,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:Ie,overlineThickness:Ie,paintOrder:null,panose1:null,path:null,pathLength:Ie,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:pn,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:Ie,pointsAtY:Ie,pointsAtZ:Ie,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:ss,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:ss,rev:ss,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:ss,requiredFeatures:ss,requiredFonts:ss,requiredFormats:ss,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:Ie,specularExponent:Ie,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:Ie,strikethroughThickness:Ie,string:null,stroke:null,strokeDashArray:ss,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:Ie,strokeOpacity:Ie,strokeWidth:null,style:null,surfaceScale:Ie,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:ss,tabIndex:Ie,tableValues:null,target:null,targetX:Ie,targetY:Ie,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:ss,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:Ie,underlineThickness:Ie,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:Ie,values:null,vAlphabetic:Ie,vMathematical:Ie,vectorEffect:null,vHanging:Ie,vIdeographic:Ie,version:null,vertAdvY:Ie,vertOriginX:Ie,vertOriginY:Ie,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:Ie,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:SR}),jR=zc({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),CR=zc({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:NR}),_R=zc({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),y6={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},w6=/[A-Z]/g,l1=/-[a-z]/g,x6=/^data[-\w.:]+$/i;function b6(e,t){const n=Bx(t);let r=t,s=es;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&x6.test(t)){if(t.charAt(4)==="-"){const o=t.slice(5).replace(l1,v6);r="data"+o.charAt(0).toUpperCase()+o.slice(1)}else{const o=t.slice(4);if(!l1.test(o)){let a=o.replace(w6,k6);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}s=Bk}return new s(r,t)}function k6(e){return"-"+e.toLowerCase()}function v6(e){return e.charAt(1).toUpperCase()}const S6=kR([vR,m6,jR,CR,_R],"html"),Hk=kR([vR,g6,jR,CR,_R],"svg");function N6(e){return e.join(" ").trim()}var Wk={},c1=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,j6=/\n/g,C6=/^\s*/,_6=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,E6=/^:\s*/,A6=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,P6=/^[;\s]*/,I6=/^\s+|\s+$/g,R6=`
67
67
  `,u1="/",d1="*",Ca="",T6="comment",M6="declaration";function $6(e,t){if(typeof e!="string")throw new TypeError("First argument must be a string");if(!e)return[];t=t||{};var n=1,r=1;function s(y){var k=y.match(j6);k&&(n+=k.length);var b=y.lastIndexOf(R6);r=~b?y.length-b:r+y.length}function o(){var y={line:n,column:r};return function(k){return k.position=new a(y),u(),k}}function a(y){this.start=y,this.end={line:n,column:r},this.source=t.source}a.prototype.content=e;function l(y){var k=new Error(t.source+":"+n+":"+r+": "+y);if(k.reason=y,k.filename=t.source,k.line=n,k.column=r,k.source=e,!t.silent)throw k}function c(y){var k=y.exec(e);if(k){var b=k[0];return s(b),e=e.slice(b.length),k}}function u(){c(C6)}function d(y){var k;for(y=y||[];k=f();)k!==!1&&y.push(k);return y}function f(){var y=o();if(!(u1!=e.charAt(0)||d1!=e.charAt(1))){for(var k=2;Ca!=e.charAt(k)&&(d1!=e.charAt(k)||u1!=e.charAt(k+1));)++k;if(k+=2,Ca===e.charAt(k-1))return l("End of comment missing");var b=e.slice(2,k-2);return r+=2,s(b),e=e.slice(k),r+=2,y({type:T6,comment:b})}}function p(){var y=o(),k=c(_6);if(k){if(f(),!c(E6))return l("property missing ':'");var b=c(A6),g=y({type:M6,property:f1(k[0].replace(c1,Ca)),value:b?f1(b[0].replace(c1,Ca)):Ca});return c(P6),g}}function h(){var y=[];d(y);for(var k;k=p();)k!==!1&&(y.push(k),d(y));return y}return u(),h()}function f1(e){return e?e.replace(I6,Ca):Ca}var L6=$6,O6=hd&&hd.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Wk,"__esModule",{value:!0});Wk.default=F6;const D6=O6(L6);function F6(e,t){let n=null;if(!e||typeof e!="string")return n;const r=(0,D6.default)(e),s=typeof t=="function";return r.forEach(o=>{if(o.type!=="declaration")return;const{property:a,value:l}=o;s?t(a,l,o):l&&(n=n||{},n[a]=l)}),n}var ng={};Object.defineProperty(ng,"__esModule",{value:!0});ng.camelCase=void 0;var z6=/^--[a-zA-Z0-9_-]+$/,B6=/-([a-z])/g,H6=/^[^-]+$/,W6=/^-(webkit|moz|ms|o|khtml)-/,V6=/^-(ms)-/,K6=function(e){return!e||H6.test(e)||z6.test(e)},q6=function(e,t){return t.toUpperCase()},p1=function(e,t){return"".concat(t,"-")},U6=function(e,t){return t===void 0&&(t={}),K6(e)?e:(e=e.toLowerCase(),t.reactCompat?e=e.replace(V6,p1):e=e.replace(W6,p1),e.replace(B6,q6))};ng.camelCase=U6;var Y6=hd&&hd.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},G6=Y6(Wk),J6=ng;function Vx(e,t){var n={};return!e||typeof e!="string"||(0,G6.default)(e,function(r,s){r&&s&&(n[(0,J6.camelCase)(r,t)]=s)}),n}Vx.default=Vx;var X6=Vx;const Q6=sa(X6),ER=AR("end"),Vk=AR("start");function AR(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function Z6(e){const t=Vk(e),n=ER(e);if(t&&n)return{start:t,end:n}}function ld(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?h1(e.position):"start"in e||"end"in e?h1(e):"line"in e||"column"in e?Kx(e):""}function Kx(e){return m1(e&&e.line)+":"+m1(e&&e.column)}function h1(e){return Kx(e&&e.start)+"-"+Kx(e&&e.end)}function m1(e){return e&&typeof e=="number"?e:1}class Er extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let s="",o={},a=!1;if(n&&("line"in n&&"column"in n?o={place:n}:"start"in n&&"end"in n?o={place:n}:"type"in n?o={ancestors:[n],place:n.position}:o={...n}),typeof t=="string"?s=t:!o.cause&&t&&(a=!0,s=t.message,o.cause=t),!o.ruleId&&!o.source&&typeof r=="string"){const c=r.indexOf(":");c===-1?o.ruleId=r:(o.source=r.slice(0,c),o.ruleId=r.slice(c+1))}if(!o.place&&o.ancestors&&o.ancestors){const c=o.ancestors[o.ancestors.length-1];c&&(o.place=c.position)}const l=o.place&&"start"in o.place?o.place.start:o.place;this.ancestors=o.ancestors||void 0,this.cause=o.cause||void 0,this.column=l?l.column:void 0,this.fatal=void 0,this.file="",this.message=s,this.line=l?l.line:void 0,this.name=ld(o.place)||"1:1",this.place=o.place||void 0,this.reason=this.message,this.ruleId=o.ruleId||void 0,this.source=o.source||void 0,this.stack=a&&o.cause&&typeof o.cause.stack=="string"?o.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}Er.prototype.file="";Er.prototype.name="";Er.prototype.reason="";Er.prototype.message="";Er.prototype.stack="";Er.prototype.column=void 0;Er.prototype.line=void 0;Er.prototype.ancestors=void 0;Er.prototype.cause=void 0;Er.prototype.fatal=void 0;Er.prototype.place=void 0;Er.prototype.ruleId=void 0;Er.prototype.source=void 0;const Kk={}.hasOwnProperty,e8=new Map,t8=/[A-Z]/g,n8=new Set(["table","tbody","thead","tfoot","tr"]),r8=new Set(["td","th"]),PR="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function s8(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=f8(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=d8(n,t.jsx,t.jsxs)}const s={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?Hk:S6,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},o=IR(s,e,void 0);return o&&typeof o!="string"?o:s.create(e,s.Fragment,{children:o||void 0},void 0)}function IR(e,t,n){if(t.type==="element")return i8(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return o8(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return l8(e,t,n);if(t.type==="mdxjsEsm")return a8(e,t);if(t.type==="root")return c8(e,t,n);if(t.type==="text")return u8(e,t)}function i8(e,t,n){const r=e.schema;let s=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(s=Hk,e.schema=s),e.ancestors.push(t);const o=TR(e,t.tagName,!1),a=p8(e,t);let l=Uk(e,t);return n8.has(t.tagName)&&(l=l.filter(function(c){return typeof c=="string"?!p6(c):!0})),RR(e,a,o,t),qk(a,l),e.ancestors.pop(),e.schema=r,e.create(t,o,a,n)}function o8(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}Bd(e,t.position)}function a8(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Bd(e,t.position)}function l8(e,t,n){const r=e.schema;let s=r;t.name==="svg"&&r.space==="html"&&(s=Hk,e.schema=s),e.ancestors.push(t);const o=t.name===null?e.Fragment:TR(e,t.name,!0),a=h8(e,t),l=Uk(e,t);return RR(e,a,o,t),qk(a,l),e.ancestors.pop(),e.schema=r,e.create(t,o,a,n)}function c8(e,t,n){const r={};return qk(r,Uk(e,t)),e.create(t,e.Fragment,r,n)}function u8(e,t){return t.value}function RR(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function qk(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function d8(e,t,n){return r;function r(s,o,a,l){const u=Array.isArray(a.children)?n:t;return l?u(o,a,l):u(o,a)}}function f8(e,t){return n;function n(r,s,o,a){const l=Array.isArray(o.children),c=Vk(r);return t(s,o,a,l,{columnNumber:c?c.column-1:void 0,fileName:e,lineNumber:c?c.line:void 0},void 0)}}function p8(e,t){const n={};let r,s;for(s in t.properties)if(s!=="children"&&Kk.call(t.properties,s)){const o=m8(e,s,t.properties[s]);if(o){const[a,l]=o;e.tableCellAlignToStyle&&a==="align"&&typeof l=="string"&&r8.has(t.tagName)?r=l:n[a]=l}}if(r){const o=n.style||(n.style={});o[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function h8(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const o=r.data.estree.body[0];o.type;const a=o.expression;a.type;const l=a.properties[0];l.type,Object.assign(n,e.evaluater.evaluateExpression(l.argument))}else Bd(e,t.position);else{const s=r.name;let o;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const l=r.value.data.estree.body[0];l.type,o=e.evaluater.evaluateExpression(l.expression)}else Bd(e,t.position);else o=r.value===null?!0:r.value;n[s]=o}return n}function Uk(e,t){const n=[];let r=-1;const s=e.passKeys?new Map:e8;for(;++r<t.children.length;){const o=t.children[r];let a;if(e.passKeys){const c=o.type==="element"?o.tagName:o.type==="mdxJsxFlowElement"||o.type==="mdxJsxTextElement"?o.name:void 0;if(c){const u=s.get(c)||0;a=c+"-"+u,s.set(c,u+1)}}const l=IR(e,o,a);l!==void 0&&n.push(l)}return n}function m8(e,t,n){const r=b6(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?l6(n):N6(n)),r.property==="style"){let s=typeof n=="object"?n:g8(e,String(n));return e.stylePropertyNameCase==="css"&&(s=y8(s)),["style",s]}return[e.elementAttributeNameCase==="react"&&r.space?y6[r.property]||r.property:r.attribute,n]}}function g8(e,t){try{return Q6(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,s=new Er("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw s.file=e.filePath||void 0,s.url=PR+"#cannot-parse-style-attribute",s}}function TR(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const s=t.split(".");let o=-1,a;for(;++o<s.length;){const l=i1(s[o])?{type:"Identifier",name:s[o]}:{type:"Literal",value:s[o]};a=a?{type:"MemberExpression",object:a,property:l,computed:!!(o&&l.type==="Literal"),optional:!1}:l}r=a}else r=i1(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const s=r.value;return Kk.call(e.components,s)?e.components[s]:s}if(e.evaluater)return e.evaluater.evaluateExpression(r);Bd(e)}function Bd(e,t){const n=new Er("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=PR+"#cannot-handle-mdx-estrees-without-createevaluater",n}function y8(e){const t={};let n;for(n in e)Kk.call(e,n)&&(t[w8(n)]=e[n]);return t}function w8(e){let t=e.replace(t8,x8);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function x8(e){return"-"+e.toLowerCase()}const Wy={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},b8={};function k8(e,t){const n=b8,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,s=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return MR(e,r,s)}function MR(e,t,n){if(v8(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return g1(e.children,t,n)}return Array.isArray(e)?g1(e,t,n):""}function g1(e,t,n){const r=[];let s=-1;for(;++s<e.length;)r[s]=MR(e[s],t,n);return r.join("")}function v8(e){return!!(e&&typeof e=="object")}const y1=document.createElement("i");function Yk(e){const t="&"+e+";";y1.innerHTML=t;const n=y1.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function Ri(e,t,n,r){const s=e.length;let o=0,a;if(t<0?t=-t>s?0:s+t:t=t>s?s:t,n=n>0?n:0,r.length<1e4)a=Array.from(r),a.unshift(t,n),e.splice(...a);else for(n&&e.splice(t,n);o<r.length;)a=r.slice(o,o+1e4),a.unshift(t,0),e.splice(...a),o+=1e4,t+=1e4}function _s(e,t){return e.length>0?(Ri(e,e.length,0,t),e):t}const w1={}.hasOwnProperty;function S8(e){const t={};let n=-1;for(;++n<e.length;)N8(t,e[n]);return t}function N8(e,t){let n;for(n in t){const s=(w1.call(e,n)?e[n]:void 0)||(e[n]={}),o=t[n];let a;if(o)for(a in o){w1.call(s,a)||(s[a]=[]);const l=o[a];j8(s[a],Array.isArray(l)?l:l?[l]:[])}}}function j8(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);Ri(e,0,0,r)}function $R(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function fc(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const ki=la(/[A-Za-z]/),cs=la(/[\dA-Za-z]/),C8=la(/[#-'*+\--9=?A-Z^-~]/);function qx(e){return e!==null&&(e<32||e===127)}const Ux=la(/\d/),_8=la(/[\dA-Fa-f]/),E8=la(/[!-/:-@[-`{-~]/);function wt(e){return e!==null&&e<-2}function Zr(e){return e!==null&&(e<0||e===32)}function Xt(e){return e===-2||e===-1||e===32}const A8=la(new RegExp("\\p{P}|\\p{S}","u")),P8=la(/\s/);function la(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Bc(e){const t=[];let n=-1,r=0,s=0;for(;++n<e.length;){const o=e.charCodeAt(n);let a="";if(o===37&&cs(e.charCodeAt(n+1))&&cs(e.charCodeAt(n+2)))s=2;else if(o<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(o))||(a=String.fromCharCode(o));else if(o>55295&&o<57344){const l=e.charCodeAt(n+1);o<56320&&l>56319&&l<57344?(a=String.fromCharCode(o,l),s=1):a="�"}else a=String.fromCharCode(o);a&&(t.push(e.slice(r,n),encodeURIComponent(a)),r=n+s+1,a=""),s&&(n+=s,s=0)}return t.join("")+e.slice(r)}function mn(e,t,n,r){const s=r?r-1:Number.POSITIVE_INFINITY;let o=0;return a;function a(c){return Xt(c)?(e.enter(n),l(c)):t(c)}function l(c){return Xt(c)&&o++<s?(e.consume(c),l):(e.exit(n),t(c))}}const I8={tokenize:R8};function R8(e){const t=e.attempt(this.parser.constructs.contentInitial,r,s);let n;return t;function r(l){if(l===null){e.consume(l);return}return e.enter("lineEnding"),e.consume(l),e.exit("lineEnding"),mn(e,t,"linePrefix")}function s(l){return e.enter("paragraph"),o(l)}function o(l){const c=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=c),n=c,a(l)}function a(l){if(l===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(l);return}return wt(l)?(e.consume(l),e.exit("chunkText"),o):(e.consume(l),a)}}const T8={tokenize:M8},x1={tokenize:$8};function M8(e){const t=this,n=[];let r=0,s,o,a;return l;function l(w){if(r<n.length){const N=n[r];return t.containerState=N[1],e.attempt(N[0].continuation,c,u)(w)}return u(w)}function c(w){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,s&&v();const N=t.events.length;let j=N,C;for(;j--;)if(t.events[j][0]==="exit"&&t.events[j][1].type==="chunkFlow"){C=t.events[j][1].end;break}g(r);let P=N;for(;P<t.events.length;)t.events[P][1].end={...C},P++;return Ri(t.events,j+1,0,t.events.slice(N)),t.events.length=P,u(w)}return l(w)}function u(w){if(r===n.length){if(!s)return p(w);if(s.currentConstruct&&s.currentConstruct.concrete)return y(w);t.interrupt=!!(s.currentConstruct&&!s._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(x1,d,f)(w)}function d(w){return s&&v(),g(r),p(w)}function f(w){return t.parser.lazy[t.now().line]=r!==n.length,a=t.now().offset,y(w)}function p(w){return t.containerState={},e.attempt(x1,h,y)(w)}function h(w){return r++,n.push([t.currentConstruct,t.containerState]),p(w)}function y(w){if(w===null){s&&v(),g(0),e.consume(w);return}return s=s||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:s,contentType:"flow",previous:o}),k(w)}function k(w){if(w===null){b(e.exit("chunkFlow"),!0),g(0),e.consume(w);return}return wt(w)?(e.consume(w),b(e.exit("chunkFlow")),r=0,t.interrupt=void 0,l):(e.consume(w),k)}function b(w,N){const j=t.sliceStream(w);if(N&&j.push(null),w.previous=o,o&&(o.next=w),o=w,s.defineSkip(w.start),s.write(j),t.parser.lazy[w.start.line]){let C=s.events.length;for(;C--;)if(s.events[C][1].start.offset<a&&(!s.events[C][1].end||s.events[C][1].end.offset>a))return;const P=t.events.length;let I=P,z,$;for(;I--;)if(t.events[I][0]==="exit"&&t.events[I][1].type==="chunkFlow"){if(z){$=t.events[I][1].end;break}z=!0}for(g(r),C=P;C<t.events.length;)t.events[C][1].end={...$},C++;Ri(t.events,I+1,0,t.events.slice(P)),t.events.length=C}}function g(w){let N=n.length;for(;N-- >w;){const j=n[N];t.containerState=j[1],j[0].exit.call(t,e)}n.length=w}function v(){s.write([null]),o=void 0,s=void 0,t.containerState._closeFlow=void 0}}function $8(e,t,n){return mn(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function b1(e){if(e===null||Zr(e)||P8(e))return 1;if(A8(e))return 2}function Gk(e,t,n){const r=[];let s=-1;for(;++s<e.length;){const o=e[s].resolveAll;o&&!r.includes(o)&&(t=o(t,n),r.push(o))}return t}const Yx={name:"attention",resolveAll:L8,tokenize:O8};function L8(e,t){let n=-1,r,s,o,a,l,c,u,d;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;c=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const f={...e[r][1].end},p={...e[n][1].start};k1(f,-c),k1(p,c),a={type:c>1?"strongSequence":"emphasisSequence",start:f,end:{...e[r][1].end}},l={type:c>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:p},o={type:c>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},s={type:c>1?"strong":"emphasis",start:{...a.start},end:{...l.end}},e[r][1].end={...a.start},e[n][1].start={...l.end},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=_s(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=_s(u,[["enter",s,t],["enter",a,t],["exit",a,t],["enter",o,t]]),u=_s(u,Gk(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=_s(u,[["exit",o,t],["enter",l,t],["exit",l,t],["exit",s,t]]),e[n][1].end.offset-e[n][1].start.offset?(d=2,u=_s(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):d=0,Ri(e,r-1,n-r+3,u),n=r+u.length-d-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function O8(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,s=b1(r);let o;return a;function a(c){return o=c,e.enter("attentionSequence"),l(c)}function l(c){if(c===o)return e.consume(c),l;const u=e.exit("attentionSequence"),d=b1(c),f=!d||d===2&&s||n.includes(c),p=!s||s===2&&d||n.includes(r);return u._open=!!(o===42?f:f&&(s||!p)),u._close=!!(o===42?p:p&&(d||!f)),t(c)}}function k1(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const D8={name:"autolink",tokenize:F8};function F8(e,t,n){let r=0;return s;function s(h){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),o}function o(h){return ki(h)?(e.consume(h),a):h===64?n(h):u(h)}function a(h){return h===43||h===45||h===46||cs(h)?(r=1,l(h)):u(h)}function l(h){return h===58?(e.consume(h),r=0,c):(h===43||h===45||h===46||cs(h))&&r++<32?(e.consume(h),l):(r=0,u(h))}function c(h){return h===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.exit("autolink"),t):h===null||h===32||h===60||qx(h)?n(h):(e.consume(h),c)}function u(h){return h===64?(e.consume(h),d):C8(h)?(e.consume(h),u):n(h)}function d(h){return cs(h)?f(h):n(h)}function f(h){return h===46?(e.consume(h),r=0,d):h===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.exit("autolink"),t):p(h)}function p(h){if((h===45||cs(h))&&r++<63){const y=h===45?p:f;return e.consume(h),y}return n(h)}}const rg={partial:!0,tokenize:z8};function z8(e,t,n){return r;function r(o){return Xt(o)?mn(e,s,"linePrefix")(o):s(o)}function s(o){return o===null||wt(o)?t(o):n(o)}}const LR={continuation:{tokenize:H8},exit:W8,name:"blockQuote",tokenize:B8};function B8(e,t,n){const r=this;return s;function s(a){if(a===62){const l=r.containerState;return l.open||(e.enter("blockQuote",{_container:!0}),l.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(a),e.exit("blockQuoteMarker"),o}return n(a)}function o(a){return Xt(a)?(e.enter("blockQuotePrefixWhitespace"),e.consume(a),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(a))}}function H8(e,t,n){const r=this;return s;function s(a){return Xt(a)?mn(e,o,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a):o(a)}function o(a){return e.attempt(LR,t,n)(a)}}function W8(e){e.exit("blockQuote")}const OR={name:"characterEscape",tokenize:V8};function V8(e,t,n){return r;function r(o){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(o),e.exit("escapeMarker"),s}function s(o){return E8(o)?(e.enter("characterEscapeValue"),e.consume(o),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(o)}}const DR={name:"characterReference",tokenize:K8};function K8(e,t,n){const r=this;let s=0,o,a;return l;function l(f){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),c}function c(f){return f===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(f),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),o=31,a=cs,d(f))}function u(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),o=6,a=_8,d):(e.enter("characterReferenceValue"),o=7,a=Ux,d(f))}function d(f){if(f===59&&s){const p=e.exit("characterReferenceValue");return a===cs&&!Yk(r.sliceSerialize(p))?n(f):(e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return a(f)&&s++<o?(e.consume(f),d):n(f)}}const v1={partial:!0,tokenize:U8},S1={concrete:!0,name:"codeFenced",tokenize:q8};function q8(e,t,n){const r=this,s={partial:!0,tokenize:j};let o=0,a=0,l;return c;function c(C){return u(C)}function u(C){const P=r.events[r.events.length-1];return o=P&&P[1].type==="linePrefix"?P[2].sliceSerialize(P[1],!0).length:0,l=C,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),d(C)}function d(C){return C===l?(a++,e.consume(C),d):a<3?n(C):(e.exit("codeFencedFenceSequence"),Xt(C)?mn(e,f,"whitespace")(C):f(C))}function f(C){return C===null||wt(C)?(e.exit("codeFencedFence"),r.interrupt?t(C):e.check(v1,k,N)(C)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),p(C))}function p(C){return C===null||wt(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(C)):Xt(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),mn(e,h,"whitespace")(C)):C===96&&C===l?n(C):(e.consume(C),p)}function h(C){return C===null||wt(C)?f(C):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),y(C))}function y(C){return C===null||wt(C)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(C)):C===96&&C===l?n(C):(e.consume(C),y)}function k(C){return e.attempt(s,N,b)(C)}function b(C){return e.enter("lineEnding"),e.consume(C),e.exit("lineEnding"),g}function g(C){return o>0&&Xt(C)?mn(e,v,"linePrefix",o+1)(C):v(C)}function v(C){return C===null||wt(C)?e.check(v1,k,N)(C):(e.enter("codeFlowValue"),w(C))}function w(C){return C===null||wt(C)?(e.exit("codeFlowValue"),v(C)):(e.consume(C),w)}function N(C){return e.exit("codeFenced"),t(C)}function j(C,P,I){let z=0;return $;function $(K){return C.enter("lineEnding"),C.consume(K),C.exit("lineEnding"),L}function L(K){return C.enter("codeFencedFence"),Xt(K)?mn(C,F,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(K):F(K)}function F(K){return K===l?(C.enter("codeFencedFenceSequence"),O(K)):I(K)}function O(K){return K===l?(z++,C.consume(K),O):z>=a?(C.exit("codeFencedFenceSequence"),Xt(K)?mn(C,M,"whitespace")(K):M(K)):I(K)}function M(K){return K===null||wt(K)?(C.exit("codeFencedFence"),P(K)):I(K)}}}function U8(e,t,n){const r=this;return s;function s(a){return a===null?n(a):(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),o)}function o(a){return r.parser.lazy[r.now().line]?n(a):t(a)}}const Vy={name:"codeIndented",tokenize:G8},Y8={partial:!0,tokenize:J8};function G8(e,t,n){const r=this;return s;function s(u){return e.enter("codeIndented"),mn(e,o,"linePrefix",5)(u)}function o(u){const d=r.events[r.events.length-1];return d&&d[1].type==="linePrefix"&&d[2].sliceSerialize(d[1],!0).length>=4?a(u):n(u)}function a(u){return u===null?c(u):wt(u)?e.attempt(Y8,a,c)(u):(e.enter("codeFlowValue"),l(u))}function l(u){return u===null||wt(u)?(e.exit("codeFlowValue"),a(u)):(e.consume(u),l)}function c(u){return e.exit("codeIndented"),t(u)}}function J8(e,t,n){const r=this;return s;function s(a){return r.parser.lazy[r.now().line]?n(a):wt(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),s):mn(e,o,"linePrefix",5)(a)}function o(a){const l=r.events[r.events.length-1];return l&&l[1].type==="linePrefix"&&l[2].sliceSerialize(l[1],!0).length>=4?t(a):wt(a)?s(a):n(a)}}const X8={name:"codeText",previous:Z8,resolve:Q8,tokenize:e9};function Q8(e){let t=e.length-4,n=3,r,s;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)s===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(s=r):(r===t||e[r][1].type==="lineEnding")&&(e[s][1].type="codeTextData",r!==s+2&&(e[s][1].end=e[r-1][1].end,e.splice(s+2,r-s-2),t-=r-s-2,r=s+2),s=void 0);return e}function Z8(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function e9(e,t,n){let r=0,s,o;return a;function a(f){return e.enter("codeText"),e.enter("codeTextSequence"),l(f)}function l(f){return f===96?(e.consume(f),r++,l):(e.exit("codeTextSequence"),c(f))}function c(f){return f===null?n(f):f===32?(e.enter("space"),e.consume(f),e.exit("space"),c):f===96?(o=e.enter("codeTextSequence"),s=0,d(f)):wt(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),c):(e.enter("codeTextData"),u(f))}function u(f){return f===null||f===32||f===96||wt(f)?(e.exit("codeTextData"),c(f)):(e.consume(f),u)}function d(f){return f===96?(e.consume(f),s++,d):s===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(o.type="codeTextData",u(f))}}class t9{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const s=n||0;this.setCursor(Math.trunc(t));const o=this.right.splice(this.right.length-s,Number.POSITIVE_INFINITY);return r&&Eu(this.left,r),o.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Eu(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Eu(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Eu(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Eu(this.left,n.reverse())}}}function Eu(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function FR(e){const t={};let n=-1,r,s,o,a,l,c,u;const d=new t9(e);for(;++n<d.length;){for(;n in t;)n=t[n];if(r=d.get(n),n&&r[1].type==="chunkFlow"&&d.get(n-1)[1].type==="listItemPrefix"&&(c=r[1]._tokenizer.events,o=0,o<c.length&&c[o][1].type==="lineEndingBlank"&&(o+=2),o<c.length&&c[o][1].type==="content"))for(;++o<c.length&&c[o][1].type!=="content";)c[o][1].type==="chunkText"&&(c[o][1]._isInFirstContentOfListItem=!0,o++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,n9(d,n)),n=t[n],u=!0);else if(r[1]._container){for(o=n,s=void 0;o--;)if(a=d.get(o),a[1].type==="lineEnding"||a[1].type==="lineEndingBlank")a[0]==="enter"&&(s&&(d.get(s)[1].type="lineEndingBlank"),a[1].type="lineEnding",s=o);else if(!(a[1].type==="linePrefix"||a[1].type==="listItemIndent"))break;s&&(r[1].end={...d.get(s)[1].start},l=d.slice(s,n),l.unshift(r),d.splice(s,n-s+1,l))}}return Ri(e,0,Number.POSITIVE_INFINITY,d.slice(0)),!u}function n9(e,t){const n=e.get(t)[1],r=e.get(t)[2];let s=t-1;const o=[];let a=n._tokenizer;a||(a=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(a._contentTypeTextTrailing=!0));const l=a.events,c=[],u={};let d,f,p=-1,h=n,y=0,k=0;const b=[k];for(;h;){for(;e.get(++s)[1]!==h;);o.push(s),h._tokenizer||(d=r.sliceStream(h),h.next||d.push(null),f&&a.defineSkip(h.start),h._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=!0),a.write(d),h._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=void 0)),f=h,h=h.next}for(h=n;++p<l.length;)l[p][0]==="exit"&&l[p-1][0]==="enter"&&l[p][1].type===l[p-1][1].type&&l[p][1].start.line!==l[p][1].end.line&&(k=p+1,b.push(k),h._tokenizer=void 0,h.previous=void 0,h=h.next);for(a.events=[],h?(h._tokenizer=void 0,h.previous=void 0):b.pop(),p=b.length;p--;){const g=l.slice(b[p],b[p+1]),v=o.pop();c.push([v,v+g.length-1]),e.splice(v,2,g)}for(c.reverse(),p=-1;++p<c.length;)u[y+c[p][0]]=y+c[p][1],y+=c[p][1]-c[p][0]-1;return u}const r9={resolve:i9,tokenize:o9},s9={partial:!0,tokenize:a9};function i9(e){return FR(e),e}function o9(e,t){let n;return r;function r(l){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),s(l)}function s(l){return l===null?o(l):wt(l)?e.check(s9,a,o)(l):(e.consume(l),s)}function o(l){return e.exit("chunkContent"),e.exit("content"),t(l)}function a(l){return e.consume(l),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,s}}function a9(e,t,n){const r=this;return s;function s(a){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),mn(e,o,"linePrefix")}function o(a){if(a===null||wt(a))return n(a);const l=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&l&&l[1].type==="linePrefix"&&l[2].sliceSerialize(l[1],!0).length>=4?t(a):e.interrupt(r.parser.constructs.flow,n,t)(a)}}function zR(e,t,n,r,s,o,a,l,c){const u=c||Number.POSITIVE_INFINITY;let d=0;return f;function f(g){return g===60?(e.enter(r),e.enter(s),e.enter(o),e.consume(g),e.exit(o),p):g===null||g===32||g===41||qx(g)?n(g):(e.enter(r),e.enter(a),e.enter(l),e.enter("chunkString",{contentType:"string"}),k(g))}function p(g){return g===62?(e.enter(o),e.consume(g),e.exit(o),e.exit(s),e.exit(r),t):(e.enter(l),e.enter("chunkString",{contentType:"string"}),h(g))}function h(g){return g===62?(e.exit("chunkString"),e.exit(l),p(g)):g===null||g===60||wt(g)?n(g):(e.consume(g),g===92?y:h)}function y(g){return g===60||g===62||g===92?(e.consume(g),h):h(g)}function k(g){return!d&&(g===null||g===41||Zr(g))?(e.exit("chunkString"),e.exit(l),e.exit(a),e.exit(r),t(g)):d<u&&g===40?(e.consume(g),d++,k):g===41?(e.consume(g),d--,k):g===null||g===32||g===40||qx(g)?n(g):(e.consume(g),g===92?b:k)}function b(g){return g===40||g===41||g===92?(e.consume(g),k):k(g)}}function BR(e,t,n,r,s,o){const a=this;let l=0,c;return u;function u(h){return e.enter(r),e.enter(s),e.consume(h),e.exit(s),e.enter(o),d}function d(h){return l>999||h===null||h===91||h===93&&!c||h===94&&!l&&"_hiddenFootnoteSupport"in a.parser.constructs?n(h):h===93?(e.exit(o),e.enter(s),e.consume(h),e.exit(s),e.exit(r),t):wt(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),d):(e.enter("chunkString",{contentType:"string"}),f(h))}function f(h){return h===null||h===91||h===93||wt(h)||l++>999?(e.exit("chunkString"),d(h)):(e.consume(h),c||(c=!Xt(h)),h===92?p:f)}function p(h){return h===91||h===92||h===93?(e.consume(h),l++,f):f(h)}}function HR(e,t,n,r,s,o){let a;return l;function l(p){return p===34||p===39||p===40?(e.enter(r),e.enter(s),e.consume(p),e.exit(s),a=p===40?41:p,c):n(p)}function c(p){return p===a?(e.enter(s),e.consume(p),e.exit(s),e.exit(r),t):(e.enter(o),u(p))}function u(p){return p===a?(e.exit(o),c(a)):p===null?n(p):wt(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),mn(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),d(p))}function d(p){return p===a||p===null||wt(p)?(e.exit("chunkString"),u(p)):(e.consume(p),p===92?f:d)}function f(p){return p===a||p===92?(e.consume(p),d):d(p)}}function cd(e,t){let n;return r;function r(s){return wt(s)?(e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),n=!0,r):Xt(s)?mn(e,r,n?"linePrefix":"lineSuffix")(s):t(s)}}const l9={name:"definition",tokenize:u9},c9={partial:!0,tokenize:d9};function u9(e,t,n){const r=this;let s;return o;function o(h){return e.enter("definition"),a(h)}function a(h){return BR.call(r,e,l,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function l(h){return s=fc(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),c):n(h)}function c(h){return Zr(h)?cd(e,u)(h):u(h)}function u(h){return zR(e,d,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function d(h){return e.attempt(c9,f,f)(h)}function f(h){return Xt(h)?mn(e,p,"whitespace")(h):p(h)}function p(h){return h===null||wt(h)?(e.exit("definition"),r.parser.defined.push(s),t(h)):n(h)}}function d9(e,t,n){return r;function r(l){return Zr(l)?cd(e,s)(l):n(l)}function s(l){return HR(e,o,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(l)}function o(l){return Xt(l)?mn(e,a,"whitespace")(l):a(l)}function a(l){return l===null||wt(l)?t(l):n(l)}}const f9={name:"hardBreakEscape",tokenize:p9};function p9(e,t,n){return r;function r(o){return e.enter("hardBreakEscape"),e.consume(o),s}function s(o){return wt(o)?(e.exit("hardBreakEscape"),t(o)):n(o)}}const h9={name:"headingAtx",resolve:m9,tokenize:g9};function m9(e,t){let n=e.length-2,r=3,s,o;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(s={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},o={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},Ri(e,r,n-r+1,[["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t]])),e}function g9(e,t,n){let r=0;return s;function s(d){return e.enter("atxHeading"),o(d)}function o(d){return e.enter("atxHeadingSequence"),a(d)}function a(d){return d===35&&r++<6?(e.consume(d),a):d===null||Zr(d)?(e.exit("atxHeadingSequence"),l(d)):n(d)}function l(d){return d===35?(e.enter("atxHeadingSequence"),c(d)):d===null||wt(d)?(e.exit("atxHeading"),t(d)):Xt(d)?mn(e,l,"whitespace")(d):(e.enter("atxHeadingText"),u(d))}function c(d){return d===35?(e.consume(d),c):(e.exit("atxHeadingSequence"),l(d))}function u(d){return d===null||d===35||Zr(d)?(e.exit("atxHeadingText"),l(d)):(e.consume(d),u)}}const y9=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],N1=["pre","script","style","textarea"],w9={concrete:!0,name:"htmlFlow",resolveTo:k9,tokenize:v9},x9={partial:!0,tokenize:N9},b9={partial:!0,tokenize:S9};function k9(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function v9(e,t,n){const r=this;let s,o,a,l,c;return u;function u(B){return d(B)}function d(B){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(B),f}function f(B){return B===33?(e.consume(B),p):B===47?(e.consume(B),o=!0,k):B===63?(e.consume(B),s=3,r.interrupt?t:E):ki(B)?(e.consume(B),a=String.fromCharCode(B),b):n(B)}function p(B){return B===45?(e.consume(B),s=2,h):B===91?(e.consume(B),s=5,l=0,y):ki(B)?(e.consume(B),s=4,r.interrupt?t:E):n(B)}function h(B){return B===45?(e.consume(B),r.interrupt?t:E):n(B)}function y(B){const se="CDATA[";return B===se.charCodeAt(l++)?(e.consume(B),l===se.length?r.interrupt?t:F:y):n(B)}function k(B){return ki(B)?(e.consume(B),a=String.fromCharCode(B),b):n(B)}function b(B){if(B===null||B===47||B===62||Zr(B)){const se=B===47,ue=a.toLowerCase();return!se&&!o&&N1.includes(ue)?(s=1,r.interrupt?t(B):F(B)):y9.includes(a.toLowerCase())?(s=6,se?(e.consume(B),g):r.interrupt?t(B):F(B)):(s=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(B):o?v(B):w(B))}return B===45||cs(B)?(e.consume(B),a+=String.fromCharCode(B),b):n(B)}function g(B){return B===62?(e.consume(B),r.interrupt?t:F):n(B)}function v(B){return Xt(B)?(e.consume(B),v):$(B)}function w(B){return B===47?(e.consume(B),$):B===58||B===95||ki(B)?(e.consume(B),N):Xt(B)?(e.consume(B),w):$(B)}function N(B){return B===45||B===46||B===58||B===95||cs(B)?(e.consume(B),N):j(B)}function j(B){return B===61?(e.consume(B),C):Xt(B)?(e.consume(B),j):w(B)}function C(B){return B===null||B===60||B===61||B===62||B===96?n(B):B===34||B===39?(e.consume(B),c=B,P):Xt(B)?(e.consume(B),C):I(B)}function P(B){return B===c?(e.consume(B),c=null,z):B===null||wt(B)?n(B):(e.consume(B),P)}function I(B){return B===null||B===34||B===39||B===47||B===60||B===61||B===62||B===96||Zr(B)?j(B):(e.consume(B),I)}function z(B){return B===47||B===62||Xt(B)?w(B):n(B)}function $(B){return B===62?(e.consume(B),L):n(B)}function L(B){return B===null||wt(B)?F(B):Xt(B)?(e.consume(B),L):n(B)}function F(B){return B===45&&s===2?(e.consume(B),H):B===60&&s===1?(e.consume(B),D):B===62&&s===4?(e.consume(B),Q):B===63&&s===3?(e.consume(B),E):B===93&&s===5?(e.consume(B),W):wt(B)&&(s===6||s===7)?(e.exit("htmlFlowData"),e.check(x9,V,O)(B)):B===null||wt(B)?(e.exit("htmlFlowData"),O(B)):(e.consume(B),F)}function O(B){return e.check(b9,M,V)(B)}function M(B){return e.enter("lineEnding"),e.consume(B),e.exit("lineEnding"),K}function K(B){return B===null||wt(B)?O(B):(e.enter("htmlFlowData"),F(B))}function H(B){return B===45?(e.consume(B),E):F(B)}function D(B){return B===47?(e.consume(B),a="",T):F(B)}function T(B){if(B===62){const se=a.toLowerCase();return N1.includes(se)?(e.consume(B),Q):F(B)}return ki(B)&&a.length<8?(e.consume(B),a+=String.fromCharCode(B),T):F(B)}function W(B){return B===93?(e.consume(B),E):F(B)}function E(B){return B===62?(e.consume(B),Q):B===45&&s===2?(e.consume(B),E):F(B)}function Q(B){return B===null||wt(B)?(e.exit("htmlFlowData"),V(B)):(e.consume(B),Q)}function V(B){return e.exit("htmlFlow"),t(B)}}function S9(e,t,n){const r=this;return s;function s(a){return wt(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),o):n(a)}function o(a){return r.parser.lazy[r.now().line]?n(a):t(a)}}function N9(e,t,n){return r;function r(s){return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),e.attempt(rg,t,n)}}const j9={name:"htmlText",tokenize:C9};function C9(e,t,n){const r=this;let s,o,a;return l;function l(E){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(E),c}function c(E){return E===33?(e.consume(E),u):E===47?(e.consume(E),j):E===63?(e.consume(E),w):ki(E)?(e.consume(E),I):n(E)}function u(E){return E===45?(e.consume(E),d):E===91?(e.consume(E),o=0,y):ki(E)?(e.consume(E),v):n(E)}function d(E){return E===45?(e.consume(E),h):n(E)}function f(E){return E===null?n(E):E===45?(e.consume(E),p):wt(E)?(a=f,D(E)):(e.consume(E),f)}function p(E){return E===45?(e.consume(E),h):f(E)}function h(E){return E===62?H(E):E===45?p(E):f(E)}function y(E){const Q="CDATA[";return E===Q.charCodeAt(o++)?(e.consume(E),o===Q.length?k:y):n(E)}function k(E){return E===null?n(E):E===93?(e.consume(E),b):wt(E)?(a=k,D(E)):(e.consume(E),k)}function b(E){return E===93?(e.consume(E),g):k(E)}function g(E){return E===62?H(E):E===93?(e.consume(E),g):k(E)}function v(E){return E===null||E===62?H(E):wt(E)?(a=v,D(E)):(e.consume(E),v)}function w(E){return E===null?n(E):E===63?(e.consume(E),N):wt(E)?(a=w,D(E)):(e.consume(E),w)}function N(E){return E===62?H(E):w(E)}function j(E){return ki(E)?(e.consume(E),C):n(E)}function C(E){return E===45||cs(E)?(e.consume(E),C):P(E)}function P(E){return wt(E)?(a=P,D(E)):Xt(E)?(e.consume(E),P):H(E)}function I(E){return E===45||cs(E)?(e.consume(E),I):E===47||E===62||Zr(E)?z(E):n(E)}function z(E){return E===47?(e.consume(E),H):E===58||E===95||ki(E)?(e.consume(E),$):wt(E)?(a=z,D(E)):Xt(E)?(e.consume(E),z):H(E)}function $(E){return E===45||E===46||E===58||E===95||cs(E)?(e.consume(E),$):L(E)}function L(E){return E===61?(e.consume(E),F):wt(E)?(a=L,D(E)):Xt(E)?(e.consume(E),L):z(E)}function F(E){return E===null||E===60||E===61||E===62||E===96?n(E):E===34||E===39?(e.consume(E),s=E,O):wt(E)?(a=F,D(E)):Xt(E)?(e.consume(E),F):(e.consume(E),M)}function O(E){return E===s?(e.consume(E),s=void 0,K):E===null?n(E):wt(E)?(a=O,D(E)):(e.consume(E),O)}function M(E){return E===null||E===34||E===39||E===60||E===61||E===96?n(E):E===47||E===62||Zr(E)?z(E):(e.consume(E),M)}function K(E){return E===47||E===62||Zr(E)?z(E):n(E)}function H(E){return E===62?(e.consume(E),e.exit("htmlTextData"),e.exit("htmlText"),t):n(E)}function D(E){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(E),e.exit("lineEnding"),T}function T(E){return Xt(E)?mn(e,W,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(E):W(E)}function W(E){return e.enter("htmlTextData"),a(E)}}const Jk={name:"labelEnd",resolveAll:P9,resolveTo:I9,tokenize:R9},_9={tokenize:T9},E9={tokenize:M9},A9={tokenize:$9};function P9(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const s=r.type==="labelImage"?4:2;r.type="data",t+=s}}return e.length!==n.length&&Ri(e,0,e.length,n),e}function I9(e,t){let n=e.length,r=0,s,o,a,l;for(;n--;)if(s=e[n][1],o){if(s.type==="link"||s.type==="labelLink"&&s._inactive)break;e[n][0]==="enter"&&s.type==="labelLink"&&(s._inactive=!0)}else if(a){if(e[n][0]==="enter"&&(s.type==="labelImage"||s.type==="labelLink")&&!s._balanced&&(o=n,s.type!=="labelLink")){r=2;break}}else s.type==="labelEnd"&&(a=n);const c={type:e[o][1].type==="labelLink"?"link":"image",start:{...e[o][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[o][1].start},end:{...e[a][1].end}},d={type:"labelText",start:{...e[o+r+2][1].end},end:{...e[a-2][1].start}};return l=[["enter",c,t],["enter",u,t]],l=_s(l,e.slice(o+1,o+r+3)),l=_s(l,[["enter",d,t]]),l=_s(l,Gk(t.parser.constructs.insideSpan.null,e.slice(o+r+4,a-3),t)),l=_s(l,[["exit",d,t],e[a-2],e[a-1],["exit",u,t]]),l=_s(l,e.slice(a+1)),l=_s(l,[["exit",c,t]]),Ri(e,o,e.length,l),e}function R9(e,t,n){const r=this;let s=r.events.length,o,a;for(;s--;)if((r.events[s][1].type==="labelImage"||r.events[s][1].type==="labelLink")&&!r.events[s][1]._balanced){o=r.events[s][1];break}return l;function l(p){return o?o._inactive?f(p):(a=r.parser.defined.includes(fc(r.sliceSerialize({start:o.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(p),e.exit("labelMarker"),e.exit("labelEnd"),c):n(p)}function c(p){return p===40?e.attempt(_9,d,a?d:f)(p):p===91?e.attempt(E9,d,a?u:f)(p):a?d(p):f(p)}function u(p){return e.attempt(A9,d,f)(p)}function d(p){return t(p)}function f(p){return o._balanced=!0,n(p)}}function T9(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),s}function s(f){return Zr(f)?cd(e,o)(f):o(f)}function o(f){return f===41?d(f):zR(e,a,l,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function a(f){return Zr(f)?cd(e,c)(f):d(f)}function l(f){return n(f)}function c(f){return f===34||f===39||f===40?HR(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):d(f)}function u(f){return Zr(f)?cd(e,d)(f):d(f)}function d(f){return f===41?(e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),e.exit("resource"),t):n(f)}}function M9(e,t,n){const r=this;return s;function s(l){return BR.call(r,e,o,a,"reference","referenceMarker","referenceString")(l)}function o(l){return r.parser.defined.includes(fc(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(l):n(l)}function a(l){return n(l)}}function $9(e,t,n){return r;function r(o){return e.enter("reference"),e.enter("referenceMarker"),e.consume(o),e.exit("referenceMarker"),s}function s(o){return o===93?(e.enter("referenceMarker"),e.consume(o),e.exit("referenceMarker"),e.exit("reference"),t):n(o)}}const L9={name:"labelStartImage",resolveAll:Jk.resolveAll,tokenize:O9};function O9(e,t,n){const r=this;return s;function s(l){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(l),e.exit("labelImageMarker"),o}function o(l){return l===91?(e.enter("labelMarker"),e.consume(l),e.exit("labelMarker"),e.exit("labelImage"),a):n(l)}function a(l){return l===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(l):t(l)}}const D9={name:"labelStartLink",resolveAll:Jk.resolveAll,tokenize:F9};function F9(e,t,n){const r=this;return s;function s(a){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelLink"),o}function o(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const Ky={name:"lineEnding",tokenize:z9};function z9(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),mn(e,t,"linePrefix")}}const dh={name:"thematicBreak",tokenize:B9};function B9(e,t,n){let r=0,s;return o;function o(u){return e.enter("thematicBreak"),a(u)}function a(u){return s=u,l(u)}function l(u){return u===s?(e.enter("thematicBreakSequence"),c(u)):r>=3&&(u===null||wt(u))?(e.exit("thematicBreak"),t(u)):n(u)}function c(u){return u===s?(e.consume(u),r++,c):(e.exit("thematicBreakSequence"),Xt(u)?mn(e,l,"whitespace")(u):l(u))}}const Vr={continuation:{tokenize:K9},exit:U9,name:"list",tokenize:V9},H9={partial:!0,tokenize:Y9},W9={partial:!0,tokenize:q9};function V9(e,t,n){const r=this,s=r.events[r.events.length-1];let o=s&&s[1].type==="linePrefix"?s[2].sliceSerialize(s[1],!0).length:0,a=0;return l;function l(h){const y=r.containerState.type||(h===42||h===43||h===45?"listUnordered":"listOrdered");if(y==="listUnordered"?!r.containerState.marker||h===r.containerState.marker:Ux(h)){if(r.containerState.type||(r.containerState.type=y,e.enter(y,{_container:!0})),y==="listUnordered")return e.enter("listItemPrefix"),h===42||h===45?e.check(dh,n,u)(h):u(h);if(!r.interrupt||h===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),c(h)}return n(h)}function c(h){return Ux(h)&&++a<10?(e.consume(h),c):(!r.interrupt||a<2)&&(r.containerState.marker?h===r.containerState.marker:h===41||h===46)?(e.exit("listItemValue"),u(h)):n(h)}function u(h){return e.enter("listItemMarker"),e.consume(h),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||h,e.check(rg,r.interrupt?n:d,e.attempt(H9,p,f))}function d(h){return r.containerState.initialBlankLine=!0,o++,p(h)}function f(h){return Xt(h)?(e.enter("listItemPrefixWhitespace"),e.consume(h),e.exit("listItemPrefixWhitespace"),p):n(h)}function p(h){return r.containerState.size=o+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(h)}}function K9(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(rg,s,o);function s(l){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,mn(e,t,"listItemIndent",r.containerState.size+1)(l)}function o(l){return r.containerState.furtherBlankLines||!Xt(l)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,a(l)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(W9,t,a)(l))}function a(l){return r.containerState._closeFlow=!0,r.interrupt=void 0,mn(e,e.attempt(Vr,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(l)}}function q9(e,t,n){const r=this;return mn(e,s,"listItemIndent",r.containerState.size+1);function s(o){const a=r.events[r.events.length-1];return a&&a[1].type==="listItemIndent"&&a[2].sliceSerialize(a[1],!0).length===r.containerState.size?t(o):n(o)}}function U9(e){e.exit(this.containerState.type)}function Y9(e,t,n){const r=this;return mn(e,s,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function s(o){const a=r.events[r.events.length-1];return!Xt(o)&&a&&a[1].type==="listItemPrefixWhitespace"?t(o):n(o)}}const j1={name:"setextUnderline",resolveTo:G9,tokenize:J9};function G9(e,t){let n=e.length,r,s,o;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(s=n)}else e[n][1].type==="content"&&e.splice(n,1),!o&&e[n][1].type==="definition"&&(o=n);const a={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[s][1].type="setextHeadingText",o?(e.splice(s,0,["enter",a,t]),e.splice(o+1,0,["exit",e[r][1],t]),e[r][1].end={...e[o][1].end}):e[r][1]=a,e.push(["exit",a,t]),e}function J9(e,t,n){const r=this;let s;return o;function o(u){let d=r.events.length,f;for(;d--;)if(r.events[d][1].type!=="lineEnding"&&r.events[d][1].type!=="linePrefix"&&r.events[d][1].type!=="content"){f=r.events[d][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(e.enter("setextHeadingLine"),s=u,a(u)):n(u)}function a(u){return e.enter("setextHeadingLineSequence"),l(u)}function l(u){return u===s?(e.consume(u),l):(e.exit("setextHeadingLineSequence"),Xt(u)?mn(e,c,"lineSuffix")(u):c(u))}function c(u){return u===null||wt(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const X9={tokenize:Q9};function Q9(e){const t=this,n=e.attempt(rg,r,e.attempt(this.parser.constructs.flowInitial,s,mn(e,e.attempt(this.parser.constructs.flow,s,e.attempt(r9,s)),"linePrefix")));return n;function r(o){if(o===null){e.consume(o);return}return e.enter("lineEndingBlank"),e.consume(o),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function s(o){if(o===null){e.consume(o);return}return e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const Z9={resolveAll:VR()},eV=WR("string"),tV=WR("text");function WR(e){return{resolveAll:VR(e==="text"?nV:void 0),tokenize:t};function t(n){const r=this,s=this.parser.constructs[e],o=n.attempt(s,a,l);return a;function a(d){return u(d)?o(d):l(d)}function l(d){if(d===null){n.consume(d);return}return n.enter("data"),n.consume(d),c}function c(d){return u(d)?(n.exit("data"),o(d)):(n.consume(d),c)}function u(d){if(d===null)return!0;const f=s[d];let p=-1;if(f)for(;++p<f.length;){const h=f[p];if(!h.previous||h.previous.call(r,r.previous))return!0}return!1}}}function VR(e){return t;function t(n,r){let s=-1,o;for(;++s<=n.length;)o===void 0?n[s]&&n[s][1].type==="data"&&(o=s,s++):(!n[s]||n[s][1].type!=="data")&&(s!==o+2&&(n[o][1].end=n[s-1][1].end,n.splice(o+2,s-o-2),s=o+2),o=void 0);return e?e(n,r):n}}function nV(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],s=t.sliceStream(r);let o=s.length,a=-1,l=0,c;for(;o--;){const u=s[o];if(typeof u=="string"){for(a=u.length;u.charCodeAt(a-1)===32;)l++,a--;if(a)break;a=-1}else if(u===-2)c=!0,l++;else if(u!==-1){o++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(l=0),l){const u={type:n===e.length||c||l<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:o?a:r.start._bufferIndex+a,_index:r.start._index+o,line:r.end.line,column:r.end.column-l,offset:r.end.offset-l},end:{...r.end}};r.end={...u.start},r.start.offset===r.end.offset?Object.assign(r,u):(e.splice(n,0,["enter",u,t],["exit",u,t]),n+=2)}n++}return e}const rV={42:Vr,43:Vr,45:Vr,48:Vr,49:Vr,50:Vr,51:Vr,52:Vr,53:Vr,54:Vr,55:Vr,56:Vr,57:Vr,62:LR},sV={91:l9},iV={[-2]:Vy,[-1]:Vy,32:Vy},oV={35:h9,42:dh,45:[j1,dh],60:w9,61:j1,95:dh,96:S1,126:S1},aV={38:DR,92:OR},lV={[-5]:Ky,[-4]:Ky,[-3]:Ky,33:L9,38:DR,42:Yx,60:[D8,j9],91:D9,92:[f9,OR],93:Jk,95:Yx,96:X8},cV={null:[Yx,Z9]},uV={null:[42,95]},dV={null:[]},fV=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:uV,contentInitial:sV,disable:dV,document:rV,flow:oV,flowInitial:iV,insideSpan:cV,string:aV,text:lV},Symbol.toStringTag,{value:"Module"}));function pV(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const s={},o=[];let a=[],l=[];const c={attempt:P(j),check:P(C),consume:v,enter:w,exit:N,interrupt:P(C,{interrupt:!0})},u={code:null,containerState:{},defineSkip:k,events:[],now:y,parser:e,previous:null,sliceSerialize:p,sliceStream:h,write:f};let d=t.tokenize.call(u,c);return t.resolveAll&&o.push(t),u;function f(L){return a=_s(a,L),b(),a[a.length-1]!==null?[]:(I(t,0),u.events=Gk(o,u.events,u),u.events)}function p(L,F){return mV(h(L),F)}function h(L){return hV(a,L)}function y(){const{_bufferIndex:L,_index:F,line:O,column:M,offset:K}=r;return{_bufferIndex:L,_index:F,line:O,column:M,offset:K}}function k(L){s[L.line]=L.column,$()}function b(){let L;for(;r._index<a.length;){const F=a[r._index];if(typeof F=="string")for(L=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===L&&r._bufferIndex<F.length;)g(F.charCodeAt(r._bufferIndex));else g(F)}}function g(L){d=d(L)}function v(L){wt(L)?(r.line++,r.column=1,r.offset+=L===-3?2:1,$()):L!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===a[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=L}function w(L,F){const O=F||{};return O.type=L,O.start=y(),u.events.push(["enter",O,u]),l.push(O),O}function N(L){const F=l.pop();return F.end=y(),u.events.push(["exit",F,u]),F}function j(L,F){I(L,F.from)}function C(L,F){F.restore()}function P(L,F){return O;function O(M,K,H){let D,T,W,E;return Array.isArray(M)?V(M):"tokenize"in M?V([M]):Q(M);function Q(G){return ee;function ee(te){const ne=te!==null&&G[te],Z=te!==null&&G.null,ce=[...Array.isArray(ne)?ne:ne?[ne]:[],...Array.isArray(Z)?Z:Z?[Z]:[]];return V(ce)(te)}}function V(G){return D=G,T=0,G.length===0?H:B(G[T])}function B(G){return ee;function ee(te){return E=z(),W=G,G.partial||(u.currentConstruct=G),G.name&&u.parser.constructs.disable.null.includes(G.name)?ue():G.tokenize.call(F?Object.assign(Object.create(u),F):u,c,se,ue)(te)}}function se(G){return L(W,E),K}function ue(G){return E.restore(),++T<D.length?B(D[T]):H}}}function I(L,F){L.resolveAll&&!o.includes(L)&&o.push(L),L.resolve&&Ri(u.events,F,u.events.length-F,L.resolve(u.events.slice(F),u)),L.resolveTo&&(u.events=L.resolveTo(u.events,u))}function z(){const L=y(),F=u.previous,O=u.currentConstruct,M=u.events.length,K=Array.from(l);return{from:M,restore:H};function H(){r=L,u.previous=F,u.currentConstruct=O,u.events.length=M,l=K,$()}}function $(){r.line in s&&r.column<2&&(r.column=s[r.line],r.offset+=s[r.line]-1)}}function hV(e,t){const n=t.start._index,r=t.start._bufferIndex,s=t.end._index,o=t.end._bufferIndex;let a;if(n===s)a=[e[n].slice(r,o)];else{if(a=e.slice(n,s),r>-1){const l=a[0];typeof l=="string"?a[0]=l.slice(r):a.shift()}o>0&&a.push(e[s].slice(0,o))}return a}function mV(e,t){let n=-1;const r=[];let s;for(;++n<e.length;){const o=e[n];let a;if(typeof o=="string")a=o;else switch(o){case-5:{a="\r";break}case-4:{a=`
68
68
  `;break}case-3:{a=`\r
@@ -179,7 +179,7 @@ ${n("project:fileTruncated")}`:""]})]}):i.jsx("p",{children:n("project:noNodeFil
179
179
  <\/script>
180
180
  </body>
181
181
  </html>`}const wT=new Set(["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"]),SU=["workspaceRoot","pipelineWorkspace","cwd","flowName","runDir","flowDir"];function NU(e,t){const n=e.slice(0,t),r=n.lastIndexOf("${");if(r<0)return null;const s=n.slice(r+2);return s.includes("}")?null:{atIndex:r,query:s}}function jU(e){const t=/\$\{([^}]*)\}/g,n=[];let r;for(;(r=t.exec(e))!==null;)n.push({start:r.index,end:r.index+r[0].length,key:r[1]});return n}function lC(e){const t=new Set;if(!Array.isArray(e))return t;for(const n of e){const r=(n==null?void 0:n.name)!=null?String(n.name).trim():"";r&&t.add(r)}return t}function xT(e,{inputNames:t,outputNames:n}){const r=e.trim();if(!r)return!1;if(r.startsWith("input.")){const s=r.slice(6).trim();return s!==""&&t.has(s)}if(r.startsWith("output.")){const s=r.slice(7).trim();return s!==""&&n.has(s)}if(wT.has(r)||t.has(r)||n.has(r))return!0;if(!r.includes(".")){const s=`${r}.md`;if(t.has(s)||n.has(s))return!0}return!1}function bT(e){return{inputNames:lC(e==null?void 0:e.inputs),outputNames:lC(e==null?void 0:e.outputs)}}function CU(e,t,n){const r=bT(t),s=jU(e),o=[];for(const a of s)if(!xT(a.key,r)){const l=a.key.trim()===""?n("flow:placeholder.empty"):a.key.trim();o.push({start:a.start,end:a.end,message:n("flow:placeholder.invalidPlaceholder",{hint:l})})}return o}function _U(e,t){const n=bT(t),r=/\$\{([^}]*)\}/g,s=[];let o=0,a;for(;(a=r.exec(e))!==null;){a.index>o&&s.push({kind:"plain",text:e.slice(o,a.index)});const l=a[0],c=xT(a[1],n);s.push({kind:c?"ph-valid":"ph-invalid",text:l}),o=a.index+l.length}return o<e.length&&s.push({kind:"plain",text:e.slice(o)}),s}function EU(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function AU(e){return e.map(t=>{const n=EU(t.text);return t.kind==="ph-invalid"?`<span class="af-body-ph-invalid">${n}</span>`:t.kind==="ph-valid"?`<span class="af-body-ph-valid">${n}</span>`:n}).join("")}function PU(e,t){const n=[];for(const r of(e==null?void 0:e.inputs)??[]){const s=(r==null?void 0:r.name)!=null?String(r.name).trim():"";if(!s)continue;const o=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"input",insert:`input.${s}`,label:s,subtitle:o?t("flow:placeholder.inputSubtitle",{type:o}):t("flow:placeholder.inputSubtitleNoType")})}for(const r of(e==null?void 0:e.outputs)??[]){const s=(r==null?void 0:r.name)!=null?String(r.name).trim():"";if(!s)continue;const o=(r==null?void 0:r.type)!=null?String(r.type):"";n.push({section:"output",insert:`output.${s}`,label:s,subtitle:o?t("flow:placeholder.outputSubtitle",{type:o}):t("flow:placeholder.outputSubtitleNoType")})}for(const r of SU)wT.has(r)&&n.push({section:"runtime",insert:r,label:r,subtitle:t("flow:placeholder.runtimeConst")});return n}function IU(e,t){const n=t.toLowerCase();return n?e.filter(r=>[r.insert,r.label,r.subtitle??""].map(o=>String(o).toLowerCase()).some(o=>o.includes(n))):e}function RU(e,t){if(!e||t<0)return null;const n=Math.min(t,e.value.length),r=getComputedStyle(e),s=document.createElement("div");s.setAttribute("aria-hidden","true"),s.style.visibility="hidden",s.style.position="fixed",s.style.top="0",s.style.left="-99999px",s.style.whiteSpace="pre-wrap",s.style.wordWrap="break-word",s.style.overflow="hidden";const o=e.clientWidth;if(o<=0)return null;s.style.width=`${o}px`,s.style.font=r.font,s.style.lineHeight=r.lineHeight,s.style.padding=r.padding,s.style.border=r.border,s.style.boxSizing=r.boxSizing,s.style.letterSpacing=r.letterSpacing,s.style.textIndent=r.textIndent,s.style.tabSize=r.tabSize||"8",s.textContent=e.value.slice(0,n);const a=document.createElement("span");a.textContent="​",s.appendChild(a),document.body.appendChild(s);const l=a.getBoundingClientRect(),c=parseFloat(r.lineHeight),u=Number.isFinite(c)&&c>0?c:l.height||16;return document.body.removeChild(s),{top:l.top,left:l.left,bottom:l.bottom,height:u}}function Ip({value:e,onChange:t,disabled:n,placeholder:r,rows:s=8,textareaClassName:o,ioSlots:a,variant:l="drawer",images:c,onImagesChange:u}){const{t:d}=Fr(),f=m.useId(),p=m.useRef(null),h=m.useRef(null),[y,k]=m.useState(0),[b,g]=m.useState(0),[v,w]=m.useState(null),N=m.useMemo(()=>po(c),[c]),j=m.useMemo(()=>CU(e,a,d),[e,a,d]),C=j.length>0,P=m.useMemo(()=>_U(e,a),[e,a]),I=m.useMemo(()=>AU(P),[P]),z=m.useMemo(()=>n?null:NU(e,y),[e,y,n]),$=m.useMemo(()=>{if(!z)return[];const H=PU(a,d);return IU(H,z.query)},[z,a,d]);m.useEffect(()=>{g(H=>{const D=Math.max(0,$.length-1);return Math.min(Math.max(0,H),D)})},[$.length]);const L=m.useCallback(()=>{const H=p.current;if(!H||!z||$.length===0){w(null);return}const D=RU(H,y);if(!D){w(null);return}const T=4,W=44,E=13.5*16,Q=Math.min($.length*W+8,E);let V=D.bottom+T;V+Q>window.innerHeight-8&&(V=Math.max(8,D.top-Q-T));const B=288;let se=D.left;se=Math.max(8,Math.min(se,window.innerWidth-B-8)),w({top:V,left:se})},[z,$.length,y]);m.useLayoutEffect(()=>{if(!z||$.length===0){w(null);return}const H=requestAnimationFrame(()=>L());return()=>cancelAnimationFrame(H)},[z,$.length,y,e,L]),m.useEffect(()=>{if(!z||$.length===0)return;const H=()=>L();return window.addEventListener("scroll",H,!0),window.addEventListener("resize",H),()=>{window.removeEventListener("scroll",H,!0),window.removeEventListener("resize",H)}},[z,$.length,L]);const F=m.useCallback(H=>{if(!z)return;const{atIndex:D}=z,T=e.slice(0,D)+"${"+H+"}"+e.slice(y);t(T);const W=D+H.length+3;queueMicrotask(()=>{const E=p.current;E&&(E.focus(),E.setSelectionRange(W,W)),k(W)})},[z,e,y,t]),O=m.useCallback(()=>{const H=p.current,D=h.current;!H||!D||(D.scrollTop=H.scrollTop,D.scrollLeft=H.scrollLeft,z&&$.length>0&&queueMicrotask(()=>L()))},[z,$.length,L]),M=m.useCallback(H=>{if(!n&&z&&$.length>0&&(H.key==="ArrowDown"||H.key==="ArrowUp"||H.key==="Enter")){if(H.key==="ArrowDown")H.preventDefault(),g(D=>(D+1)%$.length);else if(H.key==="ArrowUp")H.preventDefault(),g(D=>(D-1+$.length)%$.length);else if(H.key==="Enter"&&!H.shiftKey){H.preventDefault();const D=$[b];D&&F(D.insert)}}},[n,z,$,b,F]),K=m.useCallback(async H=>{if(n||typeof u!="function")return!1;const D=await mT({files:H,body:e,images:N});return D?(t(D.body),u(D.images),queueMicrotask(()=>{const T=p.current;if(!T)return;T.focus();const W=D.body.length;T.setSelectionRange(W,W),k(W)}),!0):!1},[n,N,t,u,e]);return i.jsxs("div",{className:"af-body-prompt-editor"+(l==="expand"?" af-body-prompt-editor--expand":""),children:[N.length>0?i.jsx("div",{className:"af-body-image-list","aria-label":"image attachments",children:N.map((H,D)=>i.jsxs("span",{className:"af-body-image-chip",title:H.name,children:[i.jsx("img",{src:H.dataUrl,alt:""}),i.jsxs("span",{children:["[",H.label||`image ${D+1}`,"]"]})]},H.id||D))}):null,i.jsxs("div",{className:"af-body-prompt-stack",children:[i.jsx("pre",{ref:h,className:"af-body-prompt-backdrop "+o,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:I+`
182
- `}}),i.jsx("textarea",{ref:p,className:"af-body-prompt-textarea "+o,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":C,"aria-describedby":C?f:void 0,onChange:H=>{t(H.target.value),k(H.target.selectionStart??H.target.value.length)},onSelect:H=>{const D=H.target;D instanceof HTMLTextAreaElement&&k(D.selectionStart??0)},onClick:H=>{const D=H.target;D instanceof HTMLTextAreaElement&&k(D.selectionStart??0)},onKeyUp:H=>{const D=H.target;D instanceof HTMLTextAreaElement&&k(D.selectionStart??D.value.length)},onKeyDown:M,onPaste:H=>{const D=hT(H);D.length!==0&&(H.preventDefault(),K(D).catch(()=>{}))},onDragOver:H=>{fd(H).length>0&&H.preventDefault()},onDrop:H=>{const D=fd(H);D.length!==0&&(H.preventDefault(),K(D).catch(()=>{}))},onScroll:O})]}),z&&$.length>0&&v?cr.createPortal(i.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":d("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:v.top,left:v.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:$.map((H,D)=>i.jsx("li",{role:"option","aria-selected":D===b,children:i.jsxs("button",{type:"button",className:"af-composer-mention-item"+(D===b?" af-composer-mention-item--active":""),onMouseDown:T=>T.preventDefault(),onMouseEnter:()=>g(D),onClick:()=>F(H.insert),children:[i.jsx("span",{className:"af-composer-mention-id",children:`\${${H.insert}}`}),H.subtitle?i.jsx("span",{className:"af-composer-mention-sub",children:H.subtitle}):null]})},`${H.section}-${H.insert}`))}),document.body):null,C?i.jsx("p",{id:f,className:"af-body-ph-issues",role:"status",children:j.map(H=>H.message).join(" · ")}):null]})}const TU=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function Pu(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function cC({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:o=!0}){const{t:a}=Fr(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),c=f=>r(n.filter((p,h)=>h!==f)),u=(f,p,h)=>{const y=n.map((k,b)=>{if(b!==f)return k;const g={...k,[p]:h};return p==="required"&&h===!0&&(g.showOnNode=!0),g});r(y)},d=e==="input"?"input":"output";return i.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[i.jsxs("div",{className:"af-node-props-io-head",children:[i.jsx("span",{className:"af-node-props-label",children:t}),i.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-io-add",onClick:l,disabled:s,"aria-label":a("flow:nodeProps.addPinAriaLabel",{label:t}),children:a("flow:nodeProps.addPin")})]}),i.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:d})}),n.length===0?i.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?i.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[i.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[i.jsx("span",{children:a("flow:nodeProps.handle")}),i.jsx("span",{children:a("flow:nodeProps.type")}),i.jsx("span",{children:a("flow:nodeProps.name")}),i.jsx("span",{children:a("flow:nodeProps.defaultValue")}),i.jsx("span",{children:a("flow:nodeProps.description")}),i.jsx("span",{children:a("flow:nodeProps.required")}),i.jsx("span",{children:a("flow:nodeProps.showOnNode")}),i.jsx("span",{})]}),n.map((f,p)=>i.jsxs("div",{className:"af-node-props-io-row",children:[i.jsxs("span",{className:"af-node-props-io-handle",title:`${d}-${p}`,children:[d,"-",p]}),i.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:f.type,onChange:h=>u(p,"type",h.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:p}),children:["node","text","file","bool"].map(h=>i.jsx("option",{value:h,children:h},h))}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:f.name,onChange:h=>u(p,"name",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:p})}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:f.default,onChange:h=>u(p,"default",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:p})}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:f.description||"",onChange:h=>u(p,"description",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDescriptionAriaLabel",{label:t,index:p})}),i.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:i.jsx("input",{type:"checkbox",checked:!!f.required,onChange:h=>{o||u(p,"required",h.target.checked)},disabled:s||o,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:p})})}),i.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:i.jsx("input",{type:"checkbox",checked:f.showOnNode!==!1,onChange:h=>u(p,"showOnNode",h.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:p})})}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>c(p),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:p}),title:a("flow:nodeProps.deletePin"),children:i.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${d}-${p}`))]}):null]})}function MU({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:o,onIdBlur:a,onClose:l,onPublishToMarketplace:c,allowEditRequiredPins:u=!1,error:d,ioSlots:f}){const{t:p}=Fr(),[h,y]=m.useState(!1),[k,b]=m.useState(!1),[g,v]=m.useState({status:"idle",message:""}),w=m.useCallback(O=>{t(M=>M&&{...M,...O})},[t]),{cursorList:N,opencodeList:j,claudeCodeList:C,codexList:P,currentNotInLists:I}=m.useMemo(()=>{const O=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],M=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],K=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],H=Array.isArray(s==null?void 0:s.codex)?s.codex:[],D=new Set([...O,...M,...K,...H].map(Pu)),T=((e==null?void 0:e.model)??"").trim(),W=T.startsWith("cursor:")?T.slice(7):T.startsWith("opencode:")?T.slice(9):T.startsWith("codex:")?T.slice(6):T.startsWith("claude-code:")?T.slice(12):T,E=T&&!D.has(W)?T:"";return{cursorList:O,opencodeList:M,claudeCodeList:K,codexList:H,currentNotInLists:E}},[s,e==null?void 0:e.model]);if(!e)return null;const z=String(e.script??""),$=n==="tool_nodejs"||z.trim()!=="",L=typeof c=="function"&&!o&&(e==null?void 0:e.newId),F=async()=>{if(L){v({status:"running",message:p("flow:nodeProps.publishRunning")});try{const O=await c(e,n);v({status:"success",message:O!=null&&O.definitionId?p("flow:nodeProps.publishSuccessWithId",{id:O.definitionId}):p("flow:nodeProps.publishSuccess")})}catch(O){v({status:"error",message:String((O==null?void 0:O.message)||O)})}}};return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[i.jsx("h2",{className:"af-pipeline-drawer-title",children:p("flow:nodeProps.title")}),i.jsxs("div",{className:"af-node-props-head-actions",children:[i.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:F,disabled:!L||g.status==="running",title:p("flow:nodeProps.publishToMarketplaceHint"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),g.status==="running"?p("flow:nodeProps.publishing"):p("flow:nodeProps.publishToMarketplace")]}),i.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:p("common:common.close")})]})]}),i.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[d?i.jsx("p",{className:"af-err af-node-props-err",children:d}):null,g.message?i.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${g.status}`,children:g.message}):null,i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:p("flow:node.nodeType")}),i.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:nodeProps.instanceId"),i.jsx("span",{className:"af-node-props-hint",children:p("flow:node.displayNameHint")})]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:O=>w({newId:O.target.value}),onBlur:a,disabled:o,spellCheck:!1,autoComplete:"off","aria-label":p("flow:nodeProps.instanceId")})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.displayName"),"(LABEL)"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:O=>w({label:O.target.value}),disabled:o,spellCheck:!1})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.role"),"(ROLE)"]}),i.jsx("select",{className:"af-node-props-select",value:Wd.includes(e.role)?e.role:p("flow:roles.normal"),onChange:O=>w({role:O.target.value}),disabled:o,children:Wd.map(O=>i.jsx("option",{value:O,children:O},O))})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.model"),"(MODEL)"]}),i.jsx("span",{className:"af-node-props-sublabel",children:p("flow:node.modelHint")}),i.jsxs("select",{className:"af-node-props-select",value:(()=>{const O=(e.model||"").trim();return O?I||O:""})(),onChange:O=>w({model:O.target.value}),disabled:o,"aria-label":p("flow:nodeProps.modelAriaLabel"),children:[i.jsx("option",{value:"",children:p("flow:node.defaultModel")}),I?i.jsxs("option",{value:I,children:[I,p("flow:nodeProps.yamlValueNotInList")]}):null,N.length>0?i.jsx("optgroup",{label:"Cursor",children:N.map(O=>i.jsx("option",{value:Pu(O),children:O},`c-${O}`))}):null,j.length>0?i.jsx("optgroup",{label:"OpenCode",children:j.map(O=>i.jsx("option",{value:`opencode:${Pu(O)}`,children:O},`o-${O}`))}):null,P.length>0?i.jsx("optgroup",{label:"Codex",children:P.map(O=>i.jsx("option",{value:`codex:${Pu(O)}`,children:O},`codex-${O}`))}):null,C.length>0?i.jsx("optgroup",{label:"Claude Code",children:C.map(O=>i.jsx("option",{value:`claude-code:${Pu(O)}`,children:O},`cc-${O}`))}):null]})]}),i.jsx(cC,{kind:"input",label:p("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:O=>w({inputs:O}),disabled:o,requiredReadonly:!u}),i.jsx(cC,{kind:"output",label:p("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:O=>w({outputs:O}),disabled:o,requiredReadonly:!u}),$?i.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[i.jsxs("div",{className:"af-node-props-prompt-head",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.directCommand"),"(script)",i.jsx("span",{className:"af-node-props-hint",children:p("flow:node.scriptHint")})]}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>b(!0),"aria-label":p("flow:nodeProps.expandEditScript"),title:p("flow:nodeProps.expand"),disabled:o,children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(Ip,{value:z,onChange:O=>w({script:O}),disabled:o,placeholder:p("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:f,variant:"drawer"})]}):null,i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Script file(scriptRef)"}),i.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/script.mjs"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.scriptRef||"",onChange:O=>w({scriptRef:O.target.value}),disabled:o,spellCheck:!1,autoComplete:"off"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Implementation file(implementationRef)"}),i.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/implementation.md"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.implementationRef||"",onChange:O=>w({implementationRef:O.target.value}),disabled:o,spellCheck:!1,autoComplete:"off"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Implementation mode"}),i.jsxs("select",{className:"af-node-props-select",value:e.implementationMode||"",onChange:O=>w({implementationMode:O.target.value}),disabled:o,children:[i.jsx("option",{value:"",children:"auto"}),i.jsx("option",{value:"script",children:"script"}),i.jsx("option",{value:"steps",children:"steps"}),i.jsx("option",{value:"hybrid",children:"hybrid"})]})]}),i.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[i.jsxs("div",{className:"af-node-props-prompt-head",children:[i.jsx("span",{className:"af-node-props-label",children:p("flow:node.userPrompt")}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>y(!0),"aria-label":p("flow:nodeProps.expandEdit"),title:p("flow:nodeProps.expand"),disabled:o,children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(Ip,{value:e.body,onChange:O=>w({body:O}),images:e.images,onImagesChange:O=>w({images:O}),disabled:o,placeholder:p("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:f,variant:"drawer"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:p("flow:node.systemDescription")}),i.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||p("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),k?i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editScript"),onMouseDown:O=>{O.target===O.currentTarget&&b(!1)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.directCommand")}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>b(!1),"aria-label":p("flow:nodeProps.collapse"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx(Ip,{value:z,onChange:O=>w({script:O}),disabled:o,placeholder:p("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:f,variant:"expand"})]})}):null,h?i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editUserPrompt"),onMouseDown:O=>{O.target===O.currentTarget&&y(!1)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.body")}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>y(!1),"aria-label":p("flow:nodeProps.collapse"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx(Ip,{value:e.body,onChange:O=>w({body:O}),images:e.images,onImagesChange:O=>w({images:O}),disabled:o,placeholder:p("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:f,variant:"expand"})]})}):null]})}function $U({open:e,onClose:t,flowId:n,flowSource:r,onArchived:s}){const{t:o}=Fr(),a=m.useId(),l=m.useRef(null),[c,u]=m.useState(""),[d,f]=m.useState(!1),[p,h]=m.useState("");if(m.useEffect(()=>{if(!e)return;u(""),h(""),f(!1);const g=requestAnimationFrame(()=>{var v;return(v=l.current)==null?void 0:v.focus()});return()=>cancelAnimationFrame(g)},[e,n]),!e)return null;const y=c.trim(),k=y===n;async function b(g){if(g.preventDefault(),!(!k||d)){f(!0),h("");try{const v=await fetch("/api/flow/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:y})}),w=await v.json().catch(()=>({}));if(!v.ok){h(typeof w.error=="string"?w.error:o("project:archiveModal.archiveFailed"));return}s()}catch(v){h(String((v==null?void 0:v.message)||v))}finally{f(!1)}}}return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:g=>{g.target===g.currentTarget&&t()},children:i.jsxs("div",{ref:l,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":a,tabIndex:-1,onMouseDown:g=>g.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:a,className:"af-shortcuts-panel__title",children:o("project:archiveModal.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":o("project:archiveModal.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:b,children:[i.jsx("p",{className:"af-new-pipeline-lead",children:o("project:archiveModal.lead",{flowId:n})}),i.jsxs("label",{className:"af-new-pipeline-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:o("project:archiveModal.confirmLabel")}),i.jsx("input",{type:"text",className:"af-new-pipeline-input",value:c,onChange:g=>u(g.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":y.length>0&&!k})]}),p?i.jsx("p",{className:"af-err af-new-pipeline-err",children:p}):null,i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:d,children:o("project:archiveModal.cancel")}),i.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!k||d,children:o(d?"project:archiveModal.archiving":"project:archiveModal.confirmArchive")})]})]})]})})}function LU({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,workspaceId:o="",leaveShared:a=!1,onDeleted:l}){const{t:c}=Fr(),u=m.useId(),d=m.useRef(null),[f,p]=m.useState(""),[h,y]=m.useState(!1),[k,b]=m.useState("");if(m.useEffect(()=>{if(!e)return;p(""),b(""),y(!1);const N=requestAnimationFrame(()=>{var j;return(j=d.current)==null?void 0:j.focus()});return()=>cancelAnimationFrame(N)},[e,n]),!e)return null;const g=f.trim(),v=a||g===n;async function w(N){if(N.preventDefault(),!v||h)return;y(!0),b("");let j=null;try{const C=new AbortController;j=setTimeout(()=>C.abort(),15e3);const P=await fetch("/api/flow/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:a?n:g,flowArchived:s,workspaceId:o}),signal:C.signal}),I=await P.json().catch(()=>({}));if(!P.ok){b(typeof I.error=="string"?I.error:c("project:deleteModal.deleteFailed"));return}try{for(let z=localStorage.length-1;z>=0;z--){const $=localStorage.key(z);$&&($.startsWith(`af:composer-sessions:${n}:${r}`)||$.startsWith(`af:composer-active-session:${n}:${r}`)||$.startsWith(`af:workspace-composer:${n}:${r}`))&&localStorage.removeItem($)}}catch{}await l()}catch(C){if((C==null?void 0:C.name)==="AbortError"){b(c("project:deleteModal.deleteTimeout"));return}b(String((C==null?void 0:C.message)||C))}finally{j&&clearTimeout(j),y(!1)}}return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:N=>{N.target===N.currentTarget&&t()},children:i.jsxs("div",{ref:d,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":u,tabIndex:-1,onMouseDown:N=>N.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:u,className:"af-shortcuts-panel__title",children:a?"退出共享 Workspace":c("project:deleteModal.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":c("project:deleteModal.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:w,children:[i.jsx("p",{className:"af-new-pipeline-lead",children:a?`退出后,${n} 将从你的项目列表移除;源项目和其他成员的数据不会被删除。`:c("project:deleteModal.lead",{flowId:n})}),a?null:i.jsxs("label",{className:"af-new-pipeline-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:c("project:deleteModal.confirmLabel")}),i.jsx("input",{type:"text",className:"af-new-pipeline-input",value:f,onChange:N=>p(N.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":g.length>0&&!v})]}),k?i.jsx("p",{className:"af-err af-new-pipeline-err",children:k}):null,i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:h,children:c("project:deleteModal.cancel")}),i.jsx("button",{type:"submit",className:"af-btn-primary af-btn-destructive",disabled:!v||h,children:h?a?"退出中...":c("project:deleteModal.deleting"):a?"确认退出":c("project:deleteModal.confirmDelete")})]})]})]})})}const uC=80,OU=220;function DU(e){if(!e||typeof e!="object")return e;const{selected:t,dragging:n,resizing:r,className:s,positionAbsolute:o,measured:a,internals:l,...c}=e;return c}function FU(e){if(!e||typeof e!="object")return e;const{selected:t,className:n,...r}=e;return r}function Rp(e,t,n){const r={nodes:Array.isArray(e)?e.map(DU):[],edges:Array.isArray(t)?t.map(FU):[],extra:n&&typeof n=="object"?n:{}},s=JSON.stringify(r);return{value:JSON.parse(s),signature:s}}function nw(e,t){const n=[...e,t];return n.length>uC?n.slice(n.length-uC):n}function zU({nodes:e,edges:t,extra:n,enabled:r=!0,onRestore:s}){const[o,a]=m.useState(0),l=m.useRef([]),c=m.useRef([]),u=m.useRef(null),d=m.useRef(null),f=m.useRef(null),p=m.useRef(null),h=m.useRef(!1),y=m.useCallback(()=>a(j=>j+1),[]),k=m.useCallback(()=>{p.current&&(window.clearTimeout(p.current),p.current=null)},[]),b=m.useCallback(()=>{k();const j=d.current,C=f.current;return d.current=null,f.current=null,!j||!C||j.signature===C.signature?(C&&(u.current=C),!1):(l.current=nw(l.current,j),c.current=[],u.current=C,y(),!0)},[y,k]),g=m.useCallback((j=[],C=[],P={})=>{k(),l.current=[],c.current=[],d.current=null,f.current=null,u.current=Rp(j,C,P),h.current=!1,y()},[y,k]),v=m.useCallback(j=>{h.current=!0,u.current=j,d.current=null,f.current=null,k(),s==null||s(j.value),y()},[y,k,s]),w=m.useCallback(()=>{b();const j=u.current||Rp(e,t,n),C=l.current.pop();return C?(c.current=nw(c.current,j),v(C),!0):(y(),!1)},[y,t,n,b,e,v]),N=m.useCallback(()=>{b();const j=u.current||Rp(e,t,n),C=c.current.pop();return C?(l.current=nw(l.current,j),v(C),!0):(y(),!1)},[y,t,n,b,e,v]);return m.useEffect(()=>()=>k(),[k]),m.useEffect(()=>{if(!r)return;const j=Rp(e,t,n);if(!u.current){u.current=j;return}if(h.current){h.current=!1,u.current=j;return}j.signature!==u.current.signature&&(d.current||(d.current=u.current),f.current=j,k(),p.current=window.setTimeout(()=>{b()},OU))},[k,t,r,n,b,e]),{canUndo:l.current.length>0||!!d.current,canRedo:c.current.length>0,resetHistory:g,undo:w,redo:N,version:o}}function lo(e){return String(e??"").trim()}function dC(e){return e===!0?!0:["true","yes","done","waived","not_required"].includes(lo(e).toLowerCase())}function BU(e){return e===!1?!0:["false","no","not_required","waived"].includes(lo(e).toLowerCase())}function HU(e,t=""){return lo((e==null?void 0:e.key)||(e==null?void 0:e.issueKey)||(e==null?void 0:e.issue_key)||(e==null?void 0:e.id)||t)}function kT(e){return lo((e==null?void 0:e.platform)||"all").toLowerCase()||"all"}function vT(e){return kT(e)==="all"}function WU(e,t=[]){const n=lo((e==null?void 0:e.sourceIssue)||(e==null?void 0:e.source_issue)||(e==null?void 0:e.parentKey)||(e==null?void 0:e.parent_key)||(e==null?void 0:e.parentIssue)||(e==null?void 0:e.parent_issue)||(e==null?void 0:e.parent));if(n)return n;const r=kT(e),s=HU(e);if(!s||!["android","ios"].includes(r))return"";const o=`-${r}`;if(!s.endsWith(o))return"";const a=s.slice(0,-o.length);return new Set(t.map(l=>lo(l))).has(a)?a:""}function sm(e){const t=lo(e==null?void 0:e.label).toLowerCase(),n=lo((e==null?void 0:e.href)||(e==null?void 0:e.url)).toLowerCase();return/\/merge_requests\/\d+/.test(n)||/\bmr\b|merge request|合并请求|实现 mr|修复 mr|提测 mr|集成 mr/i.test(t)?"mr":/\/issues\/\d+/.test(n)||/gitlab issue/i.test(t)?"issue":"other"}function VU(e=[]){const t={issue:0,mr:1,other:2};return[...e].sort((n,r)=>t[sm(n)]-t[sm(r)])}function KU(e){const t=lo((e==null?void 0:e.noMrReason)||(e==null?void 0:e.no_mr_reason)||(e==null?void 0:e.mrWaiverReason)||(e==null?void 0:e.mr_waiver_reason)||(e==null?void 0:e.implementationNotRequiredReason)||(e==null?void 0:e.implementation_not_required_reason));return/user confirmed self-test completion without implementation mr evidence/i.test(t)?"自测确认,无需实现 MR":t}function qU(e,t=[]){if(vT(e))return{kind:"aggregate",label:"双端汇总",detail:"由 Android / iOS 端侧 Issue 承接"};const n=t.map(sm);if(n.includes("mr"))return{kind:"linked",label:"MR 已关联",detail:""};const r=(e==null?void 0:e.mrRequired)??(e==null?void 0:e.mr_required)??(e==null?void 0:e.requiresMr)??(e==null?void 0:e.requires_mr);return dC(e==null?void 0:e.implementationNotRequired)||dC(e==null?void 0:e.implementation_not_required)||BU(r)?{kind:"not-required",label:KU(e)||"无需实现 MR",detail:""}:n.includes("issue")?{kind:"pending",label:"MR 尚未记录",detail:""}:{kind:"missing-issue",label:"GitLab Issue 未绑定",detail:"端侧执行项应先创建或绑定 GitLab Issue"}}function sb(e=[]){return e.reduce((t,n)=>t+1+sb(Array.isArray(n==null?void 0:n.children)?n.children:[]),0)}function dr(e){return String(e||"").trim()}function $o(e){return dr(e).toLowerCase()}function im(e){return typeof e=="string"?$o(e):!e||typeof e!="object"||Array.isArray(e)?"":$o(e.kind||e.type||e.persistence||e.durability)}function ST(e,t="http://localhost"){const n=dr(e);if(!n)return"";try{const r=new URL(n,t);return r.origin==="null"?`${r.protocol}//${r.host}${r.pathname}`:`${r.origin}${r.pathname}`}catch{return n.split(/[?#]/)[0]}}function NT(e={}){const t=dr(e.href||e.url);if(!t)return!1;const n=$o(e.kind||e.type),r=$o(e.durability),s=$o(e.persistence),o=$o(e.truth||e.stateTruth||e.state_truth),a=$o(e.authority),l=im(e.source)||im(e.sourceArtifact||e.source_artifact),c=[e.label,n].map(dr).join(" "),u=[e.label,e.title,n,s,a,l,t].map(dr).join(" ");if(r==="temporary"||s==="runtime"&&l&&l!=="ai-doc"||l==="local-draft"||n==="temporary-review"||/临时\s*(markdown)?\s*(预览|review)|local[-_ ]?draft/i.test(u)||/gitlab[-_ ]?(issue|epic|mr)|merge[-_ ]?request|jenkins|tapd|实现\s*mr|修复\s*mr|提测\s*mr|集成\s*mr|安装包|二维码/i.test(c)||/tapd[-_ ]?(baseline|snapshot)|baseline[-_ ]?snapshot|tapd_snapshot|snapshot_v\d+\.md/i.test(`${c} ${t}`))return!1;const p=/ai[-_ ]?doc|方案文档|技术方案|设计文档|代码审查|code[-_ ]?review|文档预览|markdown[-_ ]?review/i.test(c),h=n==="ai-doc"||l==="ai-doc"||a==="ai-doc"||s==="ai-doc"&&p,y=o==="durable_fact"||o==="project_fact"||e.confirmed===!0;return h&&(r==="durable"||h||y)}function jT(e={}){const t=[e.label,e.kind,e.title,e.documentType].map(dr).join(" ");return/技术方案|tech(?:nical)?[-_ ]?design/i.test(t)?"tech-design":/方案文档|方案已确认|plan(?:[-_ ]?doc)?/i.test(t)?"plan":/代码审查|code[-_ ]?review/i.test(t)?"code-review":/设计文档|design[-_ ]?doc/i.test(t)?"design":"document"}function UU(e={},{issueTitle:t="",requirementTitle:n=""}={}){const r=dr(e.articleTitle||e.article_title||e.documentTitle||e.document_title||e.docTitle||e.doc_title);return r||(dr(t)?dr(t):jT(e)==="tech-design"&&dr(n)?dr(n):dr(e.title||e.label))}function YU(e={},t="http://localhost"){const n=dr(e.issueKey||e.issue_key||e.issue),r=jT(e);if(n)return`issue:${n}:${r}`;if(r==="tech-design")return"requirement:tech-design";const s=dr(e.documentPath||e.document_path||e.path);return s?`path:${s.replace(/\\/g,"/").replace(/\/+/g,"/")}`:`url:${ST(e.href||e.url,t)}`}function fC(e={}){const t=dr(e.href||e.url),n=$o(e.kind||e.type),r=im(e.source)||im(e.sourceArtifact||e.source_artifact),s=dr(e.label);let o=0;return e.confirmed===!0&&(o+=100),r==="ai-doc"&&(o+=80),n==="ai-doc"&&(o+=70),/^https?:\/\//i.test(t)&&(o+=30),/\/api\/prd-workflow\/review\//.test(t)&&(o+=20),/预览|review/i.test(s)||(o+=10),o}function GU(e,t){const n=fC(t)>fC(e)?t:e,r=n===t?e:t;return{...r,...n,title:pC(e.title)>=pC(t.title)?e.title:t.title,issueKey:e.issueKey||t.issueKey,platform:e.platform||t.platform,documentPath:n.documentPath||r.documentPath,source:n.source||r.source}}function pC(e){const t=dr(e);if(!t)return 0;const n=t.replace(/^Issue\s*\d+\s*/i,"").trim();return/^(方案文档预览|方案文档|技术方案|设计文档|代码审查|Markdown Review|文档预览)$/i.test(n)?10:100+Math.min(t.length,100)}function rw(e,t){const n=new Map,r=[];for(const s of e){const o=t(s);if(!o){r.push(s);continue}const a=n.get(o);if(a===void 0){n.set(o,r.length),r.push(s);continue}r[a]=GU(r[a],s)}return r}function JU(e=[],t="http://localhost"){const n=(Array.isArray(e)?e:[]).filter(o=>NT(o)),r=rw(n,o=>ST(o.href||o.url,t)),s=rw(r,o=>dr(o.documentPath||o.document_path||o.path).replace(/\\/g,"/").replace(/\/+/g,"/"));return rw(s,o=>YU(o,t))}function $r(e){return String(e||"").trim()}function Rc(e){return typeof e=="string"?$r(e).toLowerCase():!e||typeof e!="object"||Array.isArray(e)?"":$r(e.kind||e.type||e.persistence||e.durability).toLowerCase()}function om(e){return/\/api\/prd-workflow\/review\//.test($r((e==null?void 0:e.href)||(e==null?void 0:e.url)))}function CT(e){const t=$r((e==null?void 0:e.kind)||(e==null?void 0:e.type)).toLowerCase(),n=$r(e==null?void 0:e.durability).toLowerCase(),r=$r(e==null?void 0:e.persistence).toLowerCase(),s=Rc(e==null?void 0:e.source)||Rc((e==null?void 0:e.sourceArtifact)||(e==null?void 0:e.source_artifact)),o=[e==null?void 0:e.label,t,n,r,s].map($r).join(" ");return t==="temporary-review"||n==="temporary"||s==="local-draft"||/临时\s*(markdown)?\s*(预览|review)|local[-_ ]?draft/i.test(o)}function XU(e){if(!om(e)||CT(e))return!1;const t=$r((e==null?void 0:e.kind)||(e==null?void 0:e.type)).toLowerCase(),n=$r(e==null?void 0:e.durability).toLowerCase(),r=$r(e==null?void 0:e.persistence).toLowerCase(),s=Rc(e==null?void 0:e.source)||Rc((e==null?void 0:e.sourceArtifact)||(e==null?void 0:e.source_artifact)),o=[e==null?void 0:e.label,t,n,r,s].map($r).join(" ");return t==="review"||n==="durable"||s==="ai-doc"||r==="ai-doc"||/方案文档预览|durable/i.test(o)}function QU(e){if(om(e))return!1;const t=$r((e==null?void 0:e.kind)||(e==null?void 0:e.type)).toLowerCase(),n=$r(e==null?void 0:e.persistence).toLowerCase(),r=Rc(e==null?void 0:e.source)||Rc((e==null?void 0:e.sourceArtifact)||(e==null?void 0:e.source_artifact)),s=[e==null?void 0:e.label,t].map($r).join(" ");return t==="ai-doc"||n==="ai-doc"||r==="ai-doc"||/方案文档|技术方案/.test(s)}function ZU(e={}){const t=[e.stage,e.stageKey,e.stage_key,e.action,e.id,e.title].map($r).join(" ");return/(?:^|[:_-])issue[-_:]?plan(?:$|[:_-])|plan[-_:]?doc|submit[-_:]?plan/i.test(t)||/方案(?:文档)?(?:已确认|预览)/.test(t)}function eY(e=[],t={}){const n=Array.isArray(e)?e:[];if(!ZU(t))return n;const r=n.filter(om);if(r.length===0)return n;const s=r.filter(XU),a=s.length>0||n.some(QU)?s.at(-1):r.filter(CT).at(-1);return n.filter(l=>!om(l)||l===a)}function qr(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function am(e){return Array.isArray(e)?e.map(am):qr(e)?Object.fromEntries(Object.keys(e).sort().map(t=>[t,am(e[t])])):e}function eo(e,t){return JSON.stringify(am(e))===JSON.stringify(am(t))}function _T(e){return qr(e==null?void 0:e.instances)?e.instances:{}}function Kd(e){return qr(e==null?void 0:e.ui)?e.ui:{}}function Tp(e,t){if(!qr(e))return{};const n=new Set(t);return Object.fromEntries(Object.entries(e).filter(([r])=>!n.has(r)))}function tY(e,t){if(!qr(e)||!qr(t)||!qr(e.instances)||!qr(t.instances)||!Array.isArray(e.edges)||!Array.isArray(t.edges)||!qr(e.ui)||!qr(t.ui)||Number(e.version||1)!==Number(t.version||1))return!1;const n=Tp(e,["version","instances","edges","ui"]),r=Tp(t,["version","instances","edges","ui"]);if(!eo(n,r))return!1;const s=["nodePositions","nodeSizes","groups","displayPage","viewport"];return eo(Tp(e.ui,s),Tp(t.ui,s))}function ET(e){const t=Array.isArray(Kd(e).groups)?Kd(e).groups:[];return new Map(t.filter(n=>n==null?void 0:n.id).map(n=>[String(n.id),n]))}function hC(e){const t=new Set(Object.keys(_T(e)));for(const n of Array.isArray(e==null?void 0:e.edges)?e.edges:[])n!=null&&n.source&&t.add(String(n.source)),n!=null&&n.target&&t.add(String(n.target));for(const n of ET(e).keys())t.add(n);return t}function mC(e,t){const n=_T(e),r=Kd(e),s=ET(e);return{instance:Object.prototype.hasOwnProperty.call(n,t)?n[t]:null,position:qr(r.nodePositions)&&Object.prototype.hasOwnProperty.call(r.nodePositions,t)?r.nodePositions[t]:null,size:qr(r.nodeSizes)&&Object.prototype.hasOwnProperty.call(r.nodeSizes,t)?r.nodeSizes[t]:null,group:s.get(t)||null}}function gC(e){return(Array.isArray(e==null?void 0:e.edges)?e.edges:[]).map(t=>({...t})).sort((t,n)=>{const r=[t.source,t.target,t.sourceHandle,t.targetHandle,t.id].map(o=>String(o??"")).join("\0"),s=[n.source,n.target,n.sourceHandle,n.targetHandle,n.id].map(o=>String(o??"")).join("\0");return r.localeCompare(s)})}function nY(e,t){if(!tY(e,t))return{safe:!1,changedNodeIds:[],nodesChanged:!0,edgesChanged:!0,displayPageChanged:!0};const n=new Set([...hC(e),...hC(t)]),r=Array.from(n).filter(s=>!eo(mC(e,s),mC(t,s)));return{safe:!0,changedNodeIds:r,nodesChanged:r.length>0,edgesChanged:!eo(gC(e),gC(t)),displayPageChanged:!eo(Kd(e).displayPage||null,Kd(t).displayPage||null)}}function rY(e,t,n){const r=new Map((Array.isArray(e)?e:[]).map(o=>[o.id,o])),s=new Set(Array.isArray(n)?n:[]);return(Array.isArray(t)?t:[]).map(o=>{const a=r.get(o.id);return a&&!s.has(o.id)?a:a?{...o,selected:a.selected===!0}:o})}function yC(e){return[e==null?void 0:e.source,e==null?void 0:e.target,e==null?void 0:e.sourceHandle,e==null?void 0:e.targetHandle].map(t=>String(t??"")).join("\0")}function wC(e){if(!e||typeof e!="object")return e;const t={...e};return delete t.selected,t}function sY(e,t){const n=new Map((Array.isArray(e)?e:[]).map(r=>[yC(r),r]));return(Array.isArray(t)?t:[]).map(r=>{const s=n.get(yC(r));return s?eo(wC(s),wC(r))?s:{...r,selected:s.selected===!0}:r})}function iY(e,t,n){const r=qr(e)?e:{},s=qr(t)?t:{},o=new Set(Array.isArray(n)?n:[]);return Object.fromEntries(Object.entries(s).map(([a,l])=>[a,!o.has(a)&&Object.prototype.hasOwnProperty.call(r,a)?r[a]:l]))}function oY({background:e=!1,requestId:t=0,currentRequestId:n=0,dirty:r=!1,startedEditVersion:s=0,currentEditVersion:o=0,startedRevision:a="",currentRevision:l=""}={}){return t!==n?"superseded":e&&(r||o!==s||l!==a)?"local-edits":""}function aY({savedGraph:e,sentGraph:t,savedRevision:n="",currentRevision:r=""}={}){return{graph:e||t||null,revision:String(n||r||"")}}function AT(e=[]){let t=!1,n=!1,r=!1;for(const s of Array.isArray(e)?e:[]){if((s==null?void 0:s.type)==="position"&&s.position){r=!0,s.dragging===!0&&(t=!0),s.dragging===!1&&(n=!0);continue}if((s==null?void 0:s.type)==="dimensions"&&s.dimensions){r=!0,s.resizing===!0&&(t=!0),s.resizing===!1&&(n=!0);continue}["add","remove","replace"].includes(s==null?void 0:s.type)&&(r=!0)}return{active:t,finished:n,mutated:r}}function lY(e=[]){const t=AT(e);return t.mutated&&!t.active}function cY(e){return!!((e==null?void 0:e.type)==="position"&&e.position&&e.dragging===!0||(e==null?void 0:e.type)==="dimensions"&&e.dimensions&&e.resizing===!0)}function uY(e){return!!((e==null?void 0:e.type)==="position"&&e.position&&e.dragging===!1||(e==null?void 0:e.type)==="dimensions"&&e.dimensions&&e.resizing===!1)}function dY(e=[]){const t=[],n=[];let r=!1;for(const s of Array.isArray(e)?e:[]){if(cY(s)){t.push(s);continue}n.push(s),uY(s)&&(r=!0)}return{transient:t,committed:n,finishesInteraction:r}}function ib(e=[]){const t=[],n=new Map;for(const r of Array.isArray(e)?e:[]){const s=String((r==null?void 0:r.id)||"").trim();if(!(s&&((r==null?void 0:r.type)==="position"||(r==null?void 0:r.type)==="dimensions"))){t.push(r);continue}const a=`${r.type}:${s}`,l=n.get(a);l==null?(n.set(a,t.length),t.push(r)):t[l]=r}return t}function fY(e=[]){return ib(e).map(t=>(t==null?void 0:t.type)==="position"&&t.position&&t.dragging===!0?{...t,dragging:!1}:(t==null?void 0:t.type)==="dimensions"&&t.dimensions&&t.resizing===!0?{...t,resizing:!1}:t)}function xC(e,t){return{...t,waiters:[...Array.isArray(e==null?void 0:e.waiters)?e.waiters:[],...Array.isArray(t==null?void 0:t.waiters)?t.waiters:[]]}}function pY({background:e=!1}={}){return{graph:!0,nodes:!e,files:!e}}function hY({eventType:e="",revision:t="",currentRevision:n="",targetRevision:r="",refreshPending:s=!1}={}){return e!=="graph.committed"||!t?!1:t===n?!0:t===r&&s}const mY="af:workspace-graph:v2",bC="agentflow.workspace.sidebarCollapsed",Ol=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],gY=new Set(["control_start","control_end","control_load_skills","control_load_mcp","control_cd_workspace","control_user_workspace"]),yY={id:"workspace_run",displayName:"Run",label:"Run",description:"Run the downstream workspace subgraph connected from this node.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},wY={id:"workspace_scheduled_run",displayName:"Scheduled Run",label:"Scheduled Run",description:"Run the downstream workspace subgraph on a schedule.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},xY={id:"control_load_skills",displayName:"Load Skills",label:"Load Skills",description:"Load the currently selected Workspace skill collection for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"skillsContext",default:"",showOnNode:!0}]},bY={id:"control_load_mcp",displayName:"Load MCP",label:"Load MCP",description:"Load selected Cursor MCP server tool manifests for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"serverNames",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"mcpContext",default:"",showOnNode:!0}]},kY={id:"control_cd_workspace",displayName:"加载知识库",label:"加载知识库",description:"Select one or more knowledge sources and pass knowledgeContext to downstream nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"path",default:"",showOnNode:!1},{type:"text",name:"label",default:"",showOnNode:!1},{type:"text",name:"knowledgeContext",default:"",showOnNode:!1},{type:"text",name:"workspaceContext",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"knowledgeContext",default:"",showOnNode:!0},{type:"text",name:"workspaceContext",default:"",showOnNode:!1},{type:"file",name:"cwd",default:"",showOnNode:!1}]},vY={id:"workspace_one_click_task",displayName:"一键任务",label:"一键任务",description:"输入任务,选择 Skills、workspace 上下文和输出类型后直接运行。",type:"agent",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1},{type:"bool",name:"includeWorkspaceContext",default:"true",showOnNode:!1},{type:"text",name:"displayType",default:"markdown",showOnNode:!1},{type:"text",name:"knowledgeContext",default:"",showOnNode:!1},{type:"text",name:"workspaceContext",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"content",default:"",showOnNode:!0},{type:"text",name:"displayType",default:"markdown",showOnNode:!1}]},SY=new Set(["png","jpg","jpeg","gif","webp","svg"]),PT=320,IT=180,RT=960,lm=96,TT=900,ob=520,ab=320,Mp=52,Qa=240,Za=160,lb="display-ref:",qd="0 9 * * *",NY="Asia/Shanghai",jY="0.1.114";function CY(){const e=new URLSearchParams(window.location.search);return{flowId:e.get("flowId")||"",flowSource:e.get("flowSource")||"user",workspaceId:e.get("workspaceId")||"",workflowShare:e.get("workflowShare")||"",archived:e.get("archived")==="1"||e.get("flowArchived")==="1"}}function Tr(e){const t=new URLSearchParams;return e.flowId&&t.set("flowId",e.flowId),e.flowSource&&t.set("flowSource",e.flowSource),e.workspaceId&&t.set("workspaceId",e.workspaceId),e.workflowShare&&t.set("workflowShare",e.workflowShare),e.archived&&t.set("archived","1"),t}function cv(e,t=4e3){const n=String(e??"").trim();return n?n.length>t?`${n.slice(0,t)}
182
+ `}}),i.jsx("textarea",{ref:p,className:"af-body-prompt-textarea "+o,rows:s,value:e,disabled:n,placeholder:r,spellCheck:!1,"aria-invalid":C,"aria-describedby":C?f:void 0,onChange:H=>{t(H.target.value),k(H.target.selectionStart??H.target.value.length)},onSelect:H=>{const D=H.target;D instanceof HTMLTextAreaElement&&k(D.selectionStart??0)},onClick:H=>{const D=H.target;D instanceof HTMLTextAreaElement&&k(D.selectionStart??0)},onKeyUp:H=>{const D=H.target;D instanceof HTMLTextAreaElement&&k(D.selectionStart??D.value.length)},onKeyDown:M,onPaste:H=>{const D=hT(H);D.length!==0&&(H.preventDefault(),K(D).catch(()=>{}))},onDragOver:H=>{fd(H).length>0&&H.preventDefault()},onDrop:H=>{const D=fd(H);D.length!==0&&(H.preventDefault(),K(D).catch(()=>{}))},onScroll:O})]}),z&&$.length>0&&v?cr.createPortal(i.jsx("ul",{className:"af-body-ph-menu af-body-ph-menu--pop af-composer-mention-menu",role:"listbox","aria-label":d("flow:nodeProps.placeholderSlots"),style:{position:"fixed",top:v.top,left:v.left,right:"auto",bottom:"auto",margin:0,zIndex:2e4},children:$.map((H,D)=>i.jsx("li",{role:"option","aria-selected":D===b,children:i.jsxs("button",{type:"button",className:"af-composer-mention-item"+(D===b?" af-composer-mention-item--active":""),onMouseDown:T=>T.preventDefault(),onMouseEnter:()=>g(D),onClick:()=>F(H.insert),children:[i.jsx("span",{className:"af-composer-mention-id",children:`\${${H.insert}}`}),H.subtitle?i.jsx("span",{className:"af-composer-mention-sub",children:H.subtitle}):null]})},`${H.section}-${H.insert}`))}),document.body):null,C?i.jsx("p",{id:f,className:"af-body-ph-issues",role:"status",children:j.map(H=>H.message).join(" · ")}):null]})}const TU=/^[a-zA-Z_][a-zA-Z0-9_-]*$/;function Pu(e){const t=e.indexOf(" - ");return t>=0?e.slice(0,t).trim():e.trim()}function cC({kind:e,label:t,slots:n,onSlotsChange:r,disabled:s,requiredReadonly:o=!0}){const{t:a}=Fr(),l=()=>r([...n,{type:"text",name:"",default:"",required:!1,showOnNode:!1}]),c=f=>r(n.filter((p,h)=>h!==f)),u=(f,p,h)=>{const y=n.map((k,b)=>{if(b!==f)return k;const g={...k,[p]:h};return p==="required"&&h===!0&&(g.showOnNode=!0),g});r(y)},d=e==="input"?"input":"output";return i.jsxs("div",{className:"af-node-props-field af-node-props-field--io",children:[i.jsxs("div",{className:"af-node-props-io-head",children:[i.jsx("span",{className:"af-node-props-label",children:t}),i.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-io-add",onClick:l,disabled:s,"aria-label":a("flow:nodeProps.addPinAriaLabel",{label:t}),children:a("flow:nodeProps.addPin")})]}),i.jsx("p",{className:"af-node-props-io-hint",children:a("flow:nodeProps.handleHint",{prefix:d})}),n.length===0?i.jsx("p",{className:"af-node-props-io-empty",children:a(e==="input"?"flow:nodeProps.noInputPins":"flow:nodeProps.noOutputPins")}):null,n.length>0?i.jsxs("div",{className:"af-node-props-io-table",role:"group","aria-label":t,children:[i.jsxs("div",{className:"af-node-props-io-table-head","aria-hidden":!0,children:[i.jsx("span",{children:a("flow:nodeProps.handle")}),i.jsx("span",{children:a("flow:nodeProps.type")}),i.jsx("span",{children:a("flow:nodeProps.name")}),i.jsx("span",{children:a("flow:nodeProps.defaultValue")}),i.jsx("span",{children:a("flow:nodeProps.description")}),i.jsx("span",{children:a("flow:nodeProps.required")}),i.jsx("span",{children:a("flow:nodeProps.showOnNode")}),i.jsx("span",{})]}),n.map((f,p)=>i.jsxs("div",{className:"af-node-props-io-row",children:[i.jsxs("span",{className:"af-node-props-io-handle",title:`${d}-${p}`,children:[d,"-",p]}),i.jsx("select",{className:"af-node-props-input af-node-props-io-cell",value:f.type,onChange:h=>u(p,"type",h.target.value),disabled:s,"aria-label":a("flow:nodeProps.pinTypeAriaLabel",{label:t,index:p}),children:["node","text","file","bool"].map(h=>i.jsx("option",{value:h,children:h},h))}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:f.name,onChange:h=>u(p,"name",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinNameAriaLabel",{label:t,index:p})}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:f.default,onChange:h=>u(p,"default",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDefaultAriaLabel",{label:t,index:p})}),i.jsx("input",{type:"text",className:"af-node-props-input af-node-props-io-cell",value:f.description||"",onChange:h=>u(p,"description",h.target.value),disabled:s,spellCheck:!1,autoComplete:"off","aria-label":a("flow:nodeProps.pinDescriptionAriaLabel",{label:t,index:p})}),i.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.requiredHint"),children:i.jsx("input",{type:"checkbox",checked:!!f.required,onChange:h=>{o||u(p,"required",h.target.checked)},disabled:s||o,"aria-label":a("flow:nodeProps.pinRequiredAriaLabel",{label:t,index:p})})}),i.jsx("label",{className:"af-node-props-io-flag",title:a("flow:nodeProps.showOnNodeHint"),children:i.jsx("input",{type:"checkbox",checked:f.showOnNode!==!1,onChange:h=>u(p,"showOnNode",h.target.checked),disabled:s,"aria-label":a("flow:nodeProps.pinShowOnNodeAriaLabel",{label:t,index:p})})}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-io-remove",onClick:()=>c(p),disabled:s,"aria-label":a("flow:nodeProps.deletePinAriaLabel",{label:t,index:p}),title:a("flow:nodeProps.deletePin"),children:i.jsx("span",{className:"material-symbols-outlined",children:"delete"})})]},`${d}-${p}`))]}):null]})}function MU({draft:e,setDraft:t,definitionId:n,systemPromptReadonly:r,modelLists:s,disabled:o,onIdBlur:a,onClose:l,onPublishToMarketplace:c,allowEditRequiredPins:u=!1,error:d,ioSlots:f}){const{t:p}=Fr(),[h,y]=m.useState(!1),[k,b]=m.useState(!1),[g,v]=m.useState({status:"idle",message:""}),w=m.useCallback(O=>{t(M=>M&&{...M,...O})},[t]),{cursorList:N,opencodeList:j,claudeCodeList:C,codexList:P,currentNotInLists:I}=m.useMemo(()=>{const O=Array.isArray(s==null?void 0:s.cursor)?s.cursor:[],M=Array.isArray(s==null?void 0:s.opencode)?s.opencode:[],K=Array.isArray(s==null?void 0:s.claudeCode)?s.claudeCode:[],H=Array.isArray(s==null?void 0:s.codex)?s.codex:[],D=new Set([...O,...M,...K,...H].map(Pu)),T=((e==null?void 0:e.model)??"").trim(),W=T.startsWith("cursor:")?T.slice(7):T.startsWith("opencode:")?T.slice(9):T.startsWith("codex:")?T.slice(6):T.startsWith("claude-code:")?T.slice(12):T,E=T&&!D.has(W)?T:"";return{cursorList:O,opencodeList:M,claudeCodeList:K,codexList:H,currentNotInLists:E}},[s,e==null?void 0:e.model]);if(!e)return null;const z=String(e.script??""),$=n==="tool_nodejs"||z.trim()!=="",L=typeof c=="function"&&!o&&(e==null?void 0:e.newId),F=async()=>{if(L){v({status:"running",message:p("flow:nodeProps.publishRunning")});try{const O=await c(e,n);v({status:"success",message:O!=null&&O.definitionId?p("flow:nodeProps.publishSuccessWithId",{id:O.definitionId}):p("flow:nodeProps.publishSuccess")})}catch(O){v({status:"error",message:String((O==null?void 0:O.message)||O)})}}};return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-pipeline-drawer-head af-node-props-head",children:[i.jsx("h2",{className:"af-pipeline-drawer-title",children:p("flow:nodeProps.title")}),i.jsxs("div",{className:"af-node-props-head-actions",children:[i.jsxs("button",{type:"button",className:"af-btn-ghost af-node-props-market-btn",onClick:F,disabled:!L||g.status==="running",title:p("flow:nodeProps.publishToMarketplaceHint"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"inventory_2"}),g.status==="running"?p("flow:nodeProps.publishing"):p("flow:nodeProps.publishToMarketplace")]}),i.jsx("button",{type:"button",className:"af-btn-ghost af-node-props-close-secondary",onClick:l,children:p("common:common.close")})]})]}),i.jsxs("div",{className:"af-pipeline-drawer-body af-node-props-body",children:[d?i.jsx("p",{className:"af-err af-node-props-err",children:d}):null,g.message?i.jsx("p",{className:`af-node-props-market-status af-node-props-market-status--${g.status}`,children:g.message}):null,i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:p("flow:node.nodeType")}),i.jsx("div",{className:"af-pipeline-drawer-readonly af-node-props-readonly-mono",children:n})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:nodeProps.instanceId"),i.jsx("span",{className:"af-node-props-hint",children:p("flow:node.displayNameHint")})]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.newId,onChange:O=>w({newId:O.target.value}),onBlur:a,disabled:o,spellCheck:!1,autoComplete:"off","aria-label":p("flow:nodeProps.instanceId")})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.displayName"),"(LABEL)"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.label,onChange:O=>w({label:O.target.value}),disabled:o,spellCheck:!1})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.role"),"(ROLE)"]}),i.jsx("select",{className:"af-node-props-select",value:Wd.includes(e.role)?e.role:p("flow:roles.normal"),onChange:O=>w({role:O.target.value}),disabled:o,children:Wd.map(O=>i.jsx("option",{value:O,children:O},O))})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.model"),"(MODEL)"]}),i.jsx("span",{className:"af-node-props-sublabel",children:p("flow:node.modelHint")}),i.jsxs("select",{className:"af-node-props-select",value:(()=>{const O=(e.model||"").trim();return O?I||O:""})(),onChange:O=>w({model:O.target.value}),disabled:o,"aria-label":p("flow:nodeProps.modelAriaLabel"),children:[i.jsx("option",{value:"",children:p("flow:node.defaultModel")}),I?i.jsxs("option",{value:I,children:[I,p("flow:nodeProps.yamlValueNotInList")]}):null,N.length>0?i.jsx("optgroup",{label:"Cursor",children:N.map(O=>i.jsx("option",{value:Pu(O),children:O},`c-${O}`))}):null,j.length>0?i.jsx("optgroup",{label:"OpenCode",children:j.map(O=>i.jsx("option",{value:`opencode:${Pu(O)}`,children:O},`o-${O}`))}):null,P.length>0?i.jsx("optgroup",{label:"Codex",children:P.map(O=>i.jsx("option",{value:`codex:${Pu(O)}`,children:O},`codex-${O}`))}):null,C.length>0?i.jsx("optgroup",{label:"Claude Code",children:C.map(O=>i.jsx("option",{value:`claude-code:${Pu(O)}`,children:O},`cc-${O}`))}):null]})]}),i.jsx(cC,{kind:"input",label:p("flow:nodeProps.inputPins"),slots:Array.isArray(e.inputs)?e.inputs:[],onSlotsChange:O=>w({inputs:O}),disabled:o,requiredReadonly:!u}),i.jsx(cC,{kind:"output",label:p("flow:nodeProps.outputPins"),slots:Array.isArray(e.outputs)?e.outputs:[],onSlotsChange:O=>w({outputs:O}),disabled:o,requiredReadonly:!u}),$?i.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[i.jsxs("div",{className:"af-node-props-prompt-head",children:[i.jsxs("span",{className:"af-node-props-label",children:[p("flow:node.directCommand"),"(script)",i.jsx("span",{className:"af-node-props-hint",children:p("flow:node.scriptHint")})]}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>b(!0),"aria-label":p("flow:nodeProps.expandEditScript"),title:p("flow:nodeProps.expand"),disabled:o,children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(Ip,{value:z,onChange:O=>w({script:O}),disabled:o,placeholder:p("flow:nodeProps.scriptPlaceholder"),rows:6,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea af-node-props-script-textarea",ioSlots:f,variant:"drawer"})]}):null,i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Script file(scriptRef)"}),i.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/script.mjs"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.scriptRef||"",onChange:O=>w({scriptRef:O.target.value}),disabled:o,spellCheck:!1,autoComplete:"off"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Implementation file(implementationRef)"}),i.jsxs("span",{className:"af-node-props-sublabel",children:["Relative path under this flow, for example nodes/",e.id,"/implementation.md"]}),i.jsx("input",{type:"text",className:"af-node-props-input",value:e.implementationRef||"",onChange:O=>w({implementationRef:O.target.value}),disabled:o,spellCheck:!1,autoComplete:"off"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:"Implementation mode"}),i.jsxs("select",{className:"af-node-props-select",value:e.implementationMode||"",onChange:O=>w({implementationMode:O.target.value}),disabled:o,children:[i.jsx("option",{value:"",children:"auto"}),i.jsx("option",{value:"script",children:"script"}),i.jsx("option",{value:"steps",children:"steps"}),i.jsx("option",{value:"hybrid",children:"hybrid"})]})]}),i.jsxs("div",{className:"af-pipeline-drawer-field af-node-props-field af-node-props-field--prompt",children:[i.jsxs("div",{className:"af-node-props-prompt-head",children:[i.jsx("span",{className:"af-node-props-label",children:p("flow:node.userPrompt")}),i.jsx("button",{type:"button",className:"af-icon-btn af-node-props-expand",onClick:()=>y(!0),"aria-label":p("flow:nodeProps.expandEdit"),title:p("flow:nodeProps.expand"),disabled:o,children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})})]}),i.jsx(Ip,{value:e.body,onChange:O=>w({body:O}),images:e.images,onImagesChange:O=>w({images:O}),disabled:o,placeholder:p("flow:nodeProps.bodyPlaceholder"),rows:8,textareaClassName:"af-pipeline-drawer-textarea af-node-props-body-textarea",ioSlots:f,variant:"drawer"})]}),i.jsxs("label",{className:"af-pipeline-drawer-field af-node-props-field",children:[i.jsx("span",{className:"af-node-props-label",children:p("flow:node.systemDescription")}),i.jsx("textarea",{className:"af-pipeline-drawer-textarea af-node-props-system-readonly",rows:4,readOnly:!0,value:r||p("flow:nodeProps.noDescription"),spellCheck:!1})]})]}),k?i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editScript"),onMouseDown:O=>{O.target===O.currentTarget&&b(!1)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.directCommand")}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>b(!1),"aria-label":p("flow:nodeProps.collapse"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx(Ip,{value:z,onChange:O=>w({script:O}),disabled:o,placeholder:p("flow:nodeProps.scriptPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:f,variant:"expand"})]})}):null,h?i.jsx("div",{className:"af-node-props-expand-overlay",role:"dialog","aria-modal":"true","aria-label":p("flow:nodeProps.editUserPrompt"),onMouseDown:O=>{O.target===O.currentTarget&&y(!1)},children:i.jsxs("div",{className:"af-node-props-expand-panel",children:[i.jsxs("div",{className:"af-node-props-expand-head",children:[i.jsx("span",{className:"af-node-props-expand-title",children:p("flow:node.body")}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>y(!1),"aria-label":p("flow:nodeProps.collapse"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsx(Ip,{value:e.body,onChange:O=>w({body:O}),images:e.images,onImagesChange:O=>w({images:O}),disabled:o,placeholder:p("flow:nodeProps.bodyPlaceholderExpand"),rows:16,textareaClassName:"af-node-props-expand-textarea",ioSlots:f,variant:"expand"})]})}):null]})}function $U({open:e,onClose:t,flowId:n,flowSource:r,onArchived:s}){const{t:o}=Fr(),a=m.useId(),l=m.useRef(null),[c,u]=m.useState(""),[d,f]=m.useState(!1),[p,h]=m.useState("");if(m.useEffect(()=>{if(!e)return;u(""),h(""),f(!1);const g=requestAnimationFrame(()=>{var v;return(v=l.current)==null?void 0:v.focus()});return()=>cancelAnimationFrame(g)},[e,n]),!e)return null;const y=c.trim(),k=y===n;async function b(g){if(g.preventDefault(),!(!k||d)){f(!0),h("");try{const v=await fetch("/api/flow/archive",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:y})}),w=await v.json().catch(()=>({}));if(!v.ok){h(typeof w.error=="string"?w.error:o("project:archiveModal.archiveFailed"));return}s()}catch(v){h(String((v==null?void 0:v.message)||v))}finally{f(!1)}}}return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:g=>{g.target===g.currentTarget&&t()},children:i.jsxs("div",{ref:l,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":a,tabIndex:-1,onMouseDown:g=>g.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:a,className:"af-shortcuts-panel__title",children:o("project:archiveModal.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":o("project:archiveModal.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:b,children:[i.jsx("p",{className:"af-new-pipeline-lead",children:o("project:archiveModal.lead",{flowId:n})}),i.jsxs("label",{className:"af-new-pipeline-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:o("project:archiveModal.confirmLabel")}),i.jsx("input",{type:"text",className:"af-new-pipeline-input",value:c,onChange:g=>u(g.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":y.length>0&&!k})]}),p?i.jsx("p",{className:"af-err af-new-pipeline-err",children:p}):null,i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:d,children:o("project:archiveModal.cancel")}),i.jsx("button",{type:"submit",className:"af-btn-primary",disabled:!k||d,children:o(d?"project:archiveModal.archiving":"project:archiveModal.confirmArchive")})]})]})]})})}function LU({open:e,onClose:t,flowId:n,flowSource:r,flowArchived:s=!1,workspaceId:o="",leaveShared:a=!1,onDeleted:l}){const{t:c}=Fr(),u=m.useId(),d=m.useRef(null),[f,p]=m.useState(""),[h,y]=m.useState(!1),[k,b]=m.useState("");if(m.useEffect(()=>{if(!e)return;p(""),b(""),y(!1);const N=requestAnimationFrame(()=>{var j;return(j=d.current)==null?void 0:j.focus()});return()=>cancelAnimationFrame(N)},[e,n]),!e)return null;const g=f.trim(),v=a||g===n;async function w(N){if(N.preventDefault(),!v||h)return;y(!0),b("");let j=null;try{const C=new AbortController;j=setTimeout(()=>C.abort(),15e3);const P=await fetch("/api/flow/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({flowId:n,flowSource:r,confirmFlowId:a?n:g,flowArchived:s,workspaceId:o}),signal:C.signal}),I=await P.json().catch(()=>({}));if(!P.ok){b(typeof I.error=="string"?I.error:c("project:deleteModal.deleteFailed"));return}try{for(let z=localStorage.length-1;z>=0;z--){const $=localStorage.key(z);$&&($.startsWith(`af:composer-sessions:${n}:${r}`)||$.startsWith(`af:composer-active-session:${n}:${r}`)||$.startsWith(`af:workspace-composer:${n}:${r}`))&&localStorage.removeItem($)}}catch{}await l()}catch(C){if((C==null?void 0:C.name)==="AbortError"){b(c("project:deleteModal.deleteTimeout"));return}b(String((C==null?void 0:C.message)||C))}finally{j&&clearTimeout(j),y(!1)}}return i.jsx("div",{className:"af-shortcuts-overlay",role:"presentation",onMouseDown:N=>{N.target===N.currentTarget&&t()},children:i.jsxs("div",{ref:d,className:"af-shortcuts-panel af-new-pipeline-panel",role:"dialog","aria-modal":"true","aria-labelledby":u,tabIndex:-1,onMouseDown:N=>N.stopPropagation(),children:[i.jsxs("div",{className:"af-shortcuts-panel__head",children:[i.jsx("h2",{id:u,className:"af-shortcuts-panel__title",children:a?"退出共享 Workspace":c("project:deleteModal.title")}),i.jsx("button",{type:"button",className:"af-shortcuts-panel__close af-icon-btn",onClick:t,"aria-label":c("project:deleteModal.close"),children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("form",{className:"af-shortcuts-panel__body af-new-pipeline-form",onSubmit:w,children:[i.jsx("p",{className:"af-new-pipeline-lead",children:a?`退出后,${n} 将从你的项目列表移除;源项目和其他成员的数据不会被删除。`:c("project:deleteModal.lead",{flowId:n})}),a?null:i.jsxs("label",{className:"af-new-pipeline-field",children:[i.jsx("span",{className:"af-pipeline-drawer-label",children:c("project:deleteModal.confirmLabel")}),i.jsx("input",{type:"text",className:"af-new-pipeline-input",value:f,onChange:N=>p(N.target.value),placeholder:n,autoComplete:"off",spellCheck:!1,"aria-invalid":g.length>0&&!v})]}),k?i.jsx("p",{className:"af-err af-new-pipeline-err",children:k}):null,i.jsxs("div",{className:"af-new-pipeline-actions",children:[i.jsx("button",{type:"button",className:"af-btn-secondary",onClick:t,disabled:h,children:c("project:deleteModal.cancel")}),i.jsx("button",{type:"submit",className:"af-btn-primary af-btn-destructive",disabled:!v||h,children:h?a?"退出中...":c("project:deleteModal.deleting"):a?"确认退出":c("project:deleteModal.confirmDelete")})]})]})]})})}const uC=80,OU=220;function DU(e){if(!e||typeof e!="object")return e;const{selected:t,dragging:n,resizing:r,className:s,positionAbsolute:o,measured:a,internals:l,...c}=e;return c}function FU(e){if(!e||typeof e!="object")return e;const{selected:t,className:n,...r}=e;return r}function Rp(e,t,n){const r={nodes:Array.isArray(e)?e.map(DU):[],edges:Array.isArray(t)?t.map(FU):[],extra:n&&typeof n=="object"?n:{}},s=JSON.stringify(r);return{value:JSON.parse(s),signature:s}}function nw(e,t){const n=[...e,t];return n.length>uC?n.slice(n.length-uC):n}function zU({nodes:e,edges:t,extra:n,enabled:r=!0,onRestore:s}){const[o,a]=m.useState(0),l=m.useRef([]),c=m.useRef([]),u=m.useRef(null),d=m.useRef(null),f=m.useRef(null),p=m.useRef(null),h=m.useRef(!1),y=m.useCallback(()=>a(j=>j+1),[]),k=m.useCallback(()=>{p.current&&(window.clearTimeout(p.current),p.current=null)},[]),b=m.useCallback(()=>{k();const j=d.current,C=f.current;return d.current=null,f.current=null,!j||!C||j.signature===C.signature?(C&&(u.current=C),!1):(l.current=nw(l.current,j),c.current=[],u.current=C,y(),!0)},[y,k]),g=m.useCallback((j=[],C=[],P={})=>{k(),l.current=[],c.current=[],d.current=null,f.current=null,u.current=Rp(j,C,P),h.current=!1,y()},[y,k]),v=m.useCallback(j=>{h.current=!0,u.current=j,d.current=null,f.current=null,k(),s==null||s(j.value),y()},[y,k,s]),w=m.useCallback(()=>{b();const j=u.current||Rp(e,t,n),C=l.current.pop();return C?(c.current=nw(c.current,j),v(C),!0):(y(),!1)},[y,t,n,b,e,v]),N=m.useCallback(()=>{b();const j=u.current||Rp(e,t,n),C=c.current.pop();return C?(l.current=nw(l.current,j),v(C),!0):(y(),!1)},[y,t,n,b,e,v]);return m.useEffect(()=>()=>k(),[k]),m.useEffect(()=>{if(!r)return;const j=Rp(e,t,n);if(!u.current){u.current=j;return}if(h.current){h.current=!1,u.current=j;return}j.signature!==u.current.signature&&(d.current||(d.current=u.current),f.current=j,k(),p.current=window.setTimeout(()=>{b()},OU))},[k,t,r,n,b,e]),{canUndo:l.current.length>0||!!d.current,canRedo:c.current.length>0,resetHistory:g,undo:w,redo:N,version:o}}function lo(e){return String(e??"").trim()}function dC(e){return e===!0?!0:["true","yes","done","waived","not_required"].includes(lo(e).toLowerCase())}function BU(e){return e===!1?!0:["false","no","not_required","waived"].includes(lo(e).toLowerCase())}function HU(e,t=""){return lo((e==null?void 0:e.key)||(e==null?void 0:e.issueKey)||(e==null?void 0:e.issue_key)||(e==null?void 0:e.id)||t)}function kT(e){return lo((e==null?void 0:e.platform)||"all").toLowerCase()||"all"}function vT(e){return kT(e)==="all"}function WU(e,t=[]){const n=lo((e==null?void 0:e.sourceIssue)||(e==null?void 0:e.source_issue)||(e==null?void 0:e.parentKey)||(e==null?void 0:e.parent_key)||(e==null?void 0:e.parentIssue)||(e==null?void 0:e.parent_issue)||(e==null?void 0:e.parent));if(n)return n;const r=kT(e),s=HU(e);if(!s||!["android","ios"].includes(r))return"";const o=`-${r}`;if(!s.endsWith(o))return"";const a=s.slice(0,-o.length);return new Set(t.map(l=>lo(l))).has(a)?a:""}function sm(e){const t=lo(e==null?void 0:e.label).toLowerCase(),n=lo((e==null?void 0:e.href)||(e==null?void 0:e.url)).toLowerCase();return/\/merge_requests\/\d+/.test(n)||/\bmr\b|merge request|合并请求|实现 mr|修复 mr|提测 mr|集成 mr/i.test(t)?"mr":/\/issues\/\d+/.test(n)||/gitlab issue/i.test(t)?"issue":"other"}function VU(e=[]){const t={issue:0,mr:1,other:2};return[...e].sort((n,r)=>t[sm(n)]-t[sm(r)])}function KU(e){const t=lo((e==null?void 0:e.noMrReason)||(e==null?void 0:e.no_mr_reason)||(e==null?void 0:e.mrWaiverReason)||(e==null?void 0:e.mr_waiver_reason)||(e==null?void 0:e.implementationNotRequiredReason)||(e==null?void 0:e.implementation_not_required_reason));return/user confirmed self-test completion without implementation mr evidence/i.test(t)?"自测确认,无需实现 MR":t}function qU(e,t=[]){if(vT(e))return{kind:"aggregate",label:"双端汇总",detail:"由 Android / iOS 端侧 Issue 承接"};const n=t.map(sm);if(n.includes("mr"))return{kind:"linked",label:"MR 已关联",detail:""};const r=(e==null?void 0:e.mrRequired)??(e==null?void 0:e.mr_required)??(e==null?void 0:e.requiresMr)??(e==null?void 0:e.requires_mr);return dC(e==null?void 0:e.implementationNotRequired)||dC(e==null?void 0:e.implementation_not_required)||BU(r)?{kind:"not-required",label:KU(e)||"无需实现 MR",detail:""}:n.includes("issue")?{kind:"pending",label:"MR 尚未记录",detail:""}:{kind:"missing-issue",label:"GitLab Issue 未绑定",detail:"端侧执行项应先创建或绑定 GitLab Issue"}}function sb(e=[]){return e.reduce((t,n)=>t+1+sb(Array.isArray(n==null?void 0:n.children)?n.children:[]),0)}function dr(e){return String(e||"").trim()}function $o(e){return dr(e).toLowerCase()}function im(e){return typeof e=="string"?$o(e):!e||typeof e!="object"||Array.isArray(e)?"":$o(e.kind||e.type||e.persistence||e.durability)}function ST(e,t="http://localhost"){const n=dr(e);if(!n)return"";try{const r=new URL(n,t);return r.origin==="null"?`${r.protocol}//${r.host}${r.pathname}`:`${r.origin}${r.pathname}`}catch{return n.split(/[?#]/)[0]}}function NT(e={}){const t=dr(e.href||e.url);if(!t)return!1;const n=$o(e.kind||e.type),r=$o(e.durability),s=$o(e.persistence),o=$o(e.truth||e.stateTruth||e.state_truth),a=$o(e.authority),l=im(e.source)||im(e.sourceArtifact||e.source_artifact),c=[e.label,n].map(dr).join(" "),u=[e.label,e.title,n,s,a,l,t].map(dr).join(" ");if(r==="temporary"||s==="runtime"&&l&&l!=="ai-doc"||l==="local-draft"||n==="temporary-review"||/临时\s*(markdown)?\s*(预览|review)|local[-_ ]?draft/i.test(u)||/gitlab[-_ ]?(issue|epic|mr)|merge[-_ ]?request|jenkins|tapd|实现\s*mr|修复\s*mr|提测\s*mr|集成\s*mr|安装包|二维码/i.test(c)||/tapd[-_ ]?(baseline|snapshot)|baseline[-_ ]?snapshot|tapd_snapshot|snapshot_v\d+\.md/i.test(`${c} ${t}`))return!1;const p=/ai[-_ ]?doc|方案文档|技术方案|设计文档|代码审查|code[-_ ]?review|文档预览|markdown[-_ ]?review/i.test(c),h=n==="ai-doc"||l==="ai-doc"||a==="ai-doc"||s==="ai-doc"&&p,y=o==="durable_fact"||o==="project_fact"||e.confirmed===!0;return h&&(r==="durable"||h||y)}function jT(e={}){const t=[e.label,e.kind,e.title,e.documentType].map(dr).join(" ");return/技术方案|tech(?:nical)?[-_ ]?design/i.test(t)?"tech-design":/方案文档|方案已确认|plan(?:[-_ ]?doc)?/i.test(t)?"plan":/代码审查|code[-_ ]?review/i.test(t)?"code-review":/设计文档|design[-_ ]?doc/i.test(t)?"design":"document"}function UU(e={},{issueTitle:t="",requirementTitle:n=""}={}){const r=dr(e.articleTitle||e.article_title||e.documentTitle||e.document_title||e.docTitle||e.doc_title);return r||(dr(t)?dr(t):jT(e)==="tech-design"&&dr(n)?dr(n):dr(e.title||e.label))}function YU(e={},t="http://localhost"){const n=dr(e.issueKey||e.issue_key||e.issue),r=jT(e);if(n)return`issue:${n}:${r}`;if(r==="tech-design")return"requirement:tech-design";const s=dr(e.documentPath||e.document_path||e.path);return s?`path:${s.replace(/\\/g,"/").replace(/\/+/g,"/")}`:`url:${ST(e.href||e.url,t)}`}function fC(e={}){const t=dr(e.href||e.url),n=$o(e.kind||e.type),r=im(e.source)||im(e.sourceArtifact||e.source_artifact),s=dr(e.label);let o=0;return e.confirmed===!0&&(o+=100),r==="ai-doc"&&(o+=80),n==="ai-doc"&&(o+=70),/^https?:\/\//i.test(t)&&(o+=30),/\/api\/prd-workflow\/review\//.test(t)&&(o+=20),/预览|review/i.test(s)||(o+=10),o}function GU(e,t){const n=fC(t)>fC(e)?t:e,r=n===t?e:t;return{...r,...n,title:pC(e.title)>=pC(t.title)?e.title:t.title,issueKey:e.issueKey||t.issueKey,platform:e.platform||t.platform,documentPath:n.documentPath||r.documentPath,source:n.source||r.source}}function pC(e){const t=dr(e);if(!t)return 0;const n=t.replace(/^Issue\s*\d+\s*/i,"").trim();return/^(方案文档预览|方案文档|技术方案|设计文档|代码审查|Markdown Review|文档预览)$/i.test(n)?10:100+Math.min(t.length,100)}function rw(e,t){const n=new Map,r=[];for(const s of e){const o=t(s);if(!o){r.push(s);continue}const a=n.get(o);if(a===void 0){n.set(o,r.length),r.push(s);continue}r[a]=GU(r[a],s)}return r}function JU(e=[],t="http://localhost"){const n=(Array.isArray(e)?e:[]).filter(o=>NT(o)),r=rw(n,o=>ST(o.href||o.url,t)),s=rw(r,o=>dr(o.documentPath||o.document_path||o.path).replace(/\\/g,"/").replace(/\/+/g,"/"));return rw(s,o=>YU(o,t))}function $r(e){return String(e||"").trim()}function Rc(e){return typeof e=="string"?$r(e).toLowerCase():!e||typeof e!="object"||Array.isArray(e)?"":$r(e.kind||e.type||e.persistence||e.durability).toLowerCase()}function om(e){return/\/api\/prd-workflow\/review\//.test($r((e==null?void 0:e.href)||(e==null?void 0:e.url)))}function CT(e){const t=$r((e==null?void 0:e.kind)||(e==null?void 0:e.type)).toLowerCase(),n=$r(e==null?void 0:e.durability).toLowerCase(),r=$r(e==null?void 0:e.persistence).toLowerCase(),s=Rc(e==null?void 0:e.source)||Rc((e==null?void 0:e.sourceArtifact)||(e==null?void 0:e.source_artifact)),o=[e==null?void 0:e.label,t,n,r,s].map($r).join(" ");return t==="temporary-review"||n==="temporary"||s==="local-draft"||/临时\s*(markdown)?\s*(预览|review)|local[-_ ]?draft/i.test(o)}function XU(e){if(!om(e)||CT(e))return!1;const t=$r((e==null?void 0:e.kind)||(e==null?void 0:e.type)).toLowerCase(),n=$r(e==null?void 0:e.durability).toLowerCase(),r=$r(e==null?void 0:e.persistence).toLowerCase(),s=Rc(e==null?void 0:e.source)||Rc((e==null?void 0:e.sourceArtifact)||(e==null?void 0:e.source_artifact)),o=[e==null?void 0:e.label,t,n,r,s].map($r).join(" ");return t==="review"||n==="durable"||s==="ai-doc"||r==="ai-doc"||/方案文档预览|durable/i.test(o)}function QU(e){if(om(e))return!1;const t=$r((e==null?void 0:e.kind)||(e==null?void 0:e.type)).toLowerCase(),n=$r(e==null?void 0:e.persistence).toLowerCase(),r=Rc(e==null?void 0:e.source)||Rc((e==null?void 0:e.sourceArtifact)||(e==null?void 0:e.source_artifact)),s=[e==null?void 0:e.label,t].map($r).join(" ");return t==="ai-doc"||n==="ai-doc"||r==="ai-doc"||/方案文档|技术方案/.test(s)}function ZU(e={}){const t=[e.stage,e.stageKey,e.stage_key,e.action,e.id,e.title].map($r).join(" ");return/(?:^|[:_-])issue[-_:]?plan(?:$|[:_-])|plan[-_:]?doc|submit[-_:]?plan/i.test(t)||/方案(?:文档)?(?:已确认|预览)/.test(t)}function eY(e=[],t={}){const n=Array.isArray(e)?e:[];if(!ZU(t))return n;const r=n.filter(om);if(r.length===0)return n;const s=r.filter(XU),a=s.length>0||n.some(QU)?s.at(-1):r.filter(CT).at(-1);return n.filter(l=>!om(l)||l===a)}function qr(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function am(e){return Array.isArray(e)?e.map(am):qr(e)?Object.fromEntries(Object.keys(e).sort().map(t=>[t,am(e[t])])):e}function eo(e,t){return JSON.stringify(am(e))===JSON.stringify(am(t))}function _T(e){return qr(e==null?void 0:e.instances)?e.instances:{}}function Kd(e){return qr(e==null?void 0:e.ui)?e.ui:{}}function Tp(e,t){if(!qr(e))return{};const n=new Set(t);return Object.fromEntries(Object.entries(e).filter(([r])=>!n.has(r)))}function tY(e,t){if(!qr(e)||!qr(t)||!qr(e.instances)||!qr(t.instances)||!Array.isArray(e.edges)||!Array.isArray(t.edges)||!qr(e.ui)||!qr(t.ui)||Number(e.version||1)!==Number(t.version||1))return!1;const n=Tp(e,["version","instances","edges","ui"]),r=Tp(t,["version","instances","edges","ui"]);if(!eo(n,r))return!1;const s=["nodePositions","nodeSizes","groups","displayPage","viewport"];return eo(Tp(e.ui,s),Tp(t.ui,s))}function ET(e){const t=Array.isArray(Kd(e).groups)?Kd(e).groups:[];return new Map(t.filter(n=>n==null?void 0:n.id).map(n=>[String(n.id),n]))}function hC(e){const t=new Set(Object.keys(_T(e)));for(const n of Array.isArray(e==null?void 0:e.edges)?e.edges:[])n!=null&&n.source&&t.add(String(n.source)),n!=null&&n.target&&t.add(String(n.target));for(const n of ET(e).keys())t.add(n);return t}function mC(e,t){const n=_T(e),r=Kd(e),s=ET(e);return{instance:Object.prototype.hasOwnProperty.call(n,t)?n[t]:null,position:qr(r.nodePositions)&&Object.prototype.hasOwnProperty.call(r.nodePositions,t)?r.nodePositions[t]:null,size:qr(r.nodeSizes)&&Object.prototype.hasOwnProperty.call(r.nodeSizes,t)?r.nodeSizes[t]:null,group:s.get(t)||null}}function gC(e){return(Array.isArray(e==null?void 0:e.edges)?e.edges:[]).map(t=>({...t})).sort((t,n)=>{const r=[t.source,t.target,t.sourceHandle,t.targetHandle,t.id].map(o=>String(o??"")).join("\0"),s=[n.source,n.target,n.sourceHandle,n.targetHandle,n.id].map(o=>String(o??"")).join("\0");return r.localeCompare(s)})}function nY(e,t){if(!tY(e,t))return{safe:!1,changedNodeIds:[],nodesChanged:!0,edgesChanged:!0,displayPageChanged:!0};const n=new Set([...hC(e),...hC(t)]),r=Array.from(n).filter(s=>!eo(mC(e,s),mC(t,s)));return{safe:!0,changedNodeIds:r,nodesChanged:r.length>0,edgesChanged:!eo(gC(e),gC(t)),displayPageChanged:!eo(Kd(e).displayPage||null,Kd(t).displayPage||null)}}function rY(e,t,n){const r=new Map((Array.isArray(e)?e:[]).map(o=>[o.id,o])),s=new Set(Array.isArray(n)?n:[]);return(Array.isArray(t)?t:[]).map(o=>{const a=r.get(o.id);return a&&!s.has(o.id)?a:a?{...o,selected:a.selected===!0}:o})}function yC(e){return[e==null?void 0:e.source,e==null?void 0:e.target,e==null?void 0:e.sourceHandle,e==null?void 0:e.targetHandle].map(t=>String(t??"")).join("\0")}function wC(e){if(!e||typeof e!="object")return e;const t={...e};return delete t.selected,t}function sY(e,t){const n=new Map((Array.isArray(e)?e:[]).map(r=>[yC(r),r]));return(Array.isArray(t)?t:[]).map(r=>{const s=n.get(yC(r));return s?eo(wC(s),wC(r))?s:{...r,selected:s.selected===!0}:r})}function iY(e,t,n){const r=qr(e)?e:{},s=qr(t)?t:{},o=new Set(Array.isArray(n)?n:[]);return Object.fromEntries(Object.entries(s).map(([a,l])=>[a,!o.has(a)&&Object.prototype.hasOwnProperty.call(r,a)?r[a]:l]))}function oY({background:e=!1,requestId:t=0,currentRequestId:n=0,dirty:r=!1,startedEditVersion:s=0,currentEditVersion:o=0,startedRevision:a="",currentRevision:l=""}={}){return t!==n?"superseded":e&&(r||o!==s||l!==a)?"local-edits":""}function aY({savedGraph:e,sentGraph:t,savedRevision:n="",currentRevision:r=""}={}){return{graph:e||t||null,revision:String(n||r||"")}}function AT(e=[]){let t=!1,n=!1,r=!1;for(const s of Array.isArray(e)?e:[]){if((s==null?void 0:s.type)==="position"&&s.position){r=!0,s.dragging===!0&&(t=!0),s.dragging===!1&&(n=!0);continue}if((s==null?void 0:s.type)==="dimensions"&&s.dimensions){r=!0,s.resizing===!0&&(t=!0),s.resizing===!1&&(n=!0);continue}["add","remove","replace"].includes(s==null?void 0:s.type)&&(r=!0)}return{active:t,finished:n,mutated:r}}function lY(e=[]){const t=AT(e);return t.mutated&&!t.active}function cY(e){return!!((e==null?void 0:e.type)==="position"&&e.position&&e.dragging===!0||(e==null?void 0:e.type)==="dimensions"&&e.dimensions&&e.resizing===!0)}function uY(e){return!!((e==null?void 0:e.type)==="position"&&e.position&&e.dragging===!1||(e==null?void 0:e.type)==="dimensions"&&e.dimensions&&e.resizing===!1)}function dY(e=[]){const t=[],n=[];let r=!1;for(const s of Array.isArray(e)?e:[]){if(cY(s)){t.push(s);continue}n.push(s),uY(s)&&(r=!0)}return{transient:t,committed:n,finishesInteraction:r}}function ib(e=[]){const t=[],n=new Map;for(const r of Array.isArray(e)?e:[]){const s=String((r==null?void 0:r.id)||"").trim();if(!(s&&((r==null?void 0:r.type)==="position"||(r==null?void 0:r.type)==="dimensions"))){t.push(r);continue}const a=`${r.type}:${s}`,l=n.get(a);l==null?(n.set(a,t.length),t.push(r)):t[l]=r}return t}function fY(e=[]){return ib(e).map(t=>(t==null?void 0:t.type)==="position"&&t.position&&t.dragging===!0?{...t,dragging:!1}:(t==null?void 0:t.type)==="dimensions"&&t.dimensions&&t.resizing===!0?{...t,resizing:!1}:t)}function xC(e,t){return{...t,waiters:[...Array.isArray(e==null?void 0:e.waiters)?e.waiters:[],...Array.isArray(t==null?void 0:t.waiters)?t.waiters:[]]}}function pY({background:e=!1}={}){return{graph:!0,nodes:!e,files:!e}}function hY({eventType:e="",revision:t="",currentRevision:n="",targetRevision:r="",refreshPending:s=!1}={}){return e!=="graph.committed"||!t?!1:t===n?!0:t===r&&s}const mY="af:workspace-graph:v2",bC="agentflow.workspace.sidebarCollapsed",Ol=["DISPLAY","CONTROL","TOOL","PROVIDE","AGENT"],gY=new Set(["control_start","control_end","control_load_skills","control_load_mcp","control_cd_workspace","control_user_workspace"]),yY={id:"workspace_run",displayName:"Run",label:"Run",description:"Run the downstream workspace subgraph connected from this node.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},wY={id:"workspace_scheduled_run",displayName:"Scheduled Run",label:"Scheduled Run",description:"Run the downstream workspace subgraph on a schedule.",type:"control",inputs:[{type:"node",name:"prev",default:""}],outputs:[{type:"node",name:"next",default:""}]},xY={id:"control_load_skills",displayName:"Load Skills",label:"Load Skills",description:"Load the currently selected Workspace skill collection for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"skillsContext",default:"",showOnNode:!0}]},bY={id:"control_load_mcp",displayName:"Load MCP",label:"Load MCP",description:"Load selected Cursor MCP server tool manifests for downstream agent nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"serverNames",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"mcpContext",default:"",showOnNode:!0}]},kY={id:"control_cd_workspace",displayName:"加载知识库",label:"加载知识库",description:"Select one or more knowledge sources and pass knowledgeContext to downstream nodes.",type:"control",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"path",default:"",showOnNode:!1},{type:"text",name:"label",default:"",showOnNode:!1},{type:"text",name:"knowledgeContext",default:"",showOnNode:!1},{type:"text",name:"workspaceContext",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"knowledgeContext",default:"",showOnNode:!0},{type:"text",name:"workspaceContext",default:"",showOnNode:!1},{type:"file",name:"cwd",default:"",showOnNode:!1}]},vY={id:"workspace_one_click_task",displayName:"一键任务",label:"一键任务",description:"输入任务,选择 Skills、workspace 上下文和输出类型后直接运行。",type:"agent",inputs:[{type:"node",name:"prev",default:""},{type:"text",name:"skillKeys",default:"",showOnNode:!1},{type:"bool",name:"includeWorkspaceContext",default:"true",showOnNode:!1},{type:"text",name:"displayType",default:"markdown",showOnNode:!1},{type:"text",name:"knowledgeContext",default:"",showOnNode:!1},{type:"text",name:"workspaceContext",default:"",showOnNode:!1}],outputs:[{type:"node",name:"next",default:""},{type:"text",name:"content",default:"",showOnNode:!0},{type:"text",name:"displayType",default:"markdown",showOnNode:!1}]},SY=new Set(["png","jpg","jpeg","gif","webp","svg"]),PT=320,IT=180,RT=960,lm=96,TT=900,ob=520,ab=320,Mp=52,Qa=240,Za=160,lb="display-ref:",qd="0 9 * * *",NY="Asia/Shanghai",jY="0.1.115";function CY(){const e=new URLSearchParams(window.location.search);return{flowId:e.get("flowId")||"",flowSource:e.get("flowSource")||"user",workspaceId:e.get("workspaceId")||"",workflowShare:e.get("workflowShare")||"",archived:e.get("archived")==="1"||e.get("flowArchived")==="1"}}function Tr(e){const t=new URLSearchParams;return e.flowId&&t.set("flowId",e.flowId),e.flowSource&&t.set("flowSource",e.flowSource),e.workspaceId&&t.set("workspaceId",e.workspaceId),e.workflowShare&&t.set("workflowShare",e.workflowShare),e.archived&&t.set("archived","1"),t}function cv(e,t=4e3){const n=String(e??"").trim();return n?n.length>t?`${n.slice(0,t)}
183
183
  ...[truncated ${n.length-t} chars]`:n:""}function _Y(e){const t=cv(e==null?void 0:e.text,4e3);return t?{role:(e==null?void 0:e.role)==="user"?"user":"assistant",...e!=null&&e.kind?{kind:String(e.kind)}:{},text:t,...e!=null&&e.error?{error:!0}:{},at:Number.isFinite(Number(e==null?void 0:e.at))?Number(e.at):Date.now()}:null}function uv(e,t=80){return(Array.isArray(e)?e:[]).map(_Y).filter(Boolean).slice(-t)}function EY(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:{},n={};for(const[r,s]of Object.entries(t).slice(-80)){const o=String(r||"").trim();if(!o||!s||typeof s!="object")continue;const a=uv(s.messages,40),l=cv(s.draft||"",2e3);!a.length&&!l||(n[o]={sessionId:String(s.sessionId||`nodechat_${o}`),messages:a,...l?{draft:l}:{},candidateContent:"",running:!1,error:""})}return n}function AY(e){return(Array.isArray(e)?e:[]).map(t=>{const n=String((t==null?void 0:t.id)||"").trim();if(!n)return null;const r=uv(t==null?void 0:t.messages,80);if(!r.length)return null;const s=String((t==null?void 0:t.status)||"done");return{id:n,label:cv((t==null?void 0:t.label)||n,120),status:s==="failed"?"failed":"done",messages:r}}).filter(Boolean).slice(-20)}function kC(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:{},n=t.composer&&typeof t.composer=="object"&&!Array.isArray(t.composer)?t.composer:{};return{composer:{activeSessionId:String(n.activeSessionId||"workspace").trim()||"workspace",messages:uv(n.messages,100),runSessions:AY(n.runSessions)},nodeChats:EY(t.nodeChats)}}function cm(e){if(!e)return!1;const t=String(e.type||"");if(t&&/^image\//i.test(t))return!0;const n=String(e.name||"").toLowerCase().split(".").pop();return SY.has(n)}function Ud(e,t,n={}){const r=String(e||"").trim();if(!r)return"";if(/^(?:https?:|data:|blob:|file:)/i.test(r)||r.startsWith("/"))return r;const s=Tr(t||{});return s.set("path",r),n.download&&s.set("download","1"),`/api/workspace/file/raw?${s.toString()}`}function PY(e){const t=String((e==null?void 0:e.flowId)||"").trim();if(!t)return"";const n=String((e==null?void 0:e.flowSource)||"user").trim()||"user";return`af:composer-skills:workspace:${t}:${n}${e!=null&&e.archived?":archived":""}`}function IY(e){const t=String((e==null?void 0:e.username)||(e==null?void 0:e.userId)||"").trim();return t?`${bC}:${t}`:bC}function RY(e){try{const t=window.localStorage.getItem(e);if(t==="false")return!1;if(t==="true")return!0}catch{}return!0}function vC(e){return!e||typeof e.closest!="function"?!1:!!e.closest("input, textarea, select, [contenteditable='true']")}function TY(e){var t;if(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)return Number(e.selectionStart??0)!==Number(e.selectionEnd??0);if(e instanceof Element&&e.closest('[contenteditable="true"]')){const n=(t=window.getSelection)==null?void 0:t.call(window);return!!(n&&!n.isCollapsed)}return!1}function MY(e){return!e||typeof e.closest!="function"?!1:!!e.closest(".af-flow-node__prompt-stack")&&!TY(e)}function $Y(e){const t=String(e||"").trim();if(!t||LY(t))return"";if(/^运行完成/.test(t))return"运行完成";if(/^运行暂停/.test(t))return"运行暂停";if(/^运行停止/.test(t))return"运行停止";if(/^思考中/.test(t))return"模型正在思考";if(/^生成回复中/.test(t))return"模型正在生成回复";if(/^Timing\s+(.+?):\s+(\d+)ms/i.test(t)){const n=t.match(/^Timing\s+(.+?):\s+(\d+)ms/i);return`耗时:${(n==null?void 0:n[1])||"step"} ${(n==null?void 0:n[2])||"0"}ms`}if(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i.test(t)){const n=t.match(/^工具\s+(.+?)(?:\s+\((started|completed)\))?$/i),r=String((n==null?void 0:n[1])||"tool").trim(),s=String((n==null?void 0:n[2])||"").toLowerCase();if(r==="thinking")return"模型正在思考";const o=r==="readToolCall"?"读取文件/上下文":r==="grepToolCall"?"搜索代码":r==="editToolCall"?"编辑文件":r;return s==="completed"?`完成:${o}`:`执行:${o}`}return/^\[stderr\]/.test(t)?t:""}function LY(e){return/^\[stderr\]/.test(e)?/Reading additional input from stdin/i.test(e)||/rmcp::transport::worker/i.test(e)||/Transport channel closed/i.test(e)||/http\/request failed/i.test(e)||/AuthRequiredError/i.test(e)||/No access token was provided/i.test(e)||/api\.githubcopilot\.com/i.test(e):!1}function OY(e){const t=String(e||"").trim();return t?/^模型/.test(t)?"model":/^(执行|完成|耗时):/.test(t)?"tool":/^运行/.test(t)?"run":/^\[stderr\]/.test(t)?"error":"other":"other"}function sw(e,t,n,r="Workspace Run"){var c;const s=String(n||"").trim(),o=Array.isArray(e)?e.find(u=>String((u==null?void 0:u.id)||"")===s):null,a=t&&typeof t=="object"?t[s]:null;return String(((c=o==null?void 0:o.data)==null?void 0:c.label)||(a==null?void 0:a.label)||"").trim()||s||r}function iw(e,t,n="Workspace Run"){const r=String(e||"").trim()||n,s=String(t||"").trim();return!s||r===s?r:`${r} (${s})`}function Ea(e){const t=Math.max(0,Number(e)||0);if(t<1e3)return`${t}ms`;if(t<6e4)return`${(t/1e3).toFixed(t<1e4?1:0)}s`;const n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return`${n}m${r?`${r}s`:""}`}function SC(e){const t=String(e||"").trim().toLowerCase();return{unselected:"未选择需求",unavailable:"未连接",json_unsupported:"待升级",command_failed:"读取失败",uninitialized:"未初始化",preflight_blocked:"环境阻塞",tech_design_missing:"缺技术方案",tech_design_draft_review:"方案待确认",tech_design_confirmed:"方案已确认",baseline_missing:"缺基线",plan_missing:"缺计划",plan_draft_review:"计划待确认",issue_binding_missing:"待绑定 Issue",ready_for_implementation:"待实现",implementation_ready:"待实现",implementing:"实现中",implementation_in_progress:"实现中",implementation_review:"实现待审",self_test_ready:"待自测",bugfix:"修 Bug",fix_ready:"待修复",fix_in_progress:"修复中",testing:"已提测",done:"完成",blocked:"阻塞",conflict:"冲突",requirement_changed:"需求变更"}[t]||t||"未知"}function DY(e){const t=String(e||"").trim().toLowerCase();return!t||["unselected","unavailable","json_unsupported","command_failed","uninitialized","preflight_blocked"].includes(t)?-1:/done|complete|closed|finished/.test(t)?3:/bug|fix|testing|test|self_test|submit_test/.test(t)?2:/implement|development|ready_for_implementation|issue_binding|gitlab|mr/.test(t)?1:0}function FY(e){const t=DY(e);return["方案确定","开发","Bug 修复","完成"].map((n,r)=>{let s="pending";return t>r?s="done":t===r&&(s=r===3?"done":"current"),{label:n,status:s}})}function MT(e){const t=String(e||"").trim();if(!/^https?:\/\//i.test(t))return t;try{const n=new URL(t);if(n.hostname==="0.0.0.0"||n.hostname==="::"||n.hostname==="[::]"){const s=window.location.hostname;n.hostname=s&&s!=="0.0.0.0"&&s!=="::"?s:"127.0.0.1"}const r=String(new URLSearchParams(window.location.search).get("workflowShare")||"").trim();return r&&n.pathname.startsWith("/api/prd-workflow/review/")&&!n.searchParams.has("workflowShare")&&n.searchParams.set("workflowShare",r),n.href}catch{return t}}function hc(e){const t=String((e==null?void 0:e.url)||(e==null?void 0:e.href)||"").trim();if(t)return MT(t);const n=String((e==null?void 0:e.path)||"").trim();return n?`file://${n}`:""}function ca(e){const t=String(e||"").trim().toLowerCase();return["done","success","completed","passed"].includes(t)?"done":["current","running","active","next"].includes(t)?"current":["observed","observation"].includes(t)?"observed":["superseded","stale","replaced"].includes(t)?"superseded":["blocked","failed","error","conflict"].includes(t)?"blocked":"pending"}function Zo(e){if(!e||typeof e!="object")return"";const t=String(e.truth||e.stateTruth||e.state_truth||"").trim().toLowerCase();return t||(String(e.idempotencyKey||e.idempotency_key||"").trim().startsWith("snapshot-action:")||String(e.source||"")==="prd-flow-client"&&String(e.type||"")==="workflow-action"?"observation":String(e.type||"")==="review-link"?"runtime_event":"")}function dv(e){return ca(e==null?void 0:e.status)==="done"&&Zo(e)!=="observation"}function to(e,t){return!e||typeof e!="object"?`Action ${t+1}`:String(e.title||e.label||e.name||e.actionLabel||e.action_label||e.id||e.action||`Action ${t+1}`)}function ph(e){return!e||typeof e!="object"?"":String(e.detail||e.description||e.summary||e.message||e.reason||"")}function fv(e){return!e||typeof e!="object"?"":[e.code,e.action,e.actionId,e.action_id,e.stage,e.stageKey,e.stage_key,e.type,e.title].map(t=>String(t||"")).join(" ").toLowerCase()}function zY(e,t="当前任务"){const r=[e==null?void 0:e.issueLabel,e==null?void 0:e.issue_label,e==null?void 0:e.title,e==null?void 0:e.label,e==null?void 0:e.name].map(s=>String(s||"")).join(" ").match(/\b(Issue\d+|Bug\d+)\b/i);return r?r[1].replace(/^issue/i,"Issue").replace(/^bug/i,"Bug"):t}function BY(e,t){const n=to(e,t),r=ca(e==null?void 0:e.status),s=dv(e),a=`${el(e)} ${fv(e)}`,l=zY(e);if(/issue-plan:|plan_draft_local|submit-plan|plan-doc|plan_doc_confirmed/.test(a)){if(s)return`${l} 方案已确认`;if(r==="observed"||r==="superseded"||Zo(e)==="observation")return`${l} 方案状态已观察`;if(r==="current"&&/^确认\s+/.test(n))return n}if(/issue-gitlab:|gitlab_issue_missing|ensure-gitlab-issue/.test(a)){if(s)return`已为 ${l} 创建/绑定 GitLab Issue`;if(r==="observed"||r==="superseded"||Zo(e)==="observation")return`${l} GitLab Issue 状态已观察`}return/implementation_in_progress|impl_in_progress/.test(a)?`正在实现 ${l}`:/implementation_ready/.test(a)?`可以开始实现 ${l}`:n}function HY(e){if(!e||typeof e!="object")return"";const t=ca(e.status),n=Zo(e),r=dv(e),o=`${el(e)} ${fv(e)}`,a=pv(e),l=a.some(f=>/方案|plan|markdown|review|预览/i.test(String(f.label||""))),c=a.some(f=>/gitlab issue/i.test(String(f.label||""))),u=a.some(f=>/gitlab epic/i.test(String(f.label||"")));if(/issue-plan:|plan_draft_local|submit-plan|plan-doc|plan_doc_confirmed/.test(o))return r?l?"方案已确认并归档;可从下方打开方案文档预览。":"方案已确认并归档。":n==="observation"||t==="observed"?"客户端上报了当前方案阶段;这不是 ai-doc 确认结果。":t==="superseded"?"该客户端观察已被更新状态替代,仅保留为运行态记录。":t==="current"?"方案草稿已生成,等待确认;确认后会归档为正式方案。":"方案草稿已生成,等待确认。";if(/issue-gitlab:|gitlab_issue_missing|ensure-gitlab-issue/.test(o))return r?c&&u?"GitLab Issue 和 Epic 已绑定;可从下方打开关联链接。":c?"GitLab Issue 已绑定;可从下方打开关联链接。":"GitLab Issue 绑定步骤已完成。":n==="observation"||t==="observed"?"客户端上报了 GitLab Issue 阶段;是否已绑定以 GitLab/ai-doc 事实为准。":t==="superseded"?"该客户端观察已被更新状态替代,仅保留为运行态记录。":"方案文档已归档,等待创建或绑定 GitLab Issue。";if(/implementation_in_progress|impl_in_progress/.test(o))return"需求分支已就绪,当前处于实现中;实现 MR 创建后会记录到本 Issue。";if(/implementation_ready/.test(o))return"方案文档和 GitLab Issue 已就绪,等待开始实现。";const d=ph(e);return d?d.length>180&&a.length?"相关结果和产物已更新;可从下方链接查看。":d:""}function um(e){return!e||typeof e!="object"?"":String(e.time||e.at||e.observedAt||e.observed_at||e.reportedAt||e.reported_at||e.startedAt||e.started_at||e.completedAt||e.completed_at||e.updatedAt||e.updated_at||e.createdAt||e.created_at||"")}const $T="Asia/Shanghai",WY=new Intl.DateTimeFormat("zh-CN",{timeZone:$T,year:"numeric",month:"2-digit",day:"2-digit"}),VY=new Intl.DateTimeFormat("zh-CN",{timeZone:$T,hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});function LT(e){const t=um(e);if(!t)return null;const n=Date.parse(t);return Number.isFinite(n)?new Date(n):null}function KY(e){const t=LT(e);return t?WY.format(t).replace(/\//g,"-"):"无时间"}function qY(e){const t=LT(e);return t?VY.format(t):""}function UY(e=[]){const t=[];return(Array.isArray(e)?e:[]).forEach((n,r)=>{const s=KY(n);let o=t[t.length-1];(!o||o.day!==s)&&(o={day:s,items:[]},t.push(o)),o.items.push({item:n,index:r})}),t}function OT(e){const t=ca(e);return t==="done"?"完成":t==="current"?"当前":t==="observed"?"已观察":t==="superseded"?"已更新":t==="blocked"?"阻塞":"待处理"}function Ta(e){const t=String(e||"").trim(),n=t.toLowerCase();return n==="android"?"Android":n==="ios"?"iOS":["all","both","cross-platform","cross_platform"].includes(n)?"双端":t}function YY(e){const t=ca(e==null?void 0:e.status);return Zo(e)==="observation"&&t==="done"?"已观察":OT(t)}function DT(e){if(!e||typeof e!="object")return[];const t=[],n=(o,a,l)=>{const c=String(l||"").trim();c&&t.push({key:`${o}:${c}`,type:o,label:String(a||c),value:c})},r=ca(e.status),s=Zo(e)==="observation"&&r==="done"?"observed":r;return n("status",OT(s),s),n("issue",e.issueKey||e.issue_key||e.issue,e.issueKey||e.issue_key||e.issue),n("platform",Ta(e.platform),e.platform),t}function GY(e=[]){const t=new Map;return(Array.isArray(e)?e:[]).forEach(n=>{DT(n).forEach(r=>{const s=t.get(r.key);t.set(r.key,{...r,count:((s==null?void 0:s.count)||0)+1})})}),Array.from(t.values()).sort((n,r)=>{const s={status:0,issue:1,platform:2,source:3,actor:4};return(s[n.type]??9)-(s[r.type]??9)||r.count-n.count||n.label.localeCompare(r.label)})}function JY(e,t){const n=String(t||"all");return!n||n==="all"?!0:DT(e).some(r=>r.key===n)}function XY(e){if(!e||typeof e!="object")return[];const t=[],n=(r,s)=>{const o=String(s||"").trim();o&&t.push({label:r,value:o})};return n("Issue",e.issueKey||e.issue_key||e.issue),n("平台",Ta(e.platform)),t}function pv(e){const t=[],n=(c,u,d={})=>{const f=MT(u);f&&t.push({...d,label:String(c||f).trim()||f,href:f})},r=(c,u="链接",d=0)=>{if(d>3||c==null)return;if(typeof c=="string"){(/^(https?:\/\/|file:\/\/)/i.test(c)||c.startsWith("/"))&&n(u,c);return}if(Array.isArray(c)){c.forEach((p,h)=>r(p,`${u} ${h+1}`,d+1));return}if(typeof c!="object")return;const f=c.label||c.title||c.name||c.kind||c.type||u;n(f,c.url||c.href||c.path||c.file||c.filePath||c.file_path,c);for(const p of["links","urls","artifacts","outputs","output","results","result","files"])c[p]!=null&&r(c[p],p,d+1)},s=Array.isArray(e==null?void 0:e.links)?e.links:[];for(const c of s)typeof c=="string"?n("链接",c):n((c==null?void 0:c.label)||(c==null?void 0:c.title)||(c==null?void 0:c.kind)||"链接",(c==null?void 0:c.url)||(c==null?void 0:c.href),c);for(const c of Array.isArray(e==null?void 0:e.artifacts)?e.artifacts:[])n((c==null?void 0:c.label)||(c==null?void 0:c.title)||(c==null?void 0:c.kind)||"Artifact",hc(c),c);n("TAPD",(e==null?void 0:e.tapdUrl)||(e==null?void 0:e.tapd_url)),n("ai-doc",(e==null?void 0:e.docUrl)||(e==null?void 0:e.doc_url)||(e==null?void 0:e.aiDocUrl)||(e==null?void 0:e.ai_doc_url)),n("Plan",(e==null?void 0:e.planDocUrl)||(e==null?void 0:e.plan_doc_url)||(e==null?void 0:e.planUrl)||(e==null?void 0:e.plan_url)),n("Issue",(e==null?void 0:e.issueUrl)||(e==null?void 0:e.issue_url)),n("GitLab Issue",(e==null?void 0:e.gitlabIssue)||(e==null?void 0:e.gitlab_issue)),n("GitLab Epic",(e==null?void 0:e.gitlabEpic)||(e==null?void 0:e.gitlab_epic)),n("MR",(e==null?void 0:e.mrUrl)||(e==null?void 0:e.mr_url)||(e==null?void 0:e.mergeRequestUrl)||(e==null?void 0:e.merge_request_url)),n("实现 MR",(e==null?void 0:e.implMr)||(e==null?void 0:e.impl_mr)),n("修复 MR",(e==null?void 0:e.fixMr)||(e==null?void 0:e.fix_mr)),n("提测 MR",(e==null?void 0:e.testMr)||(e==null?void 0:e.test_mr)),n("集成 MR",(e==null?void 0:e.integrationMr)||(e==null?void 0:e.integration_mr)),n("Jenkins",(e==null?void 0:e.jenkinsUrl)||(e==null?void 0:e.jenkins_url)||(e==null?void 0:e.jenkinsBuildUrl)||(e==null?void 0:e.jenkins_build_url)),n("安装包",(e==null?void 0:e.jenkinsPackageUrl)||(e==null?void 0:e.jenkins_package_url)),n("二维码",(e==null?void 0:e.jenkinsQrUrl)||(e==null?void 0:e.jenkins_qr_url)),n("调整",(e==null?void 0:e.editUrl)||(e==null?void 0:e.edit_url)||(e==null?void 0:e.adjustUrl)||(e==null?void 0:e.adjust_url)),n("链接",(e==null?void 0:e.url)||(e==null?void 0:e.href)),r(e==null?void 0:e.urls,"URL"),r(e==null?void 0:e.outputs,"产物"),r(e==null?void 0:e.output,"产物"),r(e==null?void 0:e.results,"结果"),r(e==null?void 0:e.result,"结果"),r(e==null?void 0:e.files,"文件");const o=c=>{const u=String(c||"").trim();try{const d=new URL(u,window.location.origin);return`${d.origin}${d.pathname}`}catch{return u.split(/[?#]/)[0]}},a=c=>{const u=String(c||"");return/方案文档/.test(u)?50:/临时/.test(u)?40:/Markdown Review/i.test(u)?20:/预览|review/i.test(u)?10:0},l=new Map;for(const c of t){const u=/\/api\/prd-workflow\/review\//.test(String(c.href||"")),d=u?`review:${o(c.href)}`:`${c.label}
184
184
  ${c.href}`,f=l.get(d);if(!f){l.set(d,c);continue}if(u){const p=a(f.label),h=a(c.label);(h>p||h===p&&String(c.label||"").length>String(f.label||"").length)&&l.set(d,c)}}return eY(Array.from(l.values()),e)}function QY(e,t=[]){var a,l,c,u;const n=[],r=new Map,s=String(((l=(a=e==null?void 0:e.overall)==null?void 0:a.requirement)==null?void 0:l.title)||((u=(c=e==null?void 0:e.overall)==null?void 0:c.requirement)==null?void 0:u.name)||"").trim();for(const d of cb(e)){const f=_i(d),p=String((d==null?void 0:d.title)||(d==null?void 0:d.name)||(d==null?void 0:d.summary)||"").trim();f&&p&&r.set(f,p)}const o=(d,f={})=>{if(!d||typeof d!="object")return;const p=(y,k={})=>{if(!y||typeof y!="object")return;const b=String(f.issueKey||(d==null?void 0:d.issueKey)||(d==null?void 0:d.issue_key)||(d==null?void 0:d.issue)||"").trim(),g=y.source||y.sourceArtifact||y.source_artifact||d.sourceArtifact||d.source_artifact||d.source||f.source||null,v=UU({...y,title:y.title||f.documentTitle||(d==null?void 0:d.title)||"",documentTitle:y.documentTitle||y.document_title||(d==null?void 0:d.documentTitle)||(d==null?void 0:d.document_title)||""},{issueTitle:r.get(b)||"",requirementTitle:s}),w={label:String(y.label||"ai-doc").trim()||"ai-doc",href:String(y.href||y.url||"").trim(),kind:String(y.kind||y.type||d.kind||d.type||"").trim(),title:v,issueKey:b,platform:f.platform||Ta(d.platform),durability:y.durability||d.durability||f.durability||"",persistence:y.persistence||d.persistence||f.persistence||"",truth:y.truth||y.stateTruth||y.state_truth||Zo(d)||f.truth||"",authority:y.authority||d.authority||f.authority||"",confirmed:y.confirmed??d.confirmed??f.confirmed,source:g,documentPath:y.documentPath||y.document_path||y.path||k.documentPath||(g==null?void 0:g.path)||(g==null?void 0:g.documentPath)||(g==null?void 0:g.document_path)||""};w.href&&n.push(w)};for(const y of Array.isArray(d==null?void 0:d.artifacts)?d.artifacts:[])!y||typeof y!="object"||p({...y,label:y.label||y.title||y.kind||"ai-doc",href:hc(y)},{documentPath:y.path});for(const y of Array.isArray(d==null?void 0:d.links)?d.links:[])!y||typeof y!="object"||p({...y,label:y.label||y.title||y.kind||"ai-doc",href:hc(y)},{documentPath:y.path});const h=hc(d);h&&p({...d,label:d.label||d.title||d.kind||"ai-doc",href:h},{documentPath:d.path})};o(e);for(const d of Array.isArray(t)?t:[])o(d,{issueKey:String((d==null?void 0:d.issueKey)||(d==null?void 0:d.issue_key)||(d==null?void 0:d.issue)||"").trim(),platform:Ta(d==null?void 0:d.platform),documentTitle:String((d==null?void 0:d.documentTitle)||(d==null?void 0:d.document_title)||(d==null?void 0:d.title)||"").trim()});for(const d of["actions","workflowActions","workflow_actions","timeline","history","events","runtimeEvents","runtime_events"])for(const f of Array.isArray(e==null?void 0:e[d])?e[d]:[])o(f,{issueKey:String((f==null?void 0:f.issueKey)||(f==null?void 0:f.issue_key)||(f==null?void 0:f.issue)||"").trim(),platform:Ta(f==null?void 0:f.platform),documentTitle:String((f==null?void 0:f.documentTitle)||(f==null?void 0:f.document_title)||(f==null?void 0:f.title)||"").trim()});for(const d of cb(e))o(d,{issueKey:_i(d),platform:Ta(d==null?void 0:d.platform),documentTitle:String((d==null?void 0:d.title)||(d==null?void 0:d.name)||(d==null?void 0:d.summary)||"").trim()});return JU(n,window.location.origin)}function ZY(e){return!e||typeof e!="object"?{}:{marker:e.marker||e.flag||"",command:e.command||e.nextCommand||e.next_command||"",runtimeOnly:e.runtimeOnly===!0||e.runtime_only===!0,markerOnly:e.markerOnly===!0||e.marker_only===!0,url:e.url||e.href||e.mrUrl||e.mr_url||e.mergeRequestUrl||e.merge_request_url||"",mr:e.mr||e.mrUrl||e.mr_url||e.mergeRequestUrl||e.merge_request_url||"",testEnv:e.testEnv||e.test_environment||"",summary:e.summary||e.detail||e.description||"",links:Array.isArray(e.links)?e.links:[],artifacts:Array.isArray(e.artifacts)?e.artifacts:[],outputs:Array.isArray(e.outputs)?e.outputs:[],results:Array.isArray(e.results)?e.results:[]}}function _i(e,t=0){return String((e==null?void 0:e.key)||(e==null?void 0:e.issueKey)||(e==null?void 0:e.issue_key)||(e==null?void 0:e.id)||(e==null?void 0:e.iid)||(e==null?void 0:e.title)||`issue-${t+1}`).trim()}function eG(e,t=0){return String((e==null?void 0:e.title)||(e==null?void 0:e.name)||(e==null?void 0:e.label)||(e==null?void 0:e.summary)||_i(e,t)||`Issue ${t+1}`).trim()}function tG(e){return String((e==null?void 0:e.epicKey)||(e==null?void 0:e.epic_key)||(e==null?void 0:e.epic)||(e==null?void 0:e.epicTitle)||(e==null?void 0:e.epic_title)||(e==null?void 0:e.parentEpic)||(e==null?void 0:e.parent_epic)||"未归类").trim()}function nG(e){return String((e==null?void 0:e.sourceIssue)||(e==null?void 0:e.source_issue)||(e==null?void 0:e.parentKey)||(e==null?void 0:e.parent_key)||(e==null?void 0:e.parent)||(e==null?void 0:e.parentIssue)||(e==null?void 0:e.parent_issue)||"").trim()}function rG(e){const t=pv(e),n=(s,o)=>{if(Array.isArray(s)){for(const a of s)if(a)if(typeof a=="string")t.push({label:o,href:a});else{const l=a.url||a.href||a.webUrl||a.web_url||a.mrUrl||a.mr_url||a.issueUrl||a.issue_url;l&&t.push({label:a.label||a.title||a.platform||a.kind||o,href:l})}}};n(e==null?void 0:e.mrs,"MR"),n(e==null?void 0:e.mergeRequests,"MR"),n(e==null?void 0:e.merge_requests,"MR"),n(e==null?void 0:e.implMrs,"MR"),n(e==null?void 0:e.impl_mrs,"MR"),n(e==null?void 0:e.platformMrs,"MR"),n(e==null?void 0:e.platform_mrs,"MR");const r=new Set;return t.filter(s=>{const o=String(s.href||"").trim();if(!o)return!1;const a=`${s.label}
185
185
  ${o}`;return r.has(a)?!1:(r.add(a),!0)})}function sG(e){const t=Array.isArray(e==null?void 0:e.epics)?e.epics:Array.isArray(e==null?void 0:e.epicGroups)?e.epicGroups:Array.isArray(e==null?void 0:e.epic_groups)?e.epic_groups:[],n=[],r=new Map,s=(a,l="")=>{const c=String(a||"未归类").trim()||"未归类";return r.has(c)?l&&r.get(c).title===c&&(r.get(c).title=String(l)):r.set(c,{key:c,title:String(l||c),issues:[]}),r.get(c)};for(const a of t){const l=String((a==null?void 0:a.key)||(a==null?void 0:a.id)||(a==null?void 0:a.title)||(a==null?void 0:a.name)||"未归类").trim(),c=s(l,(a==null?void 0:a.title)||(a==null?void 0:a.name)||l),u=Array.isArray(a==null?void 0:a.issues)?a.issues:Array.isArray(a==null?void 0:a.children)?a.children:Array.isArray(a==null?void 0:a.items)?a.items:[];for(const d of u)d&&typeof d=="object"&&c.issues.push({...d,epicKey:l})}for(const a of Array.isArray(e==null?void 0:e.issues)?e.issues:[])a&&typeof a=="object"&&n.push(a);for(const a of n)s(tG(a)).issues.push(a);const o=a=>{const l=new Map,c=[],u=a.map((d,f)=>_i(d,f));return a.forEach((d,f)=>{const p=_i(d,f);l.set(p,{issue:d,children:[]})}),a.forEach((d,f)=>{const p=_i(d,f),h=nG(d)||WU(d,u),y=l.get(p);h&&l.has(h)?l.get(h).children.push(y):c.push(y)}),c};return Array.from(r.values()).map(a=>({...a,issues:o(a.issues)}))}function Yd(e){return String((e==null?void 0:e.actionId)||(e==null?void 0:e.action_id)||(e==null?void 0:e.action)||(e==null?void 0:e.id)||"").trim()}function el(e){if(!e||typeof e!="object")return"";const t=String(e.issueKey||e.issue_key||e.issue||"").trim(),n=String(e.action||e.actionId||e.action_id||Yd(e)||"").trim(),r=String(e.stageKey||e.stage_key||e.stage||e.phase||e.code||e.pointer||n).trim(),s=[r,n,e.code,e.type,e.title].map(o=>String(o||"")).join(" ").toLowerCase();if(t){if(/plan_draft_local|submit-plan|plan-doc/.test(s))return`issue-plan:${t}`;if(/gitlab_issue_missing|ensure-gitlab-issue/.test(s))return`issue-gitlab:${t}`}return r}function dm(e){const t=um(e)||String((e==null?void 0:e.startedAt)||(e==null?void 0:e.started_at)||(e==null?void 0:e.createdAt)||(e==null?void 0:e.created_at)||(e==null?void 0:e.updatedAt)||(e==null?void 0:e.updated_at)||""),n=Date.parse(t);return Number.isFinite(n)?n:NaN}function cb(e){var s,o,a,l,c,u,d,f,p,h,y,k;const t=[],n=b=>{b&&typeof b=="object"&&!Array.isArray(b)&&t.push(b)},r=b=>{if(!b||typeof b!="object"||Array.isArray(b))return;const g=Array.isArray(b.issues)?b.issues:Array.isArray(b.children)?b.children:Array.isArray(b.items)?b.items:[];for(const v of g)!v||typeof v!="object"||Array.isArray(v)||(v.issue&&typeof v.issue=="object"?(n(v.issue),Array.isArray(v.children)&&v.children.forEach(w=>n((w==null?void 0:w.issue)||w))):n(v))};return[e==null?void 0:e.issues,(s=e==null?void 0:e.raw)==null?void 0:s.issues,(a=(o=e==null?void 0:e.raw)==null?void 0:o.prd)==null?void 0:a.issues].forEach(b=>{Array.isArray(b)&&b.forEach(n)}),[e==null?void 0:e.epics,e==null?void 0:e.epicGroups,e==null?void 0:e.epic_groups,(l=e==null?void 0:e.raw)==null?void 0:l.epics,(c=e==null?void 0:e.raw)==null?void 0:c.epicGroups,(u=e==null?void 0:e.raw)==null?void 0:u.epic_groups,(f=(d=e==null?void 0:e.raw)==null?void 0:d.prd)==null?void 0:f.epics,(h=(p=e==null?void 0:e.raw)==null?void 0:p.prd)==null?void 0:h.epicGroups,(k=(y=e==null?void 0:e.raw)==null?void 0:y.prd)==null?void 0:k.epic_groups].forEach(b=>{Array.isArray(b)&&b.forEach(r)}),t}function iG(e,t){const n=String(t||"").trim();return n&&cb(e).find((r,s)=>_i(r,s)===n)||null}function oG(e){var t,n,r,s,o,a,l,c;return String((e==null?void 0:e.gitlabEpic)||(e==null?void 0:e.gitlab_epic)||((t=e==null?void 0:e.prd)==null?void 0:t.gitlabEpic)||((n=e==null?void 0:e.prd)==null?void 0:n.gitlab_epic)||((r=e==null?void 0:e.raw)==null?void 0:r.gitlabEpic)||((s=e==null?void 0:e.raw)==null?void 0:s.gitlab_epic)||((a=(o=e==null?void 0:e.raw)==null?void 0:o.prd)==null?void 0:a.gitlabEpic)||((c=(l=e==null?void 0:e.raw)==null?void 0:l.prd)==null?void 0:c.gitlab_epic)||"").trim()}function aG(e,t){if(!t||typeof t!="object")return t;const n=String(t.issueKey||t.issue_key||t.issue||"").trim(),r=iG(e,n),s=String(t.platform||(r==null?void 0:r.platform)||"").trim(),o=s&&!t.platform?{...t,platform:s}:t,a=String((r==null?void 0:r.gitlabIssue)||(r==null?void 0:r.gitlab_issue)||o.gitlabIssue||o.gitlab_issue||"").trim(),l=oG(e);if(!a&&!l)return o;const c=el(o),u=`${c} ${fv(o)}`;if(!/issue-gitlab:|gitlab_issue_missing|ensure-gitlab-issue|implementation|impl_|fix_|testing|submit-test|self-test/i.test(u))return o;const f=[];a&&f.push({label:"GitLab Issue",kind:"gitlab-issue",durability:"durable",url:a}),l&&f.push({label:"GitLab Epic",kind:"gitlab-epic",durability:"durable",url:l});const p=ca(o.status),h=a&&p==="done"&&/^issue-gitlab:/.test(c)&&/需要.*GitLab Issue/.test(String(o.title||o.label||""));return{...o,...a?{gitlabIssue:a,gitlab_issue:a}:{},...l?{gitlabEpic:l,gitlab_epic:l}:{},...h?{title:String(o.title||o.label||"GitLab Issue 已绑定").replace(/^需要为/,"已为").replace("创建或绑定","创建/绑定"),label:String(o.label||o.title||"GitLab Issue 已绑定").replace(/^需要为/,"已为").replace("创建或绑定","创建/绑定")}:{},artifacts:vi(o.artifacts,f)}}function vi(e,t){const n=[],r=new Set,s=o=>{if(!o)return;const a=typeof o=="string"?o:JSON.stringify(o);r.has(a)||(r.add(a),n.push(o))};return(Array.isArray(e)?e:[]).forEach(s),(Array.isArray(t)?t:[]).forEach(s),n}function NC(e,t){const n=dm(t),r=dm(e),s=Number.isFinite(n)&&(!Number.isFinite(r)||n>=r)?t:e,o=(s==null?void 0:s.status)||(t==null?void 0:t.status)||(e==null?void 0:e.status);return{...e,...t,title:to(s,0)||to(t,0)||to(e,0),detail:ph(s)||ph(t)||ph(e),status:o,links:vi(e==null?void 0:e.links,t==null?void 0:t.links),artifacts:vi(e==null?void 0:e.artifacts,t==null?void 0:t.artifacts),outputs:vi(e==null?void 0:e.outputs,t==null?void 0:t.outputs),results:vi(e==null?void 0:e.results,t==null?void 0:t.results),events:vi(e==null?void 0:e.events,t==null?void 0:t.events),createdAt:(e==null?void 0:e.createdAt)||(e==null?void 0:e.created_at)||(t==null?void 0:t.createdAt)||(t==null?void 0:t.created_at),startedAt:(e==null?void 0:e.startedAt)||(e==null?void 0:e.started_at)||(t==null?void 0:t.startedAt)||(t==null?void 0:t.started_at),updatedAt:(s==null?void 0:s.updatedAt)||(s==null?void 0:s.updated_at)||(t==null?void 0:t.updatedAt)||(t==null?void 0:t.updated_at)||(e==null?void 0:e.updatedAt)||(e==null?void 0:e.updated_at)}}function lG(e,t){const n=[],r=new Map,s=new Map,o=new Map,a=f=>{var p,h;return!!(!f||typeof f!="object"||f.auxiliary===!0||f.auxiliary_event===!0||String(f.type||"")==="review-link"||String(f.type||"")==="action-preview"||f.preview===!0||String(f.type||"")==="same-platform-stage-conflict"&&/\/api\/prd-workflow\/review\//.test(String(((p=f.conflict)==null?void 0:p.previousArtifact)||((h=f.conflict)==null?void 0:h.incomingArtifact)||"")))},l=(f,p)=>({...f,links:vi(f==null?void 0:f.links,p==null?void 0:p.links),artifacts:vi(f==null?void 0:f.artifacts,p==null?void 0:p.artifacts),outputs:vi(f==null?void 0:f.outputs,p==null?void 0:p.outputs),results:vi(f==null?void 0:f.results,p==null?void 0:p.results)}),c=(f,p)=>{if(!f)return;const h=r.get(f);if(h!=null){n[h]=l(n[h],p);return}o.set(f,l(o.get(f)||{},p))},u=(f,p)=>f&&o.has(f)?l(p,o.get(f)):p,d=f=>{if(Array.isArray(f))for(const p of f){const h=el(p);if(a(p)){c(h,p);continue}const y=String(p.id||p.eventId||p.event_id||p.actionId||p.action_id||"").trim(),k=h||y,b=k?r.get(k)??s.get(y):null;k&&b!=null?(n[b]=u(h,NC(n[b],p)),h&&r.set(h,b),y&&s.set(y,b)):(k&&r.set(k,n.length),y&&s.set(y,n.length),n.push(u(h,p)))}};if(d(e==null?void 0:e.actions),d(e==null?void 0:e.workflowActions),d(e==null?void 0:e.workflow_actions),d(e==null?void 0:e.timeline),d(e==null?void 0:e.history),d(e==null?void 0:e.events),d(e==null?void 0:e.runtimeEvents),d(e==null?void 0:e.runtime_events),t&&typeof t=="object"){const f=Yd(t),p=el(t),h=p?r.get(p):f?s.get(f):null,y={...t,status:t.status||"next",kind:"next_action"};h!=null&&(n[h]=NC(n[h],y))}return n.map((f,p)=>({item:f,index:p,ts:dm(f)})).filter(f=>Number.isFinite(f.ts)).sort((f,p)=>p.ts-f.ts||f.index-p.index).map(f=>aG(e,f.item))}function cG(e){return(Array.isArray(e==null?void 0:e.runtimeEvents)?e.runtimeEvents:Array.isArray(e==null?void 0:e.runtime_events)?e.runtime_events:[]).filter(n=>n&&typeof n=="object").map((n,r)=>({item:n,index:r,ts:dm(n)})).sort((n,r)=>{const s=Number.isFinite(n.ts),o=Number.isFinite(r.ts);return s&&o?r.ts-n.ts||r.index-n.index:s?-1:o?1:r.index-n.index}).slice(0,8).map(n=>n.item)}function uG(e,t){const n=String(t||"all");if(n==="all")return!0;const r=[e==null?void 0:e.status,e==null?void 0:e.type,e==null?void 0:e.kind,e==null?void 0:e.title,e==null?void 0:e.detail,e==null?void 0:e.error,JSON.stringify((e==null?void 0:e.links)||[]),JSON.stringify((e==null?void 0:e.artifacts)||[])].join(" ").toLowerCase();return n==="errors"?/error|failed|conflict|blocked|stale|revision|冲突|失败/.test(r):n==="review"?/review|temporary-review|临时/.test(r):n==="external"?/mr|merge request|gitlab|jenkins|package|build|tapd/.test(r):!0}function dG(e,t){const n=typeof e=="string"?e:String((e==null?void 0:e.text)||""),r=typeof e=="object"?Number(e==null?void 0:e.stepMs):NaN,s=typeof e=="object"?Number(e==null?void 0:e.totalMs):NaN,o=Number.isFinite(r)&&Number.isFinite(s)?`(+${Ea(r)} / 总 ${Ea(s)})`:"";return`${t+1}. ${n}${o}`}function FT(e){if(String((e==null?void 0:e.type)||"")!=="raw")return null;const t=String((e==null?void 0:e.text)||"").trim();if(!t)return null;try{return JSON.parse(t)}catch{return null}}function Dl(...e){for(const t of e){const n=Number(t);if(Number.isFinite(n))return n}return NaN}function fG(e){const t=e!=null&&e.tool_call&&typeof e.tool_call=="object"?e.tool_call:{},n=Object.keys(t).find(r=>/ToolCall$/i.test(r))||"";return n||String((e==null?void 0:e.name)||(e==null?void 0:e.tool)||"tool_call")}function pG(e){const t=e!=null&&e.tool_call&&typeof e.tool_call=="object"?e.tool_call:{},n=Object.keys(t).find(r=>/ToolCall$/i.test(r))||"";return n&&t[n]&&typeof t[n]=="object"?t[n]:{}}function hG(e,t){var s;const n=String(((s=t==null?void 0:t.args)==null?void 0:s.command)||"");return/ck_fetch\.py/.test(n)?"CK 查询":/collect_important_mails\.py|list_mails_by_date\.py|read_mail_content\.py/.test(n)?"邮件脚本":/npm\s+run\s+build|build:web-ui/.test(n)?"前端构建":/python3/.test(n)?"Python 脚本":{shellToolCall:"Shell 命令",readToolCall:"读取文件/上下文",grepToolCall:"搜索代码",globToolCall:"查找文件",editToolCall:"编辑文件",writeToolCall:"写入文件"}[e]||e||"工具调用"}function mG(e){var o,a,l;const t=FT(e);if(!t||typeof t!="object")return null;const n=String(t.type||""),r=String(t.subtype||""),s=Dl(t.timestamp_ms,t.completedAtMs,t.startedAtMs,e==null?void 0:e.ts,Date.now());if(n==="tool_call"&&r==="completed"){const c=pG(t),u=fG(t),d=Dl(t.startedAtMs,c==null?void 0:c.startedAtMs),f=Dl(t.completedAtMs,c==null?void 0:c.completedAtMs),p=((o=c==null?void 0:c.result)==null?void 0:o.success)||((a=c==null?void 0:c.result)==null?void 0:a.failure)||{},h=Number.isFinite(d)&&Number.isFinite(f)?Math.max(0,f-d):Dl(p.executionTime,p.localExecutionTimeMs),y=String(((l=c==null?void 0:c.args)==null?void 0:l.command)||p.command||"").trim(),k=y?y.split(`
@@ -242,13 +242,13 @@ ${t.documentElement.outerHTML}`:""}function cw(e){var n;if(!e)return null;const
242
242
  `)?`
243
243
  `:"",z=P&&!P.startsWith(`
244
244
  `)?`
245
- `:"",$=`${C}${I}${g}${z}${P}`;t==null||t($),window.requestAnimationFrame(()=>{var F,O;const L=C.length+I.length+g.length;(F=s.current)==null||F.focus(),(O=s.current)==null||O.setSelectionRange(L,L)})},[t,e]),b=m.useCallback(async g=>{if(!r&&!(!g||l)){c(!0);try{const v=await(n==null?void 0:n(g)),w=String(v||"").trim();if(w){const N=String(g.name||"image").replace(/\.[^.]+$/g,"").trim()||"image";k(`![${N}](${w})`)}}finally{c(!1)}}},[k,n,r,l]);return i.jsxs("div",{className:"af-work-display-editor nodrag nopan",onClick:g=>g.stopPropagation(),onDragOver:g=>{var w;Array.from(((w=g.dataTransfer)==null?void 0:w.items)||[]).some(N=>String((N==null?void 0:N.type)||"").startsWith("image/"))&&(g.preventDefault(),g.dataTransfer.dropEffect="copy")},onDrop:g=>{var w;const v=Array.from(((w=g.dataTransfer)==null?void 0:w.files)||[]).find(cm);v&&(g.preventDefault(),b(v))},children:[i.jsxs("div",{className:"af-work-display-editor__toolbar",children:[i.jsx("button",{type:"button",className:"af-work-display-card__action",disabled:l||r,onClick:()=>{var g;return(g=o.current)==null?void 0:g.click()},"aria-label":"上传图片",title:"上传图片",children:i.jsx("span",{className:"material-symbols-outlined",children:l?"hourglass_top":"add_photo_alternate"})}),i.jsx("input",{ref:o,className:"af-hidden-file-input",type:"file",accept:"image/*",onChange:g=>{var w;const v=(w=g.target.files)==null?void 0:w[0];g.target.value="",v&&b(v)}})]}),i.jsx("textarea",{ref:s,className:"af-work-display-editor__textarea",value:e,onChange:g=>t==null?void 0:t(g.target.value),onScroll:f,onKeyDown:g=>{g.key==="Escape"&&g.stopPropagation()},placeholder:"输入 Markdown 内容",spellCheck:!1,readOnly:r}),i.jsx("div",{ref:a,className:"af-work-display-editor__scrollbar"+(u.visible?" af-work-display-editor__scrollbar--visible":""),onPointerDown:y,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${u.height}%`,top:`${u.top}%`}})})]})}function eJ({nodeId:e,data:t}){const n=t==null?void 0:t.nodeChatActive,r=!!(t!=null&&t.selected),s=(t==null?void 0:t.nodeChat)||{},o=Array.isArray(s.messages)?s.messages:[],a=String(s.draft||""),[l,c]=m.useState(a),u=m.useRef(!1),d=String(s.candidateContent||""),f=!!s.running,p=!!(t!=null&&t.readOnly),h=String(s.error||""),y=o.slice(-2);return m.useEffect(()=>{u.current||c(a)},[a]),!n&&!r?null:n?i.jsxs("div",{className:"af-work-node-chat nodrag nopan",onClick:k=>k.stopPropagation(),children:[i.jsxs("div",{className:"af-work-node-chat__head",children:[i.jsxs("div",{children:[i.jsx("strong",{children:"继续微调"}),i.jsx("span",{children:(t==null?void 0:t.label)||e})]}),i.jsx("button",{type:"button",onClick:()=>{var k;return(k=t==null?void 0:t.onCloseNodeChat)==null?void 0:k.call(t)},"aria-label":"关闭节点微调",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),o.length>0||f||h?i.jsxs("div",{className:"af-work-node-chat__messages",children:[y.map((k,b)=>i.jsxs("div",{className:`af-work-node-chat__msg af-work-node-chat__msg--${k.role==="assistant"?"assistant":"user"}`,children:[i.jsx("span",{children:k.role==="assistant"?"AI":"你"}),i.jsx("p",{children:k.text})]},`${k.at||b}-${b}`)),f?i.jsx("div",{className:"af-work-node-chat__pending",children:"生成中..."}):null,h?i.jsx("div",{className:"af-work-node-chat__error",children:h}):null]}):null,i.jsxs("div",{className:"af-work-node-chat__composer",children:[i.jsx("button",{type:"button",className:"af-work-node-chat__add",disabled:f||p,"aria-label":"添加上下文",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"})}),i.jsx("textarea",{className:"af-work-node-chat__input",rows:2,value:l,disabled:f||p,placeholder:"描述你想怎么调整这个展示",onCompositionStart:()=>{u.current=!0},onCompositionEnd:k=>{var g;u.current=!1;const b=k.currentTarget.value;c(b),(g=t==null?void 0:t.onUpdateNodeChatDraft)==null||g.call(t,e,b)},onChange:k=>{var g;const b=k.target.value;c(b),u.current||(g=t==null?void 0:t.onUpdateNodeChatDraft)==null||g.call(t,e,b)},onKeyDown:k=>{var b,g;k.isComposing||(b=k.nativeEvent)!=null&&b.isComposing||k.keyCode===229||(k.metaKey||k.ctrlKey)&&k.key==="Enter"&&(k.preventDefault(),(g=t==null?void 0:t.onSendNodeChat)==null||g.call(t,e,l))}}),i.jsx("button",{type:"button",className:"af-work-node-chat__send",disabled:f||p||!l.trim(),onClick:()=>{var k;return(k=t==null?void 0:t.onSendNodeChat)==null?void 0:k.call(t,e,l)},"aria-label":"发送",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"arrow_upward"})})]}),d.trim()?i.jsx("div",{className:"af-work-node-chat__messages",children:i.jsxs("div",{className:"af-work-node-chat__msg af-work-node-chat__msg--assistant",children:[i.jsx("span",{children:"AI"}),i.jsx("p",{children:d})]})}):null]}):i.jsxs("button",{type:"button",className:"af-work-node-chat-anchor nodrag nopan",onClick:k=>{var b;k.stopPropagation(),(b=t==null?void 0:t.onToggleNodeChat)==null||b.call(t,e)},title:"微调这个节点","aria-label":"微调这个节点",children:[i.jsx("span",{className:"material-symbols-outlined af-work-node-chat-anchor__plus","aria-hidden":!0,children:"add"}),i.jsx("span",{className:"af-work-node-chat-anchor__label",children:"继续微调这个展示"}),i.jsx("span",{className:"material-symbols-outlined af-work-node-chat-anchor__expand","aria-hidden":!0,children:"open_in_full"})]})}function tJ(e){return e==="mermaid"?"mmd":e==="ascii"?"txt":e==="html"?"html":e==="react"?"json":e==="image"?"txt":e==="chart"||e==="table"?"json":"md"}function nJ(e){return String(e).trim().toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)||"display"}function rJ(e){return String(e||"node").trim().replace(/[^a-zA-Z0-9._-]+/g,"_").replace(/^_+|_+$/g,"").slice(0,120)||"node"}function DC(e,t=""){const n=ea(e,t).replace(/^\/+/,"");return n.startsWith("outputs/")?n:""}function sJ(e,t){const n=rJ(e),r=new Set,s=In(t)||"";ei(t==null?void 0:t.definitionId)&&r.add(`outputs/${n}`);const o=DC(no(t),s);return o&&r.add(o),(Array.isArray(t==null?void 0:t.outputs)?t.outputs:[]).some(c=>{const u=String((c==null?void 0:c.value)??(c==null?void 0:c.default)??"").trim().replace(/^\/+/,""),d=DC(u,s);return d&&r.add(d),u===`outputs/${n}`||u.startsWith(`outputs/${n}/`)})&&r.add(`outputs/${n}`),Array.from(r)}function FC(e,t){const n=In(t)||"markdown";return`outputs/${nJ((t==null?void 0:t.label)||e||n)}.${tJ(n)}`}async function eM({nodeId:e,data:t,filePath:n,content:r,setFileContent:s}){var o,a;if(n){const l=await hb((t==null?void 0:t.flowParams)||{},n,r);s==null||s(r),(o=t==null?void 0:t.onSetDisplayNodeContent)==null||o.call(t,e,l,"replace",{logChat:!1,reloadDisplay:!0,statusMessage:`已更新 ${l}`});return}(a=t==null?void 0:t.onSetDisplayNodeContent)==null||a.call(t,e,r,"replace",{logChat:!1,statusMessage:"已更新 Markdown 内容"})}function tM({id:e,data:t,selected:n,deleteNode:r}){var ee,te,ne;const s=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],a=(Array.isArray(t==null?void 0:t.outputs)?t.outputs:[]).map((Z,ce)=>({slot:Z,idx:ce})).sort((Z,ce)=>{var _e,Be,ot,yt;const de=String(((_e=Z.slot)==null?void 0:_e.name)||"").trim(),me=String(((Be=ce.slot)==null?void 0:Be.name)||"").trim();if(de==="next"&&me!=="next")return-1;if(me==="next"&&de!=="next")return 1;const $e=String(((ot=Z.slot)==null?void 0:ot.type)||"").trim(),Ce=String(((yt=ce.slot)==null?void 0:yt.type)||"").trim();return $e==="node"&&Ce!=="node"?-1:Ce==="node"&&$e!=="node"?1:Z.idx-ce.idx}),l=In(t),c=m.useRef(null),u=m.useRef(null),[d,f]=m.useState(0),[p,h]=m.useState(!1),[y,k]=m.useState(!1),[b,g]=m.useState(!1),[v,w]=m.useState(""),[N,j]=m.useState(""),[C,P]=m.useState(!1),[I,z]=m.useState(!1),$=m.useRef(null),L=no(t),F=l==="markdown"?Ei(L):"",O=l==="markdown"?ea(F,"markdown"):"",M=l==="markdown"?O?N:F:"",K=!!(t!=null&&t.readOnly),H=!!(t!=null&&t.displayPageMode);m.useEffect(()=>{let Z=!1;return l!=="markdown"||!O?(j(""),P(!1),()=>{Z=!0}):(P(!0),nl((t==null?void 0:t.flowParams)||{},O).then(ce=>{Z||j(ce)}).catch(ce=>{var de;Z||(j(""),(de=t==null?void 0:t.onStatus)==null||de.call(t,String(ce.message||ce)))}).finally(()=>{Z||P(!1)}),()=>{Z=!0})},[l,O,(ee=t==null?void 0:t.flowParams)==null?void 0:ee.flowId,(te=t==null?void 0:t.flowParams)==null?void 0:te.flowSource,(ne=t==null?void 0:t.flowParams)==null?void 0:ne.archived,t==null?void 0:t.displayReloadKey]),m.useEffect(()=>{if(!y)return;const Z=()=>k(!1);return window.addEventListener("pointerup",Z,!0),window.addEventListener("pointercancel",Z,!0),window.addEventListener("mouseup",Z,!0),window.addEventListener("blur",Z),()=>{window.removeEventListener("pointerup",Z,!0),window.removeEventListener("pointercancel",Z,!0),window.removeEventListener("mouseup",Z,!0),window.removeEventListener("blur",Z)}},[y]),m.useEffect(()=>{b||w(String(M||""))},[M,b]);const D=(t==null?void 0:t.label)||(l==="mermaid"?"Mermaid":l==="ascii"?"ASCII":l==="html"?"HTML":l==="react"?"React App":l==="image"?"Image":l==="chart"?"Chart":l==="table"?"Table":"Markdown"),T=String((t==null?void 0:t.sourceNodeId)||e),W=(t==null?void 0:t.sharingDisplayNodeId)===T,E=t!=null&&t.displaySize&&Number(t.displaySize.width)>0&&Number(t.displaySize.height)>0?{width:Number(t.displaySize.width),height:Number(t.displaySize.height)}:null,Q=m.useCallback(async()=>{var Te,st,gt,xe,Fe,lt,oe,ke,Ke,Ue;if(l!=="html"||p)return;const Z=no(t),ce=ea(Z,l);let de=Z;if(ce)try{de=await nl((t==null?void 0:t.flowParams)||{},ce)}catch(be){h(!1),console.warn("Failed to read HTML display file before saving image.",be);return}const me=Hc(de);if(!me.trim())return;const $e=Ma(l,me);if($e){console.warn($e);return}const Ce=(st=(Te=u.current)==null?void 0:Te.getBoundingClientRect)==null?void 0:st.call(Te),_e=(xe=(gt=c.current)==null?void 0:gt.querySelector)==null?void 0:xe.call(gt,".af-work-display-body"),Be=(lt=(Fe=c.current)==null?void 0:Fe.querySelector)==null?void 0:lt.call(Fe,".af-visible-scroll-frame__scroller"),ot=Math.round(Math.max(Number((Ce==null?void 0:Ce.width)||0),Number((E==null?void 0:E.width)||0),Number(((oe=c.current)==null?void 0:oe.clientWidth)||0),Number((_e==null?void 0:_e.clientWidth)||0),Number((Be==null?void 0:Be.clientWidth)||0),Math.max(320,Number((E==null?void 0:E.width)||960)-2))),yt=Math.round(Math.max(Number((Ce==null?void 0:Ce.height)||0),Number((E==null?void 0:E.height)||0),Number(((ke=c.current)==null?void 0:ke.clientHeight)||0),Number((_e==null?void 0:_e.clientHeight)||0),Number((Be==null?void 0:Be.clientHeight)||0),Math.max(180,Number((E==null?void 0:E.height)||640)-46)));h(!0);try{await GG({flowParams:(t==null?void 0:t.flowParams)||{},content:me,sourceFilePath:ce,iframe:u.current,width:ot,height:yt,filename:VG((t==null?void 0:t.label)||e||"html-render","png"),snapshotElements:{card:c.current,displayBody:_e,scroller:Be},displaySize:E}),(Ke=t==null?void 0:t.onStatus)==null||Ke.call(t,"已导出 HTML 展示截图")}catch(be){const Ht=String((be==null?void 0:be.message)||be||"截图失败");(Ue=t==null?void 0:t.onStatus)==null||Ue.call(t,`HTML 截图失败:${Ht}`),console.warn("Failed to save HTML display as PNG.",be)}finally{h(!1)}},[t,E==null?void 0:E.height,E==null?void 0:E.width,e,l,p]),V=m.useCallback(Z=>{var ce;K||!Z||l!=="image"||(ce=t==null?void 0:t.onUploadImageToDisplayNode)==null||ce.call(t,e,Z)},[t,e,l,K]),B=m.useCallback(Z=>{var ce,de;(ce=Z==null?void 0:Z.stopPropagation)==null||ce.call(Z),!K&&((de=t==null?void 0:t.onSetDisplayNodeContent)==null||de.call(t,e,"","replace",{logChat:!1,reloadDisplay:!0,statusMessage:"已清空 Display 内容"}),l==="markdown"&&(w(""),g(!1)))},[t,e,l,K]),se=m.useCallback(Z=>{var me,$e;K||l!=="image"||!(Array.from(((me=Z.dataTransfer)==null?void 0:me.files)||[]).some(cm)||Array.from((($e=Z.dataTransfer)==null?void 0:$e.items)||[]).some(Ce=>String((Ce==null?void 0:Ce.type)||"").startsWith("image/")))||(Z.preventDefault(),Z.stopPropagation(),Z.dataTransfer.dropEffect="copy",z(!0))},[l,K]),ue=m.useCallback(Z=>{l==="image"&&(Z.currentTarget.contains(Z.relatedTarget)||z(!1))},[l]),G=m.useCallback(Z=>{var de;if(l!=="image")return;const ce=Array.from(((de=Z.dataTransfer)==null?void 0:de.files)||[]).find(cm);ce&&(Z.preventDefault(),Z.stopPropagation(),z(!1),V(ce))},[l,V]);return i.jsxs("div",{className:"af-work-display-card"+(E?" af-work-display-card--sized":"")+(n?" af-work-display-card--selected":"")+(y?" af-work-display-card--resizing":"")+(I?" af-work-display-card--image-drop":"")+(H?" af-work-display-card--presentation":"")+(t!=null&&t.isExecuting?" af-work-display-card--executing":"")+((t==null?void 0:t.nodeStatus)==="success"?" af-work-display-card--done":"")+((t==null?void 0:t.nodeStatus)==="failed"?" af-work-display-card--failed":""),style:E?{width:E.width,height:E.height}:void 0,ref:c,onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,onDragOver:se,onDragLeave:ue,onDrop:G,children:[i.jsx(zk,{className:"af-work-display-resize nodrag",position:"bottom-right",minWidth:320,minHeight:180,onResizeStart:()=>k(!0),onResizeEnd:()=>k(!1),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_full"})}),s.map((Z,ce)=>{if(Z.showOnNode===!1)return null;const de=`${4.15+ce*1.75}rem`,me=Z.name||`#${ce+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:de},children:me}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${ce}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:de,background:Tn(Z.type)},title:`${me} · ${Z.type}`})]},`in-${ce}`)}),a.map(({slot:Z,idx:ce},de)=>{if(Z.showOnNode===!1)return null;const me=`${4.15+de*1.75}rem`,$e=Z.name||`#${ce+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:me},children:$e}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${ce}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:me,background:Tn(Z.type)},title:`${$e} · ${Z.type}`})]},`out-${ce}`)}),i.jsxs("div",{className:"af-work-display-card__head",children:[i.jsxs("div",{className:"af-work-display-card__title",children:[i.jsx("span",{className:"material-symbols-outlined",children:JT(l)}),i.jsx("strong",{children:D}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"display"})]}),l==="html"?i.jsxs("div",{className:"af-work-display-card__html-controls nodrag",onClick:Z=>Z.stopPropagation(),children:[i.jsx("button",{type:"button",className:"af-work-display-card__action",onClick:()=>{var Z,ce,de,me;try{(me=(de=(ce=(Z=u.current)==null?void 0:Z.contentWindow)==null?void 0:ce.history)==null?void 0:de.back)==null||me.call(de)}catch{}},"aria-label":"后退",title:"后退",children:i.jsx("span",{className:"material-symbols-outlined",children:"arrow_back"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action",onClick:()=>{var Z,ce,de,me;try{(me=(de=(ce=(Z=u.current)==null?void 0:Z.contentWindow)==null?void 0:ce.history)==null?void 0:de.forward)==null||me.call(de)}catch{}},"aria-label":"前进",title:"前进",children:i.jsx("span",{className:"material-symbols-outlined",children:"arrow_forward"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action",onClick:()=>f(Z=>Z+1),"aria-label":"刷新",title:"刷新",children:i.jsx("span",{className:"material-symbols-outlined",children:"refresh"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action",disabled:p,onClick:Q,"aria-label":"截图另存为图片",title:"截图另存为图片",children:i.jsx("span",{className:"material-symbols-outlined",children:p?"hourglass_empty":"photo_camera"})})]}):null,l==="markdown"?b?i.jsxs("div",{className:"af-work-display-card__html-controls nodrag",onClick:Z=>Z.stopPropagation(),children:[i.jsx("button",{type:"button",className:"af-work-display-card__action",disabled:K||C,onClick:async()=>{var Z;try{await eM({nodeId:e,data:t,filePath:O,content:v,setFileContent:j}),g(!1)}catch(ce){(Z=t==null?void 0:t.onStatus)==null||Z.call(t,String(ce.message||ce))}},"aria-label":"保存并预览",title:"保存并预览",children:i.jsx("span",{className:"material-symbols-outlined",children:"done"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action",onClick:()=>{w(String(M||"")),g(!1)},"aria-label":"取消编辑",title:"取消编辑",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}):i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:K||C,onClick:Z=>{Z.stopPropagation(),w(String(M||"")),g(!0)},"aria-label":"编辑 Markdown",title:"编辑 Markdown",children:i.jsx("span",{className:"material-symbols-outlined",children:"edit"})}):null,l==="image"?i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:$,className:"af-hidden-file-input",type:"file",accept:"image/*",onChange:Z=>{var de;const ce=(de=Z.target.files)==null?void 0:de[0];Z.target.value="",ce&&V(ce)}}),i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:K,onClick:Z=>{var ce;Z.stopPropagation(),(ce=$.current)==null||ce.click()},"aria-label":"上传图片",title:"上传图片",children:i.jsx("span",{className:"material-symbols-outlined",children:"upload"})})]}):null,i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",onClick:Z=>{var ce;Z.stopPropagation(),(ce=t==null?void 0:t.onOpenDisplayPreview)==null||ce.call(t,T)},"aria-label":"全屏预览",title:"全屏预览",children:i.jsx("span",{className:"material-symbols-outlined",children:"fullscreen"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:W,onClick:Z=>{var ce;Z.stopPropagation(),(ce=t==null?void 0:t.onShareDisplayNode)==null||ce.call(t,T)},"aria-label":"分享展示",title:"分享展示",children:i.jsx("span",{className:"material-symbols-outlined",children:W?"hourglass_empty":"ios_share"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:K,onClick:B,"aria-label":"清空内容",title:"清空内容",children:i.jsx("span",{className:"material-symbols-outlined",children:"delete_sweep"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:K,onClick:()=>{var Z;return(Z=t==null?void 0:t.onSaveDisplayNodeToFile)==null?void 0:Z.call(t,e,t)},"aria-label":"另存为文件",title:"另存为文件",children:i.jsx("span",{className:"material-symbols-outlined",children:"save"})}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",disabled:K,onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),l==="markdown"&&b?i.jsx(ZT,{value:v,onChange:w,onUploadImage:t==null?void 0:t.onUploadWorkspaceImage,readOnly:K}):i.jsx(QT,{data:t,flowParams:t==null?void 0:t.flowParams,htmlFrameRef:u,htmlFrameVersion:d}),i.jsx(eJ,{nodeId:e,data:t})]})}function iJ({id:e,data:t,selected:n,deleteNode:r}){var d,f,p;const s=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],o=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],a=((f=(d=t==null?void 0:t.runningRunNodeIds)==null?void 0:d.has)==null?void 0:f.call(d,e))||((p=t==null?void 0:t.runningRunNodeIds)==null?void 0:p[e])===!0||(t==null?void 0:t.isExecuting)||(t==null?void 0:t.nodeStatus)==="running",l=(t==null?void 0:t.optimizingRun)===!0,c=(t==null?void 0:t.nodeStatus)==="stopped",u=!!(t!=null&&t.readOnly);return i.jsxs("div",{className:"af-work-run-card"+(n?" af-work-run-card--selected":"")+(a?" af-work-run-card--running":"")+(t!=null&&t.isExecuting?" af-work-run-card--executing":"")+((t==null?void 0:t.nodeStatus)==="success"?" af-work-run-card--done":"")+((t==null?void 0:t.nodeStatus)==="failed"?" af-work-run-card--failed":"")+(c?" af-work-run-card--stopped":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[s.map((h,y)=>{if(h.showOnNode===!1)return null;const k=`${2.25+y*1.75}rem`,b=h.name||`#${y+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:k},children:b}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${y}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:k,background:Tn(h.type)},title:`${b} · ${h.type}`})]},`in-${y}`)}),o.map((h,y)=>{if(h.showOnNode===!1)return null;const k=`${2.25+y*1.75}rem`,b=h.name||`#${y+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:k},children:b}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${y}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:k,background:Tn(h.type)},title:`${b} · ${h.type}`})]},`out-${y}`)}),i.jsxs("div",{className:"af-work-run-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"play_circle"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"Run"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"workspace_run"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",disabled:u,onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-run-card__actions",children:[i.jsxs("button",{type:"button",className:"af-work-run-card__button nodrag"+(a?" af-work-run-card__button--stop":""),disabled:u||l,onClick:h=>{var y,k;h.stopPropagation(),a?(y=t==null?void 0:t.onStopWorkspaceNode)==null||y.call(t,e):(k=t==null?void 0:t.onRunWorkspaceNode)==null||k.call(t,e)},children:[i.jsx("span",{className:"material-symbols-outlined",children:a?"stop_circle":"play_arrow"}),i.jsx("span",{children:a?"Stop":"Run line"})]}),i.jsx("button",{type:"button",className:"af-work-run-card__button af-work-run-card__optimize nodrag"+(l?" af-work-run-card__optimize--running":""),disabled:u||a||l,title:l?"正在优化":"为下游节点提前生成 implementation","aria-label":l?"正在优化":"优化",onClick:h=>{var y;h.stopPropagation(),(y=t==null?void 0:t.onOptimizeWorkspaceRun)==null||y.call(t,e)},children:i.jsx("span",{className:"material-symbols-outlined",children:l?"sync":"auto_fix_high"})}),i.jsx("button",{type:"button",className:"af-work-run-card__button af-work-run-card__logs nodrag",title:"查看执行日志","aria-label":"查看执行日志",onClick:h=>{var y;h.stopPropagation(),(y=t==null?void 0:t.onOpenWorkspaceRunLogs)==null||y.call(t,{nodeId:e,runNodeId:e,scheduleNodeId:"",label:(t==null?void 0:t.label)||"Run"})},children:i.jsx("span",{className:"material-symbols-outlined",children:"article"})})]})]})}function oJ({id:e,data:t,selected:n,deleteNode:r,skills:s,skillCollections:o,workspaces:a}){var Ue,be,Ht,Qt,jt,yn,on;const l=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],c=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],u=vJ(t),[d,f]=m.useState(u.task),p=m.useRef(!1),h=m.useRef(u.task),y=((be=(Ue=t==null?void 0:t.runningRunNodeIds)==null?void 0:Ue.has)==null?void 0:be.call(Ue,e))||((Ht=t==null?void 0:t.runningRunNodeIds)==null?void 0:Ht[e])===!0||(t==null?void 0:t.isExecuting)||(t==null?void 0:t.nodeStatus)==="running",k=(t==null?void 0:t.nodeStatus)==="stopped",b=!!(t!=null&&t.readOnly),g=Array.isArray(s)?s:[],v=Array.isArray(o)?o:[],w=m.useMemo(()=>(Array.isArray(a)?a:[]).map(re=>({id:String((re==null?void 0:re.id)||""),label:String((re==null?void 0:re.label)||(re==null?void 0:re.name)||"知识库"),kind:(re==null?void 0:re.kind)==="git"?"git":"local",path:String((re==null?void 0:re.path)||""),repoUrl:String((re==null?void 0:re.repoUrl)||""),branch:String((re==null?void 0:re.branch)||""),mountPath:String((re==null?void 0:re.mountPath)||""),builtin:(re==null?void 0:re.builtin)===!0,exists:(re==null?void 0:re.exists)!==!1,type:String((re==null?void 0:re.type)||"")})).filter(re=>re.path),[a]),[N,j]=m.useState(!1),[C,P]=m.useState(""),[I,z]=m.useState(()=>new Set),[$,L]=m.useState(!1),[F,O]=m.useState(""),[M,K]=m.useState("config"),H=lg(t),D=!!H,T=lM(u.displayType),W=m.useMemo(()=>zG(t,T),[t==null?void 0:t.displaySize,t==null?void 0:t.nodeSize,t==null?void 0:t.inputs,t==null?void 0:t.input,T]),E=m.useMemo(()=>({...t,sourceNodeId:e,label:t!=null&&t.label&&t.label!=="Context Run"?t.label:"一键任务",definitionId:T,displaySize:W,nodeSize:W,body:H,inputs:[{type:"text",name:T==="display_image"?"src":"content",value:H,default:H}],outputs:c.length?c:[{type:"node",name:"next",default:""}]}),[t,T,e,H,c,W]),Q=Array.isArray((Qt=t==null?void 0:t.modelLists)==null?void 0:Qt.cursor)?t.modelLists.cursor:[],V=Array.isArray((jt=t==null?void 0:t.modelLists)==null?void 0:jt.opencode)?t.modelLists.opencode:[],B=Array.isArray((yn=t==null?void 0:t.modelLists)==null?void 0:yn.claudeCode)?t.modelLists.claudeCode:[],se=Array.isArray((on=t==null?void 0:t.modelLists)==null?void 0:on.codex)?t.modelLists.codex:[],ue=m.useMemo(()=>new Set(Q.map(Ss)),[Q]),G=m.useMemo(()=>new Set(V.map(Ss)),[V]),ee=m.useMemo(()=>new Set(B.map(Ss)),[B]),te=m.useMemo(()=>new Set(se.map(Ss)),[se]),ne=u.model,Z=m.useMemo(()=>ne?ne.startsWith("cursor:")||ne.startsWith("opencode:")||ne.startsWith("codex:")||ne.startsWith("claude-code:")?ne:ee.has(ne)?`claude-code:${ne}`:te.has(ne)?`codex:${ne}`:G.has(ne)?`opencode:${ne}`:ue.has(ne)?`cursor:${ne}`:ne:"",[ee,te,ue,G,ne]),ce=ne.startsWith("cursor:")?ne.slice(7):ne.startsWith("opencode:")?ne.slice(9):ne.startsWith("codex:")?ne.slice(6):ne.startsWith("claude-code:")?ne.slice(12):ne,de=ce,me=!!ne&&!ue.has(de)&&!G.has(de)&&!ee.has(de)&&!te.has(de),$e=m.useMemo(()=>new Set(u.skillKeys),[u.skillKeys]),Ce=m.useMemo(()=>new Map(g.map(re=>[re.key,re])),[g]),_e=m.useMemo(()=>{const re=new Set,Re=v.map(Ze=>{const Tt=Qo(Ze,g).map(At=>Ce.get(At)).filter(Boolean);for(const At of Tt)re.add(At.key);return{...Ze,skills:Tt}}).filter(Ze=>Ze.skills.length>0),Je=g.filter(Ze=>!re.has(Ze.key));return{collectionGroups:Re,ungrouped:Je}},[v,Ce,g]);m.useEffect(()=>{z(re=>{let Re=!1;const Je=new Set(re);for(const Ze of _e.collectionGroups)Je.has(Ze.id)||(Je.add(Ze.id),Re=!0);return Re?Je:re})},[_e.collectionGroups]);const Be=m.useMemo(()=>{const re=C.trim().toLowerCase();if(!re)return _e;const Re=Ze=>[Ze==null?void 0:Ze.key,Ze==null?void 0:Ze.name,Ze==null?void 0:Ze.description].map(Tt=>String(Tt||"").toLowerCase()).join(" ").includes(re);return{collectionGroups:_e.collectionGroups.map(Ze=>{const Tt=[Ze==null?void 0:Ze.id,Ze==null?void 0:Ze.name,Ze==null?void 0:Ze.description].map(At=>String(At||"").toLowerCase()).join(" ").includes(re);return{...Ze,skills:Tt?Ze.skills:Ze.skills.filter(Re)}}).filter(Ze=>Ze.skills.length>0),ungrouped:_e.ungrouped.filter(Re)}},[_e,C]),ot=mb(N,[Be.collectionGroups.length,Be.ungrouped.length,I.size,u.skillKeys.length,C]),yt=m.useMemo(()=>{const re=F.trim().toLowerCase();return re?w.filter(Re=>[Re.id,Re.label,Re.path,Re.repoUrl,Re.branch,Re.mountPath,Re.type].join(" ").toLowerCase().includes(re)):w},[w,F]),Te=m.useMemo(()=>fM(u.knowledgeContext),[u.knowledgeContext]),st=m.useMemo(()=>new Set(Te.map(re=>re.id||re.path||re.repoPath).filter(Boolean)),[Te]),gt=mb($,[yt.length,Te.length,F]);m.useEffect(()=>{u.task!==h.current&&(h.current=u.task,p.current||f(u.task))},[u.task]),m.useEffect(()=>{if(!D){K("config");return}y||K("result")},[D,H,y]),m.useEffect(()=>{var Re,Je;if(!(M==="result"&&D))return;(Re=t==null?void 0:t.onEnsureWorkspaceNodeDisplaySize)==null||Re.call(t,e,W),(Je=t==null?void 0:t.onRefreshNodeInternals)==null||Je.call(t,e);const re=window.setTimeout(()=>{var Ze;return(Ze=t==null?void 0:t.onRefreshNodeInternals)==null?void 0:Ze.call(t,e)},120);return()=>window.clearTimeout(re)},[t==null?void 0:t.onEnsureWorkspaceNodeDisplaySize,t==null?void 0:t.onRefreshNodeInternals,T,D,e,H,W,M]);const xe=re=>{var Re;(Re=t==null?void 0:t.onChangeContextRunConfig)==null||Re.call(t,e,{...u,task:d,...re})},Fe=(re=d)=>{var Je;const Re=String(re??"");Re!==u.task&&(h.current=Re,(Je=t==null?void 0:t.onChangeContextRunConfig)==null||Je.call(t,e,{...u,task:Re}))},lt=(re,Re)=>{const Je=new Set(u.skillKeys);for(const Ze of re){const Tt=String(Ze||"").trim();Tt&&(Re?Je.add(Tt):Je.delete(Tt))}xe({skillKeys:Array.from(Je)})},oe=re=>{z(Re=>{const Je=new Set(Re);return Je.has(re)?Je.delete(re):Je.add(re),Je})},ke=(re,Re)=>{const Je=(re==null?void 0:re.id)||(re==null?void 0:re.path)||"";if(!Je)return;const Ze=w.filter(Tt=>{const At=Tt.id||Tt.path||"";return At===Je?Re:st.has(At)});xe({knowledgeContext:cg(Ze)})},Ke=()=>{xe({knowledgeContext:null})};return M==="result"&&D?i.jsx(tM,{id:e,data:{...E,selected:t==null?void 0:t.selected,onSelectNodePointerDown:t==null?void 0:t.onSelectNodePointerDown},selected:n,deleteNode:r}):i.jsxs("div",{className:"af-work-context-run-card"+(n?" af-work-context-run-card--selected":"")+(M==="result"&&D?" af-work-context-run-card--result":"")+(y?" af-work-context-run-card--running":"")+((t==null?void 0:t.nodeStatus)==="success"?" af-work-context-run-card--done":"")+((t==null?void 0:t.nodeStatus)==="failed"?" af-work-context-run-card--failed":"")+(k?" af-work-context-run-card--stopped":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[l.map((re,Re)=>{if(re.showOnNode===!1)return null;const Je=`${2.25+Re*1.75}rem`,Ze=re.name||`#${Re+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:Je},children:Ze}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${Re}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:Je,background:Tn(re.type)},title:`${Ze} · ${re.type}`})]},`in-${Re}`)}),c.map((re,Re)=>{if(re.showOnNode===!1)return null;const Je=`${2.25+Re*1.75}rem`,Ze=re.name||`#${Re+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:Je},children:Ze}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${Re}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:Je,background:Tn(re.type)},title:`${Ze} · ${re.type}`})]},`out-${Re}`)}),i.jsxs("div",{className:"af-work-context-run-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"automation"}),i.jsx("strong",{children:t!=null&&t.label&&t.label!=="Context Run"?t.label:"一键任务"}),i.jsxs("div",{className:"af-work-context-run-card__model-wrap nodrag",onPointerDown:re=>re.stopPropagation(),onMouseDown:re=>re.stopPropagation(),onClick:re=>re.stopPropagation(),children:[i.jsxs("select",{className:"af-work-context-run-card__model",value:Z,disabled:b,"aria-label":"模型",title:ce||"默认模型",onChange:re=>xe({model:re.target.value}),children:[i.jsx("option",{value:"",children:"默认"}),me?i.jsx("option",{value:ne,children:ne}):null,Q.length?i.jsx("optgroup",{label:"Cursor",children:Q.map(re=>i.jsx("option",{value:`cursor:${Ss(re)}`,children:Ss(re)},`context-cursor-${re}`))}):null,V.length?i.jsx("optgroup",{label:"OpenCode",children:V.map(re=>i.jsx("option",{value:`opencode:${Ss(re)}`,children:Ss(re)},`context-opencode-${re}`))}):null,se.length?i.jsx("optgroup",{label:"Codex",children:se.map(re=>i.jsx("option",{value:`codex:${Ss(re)}`,children:Ss(re)},`context-codex-${re}`))}):null,B.length?i.jsx("optgroup",{label:"Claude Code",children:B.map(re=>i.jsx("option",{value:`claude-code:${Ss(re)}`,children:Ss(re)},`context-claude-${re}`))}):null]}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"expand_more"})]}),i.jsx("span",{className:"af-work-context-run-card__kind",children:ei(t==null?void 0:t.definitionId)?"workspace_one_click_task":(t==null?void 0:t.definitionId)||"workspace_one_click_task"}),D?i.jsxs("div",{className:"af-work-context-run-card__view-switch nodrag",onClick:re=>re.stopPropagation(),children:[i.jsx("button",{type:"button",className:M==="config"?"is-active":"",onClick:()=>K("config"),"aria-label":"切换到任务配置",children:i.jsx("span",{className:"material-symbols-outlined",children:"tune"})}),i.jsx("button",{type:"button",className:M==="result"?"is-active":"",onClick:()=>K("result"),"aria-label":"切换到展示结果",children:i.jsx("span",{className:"material-symbols-outlined",children:"preview"})})]}):null,i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",disabled:b,onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-context-run-card__body nodrag",children:[i.jsxs(i.Fragment,{children:[i.jsx("textarea",{value:d,disabled:b,placeholder:"输入任务,例如:基于选中的知识库总结需求并生成展示页",onCompositionStart:()=>{p.current=!0},onCompositionEnd:re=>{p.current=!1,f(re.currentTarget.value),Fe(re.currentTarget.value)},onChange:re=>{f(re.target.value)},onBlur:re=>Fe(re.currentTarget.value)}),i.jsxs("div",{className:"af-work-context-run-card__grid",children:[i.jsxs("div",{className:"af-work-context-run-card__skills",children:[i.jsxs("button",{type:"button",disabled:b,className:"af-work-context-run-card__select",onClick:re=>{var Re;re.stopPropagation(),N||(Re=t==null?void 0:t.onRefreshSkills)==null||Re.call(t),j(Je=>!Je)},children:[i.jsx("span",{className:"material-symbols-outlined",children:"extension"}),i.jsx("span",{children:u.skillKeys.length?`${u.skillKeys.length} skills`:"Skills"}),i.jsx("span",{className:"material-symbols-outlined",children:"expand_more"})]}),N?i.jsxs("div",{className:"af-work-context-run-card__skills-menu",onClick:re=>re.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:C,onChange:re=>P(re.target.value),placeholder:"搜索 Skills...",spellCheck:!1,autoComplete:"off","aria-label":"搜索 Skills"}),C?i.jsx("button",{type:"button",onClick:()=>P(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{ref:ot.menuRef,className:"af-work-load-skills-menu af-work-context-run-card__menu-scroll",onScroll:ot.updateMenuScrollbar,children:[Be.collectionGroups.map(re=>{const Re=re.skills.map(At=>At.key),Je=Re.filter(At=>$e.has(At)).length,Ze=Re.length>0&&Je===Re.length,Tt=I.has(re.id);return i.jsxs("section",{className:"af-work-load-skills-menu__group"+(Tt?" af-work-load-skills-menu__group--collapsed":""),children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head",children:[i.jsx("input",{type:"checkbox",checked:Ze,disabled:b,onChange:At=>lt(Re,At.target.checked),"aria-label":`选择 ${re.name}`}),i.jsx("button",{type:"button",className:"af-work-load-skills-menu__group-toggle",onClick:()=>oe(re.id),"aria-expanded":!Tt,children:i.jsxs("span",{className:"af-work-load-skills-menu__group-main",children:[i.jsx("span",{children:re.name}),re.description?i.jsx("em",{children:re.description}):null]})}),i.jsxs("small",{children:[Je,"/",Re.length]}),i.jsx("button",{type:"button",className:"af-work-load-skills-menu__group-arrow",onClick:()=>oe(re.id),"aria-label":Tt?`展开 ${re.name}`:`收起 ${re.name}`,children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:Tt?"chevron_right":"expand_more"})})]}),Tt?null:i.jsx("div",{className:"af-work-load-skills-menu__options",children:re.skills.map(At=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:$e.has(At.key),disabled:b,onChange:Vn=>lt([At.key],Vn.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:At.name}),At.description?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:At.description}):null]})]},`${re.id}:${At.key}`))})]},re.id)}),Be.ungrouped.length>0?i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"Ungrouped"}),i.jsx("small",{children:Be.ungrouped.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:Be.ungrouped.map(re=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:$e.has(re.key),disabled:b,onChange:Re=>lt([re.key],Re.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:re.name}),re.description?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:re.description}):null]})]},`ungrouped:${re.key}`))})]}):null,Be.collectionGroups.length===0&&Be.ungrouped.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的 Skills"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:()=>xe({skillKeys:[]}),children:"清空"})]}),i.jsx("div",{ref:ot.scrollbarTrackRef,className:"af-work-load-skills-scrollbar"+(ot.scrollbar.visible?" af-work-load-skills-scrollbar--visible":""),onPointerDown:ot.handleScrollbarPointerDown,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${ot.scrollbar.height}%`,top:`${ot.scrollbar.top}%`}})})]}):null]}),i.jsxs("div",{className:"af-work-context-run-card__workspace",children:[i.jsxs("button",{type:"button",disabled:b,className:"af-work-context-run-card__select",onClick:re=>{var Re;re.stopPropagation(),$||(Re=t==null?void 0:t.onRefreshWorkspaces)==null||Re.call(t),L(Je=>!Je)},children:[i.jsx("span",{className:"material-symbols-outlined",children:Te.length?"folder_open":"folder_off"}),i.jsx("span",{children:Te.length?`${Te.length} 知识库`:"知识库"}),i.jsx("span",{className:"material-symbols-outlined",children:"expand_more"})]}),$?i.jsxs("div",{className:"af-work-context-run-card__workspace-menu",onClick:re=>re.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:F,onChange:re=>O(re.target.value),placeholder:"搜索知识库...",spellCheck:!1,autoComplete:"off","aria-label":"搜索知识库"}),F?i.jsx("button",{type:"button",onClick:()=>O(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{ref:gt.menuRef,className:"af-work-load-skills-menu af-work-context-run-card__menu-scroll",onScroll:gt.updateMenuScrollbar,children:[i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"知识库"}),i.jsx("small",{children:yt.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:yt.map(re=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:st.has(re.id||re.path),disabled:b,onChange:Re=>ke(re,Re.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:re.label}),i.jsxs("span",{className:"af-work-load-skills-menu__option-desc",children:[re.kind==="git"&&re.repoUrl?`${re.repoUrl}${re.branch?` · ${re.branch}`:""}${re.mountPath?` · ${re.mountPath}`:""}`:re.path,re.exists?"":" · 路径未就绪"]})]})]},`${re.id}:${re.path}`))})]}),yt.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的知识库"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:Ke,children:"清空知识库"})]}),i.jsx("div",{ref:gt.scrollbarTrackRef,className:"af-work-load-skills-scrollbar"+(gt.scrollbar.visible?" af-work-load-skills-scrollbar--visible":""),onPointerDown:gt.handleScrollbarPointerDown,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${gt.scrollbar.height}%`,top:`${gt.scrollbar.top}%`}})})]}):null]}),i.jsxs("select",{value:u.displayType,disabled:b,onChange:re=>xe({displayType:re.target.value}),children:[i.jsx("option",{value:"markdown",children:"Markdown"}),i.jsx("option",{value:"html",children:"HTML"}),i.jsx("option",{value:"react",children:"React"}),i.jsx("option",{value:"table",children:"Table"}),i.jsx("option",{value:"chart",children:"Chart"}),i.jsx("option",{value:"ascii",children:"ASCII"}),i.jsx("option",{value:"mermaid",children:"Mermaid"})]})]}),H?i.jsx("pre",{className:"af-work-context-run-card__preview",children:H.slice(0,520)}):null]}),i.jsxs("div",{className:"af-work-context-run-card__actions",children:[i.jsxs("button",{type:"button",className:"af-work-run-card__button af-work-context-run-card__run nodrag"+(y?" af-work-run-card__button--stop":""),disabled:b,onClick:re=>{var Re,Je;re.stopPropagation(),Fe(),y?(Re=t==null?void 0:t.onStopWorkspaceNode)==null||Re.call(t,e):(Je=t==null?void 0:t.onRunWorkspaceNode)==null||Je.call(t,e)},children:[i.jsx("span",{className:"material-symbols-outlined",children:y?"stop_circle":"play_arrow"}),i.jsx("span",{children:y?"Stop":"Run"})]}),i.jsx("button",{type:"button",className:"af-work-run-card__button af-work-context-run-card__logs nodrag",onClick:re=>{var Re;re.stopPropagation(),(Re=t==null?void 0:t.onOpenWorkspaceRunLogs)==null||Re.call(t,{nodeId:e,runNodeId:e,scheduleNodeId:"",label:t!=null&&t.label&&t.label!=="Context Run"?t.label:"一键任务"})},children:i.jsx("span",{className:"material-symbols-outlined",children:"article"})})]})]})]})}function aJ({id:e,data:t,selected:n,deleteNode:r}){var P,I,z;const s=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],o=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],a=gv((t==null?void 0:t.body)||""),[l,c]=m.useState(a.cron),u=(t==null?void 0:t.scheduledRunState)||{},d=((I=(P=t==null?void 0:t.runningRunNodeIds)==null?void 0:P.has)==null?void 0:I.call(P,e))||((z=t==null?void 0:t.runningRunNodeIds)==null?void 0:z[e])===!0||(t==null?void 0:t.isExecuting)||(t==null?void 0:t.nodeStatus)==="running",f=(t==null?void 0:t.optimizingRun)===!0,p=(t==null?void 0:t.nodeStatus)==="stopped",h=!!(t!=null&&t.readOnly),y=$=>{var L;(L=t==null?void 0:t.onChangeScheduledRunConfig)==null||L.call(t,e,{...a,...$})},k=$=>{y({scheduleType:$,cron:Ku($,a.time,a.weekday,a.monthDay,a.cron)})},b=$=>{y({time:$,cron:Ku(a.scheduleType,$,a.weekday,a.monthDay,a.cron)})},[g,v]=mv(a.time).split(":"),w=($,L)=>{b(`${Do($,9,0,23)}:${Do(L,0,0,59)}`)},N=$=>{y({weekday:$,cron:Ku(a.scheduleType,a.time,$,a.monthDay,a.cron)})},j=$=>{y({monthDay:$,cron:Ku(a.scheduleType,a.time,a.weekday,$,a.cron)})};m.useEffect(()=>{c(a.cron)},[a.cron,e]);const C=()=>{h||l===a.cron||y({cron:l})};return i.jsxs("div",{className:"af-work-run-card af-work-schedule-card"+(n?" af-work-run-card--selected":"")+(a.enabled?" af-work-schedule-card--enabled":"")+(d?" af-work-run-card--running":"")+(t!=null&&t.isExecuting?" af-work-run-card--executing":"")+((t==null?void 0:t.nodeStatus)==="success"?" af-work-run-card--done":"")+((t==null?void 0:t.nodeStatus)==="failed"?" af-work-run-card--failed":"")+(p?" af-work-run-card--stopped":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[s.map(($,L)=>{if($.showOnNode===!1)return null;const F=`${2.25+L*1.75}rem`,O=$.name||`#${L+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:F},children:O}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${L}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:F,background:Tn($.type)},title:`${O} · ${$.type}`})]},`in-${L}`)}),o.map(($,L)=>{if($.showOnNode===!1)return null;const F=`${2.25+L*1.75}rem`,O=$.name||`#${L+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:F},children:O}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${L}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:F,background:Tn($.type)},title:`${O} · ${$.type}`})]},`out-${L}`)}),i.jsxs("div",{className:"af-work-run-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"event_repeat"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"Scheduled Run"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"workspace_scheduled_run"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",disabled:h,onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-schedule-card__body nodrag",children:[i.jsxs("label",{className:"af-work-schedule-card__toggle",children:[i.jsx("input",{type:"checkbox",checked:a.enabled,disabled:h,onChange:$=>y({enabled:$.target.checked})}),i.jsx("span",{children:a.enabled?"定时开启":"定时关闭"})]}),i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"频率"}),i.jsxs("select",{value:a.scheduleType,disabled:h,onChange:$=>k($.target.value),children:[i.jsx("option",{value:"daily",children:"每天"}),i.jsx("option",{value:"weekly",children:"每周"}),i.jsx("option",{value:"monthly",children:"每月"}),i.jsx("option",{value:"custom",children:"高级 Cron"})]})]}),a.scheduleType!=="custom"?i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"时间"}),i.jsxs("div",{className:"af-work-schedule-time-selects",children:[i.jsx("select",{value:g,disabled:h,"aria-label":"小时",onChange:$=>w($.target.value,v),children:Array.from({length:24},($,L)=>Do(L,0,0,23)).map($=>i.jsxs("option",{value:$,children:[$," 时"]},$))}),i.jsx("select",{value:v,disabled:h,"aria-label":"分钟",onChange:$=>w(g,$.target.value),children:Array.from({length:12},($,L)=>Do(L*5,0,0,59)).map($=>i.jsxs("option",{value:$,children:[$," 分"]},$))})]})]}):null,a.scheduleType==="weekly"?i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"星期"}),i.jsxs("select",{value:a.weekday,disabled:h,onChange:$=>N($.target.value),children:[i.jsx("option",{value:1,children:"周一"}),i.jsx("option",{value:2,children:"周二"}),i.jsx("option",{value:3,children:"周三"}),i.jsx("option",{value:4,children:"周四"}),i.jsx("option",{value:5,children:"周五"}),i.jsx("option",{value:6,children:"周六"}),i.jsx("option",{value:0,children:"周日"})]})]}):null,a.scheduleType==="monthly"?i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"日期"}),i.jsx("select",{value:a.monthDay,disabled:h,onChange:$=>j($.target.value),children:Array.from({length:31},($,L)=>L+1).map($=>i.jsxs("option",{value:$,children:[$," 日"]},$))})]}):null,a.scheduleType==="custom"?i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"Cron"}),i.jsx("input",{type:"text",value:l,disabled:h,spellCheck:!1,placeholder:qd,onChange:$=>c($.target.value),onBlur:C,onKeyDown:$=>{$.key==="Enter"&&$.currentTarget.blur()}})]}):null,i.jsxs("div",{className:"af-work-schedule-card__meta",children:[i.jsxs("span",{children:[_G(a.scheduleType)," ",a.scheduleType==="custom"?"":a.time]}),i.jsxs("span",{children:["Next ",CG(u.nextAt)]}),i.jsx("span",{children:d?"running":u.lastStatus||"idle"})]}),u.lastError?i.jsx("div",{className:"af-work-schedule-card__error",children:u.lastError}):null,i.jsxs("div",{className:"af-work-schedule-card__actions",children:[i.jsxs("button",{type:"button",className:"af-work-run-card__button af-work-schedule-card__run-now nodrag"+(d?" af-work-run-card__button--stop":""),disabled:h||f,onClick:$=>{var L,F;$.stopPropagation(),d?(L=t==null?void 0:t.onStopWorkspaceNode)==null||L.call(t,e):(F=t==null?void 0:t.onRunWorkspaceNode)==null||F.call(t,e)},children:[i.jsx("span",{className:"material-symbols-outlined",children:d?"stop_circle":"play_arrow"}),i.jsx("span",{children:d?"停止":"立即运行"})]}),i.jsxs("button",{type:"button",className:"af-work-run-card__button af-work-schedule-card__optimize nodrag"+(f?" af-work-schedule-card__optimize--running":""),disabled:h||d||f,title:"为下游节点提前生成 implementation",onClick:$=>{var L;$.stopPropagation(),(L=t==null?void 0:t.onOptimizeWorkspaceSchedule)==null||L.call(t,e)},children:[i.jsx("span",{className:"material-symbols-outlined",children:f?"sync":"auto_fix_high"}),i.jsx("span",{children:f?"优化中":"优化"})]}),i.jsxs("button",{type:"button",className:"af-work-run-card__button af-work-schedule-card__logs nodrag",onClick:$=>{var L;$.stopPropagation(),(L=t==null?void 0:t.onOpenWorkspaceRunLogs)==null||L.call(t,{nodeId:e,scheduleNodeId:e,runNodeId:u.targetRunNodeId||e,lastRunId:u.lastRunId||"",label:(t==null?void 0:t.label)||"Scheduled Run"})},children:[i.jsx("span",{className:"material-symbols-outlined",children:"article"}),i.jsx("span",{children:"日志"})]})]})]})]})}function lJ({id:e,data:t,selected:n,deleteNode:r}){const{setNodes:s}=Fc(),o=!!(t!=null&&t.readOnly),a=db(t==null?void 0:t.nodeSize)||{width:Qa,height:Za},l=m.useCallback(c=>{var u,d;c.button!==0||c.metaKey||c.ctrlKey||c.shiftKey||(d=(u=c.target)==null?void 0:u.closest)!=null&&d.call(u,".af-work-group-node__resize, .af-work-group-node__delete")||s(f=>sM(f,e))},[e,s]);return i.jsxs("div",{className:"af-work-group-node"+(n?" af-work-group-node--selected":""),style:{width:a.width,height:a.height},onPointerDownCapture:l,children:[o?null:i.jsx(zk,{className:"af-work-group-node__resize nodrag",minWidth:Qa,minHeight:Za,position:"bottom-right",children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})}),i.jsxs("div",{className:"af-work-group-node__title nodrag",children:[i.jsx("span",{children:(t==null?void 0:t.title)||(t==null?void 0:t.label)||"Group"}),i.jsx("button",{type:"button",className:"af-work-group-node__delete",disabled:o,onClick:c=>{c.stopPropagation(),r==null||r(e)},"aria-label":"删除分组",title:"删除分组",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]})]})}function cJ(e){var y,k,b,g,v,w,N,j,C,P,I,z,$,L,F,O,M,K,H,D,T,W,E,Q,V,B,se,ue;const{setEdges:t,setNodes:n}=Fc(),r=(y=e.data)==null?void 0:y.onSyncNodePropDraft,s=!!((k=e.data)!=null&&k.readOnly),[o,a]=m.useState(!1),l=(b=e.data)!=null&&b.nodeSize&&Number(e.data.nodeSize.width)>0&&Number(e.data.nodeSize.height)>0?{width:Number(e.data.nodeSize.width),height:Number(e.data.nodeSize.height)}:null,c=m.useCallback(G=>{var ne,Z,ce;if(s)return;(Z=(ne=e.data)==null?void 0:ne.onCleanupWorkspaceNodeOutputs)==null||Z.call(ne,G,e.data);const ee=ei((ce=e.data)==null?void 0:ce.definitionId)?cM(G):"",te=new Set([G,ee].filter(Boolean));n(de=>de.filter(me=>!te.has(me.id))),t(de=>de.filter(me=>!te.has(me.source)&&!te.has(me.target)))},[e.data,s,t,n]),u=m.useCallback(G=>{var ee,te;G.button!==0||G.metaKey||G.ctrlKey||G.shiftKey||(te=(ee=G.target)==null?void 0:ee.closest)!=null&&te.call(ee,".react-flow__handle, .af-work-display-resize")||(n(ne=>sM(ne,e.id)),t(ne=>pJ(ne)))},[e.id,t,n]),d=m.useCallback((G,ee)=>{s||(n(te=>te.map(ne=>ne.id===G?{...ne,data:{...ne.data,model:ee}}:ne)),r==null||r(G,{model:ee}))},[s,n,r]),f=m.useCallback((G,ee)=>{s||(n(te=>te.map(ne=>{var ce;if(ne.id!==G)return ne;const Z=Array.isArray((ce=ne.data)==null?void 0:ce.outputs)&&ne.data.outputs.length?ne.data.outputs.map((de,me)=>me===0?{...de,default:ee,value:ee}:de):[{type:"bool",name:"value",default:ee,value:ee}];return{...ne,data:{...ne.data,body:"",outputs:Z}}})),r==null||r(G,te=>({body:"",outputs:Array.isArray(te==null?void 0:te.outputs)&&te.outputs.length?te.outputs.map((Z,ce)=>ce===0?{...Z,default:ee,value:ee}:Z):[{type:"bool",name:"value",default:ee,value:ee}]})))},[s,n,r]),p=m.useCallback((G,ee)=>{s||(n(te=>te.map(ne=>ne.id===G?{...ne,data:{...ne.data,body:ee}}:ne)),r==null||r(G,{body:ee}))},[s,n,r]),h=m.useCallback((G,ee)=>{if(s)return;const te=po(ee);n(ne=>ne.map(Z=>Z.id===G?{...Z,data:{...Z.data,images:te}}:Z)),r==null||r(G,{images:te})},[s,n,r]);return(g=e.data)!=null&&g.isWorkspaceGroup?i.jsx(lJ,{...e,deleteNode:c}):tl((v=e.data)==null?void 0:v.definitionId)?i.jsx(tM,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c}):((w=e.data)==null?void 0:w.definitionId)==="workspace_run"?i.jsx(iJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c}):((N=e.data)==null?void 0:N.definitionId)==="workspace_scheduled_run"?i.jsx(aJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c}):ei((j=e.data)==null?void 0:j.definitionId)?i.jsx(oJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c,skills:(C=e.data)==null?void 0:C.skills,skillCollections:(P=e.data)==null?void 0:P.skillCollections,workspaces:(I=e.data)==null?void 0:I.workspaceTargets}):((z=e.data)==null?void 0:z.definitionId)==="control_load_skills"?i.jsx(AJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c,skills:($=e.data)==null?void 0:$.skills,skillCollections:(L=e.data)==null?void 0:L.skillCollections,onChangeSkillKeys:(F=e.data)==null?void 0:F.onChangeLoadSkillKeys}):((O=e.data)==null?void 0:O.definitionId)==="control_load_mcp"?i.jsx(PJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c,servers:(M=e.data)==null?void 0:M.mcpServers,onChangeMcpNames:(K=e.data)==null?void 0:K.onChangeLoadMcpNames}):((H=e.data)==null?void 0:H.definitionId)==="control_cd_workspace"?i.jsx(IJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c,workspaces:(D=e.data)==null?void 0:D.workspaceTargets,onChangeWorkspace:(T=e.data)==null?void 0:T.onChangeLoadWorkspace,onRefreshWorkspaces:(W=e.data)==null?void 0:W.onRefreshWorkspaces}):i.jsxs("div",{className:"af-work-flow-node"+(e.selected?" af-work-flow-node--selected":"")+(o?" af-work-flow-node--resizing":"")+((E=e.data)!=null&&E.isExecuting||((Q=e.data)==null?void 0:Q.nodeStatus)==="running"?" af-work-flow-node--executing":"")+(((V=e.data)==null?void 0:V.nodeStatus)==="success"?" af-work-flow-node--done":"")+(((B=e.data)==null?void 0:B.nodeStatus)==="failed"?" af-work-flow-node--failed":"")+(((se=e.data)==null?void 0:se.nodeStatus)==="stopped"?" af-work-flow-node--stopped":""),style:l?{width:l.width,height:l.height}:void 0,onPointerDownCapture:u,children:[s?null:i.jsx(zk,{className:"af-work-display-resize af-work-flow-resize nodrag",position:"bottom-right",minWidth:IT,minHeight:lm,maxWidth:RT,maxHeight:TT,onResizeStart:()=>a(!0),onResizeEnd:()=>a(!1),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_full"})}),i.jsx(Xq,{...e,deleteNode:c,deferTextCommit:!0,modelLists:(ue=e.data)==null?void 0:ue.modelLists,onModelChange:d,onProvideValueChange:f,onNodeBodyChange:p,onNodeImagesChange:h})]})}const uJ={[pc]:m.memo(cJ)};function yv(e,t=[]){for(const n of e||[])n.type==="file"&&t.push(n),Array.isArray(n.children)&&yv(n.children,t);return t}function nM(e,t){const n=String(t||"");if(!n)return null;for(const r of e||[]){if(r.path===n)return r;const s=Array.isArray(r.children)?nM(r.children,n):null;if(s)return s}return null}function dJ(e){const t=String(e||"").replace(/\\/g,"/").replace(/^\/+|\/+$/g,"");return!t||!t.includes("/")?"":t.split("/").slice(0,-1).join("/")}function rM(e,t=[]){for(const n of e||[])n.type==="directory"&&(t.push(n.path),Array.isArray(n.children)&&rM(n.children,t));return t}function Dp(e){const t=String(e||"").replace(/\\/g,"/").split("/").filter(Boolean),n=[];for(let r=1;r<t.length;r++)n.push(t.slice(0,r).join("/"));return n}function fJ(e,t){const n=String(t||"");let r=!1;const s=(e||[]).map(o=>{const a=o.id===n;return o.selected===a?o:(r=!0,{...o,selected:a})});return r?s:e}function sM(e,t){const n=String(t||""),r=(e||[]).find(o=>o.id===n),s=(e||[]).reduce((o,a)=>o+(a.selected?1:0),0);return r!=null&&r.selected&&s>1?e:fJ(e,n)}function pJ(e){let t=!1;const n=(e||[]).map(r=>r.selected?(t=!0,{...r,selected:!1}):r);return t?n:e}function hJ(e){return[...e||[]].sort((t,n)=>t.type!==n.type?t.type==="directory"?-1:1:String(t.name||"").localeCompare(String(n.name||"")))}function mJ(e,t,n=0){const r=String(t||"").replace(/\\/g,"/").split("/").filter(Boolean);if(r.length===0)return e;const s=(o,a,l)=>{const c=r[a],u=l?`${l}/${c}`:c,d=a===r.length-1;let f=!1;const p=(Array.isArray(o)?o:[]).map(h=>h.name!==c?h:(f=!0,d?{...h,type:"file",name:c,path:u,icon:tc(c),size:n}:{...h,type:"directory",name:c,path:u,icon:tc(c,!0),children:s(h.children||[],a+1,u)}));return f||p.push(d?{type:"file",name:c,path:u,icon:tc(c),size:n}:{type:"directory",name:c,path:u,icon:tc(c,!0),children:s([],a+1,u)}),hJ(p)};return s(e||[],0,"")}function gJ(e){const t=Number(e||0);return!Number.isFinite(t)||t<=0?"":t<1024?`${t} B`:t<1024*1024?`${Math.round(t/102.4)/10} KB`:`${Math.round(t/1024/102.4)/10} MB`}function iM({items:e,onOpen:t,selectedPath:n,collapsedDirs:r,onToggleDir:s,onSelect:o,onFileDragStart:a,onDelete:l,onDownload:c}){return i.jsx("ul",{className:"af-work-files",children:(e||[]).map(u=>{var h;const d=u.type==="directory",f=d&&(r==null?void 0:r.has(u.path)),p=n===u.path;return i.jsxs("li",{children:[i.jsxs("div",{className:"af-work-file-row",children:[i.jsxs("button",{type:"button",className:"af-work-file af-work-file--"+u.type+(p?" af-work-file--selected":""),draggable:!d,onDragStart:y=>{d||a==null||a(y,u)},onClick:()=>{o==null||o(u),d&&(s==null||s(u.path))},onDoubleClick:()=>{d||t(u)},title:u.path,children:[d?i.jsx("span",{className:"material-symbols-outlined af-work-file__chevron",children:f?"chevron_right":"expand_more"}):null,i.jsx("span",{className:"material-symbols-outlined",children:u.icon||tc(u.name,d)}),i.jsx("span",{children:u.name})]}),p?i.jsxs("div",{className:"af-work-file-actions",children:[d?null:i.jsx("button",{type:"button",className:"af-work-file-action",onClick:y=>{y.stopPropagation(),c==null||c(u)},"aria-label":`下载 ${u.name}`,title:`下载 ${u.path}`,children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"download"})}),i.jsx("button",{type:"button",className:"af-work-file-action af-work-file-action--danger",onClick:y=>{y.stopPropagation(),l==null||l(u)},"aria-label":`删除 ${u.name}`,title:`删除 ${u.path}`,children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"})})]}):null]}),d&&!f&&((h=u.children)!=null&&h.length)?i.jsx(iM,{items:u.children,onOpen:t,selectedPath:n,collapsedDirs:r,onToggleDir:s,onSelect:o,onFileDragStart:a,onDelete:l,onDownload:c}):null]},u.path)})})}function yJ({files:e,query:t,onQueryChange:n,onSelect:r,onUpload:s,onClose:o}){const a=m.useMemo(()=>yv(e),[e]),l=String(t||"").trim().toLowerCase(),c=a.filter(u=>l?`${u.path} ${u.name}`.toLowerCase().includes(l):!0);return i.jsx("div",{className:"af-flow-snippet-modal-overlay",onMouseDown:o,children:i.jsxs("div",{className:"af-flow-snippet-modal af-work-file-picker-modal",role:"dialog","aria-modal":"true","aria-label":"选择文件",onMouseDown:u=>u.stopPropagation(),children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined",children:"folder_open"}),"选择文件"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:o,"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("div",{className:"af-work-file-picker-modal__tools",children:[i.jsx("input",{value:t,onChange:u=>n(u.target.value),placeholder:"搜索文件路径...",autoFocus:!0}),i.jsxs("button",{type:"button",onClick:()=>s==null?void 0:s(""),children:[i.jsx("span",{className:"material-symbols-outlined",children:"upload_file"}),"上传"]})]}),i.jsxs("div",{className:"af-work-file-picker-modal__list",children:[c.map(u=>i.jsxs("button",{type:"button",className:"af-work-file-picker-modal__item",onClick:()=>r(u),children:[i.jsx("span",{className:"material-symbols-outlined",children:u.icon||tc(u.name)}),i.jsxs("span",{className:"af-work-file-picker-modal__main",children:[i.jsx("strong",{children:u.name}),i.jsx("small",{children:u.path})]}),u.size?i.jsx("em",{children:gJ(u.size)}):null]},u.path)),c.length===0?i.jsx("div",{className:"af-work-file-picker-modal__empty",children:"没有匹配文件,可先上传或调整搜索词。"}):null]})]})]})})}function zC({messages:e,running:t,showRunningIndicator:n=!0}){const r=e.length>0;return i.jsxs("div",{className:"af-composer-ai-stack af-composer-ai-stack--in-panel af-composer-thread-stack",children:[e.map((s,o)=>{const a=s.kind==="run-log"||s.kind==="run-summary"||s.kind==="activity"||s.kind==="prompt"||s.kind==="raw"||s.kind==="thinking"||s.kind==="result"||s.kind==="assistant"?"reply":s.role==="user"?"user-msg":s.error?"error":"reply",l=s.kind==="run-summary"?"Steps":s.kind==="run-log"?"Run":s.kind==="activity"?"Activity":s.kind==="prompt"?"Prompt":s.kind==="raw"?"Raw Trace":s.kind==="thinking"?"Thinking":s.kind==="result"?"Result":s.kind==="assistant"?"Response":s.role==="user"?"You":s.error?"Error":"Reply";return i.jsxs("section",{className:`af-composer-ai-block af-composer-ai-block--${a}${s.kind?` af-composer-ai-block--kind-${s.kind}`:""}`,children:[i.jsx("div",{className:"af-composer-ai-block-label",children:l}),i.jsx("div",{className:"af-composer-ai-block-body",children:s.text})]},`${o}-${s.role}-${String(s.text||"").slice(0,24)}`)}),n&&t&&!r?i.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--reply af-composer-ai-block--pending",children:[i.jsx("div",{className:"af-composer-ai-block-label",children:"Reply"}),i.jsx("div",{className:"af-composer-ai-block-body",children:"Waiting..."})]}):null,n&&t&&r?i.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--thinking",children:[i.jsx("div",{className:"af-composer-ai-block-label",children:"Thinking"}),i.jsx("div",{className:"af-composer-ai-block-body",children:"Workspace agent is running..."})]}):null]})}function oM(e){const t=String((e==null?void 0:e.kind)||"");return["run-log","run-summary","activity","prompt","raw","thinking"].includes(t)}function wJ(e,t=!1){const n=Array.isArray(e)?e:[],r=n.filter(o=>!oM(o));if(r.length>0)return r;const s=[...n].reverse().find(o=>(o==null?void 0:o.kind)==="result"||(o==null?void 0:o.kind)==="assistant"||(o==null?void 0:o.error));return s?[s]:n.length>0||t?[{role:"assistant",kind:"assistant",text:t?"正在执行,可以在完成后继续追问或要求调整。":"运行已完成。可以在下方继续追问、要求总结或调整结果。",at:0}]:[]}function xJ(e){return(Array.isArray(e)?e:[]).filter(oM)}function Gd(e){const t=String(e||"").trim();if(!t)return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(String).filter(Boolean)}catch{}return t.split(/[\n,]+/).map(n=>n.trim()).filter(Boolean)}function bJ(e){const t=Gd((e==null?void 0:e.body)||"");if(t.length>0)return t;const r=(Array.isArray(e==null?void 0:e.inputs)?e.inputs:[]).find(s=>(s==null?void 0:s.name)==="skillsContext"||(s==null?void 0:s.name)==="skillKeys"||(s==null?void 0:s.type)==="text");return Gd((r==null?void 0:r.default)||(r==null?void 0:r.value)||"")}function kJ(e){const n=[...Array.isArray(e==null?void 0:e.inputs)?e.inputs:[],...Array.isArray(e==null?void 0:e.outputs)?e.outputs:[]].find(r=>(r==null?void 0:r.name)==="skillKeys"||(r==null?void 0:r.name)==="skillsContext");return Gd((n==null?void 0:n.default)||(n==null?void 0:n.value)||"")}function aM(e,t,n=1){const r=(Array.isArray(e)?e:[]).map(o=>String(o||"").trim()).filter(Boolean);return r.length?{head:r.slice(0,n).join("、"),extra:r.length>n?`等 ${r.length} 个`:"",title:r.join(", ")}:{head:t,extra:"",title:""}}function BC(e){return JSON.stringify(Array.from(new Set((e||[]).map(String).filter(Boolean))))}function ta(e,t,n=""){const r=(Array.isArray(e)?e:[]).find(o=>(o==null?void 0:o.name)===t);return String((r==null?void 0:r.value)??(r==null?void 0:r.default)??"").trim()||n}function gm(e,t){const n=ta(e,t,"");if(!n)return null;try{const r=JSON.parse(n);return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}function gf(e){const t=String(e||"").trim().toLowerCase();return["markdown","html","react","table","chart","ascii","mermaid"].includes(t)?t:"markdown"}function Ss(e){const t=String(e||""),n=t.indexOf(" - ");return n>=0?t.slice(0,n).trim():t.trim()}function lM(e){const t=gf(e);return t==="html"?"display_html":t==="react"?"display_react_app":t==="table"?"display_table":t==="chart"?"display_chart":t==="ascii"?"display_ascii":t==="mermaid"?"display_mermaid":"display_markdown"}function cM(e){return`${String(e||"context_run").trim()||"context_run"}__display`}function uM(e){return e==="display_image"?"src":"content"}function HC(e,t,n){const r=uM(t),s=qu(e);let o=!1;const a=s.map(l=>(l==null?void 0:l.name)===r?(o=!0,{...l,default:n,value:n,showOnNode:l.showOnNode!==!1}):(l==null?void 0:l.name)==="filePath"?{...l,default:"",value:""}:l);return o||a.push({type:"text",name:r,default:n,value:n,required:!0,showOnNode:!0}),a}function WC(e,t,n=[],r=[]){const s=Array.isArray(e)?e:[],o=new Set((Array.isArray(n)?n:[]).map(u=>String(u||"").trim()).filter(Boolean)),a=new Set((Array.isArray(r)?r:[]).map(u=>String(u||"").trim()).filter(Boolean)),l=u=>(u==null?void 0:u.showOnNode)!==!1;let c=s.findIndex(u=>l(u)&&o.has(String((u==null?void 0:u.name)||"").trim()));return c<0&&(c=s.findIndex(u=>o.has(String((u==null?void 0:u.name)||"").trim()))),c<0&&(c=s.findIndex(u=>l(u)&&a.has(String((u==null?void 0:u.type)||"").trim()))),c<0&&(c=s.findIndex(u=>l(u))),c<0&&(c=0),`${t}-${c}`}function VC(e){return(Array.isArray(e)?e:[]).map(t=>(t==null?void 0:t.type)==="node"||(t==null?void 0:t.name)==="next"?t:{...t,default:"",value:""})}function lg(e){const t=Array.isArray(e==null?void 0:e.outputs)?e.outputs:Array.isArray(e==null?void 0:e.output)?e.output:[],n=s=>String((s==null?void 0:s.value)??(s==null?void 0:s.default)??"").trim(),r=t.find(s=>((s==null?void 0:s.name)==="content"||(s==null?void 0:s.name)==="result")&&n(s))||t.find(s=>(s==null?void 0:s.name)==="resultFile"&&n(s))||t.find(s=>(s==null?void 0:s.type)!=="node"&&(s==null?void 0:s.name)!=="next"&&(s==null?void 0:s.name)!=="displayType"&&n(s));return r?n(r):""}function vJ(e){const t=Array.isArray(e==null?void 0:e.inputs)?e.inputs:[],n=ta(t,"includeWorkspaceContext","true").toLowerCase(),r=gm(t,"knowledgeContext"),s=gm(t,"workspaceContext");return{task:String((e==null?void 0:e.body)||""),skillKeys:kJ(e),includeWorkspaceContext:n!=="false"&&n!=="0"&&n!=="off",knowledgeContext:r||(s?cg([s]):null),workspaceContext:s,displayType:gf(ta(t,"displayType","markdown")),model:String((e==null?void 0:e.model)||"").trim()}}function ei(e){const t=String(e||"");return t==="workspace_one_click_task"||t==="workspace_context_run"}function SJ(e){const t=Gd((e==null?void 0:e.body)||"");if(t.length>0)return t;const r=(Array.isArray(e==null?void 0:e.inputs)?e.inputs:[]).find(s=>(s==null?void 0:s.name)==="mcpContext"||(s==null?void 0:s.name)==="serverNames"||(s==null?void 0:s.type)==="text");return Gd((r==null?void 0:r.default)||(r==null?void 0:r.value)||"")}function NJ(e){return JSON.stringify(Array.from(new Set((e||[]).map(String).filter(Boolean))))}function dM(e={},t="context"){const n=String((e==null?void 0:e.cwd)||(e==null?void 0:e.workspaceRoot)||(e==null?void 0:e.path)||"").trim(),r=String((e==null?void 0:e.id)||"").trim(),s=String((e==null?void 0:e.label)||(e==null?void 0:e.name)||"").trim();if(!n&&!r&&!s)return null;const o=String(s||r||"知识库").trim();return{id:r,label:o,kind:(e==null?void 0:e.kind)==="git"?"git":"local",type:String((e==null?void 0:e.type)||""),repoPath:n,path:n,mountPath:String((e==null?void 0:e.mountPath)||r||o).trim(),repoUrl:String((e==null?void 0:e.repoUrl)||"").trim(),branch:String((e==null?void 0:e.branch)||"").trim(),readonly:!0,role:t}}function cg(e=[]){const t=(Array.isArray(e)?e:[e]).map((n,r)=>dM(n,r===0?"primary":"context")).filter(Boolean);return t.length?{version:1,sources:t}:null}function fM(e){return(e&&typeof e=="object"&&Array.isArray(e.sources)?e.sources:[]).map(n=>dM(n,(n==null?void 0:n.role)||"context")).filter(Boolean)}function jJ(e){const t=Array.isArray(e==null?void 0:e.inputs)?e.inputs:[],n=gm(t,"knowledgeContext"),r=gm(t,"workspaceContext");return{sources:fM(n||(r?cg([r]):null)),path:ta(t,"path",""),label:ta(t,"label","")}}function KC(e){var r,s,o,a,l,c,u,d,f;if(!e)return null;const{inputs:t,outputs:n}=uU(e);return{id:e.id,newId:e.id,label:String(((r=e.data)==null?void 0:r.label)??e.id),role:String(((s=e.data)==null?void 0:s.role)??"normal"),model:String(((o=e.data)==null?void 0:o.model)??""),body:String(((a=e.data)==null?void 0:a.body)??""),images:po((l=e.data)==null?void 0:l.images),script:String(((c=e.data)==null?void 0:c.script)??""),scriptRef:String(((u=e.data)==null?void 0:u.scriptRef)??""),implementationRef:String(((d=e.data)==null?void 0:d.implementationRef)??""),implementationMode:String(((f=e.data)==null?void 0:f.implementationMode)??""),inputs:t,outputs:n}}function qC(e,t,n,r=""){var c,u;const s=String(n||"").trim(),o=(Array.isArray(e)?e:[]).find(d=>String((d==null?void 0:d.id)||"")===s),a=String(((c=o==null?void 0:o.data)==null?void 0:c.model)||"").trim();if(a&&a!=="default")return a;const l=String(((u=t==null?void 0:t[s])==null?void 0:u.model)||"").trim();return l&&l!=="default"?l:String(r||"").trim()}function UC(e){return(Array.isArray(e)?e:[]).map(t=>({type:String((t==null?void 0:t.type)??"node").trim()||"node",name:String((t==null?void 0:t.name)??""),default:String((t==null?void 0:t.default)??""),required:!!(t!=null&&t.required),showOnNode:(t==null?void 0:t.showOnNode)!=null?t.showOnNode!==!1:!!(t!=null&&t.required)||String((t==null?void 0:t.type)??"node").trim().toLowerCase()==="node"}))}function CJ(e,t,n){var d,f;const r=String(((d=e==null?void 0:e.data)==null?void 0:d.definitionId)??n),s=r.startsWith("provide_"),o=String((t==null?void 0:t.role)||"").trim(),a=Wd.includes(o)?o:"normal",l=String((t==null?void 0:t.model)||"").trim(),c={...e.data,label:String((t==null?void 0:t.label)||"").trim()||n,role:a,model:l===""||l==="default"?void 0:l,body:s?"":String((t==null?void 0:t.body)??""),images:s?[]:po(t==null?void 0:t.images),inputs:UC(t==null?void 0:t.inputs),outputs:s&&Array.isArray((f=e.data)==null?void 0:f.outputs)?e.data.outputs:UC(t==null?void 0:t.outputs)},u=String((t==null?void 0:t.script)??"").trim();r==="tool_nodejs"||u!==""?c.script=String((t==null?void 0:t.script)??""):delete c.script;for(const p of["scriptRef","implementationRef","implementationMode"]){const h=String((t==null?void 0:t[p])??"").trim();h?c[p]=h:delete c[p]}return c}function YC({nodes:e,edges:t,instances:n,selectedNode:r,draft:s,allowRename:o=!1}){if(!s||!r)return{ok:!1,error:""};const a=r.id,l=String(s.newId||"").trim(),c=o?l:a;if(o){if(!TU.test(c))return{ok:!1,error:"Invalid instance id"};if(e.some(k=>k.id===c&&k.id!==a))return{ok:!1,error:"Duplicate instance id"}}const u=CJ(r,s,c),d=r.data||{};if(!(c!==a||d.label!==u.label||d.role!==u.role||d.model!==u.model||d.body!==u.body||JSON.stringify(po(d.images))!==JSON.stringify(u.images)||(d.script??void 0)!==(u.script??void 0)||(d.scriptRef??void 0)!==(u.scriptRef??void 0)||(d.implementationRef??void 0)!==(u.implementationRef??void 0)||(d.implementationMode??void 0)!==(u.implementationMode??void 0)||JSON.stringify(d.inputs||[])!==JSON.stringify(u.inputs||[])||JSON.stringify(d.outputs||[])!==JSON.stringify(u.outputs||[])))return{ok:!0,changed:!1,nextId:c,nodes:e,edges:t,instances:n};const p=e.map(k=>k.id===a?{...k,id:c,selected:!0,data:u}:k);let h=t,y=n;if(c!==a){y={...n||{}};const k={...y[a]||{}};delete y[a],y[c]=k,h=t.map((b,g)=>({...b,source:b.source===a?c:b.source,target:b.target===a?c:b.target,id:`we-${b.source===a?c:b.source}-${b.target===a?c:b.target}-${g}`}))}return{ok:!0,changed:!0,nextId:c,nodes:p,edges:h,instances:y}}function _J(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function EJ(e,t,n){if(!e||!t||!n)return n;const r={...e};for(const s of["newId","label","role","model","body","images","script","scriptRef","implementationRef","implementationMode","inputs","outputs"])_J(e[s],t[s])&&(r[s]=n[s]);return r}function mb(e,t=[]){const n=m.useRef(null),r=m.useRef(null),[s,o]=m.useState({visible:!1,top:0,height:100}),a=m.useCallback(()=>{const d=n.current;if(!d)return;const f=Math.max(1,d.scrollHeight),p=Math.max(1,d.clientHeight),h=f>p+1,y=h?Math.max(12,p/f*100):100,k=Math.max(0,100-y),b=h?Math.min(k,d.scrollTop/Math.max(1,f-p)*k):0;o({visible:h,top:b,height:y})},[]);m.useEffect(()=>{if(!e)return;const d=requestAnimationFrame(a);return()=>cancelAnimationFrame(d)},[e,a,...t]);const l=m.useCallback(d=>{const f=n.current;if(!f)return;const p=Math.max(0,f.scrollHeight-f.clientHeight);f.scrollTop=Math.min(1,Math.max(0,d))*p,a()},[a]),c=m.useCallback((d,f=0)=>{const p=r.current;if(!p)return 0;const h=p.getBoundingClientRect(),y=s.height/100*h.height,k=Math.max(1,h.height-y);return(d-h.top-f)/k},[s.height]),u=m.useCallback(d=>{var N,j;if(!s.visible)return;d.preventDefault(),d.stopPropagation();const f=r.current;if(!f)return;const p=f.getBoundingClientRect(),h=s.top/100*p.height,y=s.height/100*p.height,b=d.clientY>=p.top+h&&d.clientY<=p.top+h+y?d.clientY-p.top-h:y/2;l(c(d.clientY,b));const g=d.pointerId;(j=(N=d.currentTarget).setPointerCapture)==null||j.call(N,g);const v=C=>{C.preventDefault(),l(c(C.clientY,b))},w=()=>{window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",w),window.removeEventListener("pointercancel",w)};window.addEventListener("pointermove",v),window.addEventListener("pointerup",w),window.addEventListener("pointercancel",w)},[c,l,s.height,s.top,s.visible]);return{menuRef:n,scrollbarTrackRef:r,scrollbar:s,updateMenuScrollbar:a,handleScrollbarPointerDown:u}}function AJ({id:e,data:t,selected:n,deleteNode:r,skills:s,skillCollections:o,onChangeSkillKeys:a}){const l=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],c=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],u=Array.isArray(s)?s:[],d=Array.isArray(o)?o:[],[f,p]=m.useState(!1),[h,y]=m.useState(""),[k,b]=m.useState(()=>new Set),g=m.useRef(null),v=m.useRef(null),[w,N]=m.useState({visible:!1,top:0,height:100}),j=m.useMemo(()=>new Set(bJ(t)),[t]),C=m.useMemo(()=>new Map(u.map(D=>[D.key,D])),[u]),P=m.useMemo(()=>Array.from(j).map(D=>{var T;return((T=C.get(D))==null?void 0:T.name)||D}),[C,j]),I=m.useMemo(()=>aM(P,"选择 Skills"),[P]),z=m.useMemo(()=>{const D=new Set,T=d.map(E=>{const Q=Qo(E,u).map(V=>C.get(V)).filter(Boolean);for(const V of Q)D.add(V.key);return{...E,skills:Q}}).filter(E=>E.skills.length>0),W=u.filter(E=>!D.has(E.key));return{collectionGroups:T,ungrouped:W}},[C,d,u]);m.useEffect(()=>{b(D=>{let T=!1;const W=new Set(D);for(const E of z.collectionGroups)W.has(E.id)||(W.add(E.id),T=!0);return T?W:D})},[z.collectionGroups]);const $=m.useMemo(()=>{const D=h.trim().toLowerCase();if(!D)return z;const T=E=>[E==null?void 0:E.key,E==null?void 0:E.name,E==null?void 0:E.description].map(V=>String(V||"").toLowerCase()).join(" ").includes(D);return{collectionGroups:z.collectionGroups.map(E=>{const V=[E==null?void 0:E.id,E==null?void 0:E.name,E==null?void 0:E.description].map(B=>String(B||"").toLowerCase()).join(" ").includes(D)?E.skills:E.skills.filter(T);return{...E,skills:V}}).filter(E=>E.skills.length>0),ungrouped:z.ungrouped.filter(T)}},[z,h]),L=m.useCallback((D,T)=>{const W=new Set(j);for(const E of D)T?W.add(E):W.delete(E);a==null||a(e,Array.from(W))},[e,j,a]),F=m.useCallback(D=>{b(T=>{const W=new Set(T);return W.has(D)?W.delete(D):W.add(D),W})},[]),O=m.useCallback(()=>{const D=g.current;if(!D)return;const T=Math.max(1,D.scrollHeight),W=Math.max(1,D.clientHeight),E=T>W+1,Q=E?Math.max(12,W/T*100):100,V=Math.max(0,100-Q),B=E?Math.min(V,D.scrollTop/Math.max(1,T-W)*V):0;N({visible:E,top:B,height:Q})},[]);m.useEffect(()=>{if(!f)return;const D=requestAnimationFrame(O);return()=>cancelAnimationFrame(D)},[k,$,j.size,f,O]);const M=m.useCallback(D=>{const T=g.current;if(!T)return;const W=Math.max(0,T.scrollHeight-T.clientHeight);T.scrollTop=Math.min(1,Math.max(0,D))*W,O()},[O]),K=m.useCallback((D,T=0)=>{const W=v.current;if(!W)return 0;const E=W.getBoundingClientRect(),Q=w.height/100*E.height,V=Math.max(1,E.height-Q);return(D-E.top-T)/V},[w.height]),H=m.useCallback(D=>{var ee,te;if(!w.visible)return;D.preventDefault(),D.stopPropagation();const T=v.current;if(!T)return;const W=T.getBoundingClientRect(),E=w.top/100*W.height,Q=w.height/100*W.height,B=D.clientY>=W.top+E&&D.clientY<=W.top+E+Q?D.clientY-W.top-E:Q/2;M(K(D.clientY,B));const se=D.pointerId;(te=(ee=D.currentTarget).setPointerCapture)==null||te.call(ee,se);const ue=ne=>{ne.preventDefault(),M(K(ne.clientY,B))},G=()=>{window.removeEventListener("pointermove",ue),window.removeEventListener("pointerup",G),window.removeEventListener("pointercancel",G)};window.addEventListener("pointermove",ue),window.addEventListener("pointerup",G),window.addEventListener("pointercancel",G)},[K,M,w.height,w.top,w.visible]);return i.jsxs("div",{className:"af-work-load-skills-card"+(n?" af-work-load-skills-card--selected":"")+(f?" af-work-load-skills-card--menu-open":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[l.map((D,T)=>{if(D.showOnNode===!1)return null;const W=`${2.6+T*1.7}rem`,E=D.name||`#${T+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:W},children:E}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${T}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:W,background:Tn(D.type)},title:`${E} · ${D.type}`})]},`in-${T}`)}),c.map((D,T)=>{if(D.showOnNode===!1)return null;const W=`${2.6+T*1.7}rem`,E=D.name||`#${T+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:W},children:E}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${T}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:W,background:Tn(D.type)},title:`${E} · ${D.type}`})]},`out-${T}`)}),i.jsxs("div",{className:"af-work-load-skills-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"extension"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"Load Skills"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"control_load_skills"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-load-skills-card__body nodrag",children:[i.jsxs("button",{type:"button",className:"af-work-load-skills-card__select",onClick:D=>{var T;D.stopPropagation(),f||(T=t==null?void 0:t.onRefreshSkills)==null||T.call(t),p(W=>!W)},children:[i.jsxs("span",{className:"af-work-load-skills-card__summary",title:I.title,children:[i.jsx("span",{className:"af-work-load-skills-card__summary-main",children:I.head}),I.extra?i.jsx("span",{className:"af-work-load-skills-card__summary-extra",children:I.extra}):null]}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:f?"expand_less":"expand_more"})]}),f?i.jsxs("div",{className:"af-work-load-skills-menu-shell",onClick:D=>D.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:h,onChange:D=>y(D.target.value),placeholder:"搜索 Skills...",spellCheck:!1,autoComplete:"off","aria-label":"搜索 Skills"}),h?i.jsx("button",{type:"button",onClick:()=>y(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{ref:g,className:"af-work-load-skills-menu",onScroll:O,children:[$.collectionGroups.map(D=>{const T=D.skills.map(V=>V.key),W=T.filter(V=>j.has(V)).length,E=T.length>0&&W===T.length,Q=k.has(D.id);return i.jsxs("section",{className:"af-work-load-skills-menu__group"+(Q?" af-work-load-skills-menu__group--collapsed":""),children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head",children:[i.jsx("input",{type:"checkbox",checked:E,onChange:V=>L(T,V.target.checked),"aria-label":`选择 ${D.name}`}),i.jsx("button",{type:"button",className:"af-work-load-skills-menu__group-toggle",onClick:()=>F(D.id),"aria-expanded":!Q,children:i.jsxs("span",{className:"af-work-load-skills-menu__group-main",children:[i.jsx("span",{children:D.name}),D.description?i.jsx("em",{children:D.description}):null]})}),i.jsxs("small",{children:[W,"/",T.length]}),i.jsx("button",{type:"button",className:"af-work-load-skills-menu__group-arrow",onClick:()=>F(D.id),"aria-label":Q?`展开 ${D.name}`:`收起 ${D.name}`,children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:Q?"chevron_right":"expand_more"})})]}),Q?null:i.jsx("div",{className:"af-work-load-skills-menu__options",children:D.skills.map(V=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:j.has(V.key),onChange:B=>L([V.key],B.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:V.name}),V.description?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:V.description}):null]})]},`${D.id}:${V.key}`))})]},D.id)}),$.ungrouped.length>0?i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"Ungrouped"}),i.jsx("small",{children:$.ungrouped.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:$.ungrouped.map(D=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:j.has(D.key),onChange:T=>L([D.key],T.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:D.name}),D.description?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:D.description}):null]})]},`ungrouped:${D.key}`))})]}):null,$.collectionGroups.length===0&&$.ungrouped.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的 Skills"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:()=>a==null?void 0:a(e,[]),children:"清空"})]}),i.jsx("div",{ref:v,className:"af-work-load-skills-scrollbar"+(w.visible?" af-work-load-skills-scrollbar--visible":""),onPointerDown:H,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${w.height}%`,top:`${w.top}%`}})})]}):null]})]})}function PJ({id:e,data:t,selected:n,deleteNode:r,servers:s=[],onChangeMcpNames:o}){const a=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],l=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],[c,u]=m.useState(!1),[d,f]=m.useState(""),p=m.useMemo(()=>new Set(SJ(t)),[t]),h=m.useMemo(()=>(Array.isArray(s)?s:[]).map(b=>({name:String((b==null?void 0:b.name)||""),description:String((b==null?void 0:b.description)||""),detail:String((b==null?void 0:b.url)||[b==null?void 0:b.command,...Array.isArray(b==null?void 0:b.args)?b.args:[]].filter(Boolean).join(" ")||""),type:String((b==null?void 0:b.type)||"")})).filter(b=>b.name),[s]),y=m.useMemo(()=>{const b=d.trim().toLowerCase();return b?h.filter(g=>[g.name,g.description,g.detail,g.type].join(" ").toLowerCase().includes(b)):h},[d,h]),k=m.useCallback((b,g)=>{const v=new Set(p);for(const w of b)g?v.add(w):v.delete(w);o==null||o(e,Array.from(v))},[e,p,o]);return i.jsxs("div",{className:"af-work-load-skills-card"+(n?" af-work-load-skills-card--selected":"")+(c?" af-work-load-skills-card--menu-open":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[a.map((b,g)=>{if(b.showOnNode===!1)return null;const v=`${2.6+g*1.7}rem`,w=b.name||`#${g+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:v},children:w}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${g}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:v,background:Tn(b.type)},title:`${w} · ${b.type}`})]},`in-${g}`)}),l.map((b,g)=>{if(b.showOnNode===!1)return null;const v=`${2.6+g*1.7}rem`,w=b.name||`#${g+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:v},children:w}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${g}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:v,background:Tn(b.type)},title:`${w} · ${b.type}`})]},`out-${g}`)}),i.jsxs("div",{className:"af-work-load-skills-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"hub"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"Load MCP"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"control_load_mcp"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-load-skills-card__body nodrag",children:[i.jsxs("button",{type:"button",className:"af-work-load-skills-card__select",onClick:b=>{var g;b.stopPropagation(),c||(g=t==null?void 0:t.onRefreshMcps)==null||g.call(t),u(v=>!v)},children:[i.jsx("span",{children:p.size>0?`${p.size} MCP selected`:"选择 MCP"}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:c?"expand_less":"expand_more"})]}),c?i.jsxs("div",{className:"af-work-load-skills-menu-shell",onClick:b=>b.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:d,onChange:b=>f(b.target.value),placeholder:"搜索 MCP...",spellCheck:!1,autoComplete:"off","aria-label":"搜索 MCP"}),d?i.jsx("button",{type:"button",onClick:()=>f(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{className:"af-work-load-skills-menu",children:[i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"MCP Servers"}),i.jsx("small",{children:y.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:y.map(b=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:p.has(b.name),onChange:g=>k([b.name],g.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:b.name}),b.description||b.detail?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:b.description||b.detail}):null]})]},b.name))})]}),y.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的 MCP"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:()=>o==null?void 0:o(e,[]),children:"清空"})]})]}):null]})]})}function IJ({id:e,data:t,selected:n,deleteNode:r,workspaces:s=[],onChangeWorkspace:o,onRefreshWorkspaces:a}){const l=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],c=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],[u,d]=m.useState(!1),[f,p]=m.useState(""),h=jJ(t),y=m.useMemo(()=>(Array.isArray(s)?s:[]).map(j=>({id:String((j==null?void 0:j.id)||""),label:String((j==null?void 0:j.label)||(j==null?void 0:j.name)||"知识库"),kind:(j==null?void 0:j.kind)==="git"?"git":"local",path:String((j==null?void 0:j.path)||""),repoUrl:String((j==null?void 0:j.repoUrl)||""),branch:String((j==null?void 0:j.branch)||""),mountPath:String((j==null?void 0:j.mountPath)||""),builtin:(j==null?void 0:j.builtin)===!0,exists:(j==null?void 0:j.exists)!==!1})).filter(j=>j.path),[s]),k=m.useMemo(()=>{const j=f.trim().toLowerCase();return j?y.filter(C=>[C.id,C.label,C.path,C.repoUrl,C.branch,C.mountPath].join(" ").toLowerCase().includes(j)):y},[f,y]),b=m.useMemo(()=>new Set((h.sources||[]).map(j=>j.id||j.path||j.repoPath).filter(Boolean)),[h.sources]),g=m.useMemo(()=>(h.sources||[]).map(j=>j.label||j.id||j.mountPath||j.path),[h.sources]),v=m.useMemo(()=>aM(g,"选择知识库"),[g]),w=mb(u,[k.length,g.length,f]),N=(j,C)=>{const P=(j==null?void 0:j.id)||(j==null?void 0:j.path)||"",I=y.filter(z=>{const $=z.id||z.path||"";return $===P?C:b.has($)});o==null||o(e,I)};return i.jsxs("div",{className:"af-work-load-skills-card af-work-load-workspace-card"+(n?" af-work-load-skills-card--selected":"")+(u?" af-work-load-skills-card--menu-open":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[l.map((j,C)=>{if(j.showOnNode===!1)return null;const P=`${2.6+C*1.7}rem`,I=j.name||`#${C+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:P},children:I}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${C}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:P,background:Tn(j.type)},title:`${I} · ${j.type}`})]},`in-${C}`)}),c.map((j,C)=>{if(j.showOnNode===!1)return null;const P=`${2.6+C*1.7}rem`,I=j.name||`#${C+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:P},children:I}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${C}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:P,background:Tn(j.type)},title:`${I} · ${j.type}`})]},`out-${C}`)}),i.jsxs("div",{className:"af-work-load-skills-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"folder_managed"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"加载知识库"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"control_cd_workspace"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-load-skills-card__body nodrag",children:[i.jsxs("button",{type:"button",className:"af-work-load-skills-card__select",onClick:j=>{j.stopPropagation(),u||a==null||a(),d(C=>!C)},children:[i.jsxs("span",{className:"af-work-load-skills-card__summary",title:v.title,children:[i.jsx("span",{className:"af-work-load-skills-card__summary-main",children:v.head}),v.extra?i.jsx("span",{className:"af-work-load-skills-card__summary-extra",children:v.extra}):null]}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:u?"expand_less":"expand_more"})]}),u?i.jsxs("div",{className:"af-work-load-skills-menu-shell",onClick:j=>j.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:f,onChange:j=>p(j.target.value),placeholder:"搜索知识库...",spellCheck:!1,autoComplete:"off","aria-label":"搜索知识库"}),f?i.jsx("button",{type:"button",onClick:()=>p(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{ref:w.menuRef,className:"af-work-load-skills-menu",onScroll:w.updateMenuScrollbar,children:[i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"知识库"}),i.jsx("small",{children:k.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:k.map(j=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:b.has(j.id||j.path),onChange:C=>N(j,C.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:j.label}),i.jsxs("span",{className:"af-work-load-skills-menu__option-desc",children:[j.kind==="git"&&j.repoUrl?`${j.repoUrl}${j.branch?` · ${j.branch}`:""}${j.mountPath?` · ${j.mountPath}`:""}`:j.path,j.exists?"":" · 路径未就绪"]})]})]},`${j.id}:${j.path}`))})]}),k.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的知识库"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:()=>o==null?void 0:o(e,[]),children:"清空知识库"})]}),i.jsx("div",{ref:w.scrollbarTrackRef,className:"af-work-load-skills-scrollbar"+(w.scrollbar.visible?" af-work-load-skills-scrollbar--visible":""),onPointerDown:w.handleScrollbarPointerDown,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${w.scrollbar.height}%`,top:`${w.scrollbar.top}%`}})})]}):null]})]})}function pM({row:e,index:t=0,child:n=!1}){const r=(e==null?void 0:e.issue)||{},s=vT(r),o=VU(rG(r)),a=s?o.filter(p=>!["issue","mr"].includes(sm(p))):o,l=qU(r,o),c=_i(r,t),u=s?"":Ta(r.platform),d=Array.isArray(e==null?void 0:e.children)?e.children.length:0,f=[c,s&&d?`${d} 个端侧 Issue`:u,r.status].filter(Boolean);return i.jsxs("div",{className:`af-prd-workflow-issue${n?" af-prd-workflow-issue--child":""}${s?" af-prd-workflow-issue--aggregate":""}`,children:[i.jsx("strong",{children:eG(r,t)}),i.jsx("small",{children:f.join(" · ")}),i.jsxs("div",{className:"af-prd-workflow-issue__state-row",children:[i.jsx("span",{className:`af-prd-workflow-issue__state af-prd-workflow-issue__state--${l.kind}`,children:l.label}),l.detail?i.jsx("small",{children:l.detail}):null]}),a.length?i.jsx("div",{className:"af-prd-workflow-issue__links",children:a.map(p=>i.jsx("a",{href:p.href,target:"_blank",rel:"noreferrer",children:p.label},`${p.label}-${p.href}`))}):null,d?i.jsx("div",{className:"af-prd-workflow-issue__children",children:e.children.map((p,h)=>i.jsx(pM,{row:p,index:h,child:!0},_i((p==null?void 0:p.issue)||{},h)))}):null]})}function hM(e){return e==null?"":typeof e=="string"||typeof e=="number"?String(e).trim():typeof e!="object"||Array.isArray(e)?"":String(e.label||e.name||e.value||e.key||e.code||e.username||e.userId||"").trim()}function mM(e){return(Array.isArray(e)?e:e==null||e===""?[]:[e]).map(n=>hM(n)).filter(Boolean)}function RJ({fieldKey:e,field:t}){if(!t||typeof t!="object"||Array.isArray(t))return null;const n=String(t.label||e||"").trim(),r=String(t.type||"text").trim().toLowerCase(),s=["text","user","chips","list","link"].includes(r)?r:"text",o=mM(t.value);if(!o.length)return null;if(s==="list")return i.jsxs("div",{className:"af-prd-overall-platform__rules",children:[i.jsx("small",{children:n}),i.jsx("ul",{children:o.map((a,l)=>i.jsx("li",{children:a},`${e}-${l}-${a}`))})]});if(s==="link"){const a=t.value&&typeof t.value=="object"&&!Array.isArray(t.value)?t.value:{},l=String(t.href||t.url||a.href||a.url||"").trim();return i.jsxs("div",{className:"af-prd-overall-platform__row af-prd-overall-platform__row--link",children:[i.jsx("small",{children:n}),l?i.jsxs("a",{href:l,target:"_blank",rel:"noreferrer",children:[i.jsx("span",{children:o[0]}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"})]}):i.jsx("strong",{children:o[0]})]})}return i.jsxs("div",{className:`af-prd-overall-platform__row af-prd-overall-platform__row--${s}`,children:[i.jsx("small",{children:n}),i.jsx("div",{children:o.map((a,l)=>i.jsx("span",{children:a},`${e}-${l}-${a}`))})]})}function TJ({sectionKey:e,section:t}){if(!t||typeof t!="object"||Array.isArray(t))return null;const r=(t.fields&&typeof t.fields=="object"&&!Array.isArray(t.fields)?Object.entries(t.fields):[]).filter(([,o])=>o&&typeof o=="object"&&mM(o.value).length);if(!r.length)return null;const s=e==="progress";return i.jsxs("section",{className:`af-prd-overall-platform${s?" af-prd-overall-platform--compact":""}`,children:[i.jsx("div",{className:"af-prd-overall-platform__head",children:i.jsx("strong",{children:String(t.title||e||"").trim()})}),i.jsx("div",{className:"af-prd-overall-platform__fields",children:r.map(([o,a])=>i.jsx(RJ,{fieldKey:o,field:a},o))})]})}function MJ({globalState:e,tapdId:t}){const n=e&&typeof e=="object"&&!Array.isArray(e)?e:{},r=n.workflow&&typeof n.workflow=="object"&&!Array.isArray(n.workflow)?n.workflow:{},s=n.sections&&typeof n.sections=="object"&&!Array.isArray(n.sections)?n.sections:{},o=String(n.title||"").trim(),a=String(n.url||"").trim(),l=hM(n.status),c=String(r.id||t||"").trim(),u=Object.entries(s).filter(([f,p])=>f&&p&&typeof p=="object"&&!Array.isArray(p)),d=!!(o||a||l||u.length);return!c&&!d?null:i.jsxs("article",{className:"af-prd-workflow-card af-prd-overall",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"需求概览"}),l?i.jsx("span",{className:"af-prd-overall__status",children:l}):null]}),o||a||c?i.jsx("div",{className:"af-prd-overall__requirement",children:a?i.jsxs("a",{href:a,target:"_blank",rel:"noreferrer",children:[i.jsx("strong",{children:o||`${r.namespace||"Workflow"} ${c}`}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"})]}):i.jsx("strong",{children:o||`${r.namespace==="tapd"?"TAPD":"Workflow"} ${c}`})}):null,d?i.jsx("div",{className:"af-prd-overall__platforms",children:u.map(([f,p])=>i.jsx(TJ,{sectionKey:f,section:p},f))}):i.jsx("p",{className:"af-prd-workflow-muted",children:"暂无全局状态。各阶段可通过 Workflow 上报逐步补充负责人、配置、规则和其它上下文。"})]})}function $J({flowParams:e={},tapdId:t,setTapdId:n,snapshot:r,loading:s,error:o,actionRunning:a,actionOutput:l,pendingConfirm:c,conflict:u,reviewPublishing:d,onRefresh:f,onRunDryRun:p,onConfirmAction:h,onRetryConflict:y,onPublishReview:k}){const[b,g]=m.useState("all"),[v,w]=m.useState("all"),[N,j]=m.useState(!1),[C,P]=m.useState(!1),[I,z]=m.useState(!1),[$,L]=m.useState(""),[F,O]=m.useState(!1),[M,K]=m.useState(""),[H,D]=m.useState(null),T=String((r==null?void 0:r.phase)||(t?"unavailable":"unselected")),W=Array.isArray(r==null?void 0:r.issues)?r.issues:[],E=sG(r),Q=E.reduce((xe,Fe)=>xe+sb(Fe.issues),0),V=Array.isArray(r==null?void 0:r.artifacts)?r.artifacts:[];Array.isArray(r==null?void 0:r.optionalGaps)&&r.optionalGaps;const B=r!=null&&r.nextAction&&typeof r.nextAction=="object"?r.nextAction:null,se=lG(r,B),ue=QY(r,se),G=V.filter(xe=>!NT({...xe,href:hc(xe)})),ee=m.useMemo(()=>GY(se),[se]);m.useEffect(()=>{v!=="all"&&(ee.some(xe=>xe.key===v)||w("all"))},[v,ee]);const te=se.filter(xe=>JY(xe,v)),ne=UY(te),Z=cG(r),ce=Z.filter(xe=>uG(xe,b)),de=te.filter(xe=>dv(xe)).length,me=r!=null&&r.collaboration&&typeof r.collaboration=="object"?r.collaboration:{},$e=me.activeAction&&typeof me.activeAction=="object"?me.activeAction:null;Array.isArray(r==null?void 0:r.clientObservations)&&r.clientObservations;const Ce=String((r==null?void 0:r.rawOutput)||""),_e=r!=null&&r.globalState&&typeof r.globalState=="object"?r.globalState:null,Be=FY(T),ot=m.useCallback(async()=>{const xe=String(t||"").trim();if(!xe){D(null);return}P(!0),L(""),K("");try{const Fe=new URLSearchParams({tapdId:xe});e.workflowShare&&Fe.set("workflowShare",e.workflowShare);const lt=await fetch(`/api/prd-workflow/share?${Fe.toString()}`),oe=await lt.json().catch(()=>({}));if(!lt.ok)throw new Error(oe.error||"读取 Workflow 分享状态失败");let ke=oe.share||null;const Ke=oe.canCreate===!0&&!e.workflowShare;if(O(Ke),!ke&&Ke){const Ue=await fetch("/api/prd-workflow/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,tapdId:xe})}),be=await Ue.json().catch(()=>({}));if(!Ue.ok)throw new Error(be.error||"生成 Workflow 分享链接失败");ke=be.share||null}D(ke)}catch(Fe){L(String(Fe.message||Fe))}finally{P(!1)}},[e,t]),yt=()=>{j(!0),ot()},Te=async()=>{if(!(!t||I||e.workflowShare)){z(!0),L(""),K("");try{const xe=await fetch("/api/prd-workflow/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,tapdId:t})}),Fe=await xe.json().catch(()=>({}));if(!xe.ok)throw new Error(Fe.error||"生成 Workflow 分享链接失败");D(Fe.share||null),O(!0)}catch(xe){L(String(xe.message||xe))}finally{z(!1)}}},st=async()=>{const xe=await pb((H==null?void 0:H.url)||"");K(xe?"已复制":"复制失败")},gt=async()=>{if(!(!t||I||!(H!=null&&H.canManage))){z(!0),L(""),K("");try{const xe=await fetch("/api/prd-workflow/share",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({tapdId:t})}),Fe=await xe.json().catch(()=>({}));if(!xe.ok)throw new Error(Fe.error||"取消 Workflow 分享链接失败");D(null),O(!0)}catch(xe){L(String(xe.message||xe))}finally{z(!1)}}};return i.jsxs("main",{className:"af-prd-workflow af-prd-workflow--timeline","aria-label":"PRD Workflow",children:[i.jsxs("section",{className:"af-prd-workflow__statusbar",children:[i.jsxs("div",{className:"af-prd-workflow__status-main",children:[i.jsx("span",{className:`af-prd-workflow-phase af-prd-workflow-phase--${T.toLowerCase().replace(/[^a-z0-9_-]+/gi,"_")}`,children:SC(T)}),i.jsx("h1",{children:(r==null?void 0:r.pointer)||(t?"等待 prd-flow 返回状态":"选择 TAPD 需求后读取状态")}),i.jsx("p",{className:"af-prd-workflow__status-subtitle",children:t?i.jsxs(i.Fragment,{children:["TAPD ",i.jsx("strong",{children:t})," · 独立需求 Workflow"]}):i.jsx(i.Fragment,{children:"尚未选择 TAPD 需求"})}),o?i.jsx("p",{className:"af-prd-workflow-error",children:o}):null,$e||me.subscribers?i.jsxs("div",{className:"af-prd-workflow-collab",children:[$e?i.jsxs("span",{children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"lock"}),$e.title||$e.action||"Workflow action"," 执行中",$e.userId?i.jsx("small",{children:$e.userId}):null]}):null,me.subscribers?i.jsxs("span",{children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"group"}),me.subscribers," 个连接"]}):null]}):null]}),i.jsxs("form",{className:"af-prd-workflow__lookup",onSubmit:xe=>{xe.preventDefault(),f==null||f()},children:[i.jsx("div",{className:"af-prd-workflow-flow","aria-label":"需求流程阶段",children:Be.map(xe=>i.jsxs("div",{className:`af-prd-workflow-flow__step af-prd-workflow-flow__step--${xe.status}`,children:[i.jsx("span",{"aria-hidden":"true"}),i.jsx("small",{children:xe.label})]},xe.label))}),i.jsxs("div",{className:"af-prd-workflow__lookup-row",children:[i.jsxs("label",{children:[i.jsx("span",{children:"TAPD Workflow"}),i.jsx("input",{value:t,onChange:xe=>n(xe.target.value),placeholder:"输入需求 ID",autoComplete:"off",spellCheck:!1})]}),i.jsxs("button",{type:"submit",disabled:s,children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:s?"hourglass_empty":"sync"}),s?"读取中":t?"刷新":"读取"]}),i.jsxs("button",{type:"button",disabled:!t,onClick:yt,children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"share"}),"分享"]})]})]})]}),u?i.jsxs("section",{className:"af-prd-workflow-conflict","aria-label":"Workflow conflict",children:[i.jsxs("div",{children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"sync_problem"}),i.jsxs("div",{children:[i.jsx("strong",{children:"状态已变化,需要重新确认"}),i.jsx("p",{children:u.message||"当前 workflow 状态和执行前不一致。"})]})]}),i.jsxs("dl",{children:[i.jsxs("div",{children:[i.jsx("dt",{children:"执行时 revision"}),i.jsx("dd",{children:u.expectedRevision||"空"})]}),i.jsxs("div",{children:[i.jsx("dt",{children:"当前 revision"}),i.jsx("dd",{children:u.currentRevision||"未知"})]}),i.jsxs("div",{children:[i.jsx("dt",{children:"当前状态"}),i.jsx("dd",{children:[SC(u.currentPhase),u.currentPointer].filter(Boolean).join(" · ")||"未知"})]})]}),i.jsx("div",{className:"af-prd-workflow-conflict__actions",children:i.jsx("button",{type:"button",onClick:()=>f==null?void 0:f(),disabled:s||a,children:"刷新状态"})})]}):null,i.jsxs("section",{className:"af-prd-workflow__main",children:[i.jsxs("article",{className:"af-prd-workflow-actions","aria-label":"Workflow actions",children:[i.jsxs("div",{className:"af-prd-workflow-actions__head",children:[i.jsxs("div",{children:[i.jsx("h2",{children:"Action 时间线"}),i.jsx("p",{children:se.length?`${de}/${te.length} 已完成${v!=="all"?` · 共 ${se.length}`:""}`:"等待 prd-flow 返回 action 列表"})]}),B&&Yd(B)?i.jsxs("div",{className:"af-prd-workflow-local-command",children:[i.jsx("span",{children:"本地 agent 执行"}),i.jsx("code",{children:B.command||to(B,0)})]}):null]}),ee.length?i.jsxs("div",{className:"af-prd-workflow-action-filters","aria-label":"Action tag filters",children:[i.jsxs("button",{type:"button",className:v==="all"?"is-active":"","aria-pressed":v==="all",onClick:()=>w("all"),children:["全部 ",i.jsx("span",{children:se.length})]}),ee.map(xe=>i.jsxs("button",{type:"button",className:v===xe.key?"is-active":"","aria-pressed":v===xe.key,onClick:()=>w(xe.key),children:[xe.label," ",i.jsx("span",{children:xe.count})]},xe.key))]}):null,i.jsx("div",{className:"af-prd-workflow-action-list",children:te.length?ne.map(xe=>i.jsxs("section",{className:"af-prd-workflow-action-day",children:[i.jsxs("div",{className:"af-prd-workflow-action-day__label",children:[i.jsx("span",{children:xe.day}),i.jsx("small",{children:"北京时间"})]}),i.jsx("div",{className:"af-prd-workflow-action-day__items",children:xe.items.map(({item:Fe,index:lt})=>{const oe=ca(Fe.status),ke=Zo(Fe)==="observation"&&oe==="done"?"observed":oe,Ke=pv(Fe),Ue=qY(Fe),be=XY(Fe),Ht=BY(Fe,lt),Qt=HY(Fe);return i.jsxs("div",{className:`af-prd-workflow-action af-prd-workflow-action--${ke}`,children:[i.jsx("div",{className:"af-prd-workflow-action__rail",children:i.jsx("span",{className:"af-prd-workflow-action__dot"})}),i.jsxs("div",{className:"af-prd-workflow-action__body",children:[i.jsxs("div",{className:"af-prd-workflow-action__top",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"af-prd-workflow-action__title",children:[Ue?i.jsx("time",{dateTime:um(Fe),children:Ue}):null,i.jsx("strong",{children:Ht})]}),Qt?i.jsx("p",{children:Qt}):null,be.length?i.jsx("div",{className:"af-prd-workflow-action__meta",children:be.map(jt=>i.jsxs("span",{children:[i.jsx("b",{children:jt.label}),jt.value]},`${jt.label}-${jt.value}`))}):null]}),i.jsx("span",{className:"af-prd-workflow-action__status",children:YY(Fe)})]}),Ke.length?i.jsx("div",{className:"af-prd-workflow-action__links",children:Ke.map(jt=>i.jsxs("a",{href:jt.href,target:"_blank",rel:"noreferrer",children:[i.jsx("span",{children:jt.label}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"})]},`${jt.label}-${jt.href}`))}):null]})]},Fe.id||Fe.actionId||`${to(Fe,lt)}-${lt}`)})})]},xe.day)):i.jsxs("div",{className:"af-prd-workflow-action-empty",children:[i.jsx("strong",{children:t?se.length?"当前 tag 下暂无 action":"暂无 prd-flow 上报 action":"先选择 TAPD 需求"}),i.jsx("p",{children:t?se.length?"切换到其它 tag 或查看全部。":"Workflow tab 不会生成默认步骤;需要 prd-flow snapshot 返回 actions/timeline/events/history 或 nextAction。":"选择后从 prd-flow 读取真实 action、产物和 URL。"})]})})]}),i.jsxs("aside",{className:"af-prd-workflow-side","aria-label":"Workflow related links",children:[i.jsx(MJ,{globalState:_e,tapdId:t}),G.length?i.jsxs("article",{className:"af-prd-workflow-card",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"关联产物"}),i.jsx("span",{children:G.length})]}),i.jsx("div",{className:"af-prd-workflow-list",children:G.map((xe,Fe)=>{const lt=hc(xe),oe=String(xe.label||xe.title||xe.kind||lt||`Artifact ${Fe+1}`);return lt?i.jsxs("a",{href:lt,target:"_blank",rel:"noreferrer",children:[i.jsx("span",{children:oe}),i.jsx("small",{children:xe.kind||lt})]},`${lt}-${Fe}`):i.jsxs("div",{children:[i.jsx("span",{children:oe}),i.jsx("small",{children:xe.kind||""})]},`${oe}-${Fe}`)})})]}):null,i.jsxs("article",{className:"af-prd-workflow-card",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"AI Docs"}),i.jsx("span",{children:ue.length})]}),i.jsx("div",{className:"af-prd-workflow-list",children:ue.length?ue.map(xe=>{const Fe=String(xe.title||xe.label||"ai-doc").trim(),lt=[xe.label&&xe.label!==Fe?xe.label:"",xe.platform,xe.issueKey].filter(Boolean);return i.jsxs("a",{className:"af-prd-ai-doc",href:xe.href,target:"_blank",rel:"noreferrer",title:Fe,children:[i.jsx("span",{className:"af-prd-ai-doc__title",children:Fe}),i.jsx("small",{className:"af-prd-ai-doc__meta",children:lt.join(" · ")||xe.kind||"ai-doc"})]},xe.href)}):i.jsx("p",{className:"af-prd-workflow-muted",children:"暂无 ai-doc 文档。"})})]}),i.jsxs("article",{className:"af-prd-workflow-card",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"Issues"}),i.jsx("span",{children:Q||W.length})]}),i.jsx("div",{className:"af-prd-workflow-issues",children:E.length?E.map(xe=>i.jsxs("div",{className:"af-prd-workflow-epic",children:[i.jsxs("div",{className:"af-prd-workflow-epic__head",children:[i.jsx("strong",{children:xe.title||xe.key}),i.jsx("small",{children:sb(xe.issues)})]}),xe.issues.map((Fe,lt)=>i.jsx(pM,{row:Fe,index:lt},_i((Fe==null?void 0:Fe.issue)||{},lt)))]},xe.key)):i.jsx("p",{className:"af-prd-workflow-muted",children:"暂无 Issue 信息。"})})]}),i.jsxs("article",{className:"af-prd-workflow-card",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"运行审计"}),i.jsxs("span",{children:[ce.length,"/",Z.length]})]}),i.jsx("div",{className:"af-prd-workflow-audit-filter",role:"tablist","aria-label":"运行审计筛选",children:[["all","全部"],["errors","异常"],["review","Review"],["external","外部"]].map(([xe,Fe])=>i.jsx("button",{type:"button",className:b===xe?"is-active":"",onClick:()=>g(xe),children:Fe},xe))}),i.jsx("div",{className:"af-prd-workflow-audit",children:ce.length?ce.map((xe,Fe)=>i.jsxs("div",{children:[i.jsx("strong",{children:to(xe,Fe)}),i.jsx("small",{children:[xe.status,xe.type,um(xe)].filter(Boolean).join(" · ")})]},xe.id||`${xe.type}-${Fe}`)):i.jsx("p",{className:"af-prd-workflow-muted",children:"暂无运行事件。"})})]}),Ce||l?i.jsxs("article",{className:"af-prd-workflow-card af-prd-workflow-card--raw",children:[i.jsx("div",{className:"af-prd-workflow-card__head",children:i.jsx("h2",{children:"Raw"})}),i.jsx("pre",{children:l||Ce})]}):null]})]}),N?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-share-modal af-display-link-modal",role:"dialog","aria-modal":"true","aria-label":"分享需求 Workflow",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"share"}),"分享需求 Workflow"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>j(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("p",{className:"af-display-link-modal__empty",children:["通过只读链接分享 TAPD ",t," 的需求流程;不会分享当前 Project、画布或项目文件。"]}),C?i.jsx("div",{className:"af-display-link-modal__empty",children:"正在生成分享链接..."}):null,!C&&(H!=null&&H.url)?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-display-link-modal__url",children:[i.jsx("input",{type:"text",value:H.url,readOnly:!0,onFocus:xe=>xe.currentTarget.select(),"aria-label":"Workflow 分享链接"}),i.jsxs("button",{type:"button",disabled:I,onClick:()=>void st(),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"content_copy"}),M||"复制链接"]}),H.canManage?i.jsx("button",{type:"button",disabled:I,onClick:()=>void gt(),children:I?"处理中...":"取消分享"}):null]}),i.jsx("div",{className:"af-prd-workflow-share-note",children:"获得链接的 AgentFlow 用户可以只读查看同一份 Workflow;链接不会授予需求推进或项目编辑权限。"})]}):null,!C&&!(H!=null&&H.url)&&F?i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",disabled:I,onClick:()=>void Te(),children:I?"生成中...":"生成分享链接"}):null,$?i.jsx("div",{className:"af-flow-snippet-error",children:$}):null]}),i.jsx("div",{className:"af-flow-snippet-modal__foot",children:i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",onClick:()=>j(!1),children:"完成"})})]})}),document.body):null]})}function GC(e,t){if(!(e!=null&&e[`has${t[0].toUpperCase()}${t.slice(1)}`]))return"(删除该字段)";const n=e==null?void 0:e[t];if(typeof n=="string")return n;try{return JSON.stringify(n,null,2)}catch{return String(n)}}function Ru(e){if(!(e!=null&&e.hasIncoming))return"null";try{return JSON.stringify(e.incoming,null,2)}catch{return JSON.stringify(String(e.incoming))}}function LJ(e,t,n,r=!0){const s=JSON.parse(JSON.stringify(e||{})),o=Array.isArray(t)?t:[];if(!o.length)return r?n:{};let a=s;for(let c=0;c<o.length-1;c+=1){const u=o[c],d=o[c+1];(!a[u]||typeof a[u]!="object")&&(a[u]=Number.isInteger(d)?[]:{}),a=a[u]}const l=o[o.length-1];return r?a[l]=n:Array.isArray(a)&&Number.isInteger(l)?a.splice(l,1):delete a[l],s}function OJ(){var b0,k0,v0;const{t:e,i18n:t}=Fr(),{navigate:n}=si(),r=Fc(),s=gn(),o=IW(),a=m.useMemo(CY,[]),l=!!a.workflowShare,c=m.useRef(new URLSearchParams(window.location.search).get("focusNodeId")||""),u=m.useMemo(()=>a.workspaceId?`agentflow.workspace.viewport:shared:${a.workspaceId}`:`agentflow.workspace.viewport:${a.flowSource||"user"}:${a.flowId||""}`,[a]),[d,f]=m.useState(()=>(()=>{if(a.workflowShare)return"workflow";const x=new URLSearchParams(window.location.search).get("view");return x==="display"||x==="workflow"?x:"workspace"})()),[p,h]=m.useState(!1),[y,k]=m.useState(!1),[b,g]=RW([]),[v,w]=TW([]),N=m.useRef([]),j=m.useRef([]),C=m.useRef(null),[P,I]=m.useState(()=>hh(null,[])),z=m.useRef(P),[$,L]=m.useState(null),F=m.useRef(null),O=m.useRef(!1),[M,K]=m.useState([]),H=m.useRef(new Map),D=m.useRef(new Map),T=m.useRef(new Set),W=m.useRef(new Set),E=m.useRef(null),Q=m.useRef(null),V=m.useRef([]),B=m.useRef(null),se=m.useRef(null),ue=m.useRef(null),[G,ee]=m.useState(null),[te,ne]=m.useState({}),Z=m.useRef({}),ce=m.useRef(!1),de=m.useRef(null),me=m.useRef(""),$e=m.useRef(null),Ce=m.useRef(Promise.resolve()),_e=m.useRef({running:!1,pending:null}),Be=m.useRef(0),ot=m.useRef(!1),yt=m.useRef(0),Te=m.useRef(null),st=m.useRef(!1),gt=m.useRef(!1),xe=m.useRef(""),Fe=m.useRef(!1),lt=m.useRef(!1),oe=m.useRef(!1),ke=m.useRef(typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`client-${Date.now()}-${Math.random().toString(36).slice(2)}`),Ke=m.useRef(!1),Ue=m.useRef(null),[be,Ht]=m.useState([]),Qt=m.useRef([]),[jt,yn]=m.useState(""),[on,re]=m.useState("nodes"),[Re,Je]=m.useState([]),[Ze,Tt]=m.useState(!1),[At,Vn]=m.useState(""),[Sn,xr]=m.useState(!1),[wn,Xn]=m.useState({name:"",id:"",description:""}),[Kn,hr]=m.useState(!1),[ts,Ar]=m.useState(""),[gs,ys]=m.useState(""),cn=m.useRef(null),[rr,Pr]=m.useState(!1),[dn,Qn]=m.useState(!1),[br,sr]=m.useState(""),[Ct,Gt]=m.useState(null),[_t,le]=m.useState(()=>lw()),[ve,it]=m.useState(""),[Dt,Jt]=m.useState(!1),[tn,Zn]=m.useState(""),[mt,nn]=m.useState(!1),[Wt,kr]=m.useState([]),[tt,Ln]=m.useState(!1),[$i,zr]=m.useState(""),[mo,ai]=m.useState(""),[Ts,ie]=m.useState(""),[Se,Pe]=m.useState(!1),[xt,Lt]=m.useState(""),[qt,zn]=m.useState(""),[On,q]=m.useState(!1),[pe,Oe]=m.useState("nodes"),[Ee,et]=m.useState(""),[Nn,kt]=m.useState(0),[Ut,jn]=m.useState(""),go=m.useRef(""),[at,ws]=m.useState(null),Rv=m.useRef(null),[l$,al]=m.useState(""),[ll,Tv]=m.useState([]),[Mv,c$]=m.useState(""),[je,u$]=m.useState(!0),[an,gg]=m.useState(null),[d$,yg]=m.useState(!1),[wg,$v]=m.useState(!1),[Lv,Yc]=m.useState(""),[Gc,Ov]=m.useState(""),[Dv,Fv]=m.useState(""),[En,cl]=m.useState(null),[f$,ua]=m.useState(!1),[xg,ul]=m.useState({}),[vf,zv]=m.useState(!1),[Bv,Jc]=m.useState(""),[bg,p$]=m.useState(""),[h$,dl]=m.useState(()=>new Set),[kg,vg]=m.useState(""),[Xc,Sg]=m.useState({nodeId:"",query:""}),[Hv,Wv]=m.useState(!1),Ng=m.useRef(null),Vv=m.useRef(null),Kv=m.useRef(""),[jg,qv]=m.useState(()=>{try{const x=Number(window.localStorage.getItem("agentflow.workspace.filesPaneHeight")||0);if(Number.isFinite(x)&&x>=160)return x}catch{}return 360}),[m$,Uv]=m.useState(!1),[da,g$]=m.useState({cursor:[],opencode:[],claudeCode:[],codex:[]}),[Li,y$]=m.useState(""),[Ms,w$]=m.useState([]),[Yv,Gv]=m.useState(!1),[$s,Qc]=m.useState([]),[fl,x$]=m.useState([]),[Jv,b$]=m.useState(!1),[Xv,Qv]=m.useState([]),[Zv,eS]=m.useState([]),[ir,k$]=m.useState(()=>{try{const x=String(new URLSearchParams(window.location.search).get("tapdId")||"").trim();return x||String(window.localStorage.getItem(`agentflow.workflow.tapdId:${a.flowSource||"user"}:${a.flowId||""}`)||"").trim()}catch{return""}}),[ln,Sf]=m.useState(null),[v$,tS]=m.useState(!1),[S$,pl]=m.useState(""),[Cg,nS]=m.useState(!1),[_g,Nf]=m.useState(""),[xs,jf]=m.useState(null),[Eg,rS]=m.useState(!1),[Zc,eu]=m.useState(null),sS=m.useCallback(x=>{cn.current&&window.clearTimeout(cn.current),ys(x),cn.current=window.setTimeout(()=>{ys(""),cn.current=null},3800)},[]),Br=m.useCallback(x=>{const S=Array.isArray(x)||x instanceof Set?x:[x];for(const _ of S){const A=String(_||"").trim();A&&(T.current.add(A),W.current.add(A))}T.current.size!==0&&(E.current==null&&(E.current=window.requestAnimationFrame(()=>{E.current=null;const _=Array.from(T.current);T.current.clear(),_.forEach(A=>o(A))})),Q.current!=null&&window.clearTimeout(Q.current),Q.current=window.setTimeout(()=>{Q.current=null;const _=Array.from(W.current);W.current.clear(),_.forEach(A=>o(A))},80))},[o]);m.useEffect(()=>()=>{E.current!=null&&window.cancelAnimationFrame(E.current),Q.current!=null&&window.clearTimeout(Q.current),T.current.clear(),W.current.clear()},[]);const iS=m.useCallback((x,S)=>{const _=String(x||"").trim(),A=mm(S);!_||!A||(g(R=>R.map(U=>{var ae;if(U.id!==_)return U;const X=mm((ae=U.data)==null?void 0:ae.displaySize),J=X&&X.width===A.width&&X.height===A.height,Y=Math.round(Number(U.width||0))===A.width&&Math.round(Number(U.height||0))===A.height;return J&&Y?U:{...U,width:A.width,height:A.height,data:{...U.data,nodeSize:A,displaySize:A}}})),Br(_))},[Br,g]);m.useEffect(()=>{try{window.localStorage.setItem("agentflow.workspace.filesPaneHeight",String(Math.round(jg)))}catch{}},[jg]);const Ag=m.useCallback(x=>{const S=Ng.current;if(!S)return null;const _=S.getBoundingClientRect(),A=16,R=150,U=230,X=_.top+A,J=_.bottom-A,Y=Math.max(R,J-X-U);return Math.min(Math.max(x-X,R),Y)},[]),N$=m.useCallback(x=>{x.preventDefault(),x.stopPropagation();const S=Ng.current;if(!S)return;let _=Ag(x.clientY);if(!Number.isFinite(_))return;Uv(!0),qv(_);const A=U=>{U.preventDefault();const X=Ag(U.clientY);Number.isFinite(X)&&(_=X,S.style.setProperty("--af-work-files-pane-height",`${Math.round(X)}px`))},R=()=>{qv(_),Uv(!1),window.removeEventListener("pointermove",A,!0),window.removeEventListener("pointerup",R,!0),window.removeEventListener("pointercancel",R,!0)};window.addEventListener("pointermove",A,!0),window.addEventListener("pointerup",R,!0),window.addEventListener("pointercancel",R,!0)},[Ag]);m.useEffect(()=>()=>{cn.current&&window.clearTimeout(cn.current),Ue.current&&window.clearTimeout(Ue.current)},[]);const[j$,oS]=m.useState(()=>new Set),[Cf,Pg]=m.useState(!1),Ig=m.useRef(null),aS=m.useRef(null),lS=m.useRef(null),[C$,_$]=m.useState({}),[fa,Rg]=m.useState(""),[ns,cS]=m.useState(!1),[pa,hl]=m.useState([]),[Ls,qn]=m.useState([]),[Hr,bs]=m.useState("workspace"),[tu,ml]=m.useState(!1),uS=m.useRef(null),Tg=m.useRef(null),[nu,gl]=m.useState(null),[E$,Mg]=m.useState(!0),[dS,fS]=m.useState(""),[ha,yo]=m.useState({}),[Ir,pS]=m.useState(null),[hS,mS]=m.useState(!1),yl=m.useMemo(()=>hS?IY(Ir):"",[hS,Ir]),[ru,_f]=m.useState(!0);m.useEffect(()=>{yl&&_f(RY(yl))},[yl]),m.useEffect(()=>{if(yl)try{window.localStorage.setItem(yl,ru?"true":"false")}catch{}},[ru,yl]);const[$g,Ef]=m.useState(!1),[Lg,gS]=m.useState(!1),[Og,yS]=m.useState("pan"),[wS,A$]=m.useState({}),su=m.useRef({}),[xS,ma]=m.useState({}),iu=m.useRef(new Map),ou=m.useRef(new Set),[bS,wl]=m.useState(()=>new Set),[Dg,xl]=m.useState({}),[kS,vS]=m.useState(""),[Nce,ge]=m.useState(""),[SS,Os]=m.useState("loading"),[NS,Ds]=m.useState("正在载入 Project"),Oi=m.useMemo(()=>PY(a),[a]),[jS,CS]=m.useState(""),au=a.flowSource||"user",_S=m.useMemo(()=>new Set(Object.values(wS||{}).map(x=>String((x==null?void 0:x.runNodeId)||"").trim()).filter(Boolean)),[wS]),Di=m.useCallback(x=>{const S=su.current||{},_=typeof x=="function"?x(S):x,A=_&&typeof _=="object"&&!Array.isArray(_)?_:{};return su.current=A,A$(A),A},[]),ES=!!(a.flowId&&!a.archived&&(an!=null&&an.role?an.role==="owner":au==="user"||au==="workspace")),lu=!!(au==="workspace"&&(an!=null&&an.role)&&an.role!=="owner"),AS={loading:"载入中",dirty:"有未同步修改",saving:"同步中",synced:"已同步",conflict:"同步冲突",error:"同步失败",readonly:"只读"}[SS]||"同步状态",li=m.useCallback(()=>{!ce.current||!je||(Fe.current=!1,Be.current+=1,ot.current=!0,Os("dirty"),Ds("本地修改等待同步"))},[je]);m.useEffect(()=>{a.flowId&&mF(a.flowId,a.flowSource||"user","workspace",!!a.archived)},[a]),m.useEffect(()=>{const x=()=>{f(new URLSearchParams(window.location.search).get("view")==="display"?"display":"workspace")};return window.addEventListener("popstate",x),()=>window.removeEventListener("popstate",x)},[]),m.useEffect(()=>{hl([]),qn([]),bs("workspace"),Mg(!0)},[a]);const An=m.useCallback(async()=>{const x=Tr(a),S=await fetch(`/api/workspace/files?${x.toString()}`),_=await S.json();if(!S.ok)throw new Error(_.error||"读取 workspace 失败");const A=_.files||[];Tv(A),dl(new Set(rM(A))),c$(_.root||"")},[a]),Af=m.useCallback(async()=>{Tt(!0),Vn("");try{const x=await fetch("/api/marketplace/flow-snippets"),S=await x.json().catch(()=>({}));if(!x.ok)throw new Error(S.error||"读取流程片段失败");Je(Array.isArray(S.snippets)?S.snippets:[])}catch(x){Vn(String(x.message||x)),Je([])}finally{Tt(!1)}},[]),PS=m.useCallback(async(x,S,_)=>{var Y,ae,he;if(!ce.current)return;if(!je)throw ge("Readonly workspace"),Os("readonly"),Ds("只读 Project"),new Error("Readonly workspace");Os("saving"),Ds("正在同步修改");const A=Ml(x,S,Z.current);A.ui={...A.ui||{},displayPage:TC(z.current,x)};const R=await fetch("/api/workspace/graph",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,graph:A,baseRevision:me.current,baseGraph:$e.current,clientId:ke.current})}),U=await R.json().catch(()=>({}));if(!R.ok){if(R.status===409||R.status===428){const Ne=Array.isArray(U.conflictItems)?U.conflictItems:[];cl({currentRevision:String(U.currentRevision||""),message:U.error||"Workspace 已被其他成员更新",conflictPaths:Array.isArray(U.conflictPaths)?U.conflictPaths:[],conflictItems:Ne,mergeGraph:U.mergeGraph||null,currentGraph:U.currentGraph||null}),ul(Object.fromEntries(Ne.map((He,Me)=>[String(Me),{mode:"local",manual:Ru(He)}]))),Jc(""),ua(Ne.length>0),Os("conflict"),Ds(U.error||"存在需要处理的字段冲突");const We=Array.isArray(U.conflictPaths)?U.conflictPaths:[],ze=We.length?`${U.error||"Workspace 已被其他成员更新"}:${We.join("、")}`:U.error||"Workspace 已被其他成员更新",Ve=new Error(ze);throw Ve.code="WORKSPACE_REVISION_CONFLICT",Ve.currentRevision=U.currentRevision||"",Ve}const fe=new Error(U.error||"保存 workspace graph 失败");throw Os("error"),Ds(fe.message),fe}const X=Be.current!==_,J=aY({savedGraph:U.graph,sentGraph:A,savedRevision:U.revision,currentRevision:me.current});if(me.current=J.revision,$e.current=J.graph,!X){if(Z.current=((Y=U.graph)==null?void 0:Y.instances)||A.instances,ne(Z.current),U.merged&&U.graph){const fe=Iu(U.graph,be),Ne=hh((he=(ae=U.graph)==null?void 0:ae.ui)==null?void 0:he.displayPage,fe.nodes);Z.current=fe.instances,ne(fe.instances),g(fe.nodes),w(fe.edges),z.current=Ne,I(Ne)}ot.current=!1}return ma(Lp(U.workspaceSchedules||[])),cl(null),ua(!1),Os(X?"dirty":"synced"),Ds(X?"本地仍有修改等待同步":"所有修改已同步"),ge(X?"已保存上一版,本地新修改正在排队":U.merged?"Workspace graph merged and saved":"Workspace graph saved"),U},[a,be,w,g,je]),Zt=m.useCallback((x=b,S=v)=>{const _=_e.current,A={nextNodes:x,nextEdges:S,saveEditVersion:Be.current,waiters:[]},R=new Promise((J,Y)=>{A.waiters.push({resolve:J,reject:Y})});if(_.running)return _.pending=xC(_.pending,A),R;_.running=!0;const U=async()=>{let J=A;for(;J;){_.pending&&(J=xC(J,_.pending),_.pending=null);try{const Y=await PS(J.nextNodes,J.nextEdges,J.saveEditVersion);J.waiters.forEach(({resolve:ae})=>ae(Y))}catch(Y){(Y==null?void 0:Y.code)!=="WORKSPACE_REVISION_CONFLICT"&&(Os("error"),Ds(String(Y.message||Y))),J.waiters.forEach(({reject:ae})=>ae(Y)),(Y==null?void 0:Y.code)==="WORKSPACE_REVISION_CONFLICT"&&_.pending&&(_.pending.waiters.forEach(({reject:ae})=>ae(Y)),_.pending=null)}J=_.pending,_.pending=null}_.running=!1},X=Ce.current.catch(()=>{}).then(U);return Ce.current=X,R},[v,b,PS]),P$=m.useCallback(x=>{var _;const S=(_=x==null?void 0:x.extra)!=null&&_.instances&&typeof x.extra.instances=="object"?x.extra.instances:{};Z.current=S,ne(S),g(Array.isArray(x==null?void 0:x.nodes)?x.nodes:[]),w(Array.isArray(x==null?void 0:x.edges)?x.edges:[]),jn(""),ee(null)},[w,g]),I$=m.useMemo(()=>({instances:te}),[te]),R$=zU({nodes:b,edges:v,extra:I$,enabled:ce.current,onRestore:P$}),{resetHistory:cu,undo:IS,redo:RS}=R$,ks=m.useCallback(async(x={})=>{var Le,Mt;const S=(x==null?void 0:x.background)===!0,_=yt.current+1;yt.current=_;const A=Be.current,R=me.current;S||(ce.current=!1);const U=pY({background:S}),X=Tr(a);let J=null,Y;if(!U.nodes&&!U.files)Y=await fetch(`/api/workspace/graph?${X.toString()}`);else{const De=Tr(a);De.set("lang",String(t.language||"zh").startsWith("zh")?"zh":"en");const[dt,Pt]=await Promise.all([fetch(`/api/nodes?${De.toString()}`),fetch(`/api/workspace/graph?${X.toString()}`),An()]);if(J=await dt.json(),!dt.ok)throw new Error(J.error||"读取节点定义失败");Y=Pt}const ae=await Y.json();if(!Y.ok)throw new Error(ae.error||"读取 workspace graph 失败");const he=oY({background:S,requestId:_,currentRequestId:yt.current,dirty:ot.current,startedEditVersion:A,currentEditVersion:Be.current,startedRevision:R,currentRevision:me.current});if(he==="superseded")return{skipped:!0,reason:he};if(he==="local-edits")return ge("检测到远端更新;本地修改将在保存时自动合并"),{skipped:!0,reason:he};const fe=S?Qt.current:[...(Array.isArray(J)?J:J.nodes||[]).filter(De=>!gY.has(De.id)),vY,kY,xY,bY,yY,wY];S||(Qt.current=fe,Ht(fe));const Ne=ae.graph||JSON.parse(localStorage.getItem(mY)||"null")||{},We=Iu(Ne,fe),ze=hh((Le=Ne==null?void 0:Ne.ui)==null?void 0:Le.displayPage,We.nodes),Ve=!O.current;let He=F.current;if(Ve){let De=null;try{De=JSON.parse(window.localStorage.getItem(u)||"null")}catch{De=null}He=fb(De)||fb((Mt=Ne==null?void 0:Ne.ui)==null?void 0:Mt.viewport)}const Me=S?nY($e.current,Ne):null;if(S&&(Me!=null&&Me.safe)){const De=Me.nodesChanged?rY(N.current,We.nodes,Me.changedNodeIds):N.current,dt=Me.edgesChanged?sY(j.current,We.edges):j.current,Pt=Me.displayPageChanged||!eo(z.current,ze),_l=Me.nodesChanged||Me.edgesChanged||Pt;if(_l&&(Fe.current=!0),Me.nodesChanged){const ci=iY(Z.current,We.instances,Me.changedNodeIds);Z.current=ci,N.current=De,ne(ci),g(De)}if(Me.edgesChanged&&(j.current=dt,w(dt)),Pt&&(z.current=ze,I(ze)),_l&&cu(De,dt,{instances:Me.nodesChanged?Z.current:We.instances}),Me.nodesChanged||Pt){const ci=new Set(ze.nodeIds);K(wa=>{const xa=wa.filter(Uf=>ci.has(Uf));return xa.length===wa.length?wa:xa})}}else Z.current=We.instances,N.current=We.nodes,j.current=We.edges,z.current=ze,Fe.current=!0,ne(We.instances),g(We.nodes),w(We.edges),I(ze),K([]),cu(We.nodes,We.edges,{instances:We.instances});const Ft=Lp(ae.workspaceSchedules||[]);ma(De=>eo(De,Ft)?De:Ft),me.current=String(ae.revision||""),$e.current=Ne,ot.current=!1;const rt=ae.collaboration||null;gg(De=>eo(De,rt)?De:rt),cl(null),Ve&&(L(He),F.current=He,O.current=!0);const Ye=ae.writable!==!1;return u$(Ye),ge(Ye?"Workspace ready":"Readonly workspace"),Os(Ye?"synced":"readonly"),Ds(Ye?"所有修改已同步":"只读 Project"),ce.current=!0,{skipped:!1}},[a,t.language,An,cu,w,g,u]),Pf=m.useCallback((x={})=>{if(!ce.current)return;const S=String(x.revision||""),_=x.type==="graph.committed",A=!!(Te.current||st.current||gt.current);if(hY({eventType:x.type,revision:S,currentRevision:me.current,targetRevision:xe.current,refreshPending:A}))return;if(_&&S&&(xe.current=S),ot.current){gt.current=!1,ge("检测到其他成员的更新;保存时将自动合并");return}if(gt.current=!0,Te.current||st.current)return;const R=async()=>{if(Te.current=null,lt.current){gt.current=!0,Te.current=window.setTimeout(R,80);return}if(ot.current){gt.current=!1,ge("检测到其他成员的更新;保存时将自动合并");return}gt.current=!1,st.current=!0;try{await ks({background:!0}),xe.current=me.current}catch(U){xe.current="",ge(String(U.message||U))}finally{st.current=!1,gt.current&&!ot.current&&(Te.current=window.setTimeout(R,40))}};Te.current=window.setTimeout(R,40)},[ks]),uu=m.useCallback(async(x=ir)=>{const S=String(x||"").trim();tS(!0),pl("");try{const _=Tr(a);_.set("tapdId",S),_.set("runtimeOnly","1");const A=await fetch(`/api/prd-workflow/snapshot?${_.toString()}`),R=await A.json().catch(()=>({}));if(!A.ok)throw new Error(R.error||"读取 PRD Workflow 失败");Sf(R.snapshot||null),Nf(""),jf(null),eu(null);try{const U=`agentflow.workflow.tapdId:${a.flowSource||"user"}:${a.flowId||""}`;S?window.localStorage.setItem(U,S):window.localStorage.removeItem(U)}catch{}}catch(_){pl(String(_.message||_))}finally{tS(!1)}},[a,ir]),bl=m.useCallback(async(x=null,S={})=>{const _=x&&typeof x=="object"?x:ln==null?void 0:ln.nextAction,A=Yd(_);if(!A||Cg)return;const R=(S==null?void 0:S.confirm)===!0,U=String((S==null?void 0:S.expectedRevision)||(ln==null?void 0:ln.revision)||"");nS(!0),pl(""),R||(Nf(""),jf(null),eu(null));try{const X=await fetch("/api/prd-workflow/action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,tapdId:ir,action:A,stage:el(_),title:to(_,0),...ZY(_),dryRun:!R,confirm:R,issueKey:_.issueKey||_.issue_key||"",expectedRevision:U,idempotencyKey:`workflow-${Date.now()}-${Math.random().toString(36).slice(2)}`})}),J=await X.json().catch(()=>({}));if(!X.ok||J.ok===!1)throw J.snapshot&&Sf(J.snapshot),J.conflict&&eu({...J.conflict,action:_}),new Error(J.error||"执行 PRD Workflow action 失败");Nf(J.rawOutput||(J.output?JSON.stringify(J.output,null,2):"")),Sf(J.snapshot||ln),eu(null),jf(R?null:{action:_,output:J.output||null,expectedRevision:U,at:new Date().toISOString()})}catch(X){pl(String(X.message||X))}finally{nS(!1)}},[a,Cg,ln,ir]),T$=m.useCallback((x=null)=>bl(x,{confirm:!1}),[bl]),M$=m.useCallback(()=>{const x=(xs==null?void 0:xs.action)||(ln==null?void 0:ln.nextAction);return bl(x,{confirm:!0,expectedRevision:(xs==null?void 0:xs.expectedRevision)||""})},[bl,xs,ln]),$$=m.useCallback(()=>{const x=(Zc==null?void 0:Zc.action)||(ln==null?void 0:ln.nextAction);return eu(null),bl(x,{confirm:!1})},[bl,Zc,ln]),L$=m.useCallback(async()=>{var U;const x=String(_g||(ln==null?void 0:ln.rawOutput)||"").trim();if(!x||Eg)return;const S=(xs==null?void 0:xs.action)||(ln==null?void 0:ln.nextAction)||{},_=`Review: ${to(S,0)||(ln==null?void 0:ln.pointer)||ir||"PRD Workflow"}`,A=/^[\[{]/.test(x),R=x.startsWith("#")?x:`# ${_}
245
+ `:"",$=`${C}${I}${g}${z}${P}`;t==null||t($),window.requestAnimationFrame(()=>{var F,O;const L=C.length+I.length+g.length;(F=s.current)==null||F.focus(),(O=s.current)==null||O.setSelectionRange(L,L)})},[t,e]),b=m.useCallback(async g=>{if(!r&&!(!g||l)){c(!0);try{const v=await(n==null?void 0:n(g)),w=String(v||"").trim();if(w){const N=String(g.name||"image").replace(/\.[^.]+$/g,"").trim()||"image";k(`![${N}](${w})`)}}finally{c(!1)}}},[k,n,r,l]);return i.jsxs("div",{className:"af-work-display-editor nodrag nopan",onClick:g=>g.stopPropagation(),onDragOver:g=>{var w;Array.from(((w=g.dataTransfer)==null?void 0:w.items)||[]).some(N=>String((N==null?void 0:N.type)||"").startsWith("image/"))&&(g.preventDefault(),g.dataTransfer.dropEffect="copy")},onDrop:g=>{var w;const v=Array.from(((w=g.dataTransfer)==null?void 0:w.files)||[]).find(cm);v&&(g.preventDefault(),b(v))},children:[i.jsxs("div",{className:"af-work-display-editor__toolbar",children:[i.jsx("button",{type:"button",className:"af-work-display-card__action",disabled:l||r,onClick:()=>{var g;return(g=o.current)==null?void 0:g.click()},"aria-label":"上传图片",title:"上传图片",children:i.jsx("span",{className:"material-symbols-outlined",children:l?"hourglass_top":"add_photo_alternate"})}),i.jsx("input",{ref:o,className:"af-hidden-file-input",type:"file",accept:"image/*",onChange:g=>{var w;const v=(w=g.target.files)==null?void 0:w[0];g.target.value="",v&&b(v)}})]}),i.jsx("textarea",{ref:s,className:"af-work-display-editor__textarea",value:e,onChange:g=>t==null?void 0:t(g.target.value),onScroll:f,onKeyDown:g=>{g.key==="Escape"&&g.stopPropagation()},placeholder:"输入 Markdown 内容",spellCheck:!1,readOnly:r}),i.jsx("div",{ref:a,className:"af-work-display-editor__scrollbar"+(u.visible?" af-work-display-editor__scrollbar--visible":""),onPointerDown:y,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${u.height}%`,top:`${u.top}%`}})})]})}function eJ({nodeId:e,data:t}){const n=t==null?void 0:t.nodeChatActive,r=!!(t!=null&&t.selected),s=(t==null?void 0:t.nodeChat)||{},o=Array.isArray(s.messages)?s.messages:[],a=String(s.draft||""),[l,c]=m.useState(a),u=m.useRef(!1),d=String(s.candidateContent||""),f=!!s.running,p=!!(t!=null&&t.readOnly),h=String(s.error||""),y=o.slice(-2);return m.useEffect(()=>{u.current||c(a)},[a]),!n&&!r?null:n?i.jsxs("div",{className:"af-work-node-chat nodrag nopan",onClick:k=>k.stopPropagation(),children:[i.jsxs("div",{className:"af-work-node-chat__head",children:[i.jsxs("div",{children:[i.jsx("strong",{children:"继续微调"}),i.jsx("span",{children:(t==null?void 0:t.label)||e})]}),i.jsx("button",{type:"button",onClick:()=>{var k;return(k=t==null?void 0:t.onCloseNodeChat)==null?void 0:k.call(t)},"aria-label":"关闭节点微调",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),o.length>0||f||h?i.jsxs("div",{className:"af-work-node-chat__messages",children:[y.map((k,b)=>i.jsxs("div",{className:`af-work-node-chat__msg af-work-node-chat__msg--${k.role==="assistant"?"assistant":"user"}`,children:[i.jsx("span",{children:k.role==="assistant"?"AI":"你"}),i.jsx("p",{children:k.text})]},`${k.at||b}-${b}`)),f?i.jsx("div",{className:"af-work-node-chat__pending",children:"生成中..."}):null,h?i.jsx("div",{className:"af-work-node-chat__error",children:h}):null]}):null,i.jsxs("div",{className:"af-work-node-chat__composer",children:[i.jsx("button",{type:"button",className:"af-work-node-chat__add",disabled:f||p,"aria-label":"添加上下文",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"})}),i.jsx("textarea",{className:"af-work-node-chat__input",rows:2,value:l,disabled:f||p,placeholder:"描述你想怎么调整这个展示",onCompositionStart:()=>{u.current=!0},onCompositionEnd:k=>{var g;u.current=!1;const b=k.currentTarget.value;c(b),(g=t==null?void 0:t.onUpdateNodeChatDraft)==null||g.call(t,e,b)},onChange:k=>{var g;const b=k.target.value;c(b),u.current||(g=t==null?void 0:t.onUpdateNodeChatDraft)==null||g.call(t,e,b)},onKeyDown:k=>{var b,g;k.isComposing||(b=k.nativeEvent)!=null&&b.isComposing||k.keyCode===229||(k.metaKey||k.ctrlKey)&&k.key==="Enter"&&(k.preventDefault(),(g=t==null?void 0:t.onSendNodeChat)==null||g.call(t,e,l))}}),i.jsx("button",{type:"button",className:"af-work-node-chat__send",disabled:f||p||!l.trim(),onClick:()=>{var k;return(k=t==null?void 0:t.onSendNodeChat)==null?void 0:k.call(t,e,l)},"aria-label":"发送",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"arrow_upward"})})]}),d.trim()?i.jsx("div",{className:"af-work-node-chat__messages",children:i.jsxs("div",{className:"af-work-node-chat__msg af-work-node-chat__msg--assistant",children:[i.jsx("span",{children:"AI"}),i.jsx("p",{children:d})]})}):null]}):i.jsxs("button",{type:"button",className:"af-work-node-chat-anchor nodrag nopan",onClick:k=>{var b;k.stopPropagation(),(b=t==null?void 0:t.onToggleNodeChat)==null||b.call(t,e)},title:"微调这个节点","aria-label":"微调这个节点",children:[i.jsx("span",{className:"material-symbols-outlined af-work-node-chat-anchor__plus","aria-hidden":!0,children:"add"}),i.jsx("span",{className:"af-work-node-chat-anchor__label",children:"继续微调这个展示"}),i.jsx("span",{className:"material-symbols-outlined af-work-node-chat-anchor__expand","aria-hidden":!0,children:"open_in_full"})]})}function tJ(e){return e==="mermaid"?"mmd":e==="ascii"?"txt":e==="html"?"html":e==="react"?"json":e==="image"?"txt":e==="chart"||e==="table"?"json":"md"}function nJ(e){return String(e).trim().toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)||"display"}function rJ(e){return String(e||"node").trim().replace(/[^a-zA-Z0-9._-]+/g,"_").replace(/^_+|_+$/g,"").slice(0,120)||"node"}function DC(e,t=""){const n=ea(e,t).replace(/^\/+/,"");return n.startsWith("outputs/")?n:""}function sJ(e,t){const n=rJ(e),r=new Set,s=In(t)||"";ei(t==null?void 0:t.definitionId)&&r.add(`outputs/${n}`);const o=DC(no(t),s);return o&&r.add(o),(Array.isArray(t==null?void 0:t.outputs)?t.outputs:[]).some(c=>{const u=String((c==null?void 0:c.value)??(c==null?void 0:c.default)??"").trim().replace(/^\/+/,""),d=DC(u,s);return d&&r.add(d),u===`outputs/${n}`||u.startsWith(`outputs/${n}/`)})&&r.add(`outputs/${n}`),Array.from(r)}function FC(e,t){const n=In(t)||"markdown";return`outputs/${nJ((t==null?void 0:t.label)||e||n)}.${tJ(n)}`}async function eM({nodeId:e,data:t,filePath:n,content:r,setFileContent:s}){var o,a;if(n){const l=await hb((t==null?void 0:t.flowParams)||{},n,r);s==null||s(r),(o=t==null?void 0:t.onSetDisplayNodeContent)==null||o.call(t,e,l,"replace",{logChat:!1,reloadDisplay:!0,statusMessage:`已更新 ${l}`});return}(a=t==null?void 0:t.onSetDisplayNodeContent)==null||a.call(t,e,r,"replace",{logChat:!1,statusMessage:"已更新 Markdown 内容"})}function tM({id:e,data:t,selected:n,deleteNode:r}){var ee,te,ne;const s=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],a=(Array.isArray(t==null?void 0:t.outputs)?t.outputs:[]).map((Z,ce)=>({slot:Z,idx:ce})).sort((Z,ce)=>{var _e,Be,ot,yt;const de=String(((_e=Z.slot)==null?void 0:_e.name)||"").trim(),me=String(((Be=ce.slot)==null?void 0:Be.name)||"").trim();if(de==="next"&&me!=="next")return-1;if(me==="next"&&de!=="next")return 1;const $e=String(((ot=Z.slot)==null?void 0:ot.type)||"").trim(),Ce=String(((yt=ce.slot)==null?void 0:yt.type)||"").trim();return $e==="node"&&Ce!=="node"?-1:Ce==="node"&&$e!=="node"?1:Z.idx-ce.idx}),l=In(t),c=m.useRef(null),u=m.useRef(null),[d,f]=m.useState(0),[p,h]=m.useState(!1),[y,k]=m.useState(!1),[b,g]=m.useState(!1),[v,w]=m.useState(""),[N,j]=m.useState(""),[C,P]=m.useState(!1),[I,z]=m.useState(!1),$=m.useRef(null),L=no(t),F=l==="markdown"?Ei(L):"",O=l==="markdown"?ea(F,"markdown"):"",M=l==="markdown"?O?N:F:"",K=!!(t!=null&&t.readOnly),H=!!(t!=null&&t.displayPageMode);m.useEffect(()=>{let Z=!1;return l!=="markdown"||!O?(j(""),P(!1),()=>{Z=!0}):(P(!0),nl((t==null?void 0:t.flowParams)||{},O).then(ce=>{Z||j(ce)}).catch(ce=>{var de;Z||(j(""),(de=t==null?void 0:t.onStatus)==null||de.call(t,String(ce.message||ce)))}).finally(()=>{Z||P(!1)}),()=>{Z=!0})},[l,O,(ee=t==null?void 0:t.flowParams)==null?void 0:ee.flowId,(te=t==null?void 0:t.flowParams)==null?void 0:te.flowSource,(ne=t==null?void 0:t.flowParams)==null?void 0:ne.archived,t==null?void 0:t.displayReloadKey]),m.useEffect(()=>{if(!y)return;const Z=()=>k(!1);return window.addEventListener("pointerup",Z,!0),window.addEventListener("pointercancel",Z,!0),window.addEventListener("mouseup",Z,!0),window.addEventListener("blur",Z),()=>{window.removeEventListener("pointerup",Z,!0),window.removeEventListener("pointercancel",Z,!0),window.removeEventListener("mouseup",Z,!0),window.removeEventListener("blur",Z)}},[y]),m.useEffect(()=>{b||w(String(M||""))},[M,b]);const D=(t==null?void 0:t.label)||(l==="mermaid"?"Mermaid":l==="ascii"?"ASCII":l==="html"?"HTML":l==="react"?"React App":l==="image"?"Image":l==="chart"?"Chart":l==="table"?"Table":"Markdown"),T=String((t==null?void 0:t.sourceNodeId)||e),W=(t==null?void 0:t.sharingDisplayNodeId)===T,E=t!=null&&t.displaySize&&Number(t.displaySize.width)>0&&Number(t.displaySize.height)>0?{width:Number(t.displaySize.width),height:Number(t.displaySize.height)}:null,Q=m.useCallback(async()=>{var Te,st,gt,xe,Fe,lt,oe,ke,Ke,Ue;if(l!=="html"||p)return;const Z=no(t),ce=ea(Z,l);let de=Z;if(ce)try{de=await nl((t==null?void 0:t.flowParams)||{},ce)}catch(be){h(!1),console.warn("Failed to read HTML display file before saving image.",be);return}const me=Hc(de);if(!me.trim())return;const $e=Ma(l,me);if($e){console.warn($e);return}const Ce=(st=(Te=u.current)==null?void 0:Te.getBoundingClientRect)==null?void 0:st.call(Te),_e=(xe=(gt=c.current)==null?void 0:gt.querySelector)==null?void 0:xe.call(gt,".af-work-display-body"),Be=(lt=(Fe=c.current)==null?void 0:Fe.querySelector)==null?void 0:lt.call(Fe,".af-visible-scroll-frame__scroller"),ot=Math.round(Math.max(Number((Ce==null?void 0:Ce.width)||0),Number((E==null?void 0:E.width)||0),Number(((oe=c.current)==null?void 0:oe.clientWidth)||0),Number((_e==null?void 0:_e.clientWidth)||0),Number((Be==null?void 0:Be.clientWidth)||0),Math.max(320,Number((E==null?void 0:E.width)||960)-2))),yt=Math.round(Math.max(Number((Ce==null?void 0:Ce.height)||0),Number((E==null?void 0:E.height)||0),Number(((ke=c.current)==null?void 0:ke.clientHeight)||0),Number((_e==null?void 0:_e.clientHeight)||0),Number((Be==null?void 0:Be.clientHeight)||0),Math.max(180,Number((E==null?void 0:E.height)||640)-46)));h(!0);try{await GG({flowParams:(t==null?void 0:t.flowParams)||{},content:me,sourceFilePath:ce,iframe:u.current,width:ot,height:yt,filename:VG((t==null?void 0:t.label)||e||"html-render","png"),snapshotElements:{card:c.current,displayBody:_e,scroller:Be},displaySize:E}),(Ke=t==null?void 0:t.onStatus)==null||Ke.call(t,"已导出 HTML 展示截图")}catch(be){const Ht=String((be==null?void 0:be.message)||be||"截图失败");(Ue=t==null?void 0:t.onStatus)==null||Ue.call(t,`HTML 截图失败:${Ht}`),console.warn("Failed to save HTML display as PNG.",be)}finally{h(!1)}},[t,E==null?void 0:E.height,E==null?void 0:E.width,e,l,p]),V=m.useCallback(Z=>{var ce;K||!Z||l!=="image"||(ce=t==null?void 0:t.onUploadImageToDisplayNode)==null||ce.call(t,e,Z)},[t,e,l,K]),B=m.useCallback(Z=>{var ce,de;(ce=Z==null?void 0:Z.stopPropagation)==null||ce.call(Z),!K&&((de=t==null?void 0:t.onSetDisplayNodeContent)==null||de.call(t,e,"","replace",{logChat:!1,reloadDisplay:!0,statusMessage:"已清空 Display 内容"}),l==="markdown"&&(w(""),g(!1)))},[t,e,l,K]),se=m.useCallback(Z=>{var me,$e;K||l!=="image"||!(Array.from(((me=Z.dataTransfer)==null?void 0:me.files)||[]).some(cm)||Array.from((($e=Z.dataTransfer)==null?void 0:$e.items)||[]).some(Ce=>String((Ce==null?void 0:Ce.type)||"").startsWith("image/")))||(Z.preventDefault(),Z.stopPropagation(),Z.dataTransfer.dropEffect="copy",z(!0))},[l,K]),ue=m.useCallback(Z=>{l==="image"&&(Z.currentTarget.contains(Z.relatedTarget)||z(!1))},[l]),G=m.useCallback(Z=>{var de;if(l!=="image")return;const ce=Array.from(((de=Z.dataTransfer)==null?void 0:de.files)||[]).find(cm);ce&&(Z.preventDefault(),Z.stopPropagation(),z(!1),V(ce))},[l,V]);return i.jsxs("div",{className:"af-work-display-card"+(E?" af-work-display-card--sized":"")+(n?" af-work-display-card--selected":"")+(y?" af-work-display-card--resizing":"")+(I?" af-work-display-card--image-drop":"")+(H?" af-work-display-card--presentation":"")+(t!=null&&t.isExecuting?" af-work-display-card--executing":"")+((t==null?void 0:t.nodeStatus)==="success"?" af-work-display-card--done":"")+((t==null?void 0:t.nodeStatus)==="failed"?" af-work-display-card--failed":""),style:E?{width:E.width,height:E.height}:void 0,ref:c,onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,onDragOver:se,onDragLeave:ue,onDrop:G,children:[i.jsx(zk,{className:"af-work-display-resize nodrag",position:"bottom-right",minWidth:320,minHeight:180,onResizeStart:()=>k(!0),onResizeEnd:()=>k(!1),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_full"})}),s.map((Z,ce)=>{if(Z.showOnNode===!1)return null;const de=`${4.15+ce*1.75}rem`,me=Z.name||`#${ce+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:de},children:me}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${ce}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:de,background:Tn(Z.type)},title:`${me} · ${Z.type}`})]},`in-${ce}`)}),a.map(({slot:Z,idx:ce},de)=>{if(Z.showOnNode===!1)return null;const me=`${4.15+de*1.75}rem`,$e=Z.name||`#${ce+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:me},children:$e}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${ce}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:me,background:Tn(Z.type)},title:`${$e} · ${Z.type}`})]},`out-${ce}`)}),i.jsxs("div",{className:"af-work-display-card__head",children:[i.jsxs("div",{className:"af-work-display-card__title",children:[i.jsx("span",{className:"material-symbols-outlined",children:JT(l)}),i.jsx("strong",{children:D}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"display"})]}),l==="html"?i.jsxs("div",{className:"af-work-display-card__html-controls nodrag",onClick:Z=>Z.stopPropagation(),children:[i.jsx("button",{type:"button",className:"af-work-display-card__action",onClick:()=>{var Z,ce,de,me;try{(me=(de=(ce=(Z=u.current)==null?void 0:Z.contentWindow)==null?void 0:ce.history)==null?void 0:de.back)==null||me.call(de)}catch{}},"aria-label":"后退",title:"后退",children:i.jsx("span",{className:"material-symbols-outlined",children:"arrow_back"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action",onClick:()=>{var Z,ce,de,me;try{(me=(de=(ce=(Z=u.current)==null?void 0:Z.contentWindow)==null?void 0:ce.history)==null?void 0:de.forward)==null||me.call(de)}catch{}},"aria-label":"前进",title:"前进",children:i.jsx("span",{className:"material-symbols-outlined",children:"arrow_forward"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action",onClick:()=>f(Z=>Z+1),"aria-label":"刷新",title:"刷新",children:i.jsx("span",{className:"material-symbols-outlined",children:"refresh"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action",disabled:p,onClick:Q,"aria-label":"截图另存为图片",title:"截图另存为图片",children:i.jsx("span",{className:"material-symbols-outlined",children:p?"hourglass_empty":"photo_camera"})})]}):null,l==="markdown"?b?i.jsxs("div",{className:"af-work-display-card__html-controls nodrag",onClick:Z=>Z.stopPropagation(),children:[i.jsx("button",{type:"button",className:"af-work-display-card__action",disabled:K||C,onClick:async()=>{var Z;try{await eM({nodeId:e,data:t,filePath:O,content:v,setFileContent:j}),g(!1)}catch(ce){(Z=t==null?void 0:t.onStatus)==null||Z.call(t,String(ce.message||ce))}},"aria-label":"保存并预览",title:"保存并预览",children:i.jsx("span",{className:"material-symbols-outlined",children:"done"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action",onClick:()=>{w(String(M||"")),g(!1)},"aria-label":"取消编辑",title:"取消编辑",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}):i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:K||C,onClick:Z=>{Z.stopPropagation(),w(String(M||"")),g(!0)},"aria-label":"编辑 Markdown",title:"编辑 Markdown",children:i.jsx("span",{className:"material-symbols-outlined",children:"edit"})}):null,l==="image"?i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:$,className:"af-hidden-file-input",type:"file",accept:"image/*",onChange:Z=>{var de;const ce=(de=Z.target.files)==null?void 0:de[0];Z.target.value="",ce&&V(ce)}}),i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:K,onClick:Z=>{var ce;Z.stopPropagation(),(ce=$.current)==null||ce.click()},"aria-label":"上传图片",title:"上传图片",children:i.jsx("span",{className:"material-symbols-outlined",children:"upload"})})]}):null,i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",onClick:Z=>{var ce;Z.stopPropagation(),(ce=t==null?void 0:t.onOpenDisplayPreview)==null||ce.call(t,T)},"aria-label":"全屏预览",title:"全屏预览",children:i.jsx("span",{className:"material-symbols-outlined",children:"fullscreen"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:W,onClick:Z=>{var ce;Z.stopPropagation(),(ce=t==null?void 0:t.onShareDisplayNode)==null||ce.call(t,T)},"aria-label":"分享展示",title:"分享展示",children:i.jsx("span",{className:"material-symbols-outlined",children:W?"hourglass_empty":"ios_share"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:K,onClick:B,"aria-label":"清空内容",title:"清空内容",children:i.jsx("span",{className:"material-symbols-outlined",children:"delete_sweep"})}),i.jsx("button",{type:"button",className:"af-work-display-card__action nodrag",disabled:K,onClick:()=>{var Z;return(Z=t==null?void 0:t.onSaveDisplayNodeToFile)==null?void 0:Z.call(t,e,t)},"aria-label":"另存为文件",title:"另存为文件",children:i.jsx("span",{className:"material-symbols-outlined",children:"save"})}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",disabled:K,onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),l==="markdown"&&b?i.jsx(ZT,{value:v,onChange:w,onUploadImage:t==null?void 0:t.onUploadWorkspaceImage,readOnly:K}):i.jsx(QT,{data:t,flowParams:t==null?void 0:t.flowParams,htmlFrameRef:u,htmlFrameVersion:d}),i.jsx(eJ,{nodeId:e,data:t})]})}function iJ({id:e,data:t,selected:n,deleteNode:r}){var d,f,p;const s=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],o=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],a=((f=(d=t==null?void 0:t.runningRunNodeIds)==null?void 0:d.has)==null?void 0:f.call(d,e))||((p=t==null?void 0:t.runningRunNodeIds)==null?void 0:p[e])===!0||(t==null?void 0:t.isExecuting)||(t==null?void 0:t.nodeStatus)==="running",l=(t==null?void 0:t.optimizingRun)===!0,c=(t==null?void 0:t.nodeStatus)==="stopped",u=!!(t!=null&&t.readOnly);return i.jsxs("div",{className:"af-work-run-card"+(n?" af-work-run-card--selected":"")+(a?" af-work-run-card--running":"")+(t!=null&&t.isExecuting?" af-work-run-card--executing":"")+((t==null?void 0:t.nodeStatus)==="success"?" af-work-run-card--done":"")+((t==null?void 0:t.nodeStatus)==="failed"?" af-work-run-card--failed":"")+(c?" af-work-run-card--stopped":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[s.map((h,y)=>{if(h.showOnNode===!1)return null;const k=`${2.25+y*1.75}rem`,b=h.name||`#${y+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:k},children:b}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${y}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:k,background:Tn(h.type)},title:`${b} · ${h.type}`})]},`in-${y}`)}),o.map((h,y)=>{if(h.showOnNode===!1)return null;const k=`${2.25+y*1.75}rem`,b=h.name||`#${y+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:k},children:b}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${y}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:k,background:Tn(h.type)},title:`${b} · ${h.type}`})]},`out-${y}`)}),i.jsxs("div",{className:"af-work-run-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"play_circle"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"Run"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"workspace_run"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",disabled:u,onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-run-card__actions",children:[i.jsxs("button",{type:"button",className:"af-work-run-card__button nodrag"+(a?" af-work-run-card__button--stop":""),disabled:u||l,onClick:h=>{var y,k;h.stopPropagation(),a?(y=t==null?void 0:t.onStopWorkspaceNode)==null||y.call(t,e):(k=t==null?void 0:t.onRunWorkspaceNode)==null||k.call(t,e)},children:[i.jsx("span",{className:"material-symbols-outlined",children:a?"stop_circle":"play_arrow"}),i.jsx("span",{children:a?"Stop":"Run line"})]}),i.jsx("button",{type:"button",className:"af-work-run-card__button af-work-run-card__optimize nodrag"+(l?" af-work-run-card__optimize--running":""),disabled:u||a||l,title:l?"正在优化":"为下游节点提前生成 implementation","aria-label":l?"正在优化":"优化",onClick:h=>{var y;h.stopPropagation(),(y=t==null?void 0:t.onOptimizeWorkspaceRun)==null||y.call(t,e)},children:i.jsx("span",{className:"material-symbols-outlined",children:l?"sync":"auto_fix_high"})}),i.jsx("button",{type:"button",className:"af-work-run-card__button af-work-run-card__logs nodrag",title:"查看执行日志","aria-label":"查看执行日志",onClick:h=>{var y;h.stopPropagation(),(y=t==null?void 0:t.onOpenWorkspaceRunLogs)==null||y.call(t,{nodeId:e,runNodeId:e,scheduleNodeId:"",label:(t==null?void 0:t.label)||"Run"})},children:i.jsx("span",{className:"material-symbols-outlined",children:"article"})})]})]})}function oJ({id:e,data:t,selected:n,deleteNode:r,skills:s,skillCollections:o,workspaces:a}){var Ue,be,Ht,Qt,jt,yn,on;const l=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],c=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],u=vJ(t),[d,f]=m.useState(u.task),p=m.useRef(!1),h=m.useRef(u.task),y=((be=(Ue=t==null?void 0:t.runningRunNodeIds)==null?void 0:Ue.has)==null?void 0:be.call(Ue,e))||((Ht=t==null?void 0:t.runningRunNodeIds)==null?void 0:Ht[e])===!0||(t==null?void 0:t.isExecuting)||(t==null?void 0:t.nodeStatus)==="running",k=(t==null?void 0:t.nodeStatus)==="stopped",b=!!(t!=null&&t.readOnly),g=Array.isArray(s)?s:[],v=Array.isArray(o)?o:[],w=m.useMemo(()=>(Array.isArray(a)?a:[]).map(re=>({id:String((re==null?void 0:re.id)||""),label:String((re==null?void 0:re.label)||(re==null?void 0:re.name)||"知识库"),kind:(re==null?void 0:re.kind)==="git"?"git":"local",path:String((re==null?void 0:re.path)||""),repoUrl:String((re==null?void 0:re.repoUrl)||""),branch:String((re==null?void 0:re.branch)||""),mountPath:String((re==null?void 0:re.mountPath)||""),builtin:(re==null?void 0:re.builtin)===!0,exists:(re==null?void 0:re.exists)!==!1,type:String((re==null?void 0:re.type)||"")})).filter(re=>re.path),[a]),[N,j]=m.useState(!1),[C,P]=m.useState(""),[I,z]=m.useState(()=>new Set),[$,L]=m.useState(!1),[F,O]=m.useState(""),[M,K]=m.useState("config"),H=lg(t),D=!!H,T=lM(u.displayType),W=m.useMemo(()=>zG(t,T),[t==null?void 0:t.displaySize,t==null?void 0:t.nodeSize,t==null?void 0:t.inputs,t==null?void 0:t.input,T]),E=m.useMemo(()=>({...t,sourceNodeId:e,label:t!=null&&t.label&&t.label!=="Context Run"?t.label:"一键任务",definitionId:T,displaySize:W,nodeSize:W,body:H,inputs:[{type:"text",name:T==="display_image"?"src":"content",value:H,default:H}],outputs:c.length?c:[{type:"node",name:"next",default:""}]}),[t,T,e,H,c,W]),Q=Array.isArray((Qt=t==null?void 0:t.modelLists)==null?void 0:Qt.cursor)?t.modelLists.cursor:[],V=Array.isArray((jt=t==null?void 0:t.modelLists)==null?void 0:jt.opencode)?t.modelLists.opencode:[],B=Array.isArray((yn=t==null?void 0:t.modelLists)==null?void 0:yn.claudeCode)?t.modelLists.claudeCode:[],se=Array.isArray((on=t==null?void 0:t.modelLists)==null?void 0:on.codex)?t.modelLists.codex:[],ue=m.useMemo(()=>new Set(Q.map(Ss)),[Q]),G=m.useMemo(()=>new Set(V.map(Ss)),[V]),ee=m.useMemo(()=>new Set(B.map(Ss)),[B]),te=m.useMemo(()=>new Set(se.map(Ss)),[se]),ne=u.model,Z=m.useMemo(()=>ne?ne.startsWith("cursor:")||ne.startsWith("opencode:")||ne.startsWith("codex:")||ne.startsWith("claude-code:")?ne:ee.has(ne)?`claude-code:${ne}`:te.has(ne)?`codex:${ne}`:G.has(ne)?`opencode:${ne}`:ue.has(ne)?`cursor:${ne}`:ne:"",[ee,te,ue,G,ne]),ce=ne.startsWith("cursor:")?ne.slice(7):ne.startsWith("opencode:")?ne.slice(9):ne.startsWith("codex:")?ne.slice(6):ne.startsWith("claude-code:")?ne.slice(12):ne,de=ce,me=!!ne&&!ue.has(de)&&!G.has(de)&&!ee.has(de)&&!te.has(de),$e=m.useMemo(()=>new Set(u.skillKeys),[u.skillKeys]),Ce=m.useMemo(()=>new Map(g.map(re=>[re.key,re])),[g]),_e=m.useMemo(()=>{const re=new Set,Re=v.map(Ze=>{const Tt=Qo(Ze,g).map(At=>Ce.get(At)).filter(Boolean);for(const At of Tt)re.add(At.key);return{...Ze,skills:Tt}}).filter(Ze=>Ze.skills.length>0),Je=g.filter(Ze=>!re.has(Ze.key));return{collectionGroups:Re,ungrouped:Je}},[v,Ce,g]);m.useEffect(()=>{z(re=>{let Re=!1;const Je=new Set(re);for(const Ze of _e.collectionGroups)Je.has(Ze.id)||(Je.add(Ze.id),Re=!0);return Re?Je:re})},[_e.collectionGroups]);const Be=m.useMemo(()=>{const re=C.trim().toLowerCase();if(!re)return _e;const Re=Ze=>[Ze==null?void 0:Ze.key,Ze==null?void 0:Ze.name,Ze==null?void 0:Ze.description].map(Tt=>String(Tt||"").toLowerCase()).join(" ").includes(re);return{collectionGroups:_e.collectionGroups.map(Ze=>{const Tt=[Ze==null?void 0:Ze.id,Ze==null?void 0:Ze.name,Ze==null?void 0:Ze.description].map(At=>String(At||"").toLowerCase()).join(" ").includes(re);return{...Ze,skills:Tt?Ze.skills:Ze.skills.filter(Re)}}).filter(Ze=>Ze.skills.length>0),ungrouped:_e.ungrouped.filter(Re)}},[_e,C]),ot=mb(N,[Be.collectionGroups.length,Be.ungrouped.length,I.size,u.skillKeys.length,C]),yt=m.useMemo(()=>{const re=F.trim().toLowerCase();return re?w.filter(Re=>[Re.id,Re.label,Re.path,Re.repoUrl,Re.branch,Re.mountPath,Re.type].join(" ").toLowerCase().includes(re)):w},[w,F]),Te=m.useMemo(()=>fM(u.knowledgeContext),[u.knowledgeContext]),st=m.useMemo(()=>new Set(Te.map(re=>re.id||re.path||re.repoPath).filter(Boolean)),[Te]),gt=mb($,[yt.length,Te.length,F]);m.useEffect(()=>{u.task!==h.current&&(h.current=u.task,p.current||f(u.task))},[u.task]),m.useEffect(()=>{if(!D){K("config");return}y||K("result")},[D,H,y]),m.useEffect(()=>{var Re,Je;if(!(M==="result"&&D))return;(Re=t==null?void 0:t.onEnsureWorkspaceNodeDisplaySize)==null||Re.call(t,e,W),(Je=t==null?void 0:t.onRefreshNodeInternals)==null||Je.call(t,e);const re=window.setTimeout(()=>{var Ze;return(Ze=t==null?void 0:t.onRefreshNodeInternals)==null?void 0:Ze.call(t,e)},120);return()=>window.clearTimeout(re)},[t==null?void 0:t.onEnsureWorkspaceNodeDisplaySize,t==null?void 0:t.onRefreshNodeInternals,T,D,e,H,W,M]);const xe=re=>{var Re;(Re=t==null?void 0:t.onChangeContextRunConfig)==null||Re.call(t,e,{...u,task:d,...re})},Fe=(re=d)=>{var Je;const Re=String(re??"");Re!==u.task&&(h.current=Re,(Je=t==null?void 0:t.onChangeContextRunConfig)==null||Je.call(t,e,{...u,task:Re}))},lt=(re,Re)=>{const Je=new Set(u.skillKeys);for(const Ze of re){const Tt=String(Ze||"").trim();Tt&&(Re?Je.add(Tt):Je.delete(Tt))}xe({skillKeys:Array.from(Je)})},oe=re=>{z(Re=>{const Je=new Set(Re);return Je.has(re)?Je.delete(re):Je.add(re),Je})},ke=(re,Re)=>{const Je=(re==null?void 0:re.id)||(re==null?void 0:re.path)||"";if(!Je)return;const Ze=w.filter(Tt=>{const At=Tt.id||Tt.path||"";return At===Je?Re:st.has(At)});xe({knowledgeContext:cg(Ze)})},Ke=()=>{xe({knowledgeContext:null})};return M==="result"&&D?i.jsx(tM,{id:e,data:{...E,selected:t==null?void 0:t.selected,onSelectNodePointerDown:t==null?void 0:t.onSelectNodePointerDown},selected:n,deleteNode:r}):i.jsxs("div",{className:"af-work-context-run-card"+(n?" af-work-context-run-card--selected":"")+(M==="result"&&D?" af-work-context-run-card--result":"")+(y?" af-work-context-run-card--running":"")+((t==null?void 0:t.nodeStatus)==="success"?" af-work-context-run-card--done":"")+((t==null?void 0:t.nodeStatus)==="failed"?" af-work-context-run-card--failed":"")+(k?" af-work-context-run-card--stopped":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[l.map((re,Re)=>{if(re.showOnNode===!1)return null;const Je=`${2.25+Re*1.75}rem`,Ze=re.name||`#${Re+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:Je},children:Ze}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${Re}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:Je,background:Tn(re.type)},title:`${Ze} · ${re.type}`})]},`in-${Re}`)}),c.map((re,Re)=>{if(re.showOnNode===!1)return null;const Je=`${2.25+Re*1.75}rem`,Ze=re.name||`#${Re+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:Je},children:Ze}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${Re}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:Je,background:Tn(re.type)},title:`${Ze} · ${re.type}`})]},`out-${Re}`)}),i.jsxs("div",{className:"af-work-context-run-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"automation"}),i.jsx("strong",{children:t!=null&&t.label&&t.label!=="Context Run"?t.label:"一键任务"}),i.jsxs("div",{className:"af-work-context-run-card__model-wrap nodrag",onPointerDown:re=>re.stopPropagation(),onMouseDown:re=>re.stopPropagation(),onClick:re=>re.stopPropagation(),children:[i.jsxs("select",{className:"af-work-context-run-card__model",value:Z,disabled:b,"aria-label":"模型",title:ce||"默认模型",onChange:re=>xe({model:re.target.value}),children:[i.jsx("option",{value:"",children:"默认"}),me?i.jsx("option",{value:ne,children:ne}):null,Q.length?i.jsx("optgroup",{label:"Cursor",children:Q.map(re=>i.jsx("option",{value:`cursor:${Ss(re)}`,children:Ss(re)},`context-cursor-${re}`))}):null,V.length?i.jsx("optgroup",{label:"OpenCode",children:V.map(re=>i.jsx("option",{value:`opencode:${Ss(re)}`,children:Ss(re)},`context-opencode-${re}`))}):null,se.length?i.jsx("optgroup",{label:"Codex",children:se.map(re=>i.jsx("option",{value:`codex:${Ss(re)}`,children:Ss(re)},`context-codex-${re}`))}):null,B.length?i.jsx("optgroup",{label:"Claude Code",children:B.map(re=>i.jsx("option",{value:`claude-code:${Ss(re)}`,children:Ss(re)},`context-claude-${re}`))}):null]}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"expand_more"})]}),i.jsx("span",{className:"af-work-context-run-card__kind",children:ei(t==null?void 0:t.definitionId)?"workspace_one_click_task":(t==null?void 0:t.definitionId)||"workspace_one_click_task"}),D?i.jsxs("div",{className:"af-work-context-run-card__view-switch nodrag",onClick:re=>re.stopPropagation(),children:[i.jsx("button",{type:"button",className:M==="config"?"is-active":"",onClick:()=>K("config"),"aria-label":"切换到任务配置",children:i.jsx("span",{className:"material-symbols-outlined",children:"tune"})}),i.jsx("button",{type:"button",className:M==="result"?"is-active":"",onClick:()=>K("result"),"aria-label":"切换到展示结果",children:i.jsx("span",{className:"material-symbols-outlined",children:"preview"})})]}):null,i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",disabled:b,onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-context-run-card__body nodrag",children:[i.jsxs(i.Fragment,{children:[i.jsx("textarea",{value:d,disabled:b,placeholder:"输入任务,例如:基于选中的知识库总结需求并生成展示页",onCompositionStart:()=>{p.current=!0},onCompositionEnd:re=>{p.current=!1,f(re.currentTarget.value),Fe(re.currentTarget.value)},onChange:re=>{f(re.target.value)},onBlur:re=>Fe(re.currentTarget.value)}),i.jsxs("div",{className:"af-work-context-run-card__grid",children:[i.jsxs("div",{className:"af-work-context-run-card__skills",children:[i.jsxs("button",{type:"button",disabled:b,className:"af-work-context-run-card__select",onClick:re=>{var Re;re.stopPropagation(),N||(Re=t==null?void 0:t.onRefreshSkills)==null||Re.call(t),j(Je=>!Je)},children:[i.jsx("span",{className:"material-symbols-outlined",children:"extension"}),i.jsx("span",{children:u.skillKeys.length?`${u.skillKeys.length} skills`:"Skills"}),i.jsx("span",{className:"material-symbols-outlined",children:"expand_more"})]}),N?i.jsxs("div",{className:"af-work-context-run-card__skills-menu",onClick:re=>re.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:C,onChange:re=>P(re.target.value),placeholder:"搜索 Skills...",spellCheck:!1,autoComplete:"off","aria-label":"搜索 Skills"}),C?i.jsx("button",{type:"button",onClick:()=>P(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{ref:ot.menuRef,className:"af-work-load-skills-menu af-work-context-run-card__menu-scroll",onScroll:ot.updateMenuScrollbar,children:[Be.collectionGroups.map(re=>{const Re=re.skills.map(At=>At.key),Je=Re.filter(At=>$e.has(At)).length,Ze=Re.length>0&&Je===Re.length,Tt=I.has(re.id);return i.jsxs("section",{className:"af-work-load-skills-menu__group"+(Tt?" af-work-load-skills-menu__group--collapsed":""),children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head",children:[i.jsx("input",{type:"checkbox",checked:Ze,disabled:b,onChange:At=>lt(Re,At.target.checked),"aria-label":`选择 ${re.name}`}),i.jsx("button",{type:"button",className:"af-work-load-skills-menu__group-toggle",onClick:()=>oe(re.id),"aria-expanded":!Tt,children:i.jsxs("span",{className:"af-work-load-skills-menu__group-main",children:[i.jsx("span",{children:re.name}),re.description?i.jsx("em",{children:re.description}):null]})}),i.jsxs("small",{children:[Je,"/",Re.length]}),i.jsx("button",{type:"button",className:"af-work-load-skills-menu__group-arrow",onClick:()=>oe(re.id),"aria-label":Tt?`展开 ${re.name}`:`收起 ${re.name}`,children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:Tt?"chevron_right":"expand_more"})})]}),Tt?null:i.jsx("div",{className:"af-work-load-skills-menu__options",children:re.skills.map(At=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:$e.has(At.key),disabled:b,onChange:Vn=>lt([At.key],Vn.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:At.name}),At.description?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:At.description}):null]})]},`${re.id}:${At.key}`))})]},re.id)}),Be.ungrouped.length>0?i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"Ungrouped"}),i.jsx("small",{children:Be.ungrouped.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:Be.ungrouped.map(re=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:$e.has(re.key),disabled:b,onChange:Re=>lt([re.key],Re.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:re.name}),re.description?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:re.description}):null]})]},`ungrouped:${re.key}`))})]}):null,Be.collectionGroups.length===0&&Be.ungrouped.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的 Skills"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:()=>xe({skillKeys:[]}),children:"清空"})]}),i.jsx("div",{ref:ot.scrollbarTrackRef,className:"af-work-load-skills-scrollbar"+(ot.scrollbar.visible?" af-work-load-skills-scrollbar--visible":""),onPointerDown:ot.handleScrollbarPointerDown,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${ot.scrollbar.height}%`,top:`${ot.scrollbar.top}%`}})})]}):null]}),i.jsxs("div",{className:"af-work-context-run-card__workspace",children:[i.jsxs("button",{type:"button",disabled:b,className:"af-work-context-run-card__select",onClick:re=>{var Re;re.stopPropagation(),$||(Re=t==null?void 0:t.onRefreshWorkspaces)==null||Re.call(t),L(Je=>!Je)},children:[i.jsx("span",{className:"material-symbols-outlined",children:Te.length?"folder_open":"folder_off"}),i.jsx("span",{children:Te.length?`${Te.length} 知识库`:"知识库"}),i.jsx("span",{className:"material-symbols-outlined",children:"expand_more"})]}),$?i.jsxs("div",{className:"af-work-context-run-card__workspace-menu",onClick:re=>re.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:F,onChange:re=>O(re.target.value),placeholder:"搜索知识库...",spellCheck:!1,autoComplete:"off","aria-label":"搜索知识库"}),F?i.jsx("button",{type:"button",onClick:()=>O(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{ref:gt.menuRef,className:"af-work-load-skills-menu af-work-context-run-card__menu-scroll",onScroll:gt.updateMenuScrollbar,children:[i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"知识库"}),i.jsx("small",{children:yt.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:yt.map(re=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:st.has(re.id||re.path),disabled:b,onChange:Re=>ke(re,Re.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:re.label}),i.jsxs("span",{className:"af-work-load-skills-menu__option-desc",children:[re.kind==="git"&&re.repoUrl?`${re.repoUrl}${re.branch?` · ${re.branch}`:""}${re.mountPath?` · ${re.mountPath}`:""}`:re.path,re.exists?"":" · 路径未就绪"]})]})]},`${re.id}:${re.path}`))})]}),yt.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的知识库"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:Ke,children:"清空知识库"})]}),i.jsx("div",{ref:gt.scrollbarTrackRef,className:"af-work-load-skills-scrollbar"+(gt.scrollbar.visible?" af-work-load-skills-scrollbar--visible":""),onPointerDown:gt.handleScrollbarPointerDown,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${gt.scrollbar.height}%`,top:`${gt.scrollbar.top}%`}})})]}):null]}),i.jsxs("select",{value:u.displayType,disabled:b,onChange:re=>xe({displayType:re.target.value}),children:[i.jsx("option",{value:"markdown",children:"Markdown"}),i.jsx("option",{value:"html",children:"HTML"}),i.jsx("option",{value:"react",children:"React"}),i.jsx("option",{value:"table",children:"Table"}),i.jsx("option",{value:"chart",children:"Chart"}),i.jsx("option",{value:"ascii",children:"ASCII"}),i.jsx("option",{value:"mermaid",children:"Mermaid"})]})]}),H?i.jsx("pre",{className:"af-work-context-run-card__preview",children:H.slice(0,520)}):null]}),i.jsxs("div",{className:"af-work-context-run-card__actions",children:[i.jsxs("button",{type:"button",className:"af-work-run-card__button af-work-context-run-card__run nodrag"+(y?" af-work-run-card__button--stop":""),disabled:b,onClick:re=>{var Re,Je;re.stopPropagation(),Fe(),y?(Re=t==null?void 0:t.onStopWorkspaceNode)==null||Re.call(t,e):(Je=t==null?void 0:t.onRunWorkspaceNode)==null||Je.call(t,e)},children:[i.jsx("span",{className:"material-symbols-outlined",children:y?"stop_circle":"play_arrow"}),i.jsx("span",{children:y?"Stop":"Run"})]}),i.jsx("button",{type:"button",className:"af-work-run-card__button af-work-context-run-card__logs nodrag",onClick:re=>{var Re;re.stopPropagation(),(Re=t==null?void 0:t.onOpenWorkspaceRunLogs)==null||Re.call(t,{nodeId:e,runNodeId:e,scheduleNodeId:"",label:t!=null&&t.label&&t.label!=="Context Run"?t.label:"一键任务"})},children:i.jsx("span",{className:"material-symbols-outlined",children:"article"})})]})]})]})}function aJ({id:e,data:t,selected:n,deleteNode:r}){var P,I,z;const s=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],o=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],a=gv((t==null?void 0:t.body)||""),[l,c]=m.useState(a.cron),u=(t==null?void 0:t.scheduledRunState)||{},d=((I=(P=t==null?void 0:t.runningRunNodeIds)==null?void 0:P.has)==null?void 0:I.call(P,e))||((z=t==null?void 0:t.runningRunNodeIds)==null?void 0:z[e])===!0||(t==null?void 0:t.isExecuting)||(t==null?void 0:t.nodeStatus)==="running",f=(t==null?void 0:t.optimizingRun)===!0,p=(t==null?void 0:t.nodeStatus)==="stopped",h=!!(t!=null&&t.readOnly),y=$=>{var L;(L=t==null?void 0:t.onChangeScheduledRunConfig)==null||L.call(t,e,{...a,...$})},k=$=>{y({scheduleType:$,cron:Ku($,a.time,a.weekday,a.monthDay,a.cron)})},b=$=>{y({time:$,cron:Ku(a.scheduleType,$,a.weekday,a.monthDay,a.cron)})},[g,v]=mv(a.time).split(":"),w=($,L)=>{b(`${Do($,9,0,23)}:${Do(L,0,0,59)}`)},N=$=>{y({weekday:$,cron:Ku(a.scheduleType,a.time,$,a.monthDay,a.cron)})},j=$=>{y({monthDay:$,cron:Ku(a.scheduleType,a.time,a.weekday,$,a.cron)})};m.useEffect(()=>{c(a.cron)},[a.cron,e]);const C=()=>{h||l===a.cron||y({cron:l})};return i.jsxs("div",{className:"af-work-run-card af-work-schedule-card"+(n?" af-work-run-card--selected":"")+(a.enabled?" af-work-schedule-card--enabled":"")+(d?" af-work-run-card--running":"")+(t!=null&&t.isExecuting?" af-work-run-card--executing":"")+((t==null?void 0:t.nodeStatus)==="success"?" af-work-run-card--done":"")+((t==null?void 0:t.nodeStatus)==="failed"?" af-work-run-card--failed":"")+(p?" af-work-run-card--stopped":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[s.map(($,L)=>{if($.showOnNode===!1)return null;const F=`${2.25+L*1.75}rem`,O=$.name||`#${L+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:F},children:O}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${L}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:F,background:Tn($.type)},title:`${O} · ${$.type}`})]},`in-${L}`)}),o.map(($,L)=>{if($.showOnNode===!1)return null;const F=`${2.25+L*1.75}rem`,O=$.name||`#${L+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:F},children:O}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${L}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:F,background:Tn($.type)},title:`${O} · ${$.type}`})]},`out-${L}`)}),i.jsxs("div",{className:"af-work-run-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"event_repeat"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"Scheduled Run"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"workspace_scheduled_run"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",disabled:h,onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-schedule-card__body nodrag",children:[i.jsxs("label",{className:"af-work-schedule-card__toggle",children:[i.jsx("input",{type:"checkbox",checked:a.enabled,disabled:h,onChange:$=>y({enabled:$.target.checked})}),i.jsx("span",{children:a.enabled?"定时开启":"定时关闭"})]}),i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"频率"}),i.jsxs("select",{value:a.scheduleType,disabled:h,onChange:$=>k($.target.value),children:[i.jsx("option",{value:"daily",children:"每天"}),i.jsx("option",{value:"weekly",children:"每周"}),i.jsx("option",{value:"monthly",children:"每月"}),i.jsx("option",{value:"custom",children:"高级 Cron"})]})]}),a.scheduleType!=="custom"?i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"时间"}),i.jsxs("div",{className:"af-work-schedule-time-selects",children:[i.jsx("select",{value:g,disabled:h,"aria-label":"小时",onChange:$=>w($.target.value,v),children:Array.from({length:24},($,L)=>Do(L,0,0,23)).map($=>i.jsxs("option",{value:$,children:[$," 时"]},$))}),i.jsx("select",{value:v,disabled:h,"aria-label":"分钟",onChange:$=>w(g,$.target.value),children:Array.from({length:12},($,L)=>Do(L*5,0,0,59)).map($=>i.jsxs("option",{value:$,children:[$," 分"]},$))})]})]}):null,a.scheduleType==="weekly"?i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"星期"}),i.jsxs("select",{value:a.weekday,disabled:h,onChange:$=>N($.target.value),children:[i.jsx("option",{value:1,children:"周一"}),i.jsx("option",{value:2,children:"周二"}),i.jsx("option",{value:3,children:"周三"}),i.jsx("option",{value:4,children:"周四"}),i.jsx("option",{value:5,children:"周五"}),i.jsx("option",{value:6,children:"周六"}),i.jsx("option",{value:0,children:"周日"})]})]}):null,a.scheduleType==="monthly"?i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"日期"}),i.jsx("select",{value:a.monthDay,disabled:h,onChange:$=>j($.target.value),children:Array.from({length:31},($,L)=>L+1).map($=>i.jsxs("option",{value:$,children:[$," 日"]},$))})]}):null,a.scheduleType==="custom"?i.jsxs("label",{className:"af-work-schedule-card__field",children:[i.jsx("span",{children:"Cron"}),i.jsx("input",{type:"text",value:l,disabled:h,spellCheck:!1,placeholder:qd,onChange:$=>c($.target.value),onBlur:C,onKeyDown:$=>{$.key==="Enter"&&$.currentTarget.blur()}})]}):null,i.jsxs("div",{className:"af-work-schedule-card__meta",children:[i.jsxs("span",{children:[_G(a.scheduleType)," ",a.scheduleType==="custom"?"":a.time]}),i.jsxs("span",{children:["Next ",CG(u.nextAt)]}),i.jsx("span",{children:d?"running":u.lastStatus||"idle"})]}),u.lastError?i.jsx("div",{className:"af-work-schedule-card__error",children:u.lastError}):null,i.jsxs("div",{className:"af-work-schedule-card__actions",children:[i.jsxs("button",{type:"button",className:"af-work-run-card__button af-work-schedule-card__run-now nodrag"+(d?" af-work-run-card__button--stop":""),disabled:h||f,onClick:$=>{var L,F;$.stopPropagation(),d?(L=t==null?void 0:t.onStopWorkspaceNode)==null||L.call(t,e):(F=t==null?void 0:t.onRunWorkspaceNode)==null||F.call(t,e)},children:[i.jsx("span",{className:"material-symbols-outlined",children:d?"stop_circle":"play_arrow"}),i.jsx("span",{children:d?"停止":"立即运行"})]}),i.jsxs("button",{type:"button",className:"af-work-run-card__button af-work-schedule-card__optimize nodrag"+(f?" af-work-schedule-card__optimize--running":""),disabled:h||d||f,title:"为下游节点提前生成 implementation",onClick:$=>{var L;$.stopPropagation(),(L=t==null?void 0:t.onOptimizeWorkspaceSchedule)==null||L.call(t,e)},children:[i.jsx("span",{className:"material-symbols-outlined",children:f?"sync":"auto_fix_high"}),i.jsx("span",{children:f?"优化中":"优化"})]}),i.jsxs("button",{type:"button",className:"af-work-run-card__button af-work-schedule-card__logs nodrag",onClick:$=>{var L;$.stopPropagation(),(L=t==null?void 0:t.onOpenWorkspaceRunLogs)==null||L.call(t,{nodeId:e,scheduleNodeId:e,runNodeId:u.targetRunNodeId||e,lastRunId:u.lastRunId||"",label:(t==null?void 0:t.label)||"Scheduled Run"})},children:[i.jsx("span",{className:"material-symbols-outlined",children:"article"}),i.jsx("span",{children:"日志"})]})]})]})]})}function lJ({id:e,data:t,selected:n,deleteNode:r}){const{setNodes:s}=Fc(),o=!!(t!=null&&t.readOnly),a=db(t==null?void 0:t.nodeSize)||{width:Qa,height:Za},l=m.useCallback(c=>{var u,d;c.button!==0||c.metaKey||c.ctrlKey||c.shiftKey||(d=(u=c.target)==null?void 0:u.closest)!=null&&d.call(u,".af-work-group-node__resize, .af-work-group-node__delete")||s(f=>sM(f,e))},[e,s]);return i.jsxs("div",{className:"af-work-group-node"+(n?" af-work-group-node--selected":""),style:{width:a.width,height:a.height},onPointerDownCapture:l,children:[o?null:i.jsx(zk,{className:"af-work-group-node__resize nodrag",minWidth:Qa,minHeight:Za,position:"bottom-right",children:i.jsx("span",{className:"material-symbols-outlined",children:"open_in_full"})}),i.jsxs("div",{className:"af-work-group-node__title nodrag",children:[i.jsx("span",{children:(t==null?void 0:t.title)||(t==null?void 0:t.label)||"Group"}),i.jsx("button",{type:"button",className:"af-work-group-node__delete",disabled:o,onClick:c=>{c.stopPropagation(),r==null||r(e)},"aria-label":"删除分组",title:"删除分组",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]})]})}function cJ(e){var y,k,b,g,v,w,N,j,C,P,I,z,$,L,F,O,M,K,H,D,T,W,E,Q,V,B,se,ue;const{setEdges:t,setNodes:n}=Fc(),r=(y=e.data)==null?void 0:y.onSyncNodePropDraft,s=!!((k=e.data)!=null&&k.readOnly),[o,a]=m.useState(!1),l=(b=e.data)!=null&&b.nodeSize&&Number(e.data.nodeSize.width)>0&&Number(e.data.nodeSize.height)>0?{width:Number(e.data.nodeSize.width),height:Number(e.data.nodeSize.height)}:null,c=m.useCallback(G=>{var ne,Z,ce;if(s)return;(Z=(ne=e.data)==null?void 0:ne.onCleanupWorkspaceNodeOutputs)==null||Z.call(ne,G,e.data);const ee=ei((ce=e.data)==null?void 0:ce.definitionId)?cM(G):"",te=new Set([G,ee].filter(Boolean));n(de=>de.filter(me=>!te.has(me.id))),t(de=>de.filter(me=>!te.has(me.source)&&!te.has(me.target)))},[e.data,s,t,n]),u=m.useCallback(G=>{var ee,te;G.button!==0||G.metaKey||G.ctrlKey||G.shiftKey||(te=(ee=G.target)==null?void 0:ee.closest)!=null&&te.call(ee,".react-flow__handle, .af-work-display-resize")||(n(ne=>sM(ne,e.id)),t(ne=>pJ(ne)))},[e.id,t,n]),d=m.useCallback((G,ee)=>{s||(n(te=>te.map(ne=>ne.id===G?{...ne,data:{...ne.data,model:ee}}:ne)),r==null||r(G,{model:ee}))},[s,n,r]),f=m.useCallback((G,ee)=>{s||(n(te=>te.map(ne=>{var ce;if(ne.id!==G)return ne;const Z=Array.isArray((ce=ne.data)==null?void 0:ce.outputs)&&ne.data.outputs.length?ne.data.outputs.map((de,me)=>me===0?{...de,default:ee,value:ee}:de):[{type:"bool",name:"value",default:ee,value:ee}];return{...ne,data:{...ne.data,body:"",outputs:Z}}})),r==null||r(G,te=>({body:"",outputs:Array.isArray(te==null?void 0:te.outputs)&&te.outputs.length?te.outputs.map((Z,ce)=>ce===0?{...Z,default:ee,value:ee}:Z):[{type:"bool",name:"value",default:ee,value:ee}]})))},[s,n,r]),p=m.useCallback((G,ee)=>{s||(n(te=>te.map(ne=>ne.id===G?{...ne,data:{...ne.data,body:ee}}:ne)),r==null||r(G,{body:ee}))},[s,n,r]),h=m.useCallback((G,ee)=>{if(s)return;const te=po(ee);n(ne=>ne.map(Z=>Z.id===G?{...Z,data:{...Z.data,images:te}}:Z)),r==null||r(G,{images:te})},[s,n,r]);return(g=e.data)!=null&&g.isWorkspaceGroup?i.jsx(lJ,{...e,deleteNode:c}):tl((v=e.data)==null?void 0:v.definitionId)?i.jsx(tM,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c}):((w=e.data)==null?void 0:w.definitionId)==="workspace_run"?i.jsx(iJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c}):((N=e.data)==null?void 0:N.definitionId)==="workspace_scheduled_run"?i.jsx(aJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c}):ei((j=e.data)==null?void 0:j.definitionId)?i.jsx(oJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c,skills:(C=e.data)==null?void 0:C.skills,skillCollections:(P=e.data)==null?void 0:P.skillCollections,workspaces:(I=e.data)==null?void 0:I.workspaceTargets}):((z=e.data)==null?void 0:z.definitionId)==="control_load_skills"?i.jsx(AJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c,skills:($=e.data)==null?void 0:$.skills,skillCollections:(L=e.data)==null?void 0:L.skillCollections,onChangeSkillKeys:(F=e.data)==null?void 0:F.onChangeLoadSkillKeys}):((O=e.data)==null?void 0:O.definitionId)==="control_load_mcp"?i.jsx(PJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c,servers:(M=e.data)==null?void 0:M.mcpServers,onChangeMcpNames:(K=e.data)==null?void 0:K.onChangeLoadMcpNames}):((H=e.data)==null?void 0:H.definitionId)==="control_cd_workspace"?i.jsx(IJ,{...e,data:{...e.data,onSelectNodePointerDown:u},deleteNode:c,workspaces:(D=e.data)==null?void 0:D.workspaceTargets,onChangeWorkspace:(T=e.data)==null?void 0:T.onChangeLoadWorkspace,onRefreshWorkspaces:(W=e.data)==null?void 0:W.onRefreshWorkspaces}):i.jsxs("div",{className:"af-work-flow-node"+(e.selected?" af-work-flow-node--selected":"")+(o?" af-work-flow-node--resizing":"")+((E=e.data)!=null&&E.isExecuting||((Q=e.data)==null?void 0:Q.nodeStatus)==="running"?" af-work-flow-node--executing":"")+(((V=e.data)==null?void 0:V.nodeStatus)==="success"?" af-work-flow-node--done":"")+(((B=e.data)==null?void 0:B.nodeStatus)==="failed"?" af-work-flow-node--failed":"")+(((se=e.data)==null?void 0:se.nodeStatus)==="stopped"?" af-work-flow-node--stopped":""),style:l?{width:l.width,height:l.height}:void 0,onPointerDownCapture:u,children:[s?null:i.jsx(zk,{className:"af-work-display-resize af-work-flow-resize nodrag",position:"bottom-right",minWidth:IT,minHeight:lm,maxWidth:RT,maxHeight:TT,onResizeStart:()=>a(!0),onResizeEnd:()=>a(!1),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_full"})}),i.jsx(Xq,{...e,deleteNode:c,deferTextCommit:!0,modelLists:(ue=e.data)==null?void 0:ue.modelLists,onModelChange:d,onProvideValueChange:f,onNodeBodyChange:p,onNodeImagesChange:h})]})}const uJ={[pc]:m.memo(cJ)};function yv(e,t=[]){for(const n of e||[])n.type==="file"&&t.push(n),Array.isArray(n.children)&&yv(n.children,t);return t}function nM(e,t){const n=String(t||"");if(!n)return null;for(const r of e||[]){if(r.path===n)return r;const s=Array.isArray(r.children)?nM(r.children,n):null;if(s)return s}return null}function dJ(e){const t=String(e||"").replace(/\\/g,"/").replace(/^\/+|\/+$/g,"");return!t||!t.includes("/")?"":t.split("/").slice(0,-1).join("/")}function rM(e,t=[]){for(const n of e||[])n.type==="directory"&&(t.push(n.path),Array.isArray(n.children)&&rM(n.children,t));return t}function Dp(e){const t=String(e||"").replace(/\\/g,"/").split("/").filter(Boolean),n=[];for(let r=1;r<t.length;r++)n.push(t.slice(0,r).join("/"));return n}function fJ(e,t){const n=String(t||"");let r=!1;const s=(e||[]).map(o=>{const a=o.id===n;return o.selected===a?o:(r=!0,{...o,selected:a})});return r?s:e}function sM(e,t){const n=String(t||""),r=(e||[]).find(o=>o.id===n),s=(e||[]).reduce((o,a)=>o+(a.selected?1:0),0);return r!=null&&r.selected&&s>1?e:fJ(e,n)}function pJ(e){let t=!1;const n=(e||[]).map(r=>r.selected?(t=!0,{...r,selected:!1}):r);return t?n:e}function hJ(e){return[...e||[]].sort((t,n)=>t.type!==n.type?t.type==="directory"?-1:1:String(t.name||"").localeCompare(String(n.name||"")))}function mJ(e,t,n=0){const r=String(t||"").replace(/\\/g,"/").split("/").filter(Boolean);if(r.length===0)return e;const s=(o,a,l)=>{const c=r[a],u=l?`${l}/${c}`:c,d=a===r.length-1;let f=!1;const p=(Array.isArray(o)?o:[]).map(h=>h.name!==c?h:(f=!0,d?{...h,type:"file",name:c,path:u,icon:tc(c),size:n}:{...h,type:"directory",name:c,path:u,icon:tc(c,!0),children:s(h.children||[],a+1,u)}));return f||p.push(d?{type:"file",name:c,path:u,icon:tc(c),size:n}:{type:"directory",name:c,path:u,icon:tc(c,!0),children:s([],a+1,u)}),hJ(p)};return s(e||[],0,"")}function gJ(e){const t=Number(e||0);return!Number.isFinite(t)||t<=0?"":t<1024?`${t} B`:t<1024*1024?`${Math.round(t/102.4)/10} KB`:`${Math.round(t/1024/102.4)/10} MB`}function iM({items:e,onOpen:t,selectedPath:n,collapsedDirs:r,onToggleDir:s,onSelect:o,onFileDragStart:a,onDelete:l,onDownload:c}){return i.jsx("ul",{className:"af-work-files",children:(e||[]).map(u=>{var h;const d=u.type==="directory",f=d&&(r==null?void 0:r.has(u.path)),p=n===u.path;return i.jsxs("li",{children:[i.jsxs("div",{className:"af-work-file-row",children:[i.jsxs("button",{type:"button",className:"af-work-file af-work-file--"+u.type+(p?" af-work-file--selected":""),draggable:!d,onDragStart:y=>{d||a==null||a(y,u)},onClick:()=>{o==null||o(u),d&&(s==null||s(u.path))},onDoubleClick:()=>{d||t(u)},title:u.path,children:[d?i.jsx("span",{className:"material-symbols-outlined af-work-file__chevron",children:f?"chevron_right":"expand_more"}):null,i.jsx("span",{className:"material-symbols-outlined",children:u.icon||tc(u.name,d)}),i.jsx("span",{children:u.name})]}),p?i.jsxs("div",{className:"af-work-file-actions",children:[d?null:i.jsx("button",{type:"button",className:"af-work-file-action",onClick:y=>{y.stopPropagation(),c==null||c(u)},"aria-label":`下载 ${u.name}`,title:`下载 ${u.path}`,children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"download"})}),i.jsx("button",{type:"button",className:"af-work-file-action af-work-file-action--danger",onClick:y=>{y.stopPropagation(),l==null||l(u)},"aria-label":`删除 ${u.name}`,title:`删除 ${u.path}`,children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"delete"})})]}):null]}),d&&!f&&((h=u.children)!=null&&h.length)?i.jsx(iM,{items:u.children,onOpen:t,selectedPath:n,collapsedDirs:r,onToggleDir:s,onSelect:o,onFileDragStart:a,onDelete:l,onDownload:c}):null]},u.path)})})}function yJ({files:e,query:t,onQueryChange:n,onSelect:r,onUpload:s,onClose:o}){const a=m.useMemo(()=>yv(e),[e]),l=String(t||"").trim().toLowerCase(),c=a.filter(u=>l?`${u.path} ${u.name}`.toLowerCase().includes(l):!0);return i.jsx("div",{className:"af-flow-snippet-modal-overlay",onMouseDown:o,children:i.jsxs("div",{className:"af-flow-snippet-modal af-work-file-picker-modal",role:"dialog","aria-modal":"true","aria-label":"选择文件",onMouseDown:u=>u.stopPropagation(),children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined",children:"folder_open"}),"选择文件"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:o,"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("div",{className:"af-work-file-picker-modal__tools",children:[i.jsx("input",{value:t,onChange:u=>n(u.target.value),placeholder:"搜索文件路径...",autoFocus:!0}),i.jsxs("button",{type:"button",onClick:()=>s==null?void 0:s(""),children:[i.jsx("span",{className:"material-symbols-outlined",children:"upload_file"}),"上传"]})]}),i.jsxs("div",{className:"af-work-file-picker-modal__list",children:[c.map(u=>i.jsxs("button",{type:"button",className:"af-work-file-picker-modal__item",onClick:()=>r(u),children:[i.jsx("span",{className:"material-symbols-outlined",children:u.icon||tc(u.name)}),i.jsxs("span",{className:"af-work-file-picker-modal__main",children:[i.jsx("strong",{children:u.name}),i.jsx("small",{children:u.path})]}),u.size?i.jsx("em",{children:gJ(u.size)}):null]},u.path)),c.length===0?i.jsx("div",{className:"af-work-file-picker-modal__empty",children:"没有匹配文件,可先上传或调整搜索词。"}):null]})]})]})})}function zC({messages:e,running:t,showRunningIndicator:n=!0}){const r=e.length>0;return i.jsxs("div",{className:"af-composer-ai-stack af-composer-ai-stack--in-panel af-composer-thread-stack",children:[e.map((s,o)=>{const a=s.kind==="run-log"||s.kind==="run-summary"||s.kind==="activity"||s.kind==="prompt"||s.kind==="raw"||s.kind==="thinking"||s.kind==="result"||s.kind==="assistant"?"reply":s.role==="user"?"user-msg":s.error?"error":"reply",l=s.kind==="run-summary"?"Steps":s.kind==="run-log"?"Run":s.kind==="activity"?"Activity":s.kind==="prompt"?"Prompt":s.kind==="raw"?"Raw Trace":s.kind==="thinking"?"Thinking":s.kind==="result"?"Result":s.kind==="assistant"?"Response":s.role==="user"?"You":s.error?"Error":"Reply";return i.jsxs("section",{className:`af-composer-ai-block af-composer-ai-block--${a}${s.kind?` af-composer-ai-block--kind-${s.kind}`:""}`,children:[i.jsx("div",{className:"af-composer-ai-block-label",children:l}),i.jsx("div",{className:"af-composer-ai-block-body",children:s.text})]},`${o}-${s.role}-${String(s.text||"").slice(0,24)}`)}),n&&t&&!r?i.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--reply af-composer-ai-block--pending",children:[i.jsx("div",{className:"af-composer-ai-block-label",children:"Reply"}),i.jsx("div",{className:"af-composer-ai-block-body",children:"Waiting..."})]}):null,n&&t&&r?i.jsxs("section",{className:"af-composer-ai-block af-composer-ai-block--thinking",children:[i.jsx("div",{className:"af-composer-ai-block-label",children:"Thinking"}),i.jsx("div",{className:"af-composer-ai-block-body",children:"Workspace agent is running..."})]}):null]})}function oM(e){const t=String((e==null?void 0:e.kind)||"");return["run-log","run-summary","activity","prompt","raw","thinking"].includes(t)}function wJ(e,t=!1){const n=Array.isArray(e)?e:[],r=n.filter(o=>!oM(o));if(r.length>0)return r;const s=[...n].reverse().find(o=>(o==null?void 0:o.kind)==="result"||(o==null?void 0:o.kind)==="assistant"||(o==null?void 0:o.error));return s?[s]:n.length>0||t?[{role:"assistant",kind:"assistant",text:t?"正在执行,可以在完成后继续追问或要求调整。":"运行已完成。可以在下方继续追问、要求总结或调整结果。",at:0}]:[]}function xJ(e){return(Array.isArray(e)?e:[]).filter(oM)}function Gd(e){const t=String(e||"").trim();if(!t)return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(String).filter(Boolean)}catch{}return t.split(/[\n,]+/).map(n=>n.trim()).filter(Boolean)}function bJ(e){const t=Gd((e==null?void 0:e.body)||"");if(t.length>0)return t;const r=(Array.isArray(e==null?void 0:e.inputs)?e.inputs:[]).find(s=>(s==null?void 0:s.name)==="skillsContext"||(s==null?void 0:s.name)==="skillKeys"||(s==null?void 0:s.type)==="text");return Gd((r==null?void 0:r.default)||(r==null?void 0:r.value)||"")}function kJ(e){const n=[...Array.isArray(e==null?void 0:e.inputs)?e.inputs:[],...Array.isArray(e==null?void 0:e.outputs)?e.outputs:[]].find(r=>(r==null?void 0:r.name)==="skillKeys"||(r==null?void 0:r.name)==="skillsContext");return Gd((n==null?void 0:n.default)||(n==null?void 0:n.value)||"")}function aM(e,t,n=1){const r=(Array.isArray(e)?e:[]).map(o=>String(o||"").trim()).filter(Boolean);return r.length?{head:r.slice(0,n).join("、"),extra:r.length>n?`等 ${r.length} 个`:"",title:r.join(", ")}:{head:t,extra:"",title:""}}function BC(e){return JSON.stringify(Array.from(new Set((e||[]).map(String).filter(Boolean))))}function ta(e,t,n=""){const r=(Array.isArray(e)?e:[]).find(o=>(o==null?void 0:o.name)===t);return String((r==null?void 0:r.value)??(r==null?void 0:r.default)??"").trim()||n}function gm(e,t){const n=ta(e,t,"");if(!n)return null;try{const r=JSON.parse(n);return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}function gf(e){const t=String(e||"").trim().toLowerCase();return["markdown","html","react","table","chart","ascii","mermaid"].includes(t)?t:"markdown"}function Ss(e){const t=String(e||""),n=t.indexOf(" - ");return n>=0?t.slice(0,n).trim():t.trim()}function lM(e){const t=gf(e);return t==="html"?"display_html":t==="react"?"display_react_app":t==="table"?"display_table":t==="chart"?"display_chart":t==="ascii"?"display_ascii":t==="mermaid"?"display_mermaid":"display_markdown"}function cM(e){return`${String(e||"context_run").trim()||"context_run"}__display`}function uM(e){return e==="display_image"?"src":"content"}function HC(e,t,n){const r=uM(t),s=qu(e);let o=!1;const a=s.map(l=>(l==null?void 0:l.name)===r?(o=!0,{...l,default:n,value:n,showOnNode:l.showOnNode!==!1}):(l==null?void 0:l.name)==="filePath"?{...l,default:"",value:""}:l);return o||a.push({type:"text",name:r,default:n,value:n,required:!0,showOnNode:!0}),a}function WC(e,t,n=[],r=[]){const s=Array.isArray(e)?e:[],o=new Set((Array.isArray(n)?n:[]).map(u=>String(u||"").trim()).filter(Boolean)),a=new Set((Array.isArray(r)?r:[]).map(u=>String(u||"").trim()).filter(Boolean)),l=u=>(u==null?void 0:u.showOnNode)!==!1;let c=s.findIndex(u=>l(u)&&o.has(String((u==null?void 0:u.name)||"").trim()));return c<0&&(c=s.findIndex(u=>o.has(String((u==null?void 0:u.name)||"").trim()))),c<0&&(c=s.findIndex(u=>l(u)&&a.has(String((u==null?void 0:u.type)||"").trim()))),c<0&&(c=s.findIndex(u=>l(u))),c<0&&(c=0),`${t}-${c}`}function VC(e){return(Array.isArray(e)?e:[]).map(t=>(t==null?void 0:t.type)==="node"||(t==null?void 0:t.name)==="next"?t:{...t,default:"",value:""})}function lg(e){const t=Array.isArray(e==null?void 0:e.outputs)?e.outputs:Array.isArray(e==null?void 0:e.output)?e.output:[],n=s=>String((s==null?void 0:s.value)??(s==null?void 0:s.default)??"").trim(),r=t.find(s=>((s==null?void 0:s.name)==="content"||(s==null?void 0:s.name)==="result")&&n(s))||t.find(s=>(s==null?void 0:s.name)==="resultFile"&&n(s))||t.find(s=>(s==null?void 0:s.type)!=="node"&&(s==null?void 0:s.name)!=="next"&&(s==null?void 0:s.name)!=="displayType"&&n(s));return r?n(r):""}function vJ(e){const t=Array.isArray(e==null?void 0:e.inputs)?e.inputs:[],n=ta(t,"includeWorkspaceContext","true").toLowerCase(),r=gm(t,"knowledgeContext"),s=gm(t,"workspaceContext");return{task:String((e==null?void 0:e.body)||""),skillKeys:kJ(e),includeWorkspaceContext:n!=="false"&&n!=="0"&&n!=="off",knowledgeContext:r||(s?cg([s]):null),workspaceContext:s,displayType:gf(ta(t,"displayType","markdown")),model:String((e==null?void 0:e.model)||"").trim()}}function ei(e){const t=String(e||"");return t==="workspace_one_click_task"||t==="workspace_context_run"}function SJ(e){const t=Gd((e==null?void 0:e.body)||"");if(t.length>0)return t;const r=(Array.isArray(e==null?void 0:e.inputs)?e.inputs:[]).find(s=>(s==null?void 0:s.name)==="mcpContext"||(s==null?void 0:s.name)==="serverNames"||(s==null?void 0:s.type)==="text");return Gd((r==null?void 0:r.default)||(r==null?void 0:r.value)||"")}function NJ(e){return JSON.stringify(Array.from(new Set((e||[]).map(String).filter(Boolean))))}function dM(e={},t="context"){const n=String((e==null?void 0:e.cwd)||(e==null?void 0:e.workspaceRoot)||(e==null?void 0:e.path)||"").trim(),r=String((e==null?void 0:e.id)||"").trim(),s=String((e==null?void 0:e.label)||(e==null?void 0:e.name)||"").trim();if(!n&&!r&&!s)return null;const o=String(s||r||"知识库").trim();return{id:r,label:o,kind:(e==null?void 0:e.kind)==="git"?"git":"local",type:String((e==null?void 0:e.type)||""),repoPath:n,path:n,mountPath:String((e==null?void 0:e.mountPath)||r||o).trim(),repoUrl:String((e==null?void 0:e.repoUrl)||"").trim(),branch:String((e==null?void 0:e.branch)||"").trim(),readonly:!0,role:t}}function cg(e=[]){const t=(Array.isArray(e)?e:[e]).map((n,r)=>dM(n,r===0?"primary":"context")).filter(Boolean);return t.length?{version:1,sources:t}:null}function fM(e){return(e&&typeof e=="object"&&Array.isArray(e.sources)?e.sources:[]).map(n=>dM(n,(n==null?void 0:n.role)||"context")).filter(Boolean)}function jJ(e){const t=Array.isArray(e==null?void 0:e.inputs)?e.inputs:[],n=gm(t,"knowledgeContext"),r=gm(t,"workspaceContext");return{sources:fM(n||(r?cg([r]):null)),path:ta(t,"path",""),label:ta(t,"label","")}}function KC(e){var r,s,o,a,l,c,u,d,f;if(!e)return null;const{inputs:t,outputs:n}=uU(e);return{id:e.id,newId:e.id,label:String(((r=e.data)==null?void 0:r.label)??e.id),role:String(((s=e.data)==null?void 0:s.role)??"normal"),model:String(((o=e.data)==null?void 0:o.model)??""),body:String(((a=e.data)==null?void 0:a.body)??""),images:po((l=e.data)==null?void 0:l.images),script:String(((c=e.data)==null?void 0:c.script)??""),scriptRef:String(((u=e.data)==null?void 0:u.scriptRef)??""),implementationRef:String(((d=e.data)==null?void 0:d.implementationRef)??""),implementationMode:String(((f=e.data)==null?void 0:f.implementationMode)??""),inputs:t,outputs:n}}function qC(e,t,n,r=""){var c,u;const s=String(n||"").trim(),o=(Array.isArray(e)?e:[]).find(d=>String((d==null?void 0:d.id)||"")===s),a=String(((c=o==null?void 0:o.data)==null?void 0:c.model)||"").trim();if(a&&a!=="default")return a;const l=String(((u=t==null?void 0:t[s])==null?void 0:u.model)||"").trim();return l&&l!=="default"?l:String(r||"").trim()}function UC(e){return(Array.isArray(e)?e:[]).map(t=>({type:String((t==null?void 0:t.type)??"node").trim()||"node",name:String((t==null?void 0:t.name)??""),default:String((t==null?void 0:t.default)??""),required:!!(t!=null&&t.required),showOnNode:(t==null?void 0:t.showOnNode)!=null?t.showOnNode!==!1:!!(t!=null&&t.required)||String((t==null?void 0:t.type)??"node").trim().toLowerCase()==="node"}))}function CJ(e,t,n){var d,f;const r=String(((d=e==null?void 0:e.data)==null?void 0:d.definitionId)??n),s=r.startsWith("provide_"),o=String((t==null?void 0:t.role)||"").trim(),a=Wd.includes(o)?o:"normal",l=String((t==null?void 0:t.model)||"").trim(),c={...e.data,label:String((t==null?void 0:t.label)||"").trim()||n,role:a,model:l===""||l==="default"?void 0:l,body:s?"":String((t==null?void 0:t.body)??""),images:s?[]:po(t==null?void 0:t.images),inputs:UC(t==null?void 0:t.inputs),outputs:s&&Array.isArray((f=e.data)==null?void 0:f.outputs)?e.data.outputs:UC(t==null?void 0:t.outputs)},u=String((t==null?void 0:t.script)??"").trim();r==="tool_nodejs"||u!==""?c.script=String((t==null?void 0:t.script)??""):delete c.script;for(const p of["scriptRef","implementationRef","implementationMode"]){const h=String((t==null?void 0:t[p])??"").trim();h?c[p]=h:delete c[p]}return c}function YC({nodes:e,edges:t,instances:n,selectedNode:r,draft:s,allowRename:o=!1}){if(!s||!r)return{ok:!1,error:""};const a=r.id,l=String(s.newId||"").trim(),c=o?l:a;if(o){if(!TU.test(c))return{ok:!1,error:"Invalid instance id"};if(e.some(k=>k.id===c&&k.id!==a))return{ok:!1,error:"Duplicate instance id"}}const u=CJ(r,s,c),d=r.data||{};if(!(c!==a||d.label!==u.label||d.role!==u.role||d.model!==u.model||d.body!==u.body||JSON.stringify(po(d.images))!==JSON.stringify(u.images)||(d.script??void 0)!==(u.script??void 0)||(d.scriptRef??void 0)!==(u.scriptRef??void 0)||(d.implementationRef??void 0)!==(u.implementationRef??void 0)||(d.implementationMode??void 0)!==(u.implementationMode??void 0)||JSON.stringify(d.inputs||[])!==JSON.stringify(u.inputs||[])||JSON.stringify(d.outputs||[])!==JSON.stringify(u.outputs||[])))return{ok:!0,changed:!1,nextId:c,nodes:e,edges:t,instances:n};const p=e.map(k=>k.id===a?{...k,id:c,selected:!0,data:u}:k);let h=t,y=n;if(c!==a){y={...n||{}};const k={...y[a]||{}};delete y[a],y[c]=k,h=t.map((b,g)=>({...b,source:b.source===a?c:b.source,target:b.target===a?c:b.target,id:`we-${b.source===a?c:b.source}-${b.target===a?c:b.target}-${g}`}))}return{ok:!0,changed:!0,nextId:c,nodes:p,edges:h,instances:y}}function _J(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function EJ(e,t,n){if(!e||!t||!n)return n;const r={...e};for(const s of["newId","label","role","model","body","images","script","scriptRef","implementationRef","implementationMode","inputs","outputs"])_J(e[s],t[s])&&(r[s]=n[s]);return r}function mb(e,t=[]){const n=m.useRef(null),r=m.useRef(null),[s,o]=m.useState({visible:!1,top:0,height:100}),a=m.useCallback(()=>{const d=n.current;if(!d)return;const f=Math.max(1,d.scrollHeight),p=Math.max(1,d.clientHeight),h=f>p+1,y=h?Math.max(12,p/f*100):100,k=Math.max(0,100-y),b=h?Math.min(k,d.scrollTop/Math.max(1,f-p)*k):0;o({visible:h,top:b,height:y})},[]);m.useEffect(()=>{if(!e)return;const d=requestAnimationFrame(a);return()=>cancelAnimationFrame(d)},[e,a,...t]);const l=m.useCallback(d=>{const f=n.current;if(!f)return;const p=Math.max(0,f.scrollHeight-f.clientHeight);f.scrollTop=Math.min(1,Math.max(0,d))*p,a()},[a]),c=m.useCallback((d,f=0)=>{const p=r.current;if(!p)return 0;const h=p.getBoundingClientRect(),y=s.height/100*h.height,k=Math.max(1,h.height-y);return(d-h.top-f)/k},[s.height]),u=m.useCallback(d=>{var N,j;if(!s.visible)return;d.preventDefault(),d.stopPropagation();const f=r.current;if(!f)return;const p=f.getBoundingClientRect(),h=s.top/100*p.height,y=s.height/100*p.height,b=d.clientY>=p.top+h&&d.clientY<=p.top+h+y?d.clientY-p.top-h:y/2;l(c(d.clientY,b));const g=d.pointerId;(j=(N=d.currentTarget).setPointerCapture)==null||j.call(N,g);const v=C=>{C.preventDefault(),l(c(C.clientY,b))},w=()=>{window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",w),window.removeEventListener("pointercancel",w)};window.addEventListener("pointermove",v),window.addEventListener("pointerup",w),window.addEventListener("pointercancel",w)},[c,l,s.height,s.top,s.visible]);return{menuRef:n,scrollbarTrackRef:r,scrollbar:s,updateMenuScrollbar:a,handleScrollbarPointerDown:u}}function AJ({id:e,data:t,selected:n,deleteNode:r,skills:s,skillCollections:o,onChangeSkillKeys:a}){const l=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],c=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],u=Array.isArray(s)?s:[],d=Array.isArray(o)?o:[],[f,p]=m.useState(!1),[h,y]=m.useState(""),[k,b]=m.useState(()=>new Set),g=m.useRef(null),v=m.useRef(null),[w,N]=m.useState({visible:!1,top:0,height:100}),j=m.useMemo(()=>new Set(bJ(t)),[t]),C=m.useMemo(()=>new Map(u.map(D=>[D.key,D])),[u]),P=m.useMemo(()=>Array.from(j).map(D=>{var T;return((T=C.get(D))==null?void 0:T.name)||D}),[C,j]),I=m.useMemo(()=>aM(P,"选择 Skills"),[P]),z=m.useMemo(()=>{const D=new Set,T=d.map(E=>{const Q=Qo(E,u).map(V=>C.get(V)).filter(Boolean);for(const V of Q)D.add(V.key);return{...E,skills:Q}}).filter(E=>E.skills.length>0),W=u.filter(E=>!D.has(E.key));return{collectionGroups:T,ungrouped:W}},[C,d,u]);m.useEffect(()=>{b(D=>{let T=!1;const W=new Set(D);for(const E of z.collectionGroups)W.has(E.id)||(W.add(E.id),T=!0);return T?W:D})},[z.collectionGroups]);const $=m.useMemo(()=>{const D=h.trim().toLowerCase();if(!D)return z;const T=E=>[E==null?void 0:E.key,E==null?void 0:E.name,E==null?void 0:E.description].map(V=>String(V||"").toLowerCase()).join(" ").includes(D);return{collectionGroups:z.collectionGroups.map(E=>{const V=[E==null?void 0:E.id,E==null?void 0:E.name,E==null?void 0:E.description].map(B=>String(B||"").toLowerCase()).join(" ").includes(D)?E.skills:E.skills.filter(T);return{...E,skills:V}}).filter(E=>E.skills.length>0),ungrouped:z.ungrouped.filter(T)}},[z,h]),L=m.useCallback((D,T)=>{const W=new Set(j);for(const E of D)T?W.add(E):W.delete(E);a==null||a(e,Array.from(W))},[e,j,a]),F=m.useCallback(D=>{b(T=>{const W=new Set(T);return W.has(D)?W.delete(D):W.add(D),W})},[]),O=m.useCallback(()=>{const D=g.current;if(!D)return;const T=Math.max(1,D.scrollHeight),W=Math.max(1,D.clientHeight),E=T>W+1,Q=E?Math.max(12,W/T*100):100,V=Math.max(0,100-Q),B=E?Math.min(V,D.scrollTop/Math.max(1,T-W)*V):0;N({visible:E,top:B,height:Q})},[]);m.useEffect(()=>{if(!f)return;const D=requestAnimationFrame(O);return()=>cancelAnimationFrame(D)},[k,$,j.size,f,O]);const M=m.useCallback(D=>{const T=g.current;if(!T)return;const W=Math.max(0,T.scrollHeight-T.clientHeight);T.scrollTop=Math.min(1,Math.max(0,D))*W,O()},[O]),K=m.useCallback((D,T=0)=>{const W=v.current;if(!W)return 0;const E=W.getBoundingClientRect(),Q=w.height/100*E.height,V=Math.max(1,E.height-Q);return(D-E.top-T)/V},[w.height]),H=m.useCallback(D=>{var ee,te;if(!w.visible)return;D.preventDefault(),D.stopPropagation();const T=v.current;if(!T)return;const W=T.getBoundingClientRect(),E=w.top/100*W.height,Q=w.height/100*W.height,B=D.clientY>=W.top+E&&D.clientY<=W.top+E+Q?D.clientY-W.top-E:Q/2;M(K(D.clientY,B));const se=D.pointerId;(te=(ee=D.currentTarget).setPointerCapture)==null||te.call(ee,se);const ue=ne=>{ne.preventDefault(),M(K(ne.clientY,B))},G=()=>{window.removeEventListener("pointermove",ue),window.removeEventListener("pointerup",G),window.removeEventListener("pointercancel",G)};window.addEventListener("pointermove",ue),window.addEventListener("pointerup",G),window.addEventListener("pointercancel",G)},[K,M,w.height,w.top,w.visible]);return i.jsxs("div",{className:"af-work-load-skills-card"+(n?" af-work-load-skills-card--selected":"")+(f?" af-work-load-skills-card--menu-open":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[l.map((D,T)=>{if(D.showOnNode===!1)return null;const W=`${2.6+T*1.7}rem`,E=D.name||`#${T+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:W},children:E}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${T}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:W,background:Tn(D.type)},title:`${E} · ${D.type}`})]},`in-${T}`)}),c.map((D,T)=>{if(D.showOnNode===!1)return null;const W=`${2.6+T*1.7}rem`,E=D.name||`#${T+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:W},children:E}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${T}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:W,background:Tn(D.type)},title:`${E} · ${D.type}`})]},`out-${T}`)}),i.jsxs("div",{className:"af-work-load-skills-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"extension"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"Load Skills"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"control_load_skills"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-load-skills-card__body nodrag",children:[i.jsxs("button",{type:"button",className:"af-work-load-skills-card__select",onClick:D=>{var T;D.stopPropagation(),f||(T=t==null?void 0:t.onRefreshSkills)==null||T.call(t),p(W=>!W)},children:[i.jsxs("span",{className:"af-work-load-skills-card__summary",title:I.title,children:[i.jsx("span",{className:"af-work-load-skills-card__summary-main",children:I.head}),I.extra?i.jsx("span",{className:"af-work-load-skills-card__summary-extra",children:I.extra}):null]}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:f?"expand_less":"expand_more"})]}),f?i.jsxs("div",{className:"af-work-load-skills-menu-shell",onClick:D=>D.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:h,onChange:D=>y(D.target.value),placeholder:"搜索 Skills...",spellCheck:!1,autoComplete:"off","aria-label":"搜索 Skills"}),h?i.jsx("button",{type:"button",onClick:()=>y(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{ref:g,className:"af-work-load-skills-menu",onScroll:O,children:[$.collectionGroups.map(D=>{const T=D.skills.map(V=>V.key),W=T.filter(V=>j.has(V)).length,E=T.length>0&&W===T.length,Q=k.has(D.id);return i.jsxs("section",{className:"af-work-load-skills-menu__group"+(Q?" af-work-load-skills-menu__group--collapsed":""),children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head",children:[i.jsx("input",{type:"checkbox",checked:E,onChange:V=>L(T,V.target.checked),"aria-label":`选择 ${D.name}`}),i.jsx("button",{type:"button",className:"af-work-load-skills-menu__group-toggle",onClick:()=>F(D.id),"aria-expanded":!Q,children:i.jsxs("span",{className:"af-work-load-skills-menu__group-main",children:[i.jsx("span",{children:D.name}),D.description?i.jsx("em",{children:D.description}):null]})}),i.jsxs("small",{children:[W,"/",T.length]}),i.jsx("button",{type:"button",className:"af-work-load-skills-menu__group-arrow",onClick:()=>F(D.id),"aria-label":Q?`展开 ${D.name}`:`收起 ${D.name}`,children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:Q?"chevron_right":"expand_more"})})]}),Q?null:i.jsx("div",{className:"af-work-load-skills-menu__options",children:D.skills.map(V=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:j.has(V.key),onChange:B=>L([V.key],B.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:V.name}),V.description?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:V.description}):null]})]},`${D.id}:${V.key}`))})]},D.id)}),$.ungrouped.length>0?i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"Ungrouped"}),i.jsx("small",{children:$.ungrouped.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:$.ungrouped.map(D=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:j.has(D.key),onChange:T=>L([D.key],T.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:D.name}),D.description?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:D.description}):null]})]},`ungrouped:${D.key}`))})]}):null,$.collectionGroups.length===0&&$.ungrouped.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的 Skills"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:()=>a==null?void 0:a(e,[]),children:"清空"})]}),i.jsx("div",{ref:v,className:"af-work-load-skills-scrollbar"+(w.visible?" af-work-load-skills-scrollbar--visible":""),onPointerDown:H,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${w.height}%`,top:`${w.top}%`}})})]}):null]})]})}function PJ({id:e,data:t,selected:n,deleteNode:r,servers:s=[],onChangeMcpNames:o}){const a=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],l=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],[c,u]=m.useState(!1),[d,f]=m.useState(""),p=m.useMemo(()=>new Set(SJ(t)),[t]),h=m.useMemo(()=>(Array.isArray(s)?s:[]).map(b=>({name:String((b==null?void 0:b.name)||""),description:String((b==null?void 0:b.description)||""),detail:String((b==null?void 0:b.url)||[b==null?void 0:b.command,...Array.isArray(b==null?void 0:b.args)?b.args:[]].filter(Boolean).join(" ")||""),type:String((b==null?void 0:b.type)||"")})).filter(b=>b.name),[s]),y=m.useMemo(()=>{const b=d.trim().toLowerCase();return b?h.filter(g=>[g.name,g.description,g.detail,g.type].join(" ").toLowerCase().includes(b)):h},[d,h]),k=m.useCallback((b,g)=>{const v=new Set(p);for(const w of b)g?v.add(w):v.delete(w);o==null||o(e,Array.from(v))},[e,p,o]);return i.jsxs("div",{className:"af-work-load-skills-card"+(n?" af-work-load-skills-card--selected":"")+(c?" af-work-load-skills-card--menu-open":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[a.map((b,g)=>{if(b.showOnNode===!1)return null;const v=`${2.6+g*1.7}rem`,w=b.name||`#${g+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:v},children:w}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${g}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:v,background:Tn(b.type)},title:`${w} · ${b.type}`})]},`in-${g}`)}),l.map((b,g)=>{if(b.showOnNode===!1)return null;const v=`${2.6+g*1.7}rem`,w=b.name||`#${g+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:v},children:w}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${g}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:v,background:Tn(b.type)},title:`${w} · ${b.type}`})]},`out-${g}`)}),i.jsxs("div",{className:"af-work-load-skills-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"hub"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"Load MCP"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"control_load_mcp"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-load-skills-card__body nodrag",children:[i.jsxs("button",{type:"button",className:"af-work-load-skills-card__select",onClick:b=>{var g;b.stopPropagation(),c||(g=t==null?void 0:t.onRefreshMcps)==null||g.call(t),u(v=>!v)},children:[i.jsx("span",{children:p.size>0?`${p.size} MCP selected`:"选择 MCP"}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:c?"expand_less":"expand_more"})]}),c?i.jsxs("div",{className:"af-work-load-skills-menu-shell",onClick:b=>b.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:d,onChange:b=>f(b.target.value),placeholder:"搜索 MCP...",spellCheck:!1,autoComplete:"off","aria-label":"搜索 MCP"}),d?i.jsx("button",{type:"button",onClick:()=>f(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{className:"af-work-load-skills-menu",children:[i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"MCP Servers"}),i.jsx("small",{children:y.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:y.map(b=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:p.has(b.name),onChange:g=>k([b.name],g.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:b.name}),b.description||b.detail?i.jsx("span",{className:"af-work-load-skills-menu__option-desc",children:b.description||b.detail}):null]})]},b.name))})]}),y.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的 MCP"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:()=>o==null?void 0:o(e,[]),children:"清空"})]})]}):null]})]})}function IJ({id:e,data:t,selected:n,deleteNode:r,workspaces:s=[],onChangeWorkspace:o,onRefreshWorkspaces:a}){const l=Array.isArray(t==null?void 0:t.inputs)?t.inputs:[],c=Array.isArray(t==null?void 0:t.outputs)?t.outputs:[],[u,d]=m.useState(!1),[f,p]=m.useState(""),h=jJ(t),y=m.useMemo(()=>(Array.isArray(s)?s:[]).map(j=>({id:String((j==null?void 0:j.id)||""),label:String((j==null?void 0:j.label)||(j==null?void 0:j.name)||"知识库"),kind:(j==null?void 0:j.kind)==="git"?"git":"local",path:String((j==null?void 0:j.path)||""),repoUrl:String((j==null?void 0:j.repoUrl)||""),branch:String((j==null?void 0:j.branch)||""),mountPath:String((j==null?void 0:j.mountPath)||""),builtin:(j==null?void 0:j.builtin)===!0,exists:(j==null?void 0:j.exists)!==!1})).filter(j=>j.path),[s]),k=m.useMemo(()=>{const j=f.trim().toLowerCase();return j?y.filter(C=>[C.id,C.label,C.path,C.repoUrl,C.branch,C.mountPath].join(" ").toLowerCase().includes(j)):y},[f,y]),b=m.useMemo(()=>new Set((h.sources||[]).map(j=>j.id||j.path||j.repoPath).filter(Boolean)),[h.sources]),g=m.useMemo(()=>(h.sources||[]).map(j=>j.label||j.id||j.mountPath||j.path),[h.sources]),v=m.useMemo(()=>aM(g,"选择知识库"),[g]),w=mb(u,[k.length,g.length,f]),N=(j,C)=>{const P=(j==null?void 0:j.id)||(j==null?void 0:j.path)||"",I=y.filter(z=>{const $=z.id||z.path||"";return $===P?C:b.has($)});o==null||o(e,I)};return i.jsxs("div",{className:"af-work-load-skills-card af-work-load-workspace-card"+(n?" af-work-load-skills-card--selected":"")+(u?" af-work-load-skills-card--menu-open":""),onPointerDownCapture:t==null?void 0:t.onSelectNodePointerDown,children:[l.map((j,C)=>{if(j.showOnNode===!1)return null;const P=`${2.6+C*1.7}rem`,I=j.name||`#${C+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--in",style:{top:P},children:I}),i.jsx(Gn,{type:"target",position:qe.Left,id:`input-${C}`,className:"af-work-display-handle af-work-display-handle--in",style:{top:P,background:Tn(j.type)},title:`${I} · ${j.type}`})]},`in-${C}`)}),c.map((j,C)=>{if(j.showOnNode===!1)return null;const P=`${2.6+C*1.7}rem`,I=j.name||`#${C+1}`;return i.jsxs(m.Fragment,{children:[i.jsx("span",{className:"af-work-port-label af-work-port-label--out",style:{top:P},children:I}),i.jsx(Gn,{type:"source",position:qe.Right,id:`output-${C}`,className:"af-work-display-handle af-work-display-handle--out",style:{top:P,background:Tn(j.type)},title:`${I} · ${j.type}`})]},`out-${C}`)}),i.jsxs("div",{className:"af-work-load-skills-card__head",children:[i.jsx("span",{className:"material-symbols-outlined",children:"folder_managed"}),i.jsx("strong",{children:(t==null?void 0:t.label)||"加载知识库"}),i.jsx("span",{children:(t==null?void 0:t.definitionId)||"control_cd_workspace"}),i.jsx("button",{type:"button",className:"af-work-display-card__close nodrag",onClick:()=>r==null?void 0:r(e),"aria-label":"删除节点",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-work-load-skills-card__body nodrag",children:[i.jsxs("button",{type:"button",className:"af-work-load-skills-card__select",onClick:j=>{j.stopPropagation(),u||a==null||a(),d(C=>!C)},children:[i.jsxs("span",{className:"af-work-load-skills-card__summary",title:v.title,children:[i.jsx("span",{className:"af-work-load-skills-card__summary-main",children:v.head}),v.extra?i.jsx("span",{className:"af-work-load-skills-card__summary-extra",children:v.extra}):null]}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:u?"expand_less":"expand_more"})]}),u?i.jsxs("div",{className:"af-work-load-skills-menu-shell",onClick:j=>j.stopPropagation(),children:[i.jsxs("div",{className:"af-work-load-skills-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:f,onChange:j=>p(j.target.value),placeholder:"搜索知识库...",spellCheck:!1,autoComplete:"off","aria-label":"搜索知识库"}),f?i.jsx("button",{type:"button",onClick:()=>p(""),"aria-label":"清空搜索",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})}):null]}),i.jsxs("div",{ref:w.menuRef,className:"af-work-load-skills-menu",onScroll:w.updateMenuScrollbar,children:[i.jsxs("section",{className:"af-work-load-skills-menu__group",children:[i.jsxs("div",{className:"af-work-load-skills-menu__group-head af-work-load-skills-menu__group-head--plain",children:[i.jsx("span",{children:"知识库"}),i.jsx("small",{children:k.length})]}),i.jsx("div",{className:"af-work-load-skills-menu__options",children:k.map(j=>i.jsxs("label",{className:"af-work-load-skills-menu__option",children:[i.jsx("input",{type:"checkbox",checked:b.has(j.id||j.path),onChange:C=>N(j,C.target.checked)}),i.jsxs("span",{className:"af-work-load-skills-menu__option-main",children:[i.jsx("span",{className:"af-work-load-skills-menu__option-title",children:j.label}),i.jsxs("span",{className:"af-work-load-skills-menu__option-desc",children:[j.kind==="git"&&j.repoUrl?`${j.repoUrl}${j.branch?` · ${j.branch}`:""}${j.mountPath?` · ${j.mountPath}`:""}`:j.path,j.exists?"":" · 路径未就绪"]})]})]},`${j.id}:${j.path}`))})]}),k.length===0?i.jsx("div",{className:"af-work-load-skills-menu__empty",children:"没有匹配的知识库"}):null,i.jsx("button",{type:"button",className:"af-work-load-skills-menu__clear",onClick:()=>o==null?void 0:o(e,[]),children:"清空知识库"})]}),i.jsx("div",{ref:w.scrollbarTrackRef,className:"af-work-load-skills-scrollbar"+(w.scrollbar.visible?" af-work-load-skills-scrollbar--visible":""),onPointerDown:w.handleScrollbarPointerDown,"aria-hidden":"true",children:i.jsx("span",{style:{height:`${w.scrollbar.height}%`,top:`${w.scrollbar.top}%`}})})]}):null]})]})}function pM({row:e,index:t=0,child:n=!1}){const r=(e==null?void 0:e.issue)||{},s=vT(r),o=VU(rG(r)),a=s?o.filter(p=>!["issue","mr"].includes(sm(p))):o,l=qU(r,o),c=_i(r,t),u=s?"":Ta(r.platform),d=Array.isArray(e==null?void 0:e.children)?e.children.length:0,f=[c,s&&d?`${d} 个端侧 Issue`:u,r.status].filter(Boolean);return i.jsxs("div",{className:`af-prd-workflow-issue${n?" af-prd-workflow-issue--child":""}${s?" af-prd-workflow-issue--aggregate":""}`,children:[i.jsx("strong",{children:eG(r,t)}),i.jsx("small",{children:f.join(" · ")}),i.jsxs("div",{className:"af-prd-workflow-issue__state-row",children:[i.jsx("span",{className:`af-prd-workflow-issue__state af-prd-workflow-issue__state--${l.kind}`,children:l.label}),l.detail?i.jsx("small",{children:l.detail}):null]}),a.length?i.jsx("div",{className:"af-prd-workflow-issue__links",children:a.map(p=>i.jsx("a",{href:p.href,target:"_blank",rel:"noreferrer",children:p.label},`${p.label}-${p.href}`))}):null,d?i.jsx("div",{className:"af-prd-workflow-issue__children",children:e.children.map((p,h)=>i.jsx(pM,{row:p,index:h,child:!0},_i((p==null?void 0:p.issue)||{},h)))}):null]})}function hM(e){return e==null?"":typeof e=="string"||typeof e=="number"?String(e).trim():typeof e!="object"||Array.isArray(e)?"":String(e.label||e.name||e.value||e.key||e.code||e.username||e.userId||"").trim()}function mM(e){return(Array.isArray(e)?e:e==null||e===""?[]:[e]).map(n=>hM(n)).filter(Boolean)}function RJ({fieldKey:e,field:t}){if(!t||typeof t!="object"||Array.isArray(t))return null;const n=String(t.label||e||"").trim(),r=String(t.type||"text").trim().toLowerCase(),s=["text","user","chips","list","link"].includes(r)?r:"text",o=mM(t.value);if(!o.length)return null;if(s==="list")return i.jsxs("div",{className:"af-prd-overall-platform__rules",children:[i.jsx("small",{children:n}),i.jsx("ul",{children:o.map((a,l)=>i.jsx("li",{children:a},`${e}-${l}-${a}`))})]});if(s==="link"){const a=t.value&&typeof t.value=="object"&&!Array.isArray(t.value)?t.value:{},l=String(t.href||t.url||a.href||a.url||"").trim();return i.jsxs("div",{className:"af-prd-overall-platform__row af-prd-overall-platform__row--link",children:[i.jsx("small",{children:n}),l?i.jsxs("a",{href:l,target:"_blank",rel:"noreferrer",children:[i.jsx("span",{children:o[0]}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"})]}):i.jsx("strong",{children:o[0]})]})}return i.jsxs("div",{className:`af-prd-overall-platform__row af-prd-overall-platform__row--${s}`,children:[i.jsx("small",{children:n}),i.jsx("div",{children:o.map((a,l)=>i.jsx("span",{children:a},`${e}-${l}-${a}`))})]})}function TJ({sectionKey:e,section:t}){if(!t||typeof t!="object"||Array.isArray(t))return null;const r=(t.fields&&typeof t.fields=="object"&&!Array.isArray(t.fields)?Object.entries(t.fields):[]).filter(([,o])=>o&&typeof o=="object"&&mM(o.value).length);if(!r.length)return null;const s=e==="progress";return i.jsxs("section",{className:`af-prd-overall-platform${s?" af-prd-overall-platform--compact":""}`,children:[i.jsx("div",{className:"af-prd-overall-platform__head",children:i.jsx("strong",{children:String(t.title||e||"").trim()})}),i.jsx("div",{className:"af-prd-overall-platform__fields",children:r.map(([o,a])=>i.jsx(RJ,{fieldKey:o,field:a},o))})]})}function MJ({globalState:e,tapdId:t}){const n=e&&typeof e=="object"&&!Array.isArray(e)?e:{},r=n.workflow&&typeof n.workflow=="object"&&!Array.isArray(n.workflow)?n.workflow:{},s=n.sections&&typeof n.sections=="object"&&!Array.isArray(n.sections)?n.sections:{},o=String(n.title||"").trim(),a=String(n.url||"").trim(),l=hM(n.status),c=String(r.id||t||"").trim(),u=Object.entries(s).filter(([f,p])=>f&&p&&typeof p=="object"&&!Array.isArray(p)),d=!!(o||a||l||u.length);return!c&&!d?null:i.jsxs("article",{className:"af-prd-workflow-card af-prd-overall",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"需求概览"}),l?i.jsx("span",{className:"af-prd-overall__status",children:l}):null]}),o||a||c?i.jsx("div",{className:"af-prd-overall__requirement",children:a?i.jsxs("a",{href:a,target:"_blank",rel:"noreferrer",children:[i.jsx("strong",{children:o||`${r.namespace||"Workflow"} ${c}`}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"})]}):i.jsx("strong",{children:o||`${r.namespace==="tapd"?"TAPD":"Workflow"} ${c}`})}):null,d?i.jsx("div",{className:"af-prd-overall__platforms",children:u.map(([f,p])=>i.jsx(TJ,{sectionKey:f,section:p},f))}):i.jsx("p",{className:"af-prd-workflow-muted",children:"暂无全局状态。各阶段可通过 Workflow 上报逐步补充负责人、配置、规则和其它上下文。"})]})}function $J({flowParams:e={},tapdId:t,setTapdId:n,snapshot:r,loading:s,error:o,actionRunning:a,actionOutput:l,pendingConfirm:c,conflict:u,reviewPublishing:d,onRefresh:f,onRunDryRun:p,onConfirmAction:h,onRetryConflict:y,onPublishReview:k}){const[b,g]=m.useState("all"),[v,w]=m.useState("all"),[N,j]=m.useState(!1),[C,P]=m.useState(!1),[I,z]=m.useState(!1),[$,L]=m.useState(""),[F,O]=m.useState(!1),[M,K]=m.useState(""),[H,D]=m.useState(null),T=String((r==null?void 0:r.phase)||(t?"unavailable":"unselected")),W=Array.isArray(r==null?void 0:r.issues)?r.issues:[],E=sG(r),Q=E.reduce((xe,Fe)=>xe+sb(Fe.issues),0),V=Array.isArray(r==null?void 0:r.artifacts)?r.artifacts:[];Array.isArray(r==null?void 0:r.optionalGaps)&&r.optionalGaps;const B=r!=null&&r.nextAction&&typeof r.nextAction=="object"?r.nextAction:null,se=lG(r,B),ue=QY(r,se),G=V.filter(xe=>!NT({...xe,href:hc(xe)})),ee=m.useMemo(()=>GY(se),[se]);m.useEffect(()=>{v!=="all"&&(ee.some(xe=>xe.key===v)||w("all"))},[v,ee]);const te=se.filter(xe=>JY(xe,v)),ne=UY(te),Z=cG(r),ce=Z.filter(xe=>uG(xe,b)),de=te.filter(xe=>dv(xe)).length,me=r!=null&&r.collaboration&&typeof r.collaboration=="object"?r.collaboration:{},$e=me.activeAction&&typeof me.activeAction=="object"?me.activeAction:null;Array.isArray(r==null?void 0:r.clientObservations)&&r.clientObservations;const Ce=String((r==null?void 0:r.rawOutput)||""),_e=r!=null&&r.globalState&&typeof r.globalState=="object"?r.globalState:null,Be=FY(T),ot=m.useCallback(async()=>{const xe=String(t||"").trim();if(!xe){D(null);return}P(!0),L(""),K("");try{const Fe=new URLSearchParams({tapdId:xe});e.workflowShare&&Fe.set("workflowShare",e.workflowShare);const lt=await fetch(`/api/prd-workflow/share?${Fe.toString()}`),oe=await lt.json().catch(()=>({}));if(!lt.ok)throw new Error(oe.error||"读取 Workflow 分享状态失败");let ke=oe.share||null;const Ke=oe.canCreate===!0&&!e.workflowShare;if(O(Ke),!ke&&Ke){const Ue=await fetch("/api/prd-workflow/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,tapdId:xe})}),be=await Ue.json().catch(()=>({}));if(!Ue.ok)throw new Error(be.error||"生成 Workflow 分享链接失败");ke=be.share||null}D(ke)}catch(Fe){L(String(Fe.message||Fe))}finally{P(!1)}},[e,t]),yt=()=>{j(!0),ot()},Te=async()=>{if(!(!t||I||e.workflowShare)){z(!0),L(""),K("");try{const xe=await fetch("/api/prd-workflow/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,tapdId:t})}),Fe=await xe.json().catch(()=>({}));if(!xe.ok)throw new Error(Fe.error||"生成 Workflow 分享链接失败");D(Fe.share||null),O(!0)}catch(xe){L(String(xe.message||xe))}finally{z(!1)}}},st=async()=>{const xe=await pb((H==null?void 0:H.url)||"");K(xe?"已复制":"复制失败")},gt=async()=>{if(!(!t||I||!(H!=null&&H.canManage))){z(!0),L(""),K("");try{const xe=await fetch("/api/prd-workflow/share",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({tapdId:t})}),Fe=await xe.json().catch(()=>({}));if(!xe.ok)throw new Error(Fe.error||"取消 Workflow 分享链接失败");D(null),O(!0)}catch(xe){L(String(xe.message||xe))}finally{z(!1)}}};return i.jsxs("main",{className:"af-prd-workflow af-prd-workflow--timeline","aria-label":"PRD Workflow",children:[i.jsxs("section",{className:"af-prd-workflow__statusbar",children:[i.jsxs("div",{className:"af-prd-workflow__status-main",children:[i.jsx("span",{className:`af-prd-workflow-phase af-prd-workflow-phase--${T.toLowerCase().replace(/[^a-z0-9_-]+/gi,"_")}`,children:SC(T)}),i.jsx("h1",{children:(r==null?void 0:r.pointer)||(t?"等待 prd-flow 返回状态":"选择 TAPD 需求后读取状态")}),i.jsx("p",{className:"af-prd-workflow__status-subtitle",children:t?i.jsxs(i.Fragment,{children:["TAPD ",i.jsx("strong",{children:t})," · 独立需求 Workflow"]}):i.jsx(i.Fragment,{children:"尚未选择 TAPD 需求"})}),o?i.jsx("p",{className:"af-prd-workflow-error",children:o}):null,$e||me.subscribers?i.jsxs("div",{className:"af-prd-workflow-collab",children:[$e?i.jsxs("span",{children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"lock"}),$e.title||$e.action||"Workflow action"," 执行中",$e.userId?i.jsx("small",{children:$e.userId}):null]}):null,me.subscribers?i.jsxs("span",{children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"group"}),me.subscribers," 个连接"]}):null]}):null]}),i.jsxs("form",{className:"af-prd-workflow__lookup",onSubmit:xe=>{xe.preventDefault(),f==null||f()},children:[i.jsx("div",{className:"af-prd-workflow-flow","aria-label":"需求流程阶段",children:Be.map(xe=>i.jsxs("div",{className:`af-prd-workflow-flow__step af-prd-workflow-flow__step--${xe.status}`,children:[i.jsx("span",{"aria-hidden":"true"}),i.jsx("small",{children:xe.label})]},xe.label))}),i.jsxs("div",{className:"af-prd-workflow__lookup-row",children:[i.jsxs("label",{children:[i.jsx("span",{children:"TAPD Workflow"}),i.jsx("input",{value:t,onChange:xe=>n(xe.target.value),placeholder:"输入需求 ID",autoComplete:"off",spellCheck:!1})]}),i.jsxs("button",{type:"submit",disabled:s,children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:s?"hourglass_empty":"sync"}),s?"读取中":t?"刷新":"读取"]}),i.jsxs("button",{type:"button",disabled:!t,onClick:yt,children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"share"}),"分享"]})]})]})]}),u?i.jsxs("section",{className:"af-prd-workflow-conflict","aria-label":"Workflow conflict",children:[i.jsxs("div",{children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"sync_problem"}),i.jsxs("div",{children:[i.jsx("strong",{children:"状态已变化,需要重新确认"}),i.jsx("p",{children:u.message||"当前 workflow 状态和执行前不一致。"})]})]}),i.jsxs("dl",{children:[i.jsxs("div",{children:[i.jsx("dt",{children:"执行时 revision"}),i.jsx("dd",{children:u.expectedRevision||"空"})]}),i.jsxs("div",{children:[i.jsx("dt",{children:"当前 revision"}),i.jsx("dd",{children:u.currentRevision||"未知"})]}),i.jsxs("div",{children:[i.jsx("dt",{children:"当前状态"}),i.jsx("dd",{children:[SC(u.currentPhase),u.currentPointer].filter(Boolean).join(" · ")||"未知"})]})]}),i.jsx("div",{className:"af-prd-workflow-conflict__actions",children:i.jsx("button",{type:"button",onClick:()=>f==null?void 0:f(),disabled:s||a,children:"刷新状态"})})]}):null,i.jsxs("section",{className:"af-prd-workflow__main",children:[i.jsxs("article",{className:"af-prd-workflow-actions","aria-label":"Workflow actions",children:[i.jsxs("div",{className:"af-prd-workflow-actions__head",children:[i.jsxs("div",{children:[i.jsx("h2",{children:"Action 时间线"}),i.jsx("p",{children:se.length?`${de}/${te.length} 已完成${v!=="all"?` · 共 ${se.length}`:""}`:"等待 prd-flow 返回 action 列表"})]}),B&&Yd(B)?i.jsxs("div",{className:"af-prd-workflow-local-command",children:[i.jsx("span",{children:"本地 agent 执行"}),i.jsx("code",{children:B.command||to(B,0)})]}):null]}),ee.length?i.jsxs("div",{className:"af-prd-workflow-action-filters","aria-label":"Action tag filters",children:[i.jsxs("button",{type:"button",className:v==="all"?"is-active":"","aria-pressed":v==="all",onClick:()=>w("all"),children:["全部 ",i.jsx("span",{children:se.length})]}),ee.map(xe=>i.jsxs("button",{type:"button",className:v===xe.key?"is-active":"","aria-pressed":v===xe.key,onClick:()=>w(xe.key),children:[xe.label," ",i.jsx("span",{children:xe.count})]},xe.key))]}):null,i.jsx("div",{className:"af-prd-workflow-action-list",children:te.length?ne.map(xe=>i.jsxs("section",{className:"af-prd-workflow-action-day",children:[i.jsxs("div",{className:"af-prd-workflow-action-day__label",children:[i.jsx("span",{children:xe.day}),i.jsx("small",{children:"北京时间"})]}),i.jsx("div",{className:"af-prd-workflow-action-day__items",children:xe.items.map(({item:Fe,index:lt})=>{const oe=ca(Fe.status),ke=Zo(Fe)==="observation"&&oe==="done"?"observed":oe,Ke=pv(Fe),Ue=qY(Fe),be=XY(Fe),Ht=BY(Fe,lt),Qt=HY(Fe);return i.jsxs("div",{className:`af-prd-workflow-action af-prd-workflow-action--${ke}`,children:[i.jsx("div",{className:"af-prd-workflow-action__rail",children:i.jsx("span",{className:"af-prd-workflow-action__dot"})}),i.jsxs("div",{className:"af-prd-workflow-action__body",children:[i.jsxs("div",{className:"af-prd-workflow-action__top",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"af-prd-workflow-action__title",children:[Ue?i.jsx("time",{dateTime:um(Fe),children:Ue}):null,i.jsx("strong",{children:Ht})]}),Qt?i.jsx("p",{children:Qt}):null,be.length?i.jsx("div",{className:"af-prd-workflow-action__meta",children:be.map(jt=>i.jsxs("span",{children:[i.jsx("b",{children:jt.label}),jt.value]},`${jt.label}-${jt.value}`))}):null]}),i.jsx("span",{className:"af-prd-workflow-action__status",children:YY(Fe)})]}),Ke.length?i.jsx("div",{className:"af-prd-workflow-action__links",children:Ke.map(jt=>i.jsxs("a",{href:jt.href,target:"_blank",rel:"noreferrer",children:[i.jsx("span",{children:jt.label}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"})]},`${jt.label}-${jt.href}`))}):null]})]},Fe.id||Fe.actionId||`${to(Fe,lt)}-${lt}`)})})]},xe.day)):i.jsxs("div",{className:"af-prd-workflow-action-empty",children:[i.jsx("strong",{children:t?se.length?"当前 tag 下暂无 action":"暂无 prd-flow 上报 action":"先选择 TAPD 需求"}),i.jsx("p",{children:t?se.length?"切换到其它 tag 或查看全部。":"Workflow tab 不会生成默认步骤;需要 prd-flow snapshot 返回 actions/timeline/events/history 或 nextAction。":"选择后从 prd-flow 读取真实 action、产物和 URL。"})]})})]}),i.jsxs("aside",{className:"af-prd-workflow-side","aria-label":"Workflow related links",children:[i.jsx(MJ,{globalState:_e,tapdId:t}),G.length?i.jsxs("article",{className:"af-prd-workflow-card",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"关联产物"}),i.jsx("span",{children:G.length})]}),i.jsx("div",{className:"af-prd-workflow-list",children:G.map((xe,Fe)=>{const lt=hc(xe),oe=String(xe.label||xe.title||xe.kind||lt||`Artifact ${Fe+1}`);return lt?i.jsxs("a",{href:lt,target:"_blank",rel:"noreferrer",children:[i.jsx("span",{children:oe}),i.jsx("small",{children:xe.kind||lt})]},`${lt}-${Fe}`):i.jsxs("div",{children:[i.jsx("span",{children:oe}),i.jsx("small",{children:xe.kind||""})]},`${oe}-${Fe}`)})})]}):null,i.jsxs("article",{className:"af-prd-workflow-card",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"AI Docs"}),i.jsx("span",{children:ue.length})]}),i.jsx("div",{className:"af-prd-workflow-list",children:ue.length?ue.map(xe=>{const Fe=String(xe.title||xe.label||"ai-doc").trim(),lt=[xe.label&&xe.label!==Fe?xe.label:"",xe.platform,xe.issueKey].filter(Boolean);return i.jsxs("a",{className:"af-prd-ai-doc",href:xe.href,target:"_blank",rel:"noreferrer",title:Fe,children:[i.jsx("span",{className:"af-prd-ai-doc__title",children:Fe}),i.jsx("small",{className:"af-prd-ai-doc__meta",children:lt.join(" · ")||xe.kind||"ai-doc"})]},xe.href)}):i.jsx("p",{className:"af-prd-workflow-muted",children:"暂无 ai-doc 文档。"})})]}),i.jsxs("article",{className:"af-prd-workflow-card",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"Issues"}),i.jsx("span",{children:Q||W.length})]}),i.jsx("div",{className:"af-prd-workflow-issues",children:E.length?E.map(xe=>i.jsxs("div",{className:"af-prd-workflow-epic",children:[i.jsxs("div",{className:"af-prd-workflow-epic__head",children:[i.jsx("strong",{children:xe.title||xe.key}),i.jsx("small",{children:sb(xe.issues)})]}),xe.issues.map((Fe,lt)=>i.jsx(pM,{row:Fe,index:lt},_i((Fe==null?void 0:Fe.issue)||{},lt)))]},xe.key)):i.jsx("p",{className:"af-prd-workflow-muted",children:"暂无 Issue 信息。"})})]}),i.jsxs("article",{className:"af-prd-workflow-card",children:[i.jsxs("div",{className:"af-prd-workflow-card__head",children:[i.jsx("h2",{children:"运行审计"}),i.jsxs("span",{children:[ce.length,"/",Z.length]})]}),i.jsx("div",{className:"af-prd-workflow-audit-filter",role:"tablist","aria-label":"运行审计筛选",children:[["all","全部"],["errors","异常"],["review","Review"],["external","外部"]].map(([xe,Fe])=>i.jsx("button",{type:"button",className:b===xe?"is-active":"",onClick:()=>g(xe),children:Fe},xe))}),i.jsx("div",{className:"af-prd-workflow-audit",children:ce.length?ce.map((xe,Fe)=>i.jsxs("div",{children:[i.jsx("strong",{children:to(xe,Fe)}),i.jsx("small",{children:[xe.status,xe.type,um(xe)].filter(Boolean).join(" · ")})]},xe.id||`${xe.type}-${Fe}`)):i.jsx("p",{className:"af-prd-workflow-muted",children:"暂无运行事件。"})})]}),Ce||l?i.jsxs("article",{className:"af-prd-workflow-card af-prd-workflow-card--raw",children:[i.jsx("div",{className:"af-prd-workflow-card__head",children:i.jsx("h2",{children:"Raw"})}),i.jsx("pre",{children:l||Ce})]}):null]})]}),N?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-share-modal af-display-link-modal",role:"dialog","aria-modal":"true","aria-label":"分享需求 Workflow",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"share"}),"分享需求 Workflow"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>j(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("p",{className:"af-display-link-modal__empty",children:["通过只读链接分享 TAPD ",t," 的需求流程;不会分享当前 Project、画布或项目文件。"]}),C?i.jsx("div",{className:"af-display-link-modal__empty",children:"正在生成分享链接..."}):null,!C&&(H!=null&&H.url)?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"af-display-link-modal__url",children:[i.jsx("input",{type:"text",value:H.url,readOnly:!0,onFocus:xe=>xe.currentTarget.select(),"aria-label":"Workflow 分享链接"}),i.jsxs("button",{type:"button",disabled:I,onClick:()=>void st(),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"content_copy"}),M||"复制链接"]}),H.canManage?i.jsx("button",{type:"button",disabled:I,onClick:()=>void gt(),children:I?"处理中...":"取消分享"}):null]}),i.jsx("div",{className:"af-prd-workflow-share-note",children:"获得链接的 AgentFlow 用户可以只读查看同一份 Workflow;链接不会授予需求推进或项目编辑权限。"})]}):null,!C&&!(H!=null&&H.url)&&F?i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",disabled:I,onClick:()=>void Te(),children:I?"生成中...":"生成分享链接"}):null,$?i.jsx("div",{className:"af-flow-snippet-error",children:$}):null]}),i.jsx("div",{className:"af-flow-snippet-modal__foot",children:i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",onClick:()=>j(!1),children:"完成"})})]})}),document.body):null]})}function GC(e,t){if(!(e!=null&&e[`has${t[0].toUpperCase()}${t.slice(1)}`]))return"(删除该字段)";const n=e==null?void 0:e[t];if(typeof n=="string")return n;try{return JSON.stringify(n,null,2)}catch{return String(n)}}function Ru(e){if(!(e!=null&&e.hasIncoming))return"null";try{return JSON.stringify(e.incoming,null,2)}catch{return JSON.stringify(String(e.incoming))}}function LJ(e,t,n,r=!0){const s=JSON.parse(JSON.stringify(e||{})),o=Array.isArray(t)?t:[];if(!o.length)return r?n:{};let a=s;for(let c=0;c<o.length-1;c+=1){const u=o[c],d=o[c+1];(!a[u]||typeof a[u]!="object")&&(a[u]=Number.isInteger(d)?[]:{}),a=a[u]}const l=o[o.length-1];return r?a[l]=n:Array.isArray(a)&&Number.isInteger(l)?a.splice(l,1):delete a[l],s}function OJ(){var b0,k0,v0;const{t:e,i18n:t}=Fr(),{navigate:n}=si(),r=Fc(),s=gn(),o=IW(),a=m.useMemo(CY,[]),l=!!a.workflowShare,c=m.useRef(new URLSearchParams(window.location.search).get("focusNodeId")||""),u=m.useMemo(()=>a.workspaceId?`agentflow.workspace.viewport:shared:${a.workspaceId}`:`agentflow.workspace.viewport:${a.flowSource||"user"}:${a.flowId||""}`,[a]),[d,f]=m.useState(()=>(()=>{if(a.workflowShare)return"workflow";const x=new URLSearchParams(window.location.search).get("view");return x==="display"||x==="workflow"?x:"workspace"})()),[p,h]=m.useState(!1),[y,k]=m.useState(!1),[b,g]=RW([]),[v,w]=TW([]),N=m.useRef([]),j=m.useRef([]),C=m.useRef(null),[P,I]=m.useState(()=>hh(null,[])),z=m.useRef(P),[$,L]=m.useState(null),F=m.useRef(null),O=m.useRef(!1),[M,K]=m.useState([]),H=m.useRef(new Map),D=m.useRef(new Map),T=m.useRef(new Set),W=m.useRef(new Set),E=m.useRef(null),Q=m.useRef(null),V=m.useRef([]),B=m.useRef(null),se=m.useRef(null),ue=m.useRef(null),[G,ee]=m.useState(null),[te,ne]=m.useState({}),Z=m.useRef({}),ce=m.useRef(!1),de=m.useRef(null),me=m.useRef(""),$e=m.useRef(null),Ce=m.useRef(Promise.resolve()),_e=m.useRef({running:!1,pending:null}),Be=m.useRef(0),ot=m.useRef(!1),yt=m.useRef(0),Te=m.useRef(null),st=m.useRef(!1),gt=m.useRef(!1),xe=m.useRef(""),Fe=m.useRef(!1),lt=m.useRef(!1),oe=m.useRef(!1),ke=m.useRef(typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`client-${Date.now()}-${Math.random().toString(36).slice(2)}`),Ke=m.useRef(!1),Ue=m.useRef(null),[be,Ht]=m.useState([]),Qt=m.useRef([]),[jt,yn]=m.useState(""),[on,re]=m.useState("nodes"),[Re,Je]=m.useState([]),[Ze,Tt]=m.useState(!1),[At,Vn]=m.useState(""),[Sn,xr]=m.useState(!1),[wn,Xn]=m.useState({name:"",id:"",description:""}),[Kn,hr]=m.useState(!1),[ts,Ar]=m.useState(""),[gs,ys]=m.useState(""),cn=m.useRef(null),[rr,Pr]=m.useState(!1),[dn,Qn]=m.useState(!1),[br,sr]=m.useState(""),[Ct,Gt]=m.useState(null),[_t,le]=m.useState(()=>lw()),[ve,it]=m.useState(""),[Dt,Jt]=m.useState(!1),[tn,Zn]=m.useState(""),[mt,nn]=m.useState(!1),[Wt,kr]=m.useState([]),[tt,Ln]=m.useState(!1),[$i,zr]=m.useState(""),[mo,ai]=m.useState(""),[Ts,ie]=m.useState(""),[Se,Pe]=m.useState(!1),[xt,Lt]=m.useState(""),[qt,zn]=m.useState(""),[On,q]=m.useState(!1),[he,Oe]=m.useState("nodes"),[Ee,et]=m.useState(""),[Nn,kt]=m.useState(0),[Ut,jn]=m.useState(""),go=m.useRef(""),[at,ws]=m.useState(null),Rv=m.useRef(null),[l$,al]=m.useState(""),[ll,Tv]=m.useState([]),[Mv,c$]=m.useState(""),[je,u$]=m.useState(!0),[an,gg]=m.useState(null),[d$,yg]=m.useState(!1),[wg,$v]=m.useState(!1),[Lv,Yc]=m.useState(""),[Gc,Ov]=m.useState(""),[Dv,Fv]=m.useState(""),[En,cl]=m.useState(null),[f$,ua]=m.useState(!1),[xg,ul]=m.useState({}),[vf,zv]=m.useState(!1),[Bv,Jc]=m.useState(""),[bg,p$]=m.useState(""),[h$,dl]=m.useState(()=>new Set),[kg,vg]=m.useState(""),[Xc,Sg]=m.useState({nodeId:"",query:""}),[Hv,Wv]=m.useState(!1),Ng=m.useRef(null),Vv=m.useRef(null),Kv=m.useRef(""),[jg,qv]=m.useState(()=>{try{const x=Number(window.localStorage.getItem("agentflow.workspace.filesPaneHeight")||0);if(Number.isFinite(x)&&x>=160)return x}catch{}return 360}),[m$,Uv]=m.useState(!1),[da,g$]=m.useState({cursor:[],opencode:[],claudeCode:[],codex:[]}),[Li,y$]=m.useState(""),[Ms,w$]=m.useState([]),[Yv,Gv]=m.useState(!1),[$s,Qc]=m.useState([]),[fl,x$]=m.useState([]),[Jv,b$]=m.useState(!1),[Xv,Qv]=m.useState([]),[Zv,eS]=m.useState([]),[ir,k$]=m.useState(()=>{try{const x=String(new URLSearchParams(window.location.search).get("tapdId")||"").trim();return x||String(window.localStorage.getItem(`agentflow.workflow.tapdId:${a.flowSource||"user"}:${a.flowId||""}`)||"").trim()}catch{return""}}),[ln,Sf]=m.useState(null),[v$,tS]=m.useState(!1),[S$,pl]=m.useState(""),[Cg,nS]=m.useState(!1),[_g,Nf]=m.useState(""),[xs,jf]=m.useState(null),[Eg,rS]=m.useState(!1),[Zc,eu]=m.useState(null),sS=m.useCallback(x=>{cn.current&&window.clearTimeout(cn.current),ys(x),cn.current=window.setTimeout(()=>{ys(""),cn.current=null},3800)},[]),Br=m.useCallback(x=>{const S=Array.isArray(x)||x instanceof Set?x:[x];for(const _ of S){const A=String(_||"").trim();A&&(T.current.add(A),W.current.add(A))}T.current.size!==0&&(E.current==null&&(E.current=window.requestAnimationFrame(()=>{E.current=null;const _=Array.from(T.current);T.current.clear(),_.forEach(A=>o(A))})),Q.current!=null&&window.clearTimeout(Q.current),Q.current=window.setTimeout(()=>{Q.current=null;const _=Array.from(W.current);W.current.clear(),_.forEach(A=>o(A))},80))},[o]);m.useEffect(()=>()=>{E.current!=null&&window.cancelAnimationFrame(E.current),Q.current!=null&&window.clearTimeout(Q.current),T.current.clear(),W.current.clear()},[]);const iS=m.useCallback((x,S)=>{const _=String(x||"").trim(),A=mm(S);!_||!A||(g(R=>R.map(U=>{var ae;if(U.id!==_)return U;const X=mm((ae=U.data)==null?void 0:ae.displaySize),J=X&&X.width===A.width&&X.height===A.height,Y=Math.round(Number(U.width||0))===A.width&&Math.round(Number(U.height||0))===A.height;return J&&Y?U:{...U,width:A.width,height:A.height,data:{...U.data,nodeSize:A,displaySize:A}}})),Br(_))},[Br,g]);m.useEffect(()=>{try{window.localStorage.setItem("agentflow.workspace.filesPaneHeight",String(Math.round(jg)))}catch{}},[jg]);const Ag=m.useCallback(x=>{const S=Ng.current;if(!S)return null;const _=S.getBoundingClientRect(),A=16,R=150,U=230,X=_.top+A,J=_.bottom-A,Y=Math.max(R,J-X-U);return Math.min(Math.max(x-X,R),Y)},[]),N$=m.useCallback(x=>{x.preventDefault(),x.stopPropagation();const S=Ng.current;if(!S)return;let _=Ag(x.clientY);if(!Number.isFinite(_))return;Uv(!0),qv(_);const A=U=>{U.preventDefault();const X=Ag(U.clientY);Number.isFinite(X)&&(_=X,S.style.setProperty("--af-work-files-pane-height",`${Math.round(X)}px`))},R=()=>{qv(_),Uv(!1),window.removeEventListener("pointermove",A,!0),window.removeEventListener("pointerup",R,!0),window.removeEventListener("pointercancel",R,!0)};window.addEventListener("pointermove",A,!0),window.addEventListener("pointerup",R,!0),window.addEventListener("pointercancel",R,!0)},[Ag]);m.useEffect(()=>()=>{cn.current&&window.clearTimeout(cn.current),Ue.current&&window.clearTimeout(Ue.current)},[]);const[j$,oS]=m.useState(()=>new Set),[Cf,Pg]=m.useState(!1),Ig=m.useRef(null),aS=m.useRef(null),lS=m.useRef(null),[C$,_$]=m.useState({}),[fa,Rg]=m.useState(""),[ns,cS]=m.useState(!1),[pa,hl]=m.useState([]),[Ls,qn]=m.useState([]),[Hr,bs]=m.useState("workspace"),[tu,ml]=m.useState(!1),uS=m.useRef(null),Tg=m.useRef(null),[nu,gl]=m.useState(null),[E$,Mg]=m.useState(!0),[dS,fS]=m.useState(""),[ha,yo]=m.useState({}),[Ir,pS]=m.useState(null),[hS,mS]=m.useState(!1),yl=m.useMemo(()=>hS?IY(Ir):"",[hS,Ir]),[ru,_f]=m.useState(!0);m.useEffect(()=>{yl&&_f(RY(yl))},[yl]),m.useEffect(()=>{if(yl)try{window.localStorage.setItem(yl,ru?"true":"false")}catch{}},[ru,yl]);const[$g,Ef]=m.useState(!1),[Lg,gS]=m.useState(!1),[Og,yS]=m.useState("pan"),[wS,A$]=m.useState({}),su=m.useRef({}),[xS,ma]=m.useState({}),iu=m.useRef(new Map),ou=m.useRef(new Set),[bS,wl]=m.useState(()=>new Set),[Dg,xl]=m.useState({}),[kS,vS]=m.useState(""),[Nce,ge]=m.useState(""),[SS,Os]=m.useState("loading"),[NS,Ds]=m.useState("正在载入 Project"),Oi=m.useMemo(()=>PY(a),[a]),[jS,CS]=m.useState(""),au=a.flowSource||"user",_S=m.useMemo(()=>new Set(Object.values(wS||{}).map(x=>String((x==null?void 0:x.runNodeId)||"").trim()).filter(Boolean)),[wS]),Di=m.useCallback(x=>{const S=su.current||{},_=typeof x=="function"?x(S):x,A=_&&typeof _=="object"&&!Array.isArray(_)?_:{};return su.current=A,A$(A),A},[]),ES=!!(a.flowId&&!a.archived&&(an!=null&&an.role?an.role==="owner":au==="user"||au==="workspace")),lu=!!(au==="workspace"&&(an!=null&&an.role)&&an.role!=="owner"),AS={loading:"载入中",dirty:"有未同步修改",saving:"同步中",synced:"已同步",conflict:"同步冲突",error:"同步失败",readonly:"只读"}[SS]||"同步状态",li=m.useCallback(()=>{!ce.current||!je||(Fe.current=!1,Be.current+=1,ot.current=!0,Os("dirty"),Ds("本地修改等待同步"))},[je]);m.useEffect(()=>{a.flowId&&mF(a.flowId,a.flowSource||"user","workspace",!!a.archived)},[a]),m.useEffect(()=>{const x=()=>{f(new URLSearchParams(window.location.search).get("view")==="display"?"display":"workspace")};return window.addEventListener("popstate",x),()=>window.removeEventListener("popstate",x)},[]),m.useEffect(()=>{hl([]),qn([]),bs("workspace"),Mg(!0)},[a]);const An=m.useCallback(async()=>{const x=Tr(a),S=await fetch(`/api/workspace/files?${x.toString()}`),_=await S.json();if(!S.ok)throw new Error(_.error||"读取 workspace 失败");const A=_.files||[];Tv(A),dl(new Set(rM(A))),c$(_.root||"")},[a]),Af=m.useCallback(async()=>{Tt(!0),Vn("");try{const x=await fetch("/api/marketplace/flow-snippets"),S=await x.json().catch(()=>({}));if(!x.ok)throw new Error(S.error||"读取流程片段失败");Je(Array.isArray(S.snippets)?S.snippets:[])}catch(x){Vn(String(x.message||x)),Je([])}finally{Tt(!1)}},[]),PS=m.useCallback(async(x,S,_)=>{var Y,ae,pe;if(!ce.current)return;if(!je)throw ge("Readonly workspace"),Os("readonly"),Ds("只读 Project"),new Error("Readonly workspace");Os("saving"),Ds("正在同步修改");const A=Ml(x,S,Z.current);A.ui={...A.ui||{},displayPage:TC(z.current,x)};const R=await fetch("/api/workspace/graph",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,graph:A,baseRevision:me.current,baseGraph:$e.current,clientId:ke.current})}),U=await R.json().catch(()=>({}));if(!R.ok){if(R.status===409||R.status===428){const Ne=Array.isArray(U.conflictItems)?U.conflictItems:[];cl({currentRevision:String(U.currentRevision||""),message:U.error||"Workspace 已被其他成员更新",conflictPaths:Array.isArray(U.conflictPaths)?U.conflictPaths:[],conflictItems:Ne,mergeGraph:U.mergeGraph||null,currentGraph:U.currentGraph||null}),ul(Object.fromEntries(Ne.map((He,Me)=>[String(Me),{mode:"local",manual:Ru(He)}]))),Jc(""),ua(Ne.length>0),Os("conflict"),Ds(U.error||"存在需要处理的字段冲突");const We=Array.isArray(U.conflictPaths)?U.conflictPaths:[],ze=We.length?`${U.error||"Workspace 已被其他成员更新"}:${We.join("、")}`:U.error||"Workspace 已被其他成员更新",Ve=new Error(ze);throw Ve.code="WORKSPACE_REVISION_CONFLICT",Ve.currentRevision=U.currentRevision||"",Ve}const fe=new Error(U.error||"保存 workspace graph 失败");throw Os("error"),Ds(fe.message),fe}const X=Be.current!==_,J=aY({savedGraph:U.graph,sentGraph:A,savedRevision:U.revision,currentRevision:me.current});if(me.current=J.revision,$e.current=J.graph,!X){if(Z.current=((Y=U.graph)==null?void 0:Y.instances)||A.instances,ne(Z.current),U.merged&&U.graph){const fe=Iu(U.graph,be),Ne=hh((pe=(ae=U.graph)==null?void 0:ae.ui)==null?void 0:pe.displayPage,fe.nodes);Z.current=fe.instances,ne(fe.instances),g(fe.nodes),w(fe.edges),z.current=Ne,I(Ne)}ot.current=!1}return ma(Lp(U.workspaceSchedules||[])),cl(null),ua(!1),Os(X?"dirty":"synced"),Ds(X?"本地仍有修改等待同步":"所有修改已同步"),ge(X?"已保存上一版,本地新修改正在排队":U.merged?"Workspace graph merged and saved":"Workspace graph saved"),U},[a,be,w,g,je]),Zt=m.useCallback((x=b,S=v)=>{const _=_e.current,A={nextNodes:x,nextEdges:S,saveEditVersion:Be.current,waiters:[]},R=new Promise((J,Y)=>{A.waiters.push({resolve:J,reject:Y})});if(_.running)return _.pending=xC(_.pending,A),R;_.running=!0;const U=async()=>{let J=A;for(;J;){_.pending&&(J=xC(J,_.pending),_.pending=null);try{const Y=await PS(J.nextNodes,J.nextEdges,J.saveEditVersion);J.waiters.forEach(({resolve:ae})=>ae(Y))}catch(Y){(Y==null?void 0:Y.code)!=="WORKSPACE_REVISION_CONFLICT"&&(Os("error"),Ds(String(Y.message||Y))),J.waiters.forEach(({reject:ae})=>ae(Y)),(Y==null?void 0:Y.code)==="WORKSPACE_REVISION_CONFLICT"&&_.pending&&(_.pending.waiters.forEach(({reject:ae})=>ae(Y)),_.pending=null)}J=_.pending,_.pending=null}_.running=!1},X=Ce.current.catch(()=>{}).then(U);return Ce.current=X,R},[v,b,PS]),P$=m.useCallback(x=>{var _;const S=(_=x==null?void 0:x.extra)!=null&&_.instances&&typeof x.extra.instances=="object"?x.extra.instances:{};Z.current=S,ne(S),g(Array.isArray(x==null?void 0:x.nodes)?x.nodes:[]),w(Array.isArray(x==null?void 0:x.edges)?x.edges:[]),jn(""),ee(null)},[w,g]),I$=m.useMemo(()=>({instances:te}),[te]),R$=zU({nodes:b,edges:v,extra:I$,enabled:ce.current,onRestore:P$}),{resetHistory:cu,undo:IS,redo:RS}=R$,ks=m.useCallback(async(x={})=>{var Le,Mt;const S=(x==null?void 0:x.background)===!0,_=yt.current+1;yt.current=_;const A=Be.current,R=me.current;S||(ce.current=!1);const U=pY({background:S}),X=Tr(a);let J=null,Y;if(!U.nodes&&!U.files)Y=await fetch(`/api/workspace/graph?${X.toString()}`);else{const De=Tr(a);De.set("lang",String(t.language||"zh").startsWith("zh")?"zh":"en");const[dt,Pt]=await Promise.all([fetch(`/api/nodes?${De.toString()}`),fetch(`/api/workspace/graph?${X.toString()}`),An()]);if(J=await dt.json(),!dt.ok)throw new Error(J.error||"读取节点定义失败");Y=Pt}const ae=await Y.json();if(!Y.ok)throw new Error(ae.error||"读取 workspace graph 失败");const pe=oY({background:S,requestId:_,currentRequestId:yt.current,dirty:ot.current,startedEditVersion:A,currentEditVersion:Be.current,startedRevision:R,currentRevision:me.current});if(pe==="superseded")return{skipped:!0,reason:pe};if(pe==="local-edits")return ge("检测到远端更新;本地修改将在保存时自动合并"),{skipped:!0,reason:pe};const fe=S?Qt.current:[...(Array.isArray(J)?J:J.nodes||[]).filter(De=>!gY.has(De.id)),vY,kY,xY,bY,yY,wY];S||(Qt.current=fe,Ht(fe));const Ne=ae.graph||JSON.parse(localStorage.getItem(mY)||"null")||{},We=Iu(Ne,fe),ze=hh((Le=Ne==null?void 0:Ne.ui)==null?void 0:Le.displayPage,We.nodes),Ve=!O.current;let He=F.current;if(Ve){let De=null;try{De=JSON.parse(window.localStorage.getItem(u)||"null")}catch{De=null}He=fb(De)||fb((Mt=Ne==null?void 0:Ne.ui)==null?void 0:Mt.viewport)}const Me=S?nY($e.current,Ne):null;if(S&&(Me!=null&&Me.safe)){const De=Me.nodesChanged?rY(N.current,We.nodes,Me.changedNodeIds):N.current,dt=Me.edgesChanged?sY(j.current,We.edges):j.current,Pt=Me.displayPageChanged||!eo(z.current,ze),_l=Me.nodesChanged||Me.edgesChanged||Pt;if(_l&&(Fe.current=!0),Me.nodesChanged){const ci=iY(Z.current,We.instances,Me.changedNodeIds);Z.current=ci,N.current=De,ne(ci),g(De)}if(Me.edgesChanged&&(j.current=dt,w(dt)),Pt&&(z.current=ze,I(ze)),_l&&cu(De,dt,{instances:Me.nodesChanged?Z.current:We.instances}),Me.nodesChanged||Pt){const ci=new Set(ze.nodeIds);K(wa=>{const xa=wa.filter(Uf=>ci.has(Uf));return xa.length===wa.length?wa:xa})}}else Z.current=We.instances,N.current=We.nodes,j.current=We.edges,z.current=ze,Fe.current=!0,ne(We.instances),g(We.nodes),w(We.edges),I(ze),K([]),cu(We.nodes,We.edges,{instances:We.instances});const Ft=Lp(ae.workspaceSchedules||[]);ma(De=>eo(De,Ft)?De:Ft),me.current=String(ae.revision||""),$e.current=Ne,ot.current=!1;const rt=ae.collaboration||null;gg(De=>eo(De,rt)?De:rt),cl(null),Ve&&(L(He),F.current=He,O.current=!0);const Ye=ae.writable!==!1;return u$(Ye),ge(Ye?"Workspace ready":"Readonly workspace"),Os(Ye?"synced":"readonly"),Ds(Ye?"所有修改已同步":"只读 Project"),ce.current=!0,{skipped:!1}},[a,t.language,An,cu,w,g,u]),Pf=m.useCallback((x={})=>{if(!ce.current)return;const S=String(x.revision||""),_=x.type==="graph.committed",A=!!(Te.current||st.current||gt.current);if(hY({eventType:x.type,revision:S,currentRevision:me.current,targetRevision:xe.current,refreshPending:A}))return;if(_&&S&&(xe.current=S),ot.current){gt.current=!1,ge("检测到其他成员的更新;保存时将自动合并");return}if(gt.current=!0,Te.current||st.current)return;const R=async()=>{if(Te.current=null,lt.current){gt.current=!0,Te.current=window.setTimeout(R,80);return}if(ot.current){gt.current=!1,ge("检测到其他成员的更新;保存时将自动合并");return}gt.current=!1,st.current=!0;try{await ks({background:!0}),xe.current=me.current}catch(U){xe.current="",ge(String(U.message||U))}finally{st.current=!1,gt.current&&!ot.current&&(Te.current=window.setTimeout(R,40))}};Te.current=window.setTimeout(R,40)},[ks]),uu=m.useCallback(async(x=ir)=>{const S=String(x||"").trim();tS(!0),pl("");try{const _=Tr(a);_.set("tapdId",S),_.set("runtimeOnly","1");const A=await fetch(`/api/prd-workflow/snapshot?${_.toString()}`),R=await A.json().catch(()=>({}));if(!A.ok)throw new Error(R.error||"读取 PRD Workflow 失败");Sf(R.snapshot||null),Nf(""),jf(null),eu(null);try{const U=`agentflow.workflow.tapdId:${a.flowSource||"user"}:${a.flowId||""}`;S?window.localStorage.setItem(U,S):window.localStorage.removeItem(U)}catch{}}catch(_){pl(String(_.message||_))}finally{tS(!1)}},[a,ir]),bl=m.useCallback(async(x=null,S={})=>{const _=x&&typeof x=="object"?x:ln==null?void 0:ln.nextAction,A=Yd(_);if(!A||Cg)return;const R=(S==null?void 0:S.confirm)===!0,U=String((S==null?void 0:S.expectedRevision)||(ln==null?void 0:ln.revision)||"");nS(!0),pl(""),R||(Nf(""),jf(null),eu(null));try{const X=await fetch("/api/prd-workflow/action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,tapdId:ir,action:A,stage:el(_),title:to(_,0),...ZY(_),dryRun:!R,confirm:R,issueKey:_.issueKey||_.issue_key||"",expectedRevision:U,idempotencyKey:`workflow-${Date.now()}-${Math.random().toString(36).slice(2)}`})}),J=await X.json().catch(()=>({}));if(!X.ok||J.ok===!1)throw J.snapshot&&Sf(J.snapshot),J.conflict&&eu({...J.conflict,action:_}),new Error(J.error||"执行 PRD Workflow action 失败");Nf(J.rawOutput||(J.output?JSON.stringify(J.output,null,2):"")),Sf(J.snapshot||ln),eu(null),jf(R?null:{action:_,output:J.output||null,expectedRevision:U,at:new Date().toISOString()})}catch(X){pl(String(X.message||X))}finally{nS(!1)}},[a,Cg,ln,ir]),T$=m.useCallback((x=null)=>bl(x,{confirm:!1}),[bl]),M$=m.useCallback(()=>{const x=(xs==null?void 0:xs.action)||(ln==null?void 0:ln.nextAction);return bl(x,{confirm:!0,expectedRevision:(xs==null?void 0:xs.expectedRevision)||""})},[bl,xs,ln]),$$=m.useCallback(()=>{const x=(Zc==null?void 0:Zc.action)||(ln==null?void 0:ln.nextAction);return eu(null),bl(x,{confirm:!1})},[bl,Zc,ln]),L$=m.useCallback(async()=>{var U,X;const x=String(_g||(ln==null?void 0:ln.rawOutput)||"").trim();if(!x||Eg)return;const S=(xs==null?void 0:xs.action)||(ln==null?void 0:ln.nextAction)||{},_=`Review: ${to(S,0)||(ln==null?void 0:ln.pointer)||ir||"PRD Workflow"}`,A=/^[\[{]/.test(x),R=x.startsWith("#")?x:`# ${_}
246
246
 
247
247
  ${A?`\`\`\`json
248
248
  ${x}
249
- \`\`\``:x}`;rS(!0),pl("");try{const X=await fetch("/api/prd-workflow/review-link",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,tapdId:ir,title:_,markdown:R,action:Yd(S),stage:el(S),issueKey:S.issueKey||S.issue_key||"",artifactLabel:"临时 Review"})}),J=await X.json().catch(()=>({}));if(!X.ok||J.ok===!1)throw new Error(J.error||"生成 Review 链接失败");Sf(J.snapshot||ln);const Y=((U=J.review)==null?void 0:U.url)||"";Y&&Nf(ae=>`${ae||x}
249
+ \`\`\``:x}`;rS(!0),pl("");try{const J=await fetch("/api/prd-workflow/review-link",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,tapdId:ir,title:_,markdown:R,action:Yd(S),stage:el(S),issueKey:S.issueKey||S.issue_key||"",artifactLabel:"临时 Review"})}),Y=await J.json().catch(()=>({}));if(!J.ok||Y.ok===!1)throw new Error(Y.error||"生成 Review 链接失败");Sf(Y.snapshot||ln);const ae=((U=Y.review)==null?void 0:U.shortUrl)||((X=Y.review)==null?void 0:X.url)||"";ae&&Nf(pe=>`${pe||x}
250
250
 
251
- Review link: ${Y}`)}catch(X){pl(String(X.message||X))}finally{rS(!1)}},[a,_g,xs,Eg,ln,ir]),O$=m.useCallback(async(x,S)=>{const _={packageId:(x==null?void 0:x.newId)||(x==null?void 0:x.id)||(x==null?void 0:x.label),label:(x==null?void 0:x.label)||(x==null?void 0:x.newId)||(x==null?void 0:x.id),version:"1.0.0",definitionId:S,body:(x==null?void 0:x.body)||"",script:(x==null?void 0:x.script)||"",scriptRef:(x==null?void 0:x.scriptRef)||"",implementationRef:(x==null?void 0:x.implementationRef)||"",implementationMode:(x==null?void 0:x.implementationMode)||"",inputs:Array.isArray(x==null?void 0:x.inputs)?x.inputs:[],outputs:Array.isArray(x==null?void 0:x.outputs)?x.outputs:[],flowId:a.flowId,flowSource:a.flowSource||"user",archived:!!a.archived},A=await fetch("/api/marketplace/publish-node-from-instance",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)}),R=await A.json().catch(()=>({}));if(!A.ok||(R==null?void 0:R.ok)===!1)throw new Error((R==null?void 0:R.error)||"Publish failed");return await ks(),ge(`Published node ${R.definitionId||R.id||_.packageId}`),R},[a,ks]),ga=m.useCallback((x=Ls)=>{const S=Array.isArray(x)?x:[],A=[...S].reverse().find(R=>(R==null?void 0:R.status)==="running"||(R==null?void 0:R.status)==="stopping")||[...S].reverse().find(R=>R==null?void 0:R.id);return String((A==null?void 0:A.id)||"workspace")},[Ls]),D$=m.useCallback(x=>{const S=String(x||"").trim();!S||S==="workspace"||qn(_=>{const A=(Array.isArray(_)?_:[]).filter(R=>R.id!==S);return bs(R=>R===S?ga(A):R),A})},[ga]);m.useCallback((x="")=>{ml(!0),gl(null),ws(null),bs(x||ga())},[ga]);const TS=m.useCallback((x={})=>{gl({scheduleNodeId:String(x.scheduleNodeId||""),runNodeId:String(x.runNodeId||x.nodeId||""),lastRunId:String(x.lastRunId||""),label:String(x.label||"")}),ml(!1),ws(null),jn("")},[]),Fg=m.useCallback(async(x="")=>{const S=String(x||"").trim();if(!(!S||!je)){vS(S),ge(`Optimizing run: ${S}`);try{await Zt(N.current,j.current);const _=Ml(N.current,j.current,Z.current),A=qC(N.current,Z.current,S,Li),R=await fetch("/api/workspace/run/optimize",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,runNodeId:S,graph:_,model:A})}),U=await R.json().catch(()=>({}));if(!R.ok||U.ok===!1)throw new Error(U.error||"优化失败");const X=U.graph||_,J=Iu(X,be);Z.current=J.instances,ne(J.instances),g(J.nodes),w(J.edges),ma(Lp(U.workspaceSchedules||[])),cu(J.nodes,J.edges,{instances:J.instances});const Y=Array.isArray(U.optimized)?U.optimized.length:0;ge(Y>0?`已生成 ${Y} 个 implementation`:"没有需要优化的节点")}catch(_){ge(String(_.message||_))}finally{vS("")}}},[Li,j,a,N,be,cu,Zt,w,g,je]),MS=m.useCallback(async(x="")=>{const S=String(x||"").trim(),_=su.current||{},A=Object.entries(_).find(([Y,ae])=>Y===S||String((ae==null?void 0:ae.runNodeId)||"")===S)||Object.entries(_)[0]||null,R=(A==null?void 0:A[0])||"",U=(A==null?void 0:A[1])||null,X=String((U==null?void 0:U.runNodeId)||S||"").trim();if((U==null?void 0:U.status)==="stopping")return;const J=new Set([X,...Array.isArray(U==null?void 0:U.plannedNodeIds)?U.plannedNodeIds:[]].map(Y=>String(Y||"").trim()).filter(Boolean));R&&Di(Y=>{const ae={...Y};return ae[R]&&(ae[R]={...ae[R],status:"stopping"}),ae}),ge(X?`Stopping Workspace run: ${X}...`:"Stopping Workspace run..."),qn(Y=>Y.map(ae=>(R?ae.id===R:!X||ae.runNodeId===X)&&ae.status==="running"?{...ae,status:"stopping"}:ae));try{const Y=await fetch("/api/workspace/run/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,runId:R,runNodeId:X})}),ae=await Y.json().catch(()=>({}));if(!Y.ok||(ae==null?void 0:ae.stopped)!==!0)throw new Error(ae.error||"Workspace run stop failed");const he=R?iu.current.get(R):null;he&&(he.abort(),iu.current.delete(R)),R&&Di(fe=>{const Ne={...fe};return delete Ne[R],Ne}),wl(fe=>{const Ne=new Set(fe);for(const We of J)Ne.delete(We);return Ne}),xl(fe=>{var We;const Ne={...fe};for(const ze of J)ze&&(!Ne[ze]||((We=Ne[ze])==null?void 0:We.status)==="running")&&(Ne[ze]={status:"stopped"});return Ne}),ge(X?`Workspace run stopped: ${X}`:"Workspace run stopped"),qn(fe=>fe.map(Ne=>(R?Ne.id===R:!X||Ne.runNodeId===X)?{...Ne,status:"stopped",endedAt:Date.now(),messages:[...Array.isArray(Ne.messages)?Ne.messages:[],{role:"assistant",kind:"status",text:"Workspace run stopped.",at:Date.now()}].slice(-160)}:Ne))}catch(Y){R&&Di(he=>{const fe={...he};return fe[R]&&(fe[R]={...fe[R],status:"running"}),fe});const ae=String((Y==null?void 0:Y.message)||Y||"Workspace run stop failed");ge(`停止失败:${ae}`),qn(he=>he.map(fe=>(R?fe.id===R:!X||fe.runNodeId===X)?{...fe,status:"running",messages:[...Array.isArray(fe.messages)?fe.messages:[],{role:"assistant",kind:"error",error:!0,text:`停止失败:${ae}`,at:Date.now()}].slice(-160)}:fe))}},[a,Di]),If=m.useCallback(async()=>{if(a.flowId)try{const x=Tr(a),S=await fetch(`/api/workspace/run/status?${x.toString()}`),_=await S.json().catch(()=>({}));if(!S.ok||!_.running)return;const A=Array.isArray(_.runs)&&_.runs.length?_.runs:[{runId:`run-restored-${_.startedAt||Date.now()}`,runNodeId:_.runNodeId||"",startedAt:_.startedAt||Date.now(),plannedNodeIds:[]}],R={},U=[];for(const X of A){const J=String((X==null?void 0:X.runNodeId)||"").trim(),Y=String((X==null?void 0:X.runId)||`run-restored-${(X==null?void 0:X.startedAt)||Date.now()}-${J}`).trim();if(!Y)continue;const ae=String((X==null?void 0:X.label)||"").trim()||sw(N.current,Z.current,J,"Workspace Run");R[Y]={id:Y,runNodeId:J,label:ae,status:(X==null?void 0:X.state)==="stopping"?"stopping":"running",plannedNodeIds:Array.isArray(X==null?void 0:X.plannedNodeIds)?X.plannedNodeIds:[],startedAt:(X==null?void 0:X.startedAt)||Date.now()},J&&U.push(J)}if(!Object.keys(R).length)return;Di(X=>({...X,...R})),wl(X=>{const J=new Set(X);for(const Y of U)J.add(Y);return J}),xl(X=>{const J={...X};for(const Y of U)J[Y]={status:"running"};return J}),ge(U.length?`Workspace run still running: ${U.join(", ")}`:"Workspace run still running"),qn(X=>{const J=[...X];for(const[Y,ae]of Object.entries(R)){if(J.some(Ne=>Ne.id===Y||["running","stopping"].includes(Ne.status)&&Ne.runNodeId===ae.runNodeId))continue;const he=String(ae.runNodeId||""),fe=String(ae.label||"").trim()||sw(N.current,Z.current,he,"Workspace Run");J.push({id:Y,label:iw(fe,he,"Workspace Run"),alias:fe,runNodeId:he,status:ae.status,startedAt:ae.startedAt||Date.now(),steps:he?[{id:he,label:iw(fe,he,"Workspace Run"),status:"running"}]:[],messages:[{role:"assistant",kind:"run-summary",text:ae.status==="stopping"?"Workspace run is stopping in the background.":"Workspace run is still running in the background.",at:Date.now()}]})}return[...J.slice(-8)]})}catch{}},[a,N,Di]),$S=m.useCallback(async x=>{if(!je){ge("Readonly workspace");return}if(!x)return;if(Object.values(su.current||{}).find(rt=>String((rt==null?void 0:rt.runNodeId)||"")===String(x||""))){ge(`Workspace run already running: ${x}`);return}let _=N.current,A=j.current,R=Z.current;const U=Rv.current;if(U!=null&&U.id){const rt=_.find(Le=>Le.id===U.id),Ye=YC({nodes:_,edges:A,instances:R,selectedNode:rt,draft:U,allowRename:!1});if(Ye!=null&&Ye.error){al(Ye.error),ge(Ye.error);return}Ye!=null&&Ye.ok&&Ye.changed&&(_=Ye.nodes,A=Ye.edges,R=Ye.instances,Z.current=R,N.current=_,j.current=A,ne(R),g(_),w(A),Br(Ye.nextId||U.id))}const X=Ml(_,A,R),J=`run-${Date.now()}-${String(x).replace(/[^a-z0-9_-]+/gi,"_")}`,Y=sw(_,R,x,"Workspace Run"),ae=iw(Y,x,"Workspace Run");let he=[x];try{const rt=await fetch("/api/workspace/run/plan",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,graph:X,runNodeId:x})}),Ye=await rt.json().catch(()=>({}));if(!rt.ok||(Ye==null?void 0:Ye.ok)===!1)throw new Error(Ye.error||"Workspace run plan failed");he=Array.isArray(Ye.plannedNodeIds)&&Ye.plannedNodeIds.length?Ye.plannedNodeIds.map(Mt=>String(Mt||"").trim()).filter(Boolean):[x],he=Array.from(new Set([x,...he].filter(Boolean)));const Le=Ye.conflict||null;if(Le!=null&&Le.runNodeId||Le!=null&&Le.runId){const Mt=Array.isArray(Le.conflictNodeIds)&&Le.conflictNodeIds.length?`: ${Le.conflictNodeIds.join(", ")}`:"";ge(`Run ${x} conflicts with running ${Le.runNodeId||Le.runId}${Mt}`);return}}catch(rt){ge(String(rt.message||rt));return}const fe=new Set(he),Ne=Object.values(su.current||{}).find(rt=>(Array.isArray(rt==null?void 0:rt.plannedNodeIds)?rt.plannedNodeIds:[]).some(Ye=>fe.has(String(Ye||"").trim())));if(Ne){const rt=(Array.isArray(Ne.plannedNodeIds)?Ne.plannedNodeIds:[]).map(Ye=>String(Ye||"").trim()).filter(Ye=>Ye&&fe.has(Ye));ge(`Run ${x} conflicts with running ${Ne.runNodeId||"workspace run"}${rt.length?`: ${rt.join(", ")}`:""}`);return}const We=new AbortController;iu.current.set(J,We),ou.current.delete(J),Di(rt=>({...rt,[J]:{id:J,runNodeId:x,label:Y,plannedNodeIds:he,startedAt:Date.now()}})),wl(rt=>new Set([...rt,x])),xl(rt=>({...rt,[x]:{status:"running"}})),ge(`Running ${ae}...`),bs(J),qn(rt=>[...rt.slice(-7),{id:J,label:ae,alias:Y,runNodeId:x,status:"running",startedAt:Date.now(),steps:[],messages:[{role:"assistant",kind:"run-summary",text:"准备运行...",at:Date.now()}]}]);let ze=x;const Ve=new Map,He=()=>ou.current.has(J),Me=rt=>{const Ye=new Set((rt||[]).map(Le=>String(Le||"").trim()).filter(Boolean));Ye.size||Ye.add(String(x||"")),wl(Le=>{const Mt=new Set(Le);for(const De of Ye)Mt.delete(De);return Mt})},Ft=(rt,Ye)=>{const Le=new Set((rt||[]).map(Mt=>String(Mt||"").trim()).filter(Boolean));Le.size||Le.add(String(x||"")),xl(Mt=>{var dt;const De={...Mt};for(const Pt of Le)Pt&&(!De[Pt]||((dt=De[Pt])==null?void 0:dt.status)==="running")&&(De[Pt]={status:Ye});return De})};try{await Zt(_,A);const rt=qC(_,R,x,Li),Ye=await fetch("/api/workspace/run",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/x-ndjson"},signal:We.signal,body:JSON.stringify({...a,graph:X,runNodeId:x,runAlias:Y,runSessionId:J,expectedRevision:me.current,clientId:ke.current,model:rt,selectedSkills:$s,stream:!0})});if(!Ye.ok){const ye=await Ye.json().catch(()=>({}));throw new Error(ye.error||"Workspace run failed")}if(!Ye.body)throw new Error("Workspace run stream unavailable");const Le=Ye.body.getReader(),Mt=new TextDecoder;let De="",dt=[],Pt=[];const _l=(ye,nt)=>{var ct,Et;const Ge=b.find(Ot=>Ot.id===ye),pt=String(((ct=Ge==null?void 0:Ge.data)==null?void 0:ct.label)||ye||"").trim(),we=String(nt||((Et=Ge==null?void 0:Ge.data)==null?void 0:Et.definitionId)||"").trim();return we&&we!==pt?`${pt} (${we})`:pt},ci=(ye,nt,Ge)=>{const pt=String(ye||"").trim();pt&&qn(we=>we.map(ct=>{if(ct.id!==J)return ct;const Ot=[...Array.isArray(ct.steps)?ct.steps:[]],ht=Ot.findIndex(fn=>fn.id===pt),vt={id:pt,label:_l(pt,nt),status:Ge};ht>=0?Ot[ht]={...Ot[ht],...vt}:Ot.push(vt);const un=Ot.map((fn,bo)=>{const Bi=fn.status==="done"?"[done]":fn.status==="failed"?"[failed]":"[running]";return`${bo+1}. ${Bi} ${fn.label}`}).join(`
251
+ Review link: ${ae}`)}catch(J){pl(String(J.message||J))}finally{rS(!1)}},[a,_g,xs,Eg,ln,ir]),O$=m.useCallback(async(x,S)=>{const _={packageId:(x==null?void 0:x.newId)||(x==null?void 0:x.id)||(x==null?void 0:x.label),label:(x==null?void 0:x.label)||(x==null?void 0:x.newId)||(x==null?void 0:x.id),version:"1.0.0",definitionId:S,body:(x==null?void 0:x.body)||"",script:(x==null?void 0:x.script)||"",scriptRef:(x==null?void 0:x.scriptRef)||"",implementationRef:(x==null?void 0:x.implementationRef)||"",implementationMode:(x==null?void 0:x.implementationMode)||"",inputs:Array.isArray(x==null?void 0:x.inputs)?x.inputs:[],outputs:Array.isArray(x==null?void 0:x.outputs)?x.outputs:[],flowId:a.flowId,flowSource:a.flowSource||"user",archived:!!a.archived},A=await fetch("/api/marketplace/publish-node-from-instance",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)}),R=await A.json().catch(()=>({}));if(!A.ok||(R==null?void 0:R.ok)===!1)throw new Error((R==null?void 0:R.error)||"Publish failed");return await ks(),ge(`Published node ${R.definitionId||R.id||_.packageId}`),R},[a,ks]),ga=m.useCallback((x=Ls)=>{const S=Array.isArray(x)?x:[],A=[...S].reverse().find(R=>(R==null?void 0:R.status)==="running"||(R==null?void 0:R.status)==="stopping")||[...S].reverse().find(R=>R==null?void 0:R.id);return String((A==null?void 0:A.id)||"workspace")},[Ls]),D$=m.useCallback(x=>{const S=String(x||"").trim();!S||S==="workspace"||qn(_=>{const A=(Array.isArray(_)?_:[]).filter(R=>R.id!==S);return bs(R=>R===S?ga(A):R),A})},[ga]);m.useCallback((x="")=>{ml(!0),gl(null),ws(null),bs(x||ga())},[ga]);const TS=m.useCallback((x={})=>{gl({scheduleNodeId:String(x.scheduleNodeId||""),runNodeId:String(x.runNodeId||x.nodeId||""),lastRunId:String(x.lastRunId||""),label:String(x.label||"")}),ml(!1),ws(null),jn("")},[]),Fg=m.useCallback(async(x="")=>{const S=String(x||"").trim();if(!(!S||!je)){vS(S),ge(`Optimizing run: ${S}`);try{await Zt(N.current,j.current);const _=Ml(N.current,j.current,Z.current),A=qC(N.current,Z.current,S,Li),R=await fetch("/api/workspace/run/optimize",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,runNodeId:S,graph:_,model:A})}),U=await R.json().catch(()=>({}));if(!R.ok||U.ok===!1)throw new Error(U.error||"优化失败");const X=U.graph||_,J=Iu(X,be);Z.current=J.instances,ne(J.instances),g(J.nodes),w(J.edges),ma(Lp(U.workspaceSchedules||[])),cu(J.nodes,J.edges,{instances:J.instances});const Y=Array.isArray(U.optimized)?U.optimized.length:0;ge(Y>0?`已生成 ${Y} 个 implementation`:"没有需要优化的节点")}catch(_){ge(String(_.message||_))}finally{vS("")}}},[Li,j,a,N,be,cu,Zt,w,g,je]),MS=m.useCallback(async(x="")=>{const S=String(x||"").trim(),_=su.current||{},A=Object.entries(_).find(([Y,ae])=>Y===S||String((ae==null?void 0:ae.runNodeId)||"")===S)||Object.entries(_)[0]||null,R=(A==null?void 0:A[0])||"",U=(A==null?void 0:A[1])||null,X=String((U==null?void 0:U.runNodeId)||S||"").trim();if((U==null?void 0:U.status)==="stopping")return;const J=new Set([X,...Array.isArray(U==null?void 0:U.plannedNodeIds)?U.plannedNodeIds:[]].map(Y=>String(Y||"").trim()).filter(Boolean));R&&Di(Y=>{const ae={...Y};return ae[R]&&(ae[R]={...ae[R],status:"stopping"}),ae}),ge(X?`Stopping Workspace run: ${X}...`:"Stopping Workspace run..."),qn(Y=>Y.map(ae=>(R?ae.id===R:!X||ae.runNodeId===X)&&ae.status==="running"?{...ae,status:"stopping"}:ae));try{const Y=await fetch("/api/workspace/run/stop",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,runId:R,runNodeId:X})}),ae=await Y.json().catch(()=>({}));if(!Y.ok||(ae==null?void 0:ae.stopped)!==!0)throw new Error(ae.error||"Workspace run stop failed");const pe=R?iu.current.get(R):null;pe&&(pe.abort(),iu.current.delete(R)),R&&Di(fe=>{const Ne={...fe};return delete Ne[R],Ne}),wl(fe=>{const Ne=new Set(fe);for(const We of J)Ne.delete(We);return Ne}),xl(fe=>{var We;const Ne={...fe};for(const ze of J)ze&&(!Ne[ze]||((We=Ne[ze])==null?void 0:We.status)==="running")&&(Ne[ze]={status:"stopped"});return Ne}),ge(X?`Workspace run stopped: ${X}`:"Workspace run stopped"),qn(fe=>fe.map(Ne=>(R?Ne.id===R:!X||Ne.runNodeId===X)?{...Ne,status:"stopped",endedAt:Date.now(),messages:[...Array.isArray(Ne.messages)?Ne.messages:[],{role:"assistant",kind:"status",text:"Workspace run stopped.",at:Date.now()}].slice(-160)}:Ne))}catch(Y){R&&Di(pe=>{const fe={...pe};return fe[R]&&(fe[R]={...fe[R],status:"running"}),fe});const ae=String((Y==null?void 0:Y.message)||Y||"Workspace run stop failed");ge(`停止失败:${ae}`),qn(pe=>pe.map(fe=>(R?fe.id===R:!X||fe.runNodeId===X)?{...fe,status:"running",messages:[...Array.isArray(fe.messages)?fe.messages:[],{role:"assistant",kind:"error",error:!0,text:`停止失败:${ae}`,at:Date.now()}].slice(-160)}:fe))}},[a,Di]),If=m.useCallback(async()=>{if(a.flowId)try{const x=Tr(a),S=await fetch(`/api/workspace/run/status?${x.toString()}`),_=await S.json().catch(()=>({}));if(!S.ok||!_.running)return;const A=Array.isArray(_.runs)&&_.runs.length?_.runs:[{runId:`run-restored-${_.startedAt||Date.now()}`,runNodeId:_.runNodeId||"",startedAt:_.startedAt||Date.now(),plannedNodeIds:[]}],R={},U=[];for(const X of A){const J=String((X==null?void 0:X.runNodeId)||"").trim(),Y=String((X==null?void 0:X.runId)||`run-restored-${(X==null?void 0:X.startedAt)||Date.now()}-${J}`).trim();if(!Y)continue;const ae=String((X==null?void 0:X.label)||"").trim()||sw(N.current,Z.current,J,"Workspace Run");R[Y]={id:Y,runNodeId:J,label:ae,status:(X==null?void 0:X.state)==="stopping"?"stopping":"running",plannedNodeIds:Array.isArray(X==null?void 0:X.plannedNodeIds)?X.plannedNodeIds:[],startedAt:(X==null?void 0:X.startedAt)||Date.now()},J&&U.push(J)}if(!Object.keys(R).length)return;Di(X=>({...X,...R})),wl(X=>{const J=new Set(X);for(const Y of U)J.add(Y);return J}),xl(X=>{const J={...X};for(const Y of U)J[Y]={status:"running"};return J}),ge(U.length?`Workspace run still running: ${U.join(", ")}`:"Workspace run still running"),qn(X=>{const J=[...X];for(const[Y,ae]of Object.entries(R)){if(J.some(Ne=>Ne.id===Y||["running","stopping"].includes(Ne.status)&&Ne.runNodeId===ae.runNodeId))continue;const pe=String(ae.runNodeId||""),fe=String(ae.label||"").trim()||sw(N.current,Z.current,pe,"Workspace Run");J.push({id:Y,label:iw(fe,pe,"Workspace Run"),alias:fe,runNodeId:pe,status:ae.status,startedAt:ae.startedAt||Date.now(),steps:pe?[{id:pe,label:iw(fe,pe,"Workspace Run"),status:"running"}]:[],messages:[{role:"assistant",kind:"run-summary",text:ae.status==="stopping"?"Workspace run is stopping in the background.":"Workspace run is still running in the background.",at:Date.now()}]})}return[...J.slice(-8)]})}catch{}},[a,N,Di]),$S=m.useCallback(async x=>{if(!je){ge("Readonly workspace");return}if(!x)return;if(Object.values(su.current||{}).find(rt=>String((rt==null?void 0:rt.runNodeId)||"")===String(x||""))){ge(`Workspace run already running: ${x}`);return}let _=N.current,A=j.current,R=Z.current;const U=Rv.current;if(U!=null&&U.id){const rt=_.find(Le=>Le.id===U.id),Ye=YC({nodes:_,edges:A,instances:R,selectedNode:rt,draft:U,allowRename:!1});if(Ye!=null&&Ye.error){al(Ye.error),ge(Ye.error);return}Ye!=null&&Ye.ok&&Ye.changed&&(_=Ye.nodes,A=Ye.edges,R=Ye.instances,Z.current=R,N.current=_,j.current=A,ne(R),g(_),w(A),Br(Ye.nextId||U.id))}const X=Ml(_,A,R),J=`run-${Date.now()}-${String(x).replace(/[^a-z0-9_-]+/gi,"_")}`,Y=sw(_,R,x,"Workspace Run"),ae=iw(Y,x,"Workspace Run");let pe=[x];try{const rt=await fetch("/api/workspace/run/plan",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,graph:X,runNodeId:x})}),Ye=await rt.json().catch(()=>({}));if(!rt.ok||(Ye==null?void 0:Ye.ok)===!1)throw new Error(Ye.error||"Workspace run plan failed");pe=Array.isArray(Ye.plannedNodeIds)&&Ye.plannedNodeIds.length?Ye.plannedNodeIds.map(Mt=>String(Mt||"").trim()).filter(Boolean):[x],pe=Array.from(new Set([x,...pe].filter(Boolean)));const Le=Ye.conflict||null;if(Le!=null&&Le.runNodeId||Le!=null&&Le.runId){const Mt=Array.isArray(Le.conflictNodeIds)&&Le.conflictNodeIds.length?`: ${Le.conflictNodeIds.join(", ")}`:"";ge(`Run ${x} conflicts with running ${Le.runNodeId||Le.runId}${Mt}`);return}}catch(rt){ge(String(rt.message||rt));return}const fe=new Set(pe),Ne=Object.values(su.current||{}).find(rt=>(Array.isArray(rt==null?void 0:rt.plannedNodeIds)?rt.plannedNodeIds:[]).some(Ye=>fe.has(String(Ye||"").trim())));if(Ne){const rt=(Array.isArray(Ne.plannedNodeIds)?Ne.plannedNodeIds:[]).map(Ye=>String(Ye||"").trim()).filter(Ye=>Ye&&fe.has(Ye));ge(`Run ${x} conflicts with running ${Ne.runNodeId||"workspace run"}${rt.length?`: ${rt.join(", ")}`:""}`);return}const We=new AbortController;iu.current.set(J,We),ou.current.delete(J),Di(rt=>({...rt,[J]:{id:J,runNodeId:x,label:Y,plannedNodeIds:pe,startedAt:Date.now()}})),wl(rt=>new Set([...rt,x])),xl(rt=>({...rt,[x]:{status:"running"}})),ge(`Running ${ae}...`),bs(J),qn(rt=>[...rt.slice(-7),{id:J,label:ae,alias:Y,runNodeId:x,status:"running",startedAt:Date.now(),steps:[],messages:[{role:"assistant",kind:"run-summary",text:"准备运行...",at:Date.now()}]}]);let ze=x;const Ve=new Map,He=()=>ou.current.has(J),Me=rt=>{const Ye=new Set((rt||[]).map(Le=>String(Le||"").trim()).filter(Boolean));Ye.size||Ye.add(String(x||"")),wl(Le=>{const Mt=new Set(Le);for(const De of Ye)Mt.delete(De);return Mt})},Ft=(rt,Ye)=>{const Le=new Set((rt||[]).map(Mt=>String(Mt||"").trim()).filter(Boolean));Le.size||Le.add(String(x||"")),xl(Mt=>{var dt;const De={...Mt};for(const Pt of Le)Pt&&(!De[Pt]||((dt=De[Pt])==null?void 0:dt.status)==="running")&&(De[Pt]={status:Ye});return De})};try{await Zt(_,A);const rt=qC(_,R,x,Li),Ye=await fetch("/api/workspace/run",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/x-ndjson"},signal:We.signal,body:JSON.stringify({...a,graph:X,runNodeId:x,runAlias:Y,runSessionId:J,expectedRevision:me.current,clientId:ke.current,model:rt,selectedSkills:$s,stream:!0})});if(!Ye.ok){const ye=await Ye.json().catch(()=>({}));throw new Error(ye.error||"Workspace run failed")}if(!Ye.body)throw new Error("Workspace run stream unavailable");const Le=Ye.body.getReader(),Mt=new TextDecoder;let De="",dt=[],Pt=[];const _l=(ye,nt)=>{var ct,Et;const Ge=b.find(Ot=>Ot.id===ye),pt=String(((ct=Ge==null?void 0:Ge.data)==null?void 0:ct.label)||ye||"").trim(),we=String(nt||((Et=Ge==null?void 0:Ge.data)==null?void 0:Et.definitionId)||"").trim();return we&&we!==pt?`${pt} (${we})`:pt},ci=(ye,nt,Ge)=>{const pt=String(ye||"").trim();pt&&qn(we=>we.map(ct=>{if(ct.id!==J)return ct;const Ot=[...Array.isArray(ct.steps)?ct.steps:[]],ht=Ot.findIndex(fn=>fn.id===pt),vt={id:pt,label:_l(pt,nt),status:Ge};ht>=0?Ot[ht]={...Ot[ht],...vt}:Ot.push(vt);const un=Ot.map((fn,bo)=>{const Bi=fn.status==="done"?"[done]":fn.status==="failed"?"[failed]":"[running]";return`${bo+1}. ${Bi} ${fn.label}`}).join(`
252
252
  `),Yt=Array.isArray(ct.messages)?ct.messages:[],rn=Yt.findIndex(fn=>fn.kind==="run-summary"),xn={role:"assistant",kind:"run-summary",text:un||"准备运行...",at:Date.now()},zt=[...Yt];return rn>=0?zt[rn]=xn:zt.unshift(xn),{...ct,steps:Ot,messages:zt.slice(-160)}}))},wa=(ye,nt)=>{var _0,E0,A0,P0,I0,R0,T0,M0,$0,L0;const Ge=String(ye||"").trim(),pt=String(nt||"").trim();if(!Ge||!pt)return;const we=(_0=Z.current)==null?void 0:_0[Ge];if(!ei(we==null?void 0:we.definitionId))return;const ct=ta(we==null?void 0:we.input,"displayType","markdown"),Et=lM(ct),Ot=cM(Ge),ht=be.find(Rr=>Rr.id===Et),vt=HC(ht==null?void 0:ht.inputs,Et,pt),un=HC(ht==null?void 0:ht.outputs,Et,pt),Yt=String((we==null?void 0:we.label)||Ge||"一键任务").trim(),rn={...Z.current||{},[Ge]:{...we||{},output:VC(we==null?void 0:we.output)},[Ot]:{...((E0=Z.current)==null?void 0:E0[Ot])||{},definitionId:Et,label:Yt,role:"normal",body:pt,input:vt,output:un,sourceContextRunNodeId:Ge,displayReloadKey:String(Date.now())}};Z.current=rn,ne(rn);const xn=N.current||[],zt=xn.find(Rr=>Rr.id===Ge),fn=xn.find(Rr=>Rr.id===Ot),bo=Number(((A0=zt==null?void 0:zt.measured)==null?void 0:A0.width)||(zt==null?void 0:zt.width)||((I0=(P0=zt==null?void 0:zt.data)==null?void 0:P0.nodeSize)==null?void 0:I0.width)||520),Bi=(fn==null?void 0:fn.position)||{x:Number(((R0=zt==null?void 0:zt.position)==null?void 0:R0.x)||0)+bo+120,y:Number(((T0=zt==null?void 0:zt.position)==null?void 0:T0.y)||0)},ar=((M0=fn==null?void 0:fn.data)==null?void 0:M0.displaySize)||(($0=fn==null?void 0:fn.data)==null?void 0:$0.nodeSize)||{width:ob,height:ab},ui=rb({id:Ot,type:pc,position:Bi,width:Number(ar.width)||ob,height:Number(ar.height)||ab,data:{label:Yt,definitionId:Et,role:"normal",body:pt,inputs:vt,outputs:un,sourceContextRunNodeId:Ge,displayReloadKey:rn[Ot].displayReloadKey,nodeSize:ar,displaySize:ar}},rn,be),ko=xn.map(Rr=>{if(Rr.id===Ge){const{width:jce,height:Cce,measured:_ce,...LL}=Rr,{nodeSize:Ece,displaySize:Ace,...Qf}=Rr.data||{};return{...LL,data:{...Qf,outputs:VC(Qf==null?void 0:Qf.outputs),contextRunResultNonce:Date.now()}}}return Rr.id===Ot?{...ui,selected:Rr.selected}:Rr});fn||ko.push(ui),N.current=ko,g(ko);const vo=j.current||[],Xf=uM(Et),Zg=WC((we==null?void 0:we.output)||((L0=zt==null?void 0:zt.data)==null?void 0:L0.outputs),"output",["content","result"],["text"]),ML=WC(vt,"input",[Xf,"content"],["text"]),$L={id:`we-${Ge}-${Ot}`,source:Ge,target:Ot,sourceHandle:Zg,targetHandle:ML,markerEnd:{type:bi.ArrowClosed}},C0=[...vo.filter(Rr=>!(Rr.source===Ge&&Rr.target===Ot)),$L];j.current=C0,w(C0),window.requestAnimationFrame(()=>{o(Ge),o(Ot)})},xa=(ye,nt=null)=>{const Ge=ye!=null&&ye.instances&&typeof ye.instances=="object"?ye.instances:{},pt=nt instanceof Set?nt:null;for(const[we,ct]of Object.entries(Ge)){if(pt&&!pt.has(we)||!ei(ct==null?void 0:ct.definitionId))continue;const Et=lg({outputs:ct.output});Et&&wa(we,Et)}},Uf=ye=>{const nt=String(ye||"").trim();if(!nt)return;const Ge=ze;ze=nt,wl(pt=>{const we=new Set(pt);return Ge&&Ge!==nt&&Ge!==x&&we.delete(Ge),x&&we.add(x),we.add(nt),we}),xl(pt=>{var we;return{...pt,...Ge&&Ge!==nt&&Ge!==x&&((we=pt[Ge])==null?void 0:we.status)==="running"?{[Ge]:{status:"success"}}:{},...x?{[x]:{status:"running"}}:{},[nt]:{status:"running"}}})},S0=ye=>{const nt=String(ye||"").trim();nt&&(wl(Ge=>{const pt=new Set(Ge);return pt.delete(nt),pt}),xl(Ge=>({...Ge,[nt]:{status:"success"}})))},N0=(ye,nt)=>{const Ge=String(nt||"");if(!Ge.trim())return;const pt=["assistant","thinking","result","error","prompt"].includes(ye)?ye:"assistant";qn(we=>we.map(ct=>{if(ct.id!==J)return ct;let Et=Array.isArray(ct.messages)?ct.messages:[];if(pt==="result"){const vt=[...Et].reverse().find(un=>un.kind==="assistant");if(String((vt==null?void 0:vt.text)||"").trim()===Ge.trim())return ct}if(pt==="assistant"){const vt=Et.findIndex(un=>un.kind==="result"&&String(un.text||"").trim()===Ge.trim());vt>=0&&(Et=Et.filter((un,Yt)=>Yt!==vt))}const Ot=[...Et],ht=Ot[Ot.length-1];return ht&&ht.kind===pt&&!ht.error?Ot[Ot.length-1]={...ht,text:`${ht.text||""}${ht.text?`
253
253
  `:""}${Ge}`}:Ot.push({role:"assistant",kind:pt,text:Ge,...pt==="error"?{error:!0}:{},at:Date.now()}),{...ct,messages:Ot.slice(-160)}}))},Yf=ye=>{const nt=String(ye||"");nt.trim()&&qn(Ge=>Ge.map(pt=>{var Ot;if(pt.id!==J)return pt;const we=Array.isArray(pt.messages)?pt.messages:[],ct=we.findIndex(ht=>ht.kind==="thinking"),Et=[...we];if(ct>=0){const ht=String(((Ot=Et[ct])==null?void 0:Ot.text)||"");Et[ct]={...Et[ct],text:`${ht}${ht&&!ht.endsWith(`
254
254
  `),""}${nt}`,at:Date.now()}}else{const ht=Et.findIndex(vt=>vt.kind==="activity");Et.splice(ht>=0?ht+1:Et.length,0,{role:"assistant",kind:"thinking",text:nt,at:Date.now()})}return{...pt,messages:Et.slice(-160)}}))},xo=(ye,nt=null)=>{const Ge=$Y(ye);Ge&&qn(pt=>pt.map(we=>{if(we.id!==J)return we;const ct=Number(nt==null?void 0:nt.ts)||Date.now(),Et=Number(we.startedAt)||ct,Ot=Number(we.lastActivityAt)||Et,ht=Math.max(0,ct-Ot),vt=Number.isFinite(Number(nt==null?void 0:nt.runElapsedMs))?Math.max(0,Number(nt.runElapsedMs)):Math.max(0,ct-Et),un=Array.isArray(we.activities)?we.activities:[],Yt=un[un.length-1],xn=(typeof Yt=="string"?Yt:String((Yt==null?void 0:Yt.text)||""))===Ge?un:[...un,{text:Ge,kind:OY(Ge),stepMs:ht,totalMs:vt,at:ct}].slice(-30),zt=Array.isArray(we.timingEntries)?we.timingEntries:[],fn=Array.isArray(we.messages)?we.messages:[],bo=fn.findIndex(ui=>ui.kind==="activity"),Bi={role:"assistant",kind:"activity",text:jC(xn,zt,Et,ct),at:Date.now()},ar=[...fn];if(bo>=0)ar[bo]=Bi;else{const ui=ar.findIndex(ko=>ko.kind==="run-summary");ar.splice(ui>=0?ui+1:0,0,Bi)}return{...we,activities:xn,lastActivityAt:ct,messages:ar.slice(-160)}}))},j0=ye=>{const nt=String((ye==null?void 0:ye.source)||"runner"),Ge=String((ye==null?void 0:ye.stream)||""),pt=String((ye==null?void 0:ye.eventType)||"event"),we=String((ye==null?void 0:ye.text)||"").trim();if(!we)return;const ct=`[${nt}${Ge?`:${Ge}`:""}] ${pt}
@@ -257,11 +257,11 @@ ${we}`,Et=mG(ye);qn(Ot=>Ot.map(ht=>{if(ht.id!==J)return ht;const un=[...Array.is
257
257
  ---
258
258
 
259
259
  `),at:Date.now()},ar=[...bo],ui=ar.findIndex(vo=>vo.kind==="activity");if(Et){const vo={role:"assistant",kind:"activity",text:jC(xn,rn,zt,fn),at:Date.now()};if(ui>=0)ar[ui]=vo;else{const Xf=ar.findIndex(Zg=>Zg.kind==="run-summary");ar.splice(Xf>=0?Xf+1:0,0,vo)}}const ko=ar.findIndex(vo=>vo.kind==="raw");return ko>=0?ar[ko]=Bi:ar.push(Bi),{...ht,rawTrace:un,timingEntries:rn,messages:ar.slice(-160)}}))},TL=ye=>{qn(nt=>nt.map(Ge=>Ge.id===J?{...Ge,status:ye,endedAt:Date.now()}:Ge))},Gf=ye=>{const nt=new Set,Ge=String((ye==null?void 0:ye.nodeId)||"").trim();Ge&&nt.add(Ge);for(const pt of Array.isArray(ye==null?void 0:ye.displayNodeIds)?ye.displayNodeIds:[]){const we=String(pt||"").trim();we&&nt.add(we)}for(const pt of Array.isArray(ye==null?void 0:ye.touchedNodeIds)?ye.touchedNodeIds:[]){const we=String(pt||"").trim();we&&nt.add(we)}if(nt.size===0)for(const pt of Array.isArray(ye==null?void 0:ye.order)?ye.order:[]){const we=String(pt||"").trim();we&&nt.add(we)}return nt},Jf=(ye,nt=null)=>{const Ge=Iu(ye||X,be),pt=new Map(Ge.nodes.map(ht=>[ht.id,ht])),we=Ge.instances||{},ct=nt instanceof Set?nt:null,Et=(ht,vt)=>{const un={...ht||vt};Array.isArray(vt==null?void 0:vt.output)&&(un.output=vt.output);for(const Yt of["scriptRef","implementationRef","implementationMode"])(vt==null?void 0:vt[Yt])!=null&&String(vt[Yt]).trim()!==""&&(un[Yt]=vt[Yt]);return un},Ot=(ht,vt)=>{const un={...ht||{}};Array.isArray(vt==null?void 0:vt.outputs)&&(un.outputs=vt.outputs);for(const Yt of["scriptRef","implementationRef","implementationMode"])(vt==null?void 0:vt[Yt])!=null&&String(vt[Yt]).trim()!==""&&(un[Yt]=vt[Yt]);return un};g(ht=>{const vt=new Set(ht.map(rn=>rn.id)),Yt={...Ml(ht,j.current,Z.current).instances||{}};for(const[rn,xn]of Object.entries(we)){if(ct&&!ct.has(rn)||!vt.has(rn))continue;const zt=Yt[rn];tl((xn==null?void 0:xn.definitionId)||(zt==null?void 0:zt.definitionId))?Yt[rn]=xn:Array.isArray(xn==null?void 0:xn.output)&&(Yt[rn]=Et(zt,xn))}return Z.current=Yt,ne(Yt),ht.map(rn=>{var zt,fn;if(ct&&!ct.has(rn.id))return rn;const xn=pt.get(rn.id);return xn?tl(((zt=xn.data)==null?void 0:zt.definitionId)||((fn=rn.data)==null?void 0:fn.definitionId))?{...rn,data:{...rn.data,...xn.data}}:{...rn,data:Ot(rn.data,xn.data)}:rn})})};for(;;){const{value:ye,done:nt}=await Le.read();if(nt)break;De+=Mt.decode(ye,{stream:!0});const Ge=De.split(`
260
- `);De=Ge.pop()||"";for(const pt of Ge){if(!pt.trim())continue;const we=JSON.parse(pt);if(we.type==="error")throw new Error(we.error||"Workspace run failed");if(we.type==="stopped"){ou.current.add(J),dt=Array.isArray(we.order)?we.order:dt,xo("运行停止",we);continue}if(we.type==="node-start"&&(ge(`Running ${we.nodeId}...`),Uf(we.nodeId),ci(we.nodeId,we.definitionId,"running")),we.type==="node-done"){const ct=Ve.get(String(we.nodeId||"").trim());ct&&wa(we.nodeId,ct),S0(we.nodeId),ci(we.nodeId,we.definitionId,"done")}if(we.type==="status"&&xo(we.line||we.message||"",we),we.type==="paused"&&(Pt=Array.isArray(we.nodeIds)?we.nodeIds:[],xo("运行暂停",we)),we.type==="natural"&&((we.kind==="result"||/---agentflow\b|resultFile\s*:|\"resultFile\"\s*:|\"result\"\s*:/i.test(String(we.text||"")))&&we.nodeId&&Ve.set(String(we.nodeId||"").trim(),String(we.text||"")),we.kind==="thinking"?Yf(we.text||""):N0(we.kind,we.text||"")),we.type==="raw"){const ct=CC(we);ct&&Yf(ct),j0(we)}if(we.type==="graph"&&we.graph){const ct=Gf(we);Jf(we.graph,ct),xa(we.graph,ct)}if(we.type==="done"){if(we.revision&&(me.current=String(we.revision)),we.graph){$e.current=we.graph;const ct=Gf(we);Jf(we.graph,ct),xa(we.graph,ct)}dt=Array.isArray(we.order)?we.order:[],Pt=Array.isArray(we.pauseNodeIds)?we.pauseNodeIds:Pt,xo(Pt.length?"运行暂停":"运行完成",we)}}}if(De.trim()){const ye=JSON.parse(De);if(ye.type==="error")throw new Error(ye.error||"Workspace run failed");if(ye.type==="stopped"&&(ou.current.add(J),xo("运行停止",ye)),ye.type==="node-start"&&(ge(`Running ${ye.nodeId}...`),Uf(ye.nodeId),ci(ye.nodeId,ye.definitionId,"running")),ye.type==="node-done"){const nt=Ve.get(String(ye.nodeId||"").trim());nt&&wa(ye.nodeId,nt),S0(ye.nodeId),ci(ye.nodeId,ye.definitionId,"done")}if(ye.type==="status"&&xo(ye.line||ye.message||"",ye),ye.type==="paused"&&(Pt=Array.isArray(ye.nodeIds)?ye.nodeIds:[],xo("运行暂停",ye)),ye.type==="natural"&&((ye.kind==="result"||/---agentflow\b|resultFile\s*:|\"resultFile\"\s*:|\"result\"\s*:/i.test(String(ye.text||"")))&&ye.nodeId&&Ve.set(String(ye.nodeId||"").trim(),String(ye.text||"")),ye.kind==="thinking"?Yf(ye.text||""):N0(ye.kind,ye.text||"")),ye.type==="raw"){const nt=CC(ye);nt&&Yf(nt),j0(ye)}if(ye.type==="graph"&&ye.graph){const nt=Gf(ye);Jf(ye.graph,nt),xa(ye.graph,nt)}if(ye.type==="done"){if(ye.revision&&(me.current=String(ye.revision)),ye.graph){$e.current=ye.graph;const nt=Gf(ye);Jf(ye.graph,nt),xa(ye.graph,nt)}dt=Array.isArray(ye.order)?ye.order:[],Pt=Array.isArray(ye.pauseNodeIds)?ye.pauseNodeIds:Pt,xo(Pt.length?"运行暂停":"运行完成",ye)}}He()&&(Me(he),Ft(he,"stopped"));const Qg=He()?`Workspace run stopped: ${x}`:Pt.length?`Workspace run paused at ${Pt.join(", ")}`:`Workspace run done: ${dt.length?dt.join(" -> "):x}`;if(ge(Qg),He()||Ft(he,Pt.length?"paused":"success"),TL(He()?"stopped":Pt.length?"paused":"done"),!He()){try{await Zt(N.current,j.current),ge(Qg)}catch(ye){ge(`${Qg},但保存结果失败:${String(ye.message||ye)}`)}await An()}}catch(rt){if(He()||(rt==null?void 0:rt.name)==="AbortError"){Me(he),Ft(he,"stopped"),ge(`Workspace run stopped: ${x}`),qn(Ye=>Ye.map(Le=>Le.id===J?{...Le,status:"stopped",endedAt:Date.now()}:Le));return}Me(he),Ft([x,ze].filter(Boolean),"failed"),ge(String(rt.message||rt)),qn(Ye=>Ye.map(Le=>Le.id===J?{...Le,status:"failed",endedAt:Date.now(),messages:[...Array.isArray(Le.messages)?Le.messages:[],{role:"assistant",error:!0,text:String(rt.message||rt),at:Date.now()}].slice(-160)}:Le))}finally{iu.current.get(J)===We&&iu.current.delete(J),Di(rt=>{const Ye={...rt};return delete Ye[J],Ye}),ou.current.delete(J),Me(he)}},[Li,v,a,An,b,be,Br,Zt,$s,w,g,Di,o,je]),Rf=m.useCallback(async()=>{try{const S=await(await fetch("/api/skills")).json().catch(()=>({})),_=Array.isArray(S.skills)?S.skills.map(A=>({key:String(A.key),name:String(A.name||A.id||A.key),description:A.description?String(A.description):"",sourceLabel:A.sourceLabel?String(A.sourceLabel):""})):[];w$(_),Gv(!0)}catch{Gv(!0)}},[]),Tf=m.useCallback(async()=>{try{const S=await(await fetch("/api/mcps")).json().catch(()=>({})),_=Array.isArray(S.servers)?S.servers.map(A=>({name:String((A==null?void 0:A.name)||""),type:String((A==null?void 0:A.type)||""),url:String((A==null?void 0:A.url)||""),command:String((A==null?void 0:A.command)||""),args:Array.isArray(A==null?void 0:A.args)?A.args.map(String):[],description:String((A==null?void 0:A.description)||"")})).filter(A=>A.name):[];Qv(_)}catch{Qv([])}},[]),Mf=m.useCallback(async()=>{try{const x=Tr(a),_=await(await fetch(`/api/workspaces?${x.toString()}`)).json().catch(()=>({})),A=Array.isArray(_.workspaces)?_.workspaces.map(R=>({id:String((R==null?void 0:R.id)||""),label:String((R==null?void 0:R.label)||(R==null?void 0:R.name)||"知识库"),path:String((R==null?void 0:R.path)||""),kind:(R==null?void 0:R.kind)==="git"?"git":"local",repoUrl:String((R==null?void 0:R.repoUrl)||""),branch:String((R==null?void 0:R.branch)||""),mountPath:String((R==null?void 0:R.mountPath)||""),type:String((R==null?void 0:R.type)||""),builtin:(R==null?void 0:R.builtin)===!0,exists:(R==null?void 0:R.exists)!==!1})).filter(R=>R.path):[];eS(A)}catch{eS([])}},[a]),LS=m.useCallback(async()=>{Ke.current=!1;try{const x=Tr(a),S=await fetch(`/api/workspace/conversations?${x.toString()}`),_=await S.json().catch(()=>({}));if(!S.ok)throw new Error(_.error||`HTTP ${S.status}`);const A=kC(_.conversations||{});hl(A.composer.messages),qn(A.composer.runSessions),bs(A.composer.activeSessionId||"workspace"),yo(A.nodeChats)}catch{hl([]),qn([]),bs("workspace"),yo({})}finally{Ke.current=!0}},[a]),OS=m.useCallback(async()=>{if(!je||a.archived)return;const x=kC({composer:{activeSessionId:Hr,messages:pa,runSessions:Ls},nodeChats:ha});await fetch("/api/workspace/conversations",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,conversations:x})}).then(async S=>{if(!S.ok){const _=await S.json().catch(()=>({}));throw new Error(_.error||`HTTP ${S.status}`)}})},[Hr,pa,Ls,a,ha,je]);m.useEffect(()=>{let x=!1;return(async()=>{const _=new URL(window.location.href),A=String(_.searchParams.get("invite")||"").trim();if(A){ge("正在加入共享 Workspace...");const R=await fetch("/api/workspace/collaboration/accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:A})}),U=await R.json().catch(()=>({}));if(!R.ok)throw new Error(U.error||"加入共享 Workspace 失败");_.searchParams.delete("invite"),window.history.replaceState({},"",`${_.pathname}${_.search}${_.hash}`)}x||(await ks(),x||await LS())})().catch(_=>{const A=String(_.message||_);ge(A),Os("error"),Ds(A)}),Af(),fetch("/api/model-lists").then(_=>_.json()).then(_=>g$({cursor:Array.isArray(_.cursor)?_.cursor.map(String):[],opencode:Array.isArray(_.opencode)?_.opencode.map(String):[],claudeCode:Array.isArray(_.claudeCode)?_.claudeCode.map(String):[],codex:Array.isArray(_.codex)?_.codex.map(String):[]})).catch(()=>{}),Rf(),Tf(),Mf(),If(),fetch("/api/skill-collections").then(_=>_.json()).then(_=>{x$(Oa(_)),b$(!0)}).catch(()=>{}),fetch("/api/auth/me").then(_=>_.json()).then(_=>{pS(_.user||null),mS(!0)}).catch(()=>{pS(null),mS(!0)}),()=>{x=!0}},[ks,LS,Af,Tf,Rf,If,Mf,Oi]),m.useEffect(()=>{if(CS(""),!(!Yv||!Jv)){if(!Oi){Qc([]);return}Qc(_F(Oi,"workspace",Ms,fl)),CS(Oi)}},[fl,Jv,Ms,Yv,Oi]),m.useEffect(()=>{if(!(jS!==Oi||!Oi))try{localStorage.setItem(Oi,JSON.stringify($s))}catch{}},[$s,Oi,jS]),m.useEffect(()=>{Z.current=te},[te]),m.useEffect(()=>{N.current=b},[b]),m.useEffect(()=>{if(lt.current)return;const x=H.current,S=new Map,_=[];for(const A of b){const R=VT(A);S.set(A.id,R),x.get(A.id)!==R&&_.push(A.id)}H.current=S,_.length!==0&&Br(_)},[b,Br]),m.useEffect(()=>{j.current=v},[v]),m.useEffect(()=>{z.current=P},[P]),m.useEffect(()=>{F.current=$},[$]),m.useEffect(()=>{Rv.current=at},[at]),m.useEffect(()=>{go.current=Ut},[Ut]),m.useEffect(()=>{ue.current=G},[G]),m.useEffect(()=>{if(!G)return;const x=_=>{_.key==="Escape"&&ee(null)},S=_=>{var A,R;(R=(A=_.target)==null?void 0:A.closest)!=null&&R.call(A,".af-connect-node-menu")||ee(null)};return document.addEventListener("keydown",x),document.addEventListener("pointerdown",S),()=>{document.removeEventListener("keydown",x),document.removeEventListener("pointerdown",S)}},[G]),m.useEffect(()=>{if(!ce.current||!je)return;if(lt.current){de.current&&window.clearTimeout(de.current);return}if(Fe.current){Fe.current=!1;return}li(),de.current&&window.clearTimeout(de.current);const x=oe.current?0:650;return oe.current=!1,de.current=window.setTimeout(()=>{Zt().catch(S=>ge(String(S.message||S)))},x),()=>{de.current&&window.clearTimeout(de.current)}},[b,v,P,li,Zt,je]),m.useEffect(()=>{if(Ke.current&&!(!je||a.archived))return Ue.current&&window.clearTimeout(Ue.current),Ue.current=window.setTimeout(()=>{OS().catch(x=>ge(String(x.message||x)))},900),()=>{Ue.current&&window.clearTimeout(Ue.current)}},[Hr,pa,Ls,a.archived,ha,OS,je]);const du=m.useMemo(()=>b.filter(x=>{var S;return((S=x==null?void 0:x.data)==null?void 0:S.definitionId)==="workspace_scheduled_run"}).map(x=>{var S;return{id:x.id,config:gv(((S=x.data)==null?void 0:S.body)||"")}}),[b]),F$=m.useMemo(()=>du.map(x=>`${x.id}:${x.config.enabled?"1":"0"}:${x.config.cron}:${x.config.timezone}`).join("|"),[du]);m.useEffect(()=>{if(!ce.current||d!=="workspace"||!a.flowId){ma({});return}if(!du.length){ma({});return}let x=!1;const S=async()=>{try{const A=Tr(a),R=await fetch(`/api/workspace/schedules?${A.toString()}`),U=await R.json().catch(()=>({}));if(!R.ok)throw new Error(U.error||"读取 Workspace 定时状态失败");x||ma(Lp(U.schedules||[]))}catch{x||ma(A=>{var U;const R={};for(const X of du)R[X.id]={...A[X.id]||{},lastStatus:((U=A[X.id])==null?void 0:U.lastStatus)||"unknown"};return R})}};S();const _=window.setInterval(S,5e3);return()=>{x=!0,window.clearInterval(_)}},[a,du,F$,d]);const DS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=BC(S),A=Y=>Array.isArray(Y)?Y.map(ae=>(ae==null?void 0:ae.name)!=="skillKeys"&&(ae==null?void 0:ae.name)!=="skillsContext"&&(ae==null?void 0:ae.type)!=="text"?ae:{...ae,default:_,value:_}):[],R=b.map(Y=>{var ae;return Y.id!==x?Y:{...Y,data:{...Y.data,body:_,inputs:A((ae=Y.data)==null?void 0:ae.inputs)}}}),U=Z.current||{},X=U[x]&&typeof U[x]=="object"?U[x]:{},J={...U,[x]:{...X,body:_,input:A(X.input)}};Z.current=J,g(R),ne(J),ws(Y=>!Y||Y.id!==x?Y:{...Y,body:_,inputs:A(Y.inputs)}),Zt(R,v).catch(Y=>ge(String(Y.message||Y)))},[v,b,Zt,g,je]),FS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=NJ(S),A=Y=>Array.isArray(Y)?Y.map(ae=>(ae==null?void 0:ae.name)!=="serverNames"&&(ae==null?void 0:ae.name)!=="mcpContext"&&(ae==null?void 0:ae.type)!=="text"?ae:{...ae,default:_,value:_}):[],R=b.map(Y=>{var ae;return Y.id!==x?Y:{...Y,data:{...Y.data,body:_,inputs:A((ae=Y.data)==null?void 0:ae.inputs)}}}),U=Z.current||{},X=U[x]&&typeof U[x]=="object"?U[x]:{},J={...U,[x]:{...X,body:_,input:A(X.input)}};Z.current=J,g(R),ne(J),ws(Y=>!Y||Y.id!==x?Y:{...Y,body:_,inputs:A(Y.inputs)}),Zt(R,v).catch(Y=>ge(String(Y.message||Y)))},[v,b,Zt,g,je]),zS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=(Array.isArray(S)?S:S?[S]:[]).filter(ze=>String((ze==null?void 0:ze.path)||"").trim()),A=_[0]||null,R=String((A==null?void 0:A.path)||"").trim(),U=_.length===1?String((A==null?void 0:A.label)||(A==null?void 0:A.id)||"知识库").trim():_.length?`${_.length} 个知识库`:"",X=_.length?JSON.stringify(cg(_)):"",J=A?JSON.stringify({version:1,id:(A==null?void 0:A.id)||"",label:String((A==null?void 0:A.label)||(A==null?void 0:A.id)||"知识库").trim(),kind:(A==null?void 0:A.kind)||"local",cwd:R,workspaceRoot:R,repoUrl:(A==null?void 0:A.repoUrl)||"",branch:(A==null?void 0:A.branch)||"",mountPath:(A==null?void 0:A.mountPath)||"",type:(A==null?void 0:A.type)||""}):"",Y=ze=>Array.isArray(ze)?ze.map(Ve=>(Ve==null?void 0:Ve.name)==="path"?{...Ve,default:R,value:R}:(Ve==null?void 0:Ve.name)==="label"?{...Ve,default:U,value:U}:(Ve==null?void 0:Ve.name)==="knowledgeContext"?{...Ve,default:X,value:X}:(Ve==null?void 0:Ve.name)==="workspaceContext"?{...Ve,default:J,value:J}:(Ve==null?void 0:Ve.name)==="mode"?{...Ve,default:"set",value:"set"}:Ve):[],ae=ze=>Array.isArray(ze)?ze.map(Ve=>(Ve==null?void 0:Ve.name)==="knowledgeContext"?{...Ve,default:X,value:X}:(Ve==null?void 0:Ve.name)==="workspaceContext"?{...Ve,default:J,value:J,showOnNode:!1}:(Ve==null?void 0:Ve.name)==="cwd"?{...Ve,default:R,value:R,showOnNode:!1}:Ve):[],he=b.map(ze=>{var Ve,He,Me;return ze.id===x?{...ze,data:{...ze.data,label:((Ve=ze.data)==null?void 0:Ve.label)||"加载知识库",inputs:Y((He=ze.data)==null?void 0:He.inputs),outputs:ae((Me=ze.data)==null?void 0:Me.outputs)}}:ze}),fe=Z.current||{},Ne=fe[x]&&typeof fe[x]=="object"?fe[x]:{},We={...fe,[x]:{...Ne,label:Ne.label||"加载知识库",input:Y(Ne.input),output:ae(Ne.output)}};Z.current=We,g(he),ne(We),ws(ze=>(ze==null?void 0:ze.id)===x?{...ze,inputs:Y(ze.inputs),outputs:ae(ze.outputs)}:ze),Zt(he,v).catch(ze=>ge(String(ze.message||ze)))},[v,b,Zt,g,je]),BS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=String(x||"");if(!_)return;const A=BC((S==null?void 0:S.skillKeys)||[]),R=gf((S==null?void 0:S.displayType)||"markdown"),U=String((S==null?void 0:S.model)||"").trim(),X=(S==null?void 0:S.includeWorkspaceContext)===!1?"false":"true",J=S!=null&&S.workspaceContext&&typeof S.workspaceContext=="object"?JSON.stringify(S.workspaceContext):"",Y=S!=null&&S.knowledgeContext&&typeof S.knowledgeContext=="object"?JSON.stringify(S.knowledgeContext):"",ae=He=>Array.isArray(He)?He.map(Me=>(Me==null?void 0:Me.name)==="skillKeys"?{...Me,default:A,value:A}:(Me==null?void 0:Me.name)==="displayType"?{...Me,default:R,value:R}:(Me==null?void 0:Me.name)==="includeWorkspaceContext"?{...Me,default:X,value:X}:(Me==null?void 0:Me.name)==="knowledgeContext"?{...Me,default:Y,value:Y}:(Me==null?void 0:Me.name)==="workspaceContext"?{...Me,default:J,value:J}:Me):[],he=He=>Array.isArray(He)?He.map(Me=>(Me==null?void 0:Me.name)==="displayType"?{...Me,default:R,value:R}:Me):[],fe=String((S==null?void 0:S.task)??""),Ne=b.map(He=>{var Me,Ft;return He.id===_?{...He,data:{...He.data,body:fe,model:U,inputs:ae((Me=He.data)==null?void 0:Me.inputs),outputs:he((Ft=He.data)==null?void 0:Ft.outputs)}}:He}),We=Z.current||{},ze=We[_]&&typeof We[_]=="object"?We[_]:{},Ve={...We,[_]:{...ze,body:fe,model:U,input:ae(ze.input),output:he(ze.output)}};Z.current=Ve,g(Ne),ne(Ve),ws(He=>(He==null?void 0:He.id)===_?{...He,body:fe,model:U,inputs:ae(He.inputs),outputs:he(He.outputs)}:He),Zt(Ne,v).catch(He=>ge(String(He.message||He)))},[v,b,Zt,g,je]),HS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=jG(S),A=b.map(J=>J.id===x?{...J,data:{...J.data,body:_}}:J),R=Z.current||{},U=R[x]&&typeof R[x]=="object"?R[x]:{},X={...R,[x]:{...U,body:_}};Z.current=X,Fe.current=!0,g(A),ne(X),ws(J=>(J==null?void 0:J.id)===x?{...J,body:_}:J),Zt(A,v).catch(J=>ge(String(J.message||J)))},[v,b,Zt,g,je]),WS=m.useCallback(x=>{const S=String(x||"").trim();S&&(fS(_=>_===S?"":S),yo(_=>({..._,[S]:_[S]||{sessionId:`nodechat_${Date.now()}_${S.replace(/[^a-z0-9_-]+/gi,"_")}`,messages:[],draft:"",candidateContent:"",running:!1,error:""}})))},[]),VS=m.useCallback(()=>fS(""),[]),KS=m.useCallback((x,S)=>{const _=String(x||"").trim();_&&yo(A=>({...A,[_]:{...A[_]||{sessionId:`nodechat_${Date.now()}_${_.replace(/[^a-z0-9_-]+/gi,"_")}`,messages:[]},draft:String(S||""),error:""}}))},[]),Fs=m.useCallback((x,S,_="replace",A={})=>{var rt,Ye;if(!je){ge("Readonly workspace");return}const R=String(x||"").trim();if(!R)return;const U=N.current.find(Le=>Le.id===R),X=In(U==null?void 0:U.data),J=ei((rt=U==null?void 0:U.data)==null?void 0:rt.definitionId),Y=Ei(S),ae=X==="html"?Hc(Y):X==="react"?ag(Y):String(Y||""),he=U?no(U.data):"",fe=_==="append"&&String(he||"").trim()?`${String(he).replace(/\s+$/g,"")}
260
+ `);De=Ge.pop()||"";for(const pt of Ge){if(!pt.trim())continue;const we=JSON.parse(pt);if(we.type==="error")throw new Error(we.error||"Workspace run failed");if(we.type==="stopped"){ou.current.add(J),dt=Array.isArray(we.order)?we.order:dt,xo("运行停止",we);continue}if(we.type==="node-start"&&(ge(`Running ${we.nodeId}...`),Uf(we.nodeId),ci(we.nodeId,we.definitionId,"running")),we.type==="node-done"){const ct=Ve.get(String(we.nodeId||"").trim());ct&&wa(we.nodeId,ct),S0(we.nodeId),ci(we.nodeId,we.definitionId,"done")}if(we.type==="status"&&xo(we.line||we.message||"",we),we.type==="paused"&&(Pt=Array.isArray(we.nodeIds)?we.nodeIds:[],xo("运行暂停",we)),we.type==="natural"&&((we.kind==="result"||/---agentflow\b|resultFile\s*:|\"resultFile\"\s*:|\"result\"\s*:/i.test(String(we.text||"")))&&we.nodeId&&Ve.set(String(we.nodeId||"").trim(),String(we.text||"")),we.kind==="thinking"?Yf(we.text||""):N0(we.kind,we.text||"")),we.type==="raw"){const ct=CC(we);ct&&Yf(ct),j0(we)}if(we.type==="graph"&&we.graph){const ct=Gf(we);Jf(we.graph,ct),xa(we.graph,ct)}if(we.type==="done"){if(we.revision&&(me.current=String(we.revision)),we.graph){$e.current=we.graph;const ct=Gf(we);Jf(we.graph,ct),xa(we.graph,ct)}dt=Array.isArray(we.order)?we.order:[],Pt=Array.isArray(we.pauseNodeIds)?we.pauseNodeIds:Pt,xo(Pt.length?"运行暂停":"运行完成",we)}}}if(De.trim()){const ye=JSON.parse(De);if(ye.type==="error")throw new Error(ye.error||"Workspace run failed");if(ye.type==="stopped"&&(ou.current.add(J),xo("运行停止",ye)),ye.type==="node-start"&&(ge(`Running ${ye.nodeId}...`),Uf(ye.nodeId),ci(ye.nodeId,ye.definitionId,"running")),ye.type==="node-done"){const nt=Ve.get(String(ye.nodeId||"").trim());nt&&wa(ye.nodeId,nt),S0(ye.nodeId),ci(ye.nodeId,ye.definitionId,"done")}if(ye.type==="status"&&xo(ye.line||ye.message||"",ye),ye.type==="paused"&&(Pt=Array.isArray(ye.nodeIds)?ye.nodeIds:[],xo("运行暂停",ye)),ye.type==="natural"&&((ye.kind==="result"||/---agentflow\b|resultFile\s*:|\"resultFile\"\s*:|\"result\"\s*:/i.test(String(ye.text||"")))&&ye.nodeId&&Ve.set(String(ye.nodeId||"").trim(),String(ye.text||"")),ye.kind==="thinking"?Yf(ye.text||""):N0(ye.kind,ye.text||"")),ye.type==="raw"){const nt=CC(ye);nt&&Yf(nt),j0(ye)}if(ye.type==="graph"&&ye.graph){const nt=Gf(ye);Jf(ye.graph,nt),xa(ye.graph,nt)}if(ye.type==="done"){if(ye.revision&&(me.current=String(ye.revision)),ye.graph){$e.current=ye.graph;const nt=Gf(ye);Jf(ye.graph,nt),xa(ye.graph,nt)}dt=Array.isArray(ye.order)?ye.order:[],Pt=Array.isArray(ye.pauseNodeIds)?ye.pauseNodeIds:Pt,xo(Pt.length?"运行暂停":"运行完成",ye)}}He()&&(Me(pe),Ft(pe,"stopped"));const Qg=He()?`Workspace run stopped: ${x}`:Pt.length?`Workspace run paused at ${Pt.join(", ")}`:`Workspace run done: ${dt.length?dt.join(" -> "):x}`;if(ge(Qg),He()||Ft(pe,Pt.length?"paused":"success"),TL(He()?"stopped":Pt.length?"paused":"done"),!He()){try{await Zt(N.current,j.current),ge(Qg)}catch(ye){ge(`${Qg},但保存结果失败:${String(ye.message||ye)}`)}await An()}}catch(rt){if(He()||(rt==null?void 0:rt.name)==="AbortError"){Me(pe),Ft(pe,"stopped"),ge(`Workspace run stopped: ${x}`),qn(Ye=>Ye.map(Le=>Le.id===J?{...Le,status:"stopped",endedAt:Date.now()}:Le));return}Me(pe),Ft([x,ze].filter(Boolean),"failed"),ge(String(rt.message||rt)),qn(Ye=>Ye.map(Le=>Le.id===J?{...Le,status:"failed",endedAt:Date.now(),messages:[...Array.isArray(Le.messages)?Le.messages:[],{role:"assistant",error:!0,text:String(rt.message||rt),at:Date.now()}].slice(-160)}:Le))}finally{iu.current.get(J)===We&&iu.current.delete(J),Di(rt=>{const Ye={...rt};return delete Ye[J],Ye}),ou.current.delete(J),Me(pe)}},[Li,v,a,An,b,be,Br,Zt,$s,w,g,Di,o,je]),Rf=m.useCallback(async()=>{try{const S=await(await fetch("/api/skills")).json().catch(()=>({})),_=Array.isArray(S.skills)?S.skills.map(A=>({key:String(A.key),name:String(A.name||A.id||A.key),description:A.description?String(A.description):"",sourceLabel:A.sourceLabel?String(A.sourceLabel):""})):[];w$(_),Gv(!0)}catch{Gv(!0)}},[]),Tf=m.useCallback(async()=>{try{const S=await(await fetch("/api/mcps")).json().catch(()=>({})),_=Array.isArray(S.servers)?S.servers.map(A=>({name:String((A==null?void 0:A.name)||""),type:String((A==null?void 0:A.type)||""),url:String((A==null?void 0:A.url)||""),command:String((A==null?void 0:A.command)||""),args:Array.isArray(A==null?void 0:A.args)?A.args.map(String):[],description:String((A==null?void 0:A.description)||"")})).filter(A=>A.name):[];Qv(_)}catch{Qv([])}},[]),Mf=m.useCallback(async()=>{try{const x=Tr(a),_=await(await fetch(`/api/workspaces?${x.toString()}`)).json().catch(()=>({})),A=Array.isArray(_.workspaces)?_.workspaces.map(R=>({id:String((R==null?void 0:R.id)||""),label:String((R==null?void 0:R.label)||(R==null?void 0:R.name)||"知识库"),path:String((R==null?void 0:R.path)||""),kind:(R==null?void 0:R.kind)==="git"?"git":"local",repoUrl:String((R==null?void 0:R.repoUrl)||""),branch:String((R==null?void 0:R.branch)||""),mountPath:String((R==null?void 0:R.mountPath)||""),type:String((R==null?void 0:R.type)||""),builtin:(R==null?void 0:R.builtin)===!0,exists:(R==null?void 0:R.exists)!==!1})).filter(R=>R.path):[];eS(A)}catch{eS([])}},[a]),LS=m.useCallback(async()=>{Ke.current=!1;try{const x=Tr(a),S=await fetch(`/api/workspace/conversations?${x.toString()}`),_=await S.json().catch(()=>({}));if(!S.ok)throw new Error(_.error||`HTTP ${S.status}`);const A=kC(_.conversations||{});hl(A.composer.messages),qn(A.composer.runSessions),bs(A.composer.activeSessionId||"workspace"),yo(A.nodeChats)}catch{hl([]),qn([]),bs("workspace"),yo({})}finally{Ke.current=!0}},[a]),OS=m.useCallback(async()=>{if(!je||a.archived)return;const x=kC({composer:{activeSessionId:Hr,messages:pa,runSessions:Ls},nodeChats:ha});await fetch("/api/workspace/conversations",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,conversations:x})}).then(async S=>{if(!S.ok){const _=await S.json().catch(()=>({}));throw new Error(_.error||`HTTP ${S.status}`)}})},[Hr,pa,Ls,a,ha,je]);m.useEffect(()=>{let x=!1;return(async()=>{const _=new URL(window.location.href),A=String(_.searchParams.get("invite")||"").trim();if(A){ge("正在加入共享 Workspace...");const R=await fetch("/api/workspace/collaboration/accept",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:A})}),U=await R.json().catch(()=>({}));if(!R.ok)throw new Error(U.error||"加入共享 Workspace 失败");_.searchParams.delete("invite"),window.history.replaceState({},"",`${_.pathname}${_.search}${_.hash}`)}x||(await ks(),x||await LS())})().catch(_=>{const A=String(_.message||_);ge(A),Os("error"),Ds(A)}),Af(),fetch("/api/model-lists").then(_=>_.json()).then(_=>g$({cursor:Array.isArray(_.cursor)?_.cursor.map(String):[],opencode:Array.isArray(_.opencode)?_.opencode.map(String):[],claudeCode:Array.isArray(_.claudeCode)?_.claudeCode.map(String):[],codex:Array.isArray(_.codex)?_.codex.map(String):[]})).catch(()=>{}),Rf(),Tf(),Mf(),If(),fetch("/api/skill-collections").then(_=>_.json()).then(_=>{x$(Oa(_)),b$(!0)}).catch(()=>{}),fetch("/api/auth/me").then(_=>_.json()).then(_=>{pS(_.user||null),mS(!0)}).catch(()=>{pS(null),mS(!0)}),()=>{x=!0}},[ks,LS,Af,Tf,Rf,If,Mf,Oi]),m.useEffect(()=>{if(CS(""),!(!Yv||!Jv)){if(!Oi){Qc([]);return}Qc(_F(Oi,"workspace",Ms,fl)),CS(Oi)}},[fl,Jv,Ms,Yv,Oi]),m.useEffect(()=>{if(!(jS!==Oi||!Oi))try{localStorage.setItem(Oi,JSON.stringify($s))}catch{}},[$s,Oi,jS]),m.useEffect(()=>{Z.current=te},[te]),m.useEffect(()=>{N.current=b},[b]),m.useEffect(()=>{if(lt.current)return;const x=H.current,S=new Map,_=[];for(const A of b){const R=VT(A);S.set(A.id,R),x.get(A.id)!==R&&_.push(A.id)}H.current=S,_.length!==0&&Br(_)},[b,Br]),m.useEffect(()=>{j.current=v},[v]),m.useEffect(()=>{z.current=P},[P]),m.useEffect(()=>{F.current=$},[$]),m.useEffect(()=>{Rv.current=at},[at]),m.useEffect(()=>{go.current=Ut},[Ut]),m.useEffect(()=>{ue.current=G},[G]),m.useEffect(()=>{if(!G)return;const x=_=>{_.key==="Escape"&&ee(null)},S=_=>{var A,R;(R=(A=_.target)==null?void 0:A.closest)!=null&&R.call(A,".af-connect-node-menu")||ee(null)};return document.addEventListener("keydown",x),document.addEventListener("pointerdown",S),()=>{document.removeEventListener("keydown",x),document.removeEventListener("pointerdown",S)}},[G]),m.useEffect(()=>{if(!ce.current||!je)return;if(lt.current){de.current&&window.clearTimeout(de.current);return}if(Fe.current){Fe.current=!1;return}li(),de.current&&window.clearTimeout(de.current);const x=oe.current?0:650;return oe.current=!1,de.current=window.setTimeout(()=>{Zt().catch(S=>ge(String(S.message||S)))},x),()=>{de.current&&window.clearTimeout(de.current)}},[b,v,P,li,Zt,je]),m.useEffect(()=>{if(Ke.current&&!(!je||a.archived))return Ue.current&&window.clearTimeout(Ue.current),Ue.current=window.setTimeout(()=>{OS().catch(x=>ge(String(x.message||x)))},900),()=>{Ue.current&&window.clearTimeout(Ue.current)}},[Hr,pa,Ls,a.archived,ha,OS,je]);const du=m.useMemo(()=>b.filter(x=>{var S;return((S=x==null?void 0:x.data)==null?void 0:S.definitionId)==="workspace_scheduled_run"}).map(x=>{var S;return{id:x.id,config:gv(((S=x.data)==null?void 0:S.body)||"")}}),[b]),F$=m.useMemo(()=>du.map(x=>`${x.id}:${x.config.enabled?"1":"0"}:${x.config.cron}:${x.config.timezone}`).join("|"),[du]);m.useEffect(()=>{if(!ce.current||d!=="workspace"||!a.flowId){ma({});return}if(!du.length){ma({});return}let x=!1;const S=async()=>{try{const A=Tr(a),R=await fetch(`/api/workspace/schedules?${A.toString()}`),U=await R.json().catch(()=>({}));if(!R.ok)throw new Error(U.error||"读取 Workspace 定时状态失败");x||ma(Lp(U.schedules||[]))}catch{x||ma(A=>{var U;const R={};for(const X of du)R[X.id]={...A[X.id]||{},lastStatus:((U=A[X.id])==null?void 0:U.lastStatus)||"unknown"};return R})}};S();const _=window.setInterval(S,5e3);return()=>{x=!0,window.clearInterval(_)}},[a,du,F$,d]);const DS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=BC(S),A=Y=>Array.isArray(Y)?Y.map(ae=>(ae==null?void 0:ae.name)!=="skillKeys"&&(ae==null?void 0:ae.name)!=="skillsContext"&&(ae==null?void 0:ae.type)!=="text"?ae:{...ae,default:_,value:_}):[],R=b.map(Y=>{var ae;return Y.id!==x?Y:{...Y,data:{...Y.data,body:_,inputs:A((ae=Y.data)==null?void 0:ae.inputs)}}}),U=Z.current||{},X=U[x]&&typeof U[x]=="object"?U[x]:{},J={...U,[x]:{...X,body:_,input:A(X.input)}};Z.current=J,g(R),ne(J),ws(Y=>!Y||Y.id!==x?Y:{...Y,body:_,inputs:A(Y.inputs)}),Zt(R,v).catch(Y=>ge(String(Y.message||Y)))},[v,b,Zt,g,je]),FS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=NJ(S),A=Y=>Array.isArray(Y)?Y.map(ae=>(ae==null?void 0:ae.name)!=="serverNames"&&(ae==null?void 0:ae.name)!=="mcpContext"&&(ae==null?void 0:ae.type)!=="text"?ae:{...ae,default:_,value:_}):[],R=b.map(Y=>{var ae;return Y.id!==x?Y:{...Y,data:{...Y.data,body:_,inputs:A((ae=Y.data)==null?void 0:ae.inputs)}}}),U=Z.current||{},X=U[x]&&typeof U[x]=="object"?U[x]:{},J={...U,[x]:{...X,body:_,input:A(X.input)}};Z.current=J,g(R),ne(J),ws(Y=>!Y||Y.id!==x?Y:{...Y,body:_,inputs:A(Y.inputs)}),Zt(R,v).catch(Y=>ge(String(Y.message||Y)))},[v,b,Zt,g,je]),zS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=(Array.isArray(S)?S:S?[S]:[]).filter(ze=>String((ze==null?void 0:ze.path)||"").trim()),A=_[0]||null,R=String((A==null?void 0:A.path)||"").trim(),U=_.length===1?String((A==null?void 0:A.label)||(A==null?void 0:A.id)||"知识库").trim():_.length?`${_.length} 个知识库`:"",X=_.length?JSON.stringify(cg(_)):"",J=A?JSON.stringify({version:1,id:(A==null?void 0:A.id)||"",label:String((A==null?void 0:A.label)||(A==null?void 0:A.id)||"知识库").trim(),kind:(A==null?void 0:A.kind)||"local",cwd:R,workspaceRoot:R,repoUrl:(A==null?void 0:A.repoUrl)||"",branch:(A==null?void 0:A.branch)||"",mountPath:(A==null?void 0:A.mountPath)||"",type:(A==null?void 0:A.type)||""}):"",Y=ze=>Array.isArray(ze)?ze.map(Ve=>(Ve==null?void 0:Ve.name)==="path"?{...Ve,default:R,value:R}:(Ve==null?void 0:Ve.name)==="label"?{...Ve,default:U,value:U}:(Ve==null?void 0:Ve.name)==="knowledgeContext"?{...Ve,default:X,value:X}:(Ve==null?void 0:Ve.name)==="workspaceContext"?{...Ve,default:J,value:J}:(Ve==null?void 0:Ve.name)==="mode"?{...Ve,default:"set",value:"set"}:Ve):[],ae=ze=>Array.isArray(ze)?ze.map(Ve=>(Ve==null?void 0:Ve.name)==="knowledgeContext"?{...Ve,default:X,value:X}:(Ve==null?void 0:Ve.name)==="workspaceContext"?{...Ve,default:J,value:J,showOnNode:!1}:(Ve==null?void 0:Ve.name)==="cwd"?{...Ve,default:R,value:R,showOnNode:!1}:Ve):[],pe=b.map(ze=>{var Ve,He,Me;return ze.id===x?{...ze,data:{...ze.data,label:((Ve=ze.data)==null?void 0:Ve.label)||"加载知识库",inputs:Y((He=ze.data)==null?void 0:He.inputs),outputs:ae((Me=ze.data)==null?void 0:Me.outputs)}}:ze}),fe=Z.current||{},Ne=fe[x]&&typeof fe[x]=="object"?fe[x]:{},We={...fe,[x]:{...Ne,label:Ne.label||"加载知识库",input:Y(Ne.input),output:ae(Ne.output)}};Z.current=We,g(pe),ne(We),ws(ze=>(ze==null?void 0:ze.id)===x?{...ze,inputs:Y(ze.inputs),outputs:ae(ze.outputs)}:ze),Zt(pe,v).catch(ze=>ge(String(ze.message||ze)))},[v,b,Zt,g,je]),BS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=String(x||"");if(!_)return;const A=BC((S==null?void 0:S.skillKeys)||[]),R=gf((S==null?void 0:S.displayType)||"markdown"),U=String((S==null?void 0:S.model)||"").trim(),X=(S==null?void 0:S.includeWorkspaceContext)===!1?"false":"true",J=S!=null&&S.workspaceContext&&typeof S.workspaceContext=="object"?JSON.stringify(S.workspaceContext):"",Y=S!=null&&S.knowledgeContext&&typeof S.knowledgeContext=="object"?JSON.stringify(S.knowledgeContext):"",ae=He=>Array.isArray(He)?He.map(Me=>(Me==null?void 0:Me.name)==="skillKeys"?{...Me,default:A,value:A}:(Me==null?void 0:Me.name)==="displayType"?{...Me,default:R,value:R}:(Me==null?void 0:Me.name)==="includeWorkspaceContext"?{...Me,default:X,value:X}:(Me==null?void 0:Me.name)==="knowledgeContext"?{...Me,default:Y,value:Y}:(Me==null?void 0:Me.name)==="workspaceContext"?{...Me,default:J,value:J}:Me):[],pe=He=>Array.isArray(He)?He.map(Me=>(Me==null?void 0:Me.name)==="displayType"?{...Me,default:R,value:R}:Me):[],fe=String((S==null?void 0:S.task)??""),Ne=b.map(He=>{var Me,Ft;return He.id===_?{...He,data:{...He.data,body:fe,model:U,inputs:ae((Me=He.data)==null?void 0:Me.inputs),outputs:pe((Ft=He.data)==null?void 0:Ft.outputs)}}:He}),We=Z.current||{},ze=We[_]&&typeof We[_]=="object"?We[_]:{},Ve={...We,[_]:{...ze,body:fe,model:U,input:ae(ze.input),output:pe(ze.output)}};Z.current=Ve,g(Ne),ne(Ve),ws(He=>(He==null?void 0:He.id)===_?{...He,body:fe,model:U,inputs:ae(He.inputs),outputs:pe(He.outputs)}:He),Zt(Ne,v).catch(He=>ge(String(He.message||He)))},[v,b,Zt,g,je]),HS=m.useCallback((x,S)=>{if(!je){ge("Readonly workspace");return}const _=jG(S),A=b.map(J=>J.id===x?{...J,data:{...J.data,body:_}}:J),R=Z.current||{},U=R[x]&&typeof R[x]=="object"?R[x]:{},X={...R,[x]:{...U,body:_}};Z.current=X,Fe.current=!0,g(A),ne(X),ws(J=>(J==null?void 0:J.id)===x?{...J,body:_}:J),Zt(A,v).catch(J=>ge(String(J.message||J)))},[v,b,Zt,g,je]),WS=m.useCallback(x=>{const S=String(x||"").trim();S&&(fS(_=>_===S?"":S),yo(_=>({..._,[S]:_[S]||{sessionId:`nodechat_${Date.now()}_${S.replace(/[^a-z0-9_-]+/gi,"_")}`,messages:[],draft:"",candidateContent:"",running:!1,error:""}})))},[]),VS=m.useCallback(()=>fS(""),[]),KS=m.useCallback((x,S)=>{const _=String(x||"").trim();_&&yo(A=>({...A,[_]:{...A[_]||{sessionId:`nodechat_${Date.now()}_${_.replace(/[^a-z0-9_-]+/gi,"_")}`,messages:[]},draft:String(S||""),error:""}}))},[]),Fs=m.useCallback((x,S,_="replace",A={})=>{var rt,Ye;if(!je){ge("Readonly workspace");return}const R=String(x||"").trim();if(!R)return;const U=N.current.find(Le=>Le.id===R),X=In(U==null?void 0:U.data),J=ei((rt=U==null?void 0:U.data)==null?void 0:rt.definitionId),Y=Ei(S),ae=X==="html"?Hc(Y):X==="react"?ag(Y):String(Y||""),pe=U?no(U.data):"",fe=_==="append"&&String(pe||"").trim()?`${String(pe).replace(/\s+$/g,"")}
261
261
 
262
- ${ae.trim()}`:ae,Ne=X==="image"?"src":"content",We=A!=null&&A.reloadDisplay?Date.now():(Ye=U==null?void 0:U.data)==null?void 0:Ye.displayReloadKey,ze=Le=>{let Mt=!1;return(Array.isArray(Le)?Le:[]).map(dt=>{const Pt=String((dt==null?void 0:dt.name)||""),_l=String((dt==null?void 0:dt.type)||"");return(J?Pt===Ne||Pt==="result"||Pt==="filePath":Pt===Ne||Pt==="filePath"||_l==="text")?Mt?{...dt,default:"",value:""}:(Mt=!0,{...dt,default:fe,value:fe}):dt})},Ve=N.current.map(Le=>{var Mt,De;return Le.id!==R?Le:{...Le,data:{...Le.data,body:J?Le.data.body:fe,...We?{displayReloadKey:We}:{},inputs:ze((Mt=Le.data)==null?void 0:Mt.inputs),outputs:ze((De=Le.data)==null?void 0:De.outputs)}}}),He=Z.current||{},Me=He[R]&&typeof He[R]=="object"?He[R]:{},Ft={...He,[R]:{...Me,body:J?Me.body:fe,input:ze(Me.input),output:ze(Me.output)}};Z.current=Ft,g(Ve),ne(Ft),ws(Le=>(Le==null?void 0:Le.id)===R?{...Le,...J?{}:{body:fe}}:Le),(A==null?void 0:A.logChat)!==!1&&yo(Le=>{var Mt;return{...Le,[R]:{...Le[R]||{},candidateContent:"",messages:[...(Mt=Le[R])!=null&&Mt.messages&&Array.isArray(Le[R].messages)?Le[R].messages:[],{role:"assistant",text:_==="append"?"已追加到当前节点内容。":"已替换当前节点内容。",at:Date.now()}]}}}),Zt(Ve,j.current).catch(Le=>ge(String(Le.message||Le))),ge(String((A==null?void 0:A.statusMessage)||"")||(_==="append"?"已追加节点内容":"已替换节点内容"))},[Zt,g,je]),$f=m.useCallback(async(x,S="")=>{if(!je)return ge("Readonly workspace"),"";if(!x)return"";try{const _=new FormData;_.set("file",x),_.set("dir",String(S||"")),a.flowId&&_.set("flowId",a.flowId),a.flowSource&&_.set("flowSource",a.flowSource),a.archived&&_.set("archived","1");const A=await fetch("/api/workspace/upload",{method:"POST",body:_}),R=await A.json().catch(()=>({}));if(!A.ok)throw new Error(R.error||"上传文件失败");const U=String(R.path||"").trim();if(!U)throw new Error("上传文件失败:未返回路径");return await An(),dl(X=>{const J=new Set(X);for(const Y of Dp(U))J.delete(Y);return J}),ge(`已上传 ${U}`),U}catch(_){return ge(String(_.message||_)),""}},[a,An,je]),Lf=m.useCallback(async x=>cm(x)?$f(x,"img"):(ge("请选择图片文件"),""),[$f]),qS=m.useCallback((x="")=>{var S;if(!je){ge("Readonly workspace");return}Kv.current=String(x||""),(S=Vv.current)==null||S.click()},[je]),z$=m.useCallback(async x=>{const S=Array.from(x.target.files||[]);if(x.target.value="",!S.length)return;const _=Kv.current||"";Wv(!0);try{let A="";for(const R of S){const U=await $f(R,_);U&&(A=U)}S.length>1&&ge(`已上传 ${S.length} 个文件${A?`,最后一个:${A}`:""}`)}catch(A){ge(String(A.message||A))}finally{Wv(!1)}},[$f]),US=m.useCallback(async(x,S)=>{const _=String(x||"").trim();if(!_)return;const A=await Lf(S);A&&Fs(_,A,"replace",{logChat:!1,statusMessage:`已上传图片 ${A}`})},[Fs,Lf]),YS=m.useCallback(async(x,S=void 0)=>{var ze,Ve;if(!je){ge("Readonly workspace");return}const _=String(x||"").trim();if(!_)return;const A=ha[_]||{},R=String(S!==void 0?S:A.draft||"").trim();if(!R||A.running)return;const U=N.current.find(He=>He.id===_);if(!U)return;const X=In(U.data)||"markdown",J=no(U.data);let Y=ea(J,X),ae=Ei(J);if(Y)try{ae=await nl(a,Y)}catch(He){ge(String(He.message||He))}else if(X!=="image"&&String(ae||"").trim()){const He=Ma(X,ae);if(He){ge(`${He} 未进入微调。`);return}try{const Me=await hb(a,FC(_,U.data),ae);await An(),Fs(_,Me,"replace",{logChat:!1,reloadDisplay:!0,statusMessage:`已将展示保存为 ${Me}`}),Y=Me,ae=""}catch(Me){ge(String(Me.message||Me));return}}const he=HG(_,N.current,j.current),fe={role:"user",text:R,at:Date.now()},Ne=Array.isArray(A.messages)?A.messages:[],We=A.sessionId||`nodechat_${Date.now()}_${_.replace(/[^a-z0-9_-]+/gi,"_")}`;yo(He=>({...He,[_]:{...A,sessionId:We,messages:[...Ne,fe],draft:"",running:!0,error:""}}));try{const He=await fetch("/api/workspace/node-chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,sessionId:We,node:{id:_,label:((ze=U.data)==null?void 0:ze.label)||_,definitionId:((Ve=U.data)==null?void 0:Ve.definitionId)||""},nodeKind:X,currentContent:Y?"":ae,sourceContext:he,targetFilePath:Y,messages:Ne,message:R,model:Li})}),Me=await He.json().catch(()=>({}));if(!He.ok)throw new Error(Me.error||"节点微调失败");const Ft=String(Me.candidateContent||Me.reply||"").trim(),rt=!!Me.directFileEdit,Ye=String(Me.artifactPath||Y||"").trim();if(rt&&Ye){const Le=Ma(X,Ft);if(Le)throw new Error(`${Le} 文件已由 agent 修改,请检查 ${Ye}。`);await An(),Fs(_,Ye,"replace",{logChat:!1,reloadDisplay:!0,statusMessage:`已按微调描述更新 ${Ye}`})}else if(Ft){const Le=Ma(X,Ft);if(Le)throw new Error(`${Le} 已取消写入,避免覆盖当前展示文件。`);if(Y){const Mt=await hb(a,Y,Ft);await An(),Fs(_,Mt,"replace",{logChat:!1,statusMessage:`已按微调描述更新 ${Mt}`})}else Fs(_,Ft,"replace",{logChat:!1,statusMessage:"已按微调描述更新展示内容"})}yo(Le=>{var Mt;return{...Le,[_]:{...Le[_]||{},sessionId:String(Me.sessionId||We),running:!1,candidateContent:"",messages:[...(Mt=Le[_])!=null&&Mt.messages&&Array.isArray(Le[_].messages)?Le[_].messages:[...Ne,fe],{role:"assistant",text:Ft||rt?Ye?`已更新文件 ${Ye}。`:"已按你的描述更新当前展示。":"没有生成可更新的内容。",at:Date.now()}]}}})}catch(He){const Me=String(He.message||He);yo(Ft=>({...Ft,[_]:{...Ft[_]||{},running:!1,error:Me}})),ge(Me)}},[Li,a,An,ha,Fs,je]),GS=m.useCallback(async(x,S)=>{if(!je){ge("Readonly workspace");return}const _=In(S)||"markdown",A=no(S),R=ea(A,_);let U=Ei(A);if(R)try{U=await nl(a,R)}catch(ae){ge(String(ae.message||ae));return}if(!String(U||"").trim()){ge("展示节点没有可保存内容");return}const X=Ma(_,U);if(X){ge(`${X} 未保存文件。`);return}const J=FC(x,S),Y=window.prompt("保存到 workspace 相对路径",J);if(Y)try{const ae=await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:Y,content:U})}),he=await ae.json().catch(()=>({}));if(!ae.ok)throw new Error(he.error||"保存文件失败");const fe=he.path||Y,Ne=Tr(a);Ne.set("path",fe);const We=await fetch(`/api/workspace/file?${Ne.toString()}`);if(!We.ok){const ze=await We.json().catch(()=>({}));throw new Error(ze.error||`保存后读取失败:${fe}`)}await An(),Tv(ze=>mJ(ze,fe,String(U||"").length)),dl(ze=>{const Ve=new Set(ze);for(const He of Dp(fe))Ve.delete(He);return Ve}),Fs(x,fe,"replace",{logChat:!1,statusMessage:`已保存并引用 ${fe}`}),ge(`已保存 ${fe}`)}catch(ae){ge(String(ae.message||ae))}},[a,An,Fs,je]),JS=m.useCallback(x=>{var R,U;const S=String(x||"").trim();if(!S||ve)return;const _=N.current.find(X=>X.id===S);if(!_||!In(_==null?void 0:_.data)){ge("展示节点不可用");return}const A=String(((R=_.data)==null?void 0:R.label)||((U=_.data)==null?void 0:U.displayName)||S).trim()||"AgentFlow Display";le(lw({title:A,layout:"single",nodeIds:[S],mode:"single-node",sourceNodeId:S})),sr(""),Gt(null),Pr(!0)},[ve]),Of=m.useCallback((x,S)=>{const _=String(x||"");_&&ws(A=>{if(!A||A.id!==_)return A;const R=typeof S=="function"?S(A):S;return!R||typeof R!="object"?A:{...A,...R}})},[]),XS=m.useCallback((x,S)=>{const _=String(x||"");!_||!je||(g(A=>A.map(R=>{var X;if(R.id!==_)return R;const U=Array.isArray((X=R.data)==null?void 0:X.outputs)&&R.data.outputs.length?R.data.outputs.map((J,Y)=>Y===0?{...J,default:S,value:S}:J):[{type:"file",name:"value",default:S,value:S}];return{...R,data:{...R.data,body:"",outputs:U}}})),Of(_,A=>({body:"",outputs:Array.isArray(A==null?void 0:A.outputs)&&A.outputs.length?A.outputs.map((U,X)=>X===0?{...U,default:S,value:S}:U):[{type:"file",name:"value",default:S,value:S}]})),ge(`已选择文件 ${S}`))},[g,Of,je]),QS=m.useCallback(x=>{Sg({nodeId:String(x||""),query:""})},[]),zg=m.useCallback(()=>{Sg({nodeId:"",query:""})},[]),B$=m.useCallback(x=>{const S=String((x==null?void 0:x.path)||"").trim();!S||!Xc.nodeId||(XS(Xc.nodeId,S),zg())},[zg,Xc.nodeId,XS]),ZS=m.useCallback(async(x,S)=>{if(!je)return;const _=sJ(x,S);if(_.length===0)return;const A=[];try{for(const R of _){const U=await fetch("/api/workspace/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:R})});if(U.status===404)continue;const X=await U.json().catch(()=>({}));if(!U.ok)throw new Error(X.error||"清理节点输出失败");A.push(X.path||R)}if(A.length===0)return;ge(`已清理 ${A.join(", ")}`),await An(),vg(R=>_.some(U=>R===U||R.startsWith(`${U}/`))?"":R)}catch(R){ge(String(R.message||R))}},[a,An,je]),fu=m.useMemo(()=>({modelLists:da,showBodyPreview:!0,flowParams:a,readOnly:!je,onRunWorkspaceNode:$S,onStopWorkspaceNode:MS,onOpenWorkspaceRunLogs:TS,onOptimizeWorkspaceRun:Fg,onOptimizeWorkspaceSchedule:Fg,runningRunNodeIds:_S,onChangeScheduledRunConfig:HS,onChangeContextRunConfig:BS,skills:Ms,skillCollections:fl,onChangeLoadSkillKeys:DS,onRefreshSkills:Rf,mcpServers:Xv,onChangeLoadMcpNames:FS,onRefreshMcps:Tf,workspaceTargets:Zv,onChangeLoadWorkspace:zS,onRefreshWorkspaces:Mf,onSaveDisplayNodeToFile:GS,onShareDisplayNode:JS,onOpenDisplayPreview:zn,onRefreshNodeInternals:Br,onEnsureWorkspaceNodeDisplaySize:iS,sharingDisplayNodeId:ve,onUploadWorkspaceImage:Lf,onUploadImageToDisplayNode:US,onOpenProvideFilePicker:QS,onStatus:ge,onSetDisplayNodeContent:Fs,onToggleNodeChat:WS,onCloseNodeChat:VS,onUpdateNodeChatDraft:KS,onSendNodeChat:YS,onSyncNodePropDraft:Of,onCleanupWorkspaceNodeOutputs:ZS}),[BS,FS,DS,zS,HS,ZS,VS,iS,a,Xv,da,QS,TS,Fg,Tf,Br,Rf,Mf,$S,_S,GS,YS,Fs,JS,ve,fl,Ms,MS,Of,WS,KS,US,Lf,Zv,je]),H$=m.useRef(new Map),rs=m.useMemo(()=>{const x=H$.current,S=new Set,_=b.map(A=>{var Y,ae,he;const R={selected:A.selected===!0,isExecuting:bS.has(A.id),nodeStatus:((Y=Dg[A.id])==null?void 0:Y.status)??null,nodeElapsed:((ae=Dg[A.id])==null?void 0:ae.elapsed)??null,optimizingRun:kS===A.id,scheduledRunState:xS[A.id]||null,nodeChatActive:dS===A.id,nodeChat:ha[A.id]||null},U=x.get(A.id);if(U&&U.source===A&&U.commonData===fu&&IC(U.runtime,R))return S.add(A.id),U.node;const X=!!(U&&((he=U.source)==null?void 0:he.data)===A.data&&U.commonData===fu&&IC(U.runtime,R)),J={...A,data:X?U.node.data:{...A.data,...fu,...R}};return x.set(A.id,{source:A,commonData:fu,runtime:R,node:J}),S.add(A.id),J});for(const A of x.keys())S.has(A)||x.delete(A);return _},[dS,fu,ha,b,kS,xS,bS,Dg]),ut=d==="display",Pn=d==="workflow",e0=m.useMemo(()=>ut?new Map(rs.map(x=>[x.id,x])):IG,[rs,ut]),t0=m.useMemo(()=>qt&&rs.find(x=>x.id===qt)||null,[qt,rs]),n0=m.useRef(new Map),pu=m.useMemo(()=>{if(!ut)return n0.current.clear(),RG;const x=new Set(M),S=n0.current,_=new Set,A=P.nodeIds.map((R,U)=>{var We,ze,Ve,He;const X=e0.get(R);if(!X||!In(X.data))return null;const J=Fl(X)||{width:520,height:320},Y=za(P.nodeSizes[R]||J,{display:!0})||J,ae=P.nodePositions[R]||{x:180+U*36,y:120+U*28},he=x.has(R),fe=S.get(R);if(fe&&fe.source===X&&((We=fe.position)==null?void 0:We.x)===ae.x&&((ze=fe.position)==null?void 0:ze.y)===ae.y&&((Ve=fe.size)==null?void 0:Ve.width)===Y.width&&((He=fe.size)==null?void 0:He.height)===Y.height&&fe.selected===he)return _.add(R),fe.node;const Ne={...X,id:RC(R),position:ae,selected:he,width:Y.width,height:Y.height,data:{...X.data,sourceNodeId:R,displayPageMode:!0,readOnly:!0,selected:he,displaySize:Y,nodeSize:Y}};return S.set(R,{source:X,position:ae,size:Y,selected:he,node:Ne}),_.add(R),Ne}).filter(Boolean);for(const R of S.keys())_.has(R)||S.delete(R);return A},[P,e0,ut,M]),kl=m.useMemo(()=>rs.filter(x=>In(x==null?void 0:x.data)),[rs]);m.useEffect(()=>{if(!ut||!P.viewport)return;const x=P.viewport,S=()=>{try{r.setViewport(x,{duration:0})}catch{}},_=window.requestAnimationFrame(()=>window.requestAnimationFrame(S));return()=>window.cancelAnimationFrame(_)},[P.viewport,ut,r]),m.useEffect(()=>{if(ut||Pn||!$)return;const x=$,S=()=>{try{r.setViewport(x,{duration:0})}catch{}},_=window.requestAnimationFrame(()=>window.requestAnimationFrame(S));return()=>window.cancelAnimationFrame(_)},[ut,Pn,r,$]),m.useEffect(()=>{Pn&&uu(ir)},[Pn]),m.useEffect(()=>{if(!Pn||!ir)return;const x=Tr(a);x.set("tapdId",ir);let S=null,_=null,A=!1;const R=()=>{_&&(window.clearTimeout(_),_=null),S&&(S.onmessage=null,S.onerror=null,S.close(),S=null)},U=()=>{A||document.hidden||S||(S=new EventSource(`/api/prd-workflow/events?${x.toString()}`),S.onmessage=()=>{uu(ir)},S.onerror=()=>{R(),!A&&!document.hidden&&(_=window.setTimeout(U,5e3))})},X=()=>{if(document.hidden){R();return}uu(ir),U()};return U(),document.addEventListener("visibilitychange",X),()=>{A=!0,document.removeEventListener("visibilitychange",X),R()}},[a,Pn,uu,ir]),m.useEffect(()=>{if(!a.flowId||Pn)return;const x=Tr(a);x.set("clientId",ke.current);let S=null,_=null,A=!1;const R=()=>{_&&(window.clearTimeout(_),_=null),S&&(S.onmessage=null,S.onerror=null,S.close(),S=null)},U=()=>{A||document.hidden||S||(S=new EventSource(`/api/workspace/events?${x.toString()}`),S.onmessage=J=>{let Y=null;try{Y=JSON.parse(J.data||"{}")}catch{Y=null}if(!(!Y||Y.clientId===ke.current)){if(Y.type==="graph.committed"){Pf(Y);return}if(Y.type==="runtime.committed"){Pf(Y);return}if(String(Y.type||"").startsWith("file.")){An();return}String(Y.type||"").startsWith("run.")&&If()}},S.onerror=()=>{R(),!A&&!document.hidden&&(_=window.setTimeout(U,5e3))})},X=()=>{if(document.hidden){R();return}Pf({type:"visibility.resume"}),U()};return U(),document.addEventListener("visibilitychange",X),()=>{A=!0,document.removeEventListener("visibilitychange",X),R(),Te.current&&(window.clearTimeout(Te.current),Te.current=null),gt.current=!1}},[a,Pn,An,If,Pf]),m.useEffect(()=>{if(lt.current)return;const x=D.current,S=new Map,_=[];for(const A of[...rs,...pu]){const R=PG(A);S.set(A.id,R),x.get(A.id)!==R&&_.push(A.id)}D.current=S,_.length!==0&&Br(_)},[pu,rs,Br]);const Vt=m.useMemo(()=>b.find(x=>x.id===Ut)||null,[b,Ut]),Bg=m.useRef({id:"",draft:null}),W$=m.useMemo(()=>{const x=KC(Vt);return x?JSON.stringify(x):""},[Vt==null?void 0:Vt.data,Vt==null?void 0:Vt.id]);m.useEffect(()=>{if(!Vt){Bg.current={id:"",draft:null},ws(null),al("");return}const x=KC(Vt),S=Bg.current;Bg.current={id:Vt.id,draft:x},ws(_=>!_||_.id!==Vt.id||S.id!==Vt.id||!S.draft?x:EJ(_,S.draft,x)),al("")},[Vt==null?void 0:Vt.id,W$]);const Hg=m.useCallback((x=!1)=>{if(!at||!Vt)return!1;if(!je)return al("Readonly workspace"),ge("Readonly workspace"),!1;al("");const S=YC({nodes:b,edges:v,instances:Z.current,selectedNode:Vt,draft:at,allowRename:x});return S!=null&&S.error?(al(S.error),!1):(!(S!=null&&S.ok)||!S.changed||(Z.current=S.instances,ne(S.instances),g(S.nodes),w(S.edges),S.nextId!==Vt.id&&jn(S.nextId),Br(S.nextId)),!0)},[v,at,b,Vt,w,g,Br,je]);m.useEffect(()=>{if(!je||!at||!Vt)return;const x=window.setTimeout(()=>{Hg(!1)},350);return()=>window.clearTimeout(x)},[at==null?void 0:at.label,at==null?void 0:at.role,at==null?void 0:at.model,at==null?void 0:at.body,JSON.stringify((at==null?void 0:at.images)||[]),at==null?void 0:at.script,at==null?void 0:at.scriptRef,at==null?void 0:at.implementationRef,at==null?void 0:at.implementationMode,JSON.stringify((at==null?void 0:at.inputs)||[]),JSON.stringify((at==null?void 0:at.outputs)||[]),Hg,Vt==null?void 0:Vt.id,je]);const r0=m.useRef({refs:new Map,nodeDataById:new Map}),Wg=m.useMemo(()=>{const x=r0.current;let S=x.refs.size!==b.length;const _=new Map;for(const R of b)_.set(R.id,R.data),(!x.refs.has(R.id)||x.refs.get(R.id)!==R.data)&&(S=!0);if(!S)return x.nodeDataById;const A=new Map(b.map(R=>[R.id,R.data]));return r0.current={refs:_,nodeDataById:A},A},[b]),V$=m.useMemo(()=>v.map(x=>{var Y,ae;const S=Wg.get(x.source),_=Wg.get(x.target),A=/^output-(\d+)$/.exec(x.sourceHandle||""),R=/^input-(\d+)$/.exec(x.targetHandle||""),U=S&&A?(Y=S.outputs)==null?void 0:Y[parseInt(A[1],10)]:null,X=_&&R?(ae=_.inputs)==null?void 0:ae[parseInt(R[1],10)]:null,J=U!=null&&U.type?Tn(U.type):X!=null&&X.type?Tn(X.type):"";return J?{...x,style:{...x.style||{},stroke:J,strokeWidth:2},markerEnd:{type:bi.ArrowClosed,color:J}}:x}),[Wg,v]),Df=ut?pu:rs,K$=ut?[]:V$,s0=m.useRef(Df),vl=m.useRef([]);lt.current||(s0.current=Df);const q$=m.useMemo(()=>ut?pu.map(x=>({...x,id:Op(x.id)})):rs,[pu,rs,ut]),Vg=m.useCallback(x=>{const S=String(x||"").trim();if(!S)return;const _=ut?RC(S):S;ut?K([S]):(g(R=>R.map(U=>({...U,selected:U.id===_}))),w(R=>R.map(U=>({...U,selected:!1}))),jn(_));const A=()=>{var ae,he,fe;const R=r.getNode(_);if(!R)return;const U=(ae=r.getInternalNode)==null?void 0:ae.call(r,_),X=((he=U==null?void 0:U.measured)==null?void 0:he.width)??(U==null?void 0:U.width)??R.width??260,J=((fe=U==null?void 0:U.measured)==null?void 0:fe.height)??(U==null?void 0:U.height)??R.height??120,{zoom:Y}=r.getViewport();r.setCenter(R.position.x+X/2,R.position.y+J/2,{zoom:DG(Y),duration:240})};window.requestAnimationFrame(()=>window.requestAnimationFrame(A))},[ut,r,w,g]);m.useEffect(()=>{const x=String(c.current||"").trim();!x||!ce.current||d!=="workspace"||rs.some(S=>S.id===x)&&(c.current="",Fe.current=!0,Vg(x))},[rs,Vg,d]);const i0=m.useCallback(()=>{const x=r.getViewport(),S={x:Number(x.x)||0,y:Number(x.y)||0,zoom:Math.min(Math.max(Number(x.zoom)||1,.1),4)};if(ut){const _={...z.current,viewport:S};z.current=_,I(_),ge("已固定 Display 进入视角")}else{F.current=S,L(S);try{window.localStorage.setItem(u,JSON.stringify(S))}catch{}ge("已固定 Workspace 进入视角");return}Zt(N.current,j.current).catch(_=>ge(String(_.message||_)))},[ut,r,Zt,u]),Kg=m.useMemo(()=>{const x=jt.trim().toLowerCase(),S={DISPLAY:[],CONTROL:[],TOOL:[],PROVIDE:[],AGENT:[]};for(const _ of be)x&&![_.id,_.label,_.displayName,_.description].some(A=>String(A||"").toLowerCase().includes(x))||S[Wu(_)].push(_);for(const _ of Ol)S[_].sort((A,R)=>A.id.localeCompare(R.id));return S},[be,jt]),hu=m.useMemo(()=>{const x=Ee.trim().toLowerCase();return be.filter(S=>!x||[S.id,S.label,S.displayName,S.description].some(_=>String(_||"").toLowerCase().includes(x))).sort((S,_)=>{const A=Ol.indexOf(Wu(S)),R=Ol.indexOf(Wu(_));return A!==R?A-R:Vu(S).localeCompare(Vu(_))}).slice(0,30)},[be,Ee]),mu=m.useMemo(()=>{const x=Ee.trim().toLowerCase();return Re.filter(S=>!x||[S.id,S.version,S.displayName,S.name,S.description,...Array.isArray(S.tags)?S.tags:[]].some(_=>String(_||"").toLowerCase().includes(x))).sort((S,_)=>String(S.displayName||S.name||S.id).localeCompare(String(_.displayName||_.name||_.id))).slice(0,30)},[Re,Ee]);m.useEffect(()=>{kt(0)},[Ee,On,pe]),m.useEffect(()=>{if(!On)return;const x=window.setTimeout(()=>{var S;return(S=lS.current)==null?void 0:S.focus()},0);return()=>window.clearTimeout(x)},[On]);const U$=m.useMemo(()=>{const x=bg.trim().toLowerCase();return x?yv(ll).filter(S=>S.path.toLowerCase().includes(x)):ll},[bg,ll]),ya=m.useMemo(()=>nM(ll,kg),[ll,kg]),Fi=(ya==null?void 0:ya.type)==="directory"?ya.path:dJ((ya==null?void 0:ya.path)||""),Y$=m.useCallback(x=>{var S,_;(_=(S=x.target)==null?void 0:S.closest)!=null&&_.call(S,".af-work-file")||vg("")},[]),G$=[...(da.cursor||[]).map(x=>({label:`Cursor · ${x.split(" - ")[0]}`,value:`cursor:${x.split(" - ")[0]}`})),...(da.opencode||[]).map(x=>({label:`OpenCode · ${x.split(" - ")[0]}`,value:`opencode:${x.split(" - ")[0]}`})),...(da.claudeCode||[]).map(x=>({label:`Claude · ${x.split(" - ")[0]}`,value:`claude-code:${x.split(" - ")[0]}`})),...(da.codex||[]).map(x=>({label:`Codex · ${x.split(" - ")[0]}`,value:`codex:${x.split(" - ")[0]}`}))],qg=m.useMemo(()=>new Set($s),[$s]),Sl=m.useMemo(()=>{const x=new Map(Ms.map(U=>[U.key,U])),S=new Set,_=new Set,A=fl.map(U=>{const X=Qo(U,Ms).map(J=>x.get(J)).filter(Boolean);for(const J of X)S.add(J.key),_.add(String(J.name||J.id||J.key||"").trim());return{...U,skills:X}}).filter(U=>U.skills.length>0),R=Ms.filter(U=>{const X=String(U.name||U.id||U.key||"").trim();return!S.has(U.key)&&!_.has(X)});return{groups:A,ungrouped:R}},[fl,Ms]);m.useEffect(()=>{oS(x=>{let S=!1;const _=new Set(x);for(const A of Sl.groups)_.has(A.id)||(_.add(A.id),S=!0);return S?_:x})},[Sl.groups]);const er=m.useMemo(()=>{const x=b.filter(S=>S.selected);return x.length>0?x:Ut?b.filter(S=>S.id===Ut):[]},[b,Ut]),Ff=m.useMemo(()=>er.map(x=>x.id),[er]),o0=m.useCallback(()=>{if(ut)return;if(!je){ge("Readonly workspace");return}const x=(N.current||[]).filter(J=>(J==null?void 0:J.selected)&&!pm(J));if(x.length<2){ge("选择至少两个节点后按 G 创建 Group");return}const S=x.reduce((J,Y)=>{var We,ze,Ve,He,Me,Ft,rt,Ye,Le,Mt,De,dt;const ae=Number(((We=Y.position)==null?void 0:We.x)||0),he=Number(((ze=Y.position)==null?void 0:ze.y)||0),fe=Number(((Ve=Y.measured)==null?void 0:Ve.width)||Y.width||((Me=(He=Y.data)==null?void 0:He.nodeSize)==null?void 0:Me.width)||((rt=(Ft=Y.data)==null?void 0:Ft.displaySize)==null?void 0:rt.width)||PT),Ne=Number(((Ye=Y.measured)==null?void 0:Ye.height)||Y.height||((Mt=(Le=Y.data)==null?void 0:Le.nodeSize)==null?void 0:Mt.height)||((dt=(De=Y.data)==null?void 0:De.displaySize)==null?void 0:dt.height)||lm);return{minX:Math.min(J.minX,ae),minY:Math.min(J.minY,he),maxX:Math.max(J.maxX,ae+fe),maxY:Math.max(J.maxY,he+Ne)}},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});if(!Number.isFinite(S.minX)||!Number.isFinite(S.minY))return;const _=new Set((N.current||[]).map(J=>J.id));let A=1,R=`group_${A}`;for(;_.has(R);)A+=1,R=`group_${A}`;const U=db({width:S.maxX-S.minX+Mp*2,height:S.maxY-S.minY+Mp*2})||{width:Qa,height:Za},X={id:R,type:pc,position:{x:S.minX-Mp,y:S.minY-Mp},width:U.width,height:U.height,selected:!0,draggable:!0,selectable:!0,zIndex:0,data:{isWorkspaceGroup:!0,label:hm(A-1),title:hm(A-1),color:"purple",nodeSize:U}};g(J=>[X,...J.map(Y=>({...Y,selected:!1}))]),w(J=>J.map(Y=>({...Y,selected:!1}))),jn(""),ge(`Created group for ${x.length} nodes`)},[ut,w,g,je]),gu=m.useMemo(()=>b.filter(x=>In(x==null?void 0:x.data)),[b]),Ug=m.useMemo(()=>er.filter(x=>In(x==null?void 0:x.data)).map(x=>x.id),[er]),J$=m.useMemo(()=>{const x=String((Ir==null?void 0:Ir.username)||(Ir==null?void 0:Ir.userId)||"").trim();return x?x.slice(0,1).toUpperCase():"?"},[Ir]),Yg=m.useMemo(()=>new Set(Ff),[Ff]),zf=m.useMemo(()=>v.filter(x=>Yg.has(x.source)&&Yg.has(x.target)),[v,Yg]),Gg=m.useCallback(x=>{const S=x==="display"?"display":x==="workflow"?"workflow":"workspace";f(S),jn(""),K([]),ee(null),q(!1),Pe(!1);const _=Tr(a);S==="display"&&_.set("view","display"),S==="workflow"&&(_.set("view","workflow"),ir.trim()&&_.set("tapdId",ir.trim()));const A=`/workspace${_.toString()?`?${_.toString()}`:""}`;window.history.pushState({},"",A)},[a,ir]),a0=m.useCallback(x=>{const S=String(x||"").trim();if(!S)return;const _=N.current.find(A=>A.id===S);if(!_||!In(_.data)){ge("展示节点不可用");return}I(A=>{if(A.nodeIds.includes(S))return A;const R=A.nodeIds.length,U=Fl(_);return{nodeIds:[...A.nodeIds,S],nodePositions:{...A.nodePositions,[S]:{x:180+R*36,y:120+R*28}},nodeSizes:{...A.nodeSizes,...U?{[S]:U}:{}}}}),K([S])},[]),l0=m.useCallback(x=>{const S=String(x||"").trim();S&&(I(_=>{const A=_.nodeIds.filter(X=>X!==S),R={..._.nodePositions},U={..._.nodeSizes};return delete R[S],delete U[S],{nodeIds:A,nodePositions:R,nodeSizes:U}}),K(_=>_.filter(A=>A!==S)))},[]),c0=m.useCallback(x=>{const S=String(x||"").trim();S&&(z.current.nodeIds.includes(S)?l0(S):a0(S))},[a0,l0]),Bf=m.useMemo(()=>{const x=xt.trim().toLowerCase();return x?kl.filter(S=>{var _,A;return[S.id,(_=S.data)==null?void 0:_.label,(A=S.data)==null?void 0:A.definitionId].filter(Boolean).some(R=>String(R).toLowerCase().includes(x))}):kl},[kl,xt]),u0=m.useMemo(()=>{const x=Bf.length,S=x<=1?1:x<=4?2:3,_=Array.from({length:S},()=>({height:0,nodes:[]}));for(const A of Bf){const R=Fl(A)||{width:420,height:260},U=Math.max(1,Number(R.width)||420),X=Math.max(1,Number(R.height)||260),J=Math.min(26,Math.max(5.5,X/U*16))+3.2;let Y=_[0];for(const ae of _)ae.height<Y.height&&(Y=ae);Y.nodes.push(A),Y.height+=J}return _.map(A=>A.nodes)},[Bf]),X$=m.useCallback(x=>{var U;const S=P.nodeIds.includes(x.id),_=Fl(x)||{width:420,height:260},A=Math.max(1,Math.round(Number(_.width)||420)),R=Math.max(1,Math.round(Number(_.height)||260));return i.jsxs("button",{type:"button",className:"af-display-picker-card"+(S?" af-display-picker-card--selected":""),style:{"--af-display-picker-card-ratio":`${A} / ${R}`},onClick:()=>c0(x.id),children:[i.jsx("span",{className:"af-display-picker-card__check","aria-hidden":!0,children:i.jsx("input",{type:"checkbox",checked:S,readOnly:!0,tabIndex:-1})}),i.jsx("span",{className:"af-display-picker-card__preview",children:i.jsx(ZG,{node:x})}),i.jsxs("span",{className:"af-display-picker-card__meta",children:[i.jsx("strong",{children:((U=x.data)==null?void 0:U.label)||x.id}),i.jsxs("small",{children:[In(x.data)," · ",x.id]})]})]},x.id)},[P.nodeIds,c0]),d0=m.useMemo(()=>{const x=jt.trim().toLowerCase();return x?Re.filter(S=>[S.id,S.version,S.displayName,S.name,S.description,...Array.isArray(S.tags)?S.tags:[]].filter(Boolean).some(_=>String(_).toLowerCase().includes(x))):Re},[Re,jt]),f0=m.useCallback((x,S)=>{const _=String(x||"snippet_node").trim().replace(/[^a-zA-Z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"snippet_node";let A=`${_}_${Date.now().toString(36)}`,R=2;for(;S.has(A);)A=`${_}_${Date.now().toString(36)}_${R}`,R+=1;return S.add(A),A},[]),yu=m.useCallback((x,S)=>{var Le,Mt;if(!je){ge("Readonly workspace");return}const _=x!=null&&x.snippet&&typeof x.snippet=="object"?x.snippet:{},A=_.instances&&typeof _.instances=="object"?_.instances:{},R=Object.keys(A);if(R.length===0)return;const U=new Set(N.current.map(De=>De.id)),X={};for(const De of R)X[De]=f0(De,U);const J=(Le=_.ui)!=null&&Le.nodePositions&&typeof _.ui.nodePositions=="object"?_.ui.nodePositions:{},Y=(Mt=_.ui)!=null&&Mt.nodeSizes&&typeof _.ui.nodeSizes=="object"?_.ui.nodeSizes:{},ae=R.map(De=>{const dt=J[De];return{id:De,x:typeof(dt==null?void 0:dt.x)=="number"?dt.x:0,y:typeof(dt==null?void 0:dt.y)=="number"?dt.y:0}}),he=Math.min(...ae.map(De=>De.x)),fe=Math.min(...ae.map(De=>De.y));let Ne=S||{x:360+N.current.length*24,y:180+N.current.length*18};if(!S){const De=document.querySelector(".af-workspace-canvas .react-flow");if(De){const dt=De.getBoundingClientRect();Ne=r.screenToFlowPosition({x:dt.left+dt.width*.48,y:dt.top+dt.height*.32})}}const We={},ze={},Ve={};for(const De of ae){const dt=X[De.id];We[dt]={...A[De.id]||{}},ze[dt]={x:Ne.x+(De.x-he),y:Ne.y+(De.y-fe)};const Pt=Y[De.id];typeof(Pt==null?void 0:Pt.width)=="number"&&typeof(Pt==null?void 0:Pt.height)=="number"&&(Ve[dt]={width:Pt.width,height:Pt.height})}const He=new Set(R),Me=(Array.isArray(_.edges)?_.edges:[]).filter(De=>He.has(De==null?void 0:De.source)&&He.has(De==null?void 0:De.target)).map(De=>({source:X[De.source],target:X[De.target],sourceHandle:De.sourceHandle??null,targetHandle:De.targetHandle??null})),Ft=Iu({instances:We,edges:Me,ui:{nodePositions:ze,nodeSizes:Ve}},be),rt=Ft.nodes.map(De=>De.id),Ye=Ft.nodes.map(De=>({...De,selected:!0}));Z.current={...Z.current,...Ft.instances},ne(Z.current),g(De=>[...De.map(dt=>({...dt,selected:!1})),...Ye]),w(De=>[...De.map(dt=>({...dt,selected:!1})),...Ft.edges.map(dt=>({...dt,selected:!1}))]),jn(""),K([]),ge(`已添加流程片段:${x.displayName||x.id}(已选中 ${rt.length} 个节点)`)},[f0,be,r,w,g,je]),Q$=m.useCallback(()=>{var _,A;if(er.length<2){Vn("请先在 workspace 画布上选择至少两个节点。"),re("flows");return}const x=er[0],S=er.length===2?`${((_=x.data)==null?void 0:_.label)||x.id} 片段`:`${((A=x.data)==null?void 0:A.label)||x.id} 等 ${er.length} 个节点`;Xn({name:S,id:S.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,""),description:""}),Ar(""),xr(!0),re("flows")},[er]),Z$=m.useCallback(async()=>{var R,U;if(er.length<2)return;const x=wn.name.trim();if(!x){Ar("请填写片段名称。");return}const S={},_={};for(const X of er){S[X.id]={x:((R=X.position)==null?void 0:R.x)||0,y:((U=X.position)==null?void 0:U.y)||0};const J=Fl(X);J&&(_[X.id]=J)}const A=zf.map(X=>({source:X.source,target:X.target,sourceHandle:X.sourceHandle??null,targetHandle:X.targetHandle??null}));hr(!0),Ar("");try{const X=await fetch("/api/marketplace/publish-flow-snippet",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:wn.id,name:x,displayName:x,version:"1.0.0",description:wn.description,snippet:{instances:av(er,Z.current),edges:A,ui:{nodePositions:S,nodeSizes:_}}})}),J=await X.json().catch(()=>({}));if(!X.ok||J.ok===!1)throw new Error(J.error||"发布流程片段失败");xr(!1),ge(`流程片段已发布:${J.id||x}`),sS(`流程片段已发布:${J.id||x}`),await Af(),re("flows")}catch(X){Ar(String(X.message||X))}finally{hr(!1)}},[Af,wn,zf,er,sS]),p0=m.useCallback(async()=>{var S;const x=Gc.trim();if(x){$v(!0),Yc("");try{const _=await fetch("/api/workspace/collaboration/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,username:x,role:"editor"})}),A=await _.json().catch(()=>({}));if(!_.ok)throw new Error(A.error||"添加协作成员失败");gg(A.workspace||null),Ov(""),ge(`已将 Workspace 分享给 ${((S=A.member)==null?void 0:S.username)||x}`)}catch(_){Yc(String(_.message||_))}finally{$v(!1)}}},[a,Gc]),eL=m.useCallback(()=>{Yc(""),yg(!0)},[]),tL=m.useCallback(async x=>{const S=String((x==null?void 0:x.userId)||"").trim();if(!(!S||S===(an==null?void 0:an.ownerId))){Fv(S),Yc("");try{const _=await fetch("/api/workspace/collaboration/share",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,memberUserId:S})}),A=await _.json().catch(()=>({}));if(!_.ok)throw new Error(A.error||"取消成员分享失败");gg(A.workspace||null),ge(`已取消对 ${(x==null?void 0:x.username)||S} 的分享`)}catch(_){Yc(String(_.message||_))}finally{Fv("")}}},[a,an==null?void 0:an.ownerId]),h0=m.useCallback(async()=>{const x=Ml(N.current,j.current,Z.current);x.ui={...x.ui||{},...F.current?{viewport:F.current}:{},displayPage:TC(z.current,N.current)};const S=new Blob([`${JSON.stringify(x,null,2)}
263
- `],{type:"application/json"}),_=URL.createObjectURL(S),A=document.createElement("a");A.href=_,A.download=`${a.flowId||"workspace"}-conflict-draft-${Date.now()}.json`,document.body.appendChild(A),A.click(),A.remove(),URL.revokeObjectURL(_),await ks(),cl(null),ua(!1),ge("已备份本地草稿并载入远端最新版本")},[j,a.flowId,ks,N]),nL=m.useCallback(async()=>{const x=Array.isArray(En==null?void 0:En.conflictItems)?En.conflictItems:[];if(!x.length||!(En!=null&&En.mergeGraph)||!(En!=null&&En.currentGraph)){Jc("当前冲突缺少字段合并数据,请改用“备份并载入远端”。");return}let S=En.mergeGraph;try{x.forEach((A,R)=>{const U=xg[String(R)]||{mode:"local"};let X,J=!0;U.mode==="remote"?(X=A.current,J=A.hasCurrent!==!1):U.mode==="manual"?X=JSON.parse(String(U.manual||"")):(X=A.incoming,J=A.hasIncoming!==!1),S=LJ(S,A.pathParts,X,J)})}catch(A){Jc(`手动值不是有效 JSON:${String(A.message||A)}`);return}zv(!0),Jc(""),Os("saving"),Ds("正在提交冲突解决结果");const _=Ce.current.catch(()=>{}).then(async()=>{const A=await fetch("/api/workspace/graph",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,graph:S,baseRevision:En.currentRevision,baseGraph:En.currentGraph,clientId:ke.current})}),R=await A.json().catch(()=>({}));if(!A.ok){if(A.status===409&&Array.isArray(R.conflictItems)){const U=R.conflictItems;cl({currentRevision:String(R.currentRevision||""),message:R.error||"Workspace 再次出现冲突",conflictPaths:Array.isArray(R.conflictPaths)?R.conflictPaths:[],conflictItems:U,mergeGraph:R.mergeGraph||null,currentGraph:R.currentGraph||null}),ul(Object.fromEntries(U.map((X,J)=>[String(J),{mode:"local",manual:Ru(X)}])))}throw new Error(R.error||"提交冲突解决结果失败")}await ks(),cl(null),ua(!1),ge("冲突已解决并保存")});Ce.current=_;try{await _}catch(A){Jc(String(A.message||A)),Os("error"),Ds(String(A.message||A))}finally{zv(!1)}},[a,ks,En,xg]);m.useCallback(()=>{if(gu.length===0){ge("当前 workspace 没有 display 节点");return}const x=Ug.length>0?Ug:gu.map(_=>_.id),S=a.flowId?`${a.flowId} 展示页`:"AgentFlow Display";le(lw({title:S,layout:"gallery",nodeIds:x,mode:"multi-node"})),sr(""),Gt(null),Pr(!0)},[a.flowId,Ug,gu]);const rL=m.useCallback(x=>{le(S=>{const _=Array.isArray(S.nodeIds)?S.nodeIds:[];return _.includes(x)?{...S,nodeIds:_.filter(A=>A!==x)}:{...S,nodeIds:[..._,x]}})},[]),zs=m.useCallback(async()=>{Ln(!0),zr("");try{const x=await fetch("/api/display/shares"),S=await x.json().catch(()=>({}));if(!x.ok)throw new Error(S.error||"读取分享列表失败");kr(Array.isArray(S.shares)?S.shares:[])}catch(x){zr(String(x.message||x)),kr([])}finally{Ln(!1)}},[]),sL=m.useCallback(()=>{nn(!0),ie(""),zs()},[zs]),iL=m.useCallback(async()=>{var _,A;const x=_t.title.trim(),S=Array.isArray(_t.nodeIds)?_t.nodeIds:[];if(S.length===0){sr("请选择至少一个 display 节点。");return}Qn(!0),sr(""),Gt(null);try{await Zt(b,v);const R=await fetch("/api/display/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,title:x,layout:_t.layout,nodeIds:S,...$C(_t)})}),U=await R.json().catch(()=>({}));if(!R.ok||U.ok===!1)throw new Error(U.error||"发布展示页失败");const X=new URL(U.url||`/display/${((_=U.share)==null?void 0:_.id)||""}`,window.location.origin).href;Gt({...U,absoluteUrl:X}),ge((A=U.share)!=null&&A.expiresAt?"展示页已生成":"展示页已生成:永久有效"),mt&&zs()}catch(R){sr(String(R.message||R))}finally{Qn(!1)}},[_t,mt,v,a,zs,b,Zt]),oL=m.useCallback(async()=>{var S,_;const x=Array.isArray(P.nodeIds)?P.nodeIds:[];if(x.length===0){sr("请先添加至少一个展示节点。"),ge("请先添加至少一个展示节点"),Pe(!0);return}Qn(!0),sr("");try{await Zt(b,v);const A=a.flowId?`${a.flowId} 展示页`:"AgentFlow Display",R=await fetch("/api/display/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,title:A,layout:"canvas",nodeIds:x,...$C(_t)})}),U=await R.json().catch(()=>({}));if(!R.ok||U.ok===!1)throw new Error(U.error||"生成展示链接失败");const X=new URL(U.url||`/display/${((S=U.share)==null?void 0:S.id)||""}`,window.location.origin).href;Gt({...U,absoluteUrl:X}),Jt(!0),ge((_=U.share)!=null&&_.expiresAt?"展示链接已生成":"展示链接已生成:永久有效"),mt&&zs()}catch(A){const R=String(A.message||A);sr(R),ge(R)}finally{Qn(!1)}},[P.nodeIds,_t,mt,v,a,zs,b,Zt]),m0=m.useCallback(async()=>{const x=Ct==null?void 0:Ct.absoluteUrl;if(!x)return;const S=await pb(x);Zn(S?"copied":"failed"),window.setTimeout(()=>Zn(""),1600)},[Ct==null?void 0:Ct.absoluteUrl]),aL=m.useCallback(async x=>{const S=LC(x),_=await pb(S);ie(_?String((x==null?void 0:x.id)||""):"failed"),window.setTimeout(()=>ie(""),1600)},[]),lL=m.useCallback(async(x,S)=>{const _=String((x==null?void 0:x.id)||"");if(_){ai(_),zr("");try{const A=S==="permanent"?{id:_,expiresMode:"permanent",permanent:!0}:{id:_,expiresMode:"days",expiresInDays:Number(S||30)},R=await fetch("/api/display/share",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(A)}),U=await R.json().catch(()=>({}));if(!R.ok||U.ok===!1)throw new Error(U.error||"更新分享有效期失败");await zs(),ge("分享有效期已更新")}catch(A){zr(String(A.message||A))}finally{ai("")}}},[zs]),cL=m.useCallback(async x=>{const S=String((x==null?void 0:x.id)||"");if(S){ai(S),zr("");try{const _=await fetch(`/api/display/share?id=${encodeURIComponent(S)}`,{method:"DELETE"}),A=await _.json().catch(()=>({}));if(!_.ok||A.ok===!1)throw new Error(A.error||"撤销分享失败");await zs(),ge("分享已撤销")}catch(_){zr(String(_.message||_))}finally{ai("")}}},[zs]),uL=m.useCallback(x=>{g(S=>S.map(_=>_.id===x?{..._,selected:!1}:_)),jn(S=>S===x?"":S)},[g]),Nl=m.useCallback(()=>{const x=Ig.current;if(!x)return;const S=x.getBoundingClientRect(),_=Math.min(420,Math.max(320,S.width+160)),A=12,R=Math.max(180,S.top-A*2),U=Math.min(560,R);_$({position:"fixed",left:Math.max(12,Math.min(window.innerWidth-_-12,S.left)),top:Math.max(A,S.top-U-A),width:_,maxHeight:U,zIndex:1e4})},[]);m.useEffect(()=>{if(!Cf)return;Nl();const x=_=>{var R,U;const A=_.target;(R=Ig.current)!=null&&R.contains(A)||(U=aS.current)!=null&&U.contains(A)||Pg(!1)},S=_=>{_.key==="Escape"&&Pg(!1)};return window.addEventListener("pointerdown",x),window.addEventListener("keydown",S),window.addEventListener("resize",Nl),window.addEventListener("scroll",Nl,!0),()=>{window.removeEventListener("pointerdown",x),window.removeEventListener("keydown",S),window.removeEventListener("resize",Nl),window.removeEventListener("scroll",Nl,!0)}},[Cf,Nl]);const Hf=m.useCallback(x=>{const S=AT(x);if(S.active&&(lt.current=!0),S.finished&&(lt.current=!1,oe.current=!0),lY(x)&&li(),d==="display"){I(R=>{var Y,ae;let U=R.nodePositions,X=R.nodeSizes;for(const he of x||[]){const fe=Op(he==null?void 0:he.id);if(!(!fe||!R.nodeIds.includes(fe))&&he.type!=="select"){if(he.type==="position"&&he.position){const Ne=U[fe];if((Ne==null?void 0:Ne.x)===he.position.x&&(Ne==null?void 0:Ne.y)===he.position.y)continue;U===R.nodePositions&&(U={...R.nodePositions}),U[fe]={x:he.position.x,y:he.position.y};continue}if(he.type==="dimensions"&&((Y=he.dimensions)!=null&&Y.width)&&((ae=he.dimensions)!=null&&ae.height)){const Ne=za({width:Math.round(Number(he.dimensions.width)),height:Math.round(Number(he.dimensions.height))},{display:!0});if(Ne){const We=X[fe];if((We==null?void 0:We.width)===Ne.width&&(We==null?void 0:We.height)===Ne.height)continue;X===R.nodeSizes&&(X={...R.nodeSizes}),X[fe]=Ne}}}}if(U===R.nodePositions&&X===R.nodeSizes)return R;const J={...R,nodePositions:U,nodeSizes:X};return z.current=J,J});const A=(x||[]).filter(R=>(R==null?void 0:R.type)==="select");A.length>0&&K(R=>{const U=new Set(R);for(const J of A){const Y=Op(J==null?void 0:J.id);Y&&(J.selected?U.add(Y):U.delete(Y))}const X=Array.from(U);return X.length===R.length&&X.every((J,Y)=>J===R[Y])?R:X});return}if(!je){const A=(x||[]).filter(R=>(R==null?void 0:R.type)==="select");A.length>0&&g(R=>ad(A,R));return}const _=(x||[]).filter(A=>{var R,U;return(A==null?void 0:A.type)==="dimensions"&&((R=A.dimensions)==null?void 0:R.width)&&((U=A.dimensions)==null?void 0:U.height)});g(A=>{const R=new Map;if(_.length>0){const J=new Map(A.map(Y=>[Y.id,Y]));for(const Y of _){const ae=J.get(Y.id),he={width:Math.round(Number(Y.dimensions.width)),height:Math.round(Number(Y.dimensions.height))},fe=pm(ae)?db(he):za(he,{display:!!In(ae==null?void 0:ae.data)});fe&&R.set(Y.id,fe)}}const U=ad(x,A),X=R.size===0?U:U.map(J=>{const Y=R.get(J.id);if(!Y)return J;const ae={...J.data,nodeSize:Y};return In(J.data)&&(ae.displaySize=Y),{...J,width:Y.width,height:Y.height,data:ae}});return N.current=X,X}),_.length>0&&Br(_.map(A=>A.id))},[li,Br,g,d,je]),Wf=m.useCallback((x=[],{finish:S=!1}={})=>{const _=S?fY([...V.current,...x]):ib(x);S&&(V.current=[]),_.length>0&&Hf(_)},[Hf]),dL=m.useCallback(x=>{const{transient:S,committed:_,finishesInteraction:A}=dY(x);if(S.length>0){lt.current||(lt.current=!0,vl.current=s0.current),V.current=ib([...V.current,...S]);const R=ad(S,vl.current);vl.current=R,s.getState().setNodes(R)}if(A){vl.current=[],Wf(_,{finish:!0});return}_.length>0&&Hf(_)},[Hf,Wf,s]);m.useEffect(()=>{const x=()=>{!lt.current&&V.current.length===0||(Wf([],{finish:!0}),vl.current=[])},S=()=>{document.visibilityState==="hidden"&&x()};return window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x),window.addEventListener("blur",x),document.addEventListener("visibilitychange",S),()=>{window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x),window.removeEventListener("blur",x),document.removeEventListener("visibilitychange",S),V.current=[],vl.current=[]}},[Wf]);const fL=m.useCallback(x=>{if(d!=="display"){if(!je){const S=(x||[]).filter(_=>(_==null?void 0:_.type)==="select");S.length>0&&w(_=>{const A=Qh(S,_);return j.current=A,A});return}(x||[]).some(S=>(S==null?void 0:S.type)!=="select")&&li(),w(S=>{const _=Qh(x,S);return j.current=_,_})}},[li,w,d,je]),jl=m.useCallback(()=>{const x=document.querySelector(".af-workspace-canvas .react-flow");if(x){const S=x.getBoundingClientRect();return r.screenToFlowPosition({x:S.left+S.width*.48,y:S.top+S.height*.32})}return{x:360+b.length*36,y:180+b.length*28}},[b.length,r]),Vf=m.useCallback(()=>{var x,S,_;if(Vt){const A=Number(((x=Vt.measured)==null?void 0:x.width)||Vt.width||260);return{x:Number(((S=Vt.position)==null?void 0:S.x)||0)+A+140,y:Number(((_=Vt.position)==null?void 0:_.y)||0)}}return jl()},[jl,Vt]),zi=m.useCallback((x,S={})=>{if(!je)return ge("Readonly workspace"),null;if(!x)return null;const _=hv(x)||x.id,A=BT(x),R=WT(x),U=S.id||kG(_,b),X=qu(x.inputs),J=qu(x.outputs),Y={definitionId:_,...A?{marketplaceRef:A}:{},...x.packageId?{marketplacePackageId:x.packageId}:{},...x.version?{marketplaceVersion:x.version}:{},label:S.label||fm(x),role:"normal",body:S.body||"",...S.script||R?{script:S.script||R}:{},...S.scriptRef?{scriptRef:S.scriptRef}:{},...S.implementationRef?{implementationRef:S.implementationRef}:{},...S.implementationMode?{implementationMode:S.implementationMode}:{},input:S.inputs||X,output:S.outputs||J},ae={id:U,type:pc,position:S.position||jl(),data:{label:Y.label,definitionId:_,...A?{marketplaceRef:A}:{},...x.packageId?{marketplacePackageId:x.packageId}:{},...x.version?{marketplaceVersion:x.version}:{},schemaType:zT(_,x),role:"normal",body:Y.body,...Y.script?{script:Y.script}:{},...Y.scriptRef?{scriptRef:Y.scriptRef}:{},...Y.implementationRef?{implementationRef:Y.implementationRef}:{},...Y.implementationMode?{implementationMode:Y.implementationMode}:{},inputs:Y.input,outputs:Y.output}},he={...rb(ae,{...Z.current,[U]:Y},be),selected:!0};return li(),g(fe=>[...fe.map(Ne=>({...Ne,selected:!1})),he]),S.openProperties&&jn(U),U},[jl,li,b,be,g,je]),pL=m.useCallback(x=>ow(x,N.current),[]),hL=m.useCallback(x=>{if(!je){ge("Readonly workspace");return}if(!ow(x,N.current)){ge("端口类型不匹配,已取消连线");return}ee(null),li(),g(S=>ew(S,x)),w(S=>{const _=S.filter(R=>!(R.target===x.target&&R.targetHandle===x.targetHandle)),A=uh({...x,markerEnd:{type:bi.ArrowClosed}},_);return j.current=A,A})},[li,w,g,je]),mL=m.useCallback((x,S)=>{if(!je)return;const _=wG(S,N.current);se.current=_?{..._,preferExisting:!!(x!=null&&x.shiftKey)}:null,ee(null)},[je]),gL=m.useCallback((x,S)=>{var He,Me,Ft,rt;if(!je)return;const _=se.current;if(se.current=null,!_||S!=null&&S.toNode)return;const A=xG(be,_),R=bG(N.current,j.current,_);if(A.length===0&&R.length===0){ge(`没有匹配 ${_.slotType} 端口的节点`);return}const X=!!(x!=null&&x.shiftKey||_.preferExisting)?R.length>0?"existing":"create":A.length>0?"create":"existing",J=((Me=(He=x==null?void 0:x.changedTouches)==null?void 0:He[0])==null?void 0:Me.clientX)??(x==null?void 0:x.clientX),Y=((rt=(Ft=x==null?void 0:x.changedTouches)==null?void 0:Ft[0])==null?void 0:rt.clientY)??(x==null?void 0:x.clientY);if(!Number.isFinite(J)||!Number.isFinite(Y))return;const ae=document.querySelector(".af-workspace-canvas .react-flow");if(!ae)return;const he=ae.getBoundingClientRect(),fe=320,Ne=Math.max(A.length,R.length),We=Math.min(480,150+Ne*58),ze=Math.max(12,Math.min(J-he.left,he.width-fe-12)),Ve=Math.max(12,Math.min(Y-he.top,he.height-We-12));ee({left:ze,top:Ve,flowPosition:r.screenToFlowPosition({x:J,y:Y}),draft:_,candidates:A,existingCandidates:R,mode:X,query:""})},[be,r,je]),yL=m.useCallback(x=>{if(!je){ge("Readonly workspace"),ee(null);return}const S=ue.current;if(!S||!(x!=null&&x.def))return;const _=zi(x.def,{position:S.flowPosition});if(!_)return;const A=S.draft.handleType==="source"?{source:S.draft.nodeId,sourceHandle:S.draft.handleId,target:_,targetHandle:`input-${x.slotIndex}`}:{source:_,sourceHandle:`output-${x.slotIndex}`,target:S.draft.nodeId,targetHandle:S.draft.handleId};g(R=>ew(R,A)),w(R=>{const U=R.filter(J=>!(J.target===A.target&&J.targetHandle===A.targetHandle)),X=uh({...A,markerEnd:{type:bi.ArrowClosed}},U);return j.current=X,X}),ee(null)},[zi,w,je]),wL=m.useCallback(x=>{if(!je){ge("Readonly workspace"),ee(null);return}const S=x==null?void 0:x.connection;if(!S||!ow(S,N.current)){ge("端口类型不匹配,已取消连线"),ee(null);return}g(_=>ew(_,S)),w(_=>{const A=_.filter(U=>!(U.target===S.target&&U.targetHandle===S.targetHandle)),R=uh({...S,markerEnd:{type:bi.ArrowClosed}},A);return j.current=R,R}),ee(null)},[w,g,je]),g0=m.useCallback(x=>{x&&(zi(x,{position:Vf()}),q(!1),et(""))},[zi,Vf]),y0=m.useCallback(x=>{x&&(yu(x,Vf()),q(!1),et(""))},[yu,Vf]),xL=m.useCallback(x=>{var _,A,R;if(ut||Pn)return;const S=x==null?void 0:x.target;vC(S)||(_=S==null?void 0:S.closest)!=null&&_.call(S,"button, a, [role='button'], .react-flow__handle")||(R=(A=C.current)==null?void 0:A.focus)==null||R.call(A,{preventScroll:!0})},[ut,Pn]);m.useEffect(()=>{const x=S=>{var ae;if(S.defaultPrevented)return;const _=fU(S.target)||vC(S.target);if((S.metaKey||S.ctrlKey)&&S.key.toLowerCase()==="s"){S.preventDefault(),Zt().catch(he=>ge(String(he.message||he)));return}if((S.metaKey||S.ctrlKey)&&S.key.toLowerCase()==="k"){S.preventDefault(),S.stopPropagation(),gS(he=>!he);return}if(Lg)return;if($g){(S.key==="Escape"||sC(S))&&(S.preventDefault(),Ef(!1));return}const A=S.key.toLowerCase(),R=(S.metaKey||S.ctrlKey)&&A==="c",U=(S.metaKey||S.ctrlKey)&&A==="v",X=_&&R&&MY(S.target);if(_&&!X)return;const J=(S.metaKey||S.ctrlKey)&&!S.shiftKey&&A==="z",Y=(S.metaKey||S.ctrlKey)&&(S.shiftKey&&A==="z"||A==="y");if(J||Y){if(ut){S.preventDefault(),S.stopPropagation(),ge("展示页布局会自动保存");return}if(!je){S.preventDefault(),ge("Readonly workspace");return}S.preventDefault(),S.stopPropagation();const he=J?IS():RS();ge(he?J?"Undo canvas change":"Redo canvas change":J?"Nothing to undo":"Nothing to redo");return}if(R){if(ut)return;const he=go.current,fe=(N.current||[]).some(We=>We==null?void 0:We.selected)?N.current:(N.current||[]).map(We=>he&&We.id===he?{...We,selected:!0}:We),Ne=$q(fe,j.current,Z.current);Ne&&(S.preventDefault(),S.stopPropagation(),B.current=Ne,LG(Ne),X&&typeof((ae=S.target)==null?void 0:ae.blur)=="function"&&S.target.blur(),ge(`Copied ${Ne.nodes.length} node${Ne.nodes.length>1?"s":""}`));return}if(U){if(ut){S.preventDefault(),S.stopPropagation();return}if(!je){S.preventDefault(),ge("Readonly workspace");return}const he=B.current||OG();he&&!B.current&&(B.current=he);const fe=Lq(he,N.current,j.current,Z.current);fe&&(S.preventDefault(),S.stopPropagation(),Z.current=fe.instances,ne(fe.instances),g(fe.nodes),w(fe.edges),ge(`Pasted ${fe.pastedNodeIds.length} node${fe.pastedNodeIds.length>1?"s":""}`));return}if(sC(S)&&!S.metaKey&&!S.ctrlKey&&!S.altKey){S.preventDefault(),Ef(!0);return}if(A==="g"&&!S.metaKey&&!S.ctrlKey&&!S.altKey){S.preventDefault(),o0();return}if(S.key==="a"||S.key==="A"){if(S.metaKey||S.ctrlKey){S.preventDefault(),ut?K(z.current.nodeIds):(g(he=>he.map(fe=>({...fe,selected:!0}))),w(he=>he.map(fe=>({...fe,selected:!1}))));return}if(S.altKey)return;if(ut){S.preventDefault(),Pe(!0);return}if(!je){S.preventDefault(),ge("Readonly workspace");return}S.preventDefault(),q(!0);return}if((S.key==="v"||S.key==="V")&&!S.metaKey&&!S.ctrlKey&&!S.altKey){S.preventDefault(),yS("select");return}if((S.key==="h"||S.key==="H")&&!S.metaKey&&!S.ctrlKey&&!S.altKey){S.preventDefault(),yS("pan");return}(S.key==="f"||S.key==="F")&&!S.metaKey&&!S.ctrlKey&&!S.altKey&&(S.preventDefault(),i0())};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[o0,ut,Lg,i0,RS,Zt,$g,w,g,IS,je]);const bL=m.useCallback(x=>{dl(S=>{const _=new Set(S);return _.has(x)?_.delete(x):_.add(x),_})},[]),kL=m.useCallback((x,S)=>{x.dataTransfer.effectAllowed="copy",x.dataTransfer.setData("application/x-agentflow-workspace-file",JSON.stringify({path:S.path,name:S.name,type:S.type})),x.dataTransfer.setData("text/plain",S.path)},[]),vL=m.useCallback((x,S)=>{x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("application/agentflow-node",S.id),x.dataTransfer.setData("text/plain",S.id)},[]),Kf=m.useCallback(async(x,S)=>{const _=String((x==null?void 0:x.name)||(x==null?void 0:x.path)||"").toLowerCase(),A=_.split(".").pop(),R=["jsx","tsx","js"].includes(A)?"display_react_app":A==="html"?"display_html":A==="csv"||A==="tsv"||A==="json"&&/\b(table|data|rows|report)\b/i.test(_)?"display_table":["png","jpg","jpeg","gif","webp","svg"].includes(A)?"display_image":"display_markdown",U=be.find(fe=>fe.id===R);if(!U){ge("展示节点不可用");return}const X=R==="display_image";let J=String(x.path||"");if(!X){const fe=Tr(a);fe.set("path",x.path);const Ne=await fetch(`/api/workspace/file?${fe.toString()}`),We=await Ne.json();if(!Ne.ok)throw new Error(We.error||"读取文件失败");J=String(We.content||"")}const Y=R==="display_image"?"src":"content",ae=qu(U.inputs).map(fe=>fe.name===Y?{...fe,default:J,value:J}:fe),he=qu(U.outputs).map(fe=>fe.name===Y?{...fe,default:J,value:J}:fe);zi(U,{label:x.name||"Display",body:J,inputs:ae,outputs:he,position:S}),ge(`已创建展示:${x.path}`)},[zi,a,be]),SL=m.useCallback(x=>{if(!je){ge("Readonly workspace");return}Kf(x,jl()).catch(S=>ge(String(S.message||S)))},[Kf,jl,je]),NL=m.useCallback(x=>{if(!je){x.preventDefault(),ge("Readonly workspace");return}const S=x.dataTransfer.getData("application/x-agentflow-workspace-file");if(S){x.preventDefault();let X;try{X=JSON.parse(S)}catch{return}if(!(X!=null&&X.path))return;const J=r.screenToFlowPosition({x:x.clientX,y:x.clientY});Kf(X,J).catch(Y=>ge(String(Y.message||Y)));return}const _=x.dataTransfer.getData("application/agentflow-snippet");if(_){const X=Re.find(Y=>`${Y.id}@${Y.version}`===_);if(!X)return;x.preventDefault();const J=r.screenToFlowPosition({x:x.clientX,y:x.clientY});yu(X,J);return}const A=x.dataTransfer.getData("application/agentflow-node");if(!A)return;const R=be.find(X=>X.id===A);if(!R)return;x.preventDefault();const U=r.screenToFlowPosition({x:x.clientX,y:x.clientY});zi(R,{position:U})},[Kf,zi,Re,yu,be,r,je]),jL=m.useCallback(x=>{if(!je)return;const S=Array.from(x.dataTransfer.types||[]);!S.includes("application/x-agentflow-workspace-file")&&!S.includes("application/agentflow-node")&&!S.includes("application/agentflow-snippet")||(x.preventDefault(),x.dataTransfer.dropEffect=S.includes("application/agentflow-node")||S.includes("application/agentflow-snippet")?"move":"copy")},[je]),CL=m.useCallback(async(x="")=>{if(!je){ge("Readonly workspace");return}const S=window.prompt("新文件名",x?`${x}/notes.md`:"notes.md");if(!S)return;const _=x&&!S.includes("/")?`${x}/${S}`:S;try{const A=await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:_,content:""})}),R=await A.json();if(!A.ok)throw new Error(R.error||"创建文件失败");await An(),dl(U=>{const X=new Set(U);for(const J of Dp(R.path||_))X.delete(J);return X}),ge(`已创建 ${R.path}`)}catch(A){ge(String(A.message||A))}},[a,An,je]),_L=m.useCallback(async(x="")=>{if(!je){ge("Readonly workspace");return}const S=window.prompt("新文件夹名",x?`${x}/docs`:"docs");if(!S)return;const _=x&&!S.includes("/")?`${x}/${S}`:S;try{const A=await fetch("/api/workspace/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:_})}),R=await A.json();if(!A.ok)throw new Error(R.error||"创建文件夹失败");await An(),dl(U=>{const X=new Set(U);for(const J of Dp(R.path||_))X.delete(J);return R.path&&X.delete(R.path),X}),ge(`已创建 ${R.path}`)}catch(A){ge(String(A.message||A))}},[a,An,je]),EL=m.useCallback(async x=>{if(!je){ge("Readonly workspace");return}if(!(!(x!=null&&x.path)||!window.confirm(`删除 ${x.path}?`)))try{const S=await fetch("/api/workspace/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:x.path})}),_=await S.json();if(!S.ok)throw new Error(_.error||"删除失败");ge(`已删除 ${_.path}`),await An()}catch(S){ge(String(S.message||S))}},[a,An,je]),AL=m.useCallback(x=>{if(!(x!=null&&x.path)||x.type==="directory")return;const S=Ud(x.path,a,{download:!0});if(!S)return;const _=document.createElement("a");_.href=S,_.download=x.name||x.path.split("/").pop()||"download",_.rel="noopener",document.body.appendChild(_),_.click(),_.remove()},[a]),qf=m.useCallback(async()=>{if(!je){ge("Readonly workspace");return}const x=fa.trim(),S=Hr,_=Ls.find(X=>X.id===S)||null;if(!x||ns||(_==null?void 0:_.status)==="running"||(_==null?void 0:_.status)==="stopping")return;const A=_?Array.isArray(_.messages)?_.messages:[]:pa,R=Ml(b,v,Z.current);Rg(""),cS(!0),ml(!0),gl(null);const U={role:"user",text:x,at:Date.now()};_?qn(X=>X.map(J=>J.id===S?{...J,status:"running",messages:[...Array.isArray(J.messages)?J.messages:[],U].slice(-180)}:J)):(bs("workspace"),hl(X=>[...X,U]));try{await Zt(b,v);const X=await fetch("/api/workspace/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,prompt:x,outputKind:"markdown",workspaceGraph:R,allowFlowYaml:!1,model:Li,selectedSkills:$s,selectedNodeIds:Ff,messages:A})}),J=await X.json();if(!X.ok)throw new Error(J.error||"生成失败");const ae={role:"assistant",kind:"assistant",text:String(J.content||"").trim(),at:Date.now()};_?qn(he=>he.map(fe=>fe.id===S?{...fe,status:"done",messages:[...Array.isArray(fe.messages)?fe.messages:[],ae].slice(-180)}:fe)):hl(he=>[...he,ae]),await ks(),ge("AI 生成完成")}catch(X){const J=String(X.message||X),Y={role:"assistant",text:J,error:!0,at:Date.now()};_?qn(ae=>ae.map(he=>he.id===S?{...he,status:"failed",messages:[...Array.isArray(he.messages)?he.messages:[],Y].slice(-180)}:he)):hl(ae=>[...ae,Y]),ge(J)}finally{cS(!1)}},[Hr,pa,Li,Ls,ns,fa,v,a,ks,b,Zt,Ff,$s,je]),or=Ls.find(x=>x.id===Hr)||null,Jg=or?Array.isArray(or.messages)?or.messages:[]:pa,Cl=or&&(or.status==="running"||or.status==="stopping")||ns,PL=wJ(Jg,Cl),Xg=xJ(Jg),w0=or?or.status==="stopping"?`${or.label} stopping`:or.status==="running"?`${or.label} running`:or.status==="paused"?`${or.label} paused`:or.status==="failed"?`${or.label} failed`:`${or.label} done`:ns?"Workspace agent running":pa.length>0?"Workspace conversation":"Ready";m.useEffect(()=>{Hr!=="workspace"&&(Ls.some(x=>x.id===Hr)||bs(ga()))},[Hr,Ls,ga]),m.useEffect(()=>{if(!tu)return;const x=window.requestAnimationFrame(()=>{var _,A;const S=uS.current;S&&(S.scrollTop=S.scrollHeight),(A=(_=Tg.current)==null?void 0:_.scrollIntoView)==null||A.call(_,{block:"nearest",inline:"nearest"})});return()=>window.cancelAnimationFrame(x)},[Jg.length,Hr,w0,Xg.length,tu]);const IL=String(a.flowId||"").trim()||"Workspace",wo=(_t==null?void 0:_t.mode)==="single-node",x0=wo&&gu.find(x=>{var S;return x.id===_t.sourceNodeId||((S=_t.nodeIds)==null?void 0:S.includes(x.id))})||null,RL=wo&&x0?[x0]:gu;return i.jsxs("div",{className:"af-workspace-page",children:[l?null:i.jsxs("header",{className:"af-pipeline-top af-workspace-top",children:[i.jsxs("div",{className:"af-pipeline-top-left",children:[i.jsx("button",{type:"button",className:"af-icon-btn af-pipeline-back",onClick:()=>n("/projects"),"aria-label":"返回",children:i.jsx("span",{className:"material-symbols-outlined",children:"arrow_back"})}),i.jsxs("div",{className:"af-pipeline-brand",title:a.flowId?`${a.flowId} · ${Mv}`:Mv||"PROJECT",children:[i.jsx("span",{className:"af-pipeline-brand-name",children:IL}),i.jsxs("span",{className:"af-pipeline-brand-ver",children:["V",jY,"-STABLE"]})]}),i.jsxs("div",{className:"af-view-switch","aria-label":"视图切换",children:[i.jsx("button",{type:"button",className:d==="workspace"?"af-view-switch__active":"",onClick:()=>Gg("workspace"),children:"Workspace"}),i.jsx("button",{type:"button",className:d==="display"?"af-view-switch__active":"",onClick:()=>Gg("display"),children:"Display"}),i.jsx("button",{type:"button",className:d==="workflow"?"af-view-switch__active":"",onClick:()=>Gg("workflow"),children:"Workflow"})]})]}),i.jsxs("div",{className:"af-pipeline-top-right af-workspace-actions",children:[i.jsx("span",{className:`af-workspace-sync-light is-${SS}`,title:`${AS} · ${NS}`,role:"status","aria-label":`${AS}:${NS}`,children:i.jsx("span",{className:"af-workspace-sync-light__dot","aria-hidden":!0})}),En?i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",onClick:()=>{var x;(x=En.conflictItems)!=null&&x.length?ua(!0):h0()},title:["先下载当前本地草稿,再载入远端最新版本",...En.conflictPaths||[]].join(`
264
- `),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"difference"}),"处理冲突"]}):null,ut?i.jsxs(i.Fragment,{children:[i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",disabled:dn||!(Ct!=null&&Ct.absoluteUrl)&&P.nodeIds.length===0,onClick:()=>{Zn(""),Jt(!0)},title:Ct!=null&&Ct.absoluteUrl?"查看展示链接":P.nodeIds.length===0?"先添加展示节点":"生成展示链接",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:dn?"hourglass_empty":"ios_share"}),dn?"生成中":Ct!=null&&Ct.absoluteUrl?"展示链接":"生成链接"]}),i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",disabled:kl.length===0,onClick:()=>Pe(!0),title:kl.length===0?"当前 workspace 没有 display 节点":"选择展示节点 (A)",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add_to_photos"}),"添加展示"]})]}):null,i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",disabled:!!(an!=null&&an.role&&an.role!=="owner"),onClick:eL,title:an!=null&&an.role&&an.role!=="owner"?"仅 Workspace 所有者可以创建邀请":"邀请其他成员协作编辑",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"group_add"}),"协作分享"]}),i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",onClick:sL,title:"查看我的展示分享",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"folder_shared"}),"我的分享"]}),i.jsx("button",{type:"button",className:"af-icon-btn",disabled:!ES,onClick:()=>h(!0),"aria-label":e("project:archiveModal.title"),title:e("project:archiveModal.title"),children:i.jsx("span",{className:"material-symbols-outlined",children:"archive"})}),i.jsx("button",{type:"button",className:"af-icon-btn af-icon-btn--danger",disabled:!ES&&!lu,onClick:()=>k(!0),"aria-label":lu?"退出共享 Workspace":e("flow:topbar.deletePipeline"),title:lu?"退出共享 Workspace":e("flow:topbar.deletePipeline"),children:i.jsx("span",{className:"material-symbols-outlined",children:lu?"logout":"delete_forever"})}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>Ef(!0),"aria-label":"快捷键",title:"快捷键 (?)",children:i.jsx("span",{className:"material-symbols-outlined",children:"help"})}),i.jsx("button",{type:"button",className:"af-composer-topbar-btn"+(tu?" af-composer-topbar-btn--active":"")+(ns?" af-composer-topbar-btn--running":""),disabled:ut||Pn,onClick:()=>{gl(null),ml(x=>(x||bs(ga()),!x))},children:"AI"}),i.jsx("button",{type:"button",className:"af-btn-primary af-btn-primary--lg",disabled:!je,onClick:()=>Zt().catch(x=>ge(String(x.message||x))),children:"Save"})]})]}),gs?i.jsxs("div",{className:"af-flow-snippet-toast",role:"status","aria-live":"polite",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"check_circle"}),i.jsx("span",{children:gs}),i.jsx("button",{type:"button",onClick:()=>ys(""),"aria-label":"关闭发布提示",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}):null,i.jsxs("div",{className:"af-workspace-body"+(!ut&&!Pn&&(tu||at)?" af-workspace-body--drawer":"")+(!ut&&!Pn&&ru?" af-workspace-body--sidebar-collapsed":"")+(ut?" af-workspace-body--display-mode":"")+(Pn?" af-workspace-body--workflow-mode":""),children:[!ut&&!Pn&&ru?i.jsx("nav",{className:"af-workspace-rail","aria-label":"Workspace sidebar",children:i.jsxs("div",{className:"af-workspace-rail__stack",children:[i.jsxs("button",{type:"button",className:"af-workspace-rail__primary",onClick:()=>q(!0),"aria-label":"添加节点",title:"添加节点",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"}),i.jsx("span",{className:"af-workspace-rail__dot","aria-hidden":!0})]}),i.jsx("button",{type:"button",className:"af-workspace-rail__btn",onClick:()=>_f(!1),"aria-label":"展开文件",title:"展开文件",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"folder"})}),i.jsx("span",{className:"af-workspace-rail__divider","aria-hidden":!0}),i.jsx("button",{type:"button",className:"af-workspace-rail__avatar",onClick:()=>_f(!1),"aria-label":"展开侧边栏",title:(Ir==null?void 0:Ir.username)||(Ir==null?void 0:Ir.userId)||"展开侧边栏",children:J$})]})}):null,!ut&&!Pn?i.jsxs("aside",{ref:Ng,className:"af-workspace-sidebar"+(m$?" af-workspace-sidebar--resizing":""),"aria-hidden":ru,style:{"--af-work-files-pane-height":`${Math.round(jg)}px`},children:[i.jsxs("section",{className:"af-workspace-files-section",children:[i.jsxs("div",{className:"af-workspace-sidebar-head",children:[i.jsx("h2",{children:"Files"}),i.jsxs("div",{className:"af-workspace-sidebar-actions",children:[i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>_f(!0),"aria-label":"最小化侧边栏",title:"最小化侧边栏",children:i.jsx("span",{className:"material-symbols-outlined",children:"keyboard_double_arrow_left"})}),i.jsx("button",{type:"button",className:"af-icon-btn",disabled:!je,onClick:()=>CL(Fi),"aria-label":"新增文件",title:Fi?`在 ${Fi} 新增文件`:"新增文件",children:i.jsx("span",{className:"material-symbols-outlined",children:"note_add"})}),i.jsx("button",{type:"button",className:"af-icon-btn",disabled:!je,onClick:()=>_L(Fi),"aria-label":"新增文件夹",title:Fi?`在 ${Fi} 新增文件夹`:"新增文件夹",children:i.jsx("span",{className:"material-symbols-outlined",children:"create_new_folder"})}),i.jsx("button",{type:"button",className:"af-icon-btn",disabled:!je||Hv,onClick:()=>qS(Fi),"aria-label":"上传文件",title:Fi?`上传到 ${Fi}`:"上传文件",children:i.jsx("span",{className:"material-symbols-outlined",children:Hv?"hourglass_top":"upload_file"})}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>void An(),"aria-label":"刷新文件",title:"刷新文件",children:i.jsx("span",{className:"material-symbols-outlined",children:"refresh"})}),i.jsx("input",{ref:Vv,type:"file",multiple:!0,className:"af-visually-hidden",onChange:z$})]})]}),i.jsx("input",{className:"af-workspace-search",value:bg,onChange:x=>p$(x.target.value),placeholder:"搜索文件..."}),i.jsx("div",{className:"af-workspace-files-scroll",onClick:Y$,children:i.jsx(iM,{items:U$,onOpen:SL,selectedPath:kg,collapsedDirs:h$,onToggleDir:bL,onSelect:x=>vg(x.path||""),onFileDragStart:kL,onDelete:EL,onDownload:AL})})]}),i.jsx("button",{type:"button",className:"af-workspace-sidebar-resizer",onPointerDown:N$,role:"separator","aria-orientation":"horizontal","aria-label":"调整 Files 和 Palette 区域大小",title:"拖动调整 Files / Palette 高度"}),i.jsxs("section",{className:"af-workspace-nodes-section",children:[i.jsxs("div",{className:"af-node-palette-head af-workspace-node-palette-head",children:[i.jsxs("h2",{className:"af-node-palette-title",children:[i.jsx("span",{children:"Palette"}),i.jsx("span",{className:"af-node-palette-title-kbd","aria-label":"快捷键 A",children:"A"})]}),i.jsxs("label",{className:"af-palette-search-wrap",children:[i.jsx("span",{className:"af-visually-hidden",children:on==="flows"?"搜索流程片段":"搜索节点"}),i.jsx("span",{className:"af-palette-search-icon material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",className:"af-palette-search-input",value:jt,onChange:x=>yn(x.target.value),placeholder:on==="flows"?"搜索流程片段...":"搜索节点...","aria-label":on==="flows"?"搜索流程片段":"搜索节点"})]}),i.jsxs("div",{className:"af-palette-tabs",role:"tablist","aria-label":"Palette 类型",children:[i.jsxs("button",{type:"button",role:"tab","aria-selected":on==="nodes",className:"af-palette-tab"+(on==="nodes"?" af-palette-tab--active":""),onClick:()=>re("nodes"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"category"}),"节点"]}),i.jsxs("button",{type:"button",role:"tab","aria-selected":on==="flows",className:"af-palette-tab"+(on==="flows"?" af-palette-tab--active":""),onClick:()=>re("flows"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"account_tree"}),"流程"]})]})]}),i.jsx("div",{className:"af-node-palette-scroll af-workspace-node-palette-scroll",children:on==="flows"?i.jsxs(i.Fragment,{children:[i.jsx("section",{className:"af-palette-section af-flow-palette-section--snippets",children:i.jsxs("div",{className:"af-flow-snippet-actions",children:[i.jsxs("button",{type:"button",className:"af-flow-snippet-publish-btn",onClick:Q$,disabled:er.length<2,title:er.length<2?"选择至少两个节点后发布流程片段":"发布选中的流程片段",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"ios_share"}),"发布选中片段"]}),i.jsxs("span",{className:"af-flow-snippet-selection",children:["已选 ",er.length," 节点 / ",zf.length," 连线"]})]})}),At?i.jsx("p",{className:"af-err af-palette-list-err",children:At}):null,Ze?i.jsx("p",{className:"af-palette-empty",children:"正在加载流程片段..."}):d0.length>0?i.jsxs("section",{className:"af-palette-section af-flow-palette-section--snippets",children:[i.jsx("h3",{className:"af-palette-cat",children:"FLOW SNIPPETS"}),i.jsx("div",{className:"af-palette-cards",children:d0.map(x=>{const S=`${x.id}@${x.version}`,_=x.displayName||x.name||x.id,A=x.description||`${x.nodeCount||0} 个节点,${x.edgeCount||0} 条连线`;return i.jsxs("button",{type:"button",className:"af-palette-card af-flow-snippet-card",draggable:!0,onDragStart:R=>{R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("application/agentflow-snippet",S),R.dataTransfer.setData("text/plain",S)},onClick:()=>yu(x),title:A,children:[i.jsxs("span",{className:"af-palette-card-head",children:[i.jsx("span",{className:"af-palette-card-icon","aria-hidden":!0,children:i.jsx("span",{className:"material-symbols-outlined",children:"account_tree"})}),i.jsxs("span",{className:"af-palette-card-main",children:[i.jsx("span",{className:"af-palette-card-label",children:_}),i.jsxs("span",{className:"af-palette-card-id",children:[x.id,"@",x.version]})]})]}),A?i.jsx("span",{className:"af-palette-card-desc",children:A}):null,i.jsxs("span",{className:"af-flow-snippet-meta","aria-hidden":!0,children:[i.jsxs("span",{children:[x.nodeCount||0," nodes"]}),i.jsxs("span",{children:[x.edgeCount||0," edges"]})]})]},S)})})]}):i.jsx("p",{className:"af-palette-empty",children:jt.trim()?"没有匹配的流程片段":"暂无流程片段。选择多个节点后发布。"})]}):i.jsxs(i.Fragment,{children:[Ol.map(x=>{var S;return(S=Kg[x])!=null&&S.length?i.jsxs("section",{className:`af-palette-section af-flow-palette-section--${x}`,children:[i.jsx("h3",{className:"af-palette-cat",children:x}),i.jsx("div",{className:"af-palette-cards",children:Kg[x].map(_=>{const A=AC(_.inputs,"input"),R=AC(_.outputs,"output"),U=ub(_),X=Vu(_);return i.jsxs("button",{type:"button",className:"af-palette-card",draggable:!0,onDragStart:J=>vL(J,_),onClick:()=>zi(_),title:U||_.id,children:[i.jsxs("span",{className:"af-palette-card-head",children:[i.jsx("span",{className:"af-palette-card-icon","aria-hidden":!0,children:i.jsx("span",{className:"material-symbols-outlined",children:_C(x)})}),i.jsxs("span",{className:"af-palette-card-main",children:[i.jsx("span",{className:"af-palette-card-label",children:X}),X!==_.id?i.jsx("span",{className:"af-palette-card-id",children:_.id}):null]})]}),U?i.jsx("span",{className:"af-palette-card-desc",children:U}):null,i.jsxs("span",{className:"af-palette-card-ports","aria-hidden":!0,children:[i.jsxs("span",{className:"af-palette-card-port-side af-palette-card-port-side--in",children:[i.jsxs("span",{className:"af-palette-card-port-count",children:[A.list.length," IN"]}),i.jsxs("span",{className:"af-palette-card-port-list",children:[A.shown.map((J,Y)=>i.jsxs("span",{className:"af-palette-card-port",title:EC("input",J,Y),children:[i.jsx("span",{className:"af-palette-card-port-dot",style:{background:Tn(J==null?void 0:J.type)}}),i.jsx("span",{className:"af-palette-card-port-name",children:$p(J,Y)})]},`in-${Y}`)),A.hidden>0?i.jsxs("span",{className:"af-palette-card-port-more",children:["+",A.hidden]}):null]})]}),i.jsxs("span",{className:"af-palette-card-port-side af-palette-card-port-side--out",children:[i.jsxs("span",{className:"af-palette-card-port-count",children:[R.list.length," OUT"]}),i.jsxs("span",{className:"af-palette-card-port-list",children:[R.shown.map((J,Y)=>i.jsxs("span",{className:"af-palette-card-port",title:EC("output",J,Y),children:[i.jsx("span",{className:"af-palette-card-port-name",children:$p(J,Y)}),i.jsx("span",{className:"af-palette-card-port-dot",style:{background:Tn(J==null?void 0:J.type)}})]},`out-${Y}`)),R.hidden>0?i.jsxs("span",{className:"af-palette-card-port-more",children:["+",R.hidden]}):null]})]})]})]},_.id)})})]},x):null}),be.length>0&&jt.trim()&&Ol.every(x=>{var S;return!((S=Kg[x])!=null&&S.length)})?i.jsx("p",{className:"af-palette-empty",children:"没有匹配的节点"}):null]})})]})]}):null,Pn?i.jsx($J,{flowParams:a,tapdId:ir,setTapdId:k$,snapshot:ln,loading:v$,error:S$,actionRunning:Cg,actionOutput:_g,pendingConfirm:xs,conflict:Zc,reviewPublishing:Eg,onRefresh:()=>uu(ir),onRunDryRun:T$,onConfirmAction:M$,onRetryConflict:$$,onPublishReview:L$}):i.jsxs("main",{ref:C,className:"af-workspace-canvas",tabIndex:-1,onPointerDownCapture:xL,children:[i.jsx(gR,{className:"af-flow-canvas af-workspace-flow"+(Og==="pan"?" af-flow-canvas--tool-pan":" af-flow-canvas--tool-select")+(ut?" af-workspace-flow--display-mode":""),nodes:Df,edges:K$,nodeTypes:uJ,onNodesChange:dL,onEdgesChange:fL,onConnect:ut?void 0:hL,onConnectStart:ut?void 0:mL,onConnectEnd:ut?void 0:gL,isValidConnection:ut?void 0:pL,onNodeClick:(x,S)=>{var _;if(ut){K([Op(S.id)]);return}if((_=S==null?void 0:S.data)!=null&&_.isWorkspaceGroup){jn("");return}if(x.detail>=3){ml(!1),g(A=>A.map(R=>({...R,selected:R.id===S.id}))),w(A=>A.map(R=>({...R,selected:!1}))),jn(S.id);return}Ut&&jn(S.id)},onNodeDoubleClick:x=>{x.preventDefault()},onPaneClick:()=>{ut?K([]):jn("")},onDrop:ut?void 0:NL,onDragOver:ut?void 0:jL,nodesDraggable:ut?!0:je,nodesConnectable:ut?!1:je,edgesReconnectable:ut?!1:je,onlyRenderVisibleElements:Df.length>=80,deleteKeyCode:ut?null:je?["Backspace","Delete"]:null,selectionOnDrag:Og==="select",panOnDrag:Og==="pan"?!0:[1,2],panActivationKeyCode:"Space",proOptions:{hideAttribution:!0},fitView:!1,minZoom:.1,maxZoom:4,children:i.jsx(wR,{color:"rgba(255,255,255,0.12)",gap:22,size:1})}),!ut&&G?(()=>{var J;const x=String(G.query||"").trim().toLowerCase(),S=G.mode==="create"?"create":"existing",_=Array.isArray(G.candidates)?G.candidates:[],A=Array.isArray(G.existingCandidates)?G.existingCandidates:[],R=x?_.filter(Y=>{var ae,he,fe;return[(ae=Y.def)==null?void 0:ae.id,Y.displayLabel,Y.description,(he=Y.slot)==null?void 0:he.name,(fe=Y.slot)==null?void 0:fe.type].filter(Boolean).some(Ne=>String(Ne).toLowerCase().includes(x))}):_,U=x?A.filter(Y=>{var ae,he;return[Y.nodeId,Y.nodeLabel,Y.definitionId,(ae=Y.slot)==null?void 0:ae.name,(he=Y.slot)==null?void 0:he.type].filter(Boolean).some(fe=>String(fe).toLowerCase().includes(x))}):A,X=G.draft.handleType==="source"?"IN":"OUT";return i.jsxs("div",{className:"af-connect-node-menu",style:{left:G.left,top:G.top},role:"dialog","aria-label":"选择匹配节点",children:[i.jsxs("div",{className:"af-connect-node-menu__head",children:[i.jsxs("div",{className:"af-connect-node-menu__title",children:[i.jsx("span",{className:"af-connect-node-menu__dot",style:{background:Tn((J=G.draft.slot)==null?void 0:J.type)},"aria-hidden":!0}),i.jsxs("span",{children:["匹配 ",G.draft.slotType," 节点"]})]}),i.jsx("button",{type:"button",className:"af-connect-node-menu__close","aria-label":"关闭",onClick:()=>ee(null),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-connect-node-menu__tabs",role:"tablist","aria-label":"连接方式",children:[i.jsxs("button",{type:"button",className:S==="existing"?"af-connect-node-menu__tab af-connect-node-menu__tab--active":"af-connect-node-menu__tab",disabled:A.length===0,onClick:()=>ee(Y=>Y&&{...Y,mode:"existing",query:""}),children:["连接已有 ",i.jsx("span",{children:A.length})]}),i.jsxs("button",{type:"button",className:S==="create"?"af-connect-node-menu__tab af-connect-node-menu__tab--active":"af-connect-node-menu__tab",disabled:_.length===0,onClick:()=>ee(Y=>Y&&{...Y,mode:"create",query:""}),children:["新建节点 ",i.jsx("span",{children:_.length})]})]}),i.jsxs("label",{className:"af-connect-node-menu__search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:G.query,onChange:Y=>ee(ae=>ae&&{...ae,query:Y.target.value}),placeholder:"搜索节点",autoFocus:!0})]}),i.jsxs("div",{className:"af-connect-node-menu__list",children:[S==="create"?R.map(Y=>{var fe,Ne;const ae=Y.displayLabel||((fe=Y.def)==null?void 0:fe.id),he=$p(Y.slot,Y.slotIndex);return i.jsxs("button",{type:"button",className:"af-connect-node-menu__item",onClick:()=>yL(Y),title:Y.description||Y.def.id,children:[i.jsxs("span",{className:"af-connect-node-menu__item-main",children:[i.jsx("span",{className:"af-connect-node-menu__item-label",children:ae}),ae!==Y.def.id?i.jsx("span",{className:"af-connect-node-menu__item-id",children:Y.def.id}):null]}),i.jsxs("span",{className:"af-connect-node-menu__port",children:[i.jsx("span",{children:X}),i.jsx("span",{className:"af-connect-node-menu__port-dot",style:{background:Tn((Ne=Y.slot)==null?void 0:Ne.type)},"aria-hidden":!0}),i.jsx("span",{className:"af-connect-node-menu__port-name",children:he})]})]},`${Y.def.id}-${Y.slotIndex}`)}):U.map(Y=>{var fe;const ae=Y.nodeLabel||Y.nodeId,he=$p(Y.slot,Y.slotIndex);return i.jsxs("button",{type:"button",className:"af-connect-node-menu__item",onClick:()=>wL(Y),title:`${Y.definitionId||Y.nodeId} · ${he}`,children:[i.jsxs("span",{className:"af-connect-node-menu__item-main",children:[i.jsx("span",{className:"af-connect-node-menu__item-label",children:ae}),i.jsxs("span",{className:"af-connect-node-menu__item-id",children:[Y.definitionId?`${Y.definitionId} · `:"",Y.nodeId]})]}),i.jsxs("span",{className:"af-connect-node-menu__port",children:[i.jsx("span",{children:X}),i.jsx("span",{className:"af-connect-node-menu__port-dot",style:{background:Tn((fe=Y.slot)==null?void 0:fe.type)},"aria-hidden":!0}),i.jsx("span",{className:"af-connect-node-menu__port-name",children:he}),Y.occupied?i.jsx("span",{className:"af-connect-node-menu__port-badge",children:"替换"}):null]})]},`${Y.nodeId}-${Y.handleId}`)}),(S==="create"?R.length:U.length)===0?i.jsx("div",{className:"af-connect-node-menu__empty",children:"没有匹配结果"}):null]})]})})():null,!ut&&!Pn&&!E$?i.jsx("div",{className:"af-workspace-composer af-bottom-composer-stack af-flow-bottom-composer",children:i.jsxs("div",{className:"af-pipeline-composer-inner",children:[i.jsx("button",{type:"button",className:"af-workspace-composer-minimize",onClick:()=>Mg(!0),"aria-label":"最小化 AI 输入框",title:"最小化",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"remove"})}),i.jsx("div",{className:"af-composer-selected","aria-label":"Selected workspace nodes",children:er.length===0?i.jsx("span",{className:"af-composer-selected-empty",children:"选择画布节点后,可作为本次 Workspace AI 的上下文。"}):er.map(x=>{var R,U;const S=String(((R=x.data)==null?void 0:R.label)??x.id),_=(U=x.data)!=null&&U.definitionId?String(x.data.definitionId):"",A=_&&_!==S?`${S} · ${x.id} · ${_}`:`${S} · ${x.id}`;return i.jsxs("div",{className:"af-composer-node-chip",title:A,children:[i.jsx("span",{className:"af-composer-node-chip-kind",children:_||"node"}),i.jsx("span",{className:"af-composer-node-chip-label",children:S}),i.jsx("button",{type:"button",className:"af-composer-node-chip-dismiss",onClick:()=>uL(x.id),"aria-label":`取消选择 ${x.id}`,children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]},x.id)})}),i.jsxs("div",{className:"af-composer-card af-composer-card--input-only",children:[i.jsx("div",{className:"af-composer-input-wrap",children:i.jsx("textarea",{className:"af-composer-textarea",value:fa,rows:2,onChange:x=>Rg(x.target.value),onKeyDown:x=>{(x.metaKey||x.ctrlKey)&&x.key==="Enter"&&(x.preventDefault(),qf())},placeholder:"描述你想在 workspace 中生成、分析或展示的内容",autoComplete:"off",spellCheck:!1,disabled:!je})}),i.jsxs("div",{className:"af-composer-toolbar",children:[i.jsxs("div",{className:"af-composer-skills-field",children:[i.jsxs("button",{ref:Ig,type:"button",className:"af-composer-skills-button"+($s.length>0?" af-composer-skills-button--active":""),disabled:ns||!je,"aria-haspopup":"listbox","aria-expanded":Cf,onClick:()=>Pg(x=>!x),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"extension"}),i.jsx("span",{children:$s.length>0?`Skills ${$s.length}`:"Skills"})]}),Cf&&!ns?cr.createPortal(i.jsx("div",{ref:aS,className:"af-composer-skills-menu",role:"listbox","aria-label":"Skills",style:C$,children:Ms.length===0?i.jsx("div",{className:"af-composer-skills-empty",children:"No skills found"}):i.jsxs(i.Fragment,{children:[Sl.groups.map(x=>{const S=Qo(x,Ms),_=jF(x,qg,Ms),A=j$.has(x.id);return i.jsxs("div",{className:"af-composer-skill-group af-composer-skill-group--framed"+(A?" af-composer-skill-group--collapsed":""),children:[i.jsxs("div",{className:"af-composer-skill-group-title af-composer-skill-group-title--selectable",children:[i.jsxs("label",{className:"af-composer-skill-group-check",children:[i.jsx("input",{type:"checkbox",checked:_==="all",disabled:S.length===0,onChange:R=>{const U=R.target.checked;Qc(X=>U?SF(X,S):NF(X,S))}}),i.jsxs("span",{className:"af-composer-skill-group-title-main",children:[i.jsx("span",{children:x.name}),x.builtin?i.jsx("em",{children:"built-in"}):null,_==="partial"?i.jsx("em",{children:"partial"}):null]})]}),i.jsxs("button",{type:"button",className:"af-composer-skill-group-toggle","aria-label":A?`展开 ${x.name}`:`收起 ${x.name}`,onClick:()=>{oS(R=>{const U=new Set(R);return U.has(x.id)?U.delete(x.id):U.add(x.id),U})},children:[i.jsx("span",{children:x.skills.length}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:A?"expand_more":"expand_less"})]})]}),A?null:i.jsx("div",{className:"af-composer-skill-group-items",children:x.skills.map(R=>i.jsxs("label",{className:"af-composer-skill-option",children:[i.jsx("input",{type:"checkbox",checked:qg.has(R.key),onChange:U=>{const X=U.target.checked;Qc(J=>X?J.includes(R.key)?J:[...J,R.key]:J.filter(Y=>Y!==R.key))}}),i.jsxs("span",{className:"af-composer-skill-option-main",children:[i.jsx("span",{className:"af-composer-skill-option-title",children:R.name}),R.description?i.jsx("span",{className:"af-composer-skill-option-desc",children:R.description}):null]})]},`${x.id}:${R.key}`))})]},x.id)}),Sl.ungrouped.length>0?i.jsxs("div",{className:"af-composer-skill-group",children:[i.jsxs("div",{className:"af-composer-skill-group-title",children:[i.jsx("span",{children:"Ungrouped"}),i.jsx("span",{children:Sl.ungrouped.length})]}),Sl.ungrouped.map(x=>i.jsxs("label",{className:"af-composer-skill-option",children:[i.jsx("input",{type:"checkbox",checked:qg.has(x.key),onChange:S=>{const _=S.target.checked;Qc(A=>_?A.includes(x.key)?A:[...A,x.key]:A.filter(R=>R!==x.key))}}),i.jsxs("span",{className:"af-composer-skill-option-main",children:[i.jsx("span",{className:"af-composer-skill-option-title",children:x.name}),x.description?i.jsx("span",{className:"af-composer-skill-option-desc",children:x.description}):null]})]},`ungrouped:${x.key}`))]}):null]})}),document.body):null]}),i.jsx("label",{className:"af-composer-model-field",children:i.jsxs("select",{className:"af-composer-model-select",value:Li,onChange:x=>y$(x.target.value),"aria-label":"模型",children:[i.jsx("option",{value:"",children:"默认模型"}),G$.map(x=>i.jsx("option",{value:x.value,children:x.label},x.value))]})}),i.jsx("button",{type:"button",className:"af-composer-send"+(fa.trim()&&!ns?" af-composer-send--active":"")+(ns?" af-composer-send--stop":""),disabled:ns||!fa.trim()||!je,"aria-label":ns?"Running":"Send",onClick:()=>void qf(),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:ns?"sync":"arrow_upward"})})]})]})]})}):!ut&&!Pn?i.jsx("button",{type:"button",className:"af-workspace-composer-fab",onClick:()=>Mg(!1),"aria-label":"展开 AI 输入框",title:"展开 AI 输入框",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"auto_awesome"})}):null]}),!ut&&!Pn&&tu?i.jsx("aside",{className:"af-pipeline-drawer af-pipeline-drawer--wide af-workspace-composer-drawer","aria-label":"Workspace AI Composer",children:i.jsxs("div",{className:"af-composer-sidebar",children:[i.jsxs("div",{className:"af-pipeline-drawer-head",children:[i.jsx("h2",{className:"af-pipeline-drawer-title",children:"AI Composer"}),i.jsx("button",{type:"button",className:"af-pipeline-drawer-close af-icon-btn",onClick:()=>ml(!1),"aria-label":"关闭 AI 对话侧栏",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-composer-session-tabs",children:[i.jsx("button",{type:"button",className:"af-composer-session-tab"+(Hr==="workspace"?" af-composer-session-tab--active":""),ref:Hr==="workspace"?Tg:null,onClick:()=>bs("workspace"),children:i.jsx("span",{className:"af-composer-session-label",children:"Workspace"})}),Ls.map(x=>i.jsxs("div",{role:"tab",tabIndex:0,ref:Hr===x.id?Tg:null,className:"af-composer-session-tab"+(Hr===x.id?" af-composer-session-tab--active":"")+(x.status==="running"||x.status==="stopping"?" af-composer-session-tab--running":""),onClick:()=>bs(x.id),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),bs(x.id))},title:x.runNodeId||x.label,children:[i.jsx("span",{className:"af-composer-session-label",children:x.label}),i.jsx("button",{type:"button",className:"af-composer-session-close",onClick:S=>{S.preventDefault(),S.stopPropagation(),D$(x.id)},"aria-label":`关闭 ${x.label}`,title:"关闭 tab",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]},x.id))]}),i.jsx("div",{className:"af-composer-sidebar-status"+(Cl?" af-composer-sidebar-status--running":""),role:"status","aria-live":"polite",children:w0}),i.jsxs("div",{className:"af-composer-sidebar-thread",ref:uS,children:[i.jsx(zC,{messages:PL,running:Cl,showRunningIndicator:!or}),Xg.length>0?i.jsxs("details",{className:"af-composer-sidebar-log-details",...Cl?{open:!0}:{},children:[i.jsx("summary",{children:"执行日志"}),i.jsx(zC,{messages:Xg,running:!1,showRunningIndicator:!1})]}):null]}),i.jsxs("div",{className:"af-composer-sidebar-input",children:[i.jsx("textarea",{className:"af-composer-sidebar-textarea",value:fa,rows:3,onChange:x=>Rg(x.target.value),onKeyDown:x=>{(x.metaKey||x.ctrlKey)&&x.key==="Enter"&&(x.preventDefault(),qf())},placeholder:or?"继续追问、总结或要求调整这次结果":"继续描述你想让 AI 在 workspace 中做什么",disabled:!je||Cl}),i.jsx("button",{type:"button",className:"af-composer-sidebar-send",disabled:!je||Cl||!fa.trim(),onClick:()=>void qf(),"aria-label":"发送 AI 对话",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"arrow_upward"})})]})]})}):!ut&&!Pn&&at&&Vt?i.jsx("aside",{className:"af-pipeline-drawer af-workspace-node-drawer","aria-label":"Workspace Node Properties",children:i.jsx(MU,{draft:at,setDraft:ws,definitionId:String(((b0=Vt.data)==null?void 0:b0.definitionId)||Vt.id),systemPromptReadonly:String(((k0=Vt.data)==null?void 0:k0.description)||""),modelLists:da,disabled:!je,onIdBlur:()=>Hg(!0),onClose:()=>jn(""),onPublishToMarketplace:O$,error:l$,ioSlots:{inputs:Array.isArray(at==null?void 0:at.inputs)?at.inputs:[],outputs:Array.isArray(at==null?void 0:at.outputs)?at.outputs:[]}})}):null,!ut&&!Pn&&nu?cr.createPortal(i.jsx("div",{className:"af-workspace-run-logs-overlay",role:"presentation",onMouseDown:()=>gl(null),children:i.jsx("aside",{className:"af-workspace-run-logs-drawer","aria-label":"Workspace Run Logs",onMouseDown:x=>x.stopPropagation(),children:i.jsx(xU,{flowParams:a,scheduleNodeId:nu.scheduleNodeId,runNodeId:nu.runNodeId,lastRunId:nu.lastRunId,label:nu.label,onClose:()=>gl(null)})})}),document.body):null,i.jsx(mU,{open:$g,onClose:()=>Ef(!1)}),i.jsx(yU,{open:Lg,onClose:()=>gS(!1),onJump:Vg,nodes:q$}),i.jsx($U,{open:p,onClose:()=>h(!1),flowId:a.flowId||"",flowSource:au,onArchived:()=>{h(!1),n("/projects?tab=archived")}}),i.jsx(LU,{open:y&&!!a.flowId,onClose:()=>k(!1),flowId:a.flowId||"",flowSource:au,flowArchived:!!a.archived,workspaceId:a.workspaceId||"",leaveShared:lu,onDeleted:async()=>{k(!1),n("/projects")}}),f$&&En?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-workspace-conflict-modal",role:"dialog","aria-modal":"true","aria-label":"解决 Workspace 冲突",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"difference"}),"解决 ",((v0=En.conflictItems)==null?void 0:v0.length)||0," 处字段冲突"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>ua(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("div",{className:"af-workspace-conflict-summary",children:["未冲突的改动已经自动合并。这里只需要决定双方同时修改的字段。",i.jsxs("div",{className:"af-workspace-conflict-bulk",children:[i.jsx("button",{type:"button",onClick:()=>ul(Object.fromEntries((En.conflictItems||[]).map((x,S)=>[String(S),{mode:"local",manual:Ru(x)}]))),children:"全部保留我的"}),i.jsx("button",{type:"button",onClick:()=>ul(Object.fromEntries((En.conflictItems||[]).map((x,S)=>[String(S),{mode:"remote",manual:Ru(x)}]))),children:"全部使用远端"})]})]}),(En.conflictItems||[]).map((x,S)=>{const _=xg[String(S)]||{mode:"local",manual:Ru(x)};return i.jsxs("section",{className:"af-workspace-conflict-item",children:[i.jsx("code",{className:"af-workspace-conflict-path",children:x.path}),i.jsx("div",{className:"af-workspace-conflict-options",children:[["local","保留我的"],["remote","使用远端"],["manual","手动编辑"]].map(([A,R])=>i.jsx("button",{type:"button",className:_.mode===A?"is-active":"",onClick:()=>ul(U=>({...U,[String(S)]:{..._,mode:A}})),children:R},A))}),i.jsxs("div",{className:"af-workspace-conflict-values",children:[i.jsxs("div",{className:_.mode==="local"?"is-selected":"",children:[i.jsx("span",{children:"我的修改"}),i.jsx("pre",{children:GC(x,"incoming")})]}),i.jsxs("div",{className:_.mode==="remote"?"is-selected":"",children:[i.jsx("span",{children:"远端修改"}),i.jsx("pre",{children:GC(x,"current")})]})]}),_.mode==="manual"?i.jsxs("label",{className:"af-workspace-conflict-manual",children:[i.jsx("span",{children:"最终值(JSON)"}),i.jsx("textarea",{value:_.manual,onChange:A=>ul(R=>({...R,[String(S)]:{..._,manual:A.target.value}})),rows:5})]}):null]},`${x.path||"conflict"}-${S}`)}),Bv?i.jsx("div",{className:"af-flow-snippet-error",children:Bv}):null]}),i.jsxs("div",{className:"af-flow-snippet-modal__foot af-workspace-conflict-foot",children:[i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",disabled:vf,onClick:()=>void h0(),children:"备份并载入远端"}),i.jsx("span",{className:"af-workspace-conflict-foot__spacer"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",disabled:vf,onClick:()=>ua(!1),children:"稍后处理"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",disabled:vf||!(En.conflictItems||[]).length,onClick:()=>void nL(),children:vf?"保存中...":"应用选择并保存"})]})]})}),document.body):null,Sn?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal",role:"dialog","aria-modal":"true","aria-label":"发布流程片段",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"ios_share"}),"发布流程片段"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>xr(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"名称"}),i.jsx("input",{type:"text",value:wn.name,onChange:x=>{const S=x.target.value;Xn(_=>({..._,name:S,id:_.id?_.id:S.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"")}))},placeholder:"例如:内容整理片段",autoFocus:!0})]}),i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"ID"}),i.jsx("input",{type:"text",value:wn.id,onChange:x=>Xn(S=>({...S,id:x.target.value})),placeholder:"content-cleanup-snippet"})]}),i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"说明"}),i.jsx("textarea",{value:wn.description,onChange:x=>Xn(S=>({...S,description:x.target.value})),placeholder:"这段流程适合什么 workspace 场景、需要接哪些上下游。",rows:4})]}),i.jsxs("div",{className:"af-flow-snippet-summary",children:["将发布 ",er.length," 个节点和 ",zf.length," 条内部连线。"]}),ts?i.jsx("div",{className:"af-flow-snippet-error",children:ts}):null]}),i.jsxs("div",{className:"af-flow-snippet-modal__foot",children:[i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",onClick:()=>xr(!1),children:"取消"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",disabled:Kn||!wn.name.trim(),onClick:()=>void Z$(),children:Kn?"发布中...":"发布"})]})]})}),document.body):null,t0?i.jsx(QG,{node:t0,onClose:()=>zn("")}):null,rr?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-share-modal",role:"dialog","aria-modal":"true","aria-label":wo?"新建分享":"发布展示页",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"present_to_all"}),wo?"新建分享":"发布展示页"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>Pr(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"标题"}),i.jsx("input",{type:"text",value:_t.title,onChange:x=>le(S=>({...S,title:x.target.value})),placeholder:"展示页标题",autoFocus:!0})]}),wo?null:i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"布局"}),i.jsxs("select",{className:"af-display-share-select",value:_t.layout,onChange:x=>le(S=>({...S,layout:x.target.value})),children:[i.jsx("option",{value:"gallery",children:"Gallery"}),i.jsx("option",{value:"document",children:"Document"}),i.jsx("option",{value:"slides",children:"Slides"})]})]}),i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"有效期"}),i.jsx("select",{className:"af-display-share-select",value:MC(_t),onChange:x=>{const S=x.target.value;le(_=>({..._,permanent:S==="permanent",expiresInDays:S==="permanent"?_.expiresInDays||30:Number(S)}))},children:aw.map(x=>i.jsx("option",{value:x.value,children:x.label},x.value))})]}),i.jsxs("div",{className:"af-display-share-node-list",role:"group","aria-label":wo?"分享内容":"选择展示节点",children:[wo?i.jsx("span",{className:"af-display-share-node-list__label",children:"分享内容"}):null,RL.map(x=>{var _;const S=Array.isArray(_t.nodeIds)&&_t.nodeIds.includes(x.id);return i.jsxs("label",{className:"af-display-share-node-row",children:[i.jsx("input",{type:"checkbox",checked:S,disabled:wo,onChange:()=>rL(x.id)}),i.jsxs("span",{className:"af-display-share-node-row__main",children:[i.jsx("strong",{children:((_=x.data)==null?void 0:_.label)||x.id}),i.jsxs("small",{children:[In(x.data)," · ",x.id]})]})]},x.id)})]}),Ct!=null&&Ct.absoluteUrl?i.jsxs("div",{className:"af-display-share-result",children:[i.jsx("input",{type:"text",readOnly:!0,value:Ct.absoluteUrl,onFocus:x=>x.target.select()}),i.jsx("button",{type:"button",onClick:()=>window.open(Ct.absoluteUrl,"_blank","noopener,noreferrer"),children:"打开"}),i.jsx("button",{type:"button",onClick:()=>void m0(),children:tn==="copied"?"已复制":tn==="failed"?"复制失败":"复制"})]}):null,br?i.jsx("div",{className:"af-flow-snippet-error",children:br}):null]}),i.jsxs("div",{className:"af-flow-snippet-modal__foot",children:[i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",onClick:()=>Pr(!1),children:"取消"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",disabled:dn||!Array.isArray(_t.nodeIds)||_t.nodeIds.length===0,onClick:()=>void iL(),children:dn?"生成中...":"生成链接"})]})]})}),document.body):null,Dt?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-link-modal",role:"dialog","aria-modal":"true","aria-label":"展示链接",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"link"}),"展示链接"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>{Zn(""),Jt(!1)},"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[Ct!=null&&Ct.absoluteUrl?i.jsxs("div",{className:"af-display-link-modal__url",children:[i.jsx("input",{type:"text",readOnly:!0,value:Ct.absoluteUrl,onFocus:x=>x.target.select(),autoFocus:!0}),i.jsxs("button",{type:"button",onClick:()=>window.open(Ct.absoluteUrl,"_blank","noopener,noreferrer"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"}),"打开"]}),i.jsxs("button",{type:"button",onClick:()=>void m0(),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:tn==="copied"?"check":"content_copy"}),tn==="copied"?"已复制":tn==="failed"?"复制失败":"复制"]})]}):i.jsx("div",{className:"af-display-link-modal__empty",children:"还没有生成展示链接"}),i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"新链接有效期"}),i.jsx("select",{className:"af-display-share-select",value:MC(_t),onChange:x=>{const S=x.target.value;le(_=>({..._,permanent:S==="permanent",expiresInDays:S==="permanent"?_.expiresInDays||30:Number(S)}))},children:aw.map(x=>i.jsx("option",{value:x.value,children:x.label},x.value))})]}),br?i.jsx("div",{className:"af-flow-snippet-error",children:br}):null]}),i.jsxs("div",{className:"af-flow-snippet-modal__foot",children:[i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",onClick:()=>{Zn(""),Jt(!1)},children:"关闭"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",disabled:dn||P.nodeIds.length===0,onClick:()=>void oL(),children:dn?"生成中...":Ct!=null&&Ct.absoluteUrl?"更新链接":"生成链接"})]})]})}),document.body):null,d$?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-share-modal",role:"dialog","aria-modal":"true","aria-label":"协作分享",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"group_add"}),"协作分享"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>yg(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsx("p",{className:"af-display-link-modal__empty",children:"输入已注册用户名。添加后,这个 Workspace 会直接出现在对方的项目列表中。"}),i.jsxs("div",{className:"af-workspace-member-add",children:[i.jsx("input",{type:"text",value:Gc,onChange:x=>Ov(x.target.value),onKeyDown:x=>{x.key==="Enter"&&Gc.trim()&&!wg&&(x.preventDefault(),p0())},placeholder:"输入用户名",autoFocus:!0}),i.jsx("button",{type:"button",disabled:wg||!Gc.trim(),onClick:()=>void p0(),children:wg?"添加中...":"添加成员"})]}),Lv?i.jsx("div",{className:"af-flow-snippet-error",children:Lv}):null,i.jsx("div",{className:"af-workspace-member-list",children:((an==null?void 0:an.members)||[]).map(x=>{const S=x.userId===(an==null?void 0:an.ownerId)||x.role==="owner";return i.jsxs("div",{className:"af-workspace-member-row",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:S?"shield_person":"person"}),i.jsxs("div",{children:[i.jsx("strong",{children:x.username||x.userId}),i.jsx("small",{children:S?"所有者":x.role==="viewer"?"只读成员":"编辑成员"})]}),S?null:i.jsx("button",{type:"button",disabled:Dv===x.userId,onClick:()=>void tL(x),children:Dv===x.userId?"移除中...":"取消分享"})]},x.userId)})})]}),i.jsx("div",{className:"af-flow-snippet-modal__foot",children:i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",onClick:()=>yg(!1),children:"完成"})})]})}),document.body):null,mt?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-shares-modal",role:"dialog","aria-modal":"true","aria-label":"我的分享",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"folder_shared"}),"我的分享"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>nn(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("div",{className:"af-display-shares-toolbar",children:[i.jsx("span",{children:Wt.length?`${Wt.length} 个分享`:"暂无分享"}),i.jsxs("button",{type:"button",onClick:()=>void zs(),disabled:tt,children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"refresh"}),"刷新"]})]}),$i?i.jsx("div",{className:"af-flow-snippet-error",children:$i}):null,tt?i.jsx("div",{className:"af-display-link-modal__empty",children:"Loading..."}):null,!tt&&Wt.length===0?i.jsx("div",{className:"af-display-link-modal__empty",children:"还没有创建过展示分享"}):null,i.jsx("div",{className:"af-display-shares-list",children:Wt.map(x=>{const S=LC(x),_=mo===x.id,A=x.expiresAt?String(x.expiresInDays||30):"permanent";return i.jsxs("article",{className:"af-display-share-item",children:[i.jsxs("div",{className:"af-display-share-item__main",children:[i.jsx("strong",{children:x.title||"AgentFlow Display"}),i.jsxs("span",{children:[x.flowId||"-"," · ",x.layout||"gallery"," · ",Array.isArray(x.nodeIds)?x.nodeIds.length:0," nodes"]}),i.jsx("small",{children:TG(x)})]}),i.jsx("input",{className:"af-display-share-item__url",type:"text",readOnly:!0,value:S,onFocus:R=>R.target.select()}),i.jsx("select",{className:"af-display-share-select",value:A,disabled:_,onChange:R=>void lL(x,R.target.value),"aria-label":"修改分享有效期",children:aw.map(R=>i.jsx("option",{value:R.value,children:R.label},R.value))}),i.jsxs("div",{className:"af-display-share-item__actions",children:[i.jsxs("button",{type:"button",onClick:()=>window.open(S,"_blank","noopener,noreferrer"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"}),"打开"]}),i.jsxs("button",{type:"button",onClick:()=>void aL(x),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:Ts===x.id?"check":"content_copy"}),Ts===x.id?"已复制":"复制"]}),i.jsxs("button",{type:"button",className:"af-display-share-item__danger",disabled:_,onClick:()=>void cL(x),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:_?"hourglass_empty":"link_off"}),"撤销"]})]})]},x.id)})})]})]})}),document.body):null,Se?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-picker-modal",role:"dialog","aria-modal":"true","aria-label":"选择展示节点",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add_to_photos"}),"选择展示节点"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>Pe(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("label",{className:"af-display-picker-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:xt,onChange:x=>Lt(x.target.value),placeholder:"搜索展示节点...",autoFocus:!0})]}),i.jsx("div",{className:"af-display-picker-grid",role:"group","aria-label":"选择展示节点",style:{"--af-display-picker-columns":u0.length||1},children:Bf.length>0?u0.map((x,S)=>i.jsx("div",{className:"af-display-picker-column",children:x.map(X$)},`display-picker-column-${S}`)):i.jsx("div",{className:"af-display-picker-empty",children:kl.length===0?"当前 Workspace 没有 display 节点":"没有匹配的展示节点"})})]}),i.jsx("div",{className:"af-flow-snippet-modal__foot",children:i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",onClick:()=>Pe(!1),children:"完成"})})]})}),document.body):null,Xc.nodeId?cr.createPortal(i.jsx(yJ,{files:ll,query:Xc.query,onQueryChange:x=>Sg(S=>({...S,query:x})),onSelect:B$,onUpload:qS,onClose:zg}),document.body):null,!ut&&!Pn&&On?cr.createPortal(i.jsx("div",{className:"af-workspace-quick-add-backdrop",onMouseDown:()=>q(!1),children:i.jsxs("div",{className:"af-workspace-quick-add",role:"dialog","aria-modal":"true","aria-label":"Add workspace node",onMouseDown:x=>x.stopPropagation(),children:[i.jsxs("div",{className:"af-workspace-quick-add__tabs",role:"tablist","aria-label":"选择添加类型",children:[i.jsx("button",{type:"button",role:"tab","aria-selected":pe==="nodes",className:"af-workspace-quick-add__tab"+(pe==="nodes"?" af-workspace-quick-add__tab--active":""),onClick:()=>Oe("nodes"),children:"节点"}),i.jsx("button",{type:"button",role:"tab","aria-selected":pe==="flows",className:"af-workspace-quick-add__tab"+(pe==="flows"?" af-workspace-quick-add__tab--active":""),onClick:()=>Oe("flows"),children:"流程"})]}),i.jsxs("div",{className:"af-workspace-quick-add__search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{ref:lS,value:Ee,onChange:x=>et(x.target.value),onKeyDown:x=>{if(x.key==="Escape")x.preventDefault(),q(!1);else if(x.key==="ArrowDown"){x.preventDefault();const S=pe==="flows"?mu.length:hu.length;kt(_=>Math.min(Math.max(0,S-1),_+1))}else x.key==="ArrowUp"?(x.preventDefault(),kt(S=>Math.max(0,S-1))):x.key==="Tab"?(x.preventDefault(),Oe(S=>S==="nodes"?"flows":"nodes")):x.key==="Enter"&&(x.preventDefault(),pe==="flows"?y0(mu[Nn]||mu[0]):g0(hu[Nn]||hu[0]))},placeholder:pe==="flows"?"搜索流程片段...":"搜索节点...","aria-label":pe==="flows"?"搜索流程片段":"搜索节点"})]}),i.jsx("div",{className:"af-workspace-quick-add__list",children:pe==="flows"?mu.length===0?i.jsx("div",{className:"af-workspace-quick-add__empty",children:Ze?"正在加载流程片段...":At||"没有匹配的流程片段"}):mu.map((x,S)=>{const _=x.displayName||x.name||x.id,A=x.snippet&&typeof x.snippet=="object"?x.snippet.instances:null,R=x.snippet&&typeof x.snippet=="object"?x.snippet.edges:null,U=Number.isFinite(Number(x.nodeCount))?Number(x.nodeCount):Object.keys(A||{}).length,X=Number.isFinite(Number(x.edgeCount))?Number(x.edgeCount):Array.isArray(R)?R.length:0;return i.jsxs("button",{type:"button",className:"af-workspace-quick-add__item"+(S===Nn?" af-workspace-quick-add__item--active":""),onMouseEnter:()=>kt(S),onClick:()=>y0(x),children:[i.jsx("span",{className:"af-workspace-quick-add__icon material-symbols-outlined","aria-hidden":!0,children:"schema"}),i.jsxs("span",{className:"af-workspace-quick-add__main",children:[i.jsx("span",{className:"af-workspace-quick-add__label",children:_}),i.jsxs("span",{className:"af-workspace-quick-add__meta",children:[x.id,x.version?` · v${x.version}`:""]}),i.jsx("span",{className:"af-workspace-quick-add__desc",children:x.description||`${U} 节点 / ${X} 连线`})]}),i.jsx("span",{className:"af-workspace-quick-add__cat",children:"FLOW"})]},`${x.id}@${x.version}`)}):hu.length===0?i.jsx("div",{className:"af-workspace-quick-add__empty",children:"没有匹配的节点"}):hu.map((x,S)=>{const _=Wu(x),A=Vu(x),R=ub(x);return i.jsxs("button",{type:"button",className:"af-workspace-quick-add__item"+(S===Nn?" af-workspace-quick-add__item--active":""),onMouseEnter:()=>kt(S),onClick:()=>g0(x),children:[i.jsx("span",{className:"af-workspace-quick-add__icon material-symbols-outlined","aria-hidden":!0,children:_C(_)}),i.jsxs("span",{className:"af-workspace-quick-add__main",children:[i.jsx("span",{className:"af-workspace-quick-add__label",children:A}),i.jsx("span",{className:"af-workspace-quick-add__meta",children:x.id}),R?i.jsx("span",{className:"af-workspace-quick-add__desc",children:R}):null]}),i.jsx("span",{className:"af-workspace-quick-add__cat",children:_})]},x.id)})})]})}),document.body):null]})]})}function DJ(){return i.jsx(Fk,{children:i.jsx(OJ,{})})}function FJ(e){const t=[...(e==null?void 0:e.inputs)||[],...(e==null?void 0:e.outputs)||[]],n=(e==null?void 0:e.kind)==="image"?"src":"content",r=a=>String((a==null?void 0:a.value)??(a==null?void 0:a.default)??""),s=a=>r(a).trim(),o=t.find(a=>(a==null?void 0:a.name)===n&&s(a))||t.find(a=>(a==null?void 0:a.name)==="filePath"&&s(a))||t.find(a=>(a==null?void 0:a.type)==="text"&&s(a));return String((e==null?void 0:e.body)||(o?r(o):""))}function zJ(e){return e==="mermaid"?"account_tree":e==="ascii"?"notes":e==="html"?"html":e==="react"?"deployed_code":e==="image"?"image":e==="chart"?"bar_chart":e==="table"?"table":"article"}function BJ(e){let t=String(e||"").replace(/\r\n/g,`
262
+ ${ae.trim()}`:ae,Ne=X==="image"?"src":"content",We=A!=null&&A.reloadDisplay?Date.now():(Ye=U==null?void 0:U.data)==null?void 0:Ye.displayReloadKey,ze=Le=>{let Mt=!1;return(Array.isArray(Le)?Le:[]).map(dt=>{const Pt=String((dt==null?void 0:dt.name)||""),_l=String((dt==null?void 0:dt.type)||"");return(J?Pt===Ne||Pt==="result"||Pt==="filePath":Pt===Ne||Pt==="filePath"||_l==="text")?Mt?{...dt,default:"",value:""}:(Mt=!0,{...dt,default:fe,value:fe}):dt})},Ve=N.current.map(Le=>{var Mt,De;return Le.id!==R?Le:{...Le,data:{...Le.data,body:J?Le.data.body:fe,...We?{displayReloadKey:We}:{},inputs:ze((Mt=Le.data)==null?void 0:Mt.inputs),outputs:ze((De=Le.data)==null?void 0:De.outputs)}}}),He=Z.current||{},Me=He[R]&&typeof He[R]=="object"?He[R]:{},Ft={...He,[R]:{...Me,body:J?Me.body:fe,input:ze(Me.input),output:ze(Me.output)}};Z.current=Ft,g(Ve),ne(Ft),ws(Le=>(Le==null?void 0:Le.id)===R?{...Le,...J?{}:{body:fe}}:Le),(A==null?void 0:A.logChat)!==!1&&yo(Le=>{var Mt;return{...Le,[R]:{...Le[R]||{},candidateContent:"",messages:[...(Mt=Le[R])!=null&&Mt.messages&&Array.isArray(Le[R].messages)?Le[R].messages:[],{role:"assistant",text:_==="append"?"已追加到当前节点内容。":"已替换当前节点内容。",at:Date.now()}]}}}),Zt(Ve,j.current).catch(Le=>ge(String(Le.message||Le))),ge(String((A==null?void 0:A.statusMessage)||"")||(_==="append"?"已追加节点内容":"已替换节点内容"))},[Zt,g,je]),$f=m.useCallback(async(x,S="")=>{if(!je)return ge("Readonly workspace"),"";if(!x)return"";try{const _=new FormData;_.set("file",x),_.set("dir",String(S||"")),a.flowId&&_.set("flowId",a.flowId),a.flowSource&&_.set("flowSource",a.flowSource),a.archived&&_.set("archived","1");const A=await fetch("/api/workspace/upload",{method:"POST",body:_}),R=await A.json().catch(()=>({}));if(!A.ok)throw new Error(R.error||"上传文件失败");const U=String(R.path||"").trim();if(!U)throw new Error("上传文件失败:未返回路径");return await An(),dl(X=>{const J=new Set(X);for(const Y of Dp(U))J.delete(Y);return J}),ge(`已上传 ${U}`),U}catch(_){return ge(String(_.message||_)),""}},[a,An,je]),Lf=m.useCallback(async x=>cm(x)?$f(x,"img"):(ge("请选择图片文件"),""),[$f]),qS=m.useCallback((x="")=>{var S;if(!je){ge("Readonly workspace");return}Kv.current=String(x||""),(S=Vv.current)==null||S.click()},[je]),z$=m.useCallback(async x=>{const S=Array.from(x.target.files||[]);if(x.target.value="",!S.length)return;const _=Kv.current||"";Wv(!0);try{let A="";for(const R of S){const U=await $f(R,_);U&&(A=U)}S.length>1&&ge(`已上传 ${S.length} 个文件${A?`,最后一个:${A}`:""}`)}catch(A){ge(String(A.message||A))}finally{Wv(!1)}},[$f]),US=m.useCallback(async(x,S)=>{const _=String(x||"").trim();if(!_)return;const A=await Lf(S);A&&Fs(_,A,"replace",{logChat:!1,statusMessage:`已上传图片 ${A}`})},[Fs,Lf]),YS=m.useCallback(async(x,S=void 0)=>{var ze,Ve;if(!je){ge("Readonly workspace");return}const _=String(x||"").trim();if(!_)return;const A=ha[_]||{},R=String(S!==void 0?S:A.draft||"").trim();if(!R||A.running)return;const U=N.current.find(He=>He.id===_);if(!U)return;const X=In(U.data)||"markdown",J=no(U.data);let Y=ea(J,X),ae=Ei(J);if(Y)try{ae=await nl(a,Y)}catch(He){ge(String(He.message||He))}else if(X!=="image"&&String(ae||"").trim()){const He=Ma(X,ae);if(He){ge(`${He} 未进入微调。`);return}try{const Me=await hb(a,FC(_,U.data),ae);await An(),Fs(_,Me,"replace",{logChat:!1,reloadDisplay:!0,statusMessage:`已将展示保存为 ${Me}`}),Y=Me,ae=""}catch(Me){ge(String(Me.message||Me));return}}const pe=HG(_,N.current,j.current),fe={role:"user",text:R,at:Date.now()},Ne=Array.isArray(A.messages)?A.messages:[],We=A.sessionId||`nodechat_${Date.now()}_${_.replace(/[^a-z0-9_-]+/gi,"_")}`;yo(He=>({...He,[_]:{...A,sessionId:We,messages:[...Ne,fe],draft:"",running:!0,error:""}}));try{const He=await fetch("/api/workspace/node-chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,sessionId:We,node:{id:_,label:((ze=U.data)==null?void 0:ze.label)||_,definitionId:((Ve=U.data)==null?void 0:Ve.definitionId)||""},nodeKind:X,currentContent:Y?"":ae,sourceContext:pe,targetFilePath:Y,messages:Ne,message:R,model:Li})}),Me=await He.json().catch(()=>({}));if(!He.ok)throw new Error(Me.error||"节点微调失败");const Ft=String(Me.candidateContent||Me.reply||"").trim(),rt=!!Me.directFileEdit,Ye=String(Me.artifactPath||Y||"").trim();if(rt&&Ye){const Le=Ma(X,Ft);if(Le)throw new Error(`${Le} 文件已由 agent 修改,请检查 ${Ye}。`);await An(),Fs(_,Ye,"replace",{logChat:!1,reloadDisplay:!0,statusMessage:`已按微调描述更新 ${Ye}`})}else if(Ft){const Le=Ma(X,Ft);if(Le)throw new Error(`${Le} 已取消写入,避免覆盖当前展示文件。`);if(Y){const Mt=await hb(a,Y,Ft);await An(),Fs(_,Mt,"replace",{logChat:!1,statusMessage:`已按微调描述更新 ${Mt}`})}else Fs(_,Ft,"replace",{logChat:!1,statusMessage:"已按微调描述更新展示内容"})}yo(Le=>{var Mt;return{...Le,[_]:{...Le[_]||{},sessionId:String(Me.sessionId||We),running:!1,candidateContent:"",messages:[...(Mt=Le[_])!=null&&Mt.messages&&Array.isArray(Le[_].messages)?Le[_].messages:[...Ne,fe],{role:"assistant",text:Ft||rt?Ye?`已更新文件 ${Ye}。`:"已按你的描述更新当前展示。":"没有生成可更新的内容。",at:Date.now()}]}}})}catch(He){const Me=String(He.message||He);yo(Ft=>({...Ft,[_]:{...Ft[_]||{},running:!1,error:Me}})),ge(Me)}},[Li,a,An,ha,Fs,je]),GS=m.useCallback(async(x,S)=>{if(!je){ge("Readonly workspace");return}const _=In(S)||"markdown",A=no(S),R=ea(A,_);let U=Ei(A);if(R)try{U=await nl(a,R)}catch(ae){ge(String(ae.message||ae));return}if(!String(U||"").trim()){ge("展示节点没有可保存内容");return}const X=Ma(_,U);if(X){ge(`${X} 未保存文件。`);return}const J=FC(x,S),Y=window.prompt("保存到 workspace 相对路径",J);if(Y)try{const ae=await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:Y,content:U})}),pe=await ae.json().catch(()=>({}));if(!ae.ok)throw new Error(pe.error||"保存文件失败");const fe=pe.path||Y,Ne=Tr(a);Ne.set("path",fe);const We=await fetch(`/api/workspace/file?${Ne.toString()}`);if(!We.ok){const ze=await We.json().catch(()=>({}));throw new Error(ze.error||`保存后读取失败:${fe}`)}await An(),Tv(ze=>mJ(ze,fe,String(U||"").length)),dl(ze=>{const Ve=new Set(ze);for(const He of Dp(fe))Ve.delete(He);return Ve}),Fs(x,fe,"replace",{logChat:!1,statusMessage:`已保存并引用 ${fe}`}),ge(`已保存 ${fe}`)}catch(ae){ge(String(ae.message||ae))}},[a,An,Fs,je]),JS=m.useCallback(x=>{var R,U;const S=String(x||"").trim();if(!S||ve)return;const _=N.current.find(X=>X.id===S);if(!_||!In(_==null?void 0:_.data)){ge("展示节点不可用");return}const A=String(((R=_.data)==null?void 0:R.label)||((U=_.data)==null?void 0:U.displayName)||S).trim()||"AgentFlow Display";le(lw({title:A,layout:"single",nodeIds:[S],mode:"single-node",sourceNodeId:S})),sr(""),Gt(null),Pr(!0)},[ve]),Of=m.useCallback((x,S)=>{const _=String(x||"");_&&ws(A=>{if(!A||A.id!==_)return A;const R=typeof S=="function"?S(A):S;return!R||typeof R!="object"?A:{...A,...R}})},[]),XS=m.useCallback((x,S)=>{const _=String(x||"");!_||!je||(g(A=>A.map(R=>{var X;if(R.id!==_)return R;const U=Array.isArray((X=R.data)==null?void 0:X.outputs)&&R.data.outputs.length?R.data.outputs.map((J,Y)=>Y===0?{...J,default:S,value:S}:J):[{type:"file",name:"value",default:S,value:S}];return{...R,data:{...R.data,body:"",outputs:U}}})),Of(_,A=>({body:"",outputs:Array.isArray(A==null?void 0:A.outputs)&&A.outputs.length?A.outputs.map((U,X)=>X===0?{...U,default:S,value:S}:U):[{type:"file",name:"value",default:S,value:S}]})),ge(`已选择文件 ${S}`))},[g,Of,je]),QS=m.useCallback(x=>{Sg({nodeId:String(x||""),query:""})},[]),zg=m.useCallback(()=>{Sg({nodeId:"",query:""})},[]),B$=m.useCallback(x=>{const S=String((x==null?void 0:x.path)||"").trim();!S||!Xc.nodeId||(XS(Xc.nodeId,S),zg())},[zg,Xc.nodeId,XS]),ZS=m.useCallback(async(x,S)=>{if(!je)return;const _=sJ(x,S);if(_.length===0)return;const A=[];try{for(const R of _){const U=await fetch("/api/workspace/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:R})});if(U.status===404)continue;const X=await U.json().catch(()=>({}));if(!U.ok)throw new Error(X.error||"清理节点输出失败");A.push(X.path||R)}if(A.length===0)return;ge(`已清理 ${A.join(", ")}`),await An(),vg(R=>_.some(U=>R===U||R.startsWith(`${U}/`))?"":R)}catch(R){ge(String(R.message||R))}},[a,An,je]),fu=m.useMemo(()=>({modelLists:da,showBodyPreview:!0,flowParams:a,readOnly:!je,onRunWorkspaceNode:$S,onStopWorkspaceNode:MS,onOpenWorkspaceRunLogs:TS,onOptimizeWorkspaceRun:Fg,onOptimizeWorkspaceSchedule:Fg,runningRunNodeIds:_S,onChangeScheduledRunConfig:HS,onChangeContextRunConfig:BS,skills:Ms,skillCollections:fl,onChangeLoadSkillKeys:DS,onRefreshSkills:Rf,mcpServers:Xv,onChangeLoadMcpNames:FS,onRefreshMcps:Tf,workspaceTargets:Zv,onChangeLoadWorkspace:zS,onRefreshWorkspaces:Mf,onSaveDisplayNodeToFile:GS,onShareDisplayNode:JS,onOpenDisplayPreview:zn,onRefreshNodeInternals:Br,onEnsureWorkspaceNodeDisplaySize:iS,sharingDisplayNodeId:ve,onUploadWorkspaceImage:Lf,onUploadImageToDisplayNode:US,onOpenProvideFilePicker:QS,onStatus:ge,onSetDisplayNodeContent:Fs,onToggleNodeChat:WS,onCloseNodeChat:VS,onUpdateNodeChatDraft:KS,onSendNodeChat:YS,onSyncNodePropDraft:Of,onCleanupWorkspaceNodeOutputs:ZS}),[BS,FS,DS,zS,HS,ZS,VS,iS,a,Xv,da,QS,TS,Fg,Tf,Br,Rf,Mf,$S,_S,GS,YS,Fs,JS,ve,fl,Ms,MS,Of,WS,KS,US,Lf,Zv,je]),H$=m.useRef(new Map),rs=m.useMemo(()=>{const x=H$.current,S=new Set,_=b.map(A=>{var Y,ae,pe;const R={selected:A.selected===!0,isExecuting:bS.has(A.id),nodeStatus:((Y=Dg[A.id])==null?void 0:Y.status)??null,nodeElapsed:((ae=Dg[A.id])==null?void 0:ae.elapsed)??null,optimizingRun:kS===A.id,scheduledRunState:xS[A.id]||null,nodeChatActive:dS===A.id,nodeChat:ha[A.id]||null},U=x.get(A.id);if(U&&U.source===A&&U.commonData===fu&&IC(U.runtime,R))return S.add(A.id),U.node;const X=!!(U&&((pe=U.source)==null?void 0:pe.data)===A.data&&U.commonData===fu&&IC(U.runtime,R)),J={...A,data:X?U.node.data:{...A.data,...fu,...R}};return x.set(A.id,{source:A,commonData:fu,runtime:R,node:J}),S.add(A.id),J});for(const A of x.keys())S.has(A)||x.delete(A);return _},[dS,fu,ha,b,kS,xS,bS,Dg]),ut=d==="display",Pn=d==="workflow",e0=m.useMemo(()=>ut?new Map(rs.map(x=>[x.id,x])):IG,[rs,ut]),t0=m.useMemo(()=>qt&&rs.find(x=>x.id===qt)||null,[qt,rs]),n0=m.useRef(new Map),pu=m.useMemo(()=>{if(!ut)return n0.current.clear(),RG;const x=new Set(M),S=n0.current,_=new Set,A=P.nodeIds.map((R,U)=>{var We,ze,Ve,He;const X=e0.get(R);if(!X||!In(X.data))return null;const J=Fl(X)||{width:520,height:320},Y=za(P.nodeSizes[R]||J,{display:!0})||J,ae=P.nodePositions[R]||{x:180+U*36,y:120+U*28},pe=x.has(R),fe=S.get(R);if(fe&&fe.source===X&&((We=fe.position)==null?void 0:We.x)===ae.x&&((ze=fe.position)==null?void 0:ze.y)===ae.y&&((Ve=fe.size)==null?void 0:Ve.width)===Y.width&&((He=fe.size)==null?void 0:He.height)===Y.height&&fe.selected===pe)return _.add(R),fe.node;const Ne={...X,id:RC(R),position:ae,selected:pe,width:Y.width,height:Y.height,data:{...X.data,sourceNodeId:R,displayPageMode:!0,readOnly:!0,selected:pe,displaySize:Y,nodeSize:Y}};return S.set(R,{source:X,position:ae,size:Y,selected:pe,node:Ne}),_.add(R),Ne}).filter(Boolean);for(const R of S.keys())_.has(R)||S.delete(R);return A},[P,e0,ut,M]),kl=m.useMemo(()=>rs.filter(x=>In(x==null?void 0:x.data)),[rs]);m.useEffect(()=>{if(!ut||!P.viewport)return;const x=P.viewport,S=()=>{try{r.setViewport(x,{duration:0})}catch{}},_=window.requestAnimationFrame(()=>window.requestAnimationFrame(S));return()=>window.cancelAnimationFrame(_)},[P.viewport,ut,r]),m.useEffect(()=>{if(ut||Pn||!$)return;const x=$,S=()=>{try{r.setViewport(x,{duration:0})}catch{}},_=window.requestAnimationFrame(()=>window.requestAnimationFrame(S));return()=>window.cancelAnimationFrame(_)},[ut,Pn,r,$]),m.useEffect(()=>{Pn&&uu(ir)},[Pn]),m.useEffect(()=>{if(!Pn||!ir)return;const x=Tr(a);x.set("tapdId",ir);let S=null,_=null,A=!1;const R=()=>{_&&(window.clearTimeout(_),_=null),S&&(S.onmessage=null,S.onerror=null,S.close(),S=null)},U=()=>{A||document.hidden||S||(S=new EventSource(`/api/prd-workflow/events?${x.toString()}`),S.onmessage=()=>{uu(ir)},S.onerror=()=>{R(),!A&&!document.hidden&&(_=window.setTimeout(U,5e3))})},X=()=>{if(document.hidden){R();return}uu(ir),U()};return U(),document.addEventListener("visibilitychange",X),()=>{A=!0,document.removeEventListener("visibilitychange",X),R()}},[a,Pn,uu,ir]),m.useEffect(()=>{if(!a.flowId||Pn)return;const x=Tr(a);x.set("clientId",ke.current);let S=null,_=null,A=!1;const R=()=>{_&&(window.clearTimeout(_),_=null),S&&(S.onmessage=null,S.onerror=null,S.close(),S=null)},U=()=>{A||document.hidden||S||(S=new EventSource(`/api/workspace/events?${x.toString()}`),S.onmessage=J=>{let Y=null;try{Y=JSON.parse(J.data||"{}")}catch{Y=null}if(!(!Y||Y.clientId===ke.current)){if(Y.type==="graph.committed"){Pf(Y);return}if(Y.type==="runtime.committed"){Pf(Y);return}if(String(Y.type||"").startsWith("file.")){An();return}String(Y.type||"").startsWith("run.")&&If()}},S.onerror=()=>{R(),!A&&!document.hidden&&(_=window.setTimeout(U,5e3))})},X=()=>{if(document.hidden){R();return}Pf({type:"visibility.resume"}),U()};return U(),document.addEventListener("visibilitychange",X),()=>{A=!0,document.removeEventListener("visibilitychange",X),R(),Te.current&&(window.clearTimeout(Te.current),Te.current=null),gt.current=!1}},[a,Pn,An,If,Pf]),m.useEffect(()=>{if(lt.current)return;const x=D.current,S=new Map,_=[];for(const A of[...rs,...pu]){const R=PG(A);S.set(A.id,R),x.get(A.id)!==R&&_.push(A.id)}D.current=S,_.length!==0&&Br(_)},[pu,rs,Br]);const Vt=m.useMemo(()=>b.find(x=>x.id===Ut)||null,[b,Ut]),Bg=m.useRef({id:"",draft:null}),W$=m.useMemo(()=>{const x=KC(Vt);return x?JSON.stringify(x):""},[Vt==null?void 0:Vt.data,Vt==null?void 0:Vt.id]);m.useEffect(()=>{if(!Vt){Bg.current={id:"",draft:null},ws(null),al("");return}const x=KC(Vt),S=Bg.current;Bg.current={id:Vt.id,draft:x},ws(_=>!_||_.id!==Vt.id||S.id!==Vt.id||!S.draft?x:EJ(_,S.draft,x)),al("")},[Vt==null?void 0:Vt.id,W$]);const Hg=m.useCallback((x=!1)=>{if(!at||!Vt)return!1;if(!je)return al("Readonly workspace"),ge("Readonly workspace"),!1;al("");const S=YC({nodes:b,edges:v,instances:Z.current,selectedNode:Vt,draft:at,allowRename:x});return S!=null&&S.error?(al(S.error),!1):(!(S!=null&&S.ok)||!S.changed||(Z.current=S.instances,ne(S.instances),g(S.nodes),w(S.edges),S.nextId!==Vt.id&&jn(S.nextId),Br(S.nextId)),!0)},[v,at,b,Vt,w,g,Br,je]);m.useEffect(()=>{if(!je||!at||!Vt)return;const x=window.setTimeout(()=>{Hg(!1)},350);return()=>window.clearTimeout(x)},[at==null?void 0:at.label,at==null?void 0:at.role,at==null?void 0:at.model,at==null?void 0:at.body,JSON.stringify((at==null?void 0:at.images)||[]),at==null?void 0:at.script,at==null?void 0:at.scriptRef,at==null?void 0:at.implementationRef,at==null?void 0:at.implementationMode,JSON.stringify((at==null?void 0:at.inputs)||[]),JSON.stringify((at==null?void 0:at.outputs)||[]),Hg,Vt==null?void 0:Vt.id,je]);const r0=m.useRef({refs:new Map,nodeDataById:new Map}),Wg=m.useMemo(()=>{const x=r0.current;let S=x.refs.size!==b.length;const _=new Map;for(const R of b)_.set(R.id,R.data),(!x.refs.has(R.id)||x.refs.get(R.id)!==R.data)&&(S=!0);if(!S)return x.nodeDataById;const A=new Map(b.map(R=>[R.id,R.data]));return r0.current={refs:_,nodeDataById:A},A},[b]),V$=m.useMemo(()=>v.map(x=>{var Y,ae;const S=Wg.get(x.source),_=Wg.get(x.target),A=/^output-(\d+)$/.exec(x.sourceHandle||""),R=/^input-(\d+)$/.exec(x.targetHandle||""),U=S&&A?(Y=S.outputs)==null?void 0:Y[parseInt(A[1],10)]:null,X=_&&R?(ae=_.inputs)==null?void 0:ae[parseInt(R[1],10)]:null,J=U!=null&&U.type?Tn(U.type):X!=null&&X.type?Tn(X.type):"";return J?{...x,style:{...x.style||{},stroke:J,strokeWidth:2},markerEnd:{type:bi.ArrowClosed,color:J}}:x}),[Wg,v]),Df=ut?pu:rs,K$=ut?[]:V$,s0=m.useRef(Df),vl=m.useRef([]);lt.current||(s0.current=Df);const q$=m.useMemo(()=>ut?pu.map(x=>({...x,id:Op(x.id)})):rs,[pu,rs,ut]),Vg=m.useCallback(x=>{const S=String(x||"").trim();if(!S)return;const _=ut?RC(S):S;ut?K([S]):(g(R=>R.map(U=>({...U,selected:U.id===_}))),w(R=>R.map(U=>({...U,selected:!1}))),jn(_));const A=()=>{var ae,pe,fe;const R=r.getNode(_);if(!R)return;const U=(ae=r.getInternalNode)==null?void 0:ae.call(r,_),X=((pe=U==null?void 0:U.measured)==null?void 0:pe.width)??(U==null?void 0:U.width)??R.width??260,J=((fe=U==null?void 0:U.measured)==null?void 0:fe.height)??(U==null?void 0:U.height)??R.height??120,{zoom:Y}=r.getViewport();r.setCenter(R.position.x+X/2,R.position.y+J/2,{zoom:DG(Y),duration:240})};window.requestAnimationFrame(()=>window.requestAnimationFrame(A))},[ut,r,w,g]);m.useEffect(()=>{const x=String(c.current||"").trim();!x||!ce.current||d!=="workspace"||rs.some(S=>S.id===x)&&(c.current="",Fe.current=!0,Vg(x))},[rs,Vg,d]);const i0=m.useCallback(()=>{const x=r.getViewport(),S={x:Number(x.x)||0,y:Number(x.y)||0,zoom:Math.min(Math.max(Number(x.zoom)||1,.1),4)};if(ut){const _={...z.current,viewport:S};z.current=_,I(_),ge("已固定 Display 进入视角")}else{F.current=S,L(S);try{window.localStorage.setItem(u,JSON.stringify(S))}catch{}ge("已固定 Workspace 进入视角");return}Zt(N.current,j.current).catch(_=>ge(String(_.message||_)))},[ut,r,Zt,u]),Kg=m.useMemo(()=>{const x=jt.trim().toLowerCase(),S={DISPLAY:[],CONTROL:[],TOOL:[],PROVIDE:[],AGENT:[]};for(const _ of be)x&&![_.id,_.label,_.displayName,_.description].some(A=>String(A||"").toLowerCase().includes(x))||S[Wu(_)].push(_);for(const _ of Ol)S[_].sort((A,R)=>A.id.localeCompare(R.id));return S},[be,jt]),hu=m.useMemo(()=>{const x=Ee.trim().toLowerCase();return be.filter(S=>!x||[S.id,S.label,S.displayName,S.description].some(_=>String(_||"").toLowerCase().includes(x))).sort((S,_)=>{const A=Ol.indexOf(Wu(S)),R=Ol.indexOf(Wu(_));return A!==R?A-R:Vu(S).localeCompare(Vu(_))}).slice(0,30)},[be,Ee]),mu=m.useMemo(()=>{const x=Ee.trim().toLowerCase();return Re.filter(S=>!x||[S.id,S.version,S.displayName,S.name,S.description,...Array.isArray(S.tags)?S.tags:[]].some(_=>String(_||"").toLowerCase().includes(x))).sort((S,_)=>String(S.displayName||S.name||S.id).localeCompare(String(_.displayName||_.name||_.id))).slice(0,30)},[Re,Ee]);m.useEffect(()=>{kt(0)},[Ee,On,he]),m.useEffect(()=>{if(!On)return;const x=window.setTimeout(()=>{var S;return(S=lS.current)==null?void 0:S.focus()},0);return()=>window.clearTimeout(x)},[On]);const U$=m.useMemo(()=>{const x=bg.trim().toLowerCase();return x?yv(ll).filter(S=>S.path.toLowerCase().includes(x)):ll},[bg,ll]),ya=m.useMemo(()=>nM(ll,kg),[ll,kg]),Fi=(ya==null?void 0:ya.type)==="directory"?ya.path:dJ((ya==null?void 0:ya.path)||""),Y$=m.useCallback(x=>{var S,_;(_=(S=x.target)==null?void 0:S.closest)!=null&&_.call(S,".af-work-file")||vg("")},[]),G$=[...(da.cursor||[]).map(x=>({label:`Cursor · ${x.split(" - ")[0]}`,value:`cursor:${x.split(" - ")[0]}`})),...(da.opencode||[]).map(x=>({label:`OpenCode · ${x.split(" - ")[0]}`,value:`opencode:${x.split(" - ")[0]}`})),...(da.claudeCode||[]).map(x=>({label:`Claude · ${x.split(" - ")[0]}`,value:`claude-code:${x.split(" - ")[0]}`})),...(da.codex||[]).map(x=>({label:`Codex · ${x.split(" - ")[0]}`,value:`codex:${x.split(" - ")[0]}`}))],qg=m.useMemo(()=>new Set($s),[$s]),Sl=m.useMemo(()=>{const x=new Map(Ms.map(U=>[U.key,U])),S=new Set,_=new Set,A=fl.map(U=>{const X=Qo(U,Ms).map(J=>x.get(J)).filter(Boolean);for(const J of X)S.add(J.key),_.add(String(J.name||J.id||J.key||"").trim());return{...U,skills:X}}).filter(U=>U.skills.length>0),R=Ms.filter(U=>{const X=String(U.name||U.id||U.key||"").trim();return!S.has(U.key)&&!_.has(X)});return{groups:A,ungrouped:R}},[fl,Ms]);m.useEffect(()=>{oS(x=>{let S=!1;const _=new Set(x);for(const A of Sl.groups)_.has(A.id)||(_.add(A.id),S=!0);return S?_:x})},[Sl.groups]);const er=m.useMemo(()=>{const x=b.filter(S=>S.selected);return x.length>0?x:Ut?b.filter(S=>S.id===Ut):[]},[b,Ut]),Ff=m.useMemo(()=>er.map(x=>x.id),[er]),o0=m.useCallback(()=>{if(ut)return;if(!je){ge("Readonly workspace");return}const x=(N.current||[]).filter(J=>(J==null?void 0:J.selected)&&!pm(J));if(x.length<2){ge("选择至少两个节点后按 G 创建 Group");return}const S=x.reduce((J,Y)=>{var We,ze,Ve,He,Me,Ft,rt,Ye,Le,Mt,De,dt;const ae=Number(((We=Y.position)==null?void 0:We.x)||0),pe=Number(((ze=Y.position)==null?void 0:ze.y)||0),fe=Number(((Ve=Y.measured)==null?void 0:Ve.width)||Y.width||((Me=(He=Y.data)==null?void 0:He.nodeSize)==null?void 0:Me.width)||((rt=(Ft=Y.data)==null?void 0:Ft.displaySize)==null?void 0:rt.width)||PT),Ne=Number(((Ye=Y.measured)==null?void 0:Ye.height)||Y.height||((Mt=(Le=Y.data)==null?void 0:Le.nodeSize)==null?void 0:Mt.height)||((dt=(De=Y.data)==null?void 0:De.displaySize)==null?void 0:dt.height)||lm);return{minX:Math.min(J.minX,ae),minY:Math.min(J.minY,pe),maxX:Math.max(J.maxX,ae+fe),maxY:Math.max(J.maxY,pe+Ne)}},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});if(!Number.isFinite(S.minX)||!Number.isFinite(S.minY))return;const _=new Set((N.current||[]).map(J=>J.id));let A=1,R=`group_${A}`;for(;_.has(R);)A+=1,R=`group_${A}`;const U=db({width:S.maxX-S.minX+Mp*2,height:S.maxY-S.minY+Mp*2})||{width:Qa,height:Za},X={id:R,type:pc,position:{x:S.minX-Mp,y:S.minY-Mp},width:U.width,height:U.height,selected:!0,draggable:!0,selectable:!0,zIndex:0,data:{isWorkspaceGroup:!0,label:hm(A-1),title:hm(A-1),color:"purple",nodeSize:U}};g(J=>[X,...J.map(Y=>({...Y,selected:!1}))]),w(J=>J.map(Y=>({...Y,selected:!1}))),jn(""),ge(`Created group for ${x.length} nodes`)},[ut,w,g,je]),gu=m.useMemo(()=>b.filter(x=>In(x==null?void 0:x.data)),[b]),Ug=m.useMemo(()=>er.filter(x=>In(x==null?void 0:x.data)).map(x=>x.id),[er]),J$=m.useMemo(()=>{const x=String((Ir==null?void 0:Ir.username)||(Ir==null?void 0:Ir.userId)||"").trim();return x?x.slice(0,1).toUpperCase():"?"},[Ir]),Yg=m.useMemo(()=>new Set(Ff),[Ff]),zf=m.useMemo(()=>v.filter(x=>Yg.has(x.source)&&Yg.has(x.target)),[v,Yg]),Gg=m.useCallback(x=>{const S=x==="display"?"display":x==="workflow"?"workflow":"workspace";f(S),jn(""),K([]),ee(null),q(!1),Pe(!1);const _=Tr(a);S==="display"&&_.set("view","display"),S==="workflow"&&(_.set("view","workflow"),ir.trim()&&_.set("tapdId",ir.trim()));const A=`/workspace${_.toString()?`?${_.toString()}`:""}`;window.history.pushState({},"",A)},[a,ir]),a0=m.useCallback(x=>{const S=String(x||"").trim();if(!S)return;const _=N.current.find(A=>A.id===S);if(!_||!In(_.data)){ge("展示节点不可用");return}I(A=>{if(A.nodeIds.includes(S))return A;const R=A.nodeIds.length,U=Fl(_);return{nodeIds:[...A.nodeIds,S],nodePositions:{...A.nodePositions,[S]:{x:180+R*36,y:120+R*28}},nodeSizes:{...A.nodeSizes,...U?{[S]:U}:{}}}}),K([S])},[]),l0=m.useCallback(x=>{const S=String(x||"").trim();S&&(I(_=>{const A=_.nodeIds.filter(X=>X!==S),R={..._.nodePositions},U={..._.nodeSizes};return delete R[S],delete U[S],{nodeIds:A,nodePositions:R,nodeSizes:U}}),K(_=>_.filter(A=>A!==S)))},[]),c0=m.useCallback(x=>{const S=String(x||"").trim();S&&(z.current.nodeIds.includes(S)?l0(S):a0(S))},[a0,l0]),Bf=m.useMemo(()=>{const x=xt.trim().toLowerCase();return x?kl.filter(S=>{var _,A;return[S.id,(_=S.data)==null?void 0:_.label,(A=S.data)==null?void 0:A.definitionId].filter(Boolean).some(R=>String(R).toLowerCase().includes(x))}):kl},[kl,xt]),u0=m.useMemo(()=>{const x=Bf.length,S=x<=1?1:x<=4?2:3,_=Array.from({length:S},()=>({height:0,nodes:[]}));for(const A of Bf){const R=Fl(A)||{width:420,height:260},U=Math.max(1,Number(R.width)||420),X=Math.max(1,Number(R.height)||260),J=Math.min(26,Math.max(5.5,X/U*16))+3.2;let Y=_[0];for(const ae of _)ae.height<Y.height&&(Y=ae);Y.nodes.push(A),Y.height+=J}return _.map(A=>A.nodes)},[Bf]),X$=m.useCallback(x=>{var U;const S=P.nodeIds.includes(x.id),_=Fl(x)||{width:420,height:260},A=Math.max(1,Math.round(Number(_.width)||420)),R=Math.max(1,Math.round(Number(_.height)||260));return i.jsxs("button",{type:"button",className:"af-display-picker-card"+(S?" af-display-picker-card--selected":""),style:{"--af-display-picker-card-ratio":`${A} / ${R}`},onClick:()=>c0(x.id),children:[i.jsx("span",{className:"af-display-picker-card__check","aria-hidden":!0,children:i.jsx("input",{type:"checkbox",checked:S,readOnly:!0,tabIndex:-1})}),i.jsx("span",{className:"af-display-picker-card__preview",children:i.jsx(ZG,{node:x})}),i.jsxs("span",{className:"af-display-picker-card__meta",children:[i.jsx("strong",{children:((U=x.data)==null?void 0:U.label)||x.id}),i.jsxs("small",{children:[In(x.data)," · ",x.id]})]})]},x.id)},[P.nodeIds,c0]),d0=m.useMemo(()=>{const x=jt.trim().toLowerCase();return x?Re.filter(S=>[S.id,S.version,S.displayName,S.name,S.description,...Array.isArray(S.tags)?S.tags:[]].filter(Boolean).some(_=>String(_).toLowerCase().includes(x))):Re},[Re,jt]),f0=m.useCallback((x,S)=>{const _=String(x||"snippet_node").trim().replace(/[^a-zA-Z0-9_]+/g,"_").replace(/^_+|_+$/g,"")||"snippet_node";let A=`${_}_${Date.now().toString(36)}`,R=2;for(;S.has(A);)A=`${_}_${Date.now().toString(36)}_${R}`,R+=1;return S.add(A),A},[]),yu=m.useCallback((x,S)=>{var Le,Mt;if(!je){ge("Readonly workspace");return}const _=x!=null&&x.snippet&&typeof x.snippet=="object"?x.snippet:{},A=_.instances&&typeof _.instances=="object"?_.instances:{},R=Object.keys(A);if(R.length===0)return;const U=new Set(N.current.map(De=>De.id)),X={};for(const De of R)X[De]=f0(De,U);const J=(Le=_.ui)!=null&&Le.nodePositions&&typeof _.ui.nodePositions=="object"?_.ui.nodePositions:{},Y=(Mt=_.ui)!=null&&Mt.nodeSizes&&typeof _.ui.nodeSizes=="object"?_.ui.nodeSizes:{},ae=R.map(De=>{const dt=J[De];return{id:De,x:typeof(dt==null?void 0:dt.x)=="number"?dt.x:0,y:typeof(dt==null?void 0:dt.y)=="number"?dt.y:0}}),pe=Math.min(...ae.map(De=>De.x)),fe=Math.min(...ae.map(De=>De.y));let Ne=S||{x:360+N.current.length*24,y:180+N.current.length*18};if(!S){const De=document.querySelector(".af-workspace-canvas .react-flow");if(De){const dt=De.getBoundingClientRect();Ne=r.screenToFlowPosition({x:dt.left+dt.width*.48,y:dt.top+dt.height*.32})}}const We={},ze={},Ve={};for(const De of ae){const dt=X[De.id];We[dt]={...A[De.id]||{}},ze[dt]={x:Ne.x+(De.x-pe),y:Ne.y+(De.y-fe)};const Pt=Y[De.id];typeof(Pt==null?void 0:Pt.width)=="number"&&typeof(Pt==null?void 0:Pt.height)=="number"&&(Ve[dt]={width:Pt.width,height:Pt.height})}const He=new Set(R),Me=(Array.isArray(_.edges)?_.edges:[]).filter(De=>He.has(De==null?void 0:De.source)&&He.has(De==null?void 0:De.target)).map(De=>({source:X[De.source],target:X[De.target],sourceHandle:De.sourceHandle??null,targetHandle:De.targetHandle??null})),Ft=Iu({instances:We,edges:Me,ui:{nodePositions:ze,nodeSizes:Ve}},be),rt=Ft.nodes.map(De=>De.id),Ye=Ft.nodes.map(De=>({...De,selected:!0}));Z.current={...Z.current,...Ft.instances},ne(Z.current),g(De=>[...De.map(dt=>({...dt,selected:!1})),...Ye]),w(De=>[...De.map(dt=>({...dt,selected:!1})),...Ft.edges.map(dt=>({...dt,selected:!1}))]),jn(""),K([]),ge(`已添加流程片段:${x.displayName||x.id}(已选中 ${rt.length} 个节点)`)},[f0,be,r,w,g,je]),Q$=m.useCallback(()=>{var _,A;if(er.length<2){Vn("请先在 workspace 画布上选择至少两个节点。"),re("flows");return}const x=er[0],S=er.length===2?`${((_=x.data)==null?void 0:_.label)||x.id} 片段`:`${((A=x.data)==null?void 0:A.label)||x.id} 等 ${er.length} 个节点`;Xn({name:S,id:S.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,""),description:""}),Ar(""),xr(!0),re("flows")},[er]),Z$=m.useCallback(async()=>{var R,U;if(er.length<2)return;const x=wn.name.trim();if(!x){Ar("请填写片段名称。");return}const S={},_={};for(const X of er){S[X.id]={x:((R=X.position)==null?void 0:R.x)||0,y:((U=X.position)==null?void 0:U.y)||0};const J=Fl(X);J&&(_[X.id]=J)}const A=zf.map(X=>({source:X.source,target:X.target,sourceHandle:X.sourceHandle??null,targetHandle:X.targetHandle??null}));hr(!0),Ar("");try{const X=await fetch("/api/marketplace/publish-flow-snippet",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:wn.id,name:x,displayName:x,version:"1.0.0",description:wn.description,snippet:{instances:av(er,Z.current),edges:A,ui:{nodePositions:S,nodeSizes:_}}})}),J=await X.json().catch(()=>({}));if(!X.ok||J.ok===!1)throw new Error(J.error||"发布流程片段失败");xr(!1),ge(`流程片段已发布:${J.id||x}`),sS(`流程片段已发布:${J.id||x}`),await Af(),re("flows")}catch(X){Ar(String(X.message||X))}finally{hr(!1)}},[Af,wn,zf,er,sS]),p0=m.useCallback(async()=>{var S;const x=Gc.trim();if(x){$v(!0),Yc("");try{const _=await fetch("/api/workspace/collaboration/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,username:x,role:"editor"})}),A=await _.json().catch(()=>({}));if(!_.ok)throw new Error(A.error||"添加协作成员失败");gg(A.workspace||null),Ov(""),ge(`已将 Workspace 分享给 ${((S=A.member)==null?void 0:S.username)||x}`)}catch(_){Yc(String(_.message||_))}finally{$v(!1)}}},[a,Gc]),eL=m.useCallback(()=>{Yc(""),yg(!0)},[]),tL=m.useCallback(async x=>{const S=String((x==null?void 0:x.userId)||"").trim();if(!(!S||S===(an==null?void 0:an.ownerId))){Fv(S),Yc("");try{const _=await fetch("/api/workspace/collaboration/share",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,memberUserId:S})}),A=await _.json().catch(()=>({}));if(!_.ok)throw new Error(A.error||"取消成员分享失败");gg(A.workspace||null),ge(`已取消对 ${(x==null?void 0:x.username)||S} 的分享`)}catch(_){Yc(String(_.message||_))}finally{Fv("")}}},[a,an==null?void 0:an.ownerId]),h0=m.useCallback(async()=>{const x=Ml(N.current,j.current,Z.current);x.ui={...x.ui||{},...F.current?{viewport:F.current}:{},displayPage:TC(z.current,N.current)};const S=new Blob([`${JSON.stringify(x,null,2)}
263
+ `],{type:"application/json"}),_=URL.createObjectURL(S),A=document.createElement("a");A.href=_,A.download=`${a.flowId||"workspace"}-conflict-draft-${Date.now()}.json`,document.body.appendChild(A),A.click(),A.remove(),URL.revokeObjectURL(_),await ks(),cl(null),ua(!1),ge("已备份本地草稿并载入远端最新版本")},[j,a.flowId,ks,N]),nL=m.useCallback(async()=>{const x=Array.isArray(En==null?void 0:En.conflictItems)?En.conflictItems:[];if(!x.length||!(En!=null&&En.mergeGraph)||!(En!=null&&En.currentGraph)){Jc("当前冲突缺少字段合并数据,请改用“备份并载入远端”。");return}let S=En.mergeGraph;try{x.forEach((A,R)=>{const U=xg[String(R)]||{mode:"local"};let X,J=!0;U.mode==="remote"?(X=A.current,J=A.hasCurrent!==!1):U.mode==="manual"?X=JSON.parse(String(U.manual||"")):(X=A.incoming,J=A.hasIncoming!==!1),S=LJ(S,A.pathParts,X,J)})}catch(A){Jc(`手动值不是有效 JSON:${String(A.message||A)}`);return}zv(!0),Jc(""),Os("saving"),Ds("正在提交冲突解决结果");const _=Ce.current.catch(()=>{}).then(async()=>{const A=await fetch("/api/workspace/graph",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,graph:S,baseRevision:En.currentRevision,baseGraph:En.currentGraph,clientId:ke.current})}),R=await A.json().catch(()=>({}));if(!A.ok){if(A.status===409&&Array.isArray(R.conflictItems)){const U=R.conflictItems;cl({currentRevision:String(R.currentRevision||""),message:R.error||"Workspace 再次出现冲突",conflictPaths:Array.isArray(R.conflictPaths)?R.conflictPaths:[],conflictItems:U,mergeGraph:R.mergeGraph||null,currentGraph:R.currentGraph||null}),ul(Object.fromEntries(U.map((X,J)=>[String(J),{mode:"local",manual:Ru(X)}])))}throw new Error(R.error||"提交冲突解决结果失败")}await ks(),cl(null),ua(!1),ge("冲突已解决并保存")});Ce.current=_;try{await _}catch(A){Jc(String(A.message||A)),Os("error"),Ds(String(A.message||A))}finally{zv(!1)}},[a,ks,En,xg]);m.useCallback(()=>{if(gu.length===0){ge("当前 workspace 没有 display 节点");return}const x=Ug.length>0?Ug:gu.map(_=>_.id),S=a.flowId?`${a.flowId} 展示页`:"AgentFlow Display";le(lw({title:S,layout:"gallery",nodeIds:x,mode:"multi-node"})),sr(""),Gt(null),Pr(!0)},[a.flowId,Ug,gu]);const rL=m.useCallback(x=>{le(S=>{const _=Array.isArray(S.nodeIds)?S.nodeIds:[];return _.includes(x)?{...S,nodeIds:_.filter(A=>A!==x)}:{...S,nodeIds:[..._,x]}})},[]),zs=m.useCallback(async()=>{Ln(!0),zr("");try{const x=await fetch("/api/display/shares"),S=await x.json().catch(()=>({}));if(!x.ok)throw new Error(S.error||"读取分享列表失败");kr(Array.isArray(S.shares)?S.shares:[])}catch(x){zr(String(x.message||x)),kr([])}finally{Ln(!1)}},[]),sL=m.useCallback(()=>{nn(!0),ie(""),zs()},[zs]),iL=m.useCallback(async()=>{var _,A;const x=_t.title.trim(),S=Array.isArray(_t.nodeIds)?_t.nodeIds:[];if(S.length===0){sr("请选择至少一个 display 节点。");return}Qn(!0),sr(""),Gt(null);try{await Zt(b,v);const R=await fetch("/api/display/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,title:x,layout:_t.layout,nodeIds:S,...$C(_t)})}),U=await R.json().catch(()=>({}));if(!R.ok||U.ok===!1)throw new Error(U.error||"发布展示页失败");const X=new URL(U.url||`/display/${((_=U.share)==null?void 0:_.id)||""}`,window.location.origin).href;Gt({...U,absoluteUrl:X}),ge((A=U.share)!=null&&A.expiresAt?"展示页已生成":"展示页已生成:永久有效"),mt&&zs()}catch(R){sr(String(R.message||R))}finally{Qn(!1)}},[_t,mt,v,a,zs,b,Zt]),oL=m.useCallback(async()=>{var S,_;const x=Array.isArray(P.nodeIds)?P.nodeIds:[];if(x.length===0){sr("请先添加至少一个展示节点。"),ge("请先添加至少一个展示节点"),Pe(!0);return}Qn(!0),sr("");try{await Zt(b,v);const A=a.flowId?`${a.flowId} 展示页`:"AgentFlow Display",R=await fetch("/api/display/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,title:A,layout:"canvas",nodeIds:x,...$C(_t)})}),U=await R.json().catch(()=>({}));if(!R.ok||U.ok===!1)throw new Error(U.error||"生成展示链接失败");const X=new URL(U.url||`/display/${((S=U.share)==null?void 0:S.id)||""}`,window.location.origin).href;Gt({...U,absoluteUrl:X}),Jt(!0),ge((_=U.share)!=null&&_.expiresAt?"展示链接已生成":"展示链接已生成:永久有效"),mt&&zs()}catch(A){const R=String(A.message||A);sr(R),ge(R)}finally{Qn(!1)}},[P.nodeIds,_t,mt,v,a,zs,b,Zt]),m0=m.useCallback(async()=>{const x=Ct==null?void 0:Ct.absoluteUrl;if(!x)return;const S=await pb(x);Zn(S?"copied":"failed"),window.setTimeout(()=>Zn(""),1600)},[Ct==null?void 0:Ct.absoluteUrl]),aL=m.useCallback(async x=>{const S=LC(x),_=await pb(S);ie(_?String((x==null?void 0:x.id)||""):"failed"),window.setTimeout(()=>ie(""),1600)},[]),lL=m.useCallback(async(x,S)=>{const _=String((x==null?void 0:x.id)||"");if(_){ai(_),zr("");try{const A=S==="permanent"?{id:_,expiresMode:"permanent",permanent:!0}:{id:_,expiresMode:"days",expiresInDays:Number(S||30)},R=await fetch("/api/display/share",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(A)}),U=await R.json().catch(()=>({}));if(!R.ok||U.ok===!1)throw new Error(U.error||"更新分享有效期失败");await zs(),ge("分享有效期已更新")}catch(A){zr(String(A.message||A))}finally{ai("")}}},[zs]),cL=m.useCallback(async x=>{const S=String((x==null?void 0:x.id)||"");if(S){ai(S),zr("");try{const _=await fetch(`/api/display/share?id=${encodeURIComponent(S)}`,{method:"DELETE"}),A=await _.json().catch(()=>({}));if(!_.ok||A.ok===!1)throw new Error(A.error||"撤销分享失败");await zs(),ge("分享已撤销")}catch(_){zr(String(_.message||_))}finally{ai("")}}},[zs]),uL=m.useCallback(x=>{g(S=>S.map(_=>_.id===x?{..._,selected:!1}:_)),jn(S=>S===x?"":S)},[g]),Nl=m.useCallback(()=>{const x=Ig.current;if(!x)return;const S=x.getBoundingClientRect(),_=Math.min(420,Math.max(320,S.width+160)),A=12,R=Math.max(180,S.top-A*2),U=Math.min(560,R);_$({position:"fixed",left:Math.max(12,Math.min(window.innerWidth-_-12,S.left)),top:Math.max(A,S.top-U-A),width:_,maxHeight:U,zIndex:1e4})},[]);m.useEffect(()=>{if(!Cf)return;Nl();const x=_=>{var R,U;const A=_.target;(R=Ig.current)!=null&&R.contains(A)||(U=aS.current)!=null&&U.contains(A)||Pg(!1)},S=_=>{_.key==="Escape"&&Pg(!1)};return window.addEventListener("pointerdown",x),window.addEventListener("keydown",S),window.addEventListener("resize",Nl),window.addEventListener("scroll",Nl,!0),()=>{window.removeEventListener("pointerdown",x),window.removeEventListener("keydown",S),window.removeEventListener("resize",Nl),window.removeEventListener("scroll",Nl,!0)}},[Cf,Nl]);const Hf=m.useCallback(x=>{const S=AT(x);if(S.active&&(lt.current=!0),S.finished&&(lt.current=!1,oe.current=!0),lY(x)&&li(),d==="display"){I(R=>{var Y,ae;let U=R.nodePositions,X=R.nodeSizes;for(const pe of x||[]){const fe=Op(pe==null?void 0:pe.id);if(!(!fe||!R.nodeIds.includes(fe))&&pe.type!=="select"){if(pe.type==="position"&&pe.position){const Ne=U[fe];if((Ne==null?void 0:Ne.x)===pe.position.x&&(Ne==null?void 0:Ne.y)===pe.position.y)continue;U===R.nodePositions&&(U={...R.nodePositions}),U[fe]={x:pe.position.x,y:pe.position.y};continue}if(pe.type==="dimensions"&&((Y=pe.dimensions)!=null&&Y.width)&&((ae=pe.dimensions)!=null&&ae.height)){const Ne=za({width:Math.round(Number(pe.dimensions.width)),height:Math.round(Number(pe.dimensions.height))},{display:!0});if(Ne){const We=X[fe];if((We==null?void 0:We.width)===Ne.width&&(We==null?void 0:We.height)===Ne.height)continue;X===R.nodeSizes&&(X={...R.nodeSizes}),X[fe]=Ne}}}}if(U===R.nodePositions&&X===R.nodeSizes)return R;const J={...R,nodePositions:U,nodeSizes:X};return z.current=J,J});const A=(x||[]).filter(R=>(R==null?void 0:R.type)==="select");A.length>0&&K(R=>{const U=new Set(R);for(const J of A){const Y=Op(J==null?void 0:J.id);Y&&(J.selected?U.add(Y):U.delete(Y))}const X=Array.from(U);return X.length===R.length&&X.every((J,Y)=>J===R[Y])?R:X});return}if(!je){const A=(x||[]).filter(R=>(R==null?void 0:R.type)==="select");A.length>0&&g(R=>ad(A,R));return}const _=(x||[]).filter(A=>{var R,U;return(A==null?void 0:A.type)==="dimensions"&&((R=A.dimensions)==null?void 0:R.width)&&((U=A.dimensions)==null?void 0:U.height)});g(A=>{const R=new Map;if(_.length>0){const J=new Map(A.map(Y=>[Y.id,Y]));for(const Y of _){const ae=J.get(Y.id),pe={width:Math.round(Number(Y.dimensions.width)),height:Math.round(Number(Y.dimensions.height))},fe=pm(ae)?db(pe):za(pe,{display:!!In(ae==null?void 0:ae.data)});fe&&R.set(Y.id,fe)}}const U=ad(x,A),X=R.size===0?U:U.map(J=>{const Y=R.get(J.id);if(!Y)return J;const ae={...J.data,nodeSize:Y};return In(J.data)&&(ae.displaySize=Y),{...J,width:Y.width,height:Y.height,data:ae}});return N.current=X,X}),_.length>0&&Br(_.map(A=>A.id))},[li,Br,g,d,je]),Wf=m.useCallback((x=[],{finish:S=!1}={})=>{const _=S?fY([...V.current,...x]):ib(x);S&&(V.current=[]),_.length>0&&Hf(_)},[Hf]),dL=m.useCallback(x=>{const{transient:S,committed:_,finishesInteraction:A}=dY(x);if(S.length>0){lt.current||(lt.current=!0,vl.current=s0.current),V.current=ib([...V.current,...S]);const R=ad(S,vl.current);vl.current=R,s.getState().setNodes(R)}if(A){vl.current=[],Wf(_,{finish:!0});return}_.length>0&&Hf(_)},[Hf,Wf,s]);m.useEffect(()=>{const x=()=>{!lt.current&&V.current.length===0||(Wf([],{finish:!0}),vl.current=[])},S=()=>{document.visibilityState==="hidden"&&x()};return window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x),window.addEventListener("blur",x),document.addEventListener("visibilitychange",S),()=>{window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x),window.removeEventListener("blur",x),document.removeEventListener("visibilitychange",S),V.current=[],vl.current=[]}},[Wf]);const fL=m.useCallback(x=>{if(d!=="display"){if(!je){const S=(x||[]).filter(_=>(_==null?void 0:_.type)==="select");S.length>0&&w(_=>{const A=Qh(S,_);return j.current=A,A});return}(x||[]).some(S=>(S==null?void 0:S.type)!=="select")&&li(),w(S=>{const _=Qh(x,S);return j.current=_,_})}},[li,w,d,je]),jl=m.useCallback(()=>{const x=document.querySelector(".af-workspace-canvas .react-flow");if(x){const S=x.getBoundingClientRect();return r.screenToFlowPosition({x:S.left+S.width*.48,y:S.top+S.height*.32})}return{x:360+b.length*36,y:180+b.length*28}},[b.length,r]),Vf=m.useCallback(()=>{var x,S,_;if(Vt){const A=Number(((x=Vt.measured)==null?void 0:x.width)||Vt.width||260);return{x:Number(((S=Vt.position)==null?void 0:S.x)||0)+A+140,y:Number(((_=Vt.position)==null?void 0:_.y)||0)}}return jl()},[jl,Vt]),zi=m.useCallback((x,S={})=>{if(!je)return ge("Readonly workspace"),null;if(!x)return null;const _=hv(x)||x.id,A=BT(x),R=WT(x),U=S.id||kG(_,b),X=qu(x.inputs),J=qu(x.outputs),Y={definitionId:_,...A?{marketplaceRef:A}:{},...x.packageId?{marketplacePackageId:x.packageId}:{},...x.version?{marketplaceVersion:x.version}:{},label:S.label||fm(x),role:"normal",body:S.body||"",...S.script||R?{script:S.script||R}:{},...S.scriptRef?{scriptRef:S.scriptRef}:{},...S.implementationRef?{implementationRef:S.implementationRef}:{},...S.implementationMode?{implementationMode:S.implementationMode}:{},input:S.inputs||X,output:S.outputs||J},ae={id:U,type:pc,position:S.position||jl(),data:{label:Y.label,definitionId:_,...A?{marketplaceRef:A}:{},...x.packageId?{marketplacePackageId:x.packageId}:{},...x.version?{marketplaceVersion:x.version}:{},schemaType:zT(_,x),role:"normal",body:Y.body,...Y.script?{script:Y.script}:{},...Y.scriptRef?{scriptRef:Y.scriptRef}:{},...Y.implementationRef?{implementationRef:Y.implementationRef}:{},...Y.implementationMode?{implementationMode:Y.implementationMode}:{},inputs:Y.input,outputs:Y.output}},pe={...rb(ae,{...Z.current,[U]:Y},be),selected:!0};return li(),g(fe=>[...fe.map(Ne=>({...Ne,selected:!1})),pe]),S.openProperties&&jn(U),U},[jl,li,b,be,g,je]),pL=m.useCallback(x=>ow(x,N.current),[]),hL=m.useCallback(x=>{if(!je){ge("Readonly workspace");return}if(!ow(x,N.current)){ge("端口类型不匹配,已取消连线");return}ee(null),li(),g(S=>ew(S,x)),w(S=>{const _=S.filter(R=>!(R.target===x.target&&R.targetHandle===x.targetHandle)),A=uh({...x,markerEnd:{type:bi.ArrowClosed}},_);return j.current=A,A})},[li,w,g,je]),mL=m.useCallback((x,S)=>{if(!je)return;const _=wG(S,N.current);se.current=_?{..._,preferExisting:!!(x!=null&&x.shiftKey)}:null,ee(null)},[je]),gL=m.useCallback((x,S)=>{var He,Me,Ft,rt;if(!je)return;const _=se.current;if(se.current=null,!_||S!=null&&S.toNode)return;const A=xG(be,_),R=bG(N.current,j.current,_);if(A.length===0&&R.length===0){ge(`没有匹配 ${_.slotType} 端口的节点`);return}const X=!!(x!=null&&x.shiftKey||_.preferExisting)?R.length>0?"existing":"create":A.length>0?"create":"existing",J=((Me=(He=x==null?void 0:x.changedTouches)==null?void 0:He[0])==null?void 0:Me.clientX)??(x==null?void 0:x.clientX),Y=((rt=(Ft=x==null?void 0:x.changedTouches)==null?void 0:Ft[0])==null?void 0:rt.clientY)??(x==null?void 0:x.clientY);if(!Number.isFinite(J)||!Number.isFinite(Y))return;const ae=document.querySelector(".af-workspace-canvas .react-flow");if(!ae)return;const pe=ae.getBoundingClientRect(),fe=320,Ne=Math.max(A.length,R.length),We=Math.min(480,150+Ne*58),ze=Math.max(12,Math.min(J-pe.left,pe.width-fe-12)),Ve=Math.max(12,Math.min(Y-pe.top,pe.height-We-12));ee({left:ze,top:Ve,flowPosition:r.screenToFlowPosition({x:J,y:Y}),draft:_,candidates:A,existingCandidates:R,mode:X,query:""})},[be,r,je]),yL=m.useCallback(x=>{if(!je){ge("Readonly workspace"),ee(null);return}const S=ue.current;if(!S||!(x!=null&&x.def))return;const _=zi(x.def,{position:S.flowPosition});if(!_)return;const A=S.draft.handleType==="source"?{source:S.draft.nodeId,sourceHandle:S.draft.handleId,target:_,targetHandle:`input-${x.slotIndex}`}:{source:_,sourceHandle:`output-${x.slotIndex}`,target:S.draft.nodeId,targetHandle:S.draft.handleId};g(R=>ew(R,A)),w(R=>{const U=R.filter(J=>!(J.target===A.target&&J.targetHandle===A.targetHandle)),X=uh({...A,markerEnd:{type:bi.ArrowClosed}},U);return j.current=X,X}),ee(null)},[zi,w,je]),wL=m.useCallback(x=>{if(!je){ge("Readonly workspace"),ee(null);return}const S=x==null?void 0:x.connection;if(!S||!ow(S,N.current)){ge("端口类型不匹配,已取消连线"),ee(null);return}g(_=>ew(_,S)),w(_=>{const A=_.filter(U=>!(U.target===S.target&&U.targetHandle===S.targetHandle)),R=uh({...S,markerEnd:{type:bi.ArrowClosed}},A);return j.current=R,R}),ee(null)},[w,g,je]),g0=m.useCallback(x=>{x&&(zi(x,{position:Vf()}),q(!1),et(""))},[zi,Vf]),y0=m.useCallback(x=>{x&&(yu(x,Vf()),q(!1),et(""))},[yu,Vf]),xL=m.useCallback(x=>{var _,A,R;if(ut||Pn)return;const S=x==null?void 0:x.target;vC(S)||(_=S==null?void 0:S.closest)!=null&&_.call(S,"button, a, [role='button'], .react-flow__handle")||(R=(A=C.current)==null?void 0:A.focus)==null||R.call(A,{preventScroll:!0})},[ut,Pn]);m.useEffect(()=>{const x=S=>{var ae;if(S.defaultPrevented)return;const _=fU(S.target)||vC(S.target);if((S.metaKey||S.ctrlKey)&&S.key.toLowerCase()==="s"){S.preventDefault(),Zt().catch(pe=>ge(String(pe.message||pe)));return}if((S.metaKey||S.ctrlKey)&&S.key.toLowerCase()==="k"){S.preventDefault(),S.stopPropagation(),gS(pe=>!pe);return}if(Lg)return;if($g){(S.key==="Escape"||sC(S))&&(S.preventDefault(),Ef(!1));return}const A=S.key.toLowerCase(),R=(S.metaKey||S.ctrlKey)&&A==="c",U=(S.metaKey||S.ctrlKey)&&A==="v",X=_&&R&&MY(S.target);if(_&&!X)return;const J=(S.metaKey||S.ctrlKey)&&!S.shiftKey&&A==="z",Y=(S.metaKey||S.ctrlKey)&&(S.shiftKey&&A==="z"||A==="y");if(J||Y){if(ut){S.preventDefault(),S.stopPropagation(),ge("展示页布局会自动保存");return}if(!je){S.preventDefault(),ge("Readonly workspace");return}S.preventDefault(),S.stopPropagation();const pe=J?IS():RS();ge(pe?J?"Undo canvas change":"Redo canvas change":J?"Nothing to undo":"Nothing to redo");return}if(R){if(ut)return;const pe=go.current,fe=(N.current||[]).some(We=>We==null?void 0:We.selected)?N.current:(N.current||[]).map(We=>pe&&We.id===pe?{...We,selected:!0}:We),Ne=$q(fe,j.current,Z.current);Ne&&(S.preventDefault(),S.stopPropagation(),B.current=Ne,LG(Ne),X&&typeof((ae=S.target)==null?void 0:ae.blur)=="function"&&S.target.blur(),ge(`Copied ${Ne.nodes.length} node${Ne.nodes.length>1?"s":""}`));return}if(U){if(ut){S.preventDefault(),S.stopPropagation();return}if(!je){S.preventDefault(),ge("Readonly workspace");return}const pe=B.current||OG();pe&&!B.current&&(B.current=pe);const fe=Lq(pe,N.current,j.current,Z.current);fe&&(S.preventDefault(),S.stopPropagation(),Z.current=fe.instances,ne(fe.instances),g(fe.nodes),w(fe.edges),ge(`Pasted ${fe.pastedNodeIds.length} node${fe.pastedNodeIds.length>1?"s":""}`));return}if(sC(S)&&!S.metaKey&&!S.ctrlKey&&!S.altKey){S.preventDefault(),Ef(!0);return}if(A==="g"&&!S.metaKey&&!S.ctrlKey&&!S.altKey){S.preventDefault(),o0();return}if(S.key==="a"||S.key==="A"){if(S.metaKey||S.ctrlKey){S.preventDefault(),ut?K(z.current.nodeIds):(g(pe=>pe.map(fe=>({...fe,selected:!0}))),w(pe=>pe.map(fe=>({...fe,selected:!1}))));return}if(S.altKey)return;if(ut){S.preventDefault(),Pe(!0);return}if(!je){S.preventDefault(),ge("Readonly workspace");return}S.preventDefault(),q(!0);return}if((S.key==="v"||S.key==="V")&&!S.metaKey&&!S.ctrlKey&&!S.altKey){S.preventDefault(),yS("select");return}if((S.key==="h"||S.key==="H")&&!S.metaKey&&!S.ctrlKey&&!S.altKey){S.preventDefault(),yS("pan");return}(S.key==="f"||S.key==="F")&&!S.metaKey&&!S.ctrlKey&&!S.altKey&&(S.preventDefault(),i0())};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[o0,ut,Lg,i0,RS,Zt,$g,w,g,IS,je]);const bL=m.useCallback(x=>{dl(S=>{const _=new Set(S);return _.has(x)?_.delete(x):_.add(x),_})},[]),kL=m.useCallback((x,S)=>{x.dataTransfer.effectAllowed="copy",x.dataTransfer.setData("application/x-agentflow-workspace-file",JSON.stringify({path:S.path,name:S.name,type:S.type})),x.dataTransfer.setData("text/plain",S.path)},[]),vL=m.useCallback((x,S)=>{x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("application/agentflow-node",S.id),x.dataTransfer.setData("text/plain",S.id)},[]),Kf=m.useCallback(async(x,S)=>{const _=String((x==null?void 0:x.name)||(x==null?void 0:x.path)||"").toLowerCase(),A=_.split(".").pop(),R=["jsx","tsx","js"].includes(A)?"display_react_app":A==="html"?"display_html":A==="csv"||A==="tsv"||A==="json"&&/\b(table|data|rows|report)\b/i.test(_)?"display_table":["png","jpg","jpeg","gif","webp","svg"].includes(A)?"display_image":"display_markdown",U=be.find(fe=>fe.id===R);if(!U){ge("展示节点不可用");return}const X=R==="display_image";let J=String(x.path||"");if(!X){const fe=Tr(a);fe.set("path",x.path);const Ne=await fetch(`/api/workspace/file?${fe.toString()}`),We=await Ne.json();if(!Ne.ok)throw new Error(We.error||"读取文件失败");J=String(We.content||"")}const Y=R==="display_image"?"src":"content",ae=qu(U.inputs).map(fe=>fe.name===Y?{...fe,default:J,value:J}:fe),pe=qu(U.outputs).map(fe=>fe.name===Y?{...fe,default:J,value:J}:fe);zi(U,{label:x.name||"Display",body:J,inputs:ae,outputs:pe,position:S}),ge(`已创建展示:${x.path}`)},[zi,a,be]),SL=m.useCallback(x=>{if(!je){ge("Readonly workspace");return}Kf(x,jl()).catch(S=>ge(String(S.message||S)))},[Kf,jl,je]),NL=m.useCallback(x=>{if(!je){x.preventDefault(),ge("Readonly workspace");return}const S=x.dataTransfer.getData("application/x-agentflow-workspace-file");if(S){x.preventDefault();let X;try{X=JSON.parse(S)}catch{return}if(!(X!=null&&X.path))return;const J=r.screenToFlowPosition({x:x.clientX,y:x.clientY});Kf(X,J).catch(Y=>ge(String(Y.message||Y)));return}const _=x.dataTransfer.getData("application/agentflow-snippet");if(_){const X=Re.find(Y=>`${Y.id}@${Y.version}`===_);if(!X)return;x.preventDefault();const J=r.screenToFlowPosition({x:x.clientX,y:x.clientY});yu(X,J);return}const A=x.dataTransfer.getData("application/agentflow-node");if(!A)return;const R=be.find(X=>X.id===A);if(!R)return;x.preventDefault();const U=r.screenToFlowPosition({x:x.clientX,y:x.clientY});zi(R,{position:U})},[Kf,zi,Re,yu,be,r,je]),jL=m.useCallback(x=>{if(!je)return;const S=Array.from(x.dataTransfer.types||[]);!S.includes("application/x-agentflow-workspace-file")&&!S.includes("application/agentflow-node")&&!S.includes("application/agentflow-snippet")||(x.preventDefault(),x.dataTransfer.dropEffect=S.includes("application/agentflow-node")||S.includes("application/agentflow-snippet")?"move":"copy")},[je]),CL=m.useCallback(async(x="")=>{if(!je){ge("Readonly workspace");return}const S=window.prompt("新文件名",x?`${x}/notes.md`:"notes.md");if(!S)return;const _=x&&!S.includes("/")?`${x}/${S}`:S;try{const A=await fetch("/api/workspace/file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:_,content:""})}),R=await A.json();if(!A.ok)throw new Error(R.error||"创建文件失败");await An(),dl(U=>{const X=new Set(U);for(const J of Dp(R.path||_))X.delete(J);return X}),ge(`已创建 ${R.path}`)}catch(A){ge(String(A.message||A))}},[a,An,je]),_L=m.useCallback(async(x="")=>{if(!je){ge("Readonly workspace");return}const S=window.prompt("新文件夹名",x?`${x}/docs`:"docs");if(!S)return;const _=x&&!S.includes("/")?`${x}/${S}`:S;try{const A=await fetch("/api/workspace/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:_})}),R=await A.json();if(!A.ok)throw new Error(R.error||"创建文件夹失败");await An(),dl(U=>{const X=new Set(U);for(const J of Dp(R.path||_))X.delete(J);return R.path&&X.delete(R.path),X}),ge(`已创建 ${R.path}`)}catch(A){ge(String(A.message||A))}},[a,An,je]),EL=m.useCallback(async x=>{if(!je){ge("Readonly workspace");return}if(!(!(x!=null&&x.path)||!window.confirm(`删除 ${x.path}?`)))try{const S=await fetch("/api/workspace/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,path:x.path})}),_=await S.json();if(!S.ok)throw new Error(_.error||"删除失败");ge(`已删除 ${_.path}`),await An()}catch(S){ge(String(S.message||S))}},[a,An,je]),AL=m.useCallback(x=>{if(!(x!=null&&x.path)||x.type==="directory")return;const S=Ud(x.path,a,{download:!0});if(!S)return;const _=document.createElement("a");_.href=S,_.download=x.name||x.path.split("/").pop()||"download",_.rel="noopener",document.body.appendChild(_),_.click(),_.remove()},[a]),qf=m.useCallback(async()=>{if(!je){ge("Readonly workspace");return}const x=fa.trim(),S=Hr,_=Ls.find(X=>X.id===S)||null;if(!x||ns||(_==null?void 0:_.status)==="running"||(_==null?void 0:_.status)==="stopping")return;const A=_?Array.isArray(_.messages)?_.messages:[]:pa,R=Ml(b,v,Z.current);Rg(""),cS(!0),ml(!0),gl(null);const U={role:"user",text:x,at:Date.now()};_?qn(X=>X.map(J=>J.id===S?{...J,status:"running",messages:[...Array.isArray(J.messages)?J.messages:[],U].slice(-180)}:J)):(bs("workspace"),hl(X=>[...X,U]));try{await Zt(b,v);const X=await fetch("/api/workspace/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,prompt:x,outputKind:"markdown",workspaceGraph:R,allowFlowYaml:!1,model:Li,selectedSkills:$s,selectedNodeIds:Ff,messages:A})}),J=await X.json();if(!X.ok)throw new Error(J.error||"生成失败");const ae={role:"assistant",kind:"assistant",text:String(J.content||"").trim(),at:Date.now()};_?qn(pe=>pe.map(fe=>fe.id===S?{...fe,status:"done",messages:[...Array.isArray(fe.messages)?fe.messages:[],ae].slice(-180)}:fe)):hl(pe=>[...pe,ae]),await ks(),ge("AI 生成完成")}catch(X){const J=String(X.message||X),Y={role:"assistant",text:J,error:!0,at:Date.now()};_?qn(ae=>ae.map(pe=>pe.id===S?{...pe,status:"failed",messages:[...Array.isArray(pe.messages)?pe.messages:[],Y].slice(-180)}:pe)):hl(ae=>[...ae,Y]),ge(J)}finally{cS(!1)}},[Hr,pa,Li,Ls,ns,fa,v,a,ks,b,Zt,Ff,$s,je]),or=Ls.find(x=>x.id===Hr)||null,Jg=or?Array.isArray(or.messages)?or.messages:[]:pa,Cl=or&&(or.status==="running"||or.status==="stopping")||ns,PL=wJ(Jg,Cl),Xg=xJ(Jg),w0=or?or.status==="stopping"?`${or.label} stopping`:or.status==="running"?`${or.label} running`:or.status==="paused"?`${or.label} paused`:or.status==="failed"?`${or.label} failed`:`${or.label} done`:ns?"Workspace agent running":pa.length>0?"Workspace conversation":"Ready";m.useEffect(()=>{Hr!=="workspace"&&(Ls.some(x=>x.id===Hr)||bs(ga()))},[Hr,Ls,ga]),m.useEffect(()=>{if(!tu)return;const x=window.requestAnimationFrame(()=>{var _,A;const S=uS.current;S&&(S.scrollTop=S.scrollHeight),(A=(_=Tg.current)==null?void 0:_.scrollIntoView)==null||A.call(_,{block:"nearest",inline:"nearest"})});return()=>window.cancelAnimationFrame(x)},[Jg.length,Hr,w0,Xg.length,tu]);const IL=String(a.flowId||"").trim()||"Workspace",wo=(_t==null?void 0:_t.mode)==="single-node",x0=wo&&gu.find(x=>{var S;return x.id===_t.sourceNodeId||((S=_t.nodeIds)==null?void 0:S.includes(x.id))})||null,RL=wo&&x0?[x0]:gu;return i.jsxs("div",{className:"af-workspace-page",children:[l?null:i.jsxs("header",{className:"af-pipeline-top af-workspace-top",children:[i.jsxs("div",{className:"af-pipeline-top-left",children:[i.jsx("button",{type:"button",className:"af-icon-btn af-pipeline-back",onClick:()=>n("/projects"),"aria-label":"返回",children:i.jsx("span",{className:"material-symbols-outlined",children:"arrow_back"})}),i.jsxs("div",{className:"af-pipeline-brand",title:a.flowId?`${a.flowId} · ${Mv}`:Mv||"PROJECT",children:[i.jsx("span",{className:"af-pipeline-brand-name",children:IL}),i.jsxs("span",{className:"af-pipeline-brand-ver",children:["V",jY,"-STABLE"]})]}),i.jsxs("div",{className:"af-view-switch","aria-label":"视图切换",children:[i.jsx("button",{type:"button",className:d==="workspace"?"af-view-switch__active":"",onClick:()=>Gg("workspace"),children:"Workspace"}),i.jsx("button",{type:"button",className:d==="display"?"af-view-switch__active":"",onClick:()=>Gg("display"),children:"Display"}),i.jsx("button",{type:"button",className:d==="workflow"?"af-view-switch__active":"",onClick:()=>Gg("workflow"),children:"Workflow"})]})]}),i.jsxs("div",{className:"af-pipeline-top-right af-workspace-actions",children:[i.jsx("span",{className:`af-workspace-sync-light is-${SS}`,title:`${AS} · ${NS}`,role:"status","aria-label":`${AS}:${NS}`,children:i.jsx("span",{className:"af-workspace-sync-light__dot","aria-hidden":!0})}),En?i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",onClick:()=>{var x;(x=En.conflictItems)!=null&&x.length?ua(!0):h0()},title:["先下载当前本地草稿,再载入远端最新版本",...En.conflictPaths||[]].join(`
264
+ `),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"difference"}),"处理冲突"]}):null,ut?i.jsxs(i.Fragment,{children:[i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",disabled:dn||!(Ct!=null&&Ct.absoluteUrl)&&P.nodeIds.length===0,onClick:()=>{Zn(""),Jt(!0)},title:Ct!=null&&Ct.absoluteUrl?"查看展示链接":P.nodeIds.length===0?"先添加展示节点":"生成展示链接",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:dn?"hourglass_empty":"ios_share"}),dn?"生成中":Ct!=null&&Ct.absoluteUrl?"展示链接":"生成链接"]}),i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",disabled:kl.length===0,onClick:()=>Pe(!0),title:kl.length===0?"当前 workspace 没有 display 节点":"选择展示节点 (A)",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add_to_photos"}),"添加展示"]})]}):null,i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",disabled:!!(an!=null&&an.role&&an.role!=="owner"),onClick:eL,title:an!=null&&an.role&&an.role!=="owner"?"仅 Workspace 所有者可以创建邀请":"邀请其他成员协作编辑",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"group_add"}),"协作分享"]}),i.jsxs("button",{type:"button",className:"af-workspace-display-share-btn",onClick:sL,title:"查看我的展示分享",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"folder_shared"}),"我的分享"]}),i.jsx("button",{type:"button",className:"af-icon-btn",disabled:!ES,onClick:()=>h(!0),"aria-label":e("project:archiveModal.title"),title:e("project:archiveModal.title"),children:i.jsx("span",{className:"material-symbols-outlined",children:"archive"})}),i.jsx("button",{type:"button",className:"af-icon-btn af-icon-btn--danger",disabled:!ES&&!lu,onClick:()=>k(!0),"aria-label":lu?"退出共享 Workspace":e("flow:topbar.deletePipeline"),title:lu?"退出共享 Workspace":e("flow:topbar.deletePipeline"),children:i.jsx("span",{className:"material-symbols-outlined",children:lu?"logout":"delete_forever"})}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>Ef(!0),"aria-label":"快捷键",title:"快捷键 (?)",children:i.jsx("span",{className:"material-symbols-outlined",children:"help"})}),i.jsx("button",{type:"button",className:"af-composer-topbar-btn"+(tu?" af-composer-topbar-btn--active":"")+(ns?" af-composer-topbar-btn--running":""),disabled:ut||Pn,onClick:()=>{gl(null),ml(x=>(x||bs(ga()),!x))},children:"AI"}),i.jsx("button",{type:"button",className:"af-btn-primary af-btn-primary--lg",disabled:!je,onClick:()=>Zt().catch(x=>ge(String(x.message||x))),children:"Save"})]})]}),gs?i.jsxs("div",{className:"af-flow-snippet-toast",role:"status","aria-live":"polite",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"check_circle"}),i.jsx("span",{children:gs}),i.jsx("button",{type:"button",onClick:()=>ys(""),"aria-label":"关闭发布提示",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}):null,i.jsxs("div",{className:"af-workspace-body"+(!ut&&!Pn&&(tu||at)?" af-workspace-body--drawer":"")+(!ut&&!Pn&&ru?" af-workspace-body--sidebar-collapsed":"")+(ut?" af-workspace-body--display-mode":"")+(Pn?" af-workspace-body--workflow-mode":""),children:[!ut&&!Pn&&ru?i.jsx("nav",{className:"af-workspace-rail","aria-label":"Workspace sidebar",children:i.jsxs("div",{className:"af-workspace-rail__stack",children:[i.jsxs("button",{type:"button",className:"af-workspace-rail__primary",onClick:()=>q(!0),"aria-label":"添加节点",title:"添加节点",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add"}),i.jsx("span",{className:"af-workspace-rail__dot","aria-hidden":!0})]}),i.jsx("button",{type:"button",className:"af-workspace-rail__btn",onClick:()=>_f(!1),"aria-label":"展开文件",title:"展开文件",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"folder"})}),i.jsx("span",{className:"af-workspace-rail__divider","aria-hidden":!0}),i.jsx("button",{type:"button",className:"af-workspace-rail__avatar",onClick:()=>_f(!1),"aria-label":"展开侧边栏",title:(Ir==null?void 0:Ir.username)||(Ir==null?void 0:Ir.userId)||"展开侧边栏",children:J$})]})}):null,!ut&&!Pn?i.jsxs("aside",{ref:Ng,className:"af-workspace-sidebar"+(m$?" af-workspace-sidebar--resizing":""),"aria-hidden":ru,style:{"--af-work-files-pane-height":`${Math.round(jg)}px`},children:[i.jsxs("section",{className:"af-workspace-files-section",children:[i.jsxs("div",{className:"af-workspace-sidebar-head",children:[i.jsx("h2",{children:"Files"}),i.jsxs("div",{className:"af-workspace-sidebar-actions",children:[i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>_f(!0),"aria-label":"最小化侧边栏",title:"最小化侧边栏",children:i.jsx("span",{className:"material-symbols-outlined",children:"keyboard_double_arrow_left"})}),i.jsx("button",{type:"button",className:"af-icon-btn",disabled:!je,onClick:()=>CL(Fi),"aria-label":"新增文件",title:Fi?`在 ${Fi} 新增文件`:"新增文件",children:i.jsx("span",{className:"material-symbols-outlined",children:"note_add"})}),i.jsx("button",{type:"button",className:"af-icon-btn",disabled:!je,onClick:()=>_L(Fi),"aria-label":"新增文件夹",title:Fi?`在 ${Fi} 新增文件夹`:"新增文件夹",children:i.jsx("span",{className:"material-symbols-outlined",children:"create_new_folder"})}),i.jsx("button",{type:"button",className:"af-icon-btn",disabled:!je||Hv,onClick:()=>qS(Fi),"aria-label":"上传文件",title:Fi?`上传到 ${Fi}`:"上传文件",children:i.jsx("span",{className:"material-symbols-outlined",children:Hv?"hourglass_top":"upload_file"})}),i.jsx("button",{type:"button",className:"af-icon-btn",onClick:()=>void An(),"aria-label":"刷新文件",title:"刷新文件",children:i.jsx("span",{className:"material-symbols-outlined",children:"refresh"})}),i.jsx("input",{ref:Vv,type:"file",multiple:!0,className:"af-visually-hidden",onChange:z$})]})]}),i.jsx("input",{className:"af-workspace-search",value:bg,onChange:x=>p$(x.target.value),placeholder:"搜索文件..."}),i.jsx("div",{className:"af-workspace-files-scroll",onClick:Y$,children:i.jsx(iM,{items:U$,onOpen:SL,selectedPath:kg,collapsedDirs:h$,onToggleDir:bL,onSelect:x=>vg(x.path||""),onFileDragStart:kL,onDelete:EL,onDownload:AL})})]}),i.jsx("button",{type:"button",className:"af-workspace-sidebar-resizer",onPointerDown:N$,role:"separator","aria-orientation":"horizontal","aria-label":"调整 Files 和 Palette 区域大小",title:"拖动调整 Files / Palette 高度"}),i.jsxs("section",{className:"af-workspace-nodes-section",children:[i.jsxs("div",{className:"af-node-palette-head af-workspace-node-palette-head",children:[i.jsxs("h2",{className:"af-node-palette-title",children:[i.jsx("span",{children:"Palette"}),i.jsx("span",{className:"af-node-palette-title-kbd","aria-label":"快捷键 A",children:"A"})]}),i.jsxs("label",{className:"af-palette-search-wrap",children:[i.jsx("span",{className:"af-visually-hidden",children:on==="flows"?"搜索流程片段":"搜索节点"}),i.jsx("span",{className:"af-palette-search-icon material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",className:"af-palette-search-input",value:jt,onChange:x=>yn(x.target.value),placeholder:on==="flows"?"搜索流程片段...":"搜索节点...","aria-label":on==="flows"?"搜索流程片段":"搜索节点"})]}),i.jsxs("div",{className:"af-palette-tabs",role:"tablist","aria-label":"Palette 类型",children:[i.jsxs("button",{type:"button",role:"tab","aria-selected":on==="nodes",className:"af-palette-tab"+(on==="nodes"?" af-palette-tab--active":""),onClick:()=>re("nodes"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"category"}),"节点"]}),i.jsxs("button",{type:"button",role:"tab","aria-selected":on==="flows",className:"af-palette-tab"+(on==="flows"?" af-palette-tab--active":""),onClick:()=>re("flows"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"account_tree"}),"流程"]})]})]}),i.jsx("div",{className:"af-node-palette-scroll af-workspace-node-palette-scroll",children:on==="flows"?i.jsxs(i.Fragment,{children:[i.jsx("section",{className:"af-palette-section af-flow-palette-section--snippets",children:i.jsxs("div",{className:"af-flow-snippet-actions",children:[i.jsxs("button",{type:"button",className:"af-flow-snippet-publish-btn",onClick:Q$,disabled:er.length<2,title:er.length<2?"选择至少两个节点后发布流程片段":"发布选中的流程片段",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"ios_share"}),"发布选中片段"]}),i.jsxs("span",{className:"af-flow-snippet-selection",children:["已选 ",er.length," 节点 / ",zf.length," 连线"]})]})}),At?i.jsx("p",{className:"af-err af-palette-list-err",children:At}):null,Ze?i.jsx("p",{className:"af-palette-empty",children:"正在加载流程片段..."}):d0.length>0?i.jsxs("section",{className:"af-palette-section af-flow-palette-section--snippets",children:[i.jsx("h3",{className:"af-palette-cat",children:"FLOW SNIPPETS"}),i.jsx("div",{className:"af-palette-cards",children:d0.map(x=>{const S=`${x.id}@${x.version}`,_=x.displayName||x.name||x.id,A=x.description||`${x.nodeCount||0} 个节点,${x.edgeCount||0} 条连线`;return i.jsxs("button",{type:"button",className:"af-palette-card af-flow-snippet-card",draggable:!0,onDragStart:R=>{R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("application/agentflow-snippet",S),R.dataTransfer.setData("text/plain",S)},onClick:()=>yu(x),title:A,children:[i.jsxs("span",{className:"af-palette-card-head",children:[i.jsx("span",{className:"af-palette-card-icon","aria-hidden":!0,children:i.jsx("span",{className:"material-symbols-outlined",children:"account_tree"})}),i.jsxs("span",{className:"af-palette-card-main",children:[i.jsx("span",{className:"af-palette-card-label",children:_}),i.jsxs("span",{className:"af-palette-card-id",children:[x.id,"@",x.version]})]})]}),A?i.jsx("span",{className:"af-palette-card-desc",children:A}):null,i.jsxs("span",{className:"af-flow-snippet-meta","aria-hidden":!0,children:[i.jsxs("span",{children:[x.nodeCount||0," nodes"]}),i.jsxs("span",{children:[x.edgeCount||0," edges"]})]})]},S)})})]}):i.jsx("p",{className:"af-palette-empty",children:jt.trim()?"没有匹配的流程片段":"暂无流程片段。选择多个节点后发布。"})]}):i.jsxs(i.Fragment,{children:[Ol.map(x=>{var S;return(S=Kg[x])!=null&&S.length?i.jsxs("section",{className:`af-palette-section af-flow-palette-section--${x}`,children:[i.jsx("h3",{className:"af-palette-cat",children:x}),i.jsx("div",{className:"af-palette-cards",children:Kg[x].map(_=>{const A=AC(_.inputs,"input"),R=AC(_.outputs,"output"),U=ub(_),X=Vu(_);return i.jsxs("button",{type:"button",className:"af-palette-card",draggable:!0,onDragStart:J=>vL(J,_),onClick:()=>zi(_),title:U||_.id,children:[i.jsxs("span",{className:"af-palette-card-head",children:[i.jsx("span",{className:"af-palette-card-icon","aria-hidden":!0,children:i.jsx("span",{className:"material-symbols-outlined",children:_C(x)})}),i.jsxs("span",{className:"af-palette-card-main",children:[i.jsx("span",{className:"af-palette-card-label",children:X}),X!==_.id?i.jsx("span",{className:"af-palette-card-id",children:_.id}):null]})]}),U?i.jsx("span",{className:"af-palette-card-desc",children:U}):null,i.jsxs("span",{className:"af-palette-card-ports","aria-hidden":!0,children:[i.jsxs("span",{className:"af-palette-card-port-side af-palette-card-port-side--in",children:[i.jsxs("span",{className:"af-palette-card-port-count",children:[A.list.length," IN"]}),i.jsxs("span",{className:"af-palette-card-port-list",children:[A.shown.map((J,Y)=>i.jsxs("span",{className:"af-palette-card-port",title:EC("input",J,Y),children:[i.jsx("span",{className:"af-palette-card-port-dot",style:{background:Tn(J==null?void 0:J.type)}}),i.jsx("span",{className:"af-palette-card-port-name",children:$p(J,Y)})]},`in-${Y}`)),A.hidden>0?i.jsxs("span",{className:"af-palette-card-port-more",children:["+",A.hidden]}):null]})]}),i.jsxs("span",{className:"af-palette-card-port-side af-palette-card-port-side--out",children:[i.jsxs("span",{className:"af-palette-card-port-count",children:[R.list.length," OUT"]}),i.jsxs("span",{className:"af-palette-card-port-list",children:[R.shown.map((J,Y)=>i.jsxs("span",{className:"af-palette-card-port",title:EC("output",J,Y),children:[i.jsx("span",{className:"af-palette-card-port-name",children:$p(J,Y)}),i.jsx("span",{className:"af-palette-card-port-dot",style:{background:Tn(J==null?void 0:J.type)}})]},`out-${Y}`)),R.hidden>0?i.jsxs("span",{className:"af-palette-card-port-more",children:["+",R.hidden]}):null]})]})]})]},_.id)})})]},x):null}),be.length>0&&jt.trim()&&Ol.every(x=>{var S;return!((S=Kg[x])!=null&&S.length)})?i.jsx("p",{className:"af-palette-empty",children:"没有匹配的节点"}):null]})})]})]}):null,Pn?i.jsx($J,{flowParams:a,tapdId:ir,setTapdId:k$,snapshot:ln,loading:v$,error:S$,actionRunning:Cg,actionOutput:_g,pendingConfirm:xs,conflict:Zc,reviewPublishing:Eg,onRefresh:()=>uu(ir),onRunDryRun:T$,onConfirmAction:M$,onRetryConflict:$$,onPublishReview:L$}):i.jsxs("main",{ref:C,className:"af-workspace-canvas",tabIndex:-1,onPointerDownCapture:xL,children:[i.jsx(gR,{className:"af-flow-canvas af-workspace-flow"+(Og==="pan"?" af-flow-canvas--tool-pan":" af-flow-canvas--tool-select")+(ut?" af-workspace-flow--display-mode":""),nodes:Df,edges:K$,nodeTypes:uJ,onNodesChange:dL,onEdgesChange:fL,onConnect:ut?void 0:hL,onConnectStart:ut?void 0:mL,onConnectEnd:ut?void 0:gL,isValidConnection:ut?void 0:pL,onNodeClick:(x,S)=>{var _;if(ut){K([Op(S.id)]);return}if((_=S==null?void 0:S.data)!=null&&_.isWorkspaceGroup){jn("");return}if(x.detail>=3){ml(!1),g(A=>A.map(R=>({...R,selected:R.id===S.id}))),w(A=>A.map(R=>({...R,selected:!1}))),jn(S.id);return}Ut&&jn(S.id)},onNodeDoubleClick:x=>{x.preventDefault()},onPaneClick:()=>{ut?K([]):jn("")},onDrop:ut?void 0:NL,onDragOver:ut?void 0:jL,nodesDraggable:ut?!0:je,nodesConnectable:ut?!1:je,edgesReconnectable:ut?!1:je,onlyRenderVisibleElements:Df.length>=80,deleteKeyCode:ut?null:je?["Backspace","Delete"]:null,selectionOnDrag:Og==="select",panOnDrag:Og==="pan"?!0:[1,2],panActivationKeyCode:"Space",proOptions:{hideAttribution:!0},fitView:!1,minZoom:.1,maxZoom:4,children:i.jsx(wR,{color:"rgba(255,255,255,0.12)",gap:22,size:1})}),!ut&&G?(()=>{var J;const x=String(G.query||"").trim().toLowerCase(),S=G.mode==="create"?"create":"existing",_=Array.isArray(G.candidates)?G.candidates:[],A=Array.isArray(G.existingCandidates)?G.existingCandidates:[],R=x?_.filter(Y=>{var ae,pe,fe;return[(ae=Y.def)==null?void 0:ae.id,Y.displayLabel,Y.description,(pe=Y.slot)==null?void 0:pe.name,(fe=Y.slot)==null?void 0:fe.type].filter(Boolean).some(Ne=>String(Ne).toLowerCase().includes(x))}):_,U=x?A.filter(Y=>{var ae,pe;return[Y.nodeId,Y.nodeLabel,Y.definitionId,(ae=Y.slot)==null?void 0:ae.name,(pe=Y.slot)==null?void 0:pe.type].filter(Boolean).some(fe=>String(fe).toLowerCase().includes(x))}):A,X=G.draft.handleType==="source"?"IN":"OUT";return i.jsxs("div",{className:"af-connect-node-menu",style:{left:G.left,top:G.top},role:"dialog","aria-label":"选择匹配节点",children:[i.jsxs("div",{className:"af-connect-node-menu__head",children:[i.jsxs("div",{className:"af-connect-node-menu__title",children:[i.jsx("span",{className:"af-connect-node-menu__dot",style:{background:Tn((J=G.draft.slot)==null?void 0:J.type)},"aria-hidden":!0}),i.jsxs("span",{children:["匹配 ",G.draft.slotType," 节点"]})]}),i.jsx("button",{type:"button",className:"af-connect-node-menu__close","aria-label":"关闭",onClick:()=>ee(null),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-connect-node-menu__tabs",role:"tablist","aria-label":"连接方式",children:[i.jsxs("button",{type:"button",className:S==="existing"?"af-connect-node-menu__tab af-connect-node-menu__tab--active":"af-connect-node-menu__tab",disabled:A.length===0,onClick:()=>ee(Y=>Y&&{...Y,mode:"existing",query:""}),children:["连接已有 ",i.jsx("span",{children:A.length})]}),i.jsxs("button",{type:"button",className:S==="create"?"af-connect-node-menu__tab af-connect-node-menu__tab--active":"af-connect-node-menu__tab",disabled:_.length===0,onClick:()=>ee(Y=>Y&&{...Y,mode:"create",query:""}),children:["新建节点 ",i.jsx("span",{children:_.length})]})]}),i.jsxs("label",{className:"af-connect-node-menu__search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:G.query,onChange:Y=>ee(ae=>ae&&{...ae,query:Y.target.value}),placeholder:"搜索节点",autoFocus:!0})]}),i.jsxs("div",{className:"af-connect-node-menu__list",children:[S==="create"?R.map(Y=>{var fe,Ne;const ae=Y.displayLabel||((fe=Y.def)==null?void 0:fe.id),pe=$p(Y.slot,Y.slotIndex);return i.jsxs("button",{type:"button",className:"af-connect-node-menu__item",onClick:()=>yL(Y),title:Y.description||Y.def.id,children:[i.jsxs("span",{className:"af-connect-node-menu__item-main",children:[i.jsx("span",{className:"af-connect-node-menu__item-label",children:ae}),ae!==Y.def.id?i.jsx("span",{className:"af-connect-node-menu__item-id",children:Y.def.id}):null]}),i.jsxs("span",{className:"af-connect-node-menu__port",children:[i.jsx("span",{children:X}),i.jsx("span",{className:"af-connect-node-menu__port-dot",style:{background:Tn((Ne=Y.slot)==null?void 0:Ne.type)},"aria-hidden":!0}),i.jsx("span",{className:"af-connect-node-menu__port-name",children:pe})]})]},`${Y.def.id}-${Y.slotIndex}`)}):U.map(Y=>{var fe;const ae=Y.nodeLabel||Y.nodeId,pe=$p(Y.slot,Y.slotIndex);return i.jsxs("button",{type:"button",className:"af-connect-node-menu__item",onClick:()=>wL(Y),title:`${Y.definitionId||Y.nodeId} · ${pe}`,children:[i.jsxs("span",{className:"af-connect-node-menu__item-main",children:[i.jsx("span",{className:"af-connect-node-menu__item-label",children:ae}),i.jsxs("span",{className:"af-connect-node-menu__item-id",children:[Y.definitionId?`${Y.definitionId} · `:"",Y.nodeId]})]}),i.jsxs("span",{className:"af-connect-node-menu__port",children:[i.jsx("span",{children:X}),i.jsx("span",{className:"af-connect-node-menu__port-dot",style:{background:Tn((fe=Y.slot)==null?void 0:fe.type)},"aria-hidden":!0}),i.jsx("span",{className:"af-connect-node-menu__port-name",children:pe}),Y.occupied?i.jsx("span",{className:"af-connect-node-menu__port-badge",children:"替换"}):null]})]},`${Y.nodeId}-${Y.handleId}`)}),(S==="create"?R.length:U.length)===0?i.jsx("div",{className:"af-connect-node-menu__empty",children:"没有匹配结果"}):null]})]})})():null,!ut&&!Pn&&!E$?i.jsx("div",{className:"af-workspace-composer af-bottom-composer-stack af-flow-bottom-composer",children:i.jsxs("div",{className:"af-pipeline-composer-inner",children:[i.jsx("button",{type:"button",className:"af-workspace-composer-minimize",onClick:()=>Mg(!0),"aria-label":"最小化 AI 输入框",title:"最小化",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"remove"})}),i.jsx("div",{className:"af-composer-selected","aria-label":"Selected workspace nodes",children:er.length===0?i.jsx("span",{className:"af-composer-selected-empty",children:"选择画布节点后,可作为本次 Workspace AI 的上下文。"}):er.map(x=>{var R,U;const S=String(((R=x.data)==null?void 0:R.label)??x.id),_=(U=x.data)!=null&&U.definitionId?String(x.data.definitionId):"",A=_&&_!==S?`${S} · ${x.id} · ${_}`:`${S} · ${x.id}`;return i.jsxs("div",{className:"af-composer-node-chip",title:A,children:[i.jsx("span",{className:"af-composer-node-chip-kind",children:_||"node"}),i.jsx("span",{className:"af-composer-node-chip-label",children:S}),i.jsx("button",{type:"button",className:"af-composer-node-chip-dismiss",onClick:()=>uL(x.id),"aria-label":`取消选择 ${x.id}`,children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]},x.id)})}),i.jsxs("div",{className:"af-composer-card af-composer-card--input-only",children:[i.jsx("div",{className:"af-composer-input-wrap",children:i.jsx("textarea",{className:"af-composer-textarea",value:fa,rows:2,onChange:x=>Rg(x.target.value),onKeyDown:x=>{(x.metaKey||x.ctrlKey)&&x.key==="Enter"&&(x.preventDefault(),qf())},placeholder:"描述你想在 workspace 中生成、分析或展示的内容",autoComplete:"off",spellCheck:!1,disabled:!je})}),i.jsxs("div",{className:"af-composer-toolbar",children:[i.jsxs("div",{className:"af-composer-skills-field",children:[i.jsxs("button",{ref:Ig,type:"button",className:"af-composer-skills-button"+($s.length>0?" af-composer-skills-button--active":""),disabled:ns||!je,"aria-haspopup":"listbox","aria-expanded":Cf,onClick:()=>Pg(x=>!x),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"extension"}),i.jsx("span",{children:$s.length>0?`Skills ${$s.length}`:"Skills"})]}),Cf&&!ns?cr.createPortal(i.jsx("div",{ref:aS,className:"af-composer-skills-menu",role:"listbox","aria-label":"Skills",style:C$,children:Ms.length===0?i.jsx("div",{className:"af-composer-skills-empty",children:"No skills found"}):i.jsxs(i.Fragment,{children:[Sl.groups.map(x=>{const S=Qo(x,Ms),_=jF(x,qg,Ms),A=j$.has(x.id);return i.jsxs("div",{className:"af-composer-skill-group af-composer-skill-group--framed"+(A?" af-composer-skill-group--collapsed":""),children:[i.jsxs("div",{className:"af-composer-skill-group-title af-composer-skill-group-title--selectable",children:[i.jsxs("label",{className:"af-composer-skill-group-check",children:[i.jsx("input",{type:"checkbox",checked:_==="all",disabled:S.length===0,onChange:R=>{const U=R.target.checked;Qc(X=>U?SF(X,S):NF(X,S))}}),i.jsxs("span",{className:"af-composer-skill-group-title-main",children:[i.jsx("span",{children:x.name}),x.builtin?i.jsx("em",{children:"built-in"}):null,_==="partial"?i.jsx("em",{children:"partial"}):null]})]}),i.jsxs("button",{type:"button",className:"af-composer-skill-group-toggle","aria-label":A?`展开 ${x.name}`:`收起 ${x.name}`,onClick:()=>{oS(R=>{const U=new Set(R);return U.has(x.id)?U.delete(x.id):U.add(x.id),U})},children:[i.jsx("span",{children:x.skills.length}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:A?"expand_more":"expand_less"})]})]}),A?null:i.jsx("div",{className:"af-composer-skill-group-items",children:x.skills.map(R=>i.jsxs("label",{className:"af-composer-skill-option",children:[i.jsx("input",{type:"checkbox",checked:qg.has(R.key),onChange:U=>{const X=U.target.checked;Qc(J=>X?J.includes(R.key)?J:[...J,R.key]:J.filter(Y=>Y!==R.key))}}),i.jsxs("span",{className:"af-composer-skill-option-main",children:[i.jsx("span",{className:"af-composer-skill-option-title",children:R.name}),R.description?i.jsx("span",{className:"af-composer-skill-option-desc",children:R.description}):null]})]},`${x.id}:${R.key}`))})]},x.id)}),Sl.ungrouped.length>0?i.jsxs("div",{className:"af-composer-skill-group",children:[i.jsxs("div",{className:"af-composer-skill-group-title",children:[i.jsx("span",{children:"Ungrouped"}),i.jsx("span",{children:Sl.ungrouped.length})]}),Sl.ungrouped.map(x=>i.jsxs("label",{className:"af-composer-skill-option",children:[i.jsx("input",{type:"checkbox",checked:qg.has(x.key),onChange:S=>{const _=S.target.checked;Qc(A=>_?A.includes(x.key)?A:[...A,x.key]:A.filter(R=>R!==x.key))}}),i.jsxs("span",{className:"af-composer-skill-option-main",children:[i.jsx("span",{className:"af-composer-skill-option-title",children:x.name}),x.description?i.jsx("span",{className:"af-composer-skill-option-desc",children:x.description}):null]})]},`ungrouped:${x.key}`))]}):null]})}),document.body):null]}),i.jsx("label",{className:"af-composer-model-field",children:i.jsxs("select",{className:"af-composer-model-select",value:Li,onChange:x=>y$(x.target.value),"aria-label":"模型",children:[i.jsx("option",{value:"",children:"默认模型"}),G$.map(x=>i.jsx("option",{value:x.value,children:x.label},x.value))]})}),i.jsx("button",{type:"button",className:"af-composer-send"+(fa.trim()&&!ns?" af-composer-send--active":"")+(ns?" af-composer-send--stop":""),disabled:ns||!fa.trim()||!je,"aria-label":ns?"Running":"Send",onClick:()=>void qf(),children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:ns?"sync":"arrow_upward"})})]})]})]})}):!ut&&!Pn?i.jsx("button",{type:"button",className:"af-workspace-composer-fab",onClick:()=>Mg(!1),"aria-label":"展开 AI 输入框",title:"展开 AI 输入框",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"auto_awesome"})}):null]}),!ut&&!Pn&&tu?i.jsx("aside",{className:"af-pipeline-drawer af-pipeline-drawer--wide af-workspace-composer-drawer","aria-label":"Workspace AI Composer",children:i.jsxs("div",{className:"af-composer-sidebar",children:[i.jsxs("div",{className:"af-pipeline-drawer-head",children:[i.jsx("h2",{className:"af-pipeline-drawer-title",children:"AI Composer"}),i.jsx("button",{type:"button",className:"af-pipeline-drawer-close af-icon-btn",onClick:()=>ml(!1),"aria-label":"关闭 AI 对话侧栏",children:i.jsx("span",{className:"material-symbols-outlined",children:"close"})})]}),i.jsxs("div",{className:"af-composer-session-tabs",children:[i.jsx("button",{type:"button",className:"af-composer-session-tab"+(Hr==="workspace"?" af-composer-session-tab--active":""),ref:Hr==="workspace"?Tg:null,onClick:()=>bs("workspace"),children:i.jsx("span",{className:"af-composer-session-label",children:"Workspace"})}),Ls.map(x=>i.jsxs("div",{role:"tab",tabIndex:0,ref:Hr===x.id?Tg:null,className:"af-composer-session-tab"+(Hr===x.id?" af-composer-session-tab--active":"")+(x.status==="running"||x.status==="stopping"?" af-composer-session-tab--running":""),onClick:()=>bs(x.id),onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),bs(x.id))},title:x.runNodeId||x.label,children:[i.jsx("span",{className:"af-composer-session-label",children:x.label}),i.jsx("button",{type:"button",className:"af-composer-session-close",onClick:S=>{S.preventDefault(),S.stopPropagation(),D$(x.id)},"aria-label":`关闭 ${x.label}`,title:"关闭 tab",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]},x.id))]}),i.jsx("div",{className:"af-composer-sidebar-status"+(Cl?" af-composer-sidebar-status--running":""),role:"status","aria-live":"polite",children:w0}),i.jsxs("div",{className:"af-composer-sidebar-thread",ref:uS,children:[i.jsx(zC,{messages:PL,running:Cl,showRunningIndicator:!or}),Xg.length>0?i.jsxs("details",{className:"af-composer-sidebar-log-details",...Cl?{open:!0}:{},children:[i.jsx("summary",{children:"执行日志"}),i.jsx(zC,{messages:Xg,running:!1,showRunningIndicator:!1})]}):null]}),i.jsxs("div",{className:"af-composer-sidebar-input",children:[i.jsx("textarea",{className:"af-composer-sidebar-textarea",value:fa,rows:3,onChange:x=>Rg(x.target.value),onKeyDown:x=>{(x.metaKey||x.ctrlKey)&&x.key==="Enter"&&(x.preventDefault(),qf())},placeholder:or?"继续追问、总结或要求调整这次结果":"继续描述你想让 AI 在 workspace 中做什么",disabled:!je||Cl}),i.jsx("button",{type:"button",className:"af-composer-sidebar-send",disabled:!je||Cl||!fa.trim(),onClick:()=>void qf(),"aria-label":"发送 AI 对话",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"arrow_upward"})})]})]})}):!ut&&!Pn&&at&&Vt?i.jsx("aside",{className:"af-pipeline-drawer af-workspace-node-drawer","aria-label":"Workspace Node Properties",children:i.jsx(MU,{draft:at,setDraft:ws,definitionId:String(((b0=Vt.data)==null?void 0:b0.definitionId)||Vt.id),systemPromptReadonly:String(((k0=Vt.data)==null?void 0:k0.description)||""),modelLists:da,disabled:!je,onIdBlur:()=>Hg(!0),onClose:()=>jn(""),onPublishToMarketplace:O$,error:l$,ioSlots:{inputs:Array.isArray(at==null?void 0:at.inputs)?at.inputs:[],outputs:Array.isArray(at==null?void 0:at.outputs)?at.outputs:[]}})}):null,!ut&&!Pn&&nu?cr.createPortal(i.jsx("div",{className:"af-workspace-run-logs-overlay",role:"presentation",onMouseDown:()=>gl(null),children:i.jsx("aside",{className:"af-workspace-run-logs-drawer","aria-label":"Workspace Run Logs",onMouseDown:x=>x.stopPropagation(),children:i.jsx(xU,{flowParams:a,scheduleNodeId:nu.scheduleNodeId,runNodeId:nu.runNodeId,lastRunId:nu.lastRunId,label:nu.label,onClose:()=>gl(null)})})}),document.body):null,i.jsx(mU,{open:$g,onClose:()=>Ef(!1)}),i.jsx(yU,{open:Lg,onClose:()=>gS(!1),onJump:Vg,nodes:q$}),i.jsx($U,{open:p,onClose:()=>h(!1),flowId:a.flowId||"",flowSource:au,onArchived:()=>{h(!1),n("/projects?tab=archived")}}),i.jsx(LU,{open:y&&!!a.flowId,onClose:()=>k(!1),flowId:a.flowId||"",flowSource:au,flowArchived:!!a.archived,workspaceId:a.workspaceId||"",leaveShared:lu,onDeleted:async()=>{k(!1),n("/projects")}}),f$&&En?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-workspace-conflict-modal",role:"dialog","aria-modal":"true","aria-label":"解决 Workspace 冲突",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"difference"}),"解决 ",((v0=En.conflictItems)==null?void 0:v0.length)||0," 处字段冲突"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>ua(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("div",{className:"af-workspace-conflict-summary",children:["未冲突的改动已经自动合并。这里只需要决定双方同时修改的字段。",i.jsxs("div",{className:"af-workspace-conflict-bulk",children:[i.jsx("button",{type:"button",onClick:()=>ul(Object.fromEntries((En.conflictItems||[]).map((x,S)=>[String(S),{mode:"local",manual:Ru(x)}]))),children:"全部保留我的"}),i.jsx("button",{type:"button",onClick:()=>ul(Object.fromEntries((En.conflictItems||[]).map((x,S)=>[String(S),{mode:"remote",manual:Ru(x)}]))),children:"全部使用远端"})]})]}),(En.conflictItems||[]).map((x,S)=>{const _=xg[String(S)]||{mode:"local",manual:Ru(x)};return i.jsxs("section",{className:"af-workspace-conflict-item",children:[i.jsx("code",{className:"af-workspace-conflict-path",children:x.path}),i.jsx("div",{className:"af-workspace-conflict-options",children:[["local","保留我的"],["remote","使用远端"],["manual","手动编辑"]].map(([A,R])=>i.jsx("button",{type:"button",className:_.mode===A?"is-active":"",onClick:()=>ul(U=>({...U,[String(S)]:{..._,mode:A}})),children:R},A))}),i.jsxs("div",{className:"af-workspace-conflict-values",children:[i.jsxs("div",{className:_.mode==="local"?"is-selected":"",children:[i.jsx("span",{children:"我的修改"}),i.jsx("pre",{children:GC(x,"incoming")})]}),i.jsxs("div",{className:_.mode==="remote"?"is-selected":"",children:[i.jsx("span",{children:"远端修改"}),i.jsx("pre",{children:GC(x,"current")})]})]}),_.mode==="manual"?i.jsxs("label",{className:"af-workspace-conflict-manual",children:[i.jsx("span",{children:"最终值(JSON)"}),i.jsx("textarea",{value:_.manual,onChange:A=>ul(R=>({...R,[String(S)]:{..._,manual:A.target.value}})),rows:5})]}):null]},`${x.path||"conflict"}-${S}`)}),Bv?i.jsx("div",{className:"af-flow-snippet-error",children:Bv}):null]}),i.jsxs("div",{className:"af-flow-snippet-modal__foot af-workspace-conflict-foot",children:[i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",disabled:vf,onClick:()=>void h0(),children:"备份并载入远端"}),i.jsx("span",{className:"af-workspace-conflict-foot__spacer"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",disabled:vf,onClick:()=>ua(!1),children:"稍后处理"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",disabled:vf||!(En.conflictItems||[]).length,onClick:()=>void nL(),children:vf?"保存中...":"应用选择并保存"})]})]})}),document.body):null,Sn?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal",role:"dialog","aria-modal":"true","aria-label":"发布流程片段",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"ios_share"}),"发布流程片段"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>xr(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"名称"}),i.jsx("input",{type:"text",value:wn.name,onChange:x=>{const S=x.target.value;Xn(_=>({..._,name:S,id:_.id?_.id:S.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"")}))},placeholder:"例如:内容整理片段",autoFocus:!0})]}),i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"ID"}),i.jsx("input",{type:"text",value:wn.id,onChange:x=>Xn(S=>({...S,id:x.target.value})),placeholder:"content-cleanup-snippet"})]}),i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"说明"}),i.jsx("textarea",{value:wn.description,onChange:x=>Xn(S=>({...S,description:x.target.value})),placeholder:"这段流程适合什么 workspace 场景、需要接哪些上下游。",rows:4})]}),i.jsxs("div",{className:"af-flow-snippet-summary",children:["将发布 ",er.length," 个节点和 ",zf.length," 条内部连线。"]}),ts?i.jsx("div",{className:"af-flow-snippet-error",children:ts}):null]}),i.jsxs("div",{className:"af-flow-snippet-modal__foot",children:[i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",onClick:()=>xr(!1),children:"取消"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",disabled:Kn||!wn.name.trim(),onClick:()=>void Z$(),children:Kn?"发布中...":"发布"})]})]})}),document.body):null,t0?i.jsx(QG,{node:t0,onClose:()=>zn("")}):null,rr?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-share-modal",role:"dialog","aria-modal":"true","aria-label":wo?"新建分享":"发布展示页",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"present_to_all"}),wo?"新建分享":"发布展示页"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>Pr(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"标题"}),i.jsx("input",{type:"text",value:_t.title,onChange:x=>le(S=>({...S,title:x.target.value})),placeholder:"展示页标题",autoFocus:!0})]}),wo?null:i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"布局"}),i.jsxs("select",{className:"af-display-share-select",value:_t.layout,onChange:x=>le(S=>({...S,layout:x.target.value})),children:[i.jsx("option",{value:"gallery",children:"Gallery"}),i.jsx("option",{value:"document",children:"Document"}),i.jsx("option",{value:"slides",children:"Slides"})]})]}),i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"有效期"}),i.jsx("select",{className:"af-display-share-select",value:MC(_t),onChange:x=>{const S=x.target.value;le(_=>({..._,permanent:S==="permanent",expiresInDays:S==="permanent"?_.expiresInDays||30:Number(S)}))},children:aw.map(x=>i.jsx("option",{value:x.value,children:x.label},x.value))})]}),i.jsxs("div",{className:"af-display-share-node-list",role:"group","aria-label":wo?"分享内容":"选择展示节点",children:[wo?i.jsx("span",{className:"af-display-share-node-list__label",children:"分享内容"}):null,RL.map(x=>{var _;const S=Array.isArray(_t.nodeIds)&&_t.nodeIds.includes(x.id);return i.jsxs("label",{className:"af-display-share-node-row",children:[i.jsx("input",{type:"checkbox",checked:S,disabled:wo,onChange:()=>rL(x.id)}),i.jsxs("span",{className:"af-display-share-node-row__main",children:[i.jsx("strong",{children:((_=x.data)==null?void 0:_.label)||x.id}),i.jsxs("small",{children:[In(x.data)," · ",x.id]})]})]},x.id)})]}),Ct!=null&&Ct.absoluteUrl?i.jsxs("div",{className:"af-display-share-result",children:[i.jsx("input",{type:"text",readOnly:!0,value:Ct.absoluteUrl,onFocus:x=>x.target.select()}),i.jsx("button",{type:"button",onClick:()=>window.open(Ct.absoluteUrl,"_blank","noopener,noreferrer"),children:"打开"}),i.jsx("button",{type:"button",onClick:()=>void m0(),children:tn==="copied"?"已复制":tn==="failed"?"复制失败":"复制"})]}):null,br?i.jsx("div",{className:"af-flow-snippet-error",children:br}):null]}),i.jsxs("div",{className:"af-flow-snippet-modal__foot",children:[i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",onClick:()=>Pr(!1),children:"取消"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",disabled:dn||!Array.isArray(_t.nodeIds)||_t.nodeIds.length===0,onClick:()=>void iL(),children:dn?"生成中...":"生成链接"})]})]})}),document.body):null,Dt?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-link-modal",role:"dialog","aria-modal":"true","aria-label":"展示链接",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"link"}),"展示链接"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>{Zn(""),Jt(!1)},"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[Ct!=null&&Ct.absoluteUrl?i.jsxs("div",{className:"af-display-link-modal__url",children:[i.jsx("input",{type:"text",readOnly:!0,value:Ct.absoluteUrl,onFocus:x=>x.target.select(),autoFocus:!0}),i.jsxs("button",{type:"button",onClick:()=>window.open(Ct.absoluteUrl,"_blank","noopener,noreferrer"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"}),"打开"]}),i.jsxs("button",{type:"button",onClick:()=>void m0(),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:tn==="copied"?"check":"content_copy"}),tn==="copied"?"已复制":tn==="failed"?"复制失败":"复制"]})]}):i.jsx("div",{className:"af-display-link-modal__empty",children:"还没有生成展示链接"}),i.jsxs("label",{className:"af-flow-snippet-field",children:[i.jsx("span",{children:"新链接有效期"}),i.jsx("select",{className:"af-display-share-select",value:MC(_t),onChange:x=>{const S=x.target.value;le(_=>({..._,permanent:S==="permanent",expiresInDays:S==="permanent"?_.expiresInDays||30:Number(S)}))},children:aw.map(x=>i.jsx("option",{value:x.value,children:x.label},x.value))})]}),br?i.jsx("div",{className:"af-flow-snippet-error",children:br}):null]}),i.jsxs("div",{className:"af-flow-snippet-modal__foot",children:[i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",onClick:()=>{Zn(""),Jt(!1)},children:"关闭"}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",disabled:dn||P.nodeIds.length===0,onClick:()=>void oL(),children:dn?"生成中...":Ct!=null&&Ct.absoluteUrl?"更新链接":"生成链接"})]})]})}),document.body):null,d$?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-share-modal",role:"dialog","aria-modal":"true","aria-label":"协作分享",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"group_add"}),"协作分享"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>yg(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsx("p",{className:"af-display-link-modal__empty",children:"输入已注册用户名。添加后,这个 Workspace 会直接出现在对方的项目列表中。"}),i.jsxs("div",{className:"af-workspace-member-add",children:[i.jsx("input",{type:"text",value:Gc,onChange:x=>Ov(x.target.value),onKeyDown:x=>{x.key==="Enter"&&Gc.trim()&&!wg&&(x.preventDefault(),p0())},placeholder:"输入用户名",autoFocus:!0}),i.jsx("button",{type:"button",disabled:wg||!Gc.trim(),onClick:()=>void p0(),children:wg?"添加中...":"添加成员"})]}),Lv?i.jsx("div",{className:"af-flow-snippet-error",children:Lv}):null,i.jsx("div",{className:"af-workspace-member-list",children:((an==null?void 0:an.members)||[]).map(x=>{const S=x.userId===(an==null?void 0:an.ownerId)||x.role==="owner";return i.jsxs("div",{className:"af-workspace-member-row",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:S?"shield_person":"person"}),i.jsxs("div",{children:[i.jsx("strong",{children:x.username||x.userId}),i.jsx("small",{children:S?"所有者":x.role==="viewer"?"只读成员":"编辑成员"})]}),S?null:i.jsx("button",{type:"button",disabled:Dv===x.userId,onClick:()=>void tL(x),children:Dv===x.userId?"移除中...":"取消分享"})]},x.userId)})})]}),i.jsx("div",{className:"af-flow-snippet-modal__foot",children:i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn",onClick:()=>yg(!1),children:"完成"})})]})}),document.body):null,mt?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-shares-modal",role:"dialog","aria-modal":"true","aria-label":"我的分享",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"folder_shared"}),"我的分享"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>nn(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("div",{className:"af-display-shares-toolbar",children:[i.jsx("span",{children:Wt.length?`${Wt.length} 个分享`:"暂无分享"}),i.jsxs("button",{type:"button",onClick:()=>void zs(),disabled:tt,children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"refresh"}),"刷新"]})]}),$i?i.jsx("div",{className:"af-flow-snippet-error",children:$i}):null,tt?i.jsx("div",{className:"af-display-link-modal__empty",children:"Loading..."}):null,!tt&&Wt.length===0?i.jsx("div",{className:"af-display-link-modal__empty",children:"还没有创建过展示分享"}):null,i.jsx("div",{className:"af-display-shares-list",children:Wt.map(x=>{const S=LC(x),_=mo===x.id,A=x.expiresAt?String(x.expiresInDays||30):"permanent";return i.jsxs("article",{className:"af-display-share-item",children:[i.jsxs("div",{className:"af-display-share-item__main",children:[i.jsx("strong",{children:x.title||"AgentFlow Display"}),i.jsxs("span",{children:[x.flowId||"-"," · ",x.layout||"gallery"," · ",Array.isArray(x.nodeIds)?x.nodeIds.length:0," nodes"]}),i.jsx("small",{children:TG(x)})]}),i.jsx("input",{className:"af-display-share-item__url",type:"text",readOnly:!0,value:S,onFocus:R=>R.target.select()}),i.jsx("select",{className:"af-display-share-select",value:A,disabled:_,onChange:R=>void lL(x,R.target.value),"aria-label":"修改分享有效期",children:aw.map(R=>i.jsx("option",{value:R.value,children:R.label},R.value))}),i.jsxs("div",{className:"af-display-share-item__actions",children:[i.jsxs("button",{type:"button",onClick:()=>window.open(S,"_blank","noopener,noreferrer"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"}),"打开"]}),i.jsxs("button",{type:"button",onClick:()=>void aL(x),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:Ts===x.id?"check":"content_copy"}),Ts===x.id?"已复制":"复制"]}),i.jsxs("button",{type:"button",className:"af-display-share-item__danger",disabled:_,onClick:()=>void cL(x),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:_?"hourglass_empty":"link_off"}),"撤销"]})]})]},x.id)})})]})]})}),document.body):null,Se?cr.createPortal(i.jsx("div",{className:"af-flow-snippet-modal-overlay",children:i.jsxs("div",{className:"af-flow-snippet-modal af-display-picker-modal",role:"dialog","aria-modal":"true","aria-label":"选择展示节点",children:[i.jsxs("div",{className:"af-flow-snippet-modal__head",children:[i.jsxs("span",{className:"af-flow-snippet-modal__title",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"add_to_photos"}),"选择展示节点"]}),i.jsx("button",{type:"button",className:"af-flow-snippet-modal__close",onClick:()=>Pe(!1),"aria-label":"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]}),i.jsxs("div",{className:"af-flow-snippet-modal__body",children:[i.jsxs("label",{className:"af-display-picker-search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{type:"search",value:xt,onChange:x=>Lt(x.target.value),placeholder:"搜索展示节点...",autoFocus:!0})]}),i.jsx("div",{className:"af-display-picker-grid",role:"group","aria-label":"选择展示节点",style:{"--af-display-picker-columns":u0.length||1},children:Bf.length>0?u0.map((x,S)=>i.jsx("div",{className:"af-display-picker-column",children:x.map(X$)},`display-picker-column-${S}`)):i.jsx("div",{className:"af-display-picker-empty",children:kl.length===0?"当前 Workspace 没有 display 节点":"没有匹配的展示节点"})})]}),i.jsx("div",{className:"af-flow-snippet-modal__foot",children:i.jsx("button",{type:"button",className:"af-flow-snippet-modal__btn af-flow-snippet-modal__btn--primary",onClick:()=>Pe(!1),children:"完成"})})]})}),document.body):null,Xc.nodeId?cr.createPortal(i.jsx(yJ,{files:ll,query:Xc.query,onQueryChange:x=>Sg(S=>({...S,query:x})),onSelect:B$,onUpload:qS,onClose:zg}),document.body):null,!ut&&!Pn&&On?cr.createPortal(i.jsx("div",{className:"af-workspace-quick-add-backdrop",onMouseDown:()=>q(!1),children:i.jsxs("div",{className:"af-workspace-quick-add",role:"dialog","aria-modal":"true","aria-label":"Add workspace node",onMouseDown:x=>x.stopPropagation(),children:[i.jsxs("div",{className:"af-workspace-quick-add__tabs",role:"tablist","aria-label":"选择添加类型",children:[i.jsx("button",{type:"button",role:"tab","aria-selected":he==="nodes",className:"af-workspace-quick-add__tab"+(he==="nodes"?" af-workspace-quick-add__tab--active":""),onClick:()=>Oe("nodes"),children:"节点"}),i.jsx("button",{type:"button",role:"tab","aria-selected":he==="flows",className:"af-workspace-quick-add__tab"+(he==="flows"?" af-workspace-quick-add__tab--active":""),onClick:()=>Oe("flows"),children:"流程"})]}),i.jsxs("div",{className:"af-workspace-quick-add__search",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"search"}),i.jsx("input",{ref:lS,value:Ee,onChange:x=>et(x.target.value),onKeyDown:x=>{if(x.key==="Escape")x.preventDefault(),q(!1);else if(x.key==="ArrowDown"){x.preventDefault();const S=he==="flows"?mu.length:hu.length;kt(_=>Math.min(Math.max(0,S-1),_+1))}else x.key==="ArrowUp"?(x.preventDefault(),kt(S=>Math.max(0,S-1))):x.key==="Tab"?(x.preventDefault(),Oe(S=>S==="nodes"?"flows":"nodes")):x.key==="Enter"&&(x.preventDefault(),he==="flows"?y0(mu[Nn]||mu[0]):g0(hu[Nn]||hu[0]))},placeholder:he==="flows"?"搜索流程片段...":"搜索节点...","aria-label":he==="flows"?"搜索流程片段":"搜索节点"})]}),i.jsx("div",{className:"af-workspace-quick-add__list",children:he==="flows"?mu.length===0?i.jsx("div",{className:"af-workspace-quick-add__empty",children:Ze?"正在加载流程片段...":At||"没有匹配的流程片段"}):mu.map((x,S)=>{const _=x.displayName||x.name||x.id,A=x.snippet&&typeof x.snippet=="object"?x.snippet.instances:null,R=x.snippet&&typeof x.snippet=="object"?x.snippet.edges:null,U=Number.isFinite(Number(x.nodeCount))?Number(x.nodeCount):Object.keys(A||{}).length,X=Number.isFinite(Number(x.edgeCount))?Number(x.edgeCount):Array.isArray(R)?R.length:0;return i.jsxs("button",{type:"button",className:"af-workspace-quick-add__item"+(S===Nn?" af-workspace-quick-add__item--active":""),onMouseEnter:()=>kt(S),onClick:()=>y0(x),children:[i.jsx("span",{className:"af-workspace-quick-add__icon material-symbols-outlined","aria-hidden":!0,children:"schema"}),i.jsxs("span",{className:"af-workspace-quick-add__main",children:[i.jsx("span",{className:"af-workspace-quick-add__label",children:_}),i.jsxs("span",{className:"af-workspace-quick-add__meta",children:[x.id,x.version?` · v${x.version}`:""]}),i.jsx("span",{className:"af-workspace-quick-add__desc",children:x.description||`${U} 节点 / ${X} 连线`})]}),i.jsx("span",{className:"af-workspace-quick-add__cat",children:"FLOW"})]},`${x.id}@${x.version}`)}):hu.length===0?i.jsx("div",{className:"af-workspace-quick-add__empty",children:"没有匹配的节点"}):hu.map((x,S)=>{const _=Wu(x),A=Vu(x),R=ub(x);return i.jsxs("button",{type:"button",className:"af-workspace-quick-add__item"+(S===Nn?" af-workspace-quick-add__item--active":""),onMouseEnter:()=>kt(S),onClick:()=>g0(x),children:[i.jsx("span",{className:"af-workspace-quick-add__icon material-symbols-outlined","aria-hidden":!0,children:_C(_)}),i.jsxs("span",{className:"af-workspace-quick-add__main",children:[i.jsx("span",{className:"af-workspace-quick-add__label",children:A}),i.jsx("span",{className:"af-workspace-quick-add__meta",children:x.id}),R?i.jsx("span",{className:"af-workspace-quick-add__desc",children:R}):null]}),i.jsx("span",{className:"af-workspace-quick-add__cat",children:_})]},x.id)})})]})}),document.body):null]})]})}function DJ(){return i.jsx(Fk,{children:i.jsx(OJ,{})})}function FJ(e){const t=[...(e==null?void 0:e.inputs)||[],...(e==null?void 0:e.outputs)||[]],n=(e==null?void 0:e.kind)==="image"?"src":"content",r=a=>String((a==null?void 0:a.value)??(a==null?void 0:a.default)??""),s=a=>r(a).trim(),o=t.find(a=>(a==null?void 0:a.name)===n&&s(a))||t.find(a=>(a==null?void 0:a.name)==="filePath"&&s(a))||t.find(a=>(a==null?void 0:a.type)==="text"&&s(a));return String((e==null?void 0:e.body)||(o?r(o):""))}function zJ(e){return e==="mermaid"?"account_tree":e==="ascii"?"notes":e==="html"?"html":e==="react"?"deployed_code":e==="image"?"image":e==="chart"?"bar_chart":e==="table"?"table":"article"}function BJ(e){let t=String(e||"").replace(/\r\n/g,`
265
265
  `).trim();return t.includes(`
266
266
  `)||(t=t.replace(/\s+(resultFile|result|outParams|outParams\.[A-Za-z_][A-Za-z0-9_-]*)\s*:/g,`
267
267
  $1:`).replace(/(^|\n)outParams:\s+([A-Za-z_][A-Za-z0-9_-]*\s*:)/g,`$1outParams:
@@ -310,7 +310,7 @@ The left node panel allows you to freely drag, delete, and adjust connections.`}
310
310
 
311
311
  在下方输入框用自然语言描述需求,AI 会自动生成流程图。
312
312
 
313
- 左侧节点面板可以自由拖拽、删除和调整连接。`},nie={guideTitle:"首次创建提示",guideDesc:"输入名称和描述后,AI 会自动生成流程图。你可以在编辑器中自由调整节点和连接。",nameHintGuide:"例如:MyFirstFlow(字母开头,支持数字和下划线)",descPlaceholderGuide:"例如:实现用户登录功能,包含注册、验证、授权",descHintGuide:"描述越详细,AI 生成的流程越准确",createGuide:"创建并开始编辑",typeNode:"节点引用类型",typeStr:"字符串类型",typeFile:"文件路径类型",typeBool:"布尔值类型"},rie={back:Gse,next:Jse,skip:Xse,done:Qse,startCreate:Zse,projects:eie,flow:tie,newPipeline:nie},sie={en:{common:WX,flow:EQ,settings:HQ,composer:GQ,project:ute,onboarding:xte},zh:{common:_te,flow:fne,settings:Cne,composer:Tne,project:Yse,onboarding:rie}};wr.use(NM).use(SD).init({resources:sie,fallbackLng:"en",debug:!1,ns:["common","flow","settings","composer","project","onboarding"],defaultNS:"common",interpolation:{escapeValue:!1},detection:{order:["localStorage","navigator","htmlTag"],lookupLocalStorage:"agentflow-lang",caches:["localStorage"]}});const iie=[{code:"zh",name:"中文",flag:"🇨🇳"},{code:"en",name:"English",flag:"🇬🇧"}];function oie(e){return wr.changeLanguage(e)}const wb="agentflow-settings-opencode-plan-v1",Uu="CURSOR_API_KEYS",Yu="AGENTFLOW_CURSOR_API_KEY_COOLDOWN_MINUTES",fw=new Set([Uu,Yu,"CURSOR_API_KEY_COOLDOWN_MINUTES"]),jM=["cursor","opencode","claudeCode","codex"];function CM(){return{cursor:[],opencode:[],claudeCode:[],codex:[],cursorFetchedAt:null,opencodeFetchedAt:null,claudeCodeFetchedAt:null,codexFetchedAt:null}}function xb(e){const t=String(e||"").trim(),n=t.indexOf(" - ");return n>=0?t.slice(0,n).trim():t}function ba(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:{},n={};for(const r of jM)n[r]=Array.isArray(t[r])?[...new Set(t[r].map(xb).filter(Boolean))]:[];return n}function Wi(e){if(!e||typeof e!="object")return CM();const t=e;return{cursor:Array.isArray(t.cursor)?t.cursor.map(String):[],opencode:Array.isArray(t.opencode)?t.opencode.map(String):[],claudeCode:Array.isArray(t.claudeCode)?t.claudeCode.map(String):[],codex:Array.isArray(t.codex)?t.codex.map(String):[],cursorFetchedAt:t.cursorFetchedAt??null,opencodeFetchedAt:t.opencodeFetchedAt??null,claudeCodeFetchedAt:t.claudeCodeFetchedAt??null,codexFetchedAt:t.codexFetchedAt??null}}function mc(){return`e_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function aie(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(String(e||"").trim())}function ja(e,t="user"){if(!Array.isArray(e))return[];const n=[];for(const r of e){if(!r||typeof r!="object")continue;const s=String(r.key??"").trim(),o=String(r.value??""),a=String(r.id??"").trim()||mc(),c=String(r.scope??t).trim()==="global"?"global":"user";!s&&!o||n.push({id:a,key:s,value:o,scope:c})}return n}function d_(e){return ja(e).map(({key:t,value:n})=>({key:t,value:n}))}function f_(){try{return localStorage.getItem(wb)??""}catch{return""}}function _M(e){return e?e.length<=6?"•".repeat(e.length):`${"•".repeat(Math.min(20,e.length-4))}${e.slice(-4)}`:""}function lie(e){const t=String(e||"").trim();if(!t)return[];const n=(r,s)=>{if(typeof r=="string"){const a=r.trim();return a?{id:`legacy_${s}_${a.slice(-6)}`,name:`Key ${s+1}`,key:a,createdAt:""}:null}if(!r||typeof r!="object")return null;const o=String(r.key??"").trim();return o?{id:String(r.id??"").trim()||mc(),name:String(r.name??"").trim()||`Key ${s+1}`,key:o,createdAt:String(r.createdAt??"").trim()}:null};try{const r=JSON.parse(t);if(Array.isArray(r))return r.map(n).filter(Boolean)}catch{}return t.split(",").map((r,s)=>n(r,s)).filter(Boolean)}function p_(e){const t=Array.isArray(e)?e.map((n,r)=>({id:String((n==null?void 0:n.id)||"").trim()||mc(),name:String((n==null?void 0:n.name)||"").trim()||`Key ${r+1}`,key:String((n==null?void 0:n.key)||"").trim(),createdAt:String((n==null?void 0:n.createdAt)||"").trim()||new Date().toISOString()})).filter(n=>n.key):[];return JSON.stringify(t)}function cie(e){const t=String(e||"").trim();return t?t.length<=10?_M(t):`${t.slice(0,4)}${"•".repeat(Math.min(18,t.length-8))}${t.slice(-4)}`:""}function uie(e,t="zh"){if(!e)return"";const n=Date.parse(e);if(Number.isNaN(n))return String(e);try{const r=t==="en"?"en-US":t==="ja"?"ja-JP":"zh-CN";return new Intl.DateTimeFormat(r,{dateStyle:"short",timeStyle:"medium"}).format(new Date(n))}catch{return String(e)}}function die({authUser:e}){const{t,i18n:n}=Fr(["common","settings"]),r=n.language||"zh",[s,o]=m.useState(""),[a,l]=m.useState(""),[c,u]=m.useState({cursor:[],opencode:[],claudeCode:[],codex:[],cursorFetchedAt:null,opencodeFetchedAt:null,claudeCodeFetchedAt:null,codexFetchedAt:null}),[d,f]=m.useState(CM()),[p,h]=m.useState(()=>ba({})),[y,k]=m.useState(!1),[b,g]=m.useState(""),[v,w]=m.useState(""),[N,j]=m.useState(!1),[C,P]=m.useState(!1),[I,z]=m.useState(""),[$,L]=m.useState([]),[F,O]=m.useState(""),[M,K]=m.useState(!1),[H,D]=m.useState(""),[T,W]=m.useState(""),[E,Q]=m.useState(!1),[V,B]=m.useState(()=>new Set),[se,ue]=m.useState(""),[G,ee]=m.useState(""),[te,ne]=m.useState(!!(e!=null&&e.isAdmin)),[Z,ce]=m.useState(""),[de,me]=m.useState([]),[$e,Ce]=m.useState([]),[_e,Be]=m.useState(""),[ot,yt]=m.useState(""),[Te,st]=m.useState(!1),[gt,xe]=m.useState(!1),[Fe,lt]=m.useState(""),[oe,ke]=m.useState(""),[Ke,Ue]=m.useState(""),[be,Ht]=m.useState(null),[Qt,jt]=m.useState(!1),[yn,on]=m.useState(!1),[re,Re]=m.useState(""),Je=m.useRef(null),Ze=m.useRef(!1),Tt=m.useRef(!1),At=m.useRef(""),Vn=m.useCallback(async()=>{l("");try{const ie=await fetch("/api/ui-context");if(!ie.ok)throw new Error("HTTP "+ie.status);const Se=await ie.json();o(typeof Se.workspaceRoot=="string"?Se.workspaceRoot:"")}catch(ie){l(String(ie.message||ie)),o("")}},[]),Sn=m.useCallback(async()=>{w(""),j(!0),g("");try{const ie=await fetch(e!=null&&e.isAdmin?"/api/model-visibility":"/api/model-lists");if(!ie.ok)throw new Error("HTTP "+ie.status);const Se=await ie.json();if(e!=null&&e.isAdmin)u(Wi(Se.modelLists)),f(Wi(Se.allModelLists)),h(ba(Se.hiddenModels));else{const Pe=Wi(Se);u(Pe),f(Pe),h(ba({}))}}catch(ie){w(String(ie.message||ie))}finally{j(!1)}},[e==null?void 0:e.isAdmin]),xr=m.useCallback(async()=>{O("");try{const ie=await fetch("/api/user-env"),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);const Pe=ja(Array.isArray(Se.env)?Se.env:[],"user").map(qt=>({...qt,scope:"user"})),Lt=[...e!=null&&e.isAdmin?ja(Array.isArray(Se.globalEnv)?Se.globalEnv:[],"global").map(qt=>({...qt,scope:"global"})):[],...Pe];At.current=JSON.stringify(Lt),L(Lt)}catch(ie){L([]),O(String(ie.message||ie))}finally{Tt.current=!0}},[e==null?void 0:e.isAdmin]),wn=m.useCallback(async()=>{if(e!=null&&e.isAdmin){st(!0),lt("");try{const ie=await fetch("/api/admin/user-allowlist"),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);const Pe=Se.allowlist&&typeof Se.allowlist=="object"?Se.allowlist:{};me(Array.isArray(Pe.fileUsers)?Pe.fileUsers.map(String):[]),Ce(Array.isArray(Pe.envUsers)?Pe.envUsers.map(String):[]),Be(typeof Pe.path=="string"?Pe.path:"")}catch(ie){lt(String(ie.message||ie))}finally{st(!1)}}},[e==null?void 0:e.isAdmin]),Xn=m.useCallback(async ie=>{if(e!=null&&e.isAdmin){xe(!0),lt("");try{const Se=await fetch("/api/admin/user-allowlist",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({users:ie})}),Pe=await Se.json().catch(()=>({}));if(!Se.ok)throw new Error(typeof Pe.error=="string"?Pe.error:"HTTP "+Se.status);const xt=Pe.allowlist&&typeof Pe.allowlist=="object"?Pe.allowlist:{};me(Array.isArray(xt.fileUsers)?xt.fileUsers.map(String):[]),Ce(Array.isArray(xt.envUsers)?xt.envUsers.map(String):[]),Be(typeof xt.path=="string"?xt.path:"")}catch(Se){lt(String(Se.message||Se))}finally{xe(!1)}}},[e==null?void 0:e.isAdmin]),Kn=m.useCallback(async()=>{if(e!=null&&e.isAdmin){jt(!0),Re("");try{const ie=await fetch("/api/admin/storage-config"),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);const Pe=Se.config&&typeof Se.config=="object"?Se.config:{};Ht(Pe),ke(typeof Pe.dataRoot=="string"?Pe.dataRoot:""),Ue(typeof Pe.skillsRoot=="string"?Pe.skillsRoot:"")}catch(ie){Re(String(ie.message||ie))}finally{jt(!1)}}},[e==null?void 0:e.isAdmin]),hr=m.useCallback(async()=>{if(e!=null&&e.isAdmin){on(!0),Re("");try{const ie=await fetch("/api/admin/storage-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataRoot:oe.trim(),skillsRoot:Ke.trim(),migrateLegacySkills:!0})}),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);const Pe=Se.config&&typeof Se.config=="object"?Se.config:{};Ht(Pe),ke(typeof Pe.dataRoot=="string"?Pe.dataRoot:""),Ue(typeof Pe.skillsRoot=="string"?Pe.skillsRoot:"")}catch(ie){Re(String(ie.message||ie))}finally{on(!1)}}},[e==null?void 0:e.isAdmin,oe,Ke]),ts=m.useCallback(async ie=>{const Se=ja(ie),Pe=Se.filter(Lt=>Lt.scope!=="global"),xt=Se.filter(Lt=>Lt.scope==="global");K(!0),O("");try{const Lt=await fetch("/api/user-env",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({env:d_(Pe),...e!=null&&e.isAdmin?{globalEnv:d_(xt)}:{}})}),qt=await Lt.json().catch(()=>({}));if(!Lt.ok)throw new Error(typeof qt.error=="string"?qt.error:"HTTP "+Lt.status);const zn=ja(Array.isArray(qt.env)?qt.env:[],"user").map(pe=>({...pe,scope:"user"})),q=[...e!=null&&e.isAdmin?ja(Array.isArray(qt.globalEnv)?qt.globalEnv:[],"global").map(pe=>({...pe,scope:"global"})):[],...zn];At.current=JSON.stringify(q),L(q)}catch(Lt){O(String(Lt.message||Lt))}finally{K(!1)}},[e==null?void 0:e.isAdmin]),Ar=m.useCallback(async()=>{w(""),j(!0);try{const ie=await fetch("/api/update-model-lists",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({opencodeProvider:Z.trim()})}),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);u(Wi(Se.modelLists)),e!=null&&e.isAdmin?await Sn():f(Wi(Se.modelLists))}catch(ie){w(String(ie.message||ie))}finally{j(!1)}},[e==null?void 0:e.isAdmin,Sn,Z]),gs=m.useCallback(async ie=>{if(!(e!=null&&e.isAdmin))return;const Se=ba(ie);h(Se),k(!0),g("");try{const Pe=await fetch("/api/model-visibility",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({hiddenModels:Se})}),xt=await Pe.json().catch(()=>({}));if(!Pe.ok)throw new Error(typeof xt.error=="string"?xt.error:"HTTP "+Pe.status);u(Wi(xt.modelLists)),f(Wi(xt.allModelLists)),h(ba(xt.hiddenModels))}catch(Pe){g(String(Pe.message||Pe)),Sn()}finally{k(!1)}},[e==null?void 0:e.isAdmin,Sn]),ys=m.useCallback((ie,Se,Pe)=>{const xt=jM.includes(ie)?ie:"cursor",Lt=xb(Se);if(!Lt)return;const qt=ba(p),zn=new Set(qt[xt]);Pe?zn.delete(Lt):zn.add(Lt),gs({...qt,[xt]:Array.from(zn)})},[p,gs]);m.useEffect(()=>{xr(),e!=null&&e.isAdmin?(Vn(),Sn(),wn(),Kn(),(async()=>{try{const ie=await fetch("/api/agentflow-config");if(ie.ok){const Se=await ie.json(),Pe=typeof Se.opencodeProvider=="string"?Se.opencodeProvider:"";ce(Pe),Je.current=Pe;try{localStorage.setItem(wb,Pe)}catch{}}else{const Se=f_();ce(Se),Je.current=Se}}catch{const ie=f_();ce(ie),Je.current=ie}finally{Ze.current=!0}})()):(o(""),Ze.current=!1)},[e==null?void 0:e.isAdmin,Vn,Sn,Kn,wn,xr]),m.useEffect(()=>{if(!Tt.current||JSON.stringify(ja($))===At.current)return;const Se=setTimeout(()=>{ts($)},350);return()=>clearTimeout(Se)},[$,ts]),m.useEffect(()=>{if(!(e!=null&&e.isAdmin)||!Ze.current)return;const ie=Z.trim();if(ie===Je.current)return;const Se=setTimeout(()=>{(async()=>{P(!0),z("");try{const Pe=await fetch("/api/agentflow-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({opencodeProvider:ie})}),xt=await Pe.json().catch(()=>({}));if(!Pe.ok)throw new Error(typeof xt.error=="string"?xt.error:"HTTP "+Pe.status);Je.current=ie;try{localStorage.setItem(wb,ie)}catch{}xt.modelLists&&(u(Wi(xt.modelLists)),e!=null&&e.isAdmin?Sn():f(Wi(xt.modelLists)))}catch(Pe){z(String(Pe.message||Pe))}finally{P(!1)}})()},450);return()=>clearTimeout(Se)},[e==null?void 0:e.isAdmin,Sn,Z]);const cn=e!=null&&e.isAdmin?d:c,rr=cn.cursor.length>0,Pr=cn.opencode.length>0,dn=cn.claudeCode.length>0,Qn=cn.codex.length>0,br=ba(p),sr={cursor:c.cursor.length,opencode:c.opencode.length,claudeCode:c.claudeCode.length,codex:c.codex.length},Ct=m.useCallback((ie,Se,Pe)=>{const xt=Array.isArray(Se)?Se:[];if(!(e!=null&&e.isAdmin))return i.jsx("pre",{className:"af-set-model-preview","aria-label":Pe,children:xt.join(`
313
+ 左侧节点面板可以自由拖拽、删除和调整连接。`},nie={guideTitle:"首次创建提示",guideDesc:"输入名称和描述后,AI 会自动生成流程图。你可以在编辑器中自由调整节点和连接。",nameHintGuide:"例如:MyFirstFlow(字母开头,支持数字和下划线)",descPlaceholderGuide:"例如:实现用户登录功能,包含注册、验证、授权",descHintGuide:"描述越详细,AI 生成的流程越准确",createGuide:"创建并开始编辑",typeNode:"节点引用类型",typeStr:"字符串类型",typeFile:"文件路径类型",typeBool:"布尔值类型"},rie={back:Gse,next:Jse,skip:Xse,done:Qse,startCreate:Zse,projects:eie,flow:tie,newPipeline:nie},sie={en:{common:WX,flow:EQ,settings:HQ,composer:GQ,project:ute,onboarding:xte},zh:{common:_te,flow:fne,settings:Cne,composer:Tne,project:Yse,onboarding:rie}};wr.use(NM).use(SD).init({resources:sie,fallbackLng:"en",debug:!1,ns:["common","flow","settings","composer","project","onboarding"],defaultNS:"common",interpolation:{escapeValue:!1},detection:{order:["localStorage","navigator","htmlTag"],lookupLocalStorage:"agentflow-lang",caches:["localStorage"]}});const iie=[{code:"zh",name:"中文",flag:"🇨🇳"},{code:"en",name:"English",flag:"🇬🇧"}];function oie(e){return wr.changeLanguage(e)}const wb="agentflow-settings-opencode-plan-v1",Uu="CURSOR_API_KEYS",Yu="AGENTFLOW_CURSOR_API_KEY_COOLDOWN_MINUTES",fw=new Set([Uu,Yu,"CURSOR_API_KEY_COOLDOWN_MINUTES"]),jM=["cursor","opencode","claudeCode","codex"];function CM(){return{cursor:[],opencode:[],claudeCode:[],codex:[],cursorFetchedAt:null,opencodeFetchedAt:null,claudeCodeFetchedAt:null,codexFetchedAt:null}}function xb(e){const t=String(e||"").trim(),n=t.indexOf(" - ");return n>=0?t.slice(0,n).trim():t}function ba(e){const t=e&&typeof e=="object"&&!Array.isArray(e)?e:{},n={};for(const r of jM)n[r]=Array.isArray(t[r])?[...new Set(t[r].map(xb).filter(Boolean))]:[];return n}function Wi(e){if(!e||typeof e!="object")return CM();const t=e;return{cursor:Array.isArray(t.cursor)?t.cursor.map(String):[],opencode:Array.isArray(t.opencode)?t.opencode.map(String):[],claudeCode:Array.isArray(t.claudeCode)?t.claudeCode.map(String):[],codex:Array.isArray(t.codex)?t.codex.map(String):[],cursorFetchedAt:t.cursorFetchedAt??null,opencodeFetchedAt:t.opencodeFetchedAt??null,claudeCodeFetchedAt:t.claudeCodeFetchedAt??null,codexFetchedAt:t.codexFetchedAt??null}}function mc(){return`e_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function aie(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(String(e||"").trim())}function ja(e,t="user"){if(!Array.isArray(e))return[];const n=[];for(const r of e){if(!r||typeof r!="object")continue;const s=String(r.key??"").trim(),o=String(r.value??""),a=String(r.id??"").trim()||mc(),c=String(r.scope??t).trim()==="global"?"global":"user";!s&&!o||n.push({id:a,key:s,value:o,scope:c})}return n}function d_(e){return ja(e).map(({key:t,value:n})=>({key:t,value:n}))}function f_(){try{return localStorage.getItem(wb)??""}catch{return""}}function _M(e){return e?e.length<=6?"•".repeat(e.length):`${"•".repeat(Math.min(20,e.length-4))}${e.slice(-4)}`:""}function lie(e){const t=String(e||"").trim();if(!t)return[];const n=(r,s)=>{if(typeof r=="string"){const a=r.trim();return a?{id:`legacy_${s}_${a.slice(-6)}`,name:`Key ${s+1}`,key:a,createdAt:""}:null}if(!r||typeof r!="object")return null;const o=String(r.key??"").trim();return o?{id:String(r.id??"").trim()||mc(),name:String(r.name??"").trim()||`Key ${s+1}`,key:o,createdAt:String(r.createdAt??"").trim()}:null};try{const r=JSON.parse(t);if(Array.isArray(r))return r.map(n).filter(Boolean)}catch{}return t.split(",").map((r,s)=>n(r,s)).filter(Boolean)}function p_(e){const t=Array.isArray(e)?e.map((n,r)=>({id:String((n==null?void 0:n.id)||"").trim()||mc(),name:String((n==null?void 0:n.name)||"").trim()||`Key ${r+1}`,key:String((n==null?void 0:n.key)||"").trim(),createdAt:String((n==null?void 0:n.createdAt)||"").trim()||new Date().toISOString()})).filter(n=>n.key):[];return JSON.stringify(t)}function cie(e){const t=String(e||"").trim();return t?t.length<=10?_M(t):`${t.slice(0,4)}${"•".repeat(Math.min(18,t.length-8))}${t.slice(-4)}`:""}function uie(e,t="zh"){if(!e)return"";const n=Date.parse(e);if(Number.isNaN(n))return String(e);try{const r=t==="en"?"en-US":t==="ja"?"ja-JP":"zh-CN";return new Intl.DateTimeFormat(r,{dateStyle:"short",timeStyle:"medium"}).format(new Date(n))}catch{return String(e)}}function die({authUser:e}){const{t,i18n:n}=Fr(["common","settings"]),r=n.language||"zh",[s,o]=m.useState(""),[a,l]=m.useState(""),[c,u]=m.useState({cursor:[],opencode:[],claudeCode:[],codex:[],cursorFetchedAt:null,opencodeFetchedAt:null,claudeCodeFetchedAt:null,codexFetchedAt:null}),[d,f]=m.useState(CM()),[p,h]=m.useState(()=>ba({})),[y,k]=m.useState(!1),[b,g]=m.useState(""),[v,w]=m.useState(""),[N,j]=m.useState(!1),[C,P]=m.useState(!1),[I,z]=m.useState(""),[$,L]=m.useState([]),[F,O]=m.useState(""),[M,K]=m.useState(!1),[H,D]=m.useState(""),[T,W]=m.useState(""),[E,Q]=m.useState(!1),[V,B]=m.useState(()=>new Set),[se,ue]=m.useState(""),[G,ee]=m.useState(""),[te,ne]=m.useState(!!(e!=null&&e.isAdmin)),[Z,ce]=m.useState(""),[de,me]=m.useState([]),[$e,Ce]=m.useState([]),[_e,Be]=m.useState(""),[ot,yt]=m.useState(""),[Te,st]=m.useState(!1),[gt,xe]=m.useState(!1),[Fe,lt]=m.useState(""),[oe,ke]=m.useState(""),[Ke,Ue]=m.useState(""),[be,Ht]=m.useState(null),[Qt,jt]=m.useState(!1),[yn,on]=m.useState(!1),[re,Re]=m.useState(""),Je=m.useRef(null),Ze=m.useRef(!1),Tt=m.useRef(!1),At=m.useRef(""),Vn=m.useCallback(async()=>{l("");try{const ie=await fetch("/api/ui-context");if(!ie.ok)throw new Error("HTTP "+ie.status);const Se=await ie.json();o(typeof Se.workspaceRoot=="string"?Se.workspaceRoot:"")}catch(ie){l(String(ie.message||ie)),o("")}},[]),Sn=m.useCallback(async()=>{w(""),j(!0),g("");try{const ie=await fetch(e!=null&&e.isAdmin?"/api/model-visibility":"/api/model-lists");if(!ie.ok)throw new Error("HTTP "+ie.status);const Se=await ie.json();if(e!=null&&e.isAdmin)u(Wi(Se.modelLists)),f(Wi(Se.allModelLists)),h(ba(Se.hiddenModels));else{const Pe=Wi(Se);u(Pe),f(Pe),h(ba({}))}}catch(ie){w(String(ie.message||ie))}finally{j(!1)}},[e==null?void 0:e.isAdmin]),xr=m.useCallback(async()=>{O("");try{const ie=await fetch("/api/user-env"),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);const Pe=ja(Array.isArray(Se.env)?Se.env:[],"user").map(qt=>({...qt,scope:"user"})),Lt=[...e!=null&&e.isAdmin?ja(Array.isArray(Se.globalEnv)?Se.globalEnv:[],"global").map(qt=>({...qt,scope:"global"})):[],...Pe];At.current=JSON.stringify(Lt),L(Lt)}catch(ie){L([]),O(String(ie.message||ie))}finally{Tt.current=!0}},[e==null?void 0:e.isAdmin]),wn=m.useCallback(async()=>{if(e!=null&&e.isAdmin){st(!0),lt("");try{const ie=await fetch("/api/admin/user-allowlist"),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);const Pe=Se.allowlist&&typeof Se.allowlist=="object"?Se.allowlist:{};me(Array.isArray(Pe.fileUsers)?Pe.fileUsers.map(String):[]),Ce(Array.isArray(Pe.envUsers)?Pe.envUsers.map(String):[]),Be(typeof Pe.path=="string"?Pe.path:"")}catch(ie){lt(String(ie.message||ie))}finally{st(!1)}}},[e==null?void 0:e.isAdmin]),Xn=m.useCallback(async ie=>{if(e!=null&&e.isAdmin){xe(!0),lt("");try{const Se=await fetch("/api/admin/user-allowlist",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({users:ie})}),Pe=await Se.json().catch(()=>({}));if(!Se.ok)throw new Error(typeof Pe.error=="string"?Pe.error:"HTTP "+Se.status);const xt=Pe.allowlist&&typeof Pe.allowlist=="object"?Pe.allowlist:{};me(Array.isArray(xt.fileUsers)?xt.fileUsers.map(String):[]),Ce(Array.isArray(xt.envUsers)?xt.envUsers.map(String):[]),Be(typeof xt.path=="string"?xt.path:"")}catch(Se){lt(String(Se.message||Se))}finally{xe(!1)}}},[e==null?void 0:e.isAdmin]),Kn=m.useCallback(async()=>{if(e!=null&&e.isAdmin){jt(!0),Re("");try{const ie=await fetch("/api/admin/storage-config"),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);const Pe=Se.config&&typeof Se.config=="object"?Se.config:{};Ht(Pe),ke(typeof Pe.dataRoot=="string"?Pe.dataRoot:""),Ue(typeof Pe.skillsRoot=="string"?Pe.skillsRoot:"")}catch(ie){Re(String(ie.message||ie))}finally{jt(!1)}}},[e==null?void 0:e.isAdmin]),hr=m.useCallback(async()=>{if(e!=null&&e.isAdmin){on(!0),Re("");try{const ie=await fetch("/api/admin/storage-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({dataRoot:oe.trim(),skillsRoot:Ke.trim(),migrateLegacySkills:!0})}),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);const Pe=Se.config&&typeof Se.config=="object"?Se.config:{};Ht(Pe),ke(typeof Pe.dataRoot=="string"?Pe.dataRoot:""),Ue(typeof Pe.skillsRoot=="string"?Pe.skillsRoot:"")}catch(ie){Re(String(ie.message||ie))}finally{on(!1)}}},[e==null?void 0:e.isAdmin,oe,Ke]),ts=m.useCallback(async ie=>{const Se=ja(ie),Pe=Se.filter(Lt=>Lt.scope!=="global"),xt=Se.filter(Lt=>Lt.scope==="global");K(!0),O("");try{const Lt=await fetch("/api/user-env",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({env:d_(Pe),...e!=null&&e.isAdmin?{globalEnv:d_(xt)}:{}})}),qt=await Lt.json().catch(()=>({}));if(!Lt.ok)throw new Error(typeof qt.error=="string"?qt.error:"HTTP "+Lt.status);const zn=ja(Array.isArray(qt.env)?qt.env:[],"user").map(he=>({...he,scope:"user"})),q=[...e!=null&&e.isAdmin?ja(Array.isArray(qt.globalEnv)?qt.globalEnv:[],"global").map(he=>({...he,scope:"global"})):[],...zn];At.current=JSON.stringify(q),L(q)}catch(Lt){O(String(Lt.message||Lt))}finally{K(!1)}},[e==null?void 0:e.isAdmin]),Ar=m.useCallback(async()=>{w(""),j(!0);try{const ie=await fetch("/api/update-model-lists",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({opencodeProvider:Z.trim()})}),Se=await ie.json().catch(()=>({}));if(!ie.ok)throw new Error(typeof Se.error=="string"?Se.error:"HTTP "+ie.status);u(Wi(Se.modelLists)),e!=null&&e.isAdmin?await Sn():f(Wi(Se.modelLists))}catch(ie){w(String(ie.message||ie))}finally{j(!1)}},[e==null?void 0:e.isAdmin,Sn,Z]),gs=m.useCallback(async ie=>{if(!(e!=null&&e.isAdmin))return;const Se=ba(ie);h(Se),k(!0),g("");try{const Pe=await fetch("/api/model-visibility",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({hiddenModels:Se})}),xt=await Pe.json().catch(()=>({}));if(!Pe.ok)throw new Error(typeof xt.error=="string"?xt.error:"HTTP "+Pe.status);u(Wi(xt.modelLists)),f(Wi(xt.allModelLists)),h(ba(xt.hiddenModels))}catch(Pe){g(String(Pe.message||Pe)),Sn()}finally{k(!1)}},[e==null?void 0:e.isAdmin,Sn]),ys=m.useCallback((ie,Se,Pe)=>{const xt=jM.includes(ie)?ie:"cursor",Lt=xb(Se);if(!Lt)return;const qt=ba(p),zn=new Set(qt[xt]);Pe?zn.delete(Lt):zn.add(Lt),gs({...qt,[xt]:Array.from(zn)})},[p,gs]);m.useEffect(()=>{xr(),e!=null&&e.isAdmin?(Vn(),Sn(),wn(),Kn(),(async()=>{try{const ie=await fetch("/api/agentflow-config");if(ie.ok){const Se=await ie.json(),Pe=typeof Se.opencodeProvider=="string"?Se.opencodeProvider:"";ce(Pe),Je.current=Pe;try{localStorage.setItem(wb,Pe)}catch{}}else{const Se=f_();ce(Se),Je.current=Se}}catch{const ie=f_();ce(ie),Je.current=ie}finally{Ze.current=!0}})()):(o(""),Ze.current=!1)},[e==null?void 0:e.isAdmin,Vn,Sn,Kn,wn,xr]),m.useEffect(()=>{if(!Tt.current||JSON.stringify(ja($))===At.current)return;const Se=setTimeout(()=>{ts($)},350);return()=>clearTimeout(Se)},[$,ts]),m.useEffect(()=>{if(!(e!=null&&e.isAdmin)||!Ze.current)return;const ie=Z.trim();if(ie===Je.current)return;const Se=setTimeout(()=>{(async()=>{P(!0),z("");try{const Pe=await fetch("/api/agentflow-config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({opencodeProvider:ie})}),xt=await Pe.json().catch(()=>({}));if(!Pe.ok)throw new Error(typeof xt.error=="string"?xt.error:"HTTP "+Pe.status);Je.current=ie;try{localStorage.setItem(wb,ie)}catch{}xt.modelLists&&(u(Wi(xt.modelLists)),e!=null&&e.isAdmin?Sn():f(Wi(xt.modelLists)))}catch(Pe){z(String(Pe.message||Pe))}finally{P(!1)}})()},450);return()=>clearTimeout(Se)},[e==null?void 0:e.isAdmin,Sn,Z]);const cn=e!=null&&e.isAdmin?d:c,rr=cn.cursor.length>0,Pr=cn.opencode.length>0,dn=cn.claudeCode.length>0,Qn=cn.codex.length>0,br=ba(p),sr={cursor:c.cursor.length,opencode:c.opencode.length,claudeCode:c.claudeCode.length,codex:c.codex.length},Ct=m.useCallback((ie,Se,Pe)=>{const xt=Array.isArray(Se)?Se:[];if(!(e!=null&&e.isAdmin))return i.jsx("pre",{className:"af-set-model-preview","aria-label":Pe,children:xt.join(`
314
314
  `)});const Lt=new Set(br[ie]||[]);return i.jsxs("div",{className:"af-set-model-visibility","aria-label":Pe,children:[i.jsxs("div",{className:"af-set-model-visibility-head",children:[i.jsxs("span",{children:["展示 ",sr[ie]||0," / ",xt.length]}),i.jsx("span",{children:y?"保存中":"取消勾选后从模型下拉隐藏"})]}),i.jsx("div",{className:"af-set-model-visibility-list",children:xt.map(qt=>{const zn=xb(qt),On=!Lt.has(zn);return i.jsxs("label",{className:"af-set-model-visibility-row",children:[i.jsx("input",{type:"checkbox",checked:On,disabled:y,onChange:q=>ys(ie,qt,q.target.checked)}),i.jsx("span",{children:qt})]},`${ie}-${qt}`)})})]})},[e==null?void 0:e.isAdmin,br,y,sr,ys]),Gt=de.length>0||$e.length>0,_t=e!=null&&e.isAdmin?$:$.filter(ie=>!fw.has(String((ie==null?void 0:ie.key)||"").trim())),le=e!=null&&e.isAdmin&&te?"global":"user",ve=m.useMemo(()=>$.find(ie=>ie.key===Uu&&(ie.scope||"user")===le)||null,[le,$]),it=m.useMemo(()=>lie((ve==null?void 0:ve.value)||""),[ve==null?void 0:ve.value]),Dt=m.useMemo(()=>$.find(ie=>ie.key===Yu&&(ie.scope||"user")===le)||null,[le,$]),Jt=Dt!=null&&Dt.value?String(Dt.value):"30",tn=m.useCallback((ie,Se,Pe)=>{const xt=String(ie||"").trim();if(!xt)return;const Lt=String(Se??"");L(qt=>{const zn=qt.find(On=>On.key===xt&&(On.scope||"user")===Pe);return Lt?zn?qt.map(On=>On.id===zn.id?{...On,value:Lt,scope:Pe}:On):[{id:mc(),key:xt,value:Lt,scope:Pe},...qt]:qt.filter(On=>!(On.key===xt&&(On.scope||"user")===Pe))})},[]),Zn=m.useCallback(()=>{const ie=G.trim();if(!ie)return;const Se=[...it,{id:mc(),name:se.trim()||`Key ${it.length+1}`,key:ie,createdAt:new Date().toISOString()}];tn(Uu,p_(Se),le),ue(""),ee("")},[se,it,le,G,tn]),mt=m.useCallback(ie=>{const Se=it.filter(Pe=>Pe.id!==ie);tn(Uu,Se.length?p_(Se):"",le)},[it,le,tn]),nn=m.useCallback(ie=>{const Se=String(ie||"").replace(/[^\d]/g,"");if(!Se){tn(Yu,"",le);return}const Pe=Math.min(1440,Math.max(1,Number(Se)||30));tn(Yu,String(Pe),le)},[le,tn]),Wt=m.useCallback(()=>{var ie;s&&((ie=navigator.clipboard)==null||ie.writeText(s))},[s]),kr=m.useCallback(()=>{const ie=H.trim(),Se=T;if(ie){if(!aie(ie)){O(t("settings:env.invalidKey"));return}if(!(e!=null&&e.isAdmin)&&fw.has(ie)){O("该运行基础设施变量仅管理员可配置。");return}L(Pe=>[{id:mc(),key:ie,value:Se,scope:e!=null&&e.isAdmin&&E?"global":"user"},...Pe]),D(""),W("")}},[e==null?void 0:e.isAdmin,E,H,T,t]),tt=m.useCallback(ie=>{L(Se=>Se.filter(Pe=>Pe.id!==ie))},[]),Ln=m.useCallback((ie,Se)=>{const Pe=String((Se==null?void 0:Se.key)||"").trim();if(!(e!=null&&e.isAdmin)&&Pe&&fw.has(Pe)){O("该运行基础设施变量仅管理员可配置。");return}L(xt=>xt.map(Lt=>Lt.id===ie?{...Lt,...Se}:Lt))},[e==null?void 0:e.isAdmin]),$i=m.useCallback(ie=>{B(Se=>{const Pe=new Set(Se);return Pe.has(ie)?Pe.delete(ie):Pe.add(ie),Pe})},[]),zr=m.useCallback(()=>{const ie=ot.trim();if(!ie)return;if(!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(ie)){lt("用户名须以字母开头,仅可使用字母、数字、下划线与连字符,最多 64 字符");return}if(new Set(de.map(Pe=>String(Pe||"").trim().toLowerCase())).has(ie.toLowerCase())){yt("");return}yt(""),Xn([...de,ie])},[ot,de,Xn]),mo=m.useCallback(ie=>{const Se=String(ie||"").trim().toLowerCase();Se&&Xn(de.filter(Pe=>String(Pe||"").trim().toLowerCase()!==Se))},[de,Xn]),ai=m.useCallback(ie=>{const Se=ie.target.value;oie(Se)},[]),Ts=ie=>{const Se=uie(ie,r);return Se?t("settings:cursor.modelList.fetchedAt",{time:Se}):t("settings:cursor.modelList.never")};return i.jsxs("div",{className:"af-settings-page",children:[i.jsx("header",{className:"af-settings-top",children:i.jsxs("div",{className:"af-settings-crumb","aria-label":t("settings:title"),children:[i.jsx("span",{className:"af-settings-crumb-muted",children:t("settings:crumb.engine")}),i.jsx("span",{className:"af-settings-crumb-sep","aria-hidden":!0,children:"/"}),i.jsx("span",{className:"af-settings-crumb-active",children:t("settings:crumb.preferences")})]})}),i.jsx("div",{className:"af-settings-body",children:i.jsxs("div",{className:"af-settings-inner",children:[i.jsxs("header",{className:"af-settings-hero",children:[i.jsxs("h1",{className:"af-settings-h1",children:[t("common:app.name")," ",t("settings:title")]}),i.jsx("p",{className:"af-settings-lead",children:e!=null&&e.isAdmin?t("settings:workspace.description"):t("settings:env.note")}),e!=null&&e.isAdmin&&a?i.jsx("p",{className:"af-err af-settings-api-hint",children:a}):null,e!=null&&e.isAdmin&&v?i.jsx("p",{className:"af-err af-settings-api-hint",children:v}):null,F?i.jsx("p",{className:"af-err af-settings-api-hint",children:F}):null,re?i.jsx("p",{className:"af-err af-settings-api-hint",children:re}):null]}),i.jsx("div",{className:"af-settings-layout",children:i.jsxs("div",{className:"af-settings-bento",children:[e!=null&&e.isAdmin?i.jsxs(i.Fragment,{children:[i.jsxs("section",{className:"af-set-card af-set-card--narrow af-set-card--low af-set-workspace",children:[i.jsxs("div",{className:"af-set-card-inner",children:[i.jsxs("div",{className:"af-set-card-head",children:[i.jsx("span",{className:"material-symbols-outlined af-set-icon af-set-icon--secondary",children:"folder_managed"}),i.jsx("h2",{className:"af-set-h2",children:t("settings:workspace.title")})]}),i.jsx("label",{className:"af-set-label",htmlFor:"af-workspace-path",children:t("settings:workspace.currentPath")}),i.jsxs("div",{className:"af-set-input-wrap",children:[i.jsx("input",{id:"af-workspace-path",className:"af-set-input af-set-input--mono",type:"text",readOnly:!0,value:s,placeholder:t("common:loading")}),i.jsx("button",{type:"button",className:"af-set-input-suffix",onClick:Wt,"aria-label":t("settings:workspace.copyPath"),disabled:!s,children:i.jsx("span",{className:"material-symbols-outlined",children:"content_copy"})})]}),i.jsx("p",{className:"af-set-hint",children:"当前页面只展示运行时根目录。可被节点加载的代码库和文档目录请在左侧“知识库”里维护。"})]}),i.jsx("div",{className:"af-set-watermark","aria-hidden":!0,children:i.jsx("span",{className:"material-symbols-outlined",children:"account_tree"})})]}),i.jsxs("section",{className:"af-set-card af-set-card--narrow af-set-card--high",children:[i.jsxs("div",{className:"af-set-card-head af-set-card-head--spread",children:[i.jsx("h2",{className:"af-set-h2 af-set-h2--caps",children:"Cursor CLI"}),i.jsx("span",{className:"af-set-badge"+(rr?" af-set-badge--ok":" af-set-badge--muted"),children:t(rr?"settings:cursor.status.cached":"settings:cursor.status.notCached")})]}),i.jsxs("div",{className:"af-set-cli-block",children:[i.jsx("div",{className:"af-set-cli-icon",children:i.jsx("span",{className:"material-symbols-outlined af-set-icon--tertiary",children:rr?"check_circle":"hourglass_empty"})}),i.jsxs("div",{children:[i.jsx("p",{className:"af-set-cli-title",children:t(rr?"settings:cursor.modelList.cached":"settings:cursor.modelList.empty")}),i.jsx("p",{className:"af-set-cli-mono",children:rr?t("settings:cursor.modelList.count",{count:c.cursor.length})+(e!=null&&e.isAdmin?` / ${cn.cursor.length}`:"")+" · "+Ts(c.cursorFetchedAt):t("settings:cursor.modelList.refresh")})]})]}),rr?Ct("cursor",cn.cursor,t("settings:cursor.modelPreviewLabel")):null,b?i.jsx("p",{className:"af-err af-set-hint af-set-hint--inline",role:"alert",children:b}):null,i.jsx("button",{type:"button",className:"af-set-btn-outline",onClick:()=>Ar(),disabled:N,children:t(N?"settings:cursor.modelList.fetching":"settings:cursor.modelList.refresh")})]}),i.jsxs("section",{className:"af-set-card af-set-card--wide af-set-card--low af-set-cursor-pool",children:[i.jsxs("div",{className:"af-set-env-head",children:[i.jsxs("div",{className:"af-set-card-head",children:[i.jsx("div",{className:"af-set-env-icon-wrap",children:i.jsx("span",{className:"material-symbols-outlined af-set-icon--primary",children:"key"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"af-set-h2",children:"Cursor API Key 池"}),i.jsx("p",{className:"af-set-card-subtitle",children:"按请求轮换,遇到 usage limit 或 resource_exhausted 会自动尝试下一个 Key。"})]})]}),i.jsxs("span",{className:"af-set-badge"+(it.length?" af-set-badge--ok":" af-set-badge--muted"),children:[it.length," keys"]})]}),i.jsxs("div",{className:"af-set-cursor-pool-controls",children:[e!=null&&e.isAdmin?i.jsxs("div",{className:"af-set-env-scope-switch af-set-cursor-scope",role:"group","aria-label":"Cursor API Key scope",children:[i.jsx("button",{type:"button",className:te?"":"is-active",onClick:()=>ne(!1),children:"个人"}),i.jsx("button",{type:"button",className:te?"is-active":"",onClick:()=>ne(!0),children:"全局"})]}):null,i.jsxs("label",{className:"af-set-cursor-cooldown",children:[i.jsx("span",{children:"限额冷却"}),i.jsx("input",{className:"af-set-input af-set-input--sm af-set-input--mono",inputMode:"numeric",value:Jt,onChange:ie=>nn(ie.target.value)}),i.jsx("span",{children:"分钟"})]}),i.jsx("span",{className:"af-set-env-note",children:M?"保存中":le==="global"?"全局配置":"个人配置"})]}),i.jsx("div",{className:"af-set-cursor-key-list",children:it.length?it.map(ie=>i.jsxs("div",{className:"af-set-cursor-key-row",children:[i.jsxs("div",{className:"af-set-cursor-key-main",children:[i.jsx("strong",{children:ie.name}),i.jsx("code",{children:cie(ie.key)})]}),i.jsx("span",{className:"af-set-cursor-key-meta",children:ie.createdAt?new Date(ie.createdAt).toLocaleString():"历史 Key"}),i.jsx("button",{type:"button",className:"af-set-env-del af-set-cursor-key-delete","aria-label":`删除 ${ie.name}`,onClick:()=>mt(ie.id),children:i.jsx("span",{className:"material-symbols-outlined",children:"delete_outline"})})]},ie.id)):i.jsx("div",{className:"af-set-cursor-key-empty",children:"还没有配置 Key。配置后 Cursor CLI runner 会自动轮换使用。"})}),i.jsxs("div",{className:"af-set-cursor-key-add",children:[i.jsx("input",{className:"af-set-input",value:se,onChange:ie=>ue(ie.target.value),placeholder:"名称,例如 Team Key 1"}),i.jsx("input",{className:"af-set-input af-set-input--mono",type:"password",value:G,onChange:ie=>ee(ie.target.value),placeholder:"Cursor API Key"}),i.jsxs("button",{type:"button",className:"af-set-btn-add",onClick:Zn,disabled:!G.trim(),children:[i.jsx("span",{className:"material-symbols-outlined",children:"add"}),"添加 Key"]})]}),i.jsxs("p",{className:"af-set-hint",children:["保存到 ",Uu,";冷却时间保存到 ",Yu,"。个人配置会覆盖全局配置。"]})]}),i.jsxs("section",{className:"af-set-card af-set-card--narrow af-set-card--high",children:[i.jsxs("div",{className:"af-set-card-head af-set-card-head--spread",children:[i.jsx("h2",{className:"af-set-h2 af-set-h2--caps",children:"OpenCode"}),i.jsx("span",{className:"af-set-badge"+(Pr?" af-set-badge--ok":" af-set-badge--err"),children:t(Pr?"settings:opencode.status.ready":"settings:opencode.status.notFound")})]}),i.jsx("p",{className:"af-set-p",children:t("settings:opencode.description")}),i.jsxs("div",{children:[i.jsx("label",{className:"af-set-label-sm",htmlFor:"af-opencode-plan",children:t("settings:opencode.provider")}),i.jsx("input",{id:"af-opencode-plan",className:"af-set-input af-set-input--sm af-set-input--mono",type:"text",value:Z,onChange:ie=>ce(ie.target.value),placeholder:t("settings:opencode.providerPlaceholder"),autoComplete:"off"}),C?i.jsx("p",{className:"af-set-hint af-set-hint--inline","aria-live":"polite",children:t("settings:opencode.saving")}):null,I?i.jsx("p",{className:"af-err af-set-hint af-set-hint--inline",role:"alert",children:I}):null]}),Pr?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"af-set-cli-mono af-set-cli-mono--block",children:t("settings:cursor.modelList.count",{count:c.opencode.length})+(e!=null&&e.isAdmin?` / ${cn.opencode.length}`:"")+" · "+Ts(c.opencodeFetchedAt)}),Ct("opencode",cn.opencode,t("settings:opencode.modelPreviewLabel"))]}):null,i.jsx("button",{type:"button",className:"af-set-btn-outline",onClick:()=>Ar(),disabled:N,children:t(N?"settings:cursor.modelList.fetching":"settings:cursor.modelList.refresh")})]}),i.jsxs("section",{className:"af-set-card af-set-card--narrow af-set-card--high",children:[i.jsxs("div",{className:"af-set-card-head af-set-card-head--spread",children:[i.jsx("h2",{className:"af-set-h2 af-set-h2--caps",children:t("settings:claudeCode.title")}),i.jsx("span",{className:"af-set-badge"+(dn?" af-set-badge--ok":" af-set-badge--err"),children:t(dn?"settings:claudeCode.status.ready":"settings:claudeCode.status.notFound")})]}),i.jsxs("div",{className:"af-set-cli-block",children:[i.jsx("div",{className:"af-set-cli-icon",children:i.jsx("span",{className:"material-symbols-outlined af-set-icon--tertiary",children:dn?"check_circle":"hourglass_empty"})}),i.jsxs("div",{children:[i.jsx("p",{className:"af-set-cli-title",children:t(dn?"settings:cursor.modelList.cached":"settings:cursor.modelList.empty")}),i.jsx("p",{className:"af-set-cli-mono",children:dn?t("settings:cursor.modelList.count",{count:c.claudeCode.length})+(e!=null&&e.isAdmin?` / ${cn.claudeCode.length}`:"")+" · "+Ts(c.claudeCodeFetchedAt):t("settings:cursor.modelList.refresh")})]})]}),i.jsx("p",{className:"af-set-p",children:t("settings:claudeCode.description")}),dn?Ct("claudeCode",cn.claudeCode,t("settings:claudeCode.modelPreviewLabel")):null,i.jsx("button",{type:"button",className:"af-set-btn-outline",onClick:()=>Ar(),disabled:N,children:t(N?"settings:cursor.modelList.fetching":"settings:cursor.modelList.refresh")})]}),i.jsxs("section",{className:"af-set-card af-set-card--narrow af-set-card--high",children:[i.jsxs("div",{className:"af-set-card-head af-set-card-head--spread",children:[i.jsx("h2",{className:"af-set-h2 af-set-h2--caps",children:t("settings:codex.title")}),i.jsx("span",{className:"af-set-badge"+(Qn?" af-set-badge--ok":" af-set-badge--err"),children:t(Qn?"settings:codex.status.ready":"settings:codex.status.notFound")})]}),i.jsxs("div",{className:"af-set-cli-block",children:[i.jsx("div",{className:"af-set-cli-icon",children:i.jsx("span",{className:"material-symbols-outlined af-set-icon--tertiary",children:Qn?"check_circle":"hourglass_empty"})}),i.jsxs("div",{children:[i.jsx("p",{className:"af-set-cli-title",children:t(Qn?"settings:cursor.modelList.cached":"settings:cursor.modelList.empty")}),i.jsx("p",{className:"af-set-cli-mono",children:Qn?t("settings:cursor.modelList.count",{count:c.codex.length})+(e!=null&&e.isAdmin?` / ${cn.codex.length}`:"")+" · "+Ts(c.codexFetchedAt):t("settings:cursor.modelList.refresh")})]})]}),i.jsx("p",{className:"af-set-p",children:t("settings:codex.description")}),Qn?Ct("codex",cn.codex,t("settings:codex.modelPreviewLabel")):null,i.jsx("button",{type:"button",className:"af-set-btn-outline",onClick:()=>Ar(),disabled:N,children:t(N?"settings:cursor.modelList.fetching":"settings:cursor.modelList.refresh")})]})]}):null,i.jsxs("section",{className:"af-set-card af-set-card--wide af-set-card--low af-set-env",children:[i.jsxs("div",{className:"af-set-env-head",children:[i.jsxs("div",{className:"af-set-card-head",children:[i.jsx("div",{className:"af-set-env-icon-wrap",children:i.jsx("span",{className:"material-symbols-outlined af-set-icon--primary",children:"variables"})}),i.jsx("h2",{className:"af-set-h2",children:t("settings:env.title")})]}),i.jsx("span",{className:"af-set-env-note",children:M?t("settings:env.saving"):e!=null&&e.isAdmin?t("settings:env.noteAdmin"):t("settings:env.note")})]}),i.jsxs("div",{className:"af-set-env-rows"+(e!=null&&e.isAdmin?" af-set-env-rows--admin":""),children:[i.jsxs("div",{className:"af-set-env-row af-set-env-row--header","aria-hidden":!0,children:[i.jsx("span",{children:t("settings:env.key")}),e!=null&&e.isAdmin?i.jsx("span",{children:t("settings:env.scope")}):null,i.jsx("span",{children:t("settings:env.value")}),i.jsx("span",{})]}),i.jsxs("div",{className:"af-set-env-row af-set-env-row--draft"+(e!=null&&e.isAdmin?" af-set-env-row--scoped":""),children:[i.jsx("div",{className:"af-set-env-cell",children:i.jsx("input",{className:"af-set-env-inline af-set-env-inline--key",placeholder:"KEY_NAME",value:H,onChange:ie=>D(ie.target.value),"aria-label":t("settings:env.newKey")})}),e!=null&&e.isAdmin?i.jsx("div",{className:"af-set-env-cell af-set-env-cell--scope",children:i.jsxs("div",{className:"af-set-env-scope-switch",role:"group","aria-label":t("settings:env.scope"),children:[i.jsx("button",{type:"button",className:E?"":"is-active",onClick:()=>Q(!1),children:t("settings:env.personal")}),i.jsx("button",{type:"button",className:E?"is-active":"",onClick:()=>Q(!0),children:t("settings:env.global")})]})}):null,i.jsx("div",{className:"af-set-env-cell af-set-env-cell--grow af-set-env-cell--value",children:i.jsx("input",{className:"af-set-env-inline af-set-env-inline--value",type:"password",placeholder:t("settings:env.newValue"),value:T,onChange:ie=>W(ie.target.value),"aria-label":t("settings:env.newValue")})}),i.jsx("div",{className:"af-set-env-actions",children:i.jsxs("button",{type:"button",className:"af-set-btn-add",onClick:kr,disabled:!H.trim(),children:[i.jsx("span",{className:"material-symbols-outlined",children:"add"}),t("settings:env.add")]})})]}),_t.map(ie=>i.jsxs("div",{className:"af-set-env-row"+(e!=null&&e.isAdmin?" af-set-env-row--scoped":""),children:[i.jsx("div",{className:"af-set-env-cell",children:i.jsx("input",{className:"af-set-env-inline af-set-env-inline--key",value:ie.key,onChange:Se=>Ln(ie.id,{key:Se.target.value}),"aria-label":t("settings:env.key"),spellCheck:!1})}),e!=null&&e.isAdmin?i.jsx("div",{className:"af-set-env-cell af-set-env-cell--scope",children:i.jsxs("div",{className:"af-set-env-scope-switch",role:"group","aria-label":t("settings:env.scope"),children:[i.jsx("button",{type:"button",className:ie.scope!=="global"?"is-active":"",onClick:()=>Ln(ie.id,{scope:"user"}),children:t("settings:env.personal")}),i.jsx("button",{type:"button",className:ie.scope==="global"?"is-active":"",onClick:()=>Ln(ie.id,{scope:"global"}),children:t("settings:env.global")})]})}):null,i.jsxs("div",{className:"af-set-env-cell af-set-env-cell--grow af-set-env-cell--value",children:[i.jsx("input",{className:"af-set-env-inline af-set-env-inline--value",type:V.has(ie.id)?"text":"password",value:ie.value,onChange:Se=>Ln(ie.id,{value:Se.target.value}),placeholder:_M(ie.value)||t("settings:env.newValue"),"aria-label":t("settings:env.value")}),i.jsx("button",{type:"button",className:"af-set-env-value-toggle",onClick:()=>$i(ie.id),"aria-label":V.has(ie.id)?"Hide value":"Show value",children:i.jsx("span",{className:"material-symbols-outlined",children:V.has(ie.id)?"visibility_off":"visibility"})})]}),i.jsx("div",{className:"af-set-env-actions",children:i.jsx("button",{type:"button",className:"af-set-env-del","aria-label":t("settings:env.delete",{key:ie.key}),onClick:()=>tt(ie.id),children:i.jsx("span",{className:"material-symbols-outlined",children:"delete_outline"})})})]},ie.id))]})]}),e!=null&&e.isAdmin?i.jsxs("section",{className:"af-set-card af-set-card--wide af-set-card--low",children:[i.jsxs("div",{className:"af-set-env-head",children:[i.jsxs("div",{className:"af-set-card-head",children:[i.jsx("div",{className:"af-set-env-icon-wrap",children:i.jsx("span",{className:"material-symbols-outlined af-set-icon--primary",children:"hard_drive_2"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"af-set-h2",children:"AgentFlow Data Root"}),i.jsx("p",{className:"af-set-card-subtitle",children:"配置整个 AgentFlow 数据目录的位置,保存时会迁移当前数据。"})]})]}),i.jsx("span",{className:"af-set-badge"+(be!=null&&be.envLocked?" af-set-badge--err":" af-set-badge--ok"),children:be!=null&&be.envLocked?"Env locked":"Configurable"}),i.jsx("button",{type:"button",className:"af-set-btn-outline af-set-btn-outline--compact",onClick:()=>void Kn(),disabled:Qt||yn,children:Qt?"刷新中...":"刷新"})]}),re?i.jsx("p",{className:"af-err af-set-hint af-set-hint--inline",children:re}):null,i.jsx("label",{className:"af-set-label-sm",htmlFor:"af-agentflow-data-root",children:"Data Root"}),i.jsxs("div",{className:"af-set-input-wrap",children:[i.jsx("input",{id:"af-agentflow-data-root",className:"af-set-input af-set-input--mono",type:"text",value:oe,onChange:ie=>ke(ie.target.value),placeholder:"/data1/services/mengmai/agentflow",autoComplete:"off",disabled:!!(be!=null&&be.envLocked)||yn}),i.jsx("button",{type:"button",className:"af-set-input-suffix",onClick:()=>void hr(),"aria-label":"保存 AgentFlow Data Root",disabled:yn||!!(be!=null&&be.envLocked),children:i.jsx("span",{className:"material-symbols-outlined",children:yn?"hourglass_empty":"save"})})]}),i.jsxs("p",{className:"af-set-hint",children:["当前目录:",i.jsx("code",{children:(be==null?void 0:be.dataRoot)||oe||"-"}),be!=null&&be.configPath?i.jsxs(i.Fragment,{children:[";配置文件:",i.jsx("code",{children:be.configPath})]}):null]}),i.jsxs("p",{className:"af-set-hint",children:["这个目录包含 ",i.jsx("code",{children:"users/"}),"、",i.jsx("code",{children:"pipelines/"}),"、",i.jsx("code",{children:"runBuild/"}),"、",i.jsx("code",{children:"auth/"})," 和 admin 配置。 保存到新绝对路径时会复制旧目录内容;旧目录不会自动删除。",be!=null&&be.envLocked?" 当前设置了 AGENTFLOW_HOME,需要改环境变量才能生效。":""]}),i.jsx("label",{className:"af-set-label-sm",htmlFor:"af-agentflow-skills-root",children:"Skills Root"}),i.jsxs("div",{className:"af-set-input-wrap",children:[i.jsx("input",{id:"af-agentflow-skills-root",className:"af-set-input af-set-input--mono",type:"text",value:Ke,onChange:ie=>Ue(ie.target.value),placeholder:"/data1/services/mengmai/agentflow/skills",autoComplete:"off",disabled:!!(be!=null&&be.skillsEnvLocked)||yn}),i.jsx("button",{type:"button",className:"af-set-input-suffix",onClick:()=>void hr(),"aria-label":"保存 AgentFlow Skills Root",disabled:yn||!!(be!=null&&be.skillsEnvLocked),children:i.jsx("span",{className:"material-symbols-outlined",children:yn?"hourglass_empty":"save"})})]}),i.jsxs("p",{className:"af-set-hint",children:["当前 Skills:",i.jsx("code",{children:(be==null?void 0:be.skillsRoot)||Ke||"-"}),be!=null&&be.legacySkillsRootExists?i.jsxs(i.Fragment,{children:[";保存时会补迁移旧目录 ",i.jsx("code",{children:be.legacySkillsRoot})," 中缺失的 skills。"]}):null]}),i.jsxs("p",{className:"af-set-hint",children:["SkillHub 新安装、更新和卸载都作用于 Skills Root;普通用户只通过 Workspace 的 Load Skills 使用。",be!=null&&be.skillsEnvLocked?" 当前设置了 AGENTFLOW_SKILLS_ROOT,需要改环境变量才能生效。":""]})]}):null,e!=null&&e.isAdmin?i.jsxs("section",{className:"af-set-card af-set-card--wide af-set-card--allowlist",children:[i.jsxs("div",{className:"af-set-env-head",children:[i.jsxs("div",{className:"af-set-card-head",children:[i.jsx("div",{className:"af-set-env-icon-wrap",children:i.jsx("span",{className:"material-symbols-outlined af-set-icon--primary",children:"manage_accounts"})}),i.jsxs("div",{children:[i.jsx("h2",{className:"af-set-h2",children:t("settings:allowlist.title")}),i.jsx("p",{className:"af-set-card-subtitle",children:t("settings:allowlist.description")})]})]}),i.jsx("span",{className:"af-set-badge"+(Gt?" af-set-badge--ok":" af-set-badge--muted"),children:t(Gt?"settings:allowlist.enabled":"settings:allowlist.open")}),i.jsx("button",{type:"button",className:"af-set-btn-outline af-set-btn-outline--compact",onClick:()=>void wn(),disabled:Te,children:t(Te?"settings:allowlist.refreshing":"common:common.refresh")})]}),Fe?i.jsx("p",{className:"af-err af-set-hint af-set-hint--inline",children:Fe}):null,_e?i.jsxs("p",{className:"af-set-hint af-set-hint--inline",children:[t("settings:allowlist.file"),":",i.jsx("code",{children:_e})]}):null,i.jsxs("div",{className:"af-allowlist-grid",children:[i.jsxs("div",{className:"af-allowlist-main",children:[i.jsxs("div",{className:"af-allowlist-head",children:[i.jsx("span",{children:t("settings:allowlist.fileList")}),i.jsx("span",{children:gt?t("settings:allowlist.saving"):t("settings:allowlist.userCount",{count:de.length})})]}),i.jsx("div",{className:"af-allowlist-list",children:de.length>0?de.map(ie=>i.jsxs("div",{className:"af-allowlist-row",children:[i.jsx("span",{className:"af-allowlist-name",children:ie}),i.jsx("button",{type:"button",className:"af-set-env-del",onClick:()=>mo(ie),"aria-label":t("settings:allowlist.remove",{username:ie}),disabled:gt,children:i.jsx("span",{className:"material-symbols-outlined",children:"delete_outline"})})]},ie)):i.jsx("div",{className:"af-allowlist-empty",children:t("settings:allowlist.emptyFile")})}),i.jsxs("div",{className:"af-allowlist-add",children:[i.jsx("input",{className:"af-set-input af-set-input--sm af-set-input--mono",value:ot,onChange:ie=>yt(ie.target.value),onKeyDown:ie=>{ie.key==="Enter"&&zr()},placeholder:"username",autoComplete:"off"}),i.jsxs("button",{type:"button",className:"af-set-btn-add",onClick:zr,disabled:gt||!ot.trim(),children:[i.jsx("span",{className:"material-symbols-outlined",children:"add"}),t("settings:allowlist.add")]})]})]}),i.jsxs("div",{className:"af-allowlist-side",children:[i.jsxs("div",{className:"af-allowlist-head",children:[i.jsx("span",{children:t("settings:allowlist.envList")}),i.jsx("span",{children:t("settings:allowlist.readonly")})]}),i.jsx("div",{className:"af-allowlist-env-list",children:$e.length>0?$e.map(ie=>i.jsx("code",{children:ie},ie)):i.jsx("span",{children:t("settings:allowlist.emptyEnv")})}),i.jsx("p",{className:"af-set-hint af-set-hint--inline",children:t("settings:allowlist.unionHint")})]})]})]}):null,i.jsxs("section",{className:"af-settings-rail","aria-label":t("settings:title"),children:[e!=null&&e.isAdmin?i.jsxs("div",{className:"af-set-rail-card af-set-rail-card--accent",children:[i.jsxs("div",{className:"af-set-rail-inner",children:[i.jsx("h3",{className:"af-set-rail-h3",children:t("settings:system.title")}),i.jsxs("div",{className:"af-set-health-line",children:[i.jsx("span",{className:"af-set-pulse-dot","aria-hidden":!0}),i.jsx("span",{className:"af-set-health-label",children:t(!a&&!v?"settings:system.normal":"settings:system.abnormal")})]}),i.jsxs("div",{className:"af-set-meter",children:[i.jsxs("div",{className:"af-set-meter-row",children:[i.jsx("span",{children:t("settings:system.cursorModels")}),i.jsx("span",{children:c.cursor.length})]}),i.jsx("div",{className:"af-set-meter-bar",children:i.jsx("div",{className:"af-set-meter-fill",style:{width:`${Math.min(100,c.cursor.length>0?12+c.cursor.length*3:4)}%`}})})]}),i.jsxs("div",{className:"af-set-meter",children:[i.jsxs("div",{className:"af-set-meter-row",children:[i.jsx("span",{children:t("settings:system.opencodeModels")}),i.jsx("span",{children:c.opencode.length})]}),i.jsx("div",{className:"af-set-meter-bar",children:i.jsx("div",{className:"af-set-meter-fill",style:{width:`${Math.min(100,c.opencode.length>0?12+c.opencode.length*3:4)}%`}})})]}),i.jsxs("div",{className:"af-set-meter",children:[i.jsxs("div",{className:"af-set-meter-row",children:[i.jsx("span",{children:t("settings:system.claudeCodeModels")}),i.jsx("span",{children:c.claudeCode.length})]}),i.jsx("div",{className:"af-set-meter-bar",children:i.jsx("div",{className:"af-set-meter-fill",style:{width:`${Math.min(100,c.claudeCode.length>0?12+c.claudeCode.length*3:4)}%`}})})]}),i.jsxs("div",{className:"af-set-meter",children:[i.jsxs("div",{className:"af-set-meter-row",children:[i.jsx("span",{children:t("settings:system.codexModels")}),i.jsx("span",{children:c.codex.length})]}),i.jsx("div",{className:"af-set-meter-bar",children:i.jsx("div",{className:"af-set-meter-fill",style:{width:`${Math.min(100,c.codex.length>0?12+c.codex.length*3:4)}%`}})})]})]}),i.jsx("div",{className:"af-set-rail-watermark","aria-hidden":!0,children:i.jsx("span",{className:"material-symbols-outlined",children:"vital_signs"})})]}):null,i.jsxs("div",{className:"af-set-rail-card",children:[i.jsx("h3",{className:"af-set-rail-h3 af-set-rail-h3--sm",children:t("settings:language.title")}),i.jsxs("div",{className:"af-set-language-selector",children:[i.jsx("select",{className:"af-set-input af-set-input--sm",value:r,onChange:ai,"aria-label":t("settings:language.description"),children:iie.map(ie=>i.jsxs("option",{value:ie.code,children:[ie.flag," ",ie.name]},ie.code))}),i.jsx("p",{className:"af-set-hint",children:t("settings:language.description")})]})]})]})]})})]})})]})}function fie(e){const t=Number(e||0);return!Number.isFinite(t)||t<=0?"-":new Intl.DateTimeFormat(void 0,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date(t))}function pie(e){return e==="thinking"?"Thinking":e==="tool"?"工具":e==="error"?"错误":e==="result"?"结果":"过程"}function hie(e){const t=String(e||"unknown");return t==="success"?"成功":t==="failed"?"失败":t==="running"?"运行中":t==="stopped"?"已停止":t==="interrupted"?"中断":t}function mie({run:e,onClose:t}){const[n,r]=m.useState(null),[s,o]=m.useState(!1),[a,l]=m.useState(""),[c,u]=m.useState("timeline"),d=m.useCallback(async({quiet:k=!1}={})=>{if(e!=null&&e.runId){k||o(!0),l("");try{const b=new URLSearchParams({runType:e.runType||"pipeline",userId:e.userId||"",flowId:e.flowId||"",flowSource:e.flowSource||"user",runId:e.runId}),g=await fetch(`/api/admin/run-detail?${b.toString()}`),v=await g.json().catch(()=>({}));if(!g.ok)throw new Error(v.error||`HTTP ${g.status}`);r(v)}catch(b){l(String((b==null?void 0:b.message)||b))}finally{k||o(!1)}}},[e==null?void 0:e.flowId,e==null?void 0:e.flowSource,e==null?void 0:e.runId,e==null?void 0:e.runType,e==null?void 0:e.userId]);m.useEffect(()=>{r(null),u("timeline"),d()},[d]),m.useEffect(()=>{if((e==null?void 0:e.status)!=="running")return;const k=window.setInterval(()=>{document.hidden||d({quiet:!0})},5e3);return()=>window.clearInterval(k)},[d,e==null?void 0:e.status]);const f=Array.isArray(n==null?void 0:n.events)?n.events:[],p=m.useMemo(()=>f.filter(k=>(k==null?void 0:k.kind)==="thinking"),[f]),h=Array.isArray(n==null?void 0:n.rawLines)?n.rawLines:[],y=c==="thinking"?p:f;return i.jsx("div",{className:"af-admin-run-detail-overlay",role:"presentation",onMouseDown:t,children:i.jsxs("aside",{className:"af-admin-run-detail",role:"dialog","aria-modal":"true","aria-label":"Run 详情",onMouseDown:k=>k.stopPropagation(),children:[i.jsxs("header",{className:"af-admin-run-detail__head",children:[i.jsxs("div",{children:[i.jsxs("span",{className:"af-admin-run-detail__eyebrow",children:[e.runType==="workspace"?"Workspace Run":"Pipeline Run"," · ",hie(e.status)]}),i.jsx("h2",{children:e.flowId||"Run 详情"}),i.jsxs("p",{children:[e.username||e.userId," · ",i.jsx("code",{children:e.runId})]})]}),i.jsxs("div",{className:"af-admin-run-detail__actions",children:[i.jsx("button",{type:"button",onClick:()=>void d(),disabled:s,title:"刷新详情",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"refresh"})}),i.jsx("button",{type:"button",onClick:t,title:"关闭",children:i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"close"})})]})]}),i.jsxs("div",{className:"af-admin-run-detail__tabs",role:"tablist","aria-label":"Run 详情分类",children:[i.jsxs("button",{type:"button",className:c==="timeline"?"is-active":"",onClick:()=>u("timeline"),children:["过程 ",i.jsx("span",{children:f.length})]}),i.jsxs("button",{type:"button",className:c==="thinking"?"is-active":"",onClick:()=>u("thinking"),children:["Thinking ",i.jsx("span",{children:p.length})]}),i.jsxs("button",{type:"button",className:c==="raw"?"is-active":"",onClick:()=>u("raw"),children:["原始日志 ",i.jsx("span",{children:h.length})]})]}),n!=null&&n.truncated?i.jsx("div",{className:"af-admin-run-detail__notice",children:"日志较大,当前展示最新的 512 KB / 2000 条记录。"}):null,a?i.jsx("div",{className:"af-admin-run-detail__error",children:a}):null,s&&!n?i.jsx("div",{className:"af-admin-run-detail__empty",children:"正在读取 Run 详情..."}):null,i.jsx("div",{className:"af-admin-run-detail__body",children:c==="raw"?h.length>0?i.jsx("pre",{className:"af-admin-run-detail__raw",children:h.join(`
315
315
  `)}):i.jsx("div",{className:"af-admin-run-detail__empty",children:"这个 Run 没有原始日志。"}):y.length>0?i.jsx("div",{className:"af-admin-run-detail__timeline",children:y.map((k,b)=>i.jsxs("article",{className:`af-admin-run-detail__event is-${k.kind||"process"}`,children:[i.jsxs("div",{className:"af-admin-run-detail__event-meta",children:[i.jsx("time",{children:fie(k.ts)}),i.jsx("span",{className:`af-admin-run-detail__kind is-${k.kind||"process"}`,children:pie(k.kind)}),i.jsx("span",{children:k.type||"event"}),k.nodeId?i.jsx("code",{children:k.nodeId}):null]}),i.jsx("pre",{children:k.text||"-"})]},k.id||`${k.ts||0}-${b}`))}):i.jsx("div",{className:"af-admin-run-detail__empty",children:c==="thinking"?"该模型或 CLI 没有为这个 Run 输出可记录的 Thinking。":"这个 Run 暂无过程事件。"})})]})})}function Wr(e){return new Intl.NumberFormat(void 0,{maximumFractionDigits:0}).format(Math.max(0,Number(e||0)))}function zp(e){return`${Math.round(Math.max(0,Math.min(1,Number(e||0)))*100)}%`}function pw(e){const t=Math.max(0,Number(e||0));if(!t)return"-";const n=Math.round(t/1e3);if(n<60)return`${n}s`;const r=Math.round(n/60);if(r<60)return`${r}m`;const s=Math.round(r/60);return s<48?`${s}h`:`${Math.round(s/24)}d`}function gie(e){const t=String(e||"");return t.includes("-")?t.slice(5):t}function hw(e){if(!e)return"无运行记录";try{return new Intl.DateTimeFormat(void 0,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(new Date(Number(e)))}catch{return String(e)}}function yie(e){const t=String(e||"").trim();return t?t.length>18?t.slice(0,8)+"..."+t.slice(-6):t:"-"}function wie(e){const t=String(e||"unknown");return t==="success"?"成功":t==="failed"?"失败":t==="running"?"运行中":t==="stopped"?"已停止":t==="interrupted"?"中断":"未知"}function xie({authUser:e}){const[t,n]=m.useState(null),[r,s]=m.useState(!1),[o,a]=m.useState(""),[l,c]=m.useState(null),u=m.useCallback(async()=>{if(e!=null&&e.isAdmin){s(!0),a("");try{const k=await fetch("/api/admin/usage-dashboard"),b=await k.json().catch(()=>({}));if(!k.ok)throw new Error(typeof b.error=="string"?b.error:"HTTP "+k.status);n(b)}catch(k){n(null),a(String((k==null?void 0:k.message)||k))}finally{s(!1)}}},[e==null?void 0:e.isAdmin]);m.useEffect(()=>{u()},[u]);const d=Array.isArray(t==null?void 0:t.dailyTrend)?t.dailyTrend:[],f=m.useMemo(()=>{const g={top:20,right:24,bottom:42,left:42},v=980-g.left-g.right,w=250-g.top-g.bottom,N=d.length>0?d:[],j=Math.max(1,...N.map(L=>Number(L.runs||0))),C=Math.max(1,...N.flatMap(L=>[Number(L.users||0),Number(L.pipelines||0)])),P=L=>g.left+(N.length<=1?v/2:L*v/(N.length-1)),I=L=>g.top+w-Math.max(0,Number(L||0))/j*w,z=L=>g.top+w-Math.max(0,Number(L||0))/C*w,$=L=>N.map((F,O)=>`${O===0?"M":"L"} ${P(O)} ${z(F[L])}`).join(" ");return{width:980,height:250,margin:g,innerHeight:w,rows:N,x:P,yRuns:I,yLine:z,lineUsers:$("users"),linePipelines:$("pipelines"),barWidth:Math.min(34,Math.max(12,v/Math.max(1,N.length)*.44))}},[d]),p=(t==null?void 0:t.usage)||{},h=(t==null?void 0:t.totals)||{},y=Array.isArray(t==null?void 0:t.recentRuns)?t.recentRuns:[];return e!=null&&e.isAdmin?i.jsxs("main",{className:"af-admin-usage-page",children:[i.jsxs("section",{className:"af-admin-usage-hero",children:[i.jsxs("div",{children:[i.jsx("p",{className:"af-admin-usage-eyebrow",children:"Admin / Usage"}),i.jsx("h1",{children:"管理看板"}),i.jsx("p",{children:"重点观察使用率、每日趋势、成功率与各用户流水线活跃度。"})]}),i.jsxs("button",{type:"button",onClick:()=>void u(),disabled:r,children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"refresh"}),r?"刷新中":"刷新"]})]}),o?i.jsx("div",{className:"af-project-admin-usage__error",children:o}):null,i.jsxs("section",{className:"af-admin-usage-rate-grid","aria-label":"使用率",children:[i.jsxs("div",{children:[i.jsx("span",{children:"7日活跃用户率"}),i.jsx("strong",{children:zp(p.activeUserRate)}),i.jsxs("em",{children:[Wr(p.activeUsers)," / ",Wr(h.users)," users"]})]}),i.jsxs("div",{children:[i.jsx("span",{children:"7日流水线使用率"}),i.jsx("strong",{children:zp(p.activePipelineRate)}),i.jsxs("em",{children:[Wr(p.activePipelines)," / ",Wr(h.activePipelines)," active"]})]}),i.jsxs("div",{children:[i.jsx("span",{children:"7日 Run"}),i.jsx("strong",{children:Wr(p.runs)}),i.jsxs("em",{children:[Wr(p.avgRunsPerDay)," / day"]})]}),i.jsxs("div",{children:[i.jsx("span",{children:"7日成功率"}),i.jsx("strong",{children:zp(p.successRate)}),i.jsxs("em",{children:["失败率 ",zp(p.failureRate)," · avg ",pw(p.avgDurationMs)]})]})]}),i.jsxs("section",{className:"af-project-admin-usage af-admin-usage-trend",children:[i.jsx("div",{className:"af-project-admin-usage__head",children:i.jsxs("div",{children:[i.jsx("strong",{children:"每日趋势"}),i.jsx("span",{children:"上方看趋势,下方看最近 50 次具体运行。"})]})}),i.jsxs("div",{className:"af-admin-usage-chart",role:"img","aria-label":"最近 14 天运行趋势",children:[i.jsxs("div",{className:"af-admin-usage-chart__legend",children:[i.jsxs("span",{children:[i.jsx("i",{className:"af-admin-usage-chart__swatch af-admin-usage-chart__swatch--runs"}),"Runs"]}),i.jsxs("span",{children:[i.jsx("i",{className:"af-admin-usage-chart__swatch af-admin-usage-chart__swatch--users"}),"活跃用户"]}),i.jsxs("span",{children:[i.jsx("i",{className:"af-admin-usage-chart__swatch af-admin-usage-chart__swatch--pipelines"}),"活跃流水线"]})]}),i.jsx("div",{className:"af-admin-usage-chart__canvas",children:i.jsxs("svg",{viewBox:`0 0 ${f.width} ${f.height}`,preserveAspectRatio:"xMidYMid meet",children:[i.jsx("line",{className:"af-admin-usage-chart__axis",x1:f.margin.left,y1:f.margin.top+f.innerHeight,x2:f.width-f.margin.right,y2:f.margin.top+f.innerHeight}),[.25,.5,.75,1].map(k=>i.jsx("line",{className:"af-admin-usage-chart__grid",x1:f.margin.left,y1:f.margin.top+f.innerHeight-f.innerHeight*k,x2:f.width-f.margin.right,y2:f.margin.top+f.innerHeight-f.innerHeight*k},k)),f.rows.map((k,b)=>{const g=f.x(b),v=f.yRuns(k.runs),w=f.margin.top+f.innerHeight,N=Math.max(2,w-v);return i.jsxs("g",{children:[i.jsx("rect",{className:"af-admin-usage-chart__run-bar",x:g-f.barWidth/2,y:w-N,width:f.barWidth,height:N,rx:"5",children:i.jsx("title",{children:`${k.date}: ${k.runs} runs`})}),i.jsx("text",{className:"af-admin-usage-chart__value",x:g,y:w+22,children:Wr(k.runs)}),i.jsx("text",{className:"af-admin-usage-chart__date",x:g,y:w+42,children:gie(k.date)})]},k.date)}),f.rows.length>0?i.jsxs(i.Fragment,{children:[i.jsx("path",{className:"af-admin-usage-chart__line af-admin-usage-chart__line--users",d:f.lineUsers}),i.jsx("path",{className:"af-admin-usage-chart__line af-admin-usage-chart__line--pipelines",d:f.linePipelines}),f.rows.map((k,b)=>{const g=f.x(b);return i.jsxs("g",{children:[i.jsx("circle",{className:"af-admin-usage-chart__point af-admin-usage-chart__point--users",cx:g,cy:f.yLine(k.users),r:"3.5"}),i.jsx("circle",{className:"af-admin-usage-chart__point af-admin-usage-chart__point--pipelines",cx:g,cy:f.yLine(k.pipelines),r:"3.5"})]},`${k.date}-points`)})]}):null]})})]}),i.jsx("div",{className:"af-project-admin-usage__table-wrap",children:i.jsxs("table",{className:"af-project-admin-usage__table af-admin-usage-table--recent",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"用户"}),i.jsx("th",{children:"流水线"}),i.jsx("th",{children:"运行时间"}),i.jsx("th",{children:"状态"}),i.jsx("th",{children:"耗时"}),i.jsx("th",{children:"Run ID"})]})}),i.jsx("tbody",{children:y.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:6,children:"暂无运行明细"})}):y.map(k=>i.jsxs("tr",{className:"af-admin-usage-run-row",role:"button",tabIndex:0,title:"查看 Run 过程与 Thinking",onClick:()=>c(k),onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),c(k))},children:[i.jsxs("td",{children:[i.jsx("strong",{children:k.username||k.userId||"-"}),i.jsx("span",{children:k.userId||"-"})]}),i.jsxs("td",{children:[i.jsx("strong",{children:k.flowId||"-"}),i.jsxs("span",{children:[k.runType==="workspace"?"Workspace Run":"Pipeline"," · ",k.flowSource||"user"]})]}),i.jsxs("td",{children:[i.jsx("strong",{children:hw(k.at)}),k.endedAt?i.jsxs("span",{children:["结束 ",hw(k.endedAt)]}):i.jsx("span",{children:"未结束"})]}),i.jsx("td",{children:i.jsx("span",{className:"af-project-admin-usage__chips",children:i.jsx("em",{children:wie(k.status)})})}),i.jsx("td",{children:pw(k.durationMs)}),i.jsx("td",{children:i.jsxs("span",{className:"af-admin-usage-run-link",children:[i.jsx("code",{className:"af-admin-usage-run-id",title:k.runId,children:yie(k.runId)}),i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"open_in_new"})]})})]},`${k.userId}:${k.flowSource}:${k.flowId}:${k.runId}:${k.at}`))})]})})]}),i.jsxs("section",{className:"af-project-admin-usage",children:[i.jsx("div",{className:"af-project-admin-usage__head",children:i.jsxs("div",{children:[i.jsx("strong",{children:"用户使用明细"}),i.jsx("span",{children:"按用户汇总 Pipeline 数、Run 次数和最近运行。"})]})}),i.jsx("div",{className:"af-project-admin-usage__table-wrap",children:i.jsxs("table",{className:"af-project-admin-usage__table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"User"}),i.jsx("th",{children:"Pipeline"}),i.jsx("th",{children:"Runs"}),i.jsx("th",{children:"状态"}),i.jsx("th",{children:"最近运行"})]})}),i.jsx("tbody",{children:r&&!t?i.jsx("tr",{children:i.jsx("td",{colSpan:5,children:"正在加载..."})}):((t==null?void 0:t.users)||[]).length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:5,children:"暂无用户数据"})}):((t==null?void 0:t.users)||[]).map(k=>{var b,g,v,w,N,j,C,P,I,z,$;return i.jsxs("tr",{children:[i.jsxs("td",{children:[i.jsx("strong",{children:k.username||k.userId}),i.jsxs("span",{children:[k.userId,k.isAdmin?" · admin":""]})]}),i.jsxs("td",{children:[i.jsx("strong",{children:Wr((b=k.pipelines)==null?void 0:b.total)}),i.jsxs("span",{children:[Wr((g=k.pipelines)==null?void 0:g.active)," active / ",Wr((v=k.pipelines)==null?void 0:v.archived)," archived"]})]}),i.jsxs("td",{children:[i.jsx("strong",{children:Wr((w=k.runs)==null?void 0:w.total)}),i.jsxs("span",{children:["avg ",pw((N=k.runs)==null?void 0:N.avgDurationMs)]})]}),i.jsx("td",{children:i.jsxs("span",{className:"af-project-admin-usage__chips",children:[i.jsxs("em",{children:["成功 ",Wr((j=k.runs)==null?void 0:j.success)]}),i.jsxs("em",{children:["失败 ",Wr((C=k.runs)==null?void 0:C.failed)]}),i.jsxs("em",{children:["运行中 ",Wr((P=k.runs)==null?void 0:P.running)]})]})}),i.jsx("td",{children:(I=k.runs)!=null&&I.lastRunAt?i.jsxs(i.Fragment,{children:[i.jsx("strong",{children:((z=k.runs)==null?void 0:z.lastRunFlowId)||"-"}),i.jsxs("span",{children:[(($=k.runs)==null?void 0:$.lastRunStatus)||"unknown"," · ",hw(k.runs.lastRunAt)]})]}):i.jsx("span",{children:"无运行记录"})})]},k.userId)})})]})})]}),l?i.jsx(mie,{run:l,onClose:()=>c(null)}):null]}):i.jsx("main",{className:"af-admin-usage-page",children:i.jsx("section",{className:"af-project-admin-usage",children:i.jsx("div",{className:"af-project-admin-usage__head",children:i.jsxs("div",{children:[i.jsx("strong",{children:"管理看板"}),i.jsx("span",{children:"需要管理员权限。"})]})})})})}function bie(e){if(!e)return"";const t=Date.parse(e);if(Number.isNaN(t))return String(e);try{return new Intl.DateTimeFormat("zh-CN",{dateStyle:"short",timeStyle:"medium"}).format(new Date(t))}catch{return String(e)}}function kie({authUser:e}){const{navigate:t}=si(),[n,r]=m.useState(""),[s,o]=m.useState(""),[a,l]=m.useState(!1),[c,u]=m.useState(""),[d,f]=m.useState(!1),[p,h]=m.useState([]),[y,k]=m.useState(!1),[b,g]=m.useState(""),v=!!(e!=null&&e.isAdmin),w=m.useCallback(async()=>{if(v){k(!0),g("");try{const j=await fetch("/api/feedback"),C=await j.json().catch(()=>({}));if(!j.ok)throw new Error(C.error||"加载失败");h(Array.isArray(C.feedback)?C.feedback:[])}catch(j){g(String(j.message||j)),h([])}finally{k(!1)}}},[v]);m.useEffect(()=>{w()},[w]);const N=async j=>{if(j.preventDefault(),!a){l(!0),u("");try{const C=await fetch("/api/feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:n,content:s,pageUrl:window.location.href})}),P=await C.json().catch(()=>({}));if(!C.ok)throw new Error(P.error||"提交失败");f(!0),r(""),o("")}catch(C){u(String(C.message||C))}finally{l(!1)}}};return v?i.jsx("main",{className:"af-feedback-page",children:i.jsxs("section",{className:"af-feedback-panel af-feedback-panel--admin",children:[i.jsxs("div",{className:"af-feedback-head",children:[i.jsxs("div",{children:[i.jsx("span",{className:"af-feedback-eyebrow",children:"Feedback"}),i.jsx("h1",{children:"意见反馈"}),i.jsx("p",{children:"查看用户提交的问题、建议和功能需求。"})]}),i.jsxs("div",{className:"af-feedback-admin-actions",children:[i.jsxs("button",{type:"button",className:"af-feedback-back",onClick:()=>void w(),disabled:y,children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:y?"hourglass_empty":"refresh"}),y?"刷新中...":"刷新"]}),i.jsxs("button",{type:"button",className:"af-feedback-back",onClick:()=>t("/projects"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"arrow_back"}),"返回"]})]})]}),b?i.jsx("p",{className:"af-err af-feedback-error",children:b}):null,i.jsx("div",{className:"af-feedback-list af-feedback-list--page",children:p.length>0?p.map(j=>i.jsxs("article",{className:"af-feedback-item",children:[i.jsxs("header",{className:"af-feedback-item__head",children:[i.jsxs("div",{children:[i.jsx("h3",{children:j.title||"未命名反馈"}),i.jsxs("p",{children:[i.jsx("span",{children:j.username||j.userId||"unknown"}),i.jsx("span",{children:bie(j.createdAt)})]})]}),j.contact?i.jsx("span",{className:"af-feedback-item__contact",children:j.contact}):null]}),i.jsx("p",{className:"af-feedback-item__content",children:j.content}),j.pageUrl?i.jsx("code",{className:"af-feedback-item__url",children:j.pageUrl}):null]},j.id)):i.jsx("div",{className:"af-feedback-empty",children:y?"正在加载反馈...":"暂无反馈"})})]})}):i.jsx("main",{className:"af-feedback-page",children:i.jsxs("section",{className:"af-feedback-panel",children:[i.jsxs("div",{className:"af-feedback-head",children:[i.jsxs("div",{children:[i.jsx("span",{className:"af-feedback-eyebrow",children:"Feedback"}),i.jsx("h1",{children:"意见反馈"}),i.jsx("p",{children:"提交使用中遇到的问题、改进建议或功能需求,管理员会在这里统一查看。"})]}),i.jsxs("button",{type:"button",className:"af-feedback-back",onClick:()=>t("/projects"),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"arrow_back"}),"返回"]})]}),d?i.jsxs("div",{className:"af-feedback-success",role:"status",children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:"check_circle"}),i.jsxs("div",{children:[i.jsx("strong",{children:"已提交"}),i.jsx("span",{children:"感谢反馈,管理员可以在意见反馈页查看这条记录。"})]})]}):null,i.jsxs("form",{className:"af-feedback-form",onSubmit:N,children:[i.jsxs("label",{className:"af-feedback-field",children:[i.jsx("span",{children:"标题"}),i.jsx("input",{value:n,onChange:j=>r(j.target.value),placeholder:"一句话说明问题或建议",maxLength:120,required:!0})]}),i.jsxs("label",{className:"af-feedback-field",children:[i.jsx("span",{children:"反馈内容"}),i.jsx("textarea",{value:s,onChange:j=>o(j.target.value),placeholder:"描述具体场景、期望表现、实际表现或复现步骤",maxLength:5e3,rows:9,required:!0})]}),c?i.jsx("p",{className:"af-err af-feedback-error",children:c}):null,i.jsx("div",{className:"af-feedback-actions",children:i.jsxs("button",{type:"submit",className:"af-feedback-submit",disabled:a||!n.trim()||!s.trim(),children:[i.jsx("span",{className:"material-symbols-outlined","aria-hidden":!0,children:a?"hourglass_empty":"send"}),a?"提交中...":"提交反馈"]})})]})]})})}function EM(){return`m_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function h_(e,t=[]){const n=new Set((Array.isArray(t)?t:[]).map(String));return Object.entries(e&&typeof e=="object"?e:{}).map(([r,s])=>({id:EM(),key:r,value:String(s??""),private:n.has(r)}))}function m_(e){const t={};for(const n of Array.isArray(e)?e:[]){const r=String((n==null?void 0:n.key)||"").trim();r&&(t[r]=String((n==null?void 0:n.value)??""))}return t}function mh(e=null){const t=e!=null&&e.raw&&typeof e.raw=="object"?e.raw:{},n=Array.isArray(t.args)?t.args:Array.isArray(e==null?void 0:e.args)?e.args:[];return{originalName:String((e==null?void 0:e.name)||""),name:String((e==null?void 0:e.name)||""),type:e!=null&&e.url||t.url?"url":"command",url:String((e==null?void 0:e.url)||t.url||""),command:String((e==null?void 0:e.command)||t.command||""),argsText:n.map(String).join(`
316
316
  `),description:String((e==null?void 0:e.description)||t.description||""),envRows:h_(t.env||(e==null?void 0:e.env),e==null?void 0:e.privateEnvKeys),headerRows:h_(t.headers||(e==null?void 0:e.headers),e==null?void 0:e.privateHeaderKeys),extraJson:JSON.stringify(Object.fromEntries(Object.entries(t).filter(([r])=>!["url","command","args","env","headers","description","__agentflowPrivateKeys"].includes(r))),null,2)}}function mw(){return mh({name:"",raw:{command:""}})}function vie(e){const n={...e.extraJson.trim()?JSON.parse(e.extraJson):{}};if(e.type==="url")n.url=e.url.trim();else{n.command=e.command.trim();const o=e.argsText.split(/\r?\n/g).map(a=>a.trim()).filter(Boolean);o.length&&(n.args=o)}const r=m_(e.envRows),s=m_(e.headerRows);return Object.keys(r).length&&(n.env=r),Object.keys(s).length&&(n.headers=s),e.description.trim()&&(n.description=e.description.trim()),{name:e.originalName,nextName:e.name.trim(),server:n,privateEnvKeys:e.envRows.filter(o=>o.private).map(o=>String(o.key||"").trim()).filter(Boolean),privateHeaderKeys:e.headerRows.filter(o=>o.private).map(o=>String(o.key||"").trim()).filter(Boolean)}}function g_(e){return e?e.ok?`${e.toolCount||0} tools enabled`:`Error - ${e.error||"Show Output"}`:"未检测"}function y_(e){return e?e.ok?"ok":"error":"unknown"}function bb(e){return e==="ok"?"ok":e==="partial"?"partial":e==="unsupported"?"error":"unknown"}function Sie(e,t){return e&&e.label||t}async function gw(e){var n;const t=String(e||"");if(!t)return!1;try{if((n=navigator.clipboard)!=null&&n.writeText&&window.isSecureContext)return await navigator.clipboard.writeText(t),!0}catch{}try{const r=document.createElement("textarea");r.value=t,r.setAttribute("readonly",""),r.style.position="fixed",r.style.top="-9999px",r.style.left="-9999px",r.style.opacity="0",document.body.appendChild(r),r.focus(),r.select();const s=document.execCommand("copy");return r.remove(),s}catch{return!1}}function xv(e){return String(e||"").trim()||"<AGENTFLOW_TOKEN>"}function AM({baseUrl:e="",token:t=""}){return JSON.stringify({mcpServers:{agentflow:{command:"agentflow",args:["mcp"],env:{AGENTFLOW_BASE_URL:String(e||"http://127.0.0.1:8875"),AGENTFLOW_TOKEN:xv(t)}}}},null,2)}function PM({baseUrl:e="",token:t=""}){const n=JSON.stringify(String(e||"http://127.0.0.1:8875")),r=JSON.stringify(xv(t));return["[mcp_servers.agentflow]",'command = "agentflow"','args = ["mcp"]',"","[mcp_servers.agentflow.env]",`AGENTFLOW_BASE_URL = ${n}`,`AGENTFLOW_TOKEN = ${r}`].join(`
@@ -346,4 +346,4 @@ The left node panel allows you to freely drag, delete, and adjust connections.`}
346
346
  transform: scale(1);
347
347
  }
348
348
  }
349
- `)),document.head.appendChild(b);const g=setTimeout(()=>{Cr.domElement(p.current)&&c&&p.current.focus()},0);return()=>{clearTimeout(g);const v=document.getElementById("joyride-beacon-animation");v!=null&&v.parentNode&&v.parentNode.removeChild(v)}},[h,a,c]);const y=Ui(o.open);let k;if(t){const b=t;k=ft.createElement(b,{continuous:n,index:r,isLastStep:s,size:u,step:d})}else k=ft.createElement("span",{style:f.beacon},ft.createElement("span",{style:f.beaconOuter}),ft.createElement("span",{style:f.beaconInner}));return ft.createElement("button",{ref:p,"aria-label":y,className:"react-joyride__beacon","data-testid":"button-beacon",onClick:l,onMouseEnter:l,style:f.beaconWrapper,title:y,type:"button"},k)}function zle({styles:e,...t}){const{color:n,height:r,width:s,...o}=e;return ft.createElement("button",{style:o,type:"button",...t},ft.createElement("svg",{height:typeof r=="number"?`${r}px`:r,preserveAspectRatio:"xMidYMid",version:"1.1",viewBox:"0 0 18 18",width:typeof s=="number"?`${s}px`:s,xmlns:"http://www.w3.org/2000/svg"},ft.createElement("g",null,ft.createElement("path",{d:"M8.13911129,9.00268191 L0.171521827,17.0258467 C-0.0498027049,17.248715 -0.0498027049,17.6098394 0.171521827,17.8327545 C0.28204354,17.9443526 0.427188206,17.9998706 0.572051765,17.9998706 C0.71714958,17.9998706 0.862013139,17.9443526 0.972581703,17.8327545 L9.0000937,9.74924618 L17.0276057,17.8327545 C17.1384085,17.9443526 17.2832721,17.9998706 17.4281356,17.9998706 C17.5729992,17.9998706 17.718097,17.9443526 17.8286656,17.8327545 C18.0499901,17.6098862 18.0499901,17.2487618 17.8286656,17.0258467 L9.86135722,9.00268191 L17.8340066,0.973848225 C18.0553311,0.750979934 18.0553311,0.389855532 17.8340066,0.16694039 C17.6126821,-0.0556467968 17.254037,-0.0556467968 17.0329467,0.16694039 L9.00042166,8.25611765 L0.967006424,0.167268345 C0.745681892,-0.0553188426 0.387317931,-0.0553188426 0.165993399,0.167268345 C-0.0553311331,0.390136635 -0.0553311331,0.751261038 0.165993399,0.974176179 L8.13920499,9.00268191 L8.13911129,9.00268191 Z",fill:n}))))}function Ble(e){const{backProps:t,closeProps:n,index:r,isLastStep:s,primaryProps:o,skipProps:a,step:l,tooltipProps:c}=e,{buttons:u,content:d,styles:f,title:p}=l,h={};u.includes("primary")&&(h.primary=ft.createElement("button",{"data-testid":"button-primary",style:f.buttonPrimary,type:"button",...o})),u.includes("skip")&&!s&&(h.skip=ft.createElement("button",{"aria-live":"off","data-testid":"button-skip",style:f.buttonSkip,type:"button",...a})),u.includes("back")&&r>0&&(h.back=ft.createElement("button",{"data-testid":"button-back",style:f.buttonBack,type:"button",...t})),h.close=u.includes("close")&&ft.createElement(zle,{"data-testid":"button-close",styles:f.buttonClose,...n});const y=p?{"aria-labelledby":"joyride-tooltip-title","aria-describedby":"joyride-tooltip-content"}:{"aria-label":Ui(d),"aria-describedby":"joyride-tooltip-content"};return ft.createElement("div",{key:"JoyrideTooltip",className:"react-joyride__tooltip","data-joyride-step":r,...l.id&&{"data-joyride-id":l.id},style:f.tooltip,...c,...y},ft.createElement("div",{style:f.tooltipContainer},p&&ft.createElement("h4",{id:"joyride-tooltip-title",style:f.tooltipTitle},p),ft.createElement("div",{id:"joyride-tooltip-content",style:f.tooltipContent},d)),u.some(k=>k==="back"||k==="primary"||k==="skip")&&ft.createElement("div",{style:f.tooltipFooter},ft.createElement("div",{style:f.tooltipFooterSpacer},h.skip),h.back,h.primary),h.close)}function Hle(e){const{continuous:t,controls:n,index:r,isLastStep:s,size:o,step:a}=e,l=g=>{g.preventDefault(),n.prev(yi.BUTTON_BACK)},c=g=>{g.preventDefault(),a.closeButtonAction==="skip"?n.skip(yi.BUTTON_CLOSE):n.close(yi.BUTTON_CLOSE)},u=g=>{if(g.preventDefault(),!t){n.close(yi.BUTTON_PRIMARY);return}n.next(yi.BUTTON_PRIMARY)},d=g=>{g.preventDefault(),n.skip(yi.BUTTON_SKIP)},f=()=>{const{back:g,close:v,last:w,next:N,nextWithProgress:j,skip:C}=a.locale,P=Ui(g),I=Ui(v),z=Ui(w),$=Ui(N),L=Ui(C);let F=v,O=I;if(t){if(F=N,O=$,a.showProgress&&!s){const M=Ui(j,{step:r+1,steps:o});F=jb(j,r+1,o),O=M}s&&(F=w,O=z)}return{backProps:{"aria-label":P,children:g,"data-action":"back",onClick:l,role:"button",title:P},closeProps:{"aria-label":I,children:v,"data-action":"close",onClick:c,role:"button",title:I},primaryProps:{"aria-label":O,children:F,"data-action":"primary",onClick:u,role:"button",title:O},skipProps:{"aria-label":L,children:C,"data-action":"skip",onClick:d,role:"button",title:L},tooltipProps:{"aria-modal":!0,role:"alertdialog"}}},{arrowComponent:p,beaconComponent:h,tooltipComponent:y,...k}=a;let b;if(y){const g=y;b=ft.createElement(g,{...f(),continuous:t,controls:n,index:r,isLastStep:s,size:o,step:k})}else b=ft.createElement(Ble,{...f(),continuous:t,controls:n,index:r,isLastStep:s,size:o,step:k});return b}function Wle(e){if(e.startsWith("left"))return["top","bottom"];if(e.startsWith("right"))return["bottom","top"]}function Vle(e,t,n){var r,s;return e?[Yae()]:((r=t.floatingOptions)==null?void 0:r.flipOptions)===!1?[]:[Uae({crossAxis:!1,fallbackPlacements:Wle(n),padding:20,...(s=t.floatingOptions)==null?void 0:s.flipOptions})]}function Kle(e){var W,E,Q,V,B;const{continuous:t,controls:n,index:r,lifecycle:s,nonce:o,open:a,portalElement:l,setPositionData:c,setTooltipRef:u,shouldScroll:d,size:f,step:p,target:h,updateState:y}=e,k=m.useRef(null),b=m.useRef({}),g=m.useRef({}),v=p.placement==="center",w=p.placement==="auto",N=m.useMemo(()=>({getBoundingClientRect:()=>({x:window.innerWidth/2,y:window.innerHeight/2,top:window.innerHeight/2,left:window.innerWidth/2,bottom:window.innerHeight/2,right:window.innerWidth/2,width:0,height:0})}),[]),j=m.useMemo(()=>n$(h)?qc(h):void 0,[h]),C=m.useMemo(()=>Uc(h),[h]),P=m.useMemo(()=>j?{boundary:j,rootBoundary:"viewport"}:{},[j]),I=v||w?"bottom":p.placement,z=v?"fixed":((W=p.floatingOptions)==null?void 0:W.strategy)??(p.isFixed||C?"fixed":"absolute"),$=m.useMemo(()=>{var se,ue,G,ee;return v?[{name:"center",fn:({rects:te})=>({x:(window.innerWidth-te.floating.width)/2,y:(window.innerHeight-te.floating.height)/2})}]:[B_(({placement:te})=>{var ce;let ne="right";te.startsWith("top")?ne="top":te.startsWith("bottom")?ne="bottom":te.startsWith("left")&&(ne="left");const Z=p.spotlightTarget?0:p.spotlightPadding[ne];return p.offset+Z+((ce=p.floatingOptions)!=null&&ce.hideArrow?0:p.arrowSize)},[p.offset,p.spotlightPadding,p.spotlightTarget,p.arrowSize,(se=p.floatingOptions)==null?void 0:se.hideArrow]),...Vle(w,p,I),qae({padding:10,...P,...(ue=p.floatingOptions)==null?void 0:ue.shiftOptions}),...(G=p.floatingOptions)!=null&&G.hideArrow?[]:[Gae({element:k,padding:p.arrowSpacing},[p.arrowSpacing,p.arrowBase])],...((ee=p.floatingOptions)==null?void 0:ee.middleware)??[]]},[v,p,w,I,P]),L=z_({...v?{elements:{reference:N}}:{},placement:I,strategy:z,middleware:$}),F=z_({strategy:z,placement:p.beaconPlacement??(w||v?"bottom":p.placement),middleware:m.useMemo(()=>{var se,ue;return[B_(((ue=(se=p.floatingOptions)==null?void 0:se.beaconOptions)==null?void 0:ue.offset)??-18)]},[(Q=(E=p.floatingOptions)==null?void 0:E.beaconOptions)==null?void 0:Q.offset]),whileElementsMounted:O_});g.current=L.middlewareData,b.current=F.middlewareData,m.useEffect(()=>{var G;const{floating:se,reference:ue}=L.elements;if(!(!ue||!se||s!==Xe.TOOLTIP))return O_(ue,se,L.update,(G=p.floatingOptions)==null?void 0:G.autoUpdate)},[s,L.update,(V=p.floatingOptions)==null?void 0:V.autoUpdate,p.target,L.elements]),m.useEffect(()=>{!v&&h&&L.refs.setReference(h),h&&F.refs.setReference(h)},[F.refs,v,h,L.refs]),m.useEffect(()=>{L.isPositioned&&c("tooltip",{placement:L.placement,x:L.x??0,y:L.y??0,middlewareData:g.current})},[c,L.isPositioned,L.placement,L.x,L.y]),m.useEffect(()=>{F.isPositioned&&c("beacon",{placement:F.placement,x:F.x??0,y:F.y??0,middlewareData:b.current})},[c,F.isPositioned,F.placement,F.x,F.y]);const O=p.zIndex+100,M=m.useCallback(se=>{se.type==="mouseenter"&&p.beaconTrigger!=="hover"||y({lifecycle:Xe.TOOLTIP_BEFORE,positioned:!1})},[p.beaconTrigger,y]),K=m.useCallback(se=>{se&&(L.refs.setFloating(se),u(se))},[L.refs,u]),{arrow:H,floater:D}=p.styles;let T=null;if(s===Xe.TOOLTIP||s===Xe.TOOLTIP_BEFORE){const se=W_({...D,...L.floatingStyles,zIndex:O,opacity:a&&L.isPositioned?1:0,...!a&&{transition:"none"}});T=ft.createElement("div",{ref:K,className:"react-joyride__floater","data-testid":"floater",id:`react-joyride-step-${r}`,style:se},ft.createElement(Hle,{continuous:t,controls:n,index:r,isLastStep:r+1===f,size:f,step:p}),!v&&!((B=p.floatingOptions)!=null&&B.hideArrow)&&ft.createElement(Dle,{arrowComponent:p.arrowComponent,arrowRef:k,base:p.arrowBase,placement:L.placement,position:L.middlewareData.arrow,size:p.arrowSize,styles:H}))}else(s===Xe.BEACON||s===Xe.BEACON_BEFORE)&&(T=ft.createElement("div",{ref:F.refs.setFloating,className:"react-joyride__floater","data-testid":"floater-beacon",id:`react-joyride-step-${r}-beacon`,style:W_({...F.floatingStyles,zIndex:O})},ft.createElement(Fle,{beaconComponent:p.beaconComponent,continuous:t,index:r,isLastStep:r+1===f,locale:p.locale,nonce:o,onInteract:M,shouldFocus:d,size:f,step:p,styles:p.styles})));return ft.createElement(o$,{element:l},T)}function qle(e){const{continuous:t,controls:n,index:r,lifecycle:s,nonce:o,portalElement:a,setPositionData:l,shouldScroll:c,size:u,step:d,updateState:f}=e,[p,h]=m.useState(null);$le(d.disableFocusTrap?null:p,"[data-action=primary]");const y=Es(d.target),k=s===Xe.TOOLTIP;return!s$(d)||!Cr.domElement(y)?null:ft.createElement(Kle,{key:`JoyrideStep-${r}`,continuous:t,controls:n,index:r,lifecycle:s,nonce:o,open:k,portalElement:a,setPositionData:l,setTooltipRef:h,shouldScroll:c,size:u,step:d,target:y,updateState:f})}function Ule({controls:e,mergedProps:t,state:n,step:r,store:s}){const{continuous:o,debug:a,nonce:l,portalElement:c,scrollToFirstStep:u}=t,d=Cle(c),{index:f,lifecycle:p,status:h}=n,y=h===It.RUNNING,[k,b]=m.useState(!1),g=m.useRef(null),v=(r==null?void 0:r.loaderDelay)??0;m.useEffect(()=>(n.waiting?v===0?b(!0):g.current=setTimeout(()=>{b(!0)},v):b(!1),()=>{g.current&&(clearTimeout(g.current),g.current=null)}),[v,n.waiting]),m.useEffect(()=>{if(!y)return;const j=C=>{!r||p!==Xe.TOOLTIP||C.key==="Escape"&&r.dismissKeyAction&&(r.dismissKeyAction==="next"?e.next(yi.KEYBOARD):e.close(yi.KEYBOARD))};return document.body.addEventListener("keydown",j,{passive:!0}),()=>{document.body.removeEventListener("keydown",j)}},[e,y,p,r]);const w=m.useCallback(()=>{(r==null?void 0:r.overlayClickAction)==="close"?e.close(yi.OVERLAY):(r==null?void 0:r.overlayClickAction)==="next"&&e.next(yi.OVERLAY)},[e,r==null?void 0:r.overlayClickAction]);if(!r||!y)return null;const N=n.action===$t.START&&!r.skipBeacon&&r.placement!=="center";return ft.createElement(ft.Fragment,null,p!==Xe.INIT&&ft.createElement(qle,{...n,continuous:o,controls:e,debug:a,nonce:l,portalElement:d,setPositionData:s.current.setPositionData,shouldScroll:!r.skipScroll&&(f!==0||u),step:r,updateState:s.current.updateState}),ft.createElement(o$,{element:d},ft.createElement(ft.Fragment,null,k&&ft.createElement(Ele,{nonce:l,step:r}),!N&&ft.createElement(Tle,{...r,continuous:o,lifecycle:p,onClickOverlay:w,portalElement:c?d:null,scrolling:n.scrolling,waiting:n.waiting}))))}function Yle(e){const{controls:t,failures:n,mergedProps:r,state:s,step:o,store:a}=jle(e);return{controls:t,failures:n,on:m.useCallback((l,c)=>a.current.on(l,c),[a]),state:m.useMemo(()=>Cm(s,"positioned"),[s]),step:o,Tour:Av()?ft.createElement(Ule,{controls:t,mergedProps:r,state:s,step:o,store:a}):null}}function Gle(e){const{Tour:t}=Yle(e);return t}function Jle(e){return Av()?ft.createElement(Gle,e):null}function Xle(e){return[{target:"body",content:e("onboarding:projects.intro"),disableBeacon:!0,placement:"center"},{target:".af-hub-card",content:e("onboarding:projects.hubIntro"),disableBeacon:!0,placement:"left"}]}function Qle(e){return[{target:"body",content:e("onboarding:flow.intro"),disableBeacon:!0,placement:"center"}]}function Zle(e){return[{target:"body",content:e("onboarding:flow.introEmpty"),disableBeacon:!0,placement:"center"}]}const qp="af:onboarding";function ece({page:e,hasNodes:t=!1}){const{t:n}=Fr(),[r,s]=m.useState(!1),[o,a]=m.useState([]),l=m.useRef(null),c=m.useMemo(()=>e==="projects"?Xle(n):t?Qle(n):Zle(n),[e,t,n]);return m.useEffect(()=>{const u=localStorage.getItem(qp),d=u?JSON.parse(u):{};if(d.completed||d[e]){s(!1),a([]);return}localStorage.setItem(qp,JSON.stringify({...d,[e]:!0})),a(c),s(!0)},[e,t,c]),m.useEffect(()=>{if(!r)return;const u=d=>{var y;const f=d.target.closest("button");if(!f||!f.closest(".react-joyride__tooltip"))return;const h=(y=f.textContent)==null?void 0:y.trim();if(h===n("onboarding:done")||h===n("onboarding:startCreate")||h===n("onboarding:skip")){const k=localStorage.getItem(qp)||"{}",b=JSON.parse(k);h===n("onboarding:skip")?(b.projects=!0,b.flow=!0,b.completed=!0):b[e]=!0,localStorage.setItem(qp,JSON.stringify(b)),a([]),s(!1),e==="projects"&&(h===n("onboarding:done")||h===n("onboarding:startCreate"))&&(localStorage.setItem("af:newPipelineGuide","true"),setTimeout(()=>{const g=document.querySelector(".af-create-btn");g&&g.click()},500))}};return document.addEventListener("click",u,!0),()=>document.removeEventListener("click",u,!0)},[r,e,n]),!r||o.length===0?null:i.jsx(Jle,{ref:l,steps:o,run:r,continuous:!0,showSkipButton:!0,showProgress:o.length>1,styles:{options:{primaryColor:"#7c4dff",textColor:"#ffffff",backgroundColor:"#1a1a1a",arrowColor:"#1a1a1a",overlayColor:"rgba(0, 0, 0, 0.4)",zIndex:1e4},tooltip:{borderRadius:"1.5rem",padding:"1.5rem"},buttonNext:{borderRadius:"9999px",padding:"0.625rem 1.5rem"},buttonSkip:{borderRadius:"9999px",color:"#9ecaff"},buttonClose:{display:"none"}},locale:{back:n("onboarding:back"),next:n("onboarding:next"),skip:n("onboarding:skip"),last:n(e==="projects"?"onboarding:startCreate":"onboarding:done")},floaterProps:{disableAnimation:!0},scrollToFirstStep:!0})}const tce="agentflow:recent-runs:v1",nce="agentflow:recent-runs:poller",rce=3e3,sce=8e3,ice=2e3,G_=5e3,oce=16e3,J_=[1e4,3e4,6e4];function ace(e){return J_[Math.min(Math.max(e-1,0),J_.length-1)]}function lce(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function cce(e){if(!e)return"暂无成功记录";try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return"暂无成功记录"}}function uce(){const{navigate:e,path:t}=si(),[n,r]=m.useState([]),[s,o]=m.useState(!1),[a,l]=m.useState(1),[c,u]=m.useState({status:"idle",failureCount:0,lastSuccessAt:0,message:""}),d=m.useRef(()=>{});m.useEffect(()=>{let N=!1,j=!1,C=!1,P=null,I=0,z=0,$=0,L=0,F=null,O=0,M=0;const K=lce(),H=new Map,D=typeof BroadcastChannel=="function"?new BroadcastChannel(tce):null,T=Ce=>{try{D==null||D.postMessage({...Ce,tabId:K,sentAt:Date.now()})}catch{}},W=()=>{const Ce=Date.now()-oce;for(const[_e,Be]of H)Be<Ce&&H.delete(_e);l(1+H.size)},E=(Ce="presence")=>{T({type:Ce,visible:!document.hidden})},Q=Ce=>{if(!N&&(Array.isArray(Ce.runs)&&r(Ce.runs),Ce.syncHealth&&typeof Ce.syncHealth=="object")){const _e=Ce.syncHealth;O=Number(_e.failureCount)||0,M=Number(_e.lastSuccessAt)||0,u(_e)}},V=Ce=>{Q(Ce),T({type:"state",...Ce})},B=()=>{I&&(window.clearTimeout(I),I=0)},se=Ce=>{B(),!(N||!j||document.hidden)&&(I=window.setTimeout(()=>{I=0,ue()},Math.max(0,Ce)))},ue=async()=>{if(N||!j||document.hidden||F)return;const Ce=new AbortController;F=Ce;let _e=!1;const Be=window.setTimeout(()=>{_e=!0,Ce.abort()},sce);try{const ot=await fetch("/api/pipeline-recent-runs",{signal:Ce.signal});if(!ot.ok)throw new Error(`HTTP ${ot.status}`);const yt=await ot.json();if(N||!j||document.hidden)return;O=0,M=Date.now();const Te=Array.isArray(yt.runs)?yt.runs:[];V({runs:Te.filter(st=>st&&st.status==="running"),syncHealth:{status:"ok",failureCount:0,lastSuccessAt:M,message:""}}),se(rce)}catch(ot){const yt=Ce.signal.aborted&&!_e;if(N||!j||document.hidden||yt)return;O+=1,V({syncHealth:{status:"delayed",failureCount:O,lastSuccessAt:M,message:_e?"运行状态同步超过 8 秒未响应":`运行状态同步失败:${String((ot==null?void 0:ot.message)||ot)}`}}),se(ace(O))}finally{window.clearTimeout(Be),F===Ce&&(F=null)}},G=()=>{B(),F&&(F.abort(),F=null)},ee=()=>{if(G(),P){const Ce=P;P=null,Ce()}j=!1},te=(Ce=ice)=>{z&&window.clearTimeout(z),!(N||document.hidden||j||C)&&(z=window.setTimeout(()=>{z=0,Z()},Ce))},ne=()=>{N||document.hidden||j||(j=!0,se(0))},Z=async()=>{var Ce;if(!(N||document.hidden||j||C)){if(!((Ce=navigator.locks)!=null&&Ce.request)){ne();return}C=!0;try{await navigator.locks.request(nce,{mode:"exclusive",ifAvailable:!0},async _e=>{if(C=!1,!_e||N||document.hidden){te();return}j=!0,se(0),await new Promise(Be=>{P=Be}),P=null,j=!1})}catch{C=!1}finally{te()}}},ce=()=>{if(!N){if(j){O=0,se(0);return}T({type:"retry"}),te(0)}};d.current=ce,D&&(D.onmessage=Ce=>{const _e=Ce.data;if(!(!_e||_e.tabId===K)){if(_e.type==="hello"||_e.type==="presence"){H.set(_e.tabId,Date.now()),W(),_e.type==="hello"&&E();return}if(_e.type==="bye"){H.delete(_e.tabId),W(),te(0);return}if(_e.type==="state"){H.set(_e.tabId,Date.now()),W(),Q(_e);return}_e.type==="retry"&&j&&(O=0,se(0))}});const de=()=>{E(),document.hidden?ee():te(0)},me=()=>{E("bye"),ee()},$e=()=>{E("hello"),te(0)};return document.addEventListener("visibilitychange",de),window.addEventListener("pagehide",me),window.addEventListener("pageshow",$e),E("hello"),$=window.setInterval(E,G_),L=window.setInterval(W,G_),te(0),()=>{N=!0,d.current=()=>{},E("bye"),ee(),z&&window.clearTimeout(z),$&&window.clearInterval($),L&&window.clearInterval(L),document.removeEventListener("visibilitychange",de),window.removeEventListener("pagehide",me),window.removeEventListener("pageshow",$e),D==null||D.close()}},[]);const f=N=>{const j=new URLSearchParams({flowId:N.flowId,flowSource:N.flowSource||"workspace"});e(`/flow?${j.toString()}`),o(!1)},p=t==="/flow"?new URLSearchParams(window.location.search):null,h=(p==null?void 0:p.get("flowId"))||"",y=c.status==="delayed",k=a>1,b=n.length===1;if(n.length===0&&!y&&!k)return null;const g=y?"状态同步延迟":n.length>0?b?n[0].flowId:`${n.length} running`:`${a} 个标签页 · 同步已合并`,v=y?`${c.message}${k?`;检测到 ${a} 个 AgentFlow 标签页`:""}`:k?`已合并 ${a} 个 AgentFlow 标签页的运行状态同步`:b?`${n[0].flowId} 运行中,点击跳转`:`${n.length} 个 pipeline 运行中`,w=()=>{if(!y&&!k&&b){f(n[0]);return}o(N=>!N)};return i.jsxs("div",{className:"af-run-indicator"+(y?" af-run-indicator--delayed":"")+(k?" af-run-indicator--coordinated":""),role:"status","aria-live":"polite",children:[s&&i.jsxs("div",{className:"af-run-indicator__menu",onMouseLeave:()=>o(!1),children:[(y||k)&&i.jsxs("div",{className:"af-run-indicator__sync",children:[i.jsx("div",{className:"af-run-indicator__sync-title",children:y?"运行状态同步延迟":"多标签页同步已合并"}),i.jsx("div",{className:"af-run-indicator__sync-copy",children:k?`检测到 ${a} 个 AgentFlow 标签页。当前只由一个可见标签页请求运行状态,后台页面不会重复建立连接。`:"运行状态接口暂未及时返回,已停止重复请求并自动降低刷新频率。"}),y&&i.jsxs("div",{className:"af-run-indicator__sync-meta",children:["最近成功:",cce(c.lastSuccessAt)]}),y&&i.jsx("button",{type:"button",className:"af-run-indicator__retry",onClick:N=>{N.stopPropagation(),d.current()},children:"立即重试"})]}),n.map(N=>i.jsxs("button",{type:"button",className:"af-run-indicator__item"+(N.flowId===h?" af-run-indicator__item--current":""),onClick:()=>f(N),title:`${N.flowId} · ${N.runId}`,children:[i.jsx("span",{className:"af-run-indicator__dot"}),i.jsx("span",{className:"af-run-indicator__flow",children:N.flowId}),i.jsx("span",{className:"af-run-indicator__run",children:N.runId.slice(0,12)})]},`${N.flowId}:${N.runId}`))]}),i.jsxs("button",{type:"button",className:"af-run-indicator__btn",onClick:w,title:v,children:[i.jsx("span",{className:"af-run-indicator__pulse"}),i.jsx("span",{className:"af-run-indicator__label",children:g})]})]})}const Sw="0.1.114",dce=6e4,fce=30*6e4;function $c(e){return String(e||"").trim().replace(/^v/i,"")}function pce(e,t){const n=$c(e),r=$c(t);return!!(n&&r&&n!==r)}function hce(e,t){return`agentflow.app-version.snooze:${$c(e)}:${$c(t)}`}function mce(e){if(!e)return 0;try{const t=Number(window.sessionStorage.getItem(e));return Number.isFinite(t)?t:0}catch{return 0}}function gce(){const[e,t]=m.useState(null);if(m.useEffect(()=>{let r=!1,s=!1;const o=async()=>{if(!(s||document.visibilityState==="hidden")){s=!0;try{const c=await fetch("/api/app-version",{cache:"no-store"}),u=await c.json().catch(()=>({}));if(!c.ok||r)return;const d=$c(u.version);if(!pce(Sw,d)){t(null);return}const f=hce(Sw,d);if(mce(f)>Date.now())return;t({clientVersion:$c(Sw),serverVersion:d,startedAt:String(u.startedAt||""),snoozeKey:f})}catch{}finally{s=!1}}},a=()=>{document.visibilityState==="visible"&&o()},l=window.setInterval(()=>void o(),dce);return document.addEventListener("visibilitychange",a),window.addEventListener("focus",o),o(),()=>{r=!0,window.clearInterval(l),document.removeEventListener("visibilitychange",a),window.removeEventListener("focus",o)}},[]),!e)return null;const n=()=>{try{window.sessionStorage.setItem(e.snoozeKey,String(Date.now()+fce))}catch{}t(null)};return i.jsxs("aside",{className:"af-app-version-notice",role:"status","aria-live":"polite",children:[i.jsx("span",{className:"material-symbols-outlined af-app-version-notice__icon","aria-hidden":!0,children:"system_update"}),i.jsxs("div",{className:"af-app-version-notice__copy",children:[i.jsx("strong",{children:"AgentFlow 已更新"}),i.jsxs("span",{children:["v",e.clientVersion," → v",e.serverVersion,",刷新后生效"]})]}),i.jsxs("div",{className:"af-app-version-notice__actions",children:[i.jsx("button",{type:"button",className:"af-app-version-notice__later",onClick:n,children:"稍后"}),i.jsx("button",{type:"button",className:"af-app-version-notice__refresh",onClick:()=>window.location.reload(),children:"刷新更新"})]})]})}function a$(e){return e==="/likee-context"||e==="/likee_context"}function yce(){const{navigate:e}=si();return m.useEffect(()=>{const t=new URLSearchParams(window.location.search),n=new URLSearchParams,r=t.get("flowId")||"",s=t.get("flowSource")||"";r&&n.set("flowId",r),s&&n.set("flowSource",s),t.get("flowArchived")&&n.set("archived",t.get("flowArchived")),e(`/workspace${n.toString()?`?${n.toString()}`:""}`)},[e]),null}class wce extends m.Component{constructor(t){super(t),this.state={error:null,info:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,n){console.error("[AgentFlow UI render error]",t,n),this.setState({error:t,info:n})}render(){var r,s,o;if(!this.state.error)return this.props.children;const t=String(((r=this.state.error)==null?void 0:r.stack)||((s=this.state.error)==null?void 0:s.message)||this.state.error),n=String(((o=this.state.info)==null?void 0:o.componentStack)||"");return i.jsx("div",{className:"af-auth-screen",children:i.jsxs("div",{className:"af-auth-panel af-ui-error-panel",children:[i.jsxs("div",{className:"af-auth-brand",children:[i.jsx("span",{className:"material-symbols-outlined",children:"error"}),i.jsxs("div",{children:[i.jsx("h1",{children:"AgentFlow UI Error"}),i.jsx("p",{children:"页面渲染失败,下面是调试堆栈。"})]})]}),i.jsx("pre",{children:t}),n?i.jsx("pre",{children:n}):null]})})}}function xce({authUser:e}){const{path:t}=si();return t==="/projects"||t==="/"?i.jsx(Pl,{authUser:e}):t==="/nodes"?i.jsx(Pl,{authUser:e,resourceKind:"nodes"}):t==="/my-nodes"?i.jsx(Pl,{authUser:e,resourceKind:"my-nodes"}):t==="/my-flows"?i.jsx(Pl,{authUser:e,resourceKind:"my-flows"}):t==="/skills"?i.jsx(Pl,{authUser:e,resourceKind:"skills"}):t==="/workspaces"?i.jsx(Die,{authUser:e}):t==="/mcps"?i.jsx(Cie,{}):t==="/schedules"?i.jsx(Pie,{}):t==="/node-studio"?i.jsx(Rie,{}):t==="/flow"?i.jsx(yce,{}):t==="/workspace"?i.jsx(DJ,{}):t.startsWith("/display")?i.jsx(wM,{}):t==="/settings"?i.jsx(die,{authUser:e}):t==="/admin/usage"?i.jsx(xie,{authUser:e}):t==="/feedback"?i.jsx(kie,{authUser:e}):a$(t)?i.jsx(IM,{}):i.jsx(Pl,{})}function bce({children:e}){const[t,n]=m.useState({loading:!0,authenticated:!1,user:null,setupRequired:!1}),[r,s]=m.useState(""),[o,a]=m.useState(""),[l,c]=m.useState(!1),[u,d]=m.useState(""),f=async()=>{try{const y=await(await fetch("/api/auth/me")).json().catch(()=>({}));n({loading:!1,authenticated:!!y.authenticated,user:y.user||null,setupRequired:!!y.setupRequired}),d(y.error?String(y.error):"")}catch(h){n({loading:!1,authenticated:!1,user:null,setupRequired:!1}),d(String(h.message||h))}};m.useEffect(()=>{f()},[]);const p=async h=>{h.preventDefault(),c(!0),d("");try{const y=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:r,password:o})}),k=await y.json().catch(()=>({}));if(!y.ok)throw new Error(k.error||"登录失败");s(""),a(""),window.location.replace(window.location.href);return}catch(y){d(String(y.message||y))}finally{c(!1)}};return t.loading?i.jsx("div",{className:"af-auth-screen",children:i.jsx("div",{className:"af-auth-panel",children:"Loading..."})}):t.authenticated?e({user:t.user,onLogout:async()=>{await fetch("/api/auth/logout",{method:"POST"}).catch(()=>{}),n({loading:!1,authenticated:!1,user:null,setupRequired:!1})}}):i.jsx("div",{className:"af-auth-screen",children:i.jsxs("form",{className:"af-auth-panel",onSubmit:p,autoComplete:"on",children:[i.jsxs("div",{className:"af-auth-brand",children:[i.jsx("span",{className:"material-symbols-outlined",children:"account_circle"}),i.jsxs("div",{children:[i.jsx("h1",{children:"AgentFlow"}),i.jsx("p",{children:t.setupRequired?"初始化管理员账号":"登录或创建用户"})]})]}),i.jsxs("label",{className:"af-auth-field",children:[i.jsx("span",{children:"用户名"}),i.jsx("input",{id:"agentflow-auth-username",name:"username",type:"text",value:r,onChange:h=>s(h.target.value),autoComplete:"username",autoFocus:!0})]}),i.jsxs("label",{className:"af-auth-field",children:[i.jsx("span",{children:"密码"}),i.jsx("input",{id:"agentflow-auth-password",name:"password",type:"password",value:o,onChange:h=>a(h.target.value),autoComplete:t.setupRequired?"new-password":"current-password"})]}),u?i.jsx("p",{className:"af-auth-error",children:u}):null,i.jsx("button",{className:"af-auth-submit",type:"submit",disabled:l||!r.trim()||o.length<4,children:l?"处理中...":t.setupRequired?"创建并登录":"登录"})]})})}function kce({authUser:e,onLogout:t}){const{path:n}=si(),r=n==="/flow"||n==="/workspace";return i.jsxs("div",{className:"af-app",children:[n!=="/settings"?i.jsx(ece,{page:r?"flow":"projects"}):null,r?null:i.jsx(PD,{authUser:e,onLogout:t}),i.jsx("div",{className:r?"af-main af-main--pipeline":"af-main",children:i.jsx(xce,{authUser:e})}),i.jsx(uce,{})]})}function vce(){return i.jsx(wce,{children:i.jsxs(dD,{children:[i.jsx(Sce,{}),i.jsx(gce,{})]})})}function Sce(){const{path:e}=si();return e.startsWith("/display")?i.jsx(wM,{}):a$(e)?i.jsx(IM,{}):i.jsx(bce,{children:({user:t,onLogout:n})=>i.jsx(kce,{authUser:t,onLogout:n})})}window.addEventListener("error",e=>{console.error("[AgentFlow UI global error]",e.error||e.message,{filename:e.filename,lineno:e.lineno,colno:e.colno})});window.addEventListener("unhandledrejection",e=>{console.error("[AgentFlow UI unhandled rejection]",e.reason)});const X_=document.querySelector('link[rel="icon"]');X_&&(X_.href=pP);Nw.createRoot(document.getElementById("root")).render(i.jsx(ft.StrictMode,{children:i.jsx(vce,{})}));
349
+ `)),document.head.appendChild(b);const g=setTimeout(()=>{Cr.domElement(p.current)&&c&&p.current.focus()},0);return()=>{clearTimeout(g);const v=document.getElementById("joyride-beacon-animation");v!=null&&v.parentNode&&v.parentNode.removeChild(v)}},[h,a,c]);const y=Ui(o.open);let k;if(t){const b=t;k=ft.createElement(b,{continuous:n,index:r,isLastStep:s,size:u,step:d})}else k=ft.createElement("span",{style:f.beacon},ft.createElement("span",{style:f.beaconOuter}),ft.createElement("span",{style:f.beaconInner}));return ft.createElement("button",{ref:p,"aria-label":y,className:"react-joyride__beacon","data-testid":"button-beacon",onClick:l,onMouseEnter:l,style:f.beaconWrapper,title:y,type:"button"},k)}function zle({styles:e,...t}){const{color:n,height:r,width:s,...o}=e;return ft.createElement("button",{style:o,type:"button",...t},ft.createElement("svg",{height:typeof r=="number"?`${r}px`:r,preserveAspectRatio:"xMidYMid",version:"1.1",viewBox:"0 0 18 18",width:typeof s=="number"?`${s}px`:s,xmlns:"http://www.w3.org/2000/svg"},ft.createElement("g",null,ft.createElement("path",{d:"M8.13911129,9.00268191 L0.171521827,17.0258467 C-0.0498027049,17.248715 -0.0498027049,17.6098394 0.171521827,17.8327545 C0.28204354,17.9443526 0.427188206,17.9998706 0.572051765,17.9998706 C0.71714958,17.9998706 0.862013139,17.9443526 0.972581703,17.8327545 L9.0000937,9.74924618 L17.0276057,17.8327545 C17.1384085,17.9443526 17.2832721,17.9998706 17.4281356,17.9998706 C17.5729992,17.9998706 17.718097,17.9443526 17.8286656,17.8327545 C18.0499901,17.6098862 18.0499901,17.2487618 17.8286656,17.0258467 L9.86135722,9.00268191 L17.8340066,0.973848225 C18.0553311,0.750979934 18.0553311,0.389855532 17.8340066,0.16694039 C17.6126821,-0.0556467968 17.254037,-0.0556467968 17.0329467,0.16694039 L9.00042166,8.25611765 L0.967006424,0.167268345 C0.745681892,-0.0553188426 0.387317931,-0.0553188426 0.165993399,0.167268345 C-0.0553311331,0.390136635 -0.0553311331,0.751261038 0.165993399,0.974176179 L8.13920499,9.00268191 L8.13911129,9.00268191 Z",fill:n}))))}function Ble(e){const{backProps:t,closeProps:n,index:r,isLastStep:s,primaryProps:o,skipProps:a,step:l,tooltipProps:c}=e,{buttons:u,content:d,styles:f,title:p}=l,h={};u.includes("primary")&&(h.primary=ft.createElement("button",{"data-testid":"button-primary",style:f.buttonPrimary,type:"button",...o})),u.includes("skip")&&!s&&(h.skip=ft.createElement("button",{"aria-live":"off","data-testid":"button-skip",style:f.buttonSkip,type:"button",...a})),u.includes("back")&&r>0&&(h.back=ft.createElement("button",{"data-testid":"button-back",style:f.buttonBack,type:"button",...t})),h.close=u.includes("close")&&ft.createElement(zle,{"data-testid":"button-close",styles:f.buttonClose,...n});const y=p?{"aria-labelledby":"joyride-tooltip-title","aria-describedby":"joyride-tooltip-content"}:{"aria-label":Ui(d),"aria-describedby":"joyride-tooltip-content"};return ft.createElement("div",{key:"JoyrideTooltip",className:"react-joyride__tooltip","data-joyride-step":r,...l.id&&{"data-joyride-id":l.id},style:f.tooltip,...c,...y},ft.createElement("div",{style:f.tooltipContainer},p&&ft.createElement("h4",{id:"joyride-tooltip-title",style:f.tooltipTitle},p),ft.createElement("div",{id:"joyride-tooltip-content",style:f.tooltipContent},d)),u.some(k=>k==="back"||k==="primary"||k==="skip")&&ft.createElement("div",{style:f.tooltipFooter},ft.createElement("div",{style:f.tooltipFooterSpacer},h.skip),h.back,h.primary),h.close)}function Hle(e){const{continuous:t,controls:n,index:r,isLastStep:s,size:o,step:a}=e,l=g=>{g.preventDefault(),n.prev(yi.BUTTON_BACK)},c=g=>{g.preventDefault(),a.closeButtonAction==="skip"?n.skip(yi.BUTTON_CLOSE):n.close(yi.BUTTON_CLOSE)},u=g=>{if(g.preventDefault(),!t){n.close(yi.BUTTON_PRIMARY);return}n.next(yi.BUTTON_PRIMARY)},d=g=>{g.preventDefault(),n.skip(yi.BUTTON_SKIP)},f=()=>{const{back:g,close:v,last:w,next:N,nextWithProgress:j,skip:C}=a.locale,P=Ui(g),I=Ui(v),z=Ui(w),$=Ui(N),L=Ui(C);let F=v,O=I;if(t){if(F=N,O=$,a.showProgress&&!s){const M=Ui(j,{step:r+1,steps:o});F=jb(j,r+1,o),O=M}s&&(F=w,O=z)}return{backProps:{"aria-label":P,children:g,"data-action":"back",onClick:l,role:"button",title:P},closeProps:{"aria-label":I,children:v,"data-action":"close",onClick:c,role:"button",title:I},primaryProps:{"aria-label":O,children:F,"data-action":"primary",onClick:u,role:"button",title:O},skipProps:{"aria-label":L,children:C,"data-action":"skip",onClick:d,role:"button",title:L},tooltipProps:{"aria-modal":!0,role:"alertdialog"}}},{arrowComponent:p,beaconComponent:h,tooltipComponent:y,...k}=a;let b;if(y){const g=y;b=ft.createElement(g,{...f(),continuous:t,controls:n,index:r,isLastStep:s,size:o,step:k})}else b=ft.createElement(Ble,{...f(),continuous:t,controls:n,index:r,isLastStep:s,size:o,step:k});return b}function Wle(e){if(e.startsWith("left"))return["top","bottom"];if(e.startsWith("right"))return["bottom","top"]}function Vle(e,t,n){var r,s;return e?[Yae()]:((r=t.floatingOptions)==null?void 0:r.flipOptions)===!1?[]:[Uae({crossAxis:!1,fallbackPlacements:Wle(n),padding:20,...(s=t.floatingOptions)==null?void 0:s.flipOptions})]}function Kle(e){var W,E,Q,V,B;const{continuous:t,controls:n,index:r,lifecycle:s,nonce:o,open:a,portalElement:l,setPositionData:c,setTooltipRef:u,shouldScroll:d,size:f,step:p,target:h,updateState:y}=e,k=m.useRef(null),b=m.useRef({}),g=m.useRef({}),v=p.placement==="center",w=p.placement==="auto",N=m.useMemo(()=>({getBoundingClientRect:()=>({x:window.innerWidth/2,y:window.innerHeight/2,top:window.innerHeight/2,left:window.innerWidth/2,bottom:window.innerHeight/2,right:window.innerWidth/2,width:0,height:0})}),[]),j=m.useMemo(()=>n$(h)?qc(h):void 0,[h]),C=m.useMemo(()=>Uc(h),[h]),P=m.useMemo(()=>j?{boundary:j,rootBoundary:"viewport"}:{},[j]),I=v||w?"bottom":p.placement,z=v?"fixed":((W=p.floatingOptions)==null?void 0:W.strategy)??(p.isFixed||C?"fixed":"absolute"),$=m.useMemo(()=>{var se,ue,G,ee;return v?[{name:"center",fn:({rects:te})=>({x:(window.innerWidth-te.floating.width)/2,y:(window.innerHeight-te.floating.height)/2})}]:[B_(({placement:te})=>{var ce;let ne="right";te.startsWith("top")?ne="top":te.startsWith("bottom")?ne="bottom":te.startsWith("left")&&(ne="left");const Z=p.spotlightTarget?0:p.spotlightPadding[ne];return p.offset+Z+((ce=p.floatingOptions)!=null&&ce.hideArrow?0:p.arrowSize)},[p.offset,p.spotlightPadding,p.spotlightTarget,p.arrowSize,(se=p.floatingOptions)==null?void 0:se.hideArrow]),...Vle(w,p,I),qae({padding:10,...P,...(ue=p.floatingOptions)==null?void 0:ue.shiftOptions}),...(G=p.floatingOptions)!=null&&G.hideArrow?[]:[Gae({element:k,padding:p.arrowSpacing},[p.arrowSpacing,p.arrowBase])],...((ee=p.floatingOptions)==null?void 0:ee.middleware)??[]]},[v,p,w,I,P]),L=z_({...v?{elements:{reference:N}}:{},placement:I,strategy:z,middleware:$}),F=z_({strategy:z,placement:p.beaconPlacement??(w||v?"bottom":p.placement),middleware:m.useMemo(()=>{var se,ue;return[B_(((ue=(se=p.floatingOptions)==null?void 0:se.beaconOptions)==null?void 0:ue.offset)??-18)]},[(Q=(E=p.floatingOptions)==null?void 0:E.beaconOptions)==null?void 0:Q.offset]),whileElementsMounted:O_});g.current=L.middlewareData,b.current=F.middlewareData,m.useEffect(()=>{var G;const{floating:se,reference:ue}=L.elements;if(!(!ue||!se||s!==Xe.TOOLTIP))return O_(ue,se,L.update,(G=p.floatingOptions)==null?void 0:G.autoUpdate)},[s,L.update,(V=p.floatingOptions)==null?void 0:V.autoUpdate,p.target,L.elements]),m.useEffect(()=>{!v&&h&&L.refs.setReference(h),h&&F.refs.setReference(h)},[F.refs,v,h,L.refs]),m.useEffect(()=>{L.isPositioned&&c("tooltip",{placement:L.placement,x:L.x??0,y:L.y??0,middlewareData:g.current})},[c,L.isPositioned,L.placement,L.x,L.y]),m.useEffect(()=>{F.isPositioned&&c("beacon",{placement:F.placement,x:F.x??0,y:F.y??0,middlewareData:b.current})},[c,F.isPositioned,F.placement,F.x,F.y]);const O=p.zIndex+100,M=m.useCallback(se=>{se.type==="mouseenter"&&p.beaconTrigger!=="hover"||y({lifecycle:Xe.TOOLTIP_BEFORE,positioned:!1})},[p.beaconTrigger,y]),K=m.useCallback(se=>{se&&(L.refs.setFloating(se),u(se))},[L.refs,u]),{arrow:H,floater:D}=p.styles;let T=null;if(s===Xe.TOOLTIP||s===Xe.TOOLTIP_BEFORE){const se=W_({...D,...L.floatingStyles,zIndex:O,opacity:a&&L.isPositioned?1:0,...!a&&{transition:"none"}});T=ft.createElement("div",{ref:K,className:"react-joyride__floater","data-testid":"floater",id:`react-joyride-step-${r}`,style:se},ft.createElement(Hle,{continuous:t,controls:n,index:r,isLastStep:r+1===f,size:f,step:p}),!v&&!((B=p.floatingOptions)!=null&&B.hideArrow)&&ft.createElement(Dle,{arrowComponent:p.arrowComponent,arrowRef:k,base:p.arrowBase,placement:L.placement,position:L.middlewareData.arrow,size:p.arrowSize,styles:H}))}else(s===Xe.BEACON||s===Xe.BEACON_BEFORE)&&(T=ft.createElement("div",{ref:F.refs.setFloating,className:"react-joyride__floater","data-testid":"floater-beacon",id:`react-joyride-step-${r}-beacon`,style:W_({...F.floatingStyles,zIndex:O})},ft.createElement(Fle,{beaconComponent:p.beaconComponent,continuous:t,index:r,isLastStep:r+1===f,locale:p.locale,nonce:o,onInteract:M,shouldFocus:d,size:f,step:p,styles:p.styles})));return ft.createElement(o$,{element:l},T)}function qle(e){const{continuous:t,controls:n,index:r,lifecycle:s,nonce:o,portalElement:a,setPositionData:l,shouldScroll:c,size:u,step:d,updateState:f}=e,[p,h]=m.useState(null);$le(d.disableFocusTrap?null:p,"[data-action=primary]");const y=Es(d.target),k=s===Xe.TOOLTIP;return!s$(d)||!Cr.domElement(y)?null:ft.createElement(Kle,{key:`JoyrideStep-${r}`,continuous:t,controls:n,index:r,lifecycle:s,nonce:o,open:k,portalElement:a,setPositionData:l,setTooltipRef:h,shouldScroll:c,size:u,step:d,target:y,updateState:f})}function Ule({controls:e,mergedProps:t,state:n,step:r,store:s}){const{continuous:o,debug:a,nonce:l,portalElement:c,scrollToFirstStep:u}=t,d=Cle(c),{index:f,lifecycle:p,status:h}=n,y=h===It.RUNNING,[k,b]=m.useState(!1),g=m.useRef(null),v=(r==null?void 0:r.loaderDelay)??0;m.useEffect(()=>(n.waiting?v===0?b(!0):g.current=setTimeout(()=>{b(!0)},v):b(!1),()=>{g.current&&(clearTimeout(g.current),g.current=null)}),[v,n.waiting]),m.useEffect(()=>{if(!y)return;const j=C=>{!r||p!==Xe.TOOLTIP||C.key==="Escape"&&r.dismissKeyAction&&(r.dismissKeyAction==="next"?e.next(yi.KEYBOARD):e.close(yi.KEYBOARD))};return document.body.addEventListener("keydown",j,{passive:!0}),()=>{document.body.removeEventListener("keydown",j)}},[e,y,p,r]);const w=m.useCallback(()=>{(r==null?void 0:r.overlayClickAction)==="close"?e.close(yi.OVERLAY):(r==null?void 0:r.overlayClickAction)==="next"&&e.next(yi.OVERLAY)},[e,r==null?void 0:r.overlayClickAction]);if(!r||!y)return null;const N=n.action===$t.START&&!r.skipBeacon&&r.placement!=="center";return ft.createElement(ft.Fragment,null,p!==Xe.INIT&&ft.createElement(qle,{...n,continuous:o,controls:e,debug:a,nonce:l,portalElement:d,setPositionData:s.current.setPositionData,shouldScroll:!r.skipScroll&&(f!==0||u),step:r,updateState:s.current.updateState}),ft.createElement(o$,{element:d},ft.createElement(ft.Fragment,null,k&&ft.createElement(Ele,{nonce:l,step:r}),!N&&ft.createElement(Tle,{...r,continuous:o,lifecycle:p,onClickOverlay:w,portalElement:c?d:null,scrolling:n.scrolling,waiting:n.waiting}))))}function Yle(e){const{controls:t,failures:n,mergedProps:r,state:s,step:o,store:a}=jle(e);return{controls:t,failures:n,on:m.useCallback((l,c)=>a.current.on(l,c),[a]),state:m.useMemo(()=>Cm(s,"positioned"),[s]),step:o,Tour:Av()?ft.createElement(Ule,{controls:t,mergedProps:r,state:s,step:o,store:a}):null}}function Gle(e){const{Tour:t}=Yle(e);return t}function Jle(e){return Av()?ft.createElement(Gle,e):null}function Xle(e){return[{target:"body",content:e("onboarding:projects.intro"),disableBeacon:!0,placement:"center"},{target:".af-hub-card",content:e("onboarding:projects.hubIntro"),disableBeacon:!0,placement:"left"}]}function Qle(e){return[{target:"body",content:e("onboarding:flow.intro"),disableBeacon:!0,placement:"center"}]}function Zle(e){return[{target:"body",content:e("onboarding:flow.introEmpty"),disableBeacon:!0,placement:"center"}]}const qp="af:onboarding";function ece({page:e,hasNodes:t=!1}){const{t:n}=Fr(),[r,s]=m.useState(!1),[o,a]=m.useState([]),l=m.useRef(null),c=m.useMemo(()=>e==="projects"?Xle(n):t?Qle(n):Zle(n),[e,t,n]);return m.useEffect(()=>{const u=localStorage.getItem(qp),d=u?JSON.parse(u):{};if(d.completed||d[e]){s(!1),a([]);return}localStorage.setItem(qp,JSON.stringify({...d,[e]:!0})),a(c),s(!0)},[e,t,c]),m.useEffect(()=>{if(!r)return;const u=d=>{var y;const f=d.target.closest("button");if(!f||!f.closest(".react-joyride__tooltip"))return;const h=(y=f.textContent)==null?void 0:y.trim();if(h===n("onboarding:done")||h===n("onboarding:startCreate")||h===n("onboarding:skip")){const k=localStorage.getItem(qp)||"{}",b=JSON.parse(k);h===n("onboarding:skip")?(b.projects=!0,b.flow=!0,b.completed=!0):b[e]=!0,localStorage.setItem(qp,JSON.stringify(b)),a([]),s(!1),e==="projects"&&(h===n("onboarding:done")||h===n("onboarding:startCreate"))&&(localStorage.setItem("af:newPipelineGuide","true"),setTimeout(()=>{const g=document.querySelector(".af-create-btn");g&&g.click()},500))}};return document.addEventListener("click",u,!0),()=>document.removeEventListener("click",u,!0)},[r,e,n]),!r||o.length===0?null:i.jsx(Jle,{ref:l,steps:o,run:r,continuous:!0,showSkipButton:!0,showProgress:o.length>1,styles:{options:{primaryColor:"#7c4dff",textColor:"#ffffff",backgroundColor:"#1a1a1a",arrowColor:"#1a1a1a",overlayColor:"rgba(0, 0, 0, 0.4)",zIndex:1e4},tooltip:{borderRadius:"1.5rem",padding:"1.5rem"},buttonNext:{borderRadius:"9999px",padding:"0.625rem 1.5rem"},buttonSkip:{borderRadius:"9999px",color:"#9ecaff"},buttonClose:{display:"none"}},locale:{back:n("onboarding:back"),next:n("onboarding:next"),skip:n("onboarding:skip"),last:n(e==="projects"?"onboarding:startCreate":"onboarding:done")},floaterProps:{disableAnimation:!0},scrollToFirstStep:!0})}const tce="agentflow:recent-runs:v1",nce="agentflow:recent-runs:poller",rce=3e3,sce=8e3,ice=2e3,G_=5e3,oce=16e3,J_=[1e4,3e4,6e4];function ace(e){return J_[Math.min(Math.max(e-1,0),J_.length-1)]}function lce(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function cce(e){if(!e)return"暂无成功记录";try{return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch{return"暂无成功记录"}}function uce(){const{navigate:e,path:t}=si(),[n,r]=m.useState([]),[s,o]=m.useState(!1),[a,l]=m.useState(1),[c,u]=m.useState({status:"idle",failureCount:0,lastSuccessAt:0,message:""}),d=m.useRef(()=>{});m.useEffect(()=>{let N=!1,j=!1,C=!1,P=null,I=0,z=0,$=0,L=0,F=null,O=0,M=0;const K=lce(),H=new Map,D=typeof BroadcastChannel=="function"?new BroadcastChannel(tce):null,T=Ce=>{try{D==null||D.postMessage({...Ce,tabId:K,sentAt:Date.now()})}catch{}},W=()=>{const Ce=Date.now()-oce;for(const[_e,Be]of H)Be<Ce&&H.delete(_e);l(1+H.size)},E=(Ce="presence")=>{T({type:Ce,visible:!document.hidden})},Q=Ce=>{if(!N&&(Array.isArray(Ce.runs)&&r(Ce.runs),Ce.syncHealth&&typeof Ce.syncHealth=="object")){const _e=Ce.syncHealth;O=Number(_e.failureCount)||0,M=Number(_e.lastSuccessAt)||0,u(_e)}},V=Ce=>{Q(Ce),T({type:"state",...Ce})},B=()=>{I&&(window.clearTimeout(I),I=0)},se=Ce=>{B(),!(N||!j||document.hidden)&&(I=window.setTimeout(()=>{I=0,ue()},Math.max(0,Ce)))},ue=async()=>{if(N||!j||document.hidden||F)return;const Ce=new AbortController;F=Ce;let _e=!1;const Be=window.setTimeout(()=>{_e=!0,Ce.abort()},sce);try{const ot=await fetch("/api/pipeline-recent-runs",{signal:Ce.signal});if(!ot.ok)throw new Error(`HTTP ${ot.status}`);const yt=await ot.json();if(N||!j||document.hidden)return;O=0,M=Date.now();const Te=Array.isArray(yt.runs)?yt.runs:[];V({runs:Te.filter(st=>st&&st.status==="running"),syncHealth:{status:"ok",failureCount:0,lastSuccessAt:M,message:""}}),se(rce)}catch(ot){const yt=Ce.signal.aborted&&!_e;if(N||!j||document.hidden||yt)return;O+=1,V({syncHealth:{status:"delayed",failureCount:O,lastSuccessAt:M,message:_e?"运行状态同步超过 8 秒未响应":`运行状态同步失败:${String((ot==null?void 0:ot.message)||ot)}`}}),se(ace(O))}finally{window.clearTimeout(Be),F===Ce&&(F=null)}},G=()=>{B(),F&&(F.abort(),F=null)},ee=()=>{if(G(),P){const Ce=P;P=null,Ce()}j=!1},te=(Ce=ice)=>{z&&window.clearTimeout(z),!(N||document.hidden||j||C)&&(z=window.setTimeout(()=>{z=0,Z()},Ce))},ne=()=>{N||document.hidden||j||(j=!0,se(0))},Z=async()=>{var Ce;if(!(N||document.hidden||j||C)){if(!((Ce=navigator.locks)!=null&&Ce.request)){ne();return}C=!0;try{await navigator.locks.request(nce,{mode:"exclusive",ifAvailable:!0},async _e=>{if(C=!1,!_e||N||document.hidden){te();return}j=!0,se(0),await new Promise(Be=>{P=Be}),P=null,j=!1})}catch{C=!1}finally{te()}}},ce=()=>{if(!N){if(j){O=0,se(0);return}T({type:"retry"}),te(0)}};d.current=ce,D&&(D.onmessage=Ce=>{const _e=Ce.data;if(!(!_e||_e.tabId===K)){if(_e.type==="hello"||_e.type==="presence"){H.set(_e.tabId,Date.now()),W(),_e.type==="hello"&&E();return}if(_e.type==="bye"){H.delete(_e.tabId),W(),te(0);return}if(_e.type==="state"){H.set(_e.tabId,Date.now()),W(),Q(_e);return}_e.type==="retry"&&j&&(O=0,se(0))}});const de=()=>{E(),document.hidden?ee():te(0)},me=()=>{E("bye"),ee()},$e=()=>{E("hello"),te(0)};return document.addEventListener("visibilitychange",de),window.addEventListener("pagehide",me),window.addEventListener("pageshow",$e),E("hello"),$=window.setInterval(E,G_),L=window.setInterval(W,G_),te(0),()=>{N=!0,d.current=()=>{},E("bye"),ee(),z&&window.clearTimeout(z),$&&window.clearInterval($),L&&window.clearInterval(L),document.removeEventListener("visibilitychange",de),window.removeEventListener("pagehide",me),window.removeEventListener("pageshow",$e),D==null||D.close()}},[]);const f=N=>{const j=new URLSearchParams({flowId:N.flowId,flowSource:N.flowSource||"workspace"});e(`/flow?${j.toString()}`),o(!1)},p=t==="/flow"?new URLSearchParams(window.location.search):null,h=(p==null?void 0:p.get("flowId"))||"",y=c.status==="delayed",k=a>1,b=n.length===1;if(n.length===0&&!y&&!k)return null;const g=y?"状态同步延迟":n.length>0?b?n[0].flowId:`${n.length} running`:`${a} 个标签页 · 同步已合并`,v=y?`${c.message}${k?`;检测到 ${a} 个 AgentFlow 标签页`:""}`:k?`已合并 ${a} 个 AgentFlow 标签页的运行状态同步`:b?`${n[0].flowId} 运行中,点击跳转`:`${n.length} 个 pipeline 运行中`,w=()=>{if(!y&&!k&&b){f(n[0]);return}o(N=>!N)};return i.jsxs("div",{className:"af-run-indicator"+(y?" af-run-indicator--delayed":"")+(k?" af-run-indicator--coordinated":""),role:"status","aria-live":"polite",children:[s&&i.jsxs("div",{className:"af-run-indicator__menu",onMouseLeave:()=>o(!1),children:[(y||k)&&i.jsxs("div",{className:"af-run-indicator__sync",children:[i.jsx("div",{className:"af-run-indicator__sync-title",children:y?"运行状态同步延迟":"多标签页同步已合并"}),i.jsx("div",{className:"af-run-indicator__sync-copy",children:k?`检测到 ${a} 个 AgentFlow 标签页。当前只由一个可见标签页请求运行状态,后台页面不会重复建立连接。`:"运行状态接口暂未及时返回,已停止重复请求并自动降低刷新频率。"}),y&&i.jsxs("div",{className:"af-run-indicator__sync-meta",children:["最近成功:",cce(c.lastSuccessAt)]}),y&&i.jsx("button",{type:"button",className:"af-run-indicator__retry",onClick:N=>{N.stopPropagation(),d.current()},children:"立即重试"})]}),n.map(N=>i.jsxs("button",{type:"button",className:"af-run-indicator__item"+(N.flowId===h?" af-run-indicator__item--current":""),onClick:()=>f(N),title:`${N.flowId} · ${N.runId}`,children:[i.jsx("span",{className:"af-run-indicator__dot"}),i.jsx("span",{className:"af-run-indicator__flow",children:N.flowId}),i.jsx("span",{className:"af-run-indicator__run",children:N.runId.slice(0,12)})]},`${N.flowId}:${N.runId}`))]}),i.jsxs("button",{type:"button",className:"af-run-indicator__btn",onClick:w,title:v,children:[i.jsx("span",{className:"af-run-indicator__pulse"}),i.jsx("span",{className:"af-run-indicator__label",children:g})]})]})}const Sw="0.1.115",dce=6e4,fce=30*6e4;function $c(e){return String(e||"").trim().replace(/^v/i,"")}function pce(e,t){const n=$c(e),r=$c(t);return!!(n&&r&&n!==r)}function hce(e,t){return`agentflow.app-version.snooze:${$c(e)}:${$c(t)}`}function mce(e){if(!e)return 0;try{const t=Number(window.sessionStorage.getItem(e));return Number.isFinite(t)?t:0}catch{return 0}}function gce(){const[e,t]=m.useState(null);if(m.useEffect(()=>{let r=!1,s=!1;const o=async()=>{if(!(s||document.visibilityState==="hidden")){s=!0;try{const c=await fetch("/api/app-version",{cache:"no-store"}),u=await c.json().catch(()=>({}));if(!c.ok||r)return;const d=$c(u.version);if(!pce(Sw,d)){t(null);return}const f=hce(Sw,d);if(mce(f)>Date.now())return;t({clientVersion:$c(Sw),serverVersion:d,startedAt:String(u.startedAt||""),snoozeKey:f})}catch{}finally{s=!1}}},a=()=>{document.visibilityState==="visible"&&o()},l=window.setInterval(()=>void o(),dce);return document.addEventListener("visibilitychange",a),window.addEventListener("focus",o),o(),()=>{r=!0,window.clearInterval(l),document.removeEventListener("visibilitychange",a),window.removeEventListener("focus",o)}},[]),!e)return null;const n=()=>{try{window.sessionStorage.setItem(e.snoozeKey,String(Date.now()+fce))}catch{}t(null)};return i.jsxs("aside",{className:"af-app-version-notice",role:"status","aria-live":"polite",children:[i.jsx("span",{className:"material-symbols-outlined af-app-version-notice__icon","aria-hidden":!0,children:"system_update"}),i.jsxs("div",{className:"af-app-version-notice__copy",children:[i.jsx("strong",{children:"AgentFlow 已更新"}),i.jsxs("span",{children:["v",e.clientVersion," → v",e.serverVersion,",刷新后生效"]})]}),i.jsxs("div",{className:"af-app-version-notice__actions",children:[i.jsx("button",{type:"button",className:"af-app-version-notice__later",onClick:n,children:"稍后"}),i.jsx("button",{type:"button",className:"af-app-version-notice__refresh",onClick:()=>window.location.reload(),children:"刷新更新"})]})]})}function a$(e){return e==="/likee-context"||e==="/likee_context"}function yce(){const{navigate:e}=si();return m.useEffect(()=>{const t=new URLSearchParams(window.location.search),n=new URLSearchParams,r=t.get("flowId")||"",s=t.get("flowSource")||"";r&&n.set("flowId",r),s&&n.set("flowSource",s),t.get("flowArchived")&&n.set("archived",t.get("flowArchived")),e(`/workspace${n.toString()?`?${n.toString()}`:""}`)},[e]),null}class wce extends m.Component{constructor(t){super(t),this.state={error:null,info:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,n){console.error("[AgentFlow UI render error]",t,n),this.setState({error:t,info:n})}render(){var r,s,o;if(!this.state.error)return this.props.children;const t=String(((r=this.state.error)==null?void 0:r.stack)||((s=this.state.error)==null?void 0:s.message)||this.state.error),n=String(((o=this.state.info)==null?void 0:o.componentStack)||"");return i.jsx("div",{className:"af-auth-screen",children:i.jsxs("div",{className:"af-auth-panel af-ui-error-panel",children:[i.jsxs("div",{className:"af-auth-brand",children:[i.jsx("span",{className:"material-symbols-outlined",children:"error"}),i.jsxs("div",{children:[i.jsx("h1",{children:"AgentFlow UI Error"}),i.jsx("p",{children:"页面渲染失败,下面是调试堆栈。"})]})]}),i.jsx("pre",{children:t}),n?i.jsx("pre",{children:n}):null]})})}}function xce({authUser:e}){const{path:t}=si();return t==="/projects"||t==="/"?i.jsx(Pl,{authUser:e}):t==="/nodes"?i.jsx(Pl,{authUser:e,resourceKind:"nodes"}):t==="/my-nodes"?i.jsx(Pl,{authUser:e,resourceKind:"my-nodes"}):t==="/my-flows"?i.jsx(Pl,{authUser:e,resourceKind:"my-flows"}):t==="/skills"?i.jsx(Pl,{authUser:e,resourceKind:"skills"}):t==="/workspaces"?i.jsx(Die,{authUser:e}):t==="/mcps"?i.jsx(Cie,{}):t==="/schedules"?i.jsx(Pie,{}):t==="/node-studio"?i.jsx(Rie,{}):t==="/flow"?i.jsx(yce,{}):t==="/workspace"?i.jsx(DJ,{}):t.startsWith("/display")?i.jsx(wM,{}):t==="/settings"?i.jsx(die,{authUser:e}):t==="/admin/usage"?i.jsx(xie,{authUser:e}):t==="/feedback"?i.jsx(kie,{authUser:e}):a$(t)?i.jsx(IM,{}):i.jsx(Pl,{})}function bce({children:e}){const[t,n]=m.useState({loading:!0,authenticated:!1,user:null,setupRequired:!1}),[r,s]=m.useState(""),[o,a]=m.useState(""),[l,c]=m.useState(!1),[u,d]=m.useState(""),f=async()=>{try{const y=await(await fetch("/api/auth/me")).json().catch(()=>({}));n({loading:!1,authenticated:!!y.authenticated,user:y.user||null,setupRequired:!!y.setupRequired}),d(y.error?String(y.error):"")}catch(h){n({loading:!1,authenticated:!1,user:null,setupRequired:!1}),d(String(h.message||h))}};m.useEffect(()=>{f()},[]);const p=async h=>{h.preventDefault(),c(!0),d("");try{const y=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:r,password:o})}),k=await y.json().catch(()=>({}));if(!y.ok)throw new Error(k.error||"登录失败");s(""),a(""),window.location.replace(window.location.href);return}catch(y){d(String(y.message||y))}finally{c(!1)}};return t.loading?i.jsx("div",{className:"af-auth-screen",children:i.jsx("div",{className:"af-auth-panel",children:"Loading..."})}):t.authenticated?e({user:t.user,onLogout:async()=>{await fetch("/api/auth/logout",{method:"POST"}).catch(()=>{}),n({loading:!1,authenticated:!1,user:null,setupRequired:!1})}}):i.jsx("div",{className:"af-auth-screen",children:i.jsxs("form",{className:"af-auth-panel",onSubmit:p,autoComplete:"on",children:[i.jsxs("div",{className:"af-auth-brand",children:[i.jsx("span",{className:"material-symbols-outlined",children:"account_circle"}),i.jsxs("div",{children:[i.jsx("h1",{children:"AgentFlow"}),i.jsx("p",{children:t.setupRequired?"初始化管理员账号":"登录或创建用户"})]})]}),i.jsxs("label",{className:"af-auth-field",children:[i.jsx("span",{children:"用户名"}),i.jsx("input",{id:"agentflow-auth-username",name:"username",type:"text",value:r,onChange:h=>s(h.target.value),autoComplete:"username",autoFocus:!0})]}),i.jsxs("label",{className:"af-auth-field",children:[i.jsx("span",{children:"密码"}),i.jsx("input",{id:"agentflow-auth-password",name:"password",type:"password",value:o,onChange:h=>a(h.target.value),autoComplete:t.setupRequired?"new-password":"current-password"})]}),u?i.jsx("p",{className:"af-auth-error",children:u}):null,i.jsx("button",{className:"af-auth-submit",type:"submit",disabled:l||!r.trim()||o.length<4,children:l?"处理中...":t.setupRequired?"创建并登录":"登录"})]})})}function kce({authUser:e,onLogout:t}){const{path:n}=si(),r=n==="/flow"||n==="/workspace";return i.jsxs("div",{className:"af-app",children:[n!=="/settings"?i.jsx(ece,{page:r?"flow":"projects"}):null,r?null:i.jsx(PD,{authUser:e,onLogout:t}),i.jsx("div",{className:r?"af-main af-main--pipeline":"af-main",children:i.jsx(xce,{authUser:e})}),i.jsx(uce,{})]})}function vce(){return i.jsx(wce,{children:i.jsxs(dD,{children:[i.jsx(Sce,{}),i.jsx(gce,{})]})})}function Sce(){const{path:e}=si();return e.startsWith("/display")?i.jsx(wM,{}):a$(e)?i.jsx(IM,{}):i.jsx(bce,{children:({user:t,onLogout:n})=>i.jsx(kce,{authUser:t,onLogout:n})})}window.addEventListener("error",e=>{console.error("[AgentFlow UI global error]",e.error||e.message,{filename:e.filename,lineno:e.lineno,colno:e.colno})});window.addEventListener("unhandledrejection",e=>{console.error("[AgentFlow UI unhandled rejection]",e.reason)});const X_=document.querySelector('link[rel="icon"]');X_&&(X_.href=pP);Nw.createRoot(document.getElementById("root")).render(i.jsx(ft.StrictMode,{children:i.jsx(vce,{})}));