@huanban/rulego-editor-react 1.4.2 → 2.1.0

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/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),ca=require("react-dom"),v=require("@huanban/rulego-editor-core");function an(t){return Object.fromEntries(Object.entries(t).filter(([,n])=>n!==void 0))}function Or(t){return Array.isArray(t)?t.length>0:!!t}const Hn=["onAuthExpired","onApiAuthRequired","clearToken","onSettingsClick","onSettingsSubmit","onLoginClick","onSaveConflict","onRestartConfirm"],ar=["onReady","onSave","saveHandler","onSaveRequest","onSaveSuccess","onSaveError","onExternalDataConflict","onNodeClick","onNodeDbClick","onEdgeClick","onChange","onInfoClick","onExportDSL","onImportDSL","onRunClick","onTraceClick","onComponentManage","onLocaleChange","onDeploy","onRestart","onSelectRuleChain","onDeleteRuleChain","onRunHistory"];function dr(t,n,r=new WeakMap){if(Object.is(t,n))return!0;if(typeof t=="function"||typeof n=="function")return typeof t=="function"&&typeof n=="function";if(typeof t!="object"||t===null||typeof n!="object"||n===null)return!1;const o=r.get(t);if(o)return o===n;if(r.set(t,n),Array.isArray(t)||Array.isArray(n))return!Array.isArray(t)||!Array.isArray(n)||t.length!==n.length?!1:t.every((m,f)=>dr(m,n[f],r));const s=Object.keys(t),i=Object.keys(n);return s.length!==i.length?!1:s.every(m=>Object.prototype.hasOwnProperty.call(n,m)&&dr(t[m],n[m],r))}function co(t,n){if(!t)return!1;const r=Object.keys(t),o=Object.keys(n);return r.length!==o.length?!1:o.every(s=>Object.prototype.hasOwnProperty.call(t,s)&&(s==="customFetch"||s==="fetchHeaders"?Object.is(t[s],n[s]):dr(t[s],n[s])))}const ia=e.forwardRef(function(n,r){const{height:o="100%",width:s="100%",className:i,style:m,apiBase:f,fetchTimeout:M,fetchHeaders:N,apiCacheKey:P,customFetch:g,data:w,dataUpdatePolicy:y,components:k,enableConnectionStatus:F,onConnectionStatusChange:j,mode:O,capabilities:U,disabled:C,showToolbar:I,toolbarTitle:D,showToolbarButtonLabels:_,toolbarIconOnly:u,showSidebar:Z,sidebarWidth:ee,sidebarCollapsed:H,showInfoButton:V,showAiChatButton:me,showSettingsButton:q,showDebugConsoleButton:le,showDiagnosticsButton:ue,showClearDebugHighlightButton:W,showSelectionButton:ge,showExportDialog:Pe,showRunButton:Me,showComponentManage:X,showDeployButton:b,showRestartButton:$,showReloadButton:Y,showRunHistory:te,runHistoryUrl:L,showTraceButton:ke,showDebugTab:we,locale:ne,theme:he,lfOptions:xe,lfPlugins:Ee,coreOptions:Le,options:Se,onReady:se,onSave:ae,saveMode:Ne,saveHandler:_e,onSaveSuccess:J,onSaveError:Ae,onExternalDataConflict:tt,onNodeClick:z,onNodeDbClick:Ye,onEdgeClick:ht,onChange:mt,onInfoClick:Vt,onExportDSL:Bt,onImportDSL:jt,onRunClick:Pt,onTraceClick:Nt,onComponentManage:lt,onLocaleChange:vt,onDeploy:xt,onRestart:Lt,onSelectRuleChain:Tt,onDeleteRuleChain:Ke,onRunHistory:Rt,ruleItems:At,rulesApi:Mt,renderNode:Ot}=n,Ct=e.useRef(null),Te=e.useRef(null),[qt,gt]=e.useState([]),je=e.useRef({onSave:ae,saveHandler:_e,onSaveSuccess:J,onSaveError:Ae,onExternalDataConflict:tt,onReady:se,onNodeClick:z,onNodeDbClick:Ye,onEdgeClick:ht,onChange:mt,onInfoClick:Vt,onExportDSL:Bt,onImportDSL:jt,onRunClick:Pt,onTraceClick:Nt,onComponentManage:lt,onLocaleChange:vt,onDeploy:xt,onRestart:Lt,onSelectRuleChain:Tt,onDeleteRuleChain:Ke,onRunHistory:Rt}),nt=e.useRef(j);nt.current=j;const Re=e.useRef(Se),re=e.useRef({onAuthExpired:h=>{var S,K;return(K=(S=Re.current)==null?void 0:S.onAuthExpired)==null?void 0:K.call(S,h)},onApiAuthRequired:h=>{var S,K;return(K=(S=Re.current)==null?void 0:S.onApiAuthRequired)==null?void 0:K.call(S,h)},clearToken:()=>{var h,S;return(S=(h=Re.current)==null?void 0:h.clearToken)==null?void 0:S.call(h)},onSettingsClick:h=>{var S,K;return(K=(S=Re.current)==null?void 0:S.onSettingsClick)==null?void 0:K.call(S,h)},onSettingsSubmit:h=>{var S,K;return(K=(S=Re.current)==null?void 0:S.onSettingsSubmit)==null?void 0:K.call(S,h)},onLoginClick:()=>{var h,S;return(S=(h=Re.current)==null?void 0:h.onLoginClick)==null?void 0:S.call(h)},onSaveConflict:h=>{var S,K;return(K=(S=Re.current)==null?void 0:S.onSaveConflict)==null?void 0:K.call(S,h)},onRestartConfirm:h=>{var S,K;return(K=(S=Re.current)==null?void 0:S.onRestartConfirm)==null?void 0:K.call(S,h)}}),fe=e.useRef({}),Ce=e.useRef({}),ye=e.useRef({}),De=e.useRef({}),qe=e.useRef(null);e.useEffect(()=>{Re.current=Se;const h=fe.current,S={};Hn.forEach(oe=>{S[oe]=typeof(Se==null?void 0:Se[oe])=="function"}),Ce.current=h,fe.current=S;const K=ye.current,A={};ar.forEach(oe=>{A[oe]=typeof n[oe]=="function"||typeof(Se==null?void 0:Se[oe])=="function"}),De.current=K,ye.current=A,je.current={onSave:ae,saveHandler:_e,onSaveSuccess:J,onSaveError:Ae,onExternalDataConflict:tt,onReady:se,onNodeClick:z,onNodeDbClick:Ye,onEdgeClick:ht,onChange:mt,onInfoClick:Vt,onExportDSL:Bt,onImportDSL:jt,onRunClick:Pt,onTraceClick:Nt,onComponentManage:lt,onLocaleChange:vt,onDeploy:xt,onRestart:Lt,onSelectRuleChain:Tt,onDeleteRuleChain:Ke,onRunHistory:Rt}});const d=e.useRef({request:h=>{var S,K,A,oe;(K=(S=je.current).onSave)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onSaveRequest)==null||oe.call(A,h)},handler:h=>{var K,A;const S=je.current.saveHandler;return S?S(h):(A=(K=Re.current)==null?void 0:K.saveHandler)==null?void 0:A.call(K,h)},legacyHandler:h=>{var S,K;return(K=(S=Re.current)==null?void 0:S.onSave)==null?void 0:K.call(S,h)},success:h=>{var S,K,A,oe;(K=(S=je.current).onSaveSuccess)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onSaveSuccess)==null||oe.call(A,h)},error:h=>{var S,K,A,oe;(K=(S=je.current).onSaveError)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onSaveError)==null||oe.call(A,h)},conflict:h=>{var S,K,A,oe;(K=(S=je.current).onExternalDataConflict)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onExternalDataConflict)==null||oe.call(A,h)}}),ie=e.useRef({onReady:h=>{var S,K,A,oe;(K=(S=je.current).onReady)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onReady)==null||oe.call(A,h)},onSave:d.current.legacyHandler,saveHandler:d.current.handler,onSaveRequest:d.current.request,onSaveSuccess:d.current.success,onSaveError:d.current.error,onExternalDataConflict:d.current.conflict,onNodeClick:h=>{var S,K,A,oe;(K=(S=je.current).onNodeClick)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onNodeClick)==null||oe.call(A,h)},onNodeDbClick:h=>{var S,K,A,oe;(K=(S=je.current).onNodeDbClick)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onNodeDbClick)==null||oe.call(A,h)},onEdgeClick:h=>{var S,K,A,oe;(K=(S=je.current).onEdgeClick)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onEdgeClick)==null||oe.call(A,h)},onChange:()=>{var h,S,K,A;(S=(h=je.current).onChange)==null||S.call(h),(A=(K=Re.current)==null?void 0:K.onChange)==null||A.call(K)},onInfoClick:h=>{var S,K,A,oe;(K=(S=je.current).onInfoClick)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onInfoClick)==null||oe.call(A,h)},onExportDSL:h=>{var S,K,A,oe;(K=(S=je.current).onExportDSL)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onExportDSL)==null||oe.call(A,h)},onImportDSL:h=>{var S,K,A,oe;(K=(S=je.current).onImportDSL)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onImportDSL)==null||oe.call(A,h)},onRunClick:h=>{var S,K,A,oe;(K=(S=je.current).onRunClick)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onRunClick)==null||oe.call(A,h)},onTraceClick:h=>{var S,K,A,oe;(K=(S=je.current).onTraceClick)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onTraceClick)==null||oe.call(A,h)},onComponentManage:h=>{var S,K,A,oe;(K=(S=je.current).onComponentManage)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onComponentManage)==null||oe.call(A,h)},onLocaleChange:h=>{var S,K,A,oe;(K=(S=je.current).onLocaleChange)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onLocaleChange)==null||oe.call(A,h)},onDeploy:(h,S)=>{var oe,Oe,rt,Xe;const K=(Oe=(oe=je.current).onDeploy)==null?void 0:Oe.call(oe,h,S),A=(Xe=(rt=Re.current)==null?void 0:rt.onDeploy)==null?void 0:Xe.call(rt,h,S);return K!==void 0?K:A},onRestart:h=>{var A,oe,Oe,rt;const S=(oe=(A=je.current).onRestart)==null?void 0:oe.call(A,h),K=(rt=(Oe=Re.current)==null?void 0:Oe.onRestart)==null?void 0:rt.call(Oe,h);return S!==void 0?S:K},onSelectRuleChain:h=>{var S,K,A,oe;(K=(S=je.current).onSelectRuleChain)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onSelectRuleChain)==null||oe.call(A,h)},onDeleteRuleChain:h=>{var S,K,A,oe;(K=(S=je.current).onDeleteRuleChain)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onDeleteRuleChain)==null||oe.call(A,h)},onRunHistory:h=>{var S,K,A,oe;(K=(S=je.current).onRunHistory)==null||K.call(S,h),(oe=(A=Re.current)==null?void 0:A.onRunHistory)==null||oe.call(A,h)}});e.useEffect(()=>{var Ht;if(!Ct.current)return;const h=!!(_e||Se!=null&&Se.saveHandler),S=!h&&typeof(Se==null?void 0:Se.onSave)=="function",K={...(()=>{const He={...Se};return Hn.forEach(ut=>{typeof He[ut]=="function"&&(He[ut]=re.current[ut])}),He})(),container:Ct.current,...an({apiBase:f,fetchTimeout:M,fetchHeaders:N,apiCacheKey:P,customFetch:g,data:w??void 0,components:Or(k)?k:void 0,dataUpdatePolicy:y,enableConnectionStatus:F}),...an({mode:O,capabilities:U,disabled:C,showToolbar:I,toolbarTitle:D,showToolbarButtonLabels:_,toolbarIconOnly:u,showSidebar:Z,sidebarWidth:ee,sidebarCollapsed:H,showInfoButton:V,showAiChatButton:me,showSettingsButton:q,showDebugConsoleButton:le,showDiagnosticsButton:ue,showClearDebugHighlightButton:W,showSelectionButton:ge,showExportDialog:Pe,showRunButton:Me,showComponentManage:X,showDeployButton:b,showRestartButton:$,showReloadButton:Y,showRunHistory:te,runHistoryUrl:L,showTraceButton:ke,showDebugTab:we}),...an({locale:ne,theme:he}),...an({lfOptions:xe,lfPlugins:Ee,coreOptions:Le}),...an({ruleItems:At,rulesApi:Mt}),onReady:ie.current.onReady,...an({saveMode:Ne??(Se==null?void 0:Se.saveMode),saveHandler:h?d.current.handler:void 0,onSave:S?d.current.legacyHandler:void 0,onSaveRequest:d.current.request,onSaveSuccess:d.current.success,onSaveError:d.current.error,onExternalDataConflict:d.current.conflict}),onNodeClick:ie.current.onNodeClick,onNodeDbClick:ie.current.onNodeDbClick,onEdgeClick:ie.current.onEdgeClick,onChange:ie.current.onChange,onInfoClick:ye.current.onInfoClick?ie.current.onInfoClick:void 0,onExportDSL:ye.current.onExportDSL?ie.current.onExportDSL:void 0,onImportDSL:ye.current.onImportDSL?ie.current.onImportDSL:void 0,onRunClick:ye.current.onRunClick?ie.current.onRunClick:void 0,onTraceClick:ye.current.onTraceClick?ie.current.onTraceClick:void 0,onComponentManage:ye.current.onComponentManage?ie.current.onComponentManage:void 0,onLocaleChange:ie.current.onLocaleChange,onDeploy:ye.current.onDeploy?ie.current.onDeploy:void 0,onRestart:ye.current.onRestart?ie.current.onRestart:void 0,onSelectRuleChain:ie.current.onSelectRuleChain,onDeleteRuleChain:ie.current.onDeleteRuleChain,onRunHistory:ye.current.onRunHistory?ie.current.onRunHistory:void 0},A=new v.HuanbanRulegoEditor(K);Te.current=A,qe.current=null;const oe=A.connectionStatus.subscribe(He=>{var ut;(ut=nt.current)==null||ut.call(nt,He)});(Ht=nt.current)==null||Ht.call(nt,A.connectionStatus.getState());let Oe=null;const rt=setTimeout(()=>{Oe=requestAnimationFrame(()=>{if(Oe=null,A.lf&&Ct.current){const{clientWidth:He,clientHeight:ut}=Ct.current;if(He>0&&ut>0)try{A.lf.resize(He,ut)}catch{}}})},100),Xe=He=>{gt(ut=>{const st=ut.findIndex(Ue=>Ue.id===He.id),Ft={...He};if(st>=0){const Ue=[...ut];return Ue[st]=Ft,Ue}return[...ut,Ft]})},wt=He=>{gt(ut=>ut.filter(st=>st.id!==He.id))};return A.core&&(A.core.eventBus.on("node:html-mount",Xe),A.core.eventBus.on("node:html-unmount",wt)),()=>{A.core&&(A.core.eventBus.off("node:html-mount",Xe),A.core.eventBus.off("node:html-unmount",wt)),clearTimeout(rt),Oe!==null&&(cancelAnimationFrame(Oe),Oe=null),oe(),A.destroy(),Te.current=null}},[]),e.useEffect(()=>{var Xe,wt,Ht;const h=Te.current;if(!h)return;const S={...Re.current||{}};delete S.container,delete S.data,delete S.components,delete S.lfOptions,delete S.lfPlugins,delete S.persistence,ar.forEach(He=>{delete S[He]}),Hn.forEach(He=>{delete S[He]});const K=!!(_e||(Xe=Re.current)!=null&&Xe.saveHandler),A=!K&&typeof((wt=Re.current)==null?void 0:wt.onSave)=="function",oe={};Hn.forEach(He=>{fe.current[He]?oe[He]=re.current[He]:Ce.current[He]&&(oe[He]=void 0)});const Oe={};ar.forEach(He=>{ye.current[He]?Oe[He]=ie.current[He]:De.current[He]&&(Oe[He]=void 0)});const rt={...S,...an({apiBase:f,fetchTimeout:M,fetchHeaders:N,apiCacheKey:P,customFetch:g,dataUpdatePolicy:y,enableConnectionStatus:F,mode:O,capabilities:U,disabled:C,showToolbar:I,toolbarTitle:D,showToolbarButtonLabels:_,toolbarIconOnly:u,showSidebar:Z,sidebarWidth:ee,sidebarCollapsed:H,showInfoButton:V,showAiChatButton:me,showSettingsButton:q,showDebugConsoleButton:le,showDiagnosticsButton:ue,showClearDebugHighlightButton:W,showSelectionButton:ge,showExportDialog:Pe,showRunButton:Me,showComponentManage:X,showDeployButton:b,showRestartButton:$,showReloadButton:Y,showRunHistory:te,runHistoryUrl:L,showTraceButton:ke,showDebugTab:we,locale:ne,theme:he,coreOptions:Le,ruleItems:At,rulesApi:Mt,saveMode:Ne??((Ht=Re.current)==null?void 0:Ht.saveMode)}),...oe,...Oe,saveHandler:K?d.current.handler:void 0,onSave:A?d.current.legacyHandler:void 0,onSaveRequest:d.current.request,onSaveSuccess:d.current.success,onSaveError:d.current.error,onExternalDataConflict:d.current.conflict};co(qe.current,rt)||(qe.current=rt,h.updateOptions(rt))}),e.useEffect(()=>{he&&Te.current&&Te.current.setTheme(he)},[he]),e.useEffect(()=>{w&&Te.current&&Te.current.updateOptions({data:w})},[w]),e.useEffect(()=>{Or(k)&&Te.current&&Te.current.updateOptions({components:k})},[k]),e.useImperativeHandle(r,()=>({get editor(){return Te.current},get lf(){var h;return((h=Te.current)==null?void 0:h.lf)??null},get core(){var h;return((h=Te.current)==null?void 0:h.core)??null},get capabilities(){var h;return((h=Te.current)==null?void 0:h.capabilities)??null},get connectionStatus(){var h;return((h=Te.current)==null?void 0:h.connectionStatus)??null},get runtimeFields(){var h;return((h=Te.current)==null?void 0:h.runtimeFields)??null},loadData(h,S){var K;(K=Te.current)==null||K.loadData(h,S)},activateWorkspaceTab(h){var S;return((S=Te.current)==null?void 0:S.activateWorkspaceTab(h))??!1},loadComponents(h){var S;(S=Te.current)==null||S.loadComponents(h)},exportData(){var h;return((h=Te.current)==null?void 0:h.exportData())??null},toggleMiniMap(){var h;(h=Te.current)==null||h.toggleMiniMap()},autoLayout(){var h;(h=Te.current)==null||h.autoLayout()},openSettings(h="user"){var S;(S=Te.current)==null||S.openSettings(h)},openAiAssistant(h){var S;(S=Te.current)==null||S.openAiAssistant(h)},closeAiAssistant(){var h;(h=Te.current)==null||h.closeAiAssistant()},startTour(){var h;return((h=Te.current)==null?void 0:h.startTour())??!1},closeTour(){var h;(h=Te.current)==null||h.closeTour()},setTheme(h){var S;(S=Te.current)==null||S.setTheme(h)},updateOptions(h){var S;return((S=Te.current)==null?void 0:S.updateOptions(h))??null},refreshConnectionStatuses(){var h;(h=Te.current)==null||h.refreshConnectionStatuses()},acquireSharedConnectionStatuses(){var h;return((h=Te.current)==null?void 0:h.acquireSharedConnectionStatuses())??(()=>{})},invokeAction(h,S="api"){const K=Te.current;return K?K.invokeAction(h,S):Promise.reject(new Error("Editor is not ready"))},openCommandPalette(){var h;(h=Te.current)==null||h.openCommandPalette()},openShortcutHelp(){var h;(h=Te.current)==null||h.openShortcutHelp()},openNodePicker(h){var S;(S=Te.current)==null||S.openNodePicker(h)},openComponentDocs(h){const S=Te.current;return S?S.openComponentDocs(h):Promise.reject(new Error("Editor is not ready"))},openComponentManager(h="installed"){var S;(S=Te.current)==null||S.openComponentManager(h)},closeOverlay(){var h;(h=Te.current)==null||h.closeOverlay()},closeAllOverlays(){var h;(h=Te.current)==null||h.closeAllOverlays()}}),[]);const Fe=v.normalizeEditorTheme(he||(Se==null?void 0:Se.theme)),ft={...v.getThemeRuntimeVariables(Fe),width:typeof s=="number"?`${s}px`:s,height:typeof o=="number"?`${o}px`:o,position:"relative",overflow:"hidden",...m};return e.createElement(e.Fragment,null,e.createElement("div",{ref:Ct,className:`rulego-editor-wrapper ${i||""}`,"data-theme":Fe,"data-rg-theme":Fe,style:ft}),Ot&&qt.map(h=>ca.createPortal(Ot(h.type,h.data,h.model),h.el)))});ia.displayName="RuleGoEditor";function io(t,n){if(!t)return!1;let r=t;for(const o of n.split(".")){if(!r||typeof r!="object")return!1;r=r[o]}return typeof r=="string"}function vr(t){const n=String(t||"").toLowerCase().replace("_","-");return n==="en"||n.startsWith("en-")?"en-US":"zh-CN"}function ua(t,n,r){if(!t)return;const o=t(n,r);return o&&o!==n?o:void 0}function Ze(t={}){const n=vr(t.locale),r=new v.I18nManager({locale:n,fallback:n==="en-US"?"zh-CN":"en-US"});return r.register("zh-CN",v.localeZhCN),r.register("en-US",v.localeEnUS),t.messages&&r.register(n,t.messages),(o,s="",i)=>{const m=ua(t.t,o,i);if(m!==void 0)return m;const f=r.t(o,i);return f&&f!==o?f:s||o}}function uo(t,n,r,o){const s=String(t.name||"").trim(),i=`fields.${s}`,m=ua(r,i);if(m!==void 0)return m;if(io(o,i)){const f=n(i,t.label||s);if(f&&f!==i)return f}return t.label?t.label:n(i,s)}function pr(t,n){const r=t(`relationTypes.${n}`,n);return r&&r!==n?`${r} (${n})`:n}const fn={endpoint:{label:"输入端",bg:"#A6BBCF",icon:"images/endpoint-dark.svg",nodeIcon:"images/endpoint.svg"},common:{label:"公共",bg:"#D1D5DB",icon:"images/common-dark.svg",nodeIcon:"images/common.svg"},filter:{label:"过滤器",bg:"#f1e861",icon:"images/filter-dark.svg",nodeIcon:"images/filter.svg"},transform:{label:"转换器",bg:"#79cef1",icon:"images/transform-dark.svg",nodeIcon:"images/transform.svg"},action:{label:"动作",bg:"#f1928f",icon:"images/action-dark.svg",nodeIcon:"images/action.svg"},external:{label:"外部的",bg:"#fbc766",icon:"images/external-dark.svg",nodeIcon:"images/external.svg"},ai:{label:"AI",bg:"#7cbaf8",icon:"images/ai-dark.svg",nodeIcon:"images/ai.svg"},discovery:{label:"服务发现",bg:"#7ee0c0",icon:"images/discovery-dark.svg",nodeIcon:"images/discovery.svg"},knowledge:{label:"知识库",bg:"#D1C4E9",icon:"images/knowledge-dark.svg",nodeIcon:"images/knowledge.svg"},ci:{label:"CI/CD",bg:"#9ec9c9",icon:"images/ci-dark.svg",nodeIcon:"images/ci.svg"},iot:{label:"IoT",bg:"#FFA500",icon:"images/iot-dark.svg",nodeIcon:"images/iot.svg"},flow:{label:"子规则链",bg:"#E6E0F8",icon:"images/flow-dark.svg",nodeIcon:"images/flow.svg"},stats:{label:"流式计算",bg:"#f1cfbd",icon:"images/stats-dark.svg",nodeIcon:"images/stats.svg"},storage:{label:"存储",bg:"#b2d8d8",icon:"images/storage-dark.svg",nodeIcon:"images/storage.svg"},image:{label:"图像",bg:"#f6c6d8",icon:"images/image-dark.svg",nodeIcon:"images/image.svg"},audio:{label:"音频",bg:"#c7d2fe",icon:"images/audio-dark.svg",nodeIcon:"images/audio.svg"},file:{label:"文件",bg:"#ffe5b4",icon:"images/file-dark.svg",nodeIcon:"images/file.svg"},custom:{label:"自定义",bg:"#C6EFCB",icon:"images/custom-dark.svg",nodeIcon:"images/custom.svg"},other:{label:"其他",bg:"#86B4E5",icon:"images/other-dark.svg",nodeIcon:"images/other.svg"}};function mo(t,n,r,o){const s=t.map(i=>({...i,category:i.category||"other",categoryPath:i.categoryPath||i.category||"other",label:i.label||i.type.split("/").pop()||i.type,desc:i.desc||"",icon:i.icon||"",fields:i.fields||null,relationTypes:Array.isArray(i.relationTypes)?i.relationTypes:[],color:typeof i.background=="string"?i.background:void 0}));return v.buildComponentPalette(s,o,{categoryOrder:v.DEFAULT_COMPONENT_CATEGORY_ORDER,categoryLabel:i=>{const m=fn[i]||(i==="endpoints"?fn.endpoint:fn.other);return n(`category.${i}`,m.label)},subgroupLabel:(i,m)=>n(`category.${i}.${m}`,m),componentSearchText:i=>[n(`components.${i.type}`,i.label),n(`fields.${i.type}`,i.desc)]}).map(i=>{const m=fn[i.category]||(i.category==="endpoints"?fn.endpoint:fn.other);return{category:i.category,label:i.label,background:m.bg,iconUrl:v.resolveIconUrl(m.icon,{theme:r}),nodeIconUrl:v.resolveIconUrl(m.nodeIcon,{theme:r}),components:i.components,subgroups:i.subgroups.map(f=>({...f,components:f.components}))}})}const ma=({components:t,onDragStart:n,recentComponentTypes:r=[],collapsed:o=!1,searchPlaceholder:s,locale:i,messages:m,t:f,theme:M="default",virtualization:N})=>{const P=v.normalizeIconTheme(M),[g,w]=e.useState(""),[y,k]=e.useState(new Set),[F,j]=e.useState(new Set),[O,U]=e.useState({}),C=e.useMemo(()=>Ze({locale:i,messages:m,t:f}),[i,m,f]),I=e.useMemo(()=>mo(t,C,P,g),[t,P,g,C]),D=s||C("editor.sidebar.search","搜索组件..."),_=g.trim().length>0,u=I.map(X=>X.category),Z=I.flatMap(X=>X.subgroups.filter(b=>!!b.id).map(b=>`${X.category}/${b.id||"default"}`));e.useEffect(()=>{_&&(k(X=>{const b=new Set(X);return u.forEach($=>b.add($)),b}),j(X=>{const b=new Set(X);return Z.forEach($=>b.delete($)),b}))},[_,u.join("|"),Z.join("|")]);const ee=e.useMemo(()=>{if(g.trim())return[];const X=new Map(t.map(b=>[b.type,b]));return r.map(b=>X.get(b)).filter(b=>b!=null&&(b==null?void 0:b.disabled)!==!0)},[t,r,g]),H=u.length>0&&u.every(X=>y.has(X)),V=X=>C(`components.${X.type}`,X.label||X.type.split("/").pop()||X.type),me=X=>C(`fields.${X.type}`,X.desc||""),q=(X,b)=>X.icon?v.resolveIconUrl(String(X.icon),{theme:P}):b.nodeIconUrl,le={enabled:(N==null?void 0:N.enabled)!==!1,threshold:Math.max(1,(N==null?void 0:N.threshold)??v.DEFAULT_VIRTUAL_WINDOW_THRESHOLD),itemHeight:Math.max(1,(N==null?void 0:N.itemHeight)??v.DEFAULT_VIRTUAL_WINDOW_ITEM_HEIGHT),viewportHeight:Math.max(1,(N==null?void 0:N.viewportHeight)??v.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),overscan:Math.max(0,(N==null?void 0:N.overscan)??v.DEFAULT_VIRTUAL_WINDOW_OVERSCAN)},ue=(X,b,$)=>{if(!(le.enabled&&X.length>le.threshold))return X.map($);const te=v.calculateVirtualWindow({total:X.length,itemHeight:le.itemHeight,viewportHeight:le.viewportHeight,scrollTop:O[b]||0,overscan:le.overscan});return e.createElement("div",{className:"rge-sidebar-virtual-list","data-sidebar-virtualized":"true","data-sidebar-virtual-key":b,"data-sidebar-virtual-total":X.length,style:{height:`${te.viewportHeight}px`},onScroll:L=>{const ke=L.currentTarget.scrollTop;U(we=>we[b]===ke?we:{...we,[b]:ke})}},e.createElement("div",{className:"rge-sidebar-virtual-list__canvas",style:{height:`${te.totalHeight}px`}},e.createElement("div",{className:"rge-sidebar-virtual-list__items",style:{transform:`translateY(${te.offsetTop}px)`}},X.slice(te.start,te.end).map($))))},W=X=>{k(b=>{const $=new Set(b);return $.has(X)?$.delete(X):$.add(X),$})},ge=X=>{j(b=>{const $=new Set(b);return $.has(X)?$.delete(X):$.add(X),$})},Pe=()=>{if(u.length!==0){if(H){k(new Set),j(new Set);return}k(new Set(u)),j(new Set)}},Me=(X,b)=>{X.dataTransfer.setData("application/json",JSON.stringify(b)),X.dataTransfer.effectAllowed="move",n==null||n(b)};return o?null:e.createElement("div",{className:"rge-component-sidebar","data-theme":P,"data-rg-theme":P,style:v.getThemeRuntimeVariables(P)},e.createElement("div",{className:"rge-sidebar-search"},e.createElement("span",{className:"rge-search-icon","aria-hidden":"true"}),e.createElement("input",{type:"text",placeholder:D,value:g,onChange:X=>w(X.target.value),className:"rge-search-input"}),e.createElement("button",{type:"button",className:"rge-sidebar-toggle-all","data-sidebar-toggle":"all",title:C(H?"editor.sidebar.collapseAll":"editor.sidebar.expandAll",H?"全部折叠":"全部展开"),"aria-label":C(H?"editor.sidebar.collapseAll":"editor.sidebar.expandAll",H?"全部折叠":"全部展开"),"aria-pressed":H,disabled:u.length===0,onClick:Pe},H?"↙":"↗")),e.createElement("div",{className:"rge-sidebar-groups"},ee.length>0&&e.createElement("section",{className:"rge-sidebar-group rge-sidebar-recent","data-sidebar-recent":"true"},e.createElement("div",{className:"rge-group-header expanded",role:"heading","aria-level":2},e.createElement("span",{className:"rge-group-icon","aria-hidden":"true"},"★"),e.createElement("span",{className:"rge-group-label"},C("editor.sidebar.recentComponents","最近使用")),e.createElement("span",{className:"rge-group-count"},ee.length)),e.createElement("div",{className:"rge-group-content"},ee.map(X=>{const b=I.find(te=>te.components.some(L=>L.type===X.type));if(!b)return null;const $=V(X),Y=me(X);return e.createElement("div",{key:X.type,className:"rge-node-block",draggable:!0,onDragStart:te=>Me(te,X),style:{backgroundColor:X.background||b.background},title:`${X.type}
2
- ${Y||$}`},e.createElement("div",{className:"rge-node-block__icon"},e.createElement("img",{src:q(X,b),alt:"",className:"rge-node-block__icon-img"})),e.createElement("span",{className:"rge-node-block__label"},$),!X.notInput&&e.createElement("span",{className:"rge-node-block__port rge-node-block__port--input"}),!X.notOutput&&e.createElement("span",{className:"rge-node-block__port rge-node-block__port--output"}))}))),I.map(X=>{const b=X.category,$=y.has(b),Y=X.subgroups.some(L=>!!L.id),te=L=>{const ke=L.background||X.background,we=V(L),ne=me(L),he=q(L,X);return e.createElement("div",{key:L.type,className:"rge-node-block",draggable:!0,onDragStart:xe=>Me(xe,L),style:{backgroundColor:ke},title:`${L.type}
3
- ${ne||we}`},e.createElement("div",{className:"rge-node-block__icon"},e.createElement("img",{src:he,alt:"",className:"rge-node-block__icon-img"})),e.createElement("span",{className:"rge-node-block__label"},we),!L.notInput&&e.createElement("span",{className:"rge-node-block__port rge-node-block__port--input"}),!L.notOutput&&e.createElement("span",{className:"rge-node-block__port rge-node-block__port--output"}))};return e.createElement("div",{key:b,className:"rge-sidebar-group"},e.createElement("button",{type:"button",className:`rge-group-header ${$?"expanded":""}`,onClick:()=>W(b),"aria-expanded":$},e.createElement("span",{className:"rge-group-icon"},e.createElement("img",{src:X.iconUrl,alt:"",className:"rge-group-icon-img"})),e.createElement("span",{className:"rge-group-label"},X.label),e.createElement("span",{className:"rge-group-count"},X.components.length),e.createElement("span",{className:`rge-group-arrow ${$?"rotated":""}`},"›")),$&&e.createElement("div",{className:"rge-group-content"},!Y&&ue(X.components,b,te),Y&&X.subgroups.map(L=>{const ke=`${b}/${L.id||"default"}`,we=!F.has(ke);return e.createElement("section",{key:ke,className:"rge-sidebar-subgroup"},e.createElement("button",{type:"button",className:"rge-subgroup-header",onClick:()=>ge(ke),"aria-expanded":we,title:L.description||L.label},e.createElement("span",{className:`rge-subgroup-arrow ${we?"rotated":""}`},"›"),e.createElement("span",null,L.label),e.createElement("small",null,L.components.length)),we&&e.createElement("div",{className:"rge-subgroup-content"},ue(L.components,ke,te)))})))}),I.length===0&&e.createElement("div",{className:"rge-sidebar-empty"},e.createElement("img",{src:v.resolveIconUrl("images/common.svg",{theme:P}),alt:"",className:"rge-empty-icon"}),e.createElement("p",null,C("editor.sidebar.noResult","未找到匹配的组件")))))};ma.displayName="ComponentSidebar";const po=12,Fr=80;function go(t){return{label:String((t==null?void 0:t.label)??(t==null?void 0:t.value)??""),value:String((t==null?void 0:t.value)??""),description:t!=null&&t.description?String(t.description):void 0}}function Br(t,n){return t.replace(/\{\{\s*(\w+)\s*\}\}|\{(\w+)\}/g,(r,o,s)=>{const i=o||s;return Object.prototype.hasOwnProperty.call(n,i)?String(n[i]):""})}const zt=({name:t,value:n="",values:r,options:o=[],multiple:s=!1,allowCreate:i=!1,disabled:m=!1,placeholder:f="",searchPlaceholder:M="搜索选项...",noMatchText:N="没有匹配的选项",createOptionText:P="使用",selectedCountText:g="已选 {{count}} 项",resultCountText:w="显示 {{shown}} / {{total}} 项",moreOptionsText:y="结果较多,请继续输入关键词缩小范围",className:k="rge-form-select",threshold:F=po,maxVisibleOptions:j=Fr,onChange:O,onMultiChange:U})=>{const C=e.useRef(null),I=e.useRef(null),[D,_]=e.useState(!1),[u,Z]=e.useState(""),[ee,H]=e.useState(0),V=e.useMemo(()=>o.map(go),[o]),me=V.some(J=>J.value===""),q=i||V.length>F,le=e.useMemo(()=>r||(s&&n?n.split(",").map(J=>J.trim()).filter(Boolean):[]),[s,n,r]),ue=V.find(J=>J.value===n),W=le.map(J=>{var Ae;return((Ae=V.find(tt=>tt.value===J))==null?void 0:Ae.label)||J}).filter(Boolean),ge=W.length,Pe=ge>0?Br(g,{count:ge}):"",Me=W.slice(0,2).join(", "),X=s?ge?`${Pe}: ${Me}${W.length>2?" ...":""}`:f:(ue==null?void 0:ue.label)||n||f,b=s?W.length?W.join(", "):f:X,$=u.trim().toLowerCase(),Y=e.useMemo(()=>$?V.filter(J=>J.label.toLowerCase().includes($)||J.value.toLowerCase().includes($)||String(J.description||"").toLowerCase().includes($)):V,[$,V]),te=Math.max(1,Number(j)||Fr),L=e.useMemo(()=>Y.slice(0,te),[Y,te]),ke=Math.max(0,Y.length-L.length),we=Br(w,{shown:L.length,total:Y.length,selected:ge,hidden:ke}),ne=u.trim(),he=i&&!s&&ne.length>0&&!V.some(J=>J.value.toLowerCase()===$||J.label.toLowerCase()===$),xe=L.length+(he?1:0);e.useEffect(()=>{if(!D)return;const J=tt=>{var z;(z=C.current)!=null&&z.contains(tt.target)||Ee()},Ae=tt=>{tt.key==="Escape"&&Ee()};return document.addEventListener("mousedown",J),document.addEventListener("keydown",Ae),()=>{document.removeEventListener("mousedown",J),document.removeEventListener("keydown",Ae)}},[D]),e.useEffect(()=>{D&&window.setTimeout(()=>{var J;return(J=I.current)==null?void 0:J.focus()},0)},[D]),e.useEffect(()=>{if(!D)return;const J=L.findIndex(Ae=>s?le.includes(Ae.value):Ae.value===n);H(J>=0?J:0)},[D,u,s,le,n,L]);const Ee=()=>{_(!1),Z(""),H(0)},Le=()=>{m||(_(!0),Z(""))},Se=J=>{U==null||U(J)},se=J=>{const Ae=le.includes(J)?le.filter(tt=>tt!==J):[...le,J];Se(Ae)},ae=J=>{O(J),Ee()},Ne=()=>{if(!(!D||xe<=0)){if(ee<L.length){const J=L[ee];if(!J)return;if(s){se(J.value);return}ae(J.value);return}he&&ae(ne)}},_e=J=>{if(!m){if(!D&&["ArrowDown","Enter"," "].includes(J.key)){J.preventDefault(),Le();return}D&&(J.key==="ArrowDown"?(J.preventDefault(),H(Ae=>Math.min(xe-1,Ae+1))):J.key==="ArrowUp"?(J.preventDefault(),H(Ae=>Math.max(0,Ae-1))):J.key==="Home"?(J.preventDefault(),H(0)):J.key==="End"?(J.preventDefault(),H(Math.max(0,xe-1))):J.key==="Enter"?(J.preventDefault(),Ne()):J.key==="Escape"&&(J.preventDefault(),Ee()))}};return q?e.createElement("div",{className:"rge-search-select",ref:C,"data-searchable-select":t||void 0},e.createElement("button",{type:"button",className:`rge-search-select-trigger ${k}`,disabled:m,"aria-haspopup":"listbox","aria-expanded":D,"aria-multiselectable":s||void 0,"data-selected-count":ge,title:b,onKeyDown:_e,onClick:()=>{m||(D?Ee():Le())}},e.createElement("span",{className:`rge-search-select-display${X&&X!==f?"":" is-placeholder"}`},s&&ge>0&&e.createElement("span",{className:"rge-search-select-count"},Pe),e.createElement("span",{className:"rge-search-select-display-text"},s&&ge>0?Me:X||f)),e.createElement("span",{className:"rge-search-select-arrow"},"▾")),D&&e.createElement("div",{className:"rge-search-select-popover",role:"listbox"},e.createElement("input",{ref:I,className:"rge-search-select-input",value:u,onChange:J=>{Z(J.target.value),H(0)},onKeyDown:_e,placeholder:M}),e.createElement("div",{className:"rge-search-select-list"},Y.length===0&&!he?e.createElement("div",{className:"rge-search-select-empty"},N):L.map((J,Ae)=>e.createElement("button",{type:"button",key:J.value,className:`rge-search-select-option${(s?le.includes(J.value):J.value===n)?" selected":""}${Ae===ee?" active":""}`,role:"option","aria-selected":s?le.includes(J.value):J.value===n,onMouseEnter:()=>H(Ae),onClick:()=>{if(s){se(J.value);return}ae(J.value)}},e.createElement("span",{className:"rge-search-select-label"},J.label),J.label!==J.value&&e.createElement("span",{className:"rge-search-select-value"},J.value),J.description&&e.createElement("span",{className:"rge-search-select-desc"},J.description))),he&&e.createElement("button",{type:"button",className:`rge-search-select-option rge-search-select-create${ee===L.length?" active":""}`,role:"option","aria-selected":!1,onMouseEnter:()=>H(L.length),onClick:()=>{ae(ne)}},e.createElement("span",{className:"rge-search-select-label"},P," ",ne))),e.createElement("div",{className:"rge-search-select-footer","data-searchable-select-count":!0},e.createElement("span",null,we),ke>0&&e.createElement("span",{className:"rge-search-select-more"},y)))):s?e.createElement("select",{className:k,value:le,multiple:!0,onChange:J=>{Se(Array.from(J.target.selectedOptions).map(Ae=>Ae.value))},disabled:m},V.map(J=>e.createElement("option",{key:J.value,value:J.value},J.label))):e.createElement("select",{className:k,value:n,onChange:J=>O(J.target.value),disabled:m},f&&!me&&e.createElement("option",{value:""},f),V.map(J=>e.createElement("option",{key:J.value,value:J.value},J.label)))};zt.displayName="SearchableSelect";const pe=({value:t,className:n=""})=>{const r=typeof t=="string"?v.getEditorToolbarIconSvg(t):null,o=`rge-editor-icon ${n}`.trim();return r?e.createElement("span",{className:o,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:r}}):e.createElement("span",{className:o,"aria-hidden":"true"},t)};function Cn(t){if(t==null)return t;if(Array.isArray(t))return t.map(n=>Cn(n));if(t instanceof Date)return new Date(t.getTime());if(typeof t=="object"){const n={};return Object.entries(t).forEach(([r,o])=>{n[r]=Cn(o)}),n}return t}const $t=t=>String(t.type||"").toLowerCase(),gr=t=>String(t||"").toLowerCase().includes("float"),da=t=>{const n=String(t||"").toLowerCase();return n==="number"||n.includes("int")||n.includes("float")},bt=t=>{var n;return String(((n=t.component)==null?void 0:n.type)||"").toLowerCase()},zn=t=>{var n;return String(((n=t.component)==null?void 0:n.source)||"").toLowerCase()},Gn=t=>String(t&&typeof t=="object"?t.value??t.id??t.name??t.label??"":t??""),pa=t=>String(t&&typeof t=="object"?t.label??t.name??t.value??t.id??"":t??""),fo=t=>{if(t&&typeof t=="object"){const n=t.description??t.desc??t.remark;return n==null?void 0:String(n)}},bo=t=>{if(t&&typeof t=="object"){const n=String(t.value??t.id??t.name??t.label??"");return{...t,label:String(t.label??t.name??n),value:n}}return{label:String(t??""),value:String(t??"")}},jr=(t,n)=>{const r=String(t.id??t.value??t.name??t.label??"").trim();if(!r)return null;const o=typeof t.labelKey=="string"?t.labelKey:"";return{label:(o?n(o,""):"")||String(t.label??t.name??r),value:r,url:typeof t.url=="string"?t.url:void 0,models:Array.isArray(t.models)?t.models.map(bo):[],defaultModel:typeof t.defaultModel=="string"?t.defaultModel:void 0}},ga=t=>!!(t&&typeof t=="object"&&"name"in t&&("type"in t||"component"in t||"fields"in t||"defaultValue"in t||"desc"in t)),ho=t=>Array.isArray(t)&&t.some(n=>ga(n)),fr=(t,n)=>{const r=[...t],o=new Set(r.map(Gn));return(Array.isArray(n)?n:String(n??"").split(",").filter(Boolean)).forEach(i=>{const m=String(i??"");!m||o.has(m)||(r.push({label:m,value:m}),o.add(m))}),r.map(i=>({label:pa(i),value:Gn(i),description:fo(i)}))},bn=t=>{var n;return bt(t)==="select"||$t(t)==="select"||zn(t)==="nodes"||zn(t)==="rulechains"||Array.isArray((n=t.component)==null?void 0:n.options)&&!ho(t.component.options)||Array.isArray(t.options)},Eo=t=>bt(t)==="rulechainselector"||zn(t)==="rulechains",Yn=t=>bt(t)==="switch"||["boolean","bool"].includes($t(t)),Hr=t=>["textarea","json-editor"].includes(bt(t))||["textarea","json"].includes($t(t)),Pn=t=>{const n=bt(t),r=$t(t),o=t.name.toLowerCase();return n==="password"||r==="password"||/password|passwd|secret|token|api[_-]?key|private[_-]?key|pem/.test(o)},Xn=t=>da(t.type)||["input-number","slider"].includes(bt(t)),br=t=>{const n=bt(t);if(n==="command"||n==="shell")return!0;const r=t.name.toLowerCase();if(r==="command")return!0;if(r!=="cmd")return!1;const o=`${t.label||""} ${t.desc||""}`.toLowerCase();return!o.trim()||o.includes("redis command")?!1:o.includes("shell")||o.includes("execute")||o.includes("command to execute")||o.includes("命令")||o.includes("执行")},Wn=t=>t.name==="jsScript"||t.name==="JsScript"||t.name==="script"||t.name.toLowerCase()==="template"||br(t)||["codeeditor","code-editor","code","javascript","sql","monaco","json-editor","command","shell"].includes(bt(t))||["jsscript","json"].includes($t(t)),Wr=t=>t==null?"":typeof t=="object"?JSON.stringify(t,null,2):String(t),Ur=t=>bt(t)==="switchnode",hn=t=>{const n=bt(t);return n==="tools"||n==="subagents"},Vr=t=>bt(t)==="subagents"?"subagent":"tool",Yt=t=>{const n=$t(t),r=bt(t);return n==="array"||r==="array"||r==="table"},qr=t=>{const n=$t(t),r=bt(t);return n==="struct"||n==="object"||r==="struct"||r==="object"},on=t=>$t(t)==="map"||bt(t)==="map",Jr=t=>{const n=bt(t),r=$t(t),o=t.name.toLowerCase();return n==="expr"||n==="expression"||r==="expr"||r==="expression"||o==="expr"||o==="expression"},Kr=t=>["date","datepicker","time","timepicker"].includes(bt(t)),zr=t=>$t(t)==="duration"||bt(t)==="duration",wn=t=>{var n;return Array.isArray(t.fields)&&t.fields.length>0?t.fields:Array.isArray((n=t.component)==null?void 0:n.options)?t.component.options.filter(ga).map(r=>r):[]},En=(t,n)=>{if(!Yt(t))return!1;if(wn(t).length>0)return!0;const r=Array.isArray(t.defaultValue)?t.defaultValue[0]:Array.isArray(n)?n[0]:null;return!!(r&&typeof r=="object"&&!Array.isArray(r))},yo=t=>Array.isArray(t)?t:typeof t=="string"&&t.trim()?t.split(",").map(n=>n.trim()).filter(Boolean):[],_o=t=>Array.isArray(t)?t.map(n=>({case:String((n==null?void 0:n.case)??(n==null?void 0:n.condition)??""),then:String((n==null?void 0:n.then)??(n==null?void 0:n.result)??"")})):[],vo=t=>yo(t).map(n=>n&&typeof n=="object"&&!Array.isArray(n)?{...n}:{value:n});let Co=0;const yn=(t,n)=>n===t||n.startsWith(`${t}.`);function ko({field:t,value:n,onChange:r,onChildChange:o,translate:s}){const i=wn(t),m=v.decodeTableRowsForEditing(i,n),f=b=>r(v.encodeTableRowsForStorage(i,b)),M=v.getTableColumns(i,m),N=v.getTableDetailFields(i),P=i.some(b=>String(b.name).trim().toLowerCase()==="type"),[g,w]=e.useState(1),[y,k]=e.useState(50),[F,j]=e.useState(""),[O,U]=e.useState([]),[C,I]=e.useState(null),[D,_]=e.useState(""),[u,Z]=e.useState({prefix:"",start:0,count:10,step:1,type:"",namePrefix:""}),ee=v.findDuplicateRowValues(m),H=m.map((b,$)=>({row:b,index:$})).filter(({row:b})=>{const $=F.trim().toLowerCase();return $?M.some(Y=>String(b[Y]??"").toLowerCase().includes($)):!0}),V=v.paginateTableRows(H,g,y);e.useEffect(()=>{w(b=>Math.min(b,V.totalPages)),U(b=>b.filter($=>$>=0&&$<m.length)),I(b=>b!==null&&b>=m.length?null:b)},[m.length,V.totalPages]);const me=(b,$,Y)=>{const te=i.find(ne=>ne.name===$),L=v.coerceTableCellValue(te,Y),ke=m.map((ne,he)=>he===b?{...ne,[$]:L}:ne),we=f(ke);te&&o(te,`${t.name}.${b}.${$}`,L,we)},q=(b,$,Y)=>{var xe,Ee;const te=i.find(Le=>Le.name===Y),L=b[Y]??"",ke=String(L),we=te?bt(te):"",ne=Array.isArray((xe=te==null?void 0:te.component)==null?void 0:xe.options)?te.component.options:Array.isArray(te==null?void 0:te.options)?te.options:[];if(!!(te&&we==="select"&&!((Ee=te.component)!=null&&Ee.allowCreate))){const Le=fr(ne,L),Se=ke===""&&!Le.some(se=>se.value==="")?[{label:"",value:""},...Le]:Le;return e.createElement("select",{className:"rge-form-input",value:ke,"data-point-cell":Y,onChange:se=>me($,Y,se.target.value)},Se.map(se=>e.createElement("option",{key:se.value,value:se.value},se.label)))}return te&&Yn(te)?e.createElement("input",{type:"checkbox",checked:!!L,"data-point-cell":Y,onChange:Le=>me($,Y,Le.target.checked)}):e.createElement("input",{className:"rge-form-input",type:te&&Xn(te)?"number":"text",value:ke,"data-point-cell":Y,onChange:Le=>me($,Y,Le.target.value)})},le=()=>{f([...m,v.createEmptyTableRow(i)]),w(Math.max(1,Math.ceil((m.length+1)/y))),N.length>0&&I(m.length)},ue=b=>{if(b.length===0)return;const $=s("editor.property.confirmDeleteRows",`确认删除 ${b.length} 行?`,{count:String(b.length)});if(typeof window<"u"&&!window.confirm($))return;const Y=new Set(b);f(m.filter((te,L)=>!Y.has(L))),U([]),I(null)},W=b=>{if(!b)return;_("");const $=new FileReader;$.onload=()=>{const Y=v.parseCsvTable(String($.result||""));if(Y.length===0)return;(!v.getPointTableImportDecision(m,Y).requiresConfirmation||typeof window<"u"&&window.confirm(s("editor.property.confirmReplacePointTable",`导入 ${Y.length} 条将替换当前 ${m.length} 条点位,是否继续?`,{incoming:String(Y.length),existing:String(m.length)})))&&(f(Y),I(null))},$.readAsText(b)},ge=async b=>{if(b){_("");try{const $=await v.parseExcelTable(await b.arrayBuffer());if($.length===0){_(s("editor.property.emptyExcelTable","Excel 中没有有效数据"));return}(!v.getPointTableImportDecision(m,$).requiresConfirmation||typeof window<"u"&&window.confirm(s("editor.property.confirmReplacePointTable",`导入 ${$.length} 条将替换当前 ${m.length} 条点位,是否继续?`,{incoming:String($.length),existing:String(m.length)})))&&(f($),I(null))}catch($){_(s("editor.property.excelImportFailed","Excel 导入失败: {{message}}",{message:$ instanceof Error?$.message:String($)}))}}},Pe=()=>{_("");const b=v.serializeCsvTable(m,M),$=new Blob([`\uFEFF${b}`],{type:"text/csv;charset=utf-8"}),Y=URL.createObjectURL($),te=document.createElement("a");te.href=Y,te.download=`${t.name||"table"}.csv`,te.click(),URL.revokeObjectURL(Y)},Me=async()=>{_("");try{const b=await v.serializeExcelTable(m,M),$=b.buffer.slice(b.byteOffset,b.byteOffset+b.byteLength),Y=new Blob([$],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),te=URL.createObjectURL(Y),L=document.createElement("a");L.href=te,L.download=`${t.name||"table"}.xlsx`,L.click(),URL.revokeObjectURL(te)}catch(b){_(s("editor.property.excelExportFailed","Excel 导出失败: {{message}}",{message:b instanceof Error?b.message:String(b)}))}},X=()=>{const b=v.generatePointRows({...u,type:P?u.type:void 0,existing:m});b.length>0&&f([...m,...b]),w(Math.max(1,Math.ceil((m.length+b.length)/y)))};return e.createElement("div",{className:"rge-point-table-editor"},e.createElement("div",{className:"rge-point-table-toolbar"},tn(t.desc)&&e.createElement("span",{className:"rge-point-table-desc"},tn(t.desc)),e.createElement("div",{className:"rge-point-table-actions"},e.createElement("input",{className:"rge-form-input",type:"search",value:F,placeholder:s("editor.property.searchTable","搜索表格"),onChange:b=>{j(b.target.value),w(1)}}),e.createElement("label",{className:"rge-point-table-file-button"},s("editor.property.importCsv","导入 CSV"),e.createElement("input",{type:"file",accept:".csv,text/csv",onChange:b=>{var $;W(($=b.target.files)==null?void 0:$[0]),b.currentTarget.value=""}})),e.createElement("label",{className:"rge-point-table-file-button"},s("editor.property.importExcel","导入 Excel"),e.createElement("input",{type:"file",accept:".xlsx,.xls,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel",onChange:b=>{var Y;const $=(Y=b.currentTarget.files)==null?void 0:Y[0];b.currentTarget.value="",ge($)}})),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:Pe,disabled:m.length===0},s("editor.property.exportCsv","导出 CSV")),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:()=>{Me()},disabled:m.length===0},s("editor.property.exportExcel","导出 Excel")),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:()=>ue(O),disabled:O.length===0},s("editor.property.deleteSelected","删除所选")),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:le},s("editor.panel.addPair","+ 添加"))),D&&e.createElement("span",{className:"rge-point-table-error",role:"alert"},D)),e.createElement("details",{className:"rge-point-table-generator"},e.createElement("summary",null,s("editor.property.generatePoints","批量生成点位")),e.createElement("div",{className:"rge-point-table-generator-grid"},e.createElement("input",{className:"rge-form-input",value:u.prefix,placeholder:s("editor.property.pointPrefix","地址前缀"),onChange:b=>Z({...u,prefix:b.target.value})}),e.createElement("input",{className:"rge-form-input",type:"number",value:u.start,placeholder:s("editor.property.pointStart","起始编号"),onChange:b=>Z({...u,start:Number(b.target.value)||0})}),e.createElement("input",{className:"rge-form-input",type:"number",min:"1",value:u.count,placeholder:s("editor.property.pointCount","数量"),onChange:b=>Z({...u,count:Math.max(1,Number(b.target.value)||1)})}),e.createElement("input",{className:"rge-form-input",type:"number",min:"1",value:u.step,placeholder:s("editor.property.pointStep","步长"),onChange:b=>Z({...u,step:Math.max(1,Number(b.target.value)||1)})}),P&&e.createElement("input",{className:"rge-form-input",value:u.type,placeholder:s("editor.property.pointType","数据类型"),onChange:b=>Z({...u,type:b.target.value})}),e.createElement("input",{className:"rge-form-input",value:u.namePrefix,placeholder:s("editor.property.pointNamePrefix","名称前缀"),onChange:b=>Z({...u,namePrefix:b.target.value})}),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:X},s("editor.panel.confirm","生成")))),e.createElement("div",{className:"rge-point-table-scroll"},e.createElement("table",{className:"rge-point-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,e.createElement("input",{type:"checkbox",checked:V.items.length>0&&V.items.every(b=>O.includes(b.index)),onChange:b=>U(b.target.checked?[...new Set([...O,...V.items.map($=>$.index)])]:O.filter($=>!V.items.some(Y=>Y.index===$)))})),M.map(b=>{var $;return e.createElement("th",{key:b},(($=i.find(Y=>Y.name===b))==null?void 0:$.label)||b)}),e.createElement("th",null,s("editor.property.actions","操作")))),e.createElement("tbody",null,V.items.map(({row:b,index:$})=>e.createElement(e.Fragment,{key:$},e.createElement("tr",{className:ee.has(String(b.name??"").trim())?"is-duplicate":void 0},e.createElement("td",null,e.createElement("input",{type:"checkbox",checked:O.includes($),onChange:Y=>U(te=>Y.target.checked?[...new Set([...te,$])]:te.filter(L=>L!==$))})),M.map(Y=>e.createElement("td",{key:Y},q(b,$,Y))),e.createElement("td",{className:"rge-point-row-actions"},N.length>0&&e.createElement("button",{type:"button",className:"rge-btn-icon-edit","data-point-edit":$,"aria-expanded":C===$,title:s("editor.property.editRowDetails","编辑行详情"),onClick:()=>I(Y=>Y===$?null:$)},"✎"),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",title:s("editor.property.delete","删除"),onClick:()=>ue([$])},"×"))),N.length>0&&C===$&&e.createElement("tr",{className:"rge-point-detail-row","data-point-detail-row":$},e.createElement("td",{colSpan:M.length+2},e.createElement("div",{className:"rge-point-detail-grid"},N.map(Y=>e.createElement("label",{key:Y.name,className:"rge-point-detail-field"},e.createElement("span",null,Y.label||Y.name),q(b,$,Y.name),tn(Y.desc)&&e.createElement("small",null,tn(Y.desc))))))))))),V.items.length===0&&e.createElement("div",{className:"rge-point-table-empty"},s("editor.property.noRows","暂无数据"))),e.createElement("div",{className:"rge-point-table-pagination"},e.createElement("span",null,s("editor.property.tableCount",`共 ${V.total} 条`,{count:String(V.total)})),e.createElement("select",{value:y,onChange:b=>{k(Number(b.target.value)),w(1)}},e.createElement("option",{value:"20"},"20"),e.createElement("option",{value:"50"},"50"),e.createElement("option",{value:"100"},"100"),e.createElement("option",{value:"200"},"200")),e.createElement("button",{type:"button",disabled:g<=1,onClick:()=>w(b=>b-1)},s("editor.property.prevPage","上一页")),e.createElement("span",null,V.page," / ",V.totalPages),e.createElement("button",{type:"button",disabled:g>=V.totalPages,onClick:()=>w(b=>b+1)},s("editor.property.nextPage","下一页"))))}const No=(t,n)=>{const r=wn(t);if(r.length>0)return r.map(s=>s.name).filter(Boolean);const o=n[0]||(Array.isArray(t.defaultValue)&&t.defaultValue[0]&&typeof t.defaultValue[0]=="object"?t.defaultValue[0]:{});return Object.keys(o)},wo=(t,n)=>{if(!t)return n;if(Yn(t))return!!n;if(Xn(t)){const r=String(n??"");return r?gr(t.type)||$t(t)==="number"?Number(r):parseInt(r,10):""}return n},fa=(t,n)=>{const r=String(n??"").trim();return r?{label:String(t??r)||r,value:r}:null},hr=12,_n=(t=hr)=>({items:[],total:0,page:1,size:t,loading:!1,error:""}),Qn=(t,n,r)=>{const o=fa(t,n);if(!o)return null;const s=String((r==null?void 0:r.description)??(r==null?void 0:r.desc)??(r==null?void 0:r.remark)??"").trim();return{...o,root:typeof(r==null?void 0:r.root)=="boolean"?r.root:void 0,description:s||void 0}},Er=t=>{if(!t||typeof t!="object")return Qn(t,t);const n=t,r=n.ruleChain&&typeof n.ruleChain=="object"?n.ruleChain:n,o=r.id??n.id??n.value,s=r.name??n.name??n.label??o;return Qn(s,o,r)},Un=(t,n,r)=>{const o=v.normalizePagedResponse(t,s=>s,n,r);return{items:o.items,total:o.total,page:o.page,size:o.pageSize}},So=(t,n)=>{const r=String(t||n||"").trim().replace(/\/+$/,"");return r?/\/rules$/i.test(r)?r:`${r}/rules`:""},Vn=(t,n)=>{if(n.length===0)return t;const r={...t};return n.forEach(o=>{r[o.value]=o}),r},xo=(t,n)=>{var i;const r=String((n==null?void 0:n.id)||(n==null?void 0:n.nodeId)||"").trim(),o=new Set,s=[];for(const m of t||[]){const f=m,M=f.properties,N=(M==null?void 0:M.model)||M||f,P=String(N.id||f.id||"").trim();if(!P||P===r||o.has(P))continue;const g=typeof f.text=="object"?(i=f.text)==null?void 0:i.value:f.text,w=fa(N.name||g||P,P);w&&(o.add(w.value),s.push(w))}return s},To=t=>{const n=(t==null?void 0:t.ruleChain)||t;return String((n==null?void 0:n.id)||(t==null?void 0:t.id)||(t==null?void 0:t.value)||"").trim()},Ro=t=>{const n=new Set,r=[];for(const o of t||[]){const s=(o==null?void 0:o.ruleChain)||o,i=String((s==null?void 0:s.id)||(o==null?void 0:o.id)||(o==null?void 0:o.value)||"").trim(),m=(s==null?void 0:s.name)||(o==null?void 0:o.name)||(o==null?void 0:o.label)||i,f=Qn(m,i,s);!f||n.has(f.value)||(n.add(f.value),r.push(f))}return r},Io=t=>{const n=new Set,r=[];for(const o of t||[]){const s=o&&typeof o=="object"?o:void 0,i=Qn(pa(o),Gn(o),s);!i||n.has(i.value)||(n.add(i.value),r.push(i))}return r},Po=(t,n)=>n==="root"?t.root!==!1:t.root===!1||t.root===void 0,vn=t=>String(t.name||t.targetId||""),Gr=t=>String(t.description||t.desc||""),Do=(t,n)=>{var o,s;if(String(t.type||"")!=="builtin")return!1;const r=vn(t);return r?!!((s=(o=n.find(i=>i.value===r))==null?void 0:o.fields)!=null&&s.length):!1},Lo=(t,n,r)=>n!=="tool"||String(t.type||"")!=="builtin"||Do(t,r),or=(t,n=120)=>{const r=String(t??"").replace(/\s+/g," ").trim();return r.length<=n?r:`${r.slice(0,n)}...`},Mo=t=>{const r=(t!=null&&t.additionalInfo&&typeof t.additionalInfo=="object"?t.additionalInfo:{}).inputSchema??(t==null?void 0:t.inputSchema);return v.stringifyToolJson(r,"{}")},lr=t=>{var s;if(!t||typeof t!="object")return Er(t);const n=t,r=n.ruleChain&&typeof n.ruleChain=="object"?n.ruleChain:n,o=Er(n);return o?{...o,description:o.description||String(((s=r.additionalInfo)==null?void 0:s.description)||r.description||r.desc||""),raw:r}:null},sr=t=>{const n=new Set,r=[];return t.forEach(o=>{!o.value||n.has(o.value)||(n.add(o.value),r.push(o))}),r},$o=t=>t.length>0?Math.max(...t.map(n=>Number(n.order||0))):0,Ao=(t,n,r,o)=>v.updateSchemaRowsAtParent(t,n,s=>{const i=r+o;if(i<0||i>=s.length)return;const[m]=s.splice(r,1);if(!m)return;s.splice(i,0,m);const f=v.renumberSchemaRowOrders(s);s.splice(0,s.length,...f)}),tn=t=>{const n=["rulego","cc"].join("\\.");return String(t??"").replace(new RegExp(`<a\\b[^>]*href=["'][^"']*${n}[^"']*["'][^>]*>[\\s\\S]*?<\\/a>`,"gi"),"").replace(new RegExp(`https?:\\/\\/[^\\s"'<>]*${n}[^\\s"'<>]*`,"gi"),"").replace(/<[^>]+>/g,"").replace(/\s+/g," ").trim()},ba=({visible:t,nodeModel:n,nodeView:r,onSubmit:o,onClose:s,locale:i,messages:m,t:f,graphNodes:M,ruleItems:N,currentRuleChain:P,rulesApi:g,apiBase:w,rulePageSize:y,fetchRuleChains:k,componentsPayload:F,componentPayload:j,builtinTools:O,tools:U,skillPath:C,fetchBuiltinTools:I,onOpenAiAssistant:D,aiProviders:_,aiEmbeddingProviders:u,resolveFieldsByType:Z,optionSourceRegistry:ee,fieldChangeRegistry:H,onFieldChangeError:V,initializeDefaults:me=!1})=>{var Ar;const[q,le]=e.useState({}),[ue,W]=e.useState("{}"),[ge,Pe]=e.useState(""),[Me,X]=e.useState({}),[b,$]=e.useState({}),[Y,te]=e.useState({}),[L,ke]=e.useState("custom"),[we,ne]=e.useState(""),[he,xe]=e.useState("custom"),[Ee,Le]=e.useState(""),[Se,se]=e.useState([]),[ae,Ne]=e.useState(null),[_e,J]=e.useState(()=>_n()),[Ae,tt]=e.useState({}),[z,Ye]=e.useState(null),[ht,mt]=e.useState([]),[Vt,Bt]=e.useState(!1),[jt,Pt]=e.useState(""),[Nt,lt]=e.useState(()=>_n()),[vt,xt]=e.useState({}),[Lt,Tt]=e.useState(""),[Ke,Rt]=e.useState(""),[At,Mt]=e.useState({}),[Ot,Ct]=e.useState(0),[Te]=e.useState(()=>`react-drawer-${++Co}`),qt=e.useRef(""),gt=e.useRef({}),je=e.useRef({}),nt=e.useRef({}),Re=e.useRef(null),re=e.useRef(new Map),fe=e.useRef({}),Ce=e.useRef(new Set),ye=e.useRef(new Set),De=e.useRef(""),qe=e.useMemo(()=>new v.OptionSourceRegistry,[]),d=e.useMemo(()=>Ze({locale:i,messages:m,t:f}),[i,m,f]);gt.current=q,je.current=Me,nt.current=b,De.current=String((n==null?void 0:n.nodeId)||(n==null?void 0:n.id)||"");const ie=e.useCallback(a=>{const l=a(gt.current);return gt.current=l,le(l),l},[]),Fe=e.useCallback(a=>{const l=a(je.current);return je.current=l,X(l),l},[]),ft=e.useCallback(a=>{const l=a(nt.current);return nt.current=l,$(l),l},[]);e.useEffect(()=>{var l;const a=new AbortController;return(l=Re.current)==null||l.abort(),Re.current=a,re.current.clear(),Ct(0),fe.current={},ye.current.clear(),Mt({}),()=>{a.abort(),Re.current===a&&(Re.current=null)}},[H,n==null?void 0:n.id,n==null?void 0:n.nodeId,t]);const h=e.useCallback(a=>{if(typeof window>"u")return;const l=d("editor.property.confirmDeleteRows","确认删除 1 行?",{count:"1"});window.confirm(l)&&a()},[d]),S=e.useMemo(()=>({searchPlaceholder:d("editor.property.searchOptions","搜索选项..."),noMatchText:d("editor.property.noMatchingOptions","没有匹配的选项"),createOptionText:d("editor.form.useInputValue","使用"),selectedCountText:d("editor.property.selectedCount","已选 {{count}} 项"),resultCountText:d("editor.property.selectResultCount","显示 {{shown}} / {{total}} 项"),moreOptionsText:d("editor.property.moreOptionsHint","结果较多,请继续输入关键词缩小范围")}),[d]),K=e.useCallback(a=>uo(a,d,f,m),[m,f,d]),A=e.useMemo(()=>xo(M,n),[M,n]),oe=e.useMemo(()=>Ro(N),[N]),Oe=e.useMemo(()=>Math.max(1,Number(y||hr)||hr),[y]),rt=e.useMemo(()=>So(g,w),[w,g]),Xe=!!(k||rt),wt=e.useMemo(()=>v.getBuiltinToolOptionsFromSources(O,U,F,j),[O,j,F,U]),Ht=e.useMemo(()=>ht.length>0?ht:wt,[ht,wt]),He=e.useMemo(()=>v.getSkillPathFromSources(C,F,j),[j,F,C]),ut=e.useMemo(()=>oe.map(a=>({label:a.label,value:a.value})),[oe]),st=e.useMemo(()=>To(P),[P]),Ft=e.useCallback(a=>r?v.resolveComponentFields(r,{configuration:a,getFieldsByType:Z}):[],[r,Z]),Ue=e.useMemo(()=>Ft(q.configuration||(n==null?void 0:n.configuration)||{}),[q.configuration,n==null?void 0:n.configuration,Ft]),ln=e.useMemo(()=>v.getVisibleComponentFields(Ue,q.configuration||{}),[q.configuration,Ue]),nn=e.useMemo(()=>v.buildFieldAttachments(Ue),[Ue]),An=e.useMemo(()=>new Set([...nn.values()].flatMap(a=>a.map(l=>l.field.name))),[nn]);Ce.current=An;const sn=Lt?nn.get(Lt)||[]:[],On=sn.filter(a=>v.isFieldDependencySatisfied(a.field,q.configuration)),Fn=new Set(sn.map(a=>a.field.name)),Wt=[...re.current.keys()].filter(a=>[...Fn].some(l=>yn(l,a))).length,cn=Object.entries(At).filter(([a])=>ye.current.has(a)||[...An].some(l=>yn(l,a))),un=cn.filter(([a])=>[...Fn].some(l=>yn(l,a))),mn=e.useMemo(()=>{const a=[...(r==null?void 0:r.groups)||[]].sort((p,T)=>(p.order??0)-(T.order??0)),l=new Set,c=a.map(p=>{const T=new Set(p.fields||[]),R=ln.filter(x=>T.has(x.name));return R.forEach(x=>l.add(x.name)),{id:p.id,label:p.label||p.id,description:p.description,collapsed:p.collapsed,fields:R}}).filter(p=>p.fields.length>0),E=ln.filter(p=>!l.has(p.name));return E.length>0&&c.unshift({id:"",label:"",description:void 0,collapsed:!1,fields:E}),c},[r==null?void 0:r.groups,ln]),Be=e.useMemo(()=>Ue.find(a=>a.ref==="primary")||null,[Ue]),B=e.useMemo(()=>Be?null:Ue.find(a=>a.aiProvider||a.name==="provider")||null,[Be,Ue]),be=e.useMemo(()=>{var a,l,c;return{provider:((a=B==null?void 0:B.aiProvider)==null?void 0:a.providerField)||(B==null?void 0:B.name)||"provider",url:((l=B==null?void 0:B.aiProvider)==null?void 0:l.urlField)||"url",model:((c=B==null?void 0:B.aiProvider)==null?void 0:c.modelField)||"model"}},[B]),ve=e.useMemo(()=>B?(B.providerType==="embedding"?v.getAiEmbeddingProviders(u):v.getAiProviders(_)).map(l=>jr(l,d)).filter(Boolean):[],[u,_,B,d]),Ve=e.useCallback(a=>{var p;const l=vt[a.name];if(a.optionsSource&&(l!=null&&l.options))return l.options;if(a.name===be.model&&Se.length>0)return Se;const c=((p=a.component)==null?void 0:p.options)||a.options||[],E=zn(a);return E==="nodes"&&A.length>0?A:E==="rulechains"&&ut.length>0?ut:c},[A,vt,be.model,Se,ut]),Qe=e.useMemo(()=>v.buildOptionSourceRequestKey(Ue,{configuration:q.configuration||{},currentNodeId:String((n==null?void 0:n.nodeId)||(n==null?void 0:n.id)||""),graphNodes:(M||[]).map(a=>{var l,c,E;return{id:String(a.id||a.nodeId||""),name:String(a.name||(typeof a.text=="object"?(l=a.text)==null?void 0:l.value:a.text)||a.id||a.nodeId||""),type:String(a.type||((E=(c=a.properties)==null?void 0:c.model)==null?void 0:E.type)||"")}}).filter(a=>!!a.id)}),[q.configuration,M,n==null?void 0:n.id,n==null?void 0:n.nodeId,Ue]);e.useEffect(()=>{const a=Ue.filter(R=>R.optionsSource);if(a.length===0){xt({});return}const l=new AbortController,c=ee||qe,E=q.configuration||{},p=String((n==null?void 0:n.nodeId)||(n==null?void 0:n.id)||""),T=(M||[]).map(R=>{var x,G,Q;return{id:String(R.id||R.nodeId||""),name:String(R.name||(typeof R.text=="object"?(x=R.text)==null?void 0:x.value:R.text)||R.id||R.nodeId||""),type:String(R.type||((Q=(G=R.properties)==null?void 0:G.model)==null?void 0:Q.type)||"")}}).filter(R=>!!R.id);return xt(R=>Object.fromEntries(a.map(x=>{var G,Q;return[x.name,{options:((G=R[x.name])==null?void 0:G.options)||((Q=x.component)==null?void 0:Q.options)||x.options||[],loading:!0,error:""}]}))),Promise.all(a.map(async R=>{try{const x=await c.resolve(R,{configuration:E,currentNodeId:p,graphNodes:T,signal:l.signal});if(l.signal.aborted)return;xt(G=>({...G,[R.name]:{options:x,loading:!1,error:""}}))}catch(x){if(l.signal.aborted)return;xt(G=>{var Q,ce;return{...G,[R.name]:{options:((Q=G[R.name])==null?void 0:Q.options)||((ce=R.component)==null?void 0:ce.options)||R.options||[],loading:!1,error:x instanceof Error?x.message:String(x)}}})}})),()=>l.abort()},[qe,ee,Qe]);const ct=e.useCallback((a,l,c=!1)=>{const E=fr(Ve(a),l);return!c||!st?E:E.filter(p=>p.value!==st)},[st,Ve]),et=e.useCallback((a,l)=>{var R;const E=[...oe.length>0?oe:Io(((R=a.component)==null?void 0:R.options)||a.options||[])],p=new Set(E.map(x=>x.value));Object.values(Ae).forEach(x=>{p.has(x.value)||(E.push(x),p.add(x.value))});const T=String(l??"").trim();return T&&!p.has(T)&&E.push({label:T,value:T}),E},[Ae,oe]),at=e.useCallback((a,l)=>{var E;const c=String(l??"").trim();return c?((E=et(a,c).find(p=>p.value===c))==null?void 0:E.label)||c:""},[et]),St=e.useCallback(()=>{const a=Object.values(Ae).map(c=>({...c})),l=oe.map(c=>({...c}));return sr([...l,...a].map(lr).filter(Boolean)).filter(c=>!st||c.value!==st)},[st,Ae,oe]),dt=e.useMemo(()=>Be?ct(Be,we):[],[ct,Be,we]);e.useEffect(()=>{var it,Ut,Jt;if(!n)return;const a=Cn(n.configuration||{}),l=Ft(a);me&&l.forEach(ze=>{!(ze.name in a)&&ze.defaultValue!==void 0&&(a[ze.name]=Cn(ze.defaultValue))});const c={id:n.id||"",nodeId:n.nodeId||"",type:n.type||"",name:n.name||"",debugMode:n.debugMode||!1,configuration:a,additionalInfo:n.additionalInfo||{}};gt.current=c,le(c);const E={},p={},T=new Map(l.map(ze=>[ze.name,ze]));Object.entries(a).forEach(([ze,Ge])=>{const ot=T.get(ze);ot&&Yt(ot)&&!(bn(ot)||Ur(ot)||En(ot,Ge)||hn(ot))&&(Array.isArray(Ge)||typeof Ge=="string")?p[ze]=v.normalizeSimpleArrayValues(Ge).map(Zt=>({value:Zt})):ot&&on(ot)&&!Array.isArray(Ge)&&Ge&&typeof Ge=="object"&&!(Ge instanceof Date)&&(E[ze]=Object.entries(Ge).map(([Zt,rr])=>({key:Zt,value:v.formatMapEntryValue(rr,v.getMapValueMode(ot))})))}),je.current=E,nt.current=p,X(E),$(p),te({});const R=l.find(ze=>ze.ref==="primary"),x=R!=null&&R.name?a[R.name]:"",G=String(x??""),Q=G.startsWith("ref://");ke(Q?"shared":"custom"),ne(Q?G:"");const ce=R?null:l.find(ze=>ze.aiProvider||ze.name==="provider")||null,de={provider:((it=ce==null?void 0:ce.aiProvider)==null?void 0:it.providerField)||(ce==null?void 0:ce.name)||"provider",url:((Ut=ce==null?void 0:ce.aiProvider)==null?void 0:Ut.urlField)||"url",model:((Jt=ce==null?void 0:ce.aiProvider)==null?void 0:Jt.modelField)||"model"},We=ce?(ce.providerType==="embedding"?v.getAiEmbeddingProviders(u):v.getAiProviders(_)).map(ze=>jr(ze,d)).filter(Boolean):[],$e={...a};if(ce){const ze=String(a[de.provider]??""),Ge=We.find(Zt=>Zt.value===ze),ot=!!(Ge&&ze!=="custom");xe(ot?"preset":"custom"),Le(ot?ze:""),se(ot?(Ge==null?void 0:Ge.models)||[]:[]),ot&&($e[de.provider]=ze,Ge!=null&&Ge.url&&($e[de.url]=Ge.url),Ge!=null&&Ge.defaultModel&&!$e[de.model]&&($e[de.model]=Ge.defaultModel))}else xe("custom"),Le(""),se([]);Ne(null),J(_n(Oe)),Ye(null),lt(_n(Oe)),W(JSON.stringify(a,null,2)),Pe(""),Tt(""),Rt(""),qt.current=JSON.stringify(v.normalizeEditableNodeModel(n,{name:n.name||"",debugMode:n.debugMode||!1,configuration:$e,additionalInfo:n.additionalInfo||{}},{graphNodeId:n.id||n.nodeId||"",nodeViewType:r==null?void 0:r.type,graphNodeType:n.type,keepNodeId:!0}))},[me,n,r,Ft]),e.useEffect(()=>{if(he!=="preset"||!Ee)return;const a=ve.find(l=>l.value===Ee);a&&se(a.models||[])},[he,ve,Ee]),e.useEffect(()=>{wt.length!==0&&(mt(wt),Pt(""))},[wt]);const pt=e.useCallback((a,l)=>{ie(c=>({...c,[a]:l}))},[ie]),Je=e.useCallback(()=>{const a={...gt.current.configuration||{}},l=new Map(Ue.map(c=>[c.name,c]));return Object.entries(je.current).forEach(([c,E])=>{const p=l.get(c);if(!p||!on(p))return;const T={},R=v.getMapValueMode(p);E.forEach(x=>{x.key&&(T[x.key]=v.parseMapEntryValue(x.value,R))}),a[c]=T}),Object.entries(nt.current).forEach(([c,E])=>{const p=l.get(c);!p||!Yt(p)||En(p,a[c])||hn(p)||bn(p)||(a[c]=E.map(T=>T.value).filter(Boolean))}),a},[Ue]),Et=e.useCallback((a,l)=>{const c={...Je(),[a]:l};return ie(E=>({...E,configuration:c})),c},[Je,ie]),Sn=e.useCallback(a=>{const l=Je();for(const p of a.remove||[])delete l[p];Object.assign(l,Cn(a.patch||{})),ie(p=>({...p,configuration:l}));const c=new Set([...Object.keys(a.patch||{}),...a.remove||[]]),E=new Map(Ue.map(p=>[p.name,p]));if([...c].some(p=>on(E.get(p)||{}))&&Fe(p=>{const T={...p};return c.forEach(R=>{const x=E.get(R);if(!x||!on(x))return;const G=l[R];!G||typeof G!="object"||Array.isArray(G)?delete T[R]:T[R]=Object.entries(G).map(([Q,ce])=>({key:Q,value:v.formatMapEntryValue(ce,v.getMapValueMode(x))}))}),T}),[...c].some(p=>{const T=E.get(p);return T&&Yt(T)&&!En(T,l[p])&&!hn(T)&&!bn(T)})&&ft(p=>{const T={...p};return c.forEach(R=>{const x=E.get(R);!x||!Yt(x)||En(x,l[R])||hn(x)||bn(x)||(Object.prototype.hasOwnProperty.call(l,R)?T[R]=v.normalizeSimpleArrayValues(l[R]).map(G=>({value:G})):delete T[R])}),T}),Be!=null&&Be.name&&c.has(Be.name)){const p=String(l[Be.name]??"");ne(p.startsWith("ref://")?p:""),ke(p.startsWith("ref://")?"shared":"custom")}if(c.has(be.provider)){const p=String(l[be.provider]??""),T=ve.find(R=>R.value===p);xe(T&&p!=="custom"?"preset":"custom"),Le(T&&p!=="custom"?p:""),se((T==null?void 0:T.models)||[])}},[Je,Be,be.provider,ve,ft,ie,Fe,Ue]),It=e.useCallback((a,l,c,E)=>{const p=v.getFieldChangeHandlerName(a);if(!p)return;const T=De.current,R=Re.current,x=(de,We=0)=>{if(R!=null&&R.signal.aborted||De.current!==T)return;const $e=de instanceof Error?de.message:String(de);(Ce.current.has(a.name)||a.attachTo)&&ye.current.add(l);const it={...fe.current,[l]:$e};fe.current=it,Mt(it),V==null||V(de,{field:a,fieldPath:l,handlerName:p,generation:We})};if(!H||!R){x(new Error(d("editor.property.fieldChangeUnavailable","字段联动处理器不可用: {{name}}",{name:p})));return}ye.current.delete(l);const G={...fe.current};delete G[l],fe.current=G,Mt(G);const Q=(M||[]).map(de=>{var We,$e,it;return{id:String(de.id||de.nodeId||""),name:String(de.name||(typeof de.text=="object"?(We=de.text)==null?void 0:We.value:de.text)||de.id||de.nodeId||""),type:String(de.type||((it=($e=de.properties)==null?void 0:$e.model)==null?void 0:it.type)||"")}}).filter(de=>!!de.id);let ce;ce=H.execute(a,c,{configuration:E,currentNodeId:T,graphNodes:Q,requestKey:`${Te}:${T||"__draft__"}:${l}`,signal:R.signal,fieldPath:l}).then(de=>{de.status!=="applied"||R.signal.aborted||De.current!==T||Sn(de)}).catch(de=>{R.signal.aborted||de instanceof Error&&de.name==="AbortError"||x(de)}).finally(()=>{re.current.get(l)===ce&&(re.current.delete(l),Ct(re.current.size))}),re.current.set(l,ce),Ct(re.current.size)},[Sn,Te,H,M,V,d]),kt=e.useCallback((a,l,c)=>{const E=Et(a.name,c);It(a,l,c,E)},[It,Et]),dn=e.useCallback((a,l)=>{J(_n(Oe)),Ne({fieldName:a.name,value:String(l??""),tab:"sub",keyword:"",page:1})},[Oe]),Gt=e.useCallback(a=>{Ne(l=>l&&{...l,...a})},[]),La=e.useCallback(a=>{if(!ae)return;tt(c=>Vn(c,[a]));const l=Ue.find(c=>c.name===ae.fieldName);l?kt(l,l.name,a.value):Et(ae.fieldName,a.value),Ne(null)},[kt,Ue,ae,Et]);e.useEffect(()=>{if(!ae||!Xe)return;const a=new AbortController,l=ae.tab,c=ae.keyword.trim(),E=ae.page,p=Oe,T=window.setTimeout(()=>{J(R=>({...R,page:E,size:p,loading:!0,error:""})),(async()=>{try{let R;if(k)R=await k({root:l==="root",keywords:c,page:E,size:p,signal:a.signal});else{const ce=new URLSearchParams;ce.set("root",l==="root"?"true":"false"),c&&ce.set("keywords",c),ce.set("page",String(E)),ce.set("size",String(p));const de=await fetch(`${rt}?${ce.toString()}`,{signal:a.signal});if(!de.ok)throw new Error(`HTTP ${de.status}`);R=await de.json()}const x=Un(R,E,p),G=x.items.map(Er).filter(Boolean),Q=st?G.filter(ce=>ce.value!==st):G;if(a.signal.aborted)return;tt(ce=>Vn(ce,Q)),J({items:Q,total:Math.max(0,x.total-(G.length-Q.length)),page:x.page||E,size:x.size||p,loading:!1,error:""})}catch(R){if(a.signal.aborted||(R==null?void 0:R.name)==="AbortError")return;J({items:[],total:0,page:E,size:p,loading:!1,error:d("editor.panel.loadFailed",`加载失败: ${(R==null?void 0:R.message)||String(R)}`,{message:String((R==null?void 0:R.message)||R)})})}})()},c?180:0);return()=>{window.clearTimeout(T),a.abort()}},[st,Oe,k,ae,rt,d,Xe]);const Cr=e.useCallback(async()=>{if(wt.length>0){mt(wt),Pt("");return}const a=String(w||"").trim().replace(/\/+$/,"");if(!I&&!a)return;const l=new AbortController;Bt(!0),Pt("");try{const c=I?await I({signal:l.signal}):await fetch(`${a}/components`,{signal:l.signal}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}),E=c&&typeof c=="object"&&"data"in c?c.data:c,p=v.getBuiltinToolOptionsFromSources(E,c);mt(p)}catch(c){(c==null?void 0:c.name)!=="AbortError"&&Pt(d("editor.panel.loadFailed",`加载失败: ${(c==null?void 0:c.message)||String(c)}`,{message:String((c==null?void 0:c.message)||c)}))}finally{Bt(!1)}},[w,I,wt,d]);e.useEffect(()=>{if(!z||z.step!=="select"||z.activeTab!=="rulechain"||!Xe)return;const a=new AbortController,l=z.keyword.trim(),c=z.ruleChainPage,E=Oe,p=window.setTimeout(()=>{lt(T=>({...T,page:c,size:E,loading:!0,error:""})),(async()=>{try{let T;if(k){const[Q,ce]=await Promise.all([k({root:!1,keywords:l,page:c,size:E,signal:a.signal}),k({root:!0,keywords:l,page:c,size:E,signal:a.signal})]),de=Un(Q,c,E),We=Un(ce,c,E);T={items:[...de.items,...We.items],total:de.total+We.total,page:c,size:E}}else{const Q=new URLSearchParams;l&&Q.set("keywords",l),Q.set("page",String(c)),Q.set("size",String(E));const ce=await fetch(`${rt}?${Q.toString()}`,{signal:a.signal});if(!ce.ok)throw new Error(`HTTP ${ce.status}`);T=await ce.json()}const R=Un(T,c,E),x=R.items.map(lr).filter(Boolean),G=sr(x).filter(Q=>!st||Q.value!==st);if(a.signal.aborted)return;tt(Q=>Vn(Q,G)),lt({items:G,total:Math.max(0,R.total-(x.length-G.length)),page:R.page||c,size:R.size||E,loading:!1,error:""})}catch(T){if(a.signal.aborted||(T==null?void 0:T.name)==="AbortError")return;lt({items:[],total:0,page:c,size:E,loading:!1,error:d("editor.panel.loadFailed",`加载失败: ${(T==null?void 0:T.message)||String(T)}`,{message:String((T==null?void 0:T.message)||T)})})}})()},l?180:0);return()=>{window.clearTimeout(p),a.abort()}},[st,Oe,k,rt,z,d,Xe]);const kr=e.useCallback(a=>{if(a===L||(ke(a),!(Be!=null&&Be.name)))return;const l=Je(),c=String(l[Be.name]??""),E=a==="shared"?we.trim():c.startsWith("ref://")?"":c;if(E===c)return;const p={...l,[Be.name]:E};ie(T=>({...T,configuration:p})),It(Be,Be.name,E,p)},[Je,Be,L,ie,It,we]),Ma=e.useCallback(a=>{if(ne(a),!(Be!=null&&Be.name))return;const l=a.trim(),c={...Je(),[Be.name]:l};ie(E=>({...E,configuration:c})),It(Be,Be.name,l,c)},[Je,Be,ie,It]),$a=e.useCallback(a=>{const l=ve.find(R=>R.value===a);if(!l||!B)return;Le(l.value),se(l.models);const c=Je(),E=l.models.map(Gn).filter(Boolean),p=String(c[be.model]??""),T={...c,[be.provider]:l.value,...l.url?{[be.url]:l.url}:{},[be.model]:l.defaultModel||(p&&E.includes(p)?p:E[0]||p)};ie(R=>({...R,configuration:T})),It(B,be.provider,l.value,T)},[Je,B,be,ve,ie,It]),Nr=e.useCallback(a=>{if(!B)return;const l=Je(),c=String(l[be.provider]??"");if(a===he&&!(a==="custom"&&c!=="custom")||(xe(a),a!=="custom"))return;Le(""),se([]);const E={...l,[be.provider]:"custom",[be.url]:"",[be.model]:""};ie(p=>({...p,configuration:E})),c!=="custom"&&It(B,be.provider,"custom",E)},[Je,B,be,he,ie,It]),Aa=e.useCallback(a=>bn(a)||a.name===be.model&&Se.length>0,[be.model,Se.length]),Oa=a=>{Fe(l=>({...l,[a]:[...l[a]||[],{key:"",value:""}]}))},Fa=(a,l)=>{h(()=>{Fe(c=>({...c,[a]:c[a].filter((E,p)=>p!==l)}))})},wr=(a,l,c,E)=>{Fe(p=>({...p,[a]:p[a].map((T,R)=>R===l?{...T,[c]:E}:T)}))},Ba=(a,l)=>{h(()=>{ft(c=>({...c,[a]:c[a].filter((E,p)=>p!==l)}))})},Xt=e.useCallback((a,l)=>{const c=v.parseSimpleArrayInput(l);c.length>0&&ft(E=>({...E,[a]:[...E[a]||[],...c.map(p=>({value:p}))]})),te(E=>({...E,[a]:""}))},[ft]),ja=e.useCallback((a,l)=>{if(/[,,;;\n\t]/.test(l)){Xt(a,l);return}te(c=>({...c,[a]:l}))},[Xt]),Ha=e.useCallback((a,l)=>{["Enter",",",",",";",";","Tab"].includes(l.key)&&(l.key!=="Tab"&&l.preventDefault(),Xt(a,Y[a]||""))},[Y,Xt]),Wa=e.useCallback((a,l)=>{const c=l.clipboardData.getData("text");c&&(l.preventDefault(),Xt(a,Y[a]||""),Xt(a,c))},[Y,Xt]),Ua=e.useCallback(a=>{h(()=>{ft(l=>({...l,[a]:[]})),te(l=>({...l,[a]:""}))})},[h,ft]),Va=e.useCallback((a,l,c)=>{l!==c&&ft(E=>{const p=[...E[a]||[]];if(l<0||c<0||l>=p.length||c>=p.length)return E;const[T]=p.splice(l,1);return p.splice(c,0,T),{...E,[a]:p}})},[ft]),xn=e.useCallback((a,l)=>{ie(c=>{const E={...c.configuration};return E[a]=l(v.normalizeToolRows(E[a])),{...c,configuration:E}})},[ie]),yt=e.useCallback(a=>{Ye(l=>l&&{...l,...a})},[]),er=e.useCallback(a=>{Ye(l=>l&&{...l,draft:{...l.draft,...a},error:""})},[]),pn=e.useCallback((a,l)=>{Ye(c=>{if(!c)return c;const E=c.draft.config&&typeof c.draft.config=="object"&&!Array.isArray(c.draft.config)?c.draft.config:{};return{...c,draft:{...c.draft,config:{...E,[a]:l}},error:""}})},[]),Qt=e.useCallback(a=>{Ye(l=>l&&{...l,schemaRows:a,parametersText:JSON.stringify(v.generateToolSchemaFromRows(a),null,2),error:""})},[]),Sr=e.useCallback(a=>{Ye(l=>{if(!l||l.schemaMode===a)return l;if(a==="code")return{...l,schemaMode:"code",parametersText:JSON.stringify(v.generateToolSchemaFromRows(l.schemaRows),null,2),error:""};try{return{...l,schemaMode:"visual",schemaRows:v.parseToolSchemaRows(v.parseJsonObjectText(l.parametersText||"{}")),error:""}}catch(c){return{...l,error:d("editor.property.parametersJsonInvalid",`参数定义 JSON 格式错误: ${(c==null?void 0:c.message)||String(c)}`,{message:String((c==null?void 0:c.message)||c)})}}})},[d]),rn=e.useCallback((a,l,c)=>{if(!z)return;const E=v.updateSchemaRowsAtParent(z.schemaRows,a,p=>{p[l]&&(p[l]={...p[l],...c,properties:c.type&&c.type!=="object"?[]:p[l].properties,itemsProperties:c.type&&c.type!=="array"?[]:p[l].itemsProperties})});Qt(E)},[Qt,z]),xr=e.useCallback((a="")=>{if(!z)return;const l=v.updateSchemaRowsAtParent(z.schemaRows,a,c=>{c.push(v.emptySchemaEditorRow($o(c)+1))});Qt(l)},[Qt,z]),qa=e.useCallback((a,l)=>{z&&h(()=>{const c=v.updateSchemaRowsAtParent(z.schemaRows,a,E=>{E.splice(l,1);const p=v.renumberSchemaRowOrders(E);E.splice(0,E.length,...p)});Qt(c)})},[h,Qt,z]),Tr=e.useCallback((a,l,c)=>{z&&Qt(Ao(z.schemaRows,a,l,c))},[Qt,z]),gn=e.useCallback(a=>v.normalizeToolRows((q.configuration||{})[a]),[q.configuration]),Rr=e.useCallback((a,l=-1)=>{const c=Vr(a),E=gn(a.name),p=l>=0?E[l]:null,T=v.stringifyToolJson(p==null?void 0:p.parameters,"{}");let R=[];try{R=v.parseToolSchemaRows(v.parseJsonObjectText(T))}catch{R=[]}Ye({fieldName:a.name,mode:c,step:l>=0?"config":"select",activeTab:String((p==null?void 0:p.type)||"builtin")||"builtin",editIndex:l,keyword:"",page:1,ruleChainPage:1,schemaMode:"visual",schemaRows:R,parametersText:T,draft:p?{...p}:{type:"builtin",parameters:"{}"},error:""}),lt(_n(Oe)),Cr()},[Oe,gn,Cr]),Tn=e.useCallback(()=>{Ye(null),Pt("")},[]),Rn=e.useCallback((a,l,c)=>gn(a).some((E,p)=>p!==c&&String(E.type||"")==="builtin"&&vn(E)===l),[gn]),In=e.useCallback((a,l,c)=>gn(a).some((E,p)=>p!==c&&String(E.type||"")==="rulechain"&&String(E.targetId||"")===l),[gn]),Ja=e.useCallback(a=>{if(!z)return;if(Rn(z.fieldName,a.value,z.editIndex)){yt({error:d("editor.property.builtinToolAlreadyAdded","该内置工具已添加")});return}const l={};a.fields.forEach(E=>{const p=String((E==null?void 0:E.name)||"");p&&E.defaultValue!==void 0&&(l[p]=Cn(E.defaultValue))});const c={type:"builtin",name:a.value,targetId:a.value,description:a.desc||"",parameters:JSON.stringify(a.parameters||{},null,2),config:l};if(z.mode==="tool"&&a.fields.length===0){xn(z.fieldName,E=>[...E,c]),Ye(null);return}Ye(E=>E&&{...E,step:"config",activeTab:"builtin",draft:c,parametersText:JSON.stringify(a.parameters||{},null,2),schemaRows:v.parseToolSchemaRows(a.parameters||{}),schemaMode:"visual",error:""})},[Rn,yt,z,d,xn]),Ir=e.useCallback(a=>{if(!z)return;if(In(z.fieldName,a.value,z.editIndex)){yt({error:d("editor.property.ruleChainAlreadyAdded","该规则链已添加")});return}const l=Mo(a.raw);tt(c=>Vn(c,[a])),Ye(c=>c&&{...c,step:"config",activeTab:"rulechain",draft:{type:"rulechain",targetId:a.value,name:a.label,description:a.description||"",parameters:l},parametersText:l,schemaRows:v.parseToolSchemaRows(v.parseJsonObjectText(l)),schemaMode:"visual",error:""})},[In,yt,z,d]),Ka=e.useCallback(()=>{Ye(a=>a&&{...a,step:"config",activeTab:"custom",draft:{type:"custom",name:"",targetId:"",description:"",parameters:"{}",config:{}},parametersText:"{}",schemaRows:[],schemaMode:"visual",error:""})},[]),za=e.useCallback(()=>{if(!z)return;const a=String(z.draft.type||z.activeTab||"custom"),l=String(z.draft.name||"").trim(),c=String(z.draft.targetId||"").trim(),E=String(z.draft.description||z.draft.desc||"").trim();let p=z.parametersText||"{}";if(z.mode==="tool"&&a!=="builtin")if(z.schemaMode==="visual")p=JSON.stringify(v.generateToolSchemaFromRows(z.schemaRows),null,2);else try{v.parseJsonObjectText(p||"{}")}catch(x){yt({error:d("editor.property.parametersJsonInvalid",`参数定义 JSON 格式错误: ${(x==null?void 0:x.message)||String(x)}`,{message:String((x==null?void 0:x.message)||x)})});return}if(a==="rulechain"&&!c){yt({error:d("editor.property.ruleChainRequired","规则链是必须的")});return}if(a==="rulechain"&&In(z.fieldName,c,z.editIndex)){yt({error:d("editor.property.ruleChainAlreadyAdded","该规则链已添加")});return}if(a==="builtin"&&Rn(z.fieldName,l,z.editIndex)){yt({error:d("editor.property.builtinToolAlreadyAdded","该内置工具已添加")});return}if(a!=="rulechain"&&!l){const x=z.mode==="subagent"?d("editor.property.agentName","智能体名称"):d("editor.property.toolName","工具名称");yt({error:d("editor.property.nameRequired",`${x}是必须的`,{name:x})});return}const T={...z.draft,type:a,name:a==="rulechain"?l||c:l,targetId:a==="rulechain"?c:c||l,description:E};z.mode==="tool"&&(T.parameters=a==="builtin"?v.stringifyToolJson(T.parameters,"{}"):p);const R=T.config&&typeof T.config=="object"&&!Array.isArray(T.config)?T.config:{};Object.keys(R).length>0?T.config=R:delete T.config,xn(z.fieldName,x=>{const G=[...x];return z.editIndex>=0?G[z.editIndex]=T:G.push(T),G}),Ye(null)},[Rn,In,yt,z,d,xn]),Ga=e.useCallback(()=>{D==null||D({section:"skills"}),window.dispatchEvent(new CustomEvent("rulego-editor:openAiAssistant",{detail:{section:"skills"}})),Tn()},[Tn,D]),Pr=(a=!0)=>{if(!n)return null;const l=gt.current;let c={...l.configuration};if(Ue.length===0)try{c=v.parseUnknownConfiguration(ue),a&&Pe("")}catch(T){return a&&Pe(T instanceof Error?T.message:String(T)),null}const E=new Map(Ue.map(T=>[T.name,T]));if(Be!=null&&Be.name&&(L==="shared"?c[Be.name]=we.trim():String(c[Be.name]??"").startsWith("ref://")&&(c[Be.name]="")),B&&he==="preset"&&Ee){c[be.provider]=Ee;const T=ve.find(R=>R.value===Ee);T!=null&&T.url&&(c[be.url]=T.url),T!=null&&T.defaultModel&&!c[be.model]&&(c[be.model]=T.defaultModel)}Object.entries(je.current).forEach(([T,R])=>{const x=E.get(T);if(!x||!on(x))return;const G={},Q=v.getMapValueMode(x);R.forEach(ce=>{ce.key&&(G[ce.key]=v.parseMapEntryValue(ce.value,Q))}),c[T]=G}),Object.entries(nt.current).forEach(([T,R])=>{const x=E.get(T);!x||!Yt(x)||En(x,c[T])||hn(x)||(c[T]=R.map(G=>G.value).filter(Boolean))}),c=v.sanitizeConfigurationByFields(c,Ue);const p=v.validateComponentFields(Ue,c);return p.length>0?(a&&Rt(p.map(T=>`${T.field}: ${T.message}`).join(`
4
- `)),null):v.normalizeEditableNodeModel(n,{name:l.name,debugMode:l.debugMode,configuration:c,additionalInfo:l.additionalInfo},{graphNodeId:n.id||n.nodeId||l.id,nodeViewType:r==null?void 0:r.type,graphNodeType:n.type,keepNodeId:!0})},Dr=async()=>{for(;re.current.size>0;)await Promise.all([...re.current.values()]);const a=Object.entries(fe.current).filter(([c])=>ye.current.has(c)||[...Ce.current].some(E=>yn(E,c)));if(a.length>0)return Rt(d("editor.property.fieldChangeFailedMessage","关联字段更新失败: {{message}}",{message:a.map(([,c])=>c).join("; ")})),!1;const l=Pr(!0);if(!l)return!1;try{return Rt(""),await o(l),qt.current=JSON.stringify(l),!0}catch(c){return Rt(c instanceof Error?c.message:String(c)),!1}},tr=()=>s(),nr=async()=>{const a=Pr(!1);if(!(!a||JSON.stringify(a)!==qt.current)){tr();return}const c=await v.confirmDrawerUnsavedClose({t:E=>d(E,E)});c==="discard"&&tr(),c==="save"&&await Dr()&&tr()},_t=a=>tn(a.desc)?e.createElement("span",{className:"rge-field-desc"},tn(a.desc)):null,Bn=a=>{const l=[...re.current.keys()].some(E=>yn(a,E)),c=Object.entries(At).filter(([E])=>yn(a,E));return e.createElement(e.Fragment,null,l&&e.createElement("span",{className:"rge-field-desc",role:"status"},d("editor.property.fieldChangeLoading","正在更新关联字段...")),c.map(([E,p])=>e.createElement("span",{key:E,className:"rge-field-error",role:"alert"},p)))},Lr=a=>{if(L==="shared"&&(a.ref==="primary"||a.ref==="shared")||B&&a.name===B.name)return null;const l=nn.get(a.name)||[],c=vt[a.name];return e.createElement("div",{key:a.name,className:"rge-form-section"},e.createElement("div",{className:"rge-field-label-row"},e.createElement("label",{className:"rge-form-label"},K(a)),l.length>0&&e.createElement("button",{type:"button",className:"rge-field-attachment-button",title:d("editor.property.configureAttached","配置附加参数"),"aria-label":d("editor.property.configureAttached","配置附加参数"),onClick:()=>Tt(a.name)},e.createElement(pe,{value:"settings"}))),$r(a),(c==null?void 0:c.loading)&&e.createElement("span",{className:"rge-field-desc"},d("editor.property.loadingOptions","正在加载选项...")),(c==null?void 0:c.error)&&e.createElement("span",{className:"rge-field-error"},c.error),Bn(a.name))},Ya=()=>Be?e.createElement("div",{className:"rge-form-section rge-ref-mode-section"},e.createElement("label",{className:"rge-form-label"},d("editor.form.connectionMode","连接方式")),e.createElement("div",{className:"rge-segmented-control",role:"radiogroup","aria-label":d("editor.form.connectionMode","连接方式")},e.createElement("button",{type:"button",className:`rge-segmented-option${L==="custom"?" active":""}`,role:"radio","aria-checked":L==="custom",onClick:()=>kr("custom")},d("editor.form.customConnection","自定义连接")),e.createElement("button",{type:"button",className:`rge-segmented-option${L==="shared"?" active":""}`,role:"radio","aria-checked":L==="shared",onClick:()=>kr("shared")},d("editor.form.sharedConnection","共享连接"))),L==="shared"&&e.createElement("div",{className:"rge-ref-shared-picker"},e.createElement(zt,{name:"sharedRef",value:we,options:dt,allowCreate:!0,threshold:0,placeholder:d("editor.form.sharedConnectionPlaceholder","选择或输入 ref:// 共享连接"),...S,onChange:Ma})),e.createElement("span",{className:"rge-field-desc"},d("editor.form.sharedConnectionDesc","共享连接会写入 ref:// 引用,自定义连接会直接写入服务地址。")),Bn(Be.name)):null,Xa=()=>B?e.createElement("div",{className:"rge-form-section rge-provider-mode-section"},e.createElement("label",{className:"rge-form-label"},B.label||d("editor.form.aiProvider","AI服务商")),e.createElement("div",{className:"rge-segmented-control",role:"radiogroup","aria-label":d("editor.form.aiProvider","AI服务商")},e.createElement("button",{type:"button",className:`rge-segmented-option${he==="custom"?" active":""}`,role:"radio","aria-checked":he==="custom",onClick:()=>Nr("custom")},d("editor.form.customProvider","自定义供应商")),e.createElement("button",{type:"button",className:`rge-segmented-option${he==="preset"?" active":""}`,role:"radio","aria-checked":he==="preset",onClick:()=>Nr("preset")},d("editor.form.presetProvider","预设供应商"))),he==="preset"&&e.createElement("div",{className:"rge-provider-picker"},e.createElement(zt,{name:"provider",value:Ee,options:ve.map(a=>({label:a.label,value:a.value,description:a.url})),threshold:0,placeholder:d("editor.form.providerPlaceholder","选择AI供应商"),...S,onChange:$a})),e.createElement("span",{className:"rge-field-desc"},d("editor.form.providerDesc","预设供应商会自动填充 API 地址和模型,自定义供应商保留手工填写。")),Bn(be.provider)):null,Qa=(a,l)=>{const c=String(a||"").toLowerCase();return c==="rulechain"?d("editor.property.ruleChain","规则链"):c==="builtin"?d("editor.property.builtinTool","内置工具"):c==="subagent"?d("editor.property.subagent","子智能体"):c==="custom"?l==="subagent"?d("editor.property.customAgent","自定义智能体"):d("editor.property.custom","自定义"):String(a||"-")},Za=a=>{const l=String(a.name||"");if(!l||!z)return null;const c=String(a.label||l),E=a.component&&typeof a.component=="object"?a.component:{},p=String(E.type||a.type||"").toLowerCase(),R=(z.draft.config&&typeof z.draft.config=="object"&&!Array.isArray(z.draft.config)?z.draft.config:{})[l]??a.defaultValue??"";if(p==="select"){const de=fr(Array.isArray(E.options)?E.options:[],R);return e.createElement("label",{key:l,className:"rge-tool-config-field"},e.createElement("span",null,c),e.createElement(zt,{name:`tool-config-${l}`,value:String(R??""),options:de,placeholder:String(E.placeholder||""),...S,onChange:We=>pn(l,We)}))}if(p==="switch"||a.type==="bool"||a.type==="boolean")return e.createElement("label",{key:l,className:"rge-tool-config-field rge-tool-config-switch"},e.createElement("span",null,c),e.createElement("label",{className:"rge-switch-toggle"},e.createElement("input",{type:"checkbox",checked:!!R,onChange:de=>pn(l,de.target.checked)}),e.createElement("span",{className:"rge-switch-slider"})));const x=String(a.type||"").toLowerCase();if(["map","array","struct","object","json"].includes(x)||["map","array","struct","object","json","json-editor"].includes(p))return e.createElement("label",{key:l,className:"rge-tool-config-field rge-tool-config-field-wide"},e.createElement("span",null,c),e.createElement("textarea",{className:"rge-form-textarea",rows:4,value:Wr(R),spellCheck:!1,onChange:de=>{const We=x==="array"||p==="array"?[]:{};try{pn(l,de.target.value?JSON.parse(de.target.value):We)}catch{pn(l,de.target.value)}}}));if(p==="textarea")return e.createElement("label",{key:l,className:"rge-tool-config-field"},e.createElement("span",null,c),e.createElement("textarea",{className:"rge-form-textarea",rows:2,value:String(R??""),onChange:de=>pn(l,de.target.value)}));const Q=p==="input-number"||p==="number"||x==="number"||da(String(a.type||"")),ce=p==="password"||x==="password"||Pn({name:l,type:x,component:E})?"password":p==="date"||p==="datepicker"?"date":p==="time"||p==="timepicker"?"time":p==="datetime"||p==="datetimepicker"||p==="datetime-local"?"datetime-local":Q?"number":"text";return e.createElement("label",{key:l,className:"rge-tool-config-field"},e.createElement("span",null,c),e.createElement("input",{className:"rge-form-input",type:ce,value:String(R??""),placeholder:String(E.placeholder||(p==="duration"||x==="duration"?"1s / 5m / 2h":"")),autoComplete:ce==="password"?"new-password":void 0,onChange:de=>pn(l,Q?Number(de.target.value||0):de.target.value)}))},Mr=(a,l="")=>e.createElement("div",{className:"rge-tool-schema-rows"},a.length===0?e.createElement("div",{className:"rge-tool-schema-empty"},d("editor.property.noSchemaProperties","暂无属性,点击下方按钮添加")):a.map((c,E)=>{const p=l?`${l}.${E}`:String(E),T=c.type==="array"?`${p}.items`:p,R=c.type==="array"?c.itemsProperties:c.properties;return e.createElement("div",{key:p,className:"rge-tool-schema-row-wrap"},e.createElement("div",{className:"rge-tool-schema-row"},e.createElement("input",{className:"rge-form-input",value:c.name,placeholder:d("editor.property.propertyName","属性名"),onChange:x=>rn(l,E,{name:x.target.value})}),e.createElement("input",{className:"rge-form-input",value:c.title,placeholder:d("editor.property.title","标题"),onChange:x=>rn(l,E,{title:x.target.value})}),e.createElement("input",{className:"rge-form-input",value:c.description,placeholder:d("editor.property.description","描述"),onChange:x=>rn(l,E,{description:x.target.value})}),e.createElement("select",{className:"rge-form-select",value:c.type,onChange:x=>rn(l,E,{type:x.target.value})},v.TOOL_SCHEMA_TYPES.map(x=>e.createElement("option",{key:x,value:x},x))),e.createElement("input",{className:"rge-form-input",type:"number",min:0,value:c.order,onChange:x=>rn(l,E,{order:Number(x.target.value||E+1)})}),e.createElement("label",{className:"rge-inline-checkbox rge-tool-schema-required"},e.createElement("input",{type:"checkbox",checked:c.required,onChange:x=>rn(l,E,{required:x.target.checked})}),e.createElement("span",null,d("editor.property.required","必填"))),e.createElement("div",{className:"rge-tool-schema-actions"},e.createElement("button",{type:"button",title:d("editor.property.moveUp","上移"),onClick:()=>Tr(l,E,-1)},"↑"),e.createElement("button",{type:"button",title:d("editor.property.moveDown","下移"),onClick:()=>Tr(l,E,1)},"↓"),e.createElement("button",{type:"button",className:"danger",onClick:()=>qa(l,E)},"×"))),c.type==="array"&&e.createElement("div",{className:"rge-tool-schema-nested-head"},e.createElement("span",null,d("editor.property.itemType","项目类型")),e.createElement("select",{className:"rge-form-select",value:c.itemsType||"string",onChange:x=>rn(l,E,{itemsType:x.target.value})},v.TOOL_SCHEMA_ITEM_TYPES.map(x=>e.createElement("option",{key:x,value:x},x)))),(c.type==="object"||c.type==="array")&&e.createElement("div",{className:"rge-tool-schema-nested"},e.createElement("div",{className:"rge-tool-schema-nested-title"},c.type==="array"?d("editor.property.arrayItems","数组项目"):d("editor.property.childProperties","子属性"),c.name?`: ${c.name}`:""),c.type==="array"&&c.itemsType!=="object"?e.createElement("div",{className:"rge-tool-schema-empty rge-tool-schema-nested-empty"},d("editor.property.arrayNonObject","当前数组项目不是 object,无需配置项目属性。")):e.createElement(e.Fragment,null,Mr(R||[],T),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>xr(T)},c.type==="array"?d("editor.property.addItemProperty","添加项目属性"):d("editor.property.addChildProperty","添加子属性")))))})),eo=(a,l)=>{const c=v.normalizeToolRows(l),E=Vr(a),p=E==="subagent"?d("editor.property.noSubagents","暂无子智能体"):d("editor.property.noTools","暂无工具");return e.createElement("div",{className:"rge-tools-editor"},e.createElement("div",{className:"rge-tools-toolbar"},e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Rr(a)},E==="subagent"?d("editor.property.addSubagent","添加子智能体"):d("editor.property.addTool","添加工具"))),e.createElement("div",{className:"rge-tools-table-wrap"},e.createElement("table",{className:"rge-tools-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,d("editor.property.name","名称")),e.createElement("th",null,d("editor.property.type","类型")),e.createElement("th",null,d("editor.property.description","描述")),e.createElement("th",{className:"rge-tools-operations"},d("editor.property.operate","操作")))),e.createElement("tbody",null,c.length===0?e.createElement("tr",null,e.createElement("td",{colSpan:4,className:"rge-tools-empty"},p)):c.map((T,R)=>{const x=String(T.type||"custom");return e.createElement("tr",{key:R},e.createElement("td",{title:vn(T)},vn(T)||"-"),e.createElement("td",null,e.createElement("span",{className:`rge-tool-type rge-tool-type-${x.toLowerCase()}`},Qa(x,E))),e.createElement("td",{title:Gr(T)},or(Gr(T),80)),e.createElement("td",{className:"rge-tools-actions"},Lo(T,E,Ht)&&e.createElement("button",{type:"button",className:"rge-tool-action-button",title:d("editor.property.edit","编辑"),"aria-label":d("editor.property.edit","编辑"),onClick:()=>Rr(a,R)},"✎"),e.createElement("button",{type:"button",className:"rge-tool-action-button danger",title:d("editor.property.delete","删除"),"aria-label":d("editor.property.delete","删除"),onClick:()=>h(()=>{xn(a.name,G=>G.filter((Q,ce)=>ce!==R))})},"×")))})))),_t(a))},to=()=>{if(!z)return null;const a=z.editIndex>=0,l=z.mode,c=String(z.draft.type||z.activeTab||"builtin"),E=Ht.find(Ie=>Ie.value===vn(z.draft)),p=c==="builtin"?(E==null?void 0:E.fields)||[]:[],T=c==="builtin"&&vn(z.draft)==="skill",R=He||(E==null?void 0:E.defaultGlobalDir)||d("editor.property.notConfigured","未配置"),x=z.keyword.trim().toLowerCase(),G=Ht.filter(Ie=>x?Ie.value.toLowerCase().includes(x)||Ie.label.toLowerCase().includes(x)||Ie.desc.toLowerCase().includes(x):!0),Q=Math.max(1,Math.ceil(G.length/Oe)),ce=Math.min(Math.max(1,z.page),Q),de=G.slice((ce-1)*Oe,ce*Oe),We=St(),$e=Nt.items.map(lr).filter(Boolean),it=sr([...$e,...We]),Ut=z.keyword.trim().toLowerCase(),Jt=Xe?it:it.filter(Ie=>Ut?Ie.label.toLowerCase().includes(Ut)||Ie.value.toLowerCase().includes(Ut)||String(Ie.description||"").toLowerCase().includes(Ut):!0),ze=Xe?Nt.total:Jt.length,Ge=Math.max(1,Math.ceil(ze/Oe)),ot=Math.min(Math.max(1,z.ruleChainPage),Ge),Zt=Xe?Jt:Jt.slice((ot-1)*Oe,ot*Oe),rr=z.step==="select"?l==="subagent"?d("editor.property.selectSubagent","选择子智能体"):d("editor.property.selectTool","选择工具"):a?l==="subagent"?d("editor.property.editSubagent","编辑子智能体"):d("editor.property.editTool","编辑工具"):l==="subagent"?d("editor.property.configSubagent","配置子智能体"):d("editor.property.configTool","配置工具");return e.createElement("div",{className:"rge-tools-modal",onClick:Tn},e.createElement("div",{className:"rge-tools-modal-panel",role:"dialog","aria-modal":"true",onClick:Ie=>Ie.stopPropagation()},e.createElement("div",{className:"rge-tools-modal-header"},e.createElement("strong",null,rr),e.createElement("button",{type:"button",className:"rge-rule-chain-modal-close",onClick:Tn},"×")),e.createElement("div",{className:"rge-tools-modal-body"},z.step==="select"?e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-rule-chain-modal-tabs rge-tool-selector-tabs"},["builtin","rulechain","custom"].map(Ie=>e.createElement("button",{key:Ie,type:"button",className:z.activeTab===Ie?"active":"",onClick:()=>yt({activeTab:Ie,keyword:"",page:1,ruleChainPage:1,error:""})},Ie==="builtin"?d("editor.property.builtinTool","内置工具"):Ie==="rulechain"?d("editor.property.ruleChain","规则链"):l==="subagent"?d("editor.property.customAgent","自定义智能体"):d("editor.property.custom","自定义")))),z.activeTab!=="custom"&&e.createElement("input",{type:"search",className:"rge-rule-chain-modal-search",value:z.keyword,placeholder:z.activeTab==="builtin"?d("editor.property.searchTools","搜索工具..."):d("editor.property.searchRuleChains","搜索规则链..."),onChange:Ie=>yt({keyword:Ie.target.value,page:1,ruleChainPage:1})}),z.activeTab==="builtin"&&e.createElement("div",{className:"rge-tool-card-grid"},Vt?e.createElement("div",{className:"rge-tools-empty"},d("editor.panel.loading","加载中...")):jt?e.createElement("div",{className:"rge-tools-empty"},jt):de.length===0?e.createElement("div",{className:"rge-tools-empty"},d("editor.property.noMatchingOptions","没有匹配的选项")):de.map(Ie=>{const Kt=Rn(z.fieldName,Ie.value,z.editIndex);return e.createElement("button",{key:Ie.value,type:"button",className:`rge-tool-card${Kt?" disabled":""}`,disabled:Kt,onClick:()=>Ja(Ie)},e.createElement("span",{className:"rge-tool-card-icon builtin"},e.createElement(pe,{value:"settings"})),e.createElement("span",{className:"rge-tool-card-content"},e.createElement("strong",null,Ie.label),e.createElement("small",null,or(Ie.desc||d("editor.property.noDescription","暂无描述"),96))),e.createElement("span",{className:"rge-tool-card-action"},Kt?d("editor.property.added","已添加"):"+"))})),z.activeTab==="rulechain"&&e.createElement("div",{className:"rge-tool-card-grid"},Nt.loading&&Xe?e.createElement("div",{className:"rge-tools-empty"},d("editor.panel.loading","加载中...")):Nt.error&&Xe?e.createElement("div",{className:"rge-tools-empty"},Nt.error):Zt.length===0?e.createElement("div",{className:"rge-tools-empty"},d("editor.property.noMatchingOptions","没有匹配的选项")):Zt.map(Ie=>{const Kt=In(z.fieldName,Ie.value,z.editIndex);return e.createElement("button",{key:Ie.value,type:"button",className:`rge-tool-card${Kt?" disabled":""}`,disabled:Kt,onClick:()=>Ir(Ie)},e.createElement("span",{className:"rge-tool-card-icon rulechain"},e.createElement(pe,{value:"link"})),e.createElement("span",{className:"rge-tool-card-content"},e.createElement("strong",null,Ie.label),e.createElement("small",null,or(Ie.description||Ie.value,96))),e.createElement("span",{className:"rge-tool-card-action"},Kt?d("editor.property.added","已添加"):"+"))})),z.activeTab==="custom"&&e.createElement("div",{className:"rge-tool-custom-start"},e.createElement("button",{type:"button",className:"rge-tool-card rge-tool-card-wide",onClick:Ka},e.createElement("span",{className:"rge-tool-card-icon custom"},"+"),e.createElement("span",{className:"rge-tool-card-content"},e.createElement("strong",null,l==="subagent"?d("editor.property.customAgent","自定义智能体"):d("editor.property.custom","自定义")),e.createElement("small",null,d("editor.property.customToolDesc","手工填写名称、描述和参数定义。")))))):e.createElement("div",{className:"rge-tool-configurator"},e.createElement("div",{className:"rge-tool-config-grid"},c==="rulechain"&&e.createElement("label",{className:"rge-tool-config-field rge-tool-config-field-wide"},e.createElement("span",null,d("editor.property.ruleChain","规则链")),e.createElement(zt,{name:"tool-rulechain",value:String(z.draft.targetId||""),options:it.map(Ie=>({label:Ie.label,value:Ie.value,description:Ie.description})),placeholder:d("editor.form.selectRuleChain","请选择规则链"),...S,onChange:Ie=>{const Kt=it.find(so=>so.value===Ie);Kt?Ir(Kt):er({targetId:Ie})}})),e.createElement("label",{className:"rge-tool-config-field"},e.createElement("span",null,l==="subagent"?d("editor.property.agentName","智能体名称"):d("editor.property.toolName","工具名称")),e.createElement("input",{className:"rge-form-input",value:String(z.draft.name||""),disabled:c==="builtin",onChange:Ie=>er({name:Ie.target.value})})),e.createElement("label",{className:"rge-tool-config-field rge-tool-config-field-wide"},e.createElement("span",null,d("editor.property.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",rows:2,value:String(z.draft.description||z.draft.desc||""),onChange:Ie=>er({description:Ie.target.value})}))),T&&e.createElement("div",{className:"rge-skill-tool-helper"},e.createElement("span",null,d("editor.property.autoLoadSkillDir","自动加载全局技能目录({{dir}})",{dir:R})),e.createElement("button",{type:"button",onClick:Ga},d("editor.property.manageSkills","管理技能"))),l==="tool"&&c==="builtin"&&p.length>0&&e.createElement("div",{className:"rge-tool-config-section"},e.createElement("div",{className:"rge-tool-config-section-title"},d("editor.property.initConfig","初始化配置")),e.createElement("div",{className:"rge-tool-config-grid"},p.map(Ie=>Za(Ie)))),l==="tool"&&c!=="builtin"&&e.createElement("div",{className:"rge-tool-config-section"},e.createElement("div",{className:"rge-tool-config-section-title"},d("editor.property.parameters","参数定义")),e.createElement("div",{className:"rge-segmented-control rge-tool-schema-mode",role:"radiogroup"},e.createElement("button",{type:"button",className:`rge-segmented-option${z.schemaMode==="visual"?" active":""}`,onClick:()=>Sr("visual")},d("editor.property.visualMode","可视化")),e.createElement("button",{type:"button",className:`rge-segmented-option${z.schemaMode==="code"?" active":""}`,onClick:()=>Sr("code")},d("editor.property.codeMode","JSON代码"))),z.schemaMode==="visual"?e.createElement("div",{className:"rge-tool-schema-editor"},Mr(z.schemaRows),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>xr("")},d("editor.property.addProperty","添加属性"))):e.createElement("textarea",{className:"rge-code-textarea rge-tool-schema-code",rows:12,value:z.parametersText,spellCheck:!1,onChange:Ie=>yt({parametersText:Ie.target.value,error:""})}))),z.error&&e.createElement("div",{className:"rge-tools-error"},z.error)),e.createElement("div",{className:"rge-tools-modal-footer"},z.step==="select"?e.createElement("div",{className:"rge-tools-pagination"},z.activeTab==="builtin"&&G.length>0&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",disabled:ce<=1,onClick:()=>yt({page:Math.max(1,ce-1)})},d("editor.property.prevPage","上一页")),e.createElement("span",null,d("editor.property.pageInfo",`第 ${ce}/${Q} 页,共 ${G.length} 条`,{page:ce,pages:Q,total:G.length})),e.createElement("button",{type:"button",disabled:ce>=Q,onClick:()=>yt({page:Math.min(Q,ce+1)})},d("editor.property.nextPage","下一页"))),z.activeTab==="rulechain"&&ze>0&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",disabled:ot<=1||Nt.loading,onClick:()=>yt({ruleChainPage:Math.max(1,ot-1)})},d("editor.property.prevPage","上一页")),e.createElement("span",null,d("editor.property.pageInfo",`第 ${ot}/${Ge} 页,共 ${ze} 条`,{page:ot,pages:Ge,total:ze})),e.createElement("button",{type:"button",disabled:ot>=Ge||Nt.loading,onClick:()=>yt({ruleChainPage:Math.min(Ge,ot+1)})},d("editor.property.nextPage","下一页")))):e.createElement("div",{className:"rge-tools-modal-actions"},!a&&e.createElement("button",{type:"button",onClick:()=>yt({step:"select",error:""})},d("editor.property.back","返回选择")),e.createElement("button",{type:"button",onClick:Tn},d("editor.panel.cancel","取消")),e.createElement("button",{type:"button",className:"primary",onClick:za},d("editor.panel.confirm","确认"))))))},no=(a,l,c,E)=>e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-rule-chain-picker"},e.createElement("input",{type:"text",className:"rge-form-input rge-rule-chain-picker-display",value:at(a,l),placeholder:E||d("editor.form.selectRuleChain","请选择规则链"),disabled:c,readOnly:!0,onClick:()=>{c||dn(a,l)}}),e.createElement("button",{type:"button",className:"rge-rule-chain-picker-button",disabled:c,title:d("editor.form.selectRuleChain","选择规则链"),onClick:()=>dn(a,l)},d("editor.property.search","搜索"))),_t(a)),jn=(a,l,c,E)=>{var G,Q,ce,de,We;const p=a||{name:"value",type:"string"},T=!!(p.disabled||(G=p.component)!=null&&G.disabled),R=((Q=p.component)==null?void 0:Q.placeholder)||p.label||p.name,x=$e=>{const it=c($e);It(p,E||p.name,$e,it)};if(bn(p)){const $e=ct(p,l),it=!!((ce=p.component)!=null&&ce.multiple),Ut=Array.isArray(l)?l.map(Jt=>String(Jt??"")).filter(Boolean):String(l??"").split(",").map(Jt=>Jt.trim()).filter(Boolean);return e.createElement(zt,{name:E||p.name,value:String(l??""),values:it?Ut:void 0,multiple:it,allowCreate:!!((de=p.component)!=null&&de.allowCreate),disabled:T,options:$e,placeholder:R,...S,onChange:x,onMultiChange:x})}if(Yn(p))return e.createElement("label",{className:"rge-inline-checkbox"},e.createElement("input",{type:"checkbox",checked:!!l,disabled:T,onChange:$e=>x($e.target.checked)}),e.createElement("span",null,p.label||p.name));if(Xn(p)){const $e=gr(p.type)||$t(p)==="number";return e.createElement("input",{type:"number",className:"rge-form-input",step:$e?"0.01":void 0,value:String(l??""),disabled:T,placeholder:R,onChange:it=>x(wo(p,it.target.value))})}if(Jr(p))return e.createElement("textarea",{className:"rge-form-textarea rge-expression-editor",rows:2,value:String(l??""),disabled:T,placeholder:d("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,onChange:$e=>x($e.target.value)});if(Hr(p)||Wn(p))return e.createElement("textarea",{className:Wn(p)?"rge-code-textarea":"rge-form-textarea",rows:Wn(p)?6:3,value:typeof l=="object"&&l!==null?JSON.stringify(l,null,2):String(l??""),disabled:T,placeholder:R,spellCheck:!1,onChange:$e=>x($e.target.value)});if(Kr(p)){const it=bt(p).startsWith("time")?"time":"date";return e.createElement("input",{type:it,className:"rge-form-input",value:String(l??""),disabled:T,placeholder:R,onChange:Ut=>x(Ut.target.value)})}return zr(p)?e.createElement("input",{type:"text",className:"rge-form-input rge-duration-input",value:String(l??""),disabled:T,placeholder:((We=p.component)==null?void 0:We.placeholder)||"10s / 1m",onChange:$e=>x($e.target.value)}):qr(p)||Yt(p)||on(p)?e.createElement("textarea",{className:"rge-form-textarea rge-json-inline-editor",rows:4,value:typeof l=="object"&&l!==null?JSON.stringify(l,null,2):String(l??""),disabled:T,placeholder:R,spellCheck:!1,onChange:$e=>{try{x($e.target.value?JSON.parse($e.target.value):Yt(p)?[]:{})}catch{x($e.target.value)}}}):e.createElement("input",{type:Pn(p)?"password":"text",className:"rge-form-input",value:String(l??""),disabled:T,placeholder:R,autoComplete:Pn(p)?"new-password":void 0,onChange:$e=>x($e.target.value)})},ro=(a,l)=>{var T;const c=_o(l),E=String(((T=a.component)==null?void 0:T.caseType)||"").toLowerCase(),p=(R,x,G)=>{Et(a.name,c.map((Q,ce)=>ce===R?{...Q,[x]:G}:Q))};return e.createElement("div",{className:"rge-switch-node-editor"},e.createElement("div",{className:"rge-structured-array-header rge-switch-node-header"},e.createElement("span",null,d("editor.property.switchCondition","条件")),e.createElement("span",null,d("editor.property.switchRoute","路由")),e.createElement("span",null)),c.map((R,x)=>e.createElement("div",{key:x,className:"rge-switch-node-row"},e.createElement("textarea",{className:`rge-form-textarea${E==="expr"||E==="expression"?" rge-expression-editor":""}`,rows:2,value:R.case,placeholder:d("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,onChange:G=>p(x,"case",G.target.value)}),e.createElement("input",{type:"text",className:"rge-form-input",value:R.then,placeholder:d("editor.property.switchRoutePlaceholder","输入路由:如 Case1"),onChange:G=>p(x,"then",G.target.value)}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",onClick:()=>h(()=>{Et(a.name,c.filter((G,Q)=>Q!==x))})},"×"))),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Et(a.name,[...c,{case:"",then:""}])},d("editor.property.addBranch","添加分支")),_t(a))},ao=(a,l)=>{const c=vo(l),E=No(a,c),p=wn(a),T=new Map(p.map(x=>[x.name,x])),R=E.reduce((x,G)=>{const Q=T.get(G);return x[G]=(Q==null?void 0:Q.defaultValue)??"",x},{});return E.length===0?e.createElement("div",{className:"rge-array-editor"},e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Et(a.name,[...c,{}])},d("editor.panel.addPair","+ 添加")),_t(a)):e.createElement("div",{className:"rge-structured-array-editor"},e.createElement("div",{className:"rge-structured-array-scroll"},e.createElement("div",{className:"rge-structured-array-header",style:{gridTemplateColumns:`repeat(${E.length}, minmax(120px, 1fr)) 32px`}},E.map(x=>{var G;return e.createElement("span",{key:x},((G=T.get(x))==null?void 0:G.label)||x)}),e.createElement("span",null)),c.map((x,G)=>e.createElement("div",{key:G,className:"rge-structured-array-row",style:{gridTemplateColumns:`repeat(${E.length}, minmax(120px, 1fr)) 32px`}},E.map(Q=>{const ce=T.get(Q);return e.createElement("div",{key:Q,className:"rge-structured-array-cell"},jn(ce,x[Q],de=>Et(a.name,c.map((We,$e)=>$e===G?{...We,[Q]:de}:We)),`${a.name}.${G}.${Q}`))}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",onClick:()=>h(()=>{Et(a.name,c.filter((Q,ce)=>ce!==G))})},"×")))),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Et(a.name,[...c,R])},d("editor.panel.addPair","+ 添加")),_t(a))},oo=(a,l)=>{const c=l&&typeof l=="object"&&!Array.isArray(l)?l:{},E=wn(a),p=E.length>0?E.map(R=>R.name).filter(Boolean):Object.keys(c),T=new Map(E.map(R=>[R.name,R]));return e.createElement("div",{className:"rge-struct-panel"},p.length===0?e.createElement("div",{className:"rge-struct-empty"},d("editor.property.noConfigItems","暂无配置项")):p.map(R=>{const x=T.get(R);return e.createElement("div",{key:R,className:"rge-struct-child"},e.createElement("label",{className:"rge-form-label"},(x==null?void 0:x.label)||R),jn(x,c[R]??(x==null?void 0:x.defaultValue)??"",G=>Et(a.name,{...c,[R]:G}),`${a.name}.${R}`),tn(x==null?void 0:x.desc)&&e.createElement("span",{className:"rge-field-desc"},tn(x==null?void 0:x.desc)))}),_t(a))},$r=a=>{var T,R,x,G;const c=(q.configuration||{})[a.name],E=!!(a.disabled||(T=a.component)!=null&&T.disabled),p=((R=a.component)==null?void 0:R.placeholder)||"";if(Eo(a))return no(a,c,E,p);if(Aa(a)){const Q=!!((x=a.component)!=null&&x.multiple),ce=ct(a,c),de=Array.isArray(c)?c.map(We=>String(We??"")).filter(Boolean):String(c??"").split(",").map(We=>We.trim()).filter(Boolean);return e.createElement(e.Fragment,null,e.createElement(zt,{name:a.name,value:String(c??""),values:Q?de:void 0,multiple:Q,allowCreate:!!((G=a.component)!=null&&G.allowCreate),disabled:E,options:ce,placeholder:p,...S,onChange:We=>kt(a,a.name,We),onMultiChange:We=>kt(a,a.name,We)}),_t(a))}if(Ur(a))return ro(a,c);if(Yn(a))return e.createElement("div",{className:"rge-form-switch-row"},e.createElement("label",{className:"rge-switch-toggle"},e.createElement("input",{type:"checkbox",checked:!!c,disabled:E,onChange:Q=>kt(a,a.name,Q.target.checked)}),e.createElement("span",{className:"rge-switch-slider"})),_t(a));if(Kr(a))return e.createElement(e.Fragment,null,jn(a,c,Q=>Et(a.name,Q)),_t(a));if(zr(a))return e.createElement(e.Fragment,null,jn(a,c,Q=>Et(a.name,Q)),_t(a));if(on(a))return e.createElement("div",{className:"rge-map-editor"},e.createElement("div",{className:"rge-map-header"},e.createElement("span",null,"Key"),e.createElement("span",null,"Value"),e.createElement("span",null)),(Me[a.name]||[]).map((Q,ce)=>e.createElement("div",{key:ce,className:"rge-map-row"},e.createElement("input",{type:"text",className:"rge-form-input",placeholder:d("editor.form.keyPlaceholder","键"),value:Q.key,onChange:de=>wr(a.name,ce,"key",de.target.value)}),e.createElement("input",{type:"text",className:"rge-form-input",placeholder:d("editor.form.valuePlaceholder","值"),value:Q.value,onChange:de=>wr(a.name,ce,"value",de.target.value)}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",title:d("editor.property.delete","删除"),onClick:()=>Fa(a.name,ce)},e.createElement(pe,{value:"delete"})))),e.createElement("button",{className:"rge-btn-add",onClick:()=>Oa(a.name)},d("editor.panel.addPair","+ 添加")),_t(a));if(En(a,c))return v.isPointTableFields(wn(a))?e.createElement(ko,{field:a,value:c,onChange:Q=>Et(a.name,Q),onChildChange:It,translate:d}):ao(a,c);if(hn(a))return eo(a,c);if(Yt(a))return e.createElement("div",{className:"rge-array-editor rge-tag-array-editor"},e.createElement("div",{className:"rge-array-tags",role:"list"},(b[a.name]||[]).map((Q,ce)=>e.createElement("div",{key:`${Q.value}-${ce}`,className:"rge-array-row rge-array-tag",role:"listitem",draggable:!0,onDragStart:de=>de.dataTransfer.setData("text/plain",String(ce)),onDragOver:de=>de.preventDefault(),onDrop:de=>{var $e;de.preventDefault();const We=Number(($e=de.dataTransfer)==null?void 0:$e.getData("text"));Number.isInteger(We)&&Va(a.name,We,ce)}},e.createElement("span",{className:"rge-array-tag-value"},Q.value),e.createElement("button",{type:"button",className:"rge-btn-icon-danger","aria-label":d("editor.property.delete","删除"),title:d("editor.property.delete","删除"),onClick:()=>Ba(a.name,ce)},"×")))),e.createElement("input",{type:"text",className:"rge-form-input rge-array-tag-input",value:Y[a.name]||"",placeholder:d("editor.property.simpleArrayPlaceholder","输入后回车添加,支持粘贴批量内容"),onChange:Q=>ja(a.name,Q.target.value),onKeyDown:Q=>Ha(a.name,Q),onPaste:Q=>Wa(a.name,Q),onBlur:()=>Xt(a.name,Y[a.name]||"")}),(b[a.name]||[]).length>0&&e.createElement("button",{type:"button",className:"rge-array-clear",onClick:()=>Ua(a.name)},d("editor.property.clearValues","清空")),_t(a));if(Wn(a))return e.createElement("div",{className:`rge-script-editor${br(a)?" rge-command-editor":""}`},e.createElement("textarea",{className:"rge-code-textarea",rows:br(a)?4:10,value:Wr(c),onChange:Q=>kt(a,a.name,Q.target.value),placeholder:d("editor.form.jsScriptPlaceholder","请输入 JS 脚本..."),spellCheck:!1}),_t(a));if(qr(a))return oo(a,c);if(Jr(a))return e.createElement(e.Fragment,null,e.createElement("textarea",{className:"rge-form-textarea rge-expression-editor",rows:3,value:String(c??""),placeholder:d("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,disabled:E,onChange:Q=>kt(a,a.name,Q.target.value)}),_t(a));if(Hr(a))return e.createElement(e.Fragment,null,e.createElement("textarea",{className:"rge-form-textarea",rows:3,value:String(c??""),placeholder:p,disabled:E,onChange:Q=>kt(a,a.name,Q.target.value)}),_t(a));if(Xn(a)){const Q=gr(a.type)||$t(a)==="number";return e.createElement(e.Fragment,null,e.createElement("input",{type:"number",step:Q?"0.01":void 0,className:"rge-form-input",value:String(c??""),disabled:E,onChange:ce=>{const de=ce.target.value;kt(a,a.name,de===""?"":Q?Number(de):parseInt(de,10))}}),_t(a))}return e.createElement(e.Fragment,null,e.createElement("input",{type:Pn(a)?"password":"text",className:"rge-form-input",value:String(c??""),placeholder:p,disabled:E,autoComplete:Pn(a)?"new-password":void 0,onChange:Q=>kt(a,a.name,Q.target.value)}),_t(a))},lo=()=>{if(!ae)return null;const a=Ue.find(G=>G.name===ae.fieldName);if(!a)return null;const l=ae.keyword.trim().toLowerCase(),c=et(a,ae.value).filter(G=>!st||G.value!==st).filter(G=>Po(G,ae.tab)).filter(G=>l?G.label.toLowerCase().includes(l)||G.value.toLowerCase().includes(l)||String(G.description||"").toLowerCase().includes(l):!0),E=Xe?_e.total:c.length,p=Xe&&_e.size||Oe,T=Math.max(1,Math.ceil(E/p)),R=Math.min(ae.page,T),x=Xe?_e.items:c.slice((R-1)*p,R*p);return e.createElement("div",{className:"rge-rule-chain-modal",onClick:()=>Ne(null)},e.createElement("div",{className:"rge-rule-chain-modal-panel",role:"dialog","aria-modal":"true","aria-label":d("editor.form.selectRuleChain","选择规则链"),onClick:G=>G.stopPropagation()},e.createElement("div",{className:"rge-rule-chain-modal-header"},e.createElement("strong",null,d("editor.form.selectRuleChain","选择规则链")),e.createElement("button",{type:"button",className:"rge-rule-chain-modal-close",onClick:()=>Ne(null)},"×")),e.createElement("div",{className:"rge-rule-chain-modal-tools"},e.createElement("div",{className:"rge-rule-chain-modal-tabs",role:"tablist"},["sub","root"].map(G=>e.createElement("button",{key:G,type:"button",role:"tab","aria-selected":ae.tab===G,className:ae.tab===G?"active":"",onClick:()=>Gt({tab:G,page:1})},G==="sub"?d("editor.property.subRuleChains","子规则链"):d("editor.property.rootRuleChains","主规则链")))),e.createElement("input",{type:"search",className:"rge-rule-chain-modal-search",value:ae.keyword,placeholder:d("editor.property.searchRuleChains","搜索规则链..."),onChange:G=>Gt({keyword:G.target.value,page:1}),autoFocus:!0})),e.createElement("div",{className:"rge-rule-chain-modal-body"},_e.loading&&Xe?e.createElement("div",{className:"rge-rule-chain-empty"},d("editor.property.loading","加载中...")):_e.error&&Xe?e.createElement("div",{className:"rge-rule-chain-empty"},_e.error):x.length===0?e.createElement("div",{className:"rge-rule-chain-empty"},d("editor.property.noData","暂无数据")):e.createElement("table",{className:"rge-rule-chain-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,d("editor.property.name","名称")),e.createElement("th",null,"ID"),e.createElement("th",null,d("editor.panel.description","描述")),e.createElement("th",null,d("editor.property.operate","操作")))),e.createElement("tbody",null,x.map(G=>{const Q=G.value===ae.value;return e.createElement("tr",{key:G.value,className:Q?"active":void 0},e.createElement("td",{className:"rge-rule-chain-name"},e.createElement("span",{className:"rge-rule-chain-title"},G.label),e.createElement("span",{className:"rge-rule-chain-badge"},G.root===!1?d("editor.property.subChain","子链"):d("editor.property.rootChain","主链"))),e.createElement("td",{className:"rge-rule-chain-id"},G.value),e.createElement("td",{className:"rge-rule-chain-desc"},G.description||"-"),e.createElement("td",{className:"rge-rule-chain-action"},Q?e.createElement("span",{className:"rge-selected-badge"},d("editor.property.selected","已选择")):e.createElement("button",{type:"button",onClick:()=>La(G)},d("editor.property.select","选择"))))})))),e.createElement("div",{className:"rge-rule-chain-modal-footer"},e.createElement("span",{className:"rge-rule-chain-page-info"},d("editor.property.pageInfo","第 {{page}}/{{pages}} 页,共 {{total}} 条",{page:String(R),pages:String(T),total:String(E)})),e.createElement("button",{type:"button",disabled:R<=1||Xe&&_e.loading,onClick:()=>Gt({page:Math.max(1,R-1)})},d("editor.property.prevPage","上一页")),e.createElement("button",{type:"button",disabled:R>=T||Xe&&_e.loading,onClick:()=>Gt({page:Math.min(T,R+1)})},d("editor.property.nextPage","下一页")))))};return!t||!n?null:e.createElement("div",{className:`rge-node-drawer-overlay ${t?"visible":""}`,onClick:()=>{nr()}},e.createElement("div",{className:"rge-node-drawer",onClick:a=>a.stopPropagation()},e.createElement("div",{className:"rge-drawer-header"},e.createElement("div",{className:"rge-drawer-title"},e.createElement(pe,{value:"package"}),e.createElement("span",null,d(`components.${(r==null?void 0:r.type)||n.type}`,(r==null?void 0:r.label)||n.type))),e.createElement("button",{className:"rge-drawer-close",onClick:()=>{nr()}},"✕")),e.createElement("div",{className:"rge-drawer-body"},e.createElement("div",{className:"rge-node-config-section__title"},d("editor.panel.nodeInformation","节点信息")),e.createElement("div",{className:"rge-node-config-card"},e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},d("editor.panel.nodeId","节点 ID")),e.createElement("div",{className:"rge-form-row"},e.createElement("input",{type:"text",className:"rge-form-input rge-flex-1",value:q.id||"",readOnly:!0,"aria-readonly":"true",title:d("editor.panel.nodeIdLocked","节点 ID 已绑定画布,编辑属性时不会改写"),onChange:a=>pt("id",a.target.value)}),e.createElement("label",{className:"rge-debug-toggle"},e.createElement("input",{type:"checkbox",checked:q.debugMode||!1,onChange:a=>pt("debugMode",a.target.checked)}),e.createElement(pe,{value:"debug"}),e.createElement("span",null,d("editor.panel.debugMode","调试"))))),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},d("editor.panel.name","名称")),e.createElement("input",{type:"text",className:"rge-form-input",value:q.name||"",onChange:a=>pt("name",a.target.value)})),Ya(),Xa(),mn.map(a=>a.id?e.createElement("details",{key:a.id,className:"rge-field-group",open:!a.collapsed},e.createElement("summary",null,e.createElement("span",null,a.label),e.createElement("small",null,a.fields.length)),a.description&&e.createElement("p",null,a.description),e.createElement("div",{className:"rge-field-group-body"},a.fields.map(Lr))):a.fields.map(Lr)),Lt&&(()=>{if(sn.length===0)return null;const a=()=>{Wt>0||Tt("")},l=()=>{Wt>0||un.length>0||Tt("")};return e.createElement("div",{className:"rge-field-attachment-overlay",role:"presentation",onMouseDown:c=>{c.target===c.currentTarget&&a()}},e.createElement("section",{className:"rge-field-attachment-panel",role:"dialog","aria-modal":"true"},e.createElement("header",null,e.createElement("strong",null,d("editor.property.attachedSettings","附加参数")),e.createElement("button",{type:"button",disabled:Wt>0,"aria-label":d("editor.panel.close","关闭"),onClick:a},"×")),e.createElement("div",{className:"rge-field-attachment-body"},On.map(c=>e.createElement("div",{key:c.field.name,className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},K(c.field)),$r(c.field),_t(c.field),Bn(c.field.name)))),e.createElement("footer",{className:"rge-drawer-footer"},Wt>0&&e.createElement("span",{className:"rge-field-desc",role:"status"},d("editor.property.fieldChangeLoading","正在更新关联字段...")),e.createElement("button",{type:"button",className:"rge-btn-submit",disabled:Wt>0||un.length>0,onClick:l},d("editor.panel.apply","应用")))))})(),Ue.length===0&&e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},d("editor.property.configurationJson","配置 JSON")),e.createElement("textarea",{className:"rge-form-textarea",rows:14,value:ue,onChange:a=>{W(a.target.value),Pe("")},spellCheck:!1}),ge&&e.createElement("span",{className:"rge-field-error"},ge)),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},d("editor.panel.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",rows:3,placeholder:d("editor.panel.descriptionPlaceholder","请输入节点描述"),value:String(((Ar=q.additionalInfo)==null?void 0:Ar.description)??""),onChange:a=>pt("additionalInfo",{...q.additionalInfo,description:a.target.value})})))),lo(),to(),e.createElement("div",{className:"rge-drawer-footer"},Ke&&e.createElement("span",{className:"rge-drawer-submit-error",role:"alert"},Ke),!Ke&&cn.length>0&&e.createElement("span",{className:"rge-drawer-submit-error",role:"alert"},d("editor.property.fieldChangeFailedMessage","关联字段更新失败: {{message}}",{message:cn.map(([,a])=>a).join("; ")})),Ot>0&&e.createElement("span",{className:"rge-field-desc",role:"status"},d("editor.property.fieldChangeLoading","正在更新关联字段...")),e.createElement("button",{className:"rge-btn-cancel",onClick:()=>{nr()}},d("editor.panel.cancel","取消")),e.createElement("button",{className:"rge-btn-submit",disabled:Ot>0||cn.length>0,onClick:()=>{Dr()}},d("editor.panel.confirm","确认")))))};ba.displayName="NodePropertyDrawer";const Dn=[{value:"Success",label:"成功 (Success)",color:"#52c41a"},{value:"Failure",label:"失败 (Failure)",color:"#ff4d4f"},{value:"True",label:"是 (True)",color:"#1890ff"},{value:"False",label:"否 (False)",color:"#fa8c16"},{value:"Post Telemetry",label:"Post Telemetry",color:"#722ed1"}],ha=({visible:t,edgeModel:n,relationTypes:r,onSubmit:o,onClose:s,locale:i,messages:m,t:f})=>{const[M,N]=e.useState(""),[P,g]=e.useState(""),[w,y]=e.useState(!1),k=e.useMemo(()=>Ze({locale:i,messages:m,t:f}),[i,m,f]),F=e.useMemo(()=>{const C=!(r!=null&&r.length);return(r!=null&&r.length?r:Dn).map((D,_)=>{var u,Z;return typeof D=="string"?{value:D,label:pr(k,D),color:((u=Dn[_%Dn.length])==null?void 0:u.color)||"#409eff"}:{value:D.value,label:!C&&D.label?D.label:pr(k,D.value),color:D.color||((Z=Dn[_%Dn.length])==null?void 0:Z.color)||"#409eff"}})},[r,k]);e.useEffect(()=>{if(!n)return;const C=n.relationType||"Success";F.some(D=>D.value===C)?(N(C),y(!1),g("")):(N(""),y(!0),g(C))},[n,F]);const j=C=>{N(C),y(!1),g("")},O=()=>{y(!0),N("")},U=()=>{if(!n)return;const C=w?P.trim()||"Success":M||"Success";o({...n,relationType:C})};return!t||!n?null:e.createElement("div",{className:`rge-edge-drawer-overlay ${t?"visible":""}`,onClick:s},e.createElement("div",{className:"rge-edge-drawer",onClick:C=>C.stopPropagation()},e.createElement("div",{className:"rge-drawer-header"},e.createElement("div",{className:"rge-drawer-title"},e.createElement(pe,{value:"link"}),e.createElement("span",null,k("editor.edge.title","连线属性"))),e.createElement("button",{className:"rge-drawer-close",onClick:s},"✕")),e.createElement("div",{className:"rge-drawer-body"},e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},k("editor.edge.id","连线 ID")),e.createElement("div",{className:"rge-form-value"},n.id)),e.createElement("div",{className:"rge-edge-endpoints"},e.createElement("div",{className:"rge-endpoint"},e.createElement("span",{className:"rge-endpoint-label"},k("editor.edge.source","来源")),e.createElement("span",{className:"rge-endpoint-id"},n.sourceNodeId)),e.createElement("span",{className:"rge-endpoint-arrow"},"→"),e.createElement("div",{className:"rge-endpoint"},e.createElement("span",{className:"rge-endpoint-label"},k("editor.edge.target","目标")),e.createElement("span",{className:"rge-endpoint-id"},n.targetNodeId))),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},k("editor.form.relationType","关系类型")),e.createElement("div",{className:"rge-relation-types"},F.map(C=>e.createElement("button",{key:C.value,className:`rge-relation-type-btn ${!w&&M===C.value?"active":""}`,style:{borderColor:!w&&M===C.value?C.color:void 0,color:!w&&M===C.value?C.color:void 0},onClick:()=>j(C.value)},!w&&M===C.value&&e.createElement("span",null,"✓"),C.label)),e.createElement("button",{className:`rge-relation-type-btn ${w?"active custom":""}`,onClick:O},k("editor.edge.custom","自定义"))),w&&e.createElement("input",{type:"text",className:"rge-form-input rge-mt-8",placeholder:k("editor.edge.customPlaceholder","请输入自定义关系类型"),value:P,onChange:C=>g(C.target.value),autoFocus:!0}))),e.createElement("div",{className:"rge-drawer-footer"},e.createElement("button",{className:"rge-btn-cancel",onClick:s},k("editor.panel.cancel","取消")),e.createElement("button",{className:"rge-btn-submit",onClick:U},k("editor.panel.confirm","确认")))))};ha.displayName="EdgePropertyDrawer";const Oo=(t,n)=>{console[t==="success"?"log":t==="warning"?"warn":"error"](`[DebugPanel] ${t}: ${n}`)},Ea=({visible:t,chainId:n,selectedNodeId:r,onClose:o,onSendMessage:s,deployState:i="unknown",onDeploy:m,onFetchDebugLogs:f,onFetchRunLogs:M,onNotify:N=Oo,locale:P,messages:g,t:w})=>{const[y,k]=e.useState("send"),[F,j]=e.useState("TEST_MSG"),[O,U]=e.useState(`{
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),en=require("react-dom"),y=require("@huanban/rulego-editor-core");function Qt(t){return Object.fromEntries(Object.entries(t).filter(([,r])=>r!==void 0))}function pn(t){return Array.isArray(t)?t.length>0:!!t}const qr=["onAuthExpired","onApiAuthRequired","clearToken","onSettingsClick","onSettingsSubmit","onUiSettingsChange","onLoginClick","onSaveConflict","onRestartConfirm"],gn=["onReady","onSave","saveHandler","onSaveRequest","onSaveSuccess","onSaveError","onExternalDataConflict","onNodeClick","onNodeDbClick","onEdgeClick","onChange","onInfoClick","onExportDSL","onImportDSL","onRunClick","onFlow","onTraceClick","onComponentManage","onLocaleChange","onDeploy","onRestart","onSelectRuleChain","onDeleteRuleChain","onRunHistory","exportDataTransform","onNodeConfigRequest"],ko=new Set(["onInfoClick","onExportDSL","onImportDSL","onRunClick","onFlow","onTraceClick","onComponentManage","onDeploy","onRestart","onRunHistory","exportDataTransform","onNodeConfigRequest"]),wo=new Set(["identityProvider","dialogProvider","debugWsOptions","workflowFetcher","versionsFetcher","globalConfigFetcher","settingsPanes","fieldChangeContributions","coreOptions","regions","panelRenderers"]),So=["fieldChangeContributions","capabilityContributions","optionSourceContributions"];function St(t){if(!t||typeof t!="object")return!1;const r=Object.getPrototypeOf(t);return r===Object.prototype||r===null}function vn(t,r,n=new WeakMap,o=!1){if(Object.is(t,r))return!0;if(typeof t=="function"||typeof r=="function")return!o&&typeof t=="function"&&typeof r=="function";if(typeof t!="object"||t===null||typeof r!="object"||r===null)return!1;const s=n.get(t);if(s)return s===r;if(n.set(t,r),Array.isArray(t)||Array.isArray(r))return!Array.isArray(t)||!Array.isArray(r)||t.length!==r.length?!1:t.every((p,S)=>vn(p,r[S],n,o));if(!St(t)||!St(r))return!1;const u=Object.keys(t),d=Object.keys(r);return u.length!==d.length?!1:u.every(p=>Object.prototype.hasOwnProperty.call(r,p)&&vn(t[p],r[p],n,o))}function xo(t,r){if(!t)return!1;const n=Object.keys(t),o=Object.keys(r);return n.length!==o.length?!1:o.every(s=>Object.prototype.hasOwnProperty.call(t,s)&&(typeof t[s]=="function"||typeof r[s]=="function"?Object.is(t[s],r[s]):vn(t[s],r[s],new WeakMap,wo.has(s))))}function Cn(t,r=new WeakMap){if(!Array.isArray(t)&&!St(t))return t;const n=r.get(t);if(n)return n;if(Array.isArray(t)){const s=[];return r.set(t,s),t.forEach(u=>s.push(Cn(u,r))),s}const o={};return r.set(t,o),Object.entries(t).forEach(([s,u])=>{o[s]=Cn(u,r)}),o}function Xr(t,r){const n={...r};return Object.keys(t||{}).forEach(o=>{Object.prototype.hasOwnProperty.call(r,o)||(n[o]=void 0)}),n}function Ca(t,r){const n=St(t)?t:null,o=St(r)?r:{},s=Xr(n,o);return Object.keys(o).forEach(u=>{St(o[u])&&(s[u]=Ca(n==null?void 0:n[u],o[u]))}),s}function Ro(t,r){const n=Xr(t,r);for(const o of["capabilities","toolbar","header","settings","uiSettings","coreOptions","fieldChangeContributions","regions","panelRenderers"]){const s=t==null?void 0:t[o],u=r[o];if(!(["header","settings","uiSettings","regions","panelRenderers"].includes(o)&&!St(u))&&(St(s)||St(u))&&(n[o]=["capabilities","toolbar","settings","uiSettings"].includes(o)?Ca(s,u):Xr(St(s)?s:null,St(u)?u:{}),o==="coreOptions"))for(const d of So){const p=St(s)?s[d]:void 0,S=St(u)?u[d]:void 0;(St(p)||St(S))&&(n[o][d]=Xr(St(p)?p:null,St(S)?S:{}))}}return n}const Na=e.forwardRef(function(r,n){var Ee;const{height:o="100%",width:s="100%",className:u,style:d,slots:p,panelSlots:S,apiBase:w,fetchTimeout:R,fetchHeaders:b,apiCacheKey:x,customFetch:_,data:E,dataUpdatePolicy:W,components:B,enableConnectionStatus:U,visible:q,onConnectionStatusChange:C,mode:O,capabilities:j,toolbar:k,showWorkspaceTabs:v,workflowFetcher:ae,versionsFetcher:J,globalConfigFetcher:Y,settingsPanes:re,disabled:ce,showToolbar:g,toolbarTitle:F,showToolbarButtonLabels:ee,toolbarIconOnly:P,showSidebar:Z,sidebarWidth:pe,sidebarCollapsed:Te,showInfoButton:Pe,showAiChatButton:_e,showSettingsButton:me,showDebugConsoleButton:H,showDiagnosticsButton:ne,showClearDebugHighlightButton:M,showSelectionButton:ge,showExportDialog:xe,showRunButton:se,showComponentManage:Ce,showDeployButton:Re,showRestartButton:K,showReloadButton:le,showRunHistory:de,runHistoryUrl:z,showTraceButton:G,showDebugTab:ye,locale:ke,messages:$e,autoLoadLocales:at,theme:qe,lfOptions:X,lfPlugins:He,coreOptions:_t,exportDataTransform:xt,onNodeConfigRequest:$t,options:T,onReady:Ie,onSave:tt,saveMode:vt,saveHandler:ft,onSaveSuccess:Kt,onSaveError:Tt,onExternalDataConflict:dt,onNodeClick:pt,onNodeDbClick:Ht,onEdgeClick:Rt,onChange:Wt,onInfoClick:Je,onExportDSL:Zt,onImportDSL:Pt,onRunClick:Jt,onFlow:Ft,onTraceClick:bt,onComponentManage:Dt,onLocaleChange:ht,onDeploy:jt,onRestart:Ct,onSelectRuleChain:Lt,onDeleteRuleChain:Mt,onRunHistory:ue,ruleItems:ve,rulesApi:Se,renderNode:f}=r,fe=E??(T==null?void 0:T.data),we=pn(B)?B:T==null?void 0:T.components,We=xt??(T==null?void 0:T.exportDataTransform)??((Ee=_t??(T==null?void 0:T.coreOptions))==null?void 0:Ee.exportDataTransform),Fe=e.useRef(null),ie=e.useRef(null),wt=e.useRef(fe),rt=e.useRef(we),[It,yt]=e.useState([]),[st,er]=e.useState([]),ct=e.useRef(new Map),At=e.useRef(new Map),dr=e.useRef(0),pr=e.useRef(!1),sr=(l,m)=>Object.fromEntries(Object.entries(m||{}).filter(([I,L])=>L!=null&&L!==!1&&(l==="panel"||y.EDITOR_REGION_IDS.includes(I))).map(([I])=>{const L=`${l}:${I}`;return At.current.has(L)||At.current.set(L,{mount(oe,je){const nt={id:++dr.current,kind:l,name:I,container:oe,context:je},ze=()=>{pr.current&&er(Array.from(ct.current.values()))};return ct.current.set(nt.id,nt),ze(),{update(Qe){nt.context=Qe,ze()},destroy(){ct.current.delete(nt.id),ze()}}}}),[I,At.current.get(L)]})),gt=sr("region",p),Ut=sr("panel",S),Ye=T!=null&&T.regions||Object.keys(gt).length?{...T==null?void 0:T.regions,...gt}:void 0,ar=T!=null&&T.panelRenderers||Object.keys(Ut).length?{...T==null?void 0:T.panelRenderers,...Ut}:void 0,Ve=e.useRef({onSave:tt,saveHandler:ft,onSaveSuccess:Kt,onSaveError:Tt,onExternalDataConflict:dt,onReady:Ie,onNodeClick:pt,onNodeDbClick:Ht,onEdgeClick:Rt,onChange:Wt,onInfoClick:Je,onExportDSL:Zt,onImportDSL:Pt,onRunClick:Jt,onFlow:Ft,onTraceClick:bt,onComponentManage:Dt,onLocaleChange:ht,onDeploy:jt,onRestart:Ct,onSelectRuleChain:Lt,onDeleteRuleChain:Mt,onRunHistory:ue,exportDataTransform:We,onNodeConfigRequest:$t}),qt=e.useRef(C);qt.current=C;const De=e.useRef(T),gr=e.useRef({onAuthExpired:l=>{var m,I;return(I=(m=De.current)==null?void 0:m.onAuthExpired)==null?void 0:I.call(m,l)},onApiAuthRequired:l=>{var m,I;return(I=(m=De.current)==null?void 0:m.onApiAuthRequired)==null?void 0:I.call(m,l)},clearToken:()=>{var l,m;return(m=(l=De.current)==null?void 0:l.clearToken)==null?void 0:m.call(l)},onSettingsClick:l=>{var m,I;return(I=(m=De.current)==null?void 0:m.onSettingsClick)==null?void 0:I.call(m,l)},onSettingsSubmit:l=>{var m,I;return(I=(m=De.current)==null?void 0:m.onSettingsSubmit)==null?void 0:I.call(m,l)},onUiSettingsChange:l=>{var m,I;return(I=(m=De.current)==null?void 0:m.onUiSettingsChange)==null?void 0:I.call(m,l)},onLoginClick:()=>{var l,m;return(m=(l=De.current)==null?void 0:l.onLoginClick)==null?void 0:m.call(l)},onSaveConflict:l=>{var m,I;return(I=(m=De.current)==null?void 0:m.onSaveConflict)==null?void 0:I.call(m,l)},onRestartConfirm:l=>{var m,I;return(I=(m=De.current)==null?void 0:m.onRestartConfirm)==null?void 0:I.call(m,l)}}),fr=e.useRef({}),ot=e.useRef({}),zt=e.useRef(null);e.useEffect(()=>{De.current=T;const l={};qr.forEach(I=>{l[I]=typeof(T==null?void 0:T[I])=="function"}),fr.current=l;const m={};gn.forEach(I=>{m[I]=I==="exportDataTransform"?typeof We=="function":typeof r[I]=="function"||typeof(T==null?void 0:T[I])=="function"}),ot.current=m,Ve.current={onSave:tt,saveHandler:ft,onSaveSuccess:Kt,onSaveError:Tt,onExternalDataConflict:dt,onReady:Ie,onNodeClick:pt,onNodeDbClick:Ht,onEdgeClick:Rt,onChange:Wt,onInfoClick:Je,onExportDSL:Zt,onImportDSL:Pt,onRunClick:Jt,onFlow:Ft,onTraceClick:bt,onComponentManage:Dt,onLocaleChange:ht,onDeploy:jt,onRestart:Ct,onSelectRuleChain:Lt,onDeleteRuleChain:Mt,onRunHistory:ue,exportDataTransform:We,onNodeConfigRequest:$t}});const mt=e.useRef({request:l=>{var m,I,L,oe;(I=(m=Ve.current).onSave)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onSaveRequest)==null||oe.call(L,l)},handler:(l,m)=>{var L,oe;const I=Ve.current.saveHandler;return I?I(l,m):(oe=(L=De.current)==null?void 0:L.saveHandler)==null?void 0:oe.call(L,l,m)},legacyHandler:(l,m)=>{var I,L;return(L=(I=De.current)==null?void 0:I.onSave)==null?void 0:L.call(I,l,m)},success:l=>{var m,I,L,oe;(I=(m=Ve.current).onSaveSuccess)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onSaveSuccess)==null||oe.call(L,l)},error:l=>{var m,I,L,oe;(I=(m=Ve.current).onSaveError)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onSaveError)==null||oe.call(L,l)},conflict:l=>{var m,I,L,oe;(I=(m=Ve.current).onExternalDataConflict)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onExternalDataConflict)==null||oe.call(L,l)}}),Xe=e.useRef({onReady:l=>{var m,I,L,oe;(I=(m=Ve.current).onReady)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onReady)==null||oe.call(L,l)},onSave:mt.current.legacyHandler,saveHandler:mt.current.handler,onSaveRequest:mt.current.request,onSaveSuccess:mt.current.success,onSaveError:mt.current.error,onExternalDataConflict:mt.current.conflict,onNodeClick:l=>{var m,I,L,oe;(I=(m=Ve.current).onNodeClick)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onNodeClick)==null||oe.call(L,l)},onNodeDbClick:l=>{var m,I,L,oe;(I=(m=Ve.current).onNodeDbClick)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onNodeDbClick)==null||oe.call(L,l)},onEdgeClick:l=>{var m,I,L,oe;(I=(m=Ve.current).onEdgeClick)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onEdgeClick)==null||oe.call(L,l)},onChange:()=>{var l,m,I,L;(m=(l=Ve.current).onChange)==null||m.call(l),(L=(I=De.current)==null?void 0:I.onChange)==null||L.call(I)},onInfoClick:l=>{var m,I,L,oe;(I=(m=Ve.current).onInfoClick)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onInfoClick)==null||oe.call(L,l)},onExportDSL:l=>{var m,I,L,oe;(I=(m=Ve.current).onExportDSL)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onExportDSL)==null||oe.call(L,l)},onImportDSL:l=>{var m,I,L,oe;(I=(m=Ve.current).onImportDSL)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onImportDSL)==null||oe.call(L,l)},onRunClick:l=>{var m,I,L,oe;(I=(m=Ve.current).onRunClick)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onRunClick)==null||oe.call(L,l)},onFlow:(l,m)=>{var I,L,oe,je;(L=(I=Ve.current).onFlow)==null||L.call(I,l,m),(je=(oe=De.current)==null?void 0:oe.onFlow)==null||je.call(oe,l,m)},onTraceClick:l=>{var m,I,L,oe;(I=(m=Ve.current).onTraceClick)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onTraceClick)==null||oe.call(L,l)},onComponentManage:l=>{var m,I,L,oe;(I=(m=Ve.current).onComponentManage)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onComponentManage)==null||oe.call(L,l)},onLocaleChange:l=>{var m,I,L,oe;(I=(m=Ve.current).onLocaleChange)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onLocaleChange)==null||oe.call(L,l)},onDeploy:(l,m)=>{var L;const I=Ve.current.onDeploy??((L=De.current)==null?void 0:L.onDeploy);return I==null?void 0:I(l,m)},onRestart:l=>{var I;const m=Ve.current.onRestart??((I=De.current)==null?void 0:I.onRestart);return m==null?void 0:m(l)},onSelectRuleChain:l=>{var m,I,L,oe;(I=(m=Ve.current).onSelectRuleChain)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onSelectRuleChain)==null||oe.call(L,l)},onDeleteRuleChain:l=>{var m,I,L,oe;(I=(m=Ve.current).onDeleteRuleChain)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onDeleteRuleChain)==null||oe.call(L,l)},onRunHistory:l=>{var m,I,L,oe;(I=(m=Ve.current).onRunHistory)==null||I.call(m,l),(oe=(L=De.current)==null?void 0:L.onRunHistory)==null||oe.call(L,l)},exportDataTransform:l=>{var m,I;return(I=(m=Ve.current).exportDataTransform)==null?void 0:I.call(m,l)},onNodeConfigRequest:(l,m)=>{var L;const I=Ve.current.onNodeConfigRequest??((L=De.current)==null?void 0:L.onNodeConfigRequest);return(I==null?void 0:I(l,m))===!0}});e.useEffect(()=>{var Ue,it,Gt;if(!Fe.current)return;pr.current=!0,ct.current.clear(),er([]);const l=!!(ft||T!=null&&T.saveHandler),m=!l&&typeof(T==null?void 0:T.onSave)=="function",I={...(()=>{const Ke={...T};return qr.forEach(Ae=>{typeof Ke[Ae]=="function"&&(Ke[Ae]=gr.current[Ae])}),Ke})(),container:Fe.current,regions:Ye,panelRenderers:ar,...Qt({apiBase:w,fetchTimeout:R,fetchHeaders:b,apiCacheKey:x,customFetch:_,data:fe??void 0,components:pn(we)?we:void 0,dataUpdatePolicy:W,enableConnectionStatus:U,visible:q}),...Qt({mode:O,capabilities:j,toolbar:k,showWorkspaceTabs:v,workflowFetcher:ae,versionsFetcher:J,globalConfigFetcher:Y,settingsPanes:re,disabled:ce,showToolbar:g,toolbarTitle:F,showToolbarButtonLabels:ee,toolbarIconOnly:P,showSidebar:Z,sidebarWidth:pe,sidebarCollapsed:Te,showInfoButton:Pe,showAiChatButton:_e,showSettingsButton:me,showDebugConsoleButton:H,showDiagnosticsButton:ne,showClearDebugHighlightButton:M,showSelectionButton:ge,showExportDialog:xe,showRunButton:se,showComponentManage:Ce,showDeployButton:Re,showRestartButton:K,showReloadButton:le,showRunHistory:de,runHistoryUrl:z,showTraceButton:G,showDebugTab:ye}),capabilities:y.mergeEditorCapabilities((Ue=De.current)==null?void 0:Ue.capabilities,y.mergeEditorCapabilities({},j)),toolbar:{...Qt(((it=De.current)==null?void 0:it.toolbar)||{}),...Qt(k||{})},...Qt({locale:ke,messages:$e,autoLoadLocales:at,theme:qe}),...Qt({lfOptions:X,lfPlugins:He,coreOptions:_t}),...Qt({ruleItems:ve,rulesApi:Se}),onReady:Xe.current.onReady,...Qt({saveMode:vt??(T==null?void 0:T.saveMode),saveHandler:l?ft||(T==null?void 0:T.saveHandler):void 0,onSave:m?T==null?void 0:T.onSave:void 0,onSaveRequest:mt.current.request,onSaveSuccess:mt.current.success,onSaveError:mt.current.error,onExternalDataConflict:mt.current.conflict}),onNodeClick:Xe.current.onNodeClick,onNodeDbClick:Xe.current.onNodeDbClick,onEdgeClick:Xe.current.onEdgeClick,onChange:Xe.current.onChange,onInfoClick:ot.current.onInfoClick?Xe.current.onInfoClick:void 0,onExportDSL:ot.current.onExportDSL?Xe.current.onExportDSL:void 0,onImportDSL:ot.current.onImportDSL?Xe.current.onImportDSL:void 0,onRunClick:ot.current.onRunClick?Xe.current.onRunClick:void 0,onFlow:ot.current.onFlow?Xe.current.onFlow:void 0,onTraceClick:ot.current.onTraceClick?Xe.current.onTraceClick:void 0,onComponentManage:ot.current.onComponentManage?Xe.current.onComponentManage:void 0,onLocaleChange:Xe.current.onLocaleChange,onDeploy:ot.current.onDeploy?Xe.current.onDeploy:void 0,onRestart:ot.current.onRestart?Xe.current.onRestart:void 0,onSelectRuleChain:Xe.current.onSelectRuleChain,onDeleteRuleChain:Xe.current.onDeleteRuleChain,onRunHistory:ot.current.onRunHistory?Xe.current.onRunHistory:void 0,exportDataTransform:ot.current.exportDataTransform?Xe.current.exportDataTransform:void 0,onNodeConfigRequest:ot.current.onNodeConfigRequest?Xe.current.onNodeConfigRequest:void 0},L=new y.HuanbanRulegoEditor(I);ie.current=L,wt.current=fe,rt.current=we,zt.current=null;const oe=L.connectionStatus.subscribe(Ke=>{var Ae;(Ae=qt.current)==null||Ae.call(qt,Ke)});(Gt=qt.current)==null||Gt.call(qt,L.connectionStatus.getState());let je=null;const nt=setTimeout(()=>{je=requestAnimationFrame(()=>{if(je=null,L.lf&&Fe.current){const{clientWidth:Ke,clientHeight:Ae}=L.canvasEl||Fe.current;if(Ke>0&&Ae>0)try{L.lf.resize(Ke,Ae)}catch{}}})},100),ze=Ke=>{yt(Ae=>{const Yt=Ae.findIndex(yr=>yr.id===Ke.id),Vt={...Ke};if(Yt>=0){const yr=[...Ae];return yr[Yt]=Vt,yr}return[...Ae,Vt]})},Qe=Ke=>{yt(Ae=>Ae.filter(Yt=>Yt.id!==Ke.id))};return L.core&&(L.core.eventBus.on("node:html-mount",ze),L.core.eventBus.on("node:html-unmount",Qe)),()=>{L.core&&(L.core.eventBus.off("node:html-mount",ze),L.core.eventBus.off("node:html-unmount",Qe)),clearTimeout(nt),je!==null&&(cancelAnimationFrame(je),je=null),oe(),pr.current=!1,L.destroy(),ct.current.clear(),ie.current=null}},[]),e.useEffect(()=>{var Qe,Ue,it,Gt,Ke;const l=ie.current;if(!l)return;const m={...De.current||{}};delete m.container,delete m.data,delete m.components,delete m.lfOptions,delete m.lfPlugins,delete m.persistence,delete m.dock,gn.forEach(Ae=>{delete m[Ae]}),qr.forEach(Ae=>{delete m[Ae]});const I=!!(ft||(Qe=De.current)!=null&&Qe.saveHandler),L=!I&&typeof((Ue=De.current)==null?void 0:Ue.onSave)=="function",oe={};qr.forEach(Ae=>{oe[Ae]=fr.current[Ae]?gr.current[Ae]:void 0});const je={};gn.forEach(Ae=>{je[Ae]=ot.current[Ae]||!ko.has(Ae)?Xe.current[Ae]:void 0});const nt={...m,regions:Ye,panelRenderers:ar,...Qt({apiBase:w,fetchTimeout:R,fetchHeaders:b,apiCacheKey:x,customFetch:_,dataUpdatePolicy:W,enableConnectionStatus:U,visible:q,mode:O,capabilities:j,toolbar:k,showWorkspaceTabs:v,workflowFetcher:ae,versionsFetcher:J,globalConfigFetcher:Y,settingsPanes:re,disabled:ce,showToolbar:g,toolbarTitle:F,showToolbarButtonLabels:ee,toolbarIconOnly:P,showSidebar:Z,sidebarWidth:pe,sidebarCollapsed:Te,showInfoButton:Pe,showAiChatButton:_e,showSettingsButton:me,showDebugConsoleButton:H,showDiagnosticsButton:ne,showClearDebugHighlightButton:M,showSelectionButton:ge,showExportDialog:xe,showRunButton:se,showComponentManage:Ce,showDeployButton:Re,showRestartButton:K,showReloadButton:le,showRunHistory:de,runHistoryUrl:z,showTraceButton:G,showDebugTab:ye,locale:ke,messages:$e,autoLoadLocales:at,theme:qe,coreOptions:_t,ruleItems:ve,rulesApi:Se,saveMode:vt??((it=De.current)==null?void 0:it.saveMode)}),capabilities:y.mergeEditorCapabilities(m.capabilities,y.mergeEditorCapabilities({},j)),toolbar:{...Qt(m.toolbar||{}),...Qt(k||{})},...oe,...je,saveHandler:I?ft||((Gt=De.current)==null?void 0:Gt.saveHandler):void 0,onSave:L?(Ke=De.current)==null?void 0:Ke.onSave:void 0,onSaveRequest:mt.current.request,onSaveSuccess:mt.current.success,onSaveError:mt.current.error,onExternalDataConflict:mt.current.conflict};if(xo(zt.current,nt))return;const ze=Ro(zt.current,nt);zt.current=Cn(nt),l.updateOptions(ze)}),e.useEffect(()=>{Object.is(wt.current,fe)||(wt.current=fe,fe&&ie.current&&ie.current.updateOptions({data:fe}))},[fe]),e.useEffect(()=>{Object.is(rt.current,we)||(rt.current=we,pn(we)&&ie.current&&ie.current.updateOptions({components:we}))},[we]),e.useImperativeHandle(n,()=>({get editor(){return ie.current},get lf(){var l;return((l=ie.current)==null?void 0:l.lf)??null},get core(){var l;return((l=ie.current)==null?void 0:l.core)??null},get capabilities(){var l;return((l=ie.current)==null?void 0:l.capabilities)??null},get connectionStatus(){var l;return((l=ie.current)==null?void 0:l.connectionStatus)??null},get runtimeFields(){var l;return((l=ie.current)==null?void 0:l.runtimeFields)??null},loadData(l,m){var I;(I=ie.current)==null||I.loadData(l,m)},render(l){var m;(m=ie.current)==null||m.render(l)},getData(){var l;return((l=ie.current)==null?void 0:l.getData())??null},getUiConfiguration(){var l;return((l=ie.current)==null?void 0:l.getUiConfiguration())??{}},applyUiConfiguration(l){var m;return((m=ie.current)==null?void 0:m.applyUiConfiguration(l))??!1},resetUiConfiguration(){var l;return((l=ie.current)==null?void 0:l.resetUiConfiguration())??!1},applyRuleChainDraft(l,m){var I;return((I=ie.current)==null?void 0:I.applyRuleChainDraft(l,m))??Promise.resolve(!1)},activateWorkspaceTab(l){var m;return((m=ie.current)==null?void 0:m.activateWorkspaceTab(l))??!1},openRuleChain(l){var m;return((m=ie.current)==null?void 0:m.openRuleChain(l))??Promise.resolve(!1)},openChain(l){var m;return((m=ie.current)==null?void 0:m.openChain(l))??Promise.resolve(!1)},newRuleChain(l){var m;return((m=ie.current)==null?void 0:m.newRuleChain(l))??Promise.resolve(!1)},renameWorkspaceRuleChain(l){var m;return((m=ie.current)==null?void 0:m.renameWorkspaceRuleChain(l))??Promise.resolve(!1)},closeWorkspaceTab(l){var m;return((m=ie.current)==null?void 0:m.closeWorkspaceTab(l))??Promise.resolve(!1)},save(l){var m;return((m=ie.current)==null?void 0:m.save(l))??Promise.resolve(!1)},saveAll(){var l;return((l=ie.current)==null?void 0:l.saveAll())??Promise.resolve(!1)},showVersionHistory(){var l;(l=ie.current)==null||l.showVersionHistory()},openGlobalConfig(){var l;(l=ie.current)==null||l.openGlobalConfig()},showNodeLogSettings(l){var m;(m=ie.current)==null||m.showNodeLogSettings(l)},showChainLogSettings(){var l;(l=ie.current)==null||l.showChainLogSettings()},setLocale(l){var m;(m=ie.current)==null||m.setLocale(l)},setLocales(l,m){var I;(I=ie.current)==null||I.setLocales(l,m)},reloadLocales(){var l;return((l=ie.current)==null?void 0:l.reloadLocales())??Promise.resolve(!1)},isDirty(){var l;return((l=ie.current)==null?void 0:l.isDirty())??!1},flashNodes(l){var m;(m=ie.current)==null||m.flashNodes(l)},setSidebarExpanded(l){var m;(m=ie.current)==null||m.setSidebarExpanded(l)},loadComponents(l){var m;(m=ie.current)==null||m.loadComponents(l)},exportData(){var l;return((l=ie.current)==null?void 0:l.exportData())??null},toggleMiniMap(){var l;(l=ie.current)==null||l.toggleMiniMap()},autoLayout(){var l;(l=ie.current)==null||l.autoLayout()},openSettings(l="user"){var m;(m=ie.current)==null||m.openSettings(l)},openAiAssistant(l){var m;return((m=ie.current)==null?void 0:m.openAiAssistant(l))??!1},openChat(l){var m;return((m=ie.current)==null?void 0:m.openChat(l))??!1},switchChatChain(l){var m;return((m=ie.current)==null?void 0:m.switchChatChain(l))??Promise.resolve(!1)},closeAiAssistant(){var l;(l=ie.current)==null||l.closeAiAssistant()},startTour(){var l;return((l=ie.current)==null?void 0:l.startTour())??!1},closeTour(){var l;(l=ie.current)==null||l.closeTour()},setTheme(l){var m;(m=ie.current)==null||m.setTheme(l)},refreshTheme(){var l;(l=ie.current)==null||l.refreshTheme()},updateOptions(l){var m;return((m=ie.current)==null?void 0:m.updateOptions(l))??null},refreshConnectionStatuses(){var l;(l=ie.current)==null||l.refreshConnectionStatuses()},setVisible(l){var m;(m=ie.current)==null||m.setVisible(l)},acquireSharedConnectionStatuses(){var l;return((l=ie.current)==null?void 0:l.acquireSharedConnectionStatuses())??(()=>{})},invokeAction(l,m="api"){const I=ie.current;return I?I.invokeAction(l,m):Promise.reject(new Error("Editor is not ready"))},listActions(){var l;return((l=ie.current)==null?void 0:l.listActions())??[]},addAction(l){var m;(m=ie.current)==null||m.addAction(l)},removeAction(l){var m;return((m=ie.current)==null?void 0:m.removeAction(l))??!1},registerPropertyComponent(l,m,I){var L;(L=ie.current)==null||L.registerPropertyComponent(l,m,I)},resolvePropertyComponent(l){var m;return(m=ie.current)==null?void 0:m.resolvePropertyComponent(l)},unregisterPropertyComponent(l){var m;return((m=ie.current)==null?void 0:m.unregisterPropertyComponent(l))??!1},openCommandPalette(){var l;(l=ie.current)==null||l.openCommandPalette()},openShortcutHelp(){var l;(l=ie.current)==null||l.openShortcutHelp()},openNodePicker(l){var m;(m=ie.current)==null||m.openNodePicker(l)},openComponentDocs(l){const m=ie.current;return m?m.openComponentDocs(l):Promise.reject(new Error("Editor is not ready"))},openComponentManager(l="installed"){var m;(m=ie.current)==null||m.openComponentManager(l)},closeOverlay(){var l;(l=ie.current)==null||l.closeOverlay()},closeAllOverlays(){var l;(l=ie.current)==null||l.closeAllOverlays()}}),[]);const Oe=y.normalizeEditorTheme(qe||(T==null?void 0:T.theme)),V={...y.getThemeRuntimeVariables(Oe),width:typeof s=="number"?`${s}px`:s,height:typeof o=="number"?`${o}px`:o,position:"relative",overflow:"hidden",...d};return e.createElement(e.Fragment,null,e.createElement("div",{ref:Fe,className:`rulego-editor-wrapper ${u||""}`,"data-theme":Oe,"data-rg-theme":Oe,style:V}),f&&It.map(l=>en.createPortal(f(l.type,l.data,l.model),l.el)),st.map(l=>{const m=l.kind==="region"?p==null?void 0:p[l.name]:S==null?void 0:S[l.name];return en.createPortal(typeof m=="function"?m(l.context):m,l.container,`host-${l.id}`)}))});Na.displayName="RuleGoEditor";function To(t,r){if(!t)return!1;let n=t;for(const o of r.split(".")){if(!n||typeof n!="object")return!1;n=n[o]}return typeof n=="string"}function ln(t){const r=String(t||"").toLowerCase().replace("_","-");return r==="en"||r.startsWith("en-")?"en-US":"zh-CN"}function ka(t,r,n){if(!t)return;const o=t(r,n);return o&&o!==r?o:void 0}function Ge(t={}){const r=ln(t.locale),n=new y.I18nManager({locale:r,fallback:r==="en-US"?"zh-CN":"en-US"});return n.register("zh-CN",y.localeZhCN),n.register("en-US",y.localeEnUS),t.messages&&n.register(r,t.messages),(o,s="",u)=>{const d=ka(t.t,o,u);if(d!==void 0)return d;const p=n.t(o,u);return p&&p!==o?p:s||o}}function Io(t,r,n,o){const s=String(t.name||"").trim(),u=`fields.${s}`,d=ka(n,u);if(d!==void 0)return d;if(To(o,u)){const p=r(u,t.label||s);if(p&&p!==u)return p}return t.label?t.label:r(u,s)}function Nn(t,r){const n=t(`relationTypes.${r}`,r);return n&&n!==r?`${n} (${r})`:r}const Po=t=>JSON.stringify(["category",t]),Jn=(t,r)=>JSON.stringify(["subgroup",t,r]),Do=JSON.stringify(["recent"]);function kn(t){if(!/[<&]/.test(t)||typeof document>"u")return t;const r=document.createElement("template");return r.innerHTML=t,r.content.querySelectorAll("script, style").forEach(n=>n.remove()),r.content.querySelectorAll("br, p, div, li").forEach(n=>n.append(" ")),(r.content.textContent||"").replace(/\s+/g," ").trim()}function zn(t,r){return t.label||t.type}function Qr(t){return JSON.stringify([t.type,t.isSharedNode?t.sharedNodeId??"":""])}function Gn(t,r){return kn(t.desc||"")}function Yn(t){return y.DEFAULT_COMPONENT_CATEGORY_ORDER.includes(t)?t:"other"}function Vr(t,r,n){return Math.max(n,Number.isFinite(t)?Number(t):r)}function Ar({name:t}){return e.createElement("span",{"aria-hidden":"true",className:"rge-sidebar-control-icon",dangerouslySetInnerHTML:{__html:y.getEditorToolbarIconSvg(t)||""}})}function Xn({items:t,label:r,listKey:n,virtualization:o,renderItem:s}){const u=e.useRef(null),d=e.useRef(null),[p,S]=e.useState(0),w=Vr(o==null?void 0:o.itemHeight,y.DEFAULT_VIRTUAL_WINDOW_ITEM_HEIGHT,36),R=(o==null?void 0:o.enabled)!==!1&&t.length>Vr(o==null?void 0:o.threshold,y.DEFAULT_VIRTUAL_WINDOW_THRESHOLD,1),b=y.calculateVirtualWindow({total:t.length,itemHeight:w,viewportHeight:Vr(o==null?void 0:o.viewportHeight,y.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT,w),overscan:Vr(o==null?void 0:o.overscan,y.DEFAULT_VIRTUAL_WINDOW_OVERSCAN,0),scrollTop:p});e.useLayoutEffect(()=>{var E,W;R&&u.current&&u.current.scrollTop!==b.scrollTop&&(u.current.scrollTop=b.scrollTop),d.current!==null&&((W=(E=u.current)==null?void 0:E.querySelector(`[data-component-index="${d.current}"]`))==null||W.focus(),d.current=null)});const x=E=>{var C;if(E.altKey||E.ctrlKey||E.metaKey||E.nativeEvent.isComposing)return;const W=E.target.closest("[data-component-index]");if(!W)return;const B=Number(W.dataset.componentIndex),U=E.key==="Home"?0:E.key==="End"?t.length-1:E.key==="ArrowDown"?B+1:E.key==="ArrowUp"?B-1:E.key==="Tab"&&R?B+(E.shiftKey?-1:1):-1;if(U<0||U>=t.length){["ArrowDown","ArrowUp","Home","End"].includes(E.key)&&(E.preventDefault(),E.stopPropagation());return}const q=(C=u.current)==null?void 0:C.querySelector(`[data-component-index="${U}"]`);E.key==="Tab"&&q||(E.preventDefault(),E.stopPropagation(),q?q.focus():(d.current=U,S(Math.min(U*w,b.totalHeight-b.viewportHeight))))},_=R?b.start:0;return e.createElement("div",{ref:u,className:`rge-sidebar-component-list${R?" rge-sidebar-virtual-list":""}`,role:"group","aria-label":r,"data-sidebar-virtualized":R?"true":void 0,"data-sidebar-virtual-key":R?n:void 0,"data-sidebar-virtual-total":R?t.length:void 0,style:{"--rge-sidebar-item-height":`${w}px`,height:R?`${b.viewportHeight}px`:void 0},onKeyDown:x,onScroll:E=>{R&&S(E.currentTarget.scrollTop)}},e.createElement("div",{className:"rge-sidebar-virtual-list__canvas",style:R?{height:`${b.totalHeight}px`}:void 0},e.createElement("div",{className:"rge-sidebar-virtual-list__items",style:R?{transform:`translateY(${b.offsetTop}px)`}:void 0},(R?t.slice(b.start,b.end):t).map((E,W)=>e.createElement("div",{key:Qr(E),className:"rge-sidebar-item"},s(E,_+W))))))}let Lo=0;const Mo=e.useId??function(){const[r]=e.useState(()=>`rge-sidebar-${++Lo}`);return r},wa=({components:t,onDragStart:r,recentComponentTypes:n=[],showRecent:o=!0,collapsed:s=!1,defaultCollapsed:u=!0,showSearch:d=!0,search:p,onSearchChange:S,searchPlaceholder:w,showNodeMgt:R=!0,onOpenNodeMgt:b,locale:x,messages:_,t:E,theme:W="default",virtualization:B})=>{const U=Mo(),q=e.useRef(null),[C,O]=e.useState(""),[j,k]=e.useState({}),[v,ae]=e.useState({query:"",values:{}}),J=(p??C).trim().toLowerCase().replace(/\s+/g," "),Y=!!J;e.useEffect(()=>ae({query:J,values:{}}),[J]);const re=y.normalizeIconTheme(W),ce=ln(x)==="en-US",g=e.useMemo(()=>{const K=Ge({locale:x,messages:_,t:E});return(le,de="")=>{const z=K(le,de);return z===le?de:z}},[x,_,E]),F=e.useMemo(()=>{const K=new Set,le=t.filter(de=>{var G;const z=Qr(de);return!((G=de.type)!=null&&G.trim())||K.has(z)?!1:(K.add(z),!0)}).map(de=>y.localizeComponentDefinition(y.normalizeComponentCategory({...de,category:de.category||"other",label:de.label||de.type,desc:de.desc||"",icon:de.icon||"",fields:de.fields||null,relationTypes:Array.isArray(de.relationTypes)?de.relationTypes:[]}),z=>g(z,z)));return y.buildComponentPalette(le,"",{categoryOrder:y.DEFAULT_COMPONENT_CATEGORY_ORDER,subgroupCategories:y.hasDeclaredSubgroups,categoryLabel:(de,z)=>{var G;return g(`category.${de}.label`,g(`category.${de}`,String(((G=z[0])==null?void 0:G.categoryLabel)||de)))}}).map(de=>({...de,key:Po(de.category),subgroups:de.subgroups.map(z=>({...z,label:z.id?z.label:g("category.other","Other"),description:kn(z.description||"")}))}))},[t,g]),ee=e.useMemo(()=>{if(!Y)return F;const K=new Map;for(const de of F)for(const z of de.subgroups)for(const G of z.components)K.set(Qr(G),[zn(G),Gn(G),kn(G.desc),de.label,z.label,z.description||"",...Array.isArray(G.keywords)?G.keywords.map(String):[String(G.keywords||"")]]);const le=y.buildComponentPalette(F.flatMap(de=>de.components),J,{categoryOrder:y.DEFAULT_COMPONENT_CATEGORY_ORDER,subgroupCategories:y.hasDeclaredSubgroups,componentSearchText:de=>K.get(Qr(de))});return F.flatMap(de=>{const z=le.find(G=>G.category===de.category);return z?[{...de,components:z.components,subgroups:de.subgroups.flatMap(G=>{const ye=z.subgroups.find(ke=>ke.id===G.id);return ye?[{...G,components:ye.components}]:[]})}]:[]})},[F,Y,J,g]),P=e.useMemo(()=>{if(!o||Y)return[];const K=new Map(F.flatMap(le=>le.components).map(le=>[le.type,le]));return[...new Set(n)].flatMap(le=>K.has(le)?[K.get(le)]:[])},[F,Y,n,o]),Z=P.length?[{key:Do,recent:!0,category:"common",color:"",label:g("editor.sidebar.recentComponents","Recently Used"),components:P,subgroups:[]},...ee]:ee,pe=K=>K.subgroups.some(le=>!!le.id),Te=Z.flatMap(K=>[K.key,...pe(K)?K.subgroups.map(le=>Jn(K.category,le.id)):[]]),Pe=K=>Y?(v.query===J?v.values[K]:void 0)??!0:j[K]??!u,_e=Te.length>0&&Te.every(Pe),me=Te.some(Pe),H=K=>{Y?ae(le=>({query:J,values:{...le.query===J?le.values:{},...K}})):k(le=>({...le,...K}))},ne=K=>{p===void 0&&O(K),S==null||S(K)},M=()=>{var K;ne(""),(K=q.current)==null||K.focus()},ge=K=>`${U}-${encodeURIComponent(K)}`,xe=g(me?"editor.sidebar.collapseAll":"editor.sidebar.expandAll"),se=g("editorShell.clearSearch",ce?"Clear search":"清空搜索"),Ce=g("editor.toolbar.componentManage"),Re=(K,le)=>{const de=zn(K),z=Gn(K),G=Yn(K.category),ye=y.resolveComponentIconUrl({...K,icon:void 0},{theme:re}),ke=K.themeColorMode==="theme"?void 0:K.background,$e=y.safeCssColor(K.color||ke,`var(--rg-node-${G}-stroke, var(--rge-sidebar-accent))`),at=y.safeCssColor(ke,`var(--rg-node-${G}-bg, var(--rge-sidebar-input-bg))`);return e.createElement("button",{type:"button",className:"rge-node-block",draggable:!0,"data-component-type":K.type,"data-component-index":le,"aria-label":de,"aria-description":z||void 0,title:[de,K.type,z].filter(Boolean).join(`
2
+ `),style:{"--rge-component-accent":$e,"--rge-component-bg":at},onClick:()=>r==null?void 0:r(K),onKeyDown:qe=>{qe.key!=="Enter"&&qe.key!==" "||(qe.preventDefault(),qe.stopPropagation(),!qe.repeat&&!qe.nativeEvent.isComposing&&(r==null||r(K)))},onDragStart:qe=>{var He,_t;const X=JSON.stringify(K);(He=qe.dataTransfer)==null||He.setData("application/json",X),(_t=qe.dataTransfer)==null||_t.setData("application/rulego-component",X),qe.dataTransfer&&(qe.dataTransfer.effectAllowed="copy"),r==null||r(K)}},e.createElement("span",{className:"rge-node-block__icon","aria-hidden":"true"},e.createElement("img",{key:`${K.icon}-${re}`,src:y.resolveComponentIconUrl(K,{theme:re}),alt:"",draggable:!1,className:"rge-node-block__icon-img",onError:qe=>{qe.currentTarget.getAttribute("src")!==ye&&(qe.currentTarget.src=ye)}})),e.createElement("span",{className:"rge-node-block__label"},de),!K.notInput&&e.createElement("span",{"aria-hidden":"true",className:"rge-node-block__port rge-node-block__port--input"}),!K.notOutput&&e.createElement("span",{"aria-hidden":"true",className:"rge-node-block__port rge-node-block__port--output"}))};return s?null:e.createElement("aside",{className:"rge-component-sidebar","aria-label":g("editor.sidebar.ariaLabel"),"data-theme":re,"data-rg-theme":re,style:y.getThemeRuntimeVariables(re)},d&&e.createElement("div",{className:"rge-sidebar-search"},e.createElement("div",{className:"rge-sidebar-search-field"},e.createElement(Ar,{name:"search"}),e.createElement("input",{ref:q,type:"search",className:"rge-search-input","aria-label":g("editor.sidebar.search"),placeholder:w??g("editor.sidebar.search"),value:p??C,onChange:K=>ne(K.target.value),onKeyDown:K=>{K.stopPropagation(),K.key==="Escape"&&(K.preventDefault(),M())}}),(p??C).length>0&&e.createElement("button",{type:"button",className:"rge-sidebar-clear",title:se,"aria-label":se,onClick:M},e.createElement(Ar,{name:"error"}))),e.createElement("button",{type:"button",className:"rge-sidebar-toggle-all","data-sidebar-toggle":"all",title:xe,"aria-label":xe,"aria-pressed":me&&!_e?"mixed":_e,disabled:!Te.length,onClick:()=>H(Object.fromEntries(Te.map(K=>[K,!me])))},e.createElement(Ar,{name:me?"collapse-all":"expand-all"})),R&&e.createElement("button",{type:"button",className:"rge-sidebar-manage",title:Ce,"aria-label":Ce,disabled:!b,onClick:b},e.createElement(Ar,{name:"settings"}))),e.createElement("div",{className:"rge-sidebar-groups"},Z.map(K=>{const le=Pe(K.key);return e.createElement("section",{key:K.key,className:"rge-sidebar-group","data-sidebar-category":K.recent?void 0:K.category,"data-sidebar-recent":K.recent?"true":void 0},e.createElement("button",{type:"button",className:`rge-group-header${le?" expanded":""}`,title:K.label,"aria-expanded":le,"aria-controls":ge(K.key),onClick:()=>H({[K.key]:!le})},e.createElement("span",{className:"rge-group-icon","aria-hidden":"true"},e.createElement("img",{src:y.resolveIconUrl(`images/${Yn(K.category)}-dark.svg`,{theme:re}),alt:"",draggable:!1,className:"rge-group-icon-img"})),e.createElement("span",{className:"rge-group-label"},K.label),e.createElement("span",{className:"rge-group-count"},K.components.length),e.createElement("span",{"aria-hidden":"true",className:`rge-group-arrow${le?" rotated":""}`},"›")),e.createElement("div",{id:ge(K.key),hidden:!le,className:"rge-group-content"},le&&(pe(K)?K.subgroups.map(de=>{const z=Jn(K.category,de.id),G=Pe(z);return e.createElement("section",{key:z,className:"rge-sidebar-subgroup"},e.createElement("button",{type:"button",className:"rge-subgroup-header","aria-expanded":G,"aria-controls":ge(z),title:[de.label,de.description].filter(Boolean).join(`
3
+ `),onClick:()=>H({[z]:!G})},e.createElement("span",{"aria-hidden":"true",className:`rge-subgroup-arrow${G?" rotated":""}`},"›"),e.createElement("span",null,de.label),e.createElement("small",null,de.components.length)),e.createElement("div",{id:ge(z),hidden:!G,className:"rge-subgroup-content"},G&&e.createElement(Xn,{key:J,items:de.components,label:de.label,listKey:z,virtualization:B,renderItem:Re})))}):e.createElement(Xn,{key:J,items:K.components,label:K.label,listKey:K.key,virtualization:B,renderItem:Re}))))}),ee.length===0&&e.createElement("div",{className:"rge-sidebar-empty",role:"status","aria-live":"polite"},e.createElement(Ar,{name:"package"}),e.createElement("p",null,Y?g("editor.sidebar.noResult"):g("editorShell.noComponents",ce?"No components available":"暂无可用组件")))))};wa.displayName="ComponentSidebar";function Br(t,r){const n=e.useRef(r);n.current=r;const o=()=>y.createDefaultDialogProvider({t:(w,R)=>{var b;return((b=n.current)==null?void 0:b.call(n,w,R))||R},container:()=>{var w;return((w=document.activeElement)==null?void 0:w.closest("[data-rg-theme], .rge-node-drawer"))||document.body}}),s=e.useRef("");s.current=JSON.stringify(t);const u=e.useRef(!0),d=e.useRef();d.current||(d.current=o()),e.useEffect(()=>(u.current=!0,d.current||(d.current=o()),()=>{var w,R;u.current=!1,(R=(w=d.current)==null?void 0:w.destroy)==null||R.call(w),d.current=void 0}),[]);const p=e.useCallback(()=>{const w=s.current;return()=>u.current&&s.current===w},[]);return{confirm:e.useCallback(async(w,R=p())=>{try{return await d.current.confirm({message:w,type:"warning"})===!0&&R()}catch{return!1}},[p]),capture:p}}let Ao=0;const Oo=12,Qn=80;function $o(t){return{label:String((t==null?void 0:t.label)??(t==null?void 0:t.value)??""),value:String((t==null?void 0:t.value)??""),description:t!=null&&t.description?String(t.description):void 0}}function Zn(t,r){return t.replace(/\{\{\s*(\w+)\s*\}\}|\{(\w+)\}/g,(n,o,s)=>{const u=o||s;return Object.prototype.hasOwnProperty.call(r,u)?String(r[u]):""})}const nr=({name:t,value:r="",values:n,options:o=[],multiple:s=!1,allowCreate:u=!1,disabled:d=!1,placeholder:p="",searchPlaceholder:S="搜索选项...",noMatchText:w="没有匹配的选项",createOptionText:R="使用",selectedCountText:b="已选 {{count}} 项",resultCountText:x="显示 {{shown}} / {{total}} 项",moreOptionsText:_="结果较多,请继续输入关键词缩小范围",className:E="rge-form-select",threshold:W=Oo,maxVisibleOptions:B=Qn,onChange:U,onMultiChange:q})=>{var $t;const C=e.useRef(null),O=e.useRef(null),j=e.useRef(null),k=e.useRef(null),v=e.useRef(null),[ae]=e.useState(()=>`rge-select-${++Ao}`),[J,Y]=e.useState(!1),[re,ce]=e.useState(""),[g,F]=e.useState(0),[ee,P]=e.useState(1),Z=e.useMemo(()=>o.map($o),[o]),pe=Z.some(T=>T.value===""),Te=u||Z.length>W,Pe=e.useMemo(()=>n||(s&&r?r.split(",").map(T=>T.trim()).filter(Boolean):[]),[s,r,n]),_e=Z.find(T=>T.value===r),me=Pe.map(T=>{var Ie;return((Ie=Z.find(tt=>tt.value===T))==null?void 0:Ie.label)||T}).filter(Boolean),H=me.length,ne=H>0?Zn(b,{count:H}):"",M=me.slice(0,2).join(", "),ge=s?H?`${ne}: ${M}${me.length>2?" ...":""}`:p:(_e==null?void 0:_e.label)||r||p,xe=s?me.length?me.join(", "):p:ge,se=re.trim().toLowerCase(),Ce=e.useMemo(()=>se?Z.filter(T=>T.label.toLowerCase().includes(se)||T.value.toLowerCase().includes(se)||String(T.description||"").toLowerCase().includes(se)):Z,[se,Z]),Re=Math.max(1,Number(B)||Qn),K=Re*ee,le=e.useMemo(()=>Ce.slice(0,K),[Ce,K]),de=Math.max(0,Ce.length-le.length),z=Zn(x,{shown:le.length,total:Ce.length,selected:H,hidden:de}),G=re.trim(),ye=u&&!s&&G.length>0&&!Z.some(T=>T.value.toLowerCase()===se||T.label.toLowerCase()===se),ke=le.length+(ye?1:0);e.useEffect(()=>{var vt;if(!J||d||!Te){J&&$e();return}const T=O.current,Ie=j.current;if(!T||!Ie)return;const tt=y.bindAnchoredPopover({anchor:T,popup:Ie,owner:C.current||T,maxHeight:380,onDismiss:()=>$e()});return v.current=tt,(vt=k.current)==null||vt.focus({preventScroll:!0}),()=>{tt.destroy(),v.current=null}},[J,d,Te]),e.useEffect(()=>{var T;(T=v.current)==null||T.update()},[re,le]),e.useEffect(()=>{var tt;const T=(tt=j.current)==null?void 0:tt.querySelector(`[data-option-index="${g}"]`),Ie=T==null?void 0:T.parentElement;!T||!Ie||(T.offsetTop<Ie.scrollTop?Ie.scrollTop=T.offsetTop:T.offsetTop+T.offsetHeight>Ie.scrollTop+Ie.clientHeight&&(Ie.scrollTop=T.offsetTop+T.offsetHeight-Ie.clientHeight))},[g,J,le.length]),e.useEffect(()=>{if(!J)return;const T=Ce.findIndex(Ie=>s?Pe.includes(Ie.value):Ie.value===r);F(T>=0?T:0),T>=0&&P(Ie=>Math.max(Ie,Math.floor(T/Re)+1))},[J,re,s,Pe,r,Ce,Re]);const $e=(T=!1)=>{var Ie;Y(!1),ce(""),F(0),P(1),T&&((Ie=O.current)==null||Ie.focus({preventScroll:!0}))},at=()=>{d||(Y(!0),ce(""),P(1))},qe=T=>{q==null||q(T)},X=T=>{const Ie=Pe.includes(T)?Pe.filter(tt=>tt!==T):[...Pe,T];qe(Ie)},He=T=>{U(T),$e(!0)},_t=()=>{if(!(!J||ke<=0)){if(g<le.length){const T=le[g];if(!T)return;if(s){X(T.value);return}He(T.value);return}ye&&He(G)}},xt=T=>{if(!(d||T.nativeEvent.isComposing)){if(!J&&["ArrowDown","Enter"," "].includes(T.key)){T.preventDefault(),at();return}J&&(T.key==="ArrowDown"?(T.preventDefault(),F(Ie=>Math.min(ke-1,Ie+1))):T.key==="ArrowUp"?(T.preventDefault(),F(Ie=>Math.max(0,Ie-1))):T.key==="Home"?(T.preventDefault(),F(0)):T.key==="End"?(T.preventDefault(),P(Math.max(1,Math.ceil(Ce.length/Re))),F(Math.max(0,Ce.length+(ye?1:0)-1))):T.key==="Enter"?(T.preventDefault(),_t()):T.key==="Escape"&&(T.preventDefault(),$e(!0)))}};return Te?e.createElement("div",{className:"rge-search-select",ref:C,"data-searchable-select":t||void 0},e.createElement("button",{ref:O,type:"button",className:`rge-search-select-trigger ${E}`,disabled:d,"aria-haspopup":"listbox","aria-expanded":J,"aria-controls":J?ae:void 0,"aria-multiselectable":s||void 0,"data-selected-count":H,title:xe,onKeyDown:xt,onClick:()=>{d||(J?$e():at())}},e.createElement("span",{className:`rge-search-select-display${ge&&ge!==p?"":" is-placeholder"}`},s&&H>0&&e.createElement("span",{className:"rge-search-select-count"},ne),e.createElement("span",{className:"rge-search-select-display-text"},s&&H>0?M:ge||p)),e.createElement("span",{className:"rge-search-select-arrow"},"▾")),J&&en.createPortal(e.createElement("div",{ref:j,className:"rge-search-select-popover",onKeyDown:T=>T.stopPropagation()},e.createElement("input",{ref:k,className:"rge-search-select-input",value:re,onChange:T=>{ce(T.target.value),F(0),P(1)},onKeyDown:xt,placeholder:S,"aria-label":S||p,role:"combobox","aria-controls":ae,"aria-expanded":"true","aria-autocomplete":"list","aria-activedescendant":ke>0?`${ae}-${g}`:void 0}),e.createElement("div",{className:"rge-search-select-list",id:ae,role:"listbox","aria-multiselectable":s||void 0,onScroll:T=>{const Ie=T.currentTarget;de>0&&Ie.scrollTop+Ie.clientHeight>=Ie.scrollHeight-32&&P(tt=>tt+1)}},Ce.length===0&&!ye?e.createElement("div",{className:"rge-search-select-empty"},w):le.map((T,Ie)=>e.createElement("button",{type:"button",key:T.value,className:`rge-search-select-option${(s?Pe.includes(T.value):T.value===r)?" selected":""}${Ie===g?" active":""}`,role:"option",id:`${ae}-${Ie}`,"data-option-index":Ie,"aria-selected":s?Pe.includes(T.value):T.value===r,onMouseEnter:()=>F(Ie),onClick:()=>{if(s){X(T.value);return}He(T.value)}},e.createElement("span",{className:"rge-search-select-label"},T.label),T.label!==T.value&&e.createElement("span",{className:"rge-search-select-value"},T.value),T.description&&e.createElement("span",{className:"rge-search-select-desc"},T.description))),ye&&e.createElement("button",{type:"button",className:`rge-search-select-option rge-search-select-create${g===le.length?" active":""}`,role:"option",id:`${ae}-${le.length}`,"data-option-index":le.length,"aria-selected":!1,onMouseEnter:()=>F(le.length),onClick:()=>{He(G)}},e.createElement("span",{className:"rge-search-select-label"},R," ",G))),e.createElement("div",{className:"rge-search-select-footer","data-searchable-select-count":!0},e.createElement("span",null,z),de>0&&e.createElement("span",{className:"rge-search-select-more"},_))),(($t=C.current)==null?void 0:$t.ownerDocument.body)||document.body)):s?e.createElement("select",{className:E,value:Pe,multiple:!0,onChange:T=>{qe(Array.from(T.target.selectedOptions).map(Ie=>Ie.value))},disabled:d},Z.map(T=>e.createElement("option",{key:T.value,value:T.value},T.label))):e.createElement("select",{className:E,value:r,onChange:T=>U(T.target.value),disabled:d},p&&!pe&&e.createElement("option",{value:""},p),Z.map(T=>e.createElement("option",{key:T.value,value:T.value},T.label)))};nr.displayName="SearchableSelect";const be=({value:t,className:r=""})=>{const n=typeof t=="string"?y.getEditorToolbarIconSvg(t):null,o=`rge-editor-icon ${r}`.trim();return n?e.createElement("span",{className:o,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:n}}):e.createElement("span",{className:o,"aria-hidden":"true"},t)};function xr(t){if(t==null)return t;if(Array.isArray(t))return t.map(r=>xr(r));if(t instanceof Date)return new Date(t.getTime());if(typeof t=="object"){const r={};return Object.entries(t).forEach(([n,o])=>{r[n]=xr(o)}),r}return t}const Bt=t=>String(t.type||"").toLowerCase(),wn=t=>String(t||"").toLowerCase().includes("float"),Sa=t=>{const r=String(t||"").toLowerCase();return r==="number"||r.includes("int")||r.includes("float")},Et=t=>{var r;return String(((r=t.component)==null?void 0:r.type)||"").toLowerCase()},tn=t=>{var r;return String(((r=t.component)==null?void 0:r.source)||"").toLowerCase()},rn=t=>String(t&&typeof t=="object"?t.value??t.id??t.name??t.label??"":t??""),xa=t=>String(t&&typeof t=="object"?t.label??t.name??t.value??t.id??"":t??""),Fo=t=>{if(t&&typeof t=="object"){const r=t.description??t.desc??t.remark;return r==null?void 0:String(r)}},jo=t=>{if(t&&typeof t=="object"){const r=String(t.value??t.id??t.name??t.label??"");return{...t,label:String(t.label??t.name??r),value:r}}return{label:String(t??""),value:String(t??"")}},ea=(t,r)=>{const n=String(t.id??t.value??t.name??t.label??"").trim();if(!n)return null;const o=typeof t.labelKey=="string"?t.labelKey:"";return{label:(o?r(o,""):"")||String(t.label??t.name??n),value:n,url:typeof t.url=="string"?t.url:void 0,models:Array.isArray(t.models)?t.models.map(jo):[],defaultModel:typeof t.defaultModel=="string"?t.defaultModel:void 0}},Ra=t=>!!(t&&typeof t=="object"&&"name"in t&&("type"in t||"component"in t||"fields"in t||"defaultValue"in t||"desc"in t)),Bo=t=>Array.isArray(t)&&t.some(r=>Ra(r)),Sn=(t,r)=>{const n=[...t],o=new Set(n.map(rn));return(Array.isArray(r)?r:String(r??"").split(",").filter(Boolean)).forEach(u=>{const d=String(u??"");!d||o.has(d)||(n.push({label:d,value:d}),o.add(d))}),n.map(u=>({label:xa(u),value:rn(u),description:Fo(u)}))},vr=t=>{var r;return Et(t)==="select"||Bt(t)==="select"||tn(t)==="nodes"||tn(t)==="rulechains"||Array.isArray((r=t.component)==null?void 0:r.options)&&!Bo(t.component.options)||Array.isArray(t.options)},Ho=t=>Et(t)==="rulechainselector"||tn(t)==="rulechains",nn=t=>Et(t)==="switch"||["boolean","bool"].includes(Bt(t)),ta=t=>["textarea","json-editor"].includes(Et(t))||["textarea","json"].includes(Bt(t)),Or=t=>{const r=Et(t),n=Bt(t),o=t.name.toLowerCase();return r==="password"||n==="password"||/password|passwd|secret|token|api[_-]?key|private[_-]?key|pem/.test(o)},an=t=>Sa(t.type)||["input-number","slider"].includes(Et(t)),xn=t=>{const r=Et(t);if(r==="command"||r==="shell")return!0;const n=t.name.toLowerCase();if(n==="command")return!0;if(n!=="cmd")return!1;const o=`${t.label||""} ${t.desc||""}`.toLowerCase();return!o.trim()||o.includes("redis command")?!1:o.includes("shell")||o.includes("execute")||o.includes("command to execute")||o.includes("命令")||o.includes("执行")},Kr=t=>t.name==="jsScript"||t.name==="JsScript"||t.name==="script"||t.name.toLowerCase()==="template"||xn(t)||["codeeditor","code-editor","code","javascript","sql","monaco","json-editor","command","shell"].includes(Et(t))||["jsscript","json"].includes(Bt(t)),ra=t=>t==null?"":typeof t=="object"?JSON.stringify(t,null,2):String(t),na=t=>Et(t)==="switchnode",Cr=t=>{const r=Et(t);return r==="tools"||r==="subagents"},aa=t=>Et(t)==="subagents"?"subagent":"tool",or=t=>{const r=Bt(t),n=Et(t);return r==="array"||n==="array"||n==="table"},oa=t=>{const r=Bt(t),n=Et(t);return r==="struct"||r==="object"||n==="struct"||n==="object"},hr=t=>Bt(t)==="map"||Et(t)==="map",sa=t=>{const r=Et(t),n=Bt(t),o=t.name.toLowerCase();return r==="expr"||r==="expression"||n==="expr"||n==="expression"||o==="expr"||o==="expression"},la=t=>["date","datepicker","time","timepicker"].includes(Et(t)),ca=t=>Bt(t)==="duration"||Et(t)==="duration",Ir=t=>{var r;return Array.isArray(t.fields)&&t.fields.length>0?t.fields:Array.isArray((r=t.component)==null?void 0:r.options)?t.component.options.filter(Ra).map(n=>n):[]},Nr=(t,r)=>{if(!or(t))return!1;if(Ir(t).length>0)return!0;const n=Array.isArray(t.defaultValue)?t.defaultValue[0]:Array.isArray(r)?r[0]:null;return!!(n&&typeof n=="object"&&!Array.isArray(n))},Wo=t=>Array.isArray(t)?t:typeof t=="string"&&t.trim()?t.split(",").map(r=>r.trim()).filter(Boolean):[],Uo=t=>Array.isArray(t)?t.map(r=>({case:String((r==null?void 0:r.case)??(r==null?void 0:r.condition)??""),then:String((r==null?void 0:r.then)??(r==null?void 0:r.result)??"")})):[],qo=t=>Wo(t).map(r=>r&&typeof r=="object"&&!Array.isArray(r)?{...r}:{value:r});let Vo=0;const kr=(t,r)=>r===t||r.startsWith(`${t}.`);function Ko({field:t,value:r,onChange:n,onChildChange:o,translate:s}){const{confirm:u,capture:d}=Br([t,r],s),p=Ir(t),S=y.decodeTableRowsForEditing(p,r),w=H=>n(y.encodeTableRowsForStorage(p,H)),R=y.getTableColumns(p,S),b=y.getTableDetailFields(p),x=p.some(H=>String(H.name).trim().toLowerCase()==="type"),[_,E]=e.useState(1),[W,B]=e.useState(50),[U,q]=e.useState(""),[C,O]=e.useState([]),[j,k]=e.useState(null),[v,ae]=e.useState(""),[J,Y]=e.useState({prefix:"",start:0,count:10,step:1,type:"",namePrefix:""}),re=y.findDuplicateRowValues(S),ce=S.map((H,ne)=>({row:H,index:ne})).filter(({row:H})=>{const ne=U.trim().toLowerCase();return ne?R.some(M=>String(H[M]??"").toLowerCase().includes(ne)):!0}),g=y.paginateTableRows(ce,_,W);e.useEffect(()=>{E(H=>Math.min(H,g.totalPages)),O(H=>H.filter(ne=>ne>=0&&ne<S.length)),k(H=>H!==null&&H>=S.length?null:H)},[S.length,g.totalPages]);const F=(H,ne,M)=>{const ge=p.find(Re=>Re.name===ne),xe=y.coerceTableCellValue(ge,M),se=S.map((Re,K)=>K===H?{...Re,[ne]:xe}:Re),Ce=w(se);ge&&o(ge,`${t.name}.${H}.${ne}`,xe,Ce)},ee=(H,ne,M)=>{var le,de;const ge=p.find(z=>z.name===M),xe=H[M]??"",se=String(xe),Ce=ge?Et(ge):"",Re=Array.isArray((le=ge==null?void 0:ge.component)==null?void 0:le.options)?ge.component.options:Array.isArray(ge==null?void 0:ge.options)?ge.options:[];if(!!(ge&&Ce==="select"&&!((de=ge.component)!=null&&de.allowCreate))){const z=Sn(Re,xe),G=se===""&&!z.some(ye=>ye.value==="")?[{label:"",value:""},...z]:z;return e.createElement("select",{className:"rge-form-input",value:se,"data-point-cell":M,onChange:ye=>F(ne,M,ye.target.value)},G.map(ye=>e.createElement("option",{key:ye.value,value:ye.value},ye.label)))}return ge&&nn(ge)?e.createElement("input",{type:"checkbox",checked:!!xe,"data-point-cell":M,onChange:z=>F(ne,M,z.target.checked)}):e.createElement("input",{className:"rge-form-input",type:ge&&an(ge)?"number":"text",value:se,"data-point-cell":M,onChange:z=>F(ne,M,z.target.value)})},P=()=>{w([...S,y.createEmptyTableRow(p)]),E(Math.max(1,Math.ceil((S.length+1)/W))),b.length>0&&k(S.length)},Z=async H=>{if(H.length===0)return;const ne=s("editor.property.confirmDeleteRows",`确认删除 ${H.length} 行?`,{count:String(H.length)});if(!await u(ne))return;const M=new Set(H);w(S.filter((ge,xe)=>!M.has(xe))),O([]),k(null)},pe=H=>{if(!H)return;ae("");const ne=new FileReader,M=d();ne.onload=async()=>{if(!M())return;const ge=y.parseCsvTable(String(ne.result||""));if(ge.length===0)return;(!y.getPointTableImportDecision(S,ge).requiresConfirmation||await u(s("editor.property.confirmReplacePointTable",`导入 ${ge.length} 条将替换当前 ${S.length} 条点位,是否继续?`,{incoming:String(ge.length),existing:String(S.length)})))&&(w(ge),k(null))},ne.readAsText(H)},Te=async H=>{if(H){ae("");try{const ne=d(),M=await y.parseExcelTable(await H.arrayBuffer());if(!ne())return;if(M.length===0){ae(s("editor.property.emptyExcelTable","Excel 中没有有效数据"));return}(!y.getPointTableImportDecision(S,M).requiresConfirmation||await u(s("editor.property.confirmReplacePointTable",`导入 ${M.length} 条将替换当前 ${S.length} 条点位,是否继续?`,{incoming:String(M.length),existing:String(S.length)})))&&(w(M),k(null))}catch(ne){ae(s("editor.property.excelImportFailed","Excel 导入失败: {{message}}",{message:ne instanceof Error?ne.message:String(ne)}))}}},Pe=()=>{ae("");const H=y.serializeCsvTable(S,R),ne=new Blob([`\uFEFF${H}`],{type:"text/csv;charset=utf-8"}),M=URL.createObjectURL(ne),ge=document.createElement("a");ge.href=M,ge.download=`${t.name||"table"}.csv`,ge.click(),URL.revokeObjectURL(M)},_e=async()=>{ae("");try{const H=await y.serializeExcelTable(S,R),ne=H.buffer.slice(H.byteOffset,H.byteOffset+H.byteLength),M=new Blob([ne],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),ge=URL.createObjectURL(M),xe=document.createElement("a");xe.href=ge,xe.download=`${t.name||"table"}.xlsx`,xe.click(),URL.revokeObjectURL(ge)}catch(H){ae(s("editor.property.excelExportFailed","Excel 导出失败: {{message}}",{message:H instanceof Error?H.message:String(H)}))}},me=()=>{const H=y.generatePointRows({...J,type:x?J.type:void 0,existing:S});H.length>0&&w([...S,...H]),E(Math.max(1,Math.ceil((S.length+H.length)/W)))};return e.createElement("div",{className:"rge-point-table-editor"},e.createElement("div",{className:"rge-point-table-toolbar"},mr(t.desc)&&e.createElement("span",{className:"rge-point-table-desc"},mr(t.desc)),e.createElement("div",{className:"rge-point-table-actions"},e.createElement("input",{className:"rge-form-input",type:"search",value:U,placeholder:s("editor.property.searchTable","搜索表格"),onChange:H=>{q(H.target.value),E(1)}}),e.createElement("label",{className:"rge-point-table-file-button"},s("editor.property.importCsv","导入 CSV"),e.createElement("input",{type:"file",accept:".csv,text/csv",onChange:H=>{var ne;pe((ne=H.target.files)==null?void 0:ne[0]),H.currentTarget.value=""}})),e.createElement("label",{className:"rge-point-table-file-button"},s("editor.property.importExcel","导入 Excel"),e.createElement("input",{type:"file",accept:".xlsx,.xls,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel",onChange:H=>{var M;const ne=(M=H.currentTarget.files)==null?void 0:M[0];H.currentTarget.value="",Te(ne)}})),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:Pe,disabled:S.length===0},s("editor.property.exportCsv","导出 CSV")),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:()=>{_e()},disabled:S.length===0},s("editor.property.exportExcel","导出 Excel")),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:()=>Z(C),disabled:C.length===0},s("editor.property.deleteSelected","删除所选")),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:P},s("editor.panel.addPair","+ 添加"))),v&&e.createElement("span",{className:"rge-point-table-error",role:"alert"},v)),e.createElement("details",{className:"rge-point-table-generator"},e.createElement("summary",null,s("editor.property.generatePoints","批量生成点位")),e.createElement("div",{className:"rge-point-table-generator-grid"},e.createElement("input",{className:"rge-form-input",value:J.prefix,placeholder:s("editor.property.pointPrefix","地址前缀"),onChange:H=>Y({...J,prefix:H.target.value})}),e.createElement("input",{className:"rge-form-input",type:"number",value:J.start,placeholder:s("editor.property.pointStart","起始编号"),onChange:H=>Y({...J,start:Number(H.target.value)||0})}),e.createElement("input",{className:"rge-form-input",type:"number",min:"1",value:J.count,placeholder:s("editor.property.pointCount","数量"),onChange:H=>Y({...J,count:Math.max(1,Number(H.target.value)||1)})}),e.createElement("input",{className:"rge-form-input",type:"number",min:"1",value:J.step,placeholder:s("editor.property.pointStep","步长"),onChange:H=>Y({...J,step:Math.max(1,Number(H.target.value)||1)})}),x&&e.createElement("input",{className:"rge-form-input",value:J.type,placeholder:s("editor.property.pointType","数据类型"),onChange:H=>Y({...J,type:H.target.value})}),e.createElement("input",{className:"rge-form-input",value:J.namePrefix,placeholder:s("editor.property.pointNamePrefix","名称前缀"),onChange:H=>Y({...J,namePrefix:H.target.value})}),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:me},s("editor.panel.confirm","生成")))),e.createElement("div",{className:"rge-point-table-scroll"},e.createElement("table",{className:"rge-point-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,e.createElement("input",{type:"checkbox",checked:g.items.length>0&&g.items.every(H=>C.includes(H.index)),onChange:H=>O(H.target.checked?[...new Set([...C,...g.items.map(ne=>ne.index)])]:C.filter(ne=>!g.items.some(M=>M.index===ne)))})),R.map(H=>{var ne;return e.createElement("th",{key:H},((ne=p.find(M=>M.name===H))==null?void 0:ne.label)||H)}),e.createElement("th",null,s("editor.property.actions","操作")))),e.createElement("tbody",null,g.items.map(({row:H,index:ne})=>e.createElement(e.Fragment,{key:ne},e.createElement("tr",{className:re.has(String(H.name??"").trim())?"is-duplicate":void 0},e.createElement("td",null,e.createElement("input",{type:"checkbox",checked:C.includes(ne),onChange:M=>O(ge=>M.target.checked?[...new Set([...ge,ne])]:ge.filter(xe=>xe!==ne))})),R.map(M=>e.createElement("td",{key:M},ee(H,ne,M))),e.createElement("td",{className:"rge-point-row-actions"},b.length>0&&e.createElement("button",{type:"button",className:"rge-btn-icon-edit","data-point-edit":ne,"aria-expanded":j===ne,title:s("editor.property.editRowDetails","编辑行详情"),onClick:()=>k(M=>M===ne?null:ne)},"✎"),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",title:s("editor.property.delete","删除"),onClick:()=>Z([ne])},"×"))),b.length>0&&j===ne&&e.createElement("tr",{className:"rge-point-detail-row","data-point-detail-row":ne},e.createElement("td",{colSpan:R.length+2},e.createElement("div",{className:"rge-point-detail-grid"},b.map(M=>e.createElement("label",{key:M.name,className:"rge-point-detail-field"},e.createElement("span",null,M.label||M.name),ee(H,ne,M.name),mr(M.desc)&&e.createElement("small",null,mr(M.desc))))))))))),g.items.length===0&&e.createElement("div",{className:"rge-point-table-empty"},s("editor.property.noRows","暂无数据"))),e.createElement("div",{className:"rge-point-table-pagination"},e.createElement("span",null,s("editor.property.tableCount",`共 ${g.total} 条`,{count:String(g.total)})),e.createElement("select",{value:W,onChange:H=>{B(Number(H.target.value)),E(1)}},e.createElement("option",{value:"20"},"20"),e.createElement("option",{value:"50"},"50"),e.createElement("option",{value:"100"},"100"),e.createElement("option",{value:"200"},"200")),e.createElement("button",{type:"button",disabled:_<=1,onClick:()=>E(H=>H-1)},s("editor.property.prevPage","上一页")),e.createElement("span",null,g.page," / ",g.totalPages),e.createElement("button",{type:"button",disabled:_>=g.totalPages,onClick:()=>E(H=>H+1)},s("editor.property.nextPage","下一页"))))}const Jo=(t,r)=>{const n=Ir(t);if(n.length>0)return n.map(s=>s.name).filter(Boolean);const o=r[0]||(Array.isArray(t.defaultValue)&&t.defaultValue[0]&&typeof t.defaultValue[0]=="object"?t.defaultValue[0]:{});return Object.keys(o)},zo=(t,r)=>{if(!t)return r;if(nn(t))return!!r;if(an(t)){const n=String(r??"");return n?wn(t.type)||Bt(t)==="number"?Number(n):parseInt(n,10):""}return r},Ta=(t,r)=>{const n=String(r??"").trim();return n?{label:String(t??n)||n,value:n}:null},Rn=12,wr=(t=Rn)=>({items:[],total:0,page:1,size:t,loading:!1,error:""}),on=(t,r,n)=>{const o=Ta(t,r);if(!o)return null;const s=String((n==null?void 0:n.description)??(n==null?void 0:n.desc)??(n==null?void 0:n.remark)??"").trim();return{...o,root:typeof(n==null?void 0:n.root)=="boolean"?n.root:void 0,description:s||void 0}},Tn=t=>{if(!t||typeof t!="object")return on(t,t);const r=t,n=r.ruleChain&&typeof r.ruleChain=="object"?r.ruleChain:r,o=n.id??r.id??r.value,s=n.name??r.name??r.label??o;return on(s,o,n)},Jr=(t,r,n)=>{const o=y.normalizePagedResponse(t,s=>s,r,n);return{items:o.items,total:o.total,page:o.page,size:o.pageSize}},Go=(t,r)=>{const n=String(t||r||"").trim().replace(/\/+$/,"");return n?/\/rules$/i.test(n)?n:`${n}/rules`:""},zr=(t,r)=>{if(r.length===0)return t;const n={...t};return r.forEach(o=>{n[o.value]=o}),n},Yo=(t,r)=>{var u;const n=String((r==null?void 0:r.id)||(r==null?void 0:r.nodeId)||"").trim(),o=new Set,s=[];for(const d of t||[]){const p=d,S=p.properties,w=(S==null?void 0:S.model)||S||p,R=String(w.id||p.id||"").trim();if(!R||R===n||o.has(R))continue;const b=typeof p.text=="object"?(u=p.text)==null?void 0:u.value:p.text,x=Ta(w.name||b||R,R);x&&(o.add(x.value),s.push(x))}return s},Xo=t=>{const r=(t==null?void 0:t.ruleChain)||t;return String((r==null?void 0:r.id)||(t==null?void 0:t.id)||(t==null?void 0:t.value)||"").trim()},Qo=t=>{const r=new Set,n=[];for(const o of t||[]){const s=(o==null?void 0:o.ruleChain)||o,u=String((s==null?void 0:s.id)||(o==null?void 0:o.id)||(o==null?void 0:o.value)||"").trim(),d=(s==null?void 0:s.name)||(o==null?void 0:o.name)||(o==null?void 0:o.label)||u,p=on(d,u,s);!p||r.has(p.value)||(r.add(p.value),n.push(p))}return n},Zo=t=>{const r=new Set,n=[];for(const o of t||[]){const s=o&&typeof o=="object"?o:void 0,u=on(xa(o),rn(o),s);!u||r.has(u.value)||(r.add(u.value),n.push(u))}return n},es=(t,r)=>r==="root"?t.root!==!1:t.root===!1||t.root===void 0,Sr=t=>String(t.name||t.targetId||""),ia=t=>String(t.description||t.desc||""),ts=(t,r)=>{var o,s;if(String(t.type||"")!=="builtin")return!1;const n=Sr(t);return n?!!((s=(o=r.find(u=>u.value===n))==null?void 0:o.fields)!=null&&s.length):!1},rs=(t,r,n)=>r!=="tool"||String(t.type||"")!=="builtin"||ts(t,n),fn=(t,r=120)=>{const n=String(t??"").replace(/\s+/g," ").trim();return n.length<=r?n:`${n.slice(0,r)}...`},ns=t=>{const n=(t!=null&&t.additionalInfo&&typeof t.additionalInfo=="object"?t.additionalInfo:{}).inputSchema??(t==null?void 0:t.inputSchema);return y.stringifyToolJson(n,"{}")},bn=t=>{var s;if(!t||typeof t!="object")return Tn(t);const r=t,n=r.ruleChain&&typeof r.ruleChain=="object"?r.ruleChain:r,o=Tn(r);return o?{...o,description:o.description||String(((s=n.additionalInfo)==null?void 0:s.description)||n.description||n.desc||""),raw:n}:null},hn=t=>{const r=new Set,n=[];return t.forEach(o=>{!o.value||r.has(o.value)||(r.add(o.value),n.push(o))}),n},as=t=>t.length>0?Math.max(...t.map(r=>Number(r.order||0))):0,os=(t,r,n,o)=>y.updateSchemaRowsAtParent(t,r,s=>{const u=n+o;if(u<0||u>=s.length)return;const[d]=s.splice(n,1);if(!d)return;s.splice(u,0,d);const p=y.renumberSchemaRowOrders(s);s.splice(0,s.length,...p)}),mr=t=>{const r=["rulego","cc"].join("\\.");return String(t??"").replace(new RegExp(`<a\\b[^>]*href=["'][^"']*${r}[^"']*["'][^>]*>[\\s\\S]*?<\\/a>`,"gi"),"").replace(new RegExp(`https?:\\/\\/[^\\s"'<>]*${r}[^\\s"'<>]*`,"gi"),"").replace(/<[^>]+>/g,"").replace(/\s+/g," ").trim()},Ia=({visible:t,nodeModel:r,nodeView:n,onSubmit:o,onClose:s,locale:u,messages:d,t:p,graphNodes:S,ruleItems:w,currentRuleChain:R,rulesApi:b,apiBase:x,rulePageSize:_,fetchRuleChains:E,componentsPayload:W,componentPayload:B,builtinTools:U,tools:q,skillPath:C,fetchBuiltinTools:O,onOpenAiAssistant:j,aiProviders:k,aiEmbeddingProviders:v,resolveFieldsByType:ae,optionSourceRegistry:J,fieldChangeRegistry:Y,onFieldChangeError:re,initializeDefaults:ce=!1})=>{var Kn;const[g,F]=e.useState({}),[ee,P]=e.useState("{}"),[Z,pe]=e.useState(""),[Te,Pe]=e.useState({}),[_e,me]=e.useState({}),[H,ne]=e.useState({}),[M,ge]=e.useState("custom"),[xe,se]=e.useState(""),[Ce,Re]=e.useState("custom"),[K,le]=e.useState(""),[de,z]=e.useState([]),[G,ye]=e.useState(null),[ke,$e]=e.useState(()=>wr()),[at,qe]=e.useState({}),[X,He]=e.useState(null),[_t,xt]=e.useState([]),[$t,T]=e.useState(!1),[Ie,tt]=e.useState(""),[vt,ft]=e.useState(()=>wr()),[Kt,Tt]=e.useState({}),[dt,pt]=e.useState(""),[Ht,Rt]=e.useState(""),[Wt,Je]=e.useState({}),[Zt,Pt]=e.useState(0),[Jt]=e.useState(()=>`react-drawer-${++Vo}`),Ft=e.useRef(""),bt=e.useRef({}),Dt=e.useRef({}),ht=e.useRef({}),jt=e.useRef(null),Ct=e.useRef(new Map),Lt=e.useRef({}),Mt=e.useRef(new Set),ue=e.useRef(new Set),ve=e.useRef(""),Se=e.useMemo(()=>new y.OptionSourceRegistry,[]),f=e.useMemo(()=>Ge({locale:u,messages:d,t:p}),[u,d,p]);bt.current=g,Dt.current=Te,ht.current=_e,ve.current=String((r==null?void 0:r.nodeId)||(r==null?void 0:r.id)||"");const fe=e.useCallback(a=>{const c=a(bt.current);return bt.current=c,F(c),c},[]),we=e.useCallback(a=>{const c=a(Dt.current);return Dt.current=c,Pe(c),c},[]),We=e.useCallback(a=>{const c=a(ht.current);return ht.current=c,me(c),c},[]);e.useEffect(()=>{var c;const a=new AbortController;return(c=jt.current)==null||c.abort(),jt.current=a,Ct.current.clear(),Pt(0),Lt.current={},ue.current.clear(),Je({}),()=>{a.abort(),jt.current===a&&(jt.current=null)}},[Y,r==null?void 0:r.id,r==null?void 0:r.nodeId,t]);const{confirm:Fe}=Br([t,R,r,g,Te,_e],f),ie=e.useCallback(async a=>{if(typeof window>"u")return;const c=f("editor.property.confirmDeleteRows","确认删除 1 行?",{count:"1"});await Fe(c)&&a()},[f,Fe]),wt=e.useMemo(()=>({searchPlaceholder:f("editor.property.searchOptions","搜索选项..."),noMatchText:f("editor.property.noMatchingOptions","没有匹配的选项"),createOptionText:f("editor.form.useInputValue","使用"),selectedCountText:f("editor.property.selectedCount","已选 {{count}} 项"),resultCountText:f("editor.property.selectResultCount","显示 {{shown}} / {{total}} 项"),moreOptionsText:f("editor.property.moreOptionsHint","结果较多,请继续输入关键词缩小范围")}),[f]),rt=e.useCallback(a=>Io(a,f,p,d),[d,p,f]),It=e.useMemo(()=>Yo(S,r),[S,r]),yt=e.useMemo(()=>Qo(w),[w]),st=e.useMemo(()=>Math.max(1,Number(_||Rn)||Rn),[_]),er=e.useMemo(()=>Go(b,x),[x,b]),ct=!!(E||er),At=e.useMemo(()=>y.getBuiltinToolOptionsFromSources(U,q,W,B),[U,B,W,q]),dr=e.useMemo(()=>_t.length>0?_t:At,[_t,At]),pr=e.useMemo(()=>y.getSkillPathFromSources(C,W,B),[B,W,C]),sr=e.useMemo(()=>yt.map(a=>({label:a.label,value:a.value})),[yt]),gt=e.useMemo(()=>Xo(R),[R]),Ut=e.useCallback(a=>n?y.resolveComponentFields(n,{configuration:a,getFieldsByType:ae}):[],[n,ae]),Ye=e.useMemo(()=>Ut(g.configuration||(r==null?void 0:r.configuration)||{}),[g.configuration,r==null?void 0:r.configuration,Ut]),ar=e.useMemo(()=>y.getVisibleComponentFields(Ye,g.configuration||{}),[g.configuration,Ye]),Ve=e.useMemo(()=>y.buildFieldAttachments(Ye),[Ye]),qt=e.useMemo(()=>new Set([...Ve.values()].flatMap(a=>a.map(c=>c.field.name))),[Ve]);Mt.current=qt;const De=dt?Ve.get(dt)||[]:[],gr=De.filter(a=>y.isFieldDependencySatisfied(a.field,g.configuration)),fr=new Set(De.map(a=>a.field.name)),ot=[...Ct.current.keys()].filter(a=>[...fr].some(c=>kr(c,a))).length,zt=Object.entries(Wt).filter(([a])=>ue.current.has(a)||[...qt].some(c=>kr(c,a))),mt=zt.filter(([a])=>[...fr].some(c=>kr(c,a))),Xe=e.useMemo(()=>{const a=[...(n==null?void 0:n.groups)||[]].sort((h,A)=>(h.order??0)-(A.order??0)),c=new Set,i=a.map(h=>{const A=new Set(h.fields||[]),$=ar.filter(D=>A.has(D.name));return $.forEach(D=>c.add(D.name)),{id:h.id,label:h.label||h.id,description:h.description,collapsed:h.collapsed,fields:$}}).filter(h=>h.fields.length>0),N=ar.filter(h=>!c.has(h.name));return N.length>0&&i.unshift({id:"",label:"",description:void 0,collapsed:!1,fields:N}),i},[n==null?void 0:n.groups,ar]),Oe=e.useMemo(()=>Ye.find(a=>a.ref==="primary")||null,[Ye]),V=e.useMemo(()=>Oe?null:Ye.find(a=>a.aiProvider||a.name==="provider")||null,[Oe,Ye]),Ee=e.useMemo(()=>{var a,c,i;return{provider:((a=V==null?void 0:V.aiProvider)==null?void 0:a.providerField)||(V==null?void 0:V.name)||"provider",url:((c=V==null?void 0:V.aiProvider)==null?void 0:c.urlField)||"url",model:((i=V==null?void 0:V.aiProvider)==null?void 0:i.modelField)||"model"}},[V]),l=e.useMemo(()=>V?(V.providerType==="embedding"?y.getAiEmbeddingProviders(v):y.getAiProviders(k)).map(c=>ea(c,f)).filter(Boolean):[],[v,k,V,f]),m=e.useCallback(a=>{var h;const c=Kt[a.name];if(a.optionsSource&&(c!=null&&c.options))return c.options;if(a.name===Ee.model&&de.length>0)return de;const i=((h=a.component)==null?void 0:h.options)||a.options||[],N=tn(a);return N==="nodes"&&It.length>0?It:N==="rulechains"&&sr.length>0?sr:i},[It,Kt,Ee.model,de,sr]),I=e.useMemo(()=>y.buildOptionSourceRequestKey(Ye,{configuration:g.configuration||{},currentNodeId:String((r==null?void 0:r.nodeId)||(r==null?void 0:r.id)||""),graphNodes:(S||[]).map(a=>{var c,i,N;return{id:String(a.id||a.nodeId||""),name:String(a.name||(typeof a.text=="object"?(c=a.text)==null?void 0:c.value:a.text)||a.id||a.nodeId||""),type:String(a.type||((N=(i=a.properties)==null?void 0:i.model)==null?void 0:N.type)||"")}}).filter(a=>!!a.id)}),[g.configuration,S,r==null?void 0:r.id,r==null?void 0:r.nodeId,Ye]);e.useEffect(()=>{const a=Ye.filter($=>$.optionsSource);if(a.length===0){Tt({});return}const c=new AbortController,i=J||Se,N=g.configuration||{},h=String((r==null?void 0:r.nodeId)||(r==null?void 0:r.id)||""),A=(S||[]).map($=>{var D,Q,Ne;return{id:String($.id||$.nodeId||""),name:String($.name||(typeof $.text=="object"?(D=$.text)==null?void 0:D.value:$.text)||$.id||$.nodeId||""),type:String($.type||((Ne=(Q=$.properties)==null?void 0:Q.model)==null?void 0:Ne.type)||"")}}).filter($=>!!$.id);return Tt($=>Object.fromEntries(a.map(D=>{var Q,Ne;return[D.name,{options:((Q=$[D.name])==null?void 0:Q.options)||((Ne=D.component)==null?void 0:Ne.options)||D.options||[],loading:!0,error:""}]}))),Promise.all(a.map(async $=>{try{const D=await i.resolve($,{configuration:N,currentNodeId:h,graphNodes:A,signal:c.signal});if(c.signal.aborted)return;Tt(Q=>({...Q,[$.name]:{options:D,loading:!1,error:""}}))}catch(D){if(c.signal.aborted)return;Tt(Q=>{var Ne,te;return{...Q,[$.name]:{options:((Ne=Q[$.name])==null?void 0:Ne.options)||((te=$.component)==null?void 0:te.options)||$.options||[],loading:!1,error:D instanceof Error?D.message:String(D)}}})}})),()=>c.abort()},[Se,J,I]);const L=e.useCallback((a,c,i=!1)=>{const N=Sn(m(a),c);return!i||!gt?N:N.filter(h=>h.value!==gt)},[gt,m]),oe=e.useCallback((a,c)=>{var $;const N=[...yt.length>0?yt:Zo((($=a.component)==null?void 0:$.options)||a.options||[])],h=new Set(N.map(D=>D.value));Object.values(at).forEach(D=>{h.has(D.value)||(N.push(D),h.add(D.value))});const A=String(c??"").trim();return A&&!h.has(A)&&N.push({label:A,value:A}),N},[at,yt]),je=e.useCallback((a,c)=>{var N;const i=String(c??"").trim();return i?((N=oe(a,i).find(h=>h.value===i))==null?void 0:N.label)||i:""},[oe]),nt=e.useCallback(()=>{const a=Object.values(at).map(i=>({...i})),c=yt.map(i=>({...i}));return hn([...c,...a].map(bn).filter(Boolean)).filter(i=>!gt||i.value!==gt)},[gt,at,yt]),ze=e.useMemo(()=>Oe?L(Oe,xe):[],[L,Oe,xe]);e.useEffect(()=>{var lt,Xt,tr;if(!r)return;const a=xr(r.configuration||{}),c=Ut(a);ce&&c.forEach(Ze=>{!(Ze.name in a)&&Ze.defaultValue!==void 0&&(a[Ze.name]=xr(Ze.defaultValue))});const i={id:r.id||"",nodeId:r.nodeId||"",type:r.type||"",name:r.name||"",debugMode:r.debugMode||!1,configuration:a,additionalInfo:r.additionalInfo||{}};bt.current=i,F(i);const N={},h={},A=new Map(c.map(Ze=>[Ze.name,Ze]));Object.entries(a).forEach(([Ze,et])=>{const ut=A.get(Ze);ut&&or(ut)&&!(vr(ut)||na(ut)||Nr(ut,et)||Cr(ut))&&(Array.isArray(et)||typeof et=="string")?h[Ze]=y.normalizeSimpleArrayValues(et).map(ir=>({value:ir})):ut&&hr(ut)&&!Array.isArray(et)&&et&&typeof et=="object"&&!(et instanceof Date)&&(N[Ze]=Object.entries(et).map(([ir,dn])=>({key:ir,value:y.formatMapEntryValue(dn,y.getMapValueMode(ut))})))}),Dt.current=N,ht.current=h,Pe(N),me(h),ne({});const $=c.find(Ze=>Ze.ref==="primary"),D=$!=null&&$.name?a[$.name]:"",Q=String(D??""),Ne=Q.startsWith("ref://");ge(Ne?"shared":"custom"),se(Ne?Q:"");const te=$?null:c.find(Ze=>Ze.aiProvider||Ze.name==="provider")||null,he={provider:((lt=te==null?void 0:te.aiProvider)==null?void 0:lt.providerField)||(te==null?void 0:te.name)||"provider",url:((Xt=te==null?void 0:te.aiProvider)==null?void 0:Xt.urlField)||"url",model:((tr=te==null?void 0:te.aiProvider)==null?void 0:tr.modelField)||"model"},Be=te?(te.providerType==="embedding"?y.getAiEmbeddingProviders(v):y.getAiProviders(k)).map(Ze=>ea(Ze,f)).filter(Boolean):[],Le={...a};if(te){const Ze=String(a[he.provider]??""),et=Be.find(ir=>ir.value===Ze),ut=!!(et&&Ze!=="custom");Re(ut?"preset":"custom"),le(ut?Ze:""),z(ut?(et==null?void 0:et.models)||[]:[]),ut&&(Le[he.provider]=Ze,et!=null&&et.url&&(Le[he.url]=et.url),et!=null&&et.defaultModel&&!Le[he.model]&&(Le[he.model]=et.defaultModel))}else Re("custom"),le(""),z([]);ye(null),$e(wr(st)),He(null),ft(wr(st)),P(JSON.stringify(a,null,2)),pe(""),pt(""),Rt(""),Ft.current=JSON.stringify(y.normalizeEditableNodeModel(r,{name:r.name||"",debugMode:r.debugMode||!1,configuration:Le,additionalInfo:r.additionalInfo||{}},{graphNodeId:r.id||r.nodeId||"",nodeViewType:n==null?void 0:n.type,graphNodeType:r.type,keepNodeId:!0}))},[ce,r,n,Ut]),e.useEffect(()=>{if(Ce!=="preset"||!K)return;const a=l.find(c=>c.value===K);a&&z(a.models||[])},[Ce,l,K]),e.useEffect(()=>{At.length!==0&&(xt(At),tt(""))},[At]);const Qe=e.useCallback((a,c)=>{fe(i=>({...i,[a]:c}))},[fe]),Ue=e.useCallback(()=>{const a={...bt.current.configuration||{}},c=new Map(Ye.map(i=>[i.name,i]));return Object.entries(Dt.current).forEach(([i,N])=>{const h=c.get(i);if(!h||!hr(h))return;const A={},$=y.getMapValueMode(h);N.forEach(D=>{D.key&&(A[D.key]=y.parseMapEntryValue(D.value,$))}),a[i]=A}),Object.entries(ht.current).forEach(([i,N])=>{const h=c.get(i);!h||!or(h)||Nr(h,a[i])||Cr(h)||vr(h)||(a[i]=N.map(A=>A.value).filter(Boolean))}),a},[Ye]),it=e.useCallback((a,c)=>{const i={...Ue(),[a]:c};return fe(N=>({...N,configuration:i})),i},[Ue,fe]),Gt=e.useCallback(a=>{const c=Ue();for(const h of a.remove||[])delete c[h];Object.assign(c,xr(a.patch||{})),fe(h=>({...h,configuration:c}));const i=new Set([...Object.keys(a.patch||{}),...a.remove||[]]),N=new Map(Ye.map(h=>[h.name,h]));if([...i].some(h=>hr(N.get(h)||{}))&&we(h=>{const A={...h};return i.forEach($=>{const D=N.get($);if(!D||!hr(D))return;const Q=c[$];!Q||typeof Q!="object"||Array.isArray(Q)?delete A[$]:A[$]=Object.entries(Q).map(([Ne,te])=>({key:Ne,value:y.formatMapEntryValue(te,y.getMapValueMode(D))}))}),A}),[...i].some(h=>{const A=N.get(h);return A&&or(A)&&!Nr(A,c[h])&&!Cr(A)&&!vr(A)})&&We(h=>{const A={...h};return i.forEach($=>{const D=N.get($);!D||!or(D)||Nr(D,c[$])||Cr(D)||vr(D)||(Object.prototype.hasOwnProperty.call(c,$)?A[$]=y.normalizeSimpleArrayValues(c[$]).map(Q=>({value:Q})):delete A[$])}),A}),Oe!=null&&Oe.name&&i.has(Oe.name)){const h=String(c[Oe.name]??"");se(h.startsWith("ref://")?h:""),ge(h.startsWith("ref://")?"shared":"custom")}if(i.has(Ee.provider)){const h=String(c[Ee.provider]??""),A=l.find($=>$.value===h);Re(A&&h!=="custom"?"preset":"custom"),le(A&&h!=="custom"?h:""),z((A==null?void 0:A.models)||[])}},[Ue,Oe,Ee.provider,l,We,fe,we,Ye]),Ke=e.useCallback((a,c,i,N)=>{const h=y.getFieldChangeHandlerName(a);if(!h)return;const A=ve.current,$=jt.current,D=(he,Be=0)=>{if($!=null&&$.signal.aborted||ve.current!==A)return;const Le=he instanceof Error?he.message:String(he);(Mt.current.has(a.name)||a.attachTo)&&ue.current.add(c);const lt={...Lt.current,[c]:Le};Lt.current=lt,Je(lt),re==null||re(he,{field:a,fieldPath:c,handlerName:h,generation:Be})};if(!Y||!$){D(new Error(f("editor.property.fieldChangeUnavailable","字段联动处理器不可用: {{name}}",{name:h})));return}ue.current.delete(c);const Q={...Lt.current};delete Q[c],Lt.current=Q,Je(Q);const Ne=(S||[]).map(he=>{var Be,Le,lt;return{id:String(he.id||he.nodeId||""),name:String(he.name||(typeof he.text=="object"?(Be=he.text)==null?void 0:Be.value:he.text)||he.id||he.nodeId||""),type:String(he.type||((lt=(Le=he.properties)==null?void 0:Le.model)==null?void 0:lt.type)||"")}}).filter(he=>!!he.id);let te;te=Y.execute(a,i,{configuration:N,currentNodeId:A,graphNodes:Ne,requestKey:`${Jt}:${A||"__draft__"}:${c}`,signal:$.signal,fieldPath:c}).then(he=>{he.status!=="applied"||$.signal.aborted||ve.current!==A||Gt(he)}).catch(he=>{$.signal.aborted||he instanceof Error&&he.name==="AbortError"||D(he)}).finally(()=>{Ct.current.get(c)===te&&(Ct.current.delete(c),Pt(Ct.current.size))}),Ct.current.set(c,te),Pt(Ct.current.size)},[Gt,Jt,Y,S,re,f]),Ae=e.useCallback((a,c,i)=>{const N=it(a.name,i);Ke(a,c,i,N)},[Ke,it]),Yt=e.useCallback((a,c)=>{$e(wr(st)),ye({fieldName:a.name,value:String(c??""),tab:"sub",keyword:"",page:1})},[st]),Vt=e.useCallback(a=>{ye(c=>c&&{...c,...a})},[]),yr=e.useCallback(a=>{if(!G)return;qe(i=>zr(i,[a]));const c=Ye.find(i=>i.name===G.fieldName);c?Ae(c,c.name,a.value):it(G.fieldName,a.value),ye(null)},[Ae,Ye,G,it]);e.useEffect(()=>{if(!G||!ct)return;const a=new AbortController,c=G.tab,i=G.keyword.trim(),N=G.page,h=st,A=window.setTimeout(()=>{$e($=>({...$,page:N,size:h,loading:!0,error:""})),(async()=>{try{let $;if(E)$=await E({root:c==="root",keywords:i,page:N,size:h,signal:a.signal});else{const te=new URLSearchParams;te.set("root",c==="root"?"true":"false"),i&&te.set("keywords",i),te.set("page",String(N)),te.set("size",String(h));const he=await fetch(`${er}?${te.toString()}`,{signal:a.signal});if(!he.ok)throw new Error(`HTTP ${he.status}`);$=await he.json()}const D=Jr($,N,h),Q=D.items.map(Tn).filter(Boolean),Ne=gt?Q.filter(te=>te.value!==gt):Q;if(a.signal.aborted)return;qe(te=>zr(te,Ne)),$e({items:Ne,total:Math.max(0,D.total-(Q.length-Ne.length)),page:D.page||N,size:D.size||h,loading:!1,error:""})}catch($){if(a.signal.aborted||($==null?void 0:$.name)==="AbortError")return;$e({items:[],total:0,page:N,size:h,loading:!1,error:f("editor.panel.loadFailed",`加载失败: ${($==null?void 0:$.message)||String($)}`,{message:String(($==null?void 0:$.message)||$)})})}})()},i?180:0);return()=>{window.clearTimeout(A),a.abort()}},[gt,st,E,G,er,f,ct]);const Dn=e.useCallback(async()=>{if(At.length>0){xt(At),tt("");return}const a=String(x||"").trim().replace(/\/+$/,"");if(!O&&!a)return;const c=new AbortController;T(!0),tt("");try{const i=O?await O({signal:c.signal}):await fetch(`${a}/components`,{signal:c.signal}).then(A=>{if(!A.ok)throw new Error(`HTTP ${A.status}`);return A.json()}),N=i&&typeof i=="object"&&"data"in i?i.data:i,h=y.getBuiltinToolOptionsFromSources(N,i);xt(h)}catch(i){(i==null?void 0:i.name)!=="AbortError"&&tt(f("editor.panel.loadFailed",`加载失败: ${(i==null?void 0:i.message)||String(i)}`,{message:String((i==null?void 0:i.message)||i)}))}finally{T(!1)}},[x,O,At,f]);e.useEffect(()=>{if(!X||X.step!=="select"||X.activeTab!=="rulechain"||!ct)return;const a=new AbortController,c=X.keyword.trim(),i=X.ruleChainPage,N=st,h=window.setTimeout(()=>{ft(A=>({...A,page:i,size:N,loading:!0,error:""})),(async()=>{try{let A;if(E){const[Ne,te]=await Promise.all([E({root:!1,keywords:c,page:i,size:N,signal:a.signal}),E({root:!0,keywords:c,page:i,size:N,signal:a.signal})]),he=Jr(Ne,i,N),Be=Jr(te,i,N);A={items:[...he.items,...Be.items],total:he.total+Be.total,page:i,size:N}}else{const Ne=new URLSearchParams;c&&Ne.set("keywords",c),Ne.set("page",String(i)),Ne.set("size",String(N));const te=await fetch(`${er}?${Ne.toString()}`,{signal:a.signal});if(!te.ok)throw new Error(`HTTP ${te.status}`);A=await te.json()}const $=Jr(A,i,N),D=$.items.map(bn).filter(Boolean),Q=hn(D).filter(Ne=>!gt||Ne.value!==gt);if(a.signal.aborted)return;qe(Ne=>zr(Ne,Q)),ft({items:Q,total:Math.max(0,$.total-(D.length-Q.length)),page:$.page||i,size:$.size||N,loading:!1,error:""})}catch(A){if(a.signal.aborted||(A==null?void 0:A.name)==="AbortError")return;ft({items:[],total:0,page:i,size:N,loading:!1,error:f("editor.panel.loadFailed",`加载失败: ${(A==null?void 0:A.message)||String(A)}`,{message:String((A==null?void 0:A.message)||A)})})}})()},c?180:0);return()=>{window.clearTimeout(h),a.abort()}},[gt,st,E,er,X,f,ct]);const Ln=e.useCallback(a=>{if(a===M||(ge(a),!(Oe!=null&&Oe.name)))return;const c=Ue(),i=String(c[Oe.name]??""),N=a==="shared"?xe.trim():i.startsWith("ref://")?"":i;if(N===i)return;const h={...c,[Oe.name]:N};fe(A=>({...A,configuration:h})),Ke(Oe,Oe.name,N,h)},[Ue,Oe,M,fe,Ke,xe]),Ga=e.useCallback(a=>{if(se(a),!(Oe!=null&&Oe.name))return;const c=a.trim(),i={...Ue(),[Oe.name]:c};fe(N=>({...N,configuration:i})),Ke(Oe,Oe.name,c,i)},[Ue,Oe,fe,Ke]),Ya=e.useCallback(a=>{const c=l.find($=>$.value===a);if(!c||!V)return;le(c.value),z(c.models);const i=Ue(),N=c.models.map(rn).filter(Boolean),h=String(i[Ee.model]??""),A={...i,[Ee.provider]:c.value,...c.url?{[Ee.url]:c.url}:{},[Ee.model]:c.defaultModel||(h&&N.includes(h)?h:N[0]||h)};fe($=>({...$,configuration:A})),Ke(V,Ee.provider,c.value,A)},[Ue,V,Ee,l,fe,Ke]),Mn=e.useCallback(a=>{if(!V)return;const c=Ue(),i=String(c[Ee.provider]??"");if(a===Ce&&!(a==="custom"&&i!=="custom")||(Re(a),a!=="custom"))return;le(""),z([]);const N={...c,[Ee.provider]:"custom",[Ee.url]:"",[Ee.model]:""};fe(h=>({...h,configuration:N})),i!=="custom"&&Ke(V,Ee.provider,"custom",N)},[Ue,V,Ee,Ce,fe,Ke]),Xa=e.useCallback(a=>vr(a)||a.name===Ee.model&&de.length>0,[Ee.model,de.length]),Qa=a=>{we(c=>({...c,[a]:[...c[a]||[],{key:"",value:""}]}))},Za=(a,c)=>{ie(()=>{we(i=>({...i,[a]:i[a].filter((N,h)=>h!==c)}))})},An=(a,c,i,N)=>{we(h=>({...h,[a]:h[a].map((A,$)=>$===c?{...A,[i]:N}:A)}))},eo=(a,c)=>{ie(()=>{We(i=>({...i,[a]:i[a].filter((N,h)=>h!==c)}))})},lr=e.useCallback((a,c)=>{const i=y.parseSimpleArrayInput(c);i.length>0&&We(N=>({...N,[a]:[...N[a]||[],...i.map(h=>({value:h}))]})),ne(N=>({...N,[a]:""}))},[We]),to=e.useCallback((a,c)=>{if(/[,,;;\n\t]/.test(c)){lr(a,c);return}ne(i=>({...i,[a]:c}))},[lr]),ro=e.useCallback((a,c)=>{["Enter",",",",",";",";","Tab"].includes(c.key)&&(c.key!=="Tab"&&c.preventDefault(),lr(a,H[a]||""))},[H,lr]),no=e.useCallback((a,c)=>{const i=c.clipboardData.getData("text");i&&(c.preventDefault(),lr(a,H[a]||""),lr(a,i))},[H,lr]),ao=e.useCallback(a=>{ie(()=>{We(c=>({...c,[a]:[]})),ne(c=>({...c,[a]:""}))})},[ie,We]),oo=e.useCallback((a,c,i)=>{c!==i&&We(N=>{const h=[...N[a]||[]];if(c<0||i<0||c>=h.length||i>=h.length)return N;const[A]=h.splice(c,1);return h.splice(i,0,A),{...N,[a]:h}})},[We]),Pr=e.useCallback((a,c)=>{fe(i=>{const N={...i.configuration};return N[a]=c(y.normalizeToolRows(N[a])),{...i,configuration:N}})},[fe]),Nt=e.useCallback(a=>{He(c=>c&&{...c,...a})},[]),cn=e.useCallback(a=>{He(c=>c&&{...c,draft:{...c.draft,...a},error:""})},[]),Er=e.useCallback((a,c)=>{He(i=>{if(!i)return i;const N=i.draft.config&&typeof i.draft.config=="object"&&!Array.isArray(i.draft.config)?i.draft.config:{};return{...i,draft:{...i.draft,config:{...N,[a]:c}},error:""}})},[]),cr=e.useCallback(a=>{He(c=>c&&{...c,schemaRows:a,parametersText:JSON.stringify(y.generateToolSchemaFromRows(a),null,2),error:""})},[]),On=e.useCallback(a=>{He(c=>{if(!c||c.schemaMode===a)return c;if(a==="code")return{...c,schemaMode:"code",parametersText:JSON.stringify(y.generateToolSchemaFromRows(c.schemaRows),null,2),error:""};try{return{...c,schemaMode:"visual",schemaRows:y.parseToolSchemaRows(y.parseJsonObjectText(c.parametersText||"{}")),error:""}}catch(i){return{...c,error:f("editor.property.parametersJsonInvalid",`参数定义 JSON 格式错误: ${(i==null?void 0:i.message)||String(i)}`,{message:String((i==null?void 0:i.message)||i)})}}})},[f]),br=e.useCallback((a,c,i)=>{if(!X)return;const N=y.updateSchemaRowsAtParent(X.schemaRows,a,h=>{h[c]&&(h[c]={...h[c],...i,properties:i.type&&i.type!=="object"?[]:h[c].properties,itemsProperties:i.type&&i.type!=="array"?[]:h[c].itemsProperties})});cr(N)},[cr,X]),$n=e.useCallback((a="")=>{if(!X)return;const c=y.updateSchemaRowsAtParent(X.schemaRows,a,i=>{i.push(y.emptySchemaEditorRow(as(i)+1))});cr(c)},[cr,X]),so=e.useCallback((a,c)=>{X&&ie(()=>{const i=y.updateSchemaRowsAtParent(X.schemaRows,a,N=>{N.splice(c,1);const h=y.renumberSchemaRowOrders(N);N.splice(0,N.length,...h)});cr(i)})},[ie,cr,X]),Fn=e.useCallback((a,c,i)=>{X&&cr(os(X.schemaRows,a,c,i))},[cr,X]),_r=e.useCallback(a=>y.normalizeToolRows((g.configuration||{})[a]),[g.configuration]),jn=e.useCallback((a,c=-1)=>{const i=aa(a),N=_r(a.name),h=c>=0?N[c]:null,A=y.stringifyToolJson(h==null?void 0:h.parameters,"{}");let $=[];try{$=y.parseToolSchemaRows(y.parseJsonObjectText(A))}catch{$=[]}He({fieldName:a.name,mode:i,step:c>=0?"config":"select",activeTab:String((h==null?void 0:h.type)||"builtin")||"builtin",editIndex:c,keyword:"",page:1,ruleChainPage:1,schemaMode:"visual",schemaRows:$,parametersText:A,draft:h?{...h}:{type:"builtin",parameters:"{}"},error:""}),ft(wr(st)),Dn()},[st,_r,Dn]),Dr=e.useCallback(()=>{He(null),tt("")},[]),Lr=e.useCallback((a,c,i)=>_r(a).some((N,h)=>h!==i&&String(N.type||"")==="builtin"&&Sr(N)===c),[_r]),Mr=e.useCallback((a,c,i)=>_r(a).some((N,h)=>h!==i&&String(N.type||"")==="rulechain"&&String(N.targetId||"")===c),[_r]),lo=e.useCallback(a=>{if(!X)return;if(Lr(X.fieldName,a.value,X.editIndex)){Nt({error:f("editor.property.builtinToolAlreadyAdded","该内置工具已添加")});return}const c={};a.fields.forEach(N=>{const h=String((N==null?void 0:N.name)||"");h&&N.defaultValue!==void 0&&(c[h]=xr(N.defaultValue))});const i={type:"builtin",name:a.value,targetId:a.value,description:a.desc||"",parameters:JSON.stringify(a.parameters||{},null,2),config:c};if(X.mode==="tool"&&a.fields.length===0){Pr(X.fieldName,N=>[...N,i]),He(null);return}He(N=>N&&{...N,step:"config",activeTab:"builtin",draft:i,parametersText:JSON.stringify(a.parameters||{},null,2),schemaRows:y.parseToolSchemaRows(a.parameters||{}),schemaMode:"visual",error:""})},[Lr,Nt,X,f,Pr]),Bn=e.useCallback(a=>{if(!X)return;if(Mr(X.fieldName,a.value,X.editIndex)){Nt({error:f("editor.property.ruleChainAlreadyAdded","该规则链已添加")});return}const c=ns(a.raw);qe(i=>zr(i,[a])),He(i=>i&&{...i,step:"config",activeTab:"rulechain",draft:{type:"rulechain",targetId:a.value,name:a.label,description:a.description||"",parameters:c},parametersText:c,schemaRows:y.parseToolSchemaRows(y.parseJsonObjectText(c)),schemaMode:"visual",error:""})},[Mr,Nt,X,f]),co=e.useCallback(()=>{He(a=>a&&{...a,step:"config",activeTab:"custom",draft:{type:"custom",name:"",targetId:"",description:"",parameters:"{}",config:{}},parametersText:"{}",schemaRows:[],schemaMode:"visual",error:""})},[]),io=e.useCallback(()=>{if(!X)return;const a=String(X.draft.type||X.activeTab||"custom"),c=String(X.draft.name||"").trim(),i=String(X.draft.targetId||"").trim(),N=String(X.draft.description||X.draft.desc||"").trim();let h=X.parametersText||"{}";if(X.mode==="tool"&&a!=="builtin")if(X.schemaMode==="visual")h=JSON.stringify(y.generateToolSchemaFromRows(X.schemaRows),null,2);else try{y.parseJsonObjectText(h||"{}")}catch(D){Nt({error:f("editor.property.parametersJsonInvalid",`参数定义 JSON 格式错误: ${(D==null?void 0:D.message)||String(D)}`,{message:String((D==null?void 0:D.message)||D)})});return}if(a==="rulechain"&&!i){Nt({error:f("editor.property.ruleChainRequired","规则链是必须的")});return}if(a==="rulechain"&&Mr(X.fieldName,i,X.editIndex)){Nt({error:f("editor.property.ruleChainAlreadyAdded","该规则链已添加")});return}if(a==="builtin"&&Lr(X.fieldName,c,X.editIndex)){Nt({error:f("editor.property.builtinToolAlreadyAdded","该内置工具已添加")});return}if(a!=="rulechain"&&!c){const D=X.mode==="subagent"?f("editor.property.agentName","智能体名称"):f("editor.property.toolName","工具名称");Nt({error:f("editor.property.nameRequired",`${D}是必须的`,{name:D})});return}const A={...X.draft,type:a,name:a==="rulechain"?c||i:c,targetId:a==="rulechain"?i:i||c,description:N};X.mode==="tool"&&(A.parameters=a==="builtin"?y.stringifyToolJson(A.parameters,"{}"):h);const $=A.config&&typeof A.config=="object"&&!Array.isArray(A.config)?A.config:{};Object.keys($).length>0?A.config=$:delete A.config,Pr(X.fieldName,D=>{const Q=[...D];return X.editIndex>=0?Q[X.editIndex]=A:Q.push(A),Q}),He(null)},[Lr,Mr,Nt,X,f,Pr]),uo=e.useCallback(()=>{j==null||j({section:"skills"}),window.dispatchEvent(new CustomEvent("rulego-editor:openAiAssistant",{detail:{section:"skills"}})),Dr()},[Dr,j]),Hn=(a=!0)=>{if(!r)return null;const c=bt.current;let i={...c.configuration};if(Ye.length===0)try{i=y.parseUnknownConfiguration(ee),a&&pe("")}catch(A){return a&&pe(A instanceof Error?A.message:String(A)),null}const N=new Map(Ye.map(A=>[A.name,A]));if(Oe!=null&&Oe.name&&(M==="shared"?i[Oe.name]=xe.trim():String(i[Oe.name]??"").startsWith("ref://")&&(i[Oe.name]="")),V&&Ce==="preset"&&K){i[Ee.provider]=K;const A=l.find($=>$.value===K);A!=null&&A.url&&(i[Ee.url]=A.url),A!=null&&A.defaultModel&&!i[Ee.model]&&(i[Ee.model]=A.defaultModel)}Object.entries(Dt.current).forEach(([A,$])=>{const D=N.get(A);if(!D||!hr(D))return;const Q={},Ne=y.getMapValueMode(D);$.forEach(te=>{te.key&&(Q[te.key]=y.parseMapEntryValue(te.value,Ne))}),i[A]=Q}),Object.entries(ht.current).forEach(([A,$])=>{const D=N.get(A);!D||!or(D)||Nr(D,i[A])||Cr(D)||(i[A]=$.map(Q=>Q.value).filter(Boolean))}),i=y.sanitizeConfigurationByFields(i,Ye);const h=y.validateComponentFields(Ye,i,p);return h.length>0?(a&&Rt(h.map(A=>`${A.field}: ${A.message}`).join(`
4
+ `)),null):y.normalizeEditableNodeModel(r,{name:c.name,debugMode:c.debugMode,configuration:i,additionalInfo:c.additionalInfo},{graphNodeId:r.id||r.nodeId||c.id,nodeViewType:n==null?void 0:n.type,graphNodeType:r.type,keepNodeId:!0})},Wn=async()=>{for(;Ct.current.size>0;)await Promise.all([...Ct.current.values()]);const a=Object.entries(Lt.current).filter(([i])=>ue.current.has(i)||[...Mt.current].some(N=>kr(N,i)));if(a.length>0)return Rt(f("editor.property.fieldChangeFailedMessage","关联字段更新失败: {{message}}",{message:a.map(([,i])=>i).join("; ")})),!1;const c=Hn(!0);if(!c)return!1;try{return Rt(""),await o(c),Ft.current=JSON.stringify(c),!0}catch(i){return Rt(i instanceof Error?i.message:String(i)),!1}},un=()=>s(),mn=async()=>{const a=Hn(!1);if(!(!a||JSON.stringify(a)!==Ft.current)){un();return}const i=await y.confirmDrawerUnsavedClose({t:N=>f(N,N)});i==="discard"&&un(),i==="save"&&await Wn()&&un()},kt=a=>mr(a.desc)?e.createElement("span",{className:"rge-field-desc"},mr(a.desc)):null,Wr=a=>{const c=[...Ct.current.keys()].some(N=>kr(a,N)),i=Object.entries(Wt).filter(([N])=>kr(a,N));return e.createElement(e.Fragment,null,c&&e.createElement("span",{className:"rge-field-desc",role:"status"},f("editor.property.fieldChangeLoading","正在更新关联字段...")),i.map(([N,h])=>e.createElement("span",{key:N,className:"rge-field-error",role:"alert"},h)))},Un=a=>{if(M==="shared"&&(a.ref==="primary"||a.ref==="shared")||V&&a.name===V.name)return null;const c=Ve.get(a.name)||[],i=Kt[a.name];return e.createElement("div",{key:a.name,className:"rge-form-section"},e.createElement("div",{className:"rge-field-label-row"},e.createElement("label",{className:"rge-form-label"},rt(a)),c.length>0&&e.createElement("button",{type:"button",className:"rge-field-attachment-button",title:f("editor.property.configureAttached","配置附加参数"),"aria-label":f("editor.property.configureAttached","配置附加参数"),onClick:()=>pt(a.name)},e.createElement(be,{value:"settings"}))),Vn(a),(i==null?void 0:i.loading)&&e.createElement("span",{className:"rge-field-desc"},f("editor.property.loadingOptions","正在加载选项...")),(i==null?void 0:i.error)&&e.createElement("span",{className:"rge-field-error"},i.error),Wr(a.name))},mo=()=>Oe?e.createElement("div",{className:"rge-form-section rge-ref-mode-section"},e.createElement("label",{className:"rge-form-label"},f("editor.form.connectionMode","连接方式")),e.createElement("div",{className:"rge-segmented-control",role:"radiogroup","aria-label":f("editor.form.connectionMode","连接方式")},e.createElement("button",{type:"button",className:`rge-segmented-option${M==="custom"?" active":""}`,role:"radio","aria-checked":M==="custom",onClick:()=>Ln("custom")},f("editor.form.customConnection","自定义连接")),e.createElement("button",{type:"button",className:`rge-segmented-option${M==="shared"?" active":""}`,role:"radio","aria-checked":M==="shared",onClick:()=>Ln("shared")},f("editor.form.sharedConnection","共享连接"))),M==="shared"&&e.createElement("div",{className:"rge-ref-shared-picker"},e.createElement(nr,{name:"sharedRef",value:xe,options:ze,allowCreate:!0,threshold:0,placeholder:f("editor.form.sharedConnectionPlaceholder","选择或输入 ref:// 共享连接"),...wt,onChange:Ga})),e.createElement("span",{className:"rge-field-desc"},f("editor.form.sharedConnectionDesc","共享连接会写入 ref:// 引用,自定义连接会直接写入服务地址。")),Wr(Oe.name)):null,po=()=>V?e.createElement("div",{className:"rge-form-section rge-provider-mode-section"},e.createElement("label",{className:"rge-form-label"},V.label||f("editor.form.aiProvider","AI服务商")),e.createElement("div",{className:"rge-segmented-control",role:"radiogroup","aria-label":f("editor.form.aiProvider","AI服务商")},e.createElement("button",{type:"button",className:`rge-segmented-option${Ce==="custom"?" active":""}`,role:"radio","aria-checked":Ce==="custom",onClick:()=>Mn("custom")},f("editor.form.customProvider","自定义供应商")),e.createElement("button",{type:"button",className:`rge-segmented-option${Ce==="preset"?" active":""}`,role:"radio","aria-checked":Ce==="preset",onClick:()=>Mn("preset")},f("editor.form.presetProvider","预设供应商"))),Ce==="preset"&&e.createElement("div",{className:"rge-provider-picker"},e.createElement(nr,{name:"provider",value:K,options:l.map(a=>({label:a.label,value:a.value,description:a.url})),threshold:0,placeholder:f("editor.form.providerPlaceholder","选择AI供应商"),...wt,onChange:Ya})),e.createElement("span",{className:"rge-field-desc"},f("editor.form.providerDesc","预设供应商会自动填充 API 地址和模型,自定义供应商保留手工填写。")),Wr(Ee.provider)):null,go=(a,c)=>{const i=String(a||"").toLowerCase();return i==="rulechain"?f("editor.property.ruleChain","规则链"):i==="builtin"?f("editor.property.builtinTool","内置工具"):i==="subagent"?f("editor.property.subagent","子智能体"):i==="custom"?c==="subagent"?f("editor.property.customAgent","自定义智能体"):f("editor.property.custom","自定义"):String(a||"-")},fo=a=>{const c=String(a.name||"");if(!c||!X)return null;const i=String(a.label||c),N=a.component&&typeof a.component=="object"?a.component:{},h=String(N.type||a.type||"").toLowerCase(),$=(X.draft.config&&typeof X.draft.config=="object"&&!Array.isArray(X.draft.config)?X.draft.config:{})[c]??a.defaultValue??"";if(h==="select"){const he=Sn(Array.isArray(N.options)?N.options:[],$);return e.createElement("label",{key:c,className:"rge-tool-config-field"},e.createElement("span",null,i),e.createElement(nr,{name:`tool-config-${c}`,value:String($??""),options:he,placeholder:String(N.placeholder||""),...wt,onChange:Be=>Er(c,Be)}))}if(h==="switch"||a.type==="bool"||a.type==="boolean")return e.createElement("label",{key:c,className:"rge-tool-config-field rge-tool-config-switch"},e.createElement("span",null,i),e.createElement("label",{className:"rge-switch-toggle"},e.createElement("input",{type:"checkbox",checked:!!$,onChange:he=>Er(c,he.target.checked)}),e.createElement("span",{className:"rge-switch-slider"})));const D=String(a.type||"").toLowerCase();if(["map","array","struct","object","json"].includes(D)||["map","array","struct","object","json","json-editor"].includes(h))return e.createElement("label",{key:c,className:"rge-tool-config-field rge-tool-config-field-wide"},e.createElement("span",null,i),e.createElement("textarea",{className:"rge-form-textarea",rows:4,value:ra($),spellCheck:!1,onChange:he=>{const Be=D==="array"||h==="array"?[]:{};try{Er(c,he.target.value?JSON.parse(he.target.value):Be)}catch{Er(c,he.target.value)}}}));if(h==="textarea")return e.createElement("label",{key:c,className:"rge-tool-config-field"},e.createElement("span",null,i),e.createElement("textarea",{className:"rge-form-textarea",rows:2,value:String($??""),onChange:he=>Er(c,he.target.value)}));const Ne=h==="input-number"||h==="number"||D==="number"||Sa(String(a.type||"")),te=h==="password"||D==="password"||Or({name:c,type:D,component:N})?"password":h==="date"||h==="datepicker"?"date":h==="time"||h==="timepicker"?"time":h==="datetime"||h==="datetimepicker"||h==="datetime-local"?"datetime-local":Ne?"number":"text";return e.createElement("label",{key:c,className:"rge-tool-config-field"},e.createElement("span",null,i),e.createElement("input",{className:"rge-form-input",type:te,value:String($??""),placeholder:String(N.placeholder||(h==="duration"||D==="duration"?"1s / 5m / 2h":"")),autoComplete:te==="password"?"new-password":void 0,onChange:he=>Er(c,Ne?Number(he.target.value||0):he.target.value)}))},qn=(a,c="")=>e.createElement("div",{className:"rge-tool-schema-rows"},a.length===0?e.createElement("div",{className:"rge-tool-schema-empty"},f("editor.property.noSchemaProperties","暂无属性,点击下方按钮添加")):a.map((i,N)=>{const h=c?`${c}.${N}`:String(N),A=i.type==="array"?`${h}.items`:h,$=i.type==="array"?i.itemsProperties:i.properties;return e.createElement("div",{key:h,className:"rge-tool-schema-row-wrap"},e.createElement("div",{className:"rge-tool-schema-row"},e.createElement("input",{className:"rge-form-input",value:i.name,placeholder:f("editor.property.propertyName","属性名"),onChange:D=>br(c,N,{name:D.target.value})}),e.createElement("input",{className:"rge-form-input",value:i.title,placeholder:f("editor.property.title","标题"),onChange:D=>br(c,N,{title:D.target.value})}),e.createElement("input",{className:"rge-form-input",value:i.description,placeholder:f("editor.property.description","描述"),onChange:D=>br(c,N,{description:D.target.value})}),e.createElement("select",{className:"rge-form-select",value:i.type,onChange:D=>br(c,N,{type:D.target.value})},y.TOOL_SCHEMA_TYPES.map(D=>e.createElement("option",{key:D,value:D},D))),e.createElement("input",{className:"rge-form-input",type:"number",min:0,value:i.order,onChange:D=>br(c,N,{order:Number(D.target.value||N+1)})}),e.createElement("label",{className:"rge-inline-checkbox rge-tool-schema-required"},e.createElement("input",{type:"checkbox",checked:i.required,onChange:D=>br(c,N,{required:D.target.checked})}),e.createElement("span",null,f("editor.property.required","必填"))),e.createElement("div",{className:"rge-tool-schema-actions"},e.createElement("button",{type:"button",title:f("editor.property.moveUp","上移"),onClick:()=>Fn(c,N,-1)},"↑"),e.createElement("button",{type:"button",title:f("editor.property.moveDown","下移"),onClick:()=>Fn(c,N,1)},"↓"),e.createElement("button",{type:"button",className:"danger",onClick:()=>so(c,N)},"×"))),i.type==="array"&&e.createElement("div",{className:"rge-tool-schema-nested-head"},e.createElement("span",null,f("editor.property.itemType","项目类型")),e.createElement("select",{className:"rge-form-select",value:i.itemsType||"string",onChange:D=>br(c,N,{itemsType:D.target.value})},y.TOOL_SCHEMA_ITEM_TYPES.map(D=>e.createElement("option",{key:D,value:D},D)))),(i.type==="object"||i.type==="array")&&e.createElement("div",{className:"rge-tool-schema-nested"},e.createElement("div",{className:"rge-tool-schema-nested-title"},i.type==="array"?f("editor.property.arrayItems","数组项目"):f("editor.property.childProperties","子属性"),i.name?`: ${i.name}`:""),i.type==="array"&&i.itemsType!=="object"?e.createElement("div",{className:"rge-tool-schema-empty rge-tool-schema-nested-empty"},f("editor.property.arrayNonObject","当前数组项目不是 object,无需配置项目属性。")):e.createElement(e.Fragment,null,qn($||[],A),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>$n(A)},i.type==="array"?f("editor.property.addItemProperty","添加项目属性"):f("editor.property.addChildProperty","添加子属性")))))})),bo=(a,c)=>{const i=y.normalizeToolRows(c),N=aa(a),h=N==="subagent"?f("editor.property.noSubagents","暂无子智能体"):f("editor.property.noTools","暂无工具");return e.createElement("div",{className:"rge-tools-editor"},e.createElement("div",{className:"rge-tools-toolbar"},e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>jn(a)},N==="subagent"?f("editor.property.addSubagent","添加子智能体"):f("editor.property.addTool","添加工具"))),e.createElement("div",{className:"rge-tools-table-wrap"},e.createElement("table",{className:"rge-tools-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,f("editor.property.name","名称")),e.createElement("th",null,f("editor.property.type","类型")),e.createElement("th",null,f("editor.property.description","描述")),e.createElement("th",{className:"rge-tools-operations"},f("editor.property.operate","操作")))),e.createElement("tbody",null,i.length===0?e.createElement("tr",null,e.createElement("td",{colSpan:4,className:"rge-tools-empty"},h)):i.map((A,$)=>{const D=String(A.type||"custom");return e.createElement("tr",{key:$},e.createElement("td",{title:Sr(A)},Sr(A)||"-"),e.createElement("td",null,e.createElement("span",{className:`rge-tool-type rge-tool-type-${D.toLowerCase()}`},go(D,N))),e.createElement("td",{title:ia(A)},fn(ia(A),80)),e.createElement("td",{className:"rge-tools-actions"},rs(A,N,dr)&&e.createElement("button",{type:"button",className:"rge-tool-action-button",title:f("editor.property.edit","编辑"),"aria-label":f("editor.property.edit","编辑"),onClick:()=>jn(a,$)},"✎"),e.createElement("button",{type:"button",className:"rge-tool-action-button danger",title:f("editor.property.delete","删除"),"aria-label":f("editor.property.delete","删除"),onClick:()=>ie(()=>{Pr(a.name,Q=>Q.filter((Ne,te)=>te!==$))})},"×")))})))),kt(a))},ho=()=>{if(!X)return null;const a=X.editIndex>=0,c=X.mode,i=String(X.draft.type||X.activeTab||"builtin"),N=dr.find(Me=>Me.value===Sr(X.draft)),h=i==="builtin"?(N==null?void 0:N.fields)||[]:[],A=i==="builtin"&&Sr(X.draft)==="skill",$=pr||(N==null?void 0:N.defaultGlobalDir)||f("editor.property.notConfigured","未配置"),D=X.keyword.trim().toLowerCase(),Q=dr.filter(Me=>D?Me.value.toLowerCase().includes(D)||Me.label.toLowerCase().includes(D)||Me.desc.toLowerCase().includes(D):!0),Ne=Math.max(1,Math.ceil(Q.length/st)),te=Math.min(Math.max(1,X.page),Ne),he=Q.slice((te-1)*st,te*st),Be=nt(),Le=vt.items.map(bn).filter(Boolean),lt=hn([...Le,...Be]),Xt=X.keyword.trim().toLowerCase(),tr=ct?lt:lt.filter(Me=>Xt?Me.label.toLowerCase().includes(Xt)||Me.value.toLowerCase().includes(Xt)||String(Me.description||"").toLowerCase().includes(Xt):!0),Ze=ct?vt.total:tr.length,et=Math.max(1,Math.ceil(Ze/st)),ut=Math.min(Math.max(1,X.ruleChainPage),et),ir=ct?tr:tr.slice((ut-1)*st,ut*st),dn=X.step==="select"?c==="subagent"?f("editor.property.selectSubagent","选择子智能体"):f("editor.property.selectTool","选择工具"):a?c==="subagent"?f("editor.property.editSubagent","编辑子智能体"):f("editor.property.editTool","编辑工具"):c==="subagent"?f("editor.property.configSubagent","配置子智能体"):f("editor.property.configTool","配置工具");return e.createElement("div",{className:"rge-tools-modal",onClick:Dr},e.createElement("div",{className:"rge-tools-modal-panel",role:"dialog","aria-modal":"true",onClick:Me=>Me.stopPropagation()},e.createElement("div",{className:"rge-tools-modal-header"},e.createElement("strong",null,dn),e.createElement("button",{type:"button",className:"rge-rule-chain-modal-close",onClick:Dr},"×")),e.createElement("div",{className:"rge-tools-modal-body"},X.step==="select"?e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-rule-chain-modal-tabs rge-tool-selector-tabs"},["builtin","rulechain","custom"].map(Me=>e.createElement("button",{key:Me,type:"button",className:X.activeTab===Me?"active":"",onClick:()=>Nt({activeTab:Me,keyword:"",page:1,ruleChainPage:1,error:""})},Me==="builtin"?f("editor.property.builtinTool","内置工具"):Me==="rulechain"?f("editor.property.ruleChain","规则链"):c==="subagent"?f("editor.property.customAgent","自定义智能体"):f("editor.property.custom","自定义")))),X.activeTab!=="custom"&&e.createElement("input",{type:"search",className:"rge-rule-chain-modal-search",value:X.keyword,placeholder:X.activeTab==="builtin"?f("editor.property.searchTools","搜索工具..."):f("editor.property.searchRuleChains","搜索规则链..."),onChange:Me=>Nt({keyword:Me.target.value,page:1,ruleChainPage:1})}),X.activeTab==="builtin"&&e.createElement("div",{className:"rge-tool-card-grid"},$t?e.createElement("div",{className:"rge-tools-empty"},f("editor.panel.loading","加载中...")):Ie?e.createElement("div",{className:"rge-tools-empty"},Ie):he.length===0?e.createElement("div",{className:"rge-tools-empty"},f("editor.property.noMatchingOptions","没有匹配的选项")):he.map(Me=>{const rr=Lr(X.fieldName,Me.value,X.editIndex);return e.createElement("button",{key:Me.value,type:"button",className:`rge-tool-card${rr?" disabled":""}`,disabled:rr,onClick:()=>lo(Me)},e.createElement("span",{className:"rge-tool-card-icon builtin"},e.createElement(be,{value:"settings"})),e.createElement("span",{className:"rge-tool-card-content"},e.createElement("strong",null,Me.label),e.createElement("small",null,fn(Me.desc||f("editor.property.noDescription","暂无描述"),96))),e.createElement("span",{className:"rge-tool-card-action"},rr?f("editor.property.added","已添加"):"+"))})),X.activeTab==="rulechain"&&e.createElement("div",{className:"rge-tool-card-grid"},vt.loading&&ct?e.createElement("div",{className:"rge-tools-empty"},f("editor.panel.loading","加载中...")):vt.error&&ct?e.createElement("div",{className:"rge-tools-empty"},vt.error):ir.length===0?e.createElement("div",{className:"rge-tools-empty"},f("editor.property.noMatchingOptions","没有匹配的选项")):ir.map(Me=>{const rr=Mr(X.fieldName,Me.value,X.editIndex);return e.createElement("button",{key:Me.value,type:"button",className:`rge-tool-card${rr?" disabled":""}`,disabled:rr,onClick:()=>Bn(Me)},e.createElement("span",{className:"rge-tool-card-icon rulechain"},e.createElement(be,{value:"link"})),e.createElement("span",{className:"rge-tool-card-content"},e.createElement("strong",null,Me.label),e.createElement("small",null,fn(Me.description||Me.value,96))),e.createElement("span",{className:"rge-tool-card-action"},rr?f("editor.property.added","已添加"):"+"))})),X.activeTab==="custom"&&e.createElement("div",{className:"rge-tool-custom-start"},e.createElement("button",{type:"button",className:"rge-tool-card rge-tool-card-wide",onClick:co},e.createElement("span",{className:"rge-tool-card-icon custom"},"+"),e.createElement("span",{className:"rge-tool-card-content"},e.createElement("strong",null,c==="subagent"?f("editor.property.customAgent","自定义智能体"):f("editor.property.custom","自定义")),e.createElement("small",null,f("editor.property.customToolDesc","手工填写名称、描述和参数定义。")))))):e.createElement("div",{className:"rge-tool-configurator"},e.createElement("div",{className:"rge-tool-config-grid"},i==="rulechain"&&e.createElement("label",{className:"rge-tool-config-field rge-tool-config-field-wide"},e.createElement("span",null,f("editor.property.ruleChain","规则链")),e.createElement(nr,{name:"tool-rulechain",value:String(X.draft.targetId||""),options:lt.map(Me=>({label:Me.label,value:Me.value,description:Me.description})),placeholder:f("editor.form.selectRuleChain","请选择规则链"),...wt,onChange:Me=>{const rr=lt.find(No=>No.value===Me);rr?Bn(rr):cn({targetId:Me})}})),e.createElement("label",{className:"rge-tool-config-field"},e.createElement("span",null,c==="subagent"?f("editor.property.agentName","智能体名称"):f("editor.property.toolName","工具名称")),e.createElement("input",{className:"rge-form-input",value:String(X.draft.name||""),disabled:i==="builtin",onChange:Me=>cn({name:Me.target.value})})),e.createElement("label",{className:"rge-tool-config-field rge-tool-config-field-wide"},e.createElement("span",null,f("editor.property.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",rows:2,value:String(X.draft.description||X.draft.desc||""),onChange:Me=>cn({description:Me.target.value})}))),A&&e.createElement("div",{className:"rge-skill-tool-helper"},e.createElement("span",null,f("editor.property.autoLoadSkillDir","自动加载全局技能目录({{dir}})",{dir:$})),e.createElement("button",{type:"button",onClick:uo},f("editor.property.manageSkills","管理技能"))),c==="tool"&&i==="builtin"&&h.length>0&&e.createElement("div",{className:"rge-tool-config-section"},e.createElement("div",{className:"rge-tool-config-section-title"},f("editor.property.initConfig","初始化配置")),e.createElement("div",{className:"rge-tool-config-grid"},h.map(Me=>fo(Me)))),c==="tool"&&i!=="builtin"&&e.createElement("div",{className:"rge-tool-config-section"},e.createElement("div",{className:"rge-tool-config-section-title"},f("editor.property.parameters","参数定义")),e.createElement("div",{className:"rge-segmented-control rge-tool-schema-mode",role:"radiogroup"},e.createElement("button",{type:"button",className:`rge-segmented-option${X.schemaMode==="visual"?" active":""}`,onClick:()=>On("visual")},f("editor.property.visualMode","可视化")),e.createElement("button",{type:"button",className:`rge-segmented-option${X.schemaMode==="code"?" active":""}`,onClick:()=>On("code")},f("editor.property.codeMode","JSON代码"))),X.schemaMode==="visual"?e.createElement("div",{className:"rge-tool-schema-editor"},qn(X.schemaRows),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>$n("")},f("editor.property.addProperty","添加属性"))):e.createElement("textarea",{className:"rge-code-textarea rge-tool-schema-code",rows:12,value:X.parametersText,spellCheck:!1,onChange:Me=>Nt({parametersText:Me.target.value,error:""})}))),X.error&&e.createElement("div",{className:"rge-tools-error"},X.error)),e.createElement("div",{className:"rge-tools-modal-footer"},X.step==="select"?e.createElement("div",{className:"rge-tools-pagination"},X.activeTab==="builtin"&&Q.length>0&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",disabled:te<=1,onClick:()=>Nt({page:Math.max(1,te-1)})},f("editor.property.prevPage","上一页")),e.createElement("span",null,f("editor.property.pageInfo",`第 ${te}/${Ne} 页,共 ${Q.length} 条`,{page:te,pages:Ne,total:Q.length})),e.createElement("button",{type:"button",disabled:te>=Ne,onClick:()=>Nt({page:Math.min(Ne,te+1)})},f("editor.property.nextPage","下一页"))),X.activeTab==="rulechain"&&Ze>0&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",disabled:ut<=1||vt.loading,onClick:()=>Nt({ruleChainPage:Math.max(1,ut-1)})},f("editor.property.prevPage","上一页")),e.createElement("span",null,f("editor.property.pageInfo",`第 ${ut}/${et} 页,共 ${Ze} 条`,{page:ut,pages:et,total:Ze})),e.createElement("button",{type:"button",disabled:ut>=et||vt.loading,onClick:()=>Nt({ruleChainPage:Math.min(et,ut+1)})},f("editor.property.nextPage","下一页")))):e.createElement("div",{className:"rge-tools-modal-actions"},!a&&e.createElement("button",{type:"button",onClick:()=>Nt({step:"select",error:""})},f("editor.property.back","返回选择")),e.createElement("button",{type:"button",onClick:Dr},f("editor.panel.cancel","取消")),e.createElement("button",{type:"button",className:"primary",onClick:io},f("editor.panel.confirm","确认"))))))},yo=(a,c,i,N)=>e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-rule-chain-picker"},e.createElement("input",{type:"text",className:"rge-form-input rge-rule-chain-picker-display",value:je(a,c),placeholder:N||f("editor.form.selectRuleChain","请选择规则链"),disabled:i,readOnly:!0,onClick:()=>{i||Yt(a,c)}}),e.createElement("button",{type:"button",className:"rge-rule-chain-picker-button",disabled:i,title:f("editor.form.selectRuleChain","选择规则链"),onClick:()=>Yt(a,c)},f("editor.property.search","搜索"))),kt(a)),Ur=(a,c,i,N)=>{var Q,Ne,te,he,Be;const h=a||{name:"value",type:"string"},A=!!(h.disabled||(Q=h.component)!=null&&Q.disabled),$=((Ne=h.component)==null?void 0:Ne.placeholder)||h.label||h.name,D=Le=>{const lt=i(Le);Ke(h,N||h.name,Le,lt)};if(vr(h)){const Le=L(h,c),lt=!!((te=h.component)!=null&&te.multiple),Xt=Array.isArray(c)?c.map(tr=>String(tr??"")).filter(Boolean):String(c??"").split(",").map(tr=>tr.trim()).filter(Boolean);return e.createElement(nr,{name:N||h.name,value:String(c??""),values:lt?Xt:void 0,multiple:lt,allowCreate:!!((he=h.component)!=null&&he.allowCreate),disabled:A,options:Le,placeholder:$,...wt,onChange:D,onMultiChange:D})}if(nn(h))return e.createElement("label",{className:"rge-inline-checkbox"},e.createElement("input",{type:"checkbox",checked:!!c,disabled:A,onChange:Le=>D(Le.target.checked)}),e.createElement("span",null,h.label||h.name));if(an(h)){const Le=wn(h.type)||Bt(h)==="number";return e.createElement("input",{type:"number",className:"rge-form-input",step:Le?"0.01":void 0,value:String(c??""),disabled:A,placeholder:$,onChange:lt=>D(zo(h,lt.target.value))})}if(sa(h))return e.createElement("textarea",{className:"rge-form-textarea rge-expression-editor",rows:2,value:String(c??""),disabled:A,placeholder:f("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,onChange:Le=>D(Le.target.value)});if(ta(h)||Kr(h))return e.createElement("textarea",{className:Kr(h)?"rge-code-textarea":"rge-form-textarea",rows:Kr(h)?6:3,value:typeof c=="object"&&c!==null?JSON.stringify(c,null,2):String(c??""),disabled:A,placeholder:$,spellCheck:!1,onChange:Le=>D(Le.target.value)});if(la(h)){const lt=Et(h).startsWith("time")?"time":"date";return e.createElement("input",{type:lt,className:"rge-form-input",value:String(c??""),disabled:A,placeholder:$,onChange:Xt=>D(Xt.target.value)})}return ca(h)?e.createElement("input",{type:"text",className:"rge-form-input rge-duration-input",value:String(c??""),disabled:A,placeholder:((Be=h.component)==null?void 0:Be.placeholder)||"10s / 1m",onChange:Le=>D(Le.target.value)}):oa(h)||or(h)||hr(h)?e.createElement("textarea",{className:"rge-form-textarea rge-json-inline-editor",rows:4,value:typeof c=="object"&&c!==null?JSON.stringify(c,null,2):String(c??""),disabled:A,placeholder:$,spellCheck:!1,onChange:Le=>{try{D(Le.target.value?JSON.parse(Le.target.value):or(h)?[]:{})}catch{D(Le.target.value)}}}):e.createElement("input",{type:Or(h)?"password":"text",className:"rge-form-input",value:String(c??""),disabled:A,placeholder:$,autoComplete:Or(h)?"new-password":void 0,onChange:Le=>D(Le.target.value)})},Eo=(a,c)=>{var A;const i=Uo(c),N=String(((A=a.component)==null?void 0:A.caseType)||"").toLowerCase(),h=($,D,Q)=>{it(a.name,i.map((Ne,te)=>te===$?{...Ne,[D]:Q}:Ne))};return e.createElement("div",{className:"rge-switch-node-editor"},e.createElement("div",{className:"rge-structured-array-header rge-switch-node-header"},e.createElement("span",null,f("editor.property.switchCondition","条件")),e.createElement("span",null,f("editor.property.switchRoute","路由")),e.createElement("span",null)),i.map(($,D)=>e.createElement("div",{key:D,className:"rge-switch-node-row"},e.createElement("textarea",{className:`rge-form-textarea${N==="expr"||N==="expression"?" rge-expression-editor":""}`,rows:2,value:$.case,placeholder:f("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,onChange:Q=>h(D,"case",Q.target.value)}),e.createElement("input",{type:"text",className:"rge-form-input",value:$.then,placeholder:f("editor.property.switchRoutePlaceholder","输入路由:如 Case1"),onChange:Q=>h(D,"then",Q.target.value)}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",onClick:()=>ie(()=>{it(a.name,i.filter((Q,Ne)=>Ne!==D))})},"×"))),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>it(a.name,[...i,{case:"",then:""}])},f("editor.property.addBranch","添加分支")),kt(a))},_o=(a,c)=>{const i=qo(c),N=Jo(a,i),h=Ir(a),A=new Map(h.map(D=>[D.name,D])),$=N.reduce((D,Q)=>{const Ne=A.get(Q);return D[Q]=(Ne==null?void 0:Ne.defaultValue)??"",D},{});return N.length===0?e.createElement("div",{className:"rge-array-editor"},e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>it(a.name,[...i,{}])},f("editor.panel.addPair","+ 添加")),kt(a)):e.createElement("div",{className:"rge-structured-array-editor"},e.createElement("div",{className:"rge-structured-array-scroll"},e.createElement("div",{className:"rge-structured-array-header",style:{gridTemplateColumns:`repeat(${N.length}, minmax(120px, 1fr)) 32px`}},N.map(D=>{var Q;return e.createElement("span",{key:D},((Q=A.get(D))==null?void 0:Q.label)||D)}),e.createElement("span",null)),i.map((D,Q)=>e.createElement("div",{key:Q,className:"rge-structured-array-row",style:{gridTemplateColumns:`repeat(${N.length}, minmax(120px, 1fr)) 32px`}},N.map(Ne=>{const te=A.get(Ne);return e.createElement("div",{key:Ne,className:"rge-structured-array-cell"},Ur(te,D[Ne],he=>it(a.name,i.map((Be,Le)=>Le===Q?{...Be,[Ne]:he}:Be)),`${a.name}.${Q}.${Ne}`))}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",onClick:()=>ie(()=>{it(a.name,i.filter((Ne,te)=>te!==Q))})},"×")))),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>it(a.name,[...i,$])},f("editor.panel.addPair","+ 添加")),kt(a))},vo=(a,c)=>{const i=c&&typeof c=="object"&&!Array.isArray(c)?c:{},N=Ir(a),h=N.length>0?N.map($=>$.name).filter(Boolean):Object.keys(i),A=new Map(N.map($=>[$.name,$]));return e.createElement("div",{className:"rge-struct-panel"},h.length===0?e.createElement("div",{className:"rge-struct-empty"},f("editor.property.noConfigItems","暂无配置项")):h.map($=>{const D=A.get($);return e.createElement("div",{key:$,className:"rge-struct-child"},e.createElement("label",{className:"rge-form-label"},(D==null?void 0:D.label)||$),Ur(D,i[$]??(D==null?void 0:D.defaultValue)??"",Q=>it(a.name,{...i,[$]:Q}),`${a.name}.${$}`),mr(D==null?void 0:D.desc)&&e.createElement("span",{className:"rge-field-desc"},mr(D==null?void 0:D.desc)))}),kt(a))},Vn=a=>{var A,$,D,Q,Ne;const i=(g.configuration||{})[a.name],N=!!(a.disabled||(A=a.component)!=null&&A.disabled),h=(($=a.component)==null?void 0:$.placeholder)||"";if(Ho(a))return yo(a,i,N,h);if(Xa(a)){const te=!!((D=a.component)!=null&&D.multiple),he=L(a,i),Be=Array.isArray(i)?i.map(Le=>String(Le??"")).filter(Boolean):String(i??"").split(",").map(Le=>Le.trim()).filter(Boolean);return e.createElement(e.Fragment,null,e.createElement(nr,{name:a.name,value:String(i??""),values:te?Be:void 0,multiple:te,allowCreate:!!((Q=a.component)!=null&&Q.allowCreate),disabled:N,options:he,placeholder:h,...wt,onChange:Le=>Ae(a,a.name,Le),onMultiChange:Le=>Ae(a,a.name,Le)}),kt(a))}if(na(a))return Eo(a,i);if(nn(a))return e.createElement("div",{className:"rge-form-switch-row"},e.createElement("label",{className:"rge-switch-toggle"},e.createElement("input",{type:"checkbox",checked:!!i,disabled:N,onChange:te=>Ae(a,a.name,te.target.checked)}),e.createElement("span",{className:"rge-switch-slider"})),kt(a));if(la(a))return e.createElement(e.Fragment,null,Ur(a,i,te=>it(a.name,te)),kt(a));if(ca(a))return e.createElement(e.Fragment,null,Ur(a,i,te=>it(a.name,te)),kt(a));if(hr(a))return e.createElement("div",{className:"rge-map-editor"},e.createElement("div",{className:"rge-map-header"},e.createElement("span",null,"Key"),e.createElement("span",null,"Value"),e.createElement("span",null)),(Te[a.name]||[]).map((te,he)=>e.createElement("div",{key:he,className:"rge-map-row"},e.createElement("input",{type:"text",className:"rge-form-input",placeholder:f("editor.form.keyPlaceholder","键"),value:te.key,onChange:Be=>An(a.name,he,"key",Be.target.value)}),e.createElement("input",{type:"text",className:"rge-form-input",placeholder:f("editor.form.valuePlaceholder","值"),value:te.value,onChange:Be=>An(a.name,he,"value",Be.target.value)}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",title:f("editor.property.delete","删除"),onClick:()=>Za(a.name,he)},e.createElement(be,{value:"delete"})))),e.createElement("button",{className:"rge-btn-add",onClick:()=>Qa(a.name)},f("editor.panel.addPair","+ 添加")),kt(a));if(Nr(a,i))return y.isPointTableFields(Ir(a))?e.createElement(Ko,{key:`${((Ne=R==null?void 0:R.ruleChain)==null?void 0:Ne.id)||""}:${(r==null?void 0:r.nodeId)||(r==null?void 0:r.id)||""}:${a.name}`,field:a,value:i,onChange:te=>it(a.name,te),onChildChange:Ke,translate:f}):_o(a,i);if(Cr(a))return bo(a,i);if(or(a))return e.createElement("div",{className:"rge-array-editor rge-tag-array-editor"},e.createElement("div",{className:"rge-array-tags",role:"list"},(_e[a.name]||[]).map((te,he)=>e.createElement("div",{key:`${te.value}-${he}`,className:"rge-array-row rge-array-tag",role:"listitem",draggable:!0,onDragStart:Be=>Be.dataTransfer.setData("text/plain",String(he)),onDragOver:Be=>Be.preventDefault(),onDrop:Be=>{var lt;Be.preventDefault();const Le=Number((lt=Be.dataTransfer)==null?void 0:lt.getData("text"));Number.isInteger(Le)&&oo(a.name,Le,he)}},e.createElement("span",{className:"rge-array-tag-value"},te.value),e.createElement("button",{type:"button",className:"rge-btn-icon-danger","aria-label":f("editor.property.delete","删除"),title:f("editor.property.delete","删除"),onClick:()=>eo(a.name,he)},"×")))),e.createElement("input",{type:"text",className:"rge-form-input rge-array-tag-input",value:H[a.name]||"",placeholder:f("editor.property.simpleArrayPlaceholder","输入后回车添加,支持粘贴批量内容"),onChange:te=>to(a.name,te.target.value),onKeyDown:te=>ro(a.name,te),onPaste:te=>no(a.name,te),onBlur:()=>lr(a.name,H[a.name]||"")}),(_e[a.name]||[]).length>0&&e.createElement("button",{type:"button",className:"rge-array-clear",onClick:()=>ao(a.name)},f("editor.property.clearValues","清空")),kt(a));if(Kr(a))return e.createElement("div",{className:`rge-script-editor${xn(a)?" rge-command-editor":""}`},e.createElement("textarea",{className:"rge-code-textarea",rows:xn(a)?4:10,value:ra(i),onChange:te=>Ae(a,a.name,te.target.value),placeholder:f("editor.form.jsScriptPlaceholder","请输入 JS 脚本..."),spellCheck:!1}),kt(a));if(oa(a))return vo(a,i);if(sa(a))return e.createElement(e.Fragment,null,e.createElement("textarea",{className:"rge-form-textarea rge-expression-editor",rows:3,value:String(i??""),placeholder:f("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,disabled:N,onChange:te=>Ae(a,a.name,te.target.value)}),kt(a));if(ta(a))return e.createElement(e.Fragment,null,e.createElement("textarea",{className:"rge-form-textarea",rows:3,value:String(i??""),placeholder:h,disabled:N,onChange:te=>Ae(a,a.name,te.target.value)}),kt(a));if(an(a)){const te=wn(a.type)||Bt(a)==="number";return e.createElement(e.Fragment,null,e.createElement("input",{type:"number",step:te?"0.01":void 0,className:"rge-form-input",value:String(i??""),disabled:N,onChange:he=>{const Be=he.target.value;Ae(a,a.name,Be===""?"":te?Number(Be):parseInt(Be,10))}}),kt(a))}return e.createElement(e.Fragment,null,e.createElement("input",{type:Or(a)?"password":"text",className:"rge-form-input",value:String(i??""),placeholder:h,disabled:N,autoComplete:Or(a)?"new-password":void 0,onChange:te=>Ae(a,a.name,te.target.value)}),kt(a))},Co=()=>{if(!G)return null;const a=Ye.find(Q=>Q.name===G.fieldName);if(!a)return null;const c=G.keyword.trim().toLowerCase(),i=oe(a,G.value).filter(Q=>!gt||Q.value!==gt).filter(Q=>es(Q,G.tab)).filter(Q=>c?Q.label.toLowerCase().includes(c)||Q.value.toLowerCase().includes(c)||String(Q.description||"").toLowerCase().includes(c):!0),N=ct?ke.total:i.length,h=ct&&ke.size||st,A=Math.max(1,Math.ceil(N/h)),$=Math.min(G.page,A),D=ct?ke.items:i.slice(($-1)*h,$*h);return e.createElement("div",{className:"rge-rule-chain-modal",onClick:()=>ye(null)},e.createElement("div",{className:"rge-rule-chain-modal-panel",role:"dialog","aria-modal":"true","aria-label":f("editor.form.selectRuleChain","选择规则链"),onClick:Q=>Q.stopPropagation()},e.createElement("div",{className:"rge-rule-chain-modal-header"},e.createElement("strong",null,f("editor.form.selectRuleChain","选择规则链")),e.createElement("button",{type:"button",className:"rge-rule-chain-modal-close",onClick:()=>ye(null)},"×")),e.createElement("div",{className:"rge-rule-chain-modal-tools"},e.createElement("div",{className:"rge-rule-chain-modal-tabs",role:"tablist"},["sub","root"].map(Q=>e.createElement("button",{key:Q,type:"button",role:"tab","aria-selected":G.tab===Q,className:G.tab===Q?"active":"",onClick:()=>Vt({tab:Q,page:1})},Q==="sub"?f("editor.property.subRuleChains","子规则链"):f("editor.property.rootRuleChains","主规则链")))),e.createElement("input",{type:"search",className:"rge-rule-chain-modal-search",value:G.keyword,placeholder:f("editor.property.searchRuleChains","搜索规则链..."),onChange:Q=>Vt({keyword:Q.target.value,page:1}),autoFocus:!0})),e.createElement("div",{className:"rge-rule-chain-modal-body"},ke.loading&&ct?e.createElement("div",{className:"rge-rule-chain-empty"},f("editor.property.loading","加载中...")):ke.error&&ct?e.createElement("div",{className:"rge-rule-chain-empty"},ke.error):D.length===0?e.createElement("div",{className:"rge-rule-chain-empty"},f("editor.property.noData","暂无数据")):e.createElement("table",{className:"rge-rule-chain-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,f("editor.property.name","名称")),e.createElement("th",null,"ID"),e.createElement("th",null,f("editor.panel.description","描述")),e.createElement("th",null,f("editor.property.operate","操作")))),e.createElement("tbody",null,D.map(Q=>{const Ne=Q.value===G.value;return e.createElement("tr",{key:Q.value,className:Ne?"active":void 0},e.createElement("td",{className:"rge-rule-chain-name"},e.createElement("span",{className:"rge-rule-chain-title"},Q.label),e.createElement("span",{className:"rge-rule-chain-badge"},Q.root===!1?f("editor.property.subChain","子链"):f("editor.property.rootChain","主链"))),e.createElement("td",{className:"rge-rule-chain-id"},Q.value),e.createElement("td",{className:"rge-rule-chain-desc"},Q.description||"-"),e.createElement("td",{className:"rge-rule-chain-action"},Ne?e.createElement("span",{className:"rge-selected-badge"},f("editor.property.selected","已选择")):e.createElement("button",{type:"button",onClick:()=>yr(Q)},f("editor.property.select","选择"))))})))),e.createElement("div",{className:"rge-rule-chain-modal-footer"},e.createElement("span",{className:"rge-rule-chain-page-info"},f("editor.property.pageInfo","第 {{page}}/{{pages}} 页,共 {{total}} 条",{page:String($),pages:String(A),total:String(N)})),e.createElement("button",{type:"button",disabled:$<=1||ct&&ke.loading,onClick:()=>Vt({page:Math.max(1,$-1)})},f("editor.property.prevPage","上一页")),e.createElement("button",{type:"button",disabled:$>=A||ct&&ke.loading,onClick:()=>Vt({page:Math.min(A,$+1)})},f("editor.property.nextPage","下一页")))))};return!t||!r?null:e.createElement("div",{className:`rge-node-drawer-overlay ${t?"visible":""}`,onClick:()=>{mn()}},e.createElement("div",{className:"rge-node-drawer",onClick:a=>a.stopPropagation()},e.createElement("div",{className:"rge-drawer-header"},e.createElement("div",{className:"rge-drawer-title"},e.createElement(be,{value:"package"}),e.createElement("span",null,f(`components.${(n==null?void 0:n.type)||r.type}`,(n==null?void 0:n.label)||r.type))),e.createElement("button",{className:"rge-drawer-close",onClick:()=>{mn()}},"✕")),e.createElement("div",{className:"rge-drawer-body"},e.createElement("div",{className:"rge-node-config-section__title"},f("editor.panel.nodeInformation","节点信息")),e.createElement("div",{className:"rge-node-config-card"},e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},f("editor.panel.nodeId","节点 ID")),e.createElement("div",{className:"rge-form-row"},e.createElement("input",{type:"text",className:"rge-form-input rge-flex-1",value:g.id||"",readOnly:!0,"aria-readonly":"true",title:f("editor.panel.nodeIdLocked","节点 ID 已绑定画布,编辑属性时不会改写"),onChange:a=>Qe("id",a.target.value)}),e.createElement("label",{className:"rge-debug-toggle"},e.createElement("input",{type:"checkbox",checked:g.debugMode||!1,onChange:a=>Qe("debugMode",a.target.checked)}),e.createElement(be,{value:"debug"}),e.createElement("span",null,f("editor.panel.debugMode","调试"))))),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},f("editor.panel.name","名称")),e.createElement("input",{type:"text",className:"rge-form-input",value:g.name||"",onChange:a=>Qe("name",a.target.value)})),mo(),po(),Xe.map(a=>a.id?e.createElement("details",{key:a.id,className:"rge-field-group",open:!a.collapsed},e.createElement("summary",null,e.createElement("span",null,a.label),e.createElement("small",null,a.fields.length)),a.description&&e.createElement("p",null,a.description),e.createElement("div",{className:"rge-field-group-body"},a.fields.map(Un))):a.fields.map(Un)),dt&&(()=>{if(De.length===0)return null;const a=()=>{ot>0||pt("")},c=()=>{ot>0||mt.length>0||pt("")};return e.createElement("div",{className:"rge-field-attachment-overlay",role:"presentation",onMouseDown:i=>{i.target===i.currentTarget&&a()}},e.createElement("section",{className:"rge-field-attachment-panel",role:"dialog","aria-modal":"true"},e.createElement("header",null,e.createElement("strong",null,f("editor.property.attachedSettings","附加参数")),e.createElement("button",{type:"button",disabled:ot>0,"aria-label":f("editor.panel.close","关闭"),onClick:a},"×")),e.createElement("div",{className:"rge-field-attachment-body"},gr.map(i=>e.createElement("div",{key:i.field.name,className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},rt(i.field)),Vn(i.field),kt(i.field),Wr(i.field.name)))),e.createElement("footer",{className:"rge-drawer-footer"},ot>0&&e.createElement("span",{className:"rge-field-desc",role:"status"},f("editor.property.fieldChangeLoading","正在更新关联字段...")),e.createElement("button",{type:"button",className:"rge-btn-submit",disabled:ot>0||mt.length>0,onClick:c},f("editor.panel.apply","应用")))))})(),Ye.length===0&&e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},f("editor.property.configurationJson","配置 JSON")),e.createElement("textarea",{className:"rge-form-textarea",rows:14,value:ee,onChange:a=>{P(a.target.value),pe("")},spellCheck:!1}),Z&&e.createElement("span",{className:"rge-field-error"},Z)),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},f("editor.panel.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",rows:3,placeholder:f("editor.panel.descriptionPlaceholder","请输入节点描述"),value:String(((Kn=g.additionalInfo)==null?void 0:Kn.description)??""),onChange:a=>Qe("additionalInfo",{...g.additionalInfo,description:a.target.value})})))),Co(),ho(),e.createElement("div",{className:"rge-drawer-footer"},Ht&&e.createElement("span",{className:"rge-drawer-submit-error",role:"alert"},Ht),!Ht&&zt.length>0&&e.createElement("span",{className:"rge-drawer-submit-error",role:"alert"},f("editor.property.fieldChangeFailedMessage","关联字段更新失败: {{message}}",{message:zt.map(([,a])=>a).join("; ")})),Zt>0&&e.createElement("span",{className:"rge-field-desc",role:"status"},f("editor.property.fieldChangeLoading","正在更新关联字段...")),e.createElement("button",{className:"rge-btn-cancel",onClick:()=>{mn()}},f("editor.panel.cancel","取消")),e.createElement("button",{className:"rge-btn-submit",disabled:Zt>0||zt.length>0,onClick:()=>{Wn()}},f("editor.panel.confirm","确认")))))};Ia.displayName="NodePropertyDrawer";const $r=[{value:"Success",label:"成功 (Success)",color:"var(--rge-success)"},{value:"Failure",label:"失败 (Failure)",color:"var(--rge-danger)"},{value:"True",label:"是 (True)",color:"var(--rge-primary)"},{value:"False",label:"否 (False)",color:"var(--rge-warning)"},{value:"Post Telemetry",label:"Post Telemetry",color:"var(--rge-primary)"}],Pa=({visible:t,edgeModel:r,relationTypes:n,onSubmit:o,onClose:s,locale:u,messages:d,t:p})=>{const[S,w]=e.useState(""),[R,b]=e.useState(""),[x,_]=e.useState(!1),E=e.useMemo(()=>Ge({locale:u,messages:d,t:p}),[u,d,p]),W=e.useMemo(()=>{const C=!(n!=null&&n.length);return(n!=null&&n.length?n:$r).map((j,k)=>{var v,ae;return typeof j=="string"?{value:j,label:Nn(E,j),color:((v=$r[k%$r.length])==null?void 0:v.color)||"var(--rge-primary)"}:{value:j.value,label:!C&&j.label?j.label:Nn(E,j.value),color:j.color||((ae=$r[k%$r.length])==null?void 0:ae.color)||"var(--rge-primary)"}})},[n,E]);e.useEffect(()=>{if(!r)return;const C=r.relationType||"Success";W.some(j=>j.value===C)?(w(C),_(!1),b("")):(w(""),_(!0),b(C))},[r,W]);const B=C=>{w(C),_(!1),b("")},U=()=>{_(!0),w("")},q=()=>{if(!r)return;const C=x?R.trim()||"Success":S||"Success";o({...r,relationType:C})};return!t||!r?null:e.createElement("div",{className:`rge-edge-drawer-overlay ${t?"visible":""}`,onClick:s},e.createElement("div",{className:"rge-edge-drawer",onClick:C=>C.stopPropagation()},e.createElement("div",{className:"rge-drawer-header"},e.createElement("div",{className:"rge-drawer-title"},e.createElement(be,{value:"link"}),e.createElement("span",null,E("editor.edge.title","连线属性"))),e.createElement("button",{className:"rge-drawer-close",onClick:s},"✕")),e.createElement("div",{className:"rge-drawer-body"},e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},E("editor.edge.id","连线 ID")),e.createElement("div",{className:"rge-form-value"},r.id)),e.createElement("div",{className:"rge-edge-endpoints"},e.createElement("div",{className:"rge-endpoint"},e.createElement("span",{className:"rge-endpoint-label"},E("editor.edge.source","来源")),e.createElement("span",{className:"rge-endpoint-id"},r.sourceNodeId)),e.createElement("span",{className:"rge-endpoint-arrow"},"→"),e.createElement("div",{className:"rge-endpoint"},e.createElement("span",{className:"rge-endpoint-label"},E("editor.edge.target","目标")),e.createElement("span",{className:"rge-endpoint-id"},r.targetNodeId))),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},E("editor.form.relationType","关系类型")),e.createElement("div",{className:"rge-relation-types"},W.map(C=>e.createElement("button",{key:C.value,className:`rge-relation-type-btn ${!x&&S===C.value?"active":""}`,style:{borderColor:!x&&S===C.value?C.color:void 0,color:!x&&S===C.value?C.color:void 0},onClick:()=>B(C.value)},!x&&S===C.value&&e.createElement("span",null,"✓"),C.label)),e.createElement("button",{className:`rge-relation-type-btn ${x?"active custom":""}`,onClick:U},E("editor.edge.custom","自定义"))),x&&e.createElement("input",{type:"text",className:"rge-form-input rge-mt-8",placeholder:E("editor.edge.customPlaceholder","请输入自定义关系类型"),value:R,onChange:C=>b(C.target.value),autoFocus:!0}))),e.createElement("div",{className:"rge-drawer-footer"},e.createElement("button",{className:"rge-btn-cancel",onClick:s},E("editor.panel.cancel","取消")),e.createElement("button",{className:"rge-btn-submit",onClick:q},E("editor.panel.confirm","确认")))))};Pa.displayName="EdgePropertyDrawer";const ss=(t,r)=>{console[t==="success"?"log":t==="warning"?"warn":"error"](`[DebugPanel] ${t}: ${r}`)},Da=({visible:t,chainId:r,selectedNodeId:n,onClose:o,onSendMessage:s,deployState:u="unknown",onDeploy:d,onFetchDebugLogs:p,onFetchRunLogs:S,onNotify:w=ss,locale:R,messages:b,t:x})=>{const[_,E]=e.useState("send"),[W,B]=e.useState("TEST_MSG"),[U,q]=e.useState(`{
5
5
  "temperature": 25.5,
6
6
  "humidity": 60
7
- }`),[C,I]=e.useState(!1),[D,_]=e.useState(!1),[u,Z]=e.useState(!1),[ee,H]=e.useState(""),[V,me]=e.useState([]),[q,le]=e.useState(!1),[ue,W]=e.useState([]),[ge,Pe]=e.useState(!1),[Me,X]=e.useState({visible:!1,title:"",data:""}),b=e.useRef(0),$=e.useRef(0),Y=e.useRef(0),te=e.useRef(n);e.useEffect(()=>{te.current!==n&&(te.current=n,b.current+=1,$.current+=1,Y.current+=1,me([]),W([]),j("TEST_MSG"),U("{}"),H(""),le(!1),Pe(!1),I(!1),_(!1),Z(!1),X({visible:!1,title:"",data:""}))},[n]);const L=e.useMemo(()=>Ze({locale:P,messages:g,t:w}),[P,g,w]),ke=vr(P);e.useEffect(()=>{i==="running"&&Z(!1)},[i]);const we=e.useCallback(async(se=!1)=>{if(!n){N("warning",L("editor.debugPanel.selectChainFirst","请先选择规则链"));return}if(!s){N("warning",L("editor.debugPanel.noSendCallback","未配置发送消息回调"));return}if(!se&&(i==="undeployed"||i==="stopped")){const _e=L("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");Z(!0),H(_e),N("warning",_e);return}const ae=++Y.current,Ne=v.createDebugPanelRequestSnapshot(n,ae);try{I(!0);let _e;try{_e=JSON.parse(O)}catch{N("error",L("editor.debugPanel.invalidJson","消息体 JSON 格式错误"));return}const J=await s(n,F,_e);if(!v.isDebugPanelRequestCurrent(Ne,n,Y.current))return;if(J.success)Z(!1),N("success",L("editor.debugPanel.sendSuccess","消息发送成功")),H(JSON.stringify(J.data,null,2));else{const Ae=J.msg||L("editor.debugPanel.unknownError","未知错误");if(v.isRuleChainNotDeployedError(Ae,n)){const tt=L("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");Z(!0),H(tt),N("warning",tt);return}N("error",L("editor.debugPanel.sendFailed","发送失败: {{message}}",{message:Ae})),H(J.msg||L("editor.debugPanel.sendTestMessage","发送测试消息"))}}catch(_e){if(!v.isDebugPanelRequestCurrent(Ne,n,Y.current))return;if(v.isRuleChainNotDeployedError(_e,n)){const J=L("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");Z(!0),H(J),N("warning",J);return}N("error",L("editor.debugPanel.sendException","发送异常: {{message}}",{message:_e instanceof Error?_e.message:String(_e)}))}finally{v.isDebugPanelRequestCurrent(Ne,n,Y.current)&&I(!1)}},[n,i,F,O,s,N,L]),ne=e.useCallback(async()=>{if(!m||D)return;const se=n;try{_(!0);const ae=await m(se);if(te.current!==se)return;if(ae===!1||ae&&typeof ae=="object"&&ae.success===!1){const Ne=ae&&typeof ae=="object"&&ae.msg?ae.msg:L("editor.debugPanel.deployFailed","部署失败");N("error",L("editor.debugPanel.deployFailedWithMessage","部署失败: {{message}}",{message:Ne}));return}Z(!1),N("success",L("editor.debugPanel.deploySucceeded","规则链已部署,正在重新发送")),await we(!0)}catch(ae){if(te.current!==se)return;N("error",L("editor.debugPanel.deployFailedWithMessage","部署失败: {{message}}",{message:ae instanceof Error?ae.message:String(ae)}))}finally{te.current===se&&_(!1)}},[n,D,we,m,N,L]),he=e.useCallback(async()=>{if(!n||!f)return;const se=++b.current,ae=v.createDebugPanelRequestSnapshot(n,se);try{le(!0);const Ne=await f(n,r);if(!v.isDebugPanelRequestCurrent(ae,n,b.current))return;me(Ne.items||[])}catch{v.isDebugPanelRequestCurrent(ae,n,b.current)&&N("error",L("editor.debugPanel.loadDebugLogsFailed","加载调试日志失败"))}finally{v.isDebugPanelRequestCurrent(ae,n,b.current)&&le(!1)}},[n,r,f,N,L]),xe=e.useCallback(async()=>{if(!M)return;const se=++$.current,ae=v.createDebugPanelRequestSnapshot(n,se);try{Pe(!0);const Ne=await M(n);if(!v.isDebugPanelRequestCurrent(ae,n,$.current))return;W(Ne||[])}catch{v.isDebugPanelRequestCurrent(ae,n,$.current)&&N("error",L("editor.debugPanel.loadRunLogsFailed","加载运行日志失败"))}finally{v.isDebugPanelRequestCurrent(ae,n,$.current)&&Pe(!1)}},[n,M,N,L]),Ee=(se,ae)=>{let Ne=ae;try{Ne=JSON.stringify(JSON.parse(ae),null,2)}catch{}X({visible:!0,title:se,data:Ne})},Le=se=>new Date(se).toLocaleString(ke,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),Se=async se=>{try{await navigator.clipboard.writeText(se),N("success",L("editor.debugPanel.copied","已复制"))}catch{N("error",L("editor.debugPanel.copyFailed","复制失败"))}};return t?e.createElement("div",{className:"rge-debug-panel"},e.createElement("div",{className:"rge-debug-header"},e.createElement("div",{className:"rge-debug-tabs"},e.createElement("button",{className:`rge-debug-tab ${y==="send"?"active":""}`,onClick:()=>k("send")},e.createElement(pe,{value:"send"})," ",L("editor.debugPanel.sendMessage","发送消息")),e.createElement("button",{className:`rge-debug-tab ${y==="debug"?"active":""}`,onClick:()=>{k("debug"),he()}},e.createElement(pe,{value:"debug"})," ",L("editor.debugPanel.debugLogs","调试日志")),e.createElement("button",{className:`rge-debug-tab ${y==="logs"?"active":""}`,onClick:()=>{k("logs"),xe()}},e.createElement(pe,{value:"data"})," ",L("editor.debugPanel.runLogs","运行日志"))),e.createElement("button",{className:"rge-drawer-close",onClick:o},"✕")),y==="send"&&e.createElement("div",{className:"rge-debug-body"},e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},L("editor.debugPanel.chainId","规则链 ID")),e.createElement("input",{type:"text",className:"rge-form-input",value:n,readOnly:!0})),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},L("editor.debugPanel.msgType","消息类型")),e.createElement("input",{type:"text",className:"rge-form-input",value:F,onChange:se=>j(se.target.value),placeholder:L("editor.debugPanel.msgTypePlaceholder","如 TEST_MSG")})),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},L("editor.debugPanel.msgBodyJson","消息体 (JSON)")),e.createElement("textarea",{className:"rge-code-textarea",rows:8,value:O,onChange:se=>U(se.target.value),spellCheck:!1})),u&&e.createElement("div",{className:"rge-debug-deploy-guide",role:"status"},e.createElement("span",null,L("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试")),m&&e.createElement("button",{type:"button",className:"rge-btn-mini",disabled:D||C,onClick:()=>{ne()}},D?L("editor.debugPanel.deploying","部署中..."):L("editor.debugPanel.deployAndRetry","部署并重试"))),e.createElement("button",{className:"rge-btn-submit rge-full-width",onClick:()=>{we()},disabled:C},e.createElement(pe,{value:"send"})," ",C?L("editor.debugPanel.sending","发送中..."):L("editor.debugPanel.sendTestMessage","发送测试消息")),ee&&e.createElement("div",{className:"rge-form-section rge-mt-16"},e.createElement("div",{className:"rge-label-row"},e.createElement("label",{className:"rge-form-label"},L("editor.debugPanel.responseData","响应数据")),e.createElement("button",{className:"rge-btn-mini",onClick:()=>Se(ee)},e.createElement(pe,{value:"copy"})," ",L("editor.panel.copy","复制"))),e.createElement("pre",{className:"rge-response-pre"},ee))),y==="debug"&&e.createElement("div",{className:"rge-debug-body"},e.createElement("div",{className:"rge-toolbar-row"},r&&e.createElement("span",{className:"rge-tag"},L("editor.debugPanel.nodeLabel","节点"),": ",r),e.createElement("button",{className:"rge-btn-mini",onClick:he,disabled:q},e.createElement(pe,{value:"refresh",className:q?"is-spinning":""})," ",q?L("editor.debugPanel.loading","加载中..."):L("editor.debugPanel.refresh","刷新"))),V.length===0?e.createElement("div",{className:"rge-empty-tip"},e.createElement(pe,{value:"debug",className:"rge-empty-graphic"}),e.createElement("p",null,q?L("editor.debugPanel.loading","加载中..."):L("editor.debugPanel.noDebugLogs","暂无调试日志")),e.createElement("p",{className:"rge-sub-tip"},L("editor.debugPanel.debugModeHint",'需要在节点上开启"调试模式"并发送消息'))):e.createElement("div",{className:"rge-log-table"},e.createElement("div",{className:"rge-log-table-header"},e.createElement("span",null,L("editor.debugPanel.time","时间")),e.createElement("span",null,L("editor.debugPanel.type","类型")),e.createElement("span",null,L("editor.debugPanel.relation","关系")),e.createElement("span",null,L("editor.debugPanel.msgType","消息类型")),e.createElement("span",null,L("editor.debugPanel.operate","操作"))),V.map((se,ae)=>e.createElement("div",{key:ae,className:`rge-log-table-row ${se.err?"error":""}`},e.createElement("span",null,Le(se.ts)),e.createElement("span",{className:"rge-tag-small"},se.flowType),e.createElement("span",{className:"rge-tag-small"},se.relationType),e.createElement("span",{title:se.msg.type},se.msg.type.length>12?se.msg.type.slice(0,12)+"...":se.msg.type),e.createElement("span",{className:"rge-log-actions"},e.createElement("button",{className:"rge-btn-link",onClick:()=>Ee(L("editor.debugPanel.data","数据"),se.msg.data)},L("editor.debugPanel.data","数据")),e.createElement("button",{className:"rge-btn-link",onClick:()=>Ee(L("editor.debugPanel.metadata","元数据"),JSON.stringify(se.msg.metadata))},L("editor.debugPanel.metadata","元数据")),se.err&&e.createElement("button",{className:"rge-btn-link danger",onClick:()=>Ee(L("editor.debugPanel.error","错误"),se.err||"")},L("editor.debugPanel.error","错误"))))))),y==="logs"&&e.createElement("div",{className:"rge-debug-body"},e.createElement("div",{className:"rge-toolbar-row"},e.createElement("button",{className:"rge-btn-mini",onClick:xe,disabled:ge},e.createElement(pe,{value:"refresh",className:ge?"is-spinning":""})," ",ge?L("editor.debugPanel.loading","加载中..."):L("editor.debugPanel.refresh","刷新"))),ue.length===0?e.createElement("div",{className:"rge-empty-tip"},e.createElement(pe,{value:"data",className:"rge-empty-graphic"}),e.createElement("p",null,ge?L("editor.debugPanel.loading","加载中..."):L("editor.debugPanel.noRunLogs","暂无运行日志"))):e.createElement("div",{className:"rge-log-list"},ue.map((se,ae)=>e.createElement("div",{key:ae,className:"rge-run-log-item",onClick:()=>Ee(L("editor.debugPanel.runLogDetail","日志详情"),JSON.stringify(se))},e.createElement("pre",null,typeof se=="string"?se:JSON.stringify(se,null,2)))))),Me.visible&&e.createElement("div",{className:"rge-detail-overlay",onClick:()=>X({...Me,visible:!1})},e.createElement("div",{className:"rge-detail-modal",onClick:se=>se.stopPropagation()},e.createElement("div",{className:"rge-detail-header"},e.createElement("span",null,Me.title),e.createElement("div",null,e.createElement("button",{className:"rge-btn-mini",onClick:()=>Se(Me.data)},e.createElement(pe,{value:"copy"})),e.createElement("button",{className:"rge-drawer-close",onClick:()=>X({...Me,visible:!1})},"✕"))),e.createElement("pre",{className:"rge-detail-pre"},Me.data)))):null};Ea.displayName="DebugPanel";const Fo=t=>{const n=new WeakSet;try{const r=JSON.stringify(t,(o,s)=>{if(typeof s=="bigint")return`${s.toString()}n`;if(typeof s=="function")return`[Function${s.name?` ${s.name}`:""}]`;if(s&&typeof s=="object"){if(n.has(s))return"[CIRCULAR]";n.add(s)}return s},2);return r===void 0?"undefined":r}catch(r){return`[Unserializable: ${r instanceof Error?r.message:String(r)}]`}},Bo=t=>{if(!Number.isFinite(t)||t<0)return"-";if(t<1024)return`${t} B`;const n=t/1024;return n<1024?`${n.toFixed(1)} KB`:`${(n/1024).toFixed(2)} MB`},ya=({visible:t,data:n,title:r,fileNamePrefix:o="rulechain",onClose:s,onNotify:i,locale:m,messages:f,t:M})=>{const N=e.useMemo(()=>Ze({locale:m,messages:f,t:M}),[m,f,M]),P=r||N("editor.dataView.title","规则链数据"),g=e.useMemo(()=>Fo(n??{}),[n]),w=e.useMemo(()=>{const F=g?g.split(/\r\n|\r|\n/).length:0,j=typeof Blob<"u"?new Blob([g]).size:new TextEncoder().encode(g).length;return{lineCount:F,byteSize:Bo(j)}},[g]),y=async()=>{try{await navigator.clipboard.writeText(g),i==null||i("success",N("editor.dataView.copied","JSON 已复制到剪贴板"))}catch{i==null||i("error",N("editor.dataView.copyFailed","复制失败"))}},k=()=>{try{const F=new Blob([g],{type:"application/json"}),j=URL.createObjectURL(F),O=new Date().toISOString().slice(0,19).replace(/[:]/g,"-"),U=`${o}_${O}.json`,C=document.createElement("a");C.href=j,C.download=U,document.body.appendChild(C),C.click(),document.body.removeChild(C),URL.revokeObjectURL(j),i==null||i("success",N("editor.dataView.downloaded","已下载 {{fileName}}",{fileName:U}))}catch{i==null||i("error",N("editor.dataView.downloadFailed","下载失败"))}};return t?e.createElement("div",{className:"rge-dataview-overlay",onClick:s},e.createElement("div",{className:"rge-dataview-dialog",onClick:F=>F.stopPropagation()},e.createElement("div",{className:"rge-dialog-header"},e.createElement("div",{className:"rge-dialog-title"},e.createElement(pe,{value:"data"}),e.createElement("span",null,P)),e.createElement("button",{className:"rge-drawer-close",onClick:s},"✕")),e.createElement("div",{className:"rge-dialog-toolbar"},e.createElement("span",{className:"rge-dialog-meta"},N("editor.dataView.fullJson","完整 JSON")," · ",N("editor.dataView.lineCount","{{count}} 行",{count:w.lineCount})," · ",N("editor.dataView.byteSize","{{size}}",{size:w.byteSize})),e.createElement("button",{type:"button",className:"rge-btn-outline",onClick:y},e.createElement(pe,{value:"copy"})," ",N("editor.dataView.copyJson","复制")),e.createElement("button",{type:"button",className:"rge-btn-outline",onClick:k},e.createElement(pe,{value:"export"})," ",N("editor.dataView.downloadJson","下载"))),e.createElement("div",{className:"rge-dialog-hint"},N("editor.dataView.fullJsonHint","当前视图不截断数据;大数据可直接复制或下载后查看。")),e.createElement("div",{className:"rge-dialog-body"},e.createElement("textarea",{className:"rge-json-textarea",value:g,readOnly:!0,spellCheck:!1,"aria-label":P})))):null};ya.displayName="DataViewDialog";const _a=({canUndo:t=!1,canRedo:n=!1,isFullscreen:r=!1,isDebugMode:o=!1,zoomLevel:s=100,hasSelection:i=!1,onSave:m,onUndo:f,onRedo:M,onDelete:N,onZoomIn:P,onZoomOut:g,onZoomChange:w,onFitView:y,onResetZoom:k,onFullscreen:F,onToggleDebug:j,onViewData:O,onSettings:U,onValidate:C,onNew:I,onImport:D,onExport:_,onAutoLayout:u,extraButtons:Z=[],hiddenButtons:ee=[],chainName:H,locale:V,messages:me,t:q})=>{const[le,ue]=e.useState(!1),W=e.useMemo(()=>Ze({locale:V,messages:me,t:q}),[V,me,q]),ge=b=>ee.includes(b),Pe=b=>{const $=v.getEditorToolbarIconSvg(b);return $?e.createElement("span",{className:"rge-toolbar-icon rge-toolbar-icon-svg",dangerouslySetInnerHTML:{__html:$}}):e.createElement("span",{className:"rge-toolbar-icon"},b)},X=[{key:"new",icon:"file-plus",tooltip:W("editor.toolbar.newChain","新建规则链"),onClick:()=>I==null?void 0:I(),hidden:ge("new")||!I},{key:"save",icon:"save",tooltip:`${W("editor.toolbar.save","保存")} (Ctrl+S)`,onClick:()=>m==null?void 0:m(),hidden:ge("save")},{key:"import",icon:"import",tooltip:W("editor.toolbar.import","导入"),onClick:()=>D==null?void 0:D(),hidden:ge("import")||!D},{key:"export",icon:"export",tooltip:W("editor.toolbar.export","导出"),onClick:()=>_==null?void 0:_(),hidden:ge("export")||!_},{key:"undo",icon:"undo",tooltip:`${W("editor.toolbar.undo","撤销")} (Ctrl+Z)`,onClick:()=>f==null?void 0:f(),disabled:!t,hidden:ge("undo"),dividerBefore:!0},{key:"redo",icon:"redo",tooltip:`${W("editor.toolbar.redo","重做")} (Ctrl+Y)`,onClick:()=>M==null?void 0:M(),disabled:!n,hidden:ge("redo")},{key:"delete",icon:"delete",tooltip:`${W("editor.toolbar.delete","删除选中")} (Del)`,onClick:()=>N==null?void 0:N(),disabled:!i,hidden:ge("delete")},{key:"zoomIn",icon:"zoom-in",tooltip:W("editor.toolbar.zoomIn","放大"),onClick:()=>P==null?void 0:P(),hidden:ge("zoomIn"),dividerBefore:!0},{key:"zoomOut",icon:"zoom-out",tooltip:W("editor.toolbar.zoomOut","缩小"),onClick:()=>g==null?void 0:g(),hidden:ge("zoomOut")},{key:"fitView",icon:"fit",tooltip:W("editor.toolbar.fitView","适应画布"),onClick:()=>y==null?void 0:y(),hidden:ge("fitView")},{key:"autoLayout",icon:"auto-layout",tooltip:W("editor.toolbar.autoLayout","自动排版"),onClick:()=>u==null?void 0:u(),hidden:ge("autoLayout")||!u},{key:"resetZoom",icon:"1:1",tooltip:W("editor.toolbar.resetZoom","重置缩放"),onClick:()=>k==null?void 0:k(),hidden:ge("resetZoom")},{key:"validate",icon:"validate",tooltip:W("editor.toolbar.validate","校验规则链"),onClick:()=>C==null?void 0:C(),hidden:ge("validate")||!C,dividerBefore:!0},{key:"debug",icon:"debug",tooltip:o?W("editor.toolbar.debugOff","关闭调试"):W("editor.toolbar.debugOn","开启调试"),onClick:()=>j==null?void 0:j(),active:o,hidden:ge("debug")},{key:"viewData",icon:"data",tooltip:W("editor.toolbar.viewData","查看数据"),onClick:()=>O==null?void 0:O(),hidden:ge("viewData")},{key:"settings",icon:"settings",tooltip:W("editor.toolbar.settings","设置"),onClick:()=>U==null?void 0:U(),hidden:ge("settings")||!U},{key:"fullscreen",icon:r?"fullscreen-exit":"fullscreen",tooltip:r?W("editor.toolbar.exitFullscreen","退出全屏"):W("editor.toolbar.fullscreen","全屏"),onClick:()=>F==null?void 0:F(),hidden:ge("fullscreen")},...Z].filter(b=>!b.hidden);return e.createElement("div",{className:"rge-editor-toolbar"},e.createElement("div",{className:"rge-toolbar-left"},X.map(b=>e.createElement(e.Fragment,{key:b.key},b.dividerBefore&&e.createElement("div",{className:"rge-toolbar-divider"}),e.createElement("button",{className:`rge-toolbar-btn ${b.active?"active":""} ${b.disabled?"disabled":""}`,onClick:b.onClick,disabled:b.disabled,title:b.tooltip,"aria-pressed":b.active===void 0?void 0:b.active},Pe(b.icon))))),H&&e.createElement("div",{className:"rge-toolbar-center"},e.createElement("span",{className:"rge-chain-name"},H)),e.createElement("div",{className:"rge-toolbar-right"},e.createElement("button",{className:"rge-toolbar-zoom-btn",onClick:()=>ue(!le),title:W("editor.toolbar.zoomOptions","缩放选项")},s,"%"),le&&e.createElement("div",{className:"rge-zoom-menu",onMouseLeave:()=>ue(!1)},[50,75,100,125,150,200].map(b=>e.createElement("button",{key:b,className:`rge-zoom-option ${b===s?"active":""}`,"aria-pressed":b===s,disabled:!w&&b!==100,onClick:()=>{w?w(b):b===100&&(k==null||k()),ue(!1)}},b,"%")),e.createElement("div",{className:"rge-toolbar-divider horizontal"}),e.createElement("button",{className:"rge-zoom-option",onClick:()=>{y==null||y(),ue(!1)}},W("editor.toolbar.fitView","适应画布")))))};_a.displayName="EditorToolbar";const va=({visible:t,x:n,y:r,items:o,onClose:s})=>{const i=e.useRef(null),m=e.useCallback(w=>{i.current&&!i.current.contains(w.target)&&s()},[s]),f=e.useCallback(w=>{w.key==="Escape"&&s()},[s]),M=e.useCallback(w=>{const y=Array.from(w.children).find(O=>O.classList.contains("rge-ctx-submenu"));if(!y)return;y.style.display="block",y.style.visibility="hidden";const k=w.getBoundingClientRect(),F=y.getBoundingClientRect(),j=v.resolveContextSubmenuPosition(k,{width:F.width,height:F.height},{width:window.innerWidth,height:window.innerHeight});y.dataset.placement=j.placement,y.style.left=`${j.left}px`,y.style.top=`${j.top}px`,y.style.visibility="visible"},[]);if(e.useEffect(()=>(t&&(document.addEventListener("mousedown",m),document.addEventListener("keydown",f)),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",f)}),[t,m,f]),e.useEffect(()=>{if(t&&i.current){const w=i.current.getBoundingClientRect(),y=v.clampContextMenuPosition({left:n,top:r},{width:w.width,height:w.height},{width:window.innerWidth,height:window.innerHeight});i.current.style.left=`${y.left}px`,i.current.style.top=`${y.top}px`}},[t,n,r]),!t)return null;const N=o.filter(w=>!w.hidden),P=w=>w.children&&w.children.length>0?e.createElement(e.Fragment,{key:w.key},w.dividerBefore&&e.createElement("div",{className:"rge-ctx-menu-divider"}),e.createElement("div",{className:`rge-ctx-menu-item has-submenu ${w.disabled?"disabled":""}`,role:"menuitem","aria-haspopup":"menu","aria-disabled":w.disabled||void 0,onMouseEnter:y=>M(y.currentTarget)},e.createElement("div",{className:"rge-ctx-menu-item-content"},w.icon&&g(w.icon),e.createElement("span",{className:"rge-ctx-menu-label"},w.label),e.createElement("span",{className:"rge-ctx-menu-arrow","aria-hidden":"true"},"▶")),e.createElement("div",{className:"rge-ctx-submenu",role:"menu"},w.children.filter(y=>!y.hidden).map(P)))):e.createElement(e.Fragment,{key:w.key},w.dividerBefore&&e.createElement("div",{className:"rge-ctx-menu-divider"}),e.createElement("button",{className:`rge-ctx-menu-item ${w.disabled?"disabled":""} ${w.danger?"danger":""}`,onClick:()=>{var y;w.disabled||((y=w.onClick)==null||y.call(w),s())},disabled:w.disabled,role:"menuitem"},e.createElement("div",{className:"rge-ctx-menu-item-content"},w.icon&&g(w.icon),e.createElement("span",{className:"rge-ctx-menu-label"},w.label),w.shortcut&&e.createElement("span",{className:"rge-ctx-menu-shortcut"},w.shortcut)))),g=w=>{const y=v.getEditorToolbarIconSvg(w);return y?e.createElement("span",{className:"rge-ctx-menu-icon rge-ctx-menu-icon-svg","aria-hidden":"true",dangerouslySetInnerHTML:{__html:y}}):e.createElement("span",{className:"rge-ctx-menu-icon","aria-hidden":"true"},w)};return e.createElement("div",{ref:i,className:"rge-ctx-menu",role:"menu",style:{left:n,top:r}},N.map(P))};va.displayName="ContextMenu";function jo(t,n){const r=Ze(n),o=t.nodeType===void 0||v.isEditorNodeRunTarget(t.nodeType),s=[{key:"edit",label:r("editor.contextMenu.editProperties","编辑属性"),icon:"edit",shortcut:"Enter",onClick:t.onEditProperties},{key:"copy",label:r("editor.contextMenu.copy","复制"),icon:"copy",shortcut:"Ctrl+C",onClick:t.onCopy},{key:"duplicate",label:r("editor.contextMenu.duplicate","复制节点"),icon:"copy",shortcut:"Ctrl+D",onClick:t.onDuplicate},{key:"connections",label:r("editor.contextMenu.viewConnections","查看连接"),icon:"link",onClick:t.onViewConnections},{key:"delete",label:r("editor.contextMenu.delete","删除"),icon:"delete",shortcut:"Del",danger:!0,dividerBefore:!0,onClick:t.onDelete}];return o&&s.splice(4,0,{key:"runFromNode",label:r("editor.contextMenu.runFromNode","从此节点开始执行"),icon:"play",dividerBefore:!0,onClick:t.onRunFromNode},{key:"runSingleNode",label:r("editor.contextMenu.runSingleNode","仅执行此节点"),icon:"play-single",onClick:t.onRunSingleNode}),s}function Ho(t,n){const r=Ze(n);return[{key:"edit",label:r("editor.contextMenu.editProperties","编辑属性"),icon:"edit",onClick:t.onEditProperties},{key:"delete",label:r("editor.contextMenu.delete","删除"),icon:"delete",shortcut:"Del",danger:!0,dividerBefore:!0,onClick:t.onDelete}]}function Wo(t,n){const r=Ze(n);return[{key:"paste",label:r("editor.contextMenu.paste","粘贴"),icon:"paste",shortcut:"Ctrl+V",onClick:t.onPaste},{key:"selectAll",label:r("editor.contextMenu.selectAll","全选"),icon:"select-all",shortcut:"Ctrl+A",onClick:t.onSelectAll},{key:"fitView",label:r("editor.contextMenu.fitView","适应画布"),icon:"fit",dividerBefore:!0,onClick:t.onFitView},{key:"resetZoom",label:r("editor.contextMenu.resetZoom","重置缩放"),icon:"reset-zoom",onClick:t.onResetZoom}]}const cr={"start-input":"#52c41a",filter:"#1890ff",jsFilter:"#1890ff",exprFilter:"#1890ff",transformer:"#722ed1",jsTransform:"#722ed1",template:"#722ed1",action:"#fa8c16",restApiCall:"#fa8c16",mqttClient:"#fa8c16",sendMail:"#fa8c16",dbClient:"#fa8c16",log:"#fa8c16",subChain:"#eb2f96",default:"#8c8c8c"};function Uo(t,n){return n||(t&&cr[t]?cr[t]:cr.default)}const Ca=({nodes:t,viewport:n,width:r=200,height:o=150,defaultCollapsed:s=!1,position:i="bottom-right",onViewportChange:m,onNodeClick:f,locale:M,messages:N,t:P})=>{const[g,w]=e.useState(s),y=e.useRef(null),k=e.useRef(!1),F=e.useMemo(()=>Ze({locale:M,messages:N,t:P}),[M,N,P]),j=e.useCallback(()=>{if(t.length===0)return{minX:0,minY:0,maxX:100,maxY:100};let _=1/0,u=1/0,Z=-1/0,ee=-1/0;t.forEach(V=>{const me=V.width||60,q=V.height||40;_=Math.min(_,V.x),u=Math.min(u,V.y),Z=Math.max(Z,V.x+me),ee=Math.max(ee,V.y+q)});const H=50;return{minX:_-H,minY:u-H,maxX:Z+H,maxY:ee+H}},[t]);e.useEffect(()=>{if(g||!y.current)return;const _=y.current.getContext("2d");if(!_)return;const u=j(),Z=u.maxX-u.minX,ee=u.maxY-u.minY,H=Math.min(r/Z,o/ee);if(_.clearRect(0,0,r,o),_.fillStyle="rgba(30, 30, 30, 0.85)",_.fillRect(0,0,r,o),t.forEach(V=>{const me=(V.x-u.minX)*H,q=(V.y-u.minY)*H,le=Math.max((V.width||60)*H,4),ue=Math.max((V.height||40)*H,3);_.fillStyle=V.selected?"#ff4d4f":Uo(V.type,V.color),_.fillRect(me,q,le,ue),V.selected&&(_.strokeStyle="#fff",_.lineWidth=1,_.strokeRect(me-1,q-1,le+2,ue+2))}),n){const V=(n.x-u.minX)*H,me=(n.y-u.minY)*H,q=n.width*H,le=n.height*H;_.strokeStyle="rgba(64, 169, 255, 0.8)",_.lineWidth=2,_.strokeRect(V,me,q,le),_.fillStyle="rgba(64, 169, 255, 0.1)",_.fillRect(V,me,q,le)}},[t,n,g,r,o,j]);const O=e.useCallback(_=>{if(!m||!y.current)return;const u=y.current.getBoundingClientRect(),Z=_.clientX-u.left,ee=_.clientY-u.top,H=j(),V=H.maxX-H.minX,me=H.maxY-H.minY,q=Math.min(r/V,o/me),le=Z/q+H.minX,ue=ee/q+H.minY;m({x:le,y:ue})},[m,j,r,o]),U=e.useCallback(_=>{k.current=!0,O(_)},[O]),C=e.useCallback(_=>{k.current&&O(_)},[O]),I=e.useCallback(()=>{k.current=!1},[]),D={position:"absolute",zIndex:100,...i.includes("bottom")?{bottom:16}:{top:16},...i.includes("right")?{right:16}:{left:16}};return e.createElement("div",{className:"rge-minimap",style:D},e.createElement("div",{className:"rge-minimap-header",onClick:()=>w(!g)},e.createElement("span",{className:"rge-minimap-title"},e.createElement(pe,{value:"map"})," ",F("editor.toolbar.minimap","小地图")),e.createElement("span",{className:"rge-minimap-toggle"},g?"▶":"▼")),!g&&e.createElement("canvas",{ref:y,width:r,height:o,className:"rge-minimap-canvas",onMouseDown:U,onMouseMove:C,onMouseUp:I,onMouseLeave:I}))};Ca.displayName="MiniMap";function Vo(t,n){switch(t){case"close":return"关闭";case"close-others":return"关闭其他";case"close-right":return"关闭右侧";case"rename":return"重命名";case"toggle-pinned":return v.isWorkspaceTabPinned(n)?"取消固定":"固定";case"edit-info":return"编辑信息";case"run-history":return"运行记录";case"debug":return"调试";case"toggle-disabled":return v.getWorkspaceTabLifecycleState(n)==="running"?"下线":"部署"}}function qo({tabs:t,activeTabId:n=null,locale:r,t:o,onActivate:s,onClose:i,onAdd:m,onEditInfo:f,onTabAction:M,hideAdd:N=!1}){var _;const P=e.useMemo(()=>Ze({locale:r,t:o}),[r,o]),[g,w]=e.useState(!1),[y,k]=e.useState(null),[F,j]=e.useState(null),O=e.useRef(null),U=n||((_=t[0])==null?void 0:_.id)||"",C=t.find(u=>u.id===U),I=y?t.find(u=>u.id===y.tabId):void 0,D=I?v.getEditorWorkspaceTabActions(I):[];return e.useLayoutEffect(()=>{if(!y||!O.current)return;const u=O.current.getBoundingClientRect(),Z=v.clampContextMenuPosition({left:y.x,top:y.y},{width:u.width,height:u.height},{width:window.innerWidth,height:window.innerHeight});j(ee=>(ee==null?void 0:ee.left)===Z.left&&ee.top===Z.top?ee:Z)},[y,D.length]),e.useEffect(()=>{if(!y)return;const u=()=>k(null);return document.addEventListener("click",u),document.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{document.removeEventListener("click",u),document.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}},[y]),e.createElement("div",{className:"rge-workspace-tabs",role:"tablist","aria-label":P("editor.workspace.tabs","规则链标签")},e.createElement("div",{className:"rge-workspace-tabs__strip"},t.map(u=>{var me,q,le;const Z=u.id===U,ee=((me=u.metadata)==null?void 0:me.root)!==!1&&((le=(q=u.data)==null?void 0:q.ruleChain)==null?void 0:le.root)!==!1,H=v.getWorkspaceTabLifecycleState(u),V=v.isWorkspaceTabPinned(u);return e.createElement("div",{key:u.id,className:`rge-workspace-tab${Z?" is-active":""}${u.isDirty?" is-dirty":""}`,"data-workspace-tab-id":u.id,role:"tab","aria-selected":Z,"aria-busy":u.isLoading||void 0,title:u.isDirty?`${u.title} · ${P("editor.workspace.unsaved","有未保存修改")}`:u.title,onClick:()=>s==null?void 0:s(u.id),onDoubleClick:()=>f==null?void 0:f(u.id),onContextMenu:ue=>{ue.preventDefault(),ue.stopPropagation(),s==null||s(u.id),j({left:ue.clientX,top:ue.clientY}),k({tabId:u.id,x:ue.clientX,y:ue.clientY})}},H!=="undeployed"&&e.createElement("span",{className:`rge-workspace-tab__lifecycle is-${H}`,"aria-label":P(`editor.workspace.${H}`,H==="running"?"运行中":"已停止"),title:P(`editor.workspace.${H}`,H==="running"?"运行中":"已停止")}),e.createElement("span",{className:`rge-workspace-tab__kind${ee?" is-root":" is-child"}`,"aria-hidden":"true"},V?"★":ee?"◆":"↳"),e.createElement("span",{className:"rge-workspace-tab__title"},u.title||u.chainId),u.isLoading&&e.createElement("span",{className:"rge-workspace-tab__loading","aria-label":P("editor.workspace.loading","加载中")}),e.createElement("button",{type:"button",className:"rge-workspace-tab__close","data-workspace-close-id":u.id,"aria-label":`${P("editor.workspace.close","关闭")} ${u.title||u.chainId}`,title:P("editor.workspace.close","关闭"),onClick:ue=>{ue.stopPropagation(),i==null||i(u.id)}},u.isDirty?e.createElement("span",{className:"rge-workspace-tab__dirty-dot","aria-hidden":"true"}):"×"))}),!t.length&&e.createElement("span",{className:"rge-workspace-tabs__empty"},P("editor.workspace.empty","打开规则链后显示标签"))),!N&&e.createElement("button",{type:"button",className:"rge-workspace-tabs__icon",title:P("editor.workspace.add","新建规则链"),"aria-label":P("editor.workspace.add","新建规则链"),onClick:m},"+"),t.length>0&&e.createElement("div",{className:"rge-workspace-tabs__overflow"},e.createElement("button",{type:"button",className:"rge-workspace-tabs__icon",title:P("editor.workspace.all","全部规则链"),"aria-label":P("editor.workspace.all","全部规则链"),"aria-expanded":g,onClick:()=>w(u=>!u)},"▾"),g&&e.createElement("div",{className:"rge-workspace-tabs__menu",role:"menu"},t.map(u=>{const Z=v.getWorkspaceTabLifecycleState(u);return e.createElement("button",{key:u.id,type:"button",role:"menuitem",className:u.id===U?"is-active":"",onClick:()=>{s==null||s(u.id),w(!1)}},Z!=="undeployed"&&e.createElement("span",{className:`rge-workspace-tab__lifecycle is-${Z}`,"aria-hidden":"true"}),v.isWorkspaceTabPinned(u)?"★ ":"",u.isDirty?"● ":"",u.title||u.chainId)}))),C&&e.createElement("span",{className:"rge-workspace-tabs__status","aria-live":"polite"},C.isDirty?"●":""),y&&I&&e.createElement("div",{className:"rge-workspace-tabs__context-menu",ref:O,role:"menu",style:{left:(F==null?void 0:F.left)??y.x,top:(F==null?void 0:F.top)??y.y},onClick:u=>u.stopPropagation()},D.map(u=>{const Z=u.id==="close"?!!i:u.id==="edit-info"?!!f:!!M;return e.createElement("button",{key:u.id,type:"button",role:"menuitem","data-workspace-tab-action":u.id,className:u.dividerBefore?"is-divider-before":void 0,disabled:u.disabled||!Z,onClick:()=>{u.disabled||!Z||(u.id==="close"?i==null||i(I.id):u.id==="edit-info"?f==null||f(I.id):M==null||M(I.id,u.id),k(null))}},P(u.labelKey,Vo(u.id,I)))})))}const Yr=["graph:transform","node:click","edge:click","blank:click","node:add","node:delete","edge:add","edge:delete","selection:drop","graph:rendered","history:change"];function Xr(t){var o,s,i,m,f,M;if(!(t!=null&&t.graphModel))return{nodeCount:0,edgeCount:0,selectedCount:0,zoom:1};const n=((o=t.getSelectElements)==null?void 0:o.call(t))||{},r=(s=t.graphModel.transformModel)==null?void 0:s.SCALE_X;return{nodeCount:((i=t.graphModel.nodes)==null?void 0:i.length)||0,edgeCount:((m=t.graphModel.edges)==null?void 0:m.length)||0,selectedCount:(((f=n.nodes)==null?void 0:f.length)||0)+(((M=n.edges)==null?void 0:M.length)||0),zoom:typeof r=="number"&&r>0?r:1}}function Jo({lf:t,nodeCount:n,edgeCount:r,selectedCount:o,zoom:s,problemCount:i=0,onZoomIn:m,onZoomOut:f,onResetZoom:M,onOpenDiagnostics:N,className:P="",locale:g,messages:w,t:y}){const k=e.useMemo(()=>Ze({locale:g,messages:w,t:y}),[g,w,y]),[F,j]=e.useState(()=>Xr(t));e.useEffect(()=>{const H=()=>j(Xr(t));if(H(),!!(t!=null&&t.on))return Yr.forEach(V=>{var me;return(me=t.on)==null?void 0:me.call(t,V,H)}),()=>Yr.forEach(V=>{var me;return(me=t.off)==null?void 0:me.call(t,V,H)})},[t]);const O=n??F.nodeCount,U=r??F.edgeCount,C=o??F.selectedCount,I=s??F.zoom,D=H=>{t!=null&&t.zoom&&t.zoom((I>0?I:1)*H)},_=()=>m?m():D(1.2),u=()=>f?f():D(1/1.2),Z=()=>{var H;return M?M():(H=t==null?void 0:t.resetZoom)==null?void 0:H.call(t)},ee=["rge-status-bar",P].filter(Boolean).join(" ");return e.createElement("div",{className:ee,role:"status","aria-live":"polite"},e.createElement("button",{type:"button",className:"rge-status-bar__button",title:k("editor.statusBar.zoomOut","缩小"),"aria-label":k("editor.statusBar.zoomOut","缩小"),onClick:u},"−"),e.createElement("button",{type:"button",className:"rge-status-bar__value",title:k("editor.statusBar.resetZoom","重置为 100%"),onClick:Z},Math.round(I*100),"%"),e.createElement("button",{type:"button",className:"rge-status-bar__button",title:k("editor.statusBar.zoomIn","放大"),"aria-label":k("editor.statusBar.zoomIn","放大"),onClick:_},"+"),e.createElement("span",{className:"rge-status-bar__separator","aria-hidden":"true"},"|"),e.createElement("span",{className:"rge-status-bar__item"},k("editor.statusBar.nodes","节点")," ",O),e.createElement("span",{className:"rge-status-bar__item"},k("editor.statusBar.edges","边")," ",U),C>0&&e.createElement("span",{className:"rge-status-bar__item"},k("editor.statusBar.selected","已选")," ",C),i>0&&e.createElement(e.Fragment,null,e.createElement("span",{className:"rge-status-bar__separator","aria-hidden":"true"},"|"),e.createElement("button",{type:"button",className:"rge-status-bar__diagnostic",title:k("editor.statusBar.diagnostics","查看链路诊断"),onClick:N},k("editor.statusBar.diagnostics","诊断")," ",i)))}const Qr={online:{key:"editor.connection.online",fallback:"已连接",kind:"online"},checking:{key:"editor.connection.checking",fallback:"检测中",kind:"checking"},unauthorized:{key:"editor.connection.unauthorized",fallback:"需要登录",kind:"unauthorized"},forbidden:{key:"editor.connection.forbidden",fallback:"权限不足",kind:"forbidden"},offline:{key:"editor.connection.offline",fallback:"无法连接",kind:"offline"},error:{key:"editor.connection.error",fallback:"连接异常",kind:"error"},unknown:{key:"editor.connection.unknown",fallback:"未检测",kind:"unknown"}};function Ko({state:t,compact:n=!1,onRetry:r,onLogin:o,className:s="",locale:i,messages:m,t:f}){const M=e.useMemo(()=>Ze({locale:i,messages:m,t:f}),[i,m,f]),N=String((t==null?void 0:t.status)||"unknown"),P=Qr[N]||Qr.unknown,g=(t==null?void 0:t.api)||"unknown",w=(t==null?void 0:t.ws)||"idle",y=`${M("editor.connection.api","API")}: ${g} · ${M("editor.connection.ws","WS")}: ${w}`,k=["rge-connection-status",`is-${P.kind}`,n?"is-compact":"",s].filter(Boolean).join(" "),F=N==="unauthorized"?o:N==="offline"||N==="error"?r:void 0,j=N==="unauthorized"?M("editor.connection.login","登录"):M("editor.connection.retry","重试");return e.createElement("div",{className:k,role:"status","aria-live":"polite",title:y},e.createElement("span",{className:"rge-connection-status__dot","aria-hidden":"true"}),e.createElement("span",{className:"rge-connection-status__label"},M(P.key,P.fallback)),!n&&e.createElement("span",{className:"rge-connection-status__detail"},y),F&&e.createElement("button",{type:"button",className:"rge-connection-status__action",onClick:F},j))}function zo(t,n){return n.visible!==!1&&t.openPanelIds.includes(n.id)}function Go(t,n){return t.panels.filter(r=>r.dock===n&&zo(t,r)).sort((r,o)=>(r.order??0)-(o.order??0)||r.id.localeCompare(o.id))}function en(t,n){var r;return((r=t.expandedById)==null?void 0:r[n.id])??n.defaultExpanded!==!1}function Yo({dock:t,dockState:n,panelState:r,renderPanel:o,title:s,className:i="",onToggleDock:m,onActivatePanel:f,onClosePanel:M,onTogglePanel:N,onResize:P}){var D;const g=e.useRef(null),w=e.useRef(null),[y,k]=e.useState(!1),F=e.useMemo(()=>Go(r,t),[r,t]),j=r.activeByDock[t]&&F.some(_=>_.id===r.activeByDock[t])?r.activeByDock[t]:((D=F[0])==null?void 0:D.id)||null,O=t==="bottom"?n.bottom.height:n[t].width,U=n[t].visible&&F.length>0,C=t==="left";e.useEffect(()=>()=>{const _=w.current;w.current=null,_==null||_(!1)},[]);const I=_=>{var ue,W;if(!P)return;_.preventDefault();const u=t==="bottom"?_.clientY:_.clientX,Z=O,ee=t==="left"?1:-1,H=_.currentTarget,V=_.pointerId;(ue=H.setPointerCapture)==null||ue.call(H,V);const me=ge=>{const Pe=t==="bottom"?ge.clientY:ge.clientX;P(t,Z+(Pe-u)*ee)},q=ge=>{var Pe,Me;window.removeEventListener("pointermove",me),window.removeEventListener("pointerup",le),window.removeEventListener("pointercancel",le),(Pe=H.hasPointerCapture)!=null&&Pe.call(H,V)&&((Me=H.releasePointerCapture)==null||Me.call(H,V)),ge&&k(!1),w.current=null},le=()=>q(!0);(W=w.current)==null||W.call(w,!0),w.current=q,k(!0),window.addEventListener("pointermove",me),window.addEventListener("pointerup",le,{once:!0}),window.addEventListener("pointercancel",le,{once:!0})};return U?e.createElement("section",{ref:g,className:["rge-panel-dock",`rge-panel-dock--${t}`,y&&"is-resizing",i].filter(Boolean).join(" "),style:t==="bottom"?{height:O}:{width:O},"aria-label":s},e.createElement("div",{className:"rge-panel-dock__header"},C?e.createElement("strong",{className:"rge-panel-dock__title"},s||"模块"):e.createElement("div",{className:"rge-panel-dock__tabs",role:"tablist"},F.map(_=>e.createElement("button",{key:_.id,type:"button",role:"tab","aria-selected":_.id===j,className:_.id===j?"is-active":"",onClick:()=>f==null?void 0:f(_.id)},_.icon&&e.createElement("span",{"aria-hidden":"true"},_.icon),_.title||_.id))),e.createElement("button",{type:"button",className:"rge-panel-dock__close",title:s?`收起${s}`:"收起面板","aria-label":s?`收起${s}`:"收起面板",onClick:()=>m==null?void 0:m(t,!1)},"×")),e.createElement("div",{className:"rge-panel-dock__body"},C?F.map(_=>e.createElement("div",{key:_.id,className:"rge-panel-dock__stack-panel"},(()=>{const u=en(r,_);return e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-panel-dock__stack-title"},e.createElement("span",null,_.title||_.id),e.createElement("button",{type:"button",title:u?"收起内容":"展开内容","aria-label":`${u?"收起":"展开"}${_.title||_.id}`,"aria-expanded":u,onClick:()=>N==null?void 0:N(_.id,!u)},u?"−":"+"),_.closeable!==!1&&e.createElement("button",{type:"button",title:"关闭面板","aria-label":`关闭${_.title||_.id}`,onClick:()=>M==null?void 0:M(_.id)},"×")),e.createElement("div",{className:"rge-panel-dock__panel-content",hidden:!u},o==null?void 0:o(_)))})())):F.map(_=>e.createElement("div",{key:_.id,className:`rge-panel-dock__tab-panel${en(r,_)?"":" is-collapsed"}`,hidden:_.id!==j},e.createElement("div",{className:"rge-panel-dock__tab-tools"},e.createElement("button",{type:"button",title:en(r,_)?"收起内容":"展开内容","aria-label":`${en(r,_)?"收起":"展开"}${_.title||_.id}`,"aria-expanded":en(r,_),onClick:()=>N==null?void 0:N(_.id,!en(r,_))},en(r,_)?"−":"+"),_.closeable!==!1&&e.createElement("button",{type:"button",title:"关闭面板","aria-label":`关闭${_.title||_.id}`,onClick:()=>M==null?void 0:M(_.id)},"×")),e.createElement("div",{className:"rge-panel-dock__tab-content",hidden:!en(r,_)},o==null?void 0:o(_))))),e.createElement("div",{className:"rge-panel-dock__resize",role:"separator","aria-orientation":t==="bottom"?"horizontal":"vertical",onPointerDown:I})):null}function Xo({visible:t=!0,x:n,y:r,flipDown:o=!1,targetId:s,showRun:i=!0,nodeType:m,className:f="",onAction:M,onEdit:N,onCopy:P,onDelete:g,onRunFrom:w,onRunOnly:y,locale:k,messages:F,t:j}){const O=e.useMemo(()=>Ze({locale:k,messages:F,t:j}),[k,F,j]);if(!t||!s)return null;const U=i&&v.isEditorNodeRunTarget(m||"simple-node"),C=(D,_)=>{(D==="run-from"||D==="run-only")&&!U||(_==null||_(s),M==null||M(D,s))},I=(D,_,u,Z,ee="")=>e.createElement("button",{key:D,type:"button",className:`rge-hover-tools__button ${ee}`,title:_,"aria-label":_,onClick:()=>C(D,Z)},e.createElement(pe,{value:u}));return e.createElement("div",{className:["rge-hover-tools","rge-node-hover-tools",o?"is-flip-down":"",f].filter(Boolean).join(" "),style:{left:n,top:r},role:"toolbar","aria-label":O("editor.hoverTools.nodeActions","节点操作")},I("edit",O("editor.hoverTools.edit","编辑节点"),"edit",N),I("copy",O("editor.hoverTools.copy","复制节点"),"copy",P),U&&I("run-from",O("editor.hoverTools.runFrom","从此节点开始执行"),"play",w,"is-primary"),U&&I("run-only",O("editor.hoverTools.runOnly","仅执行此节点"),"play-single",y,"is-warning"),I("delete",O("editor.hoverTools.delete","删除节点"),"delete",g,"is-danger"))}function Qo({visible:t=!0,x:n,y:r,flipDown:o=!1,targetId:s,className:i="",onAction:m,onInsertNode:f,onDelete:M,locale:N,messages:P,t:g}){const w=e.useMemo(()=>Ze({locale:N,messages:P,t:g}),[N,P,g]);if(!t||!s)return null;const y=(j,O)=>{O==null||O(s),m==null||m(j,s)},k=w("editor.hoverTools.insertNode","在连线中插入组件"),F=w("editor.hoverTools.deleteEdge","删除连线");return e.createElement("div",{className:["rge-hover-tools","rge-edge-hover-tools",o?"is-flip-down":"",i].filter(Boolean).join(" "),style:{left:n,top:r},role:"toolbar","aria-label":w("editor.hoverTools.edgeActions","连线操作")},e.createElement("button",{type:"button",className:"rge-hover-tools__button is-primary",title:k,"aria-label":k,onClick:()=>y("insert-node",f)},e.createElement(pe,{value:"add"})),e.createElement("button",{type:"button",className:"rge-hover-tools__button is-danger",title:F,"aria-label":F,onClick:()=>y("delete",M)},e.createElement(pe,{value:"delete"})))}const qn={error:"error",warning:"warning",info:"docs"},ka=({items:t,isValid:n,visible:r=!0,loading:o=!1,title:s,onValidate:i,onItemClick:m,onClose:f,onClear:M,locale:N,messages:P,t:g})=>{const[w,y]=e.useState("all"),k=e.useMemo(()=>Ze({locale:N,messages:P,t:g}),[N,P,g]),F=s||k("editor.validation.title","规则链校验"),j=e.useMemo(()=>{const U={error:0,warning:0,info:0};return t.forEach(C=>{U[C.level]!==void 0&&U[C.level]++}),U},[t]),O=e.useMemo(()=>w==="all"?t:t.filter(U=>U.level===w),[t,w]);return r?e.createElement("div",{className:"rge-validation-panel"},e.createElement("div",{className:"rge-validation-header"},e.createElement("span",{className:"rge-validation-title"},n!==void 0&&e.createElement(pe,{value:n?"validate":"error"}),F),e.createElement("div",{className:"rge-validation-actions"},i&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:i,disabled:o,title:k("editor.validation.revalidate","重新校验")},e.createElement(pe,{value:"refresh",className:o?"is-spinning":""}),k("editor.validation.validate","校验")),M&&t.length>0&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:M,title:k("editor.validation.clearResults","清除结果")},e.createElement(pe,{value:"delete"})),f&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:f,title:k("editor.validation.close","关闭")},"✕"))),e.createElement("div",{className:"rge-validation-stats"},e.createElement("button",{className:`rge-validation-stat ${w==="all"?"active":""}`,onClick:()=>y("all")},k("editor.validation.all","全部")," (",t.length,")"),e.createElement("button",{className:`rge-validation-stat error ${w==="error"?"active":""}`,onClick:()=>y("error")},e.createElement(pe,{value:qn.error})," ",j.error),e.createElement("button",{className:`rge-validation-stat warning ${w==="warning"?"active":""}`,onClick:()=>y("warning")},e.createElement(pe,{value:qn.warning})," ",j.warning),e.createElement("button",{className:`rge-validation-stat info ${w==="info"?"active":""}`,onClick:()=>y("info")},e.createElement(pe,{value:qn.info})," ",j.info)),e.createElement("div",{className:"rge-validation-body"},o&&e.createElement("div",{className:"rge-validation-loading"},e.createElement(pe,{value:"refresh",className:"is-spinning"}),k("editor.validation.validating","正在校验...")),!o&&O.length===0&&e.createElement("div",{className:"rge-validation-empty"},t.length===0?e.createElement(e.Fragment,null,e.createElement(pe,{value:"validate"})," ",k("editor.validation.empty","无校验结果,请点击校验按钮开始")):k("editor.validation.noFilteredResults","当前筛选无结果")),!o&&O.map((U,C)=>e.createElement("div",{key:`${U.rule}-${U.elementId||C}`,className:`rge-validation-item level-${U.level}`,onClick:()=>m==null?void 0:m(U),role:"button",tabIndex:0},e.createElement("span",{className:"rge-validation-item-icon"},e.createElement(pe,{value:qn[U.level]})),e.createElement("div",{className:"rge-validation-item-content"},e.createElement("div",{className:"rge-validation-item-message"},U.message),e.createElement("div",{className:"rge-validation-item-meta"},e.createElement("span",{className:"rge-validation-item-rule"},U.rule),U.elementId&&e.createElement("span",{className:"rge-validation-item-element"},e.createElement(pe,{value:U.elementType==="node"?"package":"link"}),U.elementId))))))):null};ka.displayName="ValidationPanel";const Zr={error:0,warning:1,info:2},Zo={error:"editor.problems.error",warning:"editor.problems.warning",info:"editor.problems.info"};function el(t){return t.elementId?`${t.elementType||"element"}:${t.elementId}`:"chain"}function tl(t,n){return t.elementId?t.elementType==="edge"?`${n("editor.problems.edge","连线")} ${t.elementId}`:`${n("editor.problems.node","节点")} ${t.elementId}`:n("editor.problems.chain","规则链")}function Na({items:t,visible:n=!0,loading:r=!1,title:o,onValidate:s,onLocate:i,onClear:m,onClose:f,locale:M,messages:N,t:P}){const[g,w]=e.useState("all"),y=e.useMemo(()=>Ze({locale:M,messages:N,t:P}),[M,N,P]),k=e.useMemo(()=>t.reduce((C,I)=>(C[I.severity]+=1,C),{error:0,warning:0,info:0}),[t]),F=e.useMemo(()=>{const C=new Map;return t.filter(I=>g==="all"||I.severity===g).forEach(I=>{const D=el(I),_=C.get(D)||[];_.push(I),C.set(D,_)}),Array.from(C.entries()).map(([I,D])=>({key:I,items:D.sort((_,u)=>Zr[_.severity]-Zr[u.severity])}))},[g,t]);if(!n)return null;const j=o||y("editor.problems.title","链路诊断"),O=C=>y(Zo[C],C==="error"?"错误":C==="warning"?"警告":"提示"),U=(C,I,D,_="")=>e.createElement("button",{type:"button",className:`rge-problems__filter ${_} ${g===C?"is-active":""}`,"aria-pressed":g===C,onClick:()=>w(C)},I," ",e.createElement("span",null,D));return e.createElement("section",{className:"rge-problems","aria-label":j},e.createElement("header",{className:"rge-problems__header"},e.createElement("div",{className:"rge-problems__heading"},e.createElement("strong",null,j),e.createElement("span",{className:"rge-problems__total"},t.length)),e.createElement("div",{className:"rge-problems__actions"},s&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:s,disabled:r,title:y("editor.problems.validate","重新校验")},r?"…":"↻"),m&&t.length>0&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:m,title:y("editor.problems.clear","清除问题")},"⌫"),f&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:f,title:y("editor.problems.close","关闭")},"×"))),e.createElement("div",{className:"rge-problems__filters",role:"toolbar","aria-label":y("editor.problems.filter","筛选问题")},U("all",y("editor.problems.all","全部"),t.length),U("error",O("error"),k.error,"is-error"),U("warning",O("warning"),k.warning,"is-warning"),U("info",O("info"),k.info,"is-info")),e.createElement("div",{className:"rge-problems__body"},r&&e.createElement("div",{className:"rge-problems__empty"},y("editor.problems.loading","正在校验…")),!r&&F.length===0&&e.createElement("div",{className:"rge-problems__empty"},t.length?y("editor.problems.noFiltered","当前筛选无问题"):y("editor.problems.empty","未发现链路问题")),!r&&F.map(C=>{const I=C.items[0];return e.createElement("div",{className:"rge-problems__group",key:C.key},e.createElement("button",{type:"button",className:"rge-problems__group-heading",onClick:()=>i==null?void 0:i(I)},e.createElement("span",{className:`rge-problems__marker is-${I.severity}`,"aria-hidden":"true"}),e.createElement("span",{className:"rge-problems__group-label"},tl(I,(D,_)=>y(D,_))),e.createElement("span",{className:"rge-problems__group-count"},C.items.length)),C.items.map(D=>e.createElement("button",{type:"button",className:`rge-problems__item is-${D.severity}`,key:D.id,onClick:()=>i==null?void 0:i(D)},e.createElement("span",{className:"rge-problems__item-severity"},O(D.severity)),e.createElement("span",{className:"rge-problems__item-message"},D.message),e.createElement("span",{className:"rge-problems__item-rule"},D.rule))))})))}Na.displayName="ProblemsPanel";const wa=({visible:t,data:n,readOnly:r=!1,title:o,customFields:s=[],onSave:i,onClose:m,locale:f,messages:M,t:N})=>{const[P,g]=e.useState(n),[w,y]=e.useState({}),k=e.useMemo(()=>Ze({locale:f,messages:M,t:N}),[f,M,N]),F=o||k("editor.ruleChainSettings.title","规则链设置");e.useEffect(()=>{g(n),y({})},[n,t]);const j=(C,I)=>{g(D=>({...D,[C]:I})),w[C]&&y(D=>{const _={...D};return delete _[C],_})},O=()=>{const C={};return(!P.name||P.name.trim()==="")&&(C.name=k("editor.ruleChainSettings.nameRequired","规则链名称不能为空")),y(C),Object.keys(C).length===0},U=()=>{r||O()&&(i==null||i(P),m())};return e.useEffect(()=>{const C=I=>{I.key==="Escape"&&t&&m()};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[t,m]),t?e.createElement("div",{className:"rge-modal-overlay",onClick:m},e.createElement("div",{className:"rge-modal",onClick:C=>C.stopPropagation()},e.createElement("div",{className:"rge-modal-header"},e.createElement("span",{className:"rge-modal-title"},e.createElement(pe,{value:"settings"})," ",F),e.createElement("button",{className:"rge-modal-close",onClick:m},"✕")),e.createElement("div",{className:"rge-modal-body"},P.id&&e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},"ID"),e.createElement("input",{className:"rge-form-input",value:P.id,disabled:!0})),e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},k("editor.panel.name","名称")," ",e.createElement("span",{className:"rge-required"},"*")),e.createElement("input",{className:`rge-form-input ${w.name?"error":""}`,value:P.name,onChange:C=>j("name",C.target.value),placeholder:k("editor.ruleChainSettings.namePlaceholder","请输入规则链名称"),disabled:r}),w.name&&e.createElement("span",{className:"rge-form-error"},w.name)),e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},k("editor.panel.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",value:P.description||"",onChange:C=>j("description",C.target.value),placeholder:k("editor.ruleChainSettings.descriptionPlaceholder","请输入规则链描述"),rows:3,disabled:r})),e.createElement("div",{className:"rge-form-row"},e.createElement("div",{className:"rge-form-group inline"},e.createElement("label",{className:"rge-form-label"},k("editor.ruleChainSettings.root","根链")),e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:P.root||!1,onChange:C=>j("root",C.target.checked),disabled:r}),e.createElement("span",{className:"rge-switch-slider"}))),e.createElement("div",{className:"rge-form-group inline"},e.createElement("label",{className:"rge-form-label"},k("editor.panel.debugMode","调试模式")),e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:P.debugMode||!1,onChange:C=>j("debugMode",C.target.checked),disabled:r}),e.createElement("span",{className:"rge-switch-slider"})))),s.map(C=>e.createElement("div",{className:"rge-form-group",key:C.key},e.createElement("label",{className:"rge-form-label"},C.label),C.type==="text"&&e.createElement("input",{className:"rge-form-input",value:String((P[C.key]??C.defaultValue)||""),onChange:I=>j(C.key,I.target.value),placeholder:C.placeholder,disabled:r}),C.type==="number"&&e.createElement("input",{className:"rge-form-input",type:"number",value:P[C.key]??C.defaultValue??"",onChange:I=>j(C.key,Number(I.target.value)),placeholder:C.placeholder,disabled:r}),C.type==="textarea"&&e.createElement("textarea",{className:"rge-form-textarea",value:String((P[C.key]??C.defaultValue)||""),onChange:I=>j(C.key,I.target.value),placeholder:C.placeholder,rows:3,disabled:r}),C.type==="select"&&e.createElement(zt,{value:String((P[C.key]??C.defaultValue)||""),options:C.options||[],onChange:I=>j(C.key,I),disabled:r,placeholder:C.placeholder,searchPlaceholder:k("editor.property.searchOptions","搜索选项..."),noMatchText:k("editor.property.noMatchingOptions","没有匹配的选项")}),C.type==="switch"&&e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:P[C.key]??C.defaultValue??!1,onChange:I=>j(C.key,I.target.checked),disabled:r}),e.createElement("span",{className:"rge-switch-slider"})),C.help&&e.createElement("span",{className:"rge-form-help"},C.help))),P.additionalInfo&&Object.keys(P.additionalInfo).length>0&&e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},k("editor.ruleChainSettings.additionalInfo","额外配置 (JSON)")),e.createElement("textarea",{className:"rge-form-textarea mono",value:JSON.stringify(P.additionalInfo,null,2),onChange:C=>{try{j("additionalInfo",JSON.parse(C.target.value))}catch{}},rows:5,disabled:r}))),e.createElement("div",{className:"rge-modal-footer"},e.createElement("button",{className:"rge-btn secondary",onClick:m},k("editor.panel.cancel","取消")),!r&&e.createElement("button",{className:"rge-btn primary",onClick:U},e.createElement(pe,{value:"save"})," ",k("editor.toolbar.save","保存"))))):null};wa.displayName="RuleChainSettings";const Dt=({name:t,className:n=""})=>{const r=v.getEditorToolbarIconSvg(t);return r?e.createElement("span",{className:`rge-controlled-icon ${n}`.trim(),"aria-hidden":"true",dangerouslySetInnerHTML:{__html:r}}):null},nl=({mode:t="export",data:n,chainName:r="rule-chain",onImport:o,onClose:s,onNotify:i,locale:m,messages:f,t:M})=>{var me,q,le,ue,W,ge,Pe,Me,X;const[N,P]=e.useState(t),[g,w]=e.useState(""),[y,k]=e.useState(null),[F,j]=e.useState(""),[O,U]=e.useState(!1),C=e.useRef(null),I=e.useMemo(()=>Ze({locale:m,messages:f,t:M}),[m,f,M]),D=n?JSON.stringify(n,null,2):"",_=e.useCallback(b=>{j(""),w(b);try{const $=JSON.parse(b);if(!$.ruleChain&&!$.metadata){j(I("editor.importExport.invalidRuleChainJson","JSON 格式不符合 RuleGo 规则链规范(缺少 ruleChain 或 metadata 字段)")),k(null);return}k($)}catch($){j(I("editor.importExport.jsonParseFailed","JSON 解析失败: {{message}}",{message:$.message})),k(null)}},[I]),u=e.useCallback(b=>{var te;const $=(te=b.target.files)==null?void 0:te[0];if(!$)return;if(!$.name.endsWith(".json")){j(I("editor.importExport.selectJsonFile","请选择 .json 文件"));return}const Y=new FileReader;Y.onload=L=>{var we;const ke=(we=L.target)==null?void 0:we.result;_(ke)},Y.readAsText($)},[_]),Z=e.useCallback(b=>{var te;b.preventDefault(),U(!1);const $=(te=b.dataTransfer.files)==null?void 0:te[0];if(!$)return;if(!$.name.endsWith(".json")){j(I("editor.importExport.selectJsonFile","请选择 .json 文件"));return}const Y=new FileReader;Y.onload=L=>{var we;const ke=(we=L.target)==null?void 0:we.result;_(ke)},Y.readAsText($)},[_]),ee=e.useCallback(()=>{navigator.clipboard.writeText(D).then(()=>{i==null||i("success",I("editor.importExport.copied","已复制到剪贴板"))}).catch(()=>{const b=document.createElement("textarea");b.value=D,document.body.appendChild(b),b.select(),document.execCommand("copy"),document.body.removeChild(b),i==null||i("success",I("editor.importExport.copied","已复制到剪贴板"))})},[D,i,I]),H=e.useCallback(()=>{const $=`${r.replace(/[^a-zA-Z0-9_\-\u4e00-\u9fa5]/g,"_")}_${new Date().toISOString().slice(0,10)}.json`,Y=new Blob([D],{type:"application/json"}),te=URL.createObjectURL(Y),L=document.createElement("a");L.href=te,L.download=$,document.body.appendChild(L),L.click(),document.body.removeChild(L),URL.revokeObjectURL(te),i==null||i("success",I("editor.importExport.downloaded","已下载: {{fileName}}",{fileName:$}))},[D,r,i,I]),V=e.useCallback(()=>{if(!y){i==null||i("error",I("editor.importExport.noImportData","没有可导入的数据"));return}o==null||o(y),i==null||i("success",I("editor.importExport.importSuccess","规则链导入成功")),s()},[y,o,i,s,I]);return e.createElement("div",{className:"rge-modal-overlay",onClick:b=>{b.target===b.currentTarget&&s()}},e.createElement("div",{className:"rge-modal",style:{width:640}},e.createElement("div",{className:"rge-modal-header"},e.createElement("div",{className:"rge-modal-title"},e.createElement(Dt,{name:N==="export"?"export":"import"}),e.createElement("span",null,N==="export"?I("editor.importExport.exportTitle","导出规则链"):I("editor.importExport.importTitle","导入规则链"))),e.createElement("button",{type:"button",className:"rge-modal-close",onClick:s},"✕")),e.createElement("div",{className:"rge-ie-tabs"},e.createElement("button",{type:"button",className:`rge-ie-tab ${N==="export"?"active":""}`,onClick:()=>P("export")},e.createElement(Dt,{name:"export"}),e.createElement("span",null,I("editor.importExport.exportTab","导出"))),e.createElement("button",{type:"button",className:`rge-ie-tab ${N==="import"?"active":""}`,onClick:()=>P("import")},e.createElement(Dt,{name:"import"}),e.createElement("span",null,I("editor.importExport.importTab","导入")))),e.createElement("div",{className:"rge-modal-body"},N==="export"?e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-ie-info"},e.createElement("span",null,e.createElement(Dt,{name:"package"}),I("editor.importExport.nodes","节点"),": ",((q=(me=n==null?void 0:n.metadata)==null?void 0:me.nodes)==null?void 0:q.length)||0),e.createElement("span",null,e.createElement(Dt,{name:"link"}),I("editor.importExport.edges","连线"),": ",((ue=(le=n==null?void 0:n.metadata)==null?void 0:le.connections)==null?void 0:ue.length)||0),e.createElement("span",null,e.createElement(Dt,{name:"data"}),I("editor.importExport.size","大小"),": ",(D.length/1024).toFixed(1)," KB")),e.createElement("pre",{className:"rge-ie-preview"},D)):e.createElement(e.Fragment,null,e.createElement("div",{className:`rge-ie-dropzone ${O?"dragover":""} ${g?"has-file":""}`,onDragOver:b=>{b.preventDefault(),U(!0)},onDragLeave:()=>U(!1),onDrop:Z,onClick:()=>{var b;return(b=C.current)==null?void 0:b.click()}},e.createElement("input",{ref:C,type:"file",accept:".json",style:{display:"none"},onChange:u}),g?e.createElement("span",{className:"rge-ie-file-name"},e.createElement(Dt,{name:"validate"}),I("editor.importExport.fileLoaded","文件已加载,点击重新选择")):e.createElement(e.Fragment,null,e.createElement(Dt,{name:"import",className:"rge-ie-drop-icon"}),e.createElement("span",{className:"rge-ie-drop-text"},I("editor.importExport.dropHint","拖拽 JSON 文件到此处,或点击选择文件")))),F&&e.createElement("div",{className:"rge-ie-error",role:"alert"},F),y&&e.createElement("div",{className:"rge-ie-import-info"},e.createElement("div",{className:"rge-ie-info"},e.createElement("span",null,e.createElement(Dt,{name:"package"}),I("editor.importExport.nodes","节点"),": ",((ge=(W=y==null?void 0:y.metadata)==null?void 0:W.nodes)==null?void 0:ge.length)||0),e.createElement("span",null,e.createElement(Dt,{name:"link"}),I("editor.importExport.edges","连线"),": ",((Me=(Pe=y==null?void 0:y.metadata)==null?void 0:Pe.connections)==null?void 0:Me.length)||0),e.createElement("span",null,e.createElement(Dt,{name:"edit"}),I("editor.importExport.name","名称"),": ",((X=y==null?void 0:y.ruleChain)==null?void 0:X.name)||I("editor.status.unknown","未知"))),e.createElement("pre",{className:"rge-ie-preview",style:{maxHeight:200}},JSON.stringify(y,null,2))))),e.createElement("div",{className:"rge-modal-footer"},e.createElement("button",{type:"button",className:"rge-btn secondary",onClick:s},I("editor.panel.cancel","取消")),N==="export"?e.createElement(e.Fragment,null,e.createElement("button",{type:"button",className:"rge-btn secondary",onClick:ee},e.createElement(Dt,{name:"copy"}),e.createElement("span",null,I("editor.panel.copy","复制"))),e.createElement("button",{type:"button",className:"rge-btn primary",onClick:H},e.createElement(Dt,{name:"export"}),e.createElement("span",null,I("editor.importExport.downloadFile","下载文件")))):e.createElement("button",{type:"button",className:"rge-btn primary",onClick:V,disabled:!y},e.createElement(Dt,{name:"import"}),e.createElement("span",null,I("editor.importExport.confirmImport","确认导入"))))))};function ea(t,n){if(!n)return t;const r=t.toLowerCase(),o=n.toLowerCase(),s=r.indexOf(o);return s===-1?t:e.createElement(e.Fragment,null,t.slice(0,s),e.createElement("mark",{className:"rge-search-highlight"},t.slice(s,s+n.length)),t.slice(s+n.length))}const rl=({nodes:t,onSelectNode:n,onClose:r,position:o="top-center",locale:s,messages:i,t:m})=>{const[f,M]=e.useState(""),[N,P]=e.useState(0),g=e.useRef(null),w=e.useMemo(()=>Ze({locale:s,messages:i,t:m}),[s,i,m]);e.useEffect(()=>{var O;(O=g.current)==null||O.focus()},[]);const y=e.useMemo(()=>{if(!f.trim())return[];const O=f.toLowerCase().trim();return t.filter(U=>U.name.toLowerCase().includes(O)||U.type.toLowerCase().includes(O)||U.id.toLowerCase().includes(O)||U.typeLabel&&U.typeLabel.toLowerCase().includes(O)||U.extra&&U.extra.toLowerCase().includes(O))},[t,f]),k=e.useCallback(O=>{switch(O.key){case"ArrowDown":O.preventDefault(),P(U=>Math.min(U+1,y.length-1));break;case"ArrowUp":O.preventDefault(),P(U=>Math.max(U-1,0));break;case"Enter":O.preventDefault(),y[N]&&(n==null||n(y[N].id));break;case"Escape":O.preventDefault(),r();break}},[y,N,n,r]),F=e.useCallback(O=>{M(O.target.value),P(0)},[]),j=e.useCallback(O=>{n==null||n(O)},[n]);return e.createElement("div",{className:`rge-search-panel ${o}`},e.createElement("div",{className:"rge-search-input-wrapper"},e.createElement("span",{className:"rge-search-icon","aria-hidden":"true"}),e.createElement("input",{ref:g,type:"text",className:"rge-search-input",placeholder:w("editor.searchPanel.placeholder","搜索节点名称、类型或 ID..."),value:f,onChange:F,onKeyDown:k}),f&&e.createElement("span",{className:"rge-search-count"},w("editor.searchPanel.resultCount","{{count}} 个结果",{count:y.length})),e.createElement("button",{className:"rge-search-close",onClick:r},"✕")),f&&y.length>0&&e.createElement("div",{className:"rge-search-results"},y.map((O,U)=>e.createElement("div",{key:O.id,className:`rge-search-result-item ${U===N?"active":""}`,onClick:()=>j(O.id),onMouseEnter:()=>P(U)},e.createElement("div",{className:"rge-search-result-main"},e.createElement("span",{className:"rge-search-result-name"},ea(O.name,f)),e.createElement("span",{className:"rge-search-result-type"},O.typeLabel||O.type)),e.createElement("div",{className:"rge-search-result-id"},"ID: ",ea(O.id,f))))),f&&y.length===0&&e.createElement("div",{className:"rge-search-empty"},e.createElement("span",{className:"rge-search-icon","aria-hidden":"true"}),w("editor.searchPanel.empty","没有找到匹配的节点")))},al={design:"edit",info:"docs",start:"play",stop:"stop",copy:"copy",delete:"delete",search:"search",refresh:"refresh",add:"add",workflow:"arrange",subWorkflow:"link",logs:"data"},ol=/[\\/.]/,ir=180,ur=260,Ln=12,ta=new WeakMap;let ll=1;const Zn=t=>{const n=ta.get(t);if(n!==void 0)return n;const r=ll++;return ta.set(t,r),r},kn=(t,n=new WeakSet)=>{if(typeof t=="function")return`[reference:${Zn(t)}]`;if(!t||typeof t!="object")return t;if(n.has(t))return`[circular:${Zn(t)}]`;if(n.add(t),Array.isArray(t))return t.map(o=>kn(o,n));const r=t;return Object.keys(r).sort().reduce((o,s)=>(o[s]=kn(r[s],n),o),{})},yr=t=>t===void 0?"[default]":JSON.stringify(t),sl=t=>{if(!t)return"-";const n=new Date(t);if(Number.isNaN(n.getTime()))return t;const r=o=>String(o).padStart(2,"0");return`${n.getFullYear()}/${r(n.getMonth()+1)}/${r(n.getDate())} ${r(n.getHours())}:${r(n.getMinutes())}:${r(n.getSeconds())}`},cl=(t,n)=>{var o;const r=(o=t.additionalInfo)==null?void 0:o[n];return typeof r=="string"?r:""},il=(t,n,r)=>{if(!t)return"";const o=n||{};return JSON.stringify({apiBase:t,apiContextKey:yr(r),timeout:o.timeout,authToken:o.authToken,headers:kn(o.headers),credentials:o.credentials,customFetch:kn(o.customFetch),onAuthRequired:kn(o.onAuthRequired),serverStatus:o.serverStatus?`[reference:${Zn(o.serverStatus)}]`:void 0,includeStoredToken:o.includeStoredToken,routes:kn(o.routes)})},ul=t=>{const{apiBase:n,apiOptions:r,apiContextKey:o,fetcher:s,pageSize:i=10,layout:m="grid",autoOpenAfterCreate:f,theme:M="light",className:N="",style:P,icons:g,showSearch:w=!0,showCreate:y=!0,showRefresh:k=!0,disabled:F=!1,disabledMessage:j,locale:O,messages:U,t:C,renderHeader:I,renderActions:D,renderEmpty:_,renderCreateForm:u,renderRow:Z,onDesign:ee,onInfo:H,onViewLogs:V,onChange:me,onError:q,onCreateSuccess:le}=t,ue={...al,...g},W=e.useMemo(()=>Ze({locale:O,messages:U,t:C}),[O,U,C]),ge=e.useRef(null),Pe=e.useRef(""),Me=il(n,r,o),X=s?`external:${Zn(s)}`:"";s?(ge.current!==s||Pe.current!==X)&&(ge.current=s,Pe.current=X):n?(!ge.current||Pe.current!==Me)&&(ge.current=new v.RuleChainAPI({apiBase:n,...r}),Pe.current=Me):ge.current&&(ge.current=null,Pe.current="");const b=ge.current,$=s?`${X}|context:${yr(o)}`:n?`internal:${Me}`:`none:${yr(o)}`,Y=e.useRef({api:null,identity:"",disabled:!1,generation:0});(Y.current.api!==b||Y.current.identity!==$||Y.current.disabled!==F)&&(Y.current={api:b,identity:$,disabled:F,generation:Y.current.generation+1});const te=e.useRef(!1),L=e.useRef(0),ke=e.useRef(0),[we,ne]=e.useState([]),[he,xe]=e.useState(0),[Ee,Le]=e.useState(1),Se=i,[se,ae]=e.useState(""),[Ne,_e]=e.useState(!1),[J,Ae]=e.useState(!1),[tt,z]=e.useState(""),[Ye,ht]=e.useState(null),[mt,Vt]=e.useState(null),[Bt,jt]=e.useState(()=>v.RuleChainAPI.generateChainId()),[Pt,Nt]=e.useState(""),[lt,vt]=e.useState(""),[xt,Lt]=e.useState(!0),[Tt,Ke]=e.useState(!1),[Rt,At]=e.useState(!0),[Mt,Ot]=e.useState(""),[Ct,Te]=e.useState(()=>f??!!ee),[qt,gt]=e.useState(""),[je,nt]=e.useState(null),[Re,re]=e.useState(null),fe=Re===Y.current.generation,Ce=fe?we:[],ye=fe?he:0,De=e.useRef({page:Ee,keywords:se,onError:q});De.current={page:Ee,keywords:se,onError:q};const qe=e.useRef({onChange:me,onError:q,onCreateSuccess:le,onDesign:ee});qe.current={onChange:me,onError:q,onCreateSuccess:le,onDesign:ee};const d=e.useCallback(B=>te.current&&Y.current===B,[]),ie=e.useCallback((B,be)=>d(B)&&ke.current===be,[d]);e.useEffect(()=>(te.current=!0,()=>{te.current=!1,L.current+=1,ke.current+=1}),[]),e.useEffect(()=>{ke.current+=1,nt(null)},[$,F]);const Fe=e.useCallback(()=>{ht(null),Vt(null)},[]);e.useEffect(()=>{z(""),Le(1),Fe(),Ae(!1),gt("")},[$,F,Fe]);const ft=e.useCallback((B,be)=>{if(B.stopPropagation(),Ye===be){Fe();return}const ve=B.currentTarget.getBoundingClientRect(),Ve=window.innerWidth||document.documentElement.clientWidth||ir,Qe=window.innerHeight||document.documentElement.clientHeight||ur,ct=Math.max(Ln,Ve-ir-Ln),et=Math.min(Math.max(Ln,ve.right-ir),ct);let at=ve.bottom+8;at+ur>Qe-Ln&&(at=Math.max(Ln,ve.top-ur-8)),ht(be),Vt({id:be,top:at,left:et})},[Fe,Ye]);e.useEffect(()=>{if(!Ye)return;const B=ve=>{var Qe;const Ve=ve.target;(Qe=Ve==null?void 0:Ve.closest)!=null&&Qe.call(Ve,".huanban_rulego_list__actions--floating, .huanban_rulego_list__row_more")||Fe()},be=ve=>{ve.key==="Escape"&&Fe()};return document.addEventListener("pointerdown",B),document.addEventListener("keydown",be),window.addEventListener("resize",Fe),window.addEventListener("scroll",Fe,!0),()=>{document.removeEventListener("pointerdown",B),document.removeEventListener("keydown",be),window.removeEventListener("resize",Fe),window.removeEventListener("scroll",Fe,!0)}},[Fe,Ye]);const h=e.useCallback(()=>{jt(v.RuleChainAPI.generateChainId()),Nt(""),vt(""),Lt(!0),Ke(!1),At(!0),Ot(""),Te(f??!!ee),gt("")},[f,ee]),S=e.useCallback(()=>{h(),Ae(!0)},[h]),K=e.useCallback(()=>{Ae(!1),gt("")},[]),A=e.useCallback(async(B,be)=>{var at,St;const ve=Y.current,Ve=ve.api,{page:Qe,keywords:ct}=De.current;if(!Ve||ve.disabled){d(ve)&&_e(!1);return}const et=++L.current;_e(!0);try{const dt=await Ve.list(B??Qe,Se,be??ct);if(!d(ve)||L.current!==et)return;ne(dt.items),xe(dt.total),re(ve.generation)}catch(dt){if(!d(ve)||L.current!==et)return;(St=(at=De.current).onError)==null||St.call(at,dt instanceof Error?dt:new Error(String(dt)))}finally{d(ve)&&L.current===et&&_e(!1)}},[d,Se]);e.useEffect(()=>{if(F){L.current+=1,_e(!1);return}A(1)},[$,F,A]);const oe=e.useCallback(()=>{Le(1),A(1,se),Fe()},[Fe,se,A]),Oe=e.useCallback(B=>{B.key==="Enter"&&oe()},[oe]),rt=Math.max(1,Math.ceil(ye/Se)),Xe=e.useCallback(()=>{Ee>1&&(Le(Ee-1),A(Ee-1))},[Ee,A]),wt=e.useCallback(()=>{Ee<rt&&(Le(Ee+1),A(Ee+1))},[Ee,rt,A]),Ht=e.useCallback(async(B,be)=>{var ct,et,at,St,dt,pt;const ve=Y.current,Ve=ve.api;if(!Ve||ve.disabled)return;const Qe=++ke.current;nt(B);try{const Je=await Ve.operate(B,be);if(!ie(ve,Qe))return;if(!Je.success){(et=(ct=qe.current).onError)==null||et.call(ct,new Error(Je.msg||W("editor.workflowList.operateFailed","操作失败")));return}if(Fe(),await A(),!ie(ve,Qe))return;(St=(at=qe.current).onChange)==null||St.call(at)}catch(Je){ie(ve,Qe)&&((pt=(dt=qe.current).onError)==null||pt.call(dt,Je instanceof Error?Je:new Error(String(Je))))}finally{ie(ve,Qe)&&nt(null)}},[Fe,ie,A,W]),He=e.useCallback(async B=>{var Qe,ct,et,at,St,dt;const be=Y.current,ve=be.api;if(!ve||be.disabled)return;const Ve=++ke.current;nt(B);try{const pt=await ve.copy(B);if(!ie(be,Ve))return;if(!pt.success){(ct=(Qe=qe.current).onError)==null||ct.call(Qe,new Error(pt.msg||W("editor.workflowList.copyFailed","复制失败")));return}if(Fe(),await A(),!ie(be,Ve))return;(at=(et=qe.current).onChange)==null||at.call(et)}catch(pt){ie(be,Ve)&&((dt=(St=qe.current).onError)==null||dt.call(St,pt instanceof Error?pt:new Error(String(pt))))}finally{ie(be,Ve)&&nt(null)}},[Fe,ie,A,W]),ut=e.useCallback(async(B,be)=>{var ct,et,at,St,dt,pt;if(!window.confirm(W("editor.workflowList.confirmDelete","确定删除工作流「{{name}}」吗?此操作不可恢复。",{name:be})))return;const ve=Y.current,Ve=ve.api;if(!Ve||ve.disabled)return;const Qe=++ke.current;nt(B);try{const Je=await Ve.remove(B);if(!ie(ve,Qe))return;if(!Je.success){(et=(ct=qe.current).onError)==null||et.call(ct,new Error(Je.msg||W("editor.workflowList.deleteFailed","删除失败")));return}if(Fe(),await A(),!ie(ve,Qe))return;(St=(at=qe.current).onChange)==null||St.call(at)}catch(Je){ie(ve,Qe)&&((pt=(dt=qe.current).onError)==null||pt.call(dt,Je instanceof Error?Je:new Error(String(Je))))}finally{ie(ve,Qe)&&nt(null)}},[Fe,ie,A,W]),st=e.useCallback(async B=>{var at,St,dt,pt,Je,Et,Sn,It;const be=Y.current,ve=be.api;if(!ve||be.disabled)return;const Ve=++ke.current,Qe=Bt.trim();if(!B){if(!Qe||ol.test(Qe)){gt(W("editor.workflowList.idInvalid","ID 不能为空,且不能包含 /、\\ 或 ."));return}gt("")}const ct=new Date().toISOString(),et=B||{ruleChain:{id:Qe,name:Pt.trim()||W("editor.workflowList.defaultName","新工作流"),root:xt,disabled:Rt,debugMode:Tt,additionalInfo:{description:lt.trim(),category:Mt.trim(),createTime:ct,updateTime:ct,debugMode:Tt}},metadata:{firstNodeIndex:0,nodes:[],connections:[],endpoints:[]}};try{const kt=await ve.create(et);if(!ie(be,Ve))return;if(!kt.success){(St=(at=qe.current).onError)==null||St.call(at,new Error(kt.msg||W("editor.workflowList.createFailed","创建失败")));return}if(Ae(!1),h(),await A(),!ie(be,Ve))return;(pt=(dt=qe.current).onChange)==null||pt.call(dt);const dn=et.ruleChain,Gt=String((dn==null?void 0:dn.id)??"");Gt&&((Et=(Je=qe.current).onCreateSuccess)==null||Et.call(Je,Gt)),Gt&&Ct&&qe.current.onDesign&&qe.current.onDesign(Gt)}catch(kt){ie(be,Ve)&&((It=(Sn=qe.current).onError)==null||It.call(Sn,kt instanceof Error?kt:new Error(String(kt))))}},[Bt,Pt,lt,xt,Rt,Tt,Mt,A,Ct,h,d,ie,W]),Ft=e.useCallback(B=>{z(B.id),Fe(),H==null||H(B)},[Fe,H]),Ue=e.useCallback((B,be)=>{if(B.key==="Enter"){B.preventDefault(),ee&&ee(be.id);return}B.key===" "&&(B.preventDefault(),Ft(be))},[Ft,ee]),ln=B=>{const be=je===B.id;return e.createElement(e.Fragment,null,ee&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--design",disabled:be,onClick:ve=>{ve.stopPropagation(),Fe(),ee(B.id)},title:W("editor.workflowList.design","设计")},e.createElement(pe,{value:ue.design})," ",e.createElement("span",null,W("editor.workflowList.design","设计"))),H&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--info",disabled:be,onClick:ve=>{ve.stopPropagation(),Ft(B)},title:W("editor.workflowList.info","信息")},e.createElement(pe,{value:ue.info})," ",e.createElement("span",null,W("editor.workflowList.info","信息"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--operate",disabled:be,onClick:ve=>{ve.stopPropagation(),Ht(B.id,B.deployed?"stop":"start")},title:B.deployed?W("editor.workflowList.offlineAction","下线"):W("editor.workflowList.onlineAction","部署")},e.createElement(pe,{value:B.deployed?ue.stop:ue.start}),e.createElement("span",null,B.deployed?W("editor.workflowList.offlineAction","下线"):W("editor.workflowList.onlineAction","部署"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--copy",disabled:be,onClick:ve=>{ve.stopPropagation(),He(B.id)},title:W("editor.panel.copy","复制")},e.createElement(pe,{value:ue.copy})," ",e.createElement("span",null,W("editor.panel.copy","复制"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--delete",disabled:be,onClick:ve=>{ve.stopPropagation(),ut(B.id,B.name)},title:W("editor.panel.delete","删除")},e.createElement(pe,{value:ue.delete})," ",e.createElement("span",null,W("editor.panel.delete","删除"))),V&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--logs",disabled:be,onClick:ve=>{ve.stopPropagation(),Fe(),V(B.id,B)},title:W("editor.workflowList.logs","日志")},e.createElement(pe,{value:ue.logs})," ",e.createElement("span",null,W("editor.workflowList.logs","日志"))))},nn=(B,be="huanban_rulego_list__actions")=>e.createElement("div",{className:be},ln(B)),An=(B,be)=>{const ve=nn(B),Ve=D?D(B,ve):ve,Qe=tt===B.id,ct=B.deployed?W("editor.workflowList.online","运行"):W("editor.workflowList.offline","停用"),et=cl(B,"category");return e.createElement("article",{className:`huanban_rulego_list__row ${B.deployed?"huanban_rulego_list__row--deployed":"huanban_rulego_list__row--offline"} ${Qe?"huanban_rulego_list__row--selected":""}`,key:B.id,"data-id":B.id,role:"button",tabIndex:0,title:W("editor.workflowList.rowHint","单击查看信息,双击进入设计"),onClick:()=>Ft(B),onDoubleClick:()=>ee==null?void 0:ee(B.id),onKeyDown:at=>Ue(at,B)},e.createElement("div",{className:"huanban_rulego_list__row_main"},e.createElement("span",{className:`huanban_rulego_list__row_icon ${B.root?"huanban_rulego_list__row_icon--root":"huanban_rulego_list__row_icon--sub"}`},e.createElement(pe,{value:B.root?ue.workflow:ue.subWorkflow})),e.createElement("div",{className:"huanban_rulego_list__row_info"},e.createElement("span",{className:"huanban_rulego_list__row_name"},B.name),e.createElement("span",{className:"huanban_rulego_list__row_id"},B.id),(et||B.root)&&e.createElement("span",{className:"huanban_rulego_list__row_meta"},B.root?W("editor.workflowList.rootChain","主链"):W("editor.workflowList.subChain","子链"),et?` · ${et}`:"")),e.createElement("div",{className:`huanban_rulego_list__row_menu ${Ye===B.id?"huanban_rulego_list__row_menu--open":""}`},e.createElement("button",{className:"huanban_rulego_list__row_more",type:"button",title:W("editor.workflowList.more","更多操作"),onClick:at=>{ft(at,B.id)}},"•••"),m==="list"?Ve:null)),B.description&&e.createElement("div",{className:"huanban_rulego_list__row_desc"},B.description),e.createElement("div",{className:"huanban_rulego_list__row_footer"},e.createElement("span",{className:"huanban_rulego_list__row_time"},W("editor.workflowList.updateTime","更新时间"),": ",sl(B.updateTime||B.createTime)),e.createElement("span",{className:`huanban_rulego_list__row_status ${B.deployed?"huanban_rulego_list__row_status--on":"huanban_rulego_list__row_status--off"}`},ct)))},sn=e.createElement("div",{className:"huanban_rulego_list__header"},e.createElement("h3",{className:"huanban_rulego_list__title"},e.createElement(pe,{value:ue.workflow})," ",W("editor.workflowList.title","工作流列表"),e.createElement("span",{className:"huanban_rulego_list__count"},"(",ye,")")),e.createElement("div",{className:"huanban_rulego_list__toolbar"},w&&e.createElement("div",{className:"huanban_rulego_list__search"},e.createElement("input",{className:"huanban_rulego_list__search_input",type:"text",placeholder:W("editor.workflowList.searchPlaceholder","搜索工作流..."),value:se,onChange:B=>ae(B.target.value),onKeyDown:Oe}),e.createElement("button",{className:"huanban_rulego_list__search_btn",onClick:oe,title:W("editor.toolbar.searchNode","搜索")},e.createElement(pe,{value:ue.search}))),k&&e.createElement("button",{className:"huanban_rulego_list__toolbar_btn",onClick:()=>A(),title:W("editor.chainSelector.refresh","刷新"),disabled:Ne||F},e.createElement(pe,{value:ue.refresh})),y&&e.createElement("button",{className:"huanban_rulego_list__toolbar_btn huanban_rulego_list__toolbar_btn--primary",onClick:S,title:W("editor.workflowList.createTitle","新建工作流"),disabled:F},e.createElement(pe,{value:ue.add})," ",W("editor.workflowList.create","新建")))),On=e.createElement("div",{className:"huanban_rulego_list__form"},e.createElement("div",{className:"huanban_rulego_list__form_grid"},e.createElement("label",{className:"huanban_rulego_list__form_label"},W("editor.workflowList.id","ID"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:Bt,onChange:B=>{jt(B.target.value),gt("")},placeholder:W("editor.workflowList.idPlaceholder","规则链 ID,不可包含 /、\\ 或 ."),autoFocus:!0})),e.createElement("label",{className:"huanban_rulego_list__form_label"},W("editor.panel.name","名称"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:Pt,onChange:B=>Nt(B.target.value),placeholder:W("editor.workflowList.namePlaceholder","输入工作流名称")}))),e.createElement("div",{className:"huanban_rulego_list__form_group"},e.createElement("span",{className:"huanban_rulego_list__form_group_label"},W("editor.workflowList.chainType","规则链类型")),e.createElement("div",{className:"huanban_rulego_list__segmented",role:"group"},e.createElement("button",{type:"button",className:xt?"active":"",onClick:()=>Lt(!0)},W("editor.workflowList.rootChain","主链")),e.createElement("button",{type:"button",className:xt?"":"active",onClick:()=>Lt(!1)},W("editor.workflowList.subChain","子链")))),e.createElement("div",{className:"huanban_rulego_list__form_group"},e.createElement("span",{className:"huanban_rulego_list__form_group_label"},W("editor.workflowList.initialStatus","初始状态")),e.createElement("div",{className:"huanban_rulego_list__segmented",role:"group"},e.createElement("button",{type:"button",className:Rt?"active":"",onClick:()=>At(!0)},W("editor.workflowList.initialStopped","停用")),e.createElement("button",{type:"button",className:Rt?"":"active",onClick:()=>At(!1)},W("editor.workflowList.initialRunning","运行")))),e.createElement("label",{className:"huanban_rulego_list__form_switch",title:W("editor.workflowList.debugModeHint","开启后每条消息都会记录调试日志,并覆盖节点调试配置;会影响运行性能,生产环境建议关闭。编辑器手动调试不受影响。")},e.createElement("input",{type:"checkbox",checked:Tt,onChange:B=>Ke(B.target.checked)}),e.createElement("span",null,W("editor.workflowList.debugMode","调试模式"))),e.createElement("label",{className:"huanban_rulego_list__form_label"},W("editor.workflowList.category","分类"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:Mt,onChange:B=>Ot(B.target.value),placeholder:W("editor.workflowList.categoryPlaceholder","可选分类,如 IoT / AI / 数据同步")})),e.createElement("label",{className:"huanban_rulego_list__form_label"},W("editor.panel.description","描述"),e.createElement("textarea",{className:"huanban_rulego_list__form_textarea",value:lt,onChange:B=>vt(B.target.value),placeholder:W("editor.workflowList.descriptionPlaceholder","可选描述"),rows:3})),ee&&e.createElement("label",{className:"huanban_rulego_list__form_switch"},e.createElement("input",{type:"checkbox",checked:Ct,onChange:B=>Te(B.target.checked)}),e.createElement("span",null,W("editor.workflowList.openAfterCreate","创建后进入编辑器"))),qt&&e.createElement("div",{className:"huanban_rulego_list__form_error"},qt)),Fn=e.createElement("div",{className:"huanban_rulego_list__empty"},e.createElement("span",{className:"huanban_rulego_list__empty_icon"},e.createElement(pe,{value:ue.workflow})),e.createElement("p",null,W("editor.workflowList.empty","暂无工作流")),y&&e.createElement("button",{className:"huanban_rulego_list__empty_btn",onClick:S},e.createElement(pe,{value:ue.add})," ",W("editor.workflowList.createFirst","创建第一个工作流"))),Wt=v.normalizeEditorTheme(M),cn=Wt!=="default"?`huanban_rulego_list--${Wt}`:"",un=v.getThemeRuntimeVariables(Wt),mn=Ye?Ce.find(B=>B.id===Ye):void 0,Be=m==="grid"&&mt&&mn&&typeof document<"u"?ca.createPortal(D?e.createElement("div",{className:"huanban_rulego_list__actions huanban_rulego_list__actions--floating",style:{...un,top:mt.top,left:mt.left},onClick:B=>B.stopPropagation(),onPointerDown:B=>B.stopPropagation()},D(mn,nn(mn))):e.createElement("div",{className:"huanban_rulego_list__actions huanban_rulego_list__actions--floating",style:{...un,top:mt.top,left:mt.left},onClick:B=>B.stopPropagation(),onPointerDown:B=>B.stopPropagation()},ln(mn)),document.body):null;return e.createElement("div",{className:`huanban_rulego_list huanban_rulego_list--layout-${m} ${cn} ${N}`.trim(),"data-theme":Wt,"data-rg-theme":Wt,style:{...un,...P}},I?I(sn):sn,e.createElement("div",{className:"huanban_rulego_list__body"},F&&e.createElement("div",{className:"huanban_rulego_list__empty"},e.createElement("span",{className:"huanban_rulego_list__empty_icon"},e.createElement(pe,{value:ue.workflow})),e.createElement("p",null,j||W("editor.workflowList.loginRequired","请先登录后查看工作流。"))),!F&&Ne&&e.createElement("div",{className:"huanban_rulego_list__loading"},e.createElement("span",{className:"huanban_rulego_list__spinner"}),W("editor.panel.loading","加载中...")),!F&&!Ne&&Ce.length===0&&(_?_():Fn),!F&&!Ne&&Ce.length>0&&e.createElement("div",{className:`huanban_rulego_list__rows huanban_rulego_list__rows--${m}`},Ce.map((B,be)=>{const ve=An(B);return Z?e.createElement(e.Fragment,{key:B.id},Z(B,be,ve)):e.createElement(e.Fragment,{key:B.id},ve)}))),Be,!F&&ye>Se&&e.createElement("div",{className:"huanban_rulego_list__pagination"},e.createElement("button",{className:"huanban_rulego_list__page_btn",disabled:Ee<=1,onClick:Xe},W("editor.chainSelector.prevPage","上一页")),e.createElement("span",{className:"huanban_rulego_list__page_info"},Ee," / ",rt),e.createElement("button",{className:"huanban_rulego_list__page_btn",disabled:Ee>=rt,onClick:wt},W("editor.chainSelector.nextPage","下一页"))),J&&e.createElement("div",{className:"huanban_rulego_list__modal_mask",onClick:K},e.createElement("div",{className:"huanban_rulego_list__modal",onClick:B=>B.stopPropagation()},e.createElement("div",{className:"huanban_rulego_list__modal_header"},e.createElement("h4",null,W("editor.workflowList.createTitle","新建工作流")),e.createElement("button",{className:"huanban_rulego_list__modal_close",onClick:K},"✕")),e.createElement("div",{className:"huanban_rulego_list__modal_body"},u?u(On,{close:K,submit:B=>st(B)}):On),e.createElement("div",{className:"huanban_rulego_list__modal_footer"},e.createElement("button",{className:"huanban_rulego_list__btn huanban_rulego_list__btn--cancel",onClick:K},W("editor.panel.cancel","取消")),e.createElement("button",{className:"huanban_rulego_list__btn huanban_rulego_list__btn--primary",onClick:()=>st()},Ct&&ee?W("editor.workflowList.createAndOpen","创建并打开"):W("editor.workflowList.create","创建"))))))},ml=28;function Sa(t,n,r=0){const o=[];return t.forEach(s=>{var i;o.push({node:s,depth:r}),(i=s.children)!=null&&i.length&&n.has(s.key)&&o.push(...Sa(s.children,n,r+1))}),o}function dl({workflows:t,store:n,persistence:r,activeChainId:o="",keyword:s,placeholder:i="搜索规则链",emptyText:m="暂无规则链",className:f="",style:M,onKeywordChange:N,onOpen:P,virtualization:g}){const w=e.useMemo(()=>n?null:new v.ExplorerTreeStore({persistence:r,workflows:t,activeChainId:o,keyword:s}),[n,r==null?void 0:r.adapter,r==null?void 0:r.namespace.host,r==null?void 0:r.namespace.editorInstance,r==null?void 0:r.namespace.version]),y=n||w,[k,F]=e.useState(()=>y.getState()),[j,O]=e.useState(s||""),[U,C]=e.useState(0),I=e.useRef(null);e.useEffect(()=>y.subscribe(F),[y]),e.useEffect(()=>()=>{w==null||w.destroy()},[w]),e.useEffect(()=>{y.setWorkflows(t)},[y,t]),e.useEffect(()=>{y.setActiveChainId(o)},[y,o]),e.useEffect(()=>{s===void 0||s===j||(O(s),y.setKeyword(s))},[s,j,y]);const D=e.useMemo(()=>Sa(k.tree,new Set(k.expandedKeys)),[k.tree,k.expandedKeys]),_=e.useMemo(()=>({enabled:(g==null?void 0:g.enabled)!==!1,threshold:Math.max(1,(g==null?void 0:g.threshold)??v.DEFAULT_VIRTUAL_WINDOW_THRESHOLD),itemHeight:Math.max(1,(g==null?void 0:g.itemHeight)??ml),viewportHeight:Math.max(1,(g==null?void 0:g.viewportHeight)??v.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),overscan:Math.max(0,(g==null?void 0:g.overscan)??v.DEFAULT_VIRTUAL_WINDOW_OVERSCAN)}),[g==null?void 0:g.enabled,g==null?void 0:g.threshold,g==null?void 0:g.itemHeight,g==null?void 0:g.viewportHeight,g==null?void 0:g.overscan]),u=_.enabled&&D.length>_.threshold,Z=e.useMemo(()=>v.calculateVirtualWindow({total:D.length,itemHeight:_.itemHeight,viewportHeight:_.viewportHeight,scrollTop:U,overscan:_.overscan}),[D.length,_,U]),ee=u?D.slice(Z.start,Z.end):D,H=e.useMemo(()=>D.findIndex(q=>{var le;return q.node.kind==="chain"&&((le=q.node.chain)==null?void 0:le.id)===o}),[D,o]);e.useEffect(()=>{if(!u||H<0)return;const q=Math.floor(U/_.itemHeight),le=Math.ceil((U+_.viewportHeight)/_.itemHeight);let ue=U;H<q?ue=H*_.itemHeight:H>=le&&(ue=(H+1)*_.itemHeight-_.viewportHeight),ue!==U&&C(ue)},[o,H,u,D,_.itemHeight,_.viewportHeight]),e.useEffect(()=>{const q=I.current;if(!q)return;const le=u?Z.scrollTop:0;q.scrollTop!==le&&(q.scrollTop=le)},[u,Z.scrollTop]);const V=q=>{O(q),y.setKeyword(q),N==null||N(q)},me=({node:q,depth:le},ue)=>{var Me,X;const W=!!((Me=q.children)!=null&&Me.length),ge=k.expandedKeys.includes(q.key),Pe=q.kind==="chain"&&((X=q.chain)==null?void 0:X.id)===o;return e.createElement("button",{key:q.key,type:"button",role:"treeitem","aria-level":le+1,"aria-posinset":ue+1,"aria-setsize":D.length,"aria-expanded":W?ge:void 0,"aria-selected":q.kind==="chain"?Pe:void 0,className:`huanban_workflow_explorer__row is-${q.kind}${Pe?" is-active":""}`,style:{paddingInlineStart:8+le*14},onClick:()=>{W?y.setExpanded(q.key,!ge):q.chain&&(P==null||P(q.chain))},title:q.chain?`${q.chain.name}
8
- ${q.chain.id}`:q.label},e.createElement("span",{className:`huanban_workflow_explorer__chevron${W&&ge?" is-open":""}`,"aria-hidden":"true"}),e.createElement("span",{className:`huanban_workflow_explorer__kind is-${q.kind}`,"aria-hidden":"true"}),e.createElement("span",{className:"huanban_workflow_explorer__label"},q.label),q.kind==="chain"&&q.chain?e.createElement("span",{className:`huanban_workflow_explorer__status${q.chain.disabled?" is-offline":" is-online"}`,title:q.chain.disabled?"已下线":"运行中"}):null,q.count!==void 0?e.createElement("span",{className:"huanban_workflow_explorer__count"},q.count):null)};return e.createElement("section",{className:`huanban_workflow_explorer ${f}`.trim(),style:M,"aria-label":"规则链资源"},e.createElement("div",{className:"huanban_workflow_explorer__search"},e.createElement("span",{"aria-hidden":"true",className:"huanban_workflow_explorer__search_icon"}),e.createElement("input",{value:j,onChange:q=>V(q.target.value),placeholder:i,"aria-label":i}),j?e.createElement("button",{type:"button",className:"huanban_workflow_explorer__clear",onClick:()=>V(""),title:"清除搜索","aria-label":"清除搜索"},"×"):null),e.createElement("div",{ref:I,className:`huanban_workflow_explorer__tree${u?" is-virtualized":""}`,role:"tree","data-explorer-virtualized":u?"true":void 0,"data-explorer-virtual-total":u?D.length:void 0,style:u?{height:`${Z.viewportHeight}px`}:void 0,onScroll:q=>{if(!u)return;const le=q.currentTarget.scrollTop;C(ue=>ue===le?ue:le)}},D.length===0?e.createElement("div",{className:"huanban_workflow_explorer__empty"},m):u?e.createElement("div",{className:"huanban_workflow_explorer__virtual-canvas",style:{height:`${Z.totalHeight}px`}},e.createElement("div",{className:"huanban_workflow_explorer__virtual-items",style:{transform:`translateY(${Z.offsetTop}px)`}},ee.map((q,le)=>me(q,Z.start+le)))):D.map(me)))}function Jn(t,n){return!t||t.length===0?e.createElement("div",{className:"huanban_rulego_info__maintenance_empty"},n("editor.maintenance.noIssues","未返回问题")):e.createElement("ul",{className:"huanban_rulego_info__maintenance_issues"},t.map(r=>e.createElement("li",{key:`${r.id}:${r.path||r.nodeId||""}`,className:`huanban_rulego_info__maintenance_issue huanban_rulego_info__maintenance_issue--${r.severity}`},e.createElement("strong",null,r.severity),e.createElement("span",null,r.message),r.path&&e.createElement("code",null,r.path),r.suggestion&&e.createElement("small",null,r.suggestion))))}const xa=({workflow:t,fetcher:n,content:r,onError:o,locale:s,messages:i,t:m})=>{const[f,M]=e.useState(null),[N,P]=e.useState(null),[g,w]=e.useState(null),[y,k]=e.useState(null),[F,j]=e.useState(null),[O,U]=e.useState(null),C=e.useMemo(()=>r||{ruleChain:{id:t.id,name:t.name}},[r,t.id,t.name]),I=!!(n!=null&&n.validateUpstream&&(n!=null&&n.getSchemaDiff)&&(n!=null&&n.getRepairPlan)&&(n!=null&&n.previewPatch)),D=e.useMemo(()=>Ze({locale:s,messages:i,t:m}),[s,i,m]),_=e.useMemo(()=>({validate:D("editor.maintenance.runValidate","运行校验"),schemaDiff:D("editor.maintenance.schemaDiff","结构差异"),repairPlan:D("editor.maintenance.repairPlan","修复建议"),patchPreview:D("editor.maintenance.patchPreview","补丁预览")}),[D]),u=e.useCallback(async Z=>{if(!n||!I){P({type:"error",text:D("editor.maintenance.noApi","当前请求适配器未提供维护接口")});return}M(Z),P({type:"info",text:`${_[Z]}...`});try{switch(Z){case"validate":w(await n.validateUpstream(t.id,C));break;case"schemaDiff":k(await n.getSchemaDiff(t.id));break;case"repairPlan":j(await n.getRepairPlan(t.id,C));break;case"patchPreview":{const ee=[];U(await n.previewPatch(t.id,C,ee));break}}P({type:"success",text:`${_[Z]}${D("editor.maintenance.finished","已完成")}`})}catch(ee){const H=ee instanceof Error?ee:new Error(String(ee));P({type:"error",text:`${_[Z]}${D("editor.maintenance.failed","失败")}: ${H.message}`}),o==null||o(H)}finally{M(null)}},[_,C,n,I,o,D,t.id]);return I?e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},D("editor.maintenance.title","维护验证")),e.createElement("div",{className:"huanban_rulego_info__maintenance_actions"},e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:f!==null,onClick:()=>u("validate")},f==="validate"?D("editor.maintenance.validating","校验中..."):D("editor.maintenance.runValidate","运行校验")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:f!==null,onClick:()=>u("schemaDiff")},D("editor.maintenance.schemaDiff","结构差异")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:f!==null,onClick:()=>u("repairPlan")},D("editor.maintenance.repairPlan","修复建议")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:f!==null,onClick:()=>u("patchPreview")},D("editor.maintenance.patchPreview","补丁预览"))),N&&e.createElement("div",{className:`huanban_rulego_info__maintenance_status huanban_rulego_info__maintenance_status--${N.type}`},N.text),g&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,D("editor.maintenance.validateResult","校验结果"),":",g.valid?D("editor.maintenance.valid","通过"):D("editor.maintenance.invalid","未通过")),Jn(g.issues,D)),y&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,D("editor.maintenance.schemaDiff","结构差异")),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(y.changes||[],null,2)),Jn(y.issues,D)),F&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,D("editor.maintenance.repairPlan","修复建议")),F.summary&&e.createElement("p",null,F.summary),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(F.plan||[],null,2)),Jn(F.issues,D)),O&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,D("editor.maintenance.patchPreview","补丁预览")),Jn(O.rejected,D),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(O.preview||{},null,2)))):e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},D("editor.maintenance.title","维护验证")),e.createElement("div",{className:"huanban_rulego_info__maintenance_empty"},D("editor.maintenance.noApi","当前请求适配器未提供维护接口")))},pl={variable:"package",secret:"key",api:"link",mcp:"grid",copy:"copy",delete:"delete",add:"add",save:"save"};function Ta(t){const n=(t||"/api/v1").replace(/\/+$/,"");return/^https?:\/\//i.test(n)||typeof window>"u"?n:`${window.location.origin}${n.startsWith("/")?n:`/${n}`}`}function gl(t){return Ta(t).replace(/^https:/i,"wss:").replace(/^http:/i,"ws:")}const na=new WeakMap;let fl=1;const _r=t=>{const n=na.get(t);if(n!==void 0)return n;const r=fl++;return na.set(t,r),r},Nn=(t,n=new WeakSet)=>{if(typeof t=="function")return`[reference:${_r(t)}]`;if(!t||typeof t!="object")return t;if(n.has(t))return`[circular:${_r(t)}]`;if(n.add(t),Array.isArray(t))return t.map(o=>Nn(o,n));const r=t;return Object.keys(r).sort().reduce((o,s)=>(o[s]=Nn(r[s],n),o),{})},bl=t=>t===void 0?"[default]":JSON.stringify(t),hl=(t,n,r)=>{if(!t)return"";const o=n||{};return JSON.stringify({apiBase:t,apiContextKey:bl(r),timeout:o.timeout,authToken:o.authToken,headers:Nn(o.headers),credentials:o.credentials,customFetch:Nn(o.customFetch),onAuthRequired:Nn(o.onAuthRequired),serverStatus:o.serverStatus?`[reference:${_r(o.serverStatus)}]`:void 0,includeStoredToken:o.includeStoredToken,routes:Nn(o.routes)})};function El(t,n){const r=Ta(t),o=gl(t),s=encodeURIComponent(n);return{executeUrl:`${r}/rules/${n}/execute/:msgType`,notifyUrl:`${r}/rules/${n}/notify/:msgType`,openaiUrl:`${r}/rules/${n}/v1/chat/completions`,mcpStreamableUrl:`${r}/mcp/:apiKey`,mcpGroupUrl:`${r}/mcp/:apiKey/group/:groupName`,mcpSseUrl:`${r}/mcp/${n}/sse`,debugWsUrl:`${o}/logs/ws/${s}/:clientId`,runtimeWsUrl:`${o}/logs/ws/system/:clientId?client_id=:clientId&device_id=:deviceId&client_instance_id=:clientInstanceId&profile_id=:profileId`,endpointWsHint:`${o}/huanban/ws/inbound/:endpointId/:msgType`}}function Kn(t){return t&&typeof t=="object"?t:{}}function yl(t){return t.length>0?Math.max(...t.map(n=>Number(n.order||0))):0}function _l(t,n,r,o){return v.updateSchemaRowsAtParent(t,n,s=>{const i=r+o;if(i<0||i>=s.length)return;const[m]=s.splice(r,1);if(!m)return;s.splice(i,0,m);const f=v.renumberSchemaRowOrders(s);s.splice(0,s.length,...f)})}function Ra(t){if(!t)return{type:"object",properties:{}};if(typeof t=="string")try{return Ra(JSON.parse(t))}catch{return{type:"object",properties:{}}}if(t&&typeof t=="object"&&!Array.isArray(t)){const n=t;return{type:n.type||"object",...n,properties:n.properties&&typeof n.properties=="object"&&!Array.isArray(n.properties)?n.properties:{}}}return{type:"object",properties:{}}}function ra(t,n,r){const o=Kn((n==null?void 0:n.ruleChain)??n),s=Kn(o.additionalInfo),m={...Kn(t.additionalInfo),...s,category:r.category,description:r.description,debugMode:r.debugMode,updateTime:new Date().toISOString()};return"inputSchema"in r&&(m.inputSchema=r.inputSchema),{...o,id:t.id,name:r.name||t.name,root:r.root,debugMode:r.debugMode,disabled:!!(o.disabled??t.disabled),createTime:String(o.createTime??t.createTime??""),updateTime:String(o.updateTime??t.updateTime??""),additionalInfo:m}}const aa=({entries:t,onChange:n,icons:r,keyPlaceholder:o="Key",valuePlaceholder:s="Value",valueType:i="text",actionLabel:m="操作",deleteTitle:f="删除",addLabel:M="添加",batchDeleteLabel:N="批量删除",batchDeleteConfirm:P="确定删除选中的 {{count}} 项吗?",deleteConfirm:g="确定删除“{{key}}”吗?",selectLabel:w="选择",selectedCountLabel:y="已选择 {{count}} 项",selectRowLabel:k="选择第 {{index}} 项"})=>{const[F,j]=e.useState([]),O=e.useRef(null),U=t.length>0&&F.length===t.length,C=F.length>0&&!U;e.useEffect(()=>{j(H=>v.normalizeKeyValueSelection(H,t.length))},[t.length]),e.useEffect(()=>{O.current&&(O.current.indeterminate=C)},[C]);const I=()=>n([...t,{key:"",value:""}]),D=H=>{var me;const V=g.replace("{{key}}",((me=t[H])==null?void 0:me.key)||o);typeof window<"u"&&!window.confirm(V)||(n(v.removeKeyValueEntriesAtIndexes(t,[H])),j(q=>q.filter(le=>le!==H).map(le=>le>H?le-1:le)))},_=H=>{j(V=>V.includes(H)?V.filter(me=>me!==H):v.normalizeKeyValueSelection([...V,H],t.length))},u=()=>{j(U?[]:t.map((H,V)=>V))},Z=()=>{if(!F.length)return;const H=P.replace("{{count}}",String(F.length));typeof window<"u"&&!window.confirm(H)||(n(v.removeKeyValueEntriesAtIndexes(t,F)),j([]))},ee=(H,V,me)=>{const q=[...t];q[H]={...q[H],[V]:me},n(q)};return e.createElement("div",{className:"huanban_rulego_info__kv"},e.createElement("div",{className:"huanban_rulego_info__kv_toolbar"},e.createElement("label",{className:"huanban_rulego_info__kv_select_all"},e.createElement("input",{ref:O,type:"checkbox",checked:U,disabled:!t.length,onChange:u,"aria-label":w}),e.createElement("span",null,F.length?y.replace("{{count}}",String(F.length)):w)),e.createElement("button",{className:"huanban_rulego_info__kv_batch_del",type:"button",disabled:!F.length,onClick:Z},e.createElement(pe,{value:r.delete})," ",N,F.length?` (${F.length})`:"")),t.length>0&&e.createElement("div",{className:"huanban_rulego_info__kv_row huanban_rulego_info__kv_header"},e.createElement("span",{className:"huanban_rulego_info__kv_checkbox_slot","aria-hidden":"true"}),e.createElement("span",{className:"huanban_rulego_info__kv_th"},o),e.createElement("span",{className:"huanban_rulego_info__kv_th"},s),e.createElement("span",{className:"huanban_rulego_info__kv_th huanban_rulego_info__kv_th--action"},m)),t.map((H,V)=>e.createElement("div",{className:"huanban_rulego_info__kv_row",key:V},e.createElement("input",{className:"huanban_rulego_info__kv_checkbox",type:"checkbox",checked:F.includes(V),onChange:()=>_(V),"aria-label":k.replace("{{index}}",String(V+1))}),e.createElement("input",{className:"huanban_rulego_info__kv_input",type:"text",placeholder:o,value:H.key,onChange:me=>ee(V,"key",me.target.value)}),e.createElement("input",{className:"huanban_rulego_info__kv_input",type:i,placeholder:s,value:H.value,onChange:me=>ee(V,"value",me.target.value)}),e.createElement("button",{className:"huanban_rulego_info__kv_del",onClick:()=>D(V),title:f},e.createElement(pe,{value:r.delete})))),e.createElement("button",{className:"huanban_rulego_info__kv_add",onClick:I},e.createElement(pe,{value:r.add})," ",M))},vl=t=>{var Re;const{apiBase:n,apiOptions:r,apiContextKey:o,fetcher:s,workflow:i,theme:m="light",className:f="",style:M,icons:N,defaultTab:P="base",showMaintenance:g=!1,renderBaseInfo:w,renderVarsSecrets:y,renderIntegration:k,renderExtraTabs:F,onSave:j,onError:O,onRefresh:U,locale:C,messages:I,t:D}=t,_={...pl,...N},u=e.useMemo(()=>Ze({locale:C,messages:I,t:D}),[C,I,D]),Z=e.useRef(null),ee=e.useRef(""),H=hl(n,r,o);s?Z.current!==s&&(Z.current=s,ee.current="external"):n?(!Z.current||ee.current!==H)&&(Z.current=new v.RuleChainAPI({apiBase:n,...r}),ee.current=H):Z.current&&(Z.current=null,ee.current="");const V=Z.current,[me,q]=e.useState(P),[le,ue]=e.useState(""),[W,ge]=e.useState(!1),[Pe,Me]=e.useState(!1),[X,b]=e.useState(""),[$,Y]=e.useState(""),[te,L]=e.useState("visual"),[ke,we]=e.useState([]),[ne,he]=e.useState(`{
7
+ }`),[C,O]=e.useState(!1),[j,k]=e.useState(!1),[v,ae]=e.useState(!1),[J,Y]=e.useState(""),[re,ce]=e.useState([]),[g,F]=e.useState(!1),[ee,P]=e.useState([]),[Z,pe]=e.useState(!1),[Te,Pe]=e.useState({visible:!1,title:"",data:""}),_e=e.useRef(0),me=e.useRef(0),H=e.useRef(0),ne=e.useRef(r);e.useEffect(()=>{ne.current!==r&&(ne.current=r,_e.current+=1,me.current+=1,H.current+=1,ce([]),P([]),B("TEST_MSG"),q("{}"),Y(""),F(!1),pe(!1),O(!1),k(!1),ae(!1),Pe({visible:!1,title:"",data:""}))},[r]);const M=e.useMemo(()=>Ge({locale:R,messages:b,t:x}),[R,b,x]),ge=ln(R);e.useEffect(()=>{u==="running"&&ae(!1)},[u]);const xe=e.useCallback(async(z=!1)=>{if(!r){w("warning",M("editor.debugPanel.selectChainFirst","请先选择规则链"));return}if(!s){w("warning",M("editor.debugPanel.noSendCallback","未配置发送消息回调"));return}if(!z&&(u==="undeployed"||u==="stopped")){const ke=M("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");ae(!0),Y(ke),w("warning",ke);return}const G=++H.current,ye=y.createDebugPanelRequestSnapshot(r,G);try{O(!0);let ke;try{ke=JSON.parse(U)}catch{w("error",M("editor.debugPanel.invalidJson","消息体 JSON 格式错误"));return}const $e=await s(r,W,ke);if(!y.isDebugPanelRequestCurrent(ye,r,H.current))return;if($e.success)ae(!1),w("success",M("editor.debugPanel.sendSuccess","消息发送成功")),Y(JSON.stringify($e.data,null,2));else{const at=$e.msg||M("editor.debugPanel.unknownError","未知错误");if(y.isRuleChainNotDeployedError(at,r)){const qe=M("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");ae(!0),Y(qe),w("warning",qe);return}w("error",M("editor.debugPanel.sendFailed","发送失败: {{message}}",{message:at})),Y($e.msg||M("editor.debugPanel.sendTestMessage","发送测试消息"))}}catch(ke){if(!y.isDebugPanelRequestCurrent(ye,r,H.current))return;if(y.isRuleChainNotDeployedError(ke,r)){const $e=M("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");ae(!0),Y($e),w("warning",$e);return}w("error",M("editor.debugPanel.sendException","发送异常: {{message}}",{message:ke instanceof Error?ke.message:String(ke)}))}finally{y.isDebugPanelRequestCurrent(ye,r,H.current)&&O(!1)}},[r,u,W,U,s,w,M]),se=e.useCallback(async()=>{if(!d||j)return;const z=r;try{k(!0);const G=await d(z);if(ne.current!==z)return;if(G===!1||G&&typeof G=="object"&&G.success===!1){const ye=G&&typeof G=="object"&&G.msg?G.msg:M("editor.debugPanel.deployFailed","部署失败");w("error",M("editor.debugPanel.deployFailedWithMessage","部署失败: {{message}}",{message:ye}));return}ae(!1),w("success",M("editor.debugPanel.deploySucceeded","规则链已部署,正在重新发送")),await xe(!0)}catch(G){if(ne.current!==z)return;w("error",M("editor.debugPanel.deployFailedWithMessage","部署失败: {{message}}",{message:G instanceof Error?G.message:String(G)}))}finally{ne.current===z&&k(!1)}},[r,j,xe,d,w,M]),Ce=e.useCallback(async()=>{if(!r||!p)return;const z=++_e.current,G=y.createDebugPanelRequestSnapshot(r,z);try{F(!0);const ye=await p(r,n);if(!y.isDebugPanelRequestCurrent(G,r,_e.current))return;ce(ye.items||[])}catch{y.isDebugPanelRequestCurrent(G,r,_e.current)&&w("error",M("editor.debugPanel.loadDebugLogsFailed","加载调试日志失败"))}finally{y.isDebugPanelRequestCurrent(G,r,_e.current)&&F(!1)}},[r,n,p,w,M]),Re=e.useCallback(async()=>{if(!S)return;const z=++me.current,G=y.createDebugPanelRequestSnapshot(r,z);try{pe(!0);const ye=await S(r);if(!y.isDebugPanelRequestCurrent(G,r,me.current))return;P(ye||[])}catch{y.isDebugPanelRequestCurrent(G,r,me.current)&&w("error",M("editor.debugPanel.loadRunLogsFailed","加载运行日志失败"))}finally{y.isDebugPanelRequestCurrent(G,r,me.current)&&pe(!1)}},[r,S,w,M]),K=(z,G)=>{let ye=G;try{ye=JSON.stringify(JSON.parse(G),null,2)}catch{}Pe({visible:!0,title:z,data:ye})},le=z=>new Date(z).toLocaleString(ge,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),de=async z=>{try{await navigator.clipboard.writeText(z),w("success",M("editor.debugPanel.copied","已复制"))}catch{w("error",M("editor.debugPanel.copyFailed","复制失败"))}};return t?e.createElement("div",{className:"rge-debug-panel"},e.createElement("div",{className:"rge-debug-header"},e.createElement("div",{className:"rge-debug-tabs"},e.createElement("button",{className:`rge-debug-tab ${_==="send"?"active":""}`,onClick:()=>E("send")},e.createElement(be,{value:"send"})," ",M("editor.debugPanel.sendMessage","发送消息")),e.createElement("button",{className:`rge-debug-tab ${_==="debug"?"active":""}`,onClick:()=>{E("debug"),Ce()}},e.createElement(be,{value:"debug"})," ",M("editor.debugPanel.debugLogs","调试日志")),e.createElement("button",{className:`rge-debug-tab ${_==="logs"?"active":""}`,onClick:()=>{E("logs"),Re()}},e.createElement(be,{value:"data"})," ",M("editor.debugPanel.runLogs","运行日志"))),e.createElement("button",{className:"rge-drawer-close",onClick:o},"✕")),_==="send"&&e.createElement("div",{className:"rge-debug-body"},e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},M("editor.debugPanel.chainId","规则链 ID")),e.createElement("input",{type:"text",className:"rge-form-input",value:r,readOnly:!0})),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},M("editor.debugPanel.msgType","消息类型")),e.createElement("input",{type:"text",className:"rge-form-input",value:W,onChange:z=>B(z.target.value),placeholder:M("editor.debugPanel.msgTypePlaceholder","如 TEST_MSG")})),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},M("editor.debugPanel.msgBodyJson","消息体 (JSON)")),e.createElement("textarea",{className:"rge-code-textarea",rows:8,value:U,onChange:z=>q(z.target.value),spellCheck:!1})),v&&e.createElement("div",{className:"rge-debug-deploy-guide",role:"status"},e.createElement("span",null,M("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试")),d&&e.createElement("button",{type:"button",className:"rge-btn-mini",disabled:j||C,onClick:()=>{se()}},j?M("editor.debugPanel.deploying","部署中..."):M("editor.debugPanel.deployAndRetry","部署并重试"))),e.createElement("button",{className:"rge-btn-submit rge-full-width",onClick:()=>{xe()},disabled:C},e.createElement(be,{value:"send"})," ",C?M("editor.debugPanel.sending","发送中..."):M("editor.debugPanel.sendTestMessage","发送测试消息")),J&&e.createElement("div",{className:"rge-form-section rge-mt-16"},e.createElement("div",{className:"rge-label-row"},e.createElement("label",{className:"rge-form-label"},M("editor.debugPanel.responseData","响应数据")),e.createElement("button",{className:"rge-btn-mini",onClick:()=>de(J)},e.createElement(be,{value:"copy"})," ",M("editor.panel.copy","复制"))),e.createElement("pre",{className:"rge-response-pre"},J))),_==="debug"&&e.createElement("div",{className:"rge-debug-body"},e.createElement("div",{className:"rge-toolbar-row"},n&&e.createElement("span",{className:"rge-tag"},M("editor.debugPanel.nodeLabel","节点"),": ",n),e.createElement("button",{className:"rge-btn-mini",onClick:Ce,disabled:g},e.createElement(be,{value:"refresh",className:g?"is-spinning":""})," ",g?M("editor.debugPanel.loading","加载中..."):M("editor.debugPanel.refresh","刷新"))),re.length===0?e.createElement("div",{className:"rge-empty-tip"},e.createElement(be,{value:"debug",className:"rge-empty-graphic"}),e.createElement("p",null,g?M("editor.debugPanel.loading","加载中..."):M("editor.debugPanel.noDebugLogs","暂无调试日志")),e.createElement("p",{className:"rge-sub-tip"},M("editor.debugPanel.debugModeHint",'需要在节点上开启"调试模式"并发送消息'))):e.createElement("div",{className:"rge-log-table"},e.createElement("div",{className:"rge-log-table-header"},e.createElement("span",null,M("editor.debugPanel.time","时间")),e.createElement("span",null,M("editor.debugPanel.type","类型")),e.createElement("span",null,M("editor.debugPanel.relation","关系")),e.createElement("span",null,M("editor.debugPanel.msgType","消息类型")),e.createElement("span",null,M("editor.debugPanel.operate","操作"))),re.map((z,G)=>e.createElement("div",{key:G,className:`rge-log-table-row ${z.err?"error":""}`},e.createElement("span",null,le(z.ts)),e.createElement("span",{className:"rge-tag-small"},z.flowType),e.createElement("span",{className:"rge-tag-small"},z.relationType),e.createElement("span",{title:z.msg.type},z.msg.type.length>12?z.msg.type.slice(0,12)+"...":z.msg.type),e.createElement("span",{className:"rge-log-actions"},e.createElement("button",{className:"rge-btn-link",onClick:()=>K(M("editor.debugPanel.data","数据"),z.msg.data)},M("editor.debugPanel.data","数据")),e.createElement("button",{className:"rge-btn-link",onClick:()=>K(M("editor.debugPanel.metadata","元数据"),JSON.stringify(z.msg.metadata))},M("editor.debugPanel.metadata","元数据")),z.err&&e.createElement("button",{className:"rge-btn-link danger",onClick:()=>K(M("editor.debugPanel.error","错误"),z.err||"")},M("editor.debugPanel.error","错误"))))))),_==="logs"&&e.createElement("div",{className:"rge-debug-body"},e.createElement("div",{className:"rge-toolbar-row"},e.createElement("button",{className:"rge-btn-mini",onClick:Re,disabled:Z},e.createElement(be,{value:"refresh",className:Z?"is-spinning":""})," ",Z?M("editor.debugPanel.loading","加载中..."):M("editor.debugPanel.refresh","刷新"))),ee.length===0?e.createElement("div",{className:"rge-empty-tip"},e.createElement(be,{value:"data",className:"rge-empty-graphic"}),e.createElement("p",null,Z?M("editor.debugPanel.loading","加载中..."):M("editor.debugPanel.noRunLogs","暂无运行日志"))):e.createElement("div",{className:"rge-log-list"},ee.map((z,G)=>e.createElement("div",{key:G,className:"rge-run-log-item",onClick:()=>K(M("editor.debugPanel.runLogDetail","日志详情"),JSON.stringify(z))},e.createElement("pre",null,typeof z=="string"?z:JSON.stringify(z,null,2)))))),Te.visible&&e.createElement("div",{className:"rge-detail-overlay",onClick:()=>Pe({...Te,visible:!1})},e.createElement("div",{className:"rge-detail-modal",onClick:z=>z.stopPropagation()},e.createElement("div",{className:"rge-detail-header"},e.createElement("span",null,Te.title),e.createElement("div",null,e.createElement("button",{className:"rge-btn-mini",onClick:()=>de(Te.data)},e.createElement(be,{value:"copy"})),e.createElement("button",{className:"rge-drawer-close",onClick:()=>Pe({...Te,visible:!1})},"✕"))),e.createElement("pre",{className:"rge-detail-pre"},Te.data)))):null};Da.displayName="DebugPanel";const ls=t=>{const r=new WeakSet;try{const n=JSON.stringify(t,(o,s)=>{if(typeof s=="bigint")return`${s.toString()}n`;if(typeof s=="function")return`[Function${s.name?` ${s.name}`:""}]`;if(s&&typeof s=="object"){if(r.has(s))return"[CIRCULAR]";r.add(s)}return s},2);return n===void 0?"undefined":n}catch(n){return`[Unserializable: ${n instanceof Error?n.message:String(n)}]`}},cs=t=>{if(!Number.isFinite(t)||t<0)return"-";if(t<1024)return`${t} B`;const r=t/1024;return r<1024?`${r.toFixed(1)} KB`:`${(r/1024).toFixed(2)} MB`},La=({visible:t,data:r,title:n,fileNamePrefix:o="rulechain",onClose:s,onNotify:u,locale:d,messages:p,t:S})=>{const w=e.useMemo(()=>Ge({locale:d,messages:p,t:S}),[d,p,S]),R=n||w("editor.dataView.title","规则链数据"),b=e.useMemo(()=>ls(r??{}),[r]),x=e.useMemo(()=>{const W=b?b.split(/\r\n|\r|\n/).length:0,B=typeof Blob<"u"?new Blob([b]).size:new TextEncoder().encode(b).length;return{lineCount:W,byteSize:cs(B)}},[b]),_=async()=>{try{await navigator.clipboard.writeText(b),u==null||u("success",w("editor.dataView.copied","JSON 已复制到剪贴板"))}catch{u==null||u("error",w("editor.dataView.copyFailed","复制失败"))}},E=()=>{try{const W=new Blob([b],{type:"application/json"}),B=URL.createObjectURL(W),U=new Date().toISOString().slice(0,19).replace(/[:]/g,"-"),q=`${o}_${U}.json`,C=document.createElement("a");C.href=B,C.download=q,document.body.appendChild(C),C.click(),document.body.removeChild(C),URL.revokeObjectURL(B),u==null||u("success",w("editor.dataView.downloaded","已下载 {{fileName}}",{fileName:q}))}catch{u==null||u("error",w("editor.dataView.downloadFailed","下载失败"))}};return t?e.createElement("div",{className:"rge-dataview-overlay",onClick:s},e.createElement("div",{className:"rge-dataview-dialog",onClick:W=>W.stopPropagation()},e.createElement("div",{className:"rge-dialog-header"},e.createElement("div",{className:"rge-dialog-title"},e.createElement(be,{value:"data"}),e.createElement("span",null,R)),e.createElement("button",{className:"rge-drawer-close",onClick:s},"✕")),e.createElement("div",{className:"rge-dialog-toolbar"},e.createElement("span",{className:"rge-dialog-meta"},w("editor.dataView.fullJson","完整 JSON")," · ",w("editor.dataView.lineCount","{{count}} 行",{count:x.lineCount})," · ",w("editor.dataView.byteSize","{{size}}",{size:x.byteSize})),e.createElement("button",{type:"button",className:"rge-btn-outline",onClick:_},e.createElement(be,{value:"copy"})," ",w("editor.dataView.copyJson","复制")),e.createElement("button",{type:"button",className:"rge-btn-outline",onClick:E},e.createElement(be,{value:"export"})," ",w("editor.dataView.downloadJson","下载"))),e.createElement("div",{className:"rge-dialog-hint"},w("editor.dataView.fullJsonHint","当前视图不截断数据;大数据可直接复制或下载后查看。")),e.createElement("div",{className:"rge-dialog-body"},e.createElement("textarea",{className:"rge-json-textarea",value:b,readOnly:!0,spellCheck:!1,"aria-label":R})))):null};La.displayName="DataViewDialog";const Ma=({canUndo:t=!1,canRedo:r=!1,isFullscreen:n=!1,isDebugMode:o=!1,zoomLevel:s=100,hasSelection:u=!1,onSave:d,onUndo:p,onRedo:S,onDelete:w,onZoomIn:R,onZoomOut:b,onZoomChange:x,onFitView:_,onResetZoom:E,onFullscreen:W,onToggleDebug:B,onViewData:U,onSettings:q,onValidate:C,onNew:O,onImport:j,onExport:k,onAutoLayout:v,extraButtons:ae=[],hiddenButtons:J=[],hideZoom:Y=!1,chainName:re,locale:ce,messages:g,t:F})=>{const[ee,P]=e.useState(!1);e.useEffect(()=>{Y&&P(!1)},[Y]);const Z=e.useMemo(()=>Ge({locale:ce,messages:g,t:F}),[ce,g,F]),pe=me=>J.includes(me),Te=me=>{const H=y.getEditorToolbarIconSvg(me);return H?e.createElement("span",{className:"rge-toolbar-icon rge-toolbar-icon-svg",dangerouslySetInnerHTML:{__html:H}}):e.createElement("span",{className:"rge-toolbar-icon"},me)},_e=[{key:"new",icon:"file-plus",tooltip:Z("editor.toolbar.newChain","新建规则链"),onClick:()=>O==null?void 0:O(),hidden:pe("new")||!O},{key:"save",icon:"save",tooltip:`${Z("editor.toolbar.save","保存")} (Ctrl+S)`,onClick:()=>d==null?void 0:d(),hidden:pe("save")},{key:"import",icon:"import",tooltip:Z("editor.toolbar.import","导入"),onClick:()=>j==null?void 0:j(),hidden:pe("import")||!j},{key:"export",icon:"export",tooltip:Z("editor.toolbar.export","导出"),onClick:()=>k==null?void 0:k(),hidden:pe("export")||!k},{key:"undo",icon:"undo",tooltip:`${Z("editor.toolbar.undo","撤销")} (Ctrl+Z)`,onClick:()=>p==null?void 0:p(),disabled:!t,hidden:pe("undo"),dividerBefore:!0},{key:"redo",icon:"redo",tooltip:`${Z("editor.toolbar.redo","重做")} (Ctrl+Y)`,onClick:()=>S==null?void 0:S(),disabled:!r,hidden:pe("redo")},{key:"delete",icon:"delete",tooltip:`${Z("editor.toolbar.delete","删除选中")} (Del)`,onClick:()=>w==null?void 0:w(),disabled:!u,hidden:pe("delete")},{key:"zoomIn",icon:"zoom-in",tooltip:Z("editor.toolbar.zoomIn","放大"),onClick:()=>R==null?void 0:R(),hidden:pe("zoomIn"),dividerBefore:!0},{key:"zoomOut",icon:"zoom-out",tooltip:Z("editor.toolbar.zoomOut","缩小"),onClick:()=>b==null?void 0:b(),hidden:pe("zoomOut")},{key:"fitView",icon:"fit",tooltip:Z("editor.toolbar.fitView","适应画布"),onClick:()=>_==null?void 0:_(),hidden:pe("fitView")},{key:"autoLayout",icon:"auto-layout",tooltip:Z("editor.toolbar.autoLayout","自动排版"),onClick:()=>v==null?void 0:v(),hidden:pe("autoLayout")||!v},{key:"resetZoom",icon:"1:1",tooltip:Z("editor.toolbar.resetZoom","重置缩放"),onClick:()=>E==null?void 0:E(),hidden:pe("resetZoom")},{key:"validate",icon:"validate",tooltip:Z("editor.toolbar.validate","校验规则链"),onClick:()=>C==null?void 0:C(),hidden:pe("validate")||!C,dividerBefore:!0},{key:"debug",icon:"debug",tooltip:o?Z("editor.toolbar.debugOff","关闭调试"):Z("editor.toolbar.debugOn","开启调试"),onClick:()=>B==null?void 0:B(),active:o,hidden:pe("debug")},{key:"viewData",icon:"data",tooltip:Z("editor.toolbar.viewData","查看数据"),onClick:()=>U==null?void 0:U(),hidden:pe("viewData")},{key:"settings",icon:"settings",tooltip:Z("editor.toolbar.settings","设置"),onClick:()=>q==null?void 0:q(),hidden:pe("settings")||!q},{key:"fullscreen",icon:n?"fullscreen-exit":"fullscreen",tooltip:n?Z("editor.toolbar.exitFullscreen","退出全屏"):Z("editor.toolbar.fullscreen","全屏"),onClick:()=>W==null?void 0:W(),hidden:pe("fullscreen")},...ae].filter(me=>!me.hidden&&!pe(me.key));return e.createElement("div",{className:"rge-editor-toolbar"},e.createElement("div",{className:"rge-toolbar-left"},_e.map((me,H)=>e.createElement(e.Fragment,{key:me.key},H>0&&me.dividerBefore&&e.createElement("div",{className:"rge-toolbar-divider"}),e.createElement("button",{type:"button",className:`rge-toolbar-btn ${me.active?"active":""} ${me.disabled?"disabled":""}`,onClick:me.onClick,disabled:me.disabled,title:me.tooltip,"aria-pressed":me.active===void 0?void 0:me.active},Te(me.icon))))),re&&e.createElement("div",{className:"rge-toolbar-center"},e.createElement("span",{className:"rge-chain-name"},re)),!Y&&e.createElement("div",{className:"rge-toolbar-right"},e.createElement("button",{type:"button",className:"rge-toolbar-zoom-btn",onClick:()=>P(!ee),title:Z("editor.toolbar.zoomOptions","缩放选项")},s,"%"),ee&&e.createElement("div",{className:"rge-zoom-menu",onMouseLeave:()=>P(!1)},[50,75,100,125,150,200].map(me=>e.createElement("button",{type:"button",key:me,className:`rge-zoom-option ${me===s?"active":""}`,"aria-pressed":me===s,disabled:!x&&me!==100,onClick:()=>{x?x(me):me===100&&(E==null||E()),P(!1)}},me,"%")),e.createElement("div",{className:"rge-toolbar-divider horizontal"}),e.createElement("button",{type:"button",className:"rge-zoom-option",onClick:()=>{_==null||_(),P(!1)}},Z("editor.toolbar.fitView","适应画布")))))};Ma.displayName="EditorToolbar";const Aa=({visible:t,x:r,y:n,items:o,onClose:s})=>{const u=e.useRef(null),d=e.useCallback(x=>{u.current&&!u.current.contains(x.target)&&s()},[s]),p=e.useCallback(x=>{x.key==="Escape"&&s()},[s]),S=e.useCallback(x=>{const _=Array.from(x.children).find(U=>U.classList.contains("rge-ctx-submenu"));if(!_)return;_.style.display="block",_.style.visibility="hidden";const E=x.getBoundingClientRect(),W=_.getBoundingClientRect(),B=y.resolveContextSubmenuPosition(E,{width:W.width,height:W.height},{width:window.innerWidth,height:window.innerHeight});_.dataset.placement=B.placement,_.style.left=`${B.left}px`,_.style.top=`${B.top}px`,_.style.visibility="visible"},[]);if(e.useEffect(()=>(t&&(document.addEventListener("mousedown",d),document.addEventListener("keydown",p)),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",p)}),[t,d,p]),e.useEffect(()=>{if(t&&u.current){const x=u.current.getBoundingClientRect(),_=y.clampContextMenuPosition({left:r,top:n},{width:x.width,height:x.height},{width:window.innerWidth,height:window.innerHeight});u.current.style.left=`${_.left}px`,u.current.style.top=`${_.top}px`}},[t,r,n]),!t)return null;const w=o.filter(x=>!x.hidden),R=x=>x.children&&x.children.length>0?e.createElement(e.Fragment,{key:x.key},x.dividerBefore&&e.createElement("div",{className:"rge-ctx-menu-divider"}),e.createElement("div",{className:`rge-ctx-menu-item has-submenu ${x.disabled?"disabled":""}`,role:"menuitem","aria-haspopup":"menu","aria-disabled":x.disabled||void 0,onMouseEnter:_=>S(_.currentTarget)},e.createElement("div",{className:"rge-ctx-menu-item-content"},e.createElement("span",{className:"rge-ctx-menu-check","aria-hidden":"true"},x.check?"✓":""),x.icon&&b(x.icon),e.createElement("span",{className:"rge-ctx-menu-label"},x.label),e.createElement("span",{className:"rge-ctx-menu-arrow","aria-hidden":"true"},"▶")),e.createElement("div",{className:"rge-ctx-submenu",role:"menu"},x.children.filter(_=>!_.hidden).map(R)))):e.createElement(e.Fragment,{key:x.key},x.dividerBefore&&e.createElement("div",{className:"rge-ctx-menu-divider"}),e.createElement("button",{className:`rge-ctx-menu-item ${x.disabled?"disabled":""} ${x.danger?"danger":""}`,onClick:()=>{var _;x.disabled||((_=x.onClick)==null||_.call(x),s())},disabled:x.disabled,role:"menuitem"},e.createElement("div",{className:"rge-ctx-menu-item-content"},e.createElement("span",{className:"rge-ctx-menu-check","aria-hidden":"true"},x.check?"✓":""),x.icon&&b(x.icon),e.createElement("span",{className:"rge-ctx-menu-label"},x.label),x.shortcut&&e.createElement("span",{className:"rge-ctx-menu-shortcut"},x.shortcut)))),b=x=>{const _=y.getEditorToolbarIconSvg(x);return _?e.createElement("span",{className:"rge-ctx-menu-icon rge-ctx-menu-icon-svg","aria-hidden":"true",dangerouslySetInnerHTML:{__html:_}}):e.createElement("span",{className:"rge-ctx-menu-icon","aria-hidden":"true"},x)};return e.createElement("div",{ref:u,className:"rge-ctx-menu",role:"menu",style:{left:r,top:n}},w.map(R))};Aa.displayName="ContextMenu";function is(t,r){const n=Ge(r),o=t.nodeType===void 0||y.isEditorNodeRunTarget(t.nodeType),s=[{key:"edit",label:n("editor.contextMenu.editProperties","编辑属性"),icon:"edit",shortcut:"Enter",onClick:t.onEditProperties},{key:"copy",label:n("editor.contextMenu.copy","复制"),icon:"copy",shortcut:"Ctrl+C",onClick:t.onCopy},{key:"duplicate",label:n("editor.contextMenu.duplicate","复制节点"),icon:"copy",shortcut:"Ctrl+D",onClick:t.onDuplicate},{key:"connections",label:n("editor.contextMenu.viewConnections","查看连接"),icon:"link",onClick:t.onViewConnections},{key:"delete",label:n("editor.contextMenu.delete","删除"),icon:"delete",shortcut:"Del",danger:!0,dividerBefore:!0,onClick:t.onDelete}];return o&&s.splice(4,0,{key:"runFromNode",label:n("editor.contextMenu.runFromNode","从此节点开始执行"),icon:"play",dividerBefore:!0,onClick:t.onRunFromNode},{key:"runSingleNode",label:n("editor.contextMenu.runSingleNode","仅执行此节点"),icon:"play-single",onClick:t.onRunSingleNode}),s}function us(t,r){const n=Ge(r);return[{key:"edit",label:n("editor.contextMenu.editProperties","编辑属性"),icon:"edit",onClick:t.onEditProperties},{key:"delete",label:n("editor.contextMenu.delete","删除"),icon:"delete",shortcut:"Del",danger:!0,dividerBefore:!0,onClick:t.onDelete}]}function ms(t,r){const n=Ge(r);return[{key:"paste",label:n("editor.contextMenu.paste","粘贴"),icon:"paste",shortcut:"Ctrl+V",onClick:t.onPaste},{key:"selectAll",label:n("editor.contextMenu.selectAll","全选"),icon:"select-all",shortcut:"Ctrl+A",onClick:t.onSelectAll},{key:"fitView",label:n("editor.contextMenu.fitView","适应画布"),icon:"fit",dividerBefore:!0,onClick:t.onFitView},{key:"resetZoom",label:n("editor.contextMenu.resetZoom","重置缩放"),icon:"reset-zoom",onClick:t.onResetZoom}]}const ds={"start-input":"--rg-node-start-bg",filter:"--rg-node-filter-border",jsFilter:"--rg-node-filter-border",exprFilter:"--rg-node-filter-border",transformer:"--rg-node-transform-border",jsTransform:"--rg-node-transform-border",template:"--rg-node-transform-border",action:"--rg-node-action-border",restApiCall:"--rg-node-action-border",mqttClient:"--rg-node-action-border",sendMail:"--rg-node-action-border",dbClient:"--rg-node-action-border",log:"--rg-node-action-border",subChain:"--rg-node-flow-border"},Oa=({nodes:t,viewport:r,width:n=200,height:o=150,defaultCollapsed:s=!1,position:u="bottom-right",onViewportChange:d,onNodeClick:p,locale:S,messages:w,t:R})=>{const[b,x]=e.useState(s),_=e.useRef(null),E=e.useRef(!1),W=e.useMemo(()=>Ge({locale:S,messages:w,t:R}),[S,w,R]),B=e.useCallback(()=>{if(t.length===0)return{minX:0,minY:0,maxX:100,maxY:100};let k=1/0,v=1/0,ae=-1/0,J=-1/0;t.forEach(re=>{const ce=re.width||60,g=re.height||40;k=Math.min(k,re.x),v=Math.min(v,re.y),ae=Math.max(ae,re.x+ce),J=Math.max(J,re.y+g)});const Y=50;return{minX:k-Y,minY:v-Y,maxX:ae+Y,maxY:J+Y}},[t]);e.useEffect(()=>{const k=_.current;if(b||!k)return;const v=k.getContext("2d");if(!v)return;const ae=y.getThemeRuntimeVariables(),J=()=>{const re=getComputedStyle(k),ce=Z=>re.getPropertyValue(Z).trim()||ae[Z]||re.color,g=B(),F=g.maxX-g.minX,ee=g.maxY-g.minY,P=Math.min(n/F,o/ee);if(v.clearRect(0,0,n,o),v.fillStyle=ce("--rg-canvas-bg"),v.fillRect(0,0,n,o),t.forEach(Z=>{const pe=(Z.x-g.minX)*P,Te=(Z.y-g.minY)*P,Pe=Math.max((Z.width||60)*P,4),_e=Math.max((Z.height||40)*P,3);v.fillStyle=Z.color||ce(ds[Z.type||""]||"--hb-text-muted"),v.fillRect(pe,Te,Pe,_e),Z.selected&&(v.strokeStyle=ce("--hb-node-selected-stroke"),v.lineWidth=1,v.strokeRect(pe-1,Te-1,Pe+2,_e+2))}),r){const Z=(r.x-g.minX)*P,pe=(r.y-g.minY)*P,Te=r.width*P,Pe=r.height*P;v.strokeStyle=ce("--hb-color-primary"),v.lineWidth=2,v.strokeRect(Z,pe,Te,Pe),v.save(),v.fillStyle=ce("--hb-color-primary"),v.globalAlpha=.1,v.fillRect(Z,pe,Te,Pe),v.restore()}};J();const Y=new MutationObserver(J);for(let re=k.parentElement;re&&re!==k.ownerDocument.body;re=re.parentElement)Y.observe(re,{attributes:!0,attributeFilter:["style","class","data-theme","data-rg-theme"]});return()=>Y.disconnect()},[t,r,b,n,o,B]);const U=e.useCallback(k=>{if(!d||!_.current)return;const v=_.current.getBoundingClientRect(),ae=k.clientX-v.left,J=k.clientY-v.top,Y=B(),re=Y.maxX-Y.minX,ce=Y.maxY-Y.minY,g=Math.min(n/re,o/ce),F=ae/g+Y.minX,ee=J/g+Y.minY;d({x:F,y:ee})},[d,B,n,o]),q=e.useCallback(k=>{E.current=!0,U(k)},[U]),C=e.useCallback(k=>{E.current&&U(k)},[U]),O=e.useCallback(()=>{E.current=!1},[]),j={position:"absolute",zIndex:100,...u.includes("bottom")?{bottom:16}:{top:16},...u.includes("right")?{right:16}:{left:16}};return e.createElement("div",{className:"rge-minimap",style:j},e.createElement("div",{className:"rge-minimap-header",onClick:()=>x(!b)},e.createElement("span",{className:"rge-minimap-title"},e.createElement(be,{value:"map"})," ",W("editor.toolbar.minimap","小地图")),e.createElement("span",{className:"rge-minimap-toggle"},b?"▶":"▼")),!b&&e.createElement("canvas",{ref:_,width:n,height:o,className:"rge-minimap-canvas",onMouseDown:q,onMouseMove:C,onMouseUp:O,onMouseLeave:O}))};Oa.displayName="MiniMap";function ps(t,r){switch(t){case"close":return"关闭";case"close-others":return"关闭其他";case"close-right":return"关闭右侧";case"rename":return"重命名";case"toggle-pinned":return y.isWorkspaceTabPinned(r)?"取消固定":"固定";case"edit-info":return"编辑信息";case"run-history":return"运行记录";case"debug":return"调试";case"toggle-disabled":return y.getWorkspaceTabLifecycleState(r)==="running"?"下线":"部署"}}function gs({tabs:t,activeTabId:r=null,locale:n,t:o,onActivate:s,onClose:u,onAdd:d,onEditInfo:p,onTabAction:S,hideAdd:w=!1,hideOverflow:R=!1,hideClose:b=!1,hiddenTabActions:x=[]}){var ce;const _=e.useMemo(()=>Ge({locale:n,t:o}),[n,o]),[E,W]=e.useState(!1),B=e.useRef(null),U=e.useMemo(()=>{if(!E||!B.current)return{};const g=B.current.getBoundingClientRect();return{top:g.bottom+2,right:Math.max(4,window.innerWidth-g.right)}},[E]),[q,C]=e.useState(null),[O,j]=e.useState(null),k=e.useRef(null),v=r||((ce=t[0])==null?void 0:ce.id)||"",ae=t.find(g=>g.id===v),J=q?t.find(g=>g.id===q.tabId):void 0,Y=g=>y.getEditorWorkspaceTabActions(g).filter(F=>!x.includes(F.id)),re=J?Y(J):[];return e.useEffect(()=>{R&&W(!1)},[R]),e.useEffect(()=>{if(!E)return;const g=()=>W(!1),F=Z=>{var pe;(pe=B.current)!=null&&pe.contains(Z.target)||g()},ee=Z=>{Z.key==="Escape"&&g()},P=Z=>{var pe;(pe=B.current)!=null&&pe.contains(Z.target)||g()};return document.addEventListener("pointerdown",F,!0),document.addEventListener("keydown",ee),document.addEventListener("scroll",P,!0),window.addEventListener("resize",g),()=>{document.removeEventListener("pointerdown",F,!0),document.removeEventListener("keydown",ee),document.removeEventListener("scroll",P,!0),window.removeEventListener("resize",g)}},[E]),e.useEffect(()=>{re.length||C(null)},[re.length]),e.useLayoutEffect(()=>{if(!q||!k.current)return;const g=k.current.getBoundingClientRect(),F=y.clampContextMenuPosition({left:q.x,top:q.y},{width:g.width,height:g.height},{width:window.innerWidth,height:window.innerHeight});j(ee=>(ee==null?void 0:ee.left)===F.left&&ee.top===F.top?ee:F)},[q,re.length]),e.useEffect(()=>{if(!q)return;const g=()=>C(null);return document.addEventListener("click",g),document.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{document.removeEventListener("click",g),document.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g)}},[q]),e.createElement("div",{className:"rge-workspace-tabs",role:"tablist","aria-label":_("editor.workspace.tabs","规则链标签")},e.createElement("div",{className:"rge-workspace-tabs__strip"},t.map(g=>{var pe,Te,Pe;const F=g.id===v,ee=((pe=g.metadata)==null?void 0:pe.root)!==!1&&((Pe=(Te=g.data)==null?void 0:Te.ruleChain)==null?void 0:Pe.root)!==!1,P=y.getWorkspaceTabLifecycleState(g),Z=y.isWorkspaceTabPinned(g);return e.createElement("div",{key:g.id,className:`rge-workspace-tab${F?" is-active":""}${g.isDirty?" is-dirty":""}`,"data-workspace-tab-id":g.id,role:"tab","aria-selected":F,"aria-busy":g.isLoading||void 0,title:g.isDirty?`${g.title} · ${_("editor.workspace.unsaved","有未保存修改")}`:g.title,onClick:()=>s==null?void 0:s(g.id),onDoubleClick:()=>p==null?void 0:p(g.id),onContextMenu:_e=>{Y(g).length&&(_e.preventDefault(),_e.stopPropagation(),s==null||s(g.id),j({left:_e.clientX,top:_e.clientY}),C({tabId:g.id,x:_e.clientX,y:_e.clientY}))}},P!=="undeployed"&&e.createElement("span",{className:`rge-workspace-tab__lifecycle is-${P}`,"aria-label":_(`editor.workspace.${P}`,P==="running"?"运行中":"已停止"),title:_(`editor.workspace.${P}`,P==="running"?"运行中":"已停止")}),e.createElement("span",{className:`rge-workspace-tab__kind${ee?" is-root":" is-child"}`,"aria-hidden":"true"},Z?"★":ee?"◆":"↳"),e.createElement("span",{className:"rge-workspace-tab__title"},g.title||g.chainId),g.isLoading&&e.createElement("span",{className:"rge-workspace-tab__loading","aria-label":_("editor.workspace.loading","加载中")}),b&&g.isDirty&&e.createElement("span",{className:"rge-workspace-tab__dirty-dot","aria-label":_("editor.workspace.unsaved","有未保存修改")}),!b&&e.createElement("button",{type:"button",className:"rge-workspace-tab__close","data-workspace-close-id":g.id,"aria-label":`${_("editor.workspace.close","关闭")} ${g.title||g.chainId}`,title:_("editor.workspace.close","关闭"),onClick:_e=>{_e.stopPropagation(),u==null||u(g.id)}},g.isDirty?e.createElement("span",{className:"rge-workspace-tab__dirty-dot","aria-hidden":"true"}):"×"))}),!t.length&&e.createElement("span",{className:"rge-workspace-tabs__empty"},_("editor.workspace.empty","打开规则链后显示标签"))),!w&&e.createElement("button",{type:"button",className:"rge-workspace-tabs__icon",title:_("editor.workspace.add","新建规则链"),"aria-label":_("editor.workspace.add","新建规则链"),onClick:d},"+"),!R&&t.length>0&&e.createElement("div",{className:"rge-workspace-tabs__overflow",ref:B},e.createElement("button",{type:"button",className:"rge-workspace-tabs__icon",title:_("editor.workspace.all","全部规则链"),"aria-label":_("editor.workspace.all","全部规则链"),"aria-expanded":E,onClick:()=>W(g=>!g)},"▾"),E&&e.createElement("div",{className:"rge-workspace-tabs__menu",role:"menu",style:U},t.map(g=>{const F=y.getWorkspaceTabLifecycleState(g);return e.createElement("button",{key:g.id,type:"button",role:"menuitem",className:g.id===v?"is-active":"",onClick:()=>{s==null||s(g.id),W(!1)}},F!=="undeployed"&&e.createElement("span",{className:`rge-workspace-tab__lifecycle is-${F}`,"aria-hidden":"true"}),y.isWorkspaceTabPinned(g)?"★ ":"",g.isDirty?"● ":"",g.title||g.chainId)}))),ae&&e.createElement("span",{className:"rge-workspace-tabs__status","aria-live":"polite"},ae.isDirty?"●":""),q&&J&&re.length>0&&e.createElement("div",{className:"rge-workspace-tabs__context-menu",ref:k,role:"menu",style:{left:(O==null?void 0:O.left)??q.x,top:(O==null?void 0:O.top)??q.y},onClick:g=>g.stopPropagation()},re.map(g=>{const F=g.id==="close"?!!u:g.id==="edit-info"?!!p:!!S;return e.createElement("button",{key:g.id,type:"button",role:"menuitem","data-workspace-tab-action":g.id,className:g.dividerBefore?"is-divider-before":void 0,disabled:g.disabled||!F,onClick:()=>{g.disabled||!F||(g.id==="close"?u==null||u(J.id):g.id==="edit-info"?p==null||p(J.id):S==null||S(J.id,g.id),C(null))}},_(g.labelKey,ps(g.id,J)))})))}const ua=["graph:transform","node:click","edge:click","blank:click","node:add","node:delete","edge:add","edge:delete","selection:drop","graph:rendered","history:change"];function ma(t){var o,s,u,d,p,S;if(!(t!=null&&t.graphModel))return{nodeCount:0,edgeCount:0,selectedCount:0,zoom:1};const r=((o=t.getSelectElements)==null?void 0:o.call(t))||{},n=(s=t.graphModel.transformModel)==null?void 0:s.SCALE_X;return{nodeCount:((u=t.graphModel.nodes)==null?void 0:u.length)||0,edgeCount:((d=t.graphModel.edges)==null?void 0:d.length)||0,selectedCount:(((p=r.nodes)==null?void 0:p.length)||0)+(((S=r.edges)==null?void 0:S.length)||0),zoom:typeof n=="number"&&n>0?n:1}}function fs({lf:t,nodeCount:r,edgeCount:n,selectedCount:o,zoom:s,problemCount:u=0,onZoomIn:d,onZoomOut:p,onResetZoom:S,onOpenDiagnostics:w,className:R="",locale:b,messages:x,t:_}){const E=e.useMemo(()=>Ge({locale:b,messages:x,t:_}),[b,x,_]),[W,B]=e.useState(()=>ma(t));e.useEffect(()=>{const Y=()=>B(ma(t));if(Y(),!!(t!=null&&t.on))return ua.forEach(re=>{var ce;return(ce=t.on)==null?void 0:ce.call(t,re,Y)}),()=>ua.forEach(re=>{var ce;return(ce=t.off)==null?void 0:ce.call(t,re,Y)})},[t]);const U=r??W.nodeCount,q=n??W.edgeCount,C=o??W.selectedCount,O=s??W.zoom,j=Y=>{t!=null&&t.zoom&&t.zoom((O>0?O:1)*Y)},k=()=>d?d():j(1.2),v=()=>p?p():j(1/1.2),ae=()=>{var Y;return S?S():(Y=t==null?void 0:t.resetZoom)==null?void 0:Y.call(t)},J=["rge-status-bar",R].filter(Boolean).join(" ");return e.createElement("div",{className:J,role:"status","aria-live":"polite"},e.createElement("button",{type:"button",className:"rge-status-bar__button",title:E("editor.statusBar.zoomOut","缩小"),"aria-label":E("editor.statusBar.zoomOut","缩小"),onClick:v},"−"),e.createElement("button",{type:"button",className:"rge-status-bar__value",title:E("editor.statusBar.resetZoom","重置为 100%"),onClick:ae},Math.round(O*100),"%"),e.createElement("button",{type:"button",className:"rge-status-bar__button",title:E("editor.statusBar.zoomIn","放大"),"aria-label":E("editor.statusBar.zoomIn","放大"),onClick:k},"+"),e.createElement("span",{className:"rge-status-bar__separator","aria-hidden":"true"},"|"),e.createElement("span",{className:"rge-status-bar__item"},E("editor.statusBar.nodes","节点")," ",U),e.createElement("span",{className:"rge-status-bar__item"},E("editor.statusBar.edges","边")," ",q),C>0&&e.createElement("span",{className:"rge-status-bar__item"},E("editor.statusBar.selected","已选")," ",C),u>0&&e.createElement(e.Fragment,null,e.createElement("span",{className:"rge-status-bar__separator","aria-hidden":"true"},"|"),e.createElement("button",{type:"button",className:"rge-status-bar__diagnostic",title:E("editor.statusBar.diagnostics","查看链路诊断"),onClick:w},E("editor.statusBar.diagnostics","诊断")," ",u)))}const da={online:{key:"editor.connection.online",fallback:"已连接",kind:"online"},checking:{key:"editor.connection.checking",fallback:"检测中",kind:"checking"},unauthorized:{key:"editor.connection.unauthorized",fallback:"需要登录",kind:"unauthorized"},forbidden:{key:"editor.connection.forbidden",fallback:"权限不足",kind:"forbidden"},offline:{key:"editor.connection.offline",fallback:"无法连接",kind:"offline"},error:{key:"editor.connection.error",fallback:"连接异常",kind:"error"},unknown:{key:"editor.connection.unknown",fallback:"未检测",kind:"unknown"}};function bs({state:t,compact:r=!1,onRetry:n,onLogin:o,className:s="",locale:u,messages:d,t:p}){const S=e.useMemo(()=>Ge({locale:u,messages:d,t:p}),[u,d,p]),w=String((t==null?void 0:t.status)||"unknown"),R=da[w]||da.unknown,b=(t==null?void 0:t.api)||"unknown",x=(t==null?void 0:t.ws)||"idle",_=`${S("editor.connection.api","API")}: ${b} · ${S("editor.connection.ws","WS")}: ${x}`,E=["rge-connection-status",`is-${R.kind}`,r?"is-compact":"",s].filter(Boolean).join(" "),W=w==="unauthorized"?o:w==="offline"||w==="error"?n:void 0,B=w==="unauthorized"?S("editor.connection.login","登录"):S("editor.connection.retry","重试");return e.createElement("div",{className:E,role:"status","aria-live":"polite",title:_},e.createElement("span",{className:"rge-connection-status__dot","aria-hidden":"true"}),e.createElement("span",{className:"rge-connection-status__label"},S(R.key,R.fallback)),!r&&e.createElement("span",{className:"rge-connection-status__detail"},_),W&&e.createElement("button",{type:"button",className:"rge-connection-status__action",onClick:W},B))}function hs(t,r){return r.visible!==!1&&t.openPanelIds.includes(r.id)}function ys(t,r){return t.panels.filter(n=>n.dock===r&&hs(t,n)).sort((n,o)=>(n.order??0)-(o.order??0)||n.id.localeCompare(o.id))}function ur(t,r){var n;return((n=t.expandedById)==null?void 0:n[r.id])??r.defaultExpanded!==!1}function Es({dock:t,dockState:r,panelState:n,renderPanel:o,title:s,className:u="",onToggleDock:d,onActivatePanel:p,onClosePanel:S,onTogglePanel:w,onResize:R}){var j;const b=e.useRef(null),x=e.useRef(null),[_,E]=e.useState(!1),W=e.useMemo(()=>ys(n,t),[n,t]),B=n.activeByDock[t]&&W.some(k=>k.id===n.activeByDock[t])?n.activeByDock[t]:((j=W[0])==null?void 0:j.id)||null,U=t==="bottom"?r.bottom.height:r[t].width,q=r[t].visible&&W.length>0,C=t==="left";e.useEffect(()=>()=>{const k=x.current;x.current=null,k==null||k(!1)},[]);const O=k=>{var ee,P;if(!R)return;k.preventDefault();const v=t==="bottom"?k.clientY:k.clientX,ae=U,J=t==="left"?1:-1,Y=k.currentTarget,re=k.pointerId;(ee=Y.setPointerCapture)==null||ee.call(Y,re);const ce=Z=>{const pe=t==="bottom"?Z.clientY:Z.clientX;R(t,ae+(pe-v)*J)},g=Z=>{var pe,Te;window.removeEventListener("pointermove",ce),window.removeEventListener("pointerup",F),window.removeEventListener("pointercancel",F),(pe=Y.hasPointerCapture)!=null&&pe.call(Y,re)&&((Te=Y.releasePointerCapture)==null||Te.call(Y,re)),Z&&E(!1),x.current=null},F=()=>g(!0);(P=x.current)==null||P.call(x,!0),x.current=g,E(!0),window.addEventListener("pointermove",ce),window.addEventListener("pointerup",F,{once:!0}),window.addEventListener("pointercancel",F,{once:!0})};if(!q){const k=s?`展开${s}`:"展开面板",v=t==="left"?"›":t==="right"?"‹":"︿";return e.createElement("button",{type:"button",className:["rge-panel-dock__reopen",`rge-panel-dock__reopen--${t}`,u].filter(Boolean).join(" "),title:k,"aria-label":k,"data-editor-dock-reopen":t,onClick:()=>d==null?void 0:d(t,!0)},e.createElement("span",{"aria-hidden":"true"},v))}return e.createElement("section",{ref:b,className:["rge-panel-dock",`rge-panel-dock--${t}`,_&&"is-resizing",u].filter(Boolean).join(" "),style:t==="bottom"?{height:U}:{width:U},"aria-label":s},e.createElement("div",{className:"rge-panel-dock__header"},C?e.createElement("strong",{className:"rge-panel-dock__title"},s||"模块"):e.createElement("div",{className:"rge-panel-dock__tabs",role:"tablist"},W.map(k=>e.createElement("button",{key:k.id,type:"button",role:"tab","aria-selected":k.id===B,className:k.id===B?"is-active":"",onClick:()=>p==null?void 0:p(k.id)},k.icon&&e.createElement("span",{"aria-hidden":"true"},k.icon),k.title||k.id))),e.createElement("button",{type:"button",className:"rge-panel-dock__close",title:s?`收起${s}`:"收起面板","aria-label":s?`收起${s}`:"收起面板",onClick:()=>d==null?void 0:d(t,!1)},"×")),e.createElement("div",{className:"rge-panel-dock__body"},C?W.map(k=>e.createElement("div",{key:k.id,className:"rge-panel-dock__stack-panel"},(()=>{const v=ur(n,k);return e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-panel-dock__stack-title"},e.createElement("span",null,k.title||k.id),e.createElement("button",{type:"button",title:v?"收起内容":"展开内容","aria-label":`${v?"收起":"展开"}${k.title||k.id}`,"aria-expanded":v,onClick:()=>w==null?void 0:w(k.id,!v)},v?"−":"+"),k.closeable!==!1&&e.createElement("button",{type:"button",title:"关闭面板","aria-label":`关闭${k.title||k.id}`,onClick:()=>S==null?void 0:S(k.id)},"×")),e.createElement("div",{className:"rge-panel-dock__panel-content",hidden:!v},o==null?void 0:o(k)))})())):W.map(k=>e.createElement("div",{key:k.id,className:`rge-panel-dock__tab-panel${ur(n,k)?"":" is-collapsed"}`,hidden:k.id!==B},e.createElement("div",{className:"rge-panel-dock__tab-tools"},e.createElement("button",{type:"button",title:ur(n,k)?"收起内容":"展开内容","aria-label":`${ur(n,k)?"收起":"展开"}${k.title||k.id}`,"aria-expanded":ur(n,k),onClick:()=>w==null?void 0:w(k.id,!ur(n,k))},ur(n,k)?"−":"+"),k.closeable!==!1&&e.createElement("button",{type:"button",title:"关闭面板","aria-label":`关闭${k.title||k.id}`,onClick:()=>S==null?void 0:S(k.id)},"×")),e.createElement("div",{className:"rge-panel-dock__tab-content",hidden:!ur(n,k)},o==null?void 0:o(k))))),e.createElement("div",{className:"rge-panel-dock__resize",role:"separator","aria-orientation":t==="bottom"?"horizontal":"vertical",onPointerDown:O}))}function _s({visible:t=!0,x:r,y:n,flipDown:o=!1,targetId:s,showRun:u=!0,nodeType:d,className:p="",onAction:S,onEdit:w,onCopy:R,onDelete:b,onRunFrom:x,onRunOnly:_,locale:E,messages:W,t:B}){const U=e.useMemo(()=>Ge({locale:E,messages:W,t:B}),[E,W,B]);if(!t||!s)return null;const q=u&&y.isEditorNodeRunTarget(d||"simple-node"),C=(j,k)=>{(j==="run-from"||j==="run-only")&&!q||(k==null||k(s),S==null||S(j,s))},O=(j,k,v,ae,J="")=>e.createElement("button",{key:j,type:"button",className:`rge-hover-tools__button ${J}`,title:k,"aria-label":k,onClick:()=>C(j,ae)},e.createElement(be,{value:v}));return e.createElement("div",{className:["rge-hover-tools","rge-node-hover-tools",o?"is-flip-down":"",p].filter(Boolean).join(" "),style:{left:r,top:n},role:"toolbar","aria-label":U("editor.hoverTools.nodeActions","节点操作")},O("edit",U("editor.hoverTools.edit","编辑节点"),"edit",w),O("copy",U("editor.hoverTools.copy","复制节点"),"copy",R),q&&O("run-from",U("editor.hoverTools.runFrom","从此节点开始执行"),"play",x,"is-primary"),q&&O("run-only",U("editor.hoverTools.runOnly","仅执行此节点"),"play-single",_,"is-warning"),O("delete",U("editor.hoverTools.delete","删除节点"),"delete",b,"is-danger"))}function vs({visible:t=!0,x:r,y:n,flipDown:o=!1,targetId:s,className:u="",onAction:d,onInsertNode:p,onDelete:S,locale:w,messages:R,t:b}){const x=e.useMemo(()=>Ge({locale:w,messages:R,t:b}),[w,R,b]);if(!t||!s)return null;const _=(B,U)=>{U==null||U(s),d==null||d(B,s)},E=x("editor.hoverTools.insertNode","在连线中插入组件"),W=x("editor.hoverTools.deleteEdge","删除连线");return e.createElement("div",{className:["rge-hover-tools","rge-edge-hover-tools",o?"is-flip-down":"",u].filter(Boolean).join(" "),style:{left:r,top:n},role:"toolbar","aria-label":x("editor.hoverTools.edgeActions","连线操作")},e.createElement("button",{type:"button",className:"rge-hover-tools__button is-primary",title:E,"aria-label":E,onClick:()=>_("insert-node",p)},e.createElement(be,{value:"add"})),e.createElement("button",{type:"button",className:"rge-hover-tools__button is-danger",title:W,"aria-label":W,onClick:()=>_("delete",S)},e.createElement(be,{value:"delete"})))}const Gr={error:"error",warning:"warning",info:"docs"},$a=({items:t,isValid:r,visible:n=!0,loading:o=!1,title:s,onValidate:u,onItemClick:d,onClose:p,onClear:S,locale:w,messages:R,t:b})=>{const[x,_]=e.useState("all"),E=e.useMemo(()=>Ge({locale:w,messages:R,t:b}),[w,R,b]),W=s||E("editor.validation.title","规则链校验"),B=e.useMemo(()=>{const q={error:0,warning:0,info:0};return t.forEach(C=>{q[C.level]!==void 0&&q[C.level]++}),q},[t]),U=e.useMemo(()=>x==="all"?t:t.filter(q=>q.level===x),[t,x]);return n?e.createElement("div",{className:"rge-validation-panel"},e.createElement("div",{className:"rge-validation-header"},e.createElement("span",{className:"rge-validation-title"},r!==void 0&&e.createElement(be,{value:r?"validate":"error"}),W),e.createElement("div",{className:"rge-validation-actions"},u&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:u,disabled:o,title:E("editor.validation.revalidate","重新校验")},e.createElement(be,{value:"refresh",className:o?"is-spinning":""}),E("editor.validation.validate","校验")),S&&t.length>0&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:S,title:E("editor.validation.clearResults","清除结果")},e.createElement(be,{value:"delete"})),p&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:p,title:E("editor.validation.close","关闭")},"✕"))),e.createElement("div",{className:"rge-validation-stats"},e.createElement("button",{className:`rge-validation-stat ${x==="all"?"active":""}`,onClick:()=>_("all")},E("editor.validation.all","全部")," (",t.length,")"),e.createElement("button",{className:`rge-validation-stat error ${x==="error"?"active":""}`,onClick:()=>_("error")},e.createElement(be,{value:Gr.error})," ",B.error),e.createElement("button",{className:`rge-validation-stat warning ${x==="warning"?"active":""}`,onClick:()=>_("warning")},e.createElement(be,{value:Gr.warning})," ",B.warning),e.createElement("button",{className:`rge-validation-stat info ${x==="info"?"active":""}`,onClick:()=>_("info")},e.createElement(be,{value:Gr.info})," ",B.info)),e.createElement("div",{className:"rge-validation-body"},o&&e.createElement("div",{className:"rge-validation-loading"},e.createElement(be,{value:"refresh",className:"is-spinning"}),E("editor.validation.validating","正在校验...")),!o&&U.length===0&&e.createElement("div",{className:"rge-validation-empty"},t.length===0?e.createElement(e.Fragment,null,e.createElement(be,{value:"validate"})," ",E("editor.validation.empty","无校验结果,请点击校验按钮开始")):E("editor.validation.noFilteredResults","当前筛选无结果")),!o&&U.map((q,C)=>e.createElement("div",{key:`${q.rule}-${q.elementId||C}`,className:`rge-validation-item level-${q.level}`,onClick:()=>d==null?void 0:d(q),role:"button",tabIndex:0},e.createElement("span",{className:"rge-validation-item-icon"},e.createElement(be,{value:Gr[q.level]})),e.createElement("div",{className:"rge-validation-item-content"},e.createElement("div",{className:"rge-validation-item-message"},q.message),e.createElement("div",{className:"rge-validation-item-meta"},e.createElement("span",{className:"rge-validation-item-rule"},q.rule),q.elementId&&e.createElement("span",{className:"rge-validation-item-element"},e.createElement(be,{value:q.elementType==="node"?"package":"link"}),q.elementId))))))):null};$a.displayName="ValidationPanel";const pa={error:0,warning:1,info:2},Cs={error:"editor.problems.error",warning:"editor.problems.warning",info:"editor.problems.info"};function Ns(t){return t.elementId?`${t.elementType||"element"}:${t.elementId}`:"chain"}function ks(t,r){return t.elementId?t.elementType==="edge"?`${r("editor.problems.edge","连线")} ${t.elementId}`:`${r("editor.problems.node","节点")} ${t.elementId}`:r("editor.problems.chain","规则链")}function Fa({items:t,visible:r=!0,loading:n=!1,title:o,onValidate:s,onLocate:u,onClear:d,onClose:p,locale:S,messages:w,t:R}){const[b,x]=e.useState("all"),_=e.useMemo(()=>Ge({locale:S,messages:w,t:R}),[S,w,R]),E=e.useMemo(()=>t.reduce((C,O)=>(C[O.severity]+=1,C),{error:0,warning:0,info:0}),[t]),W=e.useMemo(()=>{const C=new Map;return t.filter(O=>b==="all"||O.severity===b).forEach(O=>{const j=Ns(O),k=C.get(j)||[];k.push(O),C.set(j,k)}),Array.from(C.entries()).map(([O,j])=>({key:O,items:j.sort((k,v)=>pa[k.severity]-pa[v.severity])}))},[b,t]);if(!r)return null;const B=o||_("editor.problems.title","链路诊断"),U=C=>_(Cs[C],C==="error"?"错误":C==="warning"?"警告":"提示"),q=(C,O,j,k="")=>e.createElement("button",{type:"button",className:`rge-problems__filter ${k} ${b===C?"is-active":""}`,"aria-pressed":b===C,onClick:()=>x(C)},O," ",e.createElement("span",null,j));return e.createElement("section",{className:"rge-problems","aria-label":B},e.createElement("header",{className:"rge-problems__header"},e.createElement("div",{className:"rge-problems__heading"},e.createElement("strong",null,B),e.createElement("span",{className:"rge-problems__total"},t.length)),e.createElement("div",{className:"rge-problems__actions"},s&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:s,disabled:n,title:_("editor.problems.validate","重新校验")},n?"…":"↻"),d&&t.length>0&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:d,title:_("editor.problems.clear","清除问题")},"⌫"),p&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:p,title:_("editor.problems.close","关闭")},"×"))),e.createElement("div",{className:"rge-problems__filters",role:"toolbar","aria-label":_("editor.problems.filter","筛选问题")},q("all",_("editor.problems.all","全部"),t.length),q("error",U("error"),E.error,"is-error"),q("warning",U("warning"),E.warning,"is-warning"),q("info",U("info"),E.info,"is-info")),e.createElement("div",{className:"rge-problems__body"},n&&e.createElement("div",{className:"rge-problems__empty"},_("editor.problems.loading","正在校验…")),!n&&W.length===0&&e.createElement("div",{className:"rge-problems__empty"},t.length?_("editor.problems.noFiltered","当前筛选无问题"):_("editor.problems.empty","未发现链路问题")),!n&&W.map(C=>{const O=C.items[0];return e.createElement("div",{className:"rge-problems__group",key:C.key},e.createElement("button",{type:"button",className:"rge-problems__group-heading",onClick:()=>u==null?void 0:u(O)},e.createElement("span",{className:`rge-problems__marker is-${O.severity}`,"aria-hidden":"true"}),e.createElement("span",{className:"rge-problems__group-label"},ks(O,(j,k)=>_(j,k))),e.createElement("span",{className:"rge-problems__group-count"},C.items.length)),C.items.map(j=>e.createElement("button",{type:"button",className:`rge-problems__item is-${j.severity}`,key:j.id,onClick:()=>u==null?void 0:u(j)},e.createElement("span",{className:"rge-problems__item-severity"},U(j.severity)),e.createElement("span",{className:"rge-problems__item-message"},j.message),e.createElement("span",{className:"rge-problems__item-rule"},j.rule))))})))}Fa.displayName="ProblemsPanel";const ja=({visible:t,data:r,readOnly:n=!1,title:o,customFields:s=[],onSave:u,onClose:d,locale:p,messages:S,t:w})=>{const[R,b]=e.useState(r),[x,_]=e.useState({}),E=e.useMemo(()=>Ge({locale:p,messages:S,t:w}),[p,S,w]),W=o||E("editor.ruleChainSettings.title","规则链设置");e.useEffect(()=>{b(r),_({})},[r,t]);const B=(C,O)=>{b(j=>({...j,[C]:O})),x[C]&&_(j=>{const k={...j};return delete k[C],k})},U=()=>{const C={};return(!R.name||R.name.trim()==="")&&(C.name=E("editor.ruleChainSettings.nameRequired","规则链名称不能为空")),_(C),Object.keys(C).length===0},q=()=>{n||U()&&(u==null||u(R),d())};return e.useEffect(()=>{const C=O=>{O.key==="Escape"&&t&&d()};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[t,d]),t?e.createElement("div",{className:"rge-modal-overlay",onClick:d},e.createElement("div",{className:"rge-modal",onClick:C=>C.stopPropagation()},e.createElement("div",{className:"rge-modal-header"},e.createElement("span",{className:"rge-modal-title"},e.createElement(be,{value:"settings"})," ",W),e.createElement("button",{className:"rge-modal-close",onClick:d},"✕")),e.createElement("div",{className:"rge-modal-body"},R.id&&e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},"ID"),e.createElement("input",{className:"rge-form-input",value:R.id,disabled:!0})),e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},E("editor.panel.name","名称")," ",e.createElement("span",{className:"rge-required"},"*")),e.createElement("input",{className:`rge-form-input ${x.name?"error":""}`,value:R.name,onChange:C=>B("name",C.target.value),placeholder:E("editor.ruleChainSettings.namePlaceholder","请输入规则链名称"),disabled:n}),x.name&&e.createElement("span",{className:"rge-form-error"},x.name)),e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},E("editor.panel.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",value:R.description||"",onChange:C=>B("description",C.target.value),placeholder:E("editor.ruleChainSettings.descriptionPlaceholder","请输入规则链描述"),rows:3,disabled:n})),e.createElement("div",{className:"rge-form-row"},e.createElement("div",{className:"rge-form-group inline"},e.createElement("label",{className:"rge-form-label"},E("editor.ruleChainSettings.root","根链")),e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:R.root||!1,onChange:C=>B("root",C.target.checked),disabled:n}),e.createElement("span",{className:"rge-switch-slider"}))),e.createElement("div",{className:"rge-form-group inline"},e.createElement("label",{className:"rge-form-label"},E("editor.panel.debugMode","调试模式")),e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:R.debugMode||!1,onChange:C=>B("debugMode",C.target.checked),disabled:n}),e.createElement("span",{className:"rge-switch-slider"})))),s.map(C=>e.createElement("div",{className:"rge-form-group",key:C.key},e.createElement("label",{className:"rge-form-label"},C.label),C.type==="text"&&e.createElement("input",{className:"rge-form-input",value:String((R[C.key]??C.defaultValue)||""),onChange:O=>B(C.key,O.target.value),placeholder:C.placeholder,disabled:n}),C.type==="number"&&e.createElement("input",{className:"rge-form-input",type:"number",value:R[C.key]??C.defaultValue??"",onChange:O=>B(C.key,Number(O.target.value)),placeholder:C.placeholder,disabled:n}),C.type==="textarea"&&e.createElement("textarea",{className:"rge-form-textarea",value:String((R[C.key]??C.defaultValue)||""),onChange:O=>B(C.key,O.target.value),placeholder:C.placeholder,rows:3,disabled:n}),C.type==="select"&&e.createElement(nr,{value:String((R[C.key]??C.defaultValue)||""),options:C.options||[],onChange:O=>B(C.key,O),disabled:n,placeholder:C.placeholder,searchPlaceholder:E("editor.property.searchOptions","搜索选项..."),noMatchText:E("editor.property.noMatchingOptions","没有匹配的选项")}),C.type==="switch"&&e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:R[C.key]??C.defaultValue??!1,onChange:O=>B(C.key,O.target.checked),disabled:n}),e.createElement("span",{className:"rge-switch-slider"})),C.help&&e.createElement("span",{className:"rge-form-help"},C.help))),R.additionalInfo&&Object.keys(R.additionalInfo).length>0&&e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},E("editor.ruleChainSettings.additionalInfo","额外配置 (JSON)")),e.createElement("textarea",{className:"rge-form-textarea mono",value:JSON.stringify(R.additionalInfo,null,2),onChange:C=>{try{B("additionalInfo",JSON.parse(C.target.value))}catch{}},rows:5,disabled:n}))),e.createElement("div",{className:"rge-modal-footer"},e.createElement("button",{className:"rge-btn secondary",onClick:d},E("editor.panel.cancel","取消")),!n&&e.createElement("button",{className:"rge-btn primary",onClick:q},e.createElement(be,{value:"save"})," ",E("editor.toolbar.save","保存"))))):null};ja.displayName="RuleChainSettings";const Ot=({name:t,className:r=""})=>{const n=y.getEditorToolbarIconSvg(t);return n?e.createElement("span",{className:`rge-controlled-icon ${r}`.trim(),"aria-hidden":"true",dangerouslySetInnerHTML:{__html:n}}):null},ws=({mode:t="export",data:r,chainName:n="rule-chain",onImport:o,onClose:s,onNotify:u,locale:d,messages:p,t:S})=>{var ce,g,F,ee,P,Z,pe,Te,Pe;const[w,R]=e.useState(t),[b,x]=e.useState(""),[_,E]=e.useState(null),[W,B]=e.useState(""),[U,q]=e.useState(!1),C=e.useRef(null),O=e.useMemo(()=>Ge({locale:d,messages:p,t:S}),[d,p,S]),j=r?JSON.stringify(r,null,2):"",k=e.useCallback(_e=>{B(""),x(_e);try{const me=JSON.parse(_e);if(!me.ruleChain&&!me.metadata){B(O("editor.importExport.invalidRuleChainJson","JSON 格式不符合 RuleGo 规则链规范(缺少 ruleChain 或 metadata 字段)")),E(null);return}E(me)}catch(me){B(O("editor.importExport.jsonParseFailed","JSON 解析失败: {{message}}",{message:me.message})),E(null)}},[O]),v=e.useCallback(_e=>{var ne;const me=(ne=_e.target.files)==null?void 0:ne[0];if(!me)return;if(!me.name.endsWith(".json")){B(O("editor.importExport.selectJsonFile","请选择 .json 文件"));return}const H=new FileReader;H.onload=M=>{var xe;const ge=(xe=M.target)==null?void 0:xe.result;k(ge)},H.readAsText(me)},[k]),ae=e.useCallback(_e=>{var ne;_e.preventDefault(),q(!1);const me=(ne=_e.dataTransfer.files)==null?void 0:ne[0];if(!me)return;if(!me.name.endsWith(".json")){B(O("editor.importExport.selectJsonFile","请选择 .json 文件"));return}const H=new FileReader;H.onload=M=>{var xe;const ge=(xe=M.target)==null?void 0:xe.result;k(ge)},H.readAsText(me)},[k]),J=e.useCallback(()=>{navigator.clipboard.writeText(j).then(()=>{u==null||u("success",O("editor.importExport.copied","已复制到剪贴板"))}).catch(()=>{const _e=document.createElement("textarea");_e.value=j,document.body.appendChild(_e),_e.select(),document.execCommand("copy"),document.body.removeChild(_e),u==null||u("success",O("editor.importExport.copied","已复制到剪贴板"))})},[j,u,O]),Y=e.useCallback(()=>{const me=`${n.replace(/[^a-zA-Z0-9_\-\u4e00-\u9fa5]/g,"_")}_${new Date().toISOString().slice(0,10)}.json`,H=new Blob([j],{type:"application/json"}),ne=URL.createObjectURL(H),M=document.createElement("a");M.href=ne,M.download=me,document.body.appendChild(M),M.click(),document.body.removeChild(M),URL.revokeObjectURL(ne),u==null||u("success",O("editor.importExport.downloaded","已下载: {{fileName}}",{fileName:me}))},[j,n,u,O]),re=e.useCallback(()=>{if(!_){u==null||u("error",O("editor.importExport.noImportData","没有可导入的数据"));return}o==null||o(_),u==null||u("success",O("editor.importExport.importSuccess","规则链导入成功")),s()},[_,o,u,s,O]);return e.createElement("div",{className:"rge-modal-overlay",onClick:_e=>{_e.target===_e.currentTarget&&s()}},e.createElement("div",{className:"rge-modal",style:{width:640}},e.createElement("div",{className:"rge-modal-header"},e.createElement("div",{className:"rge-modal-title"},e.createElement(Ot,{name:w==="export"?"export":"import"}),e.createElement("span",null,w==="export"?O("editor.importExport.exportTitle","导出规则链"):O("editor.importExport.importTitle","导入规则链"))),e.createElement("button",{type:"button",className:"rge-modal-close",onClick:s},"✕")),e.createElement("div",{className:"rge-ie-tabs"},e.createElement("button",{type:"button",className:`rge-ie-tab ${w==="export"?"active":""}`,onClick:()=>R("export")},e.createElement(Ot,{name:"export"}),e.createElement("span",null,O("editor.importExport.exportTab","导出"))),e.createElement("button",{type:"button",className:`rge-ie-tab ${w==="import"?"active":""}`,onClick:()=>R("import")},e.createElement(Ot,{name:"import"}),e.createElement("span",null,O("editor.importExport.importTab","导入")))),e.createElement("div",{className:"rge-modal-body"},w==="export"?e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-ie-info"},e.createElement("span",null,e.createElement(Ot,{name:"package"}),O("editor.importExport.nodes","节点"),": ",((g=(ce=r==null?void 0:r.metadata)==null?void 0:ce.nodes)==null?void 0:g.length)||0),e.createElement("span",null,e.createElement(Ot,{name:"link"}),O("editor.importExport.edges","连线"),": ",((ee=(F=r==null?void 0:r.metadata)==null?void 0:F.connections)==null?void 0:ee.length)||0),e.createElement("span",null,e.createElement(Ot,{name:"data"}),O("editor.importExport.size","大小"),": ",(j.length/1024).toFixed(1)," KB")),e.createElement("pre",{className:"rge-ie-preview"},j)):e.createElement(e.Fragment,null,e.createElement("div",{className:`rge-ie-dropzone ${U?"dragover":""} ${b?"has-file":""}`,onDragOver:_e=>{_e.preventDefault(),q(!0)},onDragLeave:()=>q(!1),onDrop:ae,onClick:()=>{var _e;return(_e=C.current)==null?void 0:_e.click()}},e.createElement("input",{ref:C,type:"file",accept:".json",style:{display:"none"},onChange:v}),b?e.createElement("span",{className:"rge-ie-file-name"},e.createElement(Ot,{name:"validate"}),O("editor.importExport.fileLoaded","文件已加载,点击重新选择")):e.createElement(e.Fragment,null,e.createElement(Ot,{name:"import",className:"rge-ie-drop-icon"}),e.createElement("span",{className:"rge-ie-drop-text"},O("editor.importExport.dropHint","拖拽 JSON 文件到此处,或点击选择文件")))),W&&e.createElement("div",{className:"rge-ie-error",role:"alert"},W),_&&e.createElement("div",{className:"rge-ie-import-info"},e.createElement("div",{className:"rge-ie-info"},e.createElement("span",null,e.createElement(Ot,{name:"package"}),O("editor.importExport.nodes","节点"),": ",((Z=(P=_==null?void 0:_.metadata)==null?void 0:P.nodes)==null?void 0:Z.length)||0),e.createElement("span",null,e.createElement(Ot,{name:"link"}),O("editor.importExport.edges","连线"),": ",((Te=(pe=_==null?void 0:_.metadata)==null?void 0:pe.connections)==null?void 0:Te.length)||0),e.createElement("span",null,e.createElement(Ot,{name:"edit"}),O("editor.importExport.name","名称"),": ",((Pe=_==null?void 0:_.ruleChain)==null?void 0:Pe.name)||O("editor.status.unknown","未知"))),e.createElement("pre",{className:"rge-ie-preview",style:{maxHeight:200}},JSON.stringify(_,null,2))))),e.createElement("div",{className:"rge-modal-footer"},e.createElement("button",{type:"button",className:"rge-btn secondary",onClick:s},O("editor.panel.cancel","取消")),w==="export"?e.createElement(e.Fragment,null,e.createElement("button",{type:"button",className:"rge-btn secondary",onClick:J},e.createElement(Ot,{name:"copy"}),e.createElement("span",null,O("editor.panel.copy","复制"))),e.createElement("button",{type:"button",className:"rge-btn primary",onClick:Y},e.createElement(Ot,{name:"export"}),e.createElement("span",null,O("editor.importExport.downloadFile","下载文件")))):e.createElement("button",{type:"button",className:"rge-btn primary",onClick:re,disabled:!_},e.createElement(Ot,{name:"import"}),e.createElement("span",null,O("editor.importExport.confirmImport","确认导入"))))))};function ga(t,r){if(!r)return t;const n=t.toLowerCase(),o=r.toLowerCase(),s=n.indexOf(o);return s===-1?t:e.createElement(e.Fragment,null,t.slice(0,s),e.createElement("mark",{className:"rge-search-highlight"},t.slice(s,s+r.length)),t.slice(s+r.length))}const Ss=({nodes:t,onSelectNode:r,onClose:n,position:o="top-center",locale:s,messages:u,t:d})=>{const[p,S]=e.useState(""),[w,R]=e.useState(0),b=e.useRef(null),x=e.useMemo(()=>Ge({locale:s,messages:u,t:d}),[s,u,d]);e.useEffect(()=>{var U;(U=b.current)==null||U.focus()},[]);const _=e.useMemo(()=>{if(!p.trim())return[];const U=p.toLowerCase().trim();return t.filter(q=>q.name.toLowerCase().includes(U)||q.type.toLowerCase().includes(U)||q.id.toLowerCase().includes(U)||q.typeLabel&&q.typeLabel.toLowerCase().includes(U)||q.extra&&q.extra.toLowerCase().includes(U))},[t,p]),E=e.useCallback(U=>{switch(U.key){case"ArrowDown":U.preventDefault(),R(q=>Math.min(q+1,_.length-1));break;case"ArrowUp":U.preventDefault(),R(q=>Math.max(q-1,0));break;case"Enter":U.preventDefault(),_[w]&&(r==null||r(_[w].id));break;case"Escape":U.preventDefault(),n();break}},[_,w,r,n]),W=e.useCallback(U=>{S(U.target.value),R(0)},[]),B=e.useCallback(U=>{r==null||r(U)},[r]);return e.createElement("div",{className:`rge-search-panel ${o}`},e.createElement("div",{className:"rge-search-input-wrapper"},e.createElement("span",{className:"rge-search-icon","aria-hidden":"true"}),e.createElement("input",{ref:b,type:"text",className:"rge-search-input",placeholder:x("editor.searchPanel.placeholder","搜索节点名称、类型或 ID..."),value:p,onChange:W,onKeyDown:E}),p&&e.createElement("span",{className:"rge-search-count"},x("editor.searchPanel.resultCount","{{count}} 个结果",{count:_.length})),e.createElement("button",{className:"rge-search-close",onClick:n},"✕")),p&&_.length>0&&e.createElement("div",{className:"rge-search-results"},_.map((U,q)=>e.createElement("div",{key:U.id,className:`rge-search-result-item ${q===w?"active":""}`,onClick:()=>B(U.id),onMouseEnter:()=>R(q)},e.createElement("div",{className:"rge-search-result-main"},e.createElement("span",{className:"rge-search-result-name"},ga(U.name,p)),e.createElement("span",{className:"rge-search-result-type"},U.typeLabel||U.type)),e.createElement("div",{className:"rge-search-result-id"},"ID: ",ga(U.id,p))))),p&&_.length===0&&e.createElement("div",{className:"rge-search-empty"},e.createElement("span",{className:"rge-search-icon","aria-hidden":"true"}),x("editor.searchPanel.empty","没有找到匹配的节点")))};function xs({chains:t,chainData:r={},loadChain:n,offline:o=!1,onSelectChain:s,onSelectNode:u,locale:d,messages:p,t:S}){const w=e.useMemo(()=>Ge({locale:d,messages:p,t:S}),[d,p,S]),[R,b]=e.useState(""),[x,_]=e.useState([]),[E,W]=e.useState(new Set),[B,U]=e.useState(!1),[q,C]=e.useState({completed:0,total:0}),[O,j]=e.useState(!1),[k,v]=e.useState({}),ae=e.useRef({}),J=e.useRef(null),Y=e.useRef(null),re=e.useMemo(()=>y.createLocalGlobalSearchGroups(()=>t.map(F=>({...F,data:ae.current[F.id]??r[F.id]??F.data})),n?async(F,ee)=>{const P=await n(F,ee);return ae.current={...ae.current,[F]:P},v(ae.current),P}:void 0),[t,r,n]);e.useEffect(()=>{var ee;(ee=Y.current)==null||ee.abort();const F=new AbortController;return Y.current=F,W(new Set),U(!1),j(!1),R.trim()?(re.searchGroups(R,{signal:F.signal}).then(P=>{F.signal.aborted||_(P)}).catch(()=>{}),()=>F.abort()):(_([]),()=>F.abort())},[R,re]),e.useEffect(()=>()=>{var F;return(F=Y.current)==null?void 0:F.abort()},[]),e.useEffect(()=>{var F,ee;(F=J.current)==null||F.focus(),(ee=J.current)==null||ee.select()},[]);const ce=async()=>{var ee;if(!n||o||B||!R.trim())return;(ee=Y.current)==null||ee.abort();const F=new AbortController;Y.current=F,U(!0),j(!1);try{const P=await re.searchGroups(R,{scanAll:!0,signal:F.signal,onProgress:C});F.signal.aborted||(_(P),j(!0))}finally{Y.current===F&&U(!1)}},g=F=>W(ee=>{const P=new Set(ee);return P.has(F)?P.delete(F):P.add(F),P});return e.createElement("section",{className:"rge-cross-search","aria-label":w("editor.crossSearch.title","跨规则链搜索")},e.createElement("div",{className:"rge-cross-search__head"},e.createElement("input",{ref:J,value:R,onChange:F=>b(F.target.value),placeholder:w("editor.crossSearch.placeholder","搜索链名、节点或配置值..."),"aria-label":w("editor.crossSearch.input","跨规则链搜索")}),R&&e.createElement("button",{type:"button","aria-label":w("editor.crossSearch.clear","清除"),onClick:()=>b("")},"×")),e.createElement("p",{className:"rge-cross-search__tip"},B?`${w("editor.crossSearch.scanning","扫描")} ${q.completed}/${q.total}`:O?w("editor.crossSearch.scanned",`已索引全部 ${t.length} 条`):`${w("editor.crossSearch.loaded","已索引")} ${t.filter(F=>y.isGlobalSearchDataLoaded(k[F.id]??r[F.id]??F.data)).length}/${t.length}`,B&&e.createElement("button",{type:"button",onClick:()=>{var F;return(F=Y.current)==null?void 0:F.abort()}},w("editor.crossSearch.stop","停止")),!B&&!O&&n&&!o&&R.trim()&&e.createElement("button",{type:"button",onClick:()=>void ce()},w("editor.crossSearch.scanAll","扫描全部"))),!R.trim()&&e.createElement("div",{className:"rge-cross-search__empty"},w("editor.crossSearch.start","输入关键词开始搜索")),R.trim()&&!x.length&&e.createElement("div",{className:"rge-cross-search__empty"},w("editor.crossSearch.empty","无匹配")),e.createElement("ul",{className:"rge-cross-search__groups"},x.map(F=>{const ee=E.has(F.chainId);return e.createElement("li",{key:F.chainId},e.createElement("div",{className:"rge-cross-search__chain",onClick:()=>g(F.chainId),onDoubleClick:()=>s==null?void 0:s(F.chainId),title:F.chainId},e.createElement("span",{"aria-hidden":"true"},ee?"›":"⌄"),e.createElement("strong",null,F.chainName),F.nodes.length+F.endpoints.length>0&&e.createElement("em",null,F.nodes.length+F.endpoints.length)),!ee&&e.createElement("ul",null,F.endpoints.map(P=>e.createElement("li",{key:`endpoint-${P.id}`,onClick:()=>s==null?void 0:s(F.chainId)},e.createElement("span",null,w("editor.crossSearch.endpoint","端点")," ",P.type),e.createElement("code",null,P.id),P.excerpt&&e.createElement("small",null,P.excerpt))),F.nodes.map(P=>e.createElement("li",{key:P.id,onClick:()=>u==null?void 0:u(F.chainId,P.id)},e.createElement("span",null,P.name),e.createElement("code",null,P.type),P.excerpt&&e.createElement("small",null,P.excerpt)))))})))}const Rs={design:"edit",info:"docs",start:"play",stop:"stop",copy:"copy",delete:"delete",search:"search",refresh:"refresh",add:"add",workflow:"arrange",subWorkflow:"link",logs:"data"},Ts=/[\\/.]/,yn=180,En=260,Fr=12,fa=new WeakMap;let Is=1;const sn=t=>{const r=fa.get(t);if(r!==void 0)return r;const n=Is++;return fa.set(t,n),n},Rr=(t,r=new WeakSet)=>{if(typeof t=="function")return`[reference:${sn(t)}]`;if(!t||typeof t!="object")return t;if(r.has(t))return`[circular:${sn(t)}]`;if(r.add(t),Array.isArray(t))return t.map(o=>Rr(o,r));const n=t;return Object.keys(n).sort().reduce((o,s)=>(o[s]=Rr(n[s],r),o),{})},In=t=>t===void 0?"[default]":JSON.stringify(t),Ps=t=>{if(!t)return"-";const r=new Date(t);if(Number.isNaN(r.getTime()))return t;const n=o=>String(o).padStart(2,"0");return`${r.getFullYear()}/${n(r.getMonth()+1)}/${n(r.getDate())} ${n(r.getHours())}:${n(r.getMinutes())}:${n(r.getSeconds())}`},Ds=(t,r)=>{var o;const n=(o=t.additionalInfo)==null?void 0:o[r];return typeof n=="string"?n:""},Ls=(t,r,n)=>{if(!t)return"";const o=r||{};return JSON.stringify({apiBase:t,apiContextKey:In(n),timeout:o.timeout,authToken:o.authToken,headers:Rr(o.headers),credentials:o.credentials,customFetch:Rr(o.customFetch),onAuthRequired:Rr(o.onAuthRequired),serverStatus:o.serverStatus?`[reference:${sn(o.serverStatus)}]`:void 0,includeStoredToken:o.includeStoredToken,routes:Rr(o.routes)})},Ms=t=>{const{apiBase:r,apiOptions:n,apiContextKey:o,fetcher:s,pageSize:u=10,layout:d="grid",autoOpenAfterCreate:p,theme:S="default",className:w="",style:R,icons:b,showSearch:x=!0,showCreate:_=!0,showRefresh:E=!0,disabled:W=!1,disabledMessage:B,locale:U,messages:q,t:C,renderHeader:O,renderActions:j,renderEmpty:k,renderCreateForm:v,renderRow:ae,onDesign:J,onInfo:Y,onViewLogs:re,onChange:ce,onError:g,onCreateSuccess:F}=t,ee={...Rs,...b},P=e.useMemo(()=>Ge({locale:U,messages:q,t:C}),[U,q,C]),Z=e.useRef(null),pe=e.useRef(""),Te=Ls(r,n,o),Pe=s?`external:${sn(s)}`:"";s?(Z.current!==s||pe.current!==Pe)&&(Z.current=s,pe.current=Pe):r?(!Z.current||pe.current!==Te)&&(Z.current=new y.RuleChainAPI({apiBase:r,...n}),pe.current=Te):Z.current&&(Z.current=null,pe.current="");const _e=Z.current,me=s?`${Pe}|context:${In(o)}`:r?`internal:${Te}`:`none:${In(o)}`,H=e.useRef({api:null,identity:"",disabled:!1,generation:0});(H.current.api!==_e||H.current.identity!==me||H.current.disabled!==W)&&(H.current={api:_e,identity:me,disabled:W,generation:H.current.generation+1});const ne=e.useRef(!1),M=e.useRef(0),ge=e.useRef(0),[xe,se]=e.useState([]),[Ce,Re]=e.useState(0),[K,le]=e.useState(1),de=u,[z,G]=e.useState(""),[ye,ke]=e.useState(!1),[$e,at]=e.useState(!1),[qe,X]=e.useState(""),[He,_t]=e.useState(null),[xt,$t]=e.useState(null),[T,Ie]=e.useState(()=>y.RuleChainAPI.generateChainId()),[tt,vt]=e.useState(""),[ft,Kt]=e.useState(""),[Tt,dt]=e.useState(!0),[pt,Ht]=e.useState(!1),[Rt,Wt]=e.useState(!0),[Je,Zt]=e.useState(""),[Pt,Jt]=e.useState(()=>p??!!J),[Ft,bt]=e.useState(""),[Dt,ht]=e.useState(null),[jt,Ct]=e.useState(null),Lt=jt===H.current.generation,Mt=Lt?xe:[],ue=Lt?Ce:0,ve=e.useRef({page:K,keywords:z,onError:g});ve.current={page:K,keywords:z,onError:g};const Se=e.useRef({onChange:ce,onError:g,onCreateSuccess:F,onDesign:J});Se.current={onChange:ce,onError:g,onCreateSuccess:F,onDesign:J};const f=e.useCallback(V=>ne.current&&H.current===V,[]),fe=e.useCallback((V,Ee)=>f(V)&&ge.current===Ee,[f]);e.useEffect(()=>(ne.current=!0,()=>{ne.current=!1,M.current+=1,ge.current+=1}),[]),e.useEffect(()=>{ge.current+=1,ht(null)},[me,W]);const we=e.useCallback(()=>{_t(null),$t(null)},[]);e.useEffect(()=>{X(""),le(1),we(),at(!1),bt("")},[me,W,we]);const We=e.useCallback((V,Ee)=>{if(V.stopPropagation(),He===Ee){we();return}const l=V.currentTarget.getBoundingClientRect(),m=window.innerWidth||document.documentElement.clientWidth||yn,I=window.innerHeight||document.documentElement.clientHeight||En,L=Math.max(Fr,m-yn-Fr),oe=Math.min(Math.max(Fr,l.right-yn),L);let je=l.bottom+8;je+En>I-Fr&&(je=Math.max(Fr,l.top-En-8)),_t(Ee),$t({id:Ee,top:je,left:oe})},[we,He]);e.useEffect(()=>{if(!He)return;const V=l=>{var I;const m=l.target;(I=m==null?void 0:m.closest)!=null&&I.call(m,".huanban_rulego_list__actions--floating, .huanban_rulego_list__row_more")||we()},Ee=l=>{l.key==="Escape"&&we()};return document.addEventListener("pointerdown",V),document.addEventListener("keydown",Ee),window.addEventListener("resize",we),window.addEventListener("scroll",we,!0),()=>{document.removeEventListener("pointerdown",V),document.removeEventListener("keydown",Ee),window.removeEventListener("resize",we),window.removeEventListener("scroll",we,!0)}},[we,He]);const Fe=e.useCallback(()=>{Ie(y.RuleChainAPI.generateChainId()),vt(""),Kt(""),dt(!0),Ht(!1),Wt(!0),Zt(""),Jt(p??!!J),bt("")},[p,J]),ie=e.useCallback(()=>{Fe(),at(!0)},[Fe]),wt=e.useCallback(()=>{at(!1),bt("")},[]),rt=e.useCallback(async(V,Ee)=>{var je,nt;const l=H.current,m=l.api,{page:I,keywords:L}=ve.current;if(!m||l.disabled){f(l)&&ke(!1);return}const oe=++M.current;ke(!0);try{const ze=await m.list(V??I,de,Ee??L);if(!f(l)||M.current!==oe)return;se(ze.items),Re(ze.total),Ct(l.generation)}catch(ze){if(!f(l)||M.current!==oe)return;(nt=(je=ve.current).onError)==null||nt.call(je,ze instanceof Error?ze:new Error(String(ze)))}finally{f(l)&&M.current===oe&&ke(!1)}},[f,de]);e.useEffect(()=>{if(W){M.current+=1,ke(!1);return}rt(1)},[me,W,rt]);const It=e.useCallback(()=>{le(1),rt(1,z),we()},[we,z,rt]),yt=e.useCallback(V=>{V.key==="Enter"&&It()},[It]),st=Math.max(1,Math.ceil(ue/de)),er=e.useCallback(()=>{K>1&&(le(K-1),rt(K-1))},[K,rt]),ct=e.useCallback(()=>{K<st&&(le(K+1),rt(K+1))},[K,st,rt]),At=e.useCallback(async(V,Ee)=>{var L,oe,je,nt,ze,Qe;const l=H.current,m=l.api;if(!m||l.disabled)return;const I=++ge.current;ht(V);try{const Ue=await m.operate(V,Ee);if(!fe(l,I))return;if(!Ue.success){(oe=(L=Se.current).onError)==null||oe.call(L,new Error(Ue.msg||P("editor.workflowList.operateFailed","操作失败")));return}if(we(),await rt(),!fe(l,I))return;(nt=(je=Se.current).onChange)==null||nt.call(je)}catch(Ue){fe(l,I)&&((Qe=(ze=Se.current).onError)==null||Qe.call(ze,Ue instanceof Error?Ue:new Error(String(Ue))))}finally{fe(l,I)&&ht(null)}},[we,fe,rt,P]),dr=e.useCallback(async V=>{var I,L,oe,je,nt,ze;const Ee=H.current,l=Ee.api;if(!l||Ee.disabled)return;const m=++ge.current;ht(V);try{const Qe=await l.copy(V);if(!fe(Ee,m))return;if(!Qe.success){(L=(I=Se.current).onError)==null||L.call(I,new Error(Qe.msg||P("editor.workflowList.copyFailed","复制失败")));return}if(we(),await rt(),!fe(Ee,m))return;(je=(oe=Se.current).onChange)==null||je.call(oe)}catch(Qe){fe(Ee,m)&&((ze=(nt=Se.current).onError)==null||ze.call(nt,Qe instanceof Error?Qe:new Error(String(Qe))))}finally{fe(Ee,m)&&ht(null)}},[we,fe,rt,P]),{confirm:pr}=Br(H.current.generation,P),sr=e.useCallback(async(V,Ee)=>{var L,oe,je,nt,ze,Qe;const l=H.current;try{if(!await pr(P("editor.workflowList.confirmDelete","确定删除工作流「{{name}}」吗?此操作不可恢复。",{name:Ee}))||!f(l))return}catch{return}const m=l.api;if(!m||l.disabled)return;const I=++ge.current;ht(V);try{const Ue=await m.remove(V);if(!fe(l,I))return;if(!Ue.success){(oe=(L=Se.current).onError)==null||oe.call(L,new Error(Ue.msg||P("editor.workflowList.deleteFailed","删除失败")));return}if(we(),await rt(),!fe(l,I))return;(nt=(je=Se.current).onChange)==null||nt.call(je)}catch(Ue){fe(l,I)&&((Qe=(ze=Se.current).onError)==null||Qe.call(ze,Ue instanceof Error?Ue:new Error(String(Ue))))}finally{fe(l,I)&&ht(null)}},[we,fe,rt,P]),gt=e.useCallback(async V=>{var je,nt,ze,Qe,Ue,it,Gt,Ke;const Ee=H.current,l=Ee.api;if(!l||Ee.disabled)return;const m=++ge.current,I=T.trim();if(!V){if(!I||Ts.test(I)){bt(P("editor.workflowList.idInvalid","ID 不能为空,且不能包含 /、\\ 或 ."));return}bt("")}const L=new Date().toISOString(),oe=V||{ruleChain:{id:I,name:tt.trim()||P("editor.workflowList.defaultName","新工作流"),root:Tt,disabled:Rt,debugMode:pt,additionalInfo:{description:ft.trim(),category:Je.trim(),createTime:L,updateTime:L,debugMode:pt}},metadata:{firstNodeIndex:0,nodes:[],connections:[],endpoints:[]}};try{const Ae=await l.create(oe);if(!fe(Ee,m))return;if(!Ae.success){(nt=(je=Se.current).onError)==null||nt.call(je,new Error(Ae.msg||P("editor.workflowList.createFailed","创建失败")));return}if(at(!1),Fe(),await rt(),!fe(Ee,m))return;(Qe=(ze=Se.current).onChange)==null||Qe.call(ze);const Yt=oe.ruleChain,Vt=String((Yt==null?void 0:Yt.id)??"");Vt&&((it=(Ue=Se.current).onCreateSuccess)==null||it.call(Ue,Vt)),Vt&&Pt&&Se.current.onDesign&&Se.current.onDesign(Vt)}catch(Ae){fe(Ee,m)&&((Ke=(Gt=Se.current).onError)==null||Ke.call(Gt,Ae instanceof Error?Ae:new Error(String(Ae))))}},[T,tt,ft,Tt,Rt,pt,Je,rt,Pt,Fe,f,fe,P]),Ut=e.useCallback(V=>{X(V.id),we(),Y==null||Y(V)},[we,Y]),Ye=e.useCallback((V,Ee)=>{if(V.key==="Enter"){V.preventDefault(),J&&J(Ee.id);return}V.key===" "&&(V.preventDefault(),Ut(Ee))},[Ut,J]),ar=V=>{const Ee=Dt===V.id;return e.createElement(e.Fragment,null,J&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--design",disabled:Ee,onClick:l=>{l.stopPropagation(),we(),J(V.id)},title:P("editor.workflowList.design","设计")},e.createElement(be,{value:ee.design})," ",e.createElement("span",null,P("editor.workflowList.design","设计"))),Y&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--info",disabled:Ee,onClick:l=>{l.stopPropagation(),Ut(V)},title:P("editor.workflowList.info","信息")},e.createElement(be,{value:ee.info})," ",e.createElement("span",null,P("editor.workflowList.info","信息"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--operate",disabled:Ee,onClick:l=>{l.stopPropagation(),At(V.id,V.deployed?"stop":"start")},title:V.deployed?P("editor.workflowList.offlineAction","下线"):P("editor.workflowList.onlineAction","部署")},e.createElement(be,{value:V.deployed?ee.stop:ee.start}),e.createElement("span",null,V.deployed?P("editor.workflowList.offlineAction","下线"):P("editor.workflowList.onlineAction","部署"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--copy",disabled:Ee,onClick:l=>{l.stopPropagation(),dr(V.id)},title:P("editor.panel.copy","复制")},e.createElement(be,{value:ee.copy})," ",e.createElement("span",null,P("editor.panel.copy","复制"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--delete",disabled:Ee,onClick:l=>{l.stopPropagation(),sr(V.id,V.name)},title:P("editor.panel.delete","删除")},e.createElement(be,{value:ee.delete})," ",e.createElement("span",null,P("editor.panel.delete","删除"))),re&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--logs",disabled:Ee,onClick:l=>{l.stopPropagation(),we(),re(V.id,V)},title:P("editor.workflowList.logs","日志")},e.createElement(be,{value:ee.logs})," ",e.createElement("span",null,P("editor.workflowList.logs","日志"))))},Ve=(V,Ee="huanban_rulego_list__actions")=>e.createElement("div",{className:Ee},ar(V)),qt=(V,Ee)=>{const l=Ve(V),m=j?j(V,l):l,I=qe===V.id,L=V.deployed?P("editor.workflowList.online","运行"):P("editor.workflowList.offline","停用"),oe=Ds(V,"category");return e.createElement("article",{className:`huanban_rulego_list__row ${V.deployed?"huanban_rulego_list__row--deployed":"huanban_rulego_list__row--offline"} ${I?"huanban_rulego_list__row--selected":""}`,key:V.id,"data-id":V.id,role:"button",tabIndex:0,title:P("editor.workflowList.rowHint","单击查看信息,双击进入设计"),onClick:()=>Ut(V),onDoubleClick:()=>J==null?void 0:J(V.id),onKeyDown:je=>Ye(je,V)},e.createElement("div",{className:"huanban_rulego_list__row_main"},e.createElement("span",{className:`huanban_rulego_list__row_icon ${V.root?"huanban_rulego_list__row_icon--root":"huanban_rulego_list__row_icon--sub"}`},e.createElement(be,{value:V.root?ee.workflow:ee.subWorkflow})),e.createElement("div",{className:"huanban_rulego_list__row_info"},e.createElement("span",{className:"huanban_rulego_list__row_name"},V.name),e.createElement("span",{className:"huanban_rulego_list__row_id"},V.id),(oe||V.root)&&e.createElement("span",{className:"huanban_rulego_list__row_meta"},V.root?P("editor.workflowList.rootChain","主链"):P("editor.workflowList.subChain","子链"),oe?` · ${oe}`:"")),e.createElement("div",{className:`huanban_rulego_list__row_menu ${He===V.id?"huanban_rulego_list__row_menu--open":""}`},e.createElement("button",{className:"huanban_rulego_list__row_more",type:"button",title:P("editor.workflowList.more","更多操作"),onClick:je=>{We(je,V.id)}},"•••"),d==="list"?m:null)),V.description&&e.createElement("div",{className:"huanban_rulego_list__row_desc"},V.description),e.createElement("div",{className:"huanban_rulego_list__row_footer"},e.createElement("span",{className:"huanban_rulego_list__row_time"},P("editor.workflowList.updateTime","更新时间"),": ",Ps(V.updateTime||V.createTime)),e.createElement("span",{className:`huanban_rulego_list__row_status ${V.deployed?"huanban_rulego_list__row_status--on":"huanban_rulego_list__row_status--off"}`},L)))},De=e.createElement("div",{className:"huanban_rulego_list__header"},e.createElement("h3",{className:"huanban_rulego_list__title"},e.createElement(be,{value:ee.workflow})," ",P("editor.workflowList.title","工作流列表"),e.createElement("span",{className:"huanban_rulego_list__count"},"(",ue,")")),e.createElement("div",{className:"huanban_rulego_list__toolbar"},x&&e.createElement("div",{className:"huanban_rulego_list__search"},e.createElement("input",{className:"huanban_rulego_list__search_input",type:"text",placeholder:P("editor.workflowList.searchPlaceholder","搜索工作流..."),value:z,onChange:V=>G(V.target.value),onKeyDown:yt}),e.createElement("button",{className:"huanban_rulego_list__search_btn",onClick:It,title:P("editor.toolbar.searchNode","搜索")},e.createElement(be,{value:ee.search}))),E&&e.createElement("button",{className:"huanban_rulego_list__toolbar_btn",onClick:()=>rt(),title:P("editor.chainSelector.refresh","刷新"),disabled:ye||W},e.createElement(be,{value:ee.refresh})),_&&e.createElement("button",{className:"huanban_rulego_list__toolbar_btn huanban_rulego_list__toolbar_btn--primary",onClick:ie,title:P("editor.workflowList.createTitle","新建工作流"),disabled:W},e.createElement(be,{value:ee.add})," ",P("editor.workflowList.create","新建")))),gr=e.createElement("div",{className:"huanban_rulego_list__form"},e.createElement("div",{className:"huanban_rulego_list__form_grid"},e.createElement("label",{className:"huanban_rulego_list__form_label"},P("editor.workflowList.id","ID"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:T,onChange:V=>{Ie(V.target.value),bt("")},placeholder:P("editor.workflowList.idPlaceholder","规则链 ID,不可包含 /、\\ 或 ."),autoFocus:!0})),e.createElement("label",{className:"huanban_rulego_list__form_label"},P("editor.panel.name","名称"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:tt,onChange:V=>vt(V.target.value),placeholder:P("editor.workflowList.namePlaceholder","输入工作流名称")}))),e.createElement("div",{className:"huanban_rulego_list__form_group"},e.createElement("span",{className:"huanban_rulego_list__form_group_label"},P("editor.workflowList.chainType","规则链类型")),e.createElement("div",{className:"huanban_rulego_list__segmented",role:"group"},e.createElement("button",{type:"button",className:Tt?"active":"",onClick:()=>dt(!0)},P("editor.workflowList.rootChain","主链")),e.createElement("button",{type:"button",className:Tt?"":"active",onClick:()=>dt(!1)},P("editor.workflowList.subChain","子链")))),e.createElement("div",{className:"huanban_rulego_list__form_group"},e.createElement("span",{className:"huanban_rulego_list__form_group_label"},P("editor.workflowList.initialStatus","初始状态")),e.createElement("div",{className:"huanban_rulego_list__segmented",role:"group"},e.createElement("button",{type:"button",className:Rt?"active":"",onClick:()=>Wt(!0)},P("editor.workflowList.initialStopped","停用")),e.createElement("button",{type:"button",className:Rt?"":"active",onClick:()=>Wt(!1)},P("editor.workflowList.initialRunning","运行")))),e.createElement("label",{className:"huanban_rulego_list__form_switch",title:P("editor.workflowList.debugModeHint","开启后每条消息都会记录调试日志,并覆盖节点调试配置;会影响运行性能,生产环境建议关闭。编辑器手动调试不受影响。")},e.createElement("input",{type:"checkbox",checked:pt,onChange:V=>Ht(V.target.checked)}),e.createElement("span",null,P("editor.workflowList.debugMode","调试模式"))),e.createElement("label",{className:"huanban_rulego_list__form_label"},P("editor.workflowList.category","分类"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:Je,onChange:V=>Zt(V.target.value),placeholder:P("editor.workflowList.categoryPlaceholder","可选分类,如 IoT / AI / 数据同步")})),e.createElement("label",{className:"huanban_rulego_list__form_label"},P("editor.panel.description","描述"),e.createElement("textarea",{className:"huanban_rulego_list__form_textarea",value:ft,onChange:V=>Kt(V.target.value),placeholder:P("editor.workflowList.descriptionPlaceholder","可选描述"),rows:3})),J&&e.createElement("label",{className:"huanban_rulego_list__form_switch"},e.createElement("input",{type:"checkbox",checked:Pt,onChange:V=>Jt(V.target.checked)}),e.createElement("span",null,P("editor.workflowList.openAfterCreate","创建后进入编辑器"))),Ft&&e.createElement("div",{className:"huanban_rulego_list__form_error"},Ft)),fr=e.createElement("div",{className:"huanban_rulego_list__empty"},e.createElement("span",{className:"huanban_rulego_list__empty_icon"},e.createElement(be,{value:ee.workflow})),e.createElement("p",null,P("editor.workflowList.empty","暂无工作流")),_&&e.createElement("button",{className:"huanban_rulego_list__empty_btn",onClick:ie},e.createElement(be,{value:ee.add})," ",P("editor.workflowList.createFirst","创建第一个工作流"))),ot=y.normalizeEditorTheme(S),zt=ot!=="default"?`huanban_rulego_list--${ot}`:"",mt=y.getThemeRuntimeVariables(ot),Xe=He?Mt.find(V=>V.id===He):void 0,Oe=d==="grid"&&xt&&Xe&&typeof document<"u"?en.createPortal(j?e.createElement("div",{className:"huanban_rulego_list__actions huanban_rulego_list__actions--floating",style:{...mt,top:xt.top,left:xt.left},onClick:V=>V.stopPropagation(),onPointerDown:V=>V.stopPropagation()},j(Xe,Ve(Xe))):e.createElement("div",{className:"huanban_rulego_list__actions huanban_rulego_list__actions--floating",style:{...mt,top:xt.top,left:xt.left},onClick:V=>V.stopPropagation(),onPointerDown:V=>V.stopPropagation()},ar(Xe)),document.body):null;return e.createElement("div",{className:`huanban_rulego_list huanban_rulego_list--layout-${d} ${zt} ${w}`.trim(),"data-theme":ot,"data-rg-theme":ot,style:{...mt,...R}},O?O(De):De,e.createElement("div",{className:"huanban_rulego_list__body"},W&&e.createElement("div",{className:"huanban_rulego_list__empty"},e.createElement("span",{className:"huanban_rulego_list__empty_icon"},e.createElement(be,{value:ee.workflow})),e.createElement("p",null,B||P("editor.workflowList.loginRequired","请先登录后查看工作流。"))),!W&&ye&&e.createElement("div",{className:"huanban_rulego_list__loading"},e.createElement("span",{className:"huanban_rulego_list__spinner"}),P("editor.panel.loading","加载中...")),!W&&!ye&&Mt.length===0&&(k?k():fr),!W&&!ye&&Mt.length>0&&e.createElement("div",{className:`huanban_rulego_list__rows huanban_rulego_list__rows--${d}`},Mt.map((V,Ee)=>{const l=qt(V);return ae?e.createElement(e.Fragment,{key:V.id},ae(V,Ee,l)):e.createElement(e.Fragment,{key:V.id},l)}))),Oe,!W&&ue>de&&e.createElement("div",{className:"huanban_rulego_list__pagination"},e.createElement("button",{className:"huanban_rulego_list__page_btn",disabled:K<=1,onClick:er},P("editor.chainSelector.prevPage","上一页")),e.createElement("span",{className:"huanban_rulego_list__page_info"},K," / ",st),e.createElement("button",{className:"huanban_rulego_list__page_btn",disabled:K>=st,onClick:ct},P("editor.chainSelector.nextPage","下一页"))),$e&&e.createElement("div",{className:"huanban_rulego_list__modal_mask",onClick:wt},e.createElement("div",{className:"huanban_rulego_list__modal",onClick:V=>V.stopPropagation()},e.createElement("div",{className:"huanban_rulego_list__modal_header"},e.createElement("h4",null,P("editor.workflowList.createTitle","新建工作流")),e.createElement("button",{className:"huanban_rulego_list__modal_close",onClick:wt},"✕")),e.createElement("div",{className:"huanban_rulego_list__modal_body"},v?v(gr,{close:wt,submit:V=>gt(V)}):gr),e.createElement("div",{className:"huanban_rulego_list__modal_footer"},e.createElement("button",{className:"huanban_rulego_list__btn huanban_rulego_list__btn--cancel",onClick:wt},P("editor.panel.cancel","取消")),e.createElement("button",{className:"huanban_rulego_list__btn huanban_rulego_list__btn--primary",onClick:()=>gt()},Pt&&J?P("editor.workflowList.createAndOpen","创建并打开"):P("editor.workflowList.create","创建"))))))},As=28;function Ba(t,r,n=0){const o=[];return t.forEach(s=>{var u;o.push({node:s,depth:n}),(u=s.children)!=null&&u.length&&r.has(s.key)&&o.push(...Ba(s.children,r,n+1))}),o}function Os({workflows:t,store:r,persistence:n,activeChainId:o="",keyword:s,placeholder:u="搜索规则链",emptyText:d="暂无规则链",className:p="",style:S,onKeywordChange:w,onOpen:R,virtualization:b}){const x=e.useMemo(()=>r?null:new y.ExplorerTreeStore({persistence:n,workflows:t,activeChainId:o,keyword:s}),[r,n==null?void 0:n.adapter,n==null?void 0:n.namespace.host,n==null?void 0:n.namespace.editorInstance,n==null?void 0:n.namespace.version]),_=r||x,[E,W]=e.useState(()=>_.getState()),[B,U]=e.useState(s||""),[q,C]=e.useState(0),O=e.useRef(null);e.useEffect(()=>_.subscribe(W),[_]),e.useEffect(()=>()=>{x==null||x.destroy()},[x]),e.useEffect(()=>{_.setWorkflows(t)},[_,t]),e.useEffect(()=>{_.setActiveChainId(o)},[_,o]),e.useEffect(()=>{s===void 0||s===B||(U(s),_.setKeyword(s))},[s,B,_]);const j=e.useMemo(()=>Ba(E.tree,new Set(E.expandedKeys)),[E.tree,E.expandedKeys]),k=e.useMemo(()=>({enabled:(b==null?void 0:b.enabled)!==!1,threshold:Math.max(1,(b==null?void 0:b.threshold)??y.DEFAULT_VIRTUAL_WINDOW_THRESHOLD),itemHeight:Math.max(1,(b==null?void 0:b.itemHeight)??As),viewportHeight:Math.max(1,(b==null?void 0:b.viewportHeight)??y.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),overscan:Math.max(0,(b==null?void 0:b.overscan)??y.DEFAULT_VIRTUAL_WINDOW_OVERSCAN)}),[b==null?void 0:b.enabled,b==null?void 0:b.threshold,b==null?void 0:b.itemHeight,b==null?void 0:b.viewportHeight,b==null?void 0:b.overscan]),v=k.enabled&&j.length>k.threshold,ae=e.useMemo(()=>y.calculateVirtualWindow({total:j.length,itemHeight:k.itemHeight,viewportHeight:k.viewportHeight,scrollTop:q,overscan:k.overscan}),[j.length,k,q]),J=v?j.slice(ae.start,ae.end):j,Y=e.useMemo(()=>j.findIndex(g=>{var F;return g.node.kind==="chain"&&((F=g.node.chain)==null?void 0:F.id)===o}),[j,o]);e.useEffect(()=>{if(!v||Y<0)return;const g=Math.floor(q/k.itemHeight),F=Math.ceil((q+k.viewportHeight)/k.itemHeight);let ee=q;Y<g?ee=Y*k.itemHeight:Y>=F&&(ee=(Y+1)*k.itemHeight-k.viewportHeight),ee!==q&&C(ee)},[o,Y,v,j,k.itemHeight,k.viewportHeight]),e.useEffect(()=>{const g=O.current;if(!g)return;const F=v?ae.scrollTop:0;g.scrollTop!==F&&(g.scrollTop=F)},[v,ae.scrollTop]);const re=g=>{U(g),_.setKeyword(g),w==null||w(g)},ce=({node:g,depth:F},ee)=>{var Te,Pe;const P=!!((Te=g.children)!=null&&Te.length),Z=E.expandedKeys.includes(g.key),pe=g.kind==="chain"&&((Pe=g.chain)==null?void 0:Pe.id)===o;return e.createElement("button",{key:g.key,type:"button",role:"treeitem","aria-level":F+1,"aria-posinset":ee+1,"aria-setsize":j.length,"aria-expanded":P?Z:void 0,"aria-selected":g.kind==="chain"?pe:void 0,className:`huanban_workflow_explorer__row is-${g.kind}${pe?" is-active":""}`,style:{paddingInlineStart:8+F*14},onClick:()=>{P?_.setExpanded(g.key,!Z):g.chain&&(R==null||R(g.chain))},title:g.chain?`${g.chain.name}
8
+ ${g.chain.id}`:g.label},e.createElement("span",{className:`huanban_workflow_explorer__chevron${P&&Z?" is-open":""}`,"aria-hidden":"true"}),e.createElement("span",{className:`huanban_workflow_explorer__kind is-${g.kind}`,"aria-hidden":"true"}),e.createElement("span",{className:"huanban_workflow_explorer__label"},g.label),g.kind==="chain"&&g.chain?e.createElement("span",{className:`huanban_workflow_explorer__status${g.chain.disabled?" is-offline":" is-online"}`,title:g.chain.disabled?"已下线":"运行中"}):null,g.count!==void 0?e.createElement("span",{className:"huanban_workflow_explorer__count"},g.count):null)};return e.createElement("section",{className:`huanban_workflow_explorer ${p}`.trim(),style:S,"aria-label":"规则链资源"},e.createElement("div",{className:"huanban_workflow_explorer__search"},e.createElement("span",{"aria-hidden":"true",className:"huanban_workflow_explorer__search_icon"}),e.createElement("input",{value:B,onChange:g=>re(g.target.value),placeholder:u,"aria-label":u}),B?e.createElement("button",{type:"button",className:"huanban_workflow_explorer__clear",onClick:()=>re(""),title:"清除搜索","aria-label":"清除搜索"},"×"):null),e.createElement("div",{ref:O,className:`huanban_workflow_explorer__tree${v?" is-virtualized":""}`,role:"tree","data-explorer-virtualized":v?"true":void 0,"data-explorer-virtual-total":v?j.length:void 0,style:v?{height:`${ae.viewportHeight}px`}:void 0,onScroll:g=>{if(!v)return;const F=g.currentTarget.scrollTop;C(ee=>ee===F?ee:F)}},j.length===0?e.createElement("div",{className:"huanban_workflow_explorer__empty"},d):v?e.createElement("div",{className:"huanban_workflow_explorer__virtual-canvas",style:{height:`${ae.totalHeight}px`}},e.createElement("div",{className:"huanban_workflow_explorer__virtual-items",style:{transform:`translateY(${ae.offsetTop}px)`}},J.map((g,F)=>ce(g,ae.start+F)))):j.map(ce)))}function Yr(t,r){return!t||t.length===0?e.createElement("div",{className:"huanban_rulego_info__maintenance_empty"},r("editor.maintenance.noIssues","未返回问题")):e.createElement("ul",{className:"huanban_rulego_info__maintenance_issues"},t.map(n=>e.createElement("li",{key:`${n.id}:${n.path||n.nodeId||""}`,className:`huanban_rulego_info__maintenance_issue huanban_rulego_info__maintenance_issue--${n.severity}`},e.createElement("strong",null,n.severity),e.createElement("span",null,n.message),n.path&&e.createElement("code",null,n.path),n.suggestion&&e.createElement("small",null,n.suggestion))))}const Ha=({workflow:t,fetcher:r,content:n,onError:o,locale:s,messages:u,t:d})=>{const[p,S]=e.useState(null),[w,R]=e.useState(null),[b,x]=e.useState(null),[_,E]=e.useState(null),[W,B]=e.useState(null),[U,q]=e.useState(null),C=e.useMemo(()=>n||{ruleChain:{id:t.id,name:t.name}},[n,t.id,t.name]),O=!!(r!=null&&r.validateUpstream&&(r!=null&&r.getSchemaDiff)&&(r!=null&&r.getRepairPlan)&&(r!=null&&r.previewPatch)),j=e.useMemo(()=>Ge({locale:s,messages:u,t:d}),[s,u,d]),k=e.useMemo(()=>({validate:j("editor.maintenance.runValidate","运行校验"),schemaDiff:j("editor.maintenance.schemaDiff","结构差异"),repairPlan:j("editor.maintenance.repairPlan","修复建议"),patchPreview:j("editor.maintenance.patchPreview","补丁预览")}),[j]),v=e.useCallback(async ae=>{if(!r||!O){R({type:"error",text:j("editor.maintenance.noApi","当前请求适配器未提供维护接口")});return}S(ae),R({type:"info",text:`${k[ae]}...`});try{switch(ae){case"validate":x(await r.validateUpstream(t.id,C));break;case"schemaDiff":E(await r.getSchemaDiff(t.id));break;case"repairPlan":B(await r.getRepairPlan(t.id,C));break;case"patchPreview":{const J=[];q(await r.previewPatch(t.id,C,J));break}}R({type:"success",text:`${k[ae]}${j("editor.maintenance.finished","已完成")}`})}catch(J){const Y=J instanceof Error?J:new Error(String(J));R({type:"error",text:`${k[ae]}${j("editor.maintenance.failed","失败")}: ${Y.message}`}),o==null||o(Y)}finally{S(null)}},[k,C,r,O,o,j,t.id]);return O?e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},j("editor.maintenance.title","维护验证")),e.createElement("div",{className:"huanban_rulego_info__maintenance_actions"},e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:p!==null,onClick:()=>v("validate")},p==="validate"?j("editor.maintenance.validating","校验中..."):j("editor.maintenance.runValidate","运行校验")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:p!==null,onClick:()=>v("schemaDiff")},j("editor.maintenance.schemaDiff","结构差异")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:p!==null,onClick:()=>v("repairPlan")},j("editor.maintenance.repairPlan","修复建议")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:p!==null,onClick:()=>v("patchPreview")},j("editor.maintenance.patchPreview","补丁预览"))),w&&e.createElement("div",{className:`huanban_rulego_info__maintenance_status huanban_rulego_info__maintenance_status--${w.type}`},w.text),b&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,j("editor.maintenance.validateResult","校验结果"),":",b.valid?j("editor.maintenance.valid","通过"):j("editor.maintenance.invalid","未通过")),Yr(b.issues,j)),_&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,j("editor.maintenance.schemaDiff","结构差异")),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(_.changes||[],null,2)),Yr(_.issues,j)),W&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,j("editor.maintenance.repairPlan","修复建议")),W.summary&&e.createElement("p",null,W.summary),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(W.plan||[],null,2)),Yr(W.issues,j)),U&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,j("editor.maintenance.patchPreview","补丁预览")),Yr(U.rejected,j),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(U.preview||{},null,2)))):e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},j("editor.maintenance.title","维护验证")),e.createElement("div",{className:"huanban_rulego_info__maintenance_empty"},j("editor.maintenance.noApi","当前请求适配器未提供维护接口")))},$s={variable:"package",secret:"key",api:"link",mcp:"grid",copy:"copy",delete:"delete",add:"add",save:"save"};function Wa(t){const r=(t||"/api/v1").replace(/\/+$/,"");return/^https?:\/\//i.test(r)||typeof window>"u"?r:`${window.location.origin}${r.startsWith("/")?r:`/${r}`}`}function Fs(t){return Wa(t).replace(/^https:/i,"wss:").replace(/^http:/i,"ws:")}const ba=new WeakMap;let js=1;const Pn=t=>{const r=ba.get(t);if(r!==void 0)return r;const n=js++;return ba.set(t,n),n},Tr=(t,r=new WeakSet)=>{if(typeof t=="function")return`[reference:${Pn(t)}]`;if(!t||typeof t!="object")return t;if(r.has(t))return`[circular:${Pn(t)}]`;if(r.add(t),Array.isArray(t))return t.map(o=>Tr(o,r));const n=t;return Object.keys(n).sort().reduce((o,s)=>(o[s]=Tr(n[s],r),o),{})},Bs=t=>t===void 0?"[default]":JSON.stringify(t),Hs=(t,r,n)=>{if(!t)return"";const o=r||{};return JSON.stringify({apiBase:t,apiContextKey:Bs(n),timeout:o.timeout,authToken:o.authToken,headers:Tr(o.headers),credentials:o.credentials,customFetch:Tr(o.customFetch),onAuthRequired:Tr(o.onAuthRequired),serverStatus:o.serverStatus?`[reference:${Pn(o.serverStatus)}]`:void 0,includeStoredToken:o.includeStoredToken,routes:Tr(o.routes)})};function Ws(t,r){const n=Wa(t),o=Fs(t),s=encodeURIComponent(r);return{executeUrl:`${n}/rules/${r}/execute/:msgType`,notifyUrl:`${n}/rules/${r}/notify/:msgType`,openaiUrl:`${n}/rules/${r}/v1/chat/completions`,mcpStreamableUrl:`${n}/mcp/:apiKey`,mcpGroupUrl:`${n}/mcp/:apiKey/group/:groupName`,mcpSseUrl:`${n}/mcp/${r}/sse`,debugWsUrl:`${o}/logs/ws/${s}/:clientId`,runtimeWsUrl:`${o}/logs/ws/system/:clientId?client_id=:clientId&device_id=:deviceId&client_instance_id=:clientInstanceId&profile_id=:profileId`,endpointWsHint:`${o}/huanban/ws/inbound/:endpointId/:msgType`}}function Zr(t){return t&&typeof t=="object"?t:{}}function Us(t){return t.length>0?Math.max(...t.map(r=>Number(r.order||0))):0}function qs(t,r,n,o){return y.updateSchemaRowsAtParent(t,r,s=>{const u=n+o;if(u<0||u>=s.length)return;const[d]=s.splice(n,1);if(!d)return;s.splice(u,0,d);const p=y.renumberSchemaRowOrders(s);s.splice(0,s.length,...p)})}function Ua(t){if(!t)return{type:"object",properties:{}};if(typeof t=="string")try{return Ua(JSON.parse(t))}catch{return{type:"object",properties:{}}}if(t&&typeof t=="object"&&!Array.isArray(t)){const r=t;return{type:r.type||"object",...r,properties:r.properties&&typeof r.properties=="object"&&!Array.isArray(r.properties)?r.properties:{}}}return{type:"object",properties:{}}}function ha(t,r,n){const o=Zr((r==null?void 0:r.ruleChain)??r),s=Zr(o.additionalInfo),d={...Zr(t.additionalInfo),...s,category:n.category,description:n.description,debugMode:n.debugMode,updateTime:new Date().toISOString()};return"inputSchema"in n&&(d.inputSchema=n.inputSchema),{...o,id:t.id,name:n.name||t.name,root:n.root,debugMode:n.debugMode,disabled:!!(o.disabled??t.disabled),createTime:String(o.createTime??t.createTime??""),updateTime:String(o.updateTime??t.updateTime??""),additionalInfo:d}}const ya=({translate:t,entries:r,onChange:n,icons:o,keyPlaceholder:s="Key",valuePlaceholder:u="Value",valueType:d="text",actionLabel:p="操作",deleteTitle:S="删除",addLabel:w="添加",batchDeleteLabel:R="批量删除",batchDeleteConfirm:b="确定删除选中的 {{count}} 项吗?",deleteConfirm:x="确定删除“{{key}}”吗?",selectLabel:_="选择",selectedCountLabel:E="已选择 {{count}} 项",selectRowLabel:W="选择第 {{index}} 项"})=>{const[B,U]=e.useState([]),q=e.useRef(null),{confirm:C}=Br([r,B],t),O=r.length>0&&B.length===r.length,j=B.length>0&&!O;e.useEffect(()=>{U(ce=>y.normalizeKeyValueSelection(ce,r.length))},[r.length]),e.useEffect(()=>{q.current&&(q.current.indeterminate=j)},[j]);const k=()=>n([...r,{key:"",value:""}]),v=async ce=>{var F;const g=x.replace("{{key}}",((F=r[ce])==null?void 0:F.key)||s);await C(g)&&(n(y.removeKeyValueEntriesAtIndexes(r,[ce])),U(ee=>ee.filter(P=>P!==ce).map(P=>P>ce?P-1:P)))},ae=ce=>{U(g=>g.includes(ce)?g.filter(F=>F!==ce):y.normalizeKeyValueSelection([...g,ce],r.length))},J=()=>{U(O?[]:r.map((ce,g)=>g))},Y=async()=>{if(!B.length)return;const ce=b.replace("{{count}}",String(B.length));await C(ce)&&(n(y.removeKeyValueEntriesAtIndexes(r,B)),U([]))},re=(ce,g,F)=>{const ee=[...r];ee[ce]={...ee[ce],[g]:F},n(ee)};return e.createElement("div",{className:"huanban_rulego_info__kv"},e.createElement("div",{className:"huanban_rulego_info__kv_toolbar"},e.createElement("label",{className:"huanban_rulego_info__kv_select_all"},e.createElement("input",{ref:q,type:"checkbox",checked:O,disabled:!r.length,onChange:J,"aria-label":_}),e.createElement("span",null,B.length?E.replace("{{count}}",String(B.length)):_)),e.createElement("button",{className:"huanban_rulego_info__kv_batch_del",type:"button",disabled:!B.length,onClick:Y},e.createElement(be,{value:o.delete})," ",R,B.length?` (${B.length})`:"")),r.length>0&&e.createElement("div",{className:"huanban_rulego_info__kv_row huanban_rulego_info__kv_header"},e.createElement("span",{className:"huanban_rulego_info__kv_checkbox_slot","aria-hidden":"true"}),e.createElement("span",{className:"huanban_rulego_info__kv_th"},s),e.createElement("span",{className:"huanban_rulego_info__kv_th"},u),e.createElement("span",{className:"huanban_rulego_info__kv_th huanban_rulego_info__kv_th--action"},p)),r.map((ce,g)=>e.createElement("div",{className:"huanban_rulego_info__kv_row",key:g},e.createElement("input",{className:"huanban_rulego_info__kv_checkbox",type:"checkbox",checked:B.includes(g),onChange:()=>ae(g),"aria-label":W.replace("{{index}}",String(g+1))}),e.createElement("input",{className:"huanban_rulego_info__kv_input",type:"text",placeholder:s,value:ce.key,onChange:F=>re(g,"key",F.target.value)}),e.createElement("input",{className:"huanban_rulego_info__kv_input",type:d,placeholder:u,value:ce.value,onChange:F=>re(g,"value",F.target.value)}),e.createElement("button",{className:"huanban_rulego_info__kv_del",onClick:()=>v(g),title:S},e.createElement(be,{value:o.delete})))),e.createElement("button",{className:"huanban_rulego_info__kv_add",onClick:k},e.createElement(be,{value:o.add})," ",w))},Vs=t=>{var Mt;const{apiBase:r,apiOptions:n,apiContextKey:o,fetcher:s,workflow:u,theme:d="default",className:p="",style:S,icons:w,defaultTab:R="base",showMaintenance:b=!1,renderBaseInfo:x,renderVarsSecrets:_,renderIntegration:E,renderExtraTabs:W,onSave:B,onError:U,onRefresh:q,locale:C,messages:O,t:j}=t,k={...$s,...w},v=e.useMemo(()=>Ge({locale:C,messages:O,t:j}),[C,O,j]),ae=e.useRef(null),J=e.useRef(""),Y=Hs(r,n,o);s?ae.current!==s&&(ae.current=s,J.current="external"):r?(!ae.current||J.current!==Y)&&(ae.current=new y.RuleChainAPI({apiBase:r,...n}),J.current=Y):ae.current&&(ae.current=null,J.current="");const re=ae.current,ce=e.useRef(re);ce.current=re;const[g,F]=e.useState(R),[ee,P]=e.useState(""),[Z,pe]=e.useState(!1),[Te,Pe]=e.useState(!1),[_e,me]=e.useState(""),[H,ne]=e.useState(""),[M,ge]=e.useState("visual"),[xe,se]=e.useState([]),[Ce,Re]=e.useState(`{
9
9
  "type": "object",
10
10
  "properties": {}
11
- }`),[xe,Ee]=e.useState(""),[Le,Se]=e.useState([]),[se,ae]=e.useState([]),[Ne,_e]=e.useState(!1),[J,Ae]=e.useState(null),tt=e.useRef(0);e.useEffect(()=>{var fe;const re=++tt.current;if(!i||!V){ue(""),ge(!1),Me(!1),b(""),Y(""),L("visual"),we([]),he(`{
11
+ }`),[K,le]=e.useState(""),[de,z]=e.useState([]),[G,ye]=e.useState([]),[ke,$e]=e.useState(!1),[at,qe]=e.useState(null),X=e.useRef(0),He=e.useRef(U),_t=e.useRef(v);He.current=U,_t.current=v,e.useEffect(()=>{var f;const ue=++X.current,ve=new AbortController,Se=ce.current;if(!u||!Se){P(""),pe(!1),Pe(!1),me(""),ne(""),ge("visual"),se([]),Re(`{
12
12
  "type": "object",
13
13
  "properties": {}
14
- }`),Ee(""),Se([]),ae([]),Ae(null);return}ue(i.name),ge(!!i.root),Me(!!i.debugMode),b(String(((fe=i.additionalInfo)==null?void 0:fe.category)??"")),Y(i.description),V.getContent(i.id).then(Ce=>{var Fe;if(re!==tt.current)return;Ae(Ce);const ye=(Ce==null?void 0:Ce.ruleChain)??Ce,De=(ye==null?void 0:ye.additionalInfo)??{};ge(!!((ye==null?void 0:ye.root)??i.root)),Me(!!((ye==null?void 0:ye.debugMode)??(De==null?void 0:De.debugMode)??i.debugMode)),b(String((De==null?void 0:De.category)??((Fe=i.additionalInfo)==null?void 0:Fe.category)??"")),Y(String((De==null?void 0:De.description)??i.description??""));try{const ft=De==null?void 0:De.inputSchema,h=Ra(ft);we(v.parseToolSchemaRows(h)),he(JSON.stringify(h,null,2)),Ee("")}catch{we([]),he(`{
14
+ }`),le(""),z([]),ye([]),qe(null);return}return P(u.name),pe(!!u.root),Pe(!!u.debugMode),me(String(((f=u.additionalInfo)==null?void 0:f.category)??"")),ne(u.description),Se.getContent(u.id,ve.signal).then(fe=>{var rt;if(ue!==X.current)return;qe(fe);const we=(fe==null?void 0:fe.ruleChain)??fe,We=(we==null?void 0:we.additionalInfo)??{};pe(!!((we==null?void 0:we.root)??u.root)),Pe(!!((we==null?void 0:we.debugMode)??(We==null?void 0:We.debugMode)??u.debugMode)),me(String((We==null?void 0:We.category)??((rt=u.additionalInfo)==null?void 0:rt.category)??"")),ne(String((We==null?void 0:We.description)??u.description??""));try{const It=We==null?void 0:We.inputSchema,yt=Ua(It);se(y.parseToolSchemaRows(yt)),Re(JSON.stringify(yt,null,2)),le("")}catch{se([]),Re(`{
15
15
  "type": "object",
16
16
  "properties": {}
17
- }`),Ee(u("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}const qe=Kn(ye==null?void 0:ye.configuration),d=qe.vars??(De==null?void 0:De.vars)??(ye==null?void 0:ye.vars)??{};Se(Object.entries(d).map(([ft,h])=>({key:ft,value:String(h)})));const ie=qe.secrets??(De==null?void 0:De.secrets)??(ye==null?void 0:ye.secrets)??{};ae(Object.entries(ie).map(([ft,h])=>({key:ft,value:String(h)})))}).catch(Ce=>{re===tt.current&&(O==null||O(Ce instanceof Error?Ce:new Error(String(Ce))))})},[i,V,O,u]);const z=e.useCallback(async()=>{if(!(!V||!i)){_e(!0);try{const re=await V.saveBaseInfo(i.id,ra(i,J,{name:le.trim(),root:W,debugMode:Pe,category:X.trim(),description:$.trim()}));if(!re.success)throw new Error(re.msg||u("editor.workflowInfo.saveFailed","保存失败"));j==null||j("base"),U==null||U()}catch(re){O==null||O(re instanceof Error?re:new Error(String(re)))}finally{_e(!1)}}},[V,i,J,le,W,Pe,X,$,j,O,U,u]),Ye=e.useCallback(re=>{if(te!==re){if(re==="code"){he(JSON.stringify(v.generateToolSchemaFromRows(ke),null,2)),Ee(""),L("code");return}try{const fe=v.parseToolSchemaRows(v.parseJsonObjectText(ne||"{}",{type:"object",properties:{}}));we(fe),Ee(""),L("visual")}catch(fe){Ee(fe instanceof Error?fe.message:u("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}}},[ne,te,ke,u]),ht=e.useCallback(re=>{we(re),he(JSON.stringify(v.generateToolSchemaFromRows(re),null,2)),Ee("")},[]),mt=e.useCallback((re,fe,Ce)=>{const ye=v.updateSchemaRowsAtParent(ke,re,De=>{De[fe]&&(De[fe]={...De[fe],...Ce,properties:Ce.type&&Ce.type!=="object"?[]:De[fe].properties,itemsProperties:Ce.type&&Ce.type!=="array"?[]:De[fe].itemsProperties})});ht(ye)},[ke,ht]),Vt=e.useCallback((re="")=>{const fe=v.updateSchemaRowsAtParent(ke,re,Ce=>{Ce.push(v.emptySchemaEditorRow(yl(Ce)+1))});ht(fe)},[ke,ht]),Bt=e.useCallback((re,fe)=>{const Ce=v.updateSchemaRowsAtParent(ke,re,ye=>{ye.splice(fe,1);const De=v.renumberSchemaRowOrders(ye);ye.splice(0,ye.length,...De)});ht(Ce)},[ke,ht]),jt=e.useCallback((re,fe,Ce)=>{ht(_l(ke,re,fe,Ce))},[ke,ht]),Pt=e.useCallback(async()=>{if(!V||!i)return;let re;try{re=te==="visual"?v.generateToolSchemaFromRows(ke):v.parseJsonObjectText(ne||"{}",{type:"object",properties:{}}),he(JSON.stringify(re,null,2)),te==="code"&&we(v.parseToolSchemaRows(re)),Ee("")}catch(fe){Ee(fe instanceof Error?fe.message:u("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"));return}_e(!0);try{const fe=await V.saveBaseInfo(i.id,ra(i,J,{name:le.trim()||i.name,root:W,debugMode:Pe,category:X.trim(),description:$.trim(),inputSchema:re}));if(!fe.success)throw new Error(fe.msg||u("editor.workflowInfo.saveFailed","保存失败"));j==null||j("inputSchema"),U==null||U()}catch(fe){O==null||O(fe instanceof Error?fe:new Error(String(fe)))}finally{_e(!1)}},[V,i,J,te,ke,ne,le,W,Pe,X,$,j,O,U,u]),Nt=e.useCallback(async re=>{if(!(!V||!i)){_e(!0);try{const fe=re==="vars"?Le:se,Ce={};fe.forEach(De=>{De.key.trim()&&(Ce[De.key.trim()]=De.value)});const ye=await V.saveConfig(i.id,re,Ce);if(!ye.success)throw new Error(ye.msg||u("editor.workflowInfo.saveFailed","保存失败"));j==null||j(re),U==null||U()}catch(fe){O==null||O(fe instanceof Error?fe:new Error(String(fe)))}finally{_e(!1)}}},[V,i,Le,se,j,O,U,u]),lt=e.useCallback(re=>{navigator.clipboard.writeText(re).catch(()=>{const fe=document.createElement("textarea");fe.value=re,document.body.appendChild(fe),fe.select(),document.execCommand("copy"),document.body.removeChild(fe)})},[]),vt=v.normalizeEditorTheme(m),xt=vt!=="default"?`huanban_rulego_info--${vt}`:"",Lt=v.getThemeRuntimeVariables(vt);if(!i)return e.createElement("div",{className:`huanban_rulego_info huanban_rulego_info--empty ${xt} ${f}`.trim(),"data-theme":vt,"data-rg-theme":vt,style:{...Lt,...M}},e.createElement("p",{className:"huanban_rulego_info__no_data"},u("editor.workflowInfo.noData","请选择一个工作流查看详情")));const Tt=n||((Re=V==null?void 0:V.getApiBase)==null?void 0:Re.call(V))||"",Ke=El(Tt,i.id),Rt=[{key:"base",label:u("editor.workflowInfo.baseInfo","基础信息"),icon:"docs"},{key:"inputSchema",label:u("editor.workflowInfo.inputDefinition","输入定义"),icon:"data"},{key:"vars",label:u("editor.workflowInfo.vars","变量"),icon:_.variable},{key:"integration",label:u("editor.workflowInfo.integration","应用集成"),icon:_.api},...g?[{key:"maintenance",label:u("editor.workflowInfo.maintenance","维护验证"),icon:"validate"}]:[]],At=F?F(i):[],Mt=[...Rt,...At.map(re=>({key:re.key,label:re.label,icon:void 0}))],Ot=Mt.some(re=>re.key===me)?me:"base",Ct=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("label",{className:"huanban_rulego_info__label"},u("editor.panel.name","名称"),e.createElement("input",{className:"huanban_rulego_info__input",type:"text",value:le,onChange:re=>ue(re.target.value)})),e.createElement("div",{className:"huanban_rulego_info__row"},e.createElement("span",{className:"huanban_rulego_info__field"},"ID: ",i.id)),e.createElement("div",{className:"huanban_rulego_info__switch_grid"},e.createElement("label",{className:"huanban_rulego_info__switch_row huanban_rulego_info__switch_row--readonly"},e.createElement("input",{type:"checkbox",checked:W,disabled:!0}),e.createElement("span",{className:"huanban_rulego_info__switch_text"},u("editor.workflowInfo.rootChain","根规则链"),e.createElement("small",null,u("editor.workflowInfo.rootChainHint","开启:主链;关闭:子链")))),e.createElement("label",{className:"huanban_rulego_info__switch_row"},e.createElement("input",{type:"checkbox",checked:Pe,onChange:re=>Me(re.target.checked)}),e.createElement("span",{className:"huanban_rulego_info__switch_text"},u("editor.workflowInfo.debugMode","调试模式"),e.createElement("small",null,u("editor.workflowInfo.debugModeHint","开启后每条消息都会记录调试日志,并覆盖节点调试配置;会影响运行性能,生产环境建议关闭。编辑器手动调试不受影响。"))))),e.createElement("label",{className:"huanban_rulego_info__label"},u("editor.workflowInfo.category","分类"),e.createElement("input",{className:"huanban_rulego_info__input",type:"text",placeholder:u("editor.workflowInfo.categoryPlaceholder","如 agent, iot, data-flow"),value:X,onChange:re=>b(re.target.value)})),e.createElement("label",{className:"huanban_rulego_info__label"},u("editor.panel.description","描述"),e.createElement("textarea",{className:"huanban_rulego_info__textarea",rows:3,value:$,onChange:re=>Y(re.target.value)})),e.createElement("div",{className:"huanban_rulego_info__row"},e.createElement("span",{className:`huanban_rulego_info__status ${i.deployed?"huanban_rulego_info__status--on":"huanban_rulego_info__status--off"}`},i.deployed?u("editor.workflowInfo.online","运行"):u("editor.workflowInfo.offline","停用"))),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:Ne,onClick:z},e.createElement(pe,{value:_.save})," ",Ne?u("editor.workflowInfo.saving","保存中..."):u("editor.workflowInfo.saveBaseInfo","保存基础信息"))),Te=(re,fe="")=>e.createElement("div",{className:"rge-tool-schema-rows"},re.length===0?e.createElement("div",{className:"rge-tool-schema-empty"},u("editor.property.noSchemaProperties","暂无属性,点击下方按钮添加")):re.map((Ce,ye)=>{const De=fe?`${fe}.${ye}`:String(ye),qe=Ce.type==="array"?`${De}.items`:De,d=Ce.type==="array"?Ce.itemsProperties:Ce.properties;return e.createElement("div",{key:De,className:"rge-tool-schema-row-wrap"},e.createElement("div",{className:"rge-tool-schema-row"},e.createElement("input",{className:"rge-form-input",value:Ce.name,placeholder:u("editor.property.propertyName","属性名"),onChange:ie=>mt(fe,ye,{name:ie.target.value})}),e.createElement("input",{className:"rge-form-input",value:Ce.title,placeholder:u("editor.property.title","标题"),onChange:ie=>mt(fe,ye,{title:ie.target.value})}),e.createElement("input",{className:"rge-form-input",value:Ce.description,placeholder:u("editor.property.description","描述"),onChange:ie=>mt(fe,ye,{description:ie.target.value})}),e.createElement("select",{className:"rge-form-select",value:Ce.type,onChange:ie=>mt(fe,ye,{type:ie.target.value})},v.TOOL_SCHEMA_TYPES.map(ie=>e.createElement("option",{key:ie,value:ie},ie))),e.createElement("input",{className:"rge-form-input",type:"number",min:0,value:Ce.order,onChange:ie=>mt(fe,ye,{order:Number(ie.target.value||ye+1)})}),e.createElement("label",{className:"rge-inline-checkbox rge-tool-schema-required"},e.createElement("input",{type:"checkbox",checked:Ce.required,onChange:ie=>mt(fe,ye,{required:ie.target.checked})}),e.createElement("span",null,u("editor.property.required","必填"))),e.createElement("div",{className:"rge-tool-schema-actions"},e.createElement("button",{type:"button",title:u("editor.property.moveUp","上移"),onClick:()=>jt(fe,ye,-1)},"↑"),e.createElement("button",{type:"button",title:u("editor.property.moveDown","下移"),onClick:()=>jt(fe,ye,1)},"↓"),e.createElement("button",{type:"button",className:"danger",title:u("editor.workflowInfo.delete","删除"),onClick:()=>Bt(fe,ye)},"×"))),Ce.type==="array"&&e.createElement("div",{className:"rge-tool-schema-nested-head"},e.createElement("span",null,u("editor.property.itemType","项目类型")),e.createElement("select",{className:"rge-form-select",value:Ce.itemsType||"string",onChange:ie=>mt(fe,ye,{itemsType:ie.target.value})},v.TOOL_SCHEMA_ITEM_TYPES.map(ie=>e.createElement("option",{key:ie,value:ie},ie)))),(Ce.type==="object"||Ce.type==="array")&&e.createElement("div",{className:"rge-tool-schema-nested"},e.createElement("div",{className:"rge-tool-schema-nested-title"},Ce.type==="array"?u("editor.property.arrayItems","数组项目"):u("editor.property.childProperties","子属性"),Ce.name?`: ${Ce.name}`:""),Ce.type==="array"&&(Ce.itemsType||"string")!=="object"?e.createElement("div",{className:"rge-tool-schema-empty rge-tool-schema-nested-empty"},u("editor.property.arrayNonObject","当前数组项目不是 object,无需配置项目属性。")):e.createElement(e.Fragment,null,Te(d||[],qe),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Vt(qe)},Ce.type==="array"?u("editor.property.addItemProperty","添加项目属性"):u("editor.property.addChildProperty","添加子属性")))))})),qt=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("div",{className:"rge-segmented-control rge-tool-schema-mode",role:"radiogroup"},e.createElement("button",{type:"button",className:`rge-segmented-option${te==="visual"?" active":""}`,onClick:()=>Ye("visual")},u("editor.workflowInfo.visualMode","可视化")),e.createElement("button",{type:"button",className:`rge-segmented-option${te==="code"?" active":""}`,onClick:()=>Ye("code")},u("editor.workflowInfo.codeMode","JSON代码"))),te==="visual"?e.createElement("div",{className:"rge-tool-schema-editor"},Te(ke),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Vt("")},u("editor.workflowInfo.addProperty","添加属性")),e.createElement("div",{className:"huanban_rulego_info__hint"},u("editor.workflowInfo.inputSchemaJsonHint","复杂嵌套 object/array 可切换到 JSON 代码模式编辑,已有嵌套结构会被保留。"))):e.createElement("label",{className:"huanban_rulego_info__label"},u("editor.workflowInfo.inputSchemaJson","输入定义 JSON"),e.createElement("textarea",{className:"huanban_rulego_info__textarea huanban_rulego_info__textarea--code rge-tool-schema-code",rows:14,spellCheck:!1,value:ne,onChange:re=>{he(re.target.value),Ee("")}})),xe&&e.createElement("div",{className:"huanban_rulego_info__maintenance_status huanban_rulego_info__maintenance_status--error"},xe),e.createElement("div",{className:"huanban_rulego_info__inline_actions"},e.createElement("button",{className:"huanban_rulego_info__copy_btn",type:"button",onClick:()=>{try{const re=te==="visual"?v.generateToolSchemaFromRows(ke):v.parseJsonObjectText(ne||"{}",{type:"object",properties:{}});he(JSON.stringify(re,null,2)),we(v.parseToolSchemaRows(re)),Ee("")}catch(re){Ee(re instanceof Error?re.message:u("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}}},u("editor.workflowInfo.formatJson","格式化 JSON")),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:Ne,onClick:Pt},e.createElement(pe,{value:_.save})," ",Ne?u("editor.workflowInfo.saving","保存中..."):u("editor.workflowInfo.saveInputDefinition","保存输入定义")))),gt=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},e.createElement(pe,{value:_.variable})," ",u("editor.workflowInfo.vars","变量")),e.createElement(aa,{entries:Le,onChange:Se,icons:_,keyPlaceholder:u("editor.workflowInfo.varName","变量名"),valuePlaceholder:u("editor.workflowInfo.varValue","变量值"),actionLabel:u("editor.workflowInfo.action","操作"),deleteTitle:u("editor.workflowInfo.delete","删除"),addLabel:u("editor.workflowInfo.add","添加"),batchDeleteLabel:u("editor.workflowInfo.batchDelete","批量删除"),batchDeleteConfirm:u("editor.workflowInfo.batchDeleteConfirm","确定删除选中的 {{count}} 项吗?"),deleteConfirm:u("editor.workflowInfo.deleteEntryConfirm","确定删除“{{key}}”吗?"),selectLabel:u("editor.workflowInfo.select","选择"),selectedCountLabel:u("editor.workflowInfo.selectedCount","已选择 {{count}} 项"),selectRowLabel:u("editor.workflowInfo.selectRow","选择第 {{index}} 项")}),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:Ne,onClick:()=>Nt("vars")},e.createElement(pe,{value:_.save})," ",u("editor.workflowInfo.saveVars","保存变量")),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(pe,{value:_.secret})," ",u("editor.workflowInfo.secrets","秘钥")),e.createElement(aa,{entries:se,onChange:ae,icons:_,keyPlaceholder:u("editor.workflowInfo.secretName","秘钥名"),valuePlaceholder:u("editor.workflowInfo.secretValue","秘钥值"),valueType:"password",actionLabel:u("editor.workflowInfo.action","操作"),deleteTitle:u("editor.workflowInfo.delete","删除"),addLabel:u("editor.workflowInfo.add","添加"),batchDeleteLabel:u("editor.workflowInfo.batchDelete","批量删除"),batchDeleteConfirm:u("editor.workflowInfo.batchDeleteConfirm","确定删除选中的 {{count}} 项吗?"),deleteConfirm:u("editor.workflowInfo.deleteEntryConfirm","确定删除“{{key}}”吗?"),selectLabel:u("editor.workflowInfo.select","选择"),selectedCountLabel:u("editor.workflowInfo.selectedCount","已选择 {{count}} 项"),selectRowLabel:u("editor.workflowInfo.selectRow","选择第 {{index}} 项")}),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:Ne,onClick:()=>Nt("secrets")},e.createElement(pe,{value:_.save})," ",u("editor.workflowInfo.saveSecrets","保存秘钥"))),je=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},e.createElement(pe,{value:_.api})," ",u("editor.workflowInfo.apiIntegration","API 集成")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.executeAPI","执行 API:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Ke.executeUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.executeUrl)},e.createElement(pe,{value:_.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.notifyAPI","通知 API:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Ke.notifyUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.notifyUrl)},e.createElement(pe,{value:_.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.openaiCompatibleAPI","OpenAI:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Ke.openaiUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.openaiUrl)},e.createElement(pe,{value:_.copy}))),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(pe,{value:_.api})," ",u("editor.workflowInfo.webSocket","WebSocket")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.debugWS","Debug WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},Ke.debugWsUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.debugWsUrl)},e.createElement(pe,{value:_.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.runtimeWS","Runtime WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},Ke.runtimeWsUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.runtimeWsUrl)},e.createElement(pe,{value:_.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.endpointWS","Endpoint WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},Ke.endpointWsHint),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.endpointWsHint)},e.createElement(pe,{value:_.copy}))),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(pe,{value:_.mcp})," ",u("editor.workflowInfo.mcpIntegration","MCP 集成")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.mcpSSE","MCP SSE:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},Ke.mcpSseUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.mcpSseUrl)},e.createElement(pe,{value:_.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.mcpStreamableHTTP","MCP HTTP:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Ke.mcpStreamableUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.mcpStreamableUrl)},e.createElement(pe,{value:_.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},u("editor.workflowInfo.mcpGroupAPI","MCP 分组:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Ke.mcpGroupUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>lt(Ke.mcpGroupUrl)},e.createElement(pe,{value:_.copy})))),nt=()=>{switch(Ot){case"base":return w?w(i,Ct):Ct;case"inputSchema":return qt;case"vars":return y?y(i,gt):gt;case"integration":return k?k(i,Tt,je):je;case"maintenance":return e.createElement(xa,{workflow:i,fetcher:V,content:J,onError:O,locale:C,messages:I,t:D});default:{const re=At.find(fe=>fe.key===Ot);return re?re.children:null}}};return e.createElement("div",{className:`huanban_rulego_info ${xt} ${f}`.trim(),"data-theme":vt,"data-rg-theme":vt,style:{...Lt,...M}},e.createElement("div",{className:"huanban_rulego_info__tabs"},Mt.map(re=>e.createElement("button",{key:re.key,className:`huanban_rulego_info__tab ${Ot===re.key?"huanban_rulego_info__tab--active":""}`,onClick:()=>q(re.key)},re.icon!==void 0&&e.createElement(pe,{value:re.icon}),re.label))),e.createElement("div",{className:"huanban_rulego_info__content"},nt()))};function Ia(t){var o,s,i;if((o=t.endpoint)!=null&&o.trim())return t.endpoint.trim();const n=(s=t.apiBase)==null?void 0:s.trim().replace(/\/+$/,""),r=(i=t.ruleChainId)==null?void 0:i.trim();return n&&r?`${n}/rules/${encodeURIComponent(r)}/v1/chat/completions`:""}function Cl(t){return typeof t=="function"?t()||{}:t||{}}function Mn(){return`copilot-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Pa(t){return typeof t=="number"&&Number.isFinite(t)||typeof t=="string"&&!Number.isNaN(Date.parse(t))?t:Date.now()}function kl(t){if(t===void 0)return"";const n=new Date(t);return Number.isNaN(n.getTime())?"":`${String(n.getHours()).padStart(2,"0")}:${String(n.getMinutes()).padStart(2,"0")}`}function Nl(t){var r;const n=v.filterCopilotSuccessfulTurns(t);for(let o=n.length-1;o>0;o-=1){const s=n[o];if(s.role==="assistant"&&s.status==="complete"&&((r=n[o-1])==null?void 0:r.role)==="user")return s.id}}const oa=new WeakMap;let wl=0;function la(t){if(!t)return"none";const n=oa.get(t);if(n)return n;const r=`ref-${++wl}`;return oa.set(t,r),r}function Sl(t){var r;const n=(r=t.conversationContextKey)==null?void 0:r.trim();return n?`context:${n}`:[`endpoint:${Ia(t)}`,`fetch:${la(t.customFetch)}`,`headers:${la(t.fetchHeaders)}`].join("|")}function sa(t){return t.map(n=>({...n,id:Mn(),status:"complete",timestamp:Pa(n.timestamp)}))}function xl(t){if(!Array.isArray(t))return;const n=t.filter(r=>r&&typeof r=="object").map((r,o)=>({id:String(r.id||`tool-${o+1}`),index:typeof r.index=="number"?r.index:void 0,type:typeof r.type=="string"?r.type:void 0,name:String(r.name||"tool"),arguments:typeof r.arguments=="string"?r.arguments:void 0,result:typeof r.result=="string"?r.result:void 0,status:r.status==="error"||r.status==="cancel"||r.status==="success"||r.status==="received"?r.status:"received"}));return n.length?n:void 0}function Tl(t){return Array.isArray(t)?v.filterCopilotSuccessfulTurns(t.filter(n=>n&&typeof n=="object"&&n.role&&typeof n.content=="string").map(n=>({...n,id:String(n.id||Mn()),status:n.status==="error"?"error":"complete",timestamp:Pa(n.timestamp),toolCalls:xl(n.toolCalls)}))):[]}const Rl=t=>{var L,ke,we;const{locale:n,messages:r,t:o,initialMessages:s=[],onMessagesChange:i,onError:m,placeholder:f,className:M,style:N,disabled:P=!1}=t,g=e.useMemo(()=>Ze({locale:n,messages:r,t:o}),[n,r,o]),w=Sl(t),y=(L=t.persistence)==null?void 0:L.adapter,k=(ke=t.persistence)==null?void 0:ke.namespace,F=((we=t.persistence)==null?void 0:we.mode)||"component",j=e.useMemo(()=>!y||!k?null:{adapter:y,namespace:k,chainId:`${t.ruleChainId}::${w}`,mode:F},[w,y,F,k,t.ruleChainId]),O=e.useMemo(()=>v.buildEditorChatHistoryKey(j||void 0),[j]),U=O||`memory:${t.ruleChainId}:${w}:${F}`,[C,I]=e.useState(()=>sa(s)),[D,_]=e.useState(U),[u,Z]=e.useState(""),[ee,H]=e.useState(!1),[V,me]=e.useState(""),q=e.useRef(null),le=e.useRef(null),ue=e.useRef(!1),W=e.useRef(0);e.useEffect(()=>{var he;W.current+=1,(he=q.current)==null||he.abort(),q.current=null,H(!1),me(""),ue.current=!0;const ne=j?Tl(v.readEditorChatHistory(j)):sa(s);I(ne),_(U)},[U,j]),e.useEffect(()=>{if(i==null||i(C),ue.current){ue.current=!1;return}if(!j||!O||D!==U)return;const ne=v.filterCopilotSuccessfulTurns(C);v.writeEditorChatHistory(j,ne)},[C,D,U,i,O,j]),e.useEffect(()=>()=>{var ne;return(ne=q.current)==null?void 0:ne.abort()},[]),e.useEffect(()=>{const ne=le.current;if(!ne)return;const he=Ee=>{const Le=Ee.detail;me(String(Le||g("editor.copilot.copyFailed","复制失败")))};ne.addEventListener("copilot-code-copy-error",he);const xe=v.bindCopilotCodeInteractions(ne,{copyLabel:g("editor.copilot.copy","复制"),copiedLabel:g("editor.copilot.copied","已复制"),copyFailedLabel:g("editor.copilot.copyFailed","复制失败"),closeLabel:g("editor.copilot.close","关闭"),codeLabel:g("editor.copilot.code","代码"),codePreviewLabel:g("editor.copilot.preview","预览")});return()=>{ne.removeEventListener("copilot-code-copy-error",he),xe()}},[g]);const ge=e.useCallback(async(ne,he,xe,Ee)=>{H(!0);const Le=new AbortController;q.current=Le;const Se=W.current,se=()=>W.current===Se&&q.current===Le;try{if(await v.streamOpenAiChatCompletion({endpoint:Ia(t),model:t.model,stream:t.stream,headers:Cl(t.fetchHeaders),customFetch:t.customFetch,messages:ne.map(({role:ae,content:Ne})=>({role:ae,content:Ne})),signal:Le.signal,onDelta:ae=>{se()&&I(Ne=>Ne.map(_e=>_e.id===he.id?{..._e,content:_e.content+ae}:_e))},onReasoningDelta:ae=>{se()&&I(Ne=>Ne.map(_e=>_e.id===he.id?{..._e,reasoning:(_e.reasoning||"")+ae}:_e))},onToolCallDelta:ae=>{se()&&I(Ne=>Ne.map(_e=>_e.id===he.id?{..._e,toolCalls:v.mergeCopilotToolCallDelta(_e.toolCalls,ae)}:_e))}}),!se())return;I(ae=>ae.map(Ne=>Ne.id===he.id?{...Ne,status:"complete",toolCalls:v.settleCopilotToolCalls(Ne.toolCalls)}:Ne))}catch(ae){if(!se())return;if((ae==null?void 0:ae.name)==="AbortError")Ee?(I(Ee),me(g("editor.copilot.cancelled","请求已取消"))):I(Ne=>Ne.map(_e=>_e.id===xe?{..._e,status:"error"}:_e.id===he.id?{..._e,status:"error",content:g("editor.copilot.cancelled","请求已取消")}:_e));else{const Ne=ae instanceof Error?ae:new Error(String(ae));me(Ne.message),I(Ee||(_e=>_e.filter(J=>J.id!==he.id).map(J=>J.id===xe?{...J,status:"error"}:J))),m==null||m(Ne)}}finally{if(!se())return;q.current=null,H(!1)}},[m,t,g]),Pe=e.useCallback(async()=>{const ne=u.trim();if(!ne||ee||P)return;const he=Date.now(),xe={id:Mn(),role:"user",content:ne,status:"complete",timestamp:he},Ee={id:Mn(),role:"assistant",content:"",reasoning:"",status:"sending",timestamp:he},Le=[...v.filterCopilotSuccessfulTurns(C),xe];I([...Le,Ee]),Z(""),me(""),await ge(Le,Ee,xe.id)},[ee,C,P,u,ge]),Me=e.useCallback(async ne=>{var he;try{if(!((he=navigator.clipboard)!=null&&he.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(ne)}catch{me(g("editor.copilot.copyFailed","复制失败"))}},[g]),X=e.useCallback(async ne=>{var se,ae;if(ee||P)return;const he=C,xe=v.filterCopilotSuccessfulTurns(he),Ee=xe.findIndex(Ne=>Ne.id===ne);if(Ee<=0||((se=xe[Ee])==null?void 0:se.role)!=="assistant"||((ae=xe[Ee-1])==null?void 0:ae.role)!=="user")return;const Le=xe.slice(0,Ee),Se={id:Mn(),role:"assistant",content:"",reasoning:"",status:"sending",timestamp:Date.now()};I([...Le,Se]),me(""),await ge(Le,Se,void 0,he)},[ee,C,P,ge]),b=()=>{var ne;return(ne=q.current)==null?void 0:ne.abort()},$=()=>{ee||(j&&v.clearEditorChatHistory(j),I([]),me(""))},Y=ne=>ne==="user"?g("editor.copilot.userRole","用户"):g("editor.copilot.assistantRole","助手"),te=e.useMemo(()=>Nl(C),[C]);return e.createElement("section",{className:`rge-copilot ${M||""}`,style:N,"aria-label":g("editor.copilot.title","AI 助理")},e.createElement("header",{className:"rge-copilot__header"},e.createElement("strong",null,g("editor.copilot.title","AI 助理")),e.createElement("button",{type:"button",onClick:$,disabled:ee||C.length===0,title:g("editor.copilot.clear","清空对话")},g("editor.copilot.clear","清空"))),e.createElement("div",{ref:le,className:"rge-copilot__messages","aria-live":"polite"},C.length===0&&e.createElement("div",{className:"rge-copilot__empty"},g("editor.copilot.empty","请输入问题开始对话")),C.map(ne=>{var he;return e.createElement("article",{key:ne.id,className:`rge-copilot__message ${ne.role}${ne.status==="error"?" is-error":""}`},e.createElement("div",{className:"rge-copilot__role"},Y(ne.role),ne.status==="sending"?` · ${g("editor.copilot.sending","处理中")}`:"",ne.role==="user"&&ne.status==="error"?` · ${g("editor.copilot.failed","未完成")}`:""),ne.reasoning&&e.createElement("details",null,e.createElement("summary",null,g("editor.copilot.reasoning","思考过程")),e.createElement("div",{className:"rge-copilot__reasoning",dangerouslySetInnerHTML:{__html:v.renderCopilotMarkdown(ne.reasoning,{codeCopyLabel:g("editor.copilot.copy","复制"),codeLabel:g("editor.copilot.code","代码"),codePreviewLabel:g("editor.copilot.preview","预览"),codeFullscreenLabel:g("editor.copilot.fullscreen","全屏"),streaming:ne.status==="sending"})}})),(he=ne.toolCalls)!=null&&he.length?e.createElement("details",{className:"rge-copilot__tools",open:ne.status==="sending","data-copilot-tool-calls":"true"},e.createElement("summary",null,g("editor.copilot.toolCalls","工具调用")," (",ne.toolCalls.length,")"),e.createElement("div",{className:"rge-copilot__tool-list"},ne.toolCalls.map(xe=>e.createElement("div",{key:xe.id,className:"rge-copilot__tool","data-copilot-tool-call":xe.id},e.createElement("div",{className:"rge-copilot__tool-header"},e.createElement("strong",null,xe.name),e.createElement("span",null,xe.status==="loading"?g("editor.copilot.toolRunning","处理中"):xe.status==="success"?g("editor.copilot.toolCompleted","已完成"):xe.status==="error"?g("editor.copilot.toolFailed","失败"):g("editor.copilot.toolReceived","已收到"))),xe.arguments&&e.createElement("pre",null,xe.arguments),xe.result&&e.createElement("pre",{className:"rge-copilot__tool-result"},xe.result))))):null,ne.content?e.createElement("div",{className:"rge-copilot__content",dangerouslySetInnerHTML:{__html:v.renderCopilotMarkdown(ne.content,{codeCopyLabel:g("editor.copilot.copy","复制"),codeLabel:g("editor.copilot.code","代码"),codePreviewLabel:g("editor.copilot.preview","预览"),codeFullscreenLabel:g("editor.copilot.fullscreen","全屏"),streaming:ne.status==="sending"})}}):ne.status==="sending"?e.createElement("div",{className:"rge-copilot__content"},g("editor.copilot.sending","处理中")):null,e.createElement("div",{className:"rge-copilot__message-meta"},e.createElement("time",{className:"rge-copilot__message-time"},kl(ne.timestamp)),e.createElement("div",{className:"rge-copilot__message-actions"},e.createElement("button",{type:"button","data-copilot-message-action":"copy",disabled:!ne.content,onClick:()=>void Me(ne.content),title:g("editor.copilot.copy","复制"),"aria-label":g("editor.copilot.copy","复制")},e.createElement("span",{"aria-hidden":"true"},"⧉")),ne.id===te&&e.createElement("button",{type:"button","data-copilot-message-action":"regenerate",disabled:ee,onClick:()=>void X(ne.id),title:g("editor.copilot.regenerate","重新生成"),"aria-label":g("editor.copilot.regenerate","重新生成")},e.createElement("span",{"aria-hidden":"true"},"↻")))))})),V&&e.createElement("div",{className:"rge-copilot__error",role:"alert","aria-live":"assertive"},e.createElement("span",null,V),e.createElement("button",{type:"button",onClick:()=>me(""),title:g("editor.copilot.dismissError","关闭错误提示"),"aria-label":g("editor.copilot.dismissError","关闭错误提示")},"×")),e.createElement("div",{className:"rge-copilot__input"},e.createElement("textarea",{value:u,disabled:P||ee,onChange:ne=>Z(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&!ne.shiftKey&&(ne.preventDefault(),Pe())},placeholder:f||g("editor.copilot.placeholder","输入消息"),rows:2}),ee?e.createElement("button",{type:"button",onClick:b,title:g("editor.copilot.stop","停止请求")},g("editor.copilot.stop","停止")):e.createElement("button",{type:"button",onClick:()=>void Pe(),disabled:P||!u.trim()},g("editor.copilot.send","发送"))))},Il=e.createElement("svg",{"aria-hidden":"true",focusable:"false",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("path",{d:"M12 4v3"}),e.createElement("path",{d:"M8 4h8"}),e.createElement("rect",{x:"4.5",y:"7",width:"15",height:"11.5",rx:"3.5",fill:"currentColor",opacity:".14",stroke:"currentColor"}),e.createElement("circle",{cx:"9.5",cy:"12.6",r:"1.35",fill:"currentColor",stroke:"none"}),e.createElement("circle",{cx:"14.5",cy:"12.6",r:"1.35",fill:"currentColor",stroke:"none"}),e.createElement("path",{d:"M9 16h6"}),e.createElement("path",{d:"M18.5 4.5l.8 1.9 1.9.8-1.9.8-.8 1.9-.8-1.9-1.9-.8 1.9-.8.8-1.9z",fill:"currentColor",stroke:"none"}));function Pl({editorRef:t,editor:n,options:r,iconOnly:o=!0,label:s="AI助手",className:i,style:m,disabled:f,onOpen:M}){const N=()=>{var g;const P=n||((g=t==null?void 0:t.current)==null?void 0:g.editor);P==null||P.openAiAssistant(r),M==null||M()};return e.createElement("button",{type:"button",className:i,style:{width:o?30:void 0,height:30,minWidth:o?30:void 0,padding:o?0:"0 10px",borderRadius:o?"50%":6,border:"1px solid rgba(124,58,237,.36)",background:"#fff",color:"#7c3aed",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,cursor:f?"not-allowed":"pointer",opacity:f?.5:1,...m},disabled:f,title:s,"aria-label":s,onClick:N},Il,!o&&e.createElement("span",null,s))}const Dl=({schema:t,formData:n,onChange:r,locale:o,messages:s,t:i})=>{const m=e.useMemo(()=>Ze({locale:o,messages:s,t:i}),[o,s,i]);return e.createElement("div",{className:"hb-node-form"},t.map(f=>e.createElement("div",{key:f.key,className:"rge-dynamic-form-item"},e.createElement("label",{className:"rge-dynamic-form-label"},m(f.labelKey||`fields.${f.key}`,f.label)),f.type==="boolean"?e.createElement("input",{type:"checkbox",checked:!!n[f.key],onChange:M=>r(f.key,M.target.checked)}):f.type==="json"||f.type==="textarea"?e.createElement("textarea",{value:n[f.key]||"",onChange:M=>r(f.key,M.target.value),rows:f.rows||(f.type==="json"?5:3),className:f.type==="json"?"rge-form-textarea mono":"rge-form-textarea",placeholder:f.placeholder}):f.type==="select"?e.createElement(zt,{value:String(n[f.key]??f.defaultValue??""),values:Array.isArray(n[f.key])?n[f.key].map(M=>String(M??"")).filter(Boolean):void 0,multiple:f.multiple,options:f.options||[],placeholder:f.placeholder,searchPlaceholder:m("editor.property.searchOptions","搜索选项..."),noMatchText:m("editor.property.noMatchingOptions","没有匹配的选项"),onChange:M=>r(f.key,M),onMultiChange:M=>r(f.key,M)}):e.createElement("input",{type:f.type==="number"?"number":f.type==="password"?"password":"text",value:n[f.key]||"",onChange:M=>r(f.key,f.type==="number"?M.target.value===""?"":Number(M.target.value):M.target.value),className:"rge-form-input",placeholder:f.placeholder}),f.help&&e.createElement("span",{className:"rge-form-help"},f.help))))},Ll=({logs:t,locale:n,messages:r,t:o})=>{const[s,i]=e.useState([]),m=e.useRef(null),f=e.useMemo(()=>Ze({locale:n,messages:r,t:o}),[n,r,o]);return e.useEffect(()=>{t.length>200?i(t.slice(t.length-200)):i(t),m.current&&(m.current.scrollTop=m.current.scrollHeight)},[t]),e.createElement("div",{className:"hb-glass-panel",style:{height:"300px",display:"flex",flexDirection:"column"}},e.createElement("div",{style:{padding:"8px 16px",borderBottom:"var(--hb-panel-border)",fontWeight:"bold"}},f("editor.logViewer.title","调试控制台 (Debug Console)")),e.createElement("div",{ref:m,style:{flex:1,overflowY:"auto",padding:"8px",fontFamily:"monospace",fontSize:"12px"}},s.map(M=>e.createElement("div",{key:M.id,style:{padding:"4px",borderBottom:"1px solid hsla(230, 20%, 50%, 0.1)",color:M.level==="error"?"#ff4d4f":M.level==="warn"?"#faad14":"var(--hb-text-primary)"}},e.createElement("span",{style:{color:"var(--hb-text-secondary)",marginRight:"8px"}},"[",new Date(M.timestamp).toLocaleTimeString(),"]"),M.message)),s.length===0&&e.createElement("div",{style:{color:"var(--hb-text-secondary)",textAlign:"center",marginTop:"20px"}},f("editor.logViewer.empty","暂无调试日志"))))},Ml={isReady:!1,isDirty:!1,isLoading:!1,selectedNode:null,selectedEdge:null,componentGroups:[],currentNodeView:null,currentNodeModel:{},currentEdgeModel:{},canUndo:!1,canRedo:!1};function $l(t={}){const[n,r]=e.useState(Ml),o=e.useRef(null),s=e.useRef([]),i=e.useRef(t);e.useEffect(()=>{const g=new v.EditorCore(i.current);o.current=g;const w=g.store.subscribe(y=>{r({isReady:y.isReady,isDirty:y.isDirty,isLoading:y.isLoading,selectedNode:y.selectedNode,selectedEdge:y.selectedEdge,componentGroups:y.componentGroups,currentNodeView:y.currentNodeView,currentNodeModel:y.currentNodeModel,currentEdgeModel:y.currentEdgeModel,canUndo:y.canUndo,canRedo:y.canRedo})});return()=>{for(const y of s.current)y();s.current=[],w(),g.destroy(),o.current=null}},[]);const m=e.useCallback(g=>{o.current&&o.current.init(g)},[]),f=e.useCallback(g=>{o.current&&o.current.loadData(g)},[]),M=e.useCallback((g,w)=>{if(o.current){const y=o.current.eventBus.on(g,w);s.current.push(y)}},[]),N=e.useCallback((g,...w)=>{o.current&&o.current.eventBus.emit(g,...w)},[]),P=e.useCallback(()=>{o.current&&o.current.eventBus.emit("editor:save",{data:{},success:!1})},[]);return{core:o.current,...n,loadData:f,on:M,emit:N,init:m,save:P}}function Al(t){const[n,r]=e.useState("light"),[o,s]=e.useState(["light","dark","blue"]);e.useEffect(()=>{t&&(r(t.theme.getTheme()),s(t.theme.getAvailableThemes().map(m=>m.name)))},[t]);const i=e.useCallback(m=>{t&&(t.theme.setTheme(m),r(m))},[t]);return{currentTheme:n,themes:o,setTheme:i}}function Ol(t){const[n,r]=e.useState((t==null?void 0:t.i18n.getLocale())||"zh-CN"),o=e.useCallback((i,m)=>t?t.i18n.t(i,m):i,[t]),s=e.useCallback(i=>{t&&(t.i18n.setLocale(i),r(i))},[t]);return{t:o,locale:n,setLocale:s}}function Da(){return typeof navigator>"u"?!1:/Mac|iPod|iPhone|iPad/.test(navigator.platform||"")}function Fl(t){if(typeof Element>"u")return!1;const n=t instanceof Element?t:document.activeElement;if(!(n instanceof Element))return!1;const r=n.tagName.toLowerCase();return!!(r==="input"||r==="textarea"||r==="select"||n.isContentEditable||n.closest('.cm-editor, .cm-content, [data-cm-container], [contenteditable="true"]'))}function Bl(t){const{shortcuts:n,enabled:r=!0,target:o}=t,s=e.useRef(n);s.current=n,e.useEffect(()=>{if(!r)return;const i=Da(),m=M=>{const N=M,P=N.key.toLowerCase();for(const g of s.current){if(P!==g.key.toLowerCase())continue;const w=g.ctrl?i?N.metaKey:N.ctrlKey:!(i?N.metaKey:N.ctrlKey),y=g.shift?N.shiftKey:!N.shiftKey,k=g.alt?N.altKey:!N.altKey;if(!(!w||!y||!k)&&!(!g.enableInInput&&Fl(N.target))){N.preventDefault(),N.stopPropagation(),g.handler(N);return}}},f=o||document;return f.addEventListener("keydown",m),()=>{f.removeEventListener("keydown",m)}},[r,o])}function jl(t){const n=Da(),r=[];return t.ctrl&&r.push(n?"⌘":"Ctrl"),t.shift&&r.push(n?"⇧":"Shift"),t.alt&&r.push(n?"⌥":"Alt"),r.push(t.key.toUpperCase()),n?r.join(""):r.join("+")}function Hl(t){return[{key:"s",ctrl:!0,enableInInput:!0,description:"保存",handler:()=>{var n;return(n=t.onSave)==null?void 0:n.call(t)}},{key:"z",ctrl:!0,description:"撤销",handler:()=>{var n;return(n=t.onUndo)==null?void 0:n.call(t)}},{key:"z",ctrl:!0,shift:!0,description:"重做",handler:()=>{var n;return(n=t.onRedo)==null?void 0:n.call(t)}},{key:"y",ctrl:!0,description:"重做",handler:()=>{var n;return(n=t.onRedo)==null?void 0:n.call(t)}},{key:"delete",description:"删除",handler:()=>{var n;return(n=t.onDelete)==null?void 0:n.call(t)}},{key:"backspace",description:"删除",handler:()=>{var n;return(n=t.onDelete)==null?void 0:n.call(t)}},{key:"c",ctrl:!0,description:"复制",handler:()=>{var n;return(n=t.onCopy)==null?void 0:n.call(t)}},{key:"v",ctrl:!0,description:"粘贴",handler:()=>{var n;return(n=t.onPaste)==null?void 0:n.call(t)}},{key:"d",ctrl:!0,description:"复制节点",handler:()=>{var n;return(n=t.onDuplicate)==null?void 0:n.call(t)}},{key:"a",ctrl:!0,description:"全选",handler:()=>{var n;return(n=t.onSelectAll)==null?void 0:n.call(t)}},{key:"f2",description:"重命名节点",handler:()=>{var n;return(n=t.onRename)==null?void 0:n.call(t)}},{key:"b",ctrl:!0,description:"折叠组件库",handler:()=>{var n;return(n=t.onToggleSidebar)==null?void 0:n.call(t)}},{key:"l",ctrl:!0,shift:!0,description:"自动排版",handler:()=>{var n;return(n=t.onAutoLayout)==null?void 0:n.call(t)}},{key:"1",ctrl:!0,description:"适应画布",handler:()=>{var n;return(n=t.onFitView)==null?void 0:n.call(t)}},{key:"=",ctrl:!0,description:"放大",handler:()=>{var n;return(n=t.onZoomIn)==null?void 0:n.call(t)}},{key:"-",ctrl:!0,description:"缩小",handler:()=>{var n;return(n=t.onZoomOut)==null?void 0:n.call(t)}},{key:"escape",description:"取消选择",handler:()=>{var n;return(n=t.onEscape)==null?void 0:n.call(t)}}]}function $n(t,n,r){const o=e.useRef(t??null),s=e.useRef(!t),i=e.useRef(t??null);i.current!==(t??null)?(i.current=t??null,o.current=t??n(),s.current=!t):o.current||(o.current=n(),s.current=!0);const m=o.current,f=e.useRef(new Map),[M,N]=e.useState(()=>({store:m,state:r(m)}));return e.useEffect(()=>{const P=s.current;let g=!1;const w=f.current.get(m);w&&(clearTimeout(w),f.current.delete(m));const y=m.subscribe(k=>{g||N({store:m,state:k})});return N({store:m,state:r(m)}),()=>{if(g=!0,y(),P){const k=setTimeout(()=>{f.current.delete(m),m.destroy()},0);f.current.set(m,k)}}},[m]),{store:m,state:M.store===m?M.state:r(m)}}function Wl(t={}){const{store:n,state:r}=$n(t.workspace,()=>new v.EditorWorkspace(t),k=>k.getState()),o=e.useCallback(k=>n.openTab(k),[n]),s=e.useCallback(k=>n.activateTab(k),[n]),i=e.useCallback((k,F)=>n.renameTab(k,F),[n]),m=e.useCallback(k=>n.togglePinned(k),[n]),f=e.useCallback(k=>n.getCloseOtherTabIds(k),[n]),M=e.useCallback(k=>n.getCloseRightTabIds(k),[n]),N=e.useCallback((k,F)=>n.setDraft(k,F),[n]),P=e.useCallback((k,F)=>n.markSaved(k,F),[n]),g=e.useCallback((k,F)=>n.setLoading(k,F),[n]),w=e.useCallback((k,F)=>n.closeTab(k,F),[n]),y=e.useCallback((k,F,j)=>n.resolveSaveConflict(k,F,j),[n]);return{workspace:n,state:r,tabs:r.tabs,activeTab:r.tabs.find(k=>k.id===r.activeTabId)??null,openTab:o,activateTab:s,renameTab:i,togglePinned:m,getCloseOtherTabIds:f,getCloseRightTabIds:M,setDraft:N,markSaved:P,setLoading:g,closeTab:w,resolveSaveConflict:y}}function Ul(t={}){const{dockStore:n,...r}=t,{store:o,state:s}=$n(n,()=>new v.EditorDockStore(r),i=>i.getDockState());return{dock:o,state:s,setDockVisibility:e.useCallback((i,m)=>o.setDockVisibility(i,m),[o]),setDockWidth:e.useCallback((i,m)=>o.setDockWidth(i,m),[o]),setDockHeight:e.useCallback((i,m)=>o.setDockHeight(i,m),[o]),resetDockState:e.useCallback(()=>o.resetDockState(),[o])}}function Vl(t={}){const{serverStatus:n,...r}=t,{store:o,state:s}=$n(n,()=>new v.ServerStatusStore(r),i=>i.getState());return{server:o,state:s,setServerUrl:e.useCallback((i,m)=>o.setServerUrl(i,m),[o]),setServerStatus:e.useCallback((i,m)=>o.setServerStatus(i,m),[o]),recordHttpStatus:e.useCallback((i,m)=>o.recordHttpStatus(i,m),[o]),recordWebSocketStatus:e.useCallback((i,m,f)=>o.recordWebSocketStatus(i,m,f),[o]),setReconnectAttempt:e.useCallback(i=>o.setReconnectAttempt(i),[o])}}function ql(t={}){const{connectionStatus:n}=t,{store:r,state:o}=$n(n,()=>new v.ConnectionStatusStore,s=>s.getState());return{connectionStatus:r,state:o}}function Jl(t={}){const n=t.panels,r=n instanceof v.EditorPanelRegistry?n:null,o={...t,panels:Array.isArray(n)?n:void 0,syncDockVisibility:!1},{store:s,state:i}=$n(r,()=>new v.EditorPanelRegistry(o),m=>m.getState());return e.useEffect(()=>{s.syncDockVisibility()},[s]),{panels:s,state:i,openPanel:e.useCallback((m,f)=>s.openPanel(m,f),[s]),closePanel:e.useCallback(m=>s.closePanel(m),[s]),activatePanel:e.useCallback(m=>s.activatePanel(m),[s]),setPanelExpanded:e.useCallback((m,f)=>s.setPanelExpanded(m,f),[s]),togglePanelExpanded:e.useCallback(m=>s.togglePanelExpanded(m),[s]),isPanelExpanded:e.useCallback(m=>s.isPanelExpanded(m),[s]),register:e.useCallback((m,f)=>s.register(m,f),[s]),unregister:e.useCallback(m=>s.unregister(m),[s]),getPanels:e.useCallback(m=>s.getPanels(m),[s]),getActivePanel:e.useCallback(m=>s.getActivePanel(m),[s])}}const Kl=30;function zl(){return`node_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function Gl(t,n,r){const o=t.trim()||r;let s=o,i=1;for(;n.has(s);)s=`${o}_${i++}`;return n.add(s),s}function mr(t){try{return JSON.parse(JSON.stringify(t))}catch{return{...t,properties:{...t.properties||{}},config:t.config?{...t.config}:void 0}}}function Yl(t){const[n,r]=e.useState([]),o=e.useRef(0),s=e.useCallback(()=>{var g,w,y;const N=((g=t.getSelectedNodes)==null?void 0:g.call(t))||[];if(N.length===0){(w=t.onNotify)==null||w.call(t,"info","没有选中的节点");return}const P=N.map(mr);r(P),o.current=0,(y=t.onNotify)==null||y.call(t,"success",`已复制 ${P.length} 个节点`)},[t]),i=e.useCallback(()=>{var y,k,F,j;const N=((y=t.getSelectedNodes)==null?void 0:y.call(t))||[];if(N.length===0){(k=t.onNotify)==null||k.call(t,"info","没有选中的节点");return}const P=N.map(O=>O.originalId);if(!(t.confirmDeleteNodes?t.confirmDeleteNodes(P):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(`确认剪切并删除 ${P.length} 个节点吗?此操作不可撤销。`):!1))return;const w=N.map(mr);r(w),o.current=0,(F=t.onDeleteNodes)==null||F.call(t,P),(j=t.onNotify)==null||j.call(t,"success",`已剪切 ${w.length} 个节点`)},[t]),m=e.useCallback(()=>{var w,y,k,F;if(n.length===0){(w=t.onNotify)==null||w.call(t,"info","剪贴板为空");return}o.current+=1;const N=Kl*o.current,P=new Set(((y=t.getExistingNodeIds)==null?void 0:y.call(t))||[]);n.forEach(j=>P.add(String(j.originalId)));const g=n.map(j=>{const O=mr(j),U=Gl(zl(),P,`node_${j.originalId||"copy"}`),C=j.x+N,I=j.y+N;return{...O,originalId:U,x:C,y:I,properties:v.cloneNodePropertiesForCopy(O.properties||{},{nodeId:U,nodeType:O.type,nodeName:O.name,layoutX:C,layoutY:I})}});(k=t.onAddNodes)==null||k.call(t,g),(F=t.onNotify)==null||F.call(t,"success",`已粘贴 ${g.length} 个节点`)},[n,t]),f=e.useCallback(()=>{var N;(N=t.onSelectAll)==null||N.call(t)},[t]),M=e.useCallback(()=>{r([]),o.current=0},[]);return{copy:s,cut:i,paste:m,selectAll:f,hasContent:n.length>0,clipboardCount:n.length,clear:M}}Object.defineProperty(exports,"ConnectionStatusController",{enumerable:!0,get:()=>v.ConnectionStatusController});Object.defineProperty(exports,"ConnectionStatusStore",{enumerable:!0,get:()=>v.ConnectionStatusStore});Object.defineProperty(exports,"DEFAULT_ROUTES",{enumerable:!0,get:()=>v.DEFAULT_ROUTES});Object.defineProperty(exports,"RuleChainAPI",{enumerable:!0,get:()=>v.RuleChainAPI});Object.defineProperty(exports,"normalizeConnectionStatusMap",{enumerable:!0,get:()=>v.normalizeConnectionStatusMap});Object.defineProperty(exports,"resolveConnectionStatusView",{enumerable:!0,get:()=>v.resolveConnectionStatusView});exports.AIAssistant=Pl;exports.ComponentSidebar=ma;exports.ContextMenu=va;exports.CopilotChat=Rl;exports.DataViewDialog=ya;exports.DebugPanel=Ea;exports.DynamicForm=Dl;exports.EdgePropertyDrawer=ha;exports.EditorConnectionStatus=Ko;exports.EditorEdgeHoverTools=Qo;exports.EditorIcon=pe;exports.EditorNodeHoverTools=Xo;exports.EditorPanelDock=Yo;exports.EditorStatusBar=Jo;exports.EditorToolbar=_a;exports.ImportExportDialog=nl;exports.LogViewer=Ll;exports.MiniMap=Ca;exports.NodePropertyDrawer=ba;exports.ProblemsPanel=Na;exports.RuleChainSettings=wa;exports.RuleGoEditor=ia;exports.RuleMaintenancePanel=xa;exports.SearchPanel=rl;exports.SearchableSelect=zt;exports.ValidationPanel=ka;exports.WorkflowExplorer=dl;exports.WorkflowInfoPanel=vl;exports.WorkflowList=ul;exports.WorkspaceTabs=qo;exports.createFrameworkTranslator=Ze;exports.getCanvasContextMenuItems=Wo;exports.getDefaultEditorShortcuts=Hl;exports.getEdgeContextMenuItems=Ho;exports.getNodeContextMenuItems=jo;exports.getShortcutLabel=jl;exports.normalizeFrameworkLocale=vr;exports.relationTypeLabel=pr;exports.useClipboard=Yl;exports.useConnectionStatus=ql;exports.useEditorCore=$l;exports.useEditorDock=Ul;exports.useEditorI18n=Ol;exports.useEditorPanels=Jl;exports.useEditorTheme=Al;exports.useEditorWorkspace=Wl;exports.useKeyboardShortcuts=Bl;exports.useServerStatus=Vl;
17
+ }`),le(_t.current("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}const Fe=Zr(we==null?void 0:we.configuration),ie=Fe.vars??(We==null?void 0:We.vars)??(we==null?void 0:we.vars)??{};z(Object.entries(ie).map(([It,yt])=>({key:It,value:String(yt)})));const wt=Fe.secrets??(We==null?void 0:We.secrets)??(we==null?void 0:we.secrets)??{};ye(Object.entries(wt).map(([It,yt])=>({key:It,value:String(yt)})))}).catch(fe=>{var we;ue===X.current&&(ve.signal.aborted||(fe==null?void 0:fe.name)==="AbortError"||(we=He.current)==null||we.call(He,fe instanceof Error?fe:new Error(String(fe))))}),()=>ve.abort()},[u,r,o,s]);const xt=e.useCallback(async()=>{if(!(!re||!u)){$e(!0);try{const ue=await re.saveBaseInfo(u.id,ha(u,at,{name:ee.trim(),root:Z,debugMode:Te,category:_e.trim(),description:H.trim()}));if(!ue.success)throw new Error(ue.msg||v("editor.workflowInfo.saveFailed","保存失败"));B==null||B("base"),q==null||q()}catch(ue){U==null||U(ue instanceof Error?ue:new Error(String(ue)))}finally{$e(!1)}}},[re,u,at,ee,Z,Te,_e,H,B,U,q,v]),$t=e.useCallback(ue=>{if(M!==ue){if(ue==="code"){Re(JSON.stringify(y.generateToolSchemaFromRows(xe),null,2)),le(""),ge("code");return}try{const ve=y.parseToolSchemaRows(y.parseJsonObjectText(Ce||"{}",{type:"object",properties:{}}));se(ve),le(""),ge("visual")}catch(ve){le(ve instanceof Error?ve.message:v("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}}},[Ce,M,xe,v]),T=e.useCallback(ue=>{se(ue),Re(JSON.stringify(y.generateToolSchemaFromRows(ue),null,2)),le("")},[]),Ie=e.useCallback((ue,ve,Se)=>{const f=y.updateSchemaRowsAtParent(xe,ue,fe=>{fe[ve]&&(fe[ve]={...fe[ve],...Se,properties:Se.type&&Se.type!=="object"?[]:fe[ve].properties,itemsProperties:Se.type&&Se.type!=="array"?[]:fe[ve].itemsProperties})});T(f)},[xe,T]),tt=e.useCallback((ue="")=>{const ve=y.updateSchemaRowsAtParent(xe,ue,Se=>{Se.push(y.emptySchemaEditorRow(Us(Se)+1))});T(ve)},[xe,T]),vt=e.useCallback((ue,ve)=>{const Se=y.updateSchemaRowsAtParent(xe,ue,f=>{f.splice(ve,1);const fe=y.renumberSchemaRowOrders(f);f.splice(0,f.length,...fe)});T(Se)},[xe,T]),ft=e.useCallback((ue,ve,Se)=>{T(qs(xe,ue,ve,Se))},[xe,T]),Kt=e.useCallback(async()=>{if(!re||!u)return;let ue;try{ue=M==="visual"?y.generateToolSchemaFromRows(xe):y.parseJsonObjectText(Ce||"{}",{type:"object",properties:{}}),Re(JSON.stringify(ue,null,2)),M==="code"&&se(y.parseToolSchemaRows(ue)),le("")}catch(ve){le(ve instanceof Error?ve.message:v("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"));return}$e(!0);try{const ve=await re.saveBaseInfo(u.id,ha(u,at,{name:ee.trim()||u.name,root:Z,debugMode:Te,category:_e.trim(),description:H.trim(),inputSchema:ue}));if(!ve.success)throw new Error(ve.msg||v("editor.workflowInfo.saveFailed","保存失败"));B==null||B("inputSchema"),q==null||q()}catch(ve){U==null||U(ve instanceof Error?ve:new Error(String(ve)))}finally{$e(!1)}},[re,u,at,M,xe,Ce,ee,Z,Te,_e,H,B,U,q,v]),Tt=e.useCallback(async ue=>{if(!(!re||!u)){$e(!0);try{const ve=ue==="vars"?de:G,Se={};ve.forEach(fe=>{fe.key.trim()&&(Se[fe.key.trim()]=fe.value)});const f=await re.saveConfig(u.id,ue,Se);if(!f.success)throw new Error(f.msg||v("editor.workflowInfo.saveFailed","保存失败"));B==null||B(ue),q==null||q()}catch(ve){U==null||U(ve instanceof Error?ve:new Error(String(ve)))}finally{$e(!1)}}},[re,u,de,G,B,U,q,v]),dt=e.useCallback(ue=>{navigator.clipboard.writeText(ue).catch(()=>{const ve=document.createElement("textarea");ve.value=ue,document.body.appendChild(ve),ve.select(),document.execCommand("copy"),document.body.removeChild(ve)})},[]),pt=y.normalizeEditorTheme(d),Ht=pt!=="default"?`huanban_rulego_info--${pt}`:"",Rt=y.getThemeRuntimeVariables(pt);if(!u)return e.createElement("div",{className:`huanban_rulego_info huanban_rulego_info--empty ${Ht} ${p}`.trim(),"data-theme":pt,"data-rg-theme":pt,style:{...Rt,...S}},e.createElement("p",{className:"huanban_rulego_info__no_data"},v("editor.workflowInfo.noData","请选择一个工作流查看详情")));const Wt=r||((Mt=re==null?void 0:re.getApiBase)==null?void 0:Mt.call(re))||"",Je=Ws(Wt,u.id),Zt=[{key:"base",label:v("editor.workflowInfo.baseInfo","基础信息"),icon:"docs"},{key:"inputSchema",label:v("editor.workflowInfo.inputDefinition","输入定义"),icon:"data"},{key:"vars",label:v("editor.workflowInfo.vars","变量"),icon:k.variable},{key:"integration",label:v("editor.workflowInfo.integration","应用集成"),icon:k.api},...b?[{key:"maintenance",label:v("editor.workflowInfo.maintenance","维护验证"),icon:"validate"}]:[]],Pt=W?W(u):[],Jt=[...Zt,...Pt.map(ue=>({key:ue.key,label:ue.label,icon:void 0}))],Ft=Jt.some(ue=>ue.key===g)?g:"base",bt=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("label",{className:"huanban_rulego_info__label"},v("editor.panel.name","名称"),e.createElement("input",{className:"huanban_rulego_info__input",type:"text",value:ee,onChange:ue=>P(ue.target.value)})),e.createElement("div",{className:"huanban_rulego_info__row"},e.createElement("span",{className:"huanban_rulego_info__field"},"ID: ",u.id)),e.createElement("div",{className:"huanban_rulego_info__switch_grid"},e.createElement("label",{className:"huanban_rulego_info__switch_row huanban_rulego_info__switch_row--readonly"},e.createElement("input",{type:"checkbox",checked:Z,disabled:!0}),e.createElement("span",{className:"huanban_rulego_info__switch_text"},v("editor.workflowInfo.rootChain","根规则链"),e.createElement("small",null,v("editor.workflowInfo.rootChainHint","开启:主链;关闭:子链")))),e.createElement("label",{className:"huanban_rulego_info__switch_row"},e.createElement("input",{type:"checkbox",checked:Te,onChange:ue=>Pe(ue.target.checked)}),e.createElement("span",{className:"huanban_rulego_info__switch_text"},v("editor.workflowInfo.debugMode","调试模式"),e.createElement("small",null,v("editor.workflowInfo.debugModeHint","开启后每条消息都会记录调试日志,并覆盖节点调试配置;会影响运行性能,生产环境建议关闭。编辑器手动调试不受影响。"))))),e.createElement("label",{className:"huanban_rulego_info__label"},v("editor.workflowInfo.category","分类"),e.createElement("input",{className:"huanban_rulego_info__input",type:"text",placeholder:v("editor.workflowInfo.categoryPlaceholder","如 agent, iot, data-flow"),value:_e,onChange:ue=>me(ue.target.value)})),e.createElement("label",{className:"huanban_rulego_info__label"},v("editor.panel.description","描述"),e.createElement("textarea",{className:"huanban_rulego_info__textarea",rows:3,value:H,onChange:ue=>ne(ue.target.value)})),e.createElement("div",{className:"huanban_rulego_info__row"},e.createElement("span",{className:`huanban_rulego_info__status ${u.deployed?"huanban_rulego_info__status--on":"huanban_rulego_info__status--off"}`},u.deployed?v("editor.workflowInfo.online","运行"):v("editor.workflowInfo.offline","停用"))),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:ke,onClick:xt},e.createElement(be,{value:k.save})," ",ke?v("editor.workflowInfo.saving","保存中..."):v("editor.workflowInfo.saveBaseInfo","保存基础信息"))),Dt=(ue,ve="")=>e.createElement("div",{className:"rge-tool-schema-rows"},ue.length===0?e.createElement("div",{className:"rge-tool-schema-empty"},v("editor.property.noSchemaProperties","暂无属性,点击下方按钮添加")):ue.map((Se,f)=>{const fe=ve?`${ve}.${f}`:String(f),we=Se.type==="array"?`${fe}.items`:fe,We=Se.type==="array"?Se.itemsProperties:Se.properties;return e.createElement("div",{key:fe,className:"rge-tool-schema-row-wrap"},e.createElement("div",{className:"rge-tool-schema-row"},e.createElement("input",{className:"rge-form-input",value:Se.name,placeholder:v("editor.property.propertyName","属性名"),onChange:Fe=>Ie(ve,f,{name:Fe.target.value})}),e.createElement("input",{className:"rge-form-input",value:Se.title,placeholder:v("editor.property.title","标题"),onChange:Fe=>Ie(ve,f,{title:Fe.target.value})}),e.createElement("input",{className:"rge-form-input",value:Se.description,placeholder:v("editor.property.description","描述"),onChange:Fe=>Ie(ve,f,{description:Fe.target.value})}),e.createElement("select",{className:"rge-form-select",value:Se.type,onChange:Fe=>Ie(ve,f,{type:Fe.target.value})},y.TOOL_SCHEMA_TYPES.map(Fe=>e.createElement("option",{key:Fe,value:Fe},Fe))),e.createElement("input",{className:"rge-form-input",type:"number",min:0,value:Se.order,onChange:Fe=>Ie(ve,f,{order:Number(Fe.target.value||f+1)})}),e.createElement("label",{className:"rge-inline-checkbox rge-tool-schema-required"},e.createElement("input",{type:"checkbox",checked:Se.required,onChange:Fe=>Ie(ve,f,{required:Fe.target.checked})}),e.createElement("span",null,v("editor.property.required","必填"))),e.createElement("div",{className:"rge-tool-schema-actions"},e.createElement("button",{type:"button",title:v("editor.property.moveUp","上移"),onClick:()=>ft(ve,f,-1)},"↑"),e.createElement("button",{type:"button",title:v("editor.property.moveDown","下移"),onClick:()=>ft(ve,f,1)},"↓"),e.createElement("button",{type:"button",className:"danger",title:v("editor.workflowInfo.delete","删除"),onClick:()=>vt(ve,f)},"×"))),Se.type==="array"&&e.createElement("div",{className:"rge-tool-schema-nested-head"},e.createElement("span",null,v("editor.property.itemType","项目类型")),e.createElement("select",{className:"rge-form-select",value:Se.itemsType||"string",onChange:Fe=>Ie(ve,f,{itemsType:Fe.target.value})},y.TOOL_SCHEMA_ITEM_TYPES.map(Fe=>e.createElement("option",{key:Fe,value:Fe},Fe)))),(Se.type==="object"||Se.type==="array")&&e.createElement("div",{className:"rge-tool-schema-nested"},e.createElement("div",{className:"rge-tool-schema-nested-title"},Se.type==="array"?v("editor.property.arrayItems","数组项目"):v("editor.property.childProperties","子属性"),Se.name?`: ${Se.name}`:""),Se.type==="array"&&(Se.itemsType||"string")!=="object"?e.createElement("div",{className:"rge-tool-schema-empty rge-tool-schema-nested-empty"},v("editor.property.arrayNonObject","当前数组项目不是 object,无需配置项目属性。")):e.createElement(e.Fragment,null,Dt(We||[],we),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>tt(we)},Se.type==="array"?v("editor.property.addItemProperty","添加项目属性"):v("editor.property.addChildProperty","添加子属性")))))})),ht=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("div",{className:"rge-segmented-control rge-tool-schema-mode",role:"radiogroup"},e.createElement("button",{type:"button",className:`rge-segmented-option${M==="visual"?" active":""}`,onClick:()=>$t("visual")},v("editor.workflowInfo.visualMode","可视化")),e.createElement("button",{type:"button",className:`rge-segmented-option${M==="code"?" active":""}`,onClick:()=>$t("code")},v("editor.workflowInfo.codeMode","JSON代码"))),M==="visual"?e.createElement("div",{className:"rge-tool-schema-editor"},Dt(xe),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>tt("")},v("editor.workflowInfo.addProperty","添加属性")),e.createElement("div",{className:"huanban_rulego_info__hint"},v("editor.workflowInfo.inputSchemaJsonHint","复杂嵌套 object/array 可切换到 JSON 代码模式编辑,已有嵌套结构会被保留。"))):e.createElement("label",{className:"huanban_rulego_info__label"},v("editor.workflowInfo.inputSchemaJson","输入定义 JSON"),e.createElement("textarea",{className:"huanban_rulego_info__textarea huanban_rulego_info__textarea--code rge-tool-schema-code",rows:14,spellCheck:!1,value:Ce,onChange:ue=>{Re(ue.target.value),le("")}})),K&&e.createElement("div",{className:"huanban_rulego_info__maintenance_status huanban_rulego_info__maintenance_status--error"},K),e.createElement("div",{className:"huanban_rulego_info__inline_actions"},e.createElement("button",{className:"huanban_rulego_info__copy_btn",type:"button",onClick:()=>{try{const ue=M==="visual"?y.generateToolSchemaFromRows(xe):y.parseJsonObjectText(Ce||"{}",{type:"object",properties:{}});Re(JSON.stringify(ue,null,2)),se(y.parseToolSchemaRows(ue)),le("")}catch(ue){le(ue instanceof Error?ue.message:v("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}}},v("editor.workflowInfo.formatJson","格式化 JSON")),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:ke,onClick:Kt},e.createElement(be,{value:k.save})," ",ke?v("editor.workflowInfo.saving","保存中..."):v("editor.workflowInfo.saveInputDefinition","保存输入定义")))),jt=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},e.createElement(be,{value:k.variable})," ",v("editor.workflowInfo.vars","变量")),e.createElement(ya,{key:`vars:${u.id}`,entries:de,onChange:z,icons:k,translate:v,keyPlaceholder:v("editor.workflowInfo.varName","变量名"),valuePlaceholder:v("editor.workflowInfo.varValue","变量值"),actionLabel:v("editor.workflowInfo.action","操作"),deleteTitle:v("editor.workflowInfo.delete","删除"),addLabel:v("editor.workflowInfo.add","添加"),batchDeleteLabel:v("editor.workflowInfo.batchDelete","批量删除"),batchDeleteConfirm:v("editor.workflowInfo.batchDeleteConfirm","确定删除选中的 {{count}} 项吗?"),deleteConfirm:v("editor.workflowInfo.deleteEntryConfirm","确定删除“{{key}}”吗?"),selectLabel:v("editor.workflowInfo.select","选择"),selectedCountLabel:v("editor.workflowInfo.selectedCount","已选择 {{count}} 项"),selectRowLabel:v("editor.workflowInfo.selectRow","选择第 {{index}} 项")}),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:ke,onClick:()=>Tt("vars")},e.createElement(be,{value:k.save})," ",v("editor.workflowInfo.saveVars","保存变量")),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(be,{value:k.secret})," ",v("editor.workflowInfo.secrets","秘钥")),e.createElement(ya,{key:`secrets:${u.id}`,entries:G,onChange:ye,icons:k,translate:v,keyPlaceholder:v("editor.workflowInfo.secretName","秘钥名"),valuePlaceholder:v("editor.workflowInfo.secretValue","秘钥值"),valueType:"password",actionLabel:v("editor.workflowInfo.action","操作"),deleteTitle:v("editor.workflowInfo.delete","删除"),addLabel:v("editor.workflowInfo.add","添加"),batchDeleteLabel:v("editor.workflowInfo.batchDelete","批量删除"),batchDeleteConfirm:v("editor.workflowInfo.batchDeleteConfirm","确定删除选中的 {{count}} 项吗?"),deleteConfirm:v("editor.workflowInfo.deleteEntryConfirm","确定删除“{{key}}”吗?"),selectLabel:v("editor.workflowInfo.select","选择"),selectedCountLabel:v("editor.workflowInfo.selectedCount","已选择 {{count}} 项"),selectRowLabel:v("editor.workflowInfo.selectRow","选择第 {{index}} 项")}),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:ke,onClick:()=>Tt("secrets")},e.createElement(be,{value:k.save})," ",v("editor.workflowInfo.saveSecrets","保存秘钥"))),Ct=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},e.createElement(be,{value:k.api})," ",v("editor.workflowInfo.apiIntegration","API 集成")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.executeAPI","执行 API:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Je.executeUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.executeUrl)},e.createElement(be,{value:k.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.notifyAPI","通知 API:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Je.notifyUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.notifyUrl)},e.createElement(be,{value:k.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.openaiCompatibleAPI","OpenAI:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Je.openaiUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.openaiUrl)},e.createElement(be,{value:k.copy}))),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(be,{value:k.api})," ",v("editor.workflowInfo.webSocket","WebSocket")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.debugWS","Debug WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},Je.debugWsUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.debugWsUrl)},e.createElement(be,{value:k.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.runtimeWS","Runtime WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},Je.runtimeWsUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.runtimeWsUrl)},e.createElement(be,{value:k.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.endpointWS","Endpoint WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},Je.endpointWsHint),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.endpointWsHint)},e.createElement(be,{value:k.copy}))),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(be,{value:k.mcp})," ",v("editor.workflowInfo.mcpIntegration","MCP 集成")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.mcpSSE","MCP SSE:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},Je.mcpSseUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.mcpSseUrl)},e.createElement(be,{value:k.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.mcpStreamableHTTP","MCP HTTP:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Je.mcpStreamableUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.mcpStreamableUrl)},e.createElement(be,{value:k.copy}))),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},v("editor.workflowInfo.mcpGroupAPI","MCP 分组:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",Je.mcpGroupUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>dt(Je.mcpGroupUrl)},e.createElement(be,{value:k.copy})))),Lt=()=>{switch(Ft){case"base":return x?x(u,bt):bt;case"inputSchema":return ht;case"vars":return _?_(u,jt):jt;case"integration":return E?E(u,Wt,Ct):Ct;case"maintenance":return e.createElement(Ha,{workflow:u,fetcher:re,content:at,onError:U,locale:C,messages:O,t:j});default:{const ue=Pt.find(ve=>ve.key===Ft);return ue?ue.children:null}}};return e.createElement("div",{className:`huanban_rulego_info ${Ht} ${p}`.trim(),"data-theme":pt,"data-rg-theme":pt,style:{...Rt,...S}},e.createElement("div",{className:"huanban_rulego_info__tabs"},Jt.map(ue=>e.createElement("button",{key:ue.key,className:`huanban_rulego_info__tab ${Ft===ue.key?"huanban_rulego_info__tab--active":""}`,onClick:()=>F(ue.key)},ue.icon!==void 0&&e.createElement(be,{value:ue.icon}),ue.label))),e.createElement("div",{className:"huanban_rulego_info__content"},Lt()))};function qa(t){var o,s,u;if((o=t.endpoint)!=null&&o.trim())return t.endpoint.trim();const r=(s=t.apiBase)==null?void 0:s.trim().replace(/\/+$/,""),n=(u=t.ruleChainId)==null?void 0:u.trim();return r&&n?`${r}/rules/${encodeURIComponent(n)}/v1/chat/completions`:""}function Ks(t){return typeof t=="function"?t()||{}:t||{}}function jr(){return`copilot-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Va(t){return typeof t=="number"&&Number.isFinite(t)||typeof t=="string"&&!Number.isNaN(Date.parse(t))?t:Date.now()}function Js(t){if(t===void 0)return"";const r=new Date(t);return Number.isNaN(r.getTime())?"":`${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}`}function zs(t){var n;const r=y.filterCopilotSuccessfulTurns(t);for(let o=r.length-1;o>0;o-=1){const s=r[o];if(s.role==="assistant"&&s.status==="complete"&&((n=r[o-1])==null?void 0:n.role)==="user")return s.id}}const Ea=new WeakMap;let Gs=0;function _a(t){if(!t)return"none";const r=Ea.get(t);if(r)return r;const n=`ref-${++Gs}`;return Ea.set(t,n),n}function Ys(t){var n;const r=(n=t.conversationContextKey)==null?void 0:n.trim();return r?`context:${r}`:[`endpoint:${qa(t)}`,`fetch:${_a(t.customFetch)}`,`headers:${_a(t.fetchHeaders)}`].join("|")}function va(t){return t.map(r=>({...r,id:jr(),status:"complete",timestamp:Va(r.timestamp)}))}function Xs(t){if(!Array.isArray(t))return;const r=t.filter(n=>n&&typeof n=="object").map((n,o)=>({id:String(n.id||`tool-${o+1}`),index:typeof n.index=="number"?n.index:void 0,type:typeof n.type=="string"?n.type:void 0,name:String(n.name||"tool"),arguments:typeof n.arguments=="string"?n.arguments:void 0,result:typeof n.result=="string"?n.result:void 0,status:n.status==="error"||n.status==="cancel"||n.status==="success"||n.status==="received"?n.status:"received"}));return r.length?r:void 0}function Qs(t){return Array.isArray(t)?y.filterCopilotSuccessfulTurns(t.filter(r=>r&&typeof r=="object"&&r.role&&typeof r.content=="string").map(r=>({...r,id:String(r.id||jr()),status:r.status==="error"?"error":"complete",timestamp:Va(r.timestamp),toolCalls:Xs(r.toolCalls)}))):[]}const Ka=t=>{var M,ge,xe;const{locale:r,messages:n,t:o,initialMessages:s=[],onMessagesChange:u,onError:d,placeholder:p,className:S,style:w,disabled:R=!1}=t,b=e.useMemo(()=>Ge({locale:r,messages:n,t:o}),[r,n,o]),x=Ys(t),_=(M=t.persistence)==null?void 0:M.adapter,E=(ge=t.persistence)==null?void 0:ge.namespace,W=((xe=t.persistence)==null?void 0:xe.mode)||"component",B=e.useMemo(()=>!_||!E?null:{adapter:_,namespace:E,chainId:`${t.ruleChainId}::${x}`,mode:W},[x,_,W,E,t.ruleChainId]),U=e.useMemo(()=>y.buildEditorChatHistoryKey(B||void 0),[B]),q=U||`memory:${t.ruleChainId}:${x}:${W}`,[C,O]=e.useState(()=>va(s)),[j,k]=e.useState(q),[v,ae]=e.useState(""),[J,Y]=e.useState(!1),[re,ce]=e.useState(""),g=e.useRef(null),F=e.useRef(null),ee=e.useRef(!1),P=e.useRef(0);e.useEffect(()=>{var Ce;P.current+=1,(Ce=g.current)==null||Ce.abort(),g.current=null,Y(!1),ce(""),ee.current=!0;const se=B?Qs(y.readEditorChatHistory(B)):va(s);O(se),k(q)},[q,B]),e.useEffect(()=>{if(u==null||u(C),ee.current){ee.current=!1;return}if(!B||!U||j!==q)return;const se=y.filterCopilotSuccessfulTurns(C);y.writeEditorChatHistory(B,se)},[C,j,q,u,U,B]),e.useEffect(()=>()=>{var se;return(se=g.current)==null?void 0:se.abort()},[]),e.useEffect(()=>{const se=F.current;if(!se)return;const Ce=K=>{const le=K.detail;ce(String(le||b("editor.copilot.copyFailed","复制失败")))};se.addEventListener("copilot-code-copy-error",Ce);const Re=y.bindCopilotCodeInteractions(se,{copyLabel:b("editor.copilot.copy","复制"),copiedLabel:b("editor.copilot.copied","已复制"),copyFailedLabel:b("editor.copilot.copyFailed","复制失败"),closeLabel:b("editor.copilot.close","关闭"),codeLabel:b("editor.copilot.code","代码"),codePreviewLabel:b("editor.copilot.preview","预览")});return()=>{se.removeEventListener("copilot-code-copy-error",Ce),Re()}},[b]);const Z=e.useCallback(async(se,Ce,Re,K)=>{Y(!0);const le=new AbortController;g.current=le;const de=P.current,z=()=>P.current===de&&g.current===le;try{if(await y.streamOpenAiChatCompletion({endpoint:qa(t),model:t.model,stream:t.stream,headers:Ks(t.fetchHeaders),customFetch:t.customFetch,messages:se.map(({role:G,content:ye})=>({role:G,content:ye})),signal:le.signal,onDelta:G=>{z()&&O(ye=>ye.map(ke=>ke.id===Ce.id?{...ke,content:ke.content+G}:ke))},onReasoningDelta:G=>{z()&&O(ye=>ye.map(ke=>ke.id===Ce.id?{...ke,reasoning:(ke.reasoning||"")+G}:ke))},onToolCallDelta:G=>{z()&&O(ye=>ye.map(ke=>ke.id===Ce.id?{...ke,toolCalls:y.mergeCopilotToolCallDelta(ke.toolCalls,G)}:ke))}}),!z())return;O(G=>G.map(ye=>ye.id===Ce.id?{...ye,status:"complete",toolCalls:y.settleCopilotToolCalls(ye.toolCalls)}:ye))}catch(G){if(!z())return;if((G==null?void 0:G.name)==="AbortError")K?(O(K),ce(b("editor.copilot.cancelled","请求已取消"))):O(ye=>ye.map(ke=>ke.id===Re?{...ke,status:"error"}:ke.id===Ce.id?{...ke,status:"error",content:b("editor.copilot.cancelled","请求已取消")}:ke));else{const ye=G instanceof Error?G:new Error(String(G));ce(ye.message),O(K||(ke=>ke.filter($e=>$e.id!==Ce.id).map($e=>$e.id===Re?{...$e,status:"error"}:$e))),d==null||d(ye)}}finally{if(!z())return;g.current=null,Y(!1)}},[d,t,b]),pe=e.useCallback(async()=>{const se=v.trim();if(!se||J||R)return;const Ce=Date.now(),Re={id:jr(),role:"user",content:se,status:"complete",timestamp:Ce},K={id:jr(),role:"assistant",content:"",reasoning:"",status:"sending",timestamp:Ce},le=[...y.filterCopilotSuccessfulTurns(C),Re];O([...le,K]),ae(""),ce(""),await Z(le,K,Re.id)},[J,C,R,v,Z]),Te=e.useCallback(async se=>{var Ce;try{if(!((Ce=navigator.clipboard)!=null&&Ce.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(se)}catch{ce(b("editor.copilot.copyFailed","复制失败"))}},[b]),Pe=e.useCallback(async se=>{var z,G;if(J||R)return;const Ce=C,Re=y.filterCopilotSuccessfulTurns(Ce),K=Re.findIndex(ye=>ye.id===se);if(K<=0||((z=Re[K])==null?void 0:z.role)!=="assistant"||((G=Re[K-1])==null?void 0:G.role)!=="user")return;const le=Re.slice(0,K),de={id:jr(),role:"assistant",content:"",reasoning:"",status:"sending",timestamp:Date.now()};O([...le,de]),ce(""),await Z(le,de,void 0,Ce)},[J,C,R,Z]),_e=()=>{var se;return(se=g.current)==null?void 0:se.abort()},me=()=>{J||(B&&y.clearEditorChatHistory(B),O([]),ce(""))},H=se=>se==="user"?b("editor.copilot.userRole","用户"):b("editor.copilot.assistantRole","助手"),ne=e.useMemo(()=>zs(C),[C]);return e.createElement("section",{className:`rge-copilot ${S||""}`,style:w,"aria-label":b("editor.copilot.title","AI 助理")},e.createElement("header",{className:"rge-copilot__header"},e.createElement("strong",null,b("editor.copilot.title","AI 助理")),e.createElement("button",{type:"button",onClick:me,disabled:J||C.length===0,title:b("editor.copilot.clear","清空对话")},b("editor.copilot.clear","清空"))),e.createElement("div",{ref:F,className:"rge-copilot__messages","aria-live":"polite"},C.length===0&&e.createElement("div",{className:"rge-copilot__empty"},b("editor.copilot.empty","请输入问题开始对话")),C.map(se=>{var Ce;return e.createElement("article",{key:se.id,className:`rge-copilot__message ${se.role}${se.status==="error"?" is-error":""}`},e.createElement("div",{className:"rge-copilot__role"},H(se.role),se.status==="sending"?` · ${b("editor.copilot.sending","处理中")}`:"",se.role==="user"&&se.status==="error"?` · ${b("editor.copilot.failed","未完成")}`:""),se.reasoning&&e.createElement("details",null,e.createElement("summary",null,b("editor.copilot.reasoning","思考过程")),e.createElement("div",{className:"rge-copilot__reasoning",dangerouslySetInnerHTML:{__html:y.renderCopilotMarkdown(se.reasoning,{codeCopyLabel:b("editor.copilot.copy","复制"),codeLabel:b("editor.copilot.code","代码"),codePreviewLabel:b("editor.copilot.preview","预览"),codeFullscreenLabel:b("editor.copilot.fullscreen","全屏"),streaming:se.status==="sending"})}})),(Ce=se.toolCalls)!=null&&Ce.length?e.createElement("details",{className:"rge-copilot__tools",open:se.status==="sending","data-copilot-tool-calls":"true"},e.createElement("summary",null,b("editor.copilot.toolCalls","工具调用")," (",se.toolCalls.length,")"),e.createElement("div",{className:"rge-copilot__tool-list"},se.toolCalls.map(Re=>e.createElement("div",{key:Re.id,className:"rge-copilot__tool","data-copilot-tool-call":Re.id},e.createElement("div",{className:"rge-copilot__tool-header"},e.createElement("strong",null,Re.name),e.createElement("span",null,Re.status==="loading"?b("editor.copilot.toolRunning","处理中"):Re.status==="success"?b("editor.copilot.toolCompleted","已完成"):Re.status==="error"?b("editor.copilot.toolFailed","失败"):b("editor.copilot.toolReceived","已收到"))),Re.arguments&&e.createElement("pre",null,Re.arguments),Re.result&&e.createElement("pre",{className:"rge-copilot__tool-result"},Re.result))))):null,se.content?e.createElement("div",{className:"rge-copilot__content",dangerouslySetInnerHTML:{__html:y.renderCopilotMarkdown(se.content,{codeCopyLabel:b("editor.copilot.copy","复制"),codeLabel:b("editor.copilot.code","代码"),codePreviewLabel:b("editor.copilot.preview","预览"),codeFullscreenLabel:b("editor.copilot.fullscreen","全屏"),streaming:se.status==="sending"})}}):se.status==="sending"?e.createElement("div",{className:"rge-copilot__content"},b("editor.copilot.sending","处理中")):null,e.createElement("div",{className:"rge-copilot__message-meta"},e.createElement("time",{className:"rge-copilot__message-time"},Js(se.timestamp)),e.createElement("div",{className:"rge-copilot__message-actions"},e.createElement("button",{type:"button","data-copilot-message-action":"copy",disabled:!se.content,onClick:()=>void Te(se.content),title:b("editor.copilot.copy","复制"),"aria-label":b("editor.copilot.copy","复制")},e.createElement("span",{"aria-hidden":"true"},"⧉")),se.id===ne&&e.createElement("button",{type:"button","data-copilot-message-action":"regenerate",disabled:J,onClick:()=>void Pe(se.id),title:b("editor.copilot.regenerate","重新生成"),"aria-label":b("editor.copilot.regenerate","重新生成")},e.createElement("span",{"aria-hidden":"true"},"↻")))))})),re&&e.createElement("div",{className:"rge-copilot__error",role:"alert","aria-live":"assertive"},e.createElement("span",null,re),e.createElement("button",{type:"button",onClick:()=>ce(""),title:b("editor.copilot.dismissError","关闭错误提示"),"aria-label":b("editor.copilot.dismissError","关闭错误提示")},"×")),e.createElement("div",{className:"rge-copilot__input"},e.createElement("textarea",{value:v,disabled:R||J,onChange:se=>ae(se.target.value),onKeyDown:se=>{se.key==="Enter"&&!se.shiftKey&&(se.preventDefault(),pe())},placeholder:p||b("editor.copilot.placeholder","输入消息"),rows:2}),J?e.createElement("button",{type:"button",onClick:_e,title:b("editor.copilot.stop","停止请求")},b("editor.copilot.stop","停止")):e.createElement("button",{type:"button",onClick:()=>void pe(),disabled:R||!v.trim()},b("editor.copilot.send","发送"))))},Zs=t=>{const{chainId:r,baseUrl:n,apiPrefix:o,getToken:s,customFetch:u,conversationContextKey:d,...p}=t,S=(r==null?void 0:r.trim())||"",w=y.resolveAIChatEndpoint({chainId:S,baseUrl:n,apiPrefix:o}),R=e.useRef(t);R.current=t;const b=e.useCallback(async(x,_)=>{const E=R.current,W=y.resolveAIChatTransportOptions(E,_);return E.customFetch?E.customFetch(W.endpoint,W.init):fetch(W.endpoint,W.init)},[]);return e.createElement(Ka,{...p,key:S,ruleChainId:S,endpoint:w,conversationContextKey:(d==null?void 0:d.trim())||`AIChat:${w}`,customFetch:b,disabled:t.disabled||!S})},el=e.createElement("svg",{"aria-hidden":"true",focusable:"false",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round",strokeLinejoin:"round"},e.createElement("path",{d:"M12 4v3"}),e.createElement("path",{d:"M8 4h8"}),e.createElement("rect",{x:"4.5",y:"7",width:"15",height:"11.5",rx:"3.5",fill:"currentColor",opacity:".14",stroke:"currentColor"}),e.createElement("circle",{cx:"9.5",cy:"12.6",r:"1.35",fill:"currentColor",stroke:"none"}),e.createElement("circle",{cx:"14.5",cy:"12.6",r:"1.35",fill:"currentColor",stroke:"none"}),e.createElement("path",{d:"M9 16h6"}),e.createElement("path",{d:"M18.5 4.5l.8 1.9 1.9.8-1.9.8-.8 1.9-.8-1.9-1.9-.8 1.9-.8.8-1.9z",fill:"currentColor",stroke:"none"}));function tl({editorRef:t,editor:r,options:n,iconOnly:o=!0,label:s="AI助手",className:u,style:d,disabled:p,onOpen:S}){const w=()=>{var b;const R=r||((b=t==null?void 0:t.current)==null?void 0:b.editor);R==null||R.openAiAssistant(n),S==null||S()};return e.createElement("button",{type:"button",className:u,style:{width:o?30:void 0,height:30,minWidth:o?30:void 0,padding:o?0:"0 10px",borderRadius:o?"50%":6,border:"1px solid color-mix(in srgb, var(--rge-primary) 36%, transparent)",background:"var(--rge-surface)",color:"var(--rge-primary)",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,cursor:p?"not-allowed":"pointer",opacity:p?.5:1,...d},disabled:p,title:s,"aria-label":s,onClick:w},el,!o&&e.createElement("span",null,s))}const rl=({schema:t,formData:r,onChange:n,locale:o,messages:s,t:u})=>{const d=e.useMemo(()=>Ge({locale:o,messages:s,t:u}),[o,s,u]);return e.createElement("div",{className:"hb-node-form"},t.map(p=>e.createElement("div",{key:p.key,className:"rge-dynamic-form-item"},e.createElement("label",{className:"rge-dynamic-form-label"},d(p.labelKey||`fields.${p.key}`,p.label)),p.type==="boolean"?e.createElement("input",{type:"checkbox",checked:!!r[p.key],onChange:S=>n(p.key,S.target.checked)}):p.type==="json"||p.type==="textarea"?e.createElement("textarea",{value:r[p.key]||"",onChange:S=>n(p.key,S.target.value),rows:p.rows||(p.type==="json"?5:3),className:p.type==="json"?"rge-form-textarea mono":"rge-form-textarea",placeholder:p.placeholder}):p.type==="select"?e.createElement(nr,{value:String(r[p.key]??p.defaultValue??""),values:Array.isArray(r[p.key])?r[p.key].map(S=>String(S??"")).filter(Boolean):void 0,multiple:p.multiple,options:p.options||[],placeholder:p.placeholder,searchPlaceholder:d("editor.property.searchOptions","搜索选项..."),noMatchText:d("editor.property.noMatchingOptions","没有匹配的选项"),onChange:S=>n(p.key,S),onMultiChange:S=>n(p.key,S)}):e.createElement("input",{type:p.type==="number"?"number":p.type==="password"?"password":"text",value:r[p.key]||"",onChange:S=>n(p.key,p.type==="number"?S.target.value===""?"":Number(S.target.value):S.target.value),className:"rge-form-input",placeholder:p.placeholder}),p.help&&e.createElement("span",{className:"rge-form-help"},p.help))))},nl=({logs:t,locale:r,messages:n,t:o})=>{const[s,u]=e.useState([]),d=e.useRef(null),p=e.useMemo(()=>Ge({locale:r,messages:n,t:o}),[r,n,o]);return e.useEffect(()=>{t.length>200?u(t.slice(t.length-200)):u(t),d.current&&(d.current.scrollTop=d.current.scrollHeight)},[t]),e.createElement("div",{className:"hb-glass-panel",style:{height:"300px",display:"flex",flexDirection:"column"}},e.createElement("div",{style:{padding:"8px 16px",borderBottom:"1px solid var(--hb-panel-border)",fontWeight:"bold"}},p("editor.logViewer.title","调试控制台 (Debug Console)")),e.createElement("div",{ref:d,style:{flex:1,overflowY:"auto",padding:"8px",fontFamily:"monospace",fontSize:"12px"}},s.map(S=>e.createElement("div",{key:S.id,style:{padding:"4px",borderBottom:"1px solid var(--hb-border-light)",color:S.level==="error"?"var(--hb-color-danger)":S.level==="warn"?"var(--hb-color-warning)":"var(--hb-text-primary)"}},e.createElement("span",{style:{color:"var(--hb-text-secondary)",marginRight:"8px"}},"[",new Date(S.timestamp).toLocaleTimeString(),"]"),S.message)),s.length===0&&e.createElement("div",{style:{color:"var(--hb-text-secondary)",textAlign:"center",marginTop:"20px"}},p("editor.logViewer.empty","暂无调试日志"))))},al={isReady:!1,isDirty:!1,isLoading:!1,selectedNode:null,selectedEdge:null,componentGroups:[],currentNodeView:null,currentNodeModel:{},currentEdgeModel:{},canUndo:!1,canRedo:!1};function ol(t={}){const[r,n]=e.useState(al),o=e.useRef(null),s=e.useRef([]),u=e.useRef(t);e.useEffect(()=>{const b=new y.EditorCore(u.current);o.current=b;const x=b.store.subscribe(_=>{n({isReady:_.isReady,isDirty:_.isDirty,isLoading:_.isLoading,selectedNode:_.selectedNode,selectedEdge:_.selectedEdge,componentGroups:_.componentGroups,currentNodeView:_.currentNodeView,currentNodeModel:_.currentNodeModel,currentEdgeModel:_.currentEdgeModel,canUndo:_.canUndo,canRedo:_.canRedo})});return()=>{for(const _ of s.current)_();s.current=[],x(),b.destroy(),o.current=null}},[]);const d=e.useCallback(b=>{o.current&&o.current.init(b)},[]),p=e.useCallback(b=>{o.current&&o.current.loadData(b)},[]),S=e.useCallback((b,x)=>{if(o.current){const _=o.current.eventBus.on(b,x);s.current.push(_)}},[]),w=e.useCallback((b,...x)=>{o.current&&o.current.eventBus.emit(b,...x)},[]),R=e.useCallback(()=>{o.current&&o.current.eventBus.emit("editor:save",{data:{},success:!1})},[]);return{core:o.current,...r,loadData:p,on:S,emit:w,init:d,save:R}}function sl(t){const[r,n]=e.useState("default"),[o,s]=e.useState(()=>y.getThemeList("zh-CN").map(d=>d.id));e.useEffect(()=>{if(t)return n(t.theme.getTheme()),s(t.theme.getAvailableThemes().map(d=>d.name)),t.theme.onChange(d=>{n(d),s(t.theme.getAvailableThemes().map(p=>p.name))})},[t]);const u=e.useCallback(d=>{t&&t.theme.setTheme(d)},[t]);return{currentTheme:r,themes:o,setTheme:u}}function ll(t){const[r,n]=e.useState((t==null?void 0:t.i18n.getLocale())||"zh-CN"),o=e.useCallback((u,d)=>t?t.i18n.t(u,d):u,[t]),s=e.useCallback(u=>{t&&(t.i18n.setLocale(u),n(u))},[t]);return{t:o,locale:r,setLocale:s}}function Ja(){return typeof navigator>"u"?!1:/Mac|iPod|iPhone|iPad/.test(navigator.platform||"")}function cl(t){if(typeof Element>"u")return!1;const r=t instanceof Element?t:document.activeElement;if(!(r instanceof Element))return!1;const n=r.tagName.toLowerCase();return!!(n==="input"||n==="textarea"||n==="select"||r.isContentEditable||r.closest('.cm-editor, .cm-content, [data-cm-container], [contenteditable="true"]'))}function il(t){const{shortcuts:r,enabled:n=!0,target:o}=t,s=e.useRef(r);s.current=r,e.useEffect(()=>{if(!n)return;const u=Ja(),d=S=>{const w=S,R=w.key.toLowerCase();for(const b of s.current){if(R!==b.key.toLowerCase())continue;const x=b.ctrl?u?w.metaKey:w.ctrlKey:!(u?w.metaKey:w.ctrlKey),_=b.shift?w.shiftKey:!w.shiftKey,E=b.alt?w.altKey:!w.altKey;if(!(!x||!_||!E)&&!(!b.enableInInput&&cl(w.target))){w.preventDefault(),w.stopPropagation(),b.handler(w);return}}},p=o||document;return p.addEventListener("keydown",d),()=>{p.removeEventListener("keydown",d)}},[n,o])}function ul(t){const r=Ja(),n=[];return t.ctrl&&n.push(r?"⌘":"Ctrl"),t.shift&&n.push(r?"⇧":"Shift"),t.alt&&n.push(r?"⌥":"Alt"),n.push(t.key.toUpperCase()),r?n.join(""):n.join("+")}function ml(t){return[{key:"s",ctrl:!0,enableInInput:!0,description:"保存",handler:()=>{var r;return(r=t.onSave)==null?void 0:r.call(t)}},{key:"z",ctrl:!0,description:"撤销",handler:()=>{var r;return(r=t.onUndo)==null?void 0:r.call(t)}},{key:"z",ctrl:!0,shift:!0,description:"重做",handler:()=>{var r;return(r=t.onRedo)==null?void 0:r.call(t)}},{key:"y",ctrl:!0,description:"重做",handler:()=>{var r;return(r=t.onRedo)==null?void 0:r.call(t)}},{key:"delete",description:"删除",handler:()=>{var r;return(r=t.onDelete)==null?void 0:r.call(t)}},{key:"backspace",description:"删除",handler:()=>{var r;return(r=t.onDelete)==null?void 0:r.call(t)}},{key:"c",ctrl:!0,description:"复制",handler:()=>{var r;return(r=t.onCopy)==null?void 0:r.call(t)}},{key:"v",ctrl:!0,description:"粘贴",handler:()=>{var r;return(r=t.onPaste)==null?void 0:r.call(t)}},{key:"d",ctrl:!0,description:"复制节点",handler:()=>{var r;return(r=t.onDuplicate)==null?void 0:r.call(t)}},{key:"a",ctrl:!0,description:"全选",handler:()=>{var r;return(r=t.onSelectAll)==null?void 0:r.call(t)}},{key:"f2",description:"重命名节点",handler:()=>{var r;return(r=t.onRename)==null?void 0:r.call(t)}},{key:"b",ctrl:!0,description:"折叠组件库",handler:()=>{var r;return(r=t.onToggleSidebar)==null?void 0:r.call(t)}},{key:"l",ctrl:!0,shift:!0,description:"自动排版",handler:()=>{var r;return(r=t.onAutoLayout)==null?void 0:r.call(t)}},{key:"1",ctrl:!0,description:"适应画布",handler:()=>{var r;return(r=t.onFitView)==null?void 0:r.call(t)}},{key:"=",ctrl:!0,description:"放大",handler:()=>{var r;return(r=t.onZoomIn)==null?void 0:r.call(t)}},{key:"-",ctrl:!0,description:"缩小",handler:()=>{var r;return(r=t.onZoomOut)==null?void 0:r.call(t)}},{key:"escape",description:"取消选择",handler:()=>{var r;return(r=t.onEscape)==null?void 0:r.call(t)}}]}function Hr(t,r,n){const o=e.useRef(t??null),s=e.useRef(!t),u=e.useRef(t??null);u.current!==(t??null)?(u.current=t??null,o.current=t??r(),s.current=!t):o.current||(o.current=r(),s.current=!0);const d=o.current,p=e.useRef(new Map),[S,w]=e.useState(()=>({store:d,state:n(d)}));return e.useEffect(()=>{const R=s.current;let b=!1;const x=p.current.get(d);x&&(clearTimeout(x),p.current.delete(d));const _=d.subscribe(E=>{b||w({store:d,state:E})});return w({store:d,state:n(d)}),()=>{if(b=!0,_(),R){const E=setTimeout(()=>{p.current.delete(d),d.destroy()},0);p.current.set(d,E)}}},[d]),{store:d,state:S.store===d?S.state:n(d)}}function dl(t={}){const{store:r,state:n}=Hr(t.workspace,()=>new y.EditorWorkspace(t),E=>E.getState()),o=e.useCallback(E=>r.openTab(E),[r]),s=e.useCallback(E=>r.activateTab(E),[r]),u=e.useCallback((E,W)=>r.renameTab(E,W),[r]),d=e.useCallback(E=>r.togglePinned(E),[r]),p=e.useCallback(E=>r.getCloseOtherTabIds(E),[r]),S=e.useCallback(E=>r.getCloseRightTabIds(E),[r]),w=e.useCallback((E,W)=>r.setDraft(E,W),[r]),R=e.useCallback((E,W)=>r.markSaved(E,W),[r]),b=e.useCallback((E,W)=>r.setLoading(E,W),[r]),x=e.useCallback((E,W)=>r.closeTab(E,W),[r]),_=e.useCallback((E,W,B)=>r.resolveSaveConflict(E,W,B),[r]);return{workspace:r,state:n,tabs:n.tabs,activeTab:n.tabs.find(E=>E.id===n.activeTabId)??null,openTab:o,activateTab:s,renameTab:u,togglePinned:d,getCloseOtherTabIds:p,getCloseRightTabIds:S,setDraft:w,markSaved:R,setLoading:b,closeTab:x,resolveSaveConflict:_}}function pl(t={}){const{dockStore:r,...n}=t,{store:o,state:s}=Hr(r,()=>new y.EditorDockStore(n),u=>u.getDockState());return{dock:o,state:s,setDockVisibility:e.useCallback((u,d)=>o.setDockVisibility(u,d),[o]),setDockWidth:e.useCallback((u,d)=>o.setDockWidth(u,d),[o]),setDockHeight:e.useCallback((u,d)=>o.setDockHeight(u,d),[o]),resetDockState:e.useCallback(()=>o.resetDockState(),[o])}}function gl(t={}){const{serverStatus:r,...n}=t,{store:o,state:s}=Hr(r,()=>new y.ServerStatusStore(n),u=>u.getState());return{server:o,state:s,setServerUrl:e.useCallback((u,d)=>o.setServerUrl(u,d),[o]),setServerStatus:e.useCallback((u,d)=>o.setServerStatus(u,d),[o]),recordHttpStatus:e.useCallback((u,d)=>o.recordHttpStatus(u,d),[o]),recordWebSocketStatus:e.useCallback((u,d,p)=>o.recordWebSocketStatus(u,d,p),[o]),setReconnectAttempt:e.useCallback(u=>o.setReconnectAttempt(u),[o])}}function fl(t={}){const{connectionStatus:r}=t,{store:n,state:o}=Hr(r,()=>new y.ConnectionStatusStore,s=>s.getState());return{connectionStatus:n,state:o}}function bl(t={}){const r=t.panels,n=r instanceof y.EditorPanelRegistry?r:null,o={...t,panels:Array.isArray(r)?r:void 0,syncDockVisibility:!1},{store:s,state:u}=Hr(n,()=>new y.EditorPanelRegistry(o),d=>d.getState());return e.useEffect(()=>{s.syncDockVisibility()},[s]),{panels:s,state:u,openPanel:e.useCallback((d,p)=>s.openPanel(d,p),[s]),closePanel:e.useCallback(d=>s.closePanel(d),[s]),activatePanel:e.useCallback(d=>s.activatePanel(d),[s]),setPanelExpanded:e.useCallback((d,p)=>s.setPanelExpanded(d,p),[s]),togglePanelExpanded:e.useCallback(d=>s.togglePanelExpanded(d),[s]),isPanelExpanded:e.useCallback(d=>s.isPanelExpanded(d),[s]),register:e.useCallback((d,p)=>s.register(d,p),[s]),unregister:e.useCallback(d=>s.unregister(d),[s]),getPanels:e.useCallback(d=>s.getPanels(d),[s]),getActivePanel:e.useCallback(d=>s.getActivePanel(d),[s])}}const hl=30;function yl(){return`node_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function El(t,r,n){const o=t.trim()||n;let s=o,u=1;for(;r.has(s);)s=`${o}_${u++}`;return r.add(s),s}function _n(t){try{return JSON.parse(JSON.stringify(t))}catch{return{...t,properties:{...t.properties||{}},config:t.config?{...t.config}:void 0}}}function _l(t){var b;const{confirm:r,capture:n}=Br((b=t.getContext)==null?void 0:b.call(t)),[o,s]=e.useState([]),u=e.useRef(0),d=e.useCallback(()=>{var E,W,B;const x=((E=t.getSelectedNodes)==null?void 0:E.call(t))||[];if(x.length===0){(W=t.onNotify)==null||W.call(t,"info","没有选中的节点");return}const _=x.map(_n);s(_),u.current=0,(B=t.onNotify)==null||B.call(t,"success",`已复制 ${_.length} 个节点`)},[t]),p=e.useCallback(async()=>{var q,C,O,j,k,v,ae,J,Y;const x=((q=t.getSelectedNodes)==null?void 0:q.call(t))||[];if(x.length===0){(C=t.onNotify)==null||C.call(t,"info","没有选中的节点");return}const _=x.map(re=>re.originalId),E=JSON.stringify([x,(O=t.getContext)==null?void 0:O.call(t)]),W=n();if(((j=t.canDeleteNodes)==null?void 0:j.call(t))===!1)return;let B=!1;try{B=t.confirmDeleteNodes?await t.confirmDeleteNodes(_):await r(`确认剪切并删除 ${_.length} 个节点吗?此操作不可撤销。`)}catch{return}if(!B||!W()||((k=t.canDeleteNodes)==null?void 0:k.call(t))===!1||E!==JSON.stringify([((v=t.getSelectedNodes)==null?void 0:v.call(t))||[],(ae=t.getContext)==null?void 0:ae.call(t)]))return;const U=x.map(_n);s(U),u.current=0,(J=t.onDeleteNodes)==null||J.call(t,_),(Y=t.onNotify)==null||Y.call(t,"success",`已剪切 ${U.length} 个节点`)},[t]),S=e.useCallback(()=>{var W,B,U,q;if(o.length===0){(W=t.onNotify)==null||W.call(t,"info","剪贴板为空");return}u.current+=1;const x=hl*u.current,_=new Set(((B=t.getExistingNodeIds)==null?void 0:B.call(t))||[]);o.forEach(C=>_.add(String(C.originalId)));const E=o.map(C=>{const O=_n(C),j=El(yl(),_,`node_${C.originalId||"copy"}`),k=C.x+x,v=C.y+x;return{...O,originalId:j,x:k,y:v,properties:y.cloneNodePropertiesForCopy(O.properties||{},{nodeId:j,nodeType:O.type,nodeName:O.name,layoutX:k,layoutY:v})}});(U=t.onAddNodes)==null||U.call(t,E),(q=t.onNotify)==null||q.call(t,"success",`已粘贴 ${E.length} 个节点`)},[o,t]),w=e.useCallback(()=>{var x;(x=t.onSelectAll)==null||x.call(t)},[t]),R=e.useCallback(()=>{s([]),u.current=0},[]);return{copy:d,cut:p,paste:S,selectAll:w,hasContent:o.length>0,clipboardCount:o.length,clear:R}}const za=e.forwardRef((t,r)=>{const n=e.useRef(null),o=e.useRef(null),s=e.useMemo(()=>Ge(t),[t.locale,t.messages,t.t]),u=e.useRef({props:t,translate:s});u.current={props:t,translate:s};const d=e.useMemo(()=>y.getThemeRuntimeVariables(t.theme),[t.theme]);return e.useImperativeHandle(r,()=>({reload:()=>{var p;return((p=o.current)==null?void 0:p.reload())??Promise.resolve(!1)},isDirty:()=>{var p;return((p=o.current)==null?void 0:p.isDirty())??!1},requestClose:()=>{var p;return((p=o.current)==null?void 0:p.requestClose())??Promise.resolve(!1)}}),[]),e.useEffect(()=>{if(!n.current)return;const p={get opts(){return u.current.props.opts},get readOnly(){return u.current.props.readOnly},get capabilities(){return u.current.props.capabilities},get components(){return u.current.props.components},get _nodeComponents(){return u.current.props._nodeComponents},get connectionStatus(){return u.current.props.connectionStatus},get serverStatus(){return u.current.props.serverStatus},get acquireSharedConnectionStatuses(){return u.current.props.acquireSharedConnectionStatuses},get reloadComponents(){return u.current.props.reloadComponents},_activeDrawerWrapper:n.current,t:(w,R)=>u.current.translate(w,"",R)},S=y.createSharedNodeManager(p,n.current);return o.current=S,()=>{S.destroy(),o.current===S&&(o.current=null)}},[t.opts.apiBase,t.opts.fetchTimeout,t.opts.fetchHeaders,t.opts.customFetch,t.opts.onApiAuthRequired,t.serverStatus]),e.useEffect(()=>{var p,S,w;(p=o.current)==null||p.refresh(),t.active===!1?(S=o.current)==null||S.deactivate():(w=o.current)==null||w.activate()}),e.createElement("div",{ref:n,className:["rge-shared-node-manager",t.className].filter(Boolean).join(" "),"data-rg-theme":y.normalizeEditorTheme(t.theme),style:{fontFamily:"var(--hb-font-family, system-ui, sans-serif)",...d,...t.style}})});za.displayName="SharedNodeManager";Object.defineProperty(exports,"ConnectionStatusController",{enumerable:!0,get:()=>y.ConnectionStatusController});Object.defineProperty(exports,"ConnectionStatusStore",{enumerable:!0,get:()=>y.ConnectionStatusStore});Object.defineProperty(exports,"DEFAULT_ROUTES",{enumerable:!0,get:()=>y.DEFAULT_ROUTES});Object.defineProperty(exports,"RuleChainAPI",{enumerable:!0,get:()=>y.RuleChainAPI});Object.defineProperty(exports,"normalizeConnectionStatusMap",{enumerable:!0,get:()=>y.normalizeConnectionStatusMap});Object.defineProperty(exports,"resolveConnectionStatusView",{enumerable:!0,get:()=>y.resolveConnectionStatusView});exports.AIAssistant=tl;exports.AIChat=Zs;exports.ComponentSidebar=wa;exports.ContextMenu=Aa;exports.CopilotChat=Ka;exports.CrossChainSearchPanel=xs;exports.DataViewDialog=La;exports.DebugPanel=Da;exports.DynamicForm=rl;exports.EdgePropertyDrawer=Pa;exports.EditorConnectionStatus=bs;exports.EditorEdgeHoverTools=vs;exports.EditorIcon=be;exports.EditorNodeHoverTools=_s;exports.EditorPanelDock=Es;exports.EditorStatusBar=fs;exports.EditorToolbar=Ma;exports.ImportExportDialog=ws;exports.LogViewer=nl;exports.MiniMap=Oa;exports.NodePropertyDrawer=Ia;exports.ProblemsPanel=Fa;exports.RuleChainSettings=ja;exports.RuleGoEditor=Na;exports.RuleMaintenancePanel=Ha;exports.SearchPanel=Ss;exports.SearchableSelect=nr;exports.SharedNodeManager=za;exports.ValidationPanel=$a;exports.WorkflowExplorer=Os;exports.WorkflowInfoPanel=Vs;exports.WorkflowList=Ms;exports.WorkspaceTabs=gs;exports.createFrameworkTranslator=Ge;exports.getCanvasContextMenuItems=ms;exports.getDefaultEditorShortcuts=ml;exports.getEdgeContextMenuItems=us;exports.getNodeContextMenuItems=is;exports.getShortcutLabel=ul;exports.normalizeFrameworkLocale=ln;exports.relationTypeLabel=Nn;exports.useClipboard=_l;exports.useConnectionStatus=fl;exports.useEditorCore=ol;exports.useEditorDock=pl;exports.useEditorI18n=ll;exports.useEditorPanels=bl;exports.useEditorTheme=sl;exports.useEditorWorkspace=dl;exports.useKeyboardShortcuts=il;exports.useServerStatus=gl;