@digitalsee-ai/rcs 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rcs.umd.js CHANGED
@@ -71,7 +71,7 @@ The error may be correlated with this previous error:
71
71
  user-select: none;
72
72
  `,s.textContent=this.text,s}ignoreEvent(){return!0}}const r=new Au({regexp:/{{(.*?)}}/g,decoration:o=>De.replace({widget:new n(o[1])})});return bt.fromClass(class{constructor(o){it(this,"placeholders");this.placeholders=r.createDeco(o)}update(o){this.placeholders=r.updateDeco(o,this.placeholders)}},{decorations:o=>o.placeholders,provide:o=>ve.atomicRanges.of(i=>{var s;return((s=i.plugin(o))==null?void 0:s.placeholders)||De.none})})},e7=({completions:t,keywords:e,placeholderThemes:n,mode:r,functions:o,keywordsColor:i,keywordsClassName:s,hintPaths:a})=>[e!=null&&e.length?Qj(e,i,s):null,Wj,Zj(n,r),ve.lineWrapping,ND({override:[Uj(t),a!=null&&a.length?Xj(a):null].filter(l=>!!l)}),Kj,Yj(o)].filter(l=>!!l),t7=({completions:t,onValueChange:e,keywords:n,handleFocus:r,placeholderThemes:o,mode:i,functions:s,height:a,width:l,keywordsColor:c,keywordsClassName:u,defaultValue:d,hintPaths:h,extensions:p,disabled:m,id:v},w)=>{const y=b.useRef(null),g=b.useCallback((S,E)=>{var N;const{view:T}=y.current;if(!T)return;const{state:O}=T;if(!O)return;const[F]=((N=O==null?void 0:O.selection)==null?void 0:N.ranges)||[];T.focus(),T.dispatch({changes:{from:F.from,to:F.to,insert:S},selection:{anchor:F.from+S.length}})},[]),C=b.useCallback(()=>{const{view:S}=y.current;S.dispatch({changes:{from:0,to:S.state.doc.length,insert:""},selection:{anchor:0}}),S.focus()},[]),D=b.useCallback(S=>{const{view:E}=y.current;E.dispatch({changes:{from:0,to:E.state.doc.length,insert:S},selection:{anchor:S.length}}),E.focus()},[]);b.useImperativeHandle(w,()=>({insertText:g,clearText:C,setText:D,originEditorRef:y}),[g,C,D]);const k=b.useMemo(()=>[...e7({completions:t,keywords:n,placeholderThemes:o,mode:i,functions:s,keywordsColor:c,keywordsClassName:u,hintPaths:h}),...p||[]],[t,n,o,i,s,c,u,h,p]),A=b.useCallback(S=>{e&&e(S)},[e]);return f.jsx(Rm,{id:v,readOnly:m,height:a,width:l,onFocus:r,extensions:k,theme:fE,onChange:A,value:d,ref:y})},n7=b.forwardRef(t7);function r7(t){const e=b.useMemo(()=>or(),[]),n=b.useRef(null),{event$:r}=b.useContext(Vr),o=Ct();return r.useSubscription(i=>{var s,a;if(i.type==="insert"&&i.currentInputId===e){const l=i.expression;(s=n==null?void 0:n.current)!=null&&s.insertText&&((a=n==null?void 0:n.current)==null||a.insertText(l,!1))}}),f.jsx(n7,{handleFocus:()=>{o&&(r.emit({type:"visible",visible:!0}),r.emit({type:"setCurrentInputId",currentInputId:e}))},id:e,ref:n,mode:"name",onValueChange:i=>{var s,a;(s=t.onChange)==null||s.call(t,i),(a=t.onValueChange)==null||a.call(t,i)},defaultValue:t.value,placeholderThemes:jj,completions:[],functions:[],height:"200px",width:"100%"})}const o7=/{{(.*?)}}/,i7=(t,e)=>t?t.split(e).map((n,r)=>r%2?{type:"tag",value:n,children:[{text:n}]}:{text:n??""}):[{text:""}],hd=(t,e)=>((t==null?void 0:t.split(`
73
73
  `))??[""]).map(r=>({type:"paragraph",className:"textbox",children:i7(String(r??""),e)})),s7=t=>{const e=se.useReactFlow();return b.useMemo(()=>{const n=t.split("."),r=n[0],o=`{{${t}}}`;if(r==="global")return{exists:!0,type:"global",tooltip:n.slice(1).join("."),fullPath:o,backgroundColor:"#ECFDF5",borderColor:"#10B981",textColor:"#065F46",iconColor:"#10B981"};if(ut.includes(["sys_tenant_id","response"],r))return{exists:!0,type:"builtin",tooltip:sl.getBuiltinVariableTips(r),fullPath:o,backgroundColor:"#F3E8FF",borderColor:"#A855F7",textColor:"#6B21A8",iconColor:"#A855F7"};const i=r==null?void 0:r.slice(1),a=e.getNodes().find(h=>h.id===i);if(!a)return{exists:!1,type:"node",tooltip:R("link.flow.cannot_find_variable_output_node"),fullPath:o,backgroundColor:"#FEF2F2",borderColor:"#EF4444",textColor:"#991B1B",iconColor:"#EF4444"};const l=a.data??{},c=String(l.label||l.name||i),u=l.note;return{exists:!0,type:"node",icon:typeof l.icon=="string"?l.icon:sl.getNodeIcon(i)??void 0,tooltip:c+(u?` (${u})`:""),fullPath:o,backgroundColor:"#EBF5FF",borderColor:"#3B82F6",textColor:"#1E40AF",iconColor:"#3B82F6"}},[t,e])},a7=(t,e)=>{const n=e.exec(t);if(!n)return null;const o=t.slice(-2)==="}}";return{tagContent:n[1].trimStart(),tagLength:n[0].length,tagStartIndex:n.index,isTagLastItem:o}},dA=(t,e,n)=>{const r=[{type:"tag",value:e,children:[{text:e}]},{text:""}];le.insertNodes(t,r,n)},l7=(t,e)=>[...t.slice(0,-1),t[t.length-1]+e],c7=({attributes:t,element:e,children:n})=>f.jsx("p",{...t,children:n}),u7=({attributes:t,element:e,children:n,removeTagButton:r,transformInputText:o,transformInputElement:i})=>{const s=jL(),a=HL(),l=s7((e==null?void 0:e.value)||""),c=()=>l.type==="global"?f.jsx(Q.GlobalOutlined,{className:"tag-icon",style:{color:l.iconColor}}):l.type==="builtin"?f.jsx(Q.SettingOutlined,{className:"tag-icon",style:{color:l.iconColor}}):l.icon?f.jsx("img",{src:l.icon,alt:"",className:"tag-icon"}):f.jsx("span",{className:"tag-icon default-icon",style:{backgroundColor:l.exists?"#EBF5FF":"#FEF2F2",color:l.iconColor},children:"N"});return f.jsx(x.Tooltip,{defaultOpen:!l.exists,overlayClassName:"variable-tag-tooltip",placement:"top",getPopupContainer:()=>document.querySelector(".nodes-config-content")??document.body,title:f.jsxs("div",{className:"tag-tooltip-content",children:[f.jsx("div",{className:"tag-tooltip-header",children:f.jsxs("span",{className:"tag-tooltip-type",children:[l.type==="node"&&"节点变量",l.type==="global"&&"全局变量",l.type==="builtin"&&"系统变量"]})}),f.jsx("div",{className:"tag-tooltip-name",children:l.tooltip}),f.jsx("div",{className:"tag-tooltip-path",children:l.fullPath}),l.value&&f.jsxs("div",{className:"tag-tooltip-value",children:[f.jsx("span",{className:"tag-tooltip-value-label",children:"当前值:"}),f.jsx("span",{className:"tag-tooltip-value-text",children:l.value})]})]}),arrow:{pointAtCenter:!0},children:f.jsxs("span",{...t,className:`tag-wrapper ${l.exists?"":"tag-invalid"}`,style:{boxShadow:s&&a?`0 0 0 2px ${l.borderColor}40`:"none",borderColor:l.borderColor,backgroundColor:l.backgroundColor},children:[c(),f.jsxs("span",{className:`tag-text ${r?"tag-text-right-padding":""}`,style:{color:l.textColor},children:[n,o?f.jsx("span",{children:o(e==null?void 0:e.value)}):i?i(e==null?void 0:e.value):f.jsx("span",{children:e==null?void 0:e.value})]})]})})},d7=({attributes:t,element:e,children:n})=>f.jsx("p",{...t,children:n}),f7=(t,e)=>{const{isInline:n,isVoid:r,normalizeNode:o}=t;return t.isInline=i=>i.type==="tag"?!0:n(i),t.isVoid=i=>i.type==="tag"?!0:r(i),t.normalizeNode=([i,s])=>{if(!(i!=null&&i.text)){o([i,s]);return}const a=ge.string(i),l=a7(a,e);if(l){const{tagContent:c,tagLength:u,tagStartIndex:d,isTagLastItem:h}=l,p={path:s,offset:d};le.delete(t,{at:p,distance:u,unit:"character"}),dA(t,c,{at:p}),h&&le.select(t,{path:l7(s,1),offset:0})}o([i,s])},t},h7=t=>{var n;const e=(n=t==null?void 0:t.children)==null?void 0:n.map(r=>r.type==="tag"?`{{${r.value}}}`:r.text);return Array.isArray(e)?e.join(""):""},p7=t=>(t??[]).map(n=>h7(n)).join(`
74
- `),m7=b.forwardRef(({onValueChange:t=u=>{},removeTagButton:e=!1,initValue:n,onFocus:r,addImageElement:o,transformInputText:i,transformInputElement:s,textAreaMode:a,capturePattern:l=o7},c)=>{const u=b.useRef(null),d=b.useMemo(()=>f7(XC(cb()),l),[]),[h,p]=b.useState(hd(n,l));let m=n;const v=b.useCallback(({element:D,children:k,attributes:A})=>{switch(D.type){case"paragraph":return f.jsx(d7,{attributes:A,element:D,children:k});case"tag":return f.jsx(u7,{attributes:A,element:D,removeTagButton:e,addImageElement:o,transformInputText:i,transformInputElement:s,children:k});default:return f.jsx(c7,{attributes:A,element:D,children:k})}},[]);b.useEffect(()=>{p(hd(n,l))},[n]);const w=b.useCallback(D=>{u.current=d.selection;const k=p7(D);k!==m&&(m=D,p(D),t(k))},[]),y=D=>{le.delete(d,{at:[0]});const k=hd(D,l);d.children=hd("",l),le.insertNodes(d,k,{at:[0]})},g=D=>{dA(d,D,{at:u.current.focus}),le.move(d,{distance:h.length-1})};b.useImperativeHandle(c,()=>({insertTag:g,setValueByParent:y}));const C=Ct();return f.jsx(YC,{editor:d,initialValue:h,onChange:w,children:f.jsx(UC,{style:a?{minHeight:60,maxHeight:200}:{maxHeight:150},onFocus:r,value:h,readOnly:!C,spellCheck:!1,className:"ce-tag_input",renderElement:v})})}),fA=t=>f.jsx("div",{style:{display:t.show?"block":"none",height:"100%",width:"100%",...t.style??{}},children:t.children}),ir=t=>{const e=b.useMemo(()=>or(),[]),{event$:n}=b.useContext(Vr),r=b.useRef(null),[o,i]=b.useState(""),s=dt.useReactive({innerValueType:"",radioType:"",openEditorNumber:0});b.useEffect(()=>{s.radioType=t.valueType},[t.valueType,s]),n.useSubscription(u=>{var d,h,p;if(u.type==="insert"&&u.currentInputId===e){(h=r==null?void 0:(d=r.current).insertTag)==null||h.call(d,u.expression.slice(2,-2));const m=(o??"")+(t.valueType==="FIX_VALUE"?u.expression.slice(2,-2):u.expression);i(m),(p=t.onChange)==null||p.call(t,m)}});const a=b.useMemo(()=>!t.borrow&&["JS_EXP","ADAPTOR"].includes(t.valueType),[t.borrow,t.valueType]);b.useEffect(()=>{i(t.value)},[t.value]);const l=u=>{var d;(d=t.onChange)==null||d.call(t,u)},c=u=>{var d;i(u),(d=t.onChange)==null||d.call(t,u)};return f.jsxs(Vj,{id:e,canEditInEditor:!t.disableIDE,openEditorNumber:s.openEditorNumber,nodeId:t.nodeId,value:t.value,onFinish:u=>{r.current.setValueByParent(u)},children:[a&&f.jsx("div",{style:{textAlign:"right",position:"absolute",top:-34,right:2},children:f.jsxs(x.Radio.Group,{value:s.radioType,onChange:u=>{s.radioType=u.target.value,s.radioType==="ADAPTOR"&&r.current.setValueByParent(o)},size:"small",style:{marginTop:16},children:[f.jsx(x.Radio.Button,{style:{height:18,fontSize:10,display:"inline-flex",alignItems:"center"},value:"ADAPTOR",children:f.jsx(Se.FormattedMessage,{id:"link.flow.string"})}),f.jsx(x.Radio.Button,{style:{height:18,fontSize:10,display:"inline-flex",alignItems:"center"},value:"JS_EXP",children:f.jsx(Se.FormattedMessage,{id:"link.flow.script"})})]})}),f.jsx(fA,{show:s.radioType==="ADAPTOR"||!a&&s.radioType!=="PLAIN_CODE",children:f.jsx(m7,{ref:r,disabled:t.disabled,textAreaMode:t.textAreaMode,initValue:t.value,onFocus:()=>{["JS_EXP","FIX_VALUE","ADAPTOR","PLAIN_TEXT","PLAIN_CODE"].includes(t.valueType)&&(n.emit({type:"visible",visible:!0}),n.emit({type:"setCurrentInputId",currentInputId:e}))},removeTagButton:!1,onValueChange:l,addImageElement:u=>{const h=(u==null?void 0:u.split(".")[0]).slice(1),p=sl.getConfig().icons.get(h);return p?f.jsx("img",{src:p,alt:h,onError:m=>{m.target.src="/uc/images/default_connector.png"}}):f.jsx(Q.ThunderboltOutlined,{})},transformInputText:u=>ut.includes(["sys_tenant_id","response"],u)?u:u.split(".").slice(1).join("."),transformInputElement:u=>f.jsx("span",{style:{color:"blue"},children:u})})}),f.jsxs(fA,{show:(s.radioType==="JS_EXP"||s.radioType==="PLAIN_CODE")&&(s.radioType==="PLAIN_CODE"||a),style:{position:"relative"},children:[f.jsx("div",{children:f.jsx(r7,{...t,onValueChange:c})}),f.jsx("span",{onClick:()=>{s.openEditorNumber++},style:{position:"absolute",right:16,top:4,color:"white",fontSize:16,cursor:"pointer"},children:f.jsx(Q.FullscreenOutlined,{})})]})]})},g7=({value:t=[],onChange:e,valueType:n})=>{const r=u=>{let d=[...o.items];d=d.filter(h=>h.id!==u),e==null||e(d)},o=dt.useReactive({items:[]}),i=u=>{const d=u.which||u.keyCode;(d===37||d===229)&&u.preventDefault()};b.useEffect(()=>{const u=Array.isArray(t)?t:[];o.items=u.map(d=>({...d,id:d.id??or()}))},[t]);const s=()=>{e==null||e([...o.items,{key:"",value:"",id:or()}])},a=(u,d)=>{e==null||e(o.items.map(h=>h.id===u?{...h,key:d}:h))},l=(u,d)=>{e==null||e(o.items.map(h=>h.id===u?{...h,value:d}:h))},c=Ct();return f.jsxs("div",{children:[o.items.length?o.items.map((u,d)=>f.jsxs(x.Space,{size:"small",style:{display:"flex",marginBottom:8,width:"100%"},align:"center",children:[f.jsx(x.Input,{defaultValue:u.key,onKeyDown:i,onChange:h=>{var p;a(u.id,(p=h.target.value)==null?void 0:p.replace(/'/g,""))},placeholder:"Key"}),f.jsx("span",{style:{display:"inline-block",transform:"translateY(2px)",width:300},children:f.jsx(ir,{borrow:!0,disableIDE:!0,placeholder:"Value",style:{width:300},value:u.value,onChange:h=>l(u.id,h),valueType:n,nodeId:""})}),c&&f.jsx(Q.DeleteOutlined,{onClick:()=>{r(u.id)}})]},u.id)):null,f.jsxs(x.Button,{type:"dashed",onClick:s,block:!0,children:[f.jsx(Q.PlusOutlined,{})," ",f.jsx(Se.FormattedMessage,{id:"app.common.word.add-field"})]})]})},w7=t=>null,v7=t=>f.jsx(x.TimePicker,{style:{width:"100%"},use12Hours:!1,format:"HH:mm",value:t.value?Tt(t.value,"HH:mm"):null,onChange:e=>{const n=Tt(e).format("HH:mm:00");t.onChange&&(t==null||t.onChange(n))}}),{Text:y7}=x.Typography,hA=t=>f.jsx("div",{style:{padding:6,paddingRight:0,border:"1px solid #b0b5cb",borderRadius:4},children:f.jsx(x.Tooltip,{title:t.value,color:"cyan",placement:"topLeft",styles:{body:{width:500}},children:f.jsx(y7,{style:{color:"#b0b5cb"},ellipsis:!0,copyable:{text:t.value},children:t.value})})}),b7=({value:t=[],onChange:e,...n})=>{const[r,o]=b.useState([]);b.useEffect(()=>{const h=Array.isArray(t)?t:[];o(h.map(p=>({...p,id:p.id??or()})))},[t]);const i=Ct(),s=h=>{const p=r.filter(m=>m.id!==h);o(p),e==null||e(p)},a=()=>{const h={field:"",dataType:"string",desc:"",required:!1,id:or()},p=[...r,h];o(p),e(p)},l=(h,p)=>{const m=r.map(v=>v.id===h?{...v,field:p}:v);o(m),e(m)},c=(h,p)=>{const m=r.map(v=>v.id===h?{...v,dataType:p}:v);o(m),e(m)},u=(h,p)=>{const m=r.map(v=>v.id===h?{...v,desc:p}:v);o(m),e(m)},d=(h,p)=>{const m=r.map(v=>v.id===h?{...v,required:p}:v);o(m),e(m)};return f.jsxs("div",{children:[r.length?r.map(h=>f.jsxs(x.Space,{size:"small",style:{display:"flex",marginBottom:8,width:"100%"},align:"start",children:[f.jsx(x.Input,{value:h.field,onChange:p=>l(h.id,p.target.value),placeholder:"字段名称",status:"",style:{width:130},disabled:!i}),f.jsx(x.Select,{value:h.dataType,onChange:p=>c(h.id,p),placeholder:"数据类型",style:{width:100},disabled:!i,options:[{label:"字符串",value:"string"},{label:"数字",value:"number"},{label:"日期",value:"date"},{label:"布尔",value:"boolean"}]}),f.jsx(x.Input,{value:h.desc,onChange:p=>u(h.id,p.target.value),placeholder:"字段描述",status:"",style:{width:200},disabled:!i}),f.jsx(x.Select,{value:h.required,onChange:p=>d(h.id,p),placeholder:"是否必填",style:{width:100},disabled:!i,options:[{label:"是",value:!0},{label:"否",value:!1}]}),i&&f.jsx(Q.DeleteOutlined,{onClick:()=>{s(h.id)},style:{cursor:"pointer",color:"#ff4d4f",marginTop:8}})]},h.id)):null,i&&f.jsx(x.Button,{type:"dashed",onClick:a,block:!0,icon:f.jsx(Q.PlusOutlined,{}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-field"})})]})},C7=t=>{const e=b.useMemo(()=>or(),[]),{event$:n}=b.useContext(Vr),[r,o]=b.useState("");n.useSubscription(s=>{var a;if(s.type==="insert"&&s.currentInputId===e){const l=(r??"")+(t.valueType==="FIX_VALUE"?s.expression.slice(2,-2):s.expression);o(l),(a=t.onChange)==null||a.call(t,l)}}),b.useEffect(()=>{o(t.value)},[t.value]);const i=s=>{var a;o(s.target.value),(a=t.onChange)==null||a.call(t,s.target.value)};return f.jsx(x.Input.Password,{id:e,onFocus:()=>{(t.valueType==="JS_EXP"||t.valueType==="FIX_VALUE"||t.valueType==="PLAIN_TEXT"||t.valueType==="PLAIN_CODE")&&(n.emit({type:"visible",visible:!0}),n.emit({type:"setCurrentInputId",currentInputId:e}))},value:r,addonBefore:R("link.flow.cipherText"),onChange:i})},k7=t=>{var o;const e=or(),{multiple:n,...r}=t;return f.jsx(x.Select,{id:e,style:{borderRadius:6},mode:n?"multiple":void 0,...r,getPopupContainer:i=>i.parentNode,children:(o=t==null?void 0:t.options)==null?void 0:o.map(i=>f.jsx(x.Select.Option,{label:i.label,value:i.value,children:i.label},i.value))})},x7=t=>f.jsx(x.TimePicker,{style:{width:"100%"},value:t.value?Tt(t.value,"HH:mm:ss"):null,onChange:e=>{t.onChange&&(t==null||t.onChange(e==null?void 0:e.format("HH:mm:ss")))}}),S7=["sample","test","payload","body"],E7=["测试","样本","sample","test","payload","body"],pA=t=>{var n,r,o;return[ye.JSON,ye.TEXTAREA,ye.FIXED_OBJ].includes(t.page_control)?!0:((o=(r=(n=t.value_type)==null?void 0:n.toLowerCase)==null?void 0:r.call(n))==null?void 0:o.includes("json"))??!1},mA=(t,e)=>{if(!t)return!1;const n=t.toLowerCase();return e.some(r=>n.includes(r))},D7=t=>{if(t==null)return;const e=(t==null?void 0:t.data)!==void 0?t.data:t;if(typeof e=="string")try{const n=JSON.parse(e);return JSON.stringify(n,null,2)}catch{return e}try{return JSON.stringify(e,null,2)}catch{return}},A7=t=>{const{form:e,configList:n=[],disabled:r,...o}=t;Df();const[i,s]=b.useState(!1),[a,l]=b.useState(0),c=b.useRef(void 0),u=lo(),d=b.useMemo(()=>{const m=n.find(v=>pA(v)&&(mA(v.name,S7)||mA(v.display_name,E7)));return m||n.find(v=>pA(v))},[n]),h=b.useCallback(()=>{c.current&&(clearInterval(c.current),c.current=void 0)},[]);b.useEffect(()=>()=>{h()},[h]);const p=b.useCallback(async()=>{if(!u){x.message.warning("缺少连接流ID,无法监听Webhook");return}if(!(d!=null&&d.name)){x.message.warning("未找到测试数据字段,无法填充监听结果");return}if(!i){s(!0),l(10),c.current=setInterval(()=>{l(m=>m<=1?(h(),0):m-1)},1e3);try{const m=await vy(u,{timeout_seconds:10}),v=D7(m);v?(e.setFieldsValue({[d.name]:v}),x.message.success("已捕获Webhook推送数据并填充测试样例")):x.message.info("监听结束,暂无新的推送数据")}catch(m){console.error("监听Webhook失败:",m),x.message.error("监听失败,请稍后重试")}finally{h(),s(!1),l(0)}}},[u,e,i,d==null?void 0:d.name,h]);return f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx("div",{style:{flex:1},children:f.jsx(hA,{...o})}),f.jsx(x.Button,{size:"small",type:"primary",ghost:!0,onClick:p,disabled:r||!(d!=null&&d.name),loading:i,style:{height:32,minWidth:110,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:i?`监听中${a?`(${a}s)`:""}`:"监听"})]})},O7={configFormContainer:"_configFormContainer_1frpl_1"};function _7(t){return YV(t==null?void 0:t.credentials)}const lg=new Map,pd=new Map,md=new Map,gd=new Map,bn="[workflow:schema-render]",T7=1;function cg(t,e){return`${t}@${e??"latest"}`}function gA(t,e,n){var o,i,s;if(!t||!n){console.warn(`${bn} skip preload classic schema cache`,{nodeKey:t,nodeVersion:e,hasSchema:!!n});return}const r=cg(t,e);console.info(`${bn} preload classic schema cache`,{cacheKey:r,nodeKey:t,nodeVersion:e,schemaVersion:n.version,inputFields:((o=n.input_fields)==null?void 0:o.length)??0,outputs:((i=n.outputs)==null?void 0:i.length)??0,credentials:((s=n.credentials)==null?void 0:s.length)??0}),md.set(r,n)}async function N7(t,e){if(!t)return console.warn(`${bn} skip classic ACM schema fetch without nodeKey`,{nodeKey:t,nodeVersion:e,endpoint:"/acm/actions/{nodeKey}/{version}"}),null;const n=e??T7;e==null&&console.warn(`${bn} fallback classic ACM schema version`,{nodeKey:t,nodeVersion:e,fallbackNodeVersion:n,reason:"node data does not include action_ver/nodeVersion after reload",endpoint:"/acm/actions/{nodeKey}/{version}"});const r=cg(t,n);if(md.has(r))return console.info(`${bn} classic schema cache hit`,{cacheKey:r,nodeKey:t,nodeVersion:n}),md.get(r);if(gd.has(r))return console.info(`${bn} classic schema request pending reuse`,{cacheKey:r,nodeKey:t,nodeVersion:n}),gd.get(r);console.info(`${bn} fetch classic schema from ACM`,{cacheKey:r,nodeKey:t,nodeVersion:n,endpoint:"/acm/actions/{nodeKey}/{version}"});const o=Zv(t,n).then(i=>{var s,a,l;return console.info(`${bn} classic schema fetch success`,{cacheKey:r,nodeKey:t,nodeVersion:n,schemaVersion:i.version,inputFields:((s=i.input_fields)==null?void 0:s.length)??0,outputs:((a=i.outputs)==null?void 0:a.length)??0,credentials:((l=i.credentials)==null?void 0:l.length)??0}),md.set(r,i),i}).catch(i=>(console.warn(`${bn} classic schema fetch failed`,{cacheKey:r,nodeKey:t,nodeVersion:n,endpoint:"/acm/actions/{nodeKey}/{version}",err:i}),null)).finally(()=>{gd.delete(r)});return gd.set(r,o),o}async function wd(t,e){if(!t)return console.warn(`${bn} skip schema fetch without nodeKey`,{nodeVersion:e}),null;const n=cg(t,e);if(lg.has(n))return console.info(`${bn} schema cache hit`,{cacheKey:n,nodeKey:t,nodeVersion:e}),lg.get(n);if(pd.has(n))return console.info(`${bn} schema request pending reuse`,{cacheKey:n,nodeKey:t,nodeVersion:e}),pd.get(n);console.info(`${bn} fetch schema from DIP`,{cacheKey:n,nodeKey:t,nodeVersion:e,endpoint:e?"/dip/api/nodes/{nodeKey}/{version}":"/dip/api/nodes/{nodeKey}"});const r=IB(t,e).then(o=>{var i,s,a;return console.info(`${bn} schema fetch success`,{cacheKey:n,nodeKey:t,nodeVersion:e,inputFields:((i=o.input_fields)==null?void 0:i.length)??0,outputs:((s=o.outputs)==null?void 0:s.length)??0,credentials:((a=o.credentials)==null?void 0:a.length)??0}),lg.set(n,o),o}).catch(o=>(console.warn(`${bn} schema fetch failed`,{cacheKey:n,nodeKey:t,nodeVersion:e,endpoint:e?"/dip/api/nodes/{nodeKey}/{version}":"/dip/api/nodes/{nodeKey}",err:o}),null)).finally(()=>{pd.delete(n)});return pd.set(n,r),r}const B7=[ye.TEXT,ye.PASSWORD,ye.SELECT,ye.EXTEND_OBJ,ye.DATE,ye.TIME,ye.DATETIME,ye.TEXTAREA,ye.FIXED_OBJ,ye.JSON],vd="[workflow:schema-render]",F7=/^\{\{([^.{}]+)\.(.+)\}\}$/,I7=t=>{switch(t.page_control){case ye.SELECT:return t.multi_valued?[]:null;case ye.EXTEND_OBJ:return{};case ye.HIDDEN:return"";case ye.TEXT:return"";case ye.PASSWORD:return"";case ye.LABEL:return"";case ye.DATE:return null;case ye.TIME:return null;case ye.DATETIME:return null;case ye.TEXTAREA:return"";case ye.FIXED_OBJ:return{};case ye.MultiRowAIExtractConfig:return[];case ye.JSON:return""}},wA=(t,e,n,r,o)=>{const i=t.display_name,s=()=>{var a,l,c;switch(t.page_control){case ye.SELECT:return f.jsx(k7,{options:XD(t.option_value_objects??t.option_values),multiple:t.multi_valued});case ye.EXTEND_OBJ:return f.jsx(g7,{valueType:t.value_type});case ye.HIDDEN:return f.jsx(w7,{});case ye.TEXT:return f.jsx(ir,{valueType:t.value_type,nodeId:e});case ye.PASSWORD:return f.jsx(C7,{valueType:t.value_type});case ye.LABEL:return(a=r==null?void 0:r.webhookField)!=null&&a.enabled&&t.name==="hookUrl"&&r.webhookField.form?f.jsx(A7,{form:r.webhookField.form,configList:r.webhookField.configList,disabled:r.webhookField.disabled}):f.jsx(hA,{});case ye.DATE:return f.jsx(uj,{});case ye.TIME:return f.jsx(x7,{});case ye.DATETIME:return f.jsx(dj,{});case ye.TEXTAREA:return f.jsx(ir,{valueType:t.value_type,textAreaMode:!0,nodeId:e});case ye.FIXED_OBJ:return f.jsx(x.Input.TextArea,{});case ye.JSON:return f.jsx(ir,{valueType:t.value_type,nodeId:e});case ye.MultiRowAIExtractConfig:return f.jsx(b7,{valueType:t.value_type});case ye.MULTI_SELECT_LIST:return f.jsx(gj,{selectType:"KNOWLEDGE_BASE"});case ye.SYNC_HOUR_MINUTE:return f.jsx(v7,{});case ye.AUTH_TOKEN:return f.jsx(rj,{disabled:(l=r==null?void 0:r.webhookField)==null?void 0:l.disabled});case ye.SECRET_KEY:return f.jsx(ij,{});case ye.SELECT_CLIENT:return f.jsx(lj,{});default:{const u=(c=o==null?void 0:o.form)==null?void 0:c.find(d=>d.name===t.page_control);return u?f.jsx(u.component,{}):null}}};return n&&B7.includes(t.page_control)?f.jsx("div",{children:f.jsx(x.Form.Item,{required:t.required,rules:[{required:t.required,message:t.page_control===ye.SELECT?R("link.flow.please_select")+t.display_name:R("link.flow.please_enter")+t.display_name}],label:i,name:t.name,children:f.jsx(cj,{children:s()})})},t.ui_id):f.jsx(x.Form.Item,{required:t.required,style:t.page_control===ye.HIDDEN?{display:"none"}:{},rules:[{required:t.required,message:t.page_control===ye.SELECT?R("link.flow.please_select")+t.display_name:R("link.flow.please_enter")+t.display_name},{validator(a,l,c){if(t.page_control===ye.MultiRowAIExtractConfig)if(Array.isArray(l)&&t.required){const u=l.some(d=>!d.field||!d.dataType||!d.desc||d.required==null);c(u?"请填写完整配置":void 0)}else c(void 0);else c(void 0)}}],label:i,name:t.name,children:s()},t.ui_id)},M7=t=>(t.child_conditions??[]).map(e=>e.left).filter(e=>!!e),P7=(t,e)=>{if(!t.is_child)return!0;const n=t.child_conditions??[];return n.length?n.some(({left:r,operator:o,right:i})=>{const s=e==null?void 0:e[r];return o==="EQUALS"?s===i:s!==i}):!0},vA=b.forwardRef((t,e)=>{var z,U,X,Y;const{action:n,connector:r,nodeId:o,account_id:i,mcpMode:s}=t,a=Wt(),l=se.useStoreApi(),c=dt.useReactive({proxyId:"0"}),{config_schema:u,proxy_id:d,protocol:h}=n,p=n.action_key||n.nodeKey,m=n.action_ver??n.nodeVersion??((z=n.node_schema)==null?void 0:z.version),v=n.node_schema,w=Array.isArray(u==null?void 0:u.sub_params),y=b.useMemo(()=>w||!p?null:`${p}@${m??"latest"}`,[w,p,m]),g=y?`${o}:${y}`:o,C=n.account_id??i,D=!w&&((U=v==null?void 0:v.input_fields)!=null&&U.length||(X=v==null?void 0:v.credentials)!=null&&X.length)?v:null,[k,A]=b.useState(()=>y&&D?{identity:y,schema:D,loading:!1,finished:!0}:null),S=(k==null?void 0:k.identity)===y?k:null,E=D??(S==null?void 0:S.schema)??null,T=_7(E),O=ld((E==null?void 0:E.credentials)??[]),F=!!(!w&&p&&!E&&((S==null?void 0:S.loading)??!(S!=null&&S.finished)));b.useEffect(()=>{var ee,re;!k||k.identity===y||console.info(`${vd} classic renderer ignore stale next schema state`,{nodeId:o,nodeKey:p,nodeVersion:m,currentIdentity:y,staleIdentity:k.identity,staleLoading:k.loading,staleFinished:k.finished,staleInputFields:((re=(ee=k.schema)==null?void 0:ee.input_fields)==null?void 0:re.length)??0})},[y,k,o,p,m]),b.useEffect(()=>{d&&(c.proxyId=d)},[d]);const[N]=x.Form.useForm(),[I,P]=b.useState(C);b.useEffect(()=>{P(C)},[g,C]);const _=b.useMemo(()=>{var ee;return w?(ee=u.sub_params)==null?void 0:ee.reduce((re,ce)=>{let Ce=ce.value;return ce.page_control===ye.EXTEND_OBJ&&(Ce=VV(Ce)),re[ce.name]=Ce??I7(ce),re},{}):{}},[u==null?void 0:u.sub_params,w]);b.useEffect(()=>{w&&(N.resetFields(),N.setFieldsValue({..._}))},[_,N,w,o]);const B=b.useRef(null),L=b.useRef(null);b.useEffect(()=>{if(!y||!p){A(null);return}if(D){A({identity:y,schema:D,loading:!1,finished:!0});return}let ee=!1;return A({identity:y,schema:null,loading:!0,finished:!1}),console.info(`${vd} classic renderer load next schema`,{nodeId:o,nodeKey:p,nodeVersion:m}),N7(p,m).then(re=>{var ce;ee||(A({identity:y,schema:re,loading:!1,finished:!0}),console.info(`${vd} classic renderer next schema loaded`,{nodeId:o,nodeKey:p,nodeVersion:m,inputFields:((ce=re==null?void 0:re.input_fields)==null?void 0:ce.length)??0}))}).catch(re=>{ee||(A({identity:y,schema:null,loading:!1,finished:!0}),console.error(`${vd} classic renderer next schema load failed`,{nodeId:o,nodeKey:p,nodeVersion:m,err:re}))}),()=>{ee=!0}},[D,y,o,p,m]);const H=b.useMemo(()=>{var ee;return(ee=E==null?void 0:E.input_fields)!=null&&ee.length?il(E.input_fields):null},[E]),W=!!(!w&&(H||T||E)),K=b.useMemo(()=>n.params?n.params:u&&!w?u:{},[n,u,w]),q=b.useMemo(()=>JSON.stringify(K??{}),[K]);b.useEffect(()=>{w||!W||(N.resetFields(),N.setFieldsValue(K))},[g,N,w,K,q,W]);const te=b.useCallback(ee=>{const re=ee.trim().match(F7);if(!re)return null;const ce=re[1],Ce=re[2];if(ce==="global")return null;const Oe=ce.startsWith("N")?ce.slice(1):ce,Pe=l.getState().nodes.find(Ae=>Ae.id===Oe);return Pe?{fieldPath:Ce,node:Pe,variableNodeId:ce}:null},[l]),$=b.useCallback(ee=>{var re;return((re=te(ee))==null?void 0:re.fieldPath)??ee.replace(/^\{\{|\}\}$/g,"")},[te]),V=b.useCallback(ee=>{var Pe;const re=te(ee);if(!re)return ee;const ce=(Pe=re.node)==null?void 0:Pe.data,Ce=(ce==null?void 0:ce.label)||(ce==null?void 0:ce.name)||(ce==null?void 0:ce.action_name)||re.variableNodeId,Oe=ce!=null&&ce.note?` (${ce.note})`:"";return`${Ce}${Oe}.${re.fieldPath}`},[te]),J=(ee,re)=>N.validateFields().then(async ce=>{var Oe,Pe,Ae,fe,Ne;if(W)return re&&((Pe=(Oe=B==null?void 0:B.current)==null?void 0:Oe.onIgnoreNodeStart)==null||Pe.call(Oe)),t.onSubmit({params:ce,account_id:I,proxy_id:ce==null?void 0:ce.proxy_id},ee);const Ce=ut.cloneDeep(n.config_schema);return Ce.sub_params.forEach(Be=>{let tt=ce[Be.name];Be.page_control===ye.EXTEND_OBJ&&tt!=="{{$fromAI}}"&&(tt=Qm(tt)),Be.value=tt??null}),re&&((fe=(Ae=B==null?void 0:B.current)==null?void 0:Ae.onIgnoreNodeStart)==null||fe.call(Ae)),!i&&h==="HTTP"&&(r==null?void 0:r.deployment_type)!=="SaasApp"&&(Ce.proxy_id=(Ne=L.current)==null?void 0:Ne.getProxyId()),t.onSubmit(Ce,ee)}).catch(ce=>(console.log("err",ce),x.message.warning(R("link.flow.missing_configuration")),!1));b.useImperativeHandle(e,()=>({saveConfig:ee=>J(ee,!1)}));const ne=Ct(),ae=h==="WEBHOOK"?{webhookField:{enabled:!0,form:N,configList:(u==null?void 0:u.sub_params)??[],disabled:!ne}}:void 0,de=ee=>{const re=ee.page_control!==ye.HIDDEN?f.jsx("div",{style:{minHeight:10},children:f.jsx("p",{style:{color:"#999",fontSize:12,marginTop:-18,whiteSpace:"pre-wrap"},children:ee.description})}):null;if(!ee.is_child)return f.jsxs("div",{children:[wA(ee,o,s,ae,a.canvas.registerComponents),re]},ee.ui_id);const ce=M7(ee);return f.jsx(x.Form.Item,{noStyle:!0,shouldUpdate:(Ce={},Oe={})=>ee.is_child?ce.length?ce.some(Pe=>(Ce==null?void 0:Ce[Pe])!==(Oe==null?void 0:Oe[Pe])):!0:!1,children:()=>{const Ce=N.getFieldsValue(!0);return P7(ee,Ce)?f.jsxs("div",{children:[wA(ee,o,s,ae,a.canvas.registerComponents),re]}):null}},ee.ui_id)};return!w&&F?f.jsx("div",{style:{textAlign:"center",padding:40},children:f.jsx(x.Spin,{})}):W?f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsxs("div",{style:{height:"calc(100% - 50px)",minHeight:500,overflowY:"auto"},children:[T?f.jsx(ng,{credentialRequirements:O,value:I,onChange:P,linkApp:r,disabled:!ne}):null,H?f.jsx(Ri,{schema:H,form:N,initialValues:K,showSubmit:!1,showReset:!1,nodeId:o,mcpMode:s,renderVariableTag:$,renderVariableTooltip:V},g):f.jsx("div",{style:{padding:16,color:"#999",textAlign:"center"},children:"该节点暂无配置项"})]}),f.jsx("div",{style:{padding:"10px 20px",paddingBottom:10,paddingTop:30,position:"sticky",backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:ne&&f.jsx(x.Button,{type:"primary",disabled:!ne,style:{width:180,borderRadius:4},onClick:()=>J(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]}):f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsxs(x.Form,{form:N,disabled:!ne,style:{height:"calc(100% - 50px)",minHeight:500,overflowY:"auto",paddingRight:24},layout:"vertical",className:O7.configFormContainer,children:[(r==null?void 0:r.id)&&n.config_schema&&((Y=u==null?void 0:u.sub_params)==null?void 0:Y.map(ee=>de(ee))),!i&&h==="HTTP"&&(r==null?void 0:r.deployment_type)!=="SaasApp"?f.jsx(zh,{proxyId:c.proxyId,ref:L}):null]}),f.jsx("div",{style:{padding:"10px 20px",paddingBottom:10,paddingTop:30,position:"sticky",backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:ne&&f.jsx(x.Button,{type:"primary",disabled:!ne,style:{width:180,borderRadius:4},onClick:()=>J(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})}),L7=b.memo(b.forwardRef((t,e)=>{var h;const{nodeId:n,data:r}=t,{account_id:o,account_schema_id:i}=r,s=dt.useReactive({account_id:o}),a=b.useRef(null);b.useImperativeHandle(e,()=>({saveConfig:p=>{var m;return(m=a.current)==null?void 0:m.saveConfig(p)}}));const l=b.useMemo(()=>({id:t.data.connector_id,name:t.data.connector_name}),[t.data.connector_id,t.data.connector_name]),c=!!(t.data.action_key||t.data.nodeKey)&&!Array.isArray((h=t.data.config_schema)==null?void 0:h.sub_params),u=(p,m)=>{if(c){const v=(p==null?void 0:p.params)??p??{},y=Object.hasOwn(p??{},"account_id")?p.account_id??null:s.account_id;t.onSubmit({params:v,account_id:y,proxy_id:(p==null?void 0:p.proxy_id)??(v==null?void 0:v.proxy_id)},m);return}t.onSubmit({properties:p,account_id:s.account_id,proxy_id:p.proxy_id},m)},d=b.useCallback(p=>{s.account_id=p??null},[]);return f.jsxs("div",{children:[i&&!c?f.jsx(ng,{onChange:d,actionAccountSchemaId:i,value:s.account_id,linkApp:l}):null,f.jsx(vA,{ref:a,action:t.data,connector:l,account_id:o,nodeId:n,onSubmit:u})]})}),(t,e)=>t.nodeId===e.nodeId&&ut.isEqual(ut.omit(t.data,["isHovered"]),ut.omit(e.data,["isHovered"]))),yA=[{operator:Xe.eq,label:R("common.eq")},{operator:Xe.ne,label:R("common.ne")},{operator:Xe.sw,label:R("common.sw")},{operator:Xe.nsw,label:R("common.nsw")},{operator:Xe.ew,label:R("common.ew")},{operator:Xe.ewn,label:R("common.ewn")},{operator:Xe.gt,label:R("common.gt")},{operator:Xe.ge,label:R("common.ge")},{operator:Xe.lt,label:R("common.lt")},{operator:Xe.le,label:R("common.le")},{operator:Xe.co,label:R("common.co")},{operator:Xe.nco,label:R("common.nco")},{operator:Xe.in,label:R("common.in")},{operator:Xe.nin,label:R("common.nin")},{operator:Xe.is_null,label:R("common.is_null")},{operator:Xe.is_not_null,label:R("common.is_not_null")}];Xe.eq+"",R("common.eq"),Xe.ne+"",R("common.ne"),Xe.sw+"",R("common.sw"),Xe.nsw+"",R("common.nsw"),Xe.ew+"",R("common.ew"),Xe.ewn+"",R("common.ewn"),Xe.gt+"",R("common.gt"),Xe.lt+"",R("common.lt"),Xe.ge+"",R("common.ge"),Xe.co+"",R("common.co"),Xe.nco+"",R("common.nco"),Xe.le+"",R("common.le"),Xe.in+"",R("common.in"),Xe.nin+"",R("common.nin"),Xe.is_null+"",R("common.is_null"),Xe.is_not_null+"",R("common.is_not_null");const ug=t=>t===Xe.is_null||t===Xe.is_not_null,$7=(t,e="")=>ug(t)?"":e,{Option:z7}=x.Select,H7=b.forwardRef((t,e)=>{const{config_schema:n}=t,[r]=x.Form.useForm(),i=(l=>l!=null&&l.or_list?{or_list:l.or_list.map(u=>({and_list:u.and_list.map(d=>({query:d.query||"",operator:d.operator||"",value:d.value||""}))}))}:{or_list:[{and_list:[{query:"",operator:"",value:""}]}]})(n),s=(l,c,u="")=>r.validateFields().then(async d=>t.onSubmit({properties:d},l)).catch(()=>(x.message.warning(R("link.flow.missing_configuration")),!1));b.useImperativeHandle(e,()=>({saveConfig:()=>s(!0)}));const a=Ct();return f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsx("div",{style:{height:"calc(100% - 60px)",minHeight:500,overflowY:"auto",paddingRight:20},className:"grayBeautifyScrollbar",children:f.jsx(x.Form,{disabled:!a,form:r,initialValues:i,layout:"vertical",autoComplete:"off",children:f.jsx(x.Form.List,{name:"or_list",children:(l,{add:c,remove:u})=>f.jsxs(f.Fragment,{children:[l.map((d,h)=>f.jsxs("div",{style:{marginTop:10},children:[f.jsxs("div",{style:{background:"rgb(247, 248, 249)",borderRadius:8,padding:12},children:[h>0&&a&&f.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:f.jsx(x.Button,{type:"link",style:{color:"red"},icon:f.jsx(Q.MinusCircleOutlined,{style:{color:"red"}}),onClick:()=>u(d.name),children:f.jsx(Se.FormattedMessage,{id:"link.flow.remove"})})}),f.jsx(x.Form.List,{name:[d.name,"and_list"],children:(p,{add:m,remove:v})=>f.jsx(f.Fragment,{children:p.map((w,y)=>f.jsxs(x.Space,{direction:"vertical",children:[f.jsxs(x.Space,{align:"center",children:[f.jsx(x.Form.Item,{style:{minWidth:150},name:[w.name,"query"],label:R("app.common.word.variable-name"),rules:[{required:!0,message:R("link.flow.please_enter_variable_name")}],children:f.jsx(ir,{nodeId:t.nodeId,placeholder:R("link.flow.variable_name"),borrow:!0,disableIDE:!0,valueType:"JS_EXP"})}),f.jsx(x.Form.Item,{name:[w.name,"operator"],label:R("app.common.word.condition"),rules:[{required:!0,message:R("link.flow.please_select_condition")}],children:f.jsx(x.Select,{style:{minWidth:140},placeholder:R("link.flow.select_condition"),getPopupContainer:g=>g.parentNode,children:yA.map(g=>f.jsx(z7,{value:g.operator,children:g.label},g.operator))})}),f.jsx(x.Form.Item,{noStyle:!0,shouldUpdate:!0,children:()=>{const g=r.getFieldValue(["or_list",d.name,"and_list",w.name,"operator"]);return ug(g)?null:f.jsx(x.Form.Item,{style:{minWidth:150},name:[w.name,"value"],label:R("app.common.word.value"),rules:[],children:f.jsx(ir,{nodeId:t.nodeId,placeholder:R("link.flow.value"),borrow:!0,disableIDE:!0,valueType:"JS_EXP"})})}}),y===0&&f.jsx("div",{style:{width:30}}),y>0&&f.jsx(x.Button,{type:"link",icon:f.jsx(Q.MinusCircleOutlined,{}),onClick:()=>v(w.name)})]}),y<p.length-1&&f.jsx(x.Divider,{plain:!0,children:f.jsx(x.Tag,{color:"#999999",children:f.jsx(Se.FormattedMessage,{id:"link.flow.and"})})}),y===p.length-1&&f.jsx(x.Button,{type:"link",disabled:!a,icon:f.jsx(Q.PlusCircleOutlined,{}),onClick:()=>m({query:"",operator:"",value:""}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-new-and"})})]},w.key))})})]}),h<l.length-1&&f.jsxs("div",{className:"test",style:{textAlign:"center"},children:[" ",f.jsx(x.Divider,{style:{color:"orange"},dashed:!0,children:f.jsx(x.Tag,{color:"#1890ff",children:f.jsx(Se.FormattedMessage,{id:"link.flow.or"})})})]})]},d.key)),f.jsx(x.Form.Item,{children:f.jsx(x.Button,{type:"link",icon:f.jsx(Q.PlusCircleOutlined,{}),disabled:!a,onClick:()=>c({and_list:[{query:"",operator:"",value:""}]}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-or"})})})]})})})}),f.jsx("div",{style:{position:"sticky",padding:"10px 20px",paddingBottom:0,backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:a&&f.jsx(x.Button,{type:"primary",disabled:!a,style:{width:180,borderRadius:4},onClick:()=>s(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})}),V7={copy:"Copy JSON",copySuccess:"JSON copied to clipboard",download:"Download JSON",invalidJson:"Invalid JSON data"},j7={copy:"复制JSON",copySuccess:"JSON已复制到剪贴板",download:"下载JSON",invalidJson:"无效的JSON数据"},{Text:W7}=x.Typography,bA=({data:t,height:e=400,enableCopy:n=!0,theme:r="light",className:o="",locale:i="zh",maxHeight:s})=>{const[a,l]=b.useState(r),c=b.useRef(null),u=i==="zh"?j7:V7,d=b.useMemo(()=>{if(!t)return null;try{return typeof t=="string"?JSON.parse(t):t}catch(y){return console.error("JSON解析失败:",y),null}},[t]),h=b.useMemo(()=>{if(!d)return[];const y=(g,C=[],D=0)=>{const k=[];if(g===null)return[{key:C.join("."),value:null,type:"null",path:C,level:D}];if(Array.isArray(g)){const A={key:C.join("."),value:g,type:"array",path:C,level:D,children:[]};g.forEach((S,E)=>{const T=[...C,E.toString()],O=y(S,T,D+1);A.children.push(...O)}),k.push(A)}else if(typeof g=="object"){const A={key:C.join("."),value:g,type:"object",path:C,level:D,children:[]};Object.entries(g).forEach(([S,E])=>{const T=[...C,S],O=y(E,T,D+1);A.children.push(...O)}),k.push(A)}else{const A=typeof g;k.push({key:C.join("."),value:g,type:A,path:C,level:D})}return k};return y(d)},[d]),p=b.useCallback(()=>{const y=JSON.stringify(d,null,2);navigator.clipboard.writeText(y).then(()=>{x.message.success(u.copySuccess)})},[d,u]),m=b.useCallback(()=>{const y=JSON.stringify(d,null,2),g=new Blob([y],{type:"application/json"}),C=URL.createObjectURL(g),D=document.createElement("a");D.href=C,D.download="data.json",D.click(),URL.revokeObjectURL(C)},[d]),v=b.useCallback(y=>{switch(y.type){case"string":return f.jsxs("span",{className:"json-string",children:['"',y.value,'"']});case"number":return f.jsx("span",{className:"json-number",children:y.value});case"boolean":return f.jsx("span",{className:"json-boolean",children:String(y.value)});case"null":return f.jsx("span",{className:"json-null",children:"null"});default:return null}},[]),w=b.useCallback((y,g)=>{const C=y.children&&y.children.length>0,D=y.path[y.path.length-1];return y.type==="object"||y.type==="array"?f.jsxs("div",{className:"json-node",children:[f.jsxs("div",{className:"json-line",style:{paddingLeft:`${y.level*16}px`},children:[D&&f.jsxs("span",{className:"json-key",children:['"',D,'": ']}),f.jsx("span",{className:"json-bracket",children:y.type==="array"?"[":"{"}),!C&&f.jsx("span",{className:"json-bracket",children:y.type==="array"?"]":"}"})]}),C&&f.jsxs(f.Fragment,{children:[y.children.map((k,A)=>w(k,g+A+1)),f.jsx("div",{className:"json-line",style:{paddingLeft:`${y.level*16}px`},children:f.jsx("span",{className:"json-bracket",children:y.type==="array"?"]":"}"})})]})]},y.key):f.jsx("div",{className:"json-node",children:f.jsxs("div",{className:"json-line",style:{paddingLeft:`${y.level*16}px`},children:[D&&f.jsxs("span",{className:"json-key",children:['"',D,'": ']}),v(y)]})},y.key)},[v,u]);return b.useCallback(()=>{l(a==="dark"?"light":"dark")},[a]),d?f.jsxs("div",{className:`json-renderer ${a} ${o}`,children:[f.jsx("div",{className:"json-toolbar",children:f.jsxs(x.Space,{children:[n&&f.jsx(x.Tooltip,{title:u.copy,children:f.jsx(x.Button,{icon:f.jsx(Q.CopyOutlined,{}),size:"small",onClick:p})}),f.jsx(x.Tooltip,{title:u.download,children:f.jsx(x.Button,{icon:f.jsx(Q.DownloadOutlined,{}),size:"small",onClick:m})})]})}),f.jsx("div",{ref:c,className:"json-content",style:{height:`${e}px`,maxHeight:s?`${s}px`:void 0},children:h.map((y,g)=>w(y,g))})]}):f.jsx("div",{className:`json-renderer error ${a} ${o}`,children:f.jsx("div",{className:"error-message",children:f.jsx(W7,{type:"secondary",children:u.invalidJson})})})},jr=()=>{const t=se.useStoreApi(),{setNodes:e}=se.useReactFlow(),n=Wt();return{handleNodeDataUpdate:b.useCallback(({id:o,data:i,sync:s})=>{const{nodes:a}=t.getState(),l=n.engineMode===lr.NEXT,c=$n(a,u=>{const d=u.find(h=>h.id===o);d&&(d.data={...d.data,...i}),s&&!l&&Ml(o,{flow_id:n.flowId,properties:d.data.config_schema})});e(c)},[t])}},U7=t=>typeof t=="string"?t.trim().length>0:t!=null,q7=t=>typeof t=="string"&&t.trim().toLowerCase()==="success",G7=t=>{if(!t||typeof t!="object")return!1;const e=t;return e.result===!0?!1:e.result===!1?!0:e.error==="0"&&U7(e.error_description)&&!q7(e.error_description)},K7=t=>G7(t)?pe.FAILED:pe.SUCCESS,Y7=t=>{if(typeof t=="object")return JSON.stringify(t,null,2);if(typeof t=="string")try{const e=JSON.parse(t);return JSON.stringify(e,null,2)}catch{return t}return String(t)},{TextArea:X7}=x.Input,{Title:J7,Paragraph:R7}=x.Typography,Q7=b.forwardRef((t,e)=>{var C,D;const{nodeId:n,beforeHook:r}=t,o=Wt(),{handleNodeDataUpdate:i}=jr(),s=(D=(C=o.nodeConfigPanel)==null?void 0:C.testArea)==null?void 0:D.defaultTestResult,[a,l]=b.useState(()=>{if(s==null)return"";if(typeof s=="string")return s;try{return JSON.stringify(s,null,2)}catch{return String(s)}}),c=se.useInternalNode(n),u=dt.useReactive({testProgress:0,sampleText:"",isError:!1,editable:!1,showErrorAlert:!1,testing:!1,ignoring:!1,successShown:!1,isIgnoreSuccess:!1}),{refreshFlow:d}=Sr();b.useEffect(()=>{if(c!=null&&c.data.output&&(c.data.status===pe.SUCCESS||c.data.status===pe.RUNNABLE)){const k=typeof c.data.output=="string"?c.data.output:JSON.stringify(c.data.output,null,2);l(k),u.successShown=!0,u.isError=!1,u.showErrorAlert=!1}else if(c!=null&&c.data.output&&c.data.status===pe.FAILED){const k=typeof c.data.output=="string"?c.data.output:JSON.stringify(c.data.output,null,2);l(k),u.isError=!0,u.showErrorAlert=!0,u.successShown=!1}},[c]);const h=b.useCallback(()=>{if(!n){console.error("节点ID不能为空");return}u.testing=!0,u.testProgress=60,u.successShown=!1,u.isError=!1,u.showErrorAlert=!1,u.isIgnoreSuccess=!1,wy(n).then(k=>{const A=k,S=K7(A),E=S===pe.FAILED;u.isError=E,u.successShown=!E,u.isIgnoreSuccess=!1,u.showErrorAlert=u.isError;let T="";try{T=Y7(A)}catch(O){console.error("格式化测试结果出错:",O),T="测试结果格式化失败: "+String(O)}u.testProgress=100,l(T),i({id:n,data:{status:S,output:T}})}).catch(k=>{var E;console.error("测试失败:",k),u.testProgress=0,u.isError=!0,u.showErrorAlert=!0,u.successShown=!1,u.isIgnoreSuccess=!1;let A="测试执行失败";(E=k==null?void 0:k.response)!=null&&E.data?A=JSON.stringify(k.response.data,null,2):k!=null&&k.message&&(A=k.message);const S=JSON.stringify({error:A},null,2);l(S),i({id:n,data:{status:pe.FAILED,output:S}})}).finally(()=>{setTimeout(()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!1},500)})},[n]),p=()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!0};b.useImperativeHandle(e,()=>({onTestNode:h,finishNodeTest:p}));const m=()=>{r?r(!0):h()},v=()=>{r&&(u.testing=!0,u.ignoring=!0,u.testProgress=60,r(!0,!0,u.sampleText))},w=()=>{l(""),u.sampleText="",u.editable=!1,u.successShown=!1},y=Ct(),g=b.useMemo(()=>{var S;const k=(S=c==null?void 0:c.data)==null?void 0:S.protocol,A=c==null?void 0:c.type;return!y||k===Ie.AI_LANGUAGE_MODEL||k===Ie.AI_MEMORY||A===Z.BuiltinMCP||A===Z.MCPServer},[c]);return f.jsxs("div",{className:"node-test-container",children:[f.jsxs("div",{className:"node-test-header",children:[f.jsxs("div",{className:"header-title",children:[f.jsx(Q.RocketOutlined,{className:"title-icon"}),f.jsx(J7,{level:4,children:"节点测试"})]}),f.jsx(R7,{type:"secondary",className:"header-description",children:"点击测试按钮,实时检查节点执行效果和结果数据"})]}),f.jsxs("div",{className:"test-content",children:[y&&f.jsxs("div",{className:"action-buttons",children:[f.jsx(x.Button,{type:"primary",disabled:g||u.ignoring,icon:f.jsx(Q.RocketOutlined,{}),onClick:m,loading:u.testing&&!u.ignoring,className:"test-button",children:u.testing&&!u.ignoring?"测试中...":"开始测试"}),f.jsx(x.Button,{type:"primary",disabled:g||u.testing&&!u.ignoring,ghost:!0,onClick:v,loading:u.testing&&u.ignoring,className:"ignore-button",children:"忽略调试"}),a&&f.jsx(x.Button,{icon:f.jsx(Q.ReloadOutlined,{}),onClick:w,className:"reset-button",children:"重置"})]}),u.testProgress>0&&f.jsx(x.Progress,{percent:u.testProgress,status:u.isError?"exception":"active",className:"test-progress"}),u.isError&&u.showErrorAlert&&f.jsx(x.Alert,{className:"error-alert",showIcon:!0,message:"测试未通过",description:"请检查节点配置是否正确",type:"error",onClose:()=>{setTimeout(()=>{u.showErrorAlert=!1},500)},closable:!0}),!u.isError&&u.successShown&&a&&!u.testing&&f.jsx(x.Alert,{className:"success-alert",showIcon:!0,message:u.isIgnoreSuccess?"忽略调试成功":"测试成功",description:u.isIgnoreSuccess?"已将样本数据预设为当前节点输出":"节点运行正常,可以查看下方返回结果",type:"success",closable:y}),u.testing?f.jsx(x.Skeleton,{active:!0,className:"result-skeleton"}):f.jsx(f.Fragment,{children:a?f.jsx(x.Card,{styles:{body:{padding:0}},title:f.jsxs("div",{className:"result-header",children:[f.jsx("div",{className:"result-title",children:u.isError?f.jsxs(f.Fragment,{children:[f.jsx(Q.CloseCircleFilled,{className:"error-icon"})," 错误数据"]}):f.jsxs(f.Fragment,{children:[u.isIgnoreSuccess?f.jsx(Q.ExperimentFilled,{className:"success-icon"}):f.jsx(Q.CheckCircleFilled,{className:"success-icon"}),u.isIgnoreSuccess?"样本数据":"测试结果"]})}),y&&f.jsx(x.Button,{size:"small",type:"link",icon:f.jsx(Q.EditOutlined,{}),onClick:()=>{if(u.editable){u.editable=!1;try{const k=JSON.parse(u.sampleText),A=JSON.stringify(k,null,2);l(A),i({id:n,data:{output:A}})}catch{l(u.sampleText)}}else u.sampleText=a,u.editable=!0},className:"edit-button",children:u.editable?"完成":"编辑"})]}),variant:"borderless",className:`result-card ${u.isError?"error-result":"success-result"}`,children:u.editable?f.jsx(X7,{rows:10,value:u.sampleText,onChange:k=>u.sampleText=k.target.value,className:"result-editor"}):f.jsx(bA,{data:a,height:300,enableCopy:!0,theme:"light"},a)}):f.jsx(x.Card,{variant:"borderless",className:"empty-result",children:f.jsx(x.Result,{icon:f.jsx(Q.RocketOutlined,{}),title:"等待测试",subTitle:'点击"开始测试"按钮开始节点测试'})})})]})]})}),{Option:Lo}=x.Select,Z7=b.forwardRef(({onSubmit:t,config_schema:e,nodeId:n},r)=>{const[o]=x.Form.useForm(),i=x.Form.useWatch("type",o);dt.useMount(()=>{e&&Object.hasOwn(e,"asc")&&o.setFieldsValue(e)});const s=(l,c,u="")=>o.validateFields().then(async d=>i&&i==="NUMBER"&&d.start>d.end?x.message.warning(R("link.flow.loop_start_end_check")):t({properties:d},l)).catch(()=>(x.message.warning(R("link.flow.missing_configuration")),!1));b.useImperativeHandle(r,()=>({saveConfig:l=>s(l)}));const a=Ct();return f.jsxs("div",{style:{width:"100%",position:"relative",height:"100%"},children:[f.jsx("div",{style:{height:"calc(100% - 60px)",overflow:"scroll"},className:"grayBeautifyScrollbar",children:f.jsxs(x.Form,{disabled:!a,form:o,layout:"vertical",children:[f.jsx(x.Form.Item,{name:"type",label:R("app.common.word.loop-data-type"),rules:[{required:!0,message:R("link.flow.please_select_data_type")}],children:f.jsxs(x.Select,{children:[f.jsx(Lo,{value:"ARRAY",children:f.jsx(Se.FormattedMessage,{id:"link.flow.array"})}),f.jsx(Lo,{value:"NUMBER",children:f.jsx(Se.FormattedMessage,{id:"common.number"})}),f.jsx(Lo,{value:"CONDITION",children:f.jsx(Se.FormattedMessage,{id:"link.flow.condition_expression"})})]})}),i&&i==="NUMBER"&&f.jsxs(x.Form.Item,{required:!0,label:R("link.flow.loop_start_end"),style:{display:"flex"},children:[f.jsx(x.Form.Item,{name:"start",noStyle:!0,rules:[{required:!0,message:R("link.flow.please_select_data_type")}],children:f.jsx(x.InputNumber,{min:1,style:{marginRight:20}})}),f.jsx(x.Form.Item,{name:"end",noStyle:!0,rules:[{required:!0,message:R("link.flow.please_select_data_type")}],children:f.jsx(x.InputNumber,{min:1})})]}),i&&i!=="NUMBER"&&f.jsx(x.Form.Item,{rules:[{required:!0,message:R("link.flow.please_enter_loop_expression")}],label:R("link.flow.loop_expression"),name:"expression",children:f.jsx(ir,{nodeId:n,borrow:!0,valueType:"JS_EXP",placeholder:R("link.flow.please_enter_loop_expression")})}),f.jsx(x.Form.Item,{name:"asc",label:R("app.common.word.circulation-direction"),rules:[{required:!0,message:R("link.flow.please_select_loop_direction")}],children:f.jsxs(x.Select,{children:[f.jsx(Lo,{value:!0,children:f.jsx(Se.FormattedMessage,{id:"link.flow.loop_head_to_tail"})}),f.jsx(Lo,{value:!1,children:f.jsx(Se.FormattedMessage,{id:"link.flow.loop_tail_to_head"})})]})}),f.jsx(x.Form.Item,{name:"errorExec",label:R("link.flow.loop_processing"),rules:[{required:!0,message:R("link.flow.please_select_loop_processing")}],children:f.jsxs(x.Select,{children:[f.jsx(Lo,{value:"END",children:f.jsx(Se.FormattedMessage,{id:"link.flow.terminate_process"})}),f.jsx(Lo,{value:"CONTINUE",children:f.jsx(Se.FormattedMessage,{id:"link.flow.continue_loop"})}),f.jsx(Lo,{value:"BREAK",children:f.jsx(Se.FormattedMessage,{id:"link.flow.break_loop"})})]})})]})}),f.jsx("div",{style:{padding:"10px 20px",marginTop:30,paddingBottom:0,backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:a&&f.jsx(x.Button,{type:"primary",disabled:!a,style:{width:180,borderRadius:4},onClick:()=>s(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})}),yd=()=>`branch_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,{Option:eW}=x.Select,tW=b.forwardRef((t,e)=>{const{config_schema:n,nodeId:r}=t,[o]=x.Form.useForm(),{handleNodeDataUpdate:i}=jr(),[s,a]=b.useState(null),[l,c]=b.useState(""),d=(D=>!(D!=null&&D.branches)||D.branches.length===0?{branches:[{id:yd(),name:R("link.flow.switch.condition_one"),or_list:[{and_list:[{query:"",operator:"",value:""}]}]},{id:yd(),name:R("link.flow.switch.condition_two"),or_list:[{and_list:[{query:"",operator:"",value:""}]}]}]}:{branches:D.branches.map((A,S)=>{var E;return{id:A.id||yd(),name:A.name||R("link.flow.switch.condition_n",{n:S+1}),or_list:((E=A.or_list)==null?void 0:E.map(T=>{var O;return{and_list:((O=T.and_list)==null?void 0:O.map(F=>({query:F.query||"",operator:F.operator||"",value:F.value||""})))||[{query:"",operator:"",value:""}]}}))||[{and_list:[{query:"",operator:"",value:""}]}]}})})(n),h=()=>{const D=o.getFieldValue("branches")||[];i({id:r,data:{config_schema:{branches:D}}})},p=(D,k)=>{a(D),c(k)},m=()=>{a(null),c("")},v=D=>{const k=ut.cloneDeep(o.getFieldValue("branches"))||[],A=l.trim();if(!A){x.message.error(R("link.flow.switch.branch_name_cannot_be_empty"));return}if(k.some((E,T)=>T!==D&&E.name===A)){x.message.error(R("link.flow.switch.branch_name_duplicate"));return}k[D].name=A,o.setFieldValue("branches",k),a(null),c(""),h()},w=(D,k)=>{const A=o.getFieldValue("branches")||[];if(k<0||k>=A.length)return;const S=[...A],[E]=S.splice(D,1);S.splice(k,0,E),o.setFieldValue("branches",S),h()},y=D=>o.validateFields().then(async k=>{if(!k.branches.some(E=>E.or_list.some(T=>T.and_list.some(O=>O.query&&O.operator)))){x.message.error(R("link.flow.switch.at_least_one_valid_branch"));return}const S=ut.cloneDeep(k);return S.branches.forEach(E=>{E.or_list.forEach(T=>{T.and_list.forEach(O=>{O.value=$7(O.operator,O.value)})})}),t.onSubmit({properties:S},D)}).catch(()=>(x.message.warning(R("link.flow.missing_configuration")),!1));b.useImperativeHandle(e,()=>({saveConfig:()=>y(!0)}));const g=Ct(),C=(D,k,A,S)=>{const T=(o.getFieldValue("branches")||[])[k],O=s===k;return f.jsxs(x.Card,{style:{marginBottom:16,borderRadius:8,border:"1px solid #d9d9d9"},bodyStyle:{padding:16},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:12},children:[f.jsx("div",{style:{display:"flex",alignItems:"center",flex:1},children:O?f.jsxs(x.Space,{children:[f.jsx(x.Input,{value:l,onChange:F=>c(F.target.value),style:{width:200},placeholder:R("link.flow.switch.enter_branch_name"),onPressEnter:()=>v(k)}),f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.CheckOutlined,{style:{color:"#52c41a"}}),onClick:()=>v(k)}),f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.CloseOutlined,{}),onClick:m})]}):f.jsxs(x.Space,{children:[f.jsx("span",{style:{fontSize:16,fontWeight:500},children:(T==null?void 0:T.name)||R("link.flow.switch.condition_n",{n:k+1})}),g&&f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.EditOutlined,{}),onClick:()=>p(k,(T==null?void 0:T.name)||"")})]})}),g&&f.jsxs(x.Space,{children:[f.jsx(x.Tooltip,{title:R("link.flow.switch.move_to_top"),children:f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.VerticalAlignTopOutlined,{}),disabled:k===0,onClick:()=>w(k,0)})}),f.jsx(x.Tooltip,{title:R("link.flow.switch.move_up"),children:f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.ArrowUpOutlined,{}),disabled:k===0,onClick:()=>w(k,k-1)})}),f.jsx(x.Tooltip,{title:R("link.flow.switch.move_down"),children:f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.ArrowDownOutlined,{}),disabled:k===A-1,onClick:()=>w(k,k+1)})}),f.jsx(x.Tooltip,{title:R("link.flow.switch.move_to_bottom"),children:f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.VerticalAlignBottomOutlined,{}),disabled:k===A-1,onClick:()=>w(k,A-1)})}),f.jsx(x.Tooltip,{title:R("common.delete"),children:f.jsx(x.Button,{type:"text",size:"small",danger:!0,icon:f.jsx(Q.DeleteOutlined,{}),disabled:A<=1,onClick:()=>{if(A<=1){x.message.warning(R("link.flow.switch.at_least_one_branch"));return}S(D.name),setTimeout(()=>{h()},0)}})})]})]}),f.jsx(x.Form.Item,{name:[D.name,"name"],hidden:!0,children:f.jsx(x.Input,{})}),f.jsx(x.Form.List,{name:[D.name,"or_list"],children:(F,{add:N,remove:I})=>f.jsxs(f.Fragment,{children:[F.map((P,_)=>f.jsxs("div",{style:{marginTop:_>0?10:0},children:[f.jsxs("div",{style:{background:"rgb(247, 248, 249)",borderRadius:8,padding:12},children:[F.length>1&&g&&f.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:f.jsx(x.Button,{type:"link",style:{color:"red"},icon:f.jsx(Q.MinusCircleOutlined,{style:{color:"red"}}),onClick:()=>I(P.name),children:f.jsx(Se.FormattedMessage,{id:"link.flow.remove"})})}),f.jsx(x.Form.List,{name:[P.name,"and_list"],children:(B,{add:L,remove:H})=>f.jsx(f.Fragment,{children:B.map((W,K)=>f.jsxs(x.Space,{direction:"vertical",style:{width:"100%"},children:[f.jsxs(x.Space,{align:"center",wrap:!0,children:[f.jsx(x.Form.Item,{style:{minWidth:150,marginBottom:0},name:[W.name,"query"],label:R("app.common.word.variable-name"),rules:[{required:!0,message:R("link.flow.please_enter_variable_name")}],children:f.jsx(ir,{nodeId:t.nodeId,placeholder:R("link.flow.variable_name"),borrow:!0,disableIDE:!0,valueType:"JS_EXP"})}),f.jsx(x.Form.Item,{style:{marginBottom:0},name:[W.name,"operator"],label:R("app.common.word.condition"),rules:[{required:!0,message:R("link.flow.please_select_condition")}],children:f.jsx(x.Select,{style:{minWidth:140},placeholder:R("link.flow.select_condition"),getPopupContainer:q=>document.body,children:yA.map(q=>f.jsx(eW,{value:q.operator,children:q.label},q.operator))})}),f.jsx(x.Form.Item,{noStyle:!0,shouldUpdate:!0,children:()=>{const q=o.getFieldValue(["branches",D.name,"or_list",P.name,"and_list",W.name,"operator"]);return ug(q)?null:f.jsx(x.Form.Item,{style:{minWidth:150,marginBottom:0},name:[W.name,"value"],label:R("app.common.word.value"),rules:[],children:f.jsx(ir,{nodeId:t.nodeId,placeholder:R("link.flow.value"),borrow:!0,disableIDE:!0,valueType:"JS_EXP"})})}}),K===0&&f.jsx("div",{style:{width:30}}),K>0&&g&&f.jsx(x.Button,{type:"link",icon:f.jsx(Q.MinusCircleOutlined,{}),onClick:()=>H(W.name)})]}),K<B.length-1&&f.jsx(x.Divider,{plain:!0,style:{margin:"8px 0"},children:f.jsx(x.Tag,{color:"#999999",children:f.jsx(Se.FormattedMessage,{id:"link.flow.and"})})}),K===B.length-1&&f.jsx(x.Button,{type:"link",disabled:!g,icon:f.jsx(Q.PlusCircleOutlined,{}),onClick:()=>L({query:"",operator:"",value:""}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-new-and"})})]},W.key))})},Math.random())]}),_<F.length-1&&f.jsx("div",{style:{textAlign:"center"},children:f.jsx(x.Divider,{style:{color:"orange"},dashed:!0,children:f.jsx(x.Tag,{color:"#1890ff",children:f.jsx(Se.FormattedMessage,{id:"link.flow.or"})})})})]},P.key)),f.jsx(x.Form.Item,{style:{marginTop:12,marginBottom:0},children:f.jsx(x.Button,{type:"link",icon:f.jsx(Q.PlusCircleOutlined,{}),disabled:!g,onClick:()=>N({and_list:[{query:"",operator:"",value:""}]}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-or"})})})]})})]},D.key)};return f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsx("div",{style:{height:"calc(100% - 60px)",minHeight:500,overflowY:"auto",paddingRight:20},className:"grayBeautifyScrollbar",children:f.jsx(x.Form,{disabled:!g,form:o,initialValues:d,layout:"vertical",autoComplete:"off",children:f.jsx(x.Form.List,{name:"branches",children:(D,{add:k,remove:A})=>f.jsxs(f.Fragment,{children:[D.map((S,E)=>C(S,E,D.length,A)),D.length<10&&f.jsx(x.Button,{type:"dashed",block:!0,icon:f.jsx(Q.PlusCircleOutlined,{}),disabled:!g,onClick:()=>{const S=D.length+1;k({id:yd(),name:R("link.flow.switch.condition_n",{n:S}),or_list:[{and_list:[{query:"",operator:"",value:""}]}]}),setTimeout(()=>{h()},0)},style:{marginBottom:16},children:f.jsx(Se.FormattedMessage,{id:"link.flow.switch.add_branch"})}),D.length>=10&&f.jsx("div",{style:{textAlign:"center",color:"#999",marginBottom:16},children:f.jsx(Se.FormattedMessage,{id:"link.flow.switch.max_branches_reached"})})]})})})}),f.jsx("div",{style:{position:"sticky",padding:"10px 20px",paddingBottom:0,backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:g&&f.jsx(x.Button,{type:"primary",disabled:!g,style:{width:180,borderRadius:4},onClick:()=>y(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})}),nW=({nodeId:t,onSubmit:e,data:n})=>{const[r]=x.Form.useForm(),o=Ct(),{refreshFlow:i}=Sr(),{setNodes:s}=se.useReactFlow(),a=b.useCallback((c,u)=>{s(d=>d.map(h=>!u&&h.id!==t?h:{...h,data:{...h.data,error_handler:c}}))},[t,s]);b.useEffect(()=>{const c=(n==null?void 0:n.error_handler)||{};r.setFieldsValue({retryEnabled:c.retry||!1,retryCount:c.retry_times||3,retryInterval:c.retry_interval||5,stepFactor:c.step_factor||1.5,maxRetryInterval:c.max_retry_interval||60,alertEnabled:c.warn_type===1,webhookUrl:c.notify_url||"",errorHandling:c.process_type===2?"ignore":"interrupt",applyToAllNodes:!!c.apply_all})},[t,r,n==null?void 0:n.error_handler]);const l=async c=>{try{const u={retry:c.retryEnabled,retry_times:c.retryEnabled?c.retryCount:void 0,retry_interval:c.retryEnabled?c.retryInterval:void 0,step_factor:c.retryEnabled?c.stepFactor:void 0,max_retry_interval:c.retryEnabled?c.maxRetryInterval:void 0,warn_type:c.alertEnabled?1:0,notify_url:c.alertEnabled?c.webhookUrl:void 0,process_type:c.errorHandling==="interrupt"?1:2,apply_all:c.applyToAllNodes};await Ml(t,{error_handler:u}),a(u,c.applyToAllNodes),c.applyToAllNodes&&i(),e()}catch{x.message.error(R("common.save_failed"))}};return f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsx("div",{style:{height:"calc(100% - 60px)",overflowY:"auto",paddingRight:20},children:f.jsxs(Gn.ProForm,{form:r,layout:"vertical",disabled:!o,submitter:!1,onFinish:l,children:[f.jsx(Gn.ProFormSwitch,{name:"retryEnabled",label:R("app.common.word.enable-retry")}),f.jsx(Gn.ProFormDependency,{name:["retryEnabled"],children:({retryEnabled:c})=>c?f.jsxs(f.Fragment,{children:[f.jsx(Gn.ProFormDigit,{name:"retryCount",label:R("app.common.word.retry-count"),tooltip:R("app.common.word.retry-count-tooltip"),width:"xl",fieldProps:{min:1,max:10,precision:0,style:{width:"100%"}},rules:[{required:c,message:R("app.common.word.please-enter-retry-count")}]}),f.jsx(Gn.ProFormDigit,{name:"retryInterval",label:R("app.common.word.retry-interval"),tooltip:R("app.common.word.retry-interval-tooltip"),fieldProps:{min:1,max:60,precision:0,style:{width:"100%"},addonAfter:"s"},rules:[{required:c,message:R("app.common.word.please-enter-retry-interval")}]}),f.jsx(Gn.ProFormDigit,{name:"stepFactor",label:R("app.common.word.step-factor"),tooltip:R("app.common.word.step-factor-tooltip"),width:"xl",fieldProps:{min:1,max:5,precision:1,style:{width:"100%"}},rules:[{required:c,message:R("app.common.word.please-enter-step-factor")}]}),f.jsx(Gn.ProFormDigit,{name:"maxRetryInterval",label:R("app.common.word.max-retry-interval"),tooltip:R("app.common.word.max-retry-interval-tooltip"),width:"xl",fieldProps:{min:1,max:300,precision:0,style:{width:"100%"},addonAfter:"s"},rules:[{required:c,message:R("app.common.word.please-enter-max-retry-interval")}]})]}):null}),f.jsx(Gn.ProFormSwitch,{name:"alertEnabled",label:R("app.common.word.enable-alert")}),f.jsx(Gn.ProFormDependency,{name:["alertEnabled"],children:({alertEnabled:c})=>c?f.jsx(Gn.ProFormText,{name:"webhookUrl",label:R("app.common.word.webhook-url"),placeholder:R("app.common.word.enter-webhook-url"),width:"xl",fieldProps:{style:{width:"100%"}},rules:[{required:c,message:R("app.common.word.enter-webhook-url")}]}):null}),f.jsx(Gn.ProFormSelect,{name:"errorHandling",label:R("app.common.word.error-handling"),width:"xl",fieldProps:{style:{width:"100%"}},rules:[{required:!0,message:R("app.common.word.select-error-handling")}],options:[{label:R("app.common.word.interrupt-flow"),value:"interrupt"},{label:R("app.common.word.ignore-error"),value:"ignore"}]}),f.jsx(Gn.ProFormSwitch,{name:"applyToAllNodes",label:R("app.common.word.apply-to-all-nodes")})]})}),f.jsx("div",{style:{padding:"10px 20px",position:"sticky",paddingBottom:0,backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:f.jsx(x.Button,{type:"primary",disabled:!o,onClick:()=>r.submit(),style:{width:180,borderRadius:4},children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})},rW=b.forwardRef((t,e)=>{const{account_id:n,account_schema_id:r,action_name:o,mcp_tool_description:i,description:s}=t.data,a=t.nodeId,l=dt.useReactive({account_id:n,mcp_tool_description:i||o||s||""}),c=b.useRef(null);b.useImperativeHandle(e,()=>({saveConfig:()=>{var p;return(p=c.current)==null?void 0:p.saveConfig()}}));const u=b.useMemo(()=>({id:t.data.connector_id,name:t.data.connector_name}),[t.data.connector_id,t.data.connector_name]),d=(p,m)=>{t.onSubmit({properties:p,account_id:l.account_id,mcp_tool_description:l.mcp_tool_description},m)},h=b.useCallback(p=>{l.account_id=p??null},[]);return f.jsxs("div",{children:[r?f.jsx(ng,{onChange:h,actionAccountSchemaId:r,value:l.account_id,linkApp:u}):null,f.jsx(x.Form.Item,{layout:"vertical",label:"工具描述",children:f.jsx(x.Input,{value:l.mcp_tool_description,onChange:p=>{l.mcp_tool_description=p.target.value}})}),f.jsx(vA,{ref:c,action:t.data,connector:u,account_id:n,nodeId:a,mcpMode:!0,onSubmit:d})]})}),bd="[workflow:schema-render]",oW=()=>{const{event$:t}=b.useContext(Vr),e=jf();return t.useSubscription(n=>{n.type==="insert"&&n.expression&&e!=null&&e.activeFieldId&&e.insertVariableToActiveField(n.expression,!1)}),null},iW=t=>f.jsxs("div",{className:"node-config-title",style:{display:"flex",alignItems:"center"},children:[t.icon?f.jsx("img",{src:t.icon,alt:t.name,style:{width:24,height:24}}):null,f.jsx("div",{className:"node-config-title-name",style:{fontSize:16,fontWeight:600,marginLeft:10},children:t.name}),f.jsx("div",{className:"node-config-title-description",style:{fontSize:12,color:"gray",marginLeft:10},children:t.description})]}),sW=b.memo(({visible:t,onClose:e,data:n,nodeType:r=Z.ACTION,nodeId:o=""})=>{var P,_,B,L,H;const i=dt.useEventEmitter();Df(),se.useInternalNode(o);const{setNodeConfigVisible:s,refreshFlow:a}=Sr(),l=b.useRef(null),c=b.useRef(null),u=b.useRef(null),d=b.useRef(null),h=b.useRef(null),p=b.useRef(null),m=b.useRef(null),v=se.useStoreApi(),w=Wt(),y=((_=(P=w.nodeConfigPanel)==null?void 0:P.testArea)==null?void 0:_.allowManualTest)!==!1,g=dt.useReactive({output:"",ignore:!1}),C=b.useMemo(()=>w.nodeConfigPanel.showSettings&&![Z.TRIGGER,Z.MCP_TOOL,Z.AI_SUB_NODE].includes(r),[r,w.nodeConfigPanel.showSettings]),D=()=>{e()};b.useEffect(()=>{var W;t&&((W=l.current)==null||W.loadVariables())},[t]);const k=(n==null?void 0:n.action_id)||null,A=Array.isArray((B=n==null?void 0:n.config_schema)==null?void 0:B.sub_params),S=r===Z.ACTION&&!!(n!=null&&n.action_key||n!=null&&n.nodeKey)&&!A,E=(n==null?void 0:n.action_key)||(n==null?void 0:n.nodeKey),T=(n==null?void 0:n.action_ver)??(n==null?void 0:n.nodeVersion)??((L=n==null?void 0:n.node_schema)==null?void 0:L.version),{handleNodeDataUpdate:O}=jr();b.useEffect(()=>{var W;t&&console.info(`${bd} node config modal opened`,{nodeId:o,nodeType:r,actionId:k,isNextCompatibleNode:S,nextNodeKey:E,nextNodeVersion:T,hasConfigSchema:!!(n!=null&&n.config_schema),hasParams:!!(n!=null&&n.params),actionKey:n==null?void 0:n.action_key,actionVer:n==null?void 0:n.action_ver,dataNodeKey:n==null?void 0:n.nodeKey,dataNodeVersion:n==null?void 0:n.nodeVersion,inlineSchemaVersion:(W=n==null?void 0:n.node_schema)==null?void 0:W.version})},[k,n==null?void 0:n.config_schema,n==null?void 0:n.params,n==null?void 0:n.action_key,n==null?void 0:n.action_ver,n==null?void 0:n.nodeKey,n==null?void 0:n.nodeVersion,(H=n==null?void 0:n.node_schema)==null?void 0:H.version,S,E,T,o,r,t]);const F=b.useCallback(async(W,K)=>{const q=w.flowId;try{const te=v.getState().nodes.find(ne=>ne.id===o),$=S?W.params||W.properties||{}:W.properties,V=S?{flow_id:q,properties:$,position:te==null?void 0:te.position,action_id:k,account_id:W.account_id??null,proxy_id:W.proxy_id,action_key:E,action_ver:T}:{flow_id:q,...W,position:te==null?void 0:te.position,action_id:k};console.info(`${bd} save node config`,{nodeId:o,nodeType:r,actionId:k,isNextCompatibleNode:S,nextNodeKey:E,nextNodeVersion:T,valueKeys:Object.keys(W||{}),paramsKeys:Object.keys((W==null?void 0:W.params)||{}),propertiesKeys:Object.keys((W==null?void 0:W.properties)||{}),ignoreDebugResult:g.ignore});const J=g.ignore?await yy(o,"","","",$,g.output):await Ml(o,V);if(J)if(console.info(`${bd} save node config success`,{nodeId:o,nodeType:r,isNextCompatibleNode:S,nextNodeKey:E,nextNodeVersion:T,status:J.status}),g.ignore)m.current.finishNodeTest(),O({id:o,data:{status:pe.SUCCESS}}),x.message.success("已忽略调试结果");else{x.message.success("节点配置已保存");const ne=S?{params:$,account_id:W.account_id,action_key:E,action_ver:T,nodeKey:E,nodeVersion:T}:{};O({id:o,data:{config_schema:$,account_id:W.account_id,...ne,position:te==null?void 0:te.position,status:J.status}})}K&&!g.ignore&&m.current&&m.current.onTestNode(),g.ignore=!1,g.output=""}catch(te){console.error(`${bd} save node config failed`,{nodeId:o,nodeType:r,isNextCompatibleNode:S,nextNodeKey:E,nextNodeVersion:T,err:te}),g.ignore&&O({id:o,data:{status:pe.FAILED}})}},[k,w.flowId,n==null?void 0:n.action_key,n==null?void 0:n.action_ver,n==null?void 0:n.nodeKey,n==null?void 0:n.nodeVersion,O,S,E,T,o,r,g,v]),N=W=>{var K,q,te,$,V;return r===Z.LOOP?(K=h.current)==null?void 0:K.saveConfig(W):r===Z.CONDITION?(q=u.current)==null?void 0:q.saveConfig(W):r===Z.SWITCH?(te=d.current)==null?void 0:te.saveConfig(W):r===Z.MCP_TOOL?($=p.current)==null?void 0:$.saveConfig(W):(V=c.current)==null?void 0:V.saveConfig(W)},I=async(W,K,q)=>{var te;if(K){g.ignore=!0,g.output=q||"",await N(W)===!1&&((te=m.current)==null||te.finishNodeTest());return}if(W)try{x.message.loading("正在保存节点配置...",0),await N(W),x.message.success("节点配置已保存"),x.message.destroy()}catch($){x.message.destroy(),console.error("节点配置保存失败:",$),x.message.error("节点配置保存失败,无法执行测试")}};return f.jsx(x.Modal,{open:t,footer:null,closeIcon:null,maskClosable:!0,onCancel:()=>{s(null)},centered:!0,width:"90%",className:"nodes-config-modal",styles:{wrapper:{minWidth:1040},mask:{backgroundColor:"rgba(0, 0, 0, 0.45)"},content:{padding:0,overflow:"hidden"}},children:f.jsx(Vr.Provider,{value:{event$:i},children:f.jsxs(Vf,{children:[f.jsx(oW,{}),f.jsxs("div",{className:"nodes-config-container",children:[f.jsxs("div",{className:"nodes-config-header",children:[f.jsx("div",{className:"header-left",children:f.jsx("span",{className:"header-title",children:" 节点配置"})}),f.jsx("div",{className:"header-right",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Q.ArrowLeftOutlined,{}),onClick:D,className:"back-button",children:"返回画布"})})]}),f.jsx("div",{className:"nodes-config-content",children:f.jsxs(x.Row,{gutter:16,className:"config-row",children:[f.jsx(x.Col,{span:5,className:"left-section",children:f.jsx("div",{className:"variables-section",children:f.jsx(lA,{ref:l,nodeId:o,onInsert:()=>{},open:t})})}),f.jsx(x.Col,{span:12,className:"middle-section",children:f.jsx("div",{className:"form-section",style:{height:"100%"},children:f.jsx(x.Card,{title:f.jsx(iW,{icon:n==null?void 0:n.icon,name:n==null?void 0:n.name,description:n==null?void 0:n.description}),variant:"borderless",styles:{body:{paddingTop:0,paddingBottom:0}},className:"section-card form-card",children:f.jsx(x.Tabs,{style:{height:"100%"},items:[{key:"property",label:"参数配置",children:f.jsxs(f.Fragment,{children:[[Z.CONDITION,Z.SWITCH,Z.LOOP,Z.MCP_TOOL].includes(r)?null:f.jsx(L7,{ref:c,nodeId:o,data:n,onSubmit:F}),r===Z.CONDITION?f.jsx(H7,{ref:u,nodeId:o,config_schema:n.config_schema,onSubmit:F}):null,r===Z.SWITCH?f.jsx(tW,{ref:d,nodeId:o,config_schema:n.config_schema,onSubmit:F}):null,r===Z.LOOP?f.jsx(Z7,{ref:h,nodeId:o,config_schema:n.config_schema,onSubmit:F}):null,r===Z.MCP_TOOL?f.jsx(rW,{ref:p,nodeId:o,data:n,onSubmit:F}):null]})},{key:"setting",label:"设置",children:f.jsx(nW,{data:n,nodeId:o,onSubmit:()=>{x.message.success("保存成功")}})}].slice(0,C?2:1)})})})}),f.jsx(x.Col,{span:7,className:"right-section",children:y&&f.jsx("div",{className:"test-section",children:f.jsx(x.Card,{variant:"borderless",className:"section-card",children:f.jsx(Q7,{ref:m,nodeId:o,beforeHook:I})})})})]})})]})]})})})},(t,e)=>ut.isEqual(ut.omit(t,["isHovered"]),ut.omit(e,["isHovered"]))),{Text:CA}=x.Typography,{TextArea:aW}=x.Input,lW=({title:t,description:e,note:n,nodeId:r,statusIcon:o,className:i="",onNoteChange:s})=>{const[a,l]=b.useState(!1),[c,u]=b.useState(""),[d,h]=b.useState(!1),p=Ct();if(b.useEffect(()=>{u(n||e||"")},[n,e]),!t&&!e&&!n)return null;const m=g=>{g.stopPropagation(),l(!0)},v=async()=>{if(!r){x.message.error("节点ID不能为空"),l(!1);return}if(c===(n||e||"")){l(!1);return}h(!0);try{await Dy(r,c),x.message.success(R("link.flow.remark_modification_success")),s==null||s(c),l(!1)}catch(g){x.message.error("备注保存失败"),console.error("保存备注失败:",g),u(n||e||"")}finally{h(!1)}},w=()=>{u(n||e||""),l(!1)},y=g=>{g.key==="Enter"&&(g.ctrlKey||g.metaKey)?v():g.key==="Escape"&&w()};return f.jsxs("div",{className:`workflow-node-description-container ${i}`,children:[t&&f.jsxs("div",{className:"workflow-node-title-row",children:[f.jsx("span",{className:"workflow-node-title-text",children:t}),o&&f.jsx("span",{className:"workflow-node-status-icon",children:o})]}),f.jsx("div",{className:"workflow-node-description-wrapper",children:a?f.jsx(x.Spin,{spinning:d,children:f.jsx(aW,{value:c,onDoubleClick:g=>g.stopPropagation(),onDragStart:g=>g.stopPropagation(),onDrag:g=>g.stopPropagation(),onChange:g=>u(g.target.value),onBlur:v,onKeyDown:y,placeholder:"请输入备注...",autoSize:{minRows:1,maxRows:4},autoFocus:!0,className:"workflow-node-note-editor nodrag"})}):p?f.jsxs("div",{className:"workflow-node-note-display is-editable",onClick:m,title:"点击编辑备注 (Ctrl+Enter保存, Esc取消)",children:[f.jsx(CA,{className:`workflow-node-description ${c?"":"workflow-node-description-placeholder"}`,children:c||"点击添加备注..."}),f.jsx(Q.EditOutlined,{className:"workflow-node-edit-icon"})]}):f.jsx("div",{className:"workflow-node-note-display",children:f.jsx(CA,{className:"workflow-node-description",children:c})})})]})},{Text:kA}=x.Typography,{TextArea:cW}=x.Input,uW=({title:t,description:e,note:n,statusIcon:r,className:o="",onNoteChange:i})=>{const[s,a]=b.useState(!1),[l,c]=b.useState(""),u=Ct();if(b.useEffect(()=>{c(n||e||"")},[n,e]),!t&&!e&&!n)return null;const d=v=>{v.stopPropagation(),a(!0)},h=()=>{if(l===(n||e||"")){a(!1);return}i==null||i(l),a(!1)},p=()=>{c(n||e||""),a(!1)},m=v=>{v.key==="Enter"&&(v.ctrlKey||v.metaKey)?h():v.key==="Escape"&&p()};return f.jsxs("div",{className:`workflow-node-description-container ${o}`,children:[t&&f.jsxs("div",{className:"workflow-node-title-row",children:[f.jsx("span",{className:"workflow-node-title-text",children:t}),r&&f.jsx("span",{className:"workflow-node-status-icon",children:r})]}),f.jsx("div",{className:"workflow-node-description-wrapper",children:s?f.jsx(cW,{value:l,onDoubleClick:v=>v.stopPropagation(),onDragStart:v=>v.stopPropagation(),onDrag:v=>v.stopPropagation(),onChange:v=>c(v.target.value),onBlur:h,onKeyDown:m,placeholder:"请输入备注...",autoSize:{minRows:1,maxRows:4},autoFocus:!0,className:"workflow-node-note-editor nodrag"}):u?f.jsxs("div",{className:"workflow-node-note-display is-editable",onClick:d,title:"点击编辑备注 (Ctrl+Enter保存, Esc取消)",children:[f.jsx(kA,{className:`workflow-node-description ${l?"":"workflow-node-description-placeholder"}`,children:l||"点击添加备注..."}),f.jsx(Q.EditOutlined,{className:"workflow-node-edit-icon"})]}):f.jsx("div",{className:"workflow-node-note-display",children:f.jsx(kA,{className:"workflow-node-description",children:l})})})]})},dW=t=>({label:t.action_name,description:t.connector_name,config_schema:t.config_schema||t.properties,...Object.entries(t).reduce((e,[n,r])=>(n!=="name"&&(e[n]=r),e),{})}),dg={color:"#3883f6"},fW=[Z.TRIGGER,Z.AI_SUB_NODE],hW=[Z.TRIGGER,Z.AI_SUB_NODE],pW=({nodeId:t,isDisabled:e=!1,handleViewConfig:n,onDelete:r,className:o,type:i})=>{const{handleNodeDataUpdate:s}=jr(),{addNodes:a,getNodes:l}=$i(),c=Wt(),u=se.useInternalNode(t),d=Ct(),h=b.useMemo(()=>{var O;const A=c.nodeTypes;if(!u)return;const S=A.types[u.type];if(S)return S;const E=(O=u.data)==null?void 0:O.category;return E?Object.values(A.types).find(F=>F.category===E):void 0},[c.nodeTypes,u]),p=b.useMemo(()=>((h==null?void 0:h.operations)||[]).reduce((S,E)=>(S[E.id]=E.enabled,S),{}),[h]),m=b.useMemo(()=>{var E,T;if(!u)return!1;const A=((E=c.canvas.fixedNodes)==null?void 0:E.triggerIds)||[],S=((T=c.nodeTypes.fixed)==null?void 0:T.triggers)||[];return A.includes(u.id)||S.includes(u.type)},[c.canvas.fixedNodes,c.nodeTypes.fixed,u]),v=b.useMemo(()=>{const A=!fW.includes(i),S=p.copy===void 0?!0:p.copy;return A&&S&&d},[i,p,d]),w=b.useMemo(()=>{const A=!hW.includes(i),S=p.disable===void 0?!0:p.disable;return A&&S&&d},[i,p,d]),y=()=>{Ay(t,e?"on":"off").then(A=>{s({id:t,data:{closed:A.closed,status:A.status}})})},g=b.useMemo(()=>c.canvas.mode!=="preview"&&!d,[c.canvas.mode,d]);b.useMemo(()=>d&&!m&&c.canvas.allowRemoveTrigger,[d,m,c.canvas.allowRemoveTrigger]);const C=()=>{r&&r(t)},D=async()=>{var S;const A=l();try{const E=A.find(F=>F.id===t);if(!E){x.message.error("获取当前节点信息失败");return}const T=(S=c.canvas.limits)==null?void 0:S.maxNodes;if(typeof T=="number"&&A.length>=T){x.message.warning("已达到画布允许的最大节点数");return}const O=await kf(t);if(O){const F=In.createNode(O.node_type,O.id,dW(O),{x:E.position.x,y:E.position.y+100});a([F]),x.message.success("节点复制成功")}}catch(E){x.message.error("节点复制失败"),console.error("复制节点失败:",E)}},k=i===Z.AI_SUB_NODE;return f.jsxs("div",{className:Sn("node-operations",o,k?"node-operations-right":""),children:[v&&f.jsx(x.Tooltip,{title:"复制节点",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Oi.IoCopyOutline,{style:dg}),onClick:D,className:Sn("operation-button")})}),w&&f.jsx(x.Tooltip,{title:e?"激活节点":"禁用节点",children:f.jsx(x.Button,{type:"text",icon:e?f.jsx(Oi.IoPlayOutline,{style:dg}):f.jsx(Oi.IoBanOutline,{style:dg}),onClick:y,className:Sn("operation-button",{disabled:e})})}),d&&f.jsx(x.Popconfirm,{title:"确定要删除此节点吗?",description:"删除后无法恢复,请谨慎操作",onConfirm:C,okText:"确定",cancelText:"取消",placement:"top",children:f.jsx(x.Tooltip,{title:"删除节点",children:f.jsx(x.Button,{type:"text",icon:f.jsx(nv.RiDeleteBin5Line,{style:{color:"red"}}),className:"operation-button delete-button"})})}),g&&f.jsx(x.Tooltip,{title:"查看配置",children:f.jsx(x.Button,{type:"link",onClick:n,icon:f.jsx(Q.EyeOutlined,{}),className:Sn("operation-button")})})]})},xA={type:Z.START,id:"PLACEHOLDER_NODE",position:{x:100,y:250},data:{type:Z.START,name:"开始",nodeId:"PLACEHOLDER_NODE",id:"PLACEHOLDER_NODE",description:"开始节点"}},mW=[Z.AGENT,Z.BROWSER,Z.MCPServer,Z.BuiltinMCP],Cd=()=>{const t=se.useStoreApi(),[e,n]=b.useState(0),o=Wt().engineMode===lr.NEXT,i=b.useCallback((u,d)=>{const{nodes:h,setNodes:p}=t.getState(),m=$n(h,v=>{const w=v.find(y=>y.id===d.id);w.data?w.data.isHovered=!0:w.data={isHovered:!0}});p(m)},[]),s=b.useCallback((u,d)=>{const{nodes:h,setNodes:p}=t.getState(),m=$n(h,v=>{const w=v.find(y=>y.id===d.id);w.data?w.data.isHovered=!1:w.data={isHovered:!1}});p(m)},[]),a=b.useCallback(u=>{const{nodes:d,setNodes:h}=t.getState(),p=$n(d,m=>{u.forEach(v=>{v.type==="select"&&(m.find(w=>w.id===v.id).selected=v.selected)})});h(p)},[t]),l=b.useCallback((u,d,h=new Set)=>(d.filter(m=>m.source===u&&m.sourceHandle!==Me.OUTPUT&&m.sourceHandle!==Me.DONE&&m.sourceHandle!==Me.LOOP&&m.sourceHandle!==Me.TRUE&&m.sourceHandle!==Me.FALSE).forEach(m=>{const v=m.target;h.has(v)||(h.add(v),l(v,d,h))}),h),[]),c=b.useCallback((u,d)=>{const{nodes:h,edges:p,setNodes:m,setEdges:v}=t.getState(),w=new Set(u);mW.includes(d)&&u.forEach(A=>{l(A,p).forEach(E=>{w.add(E)})});const y=Array.from(w),g=h.filter(A=>!y.includes(A.id)),C=g.map(A=>A.id),k=p.filter(A=>!y.includes(A.source)&&!y.includes(A.target)).filter(A=>C.includes(A.target));if(o)g.length===0&&g.push(xA);else{const A=g.some(S=>S.type===Z.TRIGGER);(g.length===0||!A)&&g.push(xA)}m(g),v(k)},[t,l]);return{autoSaveNum:e,onNodeMouseEnter:i,onNodeMouseLeave:s,handleNodesChange:a,handleNodesDelete:c}},fg={color:"#3883f6"},gW=[Z.TRIGGER,Z.AI_SUB_NODE],wW=[Z.TRIGGER,Z.AI_SUB_NODE],vW=({nodeId:t,isDisabled:e=!1,handleViewConfig:n,className:r,type:o})=>{const{handleNodeDataUpdate:i}=jr(),{addNodes:s,getNodes:a}=$i(),{handleNodesDelete:l}=Cd(),c=Wt(),u=se.useInternalNode(t),d=Ct(),h=b.useMemo(()=>{var T;const A=c.nodeTypes;if(!u)return;const S=A.types[u.type];if(S)return S;const E=(T=u.data)==null?void 0:T.category;if(E)return Object.values(A.types).find(O=>O.category===E)},[c.nodeTypes,u]),p=b.useMemo(()=>((h==null?void 0:h.operations)||[]).reduce((S,E)=>(S[E.id]=E.enabled,S),{}),[h]),m=b.useMemo(()=>{var E,T;if(!u)return!1;const A=((E=c.canvas.fixedNodes)==null?void 0:E.triggerIds)||[],S=((T=c.nodeTypes.fixed)==null?void 0:T.triggers)||[];return A.includes(u.id)||S.includes(u.type)},[c.canvas.fixedNodes,c.nodeTypes.fixed,u]),v=b.useMemo(()=>{const A=!gW.includes(o),S=p.copy===void 0?!0:p.copy;return A&&S&&d},[o,p,d]),w=b.useMemo(()=>{const A=!wW.includes(o),S=p.disable===void 0?!0:p.disable;return A&&S&&d},[o,p,d]),y=b.useMemo(()=>c.canvas.mode!=="preview"&&!d,[c.canvas.mode,d]),g=()=>{i({id:t,data:{closed:e?"0":"1",status:e?"on":"off"}})},C=()=>{if(m){x.message.warning("当前触发节点已被配置为不可删除");return}l([t],o)},D=()=>{var N;const A=a(),S=A.find(I=>I.id===t);if(!S){x.message.error("获取当前节点信息失败");return}const E=(N=c.canvas.limits)==null?void 0:N.maxNodes;if(typeof E=="number"&&A.length>=E){x.message.warning("已达到画布允许的最大节点数");return}const T=crypto.randomUUID(),O=ut.cloneDeep(S.data);O.id=T,O.nodeId=T,O.name&&(O.name=`${O.name} 副本`),O.status=void 0,O.output=void 0;const F=In.createNode(S.type,T,O,{x:S.position.x+50,y:S.position.y+100});s([F]),x.message.success("节点复制成功")},k=o===Z.AI_SUB_NODE;return f.jsxs("div",{className:Sn("node-operations",r,k?"node-operations-right":""),children:[v&&f.jsx(x.Tooltip,{title:"复制节点",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Oi.IoCopyOutline,{style:fg}),onClick:D,className:"operation-button"})}),w&&f.jsx(x.Tooltip,{title:e?"激活节点":"禁用节点",children:f.jsx(x.Button,{type:"text",icon:e?f.jsx(Oi.IoPlayOutline,{style:fg}):f.jsx(Oi.IoBanOutline,{style:fg}),onClick:g,className:Sn("operation-button",{disabled:e})})}),d&&f.jsx(x.Popconfirm,{title:"确定要删除此节点吗?",description:"删除后无法恢复,请谨慎操作",onConfirm:C,okText:"确定",cancelText:"取消",placement:"top",children:f.jsx(x.Tooltip,{title:"删除节点",children:f.jsx(x.Button,{type:"text",icon:f.jsx(nv.RiDeleteBin5Line,{style:{color:"red"}}),className:"operation-button delete-button"})})}),y&&f.jsx(x.Tooltip,{title:"查看配置",children:f.jsx(x.Button,{type:"link",onClick:n,icon:f.jsx(Q.EyeOutlined,{}),className:"operation-button"})})]})};function yW(t){const{color:e,visible:n}=t;return f.jsx("span",{style:{width:16,height:16,borderRadius:10,backgroundColor:e,display:n?"flex":"none",justifyContent:"center",alignItems:"center",position:"absolute",zIndex:1e3,top:"calc(50% - 8px)",left:-8},children:f.jsx(Q.ThunderboltOutlined,{style:{fontSize:10,color:"white"}})})}const Es={info:{normal:"#007FFF",lighter:"rgba(0, 127, 255, 0.48)"},success:{normal:"#98D7A9",lighter:"rgba(0, 176, 66, 0.48)"},warning:{normal:"#F7CD8F",lighter:"rgba(255, 146, 0, 0.48)"},error:{normal:"#F3B096",lighter:"rgba(255, 82, 25, 0.48)"},disabled:{normal:"#C7CCD1",lighter:"rgba(199, 204, 209, 0.48)"}},Bn=({id:t,type:e=Z.ACTION,selected:n=!1,icon:r,inputs:o=[],outputs:i=[],showToolbar:s=!0,width:a,height:l,className:c="",status:u=pe.IDLE,onTestNode:d,data:h,contentRender:p,showNodeDescription:m=!0,onToggleNodeDisabled:v})=>{const{currentNodeConfigVisibleId:w,setNodeConfigVisible:y}=Sr(),{handleNodeDataUpdate:g}=jr(),{handleNodesDelete:C}=Cd(),D=Wt(),k=q=>{g({id:t,data:{note:q}})},A=b.useCallback(()=>{y(null)},[]),S=(h==null?void 0:h.isHovered)||!1,E=se.useNodeConnections({id:t}),T=b.useMemo(()=>e===Z.TRIGGER,[e,E]),O=()=>{y(t)},F=b.useMemo(()=>(h==null?void 0:h.closed)==="1",[h==null?void 0:h.closed]),N=b.useMemo(()=>typeof a=="number"&&a>0?a:300,[a]),I=(q="node")=>{if(F)return`workflow-${q}-disabled`;switch(u){case pe.INVALID:return`workflow-${q}-warning`;case pe.FAILED:return`workflow-${q}-failed`;case pe.SUCCESS:case pe.RUNNABLE:return`workflow-${q}-success`;case pe.RUNNING:return`workflow-${q}-running`;case pe.IDLE:default:return""}},P=()=>{if(F)return Es.disabled;switch(u){case pe.INVALID:return Es.warning;case pe.FAILED:return Es.error;case pe.SUCCESS:case pe.RUNNABLE:return Es.success;case pe.RUNNING:return Es.info;default:return Es.info}},_=(q="normal")=>P()[q],B=()=>o.map(q=>f.jsx(w0,{nodeId:t,id:q.id,position:q.position,type:We.TARGET,label:q.label,nodeStatus:u,style:q.style},`${t}-${q.id}`)),L=async()=>{var $,V;const q=(($=D.canvas.fixedNodes)==null?void 0:$.triggerIds)||[],te=((V=D.nodeTypes.fixed)==null?void 0:V.triggers)||[];if(q.includes(t)||te.includes(e)){x.message.warning("当前触发节点已被配置为不可删除");return}await vf(t),C([t],e)},H=b.useMemo(()=>i.map(q=>f.jsx(w0,{nodeId:t,connectionLimit:q.maxConnections,id:q.id,style:q.style,position:q.position,protocol:q.protocol,type:q.type,label:q.label,shape:q.shape,nodeStatus:u},`${t}-${q.id}`)),[u,JSON.stringify(i)]),W=()=>{switch(u){case pe.INVALID:return f.jsx("div",{className:"workflow-node-status-icon workflow-node-warning-icon",children:f.jsx(Q.WarningFilled,{style:{color:_(),fontSize:16}})});case pe.FAILED:return f.jsx("div",{className:"workflow-node-status-icon workflow-node-failed-icon",children:f.jsx(Q.CloseCircleFilled,{style:{color:_(),fontSize:16}})});case pe.SUCCESS:case pe.RUNNABLE:return f.jsx("div",{className:"workflow-node-status-icon workflow-node-success-icon",children:f.jsx(Q.CheckCircleFilled,{style:{color:_(),fontSize:16}})});case pe.RUNNING:return f.jsx("div",{className:"workflow-node-status-icon workflow-node-running-icon",children:f.jsx(Q.LoadingOutlined,{style:{color:_(),fontSize:16}})});default:return null}},K=()=>f.jsxs(f.Fragment,{children:[r&&f.jsx("div",{className:"workflow-node-icon-wrapper",children:f.jsx("div",{className:"workflow-node-icon",children:r})}),m&&(D.engineMode===lr.NEXT?f.jsx(uW,{title:h==null?void 0:h.name,note:(h==null?void 0:h.note)||"",statusIcon:W(),onNoteChange:k,className:"workflow-node-text"}):f.jsx(lW,{title:h==null?void 0:h.connector_name,nodeId:t,note:(h==null?void 0:h.note)||"",statusIcon:W(),onNoteChange:k,description:h.action_name,className:"workflow-node-text"}))]});return f.jsxs(b.Fragment,{children:[f.jsxs("div",{style:{width:N,height:l||"auto"},onDoubleClick:O,className:`${c}
74
+ `),m7=b.forwardRef(({onValueChange:t=u=>{},removeTagButton:e=!1,initValue:n,onFocus:r,addImageElement:o,transformInputText:i,transformInputElement:s,textAreaMode:a,capturePattern:l=o7},c)=>{const u=b.useRef(null),d=b.useMemo(()=>f7(XC(cb()),l),[]),[h,p]=b.useState(hd(n,l));let m=n;const v=b.useCallback(({element:D,children:k,attributes:A})=>{switch(D.type){case"paragraph":return f.jsx(d7,{attributes:A,element:D,children:k});case"tag":return f.jsx(u7,{attributes:A,element:D,removeTagButton:e,addImageElement:o,transformInputText:i,transformInputElement:s,children:k});default:return f.jsx(c7,{attributes:A,element:D,children:k})}},[]);b.useEffect(()=>{p(hd(n,l))},[n]);const w=b.useCallback(D=>{u.current=d.selection;const k=p7(D);k!==m&&(m=D,p(D),t(k))},[]),y=D=>{le.delete(d,{at:[0]});const k=hd(D,l);d.children=hd("",l),le.insertNodes(d,k,{at:[0]})},g=D=>{dA(d,D,{at:u.current.focus}),le.move(d,{distance:h.length-1})};b.useImperativeHandle(c,()=>({insertTag:g,setValueByParent:y}));const C=Ct();return f.jsx(YC,{editor:d,initialValue:h,onChange:w,children:f.jsx(UC,{style:a?{minHeight:60,maxHeight:200}:{maxHeight:150},onFocus:r,value:h,readOnly:!C,spellCheck:!1,className:"ce-tag_input",renderElement:v})})}),fA=t=>f.jsx("div",{style:{display:t.show?"block":"none",height:"100%",width:"100%",...t.style??{}},children:t.children}),ir=t=>{const e=b.useMemo(()=>or(),[]),{event$:n}=b.useContext(Vr),r=b.useRef(null),[o,i]=b.useState(""),s=dt.useReactive({innerValueType:"",radioType:"",openEditorNumber:0});b.useEffect(()=>{s.radioType=t.valueType},[t.valueType,s]),n.useSubscription(u=>{var d,h,p;if(u.type==="insert"&&u.currentInputId===e){(h=r==null?void 0:(d=r.current).insertTag)==null||h.call(d,u.expression.slice(2,-2));const m=(o??"")+(t.valueType==="FIX_VALUE"?u.expression.slice(2,-2):u.expression);i(m),(p=t.onChange)==null||p.call(t,m)}});const a=b.useMemo(()=>!t.borrow&&["JS_EXP","ADAPTOR"].includes(t.valueType),[t.borrow,t.valueType]);b.useEffect(()=>{i(t.value)},[t.value]);const l=u=>{var d;(d=t.onChange)==null||d.call(t,u)},c=u=>{var d;i(u),(d=t.onChange)==null||d.call(t,u)};return f.jsxs(Vj,{id:e,canEditInEditor:!t.disableIDE,openEditorNumber:s.openEditorNumber,nodeId:t.nodeId,value:t.value,onFinish:u=>{r.current.setValueByParent(u)},children:[a&&f.jsx("div",{style:{textAlign:"right",position:"absolute",top:-34,right:2},children:f.jsxs(x.Radio.Group,{value:s.radioType,onChange:u=>{s.radioType=u.target.value,s.radioType==="ADAPTOR"&&r.current.setValueByParent(o)},size:"small",style:{marginTop:16},children:[f.jsx(x.Radio.Button,{style:{height:18,fontSize:10,display:"inline-flex",alignItems:"center"},value:"ADAPTOR",children:f.jsx(Se.FormattedMessage,{id:"link.flow.string"})}),f.jsx(x.Radio.Button,{style:{height:18,fontSize:10,display:"inline-flex",alignItems:"center"},value:"JS_EXP",children:f.jsx(Se.FormattedMessage,{id:"link.flow.script"})})]})}),f.jsx(fA,{show:s.radioType==="ADAPTOR"||!a&&s.radioType!=="PLAIN_CODE",children:f.jsx(m7,{ref:r,disabled:t.disabled,textAreaMode:t.textAreaMode,initValue:t.value,onFocus:()=>{["JS_EXP","FIX_VALUE","ADAPTOR","PLAIN_TEXT","PLAIN_CODE"].includes(t.valueType)&&(n.emit({type:"visible",visible:!0}),n.emit({type:"setCurrentInputId",currentInputId:e}))},removeTagButton:!1,onValueChange:l,addImageElement:u=>{const h=(u==null?void 0:u.split(".")[0]).slice(1),p=sl.getConfig().icons.get(h);return p?f.jsx("img",{src:p,alt:h,onError:m=>{m.target.src="/uc/images/default_connector.png"}}):f.jsx(Q.ThunderboltOutlined,{})},transformInputText:u=>ut.includes(["sys_tenant_id","response"],u)?u:u.split(".").slice(1).join("."),transformInputElement:u=>f.jsx("span",{style:{color:"blue"},children:u})})}),f.jsxs(fA,{show:(s.radioType==="JS_EXP"||s.radioType==="PLAIN_CODE")&&(s.radioType==="PLAIN_CODE"||a),style:{position:"relative"},children:[f.jsx("div",{children:f.jsx(r7,{...t,onValueChange:c})}),f.jsx("span",{onClick:()=>{s.openEditorNumber++},style:{position:"absolute",right:16,top:4,color:"white",fontSize:16,cursor:"pointer"},children:f.jsx(Q.FullscreenOutlined,{})})]})]})},g7=({value:t=[],onChange:e,valueType:n})=>{const r=u=>{let d=[...o.items];d=d.filter(h=>h.id!==u),e==null||e(d)},o=dt.useReactive({items:[]}),i=u=>{const d=u.which||u.keyCode;(d===37||d===229)&&u.preventDefault()};b.useEffect(()=>{const u=Array.isArray(t)?t:[];o.items=u.map(d=>({...d,id:d.id??or()}))},[t]);const s=()=>{e==null||e([...o.items,{key:"",value:"",id:or()}])},a=(u,d)=>{e==null||e(o.items.map(h=>h.id===u?{...h,key:d}:h))},l=(u,d)=>{e==null||e(o.items.map(h=>h.id===u?{...h,value:d}:h))},c=Ct();return f.jsxs("div",{children:[o.items.length?o.items.map((u,d)=>f.jsxs(x.Space,{size:"small",style:{display:"flex",marginBottom:8,width:"100%"},align:"center",children:[f.jsx(x.Input,{defaultValue:u.key,onKeyDown:i,onChange:h=>{var p;a(u.id,(p=h.target.value)==null?void 0:p.replace(/'/g,""))},placeholder:"Key"}),f.jsx("span",{style:{display:"inline-block",transform:"translateY(2px)",width:300},children:f.jsx(ir,{borrow:!0,disableIDE:!0,placeholder:"Value",style:{width:300},value:u.value,onChange:h=>l(u.id,h),valueType:n,nodeId:""})}),c&&f.jsx(Q.DeleteOutlined,{onClick:()=>{r(u.id)}})]},u.id)):null,f.jsxs(x.Button,{type:"dashed",onClick:s,block:!0,children:[f.jsx(Q.PlusOutlined,{})," ",f.jsx(Se.FormattedMessage,{id:"app.common.word.add-field"})]})]})},w7=t=>null,v7=t=>f.jsx(x.TimePicker,{style:{width:"100%"},use12Hours:!1,format:"HH:mm",value:t.value?Tt(t.value,"HH:mm"):null,onChange:e=>{const n=Tt(e).format("HH:mm:00");t.onChange&&(t==null||t.onChange(n))}}),{Text:y7}=x.Typography,hA=t=>f.jsx("div",{style:{padding:6,paddingRight:0,border:"1px solid #b0b5cb",borderRadius:4},children:f.jsx(x.Tooltip,{title:t.value,color:"cyan",placement:"topLeft",styles:{body:{width:500}},children:f.jsx(y7,{style:{color:"#b0b5cb"},ellipsis:!0,copyable:{text:t.value},children:t.value})})}),b7=({value:t=[],onChange:e,...n})=>{const[r,o]=b.useState([]);b.useEffect(()=>{const h=Array.isArray(t)?t:[];o(h.map(p=>({...p,id:p.id??or()})))},[t]);const i=Ct(),s=h=>{const p=r.filter(m=>m.id!==h);o(p),e==null||e(p)},a=()=>{const h={field:"",dataType:"string",desc:"",required:!1,id:or()},p=[...r,h];o(p),e(p)},l=(h,p)=>{const m=r.map(v=>v.id===h?{...v,field:p}:v);o(m),e(m)},c=(h,p)=>{const m=r.map(v=>v.id===h?{...v,dataType:p}:v);o(m),e(m)},u=(h,p)=>{const m=r.map(v=>v.id===h?{...v,desc:p}:v);o(m),e(m)},d=(h,p)=>{const m=r.map(v=>v.id===h?{...v,required:p}:v);o(m),e(m)};return f.jsxs("div",{children:[r.length?r.map(h=>f.jsxs(x.Space,{size:"small",style:{display:"flex",marginBottom:8,width:"100%"},align:"start",children:[f.jsx(x.Input,{value:h.field,onChange:p=>l(h.id,p.target.value),placeholder:"字段名称",status:"",style:{width:130},disabled:!i}),f.jsx(x.Select,{value:h.dataType,onChange:p=>c(h.id,p),placeholder:"数据类型",style:{width:100},disabled:!i,options:[{label:"字符串",value:"string"},{label:"数字",value:"number"},{label:"日期",value:"date"},{label:"布尔",value:"boolean"}]}),f.jsx(x.Input,{value:h.desc,onChange:p=>u(h.id,p.target.value),placeholder:"字段描述",status:"",style:{width:200},disabled:!i}),f.jsx(x.Select,{value:h.required,onChange:p=>d(h.id,p),placeholder:"是否必填",style:{width:100},disabled:!i,options:[{label:"是",value:!0},{label:"否",value:!1}]}),i&&f.jsx(Q.DeleteOutlined,{onClick:()=>{s(h.id)},style:{cursor:"pointer",color:"#ff4d4f",marginTop:8}})]},h.id)):null,i&&f.jsx(x.Button,{type:"dashed",onClick:a,block:!0,icon:f.jsx(Q.PlusOutlined,{}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-field"})})]})},C7=t=>{const e=b.useMemo(()=>or(),[]),{event$:n}=b.useContext(Vr),[r,o]=b.useState("");n.useSubscription(s=>{var a;if(s.type==="insert"&&s.currentInputId===e){const l=(r??"")+(t.valueType==="FIX_VALUE"?s.expression.slice(2,-2):s.expression);o(l),(a=t.onChange)==null||a.call(t,l)}}),b.useEffect(()=>{o(t.value)},[t.value]);const i=s=>{var a;o(s.target.value),(a=t.onChange)==null||a.call(t,s.target.value)};return f.jsx(x.Input.Password,{id:e,onFocus:()=>{(t.valueType==="JS_EXP"||t.valueType==="FIX_VALUE"||t.valueType==="PLAIN_TEXT"||t.valueType==="PLAIN_CODE")&&(n.emit({type:"visible",visible:!0}),n.emit({type:"setCurrentInputId",currentInputId:e}))},value:r,addonBefore:R("link.flow.cipherText"),onChange:i})},k7=t=>{var o;const e=or(),{multiple:n,...r}=t;return f.jsx(x.Select,{id:e,style:{borderRadius:6},mode:n?"multiple":void 0,...r,getPopupContainer:i=>i.parentNode,children:(o=t==null?void 0:t.options)==null?void 0:o.map(i=>f.jsx(x.Select.Option,{label:i.label,value:i.value,children:i.label},i.value))})},x7=t=>f.jsx(x.TimePicker,{style:{width:"100%"},value:t.value?Tt(t.value,"HH:mm:ss"):null,onChange:e=>{t.onChange&&(t==null||t.onChange(e==null?void 0:e.format("HH:mm:ss")))}}),S7=["sample","test","payload","body"],E7=["测试","样本","sample","test","payload","body"],pA=t=>{var n,r,o;return[ye.JSON,ye.TEXTAREA,ye.FIXED_OBJ].includes(t.page_control)?!0:((o=(r=(n=t.value_type)==null?void 0:n.toLowerCase)==null?void 0:r.call(n))==null?void 0:o.includes("json"))??!1},mA=(t,e)=>{if(!t)return!1;const n=t.toLowerCase();return e.some(r=>n.includes(r))},D7=t=>{if(t==null)return;const e=(t==null?void 0:t.data)!==void 0?t.data:t;if(typeof e=="string")try{const n=JSON.parse(e);return JSON.stringify(n,null,2)}catch{return e}try{return JSON.stringify(e,null,2)}catch{return}},A7=t=>{const{form:e,configList:n=[],disabled:r,...o}=t;Df();const[i,s]=b.useState(!1),[a,l]=b.useState(0),c=b.useRef(void 0),u=lo(),d=b.useMemo(()=>{const m=n.find(v=>pA(v)&&(mA(v.name,S7)||mA(v.display_name,E7)));return m||n.find(v=>pA(v))},[n]),h=b.useCallback(()=>{c.current&&(clearInterval(c.current),c.current=void 0)},[]);b.useEffect(()=>()=>{h()},[h]);const p=b.useCallback(async()=>{if(!u){x.message.warning("缺少连接流ID,无法监听Webhook");return}if(!(d!=null&&d.name)){x.message.warning("未找到测试数据字段,无法填充监听结果");return}if(!i){s(!0),l(10),c.current=setInterval(()=>{l(m=>m<=1?(h(),0):m-1)},1e3);try{const m=await vy(u,{timeout_seconds:10}),v=D7(m);v?(e.setFieldsValue({[d.name]:v}),x.message.success("已捕获Webhook推送数据并填充测试样例")):x.message.info("监听结束,暂无新的推送数据")}catch(m){console.error("监听Webhook失败:",m),x.message.error("监听失败,请稍后重试")}finally{h(),s(!1),l(0)}}},[u,e,i,d==null?void 0:d.name,h]);return f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx("div",{style:{flex:1},children:f.jsx(hA,{...o})}),f.jsx(x.Button,{size:"small",type:"primary",ghost:!0,onClick:p,disabled:r||!(d!=null&&d.name),loading:i,style:{height:32,minWidth:110,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:i?`监听中${a?`(${a}s)`:""}`:"监听"})]})},O7={configFormContainer:"_configFormContainer_1frpl_1"};function _7(t){return YV(t==null?void 0:t.credentials)}const lg=new Map,pd=new Map,md=new Map,gd=new Map,bn="[workflow:schema-render]",T7=1;function cg(t,e){return`${t}@${e??"latest"}`}function gA(t,e,n){var o,i,s;if(!t||!n){console.warn(`${bn} skip preload classic schema cache`,{nodeKey:t,nodeVersion:e,hasSchema:!!n});return}const r=cg(t,e);console.info(`${bn} preload classic schema cache`,{cacheKey:r,nodeKey:t,nodeVersion:e,schemaVersion:n.version,inputFields:((o=n.input_fields)==null?void 0:o.length)??0,outputs:((i=n.outputs)==null?void 0:i.length)??0,credentials:((s=n.credentials)==null?void 0:s.length)??0}),md.set(r,n)}async function N7(t,e){if(!t)return console.warn(`${bn} skip classic ACM schema fetch without nodeKey`,{nodeKey:t,nodeVersion:e,endpoint:"/acm/actions/{nodeKey}/{version}"}),null;const n=e??T7;e==null&&console.warn(`${bn} fallback classic ACM schema version`,{nodeKey:t,nodeVersion:e,fallbackNodeVersion:n,reason:"node data does not include action_ver/nodeVersion after reload",endpoint:"/acm/actions/{nodeKey}/{version}"});const r=cg(t,n);if(md.has(r))return console.info(`${bn} classic schema cache hit`,{cacheKey:r,nodeKey:t,nodeVersion:n}),md.get(r);if(gd.has(r))return console.info(`${bn} classic schema request pending reuse`,{cacheKey:r,nodeKey:t,nodeVersion:n}),gd.get(r);console.info(`${bn} fetch classic schema from ACM`,{cacheKey:r,nodeKey:t,nodeVersion:n,endpoint:"/acm/actions/{nodeKey}/{version}"});const o=Zv(t,n).then(i=>{var s,a,l;return console.info(`${bn} classic schema fetch success`,{cacheKey:r,nodeKey:t,nodeVersion:n,schemaVersion:i.version,inputFields:((s=i.input_fields)==null?void 0:s.length)??0,outputs:((a=i.outputs)==null?void 0:a.length)??0,credentials:((l=i.credentials)==null?void 0:l.length)??0}),md.set(r,i),i}).catch(i=>(console.warn(`${bn} classic schema fetch failed`,{cacheKey:r,nodeKey:t,nodeVersion:n,endpoint:"/acm/actions/{nodeKey}/{version}",err:i}),null)).finally(()=>{gd.delete(r)});return gd.set(r,o),o}async function wd(t,e){if(!t)return console.warn(`${bn} skip schema fetch without nodeKey`,{nodeVersion:e}),null;const n=cg(t,e);if(lg.has(n))return console.info(`${bn} schema cache hit`,{cacheKey:n,nodeKey:t,nodeVersion:e}),lg.get(n);if(pd.has(n))return console.info(`${bn} schema request pending reuse`,{cacheKey:n,nodeKey:t,nodeVersion:e}),pd.get(n);console.info(`${bn} fetch schema from DIP`,{cacheKey:n,nodeKey:t,nodeVersion:e,endpoint:e?"/dip/api/nodes/{nodeKey}/{version}":"/dip/api/nodes/{nodeKey}"});const r=IB(t,e).then(o=>{var i,s,a;return console.info(`${bn} schema fetch success`,{cacheKey:n,nodeKey:t,nodeVersion:e,inputFields:((i=o.input_fields)==null?void 0:i.length)??0,outputs:((s=o.outputs)==null?void 0:s.length)??0,credentials:((a=o.credentials)==null?void 0:a.length)??0}),lg.set(n,o),o}).catch(o=>(console.warn(`${bn} schema fetch failed`,{cacheKey:n,nodeKey:t,nodeVersion:e,endpoint:e?"/dip/api/nodes/{nodeKey}/{version}":"/dip/api/nodes/{nodeKey}",err:o}),null)).finally(()=>{pd.delete(n)});return pd.set(n,r),r}const B7=[ye.TEXT,ye.PASSWORD,ye.SELECT,ye.EXTEND_OBJ,ye.DATE,ye.TIME,ye.DATETIME,ye.TEXTAREA,ye.FIXED_OBJ,ye.JSON],vd="[workflow:schema-render]",F7=/^\{\{([^.{}]+)\.(.+)\}\}$/,I7=t=>{switch(t.page_control){case ye.SELECT:return t.multi_valued?[]:null;case ye.EXTEND_OBJ:return{};case ye.HIDDEN:return"";case ye.TEXT:return"";case ye.PASSWORD:return"";case ye.LABEL:return"";case ye.DATE:return null;case ye.TIME:return null;case ye.DATETIME:return null;case ye.TEXTAREA:return"";case ye.FIXED_OBJ:return{};case ye.MultiRowAIExtractConfig:return[];case ye.JSON:return""}},wA=(t,e,n,r,o)=>{const i=t.display_name,s=()=>{var a,l,c;switch(t.page_control){case ye.SELECT:return f.jsx(k7,{options:XD(t.option_value_objects??t.option_values),multiple:t.multi_valued});case ye.EXTEND_OBJ:return f.jsx(g7,{valueType:t.value_type});case ye.HIDDEN:return f.jsx(w7,{});case ye.TEXT:return f.jsx(ir,{valueType:t.value_type,nodeId:e});case ye.PASSWORD:return f.jsx(C7,{valueType:t.value_type});case ye.LABEL:return(a=r==null?void 0:r.webhookField)!=null&&a.enabled&&t.name==="hookUrl"&&r.webhookField.form?f.jsx(A7,{form:r.webhookField.form,configList:r.webhookField.configList,disabled:r.webhookField.disabled}):f.jsx(hA,{});case ye.DATE:return f.jsx(uj,{});case ye.TIME:return f.jsx(x7,{});case ye.DATETIME:return f.jsx(dj,{});case ye.TEXTAREA:return f.jsx(ir,{valueType:t.value_type,textAreaMode:!0,nodeId:e});case ye.FIXED_OBJ:return f.jsx(x.Input.TextArea,{});case ye.JSON:return f.jsx(ir,{valueType:t.value_type,nodeId:e});case ye.MultiRowAIExtractConfig:return f.jsx(b7,{valueType:t.value_type});case ye.MULTI_SELECT_LIST:return f.jsx(gj,{selectType:"KNOWLEDGE_BASE"});case ye.SYNC_HOUR_MINUTE:return f.jsx(v7,{});case ye.AUTH_TOKEN:return f.jsx(rj,{disabled:(l=r==null?void 0:r.webhookField)==null?void 0:l.disabled});case ye.SECRET_KEY:return f.jsx(ij,{});case ye.SELECT_CLIENT:return f.jsx(lj,{});default:{const u=(c=o==null?void 0:o.form)==null?void 0:c.find(d=>d.name===t.page_control);return u?f.jsx(u.component,{config:t,configList:r==null?void 0:r.configList,disabled:r==null?void 0:r.disabled,form:r==null?void 0:r.form,mcpMode:n,nodeId:e}):null}}};return n&&B7.includes(t.page_control)?f.jsx("div",{children:f.jsx(x.Form.Item,{required:t.required,rules:[{required:t.required,message:t.page_control===ye.SELECT?R("link.flow.please_select")+t.display_name:R("link.flow.please_enter")+t.display_name}],label:i,name:t.name,children:f.jsx(cj,{children:s()})})},t.ui_id):f.jsx(x.Form.Item,{required:t.required,style:t.page_control===ye.HIDDEN?{display:"none"}:{},rules:[{required:t.required,message:t.page_control===ye.SELECT?R("link.flow.please_select")+t.display_name:R("link.flow.please_enter")+t.display_name},{validator(a,l,c){if(t.page_control===ye.MultiRowAIExtractConfig)if(Array.isArray(l)&&t.required){const u=l.some(d=>!d.field||!d.dataType||!d.desc||d.required==null);c(u?"请填写完整配置":void 0)}else c(void 0);else c(void 0)}}],label:i,name:t.name,children:s()},t.ui_id)},M7=t=>(t.child_conditions??[]).map(e=>e.left).filter(e=>!!e),P7=(t,e)=>{if(!t.is_child)return!0;const n=t.child_conditions??[];return n.length?n.some(({left:r,operator:o,right:i})=>{const s=e==null?void 0:e[r];return o==="EQUALS"?s===i:s!==i}):!0},vA=b.forwardRef((t,e)=>{var z,U,X,Y;const{action:n,connector:r,nodeId:o,account_id:i,mcpMode:s}=t,a=Wt(),l=se.useStoreApi(),c=dt.useReactive({proxyId:"0"}),{config_schema:u,proxy_id:d,protocol:h}=n,p=n.action_key||n.nodeKey,m=n.action_ver??n.nodeVersion??((z=n.node_schema)==null?void 0:z.version),v=n.node_schema,w=Array.isArray(u==null?void 0:u.sub_params),y=b.useMemo(()=>w||!p?null:`${p}@${m??"latest"}`,[w,p,m]),g=y?`${o}:${y}`:o,C=n.account_id??i,D=!w&&((U=v==null?void 0:v.input_fields)!=null&&U.length||(X=v==null?void 0:v.credentials)!=null&&X.length)?v:null,[k,A]=b.useState(()=>y&&D?{identity:y,schema:D,loading:!1,finished:!0}:null),S=(k==null?void 0:k.identity)===y?k:null,E=D??(S==null?void 0:S.schema)??null,T=_7(E),O=ld((E==null?void 0:E.credentials)??[]),F=!!(!w&&p&&!E&&((S==null?void 0:S.loading)??!(S!=null&&S.finished)));b.useEffect(()=>{var ee,re;!k||k.identity===y||console.info(`${vd} classic renderer ignore stale next schema state`,{nodeId:o,nodeKey:p,nodeVersion:m,currentIdentity:y,staleIdentity:k.identity,staleLoading:k.loading,staleFinished:k.finished,staleInputFields:((re=(ee=k.schema)==null?void 0:ee.input_fields)==null?void 0:re.length)??0})},[y,k,o,p,m]),b.useEffect(()=>{d&&(c.proxyId=d)},[d]);const[N]=x.Form.useForm(),[I,P]=b.useState(C);b.useEffect(()=>{P(C)},[g,C]);const _=b.useMemo(()=>{var ee;return w?(ee=u.sub_params)==null?void 0:ee.reduce((re,ce)=>{let Ce=ce.value;return ce.page_control===ye.EXTEND_OBJ&&(Ce=VV(Ce)),re[ce.name]=Ce??I7(ce),re},{}):{}},[u==null?void 0:u.sub_params,w]);b.useEffect(()=>{w&&(N.resetFields(),N.setFieldsValue({..._}))},[_,N,w,o]);const B=b.useRef(null),L=b.useRef(null);b.useEffect(()=>{if(!y||!p){A(null);return}if(D){A({identity:y,schema:D,loading:!1,finished:!0});return}let ee=!1;return A({identity:y,schema:null,loading:!0,finished:!1}),console.info(`${vd} classic renderer load next schema`,{nodeId:o,nodeKey:p,nodeVersion:m}),N7(p,m).then(re=>{var ce;ee||(A({identity:y,schema:re,loading:!1,finished:!0}),console.info(`${vd} classic renderer next schema loaded`,{nodeId:o,nodeKey:p,nodeVersion:m,inputFields:((ce=re==null?void 0:re.input_fields)==null?void 0:ce.length)??0}))}).catch(re=>{ee||(A({identity:y,schema:null,loading:!1,finished:!0}),console.error(`${vd} classic renderer next schema load failed`,{nodeId:o,nodeKey:p,nodeVersion:m,err:re}))}),()=>{ee=!0}},[D,y,o,p,m]);const H=b.useMemo(()=>{var ee;return(ee=E==null?void 0:E.input_fields)!=null&&ee.length?il(E.input_fields):null},[E]),W=!!(!w&&(H||T||E)),K=b.useMemo(()=>n.params?n.params:u&&!w?u:{},[n,u,w]),q=b.useMemo(()=>JSON.stringify(K??{}),[K]);b.useEffect(()=>{w||!W||(N.resetFields(),N.setFieldsValue(K))},[g,N,w,K,q,W]);const te=b.useCallback(ee=>{const re=ee.trim().match(F7);if(!re)return null;const ce=re[1],Ce=re[2];if(ce==="global")return null;const Oe=ce.startsWith("N")?ce.slice(1):ce,Pe=l.getState().nodes.find(Ae=>Ae.id===Oe);return Pe?{fieldPath:Ce,node:Pe,variableNodeId:ce}:null},[l]),$=b.useCallback(ee=>{var re;return((re=te(ee))==null?void 0:re.fieldPath)??ee.replace(/^\{\{|\}\}$/g,"")},[te]),V=b.useCallback(ee=>{var Pe;const re=te(ee);if(!re)return ee;const ce=(Pe=re.node)==null?void 0:Pe.data,Ce=(ce==null?void 0:ce.label)||(ce==null?void 0:ce.name)||(ce==null?void 0:ce.action_name)||re.variableNodeId,Oe=ce!=null&&ce.note?` (${ce.note})`:"";return`${Ce}${Oe}.${re.fieldPath}`},[te]),J=(ee,re)=>N.validateFields().then(async ce=>{var Oe,Pe,Ae,fe,Ne;if(W)return re&&((Pe=(Oe=B==null?void 0:B.current)==null?void 0:Oe.onIgnoreNodeStart)==null||Pe.call(Oe)),t.onSubmit({params:ce,account_id:I,proxy_id:ce==null?void 0:ce.proxy_id},ee);const Ce=ut.cloneDeep(n.config_schema);return Ce.sub_params.forEach(Be=>{let tt=ce[Be.name];Be.page_control===ye.EXTEND_OBJ&&tt!=="{{$fromAI}}"&&(tt=Qm(tt)),Be.value=tt??null}),re&&((fe=(Ae=B==null?void 0:B.current)==null?void 0:Ae.onIgnoreNodeStart)==null||fe.call(Ae)),!i&&h==="HTTP"&&(r==null?void 0:r.deployment_type)!=="SaasApp"&&(Ce.proxy_id=(Ne=L.current)==null?void 0:Ne.getProxyId()),t.onSubmit(Ce,ee)}).catch(ce=>(console.log("err",ce),x.message.warning(R("link.flow.missing_configuration")),!1));b.useImperativeHandle(e,()=>({saveConfig:ee=>J(ee,!1)}));const ne=Ct(),ae={form:N,configList:(u==null?void 0:u.sub_params)??[],disabled:!ne,...h==="WEBHOOK"?{webhookField:{enabled:!0,form:N,configList:(u==null?void 0:u.sub_params)??[],disabled:!ne}}:{}},de=ee=>{const re=ee.page_control!==ye.HIDDEN?f.jsx("div",{style:{minHeight:10},children:f.jsx("p",{style:{color:"#999",fontSize:12,marginTop:-18,whiteSpace:"pre-wrap"},children:ee.description})}):null;if(!ee.is_child)return f.jsxs("div",{children:[wA(ee,o,s,ae,a.canvas.registerComponents),re]},ee.ui_id);const ce=M7(ee);return f.jsx(x.Form.Item,{noStyle:!0,shouldUpdate:(Ce={},Oe={})=>ee.is_child?ce.length?ce.some(Pe=>(Ce==null?void 0:Ce[Pe])!==(Oe==null?void 0:Oe[Pe])):!0:!1,children:()=>{const Ce=N.getFieldsValue(!0);return P7(ee,Ce)?f.jsxs("div",{children:[wA(ee,o,s,ae,a.canvas.registerComponents),re]}):null}},ee.ui_id)};return!w&&F?f.jsx("div",{style:{textAlign:"center",padding:40},children:f.jsx(x.Spin,{})}):W?f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsxs("div",{style:{height:"calc(100% - 50px)",minHeight:500,overflowY:"auto"},children:[T?f.jsx(ng,{credentialRequirements:O,value:I,onChange:P,linkApp:r,disabled:!ne}):null,H?f.jsx(Ri,{schema:H,form:N,initialValues:K,showSubmit:!1,showReset:!1,nodeId:o,mcpMode:s,renderVariableTag:$,renderVariableTooltip:V},g):f.jsx("div",{style:{padding:16,color:"#999",textAlign:"center"},children:"该节点暂无配置项"})]}),f.jsx("div",{style:{padding:"10px 20px",paddingBottom:10,paddingTop:30,position:"sticky",backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:ne&&f.jsx(x.Button,{type:"primary",disabled:!ne,style:{width:180,borderRadius:4},onClick:()=>J(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]}):f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsxs(x.Form,{form:N,disabled:!ne,style:{height:"calc(100% - 50px)",minHeight:500,overflowY:"auto",paddingRight:24},layout:"vertical",className:O7.configFormContainer,children:[(r==null?void 0:r.id)&&n.config_schema&&((Y=u==null?void 0:u.sub_params)==null?void 0:Y.map(ee=>de(ee))),!i&&h==="HTTP"&&(r==null?void 0:r.deployment_type)!=="SaasApp"?f.jsx(zh,{proxyId:c.proxyId,ref:L}):null]}),f.jsx("div",{style:{padding:"10px 20px",paddingBottom:10,paddingTop:30,position:"sticky",backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:ne&&f.jsx(x.Button,{type:"primary",disabled:!ne,style:{width:180,borderRadius:4},onClick:()=>J(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})}),L7=b.memo(b.forwardRef((t,e)=>{var h;const{nodeId:n,data:r}=t,{account_id:o,account_schema_id:i}=r,s=dt.useReactive({account_id:o}),a=b.useRef(null);b.useImperativeHandle(e,()=>({saveConfig:p=>{var m;return(m=a.current)==null?void 0:m.saveConfig(p)}}));const l=b.useMemo(()=>({id:t.data.connector_id,name:t.data.connector_name}),[t.data.connector_id,t.data.connector_name]),c=!!(t.data.action_key||t.data.nodeKey)&&!Array.isArray((h=t.data.config_schema)==null?void 0:h.sub_params),u=(p,m)=>{if(c){const v=(p==null?void 0:p.params)??p??{},y=Object.hasOwn(p??{},"account_id")?p.account_id??null:s.account_id;t.onSubmit({params:v,account_id:y,proxy_id:(p==null?void 0:p.proxy_id)??(v==null?void 0:v.proxy_id)},m);return}t.onSubmit({properties:p,account_id:s.account_id,proxy_id:p.proxy_id},m)},d=b.useCallback(p=>{s.account_id=p??null},[]);return f.jsxs("div",{children:[i&&!c?f.jsx(ng,{onChange:d,actionAccountSchemaId:i,value:s.account_id,linkApp:l}):null,f.jsx(vA,{ref:a,action:t.data,connector:l,account_id:o,nodeId:n,onSubmit:u})]})}),(t,e)=>t.nodeId===e.nodeId&&ut.isEqual(ut.omit(t.data,["isHovered"]),ut.omit(e.data,["isHovered"]))),yA=[{operator:Xe.eq,label:R("common.eq")},{operator:Xe.ne,label:R("common.ne")},{operator:Xe.sw,label:R("common.sw")},{operator:Xe.nsw,label:R("common.nsw")},{operator:Xe.ew,label:R("common.ew")},{operator:Xe.ewn,label:R("common.ewn")},{operator:Xe.gt,label:R("common.gt")},{operator:Xe.ge,label:R("common.ge")},{operator:Xe.lt,label:R("common.lt")},{operator:Xe.le,label:R("common.le")},{operator:Xe.co,label:R("common.co")},{operator:Xe.nco,label:R("common.nco")},{operator:Xe.in,label:R("common.in")},{operator:Xe.nin,label:R("common.nin")},{operator:Xe.is_null,label:R("common.is_null")},{operator:Xe.is_not_null,label:R("common.is_not_null")}];Xe.eq+"",R("common.eq"),Xe.ne+"",R("common.ne"),Xe.sw+"",R("common.sw"),Xe.nsw+"",R("common.nsw"),Xe.ew+"",R("common.ew"),Xe.ewn+"",R("common.ewn"),Xe.gt+"",R("common.gt"),Xe.lt+"",R("common.lt"),Xe.ge+"",R("common.ge"),Xe.co+"",R("common.co"),Xe.nco+"",R("common.nco"),Xe.le+"",R("common.le"),Xe.in+"",R("common.in"),Xe.nin+"",R("common.nin"),Xe.is_null+"",R("common.is_null"),Xe.is_not_null+"",R("common.is_not_null");const ug=t=>t===Xe.is_null||t===Xe.is_not_null,$7=(t,e="")=>ug(t)?"":e,{Option:z7}=x.Select,H7=b.forwardRef((t,e)=>{const{config_schema:n}=t,[r]=x.Form.useForm(),i=(l=>l!=null&&l.or_list?{or_list:l.or_list.map(u=>({and_list:u.and_list.map(d=>({query:d.query||"",operator:d.operator||"",value:d.value||""}))}))}:{or_list:[{and_list:[{query:"",operator:"",value:""}]}]})(n),s=(l,c,u="")=>r.validateFields().then(async d=>t.onSubmit({properties:d},l)).catch(()=>(x.message.warning(R("link.flow.missing_configuration")),!1));b.useImperativeHandle(e,()=>({saveConfig:()=>s(!0)}));const a=Ct();return f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsx("div",{style:{height:"calc(100% - 60px)",minHeight:500,overflowY:"auto",paddingRight:20},className:"grayBeautifyScrollbar",children:f.jsx(x.Form,{disabled:!a,form:r,initialValues:i,layout:"vertical",autoComplete:"off",children:f.jsx(x.Form.List,{name:"or_list",children:(l,{add:c,remove:u})=>f.jsxs(f.Fragment,{children:[l.map((d,h)=>f.jsxs("div",{style:{marginTop:10},children:[f.jsxs("div",{style:{background:"rgb(247, 248, 249)",borderRadius:8,padding:12},children:[h>0&&a&&f.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:f.jsx(x.Button,{type:"link",style:{color:"red"},icon:f.jsx(Q.MinusCircleOutlined,{style:{color:"red"}}),onClick:()=>u(d.name),children:f.jsx(Se.FormattedMessage,{id:"link.flow.remove"})})}),f.jsx(x.Form.List,{name:[d.name,"and_list"],children:(p,{add:m,remove:v})=>f.jsx(f.Fragment,{children:p.map((w,y)=>f.jsxs(x.Space,{direction:"vertical",children:[f.jsxs(x.Space,{align:"center",children:[f.jsx(x.Form.Item,{style:{minWidth:150},name:[w.name,"query"],label:R("app.common.word.variable-name"),rules:[{required:!0,message:R("link.flow.please_enter_variable_name")}],children:f.jsx(ir,{nodeId:t.nodeId,placeholder:R("link.flow.variable_name"),borrow:!0,disableIDE:!0,valueType:"JS_EXP"})}),f.jsx(x.Form.Item,{name:[w.name,"operator"],label:R("app.common.word.condition"),rules:[{required:!0,message:R("link.flow.please_select_condition")}],children:f.jsx(x.Select,{style:{minWidth:140},placeholder:R("link.flow.select_condition"),getPopupContainer:g=>g.parentNode,children:yA.map(g=>f.jsx(z7,{value:g.operator,children:g.label},g.operator))})}),f.jsx(x.Form.Item,{noStyle:!0,shouldUpdate:!0,children:()=>{const g=r.getFieldValue(["or_list",d.name,"and_list",w.name,"operator"]);return ug(g)?null:f.jsx(x.Form.Item,{style:{minWidth:150},name:[w.name,"value"],label:R("app.common.word.value"),rules:[],children:f.jsx(ir,{nodeId:t.nodeId,placeholder:R("link.flow.value"),borrow:!0,disableIDE:!0,valueType:"JS_EXP"})})}}),y===0&&f.jsx("div",{style:{width:30}}),y>0&&f.jsx(x.Button,{type:"link",icon:f.jsx(Q.MinusCircleOutlined,{}),onClick:()=>v(w.name)})]}),y<p.length-1&&f.jsx(x.Divider,{plain:!0,children:f.jsx(x.Tag,{color:"#999999",children:f.jsx(Se.FormattedMessage,{id:"link.flow.and"})})}),y===p.length-1&&f.jsx(x.Button,{type:"link",disabled:!a,icon:f.jsx(Q.PlusCircleOutlined,{}),onClick:()=>m({query:"",operator:"",value:""}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-new-and"})})]},w.key))})})]}),h<l.length-1&&f.jsxs("div",{className:"test",style:{textAlign:"center"},children:[" ",f.jsx(x.Divider,{style:{color:"orange"},dashed:!0,children:f.jsx(x.Tag,{color:"#1890ff",children:f.jsx(Se.FormattedMessage,{id:"link.flow.or"})})})]})]},d.key)),f.jsx(x.Form.Item,{children:f.jsx(x.Button,{type:"link",icon:f.jsx(Q.PlusCircleOutlined,{}),disabled:!a,onClick:()=>c({and_list:[{query:"",operator:"",value:""}]}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-or"})})})]})})})}),f.jsx("div",{style:{position:"sticky",padding:"10px 20px",paddingBottom:0,backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:a&&f.jsx(x.Button,{type:"primary",disabled:!a,style:{width:180,borderRadius:4},onClick:()=>s(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})}),V7={copy:"Copy JSON",copySuccess:"JSON copied to clipboard",download:"Download JSON",invalidJson:"Invalid JSON data"},j7={copy:"复制JSON",copySuccess:"JSON已复制到剪贴板",download:"下载JSON",invalidJson:"无效的JSON数据"},{Text:W7}=x.Typography,bA=({data:t,height:e=400,enableCopy:n=!0,theme:r="light",className:o="",locale:i="zh",maxHeight:s})=>{const[a,l]=b.useState(r),c=b.useRef(null),u=i==="zh"?j7:V7,d=b.useMemo(()=>{if(!t)return null;try{return typeof t=="string"?JSON.parse(t):t}catch(y){return console.error("JSON解析失败:",y),null}},[t]),h=b.useMemo(()=>{if(!d)return[];const y=(g,C=[],D=0)=>{const k=[];if(g===null)return[{key:C.join("."),value:null,type:"null",path:C,level:D}];if(Array.isArray(g)){const A={key:C.join("."),value:g,type:"array",path:C,level:D,children:[]};g.forEach((S,E)=>{const T=[...C,E.toString()],O=y(S,T,D+1);A.children.push(...O)}),k.push(A)}else if(typeof g=="object"){const A={key:C.join("."),value:g,type:"object",path:C,level:D,children:[]};Object.entries(g).forEach(([S,E])=>{const T=[...C,S],O=y(E,T,D+1);A.children.push(...O)}),k.push(A)}else{const A=typeof g;k.push({key:C.join("."),value:g,type:A,path:C,level:D})}return k};return y(d)},[d]),p=b.useCallback(()=>{const y=JSON.stringify(d,null,2);navigator.clipboard.writeText(y).then(()=>{x.message.success(u.copySuccess)})},[d,u]),m=b.useCallback(()=>{const y=JSON.stringify(d,null,2),g=new Blob([y],{type:"application/json"}),C=URL.createObjectURL(g),D=document.createElement("a");D.href=C,D.download="data.json",D.click(),URL.revokeObjectURL(C)},[d]),v=b.useCallback(y=>{switch(y.type){case"string":return f.jsxs("span",{className:"json-string",children:['"',y.value,'"']});case"number":return f.jsx("span",{className:"json-number",children:y.value});case"boolean":return f.jsx("span",{className:"json-boolean",children:String(y.value)});case"null":return f.jsx("span",{className:"json-null",children:"null"});default:return null}},[]),w=b.useCallback((y,g)=>{const C=y.children&&y.children.length>0,D=y.path[y.path.length-1];return y.type==="object"||y.type==="array"?f.jsxs("div",{className:"json-node",children:[f.jsxs("div",{className:"json-line",style:{paddingLeft:`${y.level*16}px`},children:[D&&f.jsxs("span",{className:"json-key",children:['"',D,'": ']}),f.jsx("span",{className:"json-bracket",children:y.type==="array"?"[":"{"}),!C&&f.jsx("span",{className:"json-bracket",children:y.type==="array"?"]":"}"})]}),C&&f.jsxs(f.Fragment,{children:[y.children.map((k,A)=>w(k,g+A+1)),f.jsx("div",{className:"json-line",style:{paddingLeft:`${y.level*16}px`},children:f.jsx("span",{className:"json-bracket",children:y.type==="array"?"]":"}"})})]})]},y.key):f.jsx("div",{className:"json-node",children:f.jsxs("div",{className:"json-line",style:{paddingLeft:`${y.level*16}px`},children:[D&&f.jsxs("span",{className:"json-key",children:['"',D,'": ']}),v(y)]})},y.key)},[v,u]);return b.useCallback(()=>{l(a==="dark"?"light":"dark")},[a]),d?f.jsxs("div",{className:`json-renderer ${a} ${o}`,children:[f.jsx("div",{className:"json-toolbar",children:f.jsxs(x.Space,{children:[n&&f.jsx(x.Tooltip,{title:u.copy,children:f.jsx(x.Button,{icon:f.jsx(Q.CopyOutlined,{}),size:"small",onClick:p})}),f.jsx(x.Tooltip,{title:u.download,children:f.jsx(x.Button,{icon:f.jsx(Q.DownloadOutlined,{}),size:"small",onClick:m})})]})}),f.jsx("div",{ref:c,className:"json-content",style:{height:`${e}px`,maxHeight:s?`${s}px`:void 0},children:h.map((y,g)=>w(y,g))})]}):f.jsx("div",{className:`json-renderer error ${a} ${o}`,children:f.jsx("div",{className:"error-message",children:f.jsx(W7,{type:"secondary",children:u.invalidJson})})})},jr=()=>{const t=se.useStoreApi(),{setNodes:e}=se.useReactFlow(),n=Wt();return{handleNodeDataUpdate:b.useCallback(({id:o,data:i,sync:s})=>{const{nodes:a}=t.getState(),l=n.engineMode===lr.NEXT,c=$n(a,u=>{const d=u.find(h=>h.id===o);d&&(d.data={...d.data,...i}),s&&!l&&Ml(o,{flow_id:n.flowId,properties:d.data.config_schema})});e(c)},[t])}},U7=t=>typeof t=="string"?t.trim().length>0:t!=null,q7=t=>typeof t=="string"&&t.trim().toLowerCase()==="success",G7=t=>{if(!t||typeof t!="object")return!1;const e=t;return e.result===!0?!1:e.result===!1?!0:e.error==="0"&&U7(e.error_description)&&!q7(e.error_description)},K7=t=>G7(t)?pe.FAILED:pe.SUCCESS,Y7=t=>{if(typeof t=="object")return JSON.stringify(t,null,2);if(typeof t=="string")try{const e=JSON.parse(t);return JSON.stringify(e,null,2)}catch{return t}return String(t)},{TextArea:X7}=x.Input,{Title:J7,Paragraph:R7}=x.Typography,Q7=b.forwardRef((t,e)=>{var C,D;const{nodeId:n,beforeHook:r}=t,o=Wt(),{handleNodeDataUpdate:i}=jr(),s=(D=(C=o.nodeConfigPanel)==null?void 0:C.testArea)==null?void 0:D.defaultTestResult,[a,l]=b.useState(()=>{if(s==null)return"";if(typeof s=="string")return s;try{return JSON.stringify(s,null,2)}catch{return String(s)}}),c=se.useInternalNode(n),u=dt.useReactive({testProgress:0,sampleText:"",isError:!1,editable:!1,showErrorAlert:!1,testing:!1,ignoring:!1,successShown:!1,isIgnoreSuccess:!1}),{refreshFlow:d}=Sr();b.useEffect(()=>{if(c!=null&&c.data.output&&(c.data.status===pe.SUCCESS||c.data.status===pe.RUNNABLE)){const k=typeof c.data.output=="string"?c.data.output:JSON.stringify(c.data.output,null,2);l(k),u.successShown=!0,u.isError=!1,u.showErrorAlert=!1}else if(c!=null&&c.data.output&&c.data.status===pe.FAILED){const k=typeof c.data.output=="string"?c.data.output:JSON.stringify(c.data.output,null,2);l(k),u.isError=!0,u.showErrorAlert=!0,u.successShown=!1}},[c]);const h=b.useCallback(()=>{if(!n){console.error("节点ID不能为空");return}u.testing=!0,u.testProgress=60,u.successShown=!1,u.isError=!1,u.showErrorAlert=!1,u.isIgnoreSuccess=!1,wy(n).then(k=>{const A=k,S=K7(A),E=S===pe.FAILED;u.isError=E,u.successShown=!E,u.isIgnoreSuccess=!1,u.showErrorAlert=u.isError;let T="";try{T=Y7(A)}catch(O){console.error("格式化测试结果出错:",O),T="测试结果格式化失败: "+String(O)}u.testProgress=100,l(T),i({id:n,data:{status:S,output:T}})}).catch(k=>{var E;console.error("测试失败:",k),u.testProgress=0,u.isError=!0,u.showErrorAlert=!0,u.successShown=!1,u.isIgnoreSuccess=!1;let A="测试执行失败";(E=k==null?void 0:k.response)!=null&&E.data?A=JSON.stringify(k.response.data,null,2):k!=null&&k.message&&(A=k.message);const S=JSON.stringify({error:A},null,2);l(S),i({id:n,data:{status:pe.FAILED,output:S}})}).finally(()=>{setTimeout(()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!1},500)})},[n]),p=()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!0};b.useImperativeHandle(e,()=>({onTestNode:h,finishNodeTest:p}));const m=()=>{r?r(!0):h()},v=()=>{r&&(u.testing=!0,u.ignoring=!0,u.testProgress=60,r(!0,!0,u.sampleText))},w=()=>{l(""),u.sampleText="",u.editable=!1,u.successShown=!1},y=Ct(),g=b.useMemo(()=>{var S;const k=(S=c==null?void 0:c.data)==null?void 0:S.protocol,A=c==null?void 0:c.type;return!y||k===Ie.AI_LANGUAGE_MODEL||k===Ie.AI_MEMORY||A===Z.BuiltinMCP||A===Z.MCPServer},[c]);return f.jsxs("div",{className:"node-test-container",children:[f.jsxs("div",{className:"node-test-header",children:[f.jsxs("div",{className:"header-title",children:[f.jsx(Q.RocketOutlined,{className:"title-icon"}),f.jsx(J7,{level:4,children:"节点测试"})]}),f.jsx(R7,{type:"secondary",className:"header-description",children:"点击测试按钮,实时检查节点执行效果和结果数据"})]}),f.jsxs("div",{className:"test-content",children:[y&&f.jsxs("div",{className:"action-buttons",children:[f.jsx(x.Button,{type:"primary",disabled:g||u.ignoring,icon:f.jsx(Q.RocketOutlined,{}),onClick:m,loading:u.testing&&!u.ignoring,className:"test-button",children:u.testing&&!u.ignoring?"测试中...":"开始测试"}),f.jsx(x.Button,{type:"primary",disabled:g||u.testing&&!u.ignoring,ghost:!0,onClick:v,loading:u.testing&&u.ignoring,className:"ignore-button",children:"忽略调试"}),a&&f.jsx(x.Button,{icon:f.jsx(Q.ReloadOutlined,{}),onClick:w,className:"reset-button",children:"重置"})]}),u.testProgress>0&&f.jsx(x.Progress,{percent:u.testProgress,status:u.isError?"exception":"active",className:"test-progress"}),u.isError&&u.showErrorAlert&&f.jsx(x.Alert,{className:"error-alert",showIcon:!0,message:"测试未通过",description:"请检查节点配置是否正确",type:"error",onClose:()=>{setTimeout(()=>{u.showErrorAlert=!1},500)},closable:!0}),!u.isError&&u.successShown&&a&&!u.testing&&f.jsx(x.Alert,{className:"success-alert",showIcon:!0,message:u.isIgnoreSuccess?"忽略调试成功":"测试成功",description:u.isIgnoreSuccess?"已将样本数据预设为当前节点输出":"节点运行正常,可以查看下方返回结果",type:"success",closable:y}),u.testing?f.jsx(x.Skeleton,{active:!0,className:"result-skeleton"}):f.jsx(f.Fragment,{children:a?f.jsx(x.Card,{styles:{body:{padding:0}},title:f.jsxs("div",{className:"result-header",children:[f.jsx("div",{className:"result-title",children:u.isError?f.jsxs(f.Fragment,{children:[f.jsx(Q.CloseCircleFilled,{className:"error-icon"})," 错误数据"]}):f.jsxs(f.Fragment,{children:[u.isIgnoreSuccess?f.jsx(Q.ExperimentFilled,{className:"success-icon"}):f.jsx(Q.CheckCircleFilled,{className:"success-icon"}),u.isIgnoreSuccess?"样本数据":"测试结果"]})}),y&&f.jsx(x.Button,{size:"small",type:"link",icon:f.jsx(Q.EditOutlined,{}),onClick:()=>{if(u.editable){u.editable=!1;try{const k=JSON.parse(u.sampleText),A=JSON.stringify(k,null,2);l(A),i({id:n,data:{output:A}})}catch{l(u.sampleText)}}else u.sampleText=a,u.editable=!0},className:"edit-button",children:u.editable?"完成":"编辑"})]}),variant:"borderless",className:`result-card ${u.isError?"error-result":"success-result"}`,children:u.editable?f.jsx(X7,{rows:10,value:u.sampleText,onChange:k=>u.sampleText=k.target.value,className:"result-editor"}):f.jsx(bA,{data:a,height:300,enableCopy:!0,theme:"light"},a)}):f.jsx(x.Card,{variant:"borderless",className:"empty-result",children:f.jsx(x.Result,{icon:f.jsx(Q.RocketOutlined,{}),title:"等待测试",subTitle:'点击"开始测试"按钮开始节点测试'})})})]})]})}),{Option:Lo}=x.Select,Z7=b.forwardRef(({onSubmit:t,config_schema:e,nodeId:n},r)=>{const[o]=x.Form.useForm(),i=x.Form.useWatch("type",o);dt.useMount(()=>{e&&Object.hasOwn(e,"asc")&&o.setFieldsValue(e)});const s=(l,c,u="")=>o.validateFields().then(async d=>i&&i==="NUMBER"&&d.start>d.end?x.message.warning(R("link.flow.loop_start_end_check")):t({properties:d},l)).catch(()=>(x.message.warning(R("link.flow.missing_configuration")),!1));b.useImperativeHandle(r,()=>({saveConfig:l=>s(l)}));const a=Ct();return f.jsxs("div",{style:{width:"100%",position:"relative",height:"100%"},children:[f.jsx("div",{style:{height:"calc(100% - 60px)",overflow:"scroll"},className:"grayBeautifyScrollbar",children:f.jsxs(x.Form,{disabled:!a,form:o,layout:"vertical",children:[f.jsx(x.Form.Item,{name:"type",label:R("app.common.word.loop-data-type"),rules:[{required:!0,message:R("link.flow.please_select_data_type")}],children:f.jsxs(x.Select,{children:[f.jsx(Lo,{value:"ARRAY",children:f.jsx(Se.FormattedMessage,{id:"link.flow.array"})}),f.jsx(Lo,{value:"NUMBER",children:f.jsx(Se.FormattedMessage,{id:"common.number"})}),f.jsx(Lo,{value:"CONDITION",children:f.jsx(Se.FormattedMessage,{id:"link.flow.condition_expression"})})]})}),i&&i==="NUMBER"&&f.jsxs(x.Form.Item,{required:!0,label:R("link.flow.loop_start_end"),style:{display:"flex"},children:[f.jsx(x.Form.Item,{name:"start",noStyle:!0,rules:[{required:!0,message:R("link.flow.please_select_data_type")}],children:f.jsx(x.InputNumber,{min:1,style:{marginRight:20}})}),f.jsx(x.Form.Item,{name:"end",noStyle:!0,rules:[{required:!0,message:R("link.flow.please_select_data_type")}],children:f.jsx(x.InputNumber,{min:1})})]}),i&&i!=="NUMBER"&&f.jsx(x.Form.Item,{rules:[{required:!0,message:R("link.flow.please_enter_loop_expression")}],label:R("link.flow.loop_expression"),name:"expression",children:f.jsx(ir,{nodeId:n,borrow:!0,valueType:"JS_EXP",placeholder:R("link.flow.please_enter_loop_expression")})}),f.jsx(x.Form.Item,{name:"asc",label:R("app.common.word.circulation-direction"),rules:[{required:!0,message:R("link.flow.please_select_loop_direction")}],children:f.jsxs(x.Select,{children:[f.jsx(Lo,{value:!0,children:f.jsx(Se.FormattedMessage,{id:"link.flow.loop_head_to_tail"})}),f.jsx(Lo,{value:!1,children:f.jsx(Se.FormattedMessage,{id:"link.flow.loop_tail_to_head"})})]})}),f.jsx(x.Form.Item,{name:"errorExec",label:R("link.flow.loop_processing"),rules:[{required:!0,message:R("link.flow.please_select_loop_processing")}],children:f.jsxs(x.Select,{children:[f.jsx(Lo,{value:"END",children:f.jsx(Se.FormattedMessage,{id:"link.flow.terminate_process"})}),f.jsx(Lo,{value:"CONTINUE",children:f.jsx(Se.FormattedMessage,{id:"link.flow.continue_loop"})}),f.jsx(Lo,{value:"BREAK",children:f.jsx(Se.FormattedMessage,{id:"link.flow.break_loop"})})]})})]})}),f.jsx("div",{style:{padding:"10px 20px",marginTop:30,paddingBottom:0,backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:a&&f.jsx(x.Button,{type:"primary",disabled:!a,style:{width:180,borderRadius:4},onClick:()=>s(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})}),yd=()=>`branch_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,{Option:eW}=x.Select,tW=b.forwardRef((t,e)=>{const{config_schema:n,nodeId:r}=t,[o]=x.Form.useForm(),{handleNodeDataUpdate:i}=jr(),[s,a]=b.useState(null),[l,c]=b.useState(""),d=(D=>!(D!=null&&D.branches)||D.branches.length===0?{branches:[{id:yd(),name:R("link.flow.switch.condition_one"),or_list:[{and_list:[{query:"",operator:"",value:""}]}]},{id:yd(),name:R("link.flow.switch.condition_two"),or_list:[{and_list:[{query:"",operator:"",value:""}]}]}]}:{branches:D.branches.map((A,S)=>{var E;return{id:A.id||yd(),name:A.name||R("link.flow.switch.condition_n",{n:S+1}),or_list:((E=A.or_list)==null?void 0:E.map(T=>{var O;return{and_list:((O=T.and_list)==null?void 0:O.map(F=>({query:F.query||"",operator:F.operator||"",value:F.value||""})))||[{query:"",operator:"",value:""}]}}))||[{and_list:[{query:"",operator:"",value:""}]}]}})})(n),h=()=>{const D=o.getFieldValue("branches")||[];i({id:r,data:{config_schema:{branches:D}}})},p=(D,k)=>{a(D),c(k)},m=()=>{a(null),c("")},v=D=>{const k=ut.cloneDeep(o.getFieldValue("branches"))||[],A=l.trim();if(!A){x.message.error(R("link.flow.switch.branch_name_cannot_be_empty"));return}if(k.some((E,T)=>T!==D&&E.name===A)){x.message.error(R("link.flow.switch.branch_name_duplicate"));return}k[D].name=A,o.setFieldValue("branches",k),a(null),c(""),h()},w=(D,k)=>{const A=o.getFieldValue("branches")||[];if(k<0||k>=A.length)return;const S=[...A],[E]=S.splice(D,1);S.splice(k,0,E),o.setFieldValue("branches",S),h()},y=D=>o.validateFields().then(async k=>{if(!k.branches.some(E=>E.or_list.some(T=>T.and_list.some(O=>O.query&&O.operator)))){x.message.error(R("link.flow.switch.at_least_one_valid_branch"));return}const S=ut.cloneDeep(k);return S.branches.forEach(E=>{E.or_list.forEach(T=>{T.and_list.forEach(O=>{O.value=$7(O.operator,O.value)})})}),t.onSubmit({properties:S},D)}).catch(()=>(x.message.warning(R("link.flow.missing_configuration")),!1));b.useImperativeHandle(e,()=>({saveConfig:()=>y(!0)}));const g=Ct(),C=(D,k,A,S)=>{const T=(o.getFieldValue("branches")||[])[k],O=s===k;return f.jsxs(x.Card,{style:{marginBottom:16,borderRadius:8,border:"1px solid #d9d9d9"},bodyStyle:{padding:16},children:[f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:12},children:[f.jsx("div",{style:{display:"flex",alignItems:"center",flex:1},children:O?f.jsxs(x.Space,{children:[f.jsx(x.Input,{value:l,onChange:F=>c(F.target.value),style:{width:200},placeholder:R("link.flow.switch.enter_branch_name"),onPressEnter:()=>v(k)}),f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.CheckOutlined,{style:{color:"#52c41a"}}),onClick:()=>v(k)}),f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.CloseOutlined,{}),onClick:m})]}):f.jsxs(x.Space,{children:[f.jsx("span",{style:{fontSize:16,fontWeight:500},children:(T==null?void 0:T.name)||R("link.flow.switch.condition_n",{n:k+1})}),g&&f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.EditOutlined,{}),onClick:()=>p(k,(T==null?void 0:T.name)||"")})]})}),g&&f.jsxs(x.Space,{children:[f.jsx(x.Tooltip,{title:R("link.flow.switch.move_to_top"),children:f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.VerticalAlignTopOutlined,{}),disabled:k===0,onClick:()=>w(k,0)})}),f.jsx(x.Tooltip,{title:R("link.flow.switch.move_up"),children:f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.ArrowUpOutlined,{}),disabled:k===0,onClick:()=>w(k,k-1)})}),f.jsx(x.Tooltip,{title:R("link.flow.switch.move_down"),children:f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.ArrowDownOutlined,{}),disabled:k===A-1,onClick:()=>w(k,k+1)})}),f.jsx(x.Tooltip,{title:R("link.flow.switch.move_to_bottom"),children:f.jsx(x.Button,{type:"text",size:"small",icon:f.jsx(Q.VerticalAlignBottomOutlined,{}),disabled:k===A-1,onClick:()=>w(k,A-1)})}),f.jsx(x.Tooltip,{title:R("common.delete"),children:f.jsx(x.Button,{type:"text",size:"small",danger:!0,icon:f.jsx(Q.DeleteOutlined,{}),disabled:A<=1,onClick:()=>{if(A<=1){x.message.warning(R("link.flow.switch.at_least_one_branch"));return}S(D.name),setTimeout(()=>{h()},0)}})})]})]}),f.jsx(x.Form.Item,{name:[D.name,"name"],hidden:!0,children:f.jsx(x.Input,{})}),f.jsx(x.Form.List,{name:[D.name,"or_list"],children:(F,{add:N,remove:I})=>f.jsxs(f.Fragment,{children:[F.map((P,_)=>f.jsxs("div",{style:{marginTop:_>0?10:0},children:[f.jsxs("div",{style:{background:"rgb(247, 248, 249)",borderRadius:8,padding:12},children:[F.length>1&&g&&f.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:f.jsx(x.Button,{type:"link",style:{color:"red"},icon:f.jsx(Q.MinusCircleOutlined,{style:{color:"red"}}),onClick:()=>I(P.name),children:f.jsx(Se.FormattedMessage,{id:"link.flow.remove"})})}),f.jsx(x.Form.List,{name:[P.name,"and_list"],children:(B,{add:L,remove:H})=>f.jsx(f.Fragment,{children:B.map((W,K)=>f.jsxs(x.Space,{direction:"vertical",style:{width:"100%"},children:[f.jsxs(x.Space,{align:"center",wrap:!0,children:[f.jsx(x.Form.Item,{style:{minWidth:150,marginBottom:0},name:[W.name,"query"],label:R("app.common.word.variable-name"),rules:[{required:!0,message:R("link.flow.please_enter_variable_name")}],children:f.jsx(ir,{nodeId:t.nodeId,placeholder:R("link.flow.variable_name"),borrow:!0,disableIDE:!0,valueType:"JS_EXP"})}),f.jsx(x.Form.Item,{style:{marginBottom:0},name:[W.name,"operator"],label:R("app.common.word.condition"),rules:[{required:!0,message:R("link.flow.please_select_condition")}],children:f.jsx(x.Select,{style:{minWidth:140},placeholder:R("link.flow.select_condition"),getPopupContainer:q=>document.body,children:yA.map(q=>f.jsx(eW,{value:q.operator,children:q.label},q.operator))})}),f.jsx(x.Form.Item,{noStyle:!0,shouldUpdate:!0,children:()=>{const q=o.getFieldValue(["branches",D.name,"or_list",P.name,"and_list",W.name,"operator"]);return ug(q)?null:f.jsx(x.Form.Item,{style:{minWidth:150,marginBottom:0},name:[W.name,"value"],label:R("app.common.word.value"),rules:[],children:f.jsx(ir,{nodeId:t.nodeId,placeholder:R("link.flow.value"),borrow:!0,disableIDE:!0,valueType:"JS_EXP"})})}}),K===0&&f.jsx("div",{style:{width:30}}),K>0&&g&&f.jsx(x.Button,{type:"link",icon:f.jsx(Q.MinusCircleOutlined,{}),onClick:()=>H(W.name)})]}),K<B.length-1&&f.jsx(x.Divider,{plain:!0,style:{margin:"8px 0"},children:f.jsx(x.Tag,{color:"#999999",children:f.jsx(Se.FormattedMessage,{id:"link.flow.and"})})}),K===B.length-1&&f.jsx(x.Button,{type:"link",disabled:!g,icon:f.jsx(Q.PlusCircleOutlined,{}),onClick:()=>L({query:"",operator:"",value:""}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-new-and"})})]},W.key))})},Math.random())]}),_<F.length-1&&f.jsx("div",{style:{textAlign:"center"},children:f.jsx(x.Divider,{style:{color:"orange"},dashed:!0,children:f.jsx(x.Tag,{color:"#1890ff",children:f.jsx(Se.FormattedMessage,{id:"link.flow.or"})})})})]},P.key)),f.jsx(x.Form.Item,{style:{marginTop:12,marginBottom:0},children:f.jsx(x.Button,{type:"link",icon:f.jsx(Q.PlusCircleOutlined,{}),disabled:!g,onClick:()=>N({and_list:[{query:"",operator:"",value:""}]}),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.add-or"})})})]})})]},D.key)};return f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsx("div",{style:{height:"calc(100% - 60px)",minHeight:500,overflowY:"auto",paddingRight:20},className:"grayBeautifyScrollbar",children:f.jsx(x.Form,{disabled:!g,form:o,initialValues:d,layout:"vertical",autoComplete:"off",children:f.jsx(x.Form.List,{name:"branches",children:(D,{add:k,remove:A})=>f.jsxs(f.Fragment,{children:[D.map((S,E)=>C(S,E,D.length,A)),D.length<10&&f.jsx(x.Button,{type:"dashed",block:!0,icon:f.jsx(Q.PlusCircleOutlined,{}),disabled:!g,onClick:()=>{const S=D.length+1;k({id:yd(),name:R("link.flow.switch.condition_n",{n:S}),or_list:[{and_list:[{query:"",operator:"",value:""}]}]}),setTimeout(()=>{h()},0)},style:{marginBottom:16},children:f.jsx(Se.FormattedMessage,{id:"link.flow.switch.add_branch"})}),D.length>=10&&f.jsx("div",{style:{textAlign:"center",color:"#999",marginBottom:16},children:f.jsx(Se.FormattedMessage,{id:"link.flow.switch.max_branches_reached"})})]})})})}),f.jsx("div",{style:{position:"sticky",padding:"10px 20px",paddingBottom:0,backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:g&&f.jsx(x.Button,{type:"primary",disabled:!g,style:{width:180,borderRadius:4},onClick:()=>y(),children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})}),nW=({nodeId:t,onSubmit:e,data:n})=>{const[r]=x.Form.useForm(),o=Ct(),{refreshFlow:i}=Sr(),{setNodes:s}=se.useReactFlow(),a=b.useCallback((c,u)=>{s(d=>d.map(h=>!u&&h.id!==t?h:{...h,data:{...h.data,error_handler:c}}))},[t,s]);b.useEffect(()=>{const c=(n==null?void 0:n.error_handler)||{};r.setFieldsValue({retryEnabled:c.retry||!1,retryCount:c.retry_times||3,retryInterval:c.retry_interval||5,stepFactor:c.step_factor||1.5,maxRetryInterval:c.max_retry_interval||60,alertEnabled:c.warn_type===1,webhookUrl:c.notify_url||"",errorHandling:c.process_type===2?"ignore":"interrupt",applyToAllNodes:!!c.apply_all})},[t,r,n==null?void 0:n.error_handler]);const l=async c=>{try{const u={retry:c.retryEnabled,retry_times:c.retryEnabled?c.retryCount:void 0,retry_interval:c.retryEnabled?c.retryInterval:void 0,step_factor:c.retryEnabled?c.stepFactor:void 0,max_retry_interval:c.retryEnabled?c.maxRetryInterval:void 0,warn_type:c.alertEnabled?1:0,notify_url:c.alertEnabled?c.webhookUrl:void 0,process_type:c.errorHandling==="interrupt"?1:2,apply_all:c.applyToAllNodes};await Ml(t,{error_handler:u}),a(u,c.applyToAllNodes),c.applyToAllNodes&&i(),e()}catch{x.message.error(R("common.save_failed"))}};return f.jsxs("div",{style:{height:"100%",position:"relative"},children:[f.jsx("div",{style:{height:"calc(100% - 60px)",overflowY:"auto",paddingRight:20},children:f.jsxs(Gn.ProForm,{form:r,layout:"vertical",disabled:!o,submitter:!1,onFinish:l,children:[f.jsx(Gn.ProFormSwitch,{name:"retryEnabled",label:R("app.common.word.enable-retry")}),f.jsx(Gn.ProFormDependency,{name:["retryEnabled"],children:({retryEnabled:c})=>c?f.jsxs(f.Fragment,{children:[f.jsx(Gn.ProFormDigit,{name:"retryCount",label:R("app.common.word.retry-count"),tooltip:R("app.common.word.retry-count-tooltip"),width:"xl",fieldProps:{min:1,max:10,precision:0,style:{width:"100%"}},rules:[{required:c,message:R("app.common.word.please-enter-retry-count")}]}),f.jsx(Gn.ProFormDigit,{name:"retryInterval",label:R("app.common.word.retry-interval"),tooltip:R("app.common.word.retry-interval-tooltip"),fieldProps:{min:1,max:60,precision:0,style:{width:"100%"},addonAfter:"s"},rules:[{required:c,message:R("app.common.word.please-enter-retry-interval")}]}),f.jsx(Gn.ProFormDigit,{name:"stepFactor",label:R("app.common.word.step-factor"),tooltip:R("app.common.word.step-factor-tooltip"),width:"xl",fieldProps:{min:1,max:5,precision:1,style:{width:"100%"}},rules:[{required:c,message:R("app.common.word.please-enter-step-factor")}]}),f.jsx(Gn.ProFormDigit,{name:"maxRetryInterval",label:R("app.common.word.max-retry-interval"),tooltip:R("app.common.word.max-retry-interval-tooltip"),width:"xl",fieldProps:{min:1,max:300,precision:0,style:{width:"100%"},addonAfter:"s"},rules:[{required:c,message:R("app.common.word.please-enter-max-retry-interval")}]})]}):null}),f.jsx(Gn.ProFormSwitch,{name:"alertEnabled",label:R("app.common.word.enable-alert")}),f.jsx(Gn.ProFormDependency,{name:["alertEnabled"],children:({alertEnabled:c})=>c?f.jsx(Gn.ProFormText,{name:"webhookUrl",label:R("app.common.word.webhook-url"),placeholder:R("app.common.word.enter-webhook-url"),width:"xl",fieldProps:{style:{width:"100%"}},rules:[{required:c,message:R("app.common.word.enter-webhook-url")}]}):null}),f.jsx(Gn.ProFormSelect,{name:"errorHandling",label:R("app.common.word.error-handling"),width:"xl",fieldProps:{style:{width:"100%"}},rules:[{required:!0,message:R("app.common.word.select-error-handling")}],options:[{label:R("app.common.word.interrupt-flow"),value:"interrupt"},{label:R("app.common.word.ignore-error"),value:"ignore"}]}),f.jsx(Gn.ProFormSwitch,{name:"applyToAllNodes",label:R("app.common.word.apply-to-all-nodes")})]})}),f.jsx("div",{style:{padding:"10px 20px",position:"sticky",paddingBottom:0,backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:f.jsx(x.Button,{type:"primary",disabled:!o,onClick:()=>r.submit(),style:{width:180,borderRadius:4},children:f.jsx(Se.FormattedMessage,{id:"app.common.word.save"})})})]})},rW=b.forwardRef((t,e)=>{const{account_id:n,account_schema_id:r,action_name:o,mcp_tool_description:i,description:s}=t.data,a=t.nodeId,l=dt.useReactive({account_id:n,mcp_tool_description:i||o||s||""}),c=b.useRef(null);b.useImperativeHandle(e,()=>({saveConfig:()=>{var p;return(p=c.current)==null?void 0:p.saveConfig()}}));const u=b.useMemo(()=>({id:t.data.connector_id,name:t.data.connector_name}),[t.data.connector_id,t.data.connector_name]),d=(p,m)=>{t.onSubmit({properties:p,account_id:l.account_id,mcp_tool_description:l.mcp_tool_description},m)},h=b.useCallback(p=>{l.account_id=p??null},[]);return f.jsxs("div",{children:[r?f.jsx(ng,{onChange:h,actionAccountSchemaId:r,value:l.account_id,linkApp:u}):null,f.jsx(x.Form.Item,{layout:"vertical",label:"工具描述",children:f.jsx(x.Input,{value:l.mcp_tool_description,onChange:p=>{l.mcp_tool_description=p.target.value}})}),f.jsx(vA,{ref:c,action:t.data,connector:u,account_id:n,nodeId:a,mcpMode:!0,onSubmit:d})]})}),bd="[workflow:schema-render]",oW=()=>{const{event$:t}=b.useContext(Vr),e=jf();return t.useSubscription(n=>{n.type==="insert"&&n.expression&&e!=null&&e.activeFieldId&&e.insertVariableToActiveField(n.expression,!1)}),null},iW=t=>f.jsxs("div",{className:"node-config-title",style:{display:"flex",alignItems:"center"},children:[t.icon?f.jsx("img",{src:t.icon,alt:t.name,style:{width:24,height:24}}):null,f.jsx("div",{className:"node-config-title-name",style:{fontSize:16,fontWeight:600,marginLeft:10},children:t.name}),f.jsx("div",{className:"node-config-title-description",style:{fontSize:12,color:"gray",marginLeft:10},children:t.description})]}),sW=b.memo(({visible:t,onClose:e,data:n,nodeType:r=Z.ACTION,nodeId:o=""})=>{var P,_,B,L,H;const i=dt.useEventEmitter();Df(),se.useInternalNode(o);const{setNodeConfigVisible:s,refreshFlow:a}=Sr(),l=b.useRef(null),c=b.useRef(null),u=b.useRef(null),d=b.useRef(null),h=b.useRef(null),p=b.useRef(null),m=b.useRef(null),v=se.useStoreApi(),w=Wt(),y=((_=(P=w.nodeConfigPanel)==null?void 0:P.testArea)==null?void 0:_.allowManualTest)!==!1,g=dt.useReactive({output:"",ignore:!1}),C=b.useMemo(()=>w.nodeConfigPanel.showSettings&&![Z.TRIGGER,Z.MCP_TOOL,Z.AI_SUB_NODE].includes(r),[r,w.nodeConfigPanel.showSettings]),D=()=>{e()};b.useEffect(()=>{var W;t&&((W=l.current)==null||W.loadVariables())},[t]);const k=(n==null?void 0:n.action_id)||null,A=Array.isArray((B=n==null?void 0:n.config_schema)==null?void 0:B.sub_params),S=r===Z.ACTION&&!!(n!=null&&n.action_key||n!=null&&n.nodeKey)&&!A,E=(n==null?void 0:n.action_key)||(n==null?void 0:n.nodeKey),T=(n==null?void 0:n.action_ver)??(n==null?void 0:n.nodeVersion)??((L=n==null?void 0:n.node_schema)==null?void 0:L.version),{handleNodeDataUpdate:O}=jr();b.useEffect(()=>{var W;t&&console.info(`${bd} node config modal opened`,{nodeId:o,nodeType:r,actionId:k,isNextCompatibleNode:S,nextNodeKey:E,nextNodeVersion:T,hasConfigSchema:!!(n!=null&&n.config_schema),hasParams:!!(n!=null&&n.params),actionKey:n==null?void 0:n.action_key,actionVer:n==null?void 0:n.action_ver,dataNodeKey:n==null?void 0:n.nodeKey,dataNodeVersion:n==null?void 0:n.nodeVersion,inlineSchemaVersion:(W=n==null?void 0:n.node_schema)==null?void 0:W.version})},[k,n==null?void 0:n.config_schema,n==null?void 0:n.params,n==null?void 0:n.action_key,n==null?void 0:n.action_ver,n==null?void 0:n.nodeKey,n==null?void 0:n.nodeVersion,(H=n==null?void 0:n.node_schema)==null?void 0:H.version,S,E,T,o,r,t]);const F=b.useCallback(async(W,K)=>{const q=w.flowId;try{const te=v.getState().nodes.find(ne=>ne.id===o),$=S?W.params||W.properties||{}:W.properties,V=S?{flow_id:q,properties:$,position:te==null?void 0:te.position,action_id:k,account_id:W.account_id??null,proxy_id:W.proxy_id,action_key:E,action_ver:T}:{flow_id:q,...W,position:te==null?void 0:te.position,action_id:k};console.info(`${bd} save node config`,{nodeId:o,nodeType:r,actionId:k,isNextCompatibleNode:S,nextNodeKey:E,nextNodeVersion:T,valueKeys:Object.keys(W||{}),paramsKeys:Object.keys((W==null?void 0:W.params)||{}),propertiesKeys:Object.keys((W==null?void 0:W.properties)||{}),ignoreDebugResult:g.ignore});const J=g.ignore?await yy(o,"","","",$,g.output):await Ml(o,V);if(J)if(console.info(`${bd} save node config success`,{nodeId:o,nodeType:r,isNextCompatibleNode:S,nextNodeKey:E,nextNodeVersion:T,status:J.status}),g.ignore)m.current.finishNodeTest(),O({id:o,data:{status:pe.SUCCESS}}),x.message.success("已忽略调试结果");else{x.message.success("节点配置已保存");const ne=S?{params:$,account_id:W.account_id,action_key:E,action_ver:T,nodeKey:E,nodeVersion:T}:{};O({id:o,data:{config_schema:$,account_id:W.account_id,...ne,position:te==null?void 0:te.position,status:J.status}})}K&&!g.ignore&&m.current&&m.current.onTestNode(),g.ignore=!1,g.output=""}catch(te){console.error(`${bd} save node config failed`,{nodeId:o,nodeType:r,isNextCompatibleNode:S,nextNodeKey:E,nextNodeVersion:T,err:te}),g.ignore&&O({id:o,data:{status:pe.FAILED}})}},[k,w.flowId,n==null?void 0:n.action_key,n==null?void 0:n.action_ver,n==null?void 0:n.nodeKey,n==null?void 0:n.nodeVersion,O,S,E,T,o,r,g,v]),N=W=>{var K,q,te,$,V;return r===Z.LOOP?(K=h.current)==null?void 0:K.saveConfig(W):r===Z.CONDITION?(q=u.current)==null?void 0:q.saveConfig(W):r===Z.SWITCH?(te=d.current)==null?void 0:te.saveConfig(W):r===Z.MCP_TOOL?($=p.current)==null?void 0:$.saveConfig(W):(V=c.current)==null?void 0:V.saveConfig(W)},I=async(W,K,q)=>{var te;if(K){g.ignore=!0,g.output=q||"",await N(W)===!1&&((te=m.current)==null||te.finishNodeTest());return}if(W)try{x.message.loading("正在保存节点配置...",0),await N(W),x.message.success("节点配置已保存"),x.message.destroy()}catch($){x.message.destroy(),console.error("节点配置保存失败:",$),x.message.error("节点配置保存失败,无法执行测试")}};return f.jsx(x.Modal,{open:t,footer:null,closeIcon:null,maskClosable:!0,onCancel:()=>{s(null)},centered:!0,width:"90%",className:"nodes-config-modal",styles:{wrapper:{minWidth:1040},mask:{backgroundColor:"rgba(0, 0, 0, 0.45)"},content:{padding:0,overflow:"hidden"}},children:f.jsx(Vr.Provider,{value:{event$:i},children:f.jsxs(Vf,{children:[f.jsx(oW,{}),f.jsxs("div",{className:"nodes-config-container",children:[f.jsxs("div",{className:"nodes-config-header",children:[f.jsx("div",{className:"header-left",children:f.jsx("span",{className:"header-title",children:" 节点配置"})}),f.jsx("div",{className:"header-right",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Q.ArrowLeftOutlined,{}),onClick:D,className:"back-button",children:"返回画布"})})]}),f.jsx("div",{className:"nodes-config-content",children:f.jsxs(x.Row,{gutter:16,className:"config-row",children:[f.jsx(x.Col,{span:5,className:"left-section",children:f.jsx("div",{className:"variables-section",children:f.jsx(lA,{ref:l,nodeId:o,onInsert:()=>{},open:t})})}),f.jsx(x.Col,{span:12,className:"middle-section",children:f.jsx("div",{className:"form-section",style:{height:"100%"},children:f.jsx(x.Card,{title:f.jsx(iW,{icon:n==null?void 0:n.icon,name:n==null?void 0:n.name,description:n==null?void 0:n.description}),variant:"borderless",styles:{body:{paddingTop:0,paddingBottom:0}},className:"section-card form-card",children:f.jsx(x.Tabs,{style:{height:"100%"},items:[{key:"property",label:"参数配置",children:f.jsxs(f.Fragment,{children:[[Z.CONDITION,Z.SWITCH,Z.LOOP,Z.MCP_TOOL].includes(r)?null:f.jsx(L7,{ref:c,nodeId:o,data:n,onSubmit:F}),r===Z.CONDITION?f.jsx(H7,{ref:u,nodeId:o,config_schema:n.config_schema,onSubmit:F}):null,r===Z.SWITCH?f.jsx(tW,{ref:d,nodeId:o,config_schema:n.config_schema,onSubmit:F}):null,r===Z.LOOP?f.jsx(Z7,{ref:h,nodeId:o,config_schema:n.config_schema,onSubmit:F}):null,r===Z.MCP_TOOL?f.jsx(rW,{ref:p,nodeId:o,data:n,onSubmit:F}):null]})},{key:"setting",label:"设置",children:f.jsx(nW,{data:n,nodeId:o,onSubmit:()=>{x.message.success("保存成功")}})}].slice(0,C?2:1)})})})}),f.jsx(x.Col,{span:7,className:"right-section",children:y&&f.jsx("div",{className:"test-section",children:f.jsx(x.Card,{variant:"borderless",className:"section-card",children:f.jsx(Q7,{ref:m,nodeId:o,beforeHook:I})})})})]})})]})]})})})},(t,e)=>ut.isEqual(ut.omit(t,["isHovered"]),ut.omit(e,["isHovered"]))),{Text:CA}=x.Typography,{TextArea:aW}=x.Input,lW=({title:t,description:e,note:n,nodeId:r,statusIcon:o,className:i="",onNoteChange:s})=>{const[a,l]=b.useState(!1),[c,u]=b.useState(""),[d,h]=b.useState(!1),p=Ct();if(b.useEffect(()=>{u(n||e||"")},[n,e]),!t&&!e&&!n)return null;const m=g=>{g.stopPropagation(),l(!0)},v=async()=>{if(!r){x.message.error("节点ID不能为空"),l(!1);return}if(c===(n||e||"")){l(!1);return}h(!0);try{await Dy(r,c),x.message.success(R("link.flow.remark_modification_success")),s==null||s(c),l(!1)}catch(g){x.message.error("备注保存失败"),console.error("保存备注失败:",g),u(n||e||"")}finally{h(!1)}},w=()=>{u(n||e||""),l(!1)},y=g=>{g.key==="Enter"&&(g.ctrlKey||g.metaKey)?v():g.key==="Escape"&&w()};return f.jsxs("div",{className:`workflow-node-description-container ${i}`,children:[t&&f.jsxs("div",{className:"workflow-node-title-row",children:[f.jsx("span",{className:"workflow-node-title-text",children:t}),o&&f.jsx("span",{className:"workflow-node-status-icon",children:o})]}),f.jsx("div",{className:"workflow-node-description-wrapper",children:a?f.jsx(x.Spin,{spinning:d,children:f.jsx(aW,{value:c,onDoubleClick:g=>g.stopPropagation(),onDragStart:g=>g.stopPropagation(),onDrag:g=>g.stopPropagation(),onChange:g=>u(g.target.value),onBlur:v,onKeyDown:y,placeholder:"请输入备注...",autoSize:{minRows:1,maxRows:4},autoFocus:!0,className:"workflow-node-note-editor nodrag"})}):p?f.jsxs("div",{className:"workflow-node-note-display is-editable",onClick:m,title:"点击编辑备注 (Ctrl+Enter保存, Esc取消)",children:[f.jsx(CA,{className:`workflow-node-description ${c?"":"workflow-node-description-placeholder"}`,children:c||"点击添加备注..."}),f.jsx(Q.EditOutlined,{className:"workflow-node-edit-icon"})]}):f.jsx("div",{className:"workflow-node-note-display",children:f.jsx(CA,{className:"workflow-node-description",children:c})})})]})},{Text:kA}=x.Typography,{TextArea:cW}=x.Input,uW=({title:t,description:e,note:n,statusIcon:r,className:o="",onNoteChange:i})=>{const[s,a]=b.useState(!1),[l,c]=b.useState(""),u=Ct();if(b.useEffect(()=>{c(n||e||"")},[n,e]),!t&&!e&&!n)return null;const d=v=>{v.stopPropagation(),a(!0)},h=()=>{if(l===(n||e||"")){a(!1);return}i==null||i(l),a(!1)},p=()=>{c(n||e||""),a(!1)},m=v=>{v.key==="Enter"&&(v.ctrlKey||v.metaKey)?h():v.key==="Escape"&&p()};return f.jsxs("div",{className:`workflow-node-description-container ${o}`,children:[t&&f.jsxs("div",{className:"workflow-node-title-row",children:[f.jsx("span",{className:"workflow-node-title-text",children:t}),r&&f.jsx("span",{className:"workflow-node-status-icon",children:r})]}),f.jsx("div",{className:"workflow-node-description-wrapper",children:s?f.jsx(cW,{value:l,onDoubleClick:v=>v.stopPropagation(),onDragStart:v=>v.stopPropagation(),onDrag:v=>v.stopPropagation(),onChange:v=>c(v.target.value),onBlur:h,onKeyDown:m,placeholder:"请输入备注...",autoSize:{minRows:1,maxRows:4},autoFocus:!0,className:"workflow-node-note-editor nodrag"}):u?f.jsxs("div",{className:"workflow-node-note-display is-editable",onClick:d,title:"点击编辑备注 (Ctrl+Enter保存, Esc取消)",children:[f.jsx(kA,{className:`workflow-node-description ${l?"":"workflow-node-description-placeholder"}`,children:l||"点击添加备注..."}),f.jsx(Q.EditOutlined,{className:"workflow-node-edit-icon"})]}):f.jsx("div",{className:"workflow-node-note-display",children:f.jsx(kA,{className:"workflow-node-description",children:l})})})]})},dW=t=>({label:t.action_name,description:t.connector_name,config_schema:t.config_schema||t.properties,...Object.entries(t).reduce((e,[n,r])=>(n!=="name"&&(e[n]=r),e),{})}),dg={color:"#3883f6"},fW=[Z.TRIGGER,Z.AI_SUB_NODE],hW=[Z.TRIGGER,Z.AI_SUB_NODE],pW=({nodeId:t,isDisabled:e=!1,handleViewConfig:n,onDelete:r,className:o,type:i})=>{const{handleNodeDataUpdate:s}=jr(),{addNodes:a,getNodes:l}=$i(),c=Wt(),u=se.useInternalNode(t),d=Ct(),h=b.useMemo(()=>{var O;const A=c.nodeTypes;if(!u)return;const S=A.types[u.type];if(S)return S;const E=(O=u.data)==null?void 0:O.category;return E?Object.values(A.types).find(F=>F.category===E):void 0},[c.nodeTypes,u]),p=b.useMemo(()=>((h==null?void 0:h.operations)||[]).reduce((S,E)=>(S[E.id]=E.enabled,S),{}),[h]),m=b.useMemo(()=>{var E,T;if(!u)return!1;const A=((E=c.canvas.fixedNodes)==null?void 0:E.triggerIds)||[],S=((T=c.nodeTypes.fixed)==null?void 0:T.triggers)||[];return A.includes(u.id)||S.includes(u.type)},[c.canvas.fixedNodes,c.nodeTypes.fixed,u]),v=b.useMemo(()=>{const A=!fW.includes(i),S=p.copy===void 0?!0:p.copy;return A&&S&&d},[i,p,d]),w=b.useMemo(()=>{const A=!hW.includes(i),S=p.disable===void 0?!0:p.disable;return A&&S&&d},[i,p,d]),y=()=>{Ay(t,e?"on":"off").then(A=>{s({id:t,data:{closed:A.closed,status:A.status}})})},g=b.useMemo(()=>c.canvas.mode!=="preview"&&!d,[c.canvas.mode,d]);b.useMemo(()=>d&&!m&&c.canvas.allowRemoveTrigger,[d,m,c.canvas.allowRemoveTrigger]);const C=()=>{r&&r(t)},D=async()=>{var S;const A=l();try{const E=A.find(F=>F.id===t);if(!E){x.message.error("获取当前节点信息失败");return}const T=(S=c.canvas.limits)==null?void 0:S.maxNodes;if(typeof T=="number"&&A.length>=T){x.message.warning("已达到画布允许的最大节点数");return}const O=await kf(t);if(O){const F=In.createNode(O.node_type,O.id,dW(O),{x:E.position.x,y:E.position.y+100});a([F]),x.message.success("节点复制成功")}}catch(E){x.message.error("节点复制失败"),console.error("复制节点失败:",E)}},k=i===Z.AI_SUB_NODE;return f.jsxs("div",{className:Sn("node-operations",o,k?"node-operations-right":""),children:[v&&f.jsx(x.Tooltip,{title:"复制节点",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Oi.IoCopyOutline,{style:dg}),onClick:D,className:Sn("operation-button")})}),w&&f.jsx(x.Tooltip,{title:e?"激活节点":"禁用节点",children:f.jsx(x.Button,{type:"text",icon:e?f.jsx(Oi.IoPlayOutline,{style:dg}):f.jsx(Oi.IoBanOutline,{style:dg}),onClick:y,className:Sn("operation-button",{disabled:e})})}),d&&f.jsx(x.Popconfirm,{title:"确定要删除此节点吗?",description:"删除后无法恢复,请谨慎操作",onConfirm:C,okText:"确定",cancelText:"取消",placement:"top",children:f.jsx(x.Tooltip,{title:"删除节点",children:f.jsx(x.Button,{type:"text",icon:f.jsx(nv.RiDeleteBin5Line,{style:{color:"red"}}),className:"operation-button delete-button"})})}),g&&f.jsx(x.Tooltip,{title:"查看配置",children:f.jsx(x.Button,{type:"link",onClick:n,icon:f.jsx(Q.EyeOutlined,{}),className:Sn("operation-button")})})]})},xA={type:Z.START,id:"PLACEHOLDER_NODE",position:{x:100,y:250},data:{type:Z.START,name:"开始",nodeId:"PLACEHOLDER_NODE",id:"PLACEHOLDER_NODE",description:"开始节点"}},mW=[Z.AGENT,Z.BROWSER,Z.MCPServer,Z.BuiltinMCP],Cd=()=>{const t=se.useStoreApi(),[e,n]=b.useState(0),o=Wt().engineMode===lr.NEXT,i=b.useCallback((u,d)=>{const{nodes:h,setNodes:p}=t.getState(),m=$n(h,v=>{const w=v.find(y=>y.id===d.id);w.data?w.data.isHovered=!0:w.data={isHovered:!0}});p(m)},[]),s=b.useCallback((u,d)=>{const{nodes:h,setNodes:p}=t.getState(),m=$n(h,v=>{const w=v.find(y=>y.id===d.id);w.data?w.data.isHovered=!1:w.data={isHovered:!1}});p(m)},[]),a=b.useCallback(u=>{const{nodes:d,setNodes:h}=t.getState(),p=$n(d,m=>{u.forEach(v=>{v.type==="select"&&(m.find(w=>w.id===v.id).selected=v.selected)})});h(p)},[t]),l=b.useCallback((u,d,h=new Set)=>(d.filter(m=>m.source===u&&m.sourceHandle!==Me.OUTPUT&&m.sourceHandle!==Me.DONE&&m.sourceHandle!==Me.LOOP&&m.sourceHandle!==Me.TRUE&&m.sourceHandle!==Me.FALSE).forEach(m=>{const v=m.target;h.has(v)||(h.add(v),l(v,d,h))}),h),[]),c=b.useCallback((u,d)=>{const{nodes:h,edges:p,setNodes:m,setEdges:v}=t.getState(),w=new Set(u);mW.includes(d)&&u.forEach(A=>{l(A,p).forEach(E=>{w.add(E)})});const y=Array.from(w),g=h.filter(A=>!y.includes(A.id)),C=g.map(A=>A.id),k=p.filter(A=>!y.includes(A.source)&&!y.includes(A.target)).filter(A=>C.includes(A.target));if(o)g.length===0&&g.push(xA);else{const A=g.some(S=>S.type===Z.TRIGGER);(g.length===0||!A)&&g.push(xA)}m(g),v(k)},[t,l]);return{autoSaveNum:e,onNodeMouseEnter:i,onNodeMouseLeave:s,handleNodesChange:a,handleNodesDelete:c}},fg={color:"#3883f6"},gW=[Z.TRIGGER,Z.AI_SUB_NODE],wW=[Z.TRIGGER,Z.AI_SUB_NODE],vW=({nodeId:t,isDisabled:e=!1,handleViewConfig:n,className:r,type:o})=>{const{handleNodeDataUpdate:i}=jr(),{addNodes:s,getNodes:a}=$i(),{handleNodesDelete:l}=Cd(),c=Wt(),u=se.useInternalNode(t),d=Ct(),h=b.useMemo(()=>{var T;const A=c.nodeTypes;if(!u)return;const S=A.types[u.type];if(S)return S;const E=(T=u.data)==null?void 0:T.category;if(E)return Object.values(A.types).find(O=>O.category===E)},[c.nodeTypes,u]),p=b.useMemo(()=>((h==null?void 0:h.operations)||[]).reduce((S,E)=>(S[E.id]=E.enabled,S),{}),[h]),m=b.useMemo(()=>{var E,T;if(!u)return!1;const A=((E=c.canvas.fixedNodes)==null?void 0:E.triggerIds)||[],S=((T=c.nodeTypes.fixed)==null?void 0:T.triggers)||[];return A.includes(u.id)||S.includes(u.type)},[c.canvas.fixedNodes,c.nodeTypes.fixed,u]),v=b.useMemo(()=>{const A=!gW.includes(o),S=p.copy===void 0?!0:p.copy;return A&&S&&d},[o,p,d]),w=b.useMemo(()=>{const A=!wW.includes(o),S=p.disable===void 0?!0:p.disable;return A&&S&&d},[o,p,d]),y=b.useMemo(()=>c.canvas.mode!=="preview"&&!d,[c.canvas.mode,d]),g=()=>{i({id:t,data:{closed:e?"0":"1",status:e?"on":"off"}})},C=()=>{if(m){x.message.warning("当前触发节点已被配置为不可删除");return}l([t],o)},D=()=>{var N;const A=a(),S=A.find(I=>I.id===t);if(!S){x.message.error("获取当前节点信息失败");return}const E=(N=c.canvas.limits)==null?void 0:N.maxNodes;if(typeof E=="number"&&A.length>=E){x.message.warning("已达到画布允许的最大节点数");return}const T=crypto.randomUUID(),O=ut.cloneDeep(S.data);O.id=T,O.nodeId=T,O.name&&(O.name=`${O.name} 副本`),O.status=void 0,O.output=void 0;const F=In.createNode(S.type,T,O,{x:S.position.x+50,y:S.position.y+100});s([F]),x.message.success("节点复制成功")},k=o===Z.AI_SUB_NODE;return f.jsxs("div",{className:Sn("node-operations",r,k?"node-operations-right":""),children:[v&&f.jsx(x.Tooltip,{title:"复制节点",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Oi.IoCopyOutline,{style:fg}),onClick:D,className:"operation-button"})}),w&&f.jsx(x.Tooltip,{title:e?"激活节点":"禁用节点",children:f.jsx(x.Button,{type:"text",icon:e?f.jsx(Oi.IoPlayOutline,{style:fg}):f.jsx(Oi.IoBanOutline,{style:fg}),onClick:g,className:Sn("operation-button",{disabled:e})})}),d&&f.jsx(x.Popconfirm,{title:"确定要删除此节点吗?",description:"删除后无法恢复,请谨慎操作",onConfirm:C,okText:"确定",cancelText:"取消",placement:"top",children:f.jsx(x.Tooltip,{title:"删除节点",children:f.jsx(x.Button,{type:"text",icon:f.jsx(nv.RiDeleteBin5Line,{style:{color:"red"}}),className:"operation-button delete-button"})})}),y&&f.jsx(x.Tooltip,{title:"查看配置",children:f.jsx(x.Button,{type:"link",onClick:n,icon:f.jsx(Q.EyeOutlined,{}),className:"operation-button"})})]})};function yW(t){const{color:e,visible:n}=t;return f.jsx("span",{style:{width:16,height:16,borderRadius:10,backgroundColor:e,display:n?"flex":"none",justifyContent:"center",alignItems:"center",position:"absolute",zIndex:1e3,top:"calc(50% - 8px)",left:-8},children:f.jsx(Q.ThunderboltOutlined,{style:{fontSize:10,color:"white"}})})}const Es={info:{normal:"#007FFF",lighter:"rgba(0, 127, 255, 0.48)"},success:{normal:"#98D7A9",lighter:"rgba(0, 176, 66, 0.48)"},warning:{normal:"#F7CD8F",lighter:"rgba(255, 146, 0, 0.48)"},error:{normal:"#F3B096",lighter:"rgba(255, 82, 25, 0.48)"},disabled:{normal:"#C7CCD1",lighter:"rgba(199, 204, 209, 0.48)"}},Bn=({id:t,type:e=Z.ACTION,selected:n=!1,icon:r,inputs:o=[],outputs:i=[],showToolbar:s=!0,width:a,height:l,className:c="",status:u=pe.IDLE,onTestNode:d,data:h,contentRender:p,showNodeDescription:m=!0,onToggleNodeDisabled:v})=>{const{currentNodeConfigVisibleId:w,setNodeConfigVisible:y}=Sr(),{handleNodeDataUpdate:g}=jr(),{handleNodesDelete:C}=Cd(),D=Wt(),k=q=>{g({id:t,data:{note:q}})},A=b.useCallback(()=>{y(null)},[]),S=(h==null?void 0:h.isHovered)||!1,E=se.useNodeConnections({id:t}),T=b.useMemo(()=>e===Z.TRIGGER,[e,E]),O=()=>{y(t)},F=b.useMemo(()=>(h==null?void 0:h.closed)==="1",[h==null?void 0:h.closed]),N=b.useMemo(()=>typeof a=="number"&&a>0?a:300,[a]),I=(q="node")=>{if(F)return`workflow-${q}-disabled`;switch(u){case pe.INVALID:return`workflow-${q}-warning`;case pe.FAILED:return`workflow-${q}-failed`;case pe.SUCCESS:case pe.RUNNABLE:return`workflow-${q}-success`;case pe.RUNNING:return`workflow-${q}-running`;case pe.IDLE:default:return""}},P=()=>{if(F)return Es.disabled;switch(u){case pe.INVALID:return Es.warning;case pe.FAILED:return Es.error;case pe.SUCCESS:case pe.RUNNABLE:return Es.success;case pe.RUNNING:return Es.info;default:return Es.info}},_=(q="normal")=>P()[q],B=()=>o.map(q=>f.jsx(w0,{nodeId:t,id:q.id,position:q.position,type:We.TARGET,label:q.label,nodeStatus:u,style:q.style},`${t}-${q.id}`)),L=async()=>{var $,V;const q=(($=D.canvas.fixedNodes)==null?void 0:$.triggerIds)||[],te=((V=D.nodeTypes.fixed)==null?void 0:V.triggers)||[];if(q.includes(t)||te.includes(e)){x.message.warning("当前触发节点已被配置为不可删除");return}await vf(t),C([t],e)},H=b.useMemo(()=>i.map(q=>f.jsx(w0,{nodeId:t,connectionLimit:q.maxConnections,id:q.id,style:q.style,position:q.position,protocol:q.protocol,type:q.type,label:q.label,shape:q.shape,nodeStatus:u},`${t}-${q.id}`)),[u,JSON.stringify(i)]),W=()=>{switch(u){case pe.INVALID:return f.jsx("div",{className:"workflow-node-status-icon workflow-node-warning-icon",children:f.jsx(Q.WarningFilled,{style:{color:_(),fontSize:16}})});case pe.FAILED:return f.jsx("div",{className:"workflow-node-status-icon workflow-node-failed-icon",children:f.jsx(Q.CloseCircleFilled,{style:{color:_(),fontSize:16}})});case pe.SUCCESS:case pe.RUNNABLE:return f.jsx("div",{className:"workflow-node-status-icon workflow-node-success-icon",children:f.jsx(Q.CheckCircleFilled,{style:{color:_(),fontSize:16}})});case pe.RUNNING:return f.jsx("div",{className:"workflow-node-status-icon workflow-node-running-icon",children:f.jsx(Q.LoadingOutlined,{style:{color:_(),fontSize:16}})});default:return null}},K=()=>f.jsxs(f.Fragment,{children:[r&&f.jsx("div",{className:"workflow-node-icon-wrapper",children:f.jsx("div",{className:"workflow-node-icon",children:r})}),m&&(D.engineMode===lr.NEXT?f.jsx(uW,{title:h==null?void 0:h.name,note:(h==null?void 0:h.note)||"",statusIcon:W(),onNoteChange:k,className:"workflow-node-text"}):f.jsx(lW,{title:h==null?void 0:h.connector_name,nodeId:t,note:(h==null?void 0:h.note)||"",statusIcon:W(),onNoteChange:k,description:h.action_name,className:"workflow-node-text"}))]});return f.jsxs(b.Fragment,{children:[f.jsxs("div",{style:{width:N,height:l||"auto"},onDoubleClick:O,className:`${c}
75
75
  ${I("container")}`,children:[f.jsx(yW,{color:_("lighter"),visible:T}),f.jsxs("div",{className:`workflow-node ${n?"workflow-node-selected":""}`,style:{"--status-color":_(),"--status-color-tint":_("lighter"),...F?{opacity:.4}:{}},children:[F&&f.jsx("div",{className:"workflow-node-deactivated-line"}),f.jsx("div",{className:"workflow-node-toolbar",style:{display:s&&D.canvas.mode!=="preview"&&S?"block":"none"},children:D.engineMode===lr.NEXT?f.jsx(vW,{nodeId:t,type:e,isDisabled:F,handleViewConfig:O}):f.jsx(pW,{nodeId:t,type:e,isDisabled:F,handleViewConfig:O,onTest:d,onToggleDisabled:v,onDelete:L})}),p?p(h,W()):f.jsx("div",{className:"workflow-node-content",children:K()}),B(),H]})]}),D.engineMode!==lr.NEXT&&f.jsx(sW,{visible:t===w,onClose:A,nodeType:e,data:h,nodeId:t})]})},bW=t=>{var c,u,d,h,p,m,v,w,y,g;const{id:e,data:n,selected:r}=t,o=n.status&&n.status!==pe.IDLE?n.status:pe.IDLE,i=((c=n==null?void 0:n.backendData)==null?void 0:c.properties)&&Object.keys((u=n==null?void 0:n.backendData)==null?void 0:u.properties).length>0,s=i&&((h=(d=n==null?void 0:n.backendData)==null?void 0:d.properties)!=null&&h.display_name)?(m=(p=n==null?void 0:n.backendData)==null?void 0:p.properties)==null?void 0:m.display_name:n==null?void 0:n.label,a=i&&((w=(v=n==null?void 0:n.backendData)==null?void 0:v.properties)!=null&&w.description)?(g=(y=n==null?void 0:n.backendData)==null?void 0:y.properties)==null?void 0:g.description:n==null?void 0:n.description,l={...n,label:s,description:a};return f.jsx(Bn,{id:e,data:l,selected:r,status:o,className:"action-node",icon:n!=null&&n.icon?f.jsx("img",{src:n==null?void 0:n.icon,alt:n.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:[{id:Me.INPUT,position:se.Position.Left,type:We.TARGET}],outputs:[{id:Me.OUTPUT,position:se.Position.Right,maxConnections:1,type:We.SOURCE}]})},SA=t=>{const{data:e}=t,n=e.status?e.status:pe.IDLE;return f.jsx(Bn,{...t,type:t.type,status:n,className:"agent-node",icon:e!=null&&e.icon?f.jsx("img",{src:e==null?void 0:e.icon,alt:e.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:[{id:Me.INPUT,position:se.Position.Left,type:We.TARGET,isMain:!0}],outputs:[{id:Me.CHAT_MODEL,position:se.Position.Bottom,category:"slave",type:We.SOURCE,isMain:!0,maxConnections:1,label:"Chat Model",protocol:Ie.AI_LANGUAGE_MODEL,shape:"rhombus",style:{left:"30%",transform:"translateX(-50%)"}},{id:Me.MEMORY,position:se.Position.Bottom,category:"slave",type:We.SOURCE,protocol:Ie.AI_MEMORY,isMain:!0,label:"Memory",maxConnections:1,shape:"rhombus",style:{left:"54%",transform:"translateX(-50%)"}},{id:Me.TOOLS,position:se.Position.Bottom,category:"slave",protocol:Ie.AI_TOOL,type:We.SOURCE,isMain:!0,label:"Tools",shape:"rhombus",style:{left:"72%",transform:"translateX(-50%)"}},{id:Me.OUTPUT,position:se.Position.Right,type:We.SOURCE,maxConnections:1,isMain:!0}]})},kd=t=>{const{id:e,data:n,selected:r}=t,o=n,i=o.status?o.status:pe.IDLE;return f.jsx(Bn,{id:e,status:i,data:o,selected:r,type:Z.AI_SUB_NODE,className:"workflow-aisub-node",icon:o!=null&&o.icon?f.jsx("img",{src:o==null?void 0:o.icon,alt:o.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:[{id:Me.INPUT,position:se.Position.Top,type:We.TARGET,isMain:!0}]})},EA=t=>{const{data:e}=t,n=e.status?e.status:pe.IDLE;return f.jsx(Bn,{...t,type:t.type,status:n,className:"agent-node",icon:e!=null&&e.icon?f.jsx("img",{src:e==null?void 0:e.icon,alt:e.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:[{id:Me.INPUT,position:se.Position.Left,type:We.TARGET,isMain:!0}],outputs:[{id:Me.CHAT_MODEL,position:se.Position.Bottom,category:"slave",type:We.SOURCE,isMain:!0,maxConnections:1,label:"Chat Model",protocol:Ie.AI_LANGUAGE_MODEL,shape:"rhombus",style:{left:"50%",transform:"translateX(-50%)"}},{id:Me.OUTPUT,position:se.Position.Right,type:We.SOURCE,maxConnections:1,isMain:!0}]})},DA=t=>{const{id:e,data:n,selected:r}=t,o=n,i=o.status?o.status:pe.IDLE;return f.jsx(Bn,{id:e,status:i,data:o,selected:r,type:Z.BuiltinMCP,className:"workflow-aisub-node",icon:o!=null&&o.icon?f.jsx("img",{src:o==null?void 0:o.icon,alt:o.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:[{id:Me.INPUT,position:se.Position.Top,type:We.TARGET,isMain:!0}],outputs:[{id:Me.BUILTIN_MCP,position:se.Position.Bottom,protocol:Ie.BUILTIN_MCP,type:We.SOURCE,isMain:!0,shape:"rhombus",style:{left:"50%",transform:"translateX(-50%)"}}]})},CW=t=>{const{id:e,data:n,selected:r}=t,o=n;return f.jsx(Bn,{id:e,data:o,selected:r,type:Z.CONDITION,status:o==null?void 0:o.status,className:"condition-node",icon:o!=null&&o.icon?f.jsx("img",{src:o==null?void 0:o.icon,alt:o.label,style:{width:30,height:30}}):f.jsx(Q.FilterOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:[{id:Me.INPUT,position:se.Position.Left,type:We.TARGET,maxConnections:1,isMain:!0}],outputs:[{id:Me.TRUE,position:se.Position.Right,type:We.SOURCE,maxConnections:1,label:"true",style:{top:"33%"},isMain:!0},{id:Me.FALSE,position:se.Position.Right,maxConnections:1,type:We.SOURCE,label:"false",style:{top:"67%"}}]})},AA=b.memo(({data:t,id:e,selected:n})=>{const r=t.isHovered||!1,o={border:n?"2px solid #007fff":r?"2px solid #3395ff":"1px solid #d9d9d9",boxShadow:r?"0 0 8px rgba(0, 127, 255, 0.3)":n?"0 0 5px rgba(0, 127, 255, 0.2)":"none",transition:"all 0.2s ease",background:r?"rgba(0, 127, 255, 0.08)":"#fff"};return f.jsxs("div",{className:"custom-node",style:o,children:[f.jsx(se.Handle,{type:"target",position:se.Position.Top,style:{background:"#555"},id:"input"}),f.jsxs("div",{className:"node-content",children:[f.jsx("div",{className:"node-title",children:t.name||"Node"}),t.description&&f.jsx("div",{className:"node-description",children:t.description}),r&&f.jsx("div",{className:"hover-indicator",children:f.jsx("span",{className:"hover-badge",children:"悬停中"})})]}),f.jsx(se.Handle,{type:"source",position:se.Position.Bottom,style:{background:"#555"},id:"output"})]})}),{Option:$Z}=x.Select,kW=t=>{const{id:e,data:n,selected:r}=t,o=n;return f.jsx(Bn,{id:e,data:o,status:o==null?void 0:o.status,type:Z.LOOP,selected:r,icon:o!=null&&o.icon?f.jsx("img",{src:o==null?void 0:o.icon,alt:o.label,style:{width:30,height:30}}):f.jsx(Q.ReloadOutlined,{style:{fontSize:24,color:"#007fff"}}),className:"loop-node",inputs:[{id:Me.INPUT,position:se.Position.Left,type:We.TARGET}],outputs:[{type:We.SOURCE,position:se.Position.Right,id:Me.DONE,label:"done",maxConnections:1,style:{top:"33%"}},{type:We.SOURCE,position:se.Position.Right,id:Me.LOOP,label:"loop",maxConnections:1,style:{top:"67%"}}]})},xW=b.memo(kW),OA=t=>{const{id:e,data:n,selected:r}=t,o=n,i=o.status?o.status:pe.IDLE;return f.jsx(Bn,{id:e,status:i,data:o,selected:r,type:Z.MCPServer,className:"workflow-aisub-node",icon:o!=null&&o.icon?f.jsx("img",{src:o==null?void 0:o.icon,alt:o.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:[{id:Me.INPUT,position:se.Position.Top,type:We.TARGET,protocol:Ie.MCP_SERVER,isMain:!0}]})},_A=t=>{const{id:e,data:n,selected:r}=t,o=n,i=o.status?o.status:pe.IDLE;return f.jsx(Bn,{id:e,status:i,data:o,selected:r,type:Z.MCP_TOOL,className:"workflow-mcp-tool-node",icon:o!=null&&o.icon?f.jsx("img",{src:o==null?void 0:o.icon,alt:o.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:[{id:Me.INPUT,position:se.Position.Top,protocol:Ie.BUILTIN_MCP,type:We.TARGET,isMain:!0}]})},SW=({icon:t,label:e})=>{const n=t?f.jsx("img",{src:t,alt:e,style:{width:24,height:24}}):f.jsx(Q.ReloadOutlined,{style:{fontSize:24,color:"#007fff"}});return f.jsx(x.Badge,{offset:[-22,2],count:f.jsx(Q.ReloadOutlined,{style:{fontSize:12,color:"#007fff"}}),children:n})},EW=t=>{const{id:e,data:n,selected:r}=t,o=n;return f.jsx(Bn,{id:e,data:o,status:o==null?void 0:o.status,type:Z.SELF_LOOP,selected:r,icon:f.jsx(SW,{icon:o==null?void 0:o.icon,label:o==null?void 0:o.label}),className:"loop-node",inputs:[{id:Me.INPUT,position:se.Position.Left,type:We.TARGET}],outputs:[{type:We.SOURCE,position:se.Position.Right,id:Me.DONE,label:"done",maxConnections:1,style:{top:"33%"}},{type:We.SOURCE,position:se.Position.Right,id:Me.LOOP,label:"loop",maxConnections:1,style:{top:"67%"}}]})},DW=b.memo(EW),TA=()=>{const t=se.useNodes(),e=Ct(),{openNodeSelector:n}=_s(),r=o=>{o.stopPropagation(),n({trigger:!0})};return t.some(o=>{var i;return(i=o.type)==null?void 0:i.includes(Z.TRIGGER)})||!e?null:f.jsxs("div",{onClick:r,className:"nodrag nopan start-node",children:[f.jsx("div",{className:"start-node-icon",children:f.jsx(Q.PlusCircleOutlined,{})}),f.jsxs("div",{className:"start-node-text",children:[f.jsx("h3",{className:"start-node-text-title",children:"添加触发节点"}),f.jsx("p",{className:"start-node-text-desc",children:"触发时将执行节点后续步骤"})]})]})};function NA(t,e){const n=String(t);if(typeof e!="string")throw new TypeError("Expected character");let r=0,o=n.indexOf(e);for(;o!==-1;)r++,o=n.indexOf(e,o+e.length);return r}function zZ(){}const al=Sd(/[A-Za-z]/),hg=Sd(/[\dA-Za-z]/);function AW(t){return t!==null&&(t<32||t===127)}function Ds(t){return t!==null&&t<-2}function Fn(t){return t!==null&&(t<0||t===32)}function co(t){return t===-2||t===-1||t===32}const xd=Sd(new RegExp("\\p{P}|\\p{S}","u")),yi=Sd(/\s/);function Sd(t){return e;function e(n){return n!==null&&n>-1&&t.test(String.fromCharCode(n))}}function OW(t){if(typeof t!="string")throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}const Ed=(function(t){if(t==null)return BW;if(typeof t=="function")return Dd(t);if(typeof t=="object")return Array.isArray(t)?_W(t):TW(t);if(typeof t=="string")return NW(t);throw new Error("Expected function, string, or object as test")});function _W(t){const e=[];let n=-1;for(;++n<t.length;)e[n]=Ed(t[n]);return Dd(r);function r(...o){let i=-1;for(;++i<e.length;)if(e[i].apply(this,o))return!0;return!1}}function TW(t){const e=t;return Dd(n);function n(r){const o=r;let i;for(i in t)if(o[i]!==e[i])return!1;return!0}}function NW(t){return Dd(e);function e(n){return n&&n.type===t}}function Dd(t){return e;function e(n,r,o){return!!(FW(n)&&t.call(this,n,typeof r=="number"?r:void 0,o||void 0))}}function BW(){return!0}function FW(t){return t!==null&&typeof t=="object"&&"type"in t}function HZ(t){return t}const BA=[],IW=!0,pg=!1,MW="skip";function FA(t,e,n,r){let o;typeof e=="function"&&typeof n!="function"?(r=n,n=e):o=e;const i=Ed(o),s=r?-1:1;a(t,void 0,[])();function a(l,c,u){const d=l&&typeof l=="object"?l:{};if(typeof d.type=="string"){const p=typeof d.tagName=="string"?d.tagName:typeof d.name=="string"?d.name:void 0;Object.defineProperty(h,"name",{value:"node ("+(l.type+(p?"<"+p+">":""))+")"})}return h;function h(){let p=BA,m,v,w;if((!e||i(l,c,u[u.length-1]||void 0))&&(p=PW(n(l,u)),p[0]===pg))return p;if("children"in l&&l.children){const y=l;if(y.children&&p[0]!==MW)for(v=(r?y.children.length:-1)+s,w=u.concat(y);v>-1&&v<y.children.length;){const g=y.children[v];if(m=a(g,v,w)(),m[0]===pg)return m;v=typeof m[1]=="number"?m[1]:v+s}}return p}}}function PW(t){return Array.isArray(t)?t:typeof t=="number"?[IW,t]:t==null?BA:[t]}function LW(t,e,n){const o=Ed((n||{}).ignore||[]),i=$W(e);let s=-1;for(;++s<i.length;)FA(t,"text",a);function a(c,u){let d=-1,h;for(;++d<u.length;){const p=u[d],m=h?h.children:void 0;if(o(p,m?m.indexOf(p):void 0,h))return;h=p}if(h)return l(c,u)}function l(c,u){const d=u[u.length-1],h=i[s][0],p=i[s][1];let m=0;const w=d.children.indexOf(c);let y=!1,g=[];h.lastIndex=0;let C=h.exec(c.value);for(;C;){const D=C.index,k={index:C.index,input:C.input,stack:[...u,c]};let A=p(...C,k);if(typeof A=="string"&&(A=A.length>0?{type:"text",value:A}:void 0),A===!1?h.lastIndex=D+1:(m!==D&&g.push({type:"text",value:c.value.slice(m,D)}),Array.isArray(A)?g.push(...A):A&&g.push(A),m=D+C[0].length,y=!0),!h.global)break;C=h.exec(c.value)}return y?(m<c.value.length&&g.push({type:"text",value:c.value.slice(m)}),d.children.splice(w,1,...g)):g=[c],w+g.length}}function $W(t){const e=[];if(!Array.isArray(t))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!t[0]||Array.isArray(t[0])?t:[t];let r=-1;for(;++r<n.length;){const o=n[r];e.push([zW(o[0]),HW(o[1])])}return e}function zW(t){return typeof t=="string"?new RegExp(OW(t),"g"):t}function HW(t){return typeof t=="function"?t:function(){return t}}const mg="phrasing",gg=["autolink","link","image","label"];function VW(){return{transforms:[YW],enter:{literalAutolink:WW,literalAutolinkEmail:wg,literalAutolinkHttp:wg,literalAutolinkWww:wg},exit:{literalAutolink:KW,literalAutolinkEmail:GW,literalAutolinkHttp:UW,literalAutolinkWww:qW}}}function jW(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:mg,notInConstruct:gg},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:mg,notInConstruct:gg},{character:":",before:"[ps]",after:"\\/",inConstruct:mg,notInConstruct:gg}]}}function WW(t){this.enter({type:"link",title:null,url:"",children:[]},t)}function wg(t){this.config.enter.autolinkProtocol.call(this,t)}function UW(t){this.config.exit.autolinkProtocol.call(this,t)}function qW(t){this.config.exit.data.call(this,t);const e=this.stack[this.stack.length-1];e.type,e.url="http://"+this.sliceSerialize(t)}function GW(t){this.config.exit.autolinkEmail.call(this,t)}function KW(t){this.exit(t)}function YW(t){LW(t,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,XW],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),JW]],{ignore:["link","linkReference"]})}function XW(t,e,n,r,o){let i="";if(!IA(o)||(/^w/i.test(e)&&(n=e+n,e="",i="http://"),!RW(n)))return!1;const s=QW(n+r);if(!s[0])return!1;const a={type:"link",title:null,url:i+e+s[0],children:[{type:"text",value:e+s[0]}]};return s[1]?[a,{type:"text",value:s[1]}]:a}function JW(t,e,n,r){return!IA(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+e+"@"+n,children:[{type:"text",value:e+"@"+n}]}}function RW(t){const e=t.split(".");return!(e.length<2||e[e.length-1]&&(/_/.test(e[e.length-1])||!/[a-zA-Z\d]/.test(e[e.length-1]))||e[e.length-2]&&(/_/.test(e[e.length-2])||!/[a-zA-Z\d]/.test(e[e.length-2])))}function QW(t){const e=/[!"&'),.:;<>?\]}]+$/.exec(t);if(!e)return[t,void 0];t=t.slice(0,e.index);let n=e[0],r=n.indexOf(")");const o=NA(t,"(");let i=NA(t,")");for(;r!==-1&&o>i;)t+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),i++;return[t,n]}function IA(t,e){const n=t.input.charCodeAt(t.index-1);return(t.index===0||yi(n)||xd(n))&&(!e||n!==47)}function ll(t){return t.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}MA.peek=aU;function ZW(){this.buffer()}function eU(t){this.enter({type:"footnoteReference",identifier:"",label:""},t)}function tU(){this.buffer()}function nU(t){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},t)}function rU(t){const e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=ll(this.sliceSerialize(t)).toLowerCase(),n.label=e}function oU(t){this.exit(t)}function iU(t){const e=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=ll(this.sliceSerialize(t)).toLowerCase(),n.label=e}function sU(t){this.exit(t)}function aU(){return"["}function MA(t,e,n,r){const o=n.createTracker(r);let i=o.move("[^");const s=n.enter("footnoteReference"),a=n.enter("reference");return i+=o.move(n.safe(n.associationId(t),{after:"]",before:i})),a(),s(),i+=o.move("]"),i}function lU(){return{enter:{gfmFootnoteCallString:ZW,gfmFootnoteCall:eU,gfmFootnoteDefinitionLabelString:tU,gfmFootnoteDefinition:nU},exit:{gfmFootnoteCallString:rU,gfmFootnoteCall:oU,gfmFootnoteDefinitionLabelString:iU,gfmFootnoteDefinition:sU}}}function cU(t){let e=!1;return t&&t.firstLineBlank&&(e=!0),{handlers:{footnoteDefinition:n,footnoteReference:MA},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,o,i,s){const a=i.createTracker(s);let l=a.move("[^");const c=i.enter("footnoteDefinition"),u=i.enter("label");return l+=a.move(i.safe(i.associationId(r),{before:l,after:"]"})),u(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((e?`
76
76
  `:" ")+i.indentLines(i.containerFlow(r,a.current()),e?PA:uU))),c(),l}}function uU(t,e,n){return e===0?t:PA(t,e,n)}function PA(t,e,n){return(n?"":" ")+t}const dU=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];LA.peek=gU;function fU(){return{canContainEols:["delete"],enter:{strikethrough:pU},exit:{strikethrough:mU}}}function hU(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:dU}],handlers:{delete:LA}}}function pU(t){this.enter({type:"delete",children:[]},t)}function mU(t){this.exit(t)}function LA(t,e,n,r){const o=n.createTracker(r),i=n.enter("strikethrough");let s=o.move("~~");return s+=n.containerPhrasing(t,{...o.current(),before:s,after:"~"}),s+=o.move("~~"),i(),s}function gU(){return"~"}function wU(t){return t.length}function vU(t,e){const n=e||{},r=(n.align||[]).concat(),o=n.stringLength||wU,i=[],s=[],a=[],l=[];let c=0,u=-1;for(;++u<t.length;){const v=[],w=[];let y=-1;for(t[u].length>c&&(c=t[u].length);++y<t[u].length;){const g=yU(t[u][y]);if(n.alignDelimiters!==!1){const C=o(g);w[y]=C,(l[y]===void 0||C>l[y])&&(l[y]=C)}v.push(g)}s[u]=v,a[u]=w}let d=-1;if(typeof r=="object"&&"length"in r)for(;++d<c;)i[d]=$A(r[d]);else{const v=$A(r);for(;++d<c;)i[d]=v}d=-1;const h=[],p=[];for(;++d<c;){const v=i[d];let w="",y="";v===99?(w=":",y=":"):v===108?w=":":v===114&&(y=":");let g=n.alignDelimiters===!1?1:Math.max(1,l[d]-w.length-y.length);const C=w+"-".repeat(g)+y;n.alignDelimiters!==!1&&(g=w.length+g+y.length,g>l[d]&&(l[d]=g),p[d]=g),h[d]=C}s.splice(1,0,h),a.splice(1,0,p),u=-1;const m=[];for(;++u<s.length;){const v=s[u],w=a[u];d=-1;const y=[];for(;++d<c;){const g=v[d]||"";let C="",D="";if(n.alignDelimiters!==!1){const k=l[d]-(w[d]||0),A=i[d];A===114?C=" ".repeat(k):A===99?k%2?(C=" ".repeat(k/2+.5),D=" ".repeat(k/2-.5)):(C=" ".repeat(k/2),D=C):D=" ".repeat(k)}n.delimiterStart!==!1&&!d&&y.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&g==="")&&(n.delimiterStart!==!1||d)&&y.push(" "),n.alignDelimiters!==!1&&y.push(C),y.push(g),n.alignDelimiters!==!1&&y.push(D),n.padding!==!1&&y.push(" "),(n.delimiterEnd!==!1||d!==c-1)&&y.push("|")}m.push(n.delimiterEnd===!1?y.join("").replace(/ +$/,""):y.join(""))}return m.join(`
77
77
  `)}function yU(t){return t==null?"":String(t)}function $A(t){const e=typeof t=="string"?t.codePointAt(0):0;return e===67||e===99?99:e===76||e===108?108:e===82||e===114?114:0}function bU(t,e,n,r){const o=n.enter("blockquote"),i=n.createTracker(r);i.move("> "),i.shift(2);const s=n.indentLines(n.containerFlow(t,i.current()),CU);return o(),s}function CU(t,e,n){return">"+(n?"":" ")+t}function kU(t,e){return zA(t,e.inConstruct,!0)&&!zA(t,e.notInConstruct,!1)}function zA(t,e,n){if(typeof e=="string"&&(e=[e]),!e||e.length===0)return n;let r=-1;for(;++r<e.length;)if(t.includes(e[r]))return!0;return!1}function HA(t,e,n,r){let o=-1;for(;++o<n.unsafe.length;)if(n.unsafe[o].character===`
@@ -99,7 +99,7 @@ ${n}`:""}`}).join(`
99
99
  `):"暂无日志",Md=async t=>{var e;try{if((e=navigator==null?void 0:navigator.clipboard)!=null&&e.writeText)return await navigator.clipboard.writeText(t),!0}catch{}try{const n=document.createElement("textarea");n.value=t,n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.focus(),n.select();const r=document.execCommand("copy");return document.body.removeChild(n),r}catch{return!1}},F_=(t,e,n)=>{const r=new Map(t.map(l=>[l.id,l])),o=new Map(e.map(l=>[l.id,l])),i=[],s=[],a=[];return o.forEach((l,c)=>{if(!r.has(c)){i.push(c);return}const u=O_(n(r.get(c))),d=O_(n(l));u!==d&&a.push(c)}),r.forEach((l,c)=>{o.has(c)||s.push(c)}),{added:i,removed:s,changed:a}},lY=({visible:t,nodes:e,edges:n,onClose:r})=>{const[o,i]=b.useState([]),[s,a]=b.useState(!1),[l,c]=b.useState(!1),[u,d]=b.useState(),[h,p]=b.useState(),m=b.useRef({nodes:[],edges:[]});b.useEffect(()=>{const _=m.current;if(m.current={nodes:e,edges:n},!t)return;const B=F_(_.nodes,e,Ew),L=F_(_.edges,n,Dw),H=B.added.length+B.removed.length+B.changed.length>0,W=L.added.length+L.removed.length+L.changed.length>0;if(!H&&!W)return;const K=new Map(e.map(ae=>[ae.id,xi(ae)])),q=Object.fromEntries(K.entries()),te=__(n,K),$=T_(n,K),V={nodeDiff:B,edgeDiff:L,nodeCount:{prev:_.nodes.length,next:e.length},edgeCount:{prev:_.edges.length,next:n.length},edgeRelations:te,nodeNameMap:q,duplicateEdges:$},J=[];H&&J.push(`节点 +${B.added.length} -${B.removed.length} ~${B.changed.length}`),W&&J.push(`连线 +${L.added.length} -${L.removed.length} ~${L.changed.length}`);const ne={id:`${Date.now()}-${Math.random()}`,time:A_(),message:J.join(" | "),nodeSummary:H?{added:B.added.length,removed:B.removed.length,changed:B.changed.length}:void 0,edgeSummary:W?{added:L.added.length,removed:L.removed.length,changed:L.changed.length}:void 0,edgeRelations:te,duplicateEdges:$,detail:V,expanded:!1};i(ae=>[ne,...ae].slice(0,rY)),console.log("[WorkflowDebugPanel]",ne.message,V)},[n,e,t]);const v=b.useMemo(()=>e.map(_=>({label:`${_.id} (${xi(_)})`,value:_.id})),[e]),w=b.useMemo(()=>n.map(_=>({label:`${_.id} (${_.source} -> ${_.target})`,value:_.id})),[n]),y=e.find(_=>_.id===u),g=n.find(_=>_.id===h),C=b.useMemo(()=>{const _=new Map;return e.forEach(B=>{_.set(B.id,xi(B))}),_},[e]),D=b.useMemo(()=>T_(n,C),[n,C]),k=b.useMemo(()=>{const _=new Set;return D==null||D.forEach(B=>{B.edgeIds.forEach(L=>_.add(L))}),_},[D]),A=b.useMemo(()=>n.map(_=>{const B=C.get(_.source)||_.source,L=C.get(_.target)||_.target;return{id:_.id,text:`${_.source}(${B}) -> ${_.target}(${L})`,isDuplicate:k.has(_.id)}}),[k,n,C]),S=b.useMemo(()=>iY(e,n,C,k),[k,n,C,e]),E=b.useMemo(()=>aY(e,n),[n,e]),T=b.useMemo(()=>new Map(E.nodes.map(_=>[_.id,_])),[E.nodes]),O=Math.max(E.width,400),F=Math.max(E.height,180),N=b.useMemo(()=>{const{levels:_,unvisited:B}=N_(e,n),L=_.map(H=>{const W=H.nodes.map(K=>`${K.id}(${xi(K)})`).join(" | ");return`L${H.level}: ${W}`});return B.length&&L.push(`循环/未连接: ${B.map(H=>`${H.id}(${xi(H)})`).join(" | ")}`),L.length?L.join(`
100
100
  `):"暂无结构"},[n,e]),I=b.useMemo(()=>s&&l?o.filter(_=>_.nodeSummary||_.edgeSummary):s?o.filter(_=>_.nodeSummary):l?o.filter(_=>_.edgeSummary):o,[o,l,s]),P=b.useMemo(()=>{const _={nodes:e.map(Ew),edges:n.map(Dw),edgeRelations:__(n,C),duplicateEdges:D,mermaidSource:S};return JSON.stringify(_,null,2)},[D,n,S,C,e]);return t?f.jsxs(se.Panel,{position:"bottom-right",className:"workflow-debug-panel",children:[f.jsxs("div",{className:"workflow-debug-panel__header",children:[f.jsx("span",{children:"画布调试"}),f.jsx(x.Button,{size:"small",onClick:r,children:"关闭"})]}),f.jsxs("div",{className:"workflow-debug-panel__section",children:[f.jsxs("div",{className:"workflow-debug-panel__log-header",children:[f.jsx("span",{children:"变更日志"}),f.jsxs(x.Space,{size:6,children:[f.jsx(x.Button,{size:"small",onClick:async()=>{const _=B_(I);await Md(_)?x.message.success("日志已复制"):x.message.error("复制失败")},children:"复制日志"}),f.jsx(x.Button,{size:"small",onClick:async()=>{const _=I[0],B=_?B_([_]):"暂无日志";await Md(B)?x.message.success("最新日志已复制"):x.message.error("复制失败")},children:"复制最新"}),f.jsx(x.Button,{size:"small",onClick:async()=>{await Md(P)?x.message.success("快照已复制"):x.message.error("复制失败")},children:"复制快照"})]})]}),f.jsx("div",{className:"workflow-debug-panel__toolbar",children:f.jsxs(x.Space,{size:6,wrap:!0,children:[f.jsx(x.Button,{size:"small",onClick:()=>a(_=>!_),children:s?"显示全部":"仅节点"}),f.jsx(x.Button,{size:"small",onClick:()=>c(_=>!_),children:l?"显示全部":"仅连线"}),f.jsx(x.Button,{size:"small",onClick:()=>i(_=>_.map(B=>({...B,expanded:!0}))),children:"全部展开"}),f.jsx(x.Button,{size:"small",onClick:()=>i(_=>_.map(B=>({...B,expanded:!1}))),children:"全部收起"}),f.jsx(x.Button,{size:"small",onClick:()=>i([]),children:"清空"})]})}),f.jsxs("div",{className:"workflow-debug-panel__log-list",children:[I.length===0&&f.jsx("div",{className:"workflow-debug-panel__log-empty",children:"暂无日志"}),I.map(_=>f.jsxs("div",{className:"workflow-debug-panel__log-item",children:[f.jsxs("div",{className:"workflow-debug-panel__log-title",children:[f.jsx("span",{className:"workflow-debug-panel__log-time",children:_.time}),f.jsx("span",{children:_.message})]}),f.jsxs("div",{className:"workflow-debug-panel__log-tags",children:[_.nodeSummary&&f.jsxs("span",{className:"workflow-debug-panel__tag workflow-debug-panel__tag-node",children:["节点 +",_.nodeSummary.added," -",_.nodeSummary.removed," ~",_.nodeSummary.changed]}),_.edgeSummary&&f.jsxs("span",{className:"workflow-debug-panel__tag workflow-debug-panel__tag-edge",children:["连线 +",_.edgeSummary.added," -",_.edgeSummary.removed," ~",_.edgeSummary.changed]})]}),f.jsx("div",{className:"workflow-debug-panel__log-actions",children:f.jsx(x.Button,{size:"small",onClick:()=>i(B=>B.map(L=>L.id===_.id?{...L,expanded:!L.expanded}:L)),children:_.expanded?"收起详情":"展开详情"})}),_.expanded&&f.jsxs("div",{className:"workflow-debug-panel__log-detail",children:[_.edgeRelations&&f.jsxs("div",{className:"workflow-debug-panel__log-detail-block",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"连线关系"}),f.jsx("pre",{children:_.edgeRelations.join(`
101
101
  `)})]}),_.duplicateEdges&&_.duplicateEdges.length>0&&f.jsxs("div",{className:"workflow-debug-panel__log-detail-block",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"重复连线"}),f.jsx("pre",{children:_.duplicateEdges.map(B=>`${B.relation} [${B.edgeIds.join(", ")}]`).join(`
102
- `)})]}),_.detail&&f.jsxs("div",{className:"workflow-debug-panel__log-detail-block",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"详细信息"}),f.jsx("pre",{children:JSON.stringify(_.detail,null,2)})]})]})]},_.id))]})]}),f.jsxs("div",{className:"workflow-debug-panel__section",children:[f.jsxs("div",{className:"workflow-debug-panel__summary",children:[f.jsxs("span",{children:["节点数: ",e.length]}),f.jsxs("span",{children:["连线数: ",n.length]})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"结构图预览"}),f.jsx("div",{className:"workflow-debug-panel__graph",children:f.jsxs("svg",{className:"workflow-debug-panel__graph-canvas",width:"100%",height:F,viewBox:`0 0 ${O} ${F}`,preserveAspectRatio:"xMinYMin meet",children:[f.jsxs("defs",{children:[f.jsx("marker",{id:"workflow-debug-arrow",markerWidth:"10",markerHeight:"10",refX:"8",refY:"3",orient:"auto",markerUnits:"strokeWidth",children:f.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"#8c8c8c"})}),f.jsx("marker",{id:"workflow-debug-arrow-dup",markerWidth:"10",markerHeight:"10",refX:"8",refY:"3",orient:"auto",markerUnits:"strokeWidth",children:f.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"#cf1322"})})]}),E.edges.map(_=>{const B=T.get(_.source),L=T.get(_.target);if(!B||!L)return null;const H=k.has(_.id),W=B.x+Id,K=B.y+dl/2,q=L.x,te=L.y+dl/2;return f.jsx("line",{x1:W,y1:K,x2:q,y2:te,stroke:H?"#cf1322":"#8c8c8c",strokeWidth:H?2.2:1.4,markerEnd:H?"url(#workflow-debug-arrow-dup)":"url(#workflow-debug-arrow)"},_.id)}),E.nodes.map(_=>f.jsxs("g",{transform:`translate(${_.x}, ${_.y})`,children:[f.jsx("rect",{width:Id,height:dl,rx:6,fill:"#ffffff",stroke:"#91caff",strokeWidth:1.4}),f.jsx("text",{x:Id/2,y:dl/2+4,textAnchor:"middle",fontSize:"11",fill:"#1f1f1f",children:_.label})]},_.id))]})})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"Mermaid 图"}),f.jsx("div",{className:"workflow-debug-panel__mermaid-actions",children:f.jsx(x.Button,{size:"small",onClick:async()=>{await Md(S)?x.message.success("Mermaid 已复制"):x.message.error("复制失败")},children:"复制 Mermaid"})}),f.jsx("pre",{children:S})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"结构布局"}),f.jsx("pre",{children:N})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"连线关系"}),f.jsxs("div",{className:"workflow-debug-panel__edge-list",children:[A.length===0&&f.jsx("div",{className:"workflow-debug-panel__log-empty",children:"暂无连线"}),A.map(_=>f.jsxs("div",{className:`workflow-debug-panel__edge-line${_.isDuplicate?" workflow-debug-panel__edge-line--duplicate":""}`,children:[f.jsx("span",{children:_.text}),_.isDuplicate&&f.jsx("span",{className:"workflow-debug-panel__edge-flag",children:"重复"})]},_.id))]})]}),D&&D.length>0&&f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"重复连线"}),f.jsx("div",{className:"workflow-debug-panel__edge-list",children:D.map(_=>f.jsxs("div",{className:"workflow-debug-panel__edge-line--duplicate",children:[f.jsx("span",{children:_.relation}),f.jsx("span",{className:"workflow-debug-panel__edge-flag",children:_.edgeIds.join(", ")})]},_.key))})]}),f.jsxs(x.Space,{direction:"vertical",size:8,style:{width:"100%"},children:[f.jsx(x.Select,{value:u,placeholder:"选择节点查看详情",options:v,onChange:_=>d(_),allowClear:!0,size:"small"}),f.jsx(x.Select,{value:h,placeholder:"选择连线查看详情",options:w,onChange:_=>p(_),allowClear:!0,size:"small"})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"节点详情"}),f.jsx("pre",{children:y?JSON.stringify(Ew(y),null,2):"未选择节点"})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"连线详情"}),f.jsx("pre",{children:g?JSON.stringify({...Dw(g),sourceName:C.get(g.source),targetName:C.get(g.target),isDuplicate:k.has(g.id)},null,2):"未选择连线"})]})]})]}):null},I_=b.createContext(null),cY=({api:t,children:e})=>f.jsx(I_.Provider,{value:t,children:e}),M_=()=>{const t=b.useContext(I_);if(!t)throw new Error("useCanvasApi must be used within a CanvasApiProvider");return t},P_=t=>{var w;const{workflowId:e,strategy:n,readOnly:r=!1,appFlowMode:o=!1,linkMode:i=!1}=t,s=Wt(),a=eY(t,n.stickyNodeKey),{setUnSave:l,store:c,updateSaveStatus:u}=a,d=b.useMemo(()=>n.nodeTypes??In.getNodeTypes(),[n.nodeTypes]),h=b.useCallback(async()=>{if(e)try{u(pn.SAVING);const{nodes:y,edges:g}=c.getState(),C=y.map(S=>S.id),D=g.filter(S=>C.includes(S.target)&&S.source&&S.sourceHandle&&S.targetHandle),k=Sg.getState().workflow.workflowName,A=Sg.getState().workflow.executionControl;await n.saveFlow({nodes:y,edges:D,workflowName:k,workflowId:e,executionControl:A}),l(!1),u(pn.SAVED)}catch(y){u(pn.ERROR,y)}},[l,c,n,u,e]);a.saveFlowRef.current=h,nK({workflowId:e,strategy:n,setNodes:a.setNodes,setEdges:a.setEdges,fitView:a.reactFlow.fitView,setLoading:a.setLoading,setUnSave:a.setUnSave,dispatch:a.dispatch,setFlowOpStatusAction:a.setFlowOpStatusAction,refreshWorkFlowNum:a.refreshWorkFlowNum}),sK({workflowId:e,strategy:n,store:a.store,addNodes:a.addNodes,addEdges:a.addEdges,removeEdges:a.removeEdges,setNodeAddCallback:a.setNodeAddCallback,handleEdgeAddNode:a.handleEdgeAddNode,setNodeConfigVisible:a.setNodeConfigVisible,setNodeFitHumanView:a.setNodeFitHumanView,saveFlow:h,engineMode:s.engineMode});const p=n.HeaderComponent,m=n.PanelComponent,v=n.ConfigModalComponent;return f.jsxs(cY,{api:a.canvasApi,children:[f.jsxs("div",{className:a.isPreviewMode?"workflow-canvas-container workflow-canvas-container-preview":"workflow-canvas-container",style:{height:s.canvas.height?`${s.canvas.height}`:i?"calc(100vh - 320px)":void 0},children:[a.showCanvasHeader&&f.jsx(p,{onSave:h,readOnly:r,autoSaveStatus:a.autoSaveStatus,unSave:a.unSave,lastSavedTime:a.lastSavedTime,appFlowMode:o,canvasApi:a.canvasApi}),f.jsxs("div",{className:"workflow-canvas",children:[f.jsx(JG,{loading:a.loading}),f.jsx(RG,{}),f.jsxs(se.ReactFlow,{nodes:a.nodes,edges:a.edges,onNodesChange:a.onNodesChange,onEdgesChange:a.handleEdgesChange,onConnect:a.handleConnect,multiSelectionKeyCode:null,nodeTypes:d,edgeTypes:zG,connectionLineType:se.ConnectionLineType.Bezier,connectionMode:se.ConnectionMode.Loose,onNodeMouseEnter:a.onNodeMouseEnter,onNodeMouseLeave:a.onNodeMouseLeave,onEdgeMouseEnter:a.onEdgeMouseEnter,onEdgeMouseLeave:a.onEdgeMouseLeave,onNodeContextMenu:a.onNodeContextMenu,onPaneContextMenu:a.onPaneContextMenu,defaultEdgeOptions:WG,style:HG,defaultViewport:a.isPreviewMode?jG:VG,minZoom:.1,maxZoom:2,fitView:!1,snapToGrid:!0,snapGrid:[20,20],deleteKeyCode:null,nodesDraggable:!a.isInteractionDisabled,nodesConnectable:!a.isInteractionDisabled,elementsSelectable:!a.isInteractionDisabled,className:"react-flow-canvas-container",...a.restNativeProps,children:[a.showBackground&&f.jsx(se.Background,{gap:(w=s.canvas.grid)==null?void 0:w.size,color:"#eee",variant:se.BackgroundVariant.Lines}),a.showFastOperationButtons&&f.jsx(XG,{onOpenNodeSelector:a.handleOpenNodeSelector,onAddNoteNode:a.handleAddNoteNode,onTidyCanvas:a.handleTidy}),a.showControls&&f.jsx(se.Controls,{onInteractiveChange:y=>{a.setLocked(y)}}),a.showMiniMap&&f.jsx(nY,{}),f.jsx(m,{}),f.jsx(tK,{horizontal:a.helperLineHorizontal,vertical:a.helperLineVertical}),f.jsx(lY,{visible:a.debugVisible,nodes:a.nodes,edges:a.storeEdges,onClose:()=>a.setDebugVisible(!1)})]})]})]}),v&&f.jsx(v,{})]})};var Pd=(t=>(t.ONCE="ONCE",t.EACH="EACH",t))(Pd||{}),Si=(t=>(t.STOP_WORKFLOW="STOP_WORKFLOW",t.CONTINUE_ERROR_OUTPUT="CONTINUE_ERROR_OUTPUT",t))(Si||{});const Ld="error",uY=[{label:"合并执行(ONCE)",value:Pd.ONCE},{label:"逐条执行(EACH)",value:Pd.EACH}],dY=[{label:"停止工作流(STOP_WORKFLOW)",value:Si.STOP_WORKFLOW},{label:"输出错误并继续(CONTINUE_ERROR_OUTPUT)",value:Si.CONTINUE_ERROR_OUTPUT}],Aw=({unit:t,style:e,...n})=>f.jsxs(x.Space.Compact,{style:{width:"100%"},children:[f.jsx(x.InputNumber,{...n,style:{flex:1,...e}}),f.jsx(x.Button,{disabled:!0,style:{pointerEvents:"none"},children:t})]}),fY=({nodeId:t})=>{const[e]=x.Form.useForm(),{getEdges:n,getNode:r,setEdges:o}=se.useReactFlow(),{handleNodeDataUpdate:i}=jr();b.useEffect(()=>{var c;const a=r(t),l=((c=a==null?void 0:a.data)==null?void 0:c.settings)??{};e.setFieldsValue({retryCount:l.retryCount??0,retryInterval:l.retryInterval??1e3,timeout:l.timeout??0,onError:l.onError??Si.STOP_WORKFLOW,executeMode:l.executeMode??Pd.ONCE})},[t,e,r]);const s=b.useCallback(a=>{const l={retryCount:a.retryCount,retryInterval:a.retryInterval,timeout:a.timeout,onError:a.onError??Si.STOP_WORKFLOW,executeMode:a.executeMode};i({id:t,data:{settings:l}}),l.onError!==Si.CONTINUE_ERROR_OUTPUT&&o(n().filter(c=>!(c.source===t&&(c.sourceHandle||"main")===Ld))),x.message.success("节点设置已保存")},[t,i,n,o]);return f.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[f.jsx("div",{style:{flex:1,overflowY:"auto",padding:"16px 16px 0"},children:f.jsxs(x.Form,{form:e,layout:"vertical",onFinish:s,children:[f.jsx(x.Form.Item,{label:"执行模式",name:"executeMode",children:f.jsx(x.Select,{options:uY,style:{width:"100%"}})}),f.jsx(x.Form.Item,{label:"错误处理策略",name:"onError",tooltip:"选择节点执行失败后的处理方式。CONTINUE_ERROR_OUTPUT 会显示 error 输出锚点",children:f.jsx(x.Select,{options:dY,style:{width:"100%"}})}),f.jsx(x.Form.Item,{label:"重试次数",name:"retryCount",tooltip:"失败后自动重试的次数,0 表示不重试",rules:[{type:"number",min:0,max:10,message:"重试次数范围 0–10"}],children:f.jsx(Aw,{min:0,max:10,precision:0,unit:"次"})}),f.jsx(x.Form.Item,{noStyle:!0,shouldUpdate:(a,l)=>a.retryCount!==l.retryCount,children:({getFieldValue:a})=>a("retryCount")>0?f.jsx(x.Form.Item,{label:"重试间隔",name:"retryInterval",tooltip:"两次重试之间的等待时间(毫秒)",rules:[{type:"number",min:100,message:"重试间隔至少 100ms"}],children:f.jsx(Aw,{min:100,step:500,unit:"ms"})}):null}),f.jsx(x.Form.Item,{label:"执行超时",name:"timeout",tooltip:"节点执行的最大时间(秒),0 表示无限制",rules:[{type:"number",min:0,message:"超时时间不能为负数"}],children:f.jsx(Aw,{min:0,step:10,unit:"秒"})})]})}),f.jsx("div",{style:{padding:"12px 16px",borderTop:"1px solid #eaeaea",backgroundColor:"#fff",textAlign:"center"},children:f.jsx(x.Button,{type:"primary",style:{width:180},onClick:()=>e.submit(),children:"保存"})})]})},{TextArea:hY}=x.Input,{Title:pY,Paragraph:mY}=x.Typography;function gY(t,e){var r,o;const n={};for(const i of t){if(i.id===e)continue;const s=(r=i.data)==null?void 0:r.name,a=(o=i.data)==null?void 0:o.output;if(!s||a===void 0||a===null||a==="")continue;let l=a;if(typeof l=="string")try{l=JSON.parse(l)}catch{continue}Array.isArray(l)?n[s]=l:l&&typeof l=="object"&&(Array.isArray(l.default)?n[s]=l.default:n[s]=[l])}return n}const wY=b.forwardRef((t,e)=>{const{nodeId:n,beforeHook:r}=t,{handleNodeDataUpdate:o}=jr(),i=se.useInternalNode(n),s=se.useReactFlow(),a=Ct(),[l,c]=b.useState(""),u=dt.useReactive({testProgress:0,sampleText:"",isError:!1,editable:!1,showErrorAlert:!1,testing:!1,ignoring:!1,successShown:!1,isIgnoreSuccess:!1});b.useEffect(()=>{var g,C;const w=(g=i==null?void 0:i.data)==null?void 0:g.output,y=(C=i==null?void 0:i.data)==null?void 0:C.status;if(u.testProgress=0,u.sampleText="",u.editable=!1,u.testing=!1,u.ignoring=!1,u.showErrorAlert=!1,w!=null&&w!==""){const D=typeof w=="string"?w:JSON.stringify(w,null,2);c(D),y===pe.FAILED?(u.isError=!0,u.successShown=!1,u.isIgnoreSuccess=!1):(u.isError=!1,u.successShown=!0,u.isIgnoreSuccess=!1)}else c(""),u.isError=!1,u.successShown=!1,u.isIgnoreSuccess=!1},[n]);const d=b.useCallback(()=>{if(!n)return;u.testing=!0,u.testProgress=60,u.successShown=!1;const w=i==null?void 0:i.data,y=gY(s.getNodes(),n),g={nodeKey:(w==null?void 0:w.nodeKey)??"",nodeVersion:(w==null?void 0:w.nodeVersion)??0,nodeName:(w==null?void 0:w.name)??n,params:(w==null?void 0:w.params)??{},inputData:[],credentialInstanceId:w==null?void 0:w.credentialInstanceId,contextNodes:y,timeoutSeconds:30};MB(g).then(C=>{if(C.success){const D=C.outputData??C.resolvedParams;o({id:n,data:{status:pe.SUCCESS,output:D}}),u.isError=!1,u.successShown=!0,u.isIgnoreSuccess=!1,u.showErrorAlert=!1,u.testProgress=100,c(typeof D=="string"?D:JSON.stringify(D,null,2))}else{const D=C.error??"节点执行失败";console.warn("[NextNodeTest] 测试失败:",D),o({id:n,data:{status:pe.FAILED}}),u.testProgress=0,u.isError=!0,u.showErrorAlert=!0,c(JSON.stringify({error:D},null,2))}}).catch(C=>{console.error("[NextNodeTest] 请求异常:",C);const D=(C==null?void 0:C.message)??"测试执行失败";o({id:n,data:{status:pe.FAILED}}),u.testProgress=0,u.isError=!0,u.showErrorAlert=!0,c(JSON.stringify({error:D},null,2))}).finally(()=>{setTimeout(()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!1},500)})},[n,i,s,o]),h=()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!0};b.useImperativeHandle(e,()=>({onTestNode:d,finishNodeTest:h}));const p=()=>{r?r(!0):d()},m=()=>{const w=u.sampleText||l;if(!w)return;u.testing=!0,u.ignoring=!0,u.testProgress=60;let y;try{y=JSON.parse(w)}catch{y=w}console.log("[NextNodeTest] 忽略调试, 写入样本数据:",y),o({id:n,data:{status:pe.SUCCESS,output:y}});const g=typeof y=="string"?y:JSON.stringify(y,null,2);c(g),u.testProgress=100,setTimeout(()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!0,u.isError=!1,u.showErrorAlert=!1,u.successShown=!0},500)},v=()=>{c(""),u.sampleText="",u.editable=!1,u.successShown=!1};return f.jsxs("div",{className:"node-test-container",children:[f.jsxs("div",{className:"node-test-header",children:[f.jsxs("div",{className:"header-title",children:[f.jsx(Q.RocketOutlined,{className:"title-icon"}),f.jsx(pY,{level:4,children:"节点测试"})]}),f.jsx(mY,{type:"secondary",className:"header-description",children:"点击测试按钮,实时检查节点执行效果和结果数据"})]}),f.jsxs("div",{className:"test-content",children:[a&&f.jsxs("div",{className:"action-buttons",children:[f.jsx(x.Button,{type:"primary",disabled:u.ignoring,icon:f.jsx(Q.RocketOutlined,{}),onClick:p,loading:u.testing&&!u.ignoring,className:"test-button",children:u.testing&&!u.ignoring?"测试中...":"开始测试"}),f.jsx(x.Button,{type:"primary",disabled:u.testing&&!u.ignoring||!(u.sampleText||l),ghost:!0,onClick:m,loading:u.testing&&u.ignoring,className:"ignore-button",title:u.sampleText||l?void 0:"请先编辑样本数据",children:"忽略调试"}),l&&f.jsx(x.Button,{icon:f.jsx(Q.ReloadOutlined,{}),onClick:v,className:"reset-button",children:"重置"})]}),u.testProgress>0&&f.jsx(x.Progress,{percent:u.testProgress,status:u.isError?"exception":"active",className:"test-progress"}),u.isError&&u.showErrorAlert&&f.jsx(x.Alert,{className:"error-alert",showIcon:!0,message:"测试未通过",description:"请检查节点配置是否正确",type:"error",onClose:()=>{setTimeout(()=>{u.showErrorAlert=!1},500)},closable:!0}),!u.isError&&u.successShown&&l&&!u.testing&&f.jsx(x.Alert,{className:"success-alert",showIcon:!0,message:u.isIgnoreSuccess?"忽略调试成功":"测试成功",description:u.isIgnoreSuccess?"已将样本数据预设为当前节点输出":"节点运行正常,可以查看下方返回结果",type:"success",closable:a}),u.testing?f.jsx(x.Skeleton,{active:!0,className:"result-skeleton"}):f.jsx(f.Fragment,{children:l?f.jsx(x.Card,{styles:{body:{padding:0}},title:f.jsxs("div",{className:"result-header",children:[f.jsx("div",{className:"result-title",children:u.isError?f.jsxs(f.Fragment,{children:[f.jsx(Q.CloseCircleFilled,{className:"error-icon"})," 错误数据"]}):f.jsxs(f.Fragment,{children:[u.isIgnoreSuccess?f.jsx(Q.ExperimentFilled,{className:"success-icon"}):f.jsx(Q.CheckCircleFilled,{className:"success-icon"}),u.isIgnoreSuccess?"样本数据":"测试结果"]})}),a&&f.jsx(x.Button,{size:"small",type:"link",icon:f.jsx(Q.EditOutlined,{}),onClick:()=>{if(u.editable){u.editable=!1;try{const w=JSON.parse(u.sampleText),y=JSON.stringify(w,null,2);c(y),o({id:n,data:{output:y}})}catch{c(u.sampleText)}}else u.sampleText=l,u.editable=!0},className:"edit-button",children:u.editable?"完成":"编辑"})]}),variant:"borderless",className:`result-card ${u.isError?"error-result":"success-result"}`,children:u.editable?f.jsx(hY,{rows:10,value:u.sampleText,onChange:w=>u.sampleText=w.target.value,className:"result-editor"}):f.jsx(bA,{data:l,height:300,enableCopy:!0,theme:"light"})}):f.jsx(x.Card,{variant:"borderless",className:"empty-result",children:f.jsx(x.Result,{icon:f.jsx(Q.RocketOutlined,{}),title:"等待测试",subTitle:'点击"开始测试"按钮开始节点测试'})})})]})]})}),vY=t=>t.sourceHandle||"main",L_=t=>`${t.node.id}:${t.outputMode}`,yY=t=>{if(t.length===0)return[];if(t.length===1)return t[0];const e=t.slice(1).map(n=>new Set(n.map(L_)));return t[0].filter(n=>e.every(r=>r.has(L_(n))))},bY=(t,e,n)=>{const r=t.filter(o=>o.node.id!==e.id);return r.push({node:e,outputMode:n}),r};function $_(t,e,n,r=new Set){if(r.has(t))return[];const o=n.get(t)??[];if(o.length===0)return[];const i=new Set(r);i.add(t);const s=o.map(a=>{const l=e.get(a.source);if(!l)return[];const c=$_(a.source,e,n,i);return bY(c,l,vY(a)===Ld?"error":"normal")});return yY(s)}function CY(t,e,n){const r=new Map(e.map(i=>[i.id,i])),o=new Map;for(const i of n){const s=o.get(i.target)??[];s.push(i),o.set(i.target,s)}return $_(t,r,o)}function $d(t,e){const n=t.trim(),r=n.startsWith("N")?n:`N${n}`,o=e.trim();return o?`{{${r}.${o}}}`:`{{${r}}}`}function kY(t,e){return e.map(n=>({key:`${t}.${n.key}`,title:n.label||n.key,type:n.type,isLeaf:!0,expression:$d(t,n.key)}))}function xY(t){return[{key:`${t}.__error__.errorType`,title:"错误类型",type:"STRING",isLeaf:!0,expression:$d(t,"errorType")},{key:`${t}.__error__.errorDetail`,title:"错误详情",type:"STRING",isLeaf:!0,expression:$d(t,"errorDetail")}]}async function SY(t,e,n){var s,a,l;const r=CY(t,e,n);if(r.length===0)return[];const o=await Promise.all(r.map(async({node:c,outputMode:u})=>{var p,m;const d=(p=c.data)==null?void 0:p.nodeKey;if(!d||u==="error")return{node:c,outputMode:u,schema:null};const h=await wd(d,(m=c.data)==null?void 0:m.nodeVersion);return{node:c,outputMode:u,schema:h}})),i=[];for(const{node:c,outputMode:u,schema:d}of o){const h=((s=c.data)==null?void 0:s.label)||((a=c.data)==null?void 0:a.action_name)||((l=c.data)==null?void 0:l.nodeKey)||c.id,p=u==="error"?[]:(d==null?void 0:d.output_fields)??[],m=u==="error"?xY(c.id):p.length>0?kY(c.id,p):[{key:`${c.id}.__output__`,title:"output",type:"OBJECT",isLeaf:!0,expression:$d(c.id,"output")}];i.push({key:c.id,title:h,isLeaf:!1,children:m})}return i}const EY={STRING:"orange",NUMBER:"blue",BOOLEAN:"green",OBJECT:"cyan",ARRAY:"purple",EMPTY:"default"},DY={STRING:"Str",NUMBER:"Num",BOOLEAN:"Bool",OBJECT:"Obj",ARRAY:"Arr"},AY=t=>{const e=t.nodes.map(r=>{const o=r.data??{};return[r.id,o.nodeKey??"",o.nodeVersion??"",o.label??"",o.action_name??"",o.name??""].join(":")}).sort().join("|"),n=t.edges.map(r=>[r.id,r.source,r.sourceHandle??"",r.target,r.targetHandle??""].join(":")).sort().join("|");return`${e}||${n}`},OY=b.forwardRef(({nodeId:t,open:e},n)=>{const r=se.useStoreApi(),o=se.useStore(AY),{event$:i}=b.useContext(Vr),s=b.useRef(0),[a,l]=b.useState([]),[c,u]=b.useState(!1),d=b.useCallback(async m=>{if(!t)return;const v=s.current+1;s.current=v,u(!0);try{const{nodes:w,edges:y}=r.getState(),g=await SY(t,w,y);s.current===v&&l(g)}catch(w){console.error("[DIP] 构建变量树失败:",w)}finally{s.current===v&&u(!1)}},[t,r]);b.useImperativeHandle(n,()=>({loadVariables:d})),b.useEffect(()=>{e&&d(o)},[e,o,d]),i.useSubscription(m=>{m.type==="visible"&&m.visible&&d()});const h=b.useCallback((m,v)=>{const w=v.node;!w.isLeaf||!w.expression||i.emit({type:"insert",expression:w.expression})},[i]),p=a.map(m=>{var v;return{key:m.key,title:f.jsxs("span",{style:{fontSize:14,fontWeight:"bold",color:"#777"},children:[f.jsx(Q.UsbOutlined,{style:{color:"#108ee9",marginRight:4,fontSize:16}}),m.title]}),selectable:!1,children:(v=m.children)==null?void 0:v.map(w=>({key:w.key,selectable:w.type!=="EMPTY",isLeaf:w.isLeaf,title:f.jsxs("div",{style:{display:"flex",flexWrap:"nowrap",alignItems:"center"},children:[w.type&&w.type!=="EMPTY"&&f.jsx(x.Tag,{color:EY[w.type]||"gray",style:{textWrap:"nowrap",padding:"0 3px"},children:DY[w.type]||w.type}),f.jsx("span",{style:{fontSize:14,fontWeight:"bold"},children:w.title})]}),...w}))}});return f.jsxs("div",{className:Ze.container,children:[f.jsx("div",{className:Ze.header,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",color:"#999"},children:[f.jsx(Q.RocketOutlined,{style:{fontSize:20,marginRight:10}}),f.jsx("h3",{style:{margin:0,color:"#999"},children:f.jsx(Se.FormattedMessage,{id:"app.common.word.select-variable"})})]})}),f.jsx("div",{style:{flex:1,overflowY:"auto"},className:"grayBeautifyScrollbar",children:c?f.jsx("div",{style:{textAlign:"center",padding:20},children:f.jsx(x.Spin,{size:"small"})}):p.length>0?f.jsx(x.Tree,{showLine:!0,defaultExpandAll:!0,treeData:p,onSelect:h}):f.jsx(x.Empty,{image:x.Empty.PRESENTED_IMAGE_SIMPLE,description:f.jsx(Se.FormattedMessage,{id:"common.no-process-variables-yet"})})})]})}),_Y=({credentialKey:t,open:e,onCancel:n,onCreated:r})=>{const[o,i]=b.useState(null),[s,a]=b.useState(null),[l,c]=b.useState(!1),[u,d]=b.useState(!1),[h,p]=b.useState(!1),[m]=x.Form.useForm(),[v]=x.Form.useForm();b.useEffect(()=>{!e||!t||(c(!0),Py(t).then(C=>{var D;i(C),(D=C.fields)!=null&&D.length?a(il(C.fields)):a(null)}).catch(C=>{console.error("获取凭据 Schema 失败:",C),x.message.error("获取凭据配置失败")}).finally(()=>c(!1)))},[e,t]);const w=b.useCallback(()=>{m.resetFields(),v.resetFields(),n()},[m,v,n]),y=b.useCallback(async()=>{try{const C=await v.validateFields(),D=await m.validateFields();d(!0);const k=await Ly({name:C.credentialName,credentialKey:t,credentialVersion:(o==null?void 0:o.version)??1,data:D});x.message.success("凭据创建成功"),m.resetFields(),v.resetFields(),r(k.id)}catch(C){if(C!=null&&C.errorFields)return;console.error("创建凭据失败:",C),x.message.error("创建凭据失败")}finally{d(!1)}},[t,o,m,v,r]),g=b.useCallback(async()=>{try{const C=await v.validateFields(),D=await m.validateFields();p(!0);const k=await Ly({name:C.credentialName,credentialKey:t,credentialVersion:(o==null?void 0:o.version)??1,data:D}),A=await $y(k.id);A.success?(x.message.success(A.message||"测试连接成功"),m.resetFields(),v.resetFields(),r(k.id)):x.message.error(A.message||"测试连接失败")}catch(C){if(C!=null&&C.errorFields)return;console.error("测试连接失败:",C),x.message.error("测试连接失败")}finally{p(!1)}},[t,o,m,v,r]);return f.jsx(x.Modal,{title:`新建凭据${o!=null&&o.name?` - ${o.name}`:""}`,open:e,onCancel:w,width:560,footer:f.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[f.jsx(x.Button,{onClick:w,children:"取消"}),f.jsx(x.Button,{icon:f.jsx(Q.ApiOutlined,{}),onClick:g,loading:h,children:"测试连接"}),f.jsx(x.Button,{type:"primary",onClick:y,loading:u,children:"确认创建"})]}),destroyOnClose:!0,children:l?f.jsx("div",{style:{textAlign:"center",padding:40},children:f.jsx(x.Spin,{})}):f.jsxs("div",{children:[f.jsx(x.Form,{form:v,layout:"vertical",style:{marginBottom:16},children:f.jsx(x.Form.Item,{label:"凭据名称",name:"credentialName",rules:[{required:!0,message:"请输入凭据名称"}],children:f.jsx(x.Input,{placeholder:"为此凭据起一个名称"})})}),s?f.jsx(Ri,{schema:s,form:m,showSubmit:!1,showReset:!1}):f.jsx("div",{style:{padding:16,color:"#999",textAlign:"center"},children:"该凭据类型暂无配置项"})]})})},TY=({instanceId:t,credentialKey:e,open:n,onCancel:r,onUpdated:o,onDeleted:i})=>{const[s,a]=b.useState(null),[l,c]=b.useState(null),[u,d]=b.useState(!1),[h,p]=b.useState(!1),[m,v]=b.useState(!1),[w,y]=b.useState(!1),[g]=x.Form.useForm(),[C]=x.Form.useForm();b.useEffect(()=>{!n||!t||(d(!0),Promise.all([Py(e),LB(t)]).then(([E,T])=>{var O;if(a(E),C.setFieldsValue({credentialName:T.name}),(O=E.fields)!=null&&O.length){if(c(il(E.fields)),T.data)try{const F=JSON.parse(T.data);g.setFieldsValue(F)}catch{}}else c(null)}).catch(E=>{console.error("获取凭据信息失败:",E),x.message.error("获取凭据信息失败")}).finally(()=>d(!1)))},[n,t,e,g,C]);const D=b.useCallback(()=>{g.resetFields(),C.resetFields(),r()},[g,C,r]),k=b.useCallback(async()=>{try{const E=await C.validateFields(),T=await g.validateFields();p(!0),await Sf(t,{name:E.credentialName,data:T}),x.message.success("凭据更新成功"),D(),o()}catch(E){if(E!=null&&E.errorFields)return;console.error("更新凭据失败:",E),x.message.error("更新凭据失败")}finally{p(!1)}},[t,g,C,D,o]),A=b.useCallback(async()=>{try{const E=await C.validateFields(),T=await g.validateFields();v(!0),await Sf(t,{name:E.credentialName,data:T});const O=await $y(t);O.success?x.message.success(O.message||"测试连接成功"):x.message.error(O.message||"测试连接失败")}catch(E){if(E!=null&&E.errorFields)return;console.error("测试连接失败:",E),x.message.error("测试连接失败")}finally{v(!1)}},[t,g,C]),S=b.useCallback(async()=>{y(!0);try{await zy(t),x.message.success("凭据删除成功"),D(),i==null||i()}catch(E){console.error("删除凭据失败:",E),x.message.error("删除凭据失败")}finally{y(!1)}},[t,D,i]);return f.jsx(x.Modal,{title:`编辑凭据${s!=null&&s.name?` - ${s.name}`:""}`,open:n,onCancel:D,width:560,footer:f.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[f.jsx(x.Popconfirm,{title:"确认删除",description:"删除后无法恢复,确定要删除此凭据吗?",onConfirm:S,okText:"删除",cancelText:"取消",okButtonProps:{danger:!0,loading:w},children:f.jsx(x.Button,{danger:!0,icon:f.jsx(Q.DeleteOutlined,{}),loading:w,children:"删除凭据"})}),f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsx(x.Button,{onClick:D,children:"取消"}),f.jsx(x.Button,{icon:f.jsx(Q.ApiOutlined,{}),onClick:A,loading:m,children:"测试连接"}),f.jsx(x.Button,{type:"primary",onClick:k,loading:h,children:"保存修改"})]})]}),destroyOnClose:!0,children:u?f.jsx("div",{style:{textAlign:"center",padding:40},children:f.jsx(x.Spin,{})}):f.jsxs("div",{children:[f.jsx(x.Form,{form:C,layout:"vertical",style:{marginBottom:16},children:f.jsx(x.Form.Item,{label:"凭据名称",name:"credentialName",rules:[{required:!0,message:"请输入凭据名称"}],children:f.jsx(x.Input,{placeholder:"为此凭据起一个名称"})})}),l?f.jsx(Ri,{schema:l,form:g,showSubmit:!1,showReset:!1}):f.jsx("div",{style:{padding:16,color:"#999",textAlign:"center"},children:"该凭据类型暂无配置项"})]})})},{Text:z_}=x.Typography,NY=({credentialKey:t,label:e="授权配置",required:n=!1,value:r,onChange:o,disabled:i=!1})=>{const[s,a]=b.useState([]),[l,c]=b.useState(!1),[u,d]=b.useState(!1),[h,p]=b.useState(!1),[m,v]=b.useState(null),[w,y]=b.useState(null),[g,C]=b.useState(""),D=b.useRef(null),k=b.useCallback(()=>{t&&(c(!0),PB(t).then(_=>{a(Array.isArray(_)?_:[])}).catch(()=>{a([])}).finally(()=>c(!1)))},[t]);b.useEffect(()=>{k()},[k]),b.useEffect(()=>{w&&D.current&&setTimeout(()=>{var _;(_=D.current)==null||_.focus()},100)},[w]);const A=b.useCallback(_=>{d(!1),k(),o==null||o(_)},[k,o]),S=b.useCallback(_=>{v(_),p(!0)},[]),E=b.useCallback(()=>{p(!1),v(null),k()},[k]),T=b.useCallback(_=>{zy(_).then(()=>{x.message.success("凭据删除成功"),k(),r===_&&(o==null||o(void 0))}).catch(()=>{x.message.error("删除凭据失败")})},[k,r,o]),O=b.useCallback((_,B,L)=>{_.stopPropagation(),_.preventDefault(),y(B),C(L)},[]),F=b.useCallback(()=>{y(null),C("")},[]),N=b.useCallback(()=>{if(!w||!g.trim()){F();return}const _=g.trim(),B=s.find(L=>L.id===w);if((B==null?void 0:B.name)===_){F();return}Sf(w,{name:_}).then(()=>{x.message.success("凭据重命名成功"),k(),F()}).catch(()=>{x.message.error("重命名失败")})},[w,g,s,k,F]),I=b.useCallback(_=>{w&&(_.stopPropagation(),_.preventDefault())},[w]),P=b.useCallback(_=>f.jsxs("div",{children:[_,f.jsx(x.Divider,{style:{margin:"4px 0"}}),f.jsx("div",{style:{padding:"8px",textAlign:"center"},children:f.jsx(x.Button,{icon:f.jsx(Q.PlusOutlined,{}),onClick:()=>d(!0),type:"link",block:!0,disabled:i,children:"新建凭据"})})]}),[i]);return t?f.jsxs("div",{style:{padding:"16px 0"},children:[f.jsxs(z_,{strong:!0,style:{display:"block",marginBottom:8,fontSize:14},children:[e,n?f.jsx("span",{style:{color:"#ff4d4f",marginLeft:4},children:"*"}):null]}),f.jsx(x.Select,{style:{width:"100%"},placeholder:"选择凭据实例",value:r,onChange:_=>o==null?void 0:o(_),loading:l,disabled:i,allowClear:!0,onClear:()=>o==null?void 0:o(void 0),dropdownRender:P,onClick:I,children:s.map(_=>f.jsx(x.Select.Option,{value:_.id,children:f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",width:"100%",padding:"4px 0"},onClick:I,children:[f.jsx("div",{style:{display:"flex",alignItems:"center",maxWidth:"40%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w!==_.id?f.jsxs(b.Fragment,{children:[f.jsx("span",{children:_.name}),f.jsx(Q.EditOutlined,{style:{fontSize:12,color:"#1890ff",marginLeft:6,cursor:"pointer",opacity:.5},onClick:B=>{i||O(B,_.id,_.name)}})]}):f.jsx(x.Input,{ref:D,size:"small",value:g,onChange:B=>C(B.target.value),onPressEnter:N,onBlur:N,onClick:B=>B.stopPropagation(),onMouseDown:B=>B.stopPropagation(),style:{width:120}})}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx(z_,{type:"secondary",style:{fontSize:12},children:_.updatedAt?Tt(_.updatedAt).format("YYYY-MM-DD HH:mm"):_.createdAt?Tt(_.createdAt).format("YYYY-MM-DD HH:mm"):""}),f.jsx(x.Button,{type:"link",icon:f.jsx(Q.EditOutlined,{}),size:"small",onClick:B=>{B.stopPropagation(),S(_.id)},disabled:i,children:"编辑"}),f.jsx(x.Popconfirm,{title:"确认删除",description:"删除后无法恢复,确定要删除此凭据吗?",onConfirm:B=>{B==null||B.stopPropagation(),T(_.id)},onCancel:B=>B==null?void 0:B.stopPropagation(),okText:"删除",cancelText:"取消",okButtonProps:{danger:!0},disabled:i,children:f.jsx(x.Button,{type:"link",danger:!0,icon:f.jsx(Q.DeleteOutlined,{}),size:"small",onClick:B=>B.stopPropagation(),disabled:i,children:"删除"})})]})]})},_.id))}),t&&f.jsx(_Y,{credentialKey:t,open:u,onCancel:()=>d(!1),onCreated:A}),t&&m&&f.jsx(TY,{instanceId:m,credentialKey:t,open:h,onCancel:()=>{p(!1),v(null)},onUpdated:E,onDeleted:()=>{p(!1),v(null),k(),r===m&&(o==null||o(void 0))}})]}):null},Ur="[workflow:schema-render]",BY=/^\{\{([^.{}]+)\.(.+)\}\}$/,FY=b.forwardRef((t,e)=>{const{nodeId:n,data:r,onSubmitted:o,onValuesChange:i,cachedValues:s}=t,[a,l]=b.useState(null),[c,u]=b.useState([]),[d,h]=b.useState(r==null?void 0:r.credentialInstanceId),[p,m]=b.useState(),[v,w]=b.useState(!1),[y,g]=b.useState(!1),[C]=x.Form.useForm(),D=se.useStoreApi(),k=r==null?void 0:r.nodeKey,A=r==null?void 0:r.nodeVersion;b.useEffect(()=>{if(!k){console.warn(`${Ur} open next config without nodeKey`,{nodeId:n,data:r}),g(!0);return}let N=!1;return w(!0),g(!1),console.info(`${Ur} open next config`,{nodeId:n,nodeKey:k,nodeVersion:A,hasParams:!!(r!=null&&r.params),credentialInstanceId:r==null?void 0:r.credentialInstanceId}),wd(k,A).then(I=>{var P,_,B,L,H,W,K;if(N){console.info(`${Ur} ignore schema result after unmount`,{nodeId:n,nodeKey:k,nodeVersion:A});return}if(!I){console.warn(`${Ur} next config schema empty`,{nodeId:n,nodeKey:k,nodeVersion:A}),l(null),u([]);return}if(console.info(`${Ur} next config schema loaded`,{nodeId:n,nodeKey:k,nodeVersion:A,schemaKeys:Object.keys(I),schemaVersion:I.version,inputFields:((P=I.input_fields)==null?void 0:P.length)??0,outputs:((_=I.outputs)==null?void 0:_.length)??0,credentials:((B=I.credentials)==null?void 0:B.length)??0,fieldSummaries:((L=I.input_fields)==null?void 0:L.map(q=>({key:q.key,label:q.label,type:q.type,required:q.required})))??[]}),(H=I.input_fields)!=null&&H.length){const q=il(I.input_fields);console.info(`${Ur} next config form schema converted`,{nodeId:n,nodeKey:k,nodeVersion:A,fields:q.fields.length}),l(q)}else console.warn(`${Ur} next config schema has no inputFields`,{nodeId:n,nodeKey:k,nodeVersion:A,schemaKeys:Object.keys(I),hasNestedNodeSchema:!!I.node_schema,nestedInputFields:((K=(W=I.node_schema)==null?void 0:W.input_fields)==null?void 0:K.length)??0}),l(null);u(I.credentials??[])}).catch(I=>{console.error(`${Ur} next config schema load failed`,{nodeId:n,nodeKey:k,nodeVersion:A,err:I})}).finally(()=>{N||(w(!1),g(!0))}),()=>{N=!0}},[n,k,A]);const S=b.useCallback(N=>{console.info(`${Ur} submit next config`,{nodeId:n,nodeKey:k,nodeVersion:A,valueKeys:Object.keys(N),credentialInstanceId:d}),o({params:N,credentialInstanceId:d})},[d,n,k,A,o]),E=b.useCallback(N=>{const I=N.trim().match(BY);if(!I)return null;const P=I[1],_=I[2];if(P==="global")return null;const B=P.startsWith("N")?P.slice(1):P,L=D.getState().nodes.find(H=>H.id===B);return L?{fieldPath:_,node:L,variableNodeId:P}:null},[D]),T=b.useCallback(N=>{var I;return((I=E(N))==null?void 0:I.fieldPath)??N.replace(/^\{\{|\}\}$/g,"")},[E]),O=b.useCallback(N=>{var L;const I=E(N);if(!I)return N;const P=(L=I.node)==null?void 0:L.data,_=(P==null?void 0:P.label)||(P==null?void 0:P.name)||(P==null?void 0:P.action_name)||I.variableNodeId,B=P!=null&&P.note?` (${P.note})`:"";return`${_}${B}.${I.fieldPath}`},[E]);b.useImperativeHandle(e,()=>({saveConfig:()=>C.validateFields().then(N=>(S(N),N)).catch(()=>null)}));const F=b.useMemo(()=>ld(c),[c]);return b.useEffect(()=>{var N;if(!d){m(void 0);return}!p&&((N=F[0])!=null&&N.key)&&m(F[0].key)},[p,d,F]),b.useEffect(()=>{v||!y||a||console.warn(`${Ur} render empty config placeholder`,{nodeId:n,nodeKey:k,nodeVersion:A,loading:v})},[a,v,n,k,A,y]),v?f.jsx("div",{style:{textAlign:"center",padding:40},children:f.jsx(x.Spin,{})}):f.jsxs("div",{children:[F.map(N=>f.jsx(NY,{credentialKey:N.key,label:F.length>1?N.label:void 0,required:N.required,value:p===N.key?d:void 0,onChange:I=>{if(I){m(N.key),h(I);return}p===N.key&&(h(void 0),m(void 0))}},N.key)),a?f.jsx(Ri,{schema:a,form:C,initialValues:s??(r==null?void 0:r.params)??{},onSubmit:S,onChange:i?(N,I)=>i(I):void 0,renderVariableTag:T,renderVariableTooltip:O,showSubmit:!1,showReset:!1,nodeId:n}):f.jsx("div",{style:{padding:16,color:"#999",textAlign:"center"},children:k?"该节点暂无配置项":"未知节点类型"}),f.jsx("div",{style:{padding:"12px 0",position:"sticky",backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:f.jsx(x.Button,{type:"primary",style:{width:180,borderRadius:4},onClick:()=>{C.validateFields().then(N=>{S(N)}).catch(()=>{})},children:"保存"})})]})}),IY=()=>{const{event$:t}=b.useContext(Vr),e=jf();return t.useSubscription(n=>{n.type==="insert"&&(console.log("[Bridge] 收到 insert 事件:",{expression:n.expression,hasVarSelector:!!e,activeFieldId:e==null?void 0:e.activeFieldId}),n.expression&&e?e.insertVariableToActiveField(n.expression,!1):e?e.activeFieldId||console.warn("[Bridge] 没有激活的字段(请先点击一个支持变量的表单字段)"):console.warn("[Bridge] VariableSelectorContext 不可用"))}),null},MY=t=>f.jsxs("div",{className:"node-config-title",style:{display:"flex",alignItems:"center"},children:[t.icon?f.jsx("img",{src:t.icon,alt:t.name,style:{width:24,height:24}}):null,f.jsx("div",{className:"node-config-title-name",style:{fontSize:16,fontWeight:600,marginLeft:10},children:t.name}),f.jsx("div",{className:"node-config-title-description",style:{fontSize:12,color:"gray",marginLeft:10},children:t.description})]}),PY=b.memo(({visible:t,onClose:e,data:n,nodeType:r=Z.ACTION,nodeId:o="",cachedValues:i,onValuesChange:s})=>{var D,k,A,S;const a=dt.useEventEmitter(),l=se.useInternalNode(o),{setNodeConfigVisible:c}=Sr(),u=b.useRef(null),d=b.useRef(null),h=b.useRef(null),p=Wt(),m=((k=(D=p.nodeConfigPanel)==null?void 0:D.testArea)==null?void 0:k.allowManualTest)!==!1,{handleNodeDataUpdate:v}=jr(),w=b.useRef(ut.debounce((E,T)=>{s==null||s(E,T)},300)).current,y=b.useMemo(()=>p.nodeConfigPanel.showSettings&&![Z.TRIGGER,Z.MCP_TOOL,Z.AI_SUB_NODE].includes(r),[r,p.nodeConfigPanel.showSettings]),g=b.useCallback(async(E,T)=>{try{v({id:o,data:{params:E.params,credentialInstanceId:E.credentialInstanceId}}),x.message.success("节点配置已保存"),s==null||s(o,null),T&&h.current&&h.current.onTestNode()}catch{}},[(A=l==null?void 0:l.position)==null?void 0:A.x,(S=l==null?void 0:l.position)==null?void 0:S.y,o,v,s]),C=async(E,T)=>{var O,F;if(!T&&E)try{x.message.loading("正在保存节点配置...",0),await((O=d.current)==null?void 0:O.saveConfig()),x.message.destroy(),(F=h.current)==null||F.onTestNode()}catch{x.message.destroy(),x.message.error("节点配置保存失败,无法执行测试")}};return f.jsx(x.Modal,{open:t,footer:null,closeIcon:null,maskClosable:!0,onCancel:()=>{c(null)},centered:!0,width:"90%",className:"nodes-config-modal",styles:{wrapper:{minWidth:1040},mask:{backgroundColor:"rgba(0, 0, 0, 0.45)"},content:{padding:0,overflow:"hidden"}},children:f.jsx(Vr.Provider,{value:{event$:a},children:f.jsxs(Vf,{children:[f.jsx(IY,{}),f.jsxs("div",{className:"nodes-config-container",children:[f.jsxs("div",{className:"nodes-config-header",children:[f.jsx("div",{className:"header-left",children:f.jsx("span",{className:"header-title",children:" 节点配置"})}),f.jsx("div",{className:"header-right",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Q.ArrowLeftOutlined,{}),onClick:e,className:"back-button",children:"返回画布"})})]}),f.jsx("div",{className:"nodes-config-content",children:f.jsxs(x.Row,{gutter:16,className:"config-row",children:[f.jsx(x.Col,{span:5,className:"left-section",children:f.jsx("div",{className:"variables-section",children:f.jsx(OY,{ref:u,nodeId:o,open:t})})}),f.jsx(x.Col,{span:12,className:"middle-section",children:f.jsx("div",{className:"form-section",style:{height:"100%"},children:f.jsx(x.Card,{title:f.jsx(MY,{icon:n==null?void 0:n.icon,name:n==null?void 0:n.name,description:n==null?void 0:n.description}),variant:"borderless",styles:{body:{paddingTop:0,paddingBottom:0}},className:"section-card form-card",children:f.jsx(x.Tabs,{style:{height:"100%"},items:[{key:"property",label:"参数配置",children:f.jsx(FY,{ref:d,nodeId:o,data:n,onSubmitted:g,cachedValues:i,onValuesChange:s?E=>w(o,E):void 0})},...y?[{key:"setting",label:"设置",children:f.jsx(fY,{nodeId:o})}]:[]]})})})}),f.jsx(x.Col,{span:7,className:"right-section",children:m&&f.jsx("div",{className:"test-section",children:f.jsx(x.Card,{variant:"borderless",className:"section-card",children:f.jsx(wY,{ref:h,nodeId:o,beforeHook:C})})})})]})})]})]})})})},(t,e)=>ut.isEqual(ut.omit(t,["isHovered"]),ut.omit(e,["isHovered"])));function LY(){const t=b.useRef(new Map),e=b.useCallback(i=>t.current.get(i),[]),n=b.useCallback((i,s)=>{t.current.set(i,s)},[]),r=b.useCallback(i=>{t.current.delete(i)},[]),o=b.useCallback((i,s)=>{s===null?r(i):n(i,s)},[r,n]);return{getCachedValues:e,handleValuesChange:o}}const $Y=()=>{const{currentNodeConfigVisibleId:t,setNodeConfigVisible:e}=Sr(),n=se.useStoreApi(),{getCachedValues:r,handleValuesChange:o}=LY(),i=t?n.getState().nodes.find(s=>s.id===t):void 0;return f.jsx(PY,{visible:!!t,onClose:()=>e(null),nodeType:i==null?void 0:i.type,data:i==null?void 0:i.data,nodeId:t??"",cachedValues:t?r(t):void 0,onValuesChange:o})};function H_(t,e){return e===1?{top:"50%"}:{top:`${(t+1)/(e+1)*100}%`}}const zd=t=>{const{id:e,data:n,selected:r,minHeight:o=72,maxHeight:i=300,className:s}=t,[a,l]=b.useState(null),[c,u]=b.useState(!0),d=se.useUpdateNodeInternals(),h=n==null?void 0:n.settings,p=(h==null?void 0:h.onError)===Si.CONTINUE_ERROR_OUTPUT;b.useEffect(()=>{const C=n==null?void 0:n.nodeKey,D=n==null?void 0:n.nodeVersion;if(!C){u(!1);return}let k=!1;return wd(C,D).then(A=>{!k&&A&&l(A)}).catch(A=>{console.error("[NextBaseNode] 加载 Schema 失败:",A)}).finally(()=>{k||u(!1)}),()=>{k=!0}},[n==null?void 0:n.nodeKey,n==null?void 0:n.nodeVersion]);const m=b.useMemo(()=>!(a!=null&&a.inputs)||a.inputs.length===0?[{id:"main",position:se.Position.Left,type:We.TARGET}]:a.inputs.map((C,D)=>({id:C.name,position:se.Position.Left,type:We.TARGET,label:C.displayName,style:H_(D,a.inputs.length)})),[a]),v=b.useMemo(()=>{const C=!(a!=null&&a.outputs)||a.outputs.length===0?[{id:"main",position:se.Position.Right,type:We.SOURCE,maxConnections:1}]:a.outputs.map(A=>({id:A.name,position:se.Position.Right,type:We.SOURCE,maxConnections:1,label:A.displayName})),D=C.some(A=>A.id===Ld),k=p&&!D?[...C,{id:Ld,position:se.Position.Right,type:We.SOURCE,maxConnections:1,label:"error"}]:C;return k.map((A,S)=>({...A,style:H_(S,k.length)}))},[a,p]),w=b.useMemo(()=>{const C=Math.max(m.length,v.length);return C<=1?o:Math.min(C*40,i)},[m.length,v.length,o,i]),y=m.length+v.length;b.useEffect(()=>{if(c||!a||y===0)return;const C=setTimeout(()=>{d(e)},100);return()=>{clearTimeout(C)}},[c,a,y,e,d]);const g=n;return f.jsx(Bn,{id:e,data:g,selected:r,height:w,className:s,icon:g!=null&&g.icon?f.jsx("img",{src:g.icon,alt:g.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:m,outputs:v,status:g.status})},zY=t=>f.jsx(zd,{...t,className:"next-action-node"}),HY=t=>f.jsx(zd,{...t,className:"next-condition-node"}),VY=t=>f.jsx(zd,{...t,className:"next-switch-node",maxHeight:400}),V_=t=>f.jsx(zd,{...t,className:"next-loop-node"}),jY=t=>{const{id:e,data:n,selected:r}=t,o=n,i=[{id:"main",position:se.Position.Right,type:We.SOURCE,isMain:!0,label:"",maxConnections:1}];return f.jsx(Bn,{id:e,data:o,selected:r,type:Z.TRIGGER,status:o==null?void 0:o.status,icon:o!=null&&o.icon?f.jsx("img",{src:o==null?void 0:o.icon,alt:o.label,style:{width:30,height:30}}):f.jsx(rv.PiCursorFill,{style:{color:"#007fff",fontSize:24}}),inputs:[],outputs:i,className:"workflow-trigger-node"})};class WY{static getNodeTypes(){return{[Z.START]:TA,[Z.TRIGGER]:jY,[Z.ACTION]:zY,[Z.CONDITION]:HY,[Z.SWITCH]:VY,[Z.LOOP]:V_,[Z.SELF_LOOP]:V_,[Z.AGENT]:SA,[Z.BROWSER]:EA,[Z.AI_SUB_NODE]:kd,[Z.VECTOR_STORE]:kd,[Z.MCPServer]:OA,[Z.BuiltinMCP]:DA,[Z.MCP_TOOL]:_A,[Z.CUSTOM]:AA,[Z.STICKY]:mO}}}function UY(t,e){const n=new Set(e.map(o=>{var i;return((i=o.data)==null?void 0:i.name)||""}));if(!n.has(t))return t;let r=1;for(;n.has(`${t} ${r}`);)r++;return`${t} ${r}`}const qY={async loadFlow(t){const e=await TB(t),{nodes:n,edges:r,workflowName:o}=IG(e);return{nodes:n,edges:r,name:o,opStatus:e.active?qe.ONLINE:qe.OFFLINE}},async saveFlow({nodes:t,edges:e,workflowName:n,workflowId:r}){await My(r,$G(t,e,n))},async createNode({actionId:t,icon:e,name:n,connectorName:r,nodeVersion:o,existingNodes:i}){const s=UY(n||"",i||[]);return{nodeId:MG(),nodeData:{connector_name:r||"",name:s,action_name:s,label:s,status:1,protocol:"",icon:e,nodeKey:t,nodeVersion:o??1}}},stickyNodeKey:qG,nodeTypes:WY.getNodeTypes(),convertNodeData:Ag,HeaderComponent:YG,PanelComponent:xG,ConfigModalComponent:$Y,requiresTriggerNode:!1},GY=t=>f.jsx(P_,{strategy:qY,...t});var br=(t=>(t.SECOND="second",t.MINUTE="minute",t.HOUR="hour",t))(br||{});function KY(t){return{[br.SECOND]:"SECONDS",[br.MINUTE]:"MINUTES",[br.HOUR]:"HOURS"}[t]}function YY(t){return{SECONDS:br.SECOND,MINUTES:br.MINUTE,HOURS:br.HOUR}[t]}function XY(){return{enableControl:!1,timeoutValue:30,timeoutUnit:br.MINUTE,maxNodeExecutions:1e4,webhookUrl:""}}function JY(t){return{enabled:t.enableControl,timeout_value:t.timeoutValue,timeout_unit:KY(t.timeoutUnit),max_node_executions:t.maxNodeExecutions,webhook_url:t.webhookUrl||void 0}}function RY(t){return{enableControl:t.enabled,timeoutValue:t.timeout_value,timeoutUnit:YY(t.timeout_unit),maxNodeExecutions:t.max_node_executions,webhookUrl:t.webhook_url||""}}function QY(t){if(!t)return!0;try{return new URL(t),!0}catch{return!1}}const{Text:Ow}=x.Typography,ZY=()=>{const[t,e]=b.useState(!1),[n,r]=b.useState(!1),[o]=x.Form.useForm(),i=x.Form.useWatch("enableControl",o),s=Ci(),a=zo(p=>p.workflow.executionControl),l=M_(),c=()=>{e(!0),o.setFieldsValue(a?RY(a):XY())},u=()=>{e(!1)},d=async()=>{try{const p=await o.validateFields();r(!0),s(vO(JY(p))),await l.saveFlow(),x.message.success("保存成功"),e(!1)}catch(p){x.message.error("保存失败"),console.error(p)}finally{r(!1)}},h=(p,m)=>!m||QY(m)?Promise.resolve():Promise.reject(new Error("请输入合法的URL格式"));return f.jsxs(f.Fragment,{children:[f.jsx(x.Tooltip,{title:"流程设置",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Q.SettingOutlined,{}),onClick:c})}),f.jsx(x.Drawer,{title:"流程设置",placement:"right",width:480,open:t,onClose:u,footer:f.jsxs(x.Space,{style:{float:"right"},children:[f.jsx(x.Button,{onClick:u,children:"取消"}),f.jsx(x.Button,{type:"primary",onClick:d,loading:n,children:"保存"})]}),children:f.jsxs(x.Form,{form:o,layout:"vertical",autoComplete:"off",children:[f.jsx(x.Form.Item,{label:"执行管控",name:"enableControl",valuePropName:"checked",children:f.jsx(x.Switch,{})}),i&&f.jsxs(f.Fragment,{children:[f.jsxs(x.Form.Item,{label:"执行超时",required:!0,style:{marginBottom:8},children:[f.jsxs(x.Space.Compact,{style:{width:"100%"},children:[f.jsx(x.Form.Item,{name:"timeoutValue",noStyle:!0,rules:[{required:!0,message:"请输入超时时间"},{type:"number",min:1,message:"必须大于0"}],children:f.jsx(x.InputNumber,{style:{width:"70%"},placeholder:"请输入",min:1})}),f.jsx(x.Form.Item,{name:"timeoutUnit",noStyle:!0,rules:[{required:!0}],children:f.jsxs(x.Select,{style:{width:"30%"},children:[f.jsx(x.Select.Option,{value:br.SECOND,children:"秒"}),f.jsx(x.Select.Option,{value:br.MINUTE,children:"分钟"}),f.jsx(x.Select.Option,{value:br.HOUR,children:"小时"})]})})]}),f.jsx(Ow,{type:"secondary",style:{fontSize:12},children:"流程执行超过此时间将自动终止,使用墙钟时间计算"})]}),f.jsx(x.Form.Item,{label:"最大节点执行次数",name:"maxNodeExecutions",rules:[{required:!0,message:"请输入最大节点执行次数"},{type:"number",min:1,message:"必须为正整数"}],children:f.jsx(x.InputNumber,{style:{width:"100%"},placeholder:"请输入",min:1,precision:0})}),f.jsx(Ow,{type:"secondary",style:{fontSize:12,display:"block",marginTop:-16,marginBottom:16},children:"流程中所有节点执行的总次数上限,超过后将自动终止"}),f.jsx(x.Form.Item,{label:"错误通知 Webhook",name:"webhookUrl",rules:[{validator:h}],children:f.jsx(x.Input,{placeholder:"请输入 Webhook URL"})}),f.jsx(Ow,{type:"secondary",style:{fontSize:12,display:"block",marginTop:-16},children:"流程因超时或超限终止时,将向此地址发送通知"})]})]})})]})},eX=t=>t==="category"?"分类":"标签",j_=({value:t=[],onChange:e,placeholder:n,templateId:r,optionItems:o,type:i,onCreate:s,onUpdate:a,onDelete:l,onAddRelation:c,onRemoveRelation:u})=>{const[d,h]=b.useState(!1),[p,m]=b.useState(null),[v,w]=b.useState(""),[y,g]=b.useState(!1),[C,D]=b.useState(""),[k,A]=b.useState(!1),S=eX(i),E=L=>{var H;return(H=o.find(W=>W.name===L))==null?void 0:H.id},T=async L=>{const H=E(L);if(!H)return;const W=t.includes(L);try{A(!0),W?(await u(r,H),e==null||e(t.filter(K=>K!==L))):(await c(r,H),e==null||e([...t,L]))}finally{A(!1)}},O=(L,H)=>{H.stopPropagation();const W=E(L);W&&u(r,W).then(()=>{e==null||e(t.filter(K=>K!==L))}).catch(()=>{x.message.error("移除失败")})},F=(L,H)=>{H.stopPropagation(),m(L),w(L)},N=async()=>{const L=v.trim();if(!L||!p)return;if(L.length>8){x.message.error("名称长度不能超过8个字符");return}const H=E(p);if(H)try{A(!0),await a(H,L),e==null||e(t.map(W=>W===p?L:W)),x.message.success("修改成功")}catch{x.message.error("修改失败")}finally{A(!1),m(null),w("")}},I=()=>{m(null),w("")},P=async L=>{const H=E(L);if(H)try{A(!0),await l(H),e==null||e(t.filter(W=>W!==L)),x.message.success("删除成功")}catch{x.message.error("删除失败")}finally{A(!1)}},_=async()=>{const L=C.trim();if(L){if(L.length>8){x.message.error("名称长度不能超过8个字符");return}try{A(!0),await s(L),g(!1),D(""),x.message.success("创建成功")}catch{x.message.error("创建失败")}finally{A(!1)}}},B=()=>{g(!1),D("")};return f.jsxs("div",{className:"template-editable-select",children:[f.jsxs("div",{className:"template-editable-select-input",onClick:()=>h(!d),children:[f.jsx("div",{className:"template-editable-select-tags",children:t.length===0?f.jsx("span",{className:"template-editable-select-placeholder",children:n}):t.map(L=>f.jsx(x.Tag,{closable:!0,onClose:H=>O(L,H),style:{marginRight:4,marginBottom:4},children:L},L))}),f.jsx("div",{className:`template-editable-select-arrow ${d?"template-editable-select-arrow-open":""}`,children:f.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:f.jsx("path",{d:"M2.5 4.5L6 8L9.5 4.5",stroke:"#666",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5"})})})]}),d&&f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"template-editable-select-dropdown-overlay",onClick:()=>h(!1)}),f.jsx("div",{className:"template-editable-select-dropdown-container",onClick:L=>L.stopPropagation(),children:f.jsxs("div",{className:"template-editable-select-dropdown",children:[o.map(L=>f.jsx("div",{className:"template-editable-select-dropdown-item",children:p===L.name?f.jsx("div",{className:"template-editable-select-edit-container",children:f.jsx(x.Input,{autoFocus:!0,className:"template-editable-select-edit-input",disabled:k,maxLength:8,onChange:H=>w(H.target.value),onPressEnter:N,placeholder:`输入新${S}名称(8个字符以内)`,size:"small",suffix:f.jsxs("div",{className:"template-editable-select-edit-actions",children:[f.jsx(x.Button,{className:"template-editable-select-confirm-btn",icon:f.jsx(Q.CheckOutlined,{}),loading:k,onClick:N,size:"small",type:"text"}),f.jsx(x.Button,{className:"template-editable-select-cancel-btn",disabled:k,icon:f.jsx(Q.CloseOutlined,{}),onClick:I,size:"small",type:"text"})]}),value:v})}):f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"template-editable-select-item-content",onClick:()=>T(L.name),children:[f.jsx("div",{className:"template-editable-select-check",children:t.includes(L.name)&&f.jsx(Q.CheckOutlined,{style:{color:"#1890ff"}})}),f.jsx("span",{className:"template-editable-select-name",children:L.name})]}),f.jsxs("div",{className:"template-editable-select-actions",children:[f.jsx(x.Button,{className:"template-editable-select-action-btn",disabled:k,icon:f.jsx(Q.EditOutlined,{}),onClick:H=>F(L.name,H),size:"small",type:"text"}),f.jsx(x.Popconfirm,{cancelText:"取消",okText:"确定",onConfirm:()=>P(L.name),title:`确定删除${S}"${L.name}"吗?`,children:f.jsx(x.Button,{className:"template-editable-select-action-btn",danger:!0,disabled:k,icon:f.jsx(Q.DeleteOutlined,{}),onClick:H=>H.stopPropagation(),size:"small",type:"text"})})]})]})},L.id)),y?f.jsx("div",{className:"template-editable-select-dropdown-item",children:f.jsx("div",{className:"template-editable-select-edit-container",children:f.jsx(x.Input,{autoFocus:!0,className:"template-editable-select-edit-input",disabled:k,maxLength:8,onChange:L=>D(L.target.value),onPressEnter:_,placeholder:`输入新${S}名称(8个字符以内)`,size:"small",suffix:f.jsxs("div",{className:"template-editable-select-edit-actions",children:[f.jsx(x.Button,{className:"template-editable-select-confirm-btn",icon:f.jsx(Q.CheckOutlined,{}),loading:k,onClick:_,size:"small",type:"text"}),f.jsx(x.Button,{className:"template-editable-select-cancel-btn",disabled:k,icon:f.jsx(Q.CloseOutlined,{}),onClick:B,size:"small",type:"text"})]}),value:C})})}):f.jsxs("div",{className:"template-editable-select-add-item",onClick:()=>g(!0),children:[f.jsx(Q.PlusOutlined,{style:{color:"#1890ff",marginRight:4}}),f.jsx("span",{children:"添加选项"})]})]})})]})]})},{TextArea:tX}=x.Input,{Text:_w,Title:Hd}=x.Typography,W_=t=>Array.isArray(t)?t.map(e=>e.name).filter(Boolean):[],nX=({open:t,workflowId:e,workflowName:n,onOpenChange:r,onSuccess:o})=>{const[i]=x.Form.useForm(),s=Ci(),[a,l]=b.useState(!1),[c,u]=b.useState(!1),[d,h]=b.useState([]),[p,m]=b.useState([]),[v,w]=b.useState([]),[y,g]=b.useState([]),C=b.useCallback(async()=>{const B=await iy();return h(B||[]),B},[]),D=b.useCallback(async()=>{const B=await dy();return m(B||[]),B},[]),k=b.useCallback(async()=>{if(e){u(!0);try{let B;try{B=await ry(e)}catch{B=await wf(e)}const L=W_(B==null?void 0:B.categories),H=W_(B==null?void 0:B.tags);w(L),g(H),i.setFieldsValue({name:(B==null?void 0:B.name)||n||"",description:(B==null?void 0:B.description)||"",category:L,tags:H})}catch{x.message.error("获取模板设置失败"),w([]),g([]),i.setFieldsValue({name:n||"",description:"",category:[],tags:[]})}finally{u(!1)}}},[i,e,n]);b.useEffect(()=>{t&&(k(),C().catch(()=>{x.message.error("获取分类列表失败")}),D().catch(()=>{x.message.error("获取标签列表失败")}))},[C,D,k,t]);const A=async B=>{const L=await sy({name:B});return await C(),L},S=async(B,L)=>{const H=await ay(B,{name:L});return await C(),H},E=async B=>{const L=await ly(B);return await C(),L},T=async B=>{const L=await fy({name:B});return await D(),L},O=async(B,L)=>{const H=await hy(B,{name:L});return await D(),H},F=async B=>{const L=await py(B);return await D(),L},N=async()=>{try{const B=await i.validateFields();l(!0);const L={description:B.description,ai_flow:1,id:e};B.name&&(L.name=B.name);try{await oy(e,L)}catch{await Pl(e,L)}B.name&&s($o(B.name)),x.message.success("模板设置已保存"),r(!1),o==null||o()}catch(B){if(B!=null&&B.errorFields)return;x.message.error("保存失败,请重试")}finally{l(!1)}},I=()=>{r(!1)},P=B=>{w(B),i.setFieldValue("category",B)},_=B=>{g(B),i.setFieldValue("tags",B)};return f.jsx(x.Modal,{cancelText:"取消",confirmLoading:a,okText:"保存设置",onCancel:I,onOk:N,open:t,title:f.jsxs(x.Space,{children:[f.jsx(Q.SettingOutlined,{}),f.jsx("span",{children:"模板设置"})]}),width:600,children:c?f.jsx(x.Skeleton,{active:!0,paragraph:{rows:8}}):f.jsxs("div",{className:"workflow-template-settings-modal",children:[f.jsx("div",{className:"workflow-template-settings-hint",children:f.jsx(_w,{type:"secondary",children:"设置模板的基本信息,包括描述和分类标签,便于更好地组织和管理模板。"})}),f.jsxs(x.Form,{form:i,layout:"vertical",preserve:!1,requiredMark:!1,children:[f.jsxs(x.Card,{bodyStyle:{padding:16},className:"workflow-template-settings-card",size:"small",children:[f.jsxs(x.Space,{className:"workflow-template-settings-section-title",children:[f.jsx(Q.FileTextOutlined,{style:{color:"#1890ff"}}),f.jsx(Hd,{level:5,children:"模板名称"})]}),f.jsx(x.Form.Item,{name:"name",rules:[{max:50,message:"最多50个字符"}],children:f.jsx(x.Input,{placeholder:"请输入模板名称",size:"large"})})]}),f.jsxs(x.Card,{bodyStyle:{padding:16},className:"workflow-template-settings-card",size:"small",children:[f.jsxs(x.Space,{className:"workflow-template-settings-section-title",children:[f.jsx(Q.FileTextOutlined,{style:{color:"#1890ff"}}),f.jsx(Hd,{level:5,children:"模板描述"})]}),f.jsx(x.Form.Item,{name:"description",rules:[{max:500,message:"最多500个字符"}],children:f.jsx(tX,{maxLength:500,placeholder:"请输入模板描述,描述该模板的功能和使用场景...",rows:4,showCount:!0})})]}),f.jsxs(x.Card,{bodyStyle:{padding:16},className:"workflow-template-settings-card",size:"small",children:[f.jsxs(x.Space,{className:"workflow-template-settings-section-title",children:[f.jsx(Q.TagsOutlined,{style:{color:"#1890ff"}}),f.jsx(Hd,{level:5,children:"模板分类"}),f.jsx(_w,{className:"workflow-template-settings-subtitle",type:"secondary",children:"(可多选)"})]}),f.jsx(x.Form.Item,{name:"category",rules:[{required:!0,message:"请选择模板分类"}],children:f.jsx(j_,{onAddRelation:cy,onChange:P,onCreate:A,onDelete:E,onRemoveRelation:uy,onUpdate:S,optionItems:d,placeholder:"请选择模板分类",templateId:e,type:"category",value:v})})]}),f.jsxs(x.Card,{bodyStyle:{padding:16},className:"workflow-template-settings-card workflow-template-settings-card-last",size:"small",children:[f.jsxs(x.Space,{className:"workflow-template-settings-section-title",children:[f.jsx(Q.TagsOutlined,{style:{color:"#52c41a"}}),f.jsx(Hd,{level:5,children:"模板标签"}),f.jsx(_w,{className:"workflow-template-settings-subtitle",type:"secondary",children:"(可多选)"})]}),f.jsx(x.Form.Item,{name:"tags",children:f.jsx(j_,{onAddRelation:my,onChange:_,onCreate:T,onDelete:F,onRemoveRelation:gy,onUpdate:O,optionItems:p,placeholder:"请选择模板标签",templateId:e,type:"tag",value:y})})]})]})]})})},{Title:rX,Text:Tw}=x.Typography,U_="[workflow:online-validation]",oX=({opStatus:t})=>{const e=lo();return{[qe.UNPUBLISHED]:f.jsx(x.Tag,{bordered:!1,color:"orange",children:f.jsx(Se.FormattedMessage,{id:"app.common.word.not-published"})}),[qe.ONLINE]:f.jsx(x.Tag,{bordered:!1,color:"green",children:f.jsx(Se.FormattedMessage,{id:"app.common.word.already-online"})}),[qe.OFFLINE]:f.jsx(x.Tag,{bordered:!1,color:"default",children:f.jsx(Se.FormattedMessage,{id:"app.common.word.already-offline"})}),[qe.ONLINE_ING]:f.jsx(x.Tag,{bordered:!1,color:"processing",children:f.jsx(Se.FormattedMessage,{id:"app.common.word.going-online"})}),[qe.ON_WARN]:f.jsx(zl,{to:`/link/log?warnId=${e}`,children:f.jsxs(x.Space,{size:[5,5],children:[f.jsx(Q.ExclamationCircleOutlined,{style:{color:"#faad14"}}),f.jsx(Se.FormattedMessage,{id:"common.warning"})]})}),[qe.OFF_WARN]:f.jsx(zl,{to:`/link/log?warnId=${e}`,children:f.jsxs(x.Space,{size:[5,5],children:[f.jsx(Q.ExclamationCircleOutlined,{style:{color:"#faad14"}}),f.jsx(Se.FormattedMessage,{id:"common.warning"})]})})}[t]},iX=({onSave:t,readOnly:e=!1,preview:n=!1,autoSaveStatus:r=pn.IDLE,lastSavedTime:o,unSave:i,appFlowMode:s=!1,canvasApi:a})=>{var de,z;const l=Ci(),c=Ct(),u=zo(U=>U.workflow.workflowName),d=zo(U=>U.workflow.op_status),[h,p]=b.useState(!1),[m,v]=b.useState(u),[w,y]=b.useState(!1),[g,C]=b.useState(!1),D=b.useRef(null),{getNodes:k}=se.useReactFlow(),A=Wt(),S=A.toolbar,E=S==null?void 0:S.templateSettings,T=lo(),O=((de=k().filter(U=>U.type!==Z.START))==null?void 0:de.length)>0;b.useEffect(()=>{v(u)},[u]),b.useEffect(()=>{h&&D.current&&D.current.focus()},[h]);const F=b.useCallback(()=>{const Y=k().filter(ee=>ee.type!==Z.START).filter(ee=>ee.data.status!==pe.SUCCESS&&ee.data.status!==pe.RUNNABLE);return Y.length&&console.warn(`${U_} node status check failed`,{unhealthyNodes:Y.map(ee=>({id:ee.id,name:ee.data.name,type:ee.type,status:ee.data.status}))}),Y.length===0},[k]),N=b.useCallback(()=>{const U=k().filter(Y=>Y.type!==Z.START),X=(Y,ee,re)=>(console.warn(`${U_} required config check failed`,{node:{id:Y.id,name:Y.data.name,type:Y.type,status:Y.data.status},reason:ee,details:re,configSchema:Y.data.config_schema}),!1);for(const Y of U){const{data:ee,type:re}=Y,{config_schema:ce}=ee;if(re===Z.LOOP){if(!(ce!=null&&ce.asc))return X(Y,"loop config is missing asc");const Ce=Object.keys(ce??{});if(Ce.length===0)return X(Y,"loop config schema is empty");if(Ce.some(Oe=>typeof ce[Oe]>"u"))return X(Y,"loop config contains undefined values",{undefinedKeys:Ce.filter(Oe=>typeof ce[Oe]>"u")})}else if(re===Z.CONDITION){if(!(ce!=null&&ce.or_list)||!ce.or_list.length)return X(Y,"condition config is missing or_list");if(!ce.or_list.every(Oe=>Oe.and_list.every(Pe=>Pe.query&&Pe.operator)))return X(Y,"condition config contains incomplete rules")}else if(re===Z.SWITCH){if(!(ce!=null&&ce.branches)||!ce.branches.length)return X(Y,"switch config is missing branches");if(!ce.branches.every(Oe=>Oe.or_list.every(Pe=>Pe.and_list.every(Ae=>Ae.query&&Ae.operator))))return X(Y,"switch config contains incomplete branch rules")}else if(re!==Z.STICKY){const Ce=ce==null?void 0:ce.sub_params;if(!Array.isArray(Ce))return X(Y,"config_schema.sub_params is missing or invalid");const Oe=Ce.every(Ae=>(console.log("subParams :",Ce),Ae.required?typeof Ae.value<"u"&&Ae.value!==null:!0));if(!Oe)return X(Y,"required parameters are missing",{missingParams:Ce.filter(Ae=>Ae.required&&(typeof Ae.value>"u"||Ae.value===null)).map(Ae=>({key:Ae.key,name:Ae.name,label:Ae.label}))});const Pe=ce!=null&&ce.account_schema_id?!!ce.account_id:!0;if(!Oe||!Pe)return X(Y,"account is required but account_id is missing",{accountSchemaId:ce==null?void 0:ce.account_schema_id,accountId:ce==null?void 0:ce.account_id})}}return!0},[k]),I=()=>{if((d===qe.ONLINE||d===qe.ON_WARN)&&(!N()||!F())){x.message.warning("当前流程节点存在异常,请完成节点测试或下线流程后再尝试保存");return}t==null||t()},P=U=>{v(U.target.value)};dt.useUnmount(()=>{l(Nd()),$o("")});const _=b.useCallback(()=>{const U=u,X=m.trim(),Y=X||"未命名工作流";l($o(Y)),Pl(T,{name:Y}).then(()=>{}).catch(()=>{l($o(U))}),p(!1)},[l,m,u]),B=()=>{_()},L=()=>{_()},H=()=>{var U;!e&&((U=S==null?void 0:S.flowName)==null?void 0:U.editable)!==!1&&p(!0)},W=()=>{if(i)return f.jsx(x.Tooltip,{title:"暂未保存",children:f.jsx(x.Tag,{bordered:!1,color:"warning",children:"未保存"})});switch(r){case pn.SAVING:return f.jsx(x.Tooltip,{children:f.jsx("div",{style:{display:"flex",alignItems:"center"},children:f.jsx(Q.SyncOutlined,{spin:!0,style:{marginRight:8,color:"#1890ff"}})})});case pn.SAVED:return f.jsx(x.Tooltip,{title:`已自动保存 (${o})`,children:f.jsx("div",{style:{display:"flex",alignItems:"center"},children:f.jsxs(x.Tag,{bordered:!1,color:"green",children:["已保存"," ",f.jsx("span",{style:{fontSize:10,marginLeft:4,color:"#999"},children:o})]})})});case pn.ERROR:return f.jsx(x.Tooltip,{title:"自动保存失败",children:f.jsx(x.Badge,{status:"error",text:f.jsx("span",{children:"保存失败"})})});default:return null}},[K,q]=x.Modal.useModal(),te=async()=>{var Y;const U=d===qe.ONLINE||d===qe.ON_WARN,X=()=>{var ee,re;if((ee=S==null?void 0:S.nav)!=null&&ee.onBack){S.nav.onBack();return}if((re=S==null?void 0:S.nav)!=null&&re.backTo){Mi.push(S.nav.backTo);return}s?Mi.back():Mi.push("/link/ai-flow")};if(!U&&((Y=S==null?void 0:S.nav)!=null&&Y.confirmOnBackWhenOffline)&&i){await K.confirm({title:R("user.common.operation_title"),content:S.nav.backConfirmMessage||"当前流程未保存,是否确认返回?"})&&X();return}X()},$=async(U={})=>{if(!T)return;y(!0);const{force:X=!1,customFn:Y}=U;return(X?Ty(T):Y?Y(T):xf(T,qe.ONLINE)).then(()=>(x.message.success(R("link.flow.online_success")),l(Os(qe.ONLINE)),{success:!0})).catch(re=>({success:!1,error:re})).finally(()=>{y(!1)})},V=async U=>{if(!T)return;y(!0),(U?U(T):xf(T,qe.OFFLINE)).then(()=>{x.message.success(R("link.flow.offline_success")),l(Os(qe.OFFLINE))}).catch(()=>{}).finally(()=>{y(!1)})},J=async()=>await K.confirm({icon:f.jsx(f.Fragment,{}),centered:!0,title:R("link.flow.confirm_online"),content:(S==null?void 0:S.enableOnlineConfirmMessage)||R("link.flow.force_online_confirm"),cancelText:R("common.no"),okText:R("common.yes")}),ne=async U=>{if(U){if(!F()){await J()&&await $({force:!0,customFn:S==null?void 0:S.customOnlineApi});return}const Y=await $({force:!1,customFn:S==null?void 0:S.customOnlineApi});Y&&!Y.success&&await J()&&await $({force:!0,customFn:S==null?void 0:S.customOnlineApi})}else V(S==null?void 0:S.customOfflineApi)},ae=()=>{var X,Y,ee,re;const U=[];return((X=S==null?void 0:S.nav)==null?void 0:X.showBack)!==!1&&(U.push(f.jsx(x.Button,{type:"text",icon:f.jsx(Q.ArrowLeftOutlined,{className:"workflow-back-icon"}),onClick:te,children:R("app.common.word.back")},"back")),U.push(f.jsx(x.Divider,{type:"vertical"},"divider-back"))),s||(h?U.push(f.jsx(x.Input,{ref:D,value:m,onChange:P,onPressEnter:B,onBlur:L,maxLength:30,className:"workflow-name-input",placeholder:"请输入工作流名称"},"name-input")):U.push(f.jsx("div",{className:"workflow-name",onClick:n?void 0:H,children:u?f.jsxs(f.Fragment,{children:[f.jsx(rX,{level:4,className:"workflow-name-text",children:u}),!e&&!n&&((Y=S==null?void 0:S.flowName)==null?void 0:Y.editable)&&f.jsx(Q.FormOutlined,{className:"edit-icon"})]}):f.jsx(x.Skeleton.Input,{active:!0,size:"small"})},"name-display")),U.push(f.jsx(x.Divider,{type:"vertical"},"divider-name"))),n?U.push(f.jsx(Tw,{type:"secondary",children:"预览模式"},"preview-text")):U.push(f.jsxs(x.Space,{size:8,children:[A.toolbar.enableOnlineButton&&f.jsxs(b.Fragment,{children:[f.jsx(Tw,{children:(S==null?void 0:S.enableFlowText)||"启用流程"}),f.jsx(x.Switch,{disabled:!O,onChange:ne,loading:w,checked:d===qe.ONLINE||d===qe.ON_WARN})]}),f.jsx(x.Divider,{type:"vertical"}),((ee=S==null?void 0:S.flowStatusTag)==null?void 0:ee.enabled)===!1?null:f.jsx("span",{style:(re=S==null?void 0:S.flowStatusTag)==null?void 0:re.style,children:f.jsx(oX,{opStatus:d})})]},"online-area")),U.push(f.jsx(x.Divider,{type:"vertical"},"divider-status")),!c&&!n&&U.push(f.jsx(Tw,{type:"secondary",children:"当前流为只读模式,如需编辑,请下线流程"},"readonly-hint")),U};return f.jsxs("div",{className:"workflow-canvas-header",children:[q,f.jsx("div",{className:"workflow-heder-left-area",children:ae()}),f.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[c&&!n&&W(),f.jsx("span",{children:f.jsx(x.Button,{icon:f.jsx(Q.QuestionCircleOutlined,{}),type:"link",onClick:()=>{const U=(S==null?void 0:S.helpDocUrl)||"https://1in15q85qd.apifox.cn/8698531m0";window.open(U,"_blank")},children:(S==null?void 0:S.helpDocText)||"帮助文档"})}),f.jsxs(x.Space,{style:{marginLeft:16},children:[c&&!n&&(E==null?void 0:E.enabled)&&T&&f.jsx(x.Tooltip,{title:E.buttonText||"模板设置",children:f.jsx(x.Button,{icon:f.jsx(Q.SettingOutlined,{}),onClick:()=>C(!0),type:"text",children:E.buttonText||"模板设置"})}),(z=S==null?void 0:S.buttons)==null?void 0:z.map(U=>f.jsx(x.Button,{style:U.style,icon:U.icon,type:U.type??"default",onClick:()=>{U.onClick&&a&&U.onClick(a)},children:U.label},U.id)),c&&!n&&f.jsx(ZY,{}),c&&!n&&f.jsx(f.Fragment,{children:f.jsx(x.Tooltip,{title:"保存",children:f.jsx(x.Button,{onClick:I,type:"primary",children:"保存"})})})]})]}),(E==null?void 0:E.enabled)&&T&&f.jsx(nX,{onOpenChange:C,open:g,workflowId:T,workflowName:u})]})},sX=({categories:t,activeId:e,loading:n,onChange:r})=>n?f.jsx("div",{className:"category-tabs-wrapper loading",children:f.jsxs("div",{className:"category-tabs-loading",children:[f.jsx(x.Spin,{size:"small"}),f.jsx("span",{children:"分类加载中"})]})}):f.jsxs("div",{className:"category-tabs-wrapper",children:[f.jsx("div",{className:"category-tabs",children:t.map(o=>f.jsx("div",{className:Sn("category-tab",{active:e===o.id}),onClick:()=>r(o),children:o.name},o.id))}),f.jsx("div",{className:"category-tabs-mask left"}),f.jsx("div",{className:"category-tabs-mask right"})]}),aX=({action:t,parentNode:e,onSelect:n})=>{const r=()=>{n(e,t)};return f.jsxs("div",{className:"action-item",onClick:r,children:[f.jsx("div",{className:"item-icon","data-category":e.category.split("-")[0]||"action",children:t.icon?f.jsx("img",{src:t.icon,alt:t.name,style:{width:32,height:32}}):f.jsx("div",{children:t.name.charAt(0).toUpperCase()})}),f.jsxs("div",{className:"item-content",children:[f.jsx("div",{className:"item-title",children:t.name}),t.description&&f.jsx("div",{className:"item-description",children:t.description})]})]})},lX=({node:t,expanded:e,actions:n,loading:r,hasPartialActions:o,onToggle:i,onActionSelect:s,onLoadAllActions:a})=>{const l=()=>{i(t)},c=u=>{u.stopPropagation(),a==null||a(t)};return f.jsxs("div",{className:Sn("node-card",{expanded:e}),children:[f.jsxs("div",{className:"node-card-header",onClick:l,children:[f.jsx("div",{className:"node-card-icon",children:t.icon?f.jsx("img",{src:t.icon,alt:t.name}):f.jsx("span",{children:t.name.charAt(0).toUpperCase()})}),f.jsxs("div",{className:"node-card-info",children:[f.jsx("div",{className:"node-card-title",children:t.name}),t.description&&f.jsx("div",{className:"node-card-desc",children:t.description})]}),f.jsx(Q.CaretDownOutlined,{className:Sn("node-card-arrow",{expanded:e})})]}),e&&f.jsxs("div",{className:"node-card-body",children:[r?f.jsx("div",{className:"node-card-state",children:"动作加载中..."}):n.length===0?f.jsx("div",{className:"node-card-state",children:"暂无可用动作"}):f.jsx("div",{className:"node-card-actions",children:n.map(u=>f.jsx("div",{className:"node-card-action-wrapper",onClick:d=>d.stopPropagation(),children:f.jsx(aX,{action:u,parentNode:t,onSelect:s})},u.id))}),o&&!r&&f.jsx("div",{className:"node-card-more",onClick:c,children:"查看该节点全部动作"})]})]})},cX=({currentCategory:t,categoryPath:e,selectedNode:n,onBack:r,onClose:o,title:i,subTitle:s,showBackButton:a})=>{const l=()=>n?n.name:t?t.name:"节点选择器",c=()=>n?"选择动作":e.length>0?e.slice(0,-1).map(p=>p.name).join(" / "):"",u=i||l(),d=s??c(),h=typeof a=="boolean"?a:!!(n||e.length>0);return f.jsxs("div",{className:"panel-header",children:[f.jsxs("div",{className:"header-left",children:[h&&r&&f.jsx("div",{className:"back-button",onClick:r,children:f.jsx(Q.ArrowLeftOutlined,{})}),f.jsxs("div",{className:"title",children:[u,d&&f.jsx("div",{className:"category-path",children:d})]})]}),f.jsx("div",{className:"close-button",onClick:o,children:f.jsx(Q.CloseOutlined,{})})]})},q_=[],G_=Object.freeze(Object.defineProperty({__proto__:null,defaultCategories:q_},Symbol.toStringTag,{value:"Module"})),Nw="[workflow:schema-render]",uX=new Set(Object.values(Z)),dX=t=>{if(t)return uX.has(t)?t:void 0},fX=({nodeSelectorVisible:t,nodeAddInfo:e})=>{const[n,r]=b.useState(!1),o=lo();return{isLoadingActions:n,fetchNodeActions:async(s,a)=>{a!=null&&a.suppressLoading||r(!0);try{const l=t&&e&&e.trigger===!0,c={linkId:s.id,flowId:o},u=(e==null?void 0:e.protocol)===Ie.BUILTIN_MCP?Z.MCP_TOOL:dX(s.type);u&&(c.actionType=u),l&&(c.trigger=!0);const d=await Qv(c);return d&&d.items&&Array.isArray(d.items)?d.items.map(p=>{var v,w,y,g;const m=p.action_ver??((v=p.node_schema)==null?void 0:v.version);return p.action_key&&((y=(w=p.node_schema)==null?void 0:w.input_fields)!=null&&y.length)?(console.info(`${Nw} preload schema from actions list`,{actionId:p.id,nodeKey:p.action_key,actionVer:p.action_ver,schemaVersion:p.node_schema.version,resolvedVersion:m,inputFields:p.node_schema.input_fields.length}),gA(p.action_key,m,p.node_schema)):p.action_key&&p.node_schema?console.info(`${Nw} action list inline schema has no inputFields`,{actionId:p.id,nodeKey:p.action_key,actionVer:p.action_ver,schemaVersion:p.node_schema.version,resolvedVersion:m,inputFields:((g=p.node_schema.input_fields)==null?void 0:g.length)??0}):p.action_key&&console.info(`${Nw} action list item without inline schema`,{actionId:p.id,nodeKey:p.action_key,resolvedVersion:m}),{...p,id:p.id,action_key:p.action_key,action_ver:m,nodeKey:p.action_key,nodeVersion:m,node_schema:p.node_schema,name:p.name||"未命名动作",description:p.description||"",connector_name:s.name,nodeId:s.id,nodeIcon:s.icon}}):[]}catch(l){return console.error("获取动作列表失败:",l),[]}finally{a!=null&&a.suppressLoading||r(!1)}}}},hX=({onFetchCategories:t,restrictToCategory:e,nodeSelectorVisible:n,nodeAddInfo:r,fallbackCategories:o=[]})=>{const[i,s]=b.useState(o),[a,l]=b.useState(!1);return b.useEffect(()=>{if(!n)return;(async()=>{l(!0);try{let u="action";const d=n&&r&&r.trigger,h=r==null?void 0:r.protocol,p=!!h;d?u="trigger":h===Ie.AI_TOOL?u="mcp":h===Ie.BUILTIN_MCP?u="tool":h===Ie.AI_LANGUAGE_MODEL?u="model":h===Ie.AI_MEMORY&&(u="memory");const m=await t(u),v=e?m.filter(y=>y.id===e):d?m:m.filter(y=>y.id!=="TRIGGER"),w=e||p?null:{id:"ALL",name:"全部",description:"全部分类",icon:void 0};s(w?[w,...v]:v)}catch(u){console.error("Failed to fetch categories:",u),s(o)}finally{l(!1)}})()},[t,e,n,r,o]),{categories:i,isLoadingCategories:a,setCategories:s}},pX=({categories:t,initialCategory:e,nodeSelectorVisible:n,nodeAddInfo:r,onFetchNodesByCategory:o,defaultPageSize:i=20,flowId:s})=>{const[a,l]=b.useState(e||"ALL"),[c,u]=b.useState([]),[d,h]=b.useState(!1),[p,m]=b.useState({page:1,size:i,total:0,hasMore:!0}),v=n&&r&&r.trigger===!0,w=n&&r&&r.protocol===Ie.AI_TOOL,y=n&&r&&r.protocol===Ie.BUILTIN_MCP,g=b.useMemo(()=>{const O=r==null?void 0:r.protocol;if(O){if(O===Ie.AI_TOOL)return Ie.MCP;if(O===Ie.AI_LANGUAGE_MODEL||O===Ie.AI_MEMORY)return O}},[r==null?void 0:r.protocol]),C=b.useMemo(()=>{const O=r==null?void 0:r.protocol;if(O===Ie.AI_TOOL)return"tool";if(O===Ie.AI_LANGUAGE_MODEL)return"model";if(O===Ie.AI_MEMORY)return"memory"},[r==null?void 0:r.protocol]),D=b.useMemo(()=>a==="ALL"?null:t.find(O=>O.id===a)||null,[a,t]),k=b.useCallback((O,F=1)=>({app_domain_category:O&&O!=="ALL"?O:void 0,page:F,size:i,trigger:!!v,type:C,protocol:g,flow_id:s}),[i,v,C,g,s]),A=b.useCallback(async(O,F=1,N=!1)=>{if(n){h(!0);try{const I=k(O,F),{nodes:P,total:_,size:B}=await o(I);u(L=>N?[...L,...P]:P),m({page:F,size:B,total:_,hasMore:F*B<_})}catch(I){console.error("Failed to fetch category data:",I),N||u([])}finally{h(!1)}}},[k,n,o]),S=b.useCallback(async O=>{l(O),await A(O,1,!1)},[A]),E=b.useCallback(async()=>{d||!p.hasMore||await A(a||"ALL",p.page+1,!0)},[A,d,p,a]),T=b.useCallback(()=>{l(e||"ALL"),u([]),m({page:1,size:i,total:0,hasMore:!0})},[e,i]);return b.useEffect(()=>{var F,N;if(!n){T();return}const O=e&&((F=t.find(I=>I.id===e))==null?void 0:F.id)||((N=t[0])==null?void 0:N.id)||"ALL";l(O),A(O,1,!1)},[n,t,e,A,T]),{categoryNodes:c,currentCategory:D,isLoadingNodes:d,isRealTriggerMode:v,isAIToolMode:w,isBuiltinMCPMode:y,navigateToCategory:S,loadMoreNodes:E,resetNavigation:T,pagination:p,activeCategoryId:a,setActiveCategoryId:l}},mX=({onSearch:t})=>{const[e,n]=b.useState(""),[r,o]=b.useState([]),[i,s]=b.useState(!1),[a,l]=b.useState({total:0,page:1,size:20}),c=b.useCallback(async(d,h={})=>{if(n(d),!d.trim()){o([]),l({total:0,page:1,size:h.size||20});return}s(!0);try{const{nodes:p,total:m,page:v,size:w}=await t({...h,name:d});o(p),l({total:m,page:v,size:w})}catch(p){console.error("Search failed:",p),o([]),l({total:0,page:1,size:h.size||20})}finally{s(!1)}},[t]),u=b.useCallback(()=>{n(""),o([]),l({total:0,page:1,size:20})},[]);return{searchText:e,searchResults:r,isSearching:i,searchMeta:a,handleSearch:c,clearSearch:u,setSearchText:n}},Bw="[workflow:schema-render]",gX=(t,e)=>{var o,i,s,a;const n=t.action_type||t.node_struct||Z.ACTION,r=t.action_ver??((o=t.node_schema)==null?void 0:o.version);return t.action_key&&((s=(i=t.node_schema)==null?void 0:i.input_fields)!=null&&s.length)?(console.info(`${Bw} preload schema from search result`,{actionId:t.id,nodeKey:t.action_key,actionVer:t.action_ver,schemaVersion:t.node_schema.version,resolvedVersion:r,inputFields:t.node_schema.input_fields.length}),gA(t.action_key,r,t.node_schema)):t.action_key&&t.node_schema?console.info(`${Bw} search result inline schema has no inputFields`,{actionId:t.id,nodeKey:t.action_key,actionVer:t.action_ver,schemaVersion:t.node_schema.version,resolvedVersion:r,inputFields:((a=t.node_schema.input_fields)==null?void 0:a.length)??0}):t.action_key&&console.info(`${Bw} search result action without inline schema`,{actionId:t.id,nodeKey:t.action_key,resolvedVersion:r}),{...t,id:t.id,type:n,action_type:n,action_key:t.action_key,action_ver:r,nodeKey:t.action_key,nodeVersion:r,node_schema:t.node_schema,action_name:t.name||e.name,name:t.name||e.name,description:t.description||e.description||"",connector_name:e.name,nodeId:e.id,nodeIcon:e.icon}},wX=(t,e)=>{if(typeof e=="boolean")return e;if(!t)return!1;const n=t.toUpperCase();return n==="ACTION_ONLY"||n==="BOTH_MATCHED"},vX=(t,e)=>{const{matchedActions:n,defaultExpanded:r,matchType:o}=e||{};return{id:t.id||t.name,type:t.build_type||Z.ACTION,name:t.name,description:t.description||"",category:t.app_domain_category&&t.app_domain_category[0]||"unknown",icon:t.icon||void 0,app_domain_category:t.app_domain_category||[],actionCategories:t.app_action_category||[],deployment_type:t.deployment_type,build_type:t.build_type,matchedActions:n,defaultExpanded:wX(o,r),matchType:o,connector:t}},K_=async(t={})=>{var e;try{const{apiSearchLinks:n}=await Promise.resolve().then(()=>Iy),r=await n({...t,page:t.page||1,size:t.size||20}),o=((e=r.items)==null?void 0:e.map(({connector:i,matched_actions:s,default_expanded:a,match_type:l})=>{const c=(s||[]).map(u=>gX(u,i));return vX(i,{matchedActions:c,defaultExpanded:a,matchType:l})}))||[];return{nodes:o,total:r.total||o.length,page:r.page||t.page||1,size:r.size||t.size||20,pages:r.pages}}catch(n){return console.error("获取节点列表失败:",n),{nodes:[],total:0,page:t.page||1,size:t.size||20,pages:0}}},yX=async t=>{try{const{apiGetNodeCategory:e}=await Promise.resolve().then(()=>Iy),{defaultCategories:n}=await Promise.resolve().then(()=>G_),r=await e({type:t}),o=i=>({id:i.name,name:i.label,description:i.desc||"",icon:i.icon||void 0,search_action:i.search_action||!1,children:i.next&&i.next.length>0?i.next.map(s=>o(s)):void 0,nodes:[]});return Array.isArray(r)?r.map(i=>o(i)):n}catch(e){console.error("获取分类失败:",e);const{defaultCategories:n}=await Promise.resolve().then(()=>G_);return n}},bX=({availableCategories:t=q_,initialCategory:e,onSearch:n,onFetchCategories:r,onFetchNodesByCategory:o,restrictToCategory:i})=>{const s=b.useRef(null),a=b.useRef(null),[l,c]=b.useState([]),[u,d]=b.useState({}),h=n||K_,p=r||yX,m=o||K_,{nodeSelectorVisible:v,closeNodeSelector:w,handleNodeSelect:y,nodeAddInfo:g}=_s(),C=lo(),{fetchNodeActions:D}=fX({nodeSelectorVisible:v,nodeAddInfo:g}),{categories:k,isLoadingCategories:A}=hX({onFetchCategories:p,restrictToCategory:i,nodeSelectorVisible:v,nodeAddInfo:g,fallbackCategories:t}),{searchText:S,searchResults:E,isSearching:T,handleSearch:O,clearSearch:F,setSearchText:N}=mX({onSearch:h}),I=b.useRef(S),{categoryNodes:P,isLoadingNodes:_,isRealTriggerMode:B,navigateToCategory:L,loadMoreNodes:H,resetNavigation:W,pagination:K,activeCategoryId:q,currentCategory:te}=pX({categories:k,initialCategory:e,nodeSelectorVisible:v,nodeAddInfo:g,onFetchNodesByCategory:m,flowId:C}),$=b.useMemo(()=>S?E:P,[S,E,P]),V=b.useMemo(()=>(g==null?void 0:g.protocol)===Ie.AI_LANGUAGE_MODEL?"选择模型":"选择动作",[g==null?void 0:g.protocol]),J=b.useMemo(()=>(g==null?void 0:g.protocol)===Ie.AI_LANGUAGE_MODEL||(g==null?void 0:g.protocol)===Ie.AI_MEMORY?"按模型名称搜索":"按节点/动作名称搜索",[g==null?void 0:g.protocol]),ne=S,ae=b.useMemo(()=>{const fe=g==null?void 0:g.protocol;if(fe){if(fe===Ie.AI_TOOL)return Ie.MCP;if(fe===Ie.AI_LANGUAGE_MODEL||fe===Ie.AI_MEMORY)return fe}},[g==null?void 0:g.protocol]),de=b.useMemo(()=>{const fe=g==null?void 0:g.protocol;if(fe===Ie.AI_TOOL)return"tool";if(fe===Ie.AI_LANGUAGE_MODEL)return"model";if(fe===Ie.AI_MEMORY)return"memory"},[g==null?void 0:g.protocol]),z=b.useCallback(()=>({app_domain_category:q&&q!=="ALL"?q:void 0,trigger:!!B,type:de,protocol:ae,flow_id:C}),[q,B,de,ae,C]),{run:U,cancel:X}=dt.useDebounceFn(fe=>{const Ne=fe.trim();if(!Ne){F(),c([]);return}O(Ne,z())},{wait:300}),Y=b.useCallback(async fe=>{d(Be=>{var tt,un;return{...Be,[fe.id]:{actions:((tt=Be[fe.id])==null?void 0:tt.actions)||[],loading:!0,source:(un=Be[fe.id])==null?void 0:un.source}}});const Ne=await D(fe,{suppressLoading:!0});d(Be=>({...Be,[fe.id]:{actions:Ne,loading:!1,source:"full"}}))},[D]),ee=async fe=>{if(l.includes(fe.id)){c(tt=>tt.filter(un=>un!==fe.id));return}c(tt=>[...tt,fe.id]);const Be=u[fe.id];(!Be||Be.actions.length===0||Be.source==="search-partial")&&await Y(fe)},re=async fe=>{await Y(fe)},ce=(fe,Ne)=>{const Be={...Ne,...g,name:fe.name,description:Ne.name||"",type:(Ne==null?void 0:Ne.action_type)??Z.ACTION,connector_name:(fe==null?void 0:fe.name)||"",category:(fe==null?void 0:fe.category)||"unknown",icon:fe.icon,isAction:!0};y(Be)},Ce=async fe=>{c([]),F(),await L(fe.id)},Oe=fe=>{N(fe),U(fe)},Pe=fe=>{if(S||!K.hasMore||_)return;const{scrollTop:Ne,scrollHeight:Be,clientHeight:tt}=fe.currentTarget;Be-Ne-tt<120&&H()};b.useEffect(()=>{if(!v){const fe=setTimeout(()=>{F(),W(),c([]),d({})},200);return()=>clearTimeout(fe)}return()=>X()},[v,F,W,X]),b.useEffect(()=>{if(I.current=S,S){const fe=E.filter(Ne=>Ne.defaultExpanded).map(Ne=>Ne.id);c(fe)}},[E,S]),b.useEffect(()=>{S||c([])},[q,S]),b.useEffect(()=>{I.current&&O(I.current,z())},[q,z,O]),b.useEffect(()=>{d(fe=>{const Ne={};return $.forEach(Be=>{Be.matchedActions&&Be.matchedActions.length>0?Ne[Be.id]={actions:Be.matchedActions,loading:!1,source:"search-partial"}:fe[Be.id]?Ne[Be.id]=fe[Be.id]:Ne[Be.id]={actions:[],loading:!1}}),Ne})},[$]),dt.useClickAway(()=>{v&&w()},s);const Ae=()=>T?f.jsxs("div",{className:"loading-state",children:[f.jsx(x.Spin,{}),f.jsx("span",{className:"loading-text",children:"搜索中..."})]}):!T&&$.length===0?f.jsx("div",{className:"empty-state",children:f.jsx("div",{className:"empty-text",children:"暂无符合条件的节点"})}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"node-card-list",children:$.map(fe=>{var Ne,Be,tt;return f.jsx(lX,{node:fe,expanded:l.includes(fe.id),actions:((Ne=u[fe.id])==null?void 0:Ne.actions)||[],loading:((Be=u[fe.id])==null?void 0:Be.loading)||!1,hasPartialActions:((tt=u[fe.id])==null?void 0:tt.source)==="search-partial",onToggle:ee,onActionSelect:ce,onLoadAllActions:re},fe.id)})}),!S&&_&&$.length>0&&f.jsxs("div",{className:"list-loading",children:[f.jsx(x.Spin,{size:"small"}),f.jsx("span",{children:"正在加载更多"})]}),!S&&!K.hasMore&&!_&&$.length>0&&f.jsx("div",{className:"list-footer",children:"已加载全部"})]});return v?f.jsxs("div",{className:Sn("modern-node-selector",{visible:v}),ref:s,children:[f.jsx(cX,{currentCategory:te,categoryPath:[],selectedNode:null,onClose:w,title:V,showBackButton:!1}),f.jsx("div",{className:"search-container",children:f.jsx(x.Input,{placeholder:J,prefix:f.jsx(Q.SearchOutlined,{style:{color:"#007aff"}}),allowClear:!0,value:ne,onChange:fe=>Oe(fe.target.value)})}),f.jsx(sX,{categories:k,activeId:q||"ALL",loading:A,onChange:Ce}),f.jsx("div",{className:"panel-content",ref:a,onClick:fe=>fe.stopPropagation(),onScroll:Pe,children:Ae()})]}):null};function CX(t){return t.map(e=>{const{node_type:n,id:r,position:o,icon:i,action_name:s,connector_name:a,description:l,action_id:c,connector_id:u,properties:d,account_schema_id:h,account_id:p,action_key:m,action_ver:v,...w}=e;let y,g;if(n===Z.STICKY)try{const D=JSON.parse(d.value);y=D.width,g=D.height}catch{}const C={type:n,id:r,position:o,data:{icon:i,label:s,action_name:s,description:l,connector_name:a,connector_id:u,account_id:p,account_schema_id:h,action_id:c,action_key:m,action_ver:v,nodeKey:m||w.nodeKey,nodeVersion:v??w.nodeVersion,params:w.params||d,config_schema:d,...w}};if(typeof y=="number"||typeof g=="number"){const D=C.style||{};C.style={...D,...typeof y=="number"?{width:y}:{},...typeof g=="number"?{height:g}:{}}}return C})}function kX(t){if(!t)return console.error("API返回数据格式错误: 缺少data字段"),{workflowId:"",workflowName:"",nodes:[],edges:[]};const e=CX(t.nodes||[]),n=e.map(o=>o.id),r=(t.connections||[]).map(o=>({...o,type:o.type||"main"})).filter(o=>n.includes(o.target)&&o.source&&o.sourceHandle&&o.targetHandle);return{workflowId:t.id||"",workflowName:t.name||"",nodes:e,edges:r}}function xX(t,e,n=""){const r=t.filter(o=>o.type!==Z.START).map(o=>{const{config_schema:i,config:s,params:a,node_schema:l,...c}=o.data;return{...c,node_type:o.type,connector_id:o.data.connector_id||"",id:o.id,action_id:o.data.action_id||o.data.id||"",account_id:o.data.account_id||null,position:o.position,properties:i||s||{},action_name:o.data.label||"",description:o.data.description||""}});return{name:n,connections:e,nodes:r}}const SX={async loadFlow(t){const e=await wf(t),{nodes:n,edges:r,workflowName:o}=kX(e);return{nodes:n,edges:r,name:o||e.name||"",opStatus:e.op_status,executionControl:e.execution_control??null}},async saveFlow({nodes:t,edges:e,workflowName:n,workflowId:r,executionControl:o}){const i=xX(t,e,n);o&&(i.execution_control=o),await Pl(r,i)},async createNode({workflowId:t,nodeType:e,actionId:n,actionKey:r,actionVer:o,configSchema:i,position:s}){const a=await ty({flow_id:t,node_type:e,action_id:n,...r?{action_key:r,action_ver:o}:{},properties:i||{},position:s});return{nodeId:a.id,nodeData:{action_name:a.action_name,connector_name:a.connector_name,status:a.status,icon:a.icon,protocol:a.protocol,...r?{action_key:r,action_ver:o,nodeKey:r,nodeVersion:o}:{}}}},stickyNodeKey:UG,nodeTypes:In.getNodeTypes(),HeaderComponent:iX,PanelComponent:bX,requiresTriggerNode:!0},EX=t=>f.jsx(P_,{strategy:SX,...t}),Dt={"configSubflow-container":"_configSubflow-container_xgeh3_1","configSubflow-selectSection":"_configSubflow-selectSection_xgeh3_4","configSubflow-selectWrapper":"_configSubflow-selectWrapper_xgeh3_19","configSubflow-select":"_configSubflow-select_xgeh3_4","configSubflow-optionContent":"_configSubflow-optionContent_xgeh3_28","configSubflow-optionName":"_configSubflow-optionName_xgeh3_34","configSubflow-optionLink":"_configSubflow-optionLink_xgeh3_41","configSubflow-paramsSection":"_configSubflow-paramsSection_xgeh3_60","configSubflow-paramsTitle":"_configSubflow-paramsTitle_xgeh3_65","configSubflow-paramsList":"_configSubflow-paramsList_xgeh3_77","configSubflow-paramItem":"_configSubflow-paramItem_xgeh3_82",hasError:"_hasError_xgeh3_95","configSubflow-paramKey":"_configSubflow-paramKey_xgeh3_99","configSubflow-paramKeyLabel":"_configSubflow-paramKeyLabel_xgeh3_104","configSubflow-paramValue":"_configSubflow-paramValue_xgeh3_124","configSubflow-hintMessage":"_configSubflow-hintMessage_xgeh3_150",warning:"_warning_xgeh3_164",info:"_info_xgeh3_169","configSubflow-errorText":"_configSubflow-errorText_xgeh3_179","configSubflow-loading":"_configSubflow-loading_xgeh3_185"},DX=(t,e={})=>!(t!=null&&t.params)||Object.keys(t.params).length===0?[]:Object.entries(t.params).map(([n,r],o)=>({id:`${n}_${o}`,key:n,value:e[n]!==void 0?e[n]:r,exampleValue:r})),AX=t=>!!(t!=null&&t.params&&Object.keys(t.params).length>0),Y_=b.forwardRef(({value:t,onChange:e,disabled:n=!1,nodeId:r=""},o)=>{const[i,s]=b.useState(t==null?void 0:t.flowId),[a,l]=b.useState([]),[c,u]=b.useState([]),d=Ct(),h=n||!d,{data:p=[],loading:m,run:v}=dt.useRequest(Fy,{debounceWait:300}),w=p||[],y=b.useMemo(()=>w.find(I=>I.id===i),[w,i]);b.useEffect(()=>{(t==null?void 0:t.flowId)!==i&&s(t==null?void 0:t.flowId)},[t==null?void 0:t.flowId]),b.useEffect(()=>{if(y){const I=DX(y,t==null?void 0:t.input);l(I)}else l([])},[y,t==null?void 0:t.input]);const g=b.useCallback((I,P)=>{if(!I){e==null||e(void 0);return}e==null||e({flowId:I,input:P})},[e]),C=b.useCallback(I=>{s(I),u([]);const P=w.find(B=>B.id===I),_={};P!=null&&P.params&&Object.entries(P.params).forEach(([B,L])=>{_[B]=L}),g(I,_)},[w,g]),D=b.useCallback((I,P)=>{const _={...(t==null?void 0:t.input)||{}};_[I]=P,g(i,_),u(B=>B.filter(L=>!(L.type==="param"&&L.paramKey===I)))},[i,t==null?void 0:t.input,g]),k=b.useCallback((I,P)=>{P.stopPropagation(),P.preventDefault(),window.open(`/uc/link/ai-flow/edit?id=${I}`,"_blank")},[]),A=b.useCallback(()=>{const I=[];return i||I.push({type:"flow",message:"请选择子流程"}),y!=null&&y.params&&Object.keys(y.params).forEach(P=>{var B;const _=(B=t==null?void 0:t.input)==null?void 0:B[P];(_==null||_==="")&&I.push({type:"param",paramKey:P,message:`参数 "${P}" 不能为空`})}),u(I),I.length===0},[i,y,t==null?void 0:t.input]),S=b.useCallback(()=>{u([])},[]);b.useImperativeHandle(o,()=>({validate:A,clearErrors:S}),[A,S]);const E=()=>{var I;return(I=c.find(P=>P.type==="flow"))==null?void 0:I.message},T=I=>{var P;return(P=c.find(_=>_.type==="param"&&_.paramKey===I))==null?void 0:P.message},O=I=>f.jsxs("div",{className:Dt["configSubflow-optionContent"],children:[f.jsx("span",{className:Dt["configSubflow-optionName"],children:I.name}),f.jsx(x.Tooltip,{title:"在新标签页中打开子流程",children:f.jsx("span",{className:Dt["configSubflow-optionLink"],onClick:P=>k(I.id,P),children:f.jsx(Q.ExportOutlined,{})})})]}),F=()=>i?m?f.jsxs("div",{className:Dt["configSubflow-loading"],children:[f.jsx(x.Spin,{size:"small"}),f.jsx("span",{style:{marginLeft:8},children:"加载中..."})]}):AX(y)?f.jsx("div",{className:Dt["configSubflow-paramsList"],children:a.map(I=>{const P=T(I.key);return f.jsxs("div",{className:`${Dt["configSubflow-paramItem"]} ${P?Dt.hasError:""}`,children:[f.jsx("div",{className:Dt["configSubflow-paramKey"],children:f.jsx(x.Tooltip,{title:`示例值: ${I.exampleValue}`,children:f.jsx("div",{className:Dt["configSubflow-paramKeyLabel"],children:I.key})})}),f.jsxs("div",{className:Dt["configSubflow-paramValue"],children:[f.jsx(ir,{value:I.value,onChange:_=>D(I.key,_),placeholder:`示例: ${I.exampleValue}`,disabled:h,borrow:!0,nodeId:r,valueType:"ADAPTOR"}),P&&f.jsx("div",{className:Dt["configSubflow-errorText"],children:P})]})]},I.id)})}):f.jsxs("div",{className:`${Dt["configSubflow-hintMessage"]} ${Dt.info}`,children:[f.jsx(Q.InfoCircleOutlined,{}),f.jsx("span",{children:"该流程无需进行参数配置"})]}):f.jsxs("div",{className:`${Dt["configSubflow-hintMessage"]} ${Dt.warning}`,children:[f.jsx(Q.InfoCircleOutlined,{}),f.jsx("span",{children:"请先选择子流程"})]}),N=E();return f.jsxs("div",{className:Dt["configSubflow-container"],children:[f.jsxs("div",{className:Dt["configSubflow-selectSection"],children:[f.jsx("div",{className:Dt["configSubflow-selectWrapper"],children:f.jsx(x.Select,{className:Dt["configSubflow-select"],value:i,onChange:C,placeholder:"请选择子流程",disabled:h,loading:m,showSearch:!0,filterOption:!1,onSearch:v,notFoundContent:m?f.jsx(x.Spin,{size:"small"}):"暂无数据",allowClear:!0,status:N?"error":void 0,options:w.map(I=>({value:I.id,label:O(I)}))})}),N&&f.jsx("div",{className:Dt["configSubflow-errorText"],children:N})]}),f.jsxs("div",{className:Dt["configSubflow-paramsSection"],children:[f.jsxs("div",{className:Dt["configSubflow-paramsTitle"],children:[f.jsx(Q.SettingOutlined,{}),f.jsx("span",{children:"参数配置"})]}),F()]})]})});Y_.displayName="ConfigSubflow";function OX(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return b.useMemo(()=>r=>{e.forEach(o=>o(r))},e)}const Vd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Bs(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function Fw(t){return"nodeType"in t}function Mn(t){var e,n;return t?Bs(t)?t:Fw(t)&&(e=(n=t.ownerDocument)==null?void 0:n.defaultView)!=null?e:window:window}function Iw(t){const{Document:e}=Mn(t);return t instanceof e}function fl(t){return Bs(t)?!1:t instanceof Mn(t).HTMLElement}function X_(t){return t instanceof Mn(t).SVGElement}function Fs(t){return t?Bs(t)?t.document:Fw(t)?Iw(t)?t:fl(t)||X_(t)?t.ownerDocument:document:document:document}const qr=Vd?b.useLayoutEffect:b.useEffect;function Mw(t){const e=b.useRef(t);return qr(()=>{e.current=t}),b.useCallback(function(){for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return e.current==null?void 0:e.current(...r)},[])}function _X(){const t=b.useRef(null),e=b.useCallback((r,o)=>{t.current=setInterval(r,o)},[]),n=b.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,n]}function hl(t,e){e===void 0&&(e=[t]);const n=b.useRef(t);return qr(()=>{n.current!==t&&(n.current=t)},e),n}function pl(t,e){const n=b.useRef();return b.useMemo(()=>{const r=t(n.current);return n.current=r,r},[...e])}function jd(t){const e=Mw(t),n=b.useRef(null),r=b.useCallback(o=>{o!==n.current&&(e==null||e(o,n.current)),n.current=o},[]);return[n,r]}function Pw(t){const e=b.useRef();return b.useEffect(()=>{e.current=t},[t]),e.current}let Lw={};function ml(t,e){return b.useMemo(()=>{if(e)return e;const n=Lw[t]==null?0:Lw[t]+1;return Lw[t]=n,t+"-"+n},[t,e])}function J_(t){return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.reduce((i,s)=>{const a=Object.entries(s);for(const[l,c]of a){const u=i[l];u!=null&&(i[l]=u+t*c)}return i},{...e})}}const Is=J_(1),gl=J_(-1);function TX(t){return"clientX"in t&&"clientY"in t}function $w(t){if(!t)return!1;const{KeyboardEvent:e}=Mn(t.target);return e&&t instanceof e}function NX(t){if(!t)return!1;const{TouchEvent:e}=Mn(t.target);return e&&t instanceof e}function zw(t){if(NX(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:n}=t.touches[0];return{x:e,y:n}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:n}=t.changedTouches[0];return{x:e,y:n}}}return TX(t)?{x:t.clientX,y:t.clientY}:null}const wl=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:n}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:n}=t;return"scaleX("+e+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[wl.Translate.toString(t),wl.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:n,easing:r}=t;return e+" "+n+"ms "+r}}}),R_="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function BX(t){return t.matches(R_)?t:t.querySelector(R_)}const FX={display:"none"};function IX(t){let{id:e,value:n}=t;return b.createElement("div",{id:e,style:FX},n)}function MX(t){let{id:e,announcement:n,ariaLiveType:r="assertive"}=t;const o={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return b.createElement("div",{id:e,style:o,role:"status","aria-live":r,"aria-atomic":!0},n)}function PX(){const[t,e]=b.useState("");return{announce:b.useCallback(r=>{r!=null&&e(r)},[]),announcement:t}}const Q_=b.createContext(null);function LX(t){const e=b.useContext(Q_);b.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of <DndContext>");return e(t)},[t,e])}function $X(){const[t]=b.useState(()=>new Set),e=b.useCallback(r=>(t.add(r),()=>t.delete(r)),[t]);return[b.useCallback(r=>{let{type:o,event:i}=r;t.forEach(s=>{var a;return(a=s[o])==null?void 0:a.call(s,i)})},[t]),e]}const zX={draggable:`
102
+ `)})]}),_.detail&&f.jsxs("div",{className:"workflow-debug-panel__log-detail-block",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"详细信息"}),f.jsx("pre",{children:JSON.stringify(_.detail,null,2)})]})]})]},_.id))]})]}),f.jsxs("div",{className:"workflow-debug-panel__section",children:[f.jsxs("div",{className:"workflow-debug-panel__summary",children:[f.jsxs("span",{children:["节点数: ",e.length]}),f.jsxs("span",{children:["连线数: ",n.length]})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"结构图预览"}),f.jsx("div",{className:"workflow-debug-panel__graph",children:f.jsxs("svg",{className:"workflow-debug-panel__graph-canvas",width:"100%",height:F,viewBox:`0 0 ${O} ${F}`,preserveAspectRatio:"xMinYMin meet",children:[f.jsxs("defs",{children:[f.jsx("marker",{id:"workflow-debug-arrow",markerWidth:"10",markerHeight:"10",refX:"8",refY:"3",orient:"auto",markerUnits:"strokeWidth",children:f.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"#8c8c8c"})}),f.jsx("marker",{id:"workflow-debug-arrow-dup",markerWidth:"10",markerHeight:"10",refX:"8",refY:"3",orient:"auto",markerUnits:"strokeWidth",children:f.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"#cf1322"})})]}),E.edges.map(_=>{const B=T.get(_.source),L=T.get(_.target);if(!B||!L)return null;const H=k.has(_.id),W=B.x+Id,K=B.y+dl/2,q=L.x,te=L.y+dl/2;return f.jsx("line",{x1:W,y1:K,x2:q,y2:te,stroke:H?"#cf1322":"#8c8c8c",strokeWidth:H?2.2:1.4,markerEnd:H?"url(#workflow-debug-arrow-dup)":"url(#workflow-debug-arrow)"},_.id)}),E.nodes.map(_=>f.jsxs("g",{transform:`translate(${_.x}, ${_.y})`,children:[f.jsx("rect",{width:Id,height:dl,rx:6,fill:"#ffffff",stroke:"#91caff",strokeWidth:1.4}),f.jsx("text",{x:Id/2,y:dl/2+4,textAnchor:"middle",fontSize:"11",fill:"#1f1f1f",children:_.label})]},_.id))]})})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"Mermaid 图"}),f.jsx("div",{className:"workflow-debug-panel__mermaid-actions",children:f.jsx(x.Button,{size:"small",onClick:async()=>{await Md(S)?x.message.success("Mermaid 已复制"):x.message.error("复制失败")},children:"复制 Mermaid"})}),f.jsx("pre",{children:S})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"结构布局"}),f.jsx("pre",{children:N})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"连线关系"}),f.jsxs("div",{className:"workflow-debug-panel__edge-list",children:[A.length===0&&f.jsx("div",{className:"workflow-debug-panel__log-empty",children:"暂无连线"}),A.map(_=>f.jsxs("div",{className:`workflow-debug-panel__edge-line${_.isDuplicate?" workflow-debug-panel__edge-line--duplicate":""}`,children:[f.jsx("span",{children:_.text}),_.isDuplicate&&f.jsx("span",{className:"workflow-debug-panel__edge-flag",children:"重复"})]},_.id))]})]}),D&&D.length>0&&f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"重复连线"}),f.jsx("div",{className:"workflow-debug-panel__edge-list",children:D.map(_=>f.jsxs("div",{className:"workflow-debug-panel__edge-line--duplicate",children:[f.jsx("span",{children:_.relation}),f.jsx("span",{className:"workflow-debug-panel__edge-flag",children:_.edgeIds.join(", ")})]},_.key))})]}),f.jsxs(x.Space,{direction:"vertical",size:8,style:{width:"100%"},children:[f.jsx(x.Select,{value:u,placeholder:"选择节点查看详情",options:v,onChange:_=>d(_),allowClear:!0,size:"small"}),f.jsx(x.Select,{value:h,placeholder:"选择连线查看详情",options:w,onChange:_=>p(_),allowClear:!0,size:"small"})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"节点详情"}),f.jsx("pre",{children:y?JSON.stringify(Ew(y),null,2):"未选择节点"})]}),f.jsxs("div",{className:"workflow-debug-panel__detail",children:[f.jsx("div",{className:"workflow-debug-panel__detail-title",children:"连线详情"}),f.jsx("pre",{children:g?JSON.stringify({...Dw(g),sourceName:C.get(g.source),targetName:C.get(g.target),isDuplicate:k.has(g.id)},null,2):"未选择连线"})]})]})]}):null},I_=b.createContext(null),cY=({api:t,children:e})=>f.jsx(I_.Provider,{value:t,children:e}),M_=()=>{const t=b.useContext(I_);if(!t)throw new Error("useCanvasApi must be used within a CanvasApiProvider");return t},P_=t=>{var w;const{workflowId:e,strategy:n,readOnly:r=!1,appFlowMode:o=!1,linkMode:i=!1}=t,s=Wt(),a=eY(t,n.stickyNodeKey),{setUnSave:l,store:c,updateSaveStatus:u}=a,d=b.useMemo(()=>n.nodeTypes??In.getNodeTypes(),[n.nodeTypes]),h=b.useCallback(async()=>{if(e)try{u(pn.SAVING);const{nodes:y,edges:g}=c.getState(),C=y.map(S=>S.id),D=g.filter(S=>C.includes(S.target)&&S.source&&S.sourceHandle&&S.targetHandle),k=Sg.getState().workflow.workflowName,A=Sg.getState().workflow.executionControl;await n.saveFlow({nodes:y,edges:D,workflowName:k,workflowId:e,executionControl:A}),l(!1),u(pn.SAVED)}catch(y){u(pn.ERROR,y)}},[l,c,n,u,e]);a.saveFlowRef.current=h,nK({workflowId:e,strategy:n,setNodes:a.setNodes,setEdges:a.setEdges,fitView:a.reactFlow.fitView,setLoading:a.setLoading,setUnSave:a.setUnSave,dispatch:a.dispatch,setFlowOpStatusAction:a.setFlowOpStatusAction,refreshWorkFlowNum:a.refreshWorkFlowNum}),sK({workflowId:e,strategy:n,store:a.store,addNodes:a.addNodes,addEdges:a.addEdges,removeEdges:a.removeEdges,setNodeAddCallback:a.setNodeAddCallback,handleEdgeAddNode:a.handleEdgeAddNode,setNodeConfigVisible:a.setNodeConfigVisible,setNodeFitHumanView:a.setNodeFitHumanView,saveFlow:h,engineMode:s.engineMode});const p=n.HeaderComponent,m=n.PanelComponent,v=n.ConfigModalComponent;return f.jsxs(cY,{api:a.canvasApi,children:[f.jsxs("div",{className:a.isPreviewMode?"workflow-canvas-container workflow-canvas-container-preview":"workflow-canvas-container",style:{height:s.canvas.height?`${s.canvas.height}`:i?"calc(100vh - 320px)":void 0},children:[a.showCanvasHeader&&f.jsx(p,{onSave:h,readOnly:r,autoSaveStatus:a.autoSaveStatus,unSave:a.unSave,lastSavedTime:a.lastSavedTime,appFlowMode:o,canvasApi:a.canvasApi}),f.jsxs("div",{className:"workflow-canvas",children:[f.jsx(JG,{loading:a.loading}),f.jsx(RG,{}),f.jsxs(se.ReactFlow,{nodes:a.nodes,edges:a.edges,onNodesChange:a.onNodesChange,onEdgesChange:a.handleEdgesChange,onConnect:a.handleConnect,multiSelectionKeyCode:null,nodeTypes:d,edgeTypes:zG,connectionLineType:se.ConnectionLineType.Bezier,connectionMode:se.ConnectionMode.Loose,onNodeMouseEnter:a.onNodeMouseEnter,onNodeMouseLeave:a.onNodeMouseLeave,onEdgeMouseEnter:a.onEdgeMouseEnter,onEdgeMouseLeave:a.onEdgeMouseLeave,onNodeContextMenu:a.onNodeContextMenu,onPaneContextMenu:a.onPaneContextMenu,defaultEdgeOptions:WG,style:HG,defaultViewport:a.isPreviewMode?jG:VG,minZoom:.1,maxZoom:2,fitView:!1,snapToGrid:!0,snapGrid:[20,20],deleteKeyCode:null,nodesDraggable:!a.isInteractionDisabled,nodesConnectable:!a.isInteractionDisabled,elementsSelectable:!a.isInteractionDisabled,className:"react-flow-canvas-container",...a.restNativeProps,children:[a.showBackground&&f.jsx(se.Background,{gap:(w=s.canvas.grid)==null?void 0:w.size,color:"#eee",variant:se.BackgroundVariant.Lines}),a.showFastOperationButtons&&f.jsx(XG,{onOpenNodeSelector:a.handleOpenNodeSelector,onAddNoteNode:a.handleAddNoteNode,onTidyCanvas:a.handleTidy}),a.showControls&&f.jsx(se.Controls,{onInteractiveChange:y=>{a.setLocked(y)}}),a.showMiniMap&&f.jsx(nY,{}),f.jsx(m,{}),f.jsx(tK,{horizontal:a.helperLineHorizontal,vertical:a.helperLineVertical}),f.jsx(lY,{visible:a.debugVisible,nodes:a.nodes,edges:a.storeEdges,onClose:()=>a.setDebugVisible(!1)})]})]})]}),v&&f.jsx(v,{})]})};var Pd=(t=>(t.ONCE="ONCE",t.EACH="EACH",t))(Pd||{}),Si=(t=>(t.STOP_WORKFLOW="STOP_WORKFLOW",t.CONTINUE_ERROR_OUTPUT="CONTINUE_ERROR_OUTPUT",t))(Si||{});const Ld="error",uY=[{label:"合并执行(ONCE)",value:Pd.ONCE},{label:"逐条执行(EACH)",value:Pd.EACH}],dY=[{label:"停止工作流(STOP_WORKFLOW)",value:Si.STOP_WORKFLOW},{label:"输出错误并继续(CONTINUE_ERROR_OUTPUT)",value:Si.CONTINUE_ERROR_OUTPUT}],Aw=({unit:t,style:e,...n})=>f.jsxs(x.Space.Compact,{style:{width:"100%"},children:[f.jsx(x.InputNumber,{...n,style:{flex:1,...e}}),f.jsx(x.Button,{disabled:!0,style:{pointerEvents:"none"},children:t})]}),fY=({nodeId:t})=>{const[e]=x.Form.useForm(),{getEdges:n,getNode:r,setEdges:o}=se.useReactFlow(),{handleNodeDataUpdate:i}=jr();b.useEffect(()=>{var c;const a=r(t),l=((c=a==null?void 0:a.data)==null?void 0:c.settings)??{};e.setFieldsValue({retryCount:l.retryCount??0,retryInterval:l.retryInterval??1e3,timeout:l.timeout??0,onError:l.onError??Si.STOP_WORKFLOW,executeMode:l.executeMode??Pd.ONCE})},[t,e,r]);const s=b.useCallback(a=>{const l={retryCount:a.retryCount,retryInterval:a.retryInterval,timeout:a.timeout,onError:a.onError??Si.STOP_WORKFLOW,executeMode:a.executeMode};i({id:t,data:{settings:l}}),l.onError!==Si.CONTINUE_ERROR_OUTPUT&&o(n().filter(c=>!(c.source===t&&(c.sourceHandle||"main")===Ld))),x.message.success("节点设置已保存")},[t,i,n,o]);return f.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[f.jsx("div",{style:{flex:1,overflowY:"auto",padding:"16px 16px 0"},children:f.jsxs(x.Form,{form:e,layout:"vertical",onFinish:s,children:[f.jsx(x.Form.Item,{label:"执行模式",name:"executeMode",children:f.jsx(x.Select,{options:uY,style:{width:"100%"}})}),f.jsx(x.Form.Item,{label:"错误处理策略",name:"onError",tooltip:"选择节点执行失败后的处理方式。CONTINUE_ERROR_OUTPUT 会显示 error 输出锚点",children:f.jsx(x.Select,{options:dY,style:{width:"100%"}})}),f.jsx(x.Form.Item,{label:"重试次数",name:"retryCount",tooltip:"失败后自动重试的次数,0 表示不重试",rules:[{type:"number",min:0,max:10,message:"重试次数范围 0–10"}],children:f.jsx(Aw,{min:0,max:10,precision:0,unit:"次"})}),f.jsx(x.Form.Item,{noStyle:!0,shouldUpdate:(a,l)=>a.retryCount!==l.retryCount,children:({getFieldValue:a})=>a("retryCount")>0?f.jsx(x.Form.Item,{label:"重试间隔",name:"retryInterval",tooltip:"两次重试之间的等待时间(毫秒)",rules:[{type:"number",min:100,message:"重试间隔至少 100ms"}],children:f.jsx(Aw,{min:100,step:500,unit:"ms"})}):null}),f.jsx(x.Form.Item,{label:"执行超时",name:"timeout",tooltip:"节点执行的最大时间(秒),0 表示无限制",rules:[{type:"number",min:0,message:"超时时间不能为负数"}],children:f.jsx(Aw,{min:0,step:10,unit:"秒"})})]})}),f.jsx("div",{style:{padding:"12px 16px",borderTop:"1px solid #eaeaea",backgroundColor:"#fff",textAlign:"center"},children:f.jsx(x.Button,{type:"primary",style:{width:180},onClick:()=>e.submit(),children:"保存"})})]})},{TextArea:hY}=x.Input,{Title:pY,Paragraph:mY}=x.Typography;function gY(t,e){var r,o;const n={};for(const i of t){if(i.id===e)continue;const s=(r=i.data)==null?void 0:r.name,a=(o=i.data)==null?void 0:o.output;if(!s||a===void 0||a===null||a==="")continue;let l=a;if(typeof l=="string")try{l=JSON.parse(l)}catch{continue}Array.isArray(l)?n[s]=l:l&&typeof l=="object"&&(Array.isArray(l.default)?n[s]=l.default:n[s]=[l])}return n}const wY=b.forwardRef((t,e)=>{const{nodeId:n,beforeHook:r}=t,{handleNodeDataUpdate:o}=jr(),i=se.useInternalNode(n),s=se.useReactFlow(),a=Ct(),[l,c]=b.useState(""),u=dt.useReactive({testProgress:0,sampleText:"",isError:!1,editable:!1,showErrorAlert:!1,testing:!1,ignoring:!1,successShown:!1,isIgnoreSuccess:!1});b.useEffect(()=>{var g,C;const w=(g=i==null?void 0:i.data)==null?void 0:g.output,y=(C=i==null?void 0:i.data)==null?void 0:C.status;if(u.testProgress=0,u.sampleText="",u.editable=!1,u.testing=!1,u.ignoring=!1,u.showErrorAlert=!1,w!=null&&w!==""){const D=typeof w=="string"?w:JSON.stringify(w,null,2);c(D),y===pe.FAILED?(u.isError=!0,u.successShown=!1,u.isIgnoreSuccess=!1):(u.isError=!1,u.successShown=!0,u.isIgnoreSuccess=!1)}else c(""),u.isError=!1,u.successShown=!1,u.isIgnoreSuccess=!1},[n]);const d=b.useCallback(()=>{if(!n)return;u.testing=!0,u.testProgress=60,u.successShown=!1;const w=i==null?void 0:i.data,y=gY(s.getNodes(),n),g={nodeKey:(w==null?void 0:w.nodeKey)??"",nodeVersion:(w==null?void 0:w.nodeVersion)??0,nodeName:(w==null?void 0:w.name)??n,params:(w==null?void 0:w.params)??{},inputData:[],credentialInstanceId:w==null?void 0:w.credentialInstanceId,contextNodes:y,timeoutSeconds:30};MB(g).then(C=>{if(C.success){const D=C.outputData??C.resolvedParams;o({id:n,data:{status:pe.SUCCESS,output:D}}),u.isError=!1,u.successShown=!0,u.isIgnoreSuccess=!1,u.showErrorAlert=!1,u.testProgress=100,c(typeof D=="string"?D:JSON.stringify(D,null,2))}else{const D=C.error??"节点执行失败";console.warn("[NextNodeTest] 测试失败:",D),o({id:n,data:{status:pe.FAILED}}),u.testProgress=0,u.isError=!0,u.showErrorAlert=!0,c(JSON.stringify({error:D},null,2))}}).catch(C=>{console.error("[NextNodeTest] 请求异常:",C);const D=(C==null?void 0:C.message)??"测试执行失败";o({id:n,data:{status:pe.FAILED}}),u.testProgress=0,u.isError=!0,u.showErrorAlert=!0,c(JSON.stringify({error:D},null,2))}).finally(()=>{setTimeout(()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!1},500)})},[n,i,s,o]),h=()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!0};b.useImperativeHandle(e,()=>({onTestNode:d,finishNodeTest:h}));const p=()=>{r?r(!0):d()},m=()=>{const w=u.sampleText||l;if(!w)return;u.testing=!0,u.ignoring=!0,u.testProgress=60;let y;try{y=JSON.parse(w)}catch{y=w}console.log("[NextNodeTest] 忽略调试, 写入样本数据:",y),o({id:n,data:{status:pe.SUCCESS,output:y}});const g=typeof y=="string"?y:JSON.stringify(y,null,2);c(g),u.testProgress=100,setTimeout(()=>{u.testProgress=0,u.testing=!1,u.ignoring=!1,u.isIgnoreSuccess=!0,u.isError=!1,u.showErrorAlert=!1,u.successShown=!0},500)},v=()=>{c(""),u.sampleText="",u.editable=!1,u.successShown=!1};return f.jsxs("div",{className:"node-test-container",children:[f.jsxs("div",{className:"node-test-header",children:[f.jsxs("div",{className:"header-title",children:[f.jsx(Q.RocketOutlined,{className:"title-icon"}),f.jsx(pY,{level:4,children:"节点测试"})]}),f.jsx(mY,{type:"secondary",className:"header-description",children:"点击测试按钮,实时检查节点执行效果和结果数据"})]}),f.jsxs("div",{className:"test-content",children:[a&&f.jsxs("div",{className:"action-buttons",children:[f.jsx(x.Button,{type:"primary",disabled:u.ignoring,icon:f.jsx(Q.RocketOutlined,{}),onClick:p,loading:u.testing&&!u.ignoring,className:"test-button",children:u.testing&&!u.ignoring?"测试中...":"开始测试"}),f.jsx(x.Button,{type:"primary",disabled:u.testing&&!u.ignoring||!(u.sampleText||l),ghost:!0,onClick:m,loading:u.testing&&u.ignoring,className:"ignore-button",title:u.sampleText||l?void 0:"请先编辑样本数据",children:"忽略调试"}),l&&f.jsx(x.Button,{icon:f.jsx(Q.ReloadOutlined,{}),onClick:v,className:"reset-button",children:"重置"})]}),u.testProgress>0&&f.jsx(x.Progress,{percent:u.testProgress,status:u.isError?"exception":"active",className:"test-progress"}),u.isError&&u.showErrorAlert&&f.jsx(x.Alert,{className:"error-alert",showIcon:!0,message:"测试未通过",description:"请检查节点配置是否正确",type:"error",onClose:()=>{setTimeout(()=>{u.showErrorAlert=!1},500)},closable:!0}),!u.isError&&u.successShown&&l&&!u.testing&&f.jsx(x.Alert,{className:"success-alert",showIcon:!0,message:u.isIgnoreSuccess?"忽略调试成功":"测试成功",description:u.isIgnoreSuccess?"已将样本数据预设为当前节点输出":"节点运行正常,可以查看下方返回结果",type:"success",closable:a}),u.testing?f.jsx(x.Skeleton,{active:!0,className:"result-skeleton"}):f.jsx(f.Fragment,{children:l?f.jsx(x.Card,{styles:{body:{padding:0}},title:f.jsxs("div",{className:"result-header",children:[f.jsx("div",{className:"result-title",children:u.isError?f.jsxs(f.Fragment,{children:[f.jsx(Q.CloseCircleFilled,{className:"error-icon"})," 错误数据"]}):f.jsxs(f.Fragment,{children:[u.isIgnoreSuccess?f.jsx(Q.ExperimentFilled,{className:"success-icon"}):f.jsx(Q.CheckCircleFilled,{className:"success-icon"}),u.isIgnoreSuccess?"样本数据":"测试结果"]})}),a&&f.jsx(x.Button,{size:"small",type:"link",icon:f.jsx(Q.EditOutlined,{}),onClick:()=>{if(u.editable){u.editable=!1;try{const w=JSON.parse(u.sampleText),y=JSON.stringify(w,null,2);c(y),o({id:n,data:{output:y}})}catch{c(u.sampleText)}}else u.sampleText=l,u.editable=!0},className:"edit-button",children:u.editable?"完成":"编辑"})]}),variant:"borderless",className:`result-card ${u.isError?"error-result":"success-result"}`,children:u.editable?f.jsx(hY,{rows:10,value:u.sampleText,onChange:w=>u.sampleText=w.target.value,className:"result-editor"}):f.jsx(bA,{data:l,height:300,enableCopy:!0,theme:"light"})}):f.jsx(x.Card,{variant:"borderless",className:"empty-result",children:f.jsx(x.Result,{icon:f.jsx(Q.RocketOutlined,{}),title:"等待测试",subTitle:'点击"开始测试"按钮开始节点测试'})})})]})]})}),vY=t=>t.sourceHandle||"main",L_=t=>`${t.node.id}:${t.outputMode}`,yY=t=>{if(t.length===0)return[];if(t.length===1)return t[0];const e=t.slice(1).map(n=>new Set(n.map(L_)));return t[0].filter(n=>e.every(r=>r.has(L_(n))))},bY=(t,e,n)=>{const r=t.filter(o=>o.node.id!==e.id);return r.push({node:e,outputMode:n}),r};function $_(t,e,n,r=new Set){if(r.has(t))return[];const o=n.get(t)??[];if(o.length===0)return[];const i=new Set(r);i.add(t);const s=o.map(a=>{const l=e.get(a.source);if(!l)return[];const c=$_(a.source,e,n,i);return bY(c,l,vY(a)===Ld?"error":"normal")});return yY(s)}function CY(t,e,n){const r=new Map(e.map(i=>[i.id,i])),o=new Map;for(const i of n){const s=o.get(i.target)??[];s.push(i),o.set(i.target,s)}return $_(t,r,o)}function $d(t,e){const n=t.trim(),r=n.startsWith("N")?n:`N${n}`,o=e.trim();return o?`{{${r}.${o}}}`:`{{${r}}}`}function kY(t,e){return e.map(n=>({key:`${t}.${n.key}`,title:n.label||n.key,type:n.type,isLeaf:!0,expression:$d(t,n.key)}))}function xY(t){return[{key:`${t}.__error__.errorType`,title:"错误类型",type:"STRING",isLeaf:!0,expression:$d(t,"errorType")},{key:`${t}.__error__.errorDetail`,title:"错误详情",type:"STRING",isLeaf:!0,expression:$d(t,"errorDetail")}]}async function SY(t,e,n){var s,a,l;const r=CY(t,e,n);if(r.length===0)return[];const o=await Promise.all(r.map(async({node:c,outputMode:u})=>{var p,m;const d=(p=c.data)==null?void 0:p.nodeKey;if(!d||u==="error")return{node:c,outputMode:u,schema:null};const h=await wd(d,(m=c.data)==null?void 0:m.nodeVersion);return{node:c,outputMode:u,schema:h}})),i=[];for(const{node:c,outputMode:u,schema:d}of o){const h=((s=c.data)==null?void 0:s.label)||((a=c.data)==null?void 0:a.action_name)||((l=c.data)==null?void 0:l.nodeKey)||c.id,p=u==="error"?[]:(d==null?void 0:d.output_fields)??[],m=u==="error"?xY(c.id):p.length>0?kY(c.id,p):[{key:`${c.id}.__output__`,title:"output",type:"OBJECT",isLeaf:!0,expression:$d(c.id,"output")}];i.push({key:c.id,title:h,isLeaf:!1,children:m})}return i}const EY={STRING:"orange",NUMBER:"blue",BOOLEAN:"green",OBJECT:"cyan",ARRAY:"purple",EMPTY:"default"},DY={STRING:"Str",NUMBER:"Num",BOOLEAN:"Bool",OBJECT:"Obj",ARRAY:"Arr"},AY=t=>{const e=t.nodes.map(r=>{const o=r.data??{};return[r.id,o.nodeKey??"",o.nodeVersion??"",o.label??"",o.action_name??"",o.name??""].join(":")}).sort().join("|"),n=t.edges.map(r=>[r.id,r.source,r.sourceHandle??"",r.target,r.targetHandle??""].join(":")).sort().join("|");return`${e}||${n}`},OY=b.forwardRef(({nodeId:t,open:e},n)=>{const r=se.useStoreApi(),o=se.useStore(AY),{event$:i}=b.useContext(Vr),s=b.useRef(0),[a,l]=b.useState([]),[c,u]=b.useState(!1),d=b.useCallback(async m=>{if(!t)return;const v=s.current+1;s.current=v,u(!0);try{const{nodes:w,edges:y}=r.getState(),g=await SY(t,w,y);s.current===v&&l(g)}catch(w){console.error("[DIP] 构建变量树失败:",w)}finally{s.current===v&&u(!1)}},[t,r]);b.useImperativeHandle(n,()=>({loadVariables:d})),b.useEffect(()=>{e&&d(o)},[e,o,d]),i.useSubscription(m=>{m.type==="visible"&&m.visible&&d()});const h=b.useCallback((m,v)=>{const w=v.node;!w.isLeaf||!w.expression||i.emit({type:"insert",expression:w.expression})},[i]),p=a.map(m=>{var v;return{key:m.key,title:f.jsxs("span",{style:{fontSize:14,fontWeight:"bold",color:"#777"},children:[f.jsx(Q.UsbOutlined,{style:{color:"#108ee9",marginRight:4,fontSize:16}}),m.title]}),selectable:!1,children:(v=m.children)==null?void 0:v.map(w=>({key:w.key,selectable:w.type!=="EMPTY",isLeaf:w.isLeaf,title:f.jsxs("div",{style:{display:"flex",flexWrap:"nowrap",alignItems:"center"},children:[w.type&&w.type!=="EMPTY"&&f.jsx(x.Tag,{color:EY[w.type]||"gray",style:{textWrap:"nowrap",padding:"0 3px"},children:DY[w.type]||w.type}),f.jsx("span",{style:{fontSize:14,fontWeight:"bold"},children:w.title})]}),...w}))}});return f.jsxs("div",{className:Ze.container,children:[f.jsx("div",{className:Ze.header,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",color:"#999"},children:[f.jsx(Q.RocketOutlined,{style:{fontSize:20,marginRight:10}}),f.jsx("h3",{style:{margin:0,color:"#999"},children:f.jsx(Se.FormattedMessage,{id:"app.common.word.select-variable"})})]})}),f.jsx("div",{style:{flex:1,overflowY:"auto"},className:"grayBeautifyScrollbar",children:c?f.jsx("div",{style:{textAlign:"center",padding:20},children:f.jsx(x.Spin,{size:"small"})}):p.length>0?f.jsx(x.Tree,{showLine:!0,defaultExpandAll:!0,treeData:p,onSelect:h}):f.jsx(x.Empty,{image:x.Empty.PRESENTED_IMAGE_SIMPLE,description:f.jsx(Se.FormattedMessage,{id:"common.no-process-variables-yet"})})})]})}),_Y=({credentialKey:t,open:e,onCancel:n,onCreated:r})=>{const[o,i]=b.useState(null),[s,a]=b.useState(null),[l,c]=b.useState(!1),[u,d]=b.useState(!1),[h,p]=b.useState(!1),[m]=x.Form.useForm(),[v]=x.Form.useForm();b.useEffect(()=>{!e||!t||(c(!0),Py(t).then(C=>{var D;i(C),(D=C.fields)!=null&&D.length?a(il(C.fields)):a(null)}).catch(C=>{console.error("获取凭据 Schema 失败:",C),x.message.error("获取凭据配置失败")}).finally(()=>c(!1)))},[e,t]);const w=b.useCallback(()=>{m.resetFields(),v.resetFields(),n()},[m,v,n]),y=b.useCallback(async()=>{try{const C=await v.validateFields(),D=await m.validateFields();d(!0);const k=await Ly({name:C.credentialName,credentialKey:t,credentialVersion:(o==null?void 0:o.version)??1,data:D});x.message.success("凭据创建成功"),m.resetFields(),v.resetFields(),r(k.id)}catch(C){if(C!=null&&C.errorFields)return;console.error("创建凭据失败:",C),x.message.error("创建凭据失败")}finally{d(!1)}},[t,o,m,v,r]),g=b.useCallback(async()=>{try{const C=await v.validateFields(),D=await m.validateFields();p(!0);const k=await Ly({name:C.credentialName,credentialKey:t,credentialVersion:(o==null?void 0:o.version)??1,data:D}),A=await $y(k.id);A.success?(x.message.success(A.message||"测试连接成功"),m.resetFields(),v.resetFields(),r(k.id)):x.message.error(A.message||"测试连接失败")}catch(C){if(C!=null&&C.errorFields)return;console.error("测试连接失败:",C),x.message.error("测试连接失败")}finally{p(!1)}},[t,o,m,v,r]);return f.jsx(x.Modal,{title:`新建凭据${o!=null&&o.name?` - ${o.name}`:""}`,open:e,onCancel:w,width:560,footer:f.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[f.jsx(x.Button,{onClick:w,children:"取消"}),f.jsx(x.Button,{icon:f.jsx(Q.ApiOutlined,{}),onClick:g,loading:h,children:"测试连接"}),f.jsx(x.Button,{type:"primary",onClick:y,loading:u,children:"确认创建"})]}),destroyOnClose:!0,children:l?f.jsx("div",{style:{textAlign:"center",padding:40},children:f.jsx(x.Spin,{})}):f.jsxs("div",{children:[f.jsx(x.Form,{form:v,layout:"vertical",style:{marginBottom:16},children:f.jsx(x.Form.Item,{label:"凭据名称",name:"credentialName",rules:[{required:!0,message:"请输入凭据名称"}],children:f.jsx(x.Input,{placeholder:"为此凭据起一个名称"})})}),s?f.jsx(Ri,{schema:s,form:m,showSubmit:!1,showReset:!1}):f.jsx("div",{style:{padding:16,color:"#999",textAlign:"center"},children:"该凭据类型暂无配置项"})]})})},TY=({instanceId:t,credentialKey:e,open:n,onCancel:r,onUpdated:o,onDeleted:i})=>{const[s,a]=b.useState(null),[l,c]=b.useState(null),[u,d]=b.useState(!1),[h,p]=b.useState(!1),[m,v]=b.useState(!1),[w,y]=b.useState(!1),[g]=x.Form.useForm(),[C]=x.Form.useForm();b.useEffect(()=>{!n||!t||(d(!0),Promise.all([Py(e),LB(t)]).then(([E,T])=>{var O;if(a(E),C.setFieldsValue({credentialName:T.name}),(O=E.fields)!=null&&O.length){if(c(il(E.fields)),T.data)try{const F=JSON.parse(T.data);g.setFieldsValue(F)}catch{}}else c(null)}).catch(E=>{console.error("获取凭据信息失败:",E),x.message.error("获取凭据信息失败")}).finally(()=>d(!1)))},[n,t,e,g,C]);const D=b.useCallback(()=>{g.resetFields(),C.resetFields(),r()},[g,C,r]),k=b.useCallback(async()=>{try{const E=await C.validateFields(),T=await g.validateFields();p(!0),await Sf(t,{name:E.credentialName,data:T}),x.message.success("凭据更新成功"),D(),o()}catch(E){if(E!=null&&E.errorFields)return;console.error("更新凭据失败:",E),x.message.error("更新凭据失败")}finally{p(!1)}},[t,g,C,D,o]),A=b.useCallback(async()=>{try{const E=await C.validateFields(),T=await g.validateFields();v(!0),await Sf(t,{name:E.credentialName,data:T});const O=await $y(t);O.success?x.message.success(O.message||"测试连接成功"):x.message.error(O.message||"测试连接失败")}catch(E){if(E!=null&&E.errorFields)return;console.error("测试连接失败:",E),x.message.error("测试连接失败")}finally{v(!1)}},[t,g,C]),S=b.useCallback(async()=>{y(!0);try{await zy(t),x.message.success("凭据删除成功"),D(),i==null||i()}catch(E){console.error("删除凭据失败:",E),x.message.error("删除凭据失败")}finally{y(!1)}},[t,D,i]);return f.jsx(x.Modal,{title:`编辑凭据${s!=null&&s.name?` - ${s.name}`:""}`,open:n,onCancel:D,width:560,footer:f.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[f.jsx(x.Popconfirm,{title:"确认删除",description:"删除后无法恢复,确定要删除此凭据吗?",onConfirm:S,okText:"删除",cancelText:"取消",okButtonProps:{danger:!0,loading:w},children:f.jsx(x.Button,{danger:!0,icon:f.jsx(Q.DeleteOutlined,{}),loading:w,children:"删除凭据"})}),f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsx(x.Button,{onClick:D,children:"取消"}),f.jsx(x.Button,{icon:f.jsx(Q.ApiOutlined,{}),onClick:A,loading:m,children:"测试连接"}),f.jsx(x.Button,{type:"primary",onClick:k,loading:h,children:"保存修改"})]})]}),destroyOnClose:!0,children:u?f.jsx("div",{style:{textAlign:"center",padding:40},children:f.jsx(x.Spin,{})}):f.jsxs("div",{children:[f.jsx(x.Form,{form:C,layout:"vertical",style:{marginBottom:16},children:f.jsx(x.Form.Item,{label:"凭据名称",name:"credentialName",rules:[{required:!0,message:"请输入凭据名称"}],children:f.jsx(x.Input,{placeholder:"为此凭据起一个名称"})})}),l?f.jsx(Ri,{schema:l,form:g,showSubmit:!1,showReset:!1}):f.jsx("div",{style:{padding:16,color:"#999",textAlign:"center"},children:"该凭据类型暂无配置项"})]})})},{Text:z_}=x.Typography,NY=({credentialKey:t,label:e="授权配置",required:n=!1,value:r,onChange:o,disabled:i=!1})=>{const[s,a]=b.useState([]),[l,c]=b.useState(!1),[u,d]=b.useState(!1),[h,p]=b.useState(!1),[m,v]=b.useState(null),[w,y]=b.useState(null),[g,C]=b.useState(""),D=b.useRef(null),k=b.useCallback(()=>{t&&(c(!0),PB(t).then(_=>{a(Array.isArray(_)?_:[])}).catch(()=>{a([])}).finally(()=>c(!1)))},[t]);b.useEffect(()=>{k()},[k]),b.useEffect(()=>{w&&D.current&&setTimeout(()=>{var _;(_=D.current)==null||_.focus()},100)},[w]);const A=b.useCallback(_=>{d(!1),k(),o==null||o(_)},[k,o]),S=b.useCallback(_=>{v(_),p(!0)},[]),E=b.useCallback(()=>{p(!1),v(null),k()},[k]),T=b.useCallback(_=>{zy(_).then(()=>{x.message.success("凭据删除成功"),k(),r===_&&(o==null||o(void 0))}).catch(()=>{x.message.error("删除凭据失败")})},[k,r,o]),O=b.useCallback((_,B,L)=>{_.stopPropagation(),_.preventDefault(),y(B),C(L)},[]),F=b.useCallback(()=>{y(null),C("")},[]),N=b.useCallback(()=>{if(!w||!g.trim()){F();return}const _=g.trim(),B=s.find(L=>L.id===w);if((B==null?void 0:B.name)===_){F();return}Sf(w,{name:_}).then(()=>{x.message.success("凭据重命名成功"),k(),F()}).catch(()=>{x.message.error("重命名失败")})},[w,g,s,k,F]),I=b.useCallback(_=>{w&&(_.stopPropagation(),_.preventDefault())},[w]),P=b.useCallback(_=>f.jsxs("div",{children:[_,f.jsx(x.Divider,{style:{margin:"4px 0"}}),f.jsx("div",{style:{padding:"8px",textAlign:"center"},children:f.jsx(x.Button,{icon:f.jsx(Q.PlusOutlined,{}),onClick:()=>d(!0),type:"link",block:!0,disabled:i,children:"新建凭据"})})]}),[i]);return t?f.jsxs("div",{style:{padding:"16px 0"},children:[f.jsxs(z_,{strong:!0,style:{display:"block",marginBottom:8,fontSize:14},children:[e,n?f.jsx("span",{style:{color:"#ff4d4f",marginLeft:4},children:"*"}):null]}),f.jsx(x.Select,{style:{width:"100%"},placeholder:"选择凭据实例",value:r,onChange:_=>o==null?void 0:o(_),loading:l,disabled:i,allowClear:!0,onClear:()=>o==null?void 0:o(void 0),dropdownRender:P,onClick:I,children:s.map(_=>f.jsx(x.Select.Option,{value:_.id,children:f.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",width:"100%",padding:"4px 0"},onClick:I,children:[f.jsx("div",{style:{display:"flex",alignItems:"center",maxWidth:"40%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w!==_.id?f.jsxs(b.Fragment,{children:[f.jsx("span",{children:_.name}),f.jsx(Q.EditOutlined,{style:{fontSize:12,color:"#1890ff",marginLeft:6,cursor:"pointer",opacity:.5},onClick:B=>{i||O(B,_.id,_.name)}})]}):f.jsx(x.Input,{ref:D,size:"small",value:g,onChange:B=>C(B.target.value),onPressEnter:N,onBlur:N,onClick:B=>B.stopPropagation(),onMouseDown:B=>B.stopPropagation(),style:{width:120}})}),f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[f.jsx(z_,{type:"secondary",style:{fontSize:12},children:_.updatedAt?Tt(_.updatedAt).format("YYYY-MM-DD HH:mm"):_.createdAt?Tt(_.createdAt).format("YYYY-MM-DD HH:mm"):""}),f.jsx(x.Button,{type:"link",icon:f.jsx(Q.EditOutlined,{}),size:"small",onClick:B=>{B.stopPropagation(),S(_.id)},disabled:i,children:"编辑"}),f.jsx(x.Popconfirm,{title:"确认删除",description:"删除后无法恢复,确定要删除此凭据吗?",onConfirm:B=>{B==null||B.stopPropagation(),T(_.id)},onCancel:B=>B==null?void 0:B.stopPropagation(),okText:"删除",cancelText:"取消",okButtonProps:{danger:!0},disabled:i,children:f.jsx(x.Button,{type:"link",danger:!0,icon:f.jsx(Q.DeleteOutlined,{}),size:"small",onClick:B=>B.stopPropagation(),disabled:i,children:"删除"})})]})]})},_.id))}),t&&f.jsx(_Y,{credentialKey:t,open:u,onCancel:()=>d(!1),onCreated:A}),t&&m&&f.jsx(TY,{instanceId:m,credentialKey:t,open:h,onCancel:()=>{p(!1),v(null)},onUpdated:E,onDeleted:()=>{p(!1),v(null),k(),r===m&&(o==null||o(void 0))}})]}):null},Ur="[workflow:schema-render]",BY=/^\{\{([^.{}]+)\.(.+)\}\}$/,FY=b.forwardRef((t,e)=>{const{nodeId:n,data:r,onSubmitted:o,onValuesChange:i,cachedValues:s}=t,[a,l]=b.useState(null),[c,u]=b.useState([]),[d,h]=b.useState(r==null?void 0:r.credentialInstanceId),[p,m]=b.useState(),[v,w]=b.useState(!1),[y,g]=b.useState(!1),[C]=x.Form.useForm(),D=se.useStoreApi(),k=r==null?void 0:r.nodeKey,A=r==null?void 0:r.nodeVersion;b.useEffect(()=>{if(!k){console.warn(`${Ur} open next config without nodeKey`,{nodeId:n,data:r}),g(!0);return}let N=!1;return w(!0),g(!1),console.info(`${Ur} open next config`,{nodeId:n,nodeKey:k,nodeVersion:A,hasParams:!!(r!=null&&r.params),credentialInstanceId:r==null?void 0:r.credentialInstanceId}),wd(k,A).then(I=>{var P,_,B,L,H,W,K;if(N){console.info(`${Ur} ignore schema result after unmount`,{nodeId:n,nodeKey:k,nodeVersion:A});return}if(!I){console.warn(`${Ur} next config schema empty`,{nodeId:n,nodeKey:k,nodeVersion:A}),l(null),u([]);return}if(console.info(`${Ur} next config schema loaded`,{nodeId:n,nodeKey:k,nodeVersion:A,schemaKeys:Object.keys(I),schemaVersion:I.version,inputFields:((P=I.input_fields)==null?void 0:P.length)??0,outputs:((_=I.outputs)==null?void 0:_.length)??0,credentials:((B=I.credentials)==null?void 0:B.length)??0,fieldSummaries:((L=I.input_fields)==null?void 0:L.map(q=>({key:q.key,label:q.label,type:q.type,required:q.required})))??[]}),(H=I.input_fields)!=null&&H.length){const q=il(I.input_fields);console.info(`${Ur} next config form schema converted`,{nodeId:n,nodeKey:k,nodeVersion:A,fields:q.fields.length}),l(q)}else console.warn(`${Ur} next config schema has no inputFields`,{nodeId:n,nodeKey:k,nodeVersion:A,schemaKeys:Object.keys(I),hasNestedNodeSchema:!!I.node_schema,nestedInputFields:((K=(W=I.node_schema)==null?void 0:W.input_fields)==null?void 0:K.length)??0}),l(null);u(I.credentials??[])}).catch(I=>{console.error(`${Ur} next config schema load failed`,{nodeId:n,nodeKey:k,nodeVersion:A,err:I})}).finally(()=>{N||(w(!1),g(!0))}),()=>{N=!0}},[n,k,A]);const S=b.useCallback(N=>{console.info(`${Ur} submit next config`,{nodeId:n,nodeKey:k,nodeVersion:A,valueKeys:Object.keys(N),credentialInstanceId:d}),o({params:N,credentialInstanceId:d})},[d,n,k,A,o]),E=b.useCallback(N=>{const I=N.trim().match(BY);if(!I)return null;const P=I[1],_=I[2];if(P==="global")return null;const B=P.startsWith("N")?P.slice(1):P,L=D.getState().nodes.find(H=>H.id===B);return L?{fieldPath:_,node:L,variableNodeId:P}:null},[D]),T=b.useCallback(N=>{var I;return((I=E(N))==null?void 0:I.fieldPath)??N.replace(/^\{\{|\}\}$/g,"")},[E]),O=b.useCallback(N=>{var L;const I=E(N);if(!I)return N;const P=(L=I.node)==null?void 0:L.data,_=(P==null?void 0:P.label)||(P==null?void 0:P.name)||(P==null?void 0:P.action_name)||I.variableNodeId,B=P!=null&&P.note?` (${P.note})`:"";return`${_}${B}.${I.fieldPath}`},[E]);b.useImperativeHandle(e,()=>({saveConfig:()=>C.validateFields().then(N=>(S(N),N)).catch(()=>null)}));const F=b.useMemo(()=>ld(c),[c]);return b.useEffect(()=>{var N;if(!d){m(void 0);return}!p&&((N=F[0])!=null&&N.key)&&m(F[0].key)},[p,d,F]),b.useEffect(()=>{v||!y||a||console.warn(`${Ur} render empty config placeholder`,{nodeId:n,nodeKey:k,nodeVersion:A,loading:v})},[a,v,n,k,A,y]),v?f.jsx("div",{style:{textAlign:"center",padding:40},children:f.jsx(x.Spin,{})}):f.jsxs("div",{children:[F.map(N=>f.jsx(NY,{credentialKey:N.key,label:F.length>1?N.label:void 0,required:N.required,value:p===N.key?d:void 0,onChange:I=>{if(I){m(N.key),h(I);return}p===N.key&&(h(void 0),m(void 0))}},N.key)),a?f.jsx(Ri,{schema:a,form:C,initialValues:s??(r==null?void 0:r.params)??{},onSubmit:S,onChange:i?(N,I)=>i(I):void 0,renderVariableTag:T,renderVariableTooltip:O,showSubmit:!1,showReset:!1,nodeId:n}):f.jsx("div",{style:{padding:16,color:"#999",textAlign:"center"},children:k?"该节点暂无配置项":"未知节点类型"}),f.jsx("div",{style:{padding:"12px 0",position:"sticky",backgroundColor:"#FFFFFF",bottom:0,width:"100%",textAlign:"center",borderTop:"1px solid #eaeaea"},children:f.jsx(x.Button,{type:"primary",style:{width:180,borderRadius:4},onClick:()=>{C.validateFields().then(N=>{S(N)}).catch(()=>{})},children:"保存"})})]})}),IY=()=>{const{event$:t}=b.useContext(Vr),e=jf();return t.useSubscription(n=>{n.type==="insert"&&(console.log("[Bridge] 收到 insert 事件:",{expression:n.expression,hasVarSelector:!!e,activeFieldId:e==null?void 0:e.activeFieldId}),n.expression&&e?e.insertVariableToActiveField(n.expression,!1):e?e.activeFieldId||console.warn("[Bridge] 没有激活的字段(请先点击一个支持变量的表单字段)"):console.warn("[Bridge] VariableSelectorContext 不可用"))}),null},MY=t=>f.jsxs("div",{className:"node-config-title",style:{display:"flex",alignItems:"center"},children:[t.icon?f.jsx("img",{src:t.icon,alt:t.name,style:{width:24,height:24}}):null,f.jsx("div",{className:"node-config-title-name",style:{fontSize:16,fontWeight:600,marginLeft:10},children:t.name}),f.jsx("div",{className:"node-config-title-description",style:{fontSize:12,color:"gray",marginLeft:10},children:t.description})]}),PY=b.memo(({visible:t,onClose:e,data:n,nodeType:r=Z.ACTION,nodeId:o="",cachedValues:i,onValuesChange:s})=>{var D,k,A,S;const a=dt.useEventEmitter(),l=se.useInternalNode(o),{setNodeConfigVisible:c}=Sr(),u=b.useRef(null),d=b.useRef(null),h=b.useRef(null),p=Wt(),m=((k=(D=p.nodeConfigPanel)==null?void 0:D.testArea)==null?void 0:k.allowManualTest)!==!1,{handleNodeDataUpdate:v}=jr(),w=b.useRef(ut.debounce((E,T)=>{s==null||s(E,T)},300)).current,y=b.useMemo(()=>p.nodeConfigPanel.showSettings&&![Z.TRIGGER,Z.MCP_TOOL,Z.AI_SUB_NODE].includes(r),[r,p.nodeConfigPanel.showSettings]),g=b.useCallback(async(E,T)=>{try{v({id:o,data:{params:E.params,credentialInstanceId:E.credentialInstanceId}}),x.message.success("节点配置已保存"),s==null||s(o,null),T&&h.current&&h.current.onTestNode()}catch{}},[(A=l==null?void 0:l.position)==null?void 0:A.x,(S=l==null?void 0:l.position)==null?void 0:S.y,o,v,s]),C=async(E,T)=>{var O,F;if(!T&&E)try{x.message.loading("正在保存节点配置...",0),await((O=d.current)==null?void 0:O.saveConfig()),x.message.destroy(),(F=h.current)==null||F.onTestNode()}catch{x.message.destroy(),x.message.error("节点配置保存失败,无法执行测试")}};return f.jsx(x.Modal,{open:t,footer:null,closeIcon:null,maskClosable:!0,onCancel:()=>{c(null)},centered:!0,width:"90%",className:"nodes-config-modal",styles:{wrapper:{minWidth:1040},mask:{backgroundColor:"rgba(0, 0, 0, 0.45)"},content:{padding:0,overflow:"hidden"}},children:f.jsx(Vr.Provider,{value:{event$:a},children:f.jsxs(Vf,{children:[f.jsx(IY,{}),f.jsxs("div",{className:"nodes-config-container",children:[f.jsxs("div",{className:"nodes-config-header",children:[f.jsx("div",{className:"header-left",children:f.jsx("span",{className:"header-title",children:" 节点配置"})}),f.jsx("div",{className:"header-right",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Q.ArrowLeftOutlined,{}),onClick:e,className:"back-button",children:"返回画布"})})]}),f.jsx("div",{className:"nodes-config-content",children:f.jsxs(x.Row,{gutter:16,className:"config-row",children:[f.jsx(x.Col,{span:5,className:"left-section",children:f.jsx("div",{className:"variables-section",children:f.jsx(OY,{ref:u,nodeId:o,open:t})})}),f.jsx(x.Col,{span:12,className:"middle-section",children:f.jsx("div",{className:"form-section",style:{height:"100%"},children:f.jsx(x.Card,{title:f.jsx(MY,{icon:n==null?void 0:n.icon,name:n==null?void 0:n.name,description:n==null?void 0:n.description}),variant:"borderless",styles:{body:{paddingTop:0,paddingBottom:0}},className:"section-card form-card",children:f.jsx(x.Tabs,{style:{height:"100%"},items:[{key:"property",label:"参数配置",children:f.jsx(FY,{ref:d,nodeId:o,data:n,onSubmitted:g,cachedValues:i,onValuesChange:s?E=>w(o,E):void 0})},...y?[{key:"setting",label:"设置",children:f.jsx(fY,{nodeId:o})}]:[]]})})})}),f.jsx(x.Col,{span:7,className:"right-section",children:m&&f.jsx("div",{className:"test-section",children:f.jsx(x.Card,{variant:"borderless",className:"section-card",children:f.jsx(wY,{ref:h,nodeId:o,beforeHook:C})})})})]})})]})]})})})},(t,e)=>ut.isEqual(ut.omit(t,["isHovered"]),ut.omit(e,["isHovered"])));function LY(){const t=b.useRef(new Map),e=b.useCallback(i=>t.current.get(i),[]),n=b.useCallback((i,s)=>{t.current.set(i,s)},[]),r=b.useCallback(i=>{t.current.delete(i)},[]),o=b.useCallback((i,s)=>{s===null?r(i):n(i,s)},[r,n]);return{getCachedValues:e,handleValuesChange:o}}const $Y=()=>{const{currentNodeConfigVisibleId:t,setNodeConfigVisible:e}=Sr(),n=se.useStoreApi(),{getCachedValues:r,handleValuesChange:o}=LY(),i=t?n.getState().nodes.find(s=>s.id===t):void 0;return f.jsx(PY,{visible:!!t,onClose:()=>e(null),nodeType:i==null?void 0:i.type,data:i==null?void 0:i.data,nodeId:t??"",cachedValues:t?r(t):void 0,onValuesChange:o})};function H_(t,e){return e===1?{top:"50%"}:{top:`${(t+1)/(e+1)*100}%`}}const zd=t=>{const{id:e,data:n,selected:r,minHeight:o=72,maxHeight:i=300,className:s}=t,[a,l]=b.useState(null),[c,u]=b.useState(!0),d=se.useUpdateNodeInternals(),h=n==null?void 0:n.settings,p=(h==null?void 0:h.onError)===Si.CONTINUE_ERROR_OUTPUT;b.useEffect(()=>{const C=n==null?void 0:n.nodeKey,D=n==null?void 0:n.nodeVersion;if(!C){u(!1);return}let k=!1;return wd(C,D).then(A=>{!k&&A&&l(A)}).catch(A=>{console.error("[NextBaseNode] 加载 Schema 失败:",A)}).finally(()=>{k||u(!1)}),()=>{k=!0}},[n==null?void 0:n.nodeKey,n==null?void 0:n.nodeVersion]);const m=b.useMemo(()=>!(a!=null&&a.inputs)||a.inputs.length===0?[{id:"main",position:se.Position.Left,type:We.TARGET}]:a.inputs.map((C,D)=>({id:C.name,position:se.Position.Left,type:We.TARGET,label:C.displayName,style:H_(D,a.inputs.length)})),[a]),v=b.useMemo(()=>{const C=!(a!=null&&a.outputs)||a.outputs.length===0?[{id:"main",position:se.Position.Right,type:We.SOURCE,maxConnections:1}]:a.outputs.map(A=>({id:A.name,position:se.Position.Right,type:We.SOURCE,maxConnections:1,label:A.displayName})),D=C.some(A=>A.id===Ld),k=p&&!D?[...C,{id:Ld,position:se.Position.Right,type:We.SOURCE,maxConnections:1,label:"error"}]:C;return k.map((A,S)=>({...A,style:H_(S,k.length)}))},[a,p]),w=b.useMemo(()=>{const C=Math.max(m.length,v.length);return C<=1?o:Math.min(C*40,i)},[m.length,v.length,o,i]),y=m.length+v.length;b.useEffect(()=>{if(c||!a||y===0)return;const C=setTimeout(()=>{d(e)},100);return()=>{clearTimeout(C)}},[c,a,y,e,d]);const g=n;return f.jsx(Bn,{id:e,data:g,selected:r,height:w,className:s,icon:g!=null&&g.icon?f.jsx("img",{src:g.icon,alt:g.label,style:{width:30,height:30}}):f.jsx(Q.PlayCircleOutlined,{style:{fontSize:24,color:"#007fff"}}),inputs:m,outputs:v,status:g.status})},zY=t=>f.jsx(zd,{...t,className:"next-action-node"}),HY=t=>f.jsx(zd,{...t,className:"next-condition-node"}),VY=t=>f.jsx(zd,{...t,className:"next-switch-node",maxHeight:400}),V_=t=>f.jsx(zd,{...t,className:"next-loop-node"}),jY=t=>{const{id:e,data:n,selected:r}=t,o=n,i=[{id:"main",position:se.Position.Right,type:We.SOURCE,isMain:!0,label:"",maxConnections:1}];return f.jsx(Bn,{id:e,data:o,selected:r,type:Z.TRIGGER,status:o==null?void 0:o.status,icon:o!=null&&o.icon?f.jsx("img",{src:o==null?void 0:o.icon,alt:o.label,style:{width:30,height:30}}):f.jsx(rv.PiCursorFill,{style:{color:"#007fff",fontSize:24}}),inputs:[],outputs:i,className:"workflow-trigger-node"})};class WY{static getNodeTypes(){return{[Z.START]:TA,[Z.TRIGGER]:jY,[Z.ACTION]:zY,[Z.CONDITION]:HY,[Z.SWITCH]:VY,[Z.LOOP]:V_,[Z.SELF_LOOP]:V_,[Z.AGENT]:SA,[Z.BROWSER]:EA,[Z.AI_SUB_NODE]:kd,[Z.VECTOR_STORE]:kd,[Z.MCPServer]:OA,[Z.BuiltinMCP]:DA,[Z.MCP_TOOL]:_A,[Z.CUSTOM]:AA,[Z.STICKY]:mO}}}function UY(t,e){const n=new Set(e.map(o=>{var i;return((i=o.data)==null?void 0:i.name)||""}));if(!n.has(t))return t;let r=1;for(;n.has(`${t} ${r}`);)r++;return`${t} ${r}`}const qY={async loadFlow(t){const e=await TB(t),{nodes:n,edges:r,workflowName:o}=IG(e);return{nodes:n,edges:r,name:o,opStatus:e.active?qe.ONLINE:qe.OFFLINE}},async saveFlow({nodes:t,edges:e,workflowName:n,workflowId:r}){await My(r,$G(t,e,n))},async createNode({actionId:t,icon:e,name:n,connectorName:r,nodeVersion:o,existingNodes:i}){const s=UY(n||"",i||[]);return{nodeId:MG(),nodeData:{connector_name:r||"",name:s,action_name:s,label:s,status:1,protocol:"",icon:e,nodeKey:t,nodeVersion:o??1}}},stickyNodeKey:qG,nodeTypes:WY.getNodeTypes(),convertNodeData:Ag,HeaderComponent:YG,PanelComponent:xG,ConfigModalComponent:$Y,requiresTriggerNode:!1},GY=t=>f.jsx(P_,{strategy:qY,...t});var br=(t=>(t.SECOND="second",t.MINUTE="minute",t.HOUR="hour",t))(br||{});function KY(t){return{[br.SECOND]:"SECONDS",[br.MINUTE]:"MINUTES",[br.HOUR]:"HOURS"}[t]}function YY(t){return{SECONDS:br.SECOND,MINUTES:br.MINUTE,HOURS:br.HOUR}[t]}function XY(){return{enableControl:!1,timeoutValue:30,timeoutUnit:br.MINUTE,maxNodeExecutions:1e4,webhookUrl:""}}function JY(t){return{enabled:t.enableControl,timeout_value:t.timeoutValue,timeout_unit:KY(t.timeoutUnit),max_node_executions:t.maxNodeExecutions,webhook_url:t.webhookUrl||void 0}}function RY(t){return{enableControl:t.enabled,timeoutValue:t.timeout_value,timeoutUnit:YY(t.timeout_unit),maxNodeExecutions:t.max_node_executions,webhookUrl:t.webhook_url||""}}function QY(t){if(!t)return!0;try{return new URL(t),!0}catch{return!1}}const{Text:Ow}=x.Typography,ZY=()=>{const[t,e]=b.useState(!1),[n,r]=b.useState(!1),[o]=x.Form.useForm(),i=x.Form.useWatch("enableControl",o),s=Ci(),a=zo(p=>p.workflow.executionControl),l=M_(),c=()=>{e(!0),o.setFieldsValue(a?RY(a):XY())},u=()=>{e(!1)},d=async()=>{try{const p=await o.validateFields();r(!0),s(vO(JY(p))),await l.saveFlow(),x.message.success("保存成功"),e(!1)}catch(p){x.message.error("保存失败"),console.error(p)}finally{r(!1)}},h=(p,m)=>!m||QY(m)?Promise.resolve():Promise.reject(new Error("请输入合法的URL格式"));return f.jsxs(f.Fragment,{children:[f.jsx(x.Tooltip,{title:"流程设置",children:f.jsx(x.Button,{type:"text",icon:f.jsx(Q.SettingOutlined,{}),onClick:c})}),f.jsx(x.Drawer,{title:"流程设置",placement:"right",width:480,open:t,onClose:u,footer:f.jsxs(x.Space,{style:{float:"right"},children:[f.jsx(x.Button,{onClick:u,children:"取消"}),f.jsx(x.Button,{type:"primary",onClick:d,loading:n,children:"保存"})]}),children:f.jsxs(x.Form,{form:o,layout:"vertical",autoComplete:"off",children:[f.jsx(x.Form.Item,{label:"执行管控",name:"enableControl",valuePropName:"checked",children:f.jsx(x.Switch,{})}),i&&f.jsxs(f.Fragment,{children:[f.jsxs(x.Form.Item,{label:"执行超时",required:!0,style:{marginBottom:8},children:[f.jsxs(x.Space.Compact,{style:{width:"100%"},children:[f.jsx(x.Form.Item,{name:"timeoutValue",noStyle:!0,rules:[{required:!0,message:"请输入超时时间"},{type:"number",min:1,message:"必须大于0"}],children:f.jsx(x.InputNumber,{style:{width:"70%"},placeholder:"请输入",min:1})}),f.jsx(x.Form.Item,{name:"timeoutUnit",noStyle:!0,rules:[{required:!0}],children:f.jsxs(x.Select,{style:{width:"30%"},children:[f.jsx(x.Select.Option,{value:br.SECOND,children:"秒"}),f.jsx(x.Select.Option,{value:br.MINUTE,children:"分钟"}),f.jsx(x.Select.Option,{value:br.HOUR,children:"小时"})]})})]}),f.jsx(Ow,{type:"secondary",style:{fontSize:12},children:"流程执行超过此时间将自动终止,使用墙钟时间计算"})]}),f.jsx(x.Form.Item,{label:"最大节点执行次数",name:"maxNodeExecutions",rules:[{required:!0,message:"请输入最大节点执行次数"},{type:"number",min:1,message:"必须为正整数"}],children:f.jsx(x.InputNumber,{style:{width:"100%"},placeholder:"请输入",min:1,precision:0})}),f.jsx(Ow,{type:"secondary",style:{fontSize:12,display:"block",marginTop:-16,marginBottom:16},children:"流程中所有节点执行的总次数上限,超过后将自动终止"}),f.jsx(x.Form.Item,{label:"错误通知 Webhook",name:"webhookUrl",rules:[{validator:h}],children:f.jsx(x.Input,{placeholder:"请输入 Webhook URL"})}),f.jsx(Ow,{type:"secondary",style:{fontSize:12,display:"block",marginTop:-16},children:"流程因超时或超限终止时,将向此地址发送通知"})]})]})})]})},eX=t=>t==="category"?"分类":"标签",j_=({value:t=[],onChange:e,placeholder:n,templateId:r,optionItems:o,type:i,onCreate:s,onUpdate:a,onDelete:l,onAddRelation:c,onRemoveRelation:u})=>{const[d,h]=b.useState(!1),[p,m]=b.useState(null),[v,w]=b.useState(""),[y,g]=b.useState(!1),[C,D]=b.useState(""),[k,A]=b.useState(!1),S=eX(i),E=L=>{var H;return(H=o.find(W=>W.name===L))==null?void 0:H.id},T=async L=>{const H=E(L);if(!H)return;const W=t.includes(L);try{A(!0),W?(await u(r,H),e==null||e(t.filter(K=>K!==L))):(await c(r,H),e==null||e([...t,L]))}finally{A(!1)}},O=(L,H)=>{H.stopPropagation();const W=E(L);W&&u(r,W).then(()=>{e==null||e(t.filter(K=>K!==L))}).catch(()=>{x.message.error("移除失败")})},F=(L,H)=>{H.stopPropagation(),m(L),w(L)},N=async()=>{const L=v.trim();if(!L||!p)return;if(L.length>8){x.message.error("名称长度不能超过8个字符");return}const H=E(p);if(H)try{A(!0),await a(H,L),e==null||e(t.map(W=>W===p?L:W)),x.message.success("修改成功")}catch{x.message.error("修改失败")}finally{A(!1),m(null),w("")}},I=()=>{m(null),w("")},P=async L=>{const H=E(L);if(H)try{A(!0),await l(H),e==null||e(t.filter(W=>W!==L)),x.message.success("删除成功")}catch{x.message.error("删除失败")}finally{A(!1)}},_=async()=>{const L=C.trim();if(L){if(L.length>8){x.message.error("名称长度不能超过8个字符");return}try{A(!0),await s(L),g(!1),D(""),x.message.success("创建成功")}catch{x.message.error("创建失败")}finally{A(!1)}}},B=()=>{g(!1),D("")};return f.jsxs("div",{className:"template-editable-select",children:[f.jsxs("div",{className:"template-editable-select-input",onClick:()=>h(!d),children:[f.jsx("div",{className:"template-editable-select-tags",children:t.length===0?f.jsx("span",{className:"template-editable-select-placeholder",children:n}):t.map(L=>f.jsx(x.Tag,{closable:!0,onClose:H=>O(L,H),style:{marginRight:4,marginBottom:4},children:L},L))}),f.jsx("div",{className:`template-editable-select-arrow ${d?"template-editable-select-arrow-open":""}`,children:f.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:f.jsx("path",{d:"M2.5 4.5L6 8L9.5 4.5",stroke:"#666",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5"})})})]}),d&&f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"template-editable-select-dropdown-overlay",onClick:()=>h(!1)}),f.jsx("div",{className:"template-editable-select-dropdown-container",onClick:L=>L.stopPropagation(),children:f.jsxs("div",{className:"template-editable-select-dropdown",children:[o.map(L=>f.jsx("div",{className:"template-editable-select-dropdown-item",children:p===L.name?f.jsx("div",{className:"template-editable-select-edit-container",children:f.jsx(x.Input,{autoFocus:!0,className:"template-editable-select-edit-input",disabled:k,maxLength:8,onChange:H=>w(H.target.value),onPressEnter:N,placeholder:`输入新${S}名称(8个字符以内)`,size:"small",suffix:f.jsxs("div",{className:"template-editable-select-edit-actions",children:[f.jsx(x.Button,{className:"template-editable-select-confirm-btn",icon:f.jsx(Q.CheckOutlined,{}),loading:k,onClick:N,size:"small",type:"text"}),f.jsx(x.Button,{className:"template-editable-select-cancel-btn",disabled:k,icon:f.jsx(Q.CloseOutlined,{}),onClick:I,size:"small",type:"text"})]}),value:v})}):f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"template-editable-select-item-content",onClick:()=>T(L.name),children:[f.jsx("div",{className:"template-editable-select-check",children:t.includes(L.name)&&f.jsx(Q.CheckOutlined,{style:{color:"#1890ff"}})}),f.jsx("span",{className:"template-editable-select-name",children:L.name})]}),f.jsxs("div",{className:"template-editable-select-actions",children:[f.jsx(x.Button,{className:"template-editable-select-action-btn",disabled:k,icon:f.jsx(Q.EditOutlined,{}),onClick:H=>F(L.name,H),size:"small",type:"text"}),f.jsx(x.Popconfirm,{cancelText:"取消",okText:"确定",onConfirm:()=>P(L.name),title:`确定删除${S}"${L.name}"吗?`,children:f.jsx(x.Button,{className:"template-editable-select-action-btn",danger:!0,disabled:k,icon:f.jsx(Q.DeleteOutlined,{}),onClick:H=>H.stopPropagation(),size:"small",type:"text"})})]})]})},L.id)),y?f.jsx("div",{className:"template-editable-select-dropdown-item",children:f.jsx("div",{className:"template-editable-select-edit-container",children:f.jsx(x.Input,{autoFocus:!0,className:"template-editable-select-edit-input",disabled:k,maxLength:8,onChange:L=>D(L.target.value),onPressEnter:_,placeholder:`输入新${S}名称(8个字符以内)`,size:"small",suffix:f.jsxs("div",{className:"template-editable-select-edit-actions",children:[f.jsx(x.Button,{className:"template-editable-select-confirm-btn",icon:f.jsx(Q.CheckOutlined,{}),loading:k,onClick:_,size:"small",type:"text"}),f.jsx(x.Button,{className:"template-editable-select-cancel-btn",disabled:k,icon:f.jsx(Q.CloseOutlined,{}),onClick:B,size:"small",type:"text"})]}),value:C})})}):f.jsxs("div",{className:"template-editable-select-add-item",onClick:()=>g(!0),children:[f.jsx(Q.PlusOutlined,{style:{color:"#1890ff",marginRight:4}}),f.jsx("span",{children:"添加选项"})]})]})})]})]})},{TextArea:tX}=x.Input,{Text:_w,Title:Hd}=x.Typography,W_=t=>Array.isArray(t)?t.map(e=>e.name).filter(Boolean):[],nX=({open:t,workflowId:e,workflowName:n,onOpenChange:r,onSuccess:o})=>{const[i]=x.Form.useForm(),s=Ci(),[a,l]=b.useState(!1),[c,u]=b.useState(!1),[d,h]=b.useState([]),[p,m]=b.useState([]),[v,w]=b.useState([]),[y,g]=b.useState([]),C=b.useCallback(async()=>{const B=await iy();return h(B||[]),B},[]),D=b.useCallback(async()=>{const B=await dy();return m(B||[]),B},[]),k=b.useCallback(async()=>{if(e){u(!0);try{let B;try{B=await ry(e)}catch{B=await wf(e)}const L=W_(B==null?void 0:B.categories),H=W_(B==null?void 0:B.tags);w(L),g(H),i.setFieldsValue({name:(B==null?void 0:B.name)||n||"",description:(B==null?void 0:B.description)||"",category:L,tags:H})}catch{x.message.error("获取模板设置失败"),w([]),g([]),i.setFieldsValue({name:n||"",description:"",category:[],tags:[]})}finally{u(!1)}}},[i,e,n]);b.useEffect(()=>{t&&(k(),C().catch(()=>{x.message.error("获取分类列表失败")}),D().catch(()=>{x.message.error("获取标签列表失败")}))},[C,D,k,t]);const A=async B=>{const L=await sy({name:B});return await C(),L},S=async(B,L)=>{const H=await ay(B,{name:L});return await C(),H},E=async B=>{const L=await ly(B);return await C(),L},T=async B=>{const L=await fy({name:B});return await D(),L},O=async(B,L)=>{const H=await hy(B,{name:L});return await D(),H},F=async B=>{const L=await py(B);return await D(),L},N=async()=>{try{const B=await i.validateFields();l(!0);const L={description:B.description,ai_flow:1,id:e};B.name&&(L.name=B.name);try{await oy(e,L)}catch{await Pl(e,L)}B.name&&s($o(B.name)),x.message.success("模板设置已保存"),r(!1),o==null||o()}catch(B){if(B!=null&&B.errorFields)return;x.message.error("保存失败,请重试")}finally{l(!1)}},I=()=>{r(!1)},P=B=>{w(B),i.setFieldValue("category",B)},_=B=>{g(B),i.setFieldValue("tags",B)};return f.jsx(x.Modal,{cancelText:"取消",confirmLoading:a,okText:"保存设置",onCancel:I,onOk:N,open:t,title:f.jsxs(x.Space,{children:[f.jsx(Q.SettingOutlined,{}),f.jsx("span",{children:"模板设置"})]}),width:600,children:c?f.jsx(x.Skeleton,{active:!0,paragraph:{rows:8}}):f.jsxs("div",{className:"workflow-template-settings-modal",children:[f.jsx("div",{className:"workflow-template-settings-hint",children:f.jsx(_w,{type:"secondary",children:"设置模板的基本信息,包括描述和分类标签,便于更好地组织和管理模板。"})}),f.jsxs(x.Form,{form:i,layout:"vertical",preserve:!1,requiredMark:!1,children:[f.jsxs(x.Card,{bodyStyle:{padding:16},className:"workflow-template-settings-card",size:"small",children:[f.jsxs(x.Space,{className:"workflow-template-settings-section-title",children:[f.jsx(Q.FileTextOutlined,{style:{color:"#1890ff"}}),f.jsx(Hd,{level:5,children:"模板名称"})]}),f.jsx(x.Form.Item,{name:"name",rules:[{max:50,message:"最多50个字符"}],children:f.jsx(x.Input,{placeholder:"请输入模板名称",size:"large"})})]}),f.jsxs(x.Card,{bodyStyle:{padding:16},className:"workflow-template-settings-card",size:"small",children:[f.jsxs(x.Space,{className:"workflow-template-settings-section-title",children:[f.jsx(Q.FileTextOutlined,{style:{color:"#1890ff"}}),f.jsx(Hd,{level:5,children:"模板描述"})]}),f.jsx(x.Form.Item,{name:"description",rules:[{max:500,message:"最多500个字符"}],children:f.jsx(tX,{maxLength:500,placeholder:"请输入模板描述,描述该模板的功能和使用场景...",rows:4,showCount:!0})})]}),f.jsxs(x.Card,{bodyStyle:{padding:16},className:"workflow-template-settings-card",size:"small",children:[f.jsxs(x.Space,{className:"workflow-template-settings-section-title",children:[f.jsx(Q.TagsOutlined,{style:{color:"#1890ff"}}),f.jsx(Hd,{level:5,children:"模板分类"}),f.jsx(_w,{className:"workflow-template-settings-subtitle",type:"secondary",children:"(可多选)"})]}),f.jsx(x.Form.Item,{name:"category",rules:[{required:!0,message:"请选择模板分类"}],children:f.jsx(j_,{onAddRelation:cy,onChange:P,onCreate:A,onDelete:E,onRemoveRelation:uy,onUpdate:S,optionItems:d,placeholder:"请选择模板分类",templateId:e,type:"category",value:v})})]}),f.jsxs(x.Card,{bodyStyle:{padding:16},className:"workflow-template-settings-card workflow-template-settings-card-last",size:"small",children:[f.jsxs(x.Space,{className:"workflow-template-settings-section-title",children:[f.jsx(Q.TagsOutlined,{style:{color:"#52c41a"}}),f.jsx(Hd,{level:5,children:"模板标签"}),f.jsx(_w,{className:"workflow-template-settings-subtitle",type:"secondary",children:"(可多选)"})]}),f.jsx(x.Form.Item,{name:"tags",children:f.jsx(j_,{onAddRelation:my,onChange:_,onCreate:T,onDelete:F,onRemoveRelation:gy,onUpdate:O,optionItems:p,placeholder:"请选择模板标签",templateId:e,type:"tag",value:y})})]})]})]})})},{Title:rX,Text:Tw}=x.Typography,U_="[workflow:online-validation]",oX=({opStatus:t})=>{const e=lo();return{[qe.UNPUBLISHED]:f.jsx(x.Tag,{bordered:!1,color:"orange",children:f.jsx(Se.FormattedMessage,{id:"app.common.word.not-published"})}),[qe.ONLINE]:f.jsx(x.Tag,{bordered:!1,color:"green",children:f.jsx(Se.FormattedMessage,{id:"app.common.word.already-online"})}),[qe.OFFLINE]:f.jsx(x.Tag,{bordered:!1,color:"default",children:f.jsx(Se.FormattedMessage,{id:"app.common.word.already-offline"})}),[qe.ONLINE_ING]:f.jsx(x.Tag,{bordered:!1,color:"processing",children:f.jsx(Se.FormattedMessage,{id:"app.common.word.going-online"})}),[qe.ON_WARN]:f.jsx(zl,{to:`/link/log?warnId=${e}`,children:f.jsxs(x.Space,{size:[5,5],children:[f.jsx(Q.ExclamationCircleOutlined,{style:{color:"#faad14"}}),f.jsx(Se.FormattedMessage,{id:"common.warning"})]})}),[qe.OFF_WARN]:f.jsx(zl,{to:`/link/log?warnId=${e}`,children:f.jsxs(x.Space,{size:[5,5],children:[f.jsx(Q.ExclamationCircleOutlined,{style:{color:"#faad14"}}),f.jsx(Se.FormattedMessage,{id:"common.warning"})]})})}[t]},iX=({onSave:t,readOnly:e=!1,preview:n=!1,autoSaveStatus:r=pn.IDLE,lastSavedTime:o,unSave:i,appFlowMode:s=!1,canvasApi:a})=>{var de,z;const l=Ci(),c=Ct(),u=zo(U=>U.workflow.workflowName),d=zo(U=>U.workflow.op_status),[h,p]=b.useState(!1),[m,v]=b.useState(u),[w,y]=b.useState(!1),[g,C]=b.useState(!1),D=b.useRef(null),{getNodes:k}=se.useReactFlow(),A=Wt(),S=A.toolbar,E=S==null?void 0:S.templateSettings,T=lo(),O=((de=k().filter(U=>U.type!==Z.START))==null?void 0:de.length)>0;b.useEffect(()=>{v(u)},[u]),b.useEffect(()=>{h&&D.current&&D.current.focus()},[h]);const F=b.useCallback(()=>{const Y=k().filter(ee=>ee.type!==Z.START).filter(ee=>ee.data.status!==pe.SUCCESS&&ee.data.status!==pe.RUNNABLE);return Y.length&&console.warn(`${U_} node status check failed`,{unhealthyNodes:Y.map(ee=>({id:ee.id,name:ee.data.name,type:ee.type,status:ee.data.status}))}),Y.length===0},[k]),N=b.useCallback(()=>{const U=k().filter(Y=>Y.type!==Z.START),X=(Y,ee,re)=>(console.warn(`${U_} required config check failed`,{node:{id:Y.id,name:Y.data.name,type:Y.type,status:Y.data.status},reason:ee,details:re,configSchema:Y.data.config_schema}),!1);for(const Y of U){const{data:ee,type:re}=Y,{config_schema:ce}=ee;if(re===Z.LOOP){if(!(ce!=null&&ce.asc))return X(Y,"loop config is missing asc");const Ce=Object.keys(ce??{});if(Ce.length===0)return X(Y,"loop config schema is empty");if(Ce.some(Oe=>typeof ce[Oe]>"u"))return X(Y,"loop config contains undefined values",{undefinedKeys:Ce.filter(Oe=>typeof ce[Oe]>"u")})}else if(re===Z.CONDITION){if(!(ce!=null&&ce.or_list)||!ce.or_list.length)return X(Y,"condition config is missing or_list");if(!ce.or_list.every(Oe=>Oe.and_list.every(Pe=>Pe.query&&Pe.operator)))return X(Y,"condition config contains incomplete rules")}else if(re===Z.SWITCH){if(!(ce!=null&&ce.branches)||!ce.branches.length)return X(Y,"switch config is missing branches");if(!ce.branches.every(Oe=>Oe.or_list.every(Pe=>Pe.and_list.every(Ae=>Ae.query&&Ae.operator))))return X(Y,"switch config contains incomplete branch rules")}else if(re!==Z.STICKY){const Ce=ce==null?void 0:ce.sub_params;if(!Array.isArray(Ce))return X(Y,"config_schema.sub_params is missing or invalid");const Oe=Ce.every(Ae=>(console.log("subParams :",Ce),Ae.required?typeof Ae.value<"u"&&Ae.value!==null:!0));if(!Oe)return X(Y,"required parameters are missing",{missingParams:Ce.filter(Ae=>Ae.required&&(typeof Ae.value>"u"||Ae.value===null)).map(Ae=>({key:Ae.key,name:Ae.name,label:Ae.label}))});const Pe=ce!=null&&ce.account_schema_id?!!ce.account_id:!0;if(!Oe||!Pe)return X(Y,"account is required but account_id is missing",{accountSchemaId:ce==null?void 0:ce.account_schema_id,accountId:ce==null?void 0:ce.account_id})}}return!0},[k]),I=()=>{if((d===qe.ONLINE||d===qe.ON_WARN)&&(!N()||!F())){x.message.warning("当前流程节点存在异常,请完成节点测试或下线流程后再尝试保存");return}t==null||t()},P=U=>{v(U.target.value)};dt.useUnmount(()=>{l(Nd()),$o("")});const _=b.useCallback(()=>{const U=u,X=m.trim(),Y=X||"未命名工作流";l($o(Y)),Pl(T,{name:Y}).then(()=>{}).catch(()=>{l($o(U))}),p(!1)},[l,m,u]),B=()=>{_()},L=()=>{_()},H=()=>{var U;!e&&((U=S==null?void 0:S.flowName)==null?void 0:U.editable)!==!1&&p(!0)},W=()=>{if(i)return f.jsx(x.Tooltip,{title:"暂未保存",children:f.jsx(x.Tag,{bordered:!1,color:"warning",children:"未保存"})});switch(r){case pn.SAVING:return f.jsx(x.Tooltip,{children:f.jsx("div",{style:{display:"flex",alignItems:"center"},children:f.jsx(Q.SyncOutlined,{spin:!0,style:{marginRight:8,color:"#1890ff"}})})});case pn.SAVED:return f.jsx(x.Tooltip,{title:`已自动保存 (${o})`,children:f.jsx("div",{style:{display:"flex",alignItems:"center"},children:f.jsxs(x.Tag,{bordered:!1,color:"green",children:["已保存"," ",f.jsx("span",{style:{fontSize:10,marginLeft:4,color:"#999"},children:o})]})})});case pn.ERROR:return f.jsx(x.Tooltip,{title:"自动保存失败",children:f.jsx(x.Badge,{status:"error",text:f.jsx("span",{children:"保存失败"})})});default:return null}},[K,q]=x.Modal.useModal(),te=async()=>{var Y;const U=d===qe.ONLINE||d===qe.ON_WARN,X=()=>{var ee,re;if((ee=S==null?void 0:S.nav)!=null&&ee.onBack){S.nav.onBack();return}if((re=S==null?void 0:S.nav)!=null&&re.backTo){Mi.push(S.nav.backTo);return}s?Mi.back():Mi.push("/link/ai-flow")};if(!U&&((Y=S==null?void 0:S.nav)!=null&&Y.confirmOnBackWhenOffline)&&i){await K.confirm({title:R("user.common.operation_title"),content:S.nav.backConfirmMessage||"当前流程未保存,是否确认返回?"})&&X();return}X()},$=async(U={})=>{if(!T)return;y(!0);const{force:X=!1,customFn:Y}=U;return(X?Ty(T):Y?Y(T):xf(T,qe.ONLINE)).then(()=>(x.message.success(R("link.flow.online_success")),l(Os(qe.ONLINE)),{success:!0})).catch(re=>({success:!1,error:re})).finally(()=>{y(!1)})},V=async U=>{if(!T)return;y(!0),(U?U(T):xf(T,qe.OFFLINE)).then(()=>{x.message.success(R("link.flow.offline_success")),l(Os(qe.OFFLINE))}).catch(()=>{}).finally(()=>{y(!1)})},J=async()=>await K.confirm({icon:f.jsx(f.Fragment,{}),centered:!0,title:R("link.flow.confirm_online"),content:(S==null?void 0:S.enableOnlineConfirmMessage)||R("link.flow.force_online_confirm"),cancelText:R("common.no"),okText:R("common.yes")}),ne=async U=>{if(U){if(!F()){await J()&&await $({force:!0,customFn:S==null?void 0:S.customOnlineApi});return}const Y=await $({force:!1,customFn:S==null?void 0:S.customOnlineApi});Y&&!Y.success&&await J()&&await $({force:!0,customFn:S==null?void 0:S.customOnlineApi})}else V(S==null?void 0:S.customOfflineApi)},ae=()=>{var X,Y,ee,re;const U=[];return((X=S==null?void 0:S.nav)==null?void 0:X.showBack)!==!1&&(U.push(f.jsx(x.Button,{type:"text",icon:f.jsx(Q.ArrowLeftOutlined,{className:"workflow-back-icon"}),onClick:te,children:R("app.common.word.back")},"back")),U.push(f.jsx(x.Divider,{type:"vertical"},"divider-back"))),s||(h?U.push(f.jsx(x.Input,{ref:D,value:m,onChange:P,onPressEnter:B,onBlur:L,maxLength:30,className:"workflow-name-input",placeholder:"请输入工作流名称"},"name-input")):U.push(f.jsx("div",{className:"workflow-name",onClick:n?void 0:H,children:u?f.jsxs(f.Fragment,{children:[f.jsx(rX,{level:4,className:"workflow-name-text",children:u}),!e&&!n&&((Y=S==null?void 0:S.flowName)==null?void 0:Y.editable)&&f.jsx(Q.FormOutlined,{className:"edit-icon"})]}):f.jsx(x.Skeleton.Input,{active:!0,size:"small"})},"name-display")),U.push(f.jsx(x.Divider,{type:"vertical"},"divider-name"))),n?U.push(f.jsx(Tw,{type:"secondary",children:"预览模式"},"preview-text")):U.push(f.jsxs(x.Space,{size:8,children:[A.toolbar.enableOnlineButton&&f.jsxs(b.Fragment,{children:[f.jsx(Tw,{children:(S==null?void 0:S.enableFlowText)||"启用流程"}),f.jsx(x.Switch,{disabled:!O,onChange:ne,loading:w,checked:d===qe.ONLINE||d===qe.ON_WARN})]}),f.jsx(x.Divider,{type:"vertical"}),((ee=S==null?void 0:S.flowStatusTag)==null?void 0:ee.enabled)===!1?null:f.jsx("span",{style:(re=S==null?void 0:S.flowStatusTag)==null?void 0:re.style,children:f.jsx(oX,{opStatus:d})})]},"online-area")),U.push(f.jsx(x.Divider,{type:"vertical"},"divider-status")),!c&&!n&&U.push(f.jsx(Tw,{type:"secondary",children:"当前流为只读模式,如需编辑,请下线流程"},"readonly-hint")),U};return f.jsxs("div",{className:"workflow-canvas-header",children:[q,f.jsx("div",{className:"workflow-heder-left-area",children:ae()}),f.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[c&&!n&&W(),f.jsx("span",{children:f.jsx(x.Button,{icon:f.jsx(Q.QuestionCircleOutlined,{}),type:"link",onClick:()=>{const U=(S==null?void 0:S.helpDocUrl)||"https://1in15q85qd.apifox.cn/8698531m0";window.open(U,"_blank")},children:(S==null?void 0:S.helpDocText)||"帮助文档"})}),f.jsxs(x.Space,{style:{marginLeft:16},children:[c&&!n&&(E==null?void 0:E.enabled)&&T&&f.jsx(x.Tooltip,{title:E.buttonText||"模板设置",children:f.jsx(x.Button,{icon:f.jsx(Q.SettingOutlined,{}),onClick:()=>C(!0),type:"text",children:E.buttonText||"模板设置"})}),(z=S==null?void 0:S.buttons)==null?void 0:z.map(U=>f.jsx(x.Button,{style:U.style,icon:U.icon,type:U.type??"default",onClick:()=>{U.onClick&&a&&U.onClick(a)},children:U.label},U.id)),c&&!n&&f.jsx(ZY,{}),c&&!n&&f.jsx(f.Fragment,{children:f.jsx(x.Tooltip,{title:"保存",children:f.jsx(x.Button,{onClick:I,type:"primary",children:"保存"})})})]})]}),(E==null?void 0:E.enabled)&&T&&f.jsx(nX,{onOpenChange:C,open:g,workflowId:T,workflowName:u})]})},sX=({categories:t,activeId:e,loading:n,onChange:r})=>{const o=i=>{const s=i.currentTarget,a=s.scrollWidth-s.clientWidth;if(a<=0||Math.abs(i.deltaY)<=Math.abs(i.deltaX))return;const l=Math.min(Math.max(s.scrollLeft+i.deltaY,0),a);l!==s.scrollLeft&&(i.preventDefault(),s.scrollLeft=l)};return n?f.jsx("div",{className:"category-tabs-wrapper loading",children:f.jsxs("div",{className:"category-tabs-loading",children:[f.jsx(x.Spin,{size:"small"}),f.jsx("span",{children:"分类加载中"})]})}):f.jsxs("div",{className:"category-tabs-wrapper",children:[f.jsx("div",{className:"category-tabs",onWheel:o,children:t.map(i=>f.jsx("div",{className:Sn("category-tab",{active:e===i.id}),onClick:()=>r(i),children:i.name},i.id))}),f.jsx("div",{className:"category-tabs-mask left"}),f.jsx("div",{className:"category-tabs-mask right"})]})},aX=({action:t,parentNode:e,onSelect:n})=>{const r=()=>{n(e,t)};return f.jsxs("div",{className:"action-item",onClick:r,children:[f.jsx("div",{className:"item-icon","data-category":e.category.split("-")[0]||"action",children:t.icon?f.jsx("img",{src:t.icon,alt:t.name,style:{width:32,height:32}}):f.jsx("div",{children:t.name.charAt(0).toUpperCase()})}),f.jsxs("div",{className:"item-content",children:[f.jsx("div",{className:"item-title",children:t.name}),t.description&&f.jsx("div",{className:"item-description",children:t.description})]})]})},lX=({node:t,expanded:e,actions:n,loading:r,hasPartialActions:o,onToggle:i,onActionSelect:s,onLoadAllActions:a})=>{const l=()=>{i(t)},c=u=>{u.stopPropagation(),a==null||a(t)};return f.jsxs("div",{className:Sn("node-card",{expanded:e}),children:[f.jsxs("div",{className:"node-card-header",onClick:l,children:[f.jsx("div",{className:"node-card-icon",children:t.icon?f.jsx("img",{src:t.icon,alt:t.name}):f.jsx("span",{children:t.name.charAt(0).toUpperCase()})}),f.jsxs("div",{className:"node-card-info",children:[f.jsx("div",{className:"node-card-title",children:t.name}),t.description&&f.jsx("div",{className:"node-card-desc",children:t.description})]}),f.jsx(Q.CaretDownOutlined,{className:Sn("node-card-arrow",{expanded:e})})]}),e&&f.jsxs("div",{className:"node-card-body",children:[r?f.jsx("div",{className:"node-card-state",children:"动作加载中..."}):n.length===0?f.jsx("div",{className:"node-card-state",children:"暂无可用动作"}):f.jsx("div",{className:"node-card-actions",children:n.map(u=>f.jsx("div",{className:"node-card-action-wrapper",onClick:d=>d.stopPropagation(),children:f.jsx(aX,{action:u,parentNode:t,onSelect:s})},u.id))}),o&&!r&&f.jsx("div",{className:"node-card-more",onClick:c,children:"查看该节点全部动作"})]})]})},cX=({currentCategory:t,categoryPath:e,selectedNode:n,onBack:r,onClose:o,title:i,subTitle:s,showBackButton:a})=>{const l=()=>n?n.name:t?t.name:"节点选择器",c=()=>n?"选择动作":e.length>0?e.slice(0,-1).map(p=>p.name).join(" / "):"",u=i||l(),d=s??c(),h=typeof a=="boolean"?a:!!(n||e.length>0);return f.jsxs("div",{className:"panel-header",children:[f.jsxs("div",{className:"header-left",children:[h&&r&&f.jsx("div",{className:"back-button",onClick:r,children:f.jsx(Q.ArrowLeftOutlined,{})}),f.jsxs("div",{className:"title",children:[u,d&&f.jsx("div",{className:"category-path",children:d})]})]}),f.jsx("div",{className:"close-button",onClick:o,children:f.jsx(Q.CloseOutlined,{})})]})},q_=[],G_=Object.freeze(Object.defineProperty({__proto__:null,defaultCategories:q_},Symbol.toStringTag,{value:"Module"})),Nw="[workflow:schema-render]",uX=new Set(Object.values(Z)),dX=t=>{if(t)return uX.has(t)?t:void 0},fX=({nodeSelectorVisible:t,nodeAddInfo:e})=>{const[n,r]=b.useState(!1),o=lo();return{isLoadingActions:n,fetchNodeActions:async(s,a)=>{a!=null&&a.suppressLoading||r(!0);try{const l=t&&e&&e.trigger===!0,c={linkId:s.id,flowId:o},u=(e==null?void 0:e.protocol)===Ie.BUILTIN_MCP?Z.MCP_TOOL:dX(s.type);u&&(c.actionType=u),l&&(c.trigger=!0);const d=await Qv(c);return d&&d.items&&Array.isArray(d.items)?d.items.map(p=>{var v,w,y,g;const m=p.action_ver??((v=p.node_schema)==null?void 0:v.version);return p.action_key&&((y=(w=p.node_schema)==null?void 0:w.input_fields)!=null&&y.length)?(console.info(`${Nw} preload schema from actions list`,{actionId:p.id,nodeKey:p.action_key,actionVer:p.action_ver,schemaVersion:p.node_schema.version,resolvedVersion:m,inputFields:p.node_schema.input_fields.length}),gA(p.action_key,m,p.node_schema)):p.action_key&&p.node_schema?console.info(`${Nw} action list inline schema has no inputFields`,{actionId:p.id,nodeKey:p.action_key,actionVer:p.action_ver,schemaVersion:p.node_schema.version,resolvedVersion:m,inputFields:((g=p.node_schema.input_fields)==null?void 0:g.length)??0}):p.action_key&&console.info(`${Nw} action list item without inline schema`,{actionId:p.id,nodeKey:p.action_key,resolvedVersion:m}),{...p,id:p.id,action_key:p.action_key,action_ver:m,nodeKey:p.action_key,nodeVersion:m,node_schema:p.node_schema,name:p.name||"未命名动作",description:p.description||"",connector_name:s.name,nodeId:s.id,nodeIcon:s.icon}}):[]}catch(l){return console.error("获取动作列表失败:",l),[]}finally{a!=null&&a.suppressLoading||r(!1)}}}},hX=({onFetchCategories:t,restrictToCategory:e,nodeSelectorVisible:n,nodeAddInfo:r,fallbackCategories:o=[]})=>{const[i,s]=b.useState(o),[a,l]=b.useState(!1);return b.useEffect(()=>{if(!n)return;(async()=>{l(!0);try{let u="action";const d=n&&r&&r.trigger,h=r==null?void 0:r.protocol,p=!!h;d?u="trigger":h===Ie.AI_TOOL?u="mcp":h===Ie.BUILTIN_MCP?u="tool":h===Ie.AI_LANGUAGE_MODEL?u="model":h===Ie.AI_MEMORY&&(u="memory");const m=await t(u),v=e?m.filter(y=>y.id===e):d?m:m.filter(y=>y.id!=="TRIGGER"),w=e||p?null:{id:"ALL",name:"全部",description:"全部分类",icon:void 0};s(w?[w,...v]:v)}catch(u){console.error("Failed to fetch categories:",u),s(o)}finally{l(!1)}})()},[t,e,n,r,o]),{categories:i,isLoadingCategories:a,setCategories:s}},pX=({categories:t,initialCategory:e,nodeSelectorVisible:n,nodeAddInfo:r,onFetchNodesByCategory:o,defaultPageSize:i=20,flowId:s})=>{const[a,l]=b.useState(e||"ALL"),[c,u]=b.useState([]),[d,h]=b.useState(!1),[p,m]=b.useState({page:1,size:i,total:0,hasMore:!0}),v=n&&r&&r.trigger===!0,w=n&&r&&r.protocol===Ie.AI_TOOL,y=n&&r&&r.protocol===Ie.BUILTIN_MCP,g=b.useMemo(()=>{const O=r==null?void 0:r.protocol;if(O){if(O===Ie.AI_TOOL)return Ie.MCP;if(O===Ie.AI_LANGUAGE_MODEL||O===Ie.AI_MEMORY)return O}},[r==null?void 0:r.protocol]),C=b.useMemo(()=>{const O=r==null?void 0:r.protocol;if(O===Ie.AI_TOOL)return"tool";if(O===Ie.AI_LANGUAGE_MODEL)return"model";if(O===Ie.AI_MEMORY)return"memory"},[r==null?void 0:r.protocol]),D=b.useMemo(()=>a==="ALL"?null:t.find(O=>O.id===a)||null,[a,t]),k=b.useCallback((O,F=1)=>({app_domain_category:O&&O!=="ALL"?O:void 0,page:F,size:i,trigger:!!v,type:C,protocol:g,flow_id:s}),[i,v,C,g,s]),A=b.useCallback(async(O,F=1,N=!1)=>{if(n){h(!0);try{const I=k(O,F),{nodes:P,total:_,size:B}=await o(I);u(L=>N?[...L,...P]:P),m({page:F,size:B,total:_,hasMore:F*B<_})}catch(I){console.error("Failed to fetch category data:",I),N||u([])}finally{h(!1)}}},[k,n,o]),S=b.useCallback(async O=>{l(O),await A(O,1,!1)},[A]),E=b.useCallback(async()=>{d||!p.hasMore||await A(a||"ALL",p.page+1,!0)},[A,d,p,a]),T=b.useCallback(()=>{l(e||"ALL"),u([]),m({page:1,size:i,total:0,hasMore:!0})},[e,i]);return b.useEffect(()=>{var F,N;if(!n){T();return}const O=e&&((F=t.find(I=>I.id===e))==null?void 0:F.id)||((N=t[0])==null?void 0:N.id)||"ALL";l(O),A(O,1,!1)},[n,t,e,A,T]),{categoryNodes:c,currentCategory:D,isLoadingNodes:d,isRealTriggerMode:v,isAIToolMode:w,isBuiltinMCPMode:y,navigateToCategory:S,loadMoreNodes:E,resetNavigation:T,pagination:p,activeCategoryId:a,setActiveCategoryId:l}},mX=({onSearch:t})=>{const[e,n]=b.useState(""),[r,o]=b.useState([]),[i,s]=b.useState(!1),[a,l]=b.useState({total:0,page:1,size:20}),c=b.useCallback(async(d,h={})=>{if(n(d),!d.trim()){o([]),l({total:0,page:1,size:h.size||20});return}s(!0);try{const{nodes:p,total:m,page:v,size:w}=await t({...h,name:d});o(p),l({total:m,page:v,size:w})}catch(p){console.error("Search failed:",p),o([]),l({total:0,page:1,size:h.size||20})}finally{s(!1)}},[t]),u=b.useCallback(()=>{n(""),o([]),l({total:0,page:1,size:20})},[]);return{searchText:e,searchResults:r,isSearching:i,searchMeta:a,handleSearch:c,clearSearch:u,setSearchText:n}},Bw="[workflow:schema-render]",gX=(t,e)=>{var o,i,s,a;const n=t.action_type||t.node_struct||Z.ACTION,r=t.action_ver??((o=t.node_schema)==null?void 0:o.version);return t.action_key&&((s=(i=t.node_schema)==null?void 0:i.input_fields)!=null&&s.length)?(console.info(`${Bw} preload schema from search result`,{actionId:t.id,nodeKey:t.action_key,actionVer:t.action_ver,schemaVersion:t.node_schema.version,resolvedVersion:r,inputFields:t.node_schema.input_fields.length}),gA(t.action_key,r,t.node_schema)):t.action_key&&t.node_schema?console.info(`${Bw} search result inline schema has no inputFields`,{actionId:t.id,nodeKey:t.action_key,actionVer:t.action_ver,schemaVersion:t.node_schema.version,resolvedVersion:r,inputFields:((a=t.node_schema.input_fields)==null?void 0:a.length)??0}):t.action_key&&console.info(`${Bw} search result action without inline schema`,{actionId:t.id,nodeKey:t.action_key,resolvedVersion:r}),{...t,id:t.id,type:n,action_type:n,action_key:t.action_key,action_ver:r,nodeKey:t.action_key,nodeVersion:r,node_schema:t.node_schema,action_name:t.name||e.name,name:t.name||e.name,description:t.description||e.description||"",connector_name:e.name,nodeId:e.id,nodeIcon:e.icon}},wX=(t,e)=>{if(typeof e=="boolean")return e;if(!t)return!1;const n=t.toUpperCase();return n==="ACTION_ONLY"||n==="BOTH_MATCHED"},vX=(t,e)=>{const{matchedActions:n,defaultExpanded:r,matchType:o}=e||{};return{id:t.id||t.name,type:t.build_type||Z.ACTION,name:t.name,description:t.description||"",category:t.app_domain_category&&t.app_domain_category[0]||"unknown",icon:t.icon||void 0,app_domain_category:t.app_domain_category||[],actionCategories:t.app_action_category||[],deployment_type:t.deployment_type,build_type:t.build_type,matchedActions:n,defaultExpanded:wX(o,r),matchType:o,connector:t}},K_=async(t={})=>{var e;try{const{apiSearchLinks:n}=await Promise.resolve().then(()=>Iy),r=await n({...t,page:t.page||1,size:t.size||20}),o=((e=r.items)==null?void 0:e.map(({connector:i,matched_actions:s,default_expanded:a,match_type:l})=>{const c=(s||[]).map(u=>gX(u,i));return vX(i,{matchedActions:c,defaultExpanded:a,matchType:l})}))||[];return{nodes:o,total:r.total||o.length,page:r.page||t.page||1,size:r.size||t.size||20,pages:r.pages}}catch(n){return console.error("获取节点列表失败:",n),{nodes:[],total:0,page:t.page||1,size:t.size||20,pages:0}}},yX=async t=>{try{const{apiGetNodeCategory:e}=await Promise.resolve().then(()=>Iy),{defaultCategories:n}=await Promise.resolve().then(()=>G_),r=await e({type:t}),o=i=>({id:i.name,name:i.label,description:i.desc||"",icon:i.icon||void 0,search_action:i.search_action||!1,children:i.next&&i.next.length>0?i.next.map(s=>o(s)):void 0,nodes:[]});return Array.isArray(r)?r.map(i=>o(i)):n}catch(e){console.error("获取分类失败:",e);const{defaultCategories:n}=await Promise.resolve().then(()=>G_);return n}},bX=({availableCategories:t=q_,initialCategory:e,onSearch:n,onFetchCategories:r,onFetchNodesByCategory:o,restrictToCategory:i})=>{const s=b.useRef(null),a=b.useRef(null),[l,c]=b.useState([]),[u,d]=b.useState({}),h=n||K_,p=r||yX,m=o||K_,{nodeSelectorVisible:v,closeNodeSelector:w,handleNodeSelect:y,nodeAddInfo:g}=_s(),C=lo(),{fetchNodeActions:D}=fX({nodeSelectorVisible:v,nodeAddInfo:g}),{categories:k,isLoadingCategories:A}=hX({onFetchCategories:p,restrictToCategory:i,nodeSelectorVisible:v,nodeAddInfo:g,fallbackCategories:t}),{searchText:S,searchResults:E,isSearching:T,handleSearch:O,clearSearch:F,setSearchText:N}=mX({onSearch:h}),I=b.useRef(S),{categoryNodes:P,isLoadingNodes:_,isRealTriggerMode:B,navigateToCategory:L,loadMoreNodes:H,resetNavigation:W,pagination:K,activeCategoryId:q,currentCategory:te}=pX({categories:k,initialCategory:e,nodeSelectorVisible:v,nodeAddInfo:g,onFetchNodesByCategory:m,flowId:C}),$=b.useMemo(()=>S?E:P,[S,E,P]),V=b.useMemo(()=>(g==null?void 0:g.protocol)===Ie.AI_LANGUAGE_MODEL?"选择模型":"选择动作",[g==null?void 0:g.protocol]),J=b.useMemo(()=>(g==null?void 0:g.protocol)===Ie.AI_LANGUAGE_MODEL||(g==null?void 0:g.protocol)===Ie.AI_MEMORY?"按模型名称搜索":"按节点/动作名称搜索",[g==null?void 0:g.protocol]),ne=S,ae=b.useMemo(()=>{const fe=g==null?void 0:g.protocol;if(fe){if(fe===Ie.AI_TOOL)return Ie.MCP;if(fe===Ie.AI_LANGUAGE_MODEL||fe===Ie.AI_MEMORY)return fe}},[g==null?void 0:g.protocol]),de=b.useMemo(()=>{const fe=g==null?void 0:g.protocol;if(fe===Ie.AI_TOOL)return"tool";if(fe===Ie.AI_LANGUAGE_MODEL)return"model";if(fe===Ie.AI_MEMORY)return"memory"},[g==null?void 0:g.protocol]),z=b.useCallback(()=>({app_domain_category:q&&q!=="ALL"?q:void 0,trigger:!!B,type:de,protocol:ae,flow_id:C}),[q,B,de,ae,C]),{run:U,cancel:X}=dt.useDebounceFn(fe=>{const Ne=fe.trim();if(!Ne){F(),c([]);return}O(Ne,z())},{wait:300}),Y=b.useCallback(async fe=>{d(Be=>{var tt,un;return{...Be,[fe.id]:{actions:((tt=Be[fe.id])==null?void 0:tt.actions)||[],loading:!0,source:(un=Be[fe.id])==null?void 0:un.source}}});const Ne=await D(fe,{suppressLoading:!0});d(Be=>({...Be,[fe.id]:{actions:Ne,loading:!1,source:"full"}}))},[D]),ee=async fe=>{if(l.includes(fe.id)){c(tt=>tt.filter(un=>un!==fe.id));return}c(tt=>[...tt,fe.id]);const Be=u[fe.id];(!Be||Be.actions.length===0||Be.source==="search-partial")&&await Y(fe)},re=async fe=>{await Y(fe)},ce=(fe,Ne)=>{const Be={...Ne,...g,name:fe.name,description:Ne.name||"",type:(Ne==null?void 0:Ne.action_type)??Z.ACTION,connector_name:(fe==null?void 0:fe.name)||"",category:(fe==null?void 0:fe.category)||"unknown",icon:fe.icon,isAction:!0};y(Be)},Ce=async fe=>{c([]),F(),await L(fe.id)},Oe=fe=>{N(fe),U(fe)},Pe=fe=>{if(S||!K.hasMore||_)return;const{scrollTop:Ne,scrollHeight:Be,clientHeight:tt}=fe.currentTarget;Be-Ne-tt<120&&H()};b.useEffect(()=>{if(!v){const fe=setTimeout(()=>{F(),W(),c([]),d({})},200);return()=>clearTimeout(fe)}return()=>X()},[v,F,W,X]),b.useEffect(()=>{if(I.current=S,S){const fe=E.filter(Ne=>Ne.defaultExpanded).map(Ne=>Ne.id);c(fe)}},[E,S]),b.useEffect(()=>{S||c([])},[q,S]),b.useEffect(()=>{I.current&&O(I.current,z())},[q,z,O]),b.useEffect(()=>{d(fe=>{const Ne={};return $.forEach(Be=>{Be.matchedActions&&Be.matchedActions.length>0?Ne[Be.id]={actions:Be.matchedActions,loading:!1,source:"search-partial"}:fe[Be.id]?Ne[Be.id]=fe[Be.id]:Ne[Be.id]={actions:[],loading:!1}}),Ne})},[$]),dt.useClickAway(()=>{v&&w()},s);const Ae=()=>T?f.jsxs("div",{className:"loading-state",children:[f.jsx(x.Spin,{}),f.jsx("span",{className:"loading-text",children:"搜索中..."})]}):!T&&$.length===0?f.jsx("div",{className:"empty-state",children:f.jsx("div",{className:"empty-text",children:"暂无符合条件的节点"})}):f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"node-card-list",children:$.map(fe=>{var Ne,Be,tt;return f.jsx(lX,{node:fe,expanded:l.includes(fe.id),actions:((Ne=u[fe.id])==null?void 0:Ne.actions)||[],loading:((Be=u[fe.id])==null?void 0:Be.loading)||!1,hasPartialActions:((tt=u[fe.id])==null?void 0:tt.source)==="search-partial",onToggle:ee,onActionSelect:ce,onLoadAllActions:re},fe.id)})}),!S&&_&&$.length>0&&f.jsxs("div",{className:"list-loading",children:[f.jsx(x.Spin,{size:"small"}),f.jsx("span",{children:"正在加载更多"})]}),!S&&!K.hasMore&&!_&&$.length>0&&f.jsx("div",{className:"list-footer",children:"已加载全部"})]});return v?f.jsxs("div",{className:Sn("modern-node-selector",{visible:v}),ref:s,children:[f.jsx(cX,{currentCategory:te,categoryPath:[],selectedNode:null,onClose:w,title:V,showBackButton:!1}),f.jsx("div",{className:"search-container",children:f.jsx(x.Input,{placeholder:J,prefix:f.jsx(Q.SearchOutlined,{style:{color:"#007aff"}}),allowClear:!0,value:ne,onChange:fe=>Oe(fe.target.value)})}),f.jsx(sX,{categories:k,activeId:q||"ALL",loading:A,onChange:Ce}),f.jsx("div",{className:"panel-content",ref:a,onClick:fe=>fe.stopPropagation(),onScroll:Pe,children:Ae()})]}):null};function CX(t){return t.map(e=>{const{node_type:n,id:r,position:o,icon:i,action_name:s,connector_name:a,description:l,action_id:c,connector_id:u,properties:d,account_schema_id:h,account_id:p,action_key:m,action_ver:v,...w}=e;let y,g;if(n===Z.STICKY)try{const D=JSON.parse(d.value);y=D.width,g=D.height}catch{}const C={type:n,id:r,position:o,data:{icon:i,label:s,action_name:s,description:l,connector_name:a,connector_id:u,account_id:p,account_schema_id:h,action_id:c,action_key:m,action_ver:v,nodeKey:m||w.nodeKey,nodeVersion:v??w.nodeVersion,params:w.params||d,config_schema:d,...w}};if(typeof y=="number"||typeof g=="number"){const D=C.style||{};C.style={...D,...typeof y=="number"?{width:y}:{},...typeof g=="number"?{height:g}:{}}}return C})}function kX(t){if(!t)return console.error("API返回数据格式错误: 缺少data字段"),{workflowId:"",workflowName:"",nodes:[],edges:[]};const e=CX(t.nodes||[]),n=e.map(o=>o.id),r=(t.connections||[]).map(o=>({...o,type:o.type||"main"})).filter(o=>n.includes(o.target)&&o.source&&o.sourceHandle&&o.targetHandle);return{workflowId:t.id||"",workflowName:t.name||"",nodes:e,edges:r}}function xX(t,e,n=""){const r=t.filter(o=>o.type!==Z.START).map(o=>{const{config_schema:i,config:s,params:a,node_schema:l,...c}=o.data;return{...c,node_type:o.type,connector_id:o.data.connector_id||"",id:o.id,action_id:o.data.action_id||o.data.id||"",account_id:o.data.account_id||null,position:o.position,properties:i||s||{},action_name:o.data.label||"",description:o.data.description||""}});return{name:n,connections:e,nodes:r}}const SX={async loadFlow(t){const e=await wf(t),{nodes:n,edges:r,workflowName:o}=kX(e);return{nodes:n,edges:r,name:o||e.name||"",opStatus:e.op_status,executionControl:e.execution_control??null}},async saveFlow({nodes:t,edges:e,workflowName:n,workflowId:r,executionControl:o}){const i=xX(t,e,n);o&&(i.execution_control=o),await Pl(r,i)},async createNode({workflowId:t,nodeType:e,actionId:n,actionKey:r,actionVer:o,configSchema:i,position:s}){const a=await ty({flow_id:t,node_type:e,action_id:n,...r?{action_key:r,action_ver:o}:{},properties:i||{},position:s});return{nodeId:a.id,nodeData:{action_name:a.action_name,connector_name:a.connector_name,status:a.status,icon:a.icon,protocol:a.protocol,...r?{action_key:r,action_ver:o,nodeKey:r,nodeVersion:o}:{}}}},stickyNodeKey:UG,nodeTypes:In.getNodeTypes(),HeaderComponent:iX,PanelComponent:bX,requiresTriggerNode:!0},EX=t=>f.jsx(P_,{strategy:SX,...t}),Dt={"configSubflow-container":"_configSubflow-container_xgeh3_1","configSubflow-selectSection":"_configSubflow-selectSection_xgeh3_4","configSubflow-selectWrapper":"_configSubflow-selectWrapper_xgeh3_19","configSubflow-select":"_configSubflow-select_xgeh3_4","configSubflow-optionContent":"_configSubflow-optionContent_xgeh3_28","configSubflow-optionName":"_configSubflow-optionName_xgeh3_34","configSubflow-optionLink":"_configSubflow-optionLink_xgeh3_41","configSubflow-paramsSection":"_configSubflow-paramsSection_xgeh3_60","configSubflow-paramsTitle":"_configSubflow-paramsTitle_xgeh3_65","configSubflow-paramsList":"_configSubflow-paramsList_xgeh3_77","configSubflow-paramItem":"_configSubflow-paramItem_xgeh3_82",hasError:"_hasError_xgeh3_95","configSubflow-paramKey":"_configSubflow-paramKey_xgeh3_99","configSubflow-paramKeyLabel":"_configSubflow-paramKeyLabel_xgeh3_104","configSubflow-paramValue":"_configSubflow-paramValue_xgeh3_124","configSubflow-hintMessage":"_configSubflow-hintMessage_xgeh3_150",warning:"_warning_xgeh3_164",info:"_info_xgeh3_169","configSubflow-errorText":"_configSubflow-errorText_xgeh3_179","configSubflow-loading":"_configSubflow-loading_xgeh3_185"},DX=(t,e={})=>!(t!=null&&t.params)||Object.keys(t.params).length===0?[]:Object.entries(t.params).map(([n,r],o)=>({id:`${n}_${o}`,key:n,value:e[n]!==void 0?e[n]:r,exampleValue:r})),AX=t=>!!(t!=null&&t.params&&Object.keys(t.params).length>0),Y_=b.forwardRef(({value:t,onChange:e,disabled:n=!1,nodeId:r=""},o)=>{const[i,s]=b.useState(t==null?void 0:t.flowId),[a,l]=b.useState([]),[c,u]=b.useState([]),d=Ct(),h=n||!d,{data:p=[],loading:m,run:v}=dt.useRequest(Fy,{debounceWait:300}),w=p||[],y=b.useMemo(()=>w.find(I=>I.id===i),[w,i]);b.useEffect(()=>{(t==null?void 0:t.flowId)!==i&&s(t==null?void 0:t.flowId)},[t==null?void 0:t.flowId]),b.useEffect(()=>{if(y){const I=DX(y,t==null?void 0:t.input);l(I)}else l([])},[y,t==null?void 0:t.input]);const g=b.useCallback((I,P)=>{if(!I){e==null||e(void 0);return}e==null||e({flowId:I,input:P})},[e]),C=b.useCallback(I=>{s(I),u([]);const P=w.find(B=>B.id===I),_={};P!=null&&P.params&&Object.entries(P.params).forEach(([B,L])=>{_[B]=L}),g(I,_)},[w,g]),D=b.useCallback((I,P)=>{const _={...(t==null?void 0:t.input)||{}};_[I]=P,g(i,_),u(B=>B.filter(L=>!(L.type==="param"&&L.paramKey===I)))},[i,t==null?void 0:t.input,g]),k=b.useCallback((I,P)=>{P.stopPropagation(),P.preventDefault(),window.open(`/uc/link/ai-flow/edit?id=${I}`,"_blank")},[]),A=b.useCallback(()=>{const I=[];return i||I.push({type:"flow",message:"请选择子流程"}),y!=null&&y.params&&Object.keys(y.params).forEach(P=>{var B;const _=(B=t==null?void 0:t.input)==null?void 0:B[P];(_==null||_==="")&&I.push({type:"param",paramKey:P,message:`参数 "${P}" 不能为空`})}),u(I),I.length===0},[i,y,t==null?void 0:t.input]),S=b.useCallback(()=>{u([])},[]);b.useImperativeHandle(o,()=>({validate:A,clearErrors:S}),[A,S]);const E=()=>{var I;return(I=c.find(P=>P.type==="flow"))==null?void 0:I.message},T=I=>{var P;return(P=c.find(_=>_.type==="param"&&_.paramKey===I))==null?void 0:P.message},O=I=>f.jsxs("div",{className:Dt["configSubflow-optionContent"],children:[f.jsx("span",{className:Dt["configSubflow-optionName"],children:I.name}),f.jsx(x.Tooltip,{title:"在新标签页中打开子流程",children:f.jsx("span",{className:Dt["configSubflow-optionLink"],onClick:P=>k(I.id,P),children:f.jsx(Q.ExportOutlined,{})})})]}),F=()=>i?m?f.jsxs("div",{className:Dt["configSubflow-loading"],children:[f.jsx(x.Spin,{size:"small"}),f.jsx("span",{style:{marginLeft:8},children:"加载中..."})]}):AX(y)?f.jsx("div",{className:Dt["configSubflow-paramsList"],children:a.map(I=>{const P=T(I.key);return f.jsxs("div",{className:`${Dt["configSubflow-paramItem"]} ${P?Dt.hasError:""}`,children:[f.jsx("div",{className:Dt["configSubflow-paramKey"],children:f.jsx(x.Tooltip,{title:`示例值: ${I.exampleValue}`,children:f.jsx("div",{className:Dt["configSubflow-paramKeyLabel"],children:I.key})})}),f.jsxs("div",{className:Dt["configSubflow-paramValue"],children:[f.jsx(ir,{value:I.value,onChange:_=>D(I.key,_),placeholder:`示例: ${I.exampleValue}`,disabled:h,borrow:!0,nodeId:r,valueType:"ADAPTOR"}),P&&f.jsx("div",{className:Dt["configSubflow-errorText"],children:P})]})]},I.id)})}):f.jsxs("div",{className:`${Dt["configSubflow-hintMessage"]} ${Dt.info}`,children:[f.jsx(Q.InfoCircleOutlined,{}),f.jsx("span",{children:"该流程无需进行参数配置"})]}):f.jsxs("div",{className:`${Dt["configSubflow-hintMessage"]} ${Dt.warning}`,children:[f.jsx(Q.InfoCircleOutlined,{}),f.jsx("span",{children:"请先选择子流程"})]}),N=E();return f.jsxs("div",{className:Dt["configSubflow-container"],children:[f.jsxs("div",{className:Dt["configSubflow-selectSection"],children:[f.jsx("div",{className:Dt["configSubflow-selectWrapper"],children:f.jsx(x.Select,{className:Dt["configSubflow-select"],value:i,onChange:C,placeholder:"请选择子流程",disabled:h,loading:m,showSearch:!0,filterOption:!1,onSearch:v,notFoundContent:m?f.jsx(x.Spin,{size:"small"}):"暂无数据",allowClear:!0,status:N?"error":void 0,options:w.map(I=>({value:I.id,label:O(I)}))})}),N&&f.jsx("div",{className:Dt["configSubflow-errorText"],children:N})]}),f.jsxs("div",{className:Dt["configSubflow-paramsSection"],children:[f.jsxs("div",{className:Dt["configSubflow-paramsTitle"],children:[f.jsx(Q.SettingOutlined,{}),f.jsx("span",{children:"参数配置"})]}),F()]})]})});Y_.displayName="ConfigSubflow";function OX(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return b.useMemo(()=>r=>{e.forEach(o=>o(r))},e)}const Vd=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Bs(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function Fw(t){return"nodeType"in t}function Mn(t){var e,n;return t?Bs(t)?t:Fw(t)&&(e=(n=t.ownerDocument)==null?void 0:n.defaultView)!=null?e:window:window}function Iw(t){const{Document:e}=Mn(t);return t instanceof e}function fl(t){return Bs(t)?!1:t instanceof Mn(t).HTMLElement}function X_(t){return t instanceof Mn(t).SVGElement}function Fs(t){return t?Bs(t)?t.document:Fw(t)?Iw(t)?t:fl(t)||X_(t)?t.ownerDocument:document:document:document}const qr=Vd?b.useLayoutEffect:b.useEffect;function Mw(t){const e=b.useRef(t);return qr(()=>{e.current=t}),b.useCallback(function(){for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return e.current==null?void 0:e.current(...r)},[])}function _X(){const t=b.useRef(null),e=b.useCallback((r,o)=>{t.current=setInterval(r,o)},[]),n=b.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,n]}function hl(t,e){e===void 0&&(e=[t]);const n=b.useRef(t);return qr(()=>{n.current!==t&&(n.current=t)},e),n}function pl(t,e){const n=b.useRef();return b.useMemo(()=>{const r=t(n.current);return n.current=r,r},[...e])}function jd(t){const e=Mw(t),n=b.useRef(null),r=b.useCallback(o=>{o!==n.current&&(e==null||e(o,n.current)),n.current=o},[]);return[n,r]}function Pw(t){const e=b.useRef();return b.useEffect(()=>{e.current=t},[t]),e.current}let Lw={};function ml(t,e){return b.useMemo(()=>{if(e)return e;const n=Lw[t]==null?0:Lw[t]+1;return Lw[t]=n,t+"-"+n},[t,e])}function J_(t){return function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.reduce((i,s)=>{const a=Object.entries(s);for(const[l,c]of a){const u=i[l];u!=null&&(i[l]=u+t*c)}return i},{...e})}}const Is=J_(1),gl=J_(-1);function TX(t){return"clientX"in t&&"clientY"in t}function $w(t){if(!t)return!1;const{KeyboardEvent:e}=Mn(t.target);return e&&t instanceof e}function NX(t){if(!t)return!1;const{TouchEvent:e}=Mn(t.target);return e&&t instanceof e}function zw(t){if(NX(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:n}=t.touches[0];return{x:e,y:n}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:n}=t.changedTouches[0];return{x:e,y:n}}}return TX(t)?{x:t.clientX,y:t.clientY}:null}const wl=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:n}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:n}=t;return"scaleX("+e+") scaleY("+n+")"}},Transform:{toString(t){if(t)return[wl.Translate.toString(t),wl.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:n,easing:r}=t;return e+" "+n+"ms "+r}}}),R_="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function BX(t){return t.matches(R_)?t:t.querySelector(R_)}const FX={display:"none"};function IX(t){let{id:e,value:n}=t;return b.createElement("div",{id:e,style:FX},n)}function MX(t){let{id:e,announcement:n,ariaLiveType:r="assertive"}=t;const o={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return b.createElement("div",{id:e,style:o,role:"status","aria-live":r,"aria-atomic":!0},n)}function PX(){const[t,e]=b.useState("");return{announce:b.useCallback(r=>{r!=null&&e(r)},[]),announcement:t}}const Q_=b.createContext(null);function LX(t){const e=b.useContext(Q_);b.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of <DndContext>");return e(t)},[t,e])}function $X(){const[t]=b.useState(()=>new Set),e=b.useCallback(r=>(t.add(r),()=>t.delete(r)),[t]);return[b.useCallback(r=>{let{type:o,event:i}=r;t.forEach(s=>{var a;return(a=s[o])==null?void 0:a.call(s,i)})},[t]),e]}const zX={draggable:`
103
103
  To pick up a draggable item, press the space bar.
104
104
  While dragging, use the arrow keys to move the item.
105
105
  Press space again to drop the item in its new position, or press escape to cancel.