@huanban/rulego-editor-react 1.4.2 → 2.0.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"),h=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((d,w)=>vn(d,r[w],n,o));if(!St(t)||!St(r))return!1;const u=Object.keys(t),g=Object.keys(r);return u.length!==g.length?!1:u.every(d=>Object.prototype.hasOwnProperty.call(r,d)&&vn(t[d],r[d],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 To(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 g of So){const d=St(s)?s[g]:void 0,w=St(u)?u[g]:void 0;(St(d)||St(w))&&(n[o][g]=Xr(St(d)?d:null,St(w)?w:{}))}}return n}const Na=e.forwardRef(function(r,n){var ye;const{height:o="100%",width:s="100%",className:u,style:g,slots:d,panelSlots:w,apiBase:S,fetchTimeout:D,fetchHeaders:f,apiCacheKey:x,customFetch:_,data:y,dataUpdatePolicy:B,components:j,enableConnectionStatus:W,visible:q,onConnectionStatusChange:v,mode:A,capabilities:$,toolbar:k,showWorkspaceTabs:C,workflowFetcher:oe,versionsFetcher:K,globalConfigFetcher:X,settingsPanes:re,disabled:ce,showToolbar:p,toolbarTitle:Q,showToolbarButtonLabels:ie,toolbarIconOnly:U,showSidebar:te,sidebarWidth:ge,sidebarCollapsed:Se,showInfoButton:xe,showAiChatButton:ve,showSettingsButton:ue,showDebugConsoleButton:F,showDiagnosticsButton:Z,showClearDebugHighlightButton:O,showSelectionButton:se,showExportDialog:Re,showRunButton:ae,showComponentManage:Ee,showDeployButton:Ie,showRestartButton:H,showReloadButton:de,showRunHistory:pe,runHistoryUrl:J,showTraceButton:z,showDebugTab:fe,locale:ke,messages:je,autoLoadLocales:dt,theme:We,lfOptions:G,lfPlugins:qe,coreOptions:ct,exportDataTransform:gt,onNodeConfigRequest:Ot,options:R,onReady:Pe,onSave:nt,saveMode:Et,saveHandler:at,onSaveSuccess:wt,onSaveError:xt,onExternalDataConflict:At,onNodeClick:Tt,onNodeDbClick:ze,onEdgeClick:Rt,onChange:Bt,onInfoClick:$t,onExportDSL:Ht,onImportDSL:Pt,onRunClick:Kt,onFlow:Jt,onTraceClick:_t,onComponentManage:Dt,onLocaleChange:vt,onDeploy:Ft,onRestart:le,onSelectRuleChain:Ce,onDeleteRuleChain:we,onRunHistory:Te,ruleItems:Oe,rulesApi:Ge,renderNode:E}=r,_e=y??(R==null?void 0:R.data),$e=pn(j)?j:R==null?void 0:R.components,ft=gt??(R==null?void 0:R.exportDataTransform)??((ye=ct??(R==null?void 0:R.coreOptions))==null?void 0:ye.exportDataTransform),ht=e.useRef(null),me=e.useRef(null),It=e.useRef(_e),it=e.useRef($e),[nr,Wt]=e.useState([]),[st,Zt]=e.useState([]),ut=e.useRef(new Map),Lt=e.useRef(new Map),dr=e.useRef(0),pr=e.useRef(!1),sr=(l,m)=>Object.fromEntries(Object.entries(m||{}).filter(([T,P])=>P!=null&&P!==!1&&(l==="panel"||h.EDITOR_REGION_IDS.includes(T))).map(([T])=>{const P=`${l}:${T}`;return Lt.current.has(P)||Lt.current.set(P,{mount(ne,Be){const rt={id:++dr.current,kind:l,name:T,container:ne,context:Be},Je=()=>{pr.current&&Zt(Array.from(ut.current.values()))};return ut.current.set(rt.id,rt),Je(),{update(Qe){rt.context=Qe,Je()},destroy(){ut.current.delete(rt.id),Je()}}}}),[T,Lt.current.get(P)]})),yt=sr("region",d),Ut=sr("panel",w),Ye=R!=null&&R.regions||Object.keys(yt).length?{...R==null?void 0:R.regions,...yt}:void 0,ar=R!=null&&R.panelRenderers||Object.keys(Ut).length?{...R==null?void 0:R.panelRenderers,...Ut}:void 0,Ve=e.useRef({onSave:nt,saveHandler:at,onSaveSuccess:wt,onSaveError:xt,onExternalDataConflict:At,onReady:Pe,onNodeClick:Tt,onNodeDbClick:ze,onEdgeClick:Rt,onChange:Bt,onInfoClick:$t,onExportDSL:Ht,onImportDSL:Pt,onRunClick:Kt,onFlow:Jt,onTraceClick:_t,onComponentManage:Dt,onLocaleChange:vt,onDeploy:Ft,onRestart:le,onSelectRuleChain:Ce,onDeleteRuleChain:we,onRunHistory:Te,exportDataTransform:ft,onNodeConfigRequest:Ot}),qt=e.useRef(v);qt.current=v;const De=e.useRef(R),gr=e.useRef({onAuthExpired:l=>{var m,T;return(T=(m=De.current)==null?void 0:m.onAuthExpired)==null?void 0:T.call(m,l)},onApiAuthRequired:l=>{var m,T;return(T=(m=De.current)==null?void 0:m.onApiAuthRequired)==null?void 0:T.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,T;return(T=(m=De.current)==null?void 0:m.onSettingsClick)==null?void 0:T.call(m,l)},onSettingsSubmit:l=>{var m,T;return(T=(m=De.current)==null?void 0:m.onSettingsSubmit)==null?void 0:T.call(m,l)},onUiSettingsChange:l=>{var m,T;return(T=(m=De.current)==null?void 0:m.onUiSettingsChange)==null?void 0:T.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,T;return(T=(m=De.current)==null?void 0:m.onSaveConflict)==null?void 0:T.call(m,l)},onRestartConfirm:l=>{var m,T;return(T=(m=De.current)==null?void 0:m.onRestartConfirm)==null?void 0:T.call(m,l)}}),fr=e.useRef({}),ot=e.useRef({}),zt=e.useRef(null);e.useEffect(()=>{De.current=R;const l={};qr.forEach(T=>{l[T]=typeof(R==null?void 0:R[T])=="function"}),fr.current=l;const m={};gn.forEach(T=>{m[T]=T==="exportDataTransform"?typeof ft=="function":typeof r[T]=="function"||typeof(R==null?void 0:R[T])=="function"}),ot.current=m,Ve.current={onSave:nt,saveHandler:at,onSaveSuccess:wt,onSaveError:xt,onExternalDataConflict:At,onReady:Pe,onNodeClick:Tt,onNodeDbClick:ze,onEdgeClick:Rt,onChange:Bt,onInfoClick:$t,onExportDSL:Ht,onImportDSL:Pt,onRunClick:Kt,onFlow:Jt,onTraceClick:_t,onComponentManage:Dt,onLocaleChange:vt,onDeploy:Ft,onRestart:le,onSelectRuleChain:Ce,onDeleteRuleChain:we,onRunHistory:Te,exportDataTransform:ft,onNodeConfigRequest:Ot}});const bt=e.useRef({request:l=>{var m,T,P,ne;(T=(m=Ve.current).onSave)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onSaveRequest)==null||ne.call(P,l)},handler:(l,m)=>{var P,ne;const T=Ve.current.saveHandler;return T?T(l,m):(ne=(P=De.current)==null?void 0:P.saveHandler)==null?void 0:ne.call(P,l,m)},legacyHandler:(l,m)=>{var T,P;return(P=(T=De.current)==null?void 0:T.onSave)==null?void 0:P.call(T,l,m)},success:l=>{var m,T,P,ne;(T=(m=Ve.current).onSaveSuccess)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onSaveSuccess)==null||ne.call(P,l)},error:l=>{var m,T,P,ne;(T=(m=Ve.current).onSaveError)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onSaveError)==null||ne.call(P,l)},conflict:l=>{var m,T,P,ne;(T=(m=Ve.current).onExternalDataConflict)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onExternalDataConflict)==null||ne.call(P,l)}}),Xe=e.useRef({onReady:l=>{var m,T,P,ne;(T=(m=Ve.current).onReady)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onReady)==null||ne.call(P,l)},onSave:bt.current.legacyHandler,saveHandler:bt.current.handler,onSaveRequest:bt.current.request,onSaveSuccess:bt.current.success,onSaveError:bt.current.error,onExternalDataConflict:bt.current.conflict,onNodeClick:l=>{var m,T,P,ne;(T=(m=Ve.current).onNodeClick)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onNodeClick)==null||ne.call(P,l)},onNodeDbClick:l=>{var m,T,P,ne;(T=(m=Ve.current).onNodeDbClick)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onNodeDbClick)==null||ne.call(P,l)},onEdgeClick:l=>{var m,T,P,ne;(T=(m=Ve.current).onEdgeClick)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onEdgeClick)==null||ne.call(P,l)},onChange:()=>{var l,m,T,P;(m=(l=Ve.current).onChange)==null||m.call(l),(P=(T=De.current)==null?void 0:T.onChange)==null||P.call(T)},onInfoClick:l=>{var m,T,P,ne;(T=(m=Ve.current).onInfoClick)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onInfoClick)==null||ne.call(P,l)},onExportDSL:l=>{var m,T,P,ne;(T=(m=Ve.current).onExportDSL)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onExportDSL)==null||ne.call(P,l)},onImportDSL:l=>{var m,T,P,ne;(T=(m=Ve.current).onImportDSL)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onImportDSL)==null||ne.call(P,l)},onRunClick:l=>{var m,T,P,ne;(T=(m=Ve.current).onRunClick)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onRunClick)==null||ne.call(P,l)},onFlow:(l,m)=>{var T,P,ne,Be;(P=(T=Ve.current).onFlow)==null||P.call(T,l,m),(Be=(ne=De.current)==null?void 0:ne.onFlow)==null||Be.call(ne,l,m)},onTraceClick:l=>{var m,T,P,ne;(T=(m=Ve.current).onTraceClick)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onTraceClick)==null||ne.call(P,l)},onComponentManage:l=>{var m,T,P,ne;(T=(m=Ve.current).onComponentManage)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onComponentManage)==null||ne.call(P,l)},onLocaleChange:l=>{var m,T,P,ne;(T=(m=Ve.current).onLocaleChange)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onLocaleChange)==null||ne.call(P,l)},onDeploy:(l,m)=>{var P;const T=Ve.current.onDeploy??((P=De.current)==null?void 0:P.onDeploy);return T==null?void 0:T(l,m)},onRestart:l=>{var T;const m=Ve.current.onRestart??((T=De.current)==null?void 0:T.onRestart);return m==null?void 0:m(l)},onSelectRuleChain:l=>{var m,T,P,ne;(T=(m=Ve.current).onSelectRuleChain)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onSelectRuleChain)==null||ne.call(P,l)},onDeleteRuleChain:l=>{var m,T,P,ne;(T=(m=Ve.current).onDeleteRuleChain)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onDeleteRuleChain)==null||ne.call(P,l)},onRunHistory:l=>{var m,T,P,ne;(T=(m=Ve.current).onRunHistory)==null||T.call(m,l),(ne=(P=De.current)==null?void 0:P.onRunHistory)==null||ne.call(P,l)},exportDataTransform:l=>{var m,T;return(T=(m=Ve.current).exportDataTransform)==null?void 0:T.call(m,l)},onNodeConfigRequest:(l,m)=>{var P;const T=Ve.current.onNodeConfigRequest??((P=De.current)==null?void 0:P.onNodeConfigRequest);return(T==null?void 0:T(l,m))===!0}});e.useEffect(()=>{var Ue,mt,Gt;if(!ht.current)return;pr.current=!0,ut.current.clear(),Zt([]);const l=!!(at||R!=null&&R.saveHandler),m=!l&&typeof(R==null?void 0:R.onSave)=="function",T={...(()=>{const Ke={...R};return qr.forEach(Ae=>{typeof Ke[Ae]=="function"&&(Ke[Ae]=gr.current[Ae])}),Ke})(),container:ht.current,regions:Ye,panelRenderers:ar,...Qt({apiBase:S,fetchTimeout:D,fetchHeaders:f,apiCacheKey:x,customFetch:_,data:_e??void 0,components:pn($e)?$e:void 0,dataUpdatePolicy:B,enableConnectionStatus:W,visible:q}),...Qt({mode:A,capabilities:$,toolbar:k,showWorkspaceTabs:C,workflowFetcher:oe,versionsFetcher:K,globalConfigFetcher:X,settingsPanes:re,disabled:ce,showToolbar:p,toolbarTitle:Q,showToolbarButtonLabels:ie,toolbarIconOnly:U,showSidebar:te,sidebarWidth:ge,sidebarCollapsed:Se,showInfoButton:xe,showAiChatButton:ve,showSettingsButton:ue,showDebugConsoleButton:F,showDiagnosticsButton:Z,showClearDebugHighlightButton:O,showSelectionButton:se,showExportDialog:Re,showRunButton:ae,showComponentManage:Ee,showDeployButton:Ie,showRestartButton:H,showReloadButton:de,showRunHistory:pe,runHistoryUrl:J,showTraceButton:z,showDebugTab:fe}),capabilities:h.mergeEditorCapabilities((Ue=De.current)==null?void 0:Ue.capabilities,h.mergeEditorCapabilities({},$)),toolbar:{...Qt(((mt=De.current)==null?void 0:mt.toolbar)||{}),...Qt(k||{})},...Qt({locale:ke,messages:je,autoLoadLocales:dt,theme:We}),...Qt({lfOptions:G,lfPlugins:qe,coreOptions:ct}),...Qt({ruleItems:Oe,rulesApi:Ge}),onReady:Xe.current.onReady,...Qt({saveMode:Et??(R==null?void 0:R.saveMode),saveHandler:l?at||(R==null?void 0:R.saveHandler):void 0,onSave:m?R==null?void 0:R.onSave:void 0,onSaveRequest:bt.current.request,onSaveSuccess:bt.current.success,onSaveError:bt.current.error,onExternalDataConflict:bt.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},P=new h.HuanbanRulegoEditor(T);me.current=P,It.current=_e,it.current=$e,zt.current=null;const ne=P.connectionStatus.subscribe(Ke=>{var Ae;(Ae=qt.current)==null||Ae.call(qt,Ke)});(Gt=qt.current)==null||Gt.call(qt,P.connectionStatus.getState());let Be=null;const rt=setTimeout(()=>{Be=requestAnimationFrame(()=>{if(Be=null,P.lf&&ht.current){const{clientWidth:Ke,clientHeight:Ae}=P.canvasEl||ht.current;if(Ke>0&&Ae>0)try{P.lf.resize(Ke,Ae)}catch{}}})},100),Je=Ke=>{Wt(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=>{Wt(Ae=>Ae.filter(Yt=>Yt.id!==Ke.id))};return P.core&&(P.core.eventBus.on("node:html-mount",Je),P.core.eventBus.on("node:html-unmount",Qe)),()=>{P.core&&(P.core.eventBus.off("node:html-mount",Je),P.core.eventBus.off("node:html-unmount",Qe)),clearTimeout(rt),Be!==null&&(cancelAnimationFrame(Be),Be=null),ne(),pr.current=!1,P.destroy(),ut.current.clear(),me.current=null}},[]),e.useEffect(()=>{var Qe,Ue,mt,Gt,Ke;const l=me.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 T=!!(at||(Qe=De.current)!=null&&Qe.saveHandler),P=!T&&typeof((Ue=De.current)==null?void 0:Ue.onSave)=="function",ne={};qr.forEach(Ae=>{ne[Ae]=fr.current[Ae]?gr.current[Ae]:void 0});const Be={};gn.forEach(Ae=>{Be[Ae]=ot.current[Ae]||!ko.has(Ae)?Xe.current[Ae]:void 0});const rt={...m,regions:Ye,panelRenderers:ar,...Qt({apiBase:S,fetchTimeout:D,fetchHeaders:f,apiCacheKey:x,customFetch:_,dataUpdatePolicy:B,enableConnectionStatus:W,visible:q,mode:A,capabilities:$,toolbar:k,showWorkspaceTabs:C,workflowFetcher:oe,versionsFetcher:K,globalConfigFetcher:X,settingsPanes:re,disabled:ce,showToolbar:p,toolbarTitle:Q,showToolbarButtonLabels:ie,toolbarIconOnly:U,showSidebar:te,sidebarWidth:ge,sidebarCollapsed:Se,showInfoButton:xe,showAiChatButton:ve,showSettingsButton:ue,showDebugConsoleButton:F,showDiagnosticsButton:Z,showClearDebugHighlightButton:O,showSelectionButton:se,showExportDialog:Re,showRunButton:ae,showComponentManage:Ee,showDeployButton:Ie,showRestartButton:H,showReloadButton:de,showRunHistory:pe,runHistoryUrl:J,showTraceButton:z,showDebugTab:fe,locale:ke,messages:je,autoLoadLocales:dt,theme:We,coreOptions:ct,ruleItems:Oe,rulesApi:Ge,saveMode:Et??((mt=De.current)==null?void 0:mt.saveMode)}),capabilities:h.mergeEditorCapabilities(m.capabilities,h.mergeEditorCapabilities({},$)),toolbar:{...Qt(m.toolbar||{}),...Qt(k||{})},...ne,...Be,saveHandler:T?at||((Gt=De.current)==null?void 0:Gt.saveHandler):void 0,onSave:P?(Ke=De.current)==null?void 0:Ke.onSave:void 0,onSaveRequest:bt.current.request,onSaveSuccess:bt.current.success,onSaveError:bt.current.error,onExternalDataConflict:bt.current.conflict};if(xo(zt.current,rt))return;const Je=To(zt.current,rt);zt.current=Cn(rt),l.updateOptions(Je)}),e.useEffect(()=>{Object.is(It.current,_e)||(It.current=_e,_e&&me.current&&me.current.updateOptions({data:_e}))},[_e]),e.useEffect(()=>{Object.is(it.current,$e)||(it.current=$e,pn($e)&&me.current&&me.current.updateOptions({components:$e}))},[$e]),e.useImperativeHandle(n,()=>({get editor(){return me.current},get lf(){var l;return((l=me.current)==null?void 0:l.lf)??null},get core(){var l;return((l=me.current)==null?void 0:l.core)??null},get capabilities(){var l;return((l=me.current)==null?void 0:l.capabilities)??null},get connectionStatus(){var l;return((l=me.current)==null?void 0:l.connectionStatus)??null},get runtimeFields(){var l;return((l=me.current)==null?void 0:l.runtimeFields)??null},loadData(l,m){var T;(T=me.current)==null||T.loadData(l,m)},render(l){var m;(m=me.current)==null||m.render(l)},getData(){var l;return((l=me.current)==null?void 0:l.getData())??null},getUiConfiguration(){var l;return((l=me.current)==null?void 0:l.getUiConfiguration())??{}},applyUiConfiguration(l){var m;return((m=me.current)==null?void 0:m.applyUiConfiguration(l))??!1},resetUiConfiguration(){var l;return((l=me.current)==null?void 0:l.resetUiConfiguration())??!1},applyRuleChainDraft(l,m){var T;return((T=me.current)==null?void 0:T.applyRuleChainDraft(l,m))??Promise.resolve(!1)},activateWorkspaceTab(l){var m;return((m=me.current)==null?void 0:m.activateWorkspaceTab(l))??!1},openRuleChain(l){var m;return((m=me.current)==null?void 0:m.openRuleChain(l))??Promise.resolve(!1)},openChain(l){var m;return((m=me.current)==null?void 0:m.openChain(l))??Promise.resolve(!1)},newRuleChain(l){var m;return((m=me.current)==null?void 0:m.newRuleChain(l))??Promise.resolve(!1)},renameWorkspaceRuleChain(l){var m;return((m=me.current)==null?void 0:m.renameWorkspaceRuleChain(l))??Promise.resolve(!1)},closeWorkspaceTab(l){var m;return((m=me.current)==null?void 0:m.closeWorkspaceTab(l))??Promise.resolve(!1)},save(l){var m;return((m=me.current)==null?void 0:m.save(l))??Promise.resolve(!1)},saveAll(){var l;return((l=me.current)==null?void 0:l.saveAll())??Promise.resolve(!1)},showVersionHistory(){var l;(l=me.current)==null||l.showVersionHistory()},openGlobalConfig(){var l;(l=me.current)==null||l.openGlobalConfig()},showNodeLogSettings(l){var m;(m=me.current)==null||m.showNodeLogSettings(l)},showChainLogSettings(){var l;(l=me.current)==null||l.showChainLogSettings()},setLocale(l){var m;(m=me.current)==null||m.setLocale(l)},setLocales(l,m){var T;(T=me.current)==null||T.setLocales(l,m)},reloadLocales(){var l;return((l=me.current)==null?void 0:l.reloadLocales())??Promise.resolve(!1)},isDirty(){var l;return((l=me.current)==null?void 0:l.isDirty())??!1},flashNodes(l){var m;(m=me.current)==null||m.flashNodes(l)},setSidebarExpanded(l){var m;(m=me.current)==null||m.setSidebarExpanded(l)},loadComponents(l){var m;(m=me.current)==null||m.loadComponents(l)},exportData(){var l;return((l=me.current)==null?void 0:l.exportData())??null},toggleMiniMap(){var l;(l=me.current)==null||l.toggleMiniMap()},autoLayout(){var l;(l=me.current)==null||l.autoLayout()},openSettings(l="user"){var m;(m=me.current)==null||m.openSettings(l)},openAiAssistant(l){var m;return((m=me.current)==null?void 0:m.openAiAssistant(l))??!1},openChat(l){var m;return((m=me.current)==null?void 0:m.openChat(l))??!1},switchChatChain(l){var m;return((m=me.current)==null?void 0:m.switchChatChain(l))??Promise.resolve(!1)},closeAiAssistant(){var l;(l=me.current)==null||l.closeAiAssistant()},startTour(){var l;return((l=me.current)==null?void 0:l.startTour())??!1},closeTour(){var l;(l=me.current)==null||l.closeTour()},setTheme(l){var m;(m=me.current)==null||m.setTheme(l)},refreshTheme(){var l;(l=me.current)==null||l.refreshTheme()},updateOptions(l){var m;return((m=me.current)==null?void 0:m.updateOptions(l))??null},refreshConnectionStatuses(){var l;(l=me.current)==null||l.refreshConnectionStatuses()},setVisible(l){var m;(m=me.current)==null||m.setVisible(l)},acquireSharedConnectionStatuses(){var l;return((l=me.current)==null?void 0:l.acquireSharedConnectionStatuses())??(()=>{})},invokeAction(l,m="api"){const T=me.current;return T?T.invokeAction(l,m):Promise.reject(new Error("Editor is not ready"))},listActions(){var l;return((l=me.current)==null?void 0:l.listActions())??[]},addAction(l){var m;(m=me.current)==null||m.addAction(l)},removeAction(l){var m;return((m=me.current)==null?void 0:m.removeAction(l))??!1},registerPropertyComponent(l,m,T){var P;(P=me.current)==null||P.registerPropertyComponent(l,m,T)},resolvePropertyComponent(l){var m;return(m=me.current)==null?void 0:m.resolvePropertyComponent(l)},unregisterPropertyComponent(l){var m;return((m=me.current)==null?void 0:m.unregisterPropertyComponent(l))??!1},openCommandPalette(){var l;(l=me.current)==null||l.openCommandPalette()},openShortcutHelp(){var l;(l=me.current)==null||l.openShortcutHelp()},openNodePicker(l){var m;(m=me.current)==null||m.openNodePicker(l)},openComponentDocs(l){const m=me.current;return m?m.openComponentDocs(l):Promise.reject(new Error("Editor is not ready"))},openComponentManager(l="installed"){var m;(m=me.current)==null||m.openComponentManager(l)},closeOverlay(){var l;(l=me.current)==null||l.closeOverlay()},closeAllOverlays(){var l;(l=me.current)==null||l.closeAllOverlays()}}),[]);const Fe=h.normalizeEditorTheme(We||(R==null?void 0:R.theme)),V={...h.getThemeRuntimeVariables(Fe),width:typeof s=="number"?`${s}px`:s,height:typeof o=="number"?`${o}px`:o,position:"relative",overflow:"hidden",...g};return e.createElement(e.Fragment,null,e.createElement("div",{ref:ht,className:`rulego-editor-wrapper ${u||""}`,"data-theme":Fe,"data-rg-theme":Fe,style:V}),E&&nr.map(l=>en.createPortal(E(l.type,l.data,l.model),l.el)),st.map(l=>{const m=l.kind==="region"?d==null?void 0:d[l.name]:w==null?void 0:w[l.name];return en.createPortal(typeof m=="function"?m(l.context):m,l.container,`host-${l.id}`)}))});Na.displayName="RuleGoEditor";function Ro(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 tt(t={}){const r=ln(t.locale),n=new h.I18nManager({locale:r,fallback:r==="en-US"?"zh-CN":"en-US"});return n.register("zh-CN",h.localeZhCN),n.register("en-US",h.localeEnUS),t.messages&&n.register(r,t.messages),(o,s="",u)=>{const g=ka(t.t,o,u);if(g!==void 0)return g;const d=n.t(o,u);return d&&d!==o?d:s||o}}function Io(t,r,n,o){const s=String(t.name||"").trim(),u=`fields.${s}`,g=ka(n,u);if(g!==void 0)return g;if(Ro(o,u)){const d=r(u,t.label||s);if(d&&d!==u)return d}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 h.DEFAULT_COMPONENT_CATEGORY_ORDER.includes(t)?t:"other"}function Vr(t,r,n){return Math.max(n,Number.isFinite(t)?Number(t):r)}function Or({name:t}){return e.createElement("span",{"aria-hidden":"true",className:"rge-sidebar-control-icon",dangerouslySetInnerHTML:{__html:h.getEditorToolbarIconSvg(t)||""}})}function Xn({items:t,label:r,listKey:n,virtualization:o,renderItem:s}){const u=e.useRef(null),g=e.useRef(null),[d,w]=e.useState(0),S=Vr(o==null?void 0:o.itemHeight,h.DEFAULT_VIRTUAL_WINDOW_ITEM_HEIGHT,36),D=(o==null?void 0:o.enabled)!==!1&&t.length>Vr(o==null?void 0:o.threshold,h.DEFAULT_VIRTUAL_WINDOW_THRESHOLD,1),f=h.calculateVirtualWindow({total:t.length,itemHeight:S,viewportHeight:Vr(o==null?void 0:o.viewportHeight,h.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT,S),overscan:Vr(o==null?void 0:o.overscan,h.DEFAULT_VIRTUAL_WINDOW_OVERSCAN,0),scrollTop:d});e.useLayoutEffect(()=>{var y,B;D&&u.current&&u.current.scrollTop!==f.scrollTop&&(u.current.scrollTop=f.scrollTop),g.current!==null&&((B=(y=u.current)==null?void 0:y.querySelector(`[data-component-index="${g.current}"]`))==null||B.focus(),g.current=null)});const x=y=>{var v;if(y.altKey||y.ctrlKey||y.metaKey||y.nativeEvent.isComposing)return;const B=y.target.closest("[data-component-index]");if(!B)return;const j=Number(B.dataset.componentIndex),W=y.key==="Home"?0:y.key==="End"?t.length-1:y.key==="ArrowDown"?j+1:y.key==="ArrowUp"?j-1:y.key==="Tab"&&D?j+(y.shiftKey?-1:1):-1;if(W<0||W>=t.length){["ArrowDown","ArrowUp","Home","End"].includes(y.key)&&(y.preventDefault(),y.stopPropagation());return}const q=(v=u.current)==null?void 0:v.querySelector(`[data-component-index="${W}"]`);y.key==="Tab"&&q||(y.preventDefault(),y.stopPropagation(),q?q.focus():(g.current=W,w(Math.min(W*S,f.totalHeight-f.viewportHeight))))},_=D?f.start:0;return e.createElement("div",{ref:u,className:`rge-sidebar-component-list${D?" rge-sidebar-virtual-list":""}`,role:"group","aria-label":r,"data-sidebar-virtualized":D?"true":void 0,"data-sidebar-virtual-key":D?n:void 0,"data-sidebar-virtual-total":D?t.length:void 0,style:{"--rge-sidebar-item-height":`${S}px`,height:D?`${f.viewportHeight}px`:void 0},onKeyDown:x,onScroll:y=>{D&&w(y.currentTarget.scrollTop)}},e.createElement("div",{className:"rge-sidebar-virtual-list__canvas",style:D?{height:`${f.totalHeight}px`}:void 0},e.createElement("div",{className:"rge-sidebar-virtual-list__items",style:D?{transform:`translateY(${f.offsetTop}px)`}:void 0},(D?t.slice(f.start,f.end):t).map((y,B)=>e.createElement("div",{key:Qr(y),className:"rge-sidebar-item"},s(y,_+B))))))}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:g=!0,search:d,onSearchChange:w,searchPlaceholder:S,showNodeMgt:D=!0,onOpenNodeMgt:f,locale:x,messages:_,t:y,theme:B="default",virtualization:j})=>{const W=Mo(),q=e.useRef(null),[v,A]=e.useState(""),[$,k]=e.useState({}),[C,oe]=e.useState({query:"",values:{}}),K=(d??v).trim().toLowerCase().replace(/\s+/g," "),X=!!K;e.useEffect(()=>oe({query:K,values:{}}),[K]);const re=h.normalizeIconTheme(B),ce=ln(x)==="en-US",p=e.useMemo(()=>{const H=tt({locale:x,messages:_,t:y});return(de,pe="")=>{const J=H(de,pe);return J===de?pe:J}},[x,_,y]),Q=e.useMemo(()=>{const H=new Set,de=t.filter(pe=>{var z;const J=Qr(pe);return!((z=pe.type)!=null&&z.trim())||H.has(J)?!1:(H.add(J),!0)}).map(pe=>h.localizeComponentDefinition(h.normalizeComponentCategory({...pe,category:pe.category||"other",label:pe.label||pe.type,desc:pe.desc||"",icon:pe.icon||"",fields:pe.fields||null,relationTypes:Array.isArray(pe.relationTypes)?pe.relationTypes:[]}),J=>p(J,J)));return h.buildComponentPalette(de,"",{categoryOrder:h.DEFAULT_COMPONENT_CATEGORY_ORDER,subgroupCategories:h.hasDeclaredSubgroups,categoryLabel:(pe,J)=>{var z;return p(`category.${pe}.label`,p(`category.${pe}`,String(((z=J[0])==null?void 0:z.categoryLabel)||pe)))}}).map(pe=>({...pe,key:Po(pe.category),subgroups:pe.subgroups.map(J=>({...J,label:J.id?J.label:p("category.other","Other"),description:kn(J.description||"")}))}))},[t,p]),ie=e.useMemo(()=>{if(!X)return Q;const H=new Map;for(const pe of Q)for(const J of pe.subgroups)for(const z of J.components)H.set(Qr(z),[zn(z),Gn(z),kn(z.desc),pe.label,J.label,J.description||"",...Array.isArray(z.keywords)?z.keywords.map(String):[String(z.keywords||"")]]);const de=h.buildComponentPalette(Q.flatMap(pe=>pe.components),K,{categoryOrder:h.DEFAULT_COMPONENT_CATEGORY_ORDER,subgroupCategories:h.hasDeclaredSubgroups,componentSearchText:pe=>H.get(Qr(pe))});return Q.flatMap(pe=>{const J=de.find(z=>z.category===pe.category);return J?[{...pe,components:J.components,subgroups:pe.subgroups.flatMap(z=>{const fe=J.subgroups.find(ke=>ke.id===z.id);return fe?[{...z,components:fe.components}]:[]})}]:[]})},[Q,X,K,p]),U=e.useMemo(()=>{if(!o||X)return[];const H=new Map(Q.flatMap(de=>de.components).map(de=>[de.type,de]));return[...new Set(n)].flatMap(de=>H.has(de)?[H.get(de)]:[])},[Q,X,n,o]),te=U.length?[{key:Do,recent:!0,category:"common",color:"",label:p("editor.sidebar.recentComponents","Recently Used"),components:U,subgroups:[]},...ie]:ie,ge=H=>H.subgroups.some(de=>!!de.id),Se=te.flatMap(H=>[H.key,...ge(H)?H.subgroups.map(de=>Jn(H.category,de.id)):[]]),xe=H=>X?(C.query===K?C.values[H]:void 0)??!0:$[H]??!u,ve=Se.length>0&&Se.every(xe),ue=Se.some(xe),F=H=>{X?oe(de=>({query:K,values:{...de.query===K?de.values:{},...H}})):k(de=>({...de,...H}))},Z=H=>{d===void 0&&A(H),w==null||w(H)},O=()=>{var H;Z(""),(H=q.current)==null||H.focus()},se=H=>`${W}-${encodeURIComponent(H)}`,Re=p(ue?"editor.sidebar.collapseAll":"editor.sidebar.expandAll"),ae=p("editorShell.clearSearch",ce?"Clear search":"清空搜索"),Ee=p("editor.toolbar.componentManage"),Ie=(H,de)=>{const pe=zn(H),J=Gn(H),z=Yn(H.category),fe=h.resolveComponentIconUrl({...H,icon:void 0},{theme:re}),ke=H.themeColorMode==="theme"?void 0:H.background,je=h.safeCssColor(H.color||ke,`var(--rg-node-${z}-stroke, var(--rge-sidebar-accent))`),dt=h.safeCssColor(ke,`var(--rg-node-${z}-bg, var(--rge-sidebar-input-bg))`);return e.createElement("button",{type:"button",className:"rge-node-block",draggable:!0,"data-component-type":H.type,"data-component-index":de,"aria-label":pe,"aria-description":J||void 0,title:[pe,H.type,J].filter(Boolean).join(`
2
+ `),style:{"--rge-component-accent":je,"--rge-component-bg":dt},onClick:()=>r==null?void 0:r(H),onKeyDown:We=>{We.key!=="Enter"&&We.key!==" "||(We.preventDefault(),We.stopPropagation(),!We.repeat&&!We.nativeEvent.isComposing&&(r==null||r(H)))},onDragStart:We=>{var qe,ct;const G=JSON.stringify(H);(qe=We.dataTransfer)==null||qe.setData("application/json",G),(ct=We.dataTransfer)==null||ct.setData("application/rulego-component",G),We.dataTransfer&&(We.dataTransfer.effectAllowed="copy"),r==null||r(H)}},e.createElement("span",{className:"rge-node-block__icon","aria-hidden":"true"},e.createElement("img",{key:`${H.icon}-${re}`,src:h.resolveComponentIconUrl(H,{theme:re}),alt:"",draggable:!1,className:"rge-node-block__icon-img",onError:We=>{We.currentTarget.getAttribute("src")!==fe&&(We.currentTarget.src=fe)}})),e.createElement("span",{className:"rge-node-block__label"},pe),!H.notInput&&e.createElement("span",{"aria-hidden":"true",className:"rge-node-block__port rge-node-block__port--input"}),!H.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":p("editor.sidebar.ariaLabel"),"data-theme":re,"data-rg-theme":re,style:h.getThemeRuntimeVariables(re)},g&&e.createElement("div",{className:"rge-sidebar-search"},e.createElement("div",{className:"rge-sidebar-search-field"},e.createElement(Or,{name:"search"}),e.createElement("input",{ref:q,type:"search",className:"rge-search-input","aria-label":p("editor.sidebar.search"),placeholder:S??p("editor.sidebar.search"),value:d??v,onChange:H=>Z(H.target.value),onKeyDown:H=>{H.stopPropagation(),H.key==="Escape"&&(H.preventDefault(),O())}}),(d??v).length>0&&e.createElement("button",{type:"button",className:"rge-sidebar-clear",title:ae,"aria-label":ae,onClick:O},e.createElement(Or,{name:"error"}))),e.createElement("button",{type:"button",className:"rge-sidebar-toggle-all","data-sidebar-toggle":"all",title:Re,"aria-label":Re,"aria-pressed":ue&&!ve?"mixed":ve,disabled:!Se.length,onClick:()=>F(Object.fromEntries(Se.map(H=>[H,!ue])))},e.createElement(Or,{name:ue?"collapse-all":"expand-all"})),D&&e.createElement("button",{type:"button",className:"rge-sidebar-manage",title:Ee,"aria-label":Ee,disabled:!f,onClick:f},e.createElement(Or,{name:"settings"}))),e.createElement("div",{className:"rge-sidebar-groups"},te.map(H=>{const de=xe(H.key);return e.createElement("section",{key:H.key,className:"rge-sidebar-group","data-sidebar-category":H.recent?void 0:H.category,"data-sidebar-recent":H.recent?"true":void 0},e.createElement("button",{type:"button",className:`rge-group-header${de?" expanded":""}`,title:H.label,"aria-expanded":de,"aria-controls":se(H.key),onClick:()=>F({[H.key]:!de})},e.createElement("span",{className:"rge-group-icon","aria-hidden":"true"},e.createElement("img",{src:h.resolveIconUrl(`images/${Yn(H.category)}-dark.svg`,{theme:re}),alt:"",draggable:!1,className:"rge-group-icon-img"})),e.createElement("span",{className:"rge-group-label"},H.label),e.createElement("span",{className:"rge-group-count"},H.components.length),e.createElement("span",{"aria-hidden":"true",className:`rge-group-arrow${de?" rotated":""}`},"›")),e.createElement("div",{id:se(H.key),hidden:!de,className:"rge-group-content"},de&&(ge(H)?H.subgroups.map(pe=>{const J=Jn(H.category,pe.id),z=xe(J);return e.createElement("section",{key:J,className:"rge-sidebar-subgroup"},e.createElement("button",{type:"button",className:"rge-subgroup-header","aria-expanded":z,"aria-controls":se(J),title:[pe.label,pe.description].filter(Boolean).join(`
3
+ `),onClick:()=>F({[J]:!z})},e.createElement("span",{"aria-hidden":"true",className:`rge-subgroup-arrow${z?" rotated":""}`},"›"),e.createElement("span",null,pe.label),e.createElement("small",null,pe.components.length)),e.createElement("div",{id:se(J),hidden:!z,className:"rge-subgroup-content"},z&&e.createElement(Xn,{key:K,items:pe.components,label:pe.label,listKey:J,virtualization:j,renderItem:Ie})))}):e.createElement(Xn,{key:K,items:H.components,label:H.label,listKey:H.key,virtualization:j,renderItem:Ie}))))}),ie.length===0&&e.createElement("div",{className:"rge-sidebar-empty",role:"status","aria-live":"polite"},e.createElement(Or,{name:"package"}),e.createElement("p",null,X?p("editor.sidebar.noResult"):p("editorShell.noComponents",ce?"No components available":"暂无可用组件")))))};wa.displayName="ComponentSidebar";function Br(t,r){const n=e.useRef(r);n.current=r;const o=()=>h.createDefaultDialogProvider({t:(S,D)=>{var f;return((f=n.current)==null?void 0:f.call(n,S,D))||D},container:()=>{var S;return((S=document.activeElement)==null?void 0:S.closest("[data-rg-theme], .rge-node-drawer"))||document.body}}),s=e.useRef("");s.current=JSON.stringify(t);const u=e.useRef(!0),g=e.useRef();g.current||(g.current=o()),e.useEffect(()=>(u.current=!0,g.current||(g.current=o()),()=>{var S,D;u.current=!1,(D=(S=g.current)==null?void 0:S.destroy)==null||D.call(S),g.current=void 0}),[]);const d=e.useCallback(()=>{const S=s.current;return()=>u.current&&s.current===S},[]);return{confirm:e.useCallback(async(S,D=d())=>{try{return await g.current.confirm({message:S,type:"warning"})===!0&&D()}catch{return!1}},[d]),capture:d}}let Oo=0;const Ao=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 rr=({name:t,value:r="",values:n,options:o=[],multiple:s=!1,allowCreate:u=!1,disabled:g=!1,placeholder:d="",searchPlaceholder:w="搜索选项...",noMatchText:S="没有匹配的选项",createOptionText:D="使用",selectedCountText:f="已选 {{count}} 项",resultCountText:x="显示 {{shown}} / {{total}} 项",moreOptionsText:_="结果较多,请继续输入关键词缩小范围",className:y="rge-form-select",threshold:B=Ao,maxVisibleOptions:j=Qn,onChange:W,onMultiChange:q})=>{var Ot;const v=e.useRef(null),A=e.useRef(null),$=e.useRef(null),k=e.useRef(null),C=e.useRef(null),[oe]=e.useState(()=>`rge-select-${++Oo}`),[K,X]=e.useState(!1),[re,ce]=e.useState(""),[p,Q]=e.useState(0),[ie,U]=e.useState(1),te=e.useMemo(()=>o.map($o),[o]),ge=te.some(R=>R.value===""),Se=u||te.length>B,xe=e.useMemo(()=>n||(s&&r?r.split(",").map(R=>R.trim()).filter(Boolean):[]),[s,r,n]),ve=te.find(R=>R.value===r),ue=xe.map(R=>{var Pe;return((Pe=te.find(nt=>nt.value===R))==null?void 0:Pe.label)||R}).filter(Boolean),F=ue.length,Z=F>0?Zn(f,{count:F}):"",O=ue.slice(0,2).join(", "),se=s?F?`${Z}: ${O}${ue.length>2?" ...":""}`:d:(ve==null?void 0:ve.label)||r||d,Re=s?ue.length?ue.join(", "):d:se,ae=re.trim().toLowerCase(),Ee=e.useMemo(()=>ae?te.filter(R=>R.label.toLowerCase().includes(ae)||R.value.toLowerCase().includes(ae)||String(R.description||"").toLowerCase().includes(ae)):te,[ae,te]),Ie=Math.max(1,Number(j)||Qn),H=Ie*ie,de=e.useMemo(()=>Ee.slice(0,H),[Ee,H]),pe=Math.max(0,Ee.length-de.length),J=Zn(x,{shown:de.length,total:Ee.length,selected:F,hidden:pe}),z=re.trim(),fe=u&&!s&&z.length>0&&!te.some(R=>R.value.toLowerCase()===ae||R.label.toLowerCase()===ae),ke=de.length+(fe?1:0);e.useEffect(()=>{var Et;if(!K||g||!Se){K&&je();return}const R=A.current,Pe=$.current;if(!R||!Pe)return;const nt=h.bindAnchoredPopover({anchor:R,popup:Pe,owner:v.current||R,maxHeight:380,onDismiss:()=>je()});return C.current=nt,(Et=k.current)==null||Et.focus({preventScroll:!0}),()=>{nt.destroy(),C.current=null}},[K,g,Se]),e.useEffect(()=>{var R;(R=C.current)==null||R.update()},[re,de]),e.useEffect(()=>{var nt;const R=(nt=$.current)==null?void 0:nt.querySelector(`[data-option-index="${p}"]`),Pe=R==null?void 0:R.parentElement;!R||!Pe||(R.offsetTop<Pe.scrollTop?Pe.scrollTop=R.offsetTop:R.offsetTop+R.offsetHeight>Pe.scrollTop+Pe.clientHeight&&(Pe.scrollTop=R.offsetTop+R.offsetHeight-Pe.clientHeight))},[p,K,de.length]),e.useEffect(()=>{if(!K)return;const R=Ee.findIndex(Pe=>s?xe.includes(Pe.value):Pe.value===r);Q(R>=0?R:0),R>=0&&U(Pe=>Math.max(Pe,Math.floor(R/Ie)+1))},[K,re,s,xe,r,Ee,Ie]);const je=(R=!1)=>{var Pe;X(!1),ce(""),Q(0),U(1),R&&((Pe=A.current)==null||Pe.focus({preventScroll:!0}))},dt=()=>{g||(X(!0),ce(""),U(1))},We=R=>{q==null||q(R)},G=R=>{const Pe=xe.includes(R)?xe.filter(nt=>nt!==R):[...xe,R];We(Pe)},qe=R=>{W(R),je(!0)},ct=()=>{if(!(!K||ke<=0)){if(p<de.length){const R=de[p];if(!R)return;if(s){G(R.value);return}qe(R.value);return}fe&&qe(z)}},gt=R=>{if(!(g||R.nativeEvent.isComposing)){if(!K&&["ArrowDown","Enter"," "].includes(R.key)){R.preventDefault(),dt();return}K&&(R.key==="ArrowDown"?(R.preventDefault(),Q(Pe=>Math.min(ke-1,Pe+1))):R.key==="ArrowUp"?(R.preventDefault(),Q(Pe=>Math.max(0,Pe-1))):R.key==="Home"?(R.preventDefault(),Q(0)):R.key==="End"?(R.preventDefault(),U(Math.max(1,Math.ceil(Ee.length/Ie))),Q(Math.max(0,Ee.length+(fe?1:0)-1))):R.key==="Enter"?(R.preventDefault(),ct()):R.key==="Escape"&&(R.preventDefault(),je(!0)))}};return Se?e.createElement("div",{className:"rge-search-select",ref:v,"data-searchable-select":t||void 0},e.createElement("button",{ref:A,type:"button",className:`rge-search-select-trigger ${y}`,disabled:g,"aria-haspopup":"listbox","aria-expanded":K,"aria-controls":K?oe:void 0,"aria-multiselectable":s||void 0,"data-selected-count":F,title:Re,onKeyDown:gt,onClick:()=>{g||(K?je():dt())}},e.createElement("span",{className:`rge-search-select-display${se&&se!==d?"":" is-placeholder"}`},s&&F>0&&e.createElement("span",{className:"rge-search-select-count"},Z),e.createElement("span",{className:"rge-search-select-display-text"},s&&F>0?O:se||d)),e.createElement("span",{className:"rge-search-select-arrow"},"▾")),K&&en.createPortal(e.createElement("div",{ref:$,className:"rge-search-select-popover",onKeyDown:R=>R.stopPropagation()},e.createElement("input",{ref:k,className:"rge-search-select-input",value:re,onChange:R=>{ce(R.target.value),Q(0),U(1)},onKeyDown:gt,placeholder:w,"aria-label":w||d,role:"combobox","aria-controls":oe,"aria-expanded":"true","aria-autocomplete":"list","aria-activedescendant":ke>0?`${oe}-${p}`:void 0}),e.createElement("div",{className:"rge-search-select-list",id:oe,role:"listbox","aria-multiselectable":s||void 0,onScroll:R=>{const Pe=R.currentTarget;pe>0&&Pe.scrollTop+Pe.clientHeight>=Pe.scrollHeight-32&&U(nt=>nt+1)}},Ee.length===0&&!fe?e.createElement("div",{className:"rge-search-select-empty"},S):de.map((R,Pe)=>e.createElement("button",{type:"button",key:R.value,className:`rge-search-select-option${(s?xe.includes(R.value):R.value===r)?" selected":""}${Pe===p?" active":""}`,role:"option",id:`${oe}-${Pe}`,"data-option-index":Pe,"aria-selected":s?xe.includes(R.value):R.value===r,onMouseEnter:()=>Q(Pe),onClick:()=>{if(s){G(R.value);return}qe(R.value)}},e.createElement("span",{className:"rge-search-select-label"},R.label),R.label!==R.value&&e.createElement("span",{className:"rge-search-select-value"},R.value),R.description&&e.createElement("span",{className:"rge-search-select-desc"},R.description))),fe&&e.createElement("button",{type:"button",className:`rge-search-select-option rge-search-select-create${p===de.length?" active":""}`,role:"option",id:`${oe}-${de.length}`,"data-option-index":de.length,"aria-selected":!1,onMouseEnter:()=>Q(de.length),onClick:()=>{qe(z)}},e.createElement("span",{className:"rge-search-select-label"},D," ",z))),e.createElement("div",{className:"rge-search-select-footer","data-searchable-select-count":!0},e.createElement("span",null,J),pe>0&&e.createElement("span",{className:"rge-search-select-more"},_))),((Ot=v.current)==null?void 0:Ot.ownerDocument.body)||document.body)):s?e.createElement("select",{className:y,value:xe,multiple:!0,onChange:R=>{We(Array.from(R.target.selectedOptions).map(Pe=>Pe.value))},disabled:g},te.map(R=>e.createElement("option",{key:R.value,value:R.value},R.label))):e.createElement("select",{className:y,value:r,onChange:R=>W(R.target.value),disabled:g},d&&!ge&&e.createElement("option",{value:""},d),te.map(R=>e.createElement("option",{key:R.value,value:R.value},R.label)))};rr.displayName="SearchableSelect";const be=({value:t,className:r=""})=>{const n=typeof t=="string"?h.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 jt=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")},Ct=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}},Ta=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=>Ta(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 g=String(u??"");!g||o.has(g)||(n.push({label:g,value:g}),o.add(g))}),n.map(u=>({label:xa(u),value:rn(u),description:Fo(u)}))},vr=t=>{var r;return Ct(t)==="select"||jt(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=>Ct(t)==="rulechainselector"||tn(t)==="rulechains",nn=t=>Ct(t)==="switch"||["boolean","bool"].includes(jt(t)),ta=t=>["textarea","json-editor"].includes(Ct(t))||["textarea","json"].includes(jt(t)),Ar=t=>{const r=Ct(t),n=jt(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(Ct(t)),xn=t=>{const r=Ct(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(Ct(t))||["jsscript","json"].includes(jt(t)),ra=t=>t==null?"":typeof t=="object"?JSON.stringify(t,null,2):String(t),na=t=>Ct(t)==="switchnode",Cr=t=>{const r=Ct(t);return r==="tools"||r==="subagents"},aa=t=>Ct(t)==="subagents"?"subagent":"tool",or=t=>{const r=jt(t),n=Ct(t);return r==="array"||n==="array"||n==="table"},oa=t=>{const r=jt(t),n=Ct(t);return r==="struct"||r==="object"||n==="struct"||n==="object"},hr=t=>jt(t)==="map"||Ct(t)==="map",sa=t=>{const r=Ct(t),n=jt(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(Ct(t)),ca=t=>jt(t)==="duration"||Ct(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(Ta).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:g}=Br([t,r],s),d=Ir(t),w=h.decodeTableRowsForEditing(d,r),S=F=>n(h.encodeTableRowsForStorage(d,F)),D=h.getTableColumns(d,w),f=h.getTableDetailFields(d),x=d.some(F=>String(F.name).trim().toLowerCase()==="type"),[_,y]=e.useState(1),[B,j]=e.useState(50),[W,q]=e.useState(""),[v,A]=e.useState([]),[$,k]=e.useState(null),[C,oe]=e.useState(""),[K,X]=e.useState({prefix:"",start:0,count:10,step:1,type:"",namePrefix:""}),re=h.findDuplicateRowValues(w),ce=w.map((F,Z)=>({row:F,index:Z})).filter(({row:F})=>{const Z=W.trim().toLowerCase();return Z?D.some(O=>String(F[O]??"").toLowerCase().includes(Z)):!0}),p=h.paginateTableRows(ce,_,B);e.useEffect(()=>{y(F=>Math.min(F,p.totalPages)),A(F=>F.filter(Z=>Z>=0&&Z<w.length)),k(F=>F!==null&&F>=w.length?null:F)},[w.length,p.totalPages]);const Q=(F,Z,O)=>{const se=d.find(Ie=>Ie.name===Z),Re=h.coerceTableCellValue(se,O),ae=w.map((Ie,H)=>H===F?{...Ie,[Z]:Re}:Ie),Ee=S(ae);se&&o(se,`${t.name}.${F}.${Z}`,Re,Ee)},ie=(F,Z,O)=>{var de,pe;const se=d.find(J=>J.name===O),Re=F[O]??"",ae=String(Re),Ee=se?Ct(se):"",Ie=Array.isArray((de=se==null?void 0:se.component)==null?void 0:de.options)?se.component.options:Array.isArray(se==null?void 0:se.options)?se.options:[];if(!!(se&&Ee==="select"&&!((pe=se.component)!=null&&pe.allowCreate))){const J=Sn(Ie,Re),z=ae===""&&!J.some(fe=>fe.value==="")?[{label:"",value:""},...J]:J;return e.createElement("select",{className:"rge-form-input",value:ae,"data-point-cell":O,onChange:fe=>Q(Z,O,fe.target.value)},z.map(fe=>e.createElement("option",{key:fe.value,value:fe.value},fe.label)))}return se&&nn(se)?e.createElement("input",{type:"checkbox",checked:!!Re,"data-point-cell":O,onChange:J=>Q(Z,O,J.target.checked)}):e.createElement("input",{className:"rge-form-input",type:se&&an(se)?"number":"text",value:ae,"data-point-cell":O,onChange:J=>Q(Z,O,J.target.value)})},U=()=>{S([...w,h.createEmptyTableRow(d)]),y(Math.max(1,Math.ceil((w.length+1)/B))),f.length>0&&k(w.length)},te=async F=>{if(F.length===0)return;const Z=s("editor.property.confirmDeleteRows",`确认删除 ${F.length} 行?`,{count:String(F.length)});if(!await u(Z))return;const O=new Set(F);S(w.filter((se,Re)=>!O.has(Re))),A([]),k(null)},ge=F=>{if(!F)return;oe("");const Z=new FileReader,O=g();Z.onload=async()=>{if(!O())return;const se=h.parseCsvTable(String(Z.result||""));if(se.length===0)return;(!h.getPointTableImportDecision(w,se).requiresConfirmation||await u(s("editor.property.confirmReplacePointTable",`导入 ${se.length} 条将替换当前 ${w.length} 条点位,是否继续?`,{incoming:String(se.length),existing:String(w.length)})))&&(S(se),k(null))},Z.readAsText(F)},Se=async F=>{if(F){oe("");try{const Z=g(),O=await h.parseExcelTable(await F.arrayBuffer());if(!Z())return;if(O.length===0){oe(s("editor.property.emptyExcelTable","Excel 中没有有效数据"));return}(!h.getPointTableImportDecision(w,O).requiresConfirmation||await u(s("editor.property.confirmReplacePointTable",`导入 ${O.length} 条将替换当前 ${w.length} 条点位,是否继续?`,{incoming:String(O.length),existing:String(w.length)})))&&(S(O),k(null))}catch(Z){oe(s("editor.property.excelImportFailed","Excel 导入失败: {{message}}",{message:Z instanceof Error?Z.message:String(Z)}))}}},xe=()=>{oe("");const F=h.serializeCsvTable(w,D),Z=new Blob([`\uFEFF${F}`],{type:"text/csv;charset=utf-8"}),O=URL.createObjectURL(Z),se=document.createElement("a");se.href=O,se.download=`${t.name||"table"}.csv`,se.click(),URL.revokeObjectURL(O)},ve=async()=>{oe("");try{const F=await h.serializeExcelTable(w,D),Z=F.buffer.slice(F.byteOffset,F.byteOffset+F.byteLength),O=new Blob([Z],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),se=URL.createObjectURL(O),Re=document.createElement("a");Re.href=se,Re.download=`${t.name||"table"}.xlsx`,Re.click(),URL.revokeObjectURL(se)}catch(F){oe(s("editor.property.excelExportFailed","Excel 导出失败: {{message}}",{message:F instanceof Error?F.message:String(F)}))}},ue=()=>{const F=h.generatePointRows({...K,type:x?K.type:void 0,existing:w});F.length>0&&S([...w,...F]),y(Math.max(1,Math.ceil((w.length+F.length)/B)))};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:W,placeholder:s("editor.property.searchTable","搜索表格"),onChange:F=>{q(F.target.value),y(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:F=>{var Z;ge((Z=F.target.files)==null?void 0:Z[0]),F.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:F=>{var O;const Z=(O=F.currentTarget.files)==null?void 0:O[0];F.currentTarget.value="",Se(Z)}})),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:xe,disabled:w.length===0},s("editor.property.exportCsv","导出 CSV")),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:()=>{ve()},disabled:w.length===0},s("editor.property.exportExcel","导出 Excel")),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:()=>te(v),disabled:v.length===0},s("editor.property.deleteSelected","删除所选")),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:U},s("editor.panel.addPair","+ 添加"))),C&&e.createElement("span",{className:"rge-point-table-error",role:"alert"},C)),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:K.prefix,placeholder:s("editor.property.pointPrefix","地址前缀"),onChange:F=>X({...K,prefix:F.target.value})}),e.createElement("input",{className:"rge-form-input",type:"number",value:K.start,placeholder:s("editor.property.pointStart","起始编号"),onChange:F=>X({...K,start:Number(F.target.value)||0})}),e.createElement("input",{className:"rge-form-input",type:"number",min:"1",value:K.count,placeholder:s("editor.property.pointCount","数量"),onChange:F=>X({...K,count:Math.max(1,Number(F.target.value)||1)})}),e.createElement("input",{className:"rge-form-input",type:"number",min:"1",value:K.step,placeholder:s("editor.property.pointStep","步长"),onChange:F=>X({...K,step:Math.max(1,Number(F.target.value)||1)})}),x&&e.createElement("input",{className:"rge-form-input",value:K.type,placeholder:s("editor.property.pointType","数据类型"),onChange:F=>X({...K,type:F.target.value})}),e.createElement("input",{className:"rge-form-input",value:K.namePrefix,placeholder:s("editor.property.pointNamePrefix","名称前缀"),onChange:F=>X({...K,namePrefix:F.target.value})}),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:ue},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:p.items.length>0&&p.items.every(F=>v.includes(F.index)),onChange:F=>A(F.target.checked?[...new Set([...v,...p.items.map(Z=>Z.index)])]:v.filter(Z=>!p.items.some(O=>O.index===Z)))})),D.map(F=>{var Z;return e.createElement("th",{key:F},((Z=d.find(O=>O.name===F))==null?void 0:Z.label)||F)}),e.createElement("th",null,s("editor.property.actions","操作")))),e.createElement("tbody",null,p.items.map(({row:F,index:Z})=>e.createElement(e.Fragment,{key:Z},e.createElement("tr",{className:re.has(String(F.name??"").trim())?"is-duplicate":void 0},e.createElement("td",null,e.createElement("input",{type:"checkbox",checked:v.includes(Z),onChange:O=>A(se=>O.target.checked?[...new Set([...se,Z])]:se.filter(Re=>Re!==Z))})),D.map(O=>e.createElement("td",{key:O},ie(F,Z,O))),e.createElement("td",{className:"rge-point-row-actions"},f.length>0&&e.createElement("button",{type:"button",className:"rge-btn-icon-edit","data-point-edit":Z,"aria-expanded":$===Z,title:s("editor.property.editRowDetails","编辑行详情"),onClick:()=>k(O=>O===Z?null:Z)},"✎"),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",title:s("editor.property.delete","删除"),onClick:()=>te([Z])},"×"))),f.length>0&&$===Z&&e.createElement("tr",{className:"rge-point-detail-row","data-point-detail-row":Z},e.createElement("td",{colSpan:D.length+2},e.createElement("div",{className:"rge-point-detail-grid"},f.map(O=>e.createElement("label",{key:O.name,className:"rge-point-detail-field"},e.createElement("span",null,O.label||O.name),ie(F,Z,O.name),mr(O.desc)&&e.createElement("small",null,mr(O.desc))))))))))),p.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",`共 ${p.total} 条`,{count:String(p.total)})),e.createElement("select",{value:B,onChange:F=>{j(Number(F.target.value)),y(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:()=>y(F=>F-1)},s("editor.property.prevPage","上一页")),e.createElement("span",null,p.page," / ",p.totalPages),e.createElement("button",{type:"button",disabled:_>=p.totalPages,onClick:()=>y(F=>F+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)||jt(t)==="number"?Number(n):parseInt(n,10):""}return r},Ra=(t,r)=>{const n=String(r??"").trim();return n?{label:String(t??n)||n,value:n}:null},Tn=12,wr=(t=Tn)=>({items:[],total:0,page:1,size:t,loading:!1,error:""}),on=(t,r,n)=>{const o=Ra(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}},Rn=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=h.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 g of t||[]){const d=g,w=d.properties,S=(w==null?void 0:w.model)||w||d,D=String(S.id||d.id||"").trim();if(!D||D===n||o.has(D))continue;const f=typeof d.text=="object"?(u=d.text)==null?void 0:u.value:d.text,x=Ra(S.name||f||D,D);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(),g=(s==null?void 0:s.name)||(o==null?void 0:o.name)||(o==null?void 0:o.label)||u,d=on(g,u,s);!d||r.has(d.value)||(r.add(d.value),n.push(d))}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 h.stringifyToolJson(n,"{}")},bn=t=>{var s;if(!t||typeof t!="object")return Rn(t);const r=t,n=r.ruleChain&&typeof r.ruleChain=="object"?r.ruleChain:r,o=Rn(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)=>h.updateSchemaRowsAtParent(t,r,s=>{const u=n+o;if(u<0||u>=s.length)return;const[g]=s.splice(n,1);if(!g)return;s.splice(u,0,g);const d=h.renumberSchemaRowOrders(s);s.splice(0,s.length,...d)}),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:g,t:d,graphNodes:w,ruleItems:S,currentRuleChain:D,rulesApi:f,apiBase:x,rulePageSize:_,fetchRuleChains:y,componentsPayload:B,componentPayload:j,builtinTools:W,tools:q,skillPath:v,fetchBuiltinTools:A,onOpenAiAssistant:$,aiProviders:k,aiEmbeddingProviders:C,resolveFieldsByType:oe,optionSourceRegistry:K,fieldChangeRegistry:X,onFieldChangeError:re,initializeDefaults:ce=!1})=>{var Kn;const[p,Q]=e.useState({}),[ie,U]=e.useState("{}"),[te,ge]=e.useState(""),[Se,xe]=e.useState({}),[ve,ue]=e.useState({}),[F,Z]=e.useState({}),[O,se]=e.useState("custom"),[Re,ae]=e.useState(""),[Ee,Ie]=e.useState("custom"),[H,de]=e.useState(""),[pe,J]=e.useState([]),[z,fe]=e.useState(null),[ke,je]=e.useState(()=>wr()),[dt,We]=e.useState({}),[G,qe]=e.useState(null),[ct,gt]=e.useState([]),[Ot,R]=e.useState(!1),[Pe,nt]=e.useState(""),[Et,at]=e.useState(()=>wr()),[wt,xt]=e.useState({}),[At,Tt]=e.useState(""),[ze,Rt]=e.useState(""),[Bt,$t]=e.useState({}),[Ht,Pt]=e.useState(0),[Kt]=e.useState(()=>`react-drawer-${++Vo}`),Jt=e.useRef(""),_t=e.useRef({}),Dt=e.useRef({}),vt=e.useRef({}),Ft=e.useRef(null),le=e.useRef(new Map),Ce=e.useRef({}),we=e.useRef(new Set),Te=e.useRef(new Set),Oe=e.useRef(""),Ge=e.useMemo(()=>new h.OptionSourceRegistry,[]),E=e.useMemo(()=>tt({locale:u,messages:g,t:d}),[u,g,d]);_t.current=p,Dt.current=Se,vt.current=ve,Oe.current=String((r==null?void 0:r.nodeId)||(r==null?void 0:r.id)||"");const _e=e.useCallback(a=>{const c=a(_t.current);return _t.current=c,Q(c),c},[]),$e=e.useCallback(a=>{const c=a(Dt.current);return Dt.current=c,xe(c),c},[]),ft=e.useCallback(a=>{const c=a(vt.current);return vt.current=c,ue(c),c},[]);e.useEffect(()=>{var c;const a=new AbortController;return(c=Ft.current)==null||c.abort(),Ft.current=a,le.current.clear(),Pt(0),Ce.current={},Te.current.clear(),$t({}),()=>{a.abort(),Ft.current===a&&(Ft.current=null)}},[X,r==null?void 0:r.id,r==null?void 0:r.nodeId,t]);const{confirm:ht}=Br([t,D,r,p,Se,ve],E),me=e.useCallback(async a=>{if(typeof window>"u")return;const c=E("editor.property.confirmDeleteRows","确认删除 1 行?",{count:"1"});await ht(c)&&a()},[E,ht]),It=e.useMemo(()=>({searchPlaceholder:E("editor.property.searchOptions","搜索选项..."),noMatchText:E("editor.property.noMatchingOptions","没有匹配的选项"),createOptionText:E("editor.form.useInputValue","使用"),selectedCountText:E("editor.property.selectedCount","已选 {{count}} 项"),resultCountText:E("editor.property.selectResultCount","显示 {{shown}} / {{total}} 项"),moreOptionsText:E("editor.property.moreOptionsHint","结果较多,请继续输入关键词缩小范围")}),[E]),it=e.useCallback(a=>Io(a,E,d,g),[g,d,E]),nr=e.useMemo(()=>Yo(w,r),[w,r]),Wt=e.useMemo(()=>Qo(S),[S]),st=e.useMemo(()=>Math.max(1,Number(_||Tn)||Tn),[_]),Zt=e.useMemo(()=>Go(f,x),[x,f]),ut=!!(y||Zt),Lt=e.useMemo(()=>h.getBuiltinToolOptionsFromSources(W,q,B,j),[W,j,B,q]),dr=e.useMemo(()=>ct.length>0?ct:Lt,[ct,Lt]),pr=e.useMemo(()=>h.getSkillPathFromSources(v,B,j),[j,B,v]),sr=e.useMemo(()=>Wt.map(a=>({label:a.label,value:a.value})),[Wt]),yt=e.useMemo(()=>Xo(D),[D]),Ut=e.useCallback(a=>n?h.resolveComponentFields(n,{configuration:a,getFieldsByType:oe}):[],[n,oe]),Ye=e.useMemo(()=>Ut(p.configuration||(r==null?void 0:r.configuration)||{}),[p.configuration,r==null?void 0:r.configuration,Ut]),ar=e.useMemo(()=>h.getVisibleComponentFields(Ye,p.configuration||{}),[p.configuration,Ye]),Ve=e.useMemo(()=>h.buildFieldAttachments(Ye),[Ye]),qt=e.useMemo(()=>new Set([...Ve.values()].flatMap(a=>a.map(c=>c.field.name))),[Ve]);we.current=qt;const De=At?Ve.get(At)||[]:[],gr=De.filter(a=>h.isFieldDependencySatisfied(a.field,p.configuration)),fr=new Set(De.map(a=>a.field.name)),ot=[...le.current.keys()].filter(a=>[...fr].some(c=>kr(c,a))).length,zt=Object.entries(Bt).filter(([a])=>Te.current.has(a)||[...qt].some(c=>kr(c,a))),bt=zt.filter(([a])=>[...fr].some(c=>kr(c,a))),Xe=e.useMemo(()=>{const a=[...(n==null?void 0:n.groups)||[]].sort((b,L)=>(b.order??0)-(L.order??0)),c=new Set,i=a.map(b=>{const L=new Set(b.fields||[]),M=ar.filter(I=>L.has(I.name));return M.forEach(I=>c.add(I.name)),{id:b.id,label:b.label||b.id,description:b.description,collapsed:b.collapsed,fields:M}}).filter(b=>b.fields.length>0),N=ar.filter(b=>!c.has(b.name));return N.length>0&&i.unshift({id:"",label:"",description:void 0,collapsed:!1,fields:N}),i},[n==null?void 0:n.groups,ar]),Fe=e.useMemo(()=>Ye.find(a=>a.ref==="primary")||null,[Ye]),V=e.useMemo(()=>Fe?null:Ye.find(a=>a.aiProvider||a.name==="provider")||null,[Fe,Ye]),ye=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"?h.getAiEmbeddingProviders(C):h.getAiProviders(k)).map(c=>ea(c,E)).filter(Boolean):[],[C,k,V,E]),m=e.useCallback(a=>{var b;const c=wt[a.name];if(a.optionsSource&&(c!=null&&c.options))return c.options;if(a.name===ye.model&&pe.length>0)return pe;const i=((b=a.component)==null?void 0:b.options)||a.options||[],N=tn(a);return N==="nodes"&&nr.length>0?nr:N==="rulechains"&&sr.length>0?sr:i},[nr,wt,ye.model,pe,sr]),T=e.useMemo(()=>h.buildOptionSourceRequestKey(Ye,{configuration:p.configuration||{},currentNodeId:String((r==null?void 0:r.nodeId)||(r==null?void 0:r.id)||""),graphNodes:(w||[]).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)}),[p.configuration,w,r==null?void 0:r.id,r==null?void 0:r.nodeId,Ye]);e.useEffect(()=>{const a=Ye.filter(M=>M.optionsSource);if(a.length===0){xt({});return}const c=new AbortController,i=K||Ge,N=p.configuration||{},b=String((r==null?void 0:r.nodeId)||(r==null?void 0:r.id)||""),L=(w||[]).map(M=>{var I,Y,Ne;return{id:String(M.id||M.nodeId||""),name:String(M.name||(typeof M.text=="object"?(I=M.text)==null?void 0:I.value:M.text)||M.id||M.nodeId||""),type:String(M.type||((Ne=(Y=M.properties)==null?void 0:Y.model)==null?void 0:Ne.type)||"")}}).filter(M=>!!M.id);return xt(M=>Object.fromEntries(a.map(I=>{var Y,Ne;return[I.name,{options:((Y=M[I.name])==null?void 0:Y.options)||((Ne=I.component)==null?void 0:Ne.options)||I.options||[],loading:!0,error:""}]}))),Promise.all(a.map(async M=>{try{const I=await i.resolve(M,{configuration:N,currentNodeId:b,graphNodes:L,signal:c.signal});if(c.signal.aborted)return;xt(Y=>({...Y,[M.name]:{options:I,loading:!1,error:""}}))}catch(I){if(c.signal.aborted)return;xt(Y=>{var Ne,ee;return{...Y,[M.name]:{options:((Ne=Y[M.name])==null?void 0:Ne.options)||((ee=M.component)==null?void 0:ee.options)||M.options||[],loading:!1,error:I instanceof Error?I.message:String(I)}}})}})),()=>c.abort()},[Ge,K,T]);const P=e.useCallback((a,c,i=!1)=>{const N=Sn(m(a),c);return!i||!yt?N:N.filter(b=>b.value!==yt)},[yt,m]),ne=e.useCallback((a,c)=>{var M;const N=[...Wt.length>0?Wt:Zo(((M=a.component)==null?void 0:M.options)||a.options||[])],b=new Set(N.map(I=>I.value));Object.values(dt).forEach(I=>{b.has(I.value)||(N.push(I),b.add(I.value))});const L=String(c??"").trim();return L&&!b.has(L)&&N.push({label:L,value:L}),N},[dt,Wt]),Be=e.useCallback((a,c)=>{var N;const i=String(c??"").trim();return i?((N=ne(a,i).find(b=>b.value===i))==null?void 0:N.label)||i:""},[ne]),rt=e.useCallback(()=>{const a=Object.values(dt).map(i=>({...i})),c=Wt.map(i=>({...i}));return hn([...c,...a].map(bn).filter(Boolean)).filter(i=>!yt||i.value!==yt)},[yt,dt,Wt]),Je=e.useMemo(()=>Fe?P(Fe,Re):[],[P,Fe,Re]);e.useEffect(()=>{var lt,Xt,er;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||{}};_t.current=i,Q(i);const N={},b={},L=new Map(c.map(Ze=>[Ze.name,Ze]));Object.entries(a).forEach(([Ze,et])=>{const pt=L.get(Ze);pt&&or(pt)&&!(vr(pt)||na(pt)||Nr(pt,et)||Cr(pt))&&(Array.isArray(et)||typeof et=="string")?b[Ze]=h.normalizeSimpleArrayValues(et).map(ir=>({value:ir})):pt&&hr(pt)&&!Array.isArray(et)&&et&&typeof et=="object"&&!(et instanceof Date)&&(N[Ze]=Object.entries(et).map(([ir,dn])=>({key:ir,value:h.formatMapEntryValue(dn,h.getMapValueMode(pt))})))}),Dt.current=N,vt.current=b,xe(N),ue(b),Z({});const M=c.find(Ze=>Ze.ref==="primary"),I=M!=null&&M.name?a[M.name]:"",Y=String(I??""),Ne=Y.startsWith("ref://");se(Ne?"shared":"custom"),ae(Ne?Y:"");const ee=M?null:c.find(Ze=>Ze.aiProvider||Ze.name==="provider")||null,he={provider:((lt=ee==null?void 0:ee.aiProvider)==null?void 0:lt.providerField)||(ee==null?void 0:ee.name)||"provider",url:((Xt=ee==null?void 0:ee.aiProvider)==null?void 0:Xt.urlField)||"url",model:((er=ee==null?void 0:ee.aiProvider)==null?void 0:er.modelField)||"model"},He=ee?(ee.providerType==="embedding"?h.getAiEmbeddingProviders(C):h.getAiProviders(k)).map(Ze=>ea(Ze,E)).filter(Boolean):[],Le={...a};if(ee){const Ze=String(a[he.provider]??""),et=He.find(ir=>ir.value===Ze),pt=!!(et&&Ze!=="custom");Ie(pt?"preset":"custom"),de(pt?Ze:""),J(pt?(et==null?void 0:et.models)||[]:[]),pt&&(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 Ie("custom"),de(""),J([]);fe(null),je(wr(st)),qe(null),at(wr(st)),U(JSON.stringify(a,null,2)),ge(""),Tt(""),Rt(""),Jt.current=JSON.stringify(h.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(Ee!=="preset"||!H)return;const a=l.find(c=>c.value===H);a&&J(a.models||[])},[Ee,l,H]),e.useEffect(()=>{Lt.length!==0&&(gt(Lt),nt(""))},[Lt]);const Qe=e.useCallback((a,c)=>{_e(i=>({...i,[a]:c}))},[_e]),Ue=e.useCallback(()=>{const a={..._t.current.configuration||{}},c=new Map(Ye.map(i=>[i.name,i]));return Object.entries(Dt.current).forEach(([i,N])=>{const b=c.get(i);if(!b||!hr(b))return;const L={},M=h.getMapValueMode(b);N.forEach(I=>{I.key&&(L[I.key]=h.parseMapEntryValue(I.value,M))}),a[i]=L}),Object.entries(vt.current).forEach(([i,N])=>{const b=c.get(i);!b||!or(b)||Nr(b,a[i])||Cr(b)||vr(b)||(a[i]=N.map(L=>L.value).filter(Boolean))}),a},[Ye]),mt=e.useCallback((a,c)=>{const i={...Ue(),[a]:c};return _e(N=>({...N,configuration:i})),i},[Ue,_e]),Gt=e.useCallback(a=>{const c=Ue();for(const b of a.remove||[])delete c[b];Object.assign(c,xr(a.patch||{})),_e(b=>({...b,configuration:c}));const i=new Set([...Object.keys(a.patch||{}),...a.remove||[]]),N=new Map(Ye.map(b=>[b.name,b]));if([...i].some(b=>hr(N.get(b)||{}))&&$e(b=>{const L={...b};return i.forEach(M=>{const I=N.get(M);if(!I||!hr(I))return;const Y=c[M];!Y||typeof Y!="object"||Array.isArray(Y)?delete L[M]:L[M]=Object.entries(Y).map(([Ne,ee])=>({key:Ne,value:h.formatMapEntryValue(ee,h.getMapValueMode(I))}))}),L}),[...i].some(b=>{const L=N.get(b);return L&&or(L)&&!Nr(L,c[b])&&!Cr(L)&&!vr(L)})&&ft(b=>{const L={...b};return i.forEach(M=>{const I=N.get(M);!I||!or(I)||Nr(I,c[M])||Cr(I)||vr(I)||(Object.prototype.hasOwnProperty.call(c,M)?L[M]=h.normalizeSimpleArrayValues(c[M]).map(Y=>({value:Y})):delete L[M])}),L}),Fe!=null&&Fe.name&&i.has(Fe.name)){const b=String(c[Fe.name]??"");ae(b.startsWith("ref://")?b:""),se(b.startsWith("ref://")?"shared":"custom")}if(i.has(ye.provider)){const b=String(c[ye.provider]??""),L=l.find(M=>M.value===b);Ie(L&&b!=="custom"?"preset":"custom"),de(L&&b!=="custom"?b:""),J((L==null?void 0:L.models)||[])}},[Ue,Fe,ye.provider,l,ft,_e,$e,Ye]),Ke=e.useCallback((a,c,i,N)=>{const b=h.getFieldChangeHandlerName(a);if(!b)return;const L=Oe.current,M=Ft.current,I=(he,He=0)=>{if(M!=null&&M.signal.aborted||Oe.current!==L)return;const Le=he instanceof Error?he.message:String(he);(we.current.has(a.name)||a.attachTo)&&Te.current.add(c);const lt={...Ce.current,[c]:Le};Ce.current=lt,$t(lt),re==null||re(he,{field:a,fieldPath:c,handlerName:b,generation:He})};if(!X||!M){I(new Error(E("editor.property.fieldChangeUnavailable","字段联动处理器不可用: {{name}}",{name:b})));return}Te.current.delete(c);const Y={...Ce.current};delete Y[c],Ce.current=Y,$t(Y);const Ne=(w||[]).map(he=>{var He,Le,lt;return{id:String(he.id||he.nodeId||""),name:String(he.name||(typeof he.text=="object"?(He=he.text)==null?void 0:He.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 ee;ee=X.execute(a,i,{configuration:N,currentNodeId:L,graphNodes:Ne,requestKey:`${Kt}:${L||"__draft__"}:${c}`,signal:M.signal,fieldPath:c}).then(he=>{he.status!=="applied"||M.signal.aborted||Oe.current!==L||Gt(he)}).catch(he=>{M.signal.aborted||he instanceof Error&&he.name==="AbortError"||I(he)}).finally(()=>{le.current.get(c)===ee&&(le.current.delete(c),Pt(le.current.size))}),le.current.set(c,ee),Pt(le.current.size)},[Gt,Kt,X,w,re,E]),Ae=e.useCallback((a,c,i)=>{const N=mt(a.name,i);Ke(a,c,i,N)},[Ke,mt]),Yt=e.useCallback((a,c)=>{je(wr(st)),fe({fieldName:a.name,value:String(c??""),tab:"sub",keyword:"",page:1})},[st]),Vt=e.useCallback(a=>{fe(c=>c&&{...c,...a})},[]),yr=e.useCallback(a=>{if(!z)return;We(i=>zr(i,[a]));const c=Ye.find(i=>i.name===z.fieldName);c?Ae(c,c.name,a.value):mt(z.fieldName,a.value),fe(null)},[Ae,Ye,z,mt]);e.useEffect(()=>{if(!z||!ut)return;const a=new AbortController,c=z.tab,i=z.keyword.trim(),N=z.page,b=st,L=window.setTimeout(()=>{je(M=>({...M,page:N,size:b,loading:!0,error:""})),(async()=>{try{let M;if(y)M=await y({root:c==="root",keywords:i,page:N,size:b,signal:a.signal});else{const ee=new URLSearchParams;ee.set("root",c==="root"?"true":"false"),i&&ee.set("keywords",i),ee.set("page",String(N)),ee.set("size",String(b));const he=await fetch(`${Zt}?${ee.toString()}`,{signal:a.signal});if(!he.ok)throw new Error(`HTTP ${he.status}`);M=await he.json()}const I=Jr(M,N,b),Y=I.items.map(Rn).filter(Boolean),Ne=yt?Y.filter(ee=>ee.value!==yt):Y;if(a.signal.aborted)return;We(ee=>zr(ee,Ne)),je({items:Ne,total:Math.max(0,I.total-(Y.length-Ne.length)),page:I.page||N,size:I.size||b,loading:!1,error:""})}catch(M){if(a.signal.aborted||(M==null?void 0:M.name)==="AbortError")return;je({items:[],total:0,page:N,size:b,loading:!1,error:E("editor.panel.loadFailed",`加载失败: ${(M==null?void 0:M.message)||String(M)}`,{message:String((M==null?void 0:M.message)||M)})})}})()},i?180:0);return()=>{window.clearTimeout(L),a.abort()}},[yt,st,y,z,Zt,E,ut]);const Dn=e.useCallback(async()=>{if(Lt.length>0){gt(Lt),nt("");return}const a=String(x||"").trim().replace(/\/+$/,"");if(!A&&!a)return;const c=new AbortController;R(!0),nt("");try{const i=A?await A({signal:c.signal}):await fetch(`${a}/components`,{signal:c.signal}).then(L=>{if(!L.ok)throw new Error(`HTTP ${L.status}`);return L.json()}),N=i&&typeof i=="object"&&"data"in i?i.data:i,b=h.getBuiltinToolOptionsFromSources(N,i);gt(b)}catch(i){(i==null?void 0:i.name)!=="AbortError"&&nt(E("editor.panel.loadFailed",`加载失败: ${(i==null?void 0:i.message)||String(i)}`,{message:String((i==null?void 0:i.message)||i)}))}finally{R(!1)}},[x,A,Lt,E]);e.useEffect(()=>{if(!G||G.step!=="select"||G.activeTab!=="rulechain"||!ut)return;const a=new AbortController,c=G.keyword.trim(),i=G.ruleChainPage,N=st,b=window.setTimeout(()=>{at(L=>({...L,page:i,size:N,loading:!0,error:""})),(async()=>{try{let L;if(y){const[Ne,ee]=await Promise.all([y({root:!1,keywords:c,page:i,size:N,signal:a.signal}),y({root:!0,keywords:c,page:i,size:N,signal:a.signal})]),he=Jr(Ne,i,N),He=Jr(ee,i,N);L={items:[...he.items,...He.items],total:he.total+He.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 ee=await fetch(`${Zt}?${Ne.toString()}`,{signal:a.signal});if(!ee.ok)throw new Error(`HTTP ${ee.status}`);L=await ee.json()}const M=Jr(L,i,N),I=M.items.map(bn).filter(Boolean),Y=hn(I).filter(Ne=>!yt||Ne.value!==yt);if(a.signal.aborted)return;We(Ne=>zr(Ne,Y)),at({items:Y,total:Math.max(0,M.total-(I.length-Y.length)),page:M.page||i,size:M.size||N,loading:!1,error:""})}catch(L){if(a.signal.aborted||(L==null?void 0:L.name)==="AbortError")return;at({items:[],total:0,page:i,size:N,loading:!1,error:E("editor.panel.loadFailed",`加载失败: ${(L==null?void 0:L.message)||String(L)}`,{message:String((L==null?void 0:L.message)||L)})})}})()},c?180:0);return()=>{window.clearTimeout(b),a.abort()}},[yt,st,y,Zt,G,E,ut]);const Ln=e.useCallback(a=>{if(a===O||(se(a),!(Fe!=null&&Fe.name)))return;const c=Ue(),i=String(c[Fe.name]??""),N=a==="shared"?Re.trim():i.startsWith("ref://")?"":i;if(N===i)return;const b={...c,[Fe.name]:N};_e(L=>({...L,configuration:b})),Ke(Fe,Fe.name,N,b)},[Ue,Fe,O,_e,Ke,Re]),Ga=e.useCallback(a=>{if(ae(a),!(Fe!=null&&Fe.name))return;const c=a.trim(),i={...Ue(),[Fe.name]:c};_e(N=>({...N,configuration:i})),Ke(Fe,Fe.name,c,i)},[Ue,Fe,_e,Ke]),Ya=e.useCallback(a=>{const c=l.find(M=>M.value===a);if(!c||!V)return;de(c.value),J(c.models);const i=Ue(),N=c.models.map(rn).filter(Boolean),b=String(i[ye.model]??""),L={...i,[ye.provider]:c.value,...c.url?{[ye.url]:c.url}:{},[ye.model]:c.defaultModel||(b&&N.includes(b)?b:N[0]||b)};_e(M=>({...M,configuration:L})),Ke(V,ye.provider,c.value,L)},[Ue,V,ye,l,_e,Ke]),Mn=e.useCallback(a=>{if(!V)return;const c=Ue(),i=String(c[ye.provider]??"");if(a===Ee&&!(a==="custom"&&i!=="custom")||(Ie(a),a!=="custom"))return;de(""),J([]);const N={...c,[ye.provider]:"custom",[ye.url]:"",[ye.model]:""};_e(b=>({...b,configuration:N})),i!=="custom"&&Ke(V,ye.provider,"custom",N)},[Ue,V,ye,Ee,_e,Ke]),Xa=e.useCallback(a=>vr(a)||a.name===ye.model&&pe.length>0,[ye.model,pe.length]),Qa=a=>{$e(c=>({...c,[a]:[...c[a]||[],{key:"",value:""}]}))},Za=(a,c)=>{me(()=>{$e(i=>({...i,[a]:i[a].filter((N,b)=>b!==c)}))})},On=(a,c,i,N)=>{$e(b=>({...b,[a]:b[a].map((L,M)=>M===c?{...L,[i]:N}:L)}))},eo=(a,c)=>{me(()=>{ft(i=>({...i,[a]:i[a].filter((N,b)=>b!==c)}))})},lr=e.useCallback((a,c)=>{const i=h.parseSimpleArrayInput(c);i.length>0&&ft(N=>({...N,[a]:[...N[a]||[],...i.map(b=>({value:b}))]})),Z(N=>({...N,[a]:""}))},[ft]),to=e.useCallback((a,c)=>{if(/[,,;;\n\t]/.test(c)){lr(a,c);return}Z(i=>({...i,[a]:c}))},[lr]),ro=e.useCallback((a,c)=>{["Enter",",",",",";",";","Tab"].includes(c.key)&&(c.key!=="Tab"&&c.preventDefault(),lr(a,F[a]||""))},[F,lr]),no=e.useCallback((a,c)=>{const i=c.clipboardData.getData("text");i&&(c.preventDefault(),lr(a,F[a]||""),lr(a,i))},[F,lr]),ao=e.useCallback(a=>{me(()=>{ft(c=>({...c,[a]:[]})),Z(c=>({...c,[a]:""}))})},[me,ft]),oo=e.useCallback((a,c,i)=>{c!==i&&ft(N=>{const b=[...N[a]||[]];if(c<0||i<0||c>=b.length||i>=b.length)return N;const[L]=b.splice(c,1);return b.splice(i,0,L),{...N,[a]:b}})},[ft]),Pr=e.useCallback((a,c)=>{_e(i=>{const N={...i.configuration};return N[a]=c(h.normalizeToolRows(N[a])),{...i,configuration:N}})},[_e]),Nt=e.useCallback(a=>{qe(c=>c&&{...c,...a})},[]),cn=e.useCallback(a=>{qe(c=>c&&{...c,draft:{...c.draft,...a},error:""})},[]),Er=e.useCallback((a,c)=>{qe(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=>{qe(c=>c&&{...c,schemaRows:a,parametersText:JSON.stringify(h.generateToolSchemaFromRows(a),null,2),error:""})},[]),An=e.useCallback(a=>{qe(c=>{if(!c||c.schemaMode===a)return c;if(a==="code")return{...c,schemaMode:"code",parametersText:JSON.stringify(h.generateToolSchemaFromRows(c.schemaRows),null,2),error:""};try{return{...c,schemaMode:"visual",schemaRows:h.parseToolSchemaRows(h.parseJsonObjectText(c.parametersText||"{}")),error:""}}catch(i){return{...c,error:E("editor.property.parametersJsonInvalid",`参数定义 JSON 格式错误: ${(i==null?void 0:i.message)||String(i)}`,{message:String((i==null?void 0:i.message)||i)})}}})},[E]),br=e.useCallback((a,c,i)=>{if(!G)return;const N=h.updateSchemaRowsAtParent(G.schemaRows,a,b=>{b[c]&&(b[c]={...b[c],...i,properties:i.type&&i.type!=="object"?[]:b[c].properties,itemsProperties:i.type&&i.type!=="array"?[]:b[c].itemsProperties})});cr(N)},[cr,G]),$n=e.useCallback((a="")=>{if(!G)return;const c=h.updateSchemaRowsAtParent(G.schemaRows,a,i=>{i.push(h.emptySchemaEditorRow(as(i)+1))});cr(c)},[cr,G]),so=e.useCallback((a,c)=>{G&&me(()=>{const i=h.updateSchemaRowsAtParent(G.schemaRows,a,N=>{N.splice(c,1);const b=h.renumberSchemaRowOrders(N);N.splice(0,N.length,...b)});cr(i)})},[me,cr,G]),Fn=e.useCallback((a,c,i)=>{G&&cr(os(G.schemaRows,a,c,i))},[cr,G]),_r=e.useCallback(a=>h.normalizeToolRows((p.configuration||{})[a]),[p.configuration]),jn=e.useCallback((a,c=-1)=>{const i=aa(a),N=_r(a.name),b=c>=0?N[c]:null,L=h.stringifyToolJson(b==null?void 0:b.parameters,"{}");let M=[];try{M=h.parseToolSchemaRows(h.parseJsonObjectText(L))}catch{M=[]}qe({fieldName:a.name,mode:i,step:c>=0?"config":"select",activeTab:String((b==null?void 0:b.type)||"builtin")||"builtin",editIndex:c,keyword:"",page:1,ruleChainPage:1,schemaMode:"visual",schemaRows:M,parametersText:L,draft:b?{...b}:{type:"builtin",parameters:"{}"},error:""}),at(wr(st)),Dn()},[st,_r,Dn]),Dr=e.useCallback(()=>{qe(null),nt("")},[]),Lr=e.useCallback((a,c,i)=>_r(a).some((N,b)=>b!==i&&String(N.type||"")==="builtin"&&Sr(N)===c),[_r]),Mr=e.useCallback((a,c,i)=>_r(a).some((N,b)=>b!==i&&String(N.type||"")==="rulechain"&&String(N.targetId||"")===c),[_r]),lo=e.useCallback(a=>{if(!G)return;if(Lr(G.fieldName,a.value,G.editIndex)){Nt({error:E("editor.property.builtinToolAlreadyAdded","该内置工具已添加")});return}const c={};a.fields.forEach(N=>{const b=String((N==null?void 0:N.name)||"");b&&N.defaultValue!==void 0&&(c[b]=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(G.mode==="tool"&&a.fields.length===0){Pr(G.fieldName,N=>[...N,i]),qe(null);return}qe(N=>N&&{...N,step:"config",activeTab:"builtin",draft:i,parametersText:JSON.stringify(a.parameters||{},null,2),schemaRows:h.parseToolSchemaRows(a.parameters||{}),schemaMode:"visual",error:""})},[Lr,Nt,G,E,Pr]),Bn=e.useCallback(a=>{if(!G)return;if(Mr(G.fieldName,a.value,G.editIndex)){Nt({error:E("editor.property.ruleChainAlreadyAdded","该规则链已添加")});return}const c=ns(a.raw);We(i=>zr(i,[a])),qe(i=>i&&{...i,step:"config",activeTab:"rulechain",draft:{type:"rulechain",targetId:a.value,name:a.label,description:a.description||"",parameters:c},parametersText:c,schemaRows:h.parseToolSchemaRows(h.parseJsonObjectText(c)),schemaMode:"visual",error:""})},[Mr,Nt,G,E]),co=e.useCallback(()=>{qe(a=>a&&{...a,step:"config",activeTab:"custom",draft:{type:"custom",name:"",targetId:"",description:"",parameters:"{}",config:{}},parametersText:"{}",schemaRows:[],schemaMode:"visual",error:""})},[]),io=e.useCallback(()=>{if(!G)return;const a=String(G.draft.type||G.activeTab||"custom"),c=String(G.draft.name||"").trim(),i=String(G.draft.targetId||"").trim(),N=String(G.draft.description||G.draft.desc||"").trim();let b=G.parametersText||"{}";if(G.mode==="tool"&&a!=="builtin")if(G.schemaMode==="visual")b=JSON.stringify(h.generateToolSchemaFromRows(G.schemaRows),null,2);else try{h.parseJsonObjectText(b||"{}")}catch(I){Nt({error:E("editor.property.parametersJsonInvalid",`参数定义 JSON 格式错误: ${(I==null?void 0:I.message)||String(I)}`,{message:String((I==null?void 0:I.message)||I)})});return}if(a==="rulechain"&&!i){Nt({error:E("editor.property.ruleChainRequired","规则链是必须的")});return}if(a==="rulechain"&&Mr(G.fieldName,i,G.editIndex)){Nt({error:E("editor.property.ruleChainAlreadyAdded","该规则链已添加")});return}if(a==="builtin"&&Lr(G.fieldName,c,G.editIndex)){Nt({error:E("editor.property.builtinToolAlreadyAdded","该内置工具已添加")});return}if(a!=="rulechain"&&!c){const I=G.mode==="subagent"?E("editor.property.agentName","智能体名称"):E("editor.property.toolName","工具名称");Nt({error:E("editor.property.nameRequired",`${I}是必须的`,{name:I})});return}const L={...G.draft,type:a,name:a==="rulechain"?c||i:c,targetId:a==="rulechain"?i:i||c,description:N};G.mode==="tool"&&(L.parameters=a==="builtin"?h.stringifyToolJson(L.parameters,"{}"):b);const M=L.config&&typeof L.config=="object"&&!Array.isArray(L.config)?L.config:{};Object.keys(M).length>0?L.config=M:delete L.config,Pr(G.fieldName,I=>{const Y=[...I];return G.editIndex>=0?Y[G.editIndex]=L:Y.push(L),Y}),qe(null)},[Lr,Mr,Nt,G,E,Pr]),uo=e.useCallback(()=>{$==null||$({section:"skills"}),window.dispatchEvent(new CustomEvent("rulego-editor:openAiAssistant",{detail:{section:"skills"}})),Dr()},[Dr,$]),Hn=(a=!0)=>{if(!r)return null;const c=_t.current;let i={...c.configuration};if(Ye.length===0)try{i=h.parseUnknownConfiguration(ie),a&&ge("")}catch(L){return a&&ge(L instanceof Error?L.message:String(L)),null}const N=new Map(Ye.map(L=>[L.name,L]));if(Fe!=null&&Fe.name&&(O==="shared"?i[Fe.name]=Re.trim():String(i[Fe.name]??"").startsWith("ref://")&&(i[Fe.name]="")),V&&Ee==="preset"&&H){i[ye.provider]=H;const L=l.find(M=>M.value===H);L!=null&&L.url&&(i[ye.url]=L.url),L!=null&&L.defaultModel&&!i[ye.model]&&(i[ye.model]=L.defaultModel)}Object.entries(Dt.current).forEach(([L,M])=>{const I=N.get(L);if(!I||!hr(I))return;const Y={},Ne=h.getMapValueMode(I);M.forEach(ee=>{ee.key&&(Y[ee.key]=h.parseMapEntryValue(ee.value,Ne))}),i[L]=Y}),Object.entries(vt.current).forEach(([L,M])=>{const I=N.get(L);!I||!or(I)||Nr(I,i[L])||Cr(I)||(i[L]=M.map(Y=>Y.value).filter(Boolean))}),i=h.sanitizeConfigurationByFields(i,Ye);const b=h.validateComponentFields(Ye,i,d);return b.length>0?(a&&Rt(b.map(L=>`${L.field}: ${L.message}`).join(`
4
+ `)),null):h.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(;le.current.size>0;)await Promise.all([...le.current.values()]);const a=Object.entries(Ce.current).filter(([i])=>Te.current.has(i)||[...we.current].some(N=>kr(N,i)));if(a.length>0)return Rt(E("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),Jt.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)!==Jt.current)){un();return}const i=await h.confirmDrawerUnsavedClose({t:N=>E(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=[...le.current.keys()].some(N=>kr(a,N)),i=Object.entries(Bt).filter(([N])=>kr(a,N));return e.createElement(e.Fragment,null,c&&e.createElement("span",{className:"rge-field-desc",role:"status"},E("editor.property.fieldChangeLoading","正在更新关联字段...")),i.map(([N,b])=>e.createElement("span",{key:N,className:"rge-field-error",role:"alert"},b)))},Un=a=>{if(O==="shared"&&(a.ref==="primary"||a.ref==="shared")||V&&a.name===V.name)return null;const c=Ve.get(a.name)||[],i=wt[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"},it(a)),c.length>0&&e.createElement("button",{type:"button",className:"rge-field-attachment-button",title:E("editor.property.configureAttached","配置附加参数"),"aria-label":E("editor.property.configureAttached","配置附加参数"),onClick:()=>Tt(a.name)},e.createElement(be,{value:"settings"}))),Vn(a),(i==null?void 0:i.loading)&&e.createElement("span",{className:"rge-field-desc"},E("editor.property.loadingOptions","正在加载选项...")),(i==null?void 0:i.error)&&e.createElement("span",{className:"rge-field-error"},i.error),Wr(a.name))},mo=()=>Fe?e.createElement("div",{className:"rge-form-section rge-ref-mode-section"},e.createElement("label",{className:"rge-form-label"},E("editor.form.connectionMode","连接方式")),e.createElement("div",{className:"rge-segmented-control",role:"radiogroup","aria-label":E("editor.form.connectionMode","连接方式")},e.createElement("button",{type:"button",className:`rge-segmented-option${O==="custom"?" active":""}`,role:"radio","aria-checked":O==="custom",onClick:()=>Ln("custom")},E("editor.form.customConnection","自定义连接")),e.createElement("button",{type:"button",className:`rge-segmented-option${O==="shared"?" active":""}`,role:"radio","aria-checked":O==="shared",onClick:()=>Ln("shared")},E("editor.form.sharedConnection","共享连接"))),O==="shared"&&e.createElement("div",{className:"rge-ref-shared-picker"},e.createElement(rr,{name:"sharedRef",value:Re,options:Je,allowCreate:!0,threshold:0,placeholder:E("editor.form.sharedConnectionPlaceholder","选择或输入 ref:// 共享连接"),...It,onChange:Ga})),e.createElement("span",{className:"rge-field-desc"},E("editor.form.sharedConnectionDesc","共享连接会写入 ref:// 引用,自定义连接会直接写入服务地址。")),Wr(Fe.name)):null,po=()=>V?e.createElement("div",{className:"rge-form-section rge-provider-mode-section"},e.createElement("label",{className:"rge-form-label"},V.label||E("editor.form.aiProvider","AI服务商")),e.createElement("div",{className:"rge-segmented-control",role:"radiogroup","aria-label":E("editor.form.aiProvider","AI服务商")},e.createElement("button",{type:"button",className:`rge-segmented-option${Ee==="custom"?" active":""}`,role:"radio","aria-checked":Ee==="custom",onClick:()=>Mn("custom")},E("editor.form.customProvider","自定义供应商")),e.createElement("button",{type:"button",className:`rge-segmented-option${Ee==="preset"?" active":""}`,role:"radio","aria-checked":Ee==="preset",onClick:()=>Mn("preset")},E("editor.form.presetProvider","预设供应商"))),Ee==="preset"&&e.createElement("div",{className:"rge-provider-picker"},e.createElement(rr,{name:"provider",value:H,options:l.map(a=>({label:a.label,value:a.value,description:a.url})),threshold:0,placeholder:E("editor.form.providerPlaceholder","选择AI供应商"),...It,onChange:Ya})),e.createElement("span",{className:"rge-field-desc"},E("editor.form.providerDesc","预设供应商会自动填充 API 地址和模型,自定义供应商保留手工填写。")),Wr(ye.provider)):null,go=(a,c)=>{const i=String(a||"").toLowerCase();return i==="rulechain"?E("editor.property.ruleChain","规则链"):i==="builtin"?E("editor.property.builtinTool","内置工具"):i==="subagent"?E("editor.property.subagent","子智能体"):i==="custom"?c==="subagent"?E("editor.property.customAgent","自定义智能体"):E("editor.property.custom","自定义"):String(a||"-")},fo=a=>{const c=String(a.name||"");if(!c||!G)return null;const i=String(a.label||c),N=a.component&&typeof a.component=="object"?a.component:{},b=String(N.type||a.type||"").toLowerCase(),M=(G.draft.config&&typeof G.draft.config=="object"&&!Array.isArray(G.draft.config)?G.draft.config:{})[c]??a.defaultValue??"";if(b==="select"){const he=Sn(Array.isArray(N.options)?N.options:[],M);return e.createElement("label",{key:c,className:"rge-tool-config-field"},e.createElement("span",null,i),e.createElement(rr,{name:`tool-config-${c}`,value:String(M??""),options:he,placeholder:String(N.placeholder||""),...It,onChange:He=>Er(c,He)}))}if(b==="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:!!M,onChange:he=>Er(c,he.target.checked)}),e.createElement("span",{className:"rge-switch-slider"})));const I=String(a.type||"").toLowerCase();if(["map","array","struct","object","json"].includes(I)||["map","array","struct","object","json","json-editor"].includes(b))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(M),spellCheck:!1,onChange:he=>{const He=I==="array"||b==="array"?[]:{};try{Er(c,he.target.value?JSON.parse(he.target.value):He)}catch{Er(c,he.target.value)}}}));if(b==="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(M??""),onChange:he=>Er(c,he.target.value)}));const Ne=b==="input-number"||b==="number"||I==="number"||Sa(String(a.type||"")),ee=b==="password"||I==="password"||Ar({name:c,type:I,component:N})?"password":b==="date"||b==="datepicker"?"date":b==="time"||b==="timepicker"?"time":b==="datetime"||b==="datetimepicker"||b==="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:ee,value:String(M??""),placeholder:String(N.placeholder||(b==="duration"||I==="duration"?"1s / 5m / 2h":"")),autoComplete:ee==="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"},E("editor.property.noSchemaProperties","暂无属性,点击下方按钮添加")):a.map((i,N)=>{const b=c?`${c}.${N}`:String(N),L=i.type==="array"?`${b}.items`:b,M=i.type==="array"?i.itemsProperties:i.properties;return e.createElement("div",{key:b,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:E("editor.property.propertyName","属性名"),onChange:I=>br(c,N,{name:I.target.value})}),e.createElement("input",{className:"rge-form-input",value:i.title,placeholder:E("editor.property.title","标题"),onChange:I=>br(c,N,{title:I.target.value})}),e.createElement("input",{className:"rge-form-input",value:i.description,placeholder:E("editor.property.description","描述"),onChange:I=>br(c,N,{description:I.target.value})}),e.createElement("select",{className:"rge-form-select",value:i.type,onChange:I=>br(c,N,{type:I.target.value})},h.TOOL_SCHEMA_TYPES.map(I=>e.createElement("option",{key:I,value:I},I))),e.createElement("input",{className:"rge-form-input",type:"number",min:0,value:i.order,onChange:I=>br(c,N,{order:Number(I.target.value||N+1)})}),e.createElement("label",{className:"rge-inline-checkbox rge-tool-schema-required"},e.createElement("input",{type:"checkbox",checked:i.required,onChange:I=>br(c,N,{required:I.target.checked})}),e.createElement("span",null,E("editor.property.required","必填"))),e.createElement("div",{className:"rge-tool-schema-actions"},e.createElement("button",{type:"button",title:E("editor.property.moveUp","上移"),onClick:()=>Fn(c,N,-1)},"↑"),e.createElement("button",{type:"button",title:E("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,E("editor.property.itemType","项目类型")),e.createElement("select",{className:"rge-form-select",value:i.itemsType||"string",onChange:I=>br(c,N,{itemsType:I.target.value})},h.TOOL_SCHEMA_ITEM_TYPES.map(I=>e.createElement("option",{key:I,value:I},I)))),(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"?E("editor.property.arrayItems","数组项目"):E("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"},E("editor.property.arrayNonObject","当前数组项目不是 object,无需配置项目属性。")):e.createElement(e.Fragment,null,qn(M||[],L),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>$n(L)},i.type==="array"?E("editor.property.addItemProperty","添加项目属性"):E("editor.property.addChildProperty","添加子属性")))))})),bo=(a,c)=>{const i=h.normalizeToolRows(c),N=aa(a),b=N==="subagent"?E("editor.property.noSubagents","暂无子智能体"):E("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"?E("editor.property.addSubagent","添加子智能体"):E("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,E("editor.property.name","名称")),e.createElement("th",null,E("editor.property.type","类型")),e.createElement("th",null,E("editor.property.description","描述")),e.createElement("th",{className:"rge-tools-operations"},E("editor.property.operate","操作")))),e.createElement("tbody",null,i.length===0?e.createElement("tr",null,e.createElement("td",{colSpan:4,className:"rge-tools-empty"},b)):i.map((L,M)=>{const I=String(L.type||"custom");return e.createElement("tr",{key:M},e.createElement("td",{title:Sr(L)},Sr(L)||"-"),e.createElement("td",null,e.createElement("span",{className:`rge-tool-type rge-tool-type-${I.toLowerCase()}`},go(I,N))),e.createElement("td",{title:ia(L)},fn(ia(L),80)),e.createElement("td",{className:"rge-tools-actions"},rs(L,N,dr)&&e.createElement("button",{type:"button",className:"rge-tool-action-button",title:E("editor.property.edit","编辑"),"aria-label":E("editor.property.edit","编辑"),onClick:()=>jn(a,M)},"✎"),e.createElement("button",{type:"button",className:"rge-tool-action-button danger",title:E("editor.property.delete","删除"),"aria-label":E("editor.property.delete","删除"),onClick:()=>me(()=>{Pr(a.name,Y=>Y.filter((Ne,ee)=>ee!==M))})},"×")))})))),kt(a))},ho=()=>{if(!G)return null;const a=G.editIndex>=0,c=G.mode,i=String(G.draft.type||G.activeTab||"builtin"),N=dr.find(Me=>Me.value===Sr(G.draft)),b=i==="builtin"?(N==null?void 0:N.fields)||[]:[],L=i==="builtin"&&Sr(G.draft)==="skill",M=pr||(N==null?void 0:N.defaultGlobalDir)||E("editor.property.notConfigured","未配置"),I=G.keyword.trim().toLowerCase(),Y=dr.filter(Me=>I?Me.value.toLowerCase().includes(I)||Me.label.toLowerCase().includes(I)||Me.desc.toLowerCase().includes(I):!0),Ne=Math.max(1,Math.ceil(Y.length/st)),ee=Math.min(Math.max(1,G.page),Ne),he=Y.slice((ee-1)*st,ee*st),He=rt(),Le=Et.items.map(bn).filter(Boolean),lt=hn([...Le,...He]),Xt=G.keyword.trim().toLowerCase(),er=ut?lt:lt.filter(Me=>Xt?Me.label.toLowerCase().includes(Xt)||Me.value.toLowerCase().includes(Xt)||String(Me.description||"").toLowerCase().includes(Xt):!0),Ze=ut?Et.total:er.length,et=Math.max(1,Math.ceil(Ze/st)),pt=Math.min(Math.max(1,G.ruleChainPage),et),ir=ut?er:er.slice((pt-1)*st,pt*st),dn=G.step==="select"?c==="subagent"?E("editor.property.selectSubagent","选择子智能体"):E("editor.property.selectTool","选择工具"):a?c==="subagent"?E("editor.property.editSubagent","编辑子智能体"):E("editor.property.editTool","编辑工具"):c==="subagent"?E("editor.property.configSubagent","配置子智能体"):E("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"},G.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:G.activeTab===Me?"active":"",onClick:()=>Nt({activeTab:Me,keyword:"",page:1,ruleChainPage:1,error:""})},Me==="builtin"?E("editor.property.builtinTool","内置工具"):Me==="rulechain"?E("editor.property.ruleChain","规则链"):c==="subagent"?E("editor.property.customAgent","自定义智能体"):E("editor.property.custom","自定义")))),G.activeTab!=="custom"&&e.createElement("input",{type:"search",className:"rge-rule-chain-modal-search",value:G.keyword,placeholder:G.activeTab==="builtin"?E("editor.property.searchTools","搜索工具..."):E("editor.property.searchRuleChains","搜索规则链..."),onChange:Me=>Nt({keyword:Me.target.value,page:1,ruleChainPage:1})}),G.activeTab==="builtin"&&e.createElement("div",{className:"rge-tool-card-grid"},Ot?e.createElement("div",{className:"rge-tools-empty"},E("editor.panel.loading","加载中...")):Pe?e.createElement("div",{className:"rge-tools-empty"},Pe):he.length===0?e.createElement("div",{className:"rge-tools-empty"},E("editor.property.noMatchingOptions","没有匹配的选项")):he.map(Me=>{const tr=Lr(G.fieldName,Me.value,G.editIndex);return e.createElement("button",{key:Me.value,type:"button",className:`rge-tool-card${tr?" disabled":""}`,disabled:tr,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||E("editor.property.noDescription","暂无描述"),96))),e.createElement("span",{className:"rge-tool-card-action"},tr?E("editor.property.added","已添加"):"+"))})),G.activeTab==="rulechain"&&e.createElement("div",{className:"rge-tool-card-grid"},Et.loading&&ut?e.createElement("div",{className:"rge-tools-empty"},E("editor.panel.loading","加载中...")):Et.error&&ut?e.createElement("div",{className:"rge-tools-empty"},Et.error):ir.length===0?e.createElement("div",{className:"rge-tools-empty"},E("editor.property.noMatchingOptions","没有匹配的选项")):ir.map(Me=>{const tr=Mr(G.fieldName,Me.value,G.editIndex);return e.createElement("button",{key:Me.value,type:"button",className:`rge-tool-card${tr?" disabled":""}`,disabled:tr,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"},tr?E("editor.property.added","已添加"):"+"))})),G.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"?E("editor.property.customAgent","自定义智能体"):E("editor.property.custom","自定义")),e.createElement("small",null,E("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,E("editor.property.ruleChain","规则链")),e.createElement(rr,{name:"tool-rulechain",value:String(G.draft.targetId||""),options:lt.map(Me=>({label:Me.label,value:Me.value,description:Me.description})),placeholder:E("editor.form.selectRuleChain","请选择规则链"),...It,onChange:Me=>{const tr=lt.find(No=>No.value===Me);tr?Bn(tr):cn({targetId:Me})}})),e.createElement("label",{className:"rge-tool-config-field"},e.createElement("span",null,c==="subagent"?E("editor.property.agentName","智能体名称"):E("editor.property.toolName","工具名称")),e.createElement("input",{className:"rge-form-input",value:String(G.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,E("editor.property.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",rows:2,value:String(G.draft.description||G.draft.desc||""),onChange:Me=>cn({description:Me.target.value})}))),L&&e.createElement("div",{className:"rge-skill-tool-helper"},e.createElement("span",null,E("editor.property.autoLoadSkillDir","自动加载全局技能目录({{dir}})",{dir:M})),e.createElement("button",{type:"button",onClick:uo},E("editor.property.manageSkills","管理技能"))),c==="tool"&&i==="builtin"&&b.length>0&&e.createElement("div",{className:"rge-tool-config-section"},e.createElement("div",{className:"rge-tool-config-section-title"},E("editor.property.initConfig","初始化配置")),e.createElement("div",{className:"rge-tool-config-grid"},b.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"},E("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${G.schemaMode==="visual"?" active":""}`,onClick:()=>An("visual")},E("editor.property.visualMode","可视化")),e.createElement("button",{type:"button",className:`rge-segmented-option${G.schemaMode==="code"?" active":""}`,onClick:()=>An("code")},E("editor.property.codeMode","JSON代码"))),G.schemaMode==="visual"?e.createElement("div",{className:"rge-tool-schema-editor"},qn(G.schemaRows),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>$n("")},E("editor.property.addProperty","添加属性"))):e.createElement("textarea",{className:"rge-code-textarea rge-tool-schema-code",rows:12,value:G.parametersText,spellCheck:!1,onChange:Me=>Nt({parametersText:Me.target.value,error:""})}))),G.error&&e.createElement("div",{className:"rge-tools-error"},G.error)),e.createElement("div",{className:"rge-tools-modal-footer"},G.step==="select"?e.createElement("div",{className:"rge-tools-pagination"},G.activeTab==="builtin"&&Y.length>0&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",disabled:ee<=1,onClick:()=>Nt({page:Math.max(1,ee-1)})},E("editor.property.prevPage","上一页")),e.createElement("span",null,E("editor.property.pageInfo",`第 ${ee}/${Ne} 页,共 ${Y.length} 条`,{page:ee,pages:Ne,total:Y.length})),e.createElement("button",{type:"button",disabled:ee>=Ne,onClick:()=>Nt({page:Math.min(Ne,ee+1)})},E("editor.property.nextPage","下一页"))),G.activeTab==="rulechain"&&Ze>0&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",disabled:pt<=1||Et.loading,onClick:()=>Nt({ruleChainPage:Math.max(1,pt-1)})},E("editor.property.prevPage","上一页")),e.createElement("span",null,E("editor.property.pageInfo",`第 ${pt}/${et} 页,共 ${Ze} 条`,{page:pt,pages:et,total:Ze})),e.createElement("button",{type:"button",disabled:pt>=et||Et.loading,onClick:()=>Nt({ruleChainPage:Math.min(et,pt+1)})},E("editor.property.nextPage","下一页")))):e.createElement("div",{className:"rge-tools-modal-actions"},!a&&e.createElement("button",{type:"button",onClick:()=>Nt({step:"select",error:""})},E("editor.property.back","返回选择")),e.createElement("button",{type:"button",onClick:Dr},E("editor.panel.cancel","取消")),e.createElement("button",{type:"button",className:"primary",onClick:io},E("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:Be(a,c),placeholder:N||E("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:E("editor.form.selectRuleChain","选择规则链"),onClick:()=>Yt(a,c)},E("editor.property.search","搜索"))),kt(a)),Ur=(a,c,i,N)=>{var Y,Ne,ee,he,He;const b=a||{name:"value",type:"string"},L=!!(b.disabled||(Y=b.component)!=null&&Y.disabled),M=((Ne=b.component)==null?void 0:Ne.placeholder)||b.label||b.name,I=Le=>{const lt=i(Le);Ke(b,N||b.name,Le,lt)};if(vr(b)){const Le=P(b,c),lt=!!((ee=b.component)!=null&&ee.multiple),Xt=Array.isArray(c)?c.map(er=>String(er??"")).filter(Boolean):String(c??"").split(",").map(er=>er.trim()).filter(Boolean);return e.createElement(rr,{name:N||b.name,value:String(c??""),values:lt?Xt:void 0,multiple:lt,allowCreate:!!((he=b.component)!=null&&he.allowCreate),disabled:L,options:Le,placeholder:M,...It,onChange:I,onMultiChange:I})}if(nn(b))return e.createElement("label",{className:"rge-inline-checkbox"},e.createElement("input",{type:"checkbox",checked:!!c,disabled:L,onChange:Le=>I(Le.target.checked)}),e.createElement("span",null,b.label||b.name));if(an(b)){const Le=wn(b.type)||jt(b)==="number";return e.createElement("input",{type:"number",className:"rge-form-input",step:Le?"0.01":void 0,value:String(c??""),disabled:L,placeholder:M,onChange:lt=>I(zo(b,lt.target.value))})}if(sa(b))return e.createElement("textarea",{className:"rge-form-textarea rge-expression-editor",rows:2,value:String(c??""),disabled:L,placeholder:E("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,onChange:Le=>I(Le.target.value)});if(ta(b)||Kr(b))return e.createElement("textarea",{className:Kr(b)?"rge-code-textarea":"rge-form-textarea",rows:Kr(b)?6:3,value:typeof c=="object"&&c!==null?JSON.stringify(c,null,2):String(c??""),disabled:L,placeholder:M,spellCheck:!1,onChange:Le=>I(Le.target.value)});if(la(b)){const lt=Ct(b).startsWith("time")?"time":"date";return e.createElement("input",{type:lt,className:"rge-form-input",value:String(c??""),disabled:L,placeholder:M,onChange:Xt=>I(Xt.target.value)})}return ca(b)?e.createElement("input",{type:"text",className:"rge-form-input rge-duration-input",value:String(c??""),disabled:L,placeholder:((He=b.component)==null?void 0:He.placeholder)||"10s / 1m",onChange:Le=>I(Le.target.value)}):oa(b)||or(b)||hr(b)?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:L,placeholder:M,spellCheck:!1,onChange:Le=>{try{I(Le.target.value?JSON.parse(Le.target.value):or(b)?[]:{})}catch{I(Le.target.value)}}}):e.createElement("input",{type:Ar(b)?"password":"text",className:"rge-form-input",value:String(c??""),disabled:L,placeholder:M,autoComplete:Ar(b)?"new-password":void 0,onChange:Le=>I(Le.target.value)})},Eo=(a,c)=>{var L;const i=Uo(c),N=String(((L=a.component)==null?void 0:L.caseType)||"").toLowerCase(),b=(M,I,Y)=>{mt(a.name,i.map((Ne,ee)=>ee===M?{...Ne,[I]:Y}: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,E("editor.property.switchCondition","条件")),e.createElement("span",null,E("editor.property.switchRoute","路由")),e.createElement("span",null)),i.map((M,I)=>e.createElement("div",{key:I,className:"rge-switch-node-row"},e.createElement("textarea",{className:`rge-form-textarea${N==="expr"||N==="expression"?" rge-expression-editor":""}`,rows:2,value:M.case,placeholder:E("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,onChange:Y=>b(I,"case",Y.target.value)}),e.createElement("input",{type:"text",className:"rge-form-input",value:M.then,placeholder:E("editor.property.switchRoutePlaceholder","输入路由:如 Case1"),onChange:Y=>b(I,"then",Y.target.value)}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",onClick:()=>me(()=>{mt(a.name,i.filter((Y,Ne)=>Ne!==I))})},"×"))),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>mt(a.name,[...i,{case:"",then:""}])},E("editor.property.addBranch","添加分支")),kt(a))},_o=(a,c)=>{const i=qo(c),N=Jo(a,i),b=Ir(a),L=new Map(b.map(I=>[I.name,I])),M=N.reduce((I,Y)=>{const Ne=L.get(Y);return I[Y]=(Ne==null?void 0:Ne.defaultValue)??"",I},{});return N.length===0?e.createElement("div",{className:"rge-array-editor"},e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>mt(a.name,[...i,{}])},E("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(I=>{var Y;return e.createElement("span",{key:I},((Y=L.get(I))==null?void 0:Y.label)||I)}),e.createElement("span",null)),i.map((I,Y)=>e.createElement("div",{key:Y,className:"rge-structured-array-row",style:{gridTemplateColumns:`repeat(${N.length}, minmax(120px, 1fr)) 32px`}},N.map(Ne=>{const ee=L.get(Ne);return e.createElement("div",{key:Ne,className:"rge-structured-array-cell"},Ur(ee,I[Ne],he=>mt(a.name,i.map((He,Le)=>Le===Y?{...He,[Ne]:he}:He)),`${a.name}.${Y}.${Ne}`))}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",onClick:()=>me(()=>{mt(a.name,i.filter((Ne,ee)=>ee!==Y))})},"×")))),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>mt(a.name,[...i,M])},E("editor.panel.addPair","+ 添加")),kt(a))},vo=(a,c)=>{const i=c&&typeof c=="object"&&!Array.isArray(c)?c:{},N=Ir(a),b=N.length>0?N.map(M=>M.name).filter(Boolean):Object.keys(i),L=new Map(N.map(M=>[M.name,M]));return e.createElement("div",{className:"rge-struct-panel"},b.length===0?e.createElement("div",{className:"rge-struct-empty"},E("editor.property.noConfigItems","暂无配置项")):b.map(M=>{const I=L.get(M);return e.createElement("div",{key:M,className:"rge-struct-child"},e.createElement("label",{className:"rge-form-label"},(I==null?void 0:I.label)||M),Ur(I,i[M]??(I==null?void 0:I.defaultValue)??"",Y=>mt(a.name,{...i,[M]:Y}),`${a.name}.${M}`),mr(I==null?void 0:I.desc)&&e.createElement("span",{className:"rge-field-desc"},mr(I==null?void 0:I.desc)))}),kt(a))},Vn=a=>{var L,M,I,Y,Ne;const i=(p.configuration||{})[a.name],N=!!(a.disabled||(L=a.component)!=null&&L.disabled),b=((M=a.component)==null?void 0:M.placeholder)||"";if(Ho(a))return yo(a,i,N,b);if(Xa(a)){const ee=!!((I=a.component)!=null&&I.multiple),he=P(a,i),He=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(rr,{name:a.name,value:String(i??""),values:ee?He:void 0,multiple:ee,allowCreate:!!((Y=a.component)!=null&&Y.allowCreate),disabled:N,options:he,placeholder:b,...It,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:ee=>Ae(a,a.name,ee.target.checked)}),e.createElement("span",{className:"rge-switch-slider"})),kt(a));if(la(a))return e.createElement(e.Fragment,null,Ur(a,i,ee=>mt(a.name,ee)),kt(a));if(ca(a))return e.createElement(e.Fragment,null,Ur(a,i,ee=>mt(a.name,ee)),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)),(Se[a.name]||[]).map((ee,he)=>e.createElement("div",{key:he,className:"rge-map-row"},e.createElement("input",{type:"text",className:"rge-form-input",placeholder:E("editor.form.keyPlaceholder","键"),value:ee.key,onChange:He=>On(a.name,he,"key",He.target.value)}),e.createElement("input",{type:"text",className:"rge-form-input",placeholder:E("editor.form.valuePlaceholder","值"),value:ee.value,onChange:He=>On(a.name,he,"value",He.target.value)}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",title:E("editor.property.delete","删除"),onClick:()=>Za(a.name,he)},e.createElement(be,{value:"delete"})))),e.createElement("button",{className:"rge-btn-add",onClick:()=>Qa(a.name)},E("editor.panel.addPair","+ 添加")),kt(a));if(Nr(a,i))return h.isPointTableFields(Ir(a))?e.createElement(Ko,{key:`${((Ne=D==null?void 0:D.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:ee=>mt(a.name,ee),onChildChange:Ke,translate:E}):_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"},(ve[a.name]||[]).map((ee,he)=>e.createElement("div",{key:`${ee.value}-${he}`,className:"rge-array-row rge-array-tag",role:"listitem",draggable:!0,onDragStart:He=>He.dataTransfer.setData("text/plain",String(he)),onDragOver:He=>He.preventDefault(),onDrop:He=>{var lt;He.preventDefault();const Le=Number((lt=He.dataTransfer)==null?void 0:lt.getData("text"));Number.isInteger(Le)&&oo(a.name,Le,he)}},e.createElement("span",{className:"rge-array-tag-value"},ee.value),e.createElement("button",{type:"button",className:"rge-btn-icon-danger","aria-label":E("editor.property.delete","删除"),title:E("editor.property.delete","删除"),onClick:()=>eo(a.name,he)},"×")))),e.createElement("input",{type:"text",className:"rge-form-input rge-array-tag-input",value:F[a.name]||"",placeholder:E("editor.property.simpleArrayPlaceholder","输入后回车添加,支持粘贴批量内容"),onChange:ee=>to(a.name,ee.target.value),onKeyDown:ee=>ro(a.name,ee),onPaste:ee=>no(a.name,ee),onBlur:()=>lr(a.name,F[a.name]||"")}),(ve[a.name]||[]).length>0&&e.createElement("button",{type:"button",className:"rge-array-clear",onClick:()=>ao(a.name)},E("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:ee=>Ae(a,a.name,ee.target.value),placeholder:E("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:E("editor.property.expressionPlaceholder","输入表达式,如:msg.temperature > 50"),spellCheck:!1,disabled:N,onChange:ee=>Ae(a,a.name,ee.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:b,disabled:N,onChange:ee=>Ae(a,a.name,ee.target.value)}),kt(a));if(an(a)){const ee=wn(a.type)||jt(a)==="number";return e.createElement(e.Fragment,null,e.createElement("input",{type:"number",step:ee?"0.01":void 0,className:"rge-form-input",value:String(i??""),disabled:N,onChange:he=>{const He=he.target.value;Ae(a,a.name,He===""?"":ee?Number(He):parseInt(He,10))}}),kt(a))}return e.createElement(e.Fragment,null,e.createElement("input",{type:Ar(a)?"password":"text",className:"rge-form-input",value:String(i??""),placeholder:b,disabled:N,autoComplete:Ar(a)?"new-password":void 0,onChange:ee=>Ae(a,a.name,ee.target.value)}),kt(a))},Co=()=>{if(!z)return null;const a=Ye.find(Y=>Y.name===z.fieldName);if(!a)return null;const c=z.keyword.trim().toLowerCase(),i=ne(a,z.value).filter(Y=>!yt||Y.value!==yt).filter(Y=>es(Y,z.tab)).filter(Y=>c?Y.label.toLowerCase().includes(c)||Y.value.toLowerCase().includes(c)||String(Y.description||"").toLowerCase().includes(c):!0),N=ut?ke.total:i.length,b=ut&&ke.size||st,L=Math.max(1,Math.ceil(N/b)),M=Math.min(z.page,L),I=ut?ke.items:i.slice((M-1)*b,M*b);return e.createElement("div",{className:"rge-rule-chain-modal",onClick:()=>fe(null)},e.createElement("div",{className:"rge-rule-chain-modal-panel",role:"dialog","aria-modal":"true","aria-label":E("editor.form.selectRuleChain","选择规则链"),onClick:Y=>Y.stopPropagation()},e.createElement("div",{className:"rge-rule-chain-modal-header"},e.createElement("strong",null,E("editor.form.selectRuleChain","选择规则链")),e.createElement("button",{type:"button",className:"rge-rule-chain-modal-close",onClick:()=>fe(null)},"×")),e.createElement("div",{className:"rge-rule-chain-modal-tools"},e.createElement("div",{className:"rge-rule-chain-modal-tabs",role:"tablist"},["sub","root"].map(Y=>e.createElement("button",{key:Y,type:"button",role:"tab","aria-selected":z.tab===Y,className:z.tab===Y?"active":"",onClick:()=>Vt({tab:Y,page:1})},Y==="sub"?E("editor.property.subRuleChains","子规则链"):E("editor.property.rootRuleChains","主规则链")))),e.createElement("input",{type:"search",className:"rge-rule-chain-modal-search",value:z.keyword,placeholder:E("editor.property.searchRuleChains","搜索规则链..."),onChange:Y=>Vt({keyword:Y.target.value,page:1}),autoFocus:!0})),e.createElement("div",{className:"rge-rule-chain-modal-body"},ke.loading&&ut?e.createElement("div",{className:"rge-rule-chain-empty"},E("editor.property.loading","加载中...")):ke.error&&ut?e.createElement("div",{className:"rge-rule-chain-empty"},ke.error):I.length===0?e.createElement("div",{className:"rge-rule-chain-empty"},E("editor.property.noData","暂无数据")):e.createElement("table",{className:"rge-rule-chain-table"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,E("editor.property.name","名称")),e.createElement("th",null,"ID"),e.createElement("th",null,E("editor.panel.description","描述")),e.createElement("th",null,E("editor.property.operate","操作")))),e.createElement("tbody",null,I.map(Y=>{const Ne=Y.value===z.value;return e.createElement("tr",{key:Y.value,className:Ne?"active":void 0},e.createElement("td",{className:"rge-rule-chain-name"},e.createElement("span",{className:"rge-rule-chain-title"},Y.label),e.createElement("span",{className:"rge-rule-chain-badge"},Y.root===!1?E("editor.property.subChain","子链"):E("editor.property.rootChain","主链"))),e.createElement("td",{className:"rge-rule-chain-id"},Y.value),e.createElement("td",{className:"rge-rule-chain-desc"},Y.description||"-"),e.createElement("td",{className:"rge-rule-chain-action"},Ne?e.createElement("span",{className:"rge-selected-badge"},E("editor.property.selected","已选择")):e.createElement("button",{type:"button",onClick:()=>yr(Y)},E("editor.property.select","选择"))))})))),e.createElement("div",{className:"rge-rule-chain-modal-footer"},e.createElement("span",{className:"rge-rule-chain-page-info"},E("editor.property.pageInfo","第 {{page}}/{{pages}} 页,共 {{total}} 条",{page:String(M),pages:String(L),total:String(N)})),e.createElement("button",{type:"button",disabled:M<=1||ut&&ke.loading,onClick:()=>Vt({page:Math.max(1,M-1)})},E("editor.property.prevPage","上一页")),e.createElement("button",{type:"button",disabled:M>=L||ut&&ke.loading,onClick:()=>Vt({page:Math.min(L,M+1)})},E("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,E(`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"},E("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"},E("editor.panel.nodeId","节点 ID")),e.createElement("div",{className:"rge-form-row"},e.createElement("input",{type:"text",className:"rge-form-input rge-flex-1",value:p.id||"",readOnly:!0,"aria-readonly":"true",title:E("editor.panel.nodeIdLocked","节点 ID 已绑定画布,编辑属性时不会改写"),onChange:a=>Qe("id",a.target.value)}),e.createElement("label",{className:"rge-debug-toggle"},e.createElement("input",{type:"checkbox",checked:p.debugMode||!1,onChange:a=>Qe("debugMode",a.target.checked)}),e.createElement(be,{value:"debug"}),e.createElement("span",null,E("editor.panel.debugMode","调试"))))),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},E("editor.panel.name","名称")),e.createElement("input",{type:"text",className:"rge-form-input",value:p.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)),At&&(()=>{if(De.length===0)return null;const a=()=>{ot>0||Tt("")},c=()=>{ot>0||bt.length>0||Tt("")};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,E("editor.property.attachedSettings","附加参数")),e.createElement("button",{type:"button",disabled:ot>0,"aria-label":E("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"},it(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"},E("editor.property.fieldChangeLoading","正在更新关联字段...")),e.createElement("button",{type:"button",className:"rge-btn-submit",disabled:ot>0||bt.length>0,onClick:c},E("editor.panel.apply","应用")))))})(),Ye.length===0&&e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},E("editor.property.configurationJson","配置 JSON")),e.createElement("textarea",{className:"rge-form-textarea",rows:14,value:ie,onChange:a=>{U(a.target.value),ge("")},spellCheck:!1}),te&&e.createElement("span",{className:"rge-field-error"},te)),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},E("editor.panel.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",rows:3,placeholder:E("editor.panel.descriptionPlaceholder","请输入节点描述"),value:String(((Kn=p.additionalInfo)==null?void 0:Kn.description)??""),onChange:a=>Qe("additionalInfo",{...p.additionalInfo,description:a.target.value})})))),Co(),ho(),e.createElement("div",{className:"rge-drawer-footer"},ze&&e.createElement("span",{className:"rge-drawer-submit-error",role:"alert"},ze),!ze&&zt.length>0&&e.createElement("span",{className:"rge-drawer-submit-error",role:"alert"},E("editor.property.fieldChangeFailedMessage","关联字段更新失败: {{message}}",{message:zt.map(([,a])=>a).join("; ")})),Ht>0&&e.createElement("span",{className:"rge-field-desc",role:"status"},E("editor.property.fieldChangeLoading","正在更新关联字段...")),e.createElement("button",{className:"rge-btn-cancel",onClick:()=>{mn()}},E("editor.panel.cancel","取消")),e.createElement("button",{className:"rge-btn-submit",disabled:Ht>0||zt.length>0,onClick:()=>{Wn()}},E("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:g,t:d})=>{const[w,S]=e.useState(""),[D,f]=e.useState(""),[x,_]=e.useState(!1),y=e.useMemo(()=>tt({locale:u,messages:g,t:d}),[u,g,d]),B=e.useMemo(()=>{const v=!(n!=null&&n.length);return(n!=null&&n.length?n:$r).map(($,k)=>{var C,oe;return typeof $=="string"?{value:$,label:Nn(y,$),color:((C=$r[k%$r.length])==null?void 0:C.color)||"var(--rge-primary)"}:{value:$.value,label:!v&&$.label?$.label:Nn(y,$.value),color:$.color||((oe=$r[k%$r.length])==null?void 0:oe.color)||"var(--rge-primary)"}})},[n,y]);e.useEffect(()=>{if(!r)return;const v=r.relationType||"Success";B.some($=>$.value===v)?(S(v),_(!1),f("")):(S(""),_(!0),f(v))},[r,B]);const j=v=>{S(v),_(!1),f("")},W=()=>{_(!0),S("")},q=()=>{if(!r)return;const v=x?D.trim()||"Success":w||"Success";o({...r,relationType:v})};return!t||!r?null:e.createElement("div",{className:`rge-edge-drawer-overlay ${t?"visible":""}`,onClick:s},e.createElement("div",{className:"rge-edge-drawer",onClick:v=>v.stopPropagation()},e.createElement("div",{className:"rge-drawer-header"},e.createElement("div",{className:"rge-drawer-title"},e.createElement(be,{value:"link"}),e.createElement("span",null,y("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"},y("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"},y("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"},y("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"},y("editor.form.relationType","关系类型")),e.createElement("div",{className:"rge-relation-types"},B.map(v=>e.createElement("button",{key:v.value,className:`rge-relation-type-btn ${!x&&w===v.value?"active":""}`,style:{borderColor:!x&&w===v.value?v.color:void 0,color:!x&&w===v.value?v.color:void 0},onClick:()=>j(v.value)},!x&&w===v.value&&e.createElement("span",null,"✓"),v.label)),e.createElement("button",{className:`rge-relation-type-btn ${x?"active custom":""}`,onClick:W},y("editor.edge.custom","自定义"))),x&&e.createElement("input",{type:"text",className:"rge-form-input rge-mt-8",placeholder:y("editor.edge.customPlaceholder","请输入自定义关系类型"),value:D,onChange:v=>f(v.target.value),autoFocus:!0}))),e.createElement("div",{className:"rge-drawer-footer"},e.createElement("button",{className:"rge-btn-cancel",onClick:s},y("editor.panel.cancel","取消")),e.createElement("button",{className:"rge-btn-submit",onClick:q},y("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:g,onFetchDebugLogs:d,onFetchRunLogs:w,onNotify:S=ss,locale:D,messages:f,t:x})=>{const[_,y]=e.useState("send"),[B,j]=e.useState("TEST_MSG"),[W,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
+ }`),[v,A]=e.useState(!1),[$,k]=e.useState(!1),[C,oe]=e.useState(!1),[K,X]=e.useState(""),[re,ce]=e.useState([]),[p,Q]=e.useState(!1),[ie,U]=e.useState([]),[te,ge]=e.useState(!1),[Se,xe]=e.useState({visible:!1,title:"",data:""}),ve=e.useRef(0),ue=e.useRef(0),F=e.useRef(0),Z=e.useRef(r);e.useEffect(()=>{Z.current!==r&&(Z.current=r,ve.current+=1,ue.current+=1,F.current+=1,ce([]),U([]),j("TEST_MSG"),q("{}"),X(""),Q(!1),ge(!1),A(!1),k(!1),oe(!1),xe({visible:!1,title:"",data:""}))},[r]);const O=e.useMemo(()=>tt({locale:D,messages:f,t:x}),[D,f,x]),se=ln(D);e.useEffect(()=>{u==="running"&&oe(!1)},[u]);const Re=e.useCallback(async(J=!1)=>{if(!r){S("warning",O("editor.debugPanel.selectChainFirst","请先选择规则链"));return}if(!s){S("warning",O("editor.debugPanel.noSendCallback","未配置发送消息回调"));return}if(!J&&(u==="undeployed"||u==="stopped")){const ke=O("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");oe(!0),X(ke),S("warning",ke);return}const z=++F.current,fe=h.createDebugPanelRequestSnapshot(r,z);try{A(!0);let ke;try{ke=JSON.parse(W)}catch{S("error",O("editor.debugPanel.invalidJson","消息体 JSON 格式错误"));return}const je=await s(r,B,ke);if(!h.isDebugPanelRequestCurrent(fe,r,F.current))return;if(je.success)oe(!1),S("success",O("editor.debugPanel.sendSuccess","消息发送成功")),X(JSON.stringify(je.data,null,2));else{const dt=je.msg||O("editor.debugPanel.unknownError","未知错误");if(h.isRuleChainNotDeployedError(dt,r)){const We=O("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");oe(!0),X(We),S("warning",We);return}S("error",O("editor.debugPanel.sendFailed","发送失败: {{message}}",{message:dt})),X(je.msg||O("editor.debugPanel.sendTestMessage","发送测试消息"))}}catch(ke){if(!h.isDebugPanelRequestCurrent(fe,r,F.current))return;if(h.isRuleChainNotDeployedError(ke,r)){const je=O("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");oe(!0),X(je),S("warning",je);return}S("error",O("editor.debugPanel.sendException","发送异常: {{message}}",{message:ke instanceof Error?ke.message:String(ke)}))}finally{h.isDebugPanelRequestCurrent(fe,r,F.current)&&A(!1)}},[r,u,B,W,s,S,O]),ae=e.useCallback(async()=>{if(!g||$)return;const J=r;try{k(!0);const z=await g(J);if(Z.current!==J)return;if(z===!1||z&&typeof z=="object"&&z.success===!1){const fe=z&&typeof z=="object"&&z.msg?z.msg:O("editor.debugPanel.deployFailed","部署失败");S("error",O("editor.debugPanel.deployFailedWithMessage","部署失败: {{message}}",{message:fe}));return}oe(!1),S("success",O("editor.debugPanel.deploySucceeded","规则链已部署,正在重新发送")),await Re(!0)}catch(z){if(Z.current!==J)return;S("error",O("editor.debugPanel.deployFailedWithMessage","部署失败: {{message}}",{message:z instanceof Error?z.message:String(z)}))}finally{Z.current===J&&k(!1)}},[r,$,Re,g,S,O]),Ee=e.useCallback(async()=>{if(!r||!d)return;const J=++ve.current,z=h.createDebugPanelRequestSnapshot(r,J);try{Q(!0);const fe=await d(r,n);if(!h.isDebugPanelRequestCurrent(z,r,ve.current))return;ce(fe.items||[])}catch{h.isDebugPanelRequestCurrent(z,r,ve.current)&&S("error",O("editor.debugPanel.loadDebugLogsFailed","加载调试日志失败"))}finally{h.isDebugPanelRequestCurrent(z,r,ve.current)&&Q(!1)}},[r,n,d,S,O]),Ie=e.useCallback(async()=>{if(!w)return;const J=++ue.current,z=h.createDebugPanelRequestSnapshot(r,J);try{ge(!0);const fe=await w(r);if(!h.isDebugPanelRequestCurrent(z,r,ue.current))return;U(fe||[])}catch{h.isDebugPanelRequestCurrent(z,r,ue.current)&&S("error",O("editor.debugPanel.loadRunLogsFailed","加载运行日志失败"))}finally{h.isDebugPanelRequestCurrent(z,r,ue.current)&&ge(!1)}},[r,w,S,O]),H=(J,z)=>{let fe=z;try{fe=JSON.stringify(JSON.parse(z),null,2)}catch{}xe({visible:!0,title:J,data:fe})},de=J=>new Date(J).toLocaleString(se,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),pe=async J=>{try{await navigator.clipboard.writeText(J),S("success",O("editor.debugPanel.copied","已复制"))}catch{S("error",O("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:()=>y("send")},e.createElement(be,{value:"send"})," ",O("editor.debugPanel.sendMessage","发送消息")),e.createElement("button",{className:`rge-debug-tab ${_==="debug"?"active":""}`,onClick:()=>{y("debug"),Ee()}},e.createElement(be,{value:"debug"})," ",O("editor.debugPanel.debugLogs","调试日志")),e.createElement("button",{className:`rge-debug-tab ${_==="logs"?"active":""}`,onClick:()=>{y("logs"),Ie()}},e.createElement(be,{value:"data"})," ",O("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"},O("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"},O("editor.debugPanel.msgType","消息类型")),e.createElement("input",{type:"text",className:"rge-form-input",value:B,onChange:J=>j(J.target.value),placeholder:O("editor.debugPanel.msgTypePlaceholder","如 TEST_MSG")})),e.createElement("div",{className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},O("editor.debugPanel.msgBodyJson","消息体 (JSON)")),e.createElement("textarea",{className:"rge-code-textarea",rows:8,value:W,onChange:J=>q(J.target.value),spellCheck:!1})),C&&e.createElement("div",{className:"rge-debug-deploy-guide",role:"status"},e.createElement("span",null,O("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试")),g&&e.createElement("button",{type:"button",className:"rge-btn-mini",disabled:$||v,onClick:()=>{ae()}},$?O("editor.debugPanel.deploying","部署中..."):O("editor.debugPanel.deployAndRetry","部署并重试"))),e.createElement("button",{className:"rge-btn-submit rge-full-width",onClick:()=>{Re()},disabled:v},e.createElement(be,{value:"send"})," ",v?O("editor.debugPanel.sending","发送中..."):O("editor.debugPanel.sendTestMessage","发送测试消息")),K&&e.createElement("div",{className:"rge-form-section rge-mt-16"},e.createElement("div",{className:"rge-label-row"},e.createElement("label",{className:"rge-form-label"},O("editor.debugPanel.responseData","响应数据")),e.createElement("button",{className:"rge-btn-mini",onClick:()=>pe(K)},e.createElement(be,{value:"copy"})," ",O("editor.panel.copy","复制"))),e.createElement("pre",{className:"rge-response-pre"},K))),_==="debug"&&e.createElement("div",{className:"rge-debug-body"},e.createElement("div",{className:"rge-toolbar-row"},n&&e.createElement("span",{className:"rge-tag"},O("editor.debugPanel.nodeLabel","节点"),": ",n),e.createElement("button",{className:"rge-btn-mini",onClick:Ee,disabled:p},e.createElement(be,{value:"refresh",className:p?"is-spinning":""})," ",p?O("editor.debugPanel.loading","加载中..."):O("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,p?O("editor.debugPanel.loading","加载中..."):O("editor.debugPanel.noDebugLogs","暂无调试日志")),e.createElement("p",{className:"rge-sub-tip"},O("editor.debugPanel.debugModeHint",'需要在节点上开启"调试模式"并发送消息'))):e.createElement("div",{className:"rge-log-table"},e.createElement("div",{className:"rge-log-table-header"},e.createElement("span",null,O("editor.debugPanel.time","时间")),e.createElement("span",null,O("editor.debugPanel.type","类型")),e.createElement("span",null,O("editor.debugPanel.relation","关系")),e.createElement("span",null,O("editor.debugPanel.msgType","消息类型")),e.createElement("span",null,O("editor.debugPanel.operate","操作"))),re.map((J,z)=>e.createElement("div",{key:z,className:`rge-log-table-row ${J.err?"error":""}`},e.createElement("span",null,de(J.ts)),e.createElement("span",{className:"rge-tag-small"},J.flowType),e.createElement("span",{className:"rge-tag-small"},J.relationType),e.createElement("span",{title:J.msg.type},J.msg.type.length>12?J.msg.type.slice(0,12)+"...":J.msg.type),e.createElement("span",{className:"rge-log-actions"},e.createElement("button",{className:"rge-btn-link",onClick:()=>H(O("editor.debugPanel.data","数据"),J.msg.data)},O("editor.debugPanel.data","数据")),e.createElement("button",{className:"rge-btn-link",onClick:()=>H(O("editor.debugPanel.metadata","元数据"),JSON.stringify(J.msg.metadata))},O("editor.debugPanel.metadata","元数据")),J.err&&e.createElement("button",{className:"rge-btn-link danger",onClick:()=>H(O("editor.debugPanel.error","错误"),J.err||"")},O("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:Ie,disabled:te},e.createElement(be,{value:"refresh",className:te?"is-spinning":""})," ",te?O("editor.debugPanel.loading","加载中..."):O("editor.debugPanel.refresh","刷新"))),ie.length===0?e.createElement("div",{className:"rge-empty-tip"},e.createElement(be,{value:"data",className:"rge-empty-graphic"}),e.createElement("p",null,te?O("editor.debugPanel.loading","加载中..."):O("editor.debugPanel.noRunLogs","暂无运行日志"))):e.createElement("div",{className:"rge-log-list"},ie.map((J,z)=>e.createElement("div",{key:z,className:"rge-run-log-item",onClick:()=>H(O("editor.debugPanel.runLogDetail","日志详情"),JSON.stringify(J))},e.createElement("pre",null,typeof J=="string"?J:JSON.stringify(J,null,2)))))),Se.visible&&e.createElement("div",{className:"rge-detail-overlay",onClick:()=>xe({...Se,visible:!1})},e.createElement("div",{className:"rge-detail-modal",onClick:J=>J.stopPropagation()},e.createElement("div",{className:"rge-detail-header"},e.createElement("span",null,Se.title),e.createElement("div",null,e.createElement("button",{className:"rge-btn-mini",onClick:()=>pe(Se.data)},e.createElement(be,{value:"copy"})),e.createElement("button",{className:"rge-drawer-close",onClick:()=>xe({...Se,visible:!1})},"✕"))),e.createElement("pre",{className:"rge-detail-pre"},Se.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:g,messages:d,t:w})=>{const S=e.useMemo(()=>tt({locale:g,messages:d,t:w}),[g,d,w]),D=n||S("editor.dataView.title","规则链数据"),f=e.useMemo(()=>ls(r??{}),[r]),x=e.useMemo(()=>{const B=f?f.split(/\r\n|\r|\n/).length:0,j=typeof Blob<"u"?new Blob([f]).size:new TextEncoder().encode(f).length;return{lineCount:B,byteSize:cs(j)}},[f]),_=async()=>{try{await navigator.clipboard.writeText(f),u==null||u("success",S("editor.dataView.copied","JSON 已复制到剪贴板"))}catch{u==null||u("error",S("editor.dataView.copyFailed","复制失败"))}},y=()=>{try{const B=new Blob([f],{type:"application/json"}),j=URL.createObjectURL(B),W=new Date().toISOString().slice(0,19).replace(/[:]/g,"-"),q=`${o}_${W}.json`,v=document.createElement("a");v.href=j,v.download=q,document.body.appendChild(v),v.click(),document.body.removeChild(v),URL.revokeObjectURL(j),u==null||u("success",S("editor.dataView.downloaded","已下载 {{fileName}}",{fileName:q}))}catch{u==null||u("error",S("editor.dataView.downloadFailed","下载失败"))}};return t?e.createElement("div",{className:"rge-dataview-overlay",onClick:s},e.createElement("div",{className:"rge-dataview-dialog",onClick:B=>B.stopPropagation()},e.createElement("div",{className:"rge-dialog-header"},e.createElement("div",{className:"rge-dialog-title"},e.createElement(be,{value:"data"}),e.createElement("span",null,D)),e.createElement("button",{className:"rge-drawer-close",onClick:s},"✕")),e.createElement("div",{className:"rge-dialog-toolbar"},e.createElement("span",{className:"rge-dialog-meta"},S("editor.dataView.fullJson","完整 JSON")," · ",S("editor.dataView.lineCount","{{count}} 行",{count:x.lineCount})," · ",S("editor.dataView.byteSize","{{size}}",{size:x.byteSize})),e.createElement("button",{type:"button",className:"rge-btn-outline",onClick:_},e.createElement(be,{value:"copy"})," ",S("editor.dataView.copyJson","复制")),e.createElement("button",{type:"button",className:"rge-btn-outline",onClick:y},e.createElement(be,{value:"export"})," ",S("editor.dataView.downloadJson","下载"))),e.createElement("div",{className:"rge-dialog-hint"},S("editor.dataView.fullJsonHint","当前视图不截断数据;大数据可直接复制或下载后查看。")),e.createElement("div",{className:"rge-dialog-body"},e.createElement("textarea",{className:"rge-json-textarea",value:f,readOnly:!0,spellCheck:!1,"aria-label":D})))):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:g,onUndo:d,onRedo:w,onDelete:S,onZoomIn:D,onZoomOut:f,onZoomChange:x,onFitView:_,onResetZoom:y,onFullscreen:B,onToggleDebug:j,onViewData:W,onSettings:q,onValidate:v,onNew:A,onImport:$,onExport:k,onAutoLayout:C,extraButtons:oe=[],hiddenButtons:K=[],hideZoom:X=!1,chainName:re,locale:ce,messages:p,t:Q})=>{const[ie,U]=e.useState(!1);e.useEffect(()=>{X&&U(!1)},[X]);const te=e.useMemo(()=>tt({locale:ce,messages:p,t:Q}),[ce,p,Q]),ge=ue=>K.includes(ue),Se=ue=>{const F=h.getEditorToolbarIconSvg(ue);return F?e.createElement("span",{className:"rge-toolbar-icon rge-toolbar-icon-svg",dangerouslySetInnerHTML:{__html:F}}):e.createElement("span",{className:"rge-toolbar-icon"},ue)},ve=[{key:"new",icon:"file-plus",tooltip:te("editor.toolbar.newChain","新建规则链"),onClick:()=>A==null?void 0:A(),hidden:ge("new")||!A},{key:"save",icon:"save",tooltip:`${te("editor.toolbar.save","保存")} (Ctrl+S)`,onClick:()=>g==null?void 0:g(),hidden:ge("save")},{key:"import",icon:"import",tooltip:te("editor.toolbar.import","导入"),onClick:()=>$==null?void 0:$(),hidden:ge("import")||!$},{key:"export",icon:"export",tooltip:te("editor.toolbar.export","导出"),onClick:()=>k==null?void 0:k(),hidden:ge("export")||!k},{key:"undo",icon:"undo",tooltip:`${te("editor.toolbar.undo","撤销")} (Ctrl+Z)`,onClick:()=>d==null?void 0:d(),disabled:!t,hidden:ge("undo"),dividerBefore:!0},{key:"redo",icon:"redo",tooltip:`${te("editor.toolbar.redo","重做")} (Ctrl+Y)`,onClick:()=>w==null?void 0:w(),disabled:!r,hidden:ge("redo")},{key:"delete",icon:"delete",tooltip:`${te("editor.toolbar.delete","删除选中")} (Del)`,onClick:()=>S==null?void 0:S(),disabled:!u,hidden:ge("delete")},{key:"zoomIn",icon:"zoom-in",tooltip:te("editor.toolbar.zoomIn","放大"),onClick:()=>D==null?void 0:D(),hidden:ge("zoomIn"),dividerBefore:!0},{key:"zoomOut",icon:"zoom-out",tooltip:te("editor.toolbar.zoomOut","缩小"),onClick:()=>f==null?void 0:f(),hidden:ge("zoomOut")},{key:"fitView",icon:"fit",tooltip:te("editor.toolbar.fitView","适应画布"),onClick:()=>_==null?void 0:_(),hidden:ge("fitView")},{key:"autoLayout",icon:"auto-layout",tooltip:te("editor.toolbar.autoLayout","自动排版"),onClick:()=>C==null?void 0:C(),hidden:ge("autoLayout")||!C},{key:"resetZoom",icon:"1:1",tooltip:te("editor.toolbar.resetZoom","重置缩放"),onClick:()=>y==null?void 0:y(),hidden:ge("resetZoom")},{key:"validate",icon:"validate",tooltip:te("editor.toolbar.validate","校验规则链"),onClick:()=>v==null?void 0:v(),hidden:ge("validate")||!v,dividerBefore:!0},{key:"debug",icon:"debug",tooltip:o?te("editor.toolbar.debugOff","关闭调试"):te("editor.toolbar.debugOn","开启调试"),onClick:()=>j==null?void 0:j(),active:o,hidden:ge("debug")},{key:"viewData",icon:"data",tooltip:te("editor.toolbar.viewData","查看数据"),onClick:()=>W==null?void 0:W(),hidden:ge("viewData")},{key:"settings",icon:"settings",tooltip:te("editor.toolbar.settings","设置"),onClick:()=>q==null?void 0:q(),hidden:ge("settings")||!q},{key:"fullscreen",icon:n?"fullscreen-exit":"fullscreen",tooltip:n?te("editor.toolbar.exitFullscreen","退出全屏"):te("editor.toolbar.fullscreen","全屏"),onClick:()=>B==null?void 0:B(),hidden:ge("fullscreen")},...oe].filter(ue=>!ue.hidden&&!ge(ue.key));return e.createElement("div",{className:"rge-editor-toolbar"},e.createElement("div",{className:"rge-toolbar-left"},ve.map((ue,F)=>e.createElement(e.Fragment,{key:ue.key},F>0&&ue.dividerBefore&&e.createElement("div",{className:"rge-toolbar-divider"}),e.createElement("button",{type:"button",className:`rge-toolbar-btn ${ue.active?"active":""} ${ue.disabled?"disabled":""}`,onClick:ue.onClick,disabled:ue.disabled,title:ue.tooltip,"aria-pressed":ue.active===void 0?void 0:ue.active},Se(ue.icon))))),re&&e.createElement("div",{className:"rge-toolbar-center"},e.createElement("span",{className:"rge-chain-name"},re)),!X&&e.createElement("div",{className:"rge-toolbar-right"},e.createElement("button",{type:"button",className:"rge-toolbar-zoom-btn",onClick:()=>U(!ie),title:te("editor.toolbar.zoomOptions","缩放选项")},s,"%"),ie&&e.createElement("div",{className:"rge-zoom-menu",onMouseLeave:()=>U(!1)},[50,75,100,125,150,200].map(ue=>e.createElement("button",{type:"button",key:ue,className:`rge-zoom-option ${ue===s?"active":""}`,"aria-pressed":ue===s,disabled:!x&&ue!==100,onClick:()=>{x?x(ue):ue===100&&(y==null||y()),U(!1)}},ue,"%")),e.createElement("div",{className:"rge-toolbar-divider horizontal"}),e.createElement("button",{type:"button",className:"rge-zoom-option",onClick:()=>{_==null||_(),U(!1)}},te("editor.toolbar.fitView","适应画布")))))};Ma.displayName="EditorToolbar";const Oa=({visible:t,x:r,y:n,items:o,onClose:s})=>{const u=e.useRef(null),g=e.useCallback(x=>{u.current&&!u.current.contains(x.target)&&s()},[s]),d=e.useCallback(x=>{x.key==="Escape"&&s()},[s]),w=e.useCallback(x=>{const _=Array.from(x.children).find(W=>W.classList.contains("rge-ctx-submenu"));if(!_)return;_.style.display="block",_.style.visibility="hidden";const y=x.getBoundingClientRect(),B=_.getBoundingClientRect(),j=h.resolveContextSubmenuPosition(y,{width:B.width,height:B.height},{width:window.innerWidth,height:window.innerHeight});_.dataset.placement=j.placement,_.style.left=`${j.left}px`,_.style.top=`${j.top}px`,_.style.visibility="visible"},[]);if(e.useEffect(()=>(t&&(document.addEventListener("mousedown",g),document.addEventListener("keydown",d)),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("keydown",d)}),[t,g,d]),e.useEffect(()=>{if(t&&u.current){const x=u.current.getBoundingClientRect(),_=h.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 S=o.filter(x=>!x.hidden),D=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:_=>w(_.currentTarget)},e.createElement("div",{className:"rge-ctx-menu-item-content"},x.icon&&f(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(D)))):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"},x.icon&&f(x.icon),e.createElement("span",{className:"rge-ctx-menu-label"},x.label),x.shortcut&&e.createElement("span",{className:"rge-ctx-menu-shortcut"},x.shortcut)))),f=x=>{const _=h.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}},S.map(D))};Oa.displayName="ContextMenu";function is(t,r){const n=tt(r),o=t.nodeType===void 0||h.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=tt(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=tt(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"},Aa=({nodes:t,viewport:r,width:n=200,height:o=150,defaultCollapsed:s=!1,position:u="bottom-right",onViewportChange:g,onNodeClick:d,locale:w,messages:S,t:D})=>{const[f,x]=e.useState(s),_=e.useRef(null),y=e.useRef(!1),B=e.useMemo(()=>tt({locale:w,messages:S,t:D}),[w,S,D]),j=e.useCallback(()=>{if(t.length===0)return{minX:0,minY:0,maxX:100,maxY:100};let k=1/0,C=1/0,oe=-1/0,K=-1/0;t.forEach(re=>{const ce=re.width||60,p=re.height||40;k=Math.min(k,re.x),C=Math.min(C,re.y),oe=Math.max(oe,re.x+ce),K=Math.max(K,re.y+p)});const X=50;return{minX:k-X,minY:C-X,maxX:oe+X,maxY:K+X}},[t]);e.useEffect(()=>{const k=_.current;if(f||!k)return;const C=k.getContext("2d");if(!C)return;const oe=h.getThemeRuntimeVariables(),K=()=>{const re=getComputedStyle(k),ce=te=>re.getPropertyValue(te).trim()||oe[te]||re.color,p=j(),Q=p.maxX-p.minX,ie=p.maxY-p.minY,U=Math.min(n/Q,o/ie);if(C.clearRect(0,0,n,o),C.fillStyle=ce("--rg-canvas-bg"),C.fillRect(0,0,n,o),t.forEach(te=>{const ge=(te.x-p.minX)*U,Se=(te.y-p.minY)*U,xe=Math.max((te.width||60)*U,4),ve=Math.max((te.height||40)*U,3);C.fillStyle=te.color||ce(ds[te.type||""]||"--hb-text-muted"),C.fillRect(ge,Se,xe,ve),te.selected&&(C.strokeStyle=ce("--hb-node-selected-stroke"),C.lineWidth=1,C.strokeRect(ge-1,Se-1,xe+2,ve+2))}),r){const te=(r.x-p.minX)*U,ge=(r.y-p.minY)*U,Se=r.width*U,xe=r.height*U;C.strokeStyle=ce("--hb-color-primary"),C.lineWidth=2,C.strokeRect(te,ge,Se,xe),C.save(),C.fillStyle=ce("--hb-color-primary"),C.globalAlpha=.1,C.fillRect(te,ge,Se,xe),C.restore()}};K();const X=new MutationObserver(K);for(let re=k.parentElement;re&&re!==k.ownerDocument.body;re=re.parentElement)X.observe(re,{attributes:!0,attributeFilter:["style","class","data-theme","data-rg-theme"]});return()=>X.disconnect()},[t,r,f,n,o,j]);const W=e.useCallback(k=>{if(!g||!_.current)return;const C=_.current.getBoundingClientRect(),oe=k.clientX-C.left,K=k.clientY-C.top,X=j(),re=X.maxX-X.minX,ce=X.maxY-X.minY,p=Math.min(n/re,o/ce),Q=oe/p+X.minX,ie=K/p+X.minY;g({x:Q,y:ie})},[g,j,n,o]),q=e.useCallback(k=>{y.current=!0,W(k)},[W]),v=e.useCallback(k=>{y.current&&W(k)},[W]),A=e.useCallback(()=>{y.current=!1},[]),$={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:$},e.createElement("div",{className:"rge-minimap-header",onClick:()=>x(!f)},e.createElement("span",{className:"rge-minimap-title"},e.createElement(be,{value:"map"})," ",B("editor.toolbar.minimap","小地图")),e.createElement("span",{className:"rge-minimap-toggle"},f?"▶":"▼")),!f&&e.createElement("canvas",{ref:_,width:n,height:o,className:"rge-minimap-canvas",onMouseDown:q,onMouseMove:v,onMouseUp:A,onMouseLeave:A}))};Aa.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 h.isWorkspaceTabPinned(r)?"取消固定":"固定";case"edit-info":return"编辑信息";case"run-history":return"运行记录";case"debug":return"调试";case"toggle-disabled":return h.getWorkspaceTabLifecycleState(r)==="running"?"下线":"部署"}}function gs({tabs:t,activeTabId:r=null,locale:n,t:o,onActivate:s,onClose:u,onAdd:g,onEditInfo:d,onTabAction:w,hideAdd:S=!1,hideOverflow:D=!1,hideClose:f=!1,hiddenTabActions:x=[]}){var ce;const _=e.useMemo(()=>tt({locale:n,t:o}),[n,o]),[y,B]=e.useState(!1),j=e.useRef(null),W=e.useMemo(()=>{if(!y||!j.current)return{};const p=j.current.getBoundingClientRect();return{top:p.bottom+2,right:Math.max(4,window.innerWidth-p.right)}},[y]),[q,v]=e.useState(null),[A,$]=e.useState(null),k=e.useRef(null),C=r||((ce=t[0])==null?void 0:ce.id)||"",oe=t.find(p=>p.id===C),K=q?t.find(p=>p.id===q.tabId):void 0,X=p=>h.getEditorWorkspaceTabActions(p).filter(Q=>!x.includes(Q.id)),re=K?X(K):[];return e.useEffect(()=>{D&&B(!1)},[D]),e.useEffect(()=>{if(!y)return;const p=()=>B(!1),Q=te=>{var ge;(ge=j.current)!=null&&ge.contains(te.target)||p()},ie=te=>{te.key==="Escape"&&p()},U=te=>{var ge;(ge=j.current)!=null&&ge.contains(te.target)||p()};return document.addEventListener("pointerdown",Q,!0),document.addEventListener("keydown",ie),document.addEventListener("scroll",U,!0),window.addEventListener("resize",p),()=>{document.removeEventListener("pointerdown",Q,!0),document.removeEventListener("keydown",ie),document.removeEventListener("scroll",U,!0),window.removeEventListener("resize",p)}},[y]),e.useEffect(()=>{re.length||v(null)},[re.length]),e.useLayoutEffect(()=>{if(!q||!k.current)return;const p=k.current.getBoundingClientRect(),Q=h.clampContextMenuPosition({left:q.x,top:q.y},{width:p.width,height:p.height},{width:window.innerWidth,height:window.innerHeight});$(ie=>(ie==null?void 0:ie.left)===Q.left&&ie.top===Q.top?ie:Q)},[q,re.length]),e.useEffect(()=>{if(!q)return;const p=()=>v(null);return document.addEventListener("click",p),document.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{document.removeEventListener("click",p),document.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[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(p=>{var ge,Se,xe;const Q=p.id===C,ie=((ge=p.metadata)==null?void 0:ge.root)!==!1&&((xe=(Se=p.data)==null?void 0:Se.ruleChain)==null?void 0:xe.root)!==!1,U=h.getWorkspaceTabLifecycleState(p),te=h.isWorkspaceTabPinned(p);return e.createElement("div",{key:p.id,className:`rge-workspace-tab${Q?" is-active":""}${p.isDirty?" is-dirty":""}`,"data-workspace-tab-id":p.id,role:"tab","aria-selected":Q,"aria-busy":p.isLoading||void 0,title:p.isDirty?`${p.title} · ${_("editor.workspace.unsaved","有未保存修改")}`:p.title,onClick:()=>s==null?void 0:s(p.id),onDoubleClick:()=>d==null?void 0:d(p.id),onContextMenu:ve=>{X(p).length&&(ve.preventDefault(),ve.stopPropagation(),s==null||s(p.id),$({left:ve.clientX,top:ve.clientY}),v({tabId:p.id,x:ve.clientX,y:ve.clientY}))}},U!=="undeployed"&&e.createElement("span",{className:`rge-workspace-tab__lifecycle is-${U}`,"aria-label":_(`editor.workspace.${U}`,U==="running"?"运行中":"已停止"),title:_(`editor.workspace.${U}`,U==="running"?"运行中":"已停止")}),e.createElement("span",{className:`rge-workspace-tab__kind${ie?" is-root":" is-child"}`,"aria-hidden":"true"},te?"★":ie?"◆":"↳"),e.createElement("span",{className:"rge-workspace-tab__title"},p.title||p.chainId),p.isLoading&&e.createElement("span",{className:"rge-workspace-tab__loading","aria-label":_("editor.workspace.loading","加载中")}),f&&p.isDirty&&e.createElement("span",{className:"rge-workspace-tab__dirty-dot","aria-label":_("editor.workspace.unsaved","有未保存修改")}),!f&&e.createElement("button",{type:"button",className:"rge-workspace-tab__close","data-workspace-close-id":p.id,"aria-label":`${_("editor.workspace.close","关闭")} ${p.title||p.chainId}`,title:_("editor.workspace.close","关闭"),onClick:ve=>{ve.stopPropagation(),u==null||u(p.id)}},p.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","打开规则链后显示标签"))),!S&&e.createElement("button",{type:"button",className:"rge-workspace-tabs__icon",title:_("editor.workspace.add","新建规则链"),"aria-label":_("editor.workspace.add","新建规则链"),onClick:g},"+"),!D&&t.length>0&&e.createElement("div",{className:"rge-workspace-tabs__overflow",ref:j},e.createElement("button",{type:"button",className:"rge-workspace-tabs__icon",title:_("editor.workspace.all","全部规则链"),"aria-label":_("editor.workspace.all","全部规则链"),"aria-expanded":y,onClick:()=>B(p=>!p)},"▾"),y&&e.createElement("div",{className:"rge-workspace-tabs__menu",role:"menu",style:W},t.map(p=>{const Q=h.getWorkspaceTabLifecycleState(p);return e.createElement("button",{key:p.id,type:"button",role:"menuitem",className:p.id===C?"is-active":"",onClick:()=>{s==null||s(p.id),B(!1)}},Q!=="undeployed"&&e.createElement("span",{className:`rge-workspace-tab__lifecycle is-${Q}`,"aria-hidden":"true"}),h.isWorkspaceTabPinned(p)?"★ ":"",p.isDirty?"● ":"",p.title||p.chainId)}))),oe&&e.createElement("span",{className:"rge-workspace-tabs__status","aria-live":"polite"},oe.isDirty?"●":""),q&&K&&re.length>0&&e.createElement("div",{className:"rge-workspace-tabs__context-menu",ref:k,role:"menu",style:{left:(A==null?void 0:A.left)??q.x,top:(A==null?void 0:A.top)??q.y},onClick:p=>p.stopPropagation()},re.map(p=>{const Q=p.id==="close"?!!u:p.id==="edit-info"?!!d:!!w;return e.createElement("button",{key:p.id,type:"button",role:"menuitem","data-workspace-tab-action":p.id,className:p.dividerBefore?"is-divider-before":void 0,disabled:p.disabled||!Q,onClick:()=>{p.disabled||!Q||(p.id==="close"?u==null||u(K.id):p.id==="edit-info"?d==null||d(K.id):w==null||w(K.id,p.id),v(null))}},_(p.labelKey,ps(p.id,K)))})))}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,g,d,w;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:((g=t.graphModel.edges)==null?void 0:g.length)||0,selectedCount:(((d=r.nodes)==null?void 0:d.length)||0)+(((w=r.edges)==null?void 0:w.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:g,onZoomOut:d,onResetZoom:w,onOpenDiagnostics:S,className:D="",locale:f,messages:x,t:_}){const y=e.useMemo(()=>tt({locale:f,messages:x,t:_}),[f,x,_]),[B,j]=e.useState(()=>ma(t));e.useEffect(()=>{const X=()=>j(ma(t));if(X(),!!(t!=null&&t.on))return ua.forEach(re=>{var ce;return(ce=t.on)==null?void 0:ce.call(t,re,X)}),()=>ua.forEach(re=>{var ce;return(ce=t.off)==null?void 0:ce.call(t,re,X)})},[t]);const W=r??B.nodeCount,q=n??B.edgeCount,v=o??B.selectedCount,A=s??B.zoom,$=X=>{t!=null&&t.zoom&&t.zoom((A>0?A:1)*X)},k=()=>g?g():$(1.2),C=()=>d?d():$(1/1.2),oe=()=>{var X;return w?w():(X=t==null?void 0:t.resetZoom)==null?void 0:X.call(t)},K=["rge-status-bar",D].filter(Boolean).join(" ");return e.createElement("div",{className:K,role:"status","aria-live":"polite"},e.createElement("button",{type:"button",className:"rge-status-bar__button",title:y("editor.statusBar.zoomOut","缩小"),"aria-label":y("editor.statusBar.zoomOut","缩小"),onClick:C},"−"),e.createElement("button",{type:"button",className:"rge-status-bar__value",title:y("editor.statusBar.resetZoom","重置为 100%"),onClick:oe},Math.round(A*100),"%"),e.createElement("button",{type:"button",className:"rge-status-bar__button",title:y("editor.statusBar.zoomIn","放大"),"aria-label":y("editor.statusBar.zoomIn","放大"),onClick:k},"+"),e.createElement("span",{className:"rge-status-bar__separator","aria-hidden":"true"},"|"),e.createElement("span",{className:"rge-status-bar__item"},y("editor.statusBar.nodes","节点")," ",W),e.createElement("span",{className:"rge-status-bar__item"},y("editor.statusBar.edges","边")," ",q),v>0&&e.createElement("span",{className:"rge-status-bar__item"},y("editor.statusBar.selected","已选")," ",v),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:y("editor.statusBar.diagnostics","查看链路诊断"),onClick:S},y("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:g,t:d}){const w=e.useMemo(()=>tt({locale:u,messages:g,t:d}),[u,g,d]),S=String((t==null?void 0:t.status)||"unknown"),D=da[S]||da.unknown,f=(t==null?void 0:t.api)||"unknown",x=(t==null?void 0:t.ws)||"idle",_=`${w("editor.connection.api","API")}: ${f} · ${w("editor.connection.ws","WS")}: ${x}`,y=["rge-connection-status",`is-${D.kind}`,r?"is-compact":"",s].filter(Boolean).join(" "),B=S==="unauthorized"?o:S==="offline"||S==="error"?n:void 0,j=S==="unauthorized"?w("editor.connection.login","登录"):w("editor.connection.retry","重试");return e.createElement("div",{className:y,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"},w(D.key,D.fallback)),!r&&e.createElement("span",{className:"rge-connection-status__detail"},_),B&&e.createElement("button",{type:"button",className:"rge-connection-status__action",onClick:B},j))}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:g,onActivatePanel:d,onClosePanel:w,onTogglePanel:S,onResize:D}){var $;const f=e.useRef(null),x=e.useRef(null),[_,y]=e.useState(!1),B=e.useMemo(()=>ys(n,t),[n,t]),j=n.activeByDock[t]&&B.some(k=>k.id===n.activeByDock[t])?n.activeByDock[t]:(($=B[0])==null?void 0:$.id)||null,W=t==="bottom"?r.bottom.height:r[t].width,q=r[t].visible&&B.length>0,v=t==="left";e.useEffect(()=>()=>{const k=x.current;x.current=null,k==null||k(!1)},[]);const A=k=>{var ie,U;if(!D)return;k.preventDefault();const C=t==="bottom"?k.clientY:k.clientX,oe=W,K=t==="left"?1:-1,X=k.currentTarget,re=k.pointerId;(ie=X.setPointerCapture)==null||ie.call(X,re);const ce=te=>{const ge=t==="bottom"?te.clientY:te.clientX;D(t,oe+(ge-C)*K)},p=te=>{var ge,Se;window.removeEventListener("pointermove",ce),window.removeEventListener("pointerup",Q),window.removeEventListener("pointercancel",Q),(ge=X.hasPointerCapture)!=null&&ge.call(X,re)&&((Se=X.releasePointerCapture)==null||Se.call(X,re)),te&&y(!1),x.current=null},Q=()=>p(!0);(U=x.current)==null||U.call(x,!0),x.current=p,y(!0),window.addEventListener("pointermove",ce),window.addEventListener("pointerup",Q,{once:!0}),window.addEventListener("pointercancel",Q,{once:!0})};return q?e.createElement("section",{ref:f,className:["rge-panel-dock",`rge-panel-dock--${t}`,_&&"is-resizing",u].filter(Boolean).join(" "),style:t==="bottom"?{height:W}:{width:W},"aria-label":s},e.createElement("div",{className:"rge-panel-dock__header"},v?e.createElement("strong",{className:"rge-panel-dock__title"},s||"模块"):e.createElement("div",{className:"rge-panel-dock__tabs",role:"tablist"},B.map(k=>e.createElement("button",{key:k.id,type:"button",role:"tab","aria-selected":k.id===j,className:k.id===j?"is-active":"",onClick:()=>d==null?void 0:d(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:()=>g==null?void 0:g(t,!1)},"×")),e.createElement("div",{className:"rge-panel-dock__body"},v?B.map(k=>e.createElement("div",{key:k.id,className:"rge-panel-dock__stack-panel"},(()=>{const C=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:C?"收起内容":"展开内容","aria-label":`${C?"收起":"展开"}${k.title||k.id}`,"aria-expanded":C,onClick:()=>S==null?void 0:S(k.id,!C)},C?"−":"+"),k.closeable!==!1&&e.createElement("button",{type:"button",title:"关闭面板","aria-label":`关闭${k.title||k.id}`,onClick:()=>w==null?void 0:w(k.id)},"×")),e.createElement("div",{className:"rge-panel-dock__panel-content",hidden:!C},o==null?void 0:o(k)))})())):B.map(k=>e.createElement("div",{key:k.id,className:`rge-panel-dock__tab-panel${ur(n,k)?"":" is-collapsed"}`,hidden:k.id!==j},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:()=>S==null?void 0:S(k.id,!ur(n,k))},ur(n,k)?"−":"+"),k.closeable!==!1&&e.createElement("button",{type:"button",title:"关闭面板","aria-label":`关闭${k.title||k.id}`,onClick:()=>w==null?void 0:w(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:A})):null}function _s({visible:t=!0,x:r,y:n,flipDown:o=!1,targetId:s,showRun:u=!0,nodeType:g,className:d="",onAction:w,onEdit:S,onCopy:D,onDelete:f,onRunFrom:x,onRunOnly:_,locale:y,messages:B,t:j}){const W=e.useMemo(()=>tt({locale:y,messages:B,t:j}),[y,B,j]);if(!t||!s)return null;const q=u&&h.isEditorNodeRunTarget(g||"simple-node"),v=($,k)=>{($==="run-from"||$==="run-only")&&!q||(k==null||k(s),w==null||w($,s))},A=($,k,C,oe,K="")=>e.createElement("button",{key:$,type:"button",className:`rge-hover-tools__button ${K}`,title:k,"aria-label":k,onClick:()=>v($,oe)},e.createElement(be,{value:C}));return e.createElement("div",{className:["rge-hover-tools","rge-node-hover-tools",o?"is-flip-down":"",d].filter(Boolean).join(" "),style:{left:r,top:n},role:"toolbar","aria-label":W("editor.hoverTools.nodeActions","节点操作")},A("edit",W("editor.hoverTools.edit","编辑节点"),"edit",S),A("copy",W("editor.hoverTools.copy","复制节点"),"copy",D),q&&A("run-from",W("editor.hoverTools.runFrom","从此节点开始执行"),"play",x,"is-primary"),q&&A("run-only",W("editor.hoverTools.runOnly","仅执行此节点"),"play-single",_,"is-warning"),A("delete",W("editor.hoverTools.delete","删除节点"),"delete",f,"is-danger"))}function vs({visible:t=!0,x:r,y:n,flipDown:o=!1,targetId:s,className:u="",onAction:g,onInsertNode:d,onDelete:w,locale:S,messages:D,t:f}){const x=e.useMemo(()=>tt({locale:S,messages:D,t:f}),[S,D,f]);if(!t||!s)return null;const _=(j,W)=>{W==null||W(s),g==null||g(j,s)},y=x("editor.hoverTools.insertNode","在连线中插入组件"),B=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:y,"aria-label":y,onClick:()=>_("insert-node",d)},e.createElement(be,{value:"add"})),e.createElement("button",{type:"button",className:"rge-hover-tools__button is-danger",title:B,"aria-label":B,onClick:()=>_("delete",w)},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:g,onClose:d,onClear:w,locale:S,messages:D,t:f})=>{const[x,_]=e.useState("all"),y=e.useMemo(()=>tt({locale:S,messages:D,t:f}),[S,D,f]),B=s||y("editor.validation.title","规则链校验"),j=e.useMemo(()=>{const q={error:0,warning:0,info:0};return t.forEach(v=>{q[v.level]!==void 0&&q[v.level]++}),q},[t]),W=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"}),B),e.createElement("div",{className:"rge-validation-actions"},u&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:u,disabled:o,title:y("editor.validation.revalidate","重新校验")},e.createElement(be,{value:"refresh",className:o?"is-spinning":""}),y("editor.validation.validate","校验")),w&&t.length>0&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:w,title:y("editor.validation.clearResults","清除结果")},e.createElement(be,{value:"delete"})),d&&e.createElement("button",{type:"button",className:"rge-validation-btn",onClick:d,title:y("editor.validation.close","关闭")},"✕"))),e.createElement("div",{className:"rge-validation-stats"},e.createElement("button",{className:`rge-validation-stat ${x==="all"?"active":""}`,onClick:()=>_("all")},y("editor.validation.all","全部")," (",t.length,")"),e.createElement("button",{className:`rge-validation-stat error ${x==="error"?"active":""}`,onClick:()=>_("error")},e.createElement(be,{value:Gr.error})," ",j.error),e.createElement("button",{className:`rge-validation-stat warning ${x==="warning"?"active":""}`,onClick:()=>_("warning")},e.createElement(be,{value:Gr.warning})," ",j.warning),e.createElement("button",{className:`rge-validation-stat info ${x==="info"?"active":""}`,onClick:()=>_("info")},e.createElement(be,{value:Gr.info})," ",j.info)),e.createElement("div",{className:"rge-validation-body"},o&&e.createElement("div",{className:"rge-validation-loading"},e.createElement(be,{value:"refresh",className:"is-spinning"}),y("editor.validation.validating","正在校验...")),!o&&W.length===0&&e.createElement("div",{className:"rge-validation-empty"},t.length===0?e.createElement(e.Fragment,null,e.createElement(be,{value:"validate"})," ",y("editor.validation.empty","无校验结果,请点击校验按钮开始")):y("editor.validation.noFilteredResults","当前筛选无结果")),!o&&W.map((q,v)=>e.createElement("div",{key:`${q.rule}-${q.elementId||v}`,className:`rge-validation-item level-${q.level}`,onClick:()=>g==null?void 0:g(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:g,onClose:d,locale:w,messages:S,t:D}){const[f,x]=e.useState("all"),_=e.useMemo(()=>tt({locale:w,messages:S,t:D}),[w,S,D]),y=e.useMemo(()=>t.reduce((v,A)=>(v[A.severity]+=1,v),{error:0,warning:0,info:0}),[t]),B=e.useMemo(()=>{const v=new Map;return t.filter(A=>f==="all"||A.severity===f).forEach(A=>{const $=Ns(A),k=v.get($)||[];k.push(A),v.set($,k)}),Array.from(v.entries()).map(([A,$])=>({key:A,items:$.sort((k,C)=>pa[k.severity]-pa[C.severity])}))},[f,t]);if(!r)return null;const j=o||_("editor.problems.title","链路诊断"),W=v=>_(Cs[v],v==="error"?"错误":v==="warning"?"警告":"提示"),q=(v,A,$,k="")=>e.createElement("button",{type:"button",className:`rge-problems__filter ${k} ${f===v?"is-active":""}`,"aria-pressed":f===v,onClick:()=>x(v)},A," ",e.createElement("span",null,$));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:n,title:_("editor.problems.validate","重新校验")},n?"…":"↻"),g&&t.length>0&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:g,title:_("editor.problems.clear","清除问题")},"⌫"),d&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:d,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",W("error"),y.error,"is-error"),q("warning",W("warning"),y.warning,"is-warning"),q("info",W("info"),y.info,"is-info")),e.createElement("div",{className:"rge-problems__body"},n&&e.createElement("div",{className:"rge-problems__empty"},_("editor.problems.loading","正在校验…")),!n&&B.length===0&&e.createElement("div",{className:"rge-problems__empty"},t.length?_("editor.problems.noFiltered","当前筛选无问题"):_("editor.problems.empty","未发现链路问题")),!n&&B.map(v=>{const A=v.items[0];return e.createElement("div",{className:"rge-problems__group",key:v.key},e.createElement("button",{type:"button",className:"rge-problems__group-heading",onClick:()=>u==null?void 0:u(A)},e.createElement("span",{className:`rge-problems__marker is-${A.severity}`,"aria-hidden":"true"}),e.createElement("span",{className:"rge-problems__group-label"},ks(A,($,k)=>_($,k))),e.createElement("span",{className:"rge-problems__group-count"},v.items.length)),v.items.map($=>e.createElement("button",{type:"button",className:`rge-problems__item is-${$.severity}`,key:$.id,onClick:()=>u==null?void 0:u($)},e.createElement("span",{className:"rge-problems__item-severity"},W($.severity)),e.createElement("span",{className:"rge-problems__item-message"},$.message),e.createElement("span",{className:"rge-problems__item-rule"},$.rule))))})))}Fa.displayName="ProblemsPanel";const ja=({visible:t,data:r,readOnly:n=!1,title:o,customFields:s=[],onSave:u,onClose:g,locale:d,messages:w,t:S})=>{const[D,f]=e.useState(r),[x,_]=e.useState({}),y=e.useMemo(()=>tt({locale:d,messages:w,t:S}),[d,w,S]),B=o||y("editor.ruleChainSettings.title","规则链设置");e.useEffect(()=>{f(r),_({})},[r,t]);const j=(v,A)=>{f($=>({...$,[v]:A})),x[v]&&_($=>{const k={...$};return delete k[v],k})},W=()=>{const v={};return(!D.name||D.name.trim()==="")&&(v.name=y("editor.ruleChainSettings.nameRequired","规则链名称不能为空")),_(v),Object.keys(v).length===0},q=()=>{n||W()&&(u==null||u(D),g())};return e.useEffect(()=>{const v=A=>{A.key==="Escape"&&t&&g()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[t,g]),t?e.createElement("div",{className:"rge-modal-overlay",onClick:g},e.createElement("div",{className:"rge-modal",onClick:v=>v.stopPropagation()},e.createElement("div",{className:"rge-modal-header"},e.createElement("span",{className:"rge-modal-title"},e.createElement(be,{value:"settings"})," ",B),e.createElement("button",{className:"rge-modal-close",onClick:g},"✕")),e.createElement("div",{className:"rge-modal-body"},D.id&&e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},"ID"),e.createElement("input",{className:"rge-form-input",value:D.id,disabled:!0})),e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},y("editor.panel.name","名称")," ",e.createElement("span",{className:"rge-required"},"*")),e.createElement("input",{className:`rge-form-input ${x.name?"error":""}`,value:D.name,onChange:v=>j("name",v.target.value),placeholder:y("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"},y("editor.panel.description","描述")),e.createElement("textarea",{className:"rge-form-textarea",value:D.description||"",onChange:v=>j("description",v.target.value),placeholder:y("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"},y("editor.ruleChainSettings.root","根链")),e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:D.root||!1,onChange:v=>j("root",v.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"},y("editor.panel.debugMode","调试模式")),e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:D.debugMode||!1,onChange:v=>j("debugMode",v.target.checked),disabled:n}),e.createElement("span",{className:"rge-switch-slider"})))),s.map(v=>e.createElement("div",{className:"rge-form-group",key:v.key},e.createElement("label",{className:"rge-form-label"},v.label),v.type==="text"&&e.createElement("input",{className:"rge-form-input",value:String((D[v.key]??v.defaultValue)||""),onChange:A=>j(v.key,A.target.value),placeholder:v.placeholder,disabled:n}),v.type==="number"&&e.createElement("input",{className:"rge-form-input",type:"number",value:D[v.key]??v.defaultValue??"",onChange:A=>j(v.key,Number(A.target.value)),placeholder:v.placeholder,disabled:n}),v.type==="textarea"&&e.createElement("textarea",{className:"rge-form-textarea",value:String((D[v.key]??v.defaultValue)||""),onChange:A=>j(v.key,A.target.value),placeholder:v.placeholder,rows:3,disabled:n}),v.type==="select"&&e.createElement(rr,{value:String((D[v.key]??v.defaultValue)||""),options:v.options||[],onChange:A=>j(v.key,A),disabled:n,placeholder:v.placeholder,searchPlaceholder:y("editor.property.searchOptions","搜索选项..."),noMatchText:y("editor.property.noMatchingOptions","没有匹配的选项")}),v.type==="switch"&&e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:D[v.key]??v.defaultValue??!1,onChange:A=>j(v.key,A.target.checked),disabled:n}),e.createElement("span",{className:"rge-switch-slider"})),v.help&&e.createElement("span",{className:"rge-form-help"},v.help))),D.additionalInfo&&Object.keys(D.additionalInfo).length>0&&e.createElement("div",{className:"rge-form-group"},e.createElement("label",{className:"rge-form-label"},y("editor.ruleChainSettings.additionalInfo","额外配置 (JSON)")),e.createElement("textarea",{className:"rge-form-textarea mono",value:JSON.stringify(D.additionalInfo,null,2),onChange:v=>{try{j("additionalInfo",JSON.parse(v.target.value))}catch{}},rows:5,disabled:n}))),e.createElement("div",{className:"rge-modal-footer"},e.createElement("button",{className:"rge-btn secondary",onClick:g},y("editor.panel.cancel","取消")),!n&&e.createElement("button",{className:"rge-btn primary",onClick:q},e.createElement(be,{value:"save"})," ",y("editor.toolbar.save","保存"))))):null};ja.displayName="RuleChainSettings";const Mt=({name:t,className:r=""})=>{const n=h.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:g,messages:d,t:w})=>{var ce,p,Q,ie,U,te,ge,Se,xe;const[S,D]=e.useState(t),[f,x]=e.useState(""),[_,y]=e.useState(null),[B,j]=e.useState(""),[W,q]=e.useState(!1),v=e.useRef(null),A=e.useMemo(()=>tt({locale:g,messages:d,t:w}),[g,d,w]),$=r?JSON.stringify(r,null,2):"",k=e.useCallback(ve=>{j(""),x(ve);try{const ue=JSON.parse(ve);if(!ue.ruleChain&&!ue.metadata){j(A("editor.importExport.invalidRuleChainJson","JSON 格式不符合 RuleGo 规则链规范(缺少 ruleChain 或 metadata 字段)")),y(null);return}y(ue)}catch(ue){j(A("editor.importExport.jsonParseFailed","JSON 解析失败: {{message}}",{message:ue.message})),y(null)}},[A]),C=e.useCallback(ve=>{var Z;const ue=(Z=ve.target.files)==null?void 0:Z[0];if(!ue)return;if(!ue.name.endsWith(".json")){j(A("editor.importExport.selectJsonFile","请选择 .json 文件"));return}const F=new FileReader;F.onload=O=>{var Re;const se=(Re=O.target)==null?void 0:Re.result;k(se)},F.readAsText(ue)},[k]),oe=e.useCallback(ve=>{var Z;ve.preventDefault(),q(!1);const ue=(Z=ve.dataTransfer.files)==null?void 0:Z[0];if(!ue)return;if(!ue.name.endsWith(".json")){j(A("editor.importExport.selectJsonFile","请选择 .json 文件"));return}const F=new FileReader;F.onload=O=>{var Re;const se=(Re=O.target)==null?void 0:Re.result;k(se)},F.readAsText(ue)},[k]),K=e.useCallback(()=>{navigator.clipboard.writeText($).then(()=>{u==null||u("success",A("editor.importExport.copied","已复制到剪贴板"))}).catch(()=>{const ve=document.createElement("textarea");ve.value=$,document.body.appendChild(ve),ve.select(),document.execCommand("copy"),document.body.removeChild(ve),u==null||u("success",A("editor.importExport.copied","已复制到剪贴板"))})},[$,u,A]),X=e.useCallback(()=>{const ue=`${n.replace(/[^a-zA-Z0-9_\-\u4e00-\u9fa5]/g,"_")}_${new Date().toISOString().slice(0,10)}.json`,F=new Blob([$],{type:"application/json"}),Z=URL.createObjectURL(F),O=document.createElement("a");O.href=Z,O.download=ue,document.body.appendChild(O),O.click(),document.body.removeChild(O),URL.revokeObjectURL(Z),u==null||u("success",A("editor.importExport.downloaded","已下载: {{fileName}}",{fileName:ue}))},[$,n,u,A]),re=e.useCallback(()=>{if(!_){u==null||u("error",A("editor.importExport.noImportData","没有可导入的数据"));return}o==null||o(_),u==null||u("success",A("editor.importExport.importSuccess","规则链导入成功")),s()},[_,o,u,s,A]);return e.createElement("div",{className:"rge-modal-overlay",onClick:ve=>{ve.target===ve.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(Mt,{name:S==="export"?"export":"import"}),e.createElement("span",null,S==="export"?A("editor.importExport.exportTitle","导出规则链"):A("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 ${S==="export"?"active":""}`,onClick:()=>D("export")},e.createElement(Mt,{name:"export"}),e.createElement("span",null,A("editor.importExport.exportTab","导出"))),e.createElement("button",{type:"button",className:`rge-ie-tab ${S==="import"?"active":""}`,onClick:()=>D("import")},e.createElement(Mt,{name:"import"}),e.createElement("span",null,A("editor.importExport.importTab","导入")))),e.createElement("div",{className:"rge-modal-body"},S==="export"?e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-ie-info"},e.createElement("span",null,e.createElement(Mt,{name:"package"}),A("editor.importExport.nodes","节点"),": ",((p=(ce=r==null?void 0:r.metadata)==null?void 0:ce.nodes)==null?void 0:p.length)||0),e.createElement("span",null,e.createElement(Mt,{name:"link"}),A("editor.importExport.edges","连线"),": ",((ie=(Q=r==null?void 0:r.metadata)==null?void 0:Q.connections)==null?void 0:ie.length)||0),e.createElement("span",null,e.createElement(Mt,{name:"data"}),A("editor.importExport.size","大小"),": ",($.length/1024).toFixed(1)," KB")),e.createElement("pre",{className:"rge-ie-preview"},$)):e.createElement(e.Fragment,null,e.createElement("div",{className:`rge-ie-dropzone ${W?"dragover":""} ${f?"has-file":""}`,onDragOver:ve=>{ve.preventDefault(),q(!0)},onDragLeave:()=>q(!1),onDrop:oe,onClick:()=>{var ve;return(ve=v.current)==null?void 0:ve.click()}},e.createElement("input",{ref:v,type:"file",accept:".json",style:{display:"none"},onChange:C}),f?e.createElement("span",{className:"rge-ie-file-name"},e.createElement(Mt,{name:"validate"}),A("editor.importExport.fileLoaded","文件已加载,点击重新选择")):e.createElement(e.Fragment,null,e.createElement(Mt,{name:"import",className:"rge-ie-drop-icon"}),e.createElement("span",{className:"rge-ie-drop-text"},A("editor.importExport.dropHint","拖拽 JSON 文件到此处,或点击选择文件")))),B&&e.createElement("div",{className:"rge-ie-error",role:"alert"},B),_&&e.createElement("div",{className:"rge-ie-import-info"},e.createElement("div",{className:"rge-ie-info"},e.createElement("span",null,e.createElement(Mt,{name:"package"}),A("editor.importExport.nodes","节点"),": ",((te=(U=_==null?void 0:_.metadata)==null?void 0:U.nodes)==null?void 0:te.length)||0),e.createElement("span",null,e.createElement(Mt,{name:"link"}),A("editor.importExport.edges","连线"),": ",((Se=(ge=_==null?void 0:_.metadata)==null?void 0:ge.connections)==null?void 0:Se.length)||0),e.createElement("span",null,e.createElement(Mt,{name:"edit"}),A("editor.importExport.name","名称"),": ",((xe=_==null?void 0:_.ruleChain)==null?void 0:xe.name)||A("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},A("editor.panel.cancel","取消")),S==="export"?e.createElement(e.Fragment,null,e.createElement("button",{type:"button",className:"rge-btn secondary",onClick:K},e.createElement(Mt,{name:"copy"}),e.createElement("span",null,A("editor.panel.copy","复制"))),e.createElement("button",{type:"button",className:"rge-btn primary",onClick:X},e.createElement(Mt,{name:"export"}),e.createElement("span",null,A("editor.importExport.downloadFile","下载文件")))):e.createElement("button",{type:"button",className:"rge-btn primary",onClick:re,disabled:!_},e.createElement(Mt,{name:"import"}),e.createElement("span",null,A("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:g})=>{const[d,w]=e.useState(""),[S,D]=e.useState(0),f=e.useRef(null),x=e.useMemo(()=>tt({locale:s,messages:u,t:g}),[s,u,g]);e.useEffect(()=>{var W;(W=f.current)==null||W.focus()},[]);const _=e.useMemo(()=>{if(!d.trim())return[];const W=d.toLowerCase().trim();return t.filter(q=>q.name.toLowerCase().includes(W)||q.type.toLowerCase().includes(W)||q.id.toLowerCase().includes(W)||q.typeLabel&&q.typeLabel.toLowerCase().includes(W)||q.extra&&q.extra.toLowerCase().includes(W))},[t,d]),y=e.useCallback(W=>{switch(W.key){case"ArrowDown":W.preventDefault(),D(q=>Math.min(q+1,_.length-1));break;case"ArrowUp":W.preventDefault(),D(q=>Math.max(q-1,0));break;case"Enter":W.preventDefault(),_[S]&&(r==null||r(_[S].id));break;case"Escape":W.preventDefault(),n();break}},[_,S,r,n]),B=e.useCallback(W=>{w(W.target.value),D(0)},[]),j=e.useCallback(W=>{r==null||r(W)},[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:f,type:"text",className:"rge-search-input",placeholder:x("editor.searchPanel.placeholder","搜索节点名称、类型或 ID..."),value:d,onChange:B,onKeyDown:y}),d&&e.createElement("span",{className:"rge-search-count"},x("editor.searchPanel.resultCount","{{count}} 个结果",{count:_.length})),e.createElement("button",{className:"rge-search-close",onClick:n},"✕")),d&&_.length>0&&e.createElement("div",{className:"rge-search-results"},_.map((W,q)=>e.createElement("div",{key:W.id,className:`rge-search-result-item ${q===S?"active":""}`,onClick:()=>j(W.id),onMouseEnter:()=>D(q)},e.createElement("div",{className:"rge-search-result-main"},e.createElement("span",{className:"rge-search-result-name"},ga(W.name,d)),e.createElement("span",{className:"rge-search-result-type"},W.typeLabel||W.type)),e.createElement("div",{className:"rge-search-result-id"},"ID: ",ga(W.id,d))))),d&&_.length===0&&e.createElement("div",{className:"rge-search-empty"},e.createElement("span",{className:"rge-search-icon","aria-hidden":"true"}),x("editor.searchPanel.empty","没有找到匹配的节点")))},xs={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 Rs=1;const sn=t=>{const r=fa.get(t);if(r!==void 0)return r;const n=Rs++;return fa.set(t,n),n},Tr=(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=>Tr(o,r));const n=t;return Object.keys(n).sort().reduce((o,s)=>(o[s]=Tr(n[s],r),o),{})},In=t=>t===void 0?"[default]":JSON.stringify(t),Is=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())}`},Ps=(t,r)=>{var o;const n=(o=t.additionalInfo)==null?void 0:o[r];return typeof n=="string"?n:""},Ds=(t,r,n)=>{if(!t)return"";const o=r||{};return JSON.stringify({apiBase:t,apiContextKey:In(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:${sn(o.serverStatus)}]`:void 0,includeStoredToken:o.includeStoredToken,routes:Tr(o.routes)})},Ls=t=>{const{apiBase:r,apiOptions:n,apiContextKey:o,fetcher:s,pageSize:u=10,layout:g="grid",autoOpenAfterCreate:d,theme:w="default",className:S="",style:D,icons:f,showSearch:x=!0,showCreate:_=!0,showRefresh:y=!0,disabled:B=!1,disabledMessage:j,locale:W,messages:q,t:v,renderHeader:A,renderActions:$,renderEmpty:k,renderCreateForm:C,renderRow:oe,onDesign:K,onInfo:X,onViewLogs:re,onChange:ce,onError:p,onCreateSuccess:Q}=t,ie={...xs,...f},U=e.useMemo(()=>tt({locale:W,messages:q,t:v}),[W,q,v]),te=e.useRef(null),ge=e.useRef(""),Se=Ds(r,n,o),xe=s?`external:${sn(s)}`:"";s?(te.current!==s||ge.current!==xe)&&(te.current=s,ge.current=xe):r?(!te.current||ge.current!==Se)&&(te.current=new h.RuleChainAPI({apiBase:r,...n}),ge.current=Se):te.current&&(te.current=null,ge.current="");const ve=te.current,ue=s?`${xe}|context:${In(o)}`:r?`internal:${Se}`:`none:${In(o)}`,F=e.useRef({api:null,identity:"",disabled:!1,generation:0});(F.current.api!==ve||F.current.identity!==ue||F.current.disabled!==B)&&(F.current={api:ve,identity:ue,disabled:B,generation:F.current.generation+1});const Z=e.useRef(!1),O=e.useRef(0),se=e.useRef(0),[Re,ae]=e.useState([]),[Ee,Ie]=e.useState(0),[H,de]=e.useState(1),pe=u,[J,z]=e.useState(""),[fe,ke]=e.useState(!1),[je,dt]=e.useState(!1),[We,G]=e.useState(""),[qe,ct]=e.useState(null),[gt,Ot]=e.useState(null),[R,Pe]=e.useState(()=>h.RuleChainAPI.generateChainId()),[nt,Et]=e.useState(""),[at,wt]=e.useState(""),[xt,At]=e.useState(!0),[Tt,ze]=e.useState(!1),[Rt,Bt]=e.useState(!0),[$t,Ht]=e.useState(""),[Pt,Kt]=e.useState(()=>d??!!K),[Jt,_t]=e.useState(""),[Dt,vt]=e.useState(null),[Ft,le]=e.useState(null),Ce=Ft===F.current.generation,we=Ce?Re:[],Te=Ce?Ee:0,Oe=e.useRef({page:H,keywords:J,onError:p});Oe.current={page:H,keywords:J,onError:p};const Ge=e.useRef({onChange:ce,onError:p,onCreateSuccess:Q,onDesign:K});Ge.current={onChange:ce,onError:p,onCreateSuccess:Q,onDesign:K};const E=e.useCallback(V=>Z.current&&F.current===V,[]),_e=e.useCallback((V,ye)=>E(V)&&se.current===ye,[E]);e.useEffect(()=>(Z.current=!0,()=>{Z.current=!1,O.current+=1,se.current+=1}),[]),e.useEffect(()=>{se.current+=1,vt(null)},[ue,B]);const $e=e.useCallback(()=>{ct(null),Ot(null)},[]);e.useEffect(()=>{G(""),de(1),$e(),dt(!1),_t("")},[ue,B,$e]);const ft=e.useCallback((V,ye)=>{if(V.stopPropagation(),qe===ye){$e();return}const l=V.currentTarget.getBoundingClientRect(),m=window.innerWidth||document.documentElement.clientWidth||yn,T=window.innerHeight||document.documentElement.clientHeight||En,P=Math.max(Fr,m-yn-Fr),ne=Math.min(Math.max(Fr,l.right-yn),P);let Be=l.bottom+8;Be+En>T-Fr&&(Be=Math.max(Fr,l.top-En-8)),ct(ye),Ot({id:ye,top:Be,left:ne})},[$e,qe]);e.useEffect(()=>{if(!qe)return;const V=l=>{var T;const m=l.target;(T=m==null?void 0:m.closest)!=null&&T.call(m,".huanban_rulego_list__actions--floating, .huanban_rulego_list__row_more")||$e()},ye=l=>{l.key==="Escape"&&$e()};return document.addEventListener("pointerdown",V),document.addEventListener("keydown",ye),window.addEventListener("resize",$e),window.addEventListener("scroll",$e,!0),()=>{document.removeEventListener("pointerdown",V),document.removeEventListener("keydown",ye),window.removeEventListener("resize",$e),window.removeEventListener("scroll",$e,!0)}},[$e,qe]);const ht=e.useCallback(()=>{Pe(h.RuleChainAPI.generateChainId()),Et(""),wt(""),At(!0),ze(!1),Bt(!0),Ht(""),Kt(d??!!K),_t("")},[d,K]),me=e.useCallback(()=>{ht(),dt(!0)},[ht]),It=e.useCallback(()=>{dt(!1),_t("")},[]),it=e.useCallback(async(V,ye)=>{var Be,rt;const l=F.current,m=l.api,{page:T,keywords:P}=Oe.current;if(!m||l.disabled){E(l)&&ke(!1);return}const ne=++O.current;ke(!0);try{const Je=await m.list(V??T,pe,ye??P);if(!E(l)||O.current!==ne)return;ae(Je.items),Ie(Je.total),le(l.generation)}catch(Je){if(!E(l)||O.current!==ne)return;(rt=(Be=Oe.current).onError)==null||rt.call(Be,Je instanceof Error?Je:new Error(String(Je)))}finally{E(l)&&O.current===ne&&ke(!1)}},[E,pe]);e.useEffect(()=>{if(B){O.current+=1,ke(!1);return}it(1)},[ue,B,it]);const nr=e.useCallback(()=>{de(1),it(1,J),$e()},[$e,J,it]),Wt=e.useCallback(V=>{V.key==="Enter"&&nr()},[nr]),st=Math.max(1,Math.ceil(Te/pe)),Zt=e.useCallback(()=>{H>1&&(de(H-1),it(H-1))},[H,it]),ut=e.useCallback(()=>{H<st&&(de(H+1),it(H+1))},[H,st,it]),Lt=e.useCallback(async(V,ye)=>{var P,ne,Be,rt,Je,Qe;const l=F.current,m=l.api;if(!m||l.disabled)return;const T=++se.current;vt(V);try{const Ue=await m.operate(V,ye);if(!_e(l,T))return;if(!Ue.success){(ne=(P=Ge.current).onError)==null||ne.call(P,new Error(Ue.msg||U("editor.workflowList.operateFailed","操作失败")));return}if($e(),await it(),!_e(l,T))return;(rt=(Be=Ge.current).onChange)==null||rt.call(Be)}catch(Ue){_e(l,T)&&((Qe=(Je=Ge.current).onError)==null||Qe.call(Je,Ue instanceof Error?Ue:new Error(String(Ue))))}finally{_e(l,T)&&vt(null)}},[$e,_e,it,U]),dr=e.useCallback(async V=>{var T,P,ne,Be,rt,Je;const ye=F.current,l=ye.api;if(!l||ye.disabled)return;const m=++se.current;vt(V);try{const Qe=await l.copy(V);if(!_e(ye,m))return;if(!Qe.success){(P=(T=Ge.current).onError)==null||P.call(T,new Error(Qe.msg||U("editor.workflowList.copyFailed","复制失败")));return}if($e(),await it(),!_e(ye,m))return;(Be=(ne=Ge.current).onChange)==null||Be.call(ne)}catch(Qe){_e(ye,m)&&((Je=(rt=Ge.current).onError)==null||Je.call(rt,Qe instanceof Error?Qe:new Error(String(Qe))))}finally{_e(ye,m)&&vt(null)}},[$e,_e,it,U]),{confirm:pr}=Br(F.current.generation,U),sr=e.useCallback(async(V,ye)=>{var P,ne,Be,rt,Je,Qe;const l=F.current;try{if(!await pr(U("editor.workflowList.confirmDelete","确定删除工作流「{{name}}」吗?此操作不可恢复。",{name:ye}))||!E(l))return}catch{return}const m=l.api;if(!m||l.disabled)return;const T=++se.current;vt(V);try{const Ue=await m.remove(V);if(!_e(l,T))return;if(!Ue.success){(ne=(P=Ge.current).onError)==null||ne.call(P,new Error(Ue.msg||U("editor.workflowList.deleteFailed","删除失败")));return}if($e(),await it(),!_e(l,T))return;(rt=(Be=Ge.current).onChange)==null||rt.call(Be)}catch(Ue){_e(l,T)&&((Qe=(Je=Ge.current).onError)==null||Qe.call(Je,Ue instanceof Error?Ue:new Error(String(Ue))))}finally{_e(l,T)&&vt(null)}},[$e,_e,it,U]),yt=e.useCallback(async V=>{var Be,rt,Je,Qe,Ue,mt,Gt,Ke;const ye=F.current,l=ye.api;if(!l||ye.disabled)return;const m=++se.current,T=R.trim();if(!V){if(!T||Ts.test(T)){_t(U("editor.workflowList.idInvalid","ID 不能为空,且不能包含 /、\\ 或 ."));return}_t("")}const P=new Date().toISOString(),ne=V||{ruleChain:{id:T,name:nt.trim()||U("editor.workflowList.defaultName","新工作流"),root:xt,disabled:Rt,debugMode:Tt,additionalInfo:{description:at.trim(),category:$t.trim(),createTime:P,updateTime:P,debugMode:Tt}},metadata:{firstNodeIndex:0,nodes:[],connections:[],endpoints:[]}};try{const Ae=await l.create(ne);if(!_e(ye,m))return;if(!Ae.success){(rt=(Be=Ge.current).onError)==null||rt.call(Be,new Error(Ae.msg||U("editor.workflowList.createFailed","创建失败")));return}if(dt(!1),ht(),await it(),!_e(ye,m))return;(Qe=(Je=Ge.current).onChange)==null||Qe.call(Je);const Yt=ne.ruleChain,Vt=String((Yt==null?void 0:Yt.id)??"");Vt&&((mt=(Ue=Ge.current).onCreateSuccess)==null||mt.call(Ue,Vt)),Vt&&Pt&&Ge.current.onDesign&&Ge.current.onDesign(Vt)}catch(Ae){_e(ye,m)&&((Ke=(Gt=Ge.current).onError)==null||Ke.call(Gt,Ae instanceof Error?Ae:new Error(String(Ae))))}},[R,nt,at,xt,Rt,Tt,$t,it,Pt,ht,E,_e,U]),Ut=e.useCallback(V=>{G(V.id),$e(),X==null||X(V)},[$e,X]),Ye=e.useCallback((V,ye)=>{if(V.key==="Enter"){V.preventDefault(),K&&K(ye.id);return}V.key===" "&&(V.preventDefault(),Ut(ye))},[Ut,K]),ar=V=>{const ye=Dt===V.id;return e.createElement(e.Fragment,null,K&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--design",disabled:ye,onClick:l=>{l.stopPropagation(),$e(),K(V.id)},title:U("editor.workflowList.design","设计")},e.createElement(be,{value:ie.design})," ",e.createElement("span",null,U("editor.workflowList.design","设计"))),X&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--info",disabled:ye,onClick:l=>{l.stopPropagation(),Ut(V)},title:U("editor.workflowList.info","信息")},e.createElement(be,{value:ie.info})," ",e.createElement("span",null,U("editor.workflowList.info","信息"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--operate",disabled:ye,onClick:l=>{l.stopPropagation(),Lt(V.id,V.deployed?"stop":"start")},title:V.deployed?U("editor.workflowList.offlineAction","下线"):U("editor.workflowList.onlineAction","部署")},e.createElement(be,{value:V.deployed?ie.stop:ie.start}),e.createElement("span",null,V.deployed?U("editor.workflowList.offlineAction","下线"):U("editor.workflowList.onlineAction","部署"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--copy",disabled:ye,onClick:l=>{l.stopPropagation(),dr(V.id)},title:U("editor.panel.copy","复制")},e.createElement(be,{value:ie.copy})," ",e.createElement("span",null,U("editor.panel.copy","复制"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--delete",disabled:ye,onClick:l=>{l.stopPropagation(),sr(V.id,V.name)},title:U("editor.panel.delete","删除")},e.createElement(be,{value:ie.delete})," ",e.createElement("span",null,U("editor.panel.delete","删除"))),re&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--logs",disabled:ye,onClick:l=>{l.stopPropagation(),$e(),re(V.id,V)},title:U("editor.workflowList.logs","日志")},e.createElement(be,{value:ie.logs})," ",e.createElement("span",null,U("editor.workflowList.logs","日志"))))},Ve=(V,ye="huanban_rulego_list__actions")=>e.createElement("div",{className:ye},ar(V)),qt=(V,ye)=>{const l=Ve(V),m=$?$(V,l):l,T=We===V.id,P=V.deployed?U("editor.workflowList.online","运行"):U("editor.workflowList.offline","停用"),ne=Ps(V,"category");return e.createElement("article",{className:`huanban_rulego_list__row ${V.deployed?"huanban_rulego_list__row--deployed":"huanban_rulego_list__row--offline"} ${T?"huanban_rulego_list__row--selected":""}`,key:V.id,"data-id":V.id,role:"button",tabIndex:0,title:U("editor.workflowList.rowHint","单击查看信息,双击进入设计"),onClick:()=>Ut(V),onDoubleClick:()=>K==null?void 0:K(V.id),onKeyDown:Be=>Ye(Be,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?ie.workflow:ie.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),(ne||V.root)&&e.createElement("span",{className:"huanban_rulego_list__row_meta"},V.root?U("editor.workflowList.rootChain","主链"):U("editor.workflowList.subChain","子链"),ne?` · ${ne}`:"")),e.createElement("div",{className:`huanban_rulego_list__row_menu ${qe===V.id?"huanban_rulego_list__row_menu--open":""}`},e.createElement("button",{className:"huanban_rulego_list__row_more",type:"button",title:U("editor.workflowList.more","更多操作"),onClick:Be=>{ft(Be,V.id)}},"•••"),g==="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"},U("editor.workflowList.updateTime","更新时间"),": ",Is(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"}`},P)))},De=e.createElement("div",{className:"huanban_rulego_list__header"},e.createElement("h3",{className:"huanban_rulego_list__title"},e.createElement(be,{value:ie.workflow})," ",U("editor.workflowList.title","工作流列表"),e.createElement("span",{className:"huanban_rulego_list__count"},"(",Te,")")),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:U("editor.workflowList.searchPlaceholder","搜索工作流..."),value:J,onChange:V=>z(V.target.value),onKeyDown:Wt}),e.createElement("button",{className:"huanban_rulego_list__search_btn",onClick:nr,title:U("editor.toolbar.searchNode","搜索")},e.createElement(be,{value:ie.search}))),y&&e.createElement("button",{className:"huanban_rulego_list__toolbar_btn",onClick:()=>it(),title:U("editor.chainSelector.refresh","刷新"),disabled:fe||B},e.createElement(be,{value:ie.refresh})),_&&e.createElement("button",{className:"huanban_rulego_list__toolbar_btn huanban_rulego_list__toolbar_btn--primary",onClick:me,title:U("editor.workflowList.createTitle","新建工作流"),disabled:B},e.createElement(be,{value:ie.add})," ",U("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"},U("editor.workflowList.id","ID"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:R,onChange:V=>{Pe(V.target.value),_t("")},placeholder:U("editor.workflowList.idPlaceholder","规则链 ID,不可包含 /、\\ 或 ."),autoFocus:!0})),e.createElement("label",{className:"huanban_rulego_list__form_label"},U("editor.panel.name","名称"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:nt,onChange:V=>Et(V.target.value),placeholder:U("editor.workflowList.namePlaceholder","输入工作流名称")}))),e.createElement("div",{className:"huanban_rulego_list__form_group"},e.createElement("span",{className:"huanban_rulego_list__form_group_label"},U("editor.workflowList.chainType","规则链类型")),e.createElement("div",{className:"huanban_rulego_list__segmented",role:"group"},e.createElement("button",{type:"button",className:xt?"active":"",onClick:()=>At(!0)},U("editor.workflowList.rootChain","主链")),e.createElement("button",{type:"button",className:xt?"":"active",onClick:()=>At(!1)},U("editor.workflowList.subChain","子链")))),e.createElement("div",{className:"huanban_rulego_list__form_group"},e.createElement("span",{className:"huanban_rulego_list__form_group_label"},U("editor.workflowList.initialStatus","初始状态")),e.createElement("div",{className:"huanban_rulego_list__segmented",role:"group"},e.createElement("button",{type:"button",className:Rt?"active":"",onClick:()=>Bt(!0)},U("editor.workflowList.initialStopped","停用")),e.createElement("button",{type:"button",className:Rt?"":"active",onClick:()=>Bt(!1)},U("editor.workflowList.initialRunning","运行")))),e.createElement("label",{className:"huanban_rulego_list__form_switch",title:U("editor.workflowList.debugModeHint","开启后每条消息都会记录调试日志,并覆盖节点调试配置;会影响运行性能,生产环境建议关闭。编辑器手动调试不受影响。")},e.createElement("input",{type:"checkbox",checked:Tt,onChange:V=>ze(V.target.checked)}),e.createElement("span",null,U("editor.workflowList.debugMode","调试模式"))),e.createElement("label",{className:"huanban_rulego_list__form_label"},U("editor.workflowList.category","分类"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:$t,onChange:V=>Ht(V.target.value),placeholder:U("editor.workflowList.categoryPlaceholder","可选分类,如 IoT / AI / 数据同步")})),e.createElement("label",{className:"huanban_rulego_list__form_label"},U("editor.panel.description","描述"),e.createElement("textarea",{className:"huanban_rulego_list__form_textarea",value:at,onChange:V=>wt(V.target.value),placeholder:U("editor.workflowList.descriptionPlaceholder","可选描述"),rows:3})),K&&e.createElement("label",{className:"huanban_rulego_list__form_switch"},e.createElement("input",{type:"checkbox",checked:Pt,onChange:V=>Kt(V.target.checked)}),e.createElement("span",null,U("editor.workflowList.openAfterCreate","创建后进入编辑器"))),Jt&&e.createElement("div",{className:"huanban_rulego_list__form_error"},Jt)),fr=e.createElement("div",{className:"huanban_rulego_list__empty"},e.createElement("span",{className:"huanban_rulego_list__empty_icon"},e.createElement(be,{value:ie.workflow})),e.createElement("p",null,U("editor.workflowList.empty","暂无工作流")),_&&e.createElement("button",{className:"huanban_rulego_list__empty_btn",onClick:me},e.createElement(be,{value:ie.add})," ",U("editor.workflowList.createFirst","创建第一个工作流"))),ot=h.normalizeEditorTheme(w),zt=ot!=="default"?`huanban_rulego_list--${ot}`:"",bt=h.getThemeRuntimeVariables(ot),Xe=qe?we.find(V=>V.id===qe):void 0,Fe=g==="grid"&&gt&&Xe&&typeof document<"u"?en.createPortal($?e.createElement("div",{className:"huanban_rulego_list__actions huanban_rulego_list__actions--floating",style:{...bt,top:gt.top,left:gt.left},onClick:V=>V.stopPropagation(),onPointerDown:V=>V.stopPropagation()},$(Xe,Ve(Xe))):e.createElement("div",{className:"huanban_rulego_list__actions huanban_rulego_list__actions--floating",style:{...bt,top:gt.top,left:gt.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-${g} ${zt} ${S}`.trim(),"data-theme":ot,"data-rg-theme":ot,style:{...bt,...D}},A?A(De):De,e.createElement("div",{className:"huanban_rulego_list__body"},B&&e.createElement("div",{className:"huanban_rulego_list__empty"},e.createElement("span",{className:"huanban_rulego_list__empty_icon"},e.createElement(be,{value:ie.workflow})),e.createElement("p",null,j||U("editor.workflowList.loginRequired","请先登录后查看工作流。"))),!B&&fe&&e.createElement("div",{className:"huanban_rulego_list__loading"},e.createElement("span",{className:"huanban_rulego_list__spinner"}),U("editor.panel.loading","加载中...")),!B&&!fe&&we.length===0&&(k?k():fr),!B&&!fe&&we.length>0&&e.createElement("div",{className:`huanban_rulego_list__rows huanban_rulego_list__rows--${g}`},we.map((V,ye)=>{const l=qt(V);return oe?e.createElement(e.Fragment,{key:V.id},oe(V,ye,l)):e.createElement(e.Fragment,{key:V.id},l)}))),Fe,!B&&Te>pe&&e.createElement("div",{className:"huanban_rulego_list__pagination"},e.createElement("button",{className:"huanban_rulego_list__page_btn",disabled:H<=1,onClick:Zt},U("editor.chainSelector.prevPage","上一页")),e.createElement("span",{className:"huanban_rulego_list__page_info"},H," / ",st),e.createElement("button",{className:"huanban_rulego_list__page_btn",disabled:H>=st,onClick:ut},U("editor.chainSelector.nextPage","下一页"))),je&&e.createElement("div",{className:"huanban_rulego_list__modal_mask",onClick:It},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,U("editor.workflowList.createTitle","新建工作流")),e.createElement("button",{className:"huanban_rulego_list__modal_close",onClick:It},"✕")),e.createElement("div",{className:"huanban_rulego_list__modal_body"},C?C(gr,{close:It,submit:V=>yt(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:It},U("editor.panel.cancel","取消")),e.createElement("button",{className:"huanban_rulego_list__btn huanban_rulego_list__btn--primary",onClick:()=>yt()},Pt&&K?U("editor.workflowList.createAndOpen","创建并打开"):U("editor.workflowList.create","创建"))))))},Ms=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:g="暂无规则链",className:d="",style:w,onKeywordChange:S,onOpen:D,virtualization:f}){const x=e.useMemo(()=>r?null:new h.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,[y,B]=e.useState(()=>_.getState()),[j,W]=e.useState(s||""),[q,v]=e.useState(0),A=e.useRef(null);e.useEffect(()=>_.subscribe(B),[_]),e.useEffect(()=>()=>{x==null||x.destroy()},[x]),e.useEffect(()=>{_.setWorkflows(t)},[_,t]),e.useEffect(()=>{_.setActiveChainId(o)},[_,o]),e.useEffect(()=>{s===void 0||s===j||(W(s),_.setKeyword(s))},[s,j,_]);const $=e.useMemo(()=>Ba(y.tree,new Set(y.expandedKeys)),[y.tree,y.expandedKeys]),k=e.useMemo(()=>({enabled:(f==null?void 0:f.enabled)!==!1,threshold:Math.max(1,(f==null?void 0:f.threshold)??h.DEFAULT_VIRTUAL_WINDOW_THRESHOLD),itemHeight:Math.max(1,(f==null?void 0:f.itemHeight)??Ms),viewportHeight:Math.max(1,(f==null?void 0:f.viewportHeight)??h.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),overscan:Math.max(0,(f==null?void 0:f.overscan)??h.DEFAULT_VIRTUAL_WINDOW_OVERSCAN)}),[f==null?void 0:f.enabled,f==null?void 0:f.threshold,f==null?void 0:f.itemHeight,f==null?void 0:f.viewportHeight,f==null?void 0:f.overscan]),C=k.enabled&&$.length>k.threshold,oe=e.useMemo(()=>h.calculateVirtualWindow({total:$.length,itemHeight:k.itemHeight,viewportHeight:k.viewportHeight,scrollTop:q,overscan:k.overscan}),[$.length,k,q]),K=C?$.slice(oe.start,oe.end):$,X=e.useMemo(()=>$.findIndex(p=>{var Q;return p.node.kind==="chain"&&((Q=p.node.chain)==null?void 0:Q.id)===o}),[$,o]);e.useEffect(()=>{if(!C||X<0)return;const p=Math.floor(q/k.itemHeight),Q=Math.ceil((q+k.viewportHeight)/k.itemHeight);let ie=q;X<p?ie=X*k.itemHeight:X>=Q&&(ie=(X+1)*k.itemHeight-k.viewportHeight),ie!==q&&v(ie)},[o,X,C,$,k.itemHeight,k.viewportHeight]),e.useEffect(()=>{const p=A.current;if(!p)return;const Q=C?oe.scrollTop:0;p.scrollTop!==Q&&(p.scrollTop=Q)},[C,oe.scrollTop]);const re=p=>{W(p),_.setKeyword(p),S==null||S(p)},ce=({node:p,depth:Q},ie)=>{var Se,xe;const U=!!((Se=p.children)!=null&&Se.length),te=y.expandedKeys.includes(p.key),ge=p.kind==="chain"&&((xe=p.chain)==null?void 0:xe.id)===o;return e.createElement("button",{key:p.key,type:"button",role:"treeitem","aria-level":Q+1,"aria-posinset":ie+1,"aria-setsize":$.length,"aria-expanded":U?te:void 0,"aria-selected":p.kind==="chain"?ge:void 0,className:`huanban_workflow_explorer__row is-${p.kind}${ge?" is-active":""}`,style:{paddingInlineStart:8+Q*14},onClick:()=>{U?_.setExpanded(p.key,!te):p.chain&&(D==null||D(p.chain))},title:p.chain?`${p.chain.name}
8
+ ${p.chain.id}`:p.label},e.createElement("span",{className:`huanban_workflow_explorer__chevron${U&&te?" is-open":""}`,"aria-hidden":"true"}),e.createElement("span",{className:`huanban_workflow_explorer__kind is-${p.kind}`,"aria-hidden":"true"}),e.createElement("span",{className:"huanban_workflow_explorer__label"},p.label),p.kind==="chain"&&p.chain?e.createElement("span",{className:`huanban_workflow_explorer__status${p.chain.disabled?" is-offline":" is-online"}`,title:p.chain.disabled?"已下线":"运行中"}):null,p.count!==void 0?e.createElement("span",{className:"huanban_workflow_explorer__count"},p.count):null)};return e.createElement("section",{className:`huanban_workflow_explorer ${d}`.trim(),style:w,"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:p=>re(p.target.value),placeholder:u,"aria-label":u}),j?e.createElement("button",{type:"button",className:"huanban_workflow_explorer__clear",onClick:()=>re(""),title:"清除搜索","aria-label":"清除搜索"},"×"):null),e.createElement("div",{ref:A,className:`huanban_workflow_explorer__tree${C?" is-virtualized":""}`,role:"tree","data-explorer-virtualized":C?"true":void 0,"data-explorer-virtual-total":C?$.length:void 0,style:C?{height:`${oe.viewportHeight}px`}:void 0,onScroll:p=>{if(!C)return;const Q=p.currentTarget.scrollTop;v(ie=>ie===Q?ie:Q)}},$.length===0?e.createElement("div",{className:"huanban_workflow_explorer__empty"},g):C?e.createElement("div",{className:"huanban_workflow_explorer__virtual-canvas",style:{height:`${oe.totalHeight}px`}},e.createElement("div",{className:"huanban_workflow_explorer__virtual-items",style:{transform:`translateY(${oe.offsetTop}px)`}},K.map((p,Q)=>ce(p,oe.start+Q)))):$.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:g})=>{const[d,w]=e.useState(null),[S,D]=e.useState(null),[f,x]=e.useState(null),[_,y]=e.useState(null),[B,j]=e.useState(null),[W,q]=e.useState(null),v=e.useMemo(()=>n||{ruleChain:{id:t.id,name:t.name}},[n,t.id,t.name]),A=!!(r!=null&&r.validateUpstream&&(r!=null&&r.getSchemaDiff)&&(r!=null&&r.getRepairPlan)&&(r!=null&&r.previewPatch)),$=e.useMemo(()=>tt({locale:s,messages:u,t:g}),[s,u,g]),k=e.useMemo(()=>({validate:$("editor.maintenance.runValidate","运行校验"),schemaDiff:$("editor.maintenance.schemaDiff","结构差异"),repairPlan:$("editor.maintenance.repairPlan","修复建议"),patchPreview:$("editor.maintenance.patchPreview","补丁预览")}),[$]),C=e.useCallback(async oe=>{if(!r||!A){D({type:"error",text:$("editor.maintenance.noApi","当前请求适配器未提供维护接口")});return}w(oe),D({type:"info",text:`${k[oe]}...`});try{switch(oe){case"validate":x(await r.validateUpstream(t.id,v));break;case"schemaDiff":y(await r.getSchemaDiff(t.id));break;case"repairPlan":j(await r.getRepairPlan(t.id,v));break;case"patchPreview":{const K=[];q(await r.previewPatch(t.id,v,K));break}}D({type:"success",text:`${k[oe]}${$("editor.maintenance.finished","已完成")}`})}catch(K){const X=K instanceof Error?K:new Error(String(K));D({type:"error",text:`${k[oe]}${$("editor.maintenance.failed","失败")}: ${X.message}`}),o==null||o(X)}finally{w(null)}},[k,v,r,A,o,$,t.id]);return A?e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},$("editor.maintenance.title","维护验证")),e.createElement("div",{className:"huanban_rulego_info__maintenance_actions"},e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:d!==null,onClick:()=>C("validate")},d==="validate"?$("editor.maintenance.validating","校验中..."):$("editor.maintenance.runValidate","运行校验")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:d!==null,onClick:()=>C("schemaDiff")},$("editor.maintenance.schemaDiff","结构差异")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:d!==null,onClick:()=>C("repairPlan")},$("editor.maintenance.repairPlan","修复建议")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:d!==null,onClick:()=>C("patchPreview")},$("editor.maintenance.patchPreview","补丁预览"))),S&&e.createElement("div",{className:`huanban_rulego_info__maintenance_status huanban_rulego_info__maintenance_status--${S.type}`},S.text),f&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,$("editor.maintenance.validateResult","校验结果"),":",f.valid?$("editor.maintenance.valid","通过"):$("editor.maintenance.invalid","未通过")),Yr(f.issues,$)),_&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,$("editor.maintenance.schemaDiff","结构差异")),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(_.changes||[],null,2)),Yr(_.issues,$)),B&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,$("editor.maintenance.repairPlan","修复建议")),B.summary&&e.createElement("p",null,B.summary),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(B.plan||[],null,2)),Yr(B.issues,$)),W&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,$("editor.maintenance.patchPreview","补丁预览")),Yr(W.rejected,$),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(W.preview||{},null,2)))):e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},$("editor.maintenance.title","维护验证")),e.createElement("div",{className:"huanban_rulego_info__maintenance_empty"},$("editor.maintenance.noApi","当前请求适配器未提供维护接口")))},As={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 $s(t){return Wa(t).replace(/^https:/i,"wss:").replace(/^http:/i,"ws:")}const ba=new WeakMap;let Fs=1;const Pn=t=>{const r=ba.get(t);if(r!==void 0)return r;const n=Fs++;return ba.set(t,n),n},Rr=(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=>Rr(o,r));const n=t;return Object.keys(n).sort().reduce((o,s)=>(o[s]=Rr(n[s],r),o),{})},js=t=>t===void 0?"[default]":JSON.stringify(t),Bs=(t,r,n)=>{if(!t)return"";const o=r||{};return JSON.stringify({apiBase:t,apiContextKey:js(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:${Pn(o.serverStatus)}]`:void 0,includeStoredToken:o.includeStoredToken,routes:Rr(o.routes)})};function Hs(t,r){const n=Wa(t),o=$s(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 Ws(t){return t.length>0?Math.max(...t.map(r=>Number(r.order||0))):0}function Us(t,r,n,o){return h.updateSchemaRowsAtParent(t,r,s=>{const u=n+o;if(u<0||u>=s.length)return;const[g]=s.splice(n,1);if(!g)return;s.splice(u,0,g);const d=h.renumberSchemaRowOrders(s);s.splice(0,s.length,...d)})}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),g={...Zr(t.additionalInfo),...s,category:n.category,description:n.description,debugMode:n.debugMode,updateTime:new Date().toISOString()};return"inputSchema"in n&&(g.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:g}}const ya=({translate:t,entries:r,onChange:n,icons:o,keyPlaceholder:s="Key",valuePlaceholder:u="Value",valueType:g="text",actionLabel:d="操作",deleteTitle:w="删除",addLabel:S="添加",batchDeleteLabel:D="批量删除",batchDeleteConfirm:f="确定删除选中的 {{count}} 项吗?",deleteConfirm:x="确定删除“{{key}}”吗?",selectLabel:_="选择",selectedCountLabel:y="已选择 {{count}} 项",selectRowLabel:B="选择第 {{index}} 项"})=>{const[j,W]=e.useState([]),q=e.useRef(null),{confirm:v}=Br([r,j],t),A=r.length>0&&j.length===r.length,$=j.length>0&&!A;e.useEffect(()=>{W(ce=>h.normalizeKeyValueSelection(ce,r.length))},[r.length]),e.useEffect(()=>{q.current&&(q.current.indeterminate=$)},[$]);const k=()=>n([...r,{key:"",value:""}]),C=async ce=>{var Q;const p=x.replace("{{key}}",((Q=r[ce])==null?void 0:Q.key)||s);await v(p)&&(n(h.removeKeyValueEntriesAtIndexes(r,[ce])),W(ie=>ie.filter(U=>U!==ce).map(U=>U>ce?U-1:U)))},oe=ce=>{W(p=>p.includes(ce)?p.filter(Q=>Q!==ce):h.normalizeKeyValueSelection([...p,ce],r.length))},K=()=>{W(A?[]:r.map((ce,p)=>p))},X=async()=>{if(!j.length)return;const ce=f.replace("{{count}}",String(j.length));await v(ce)&&(n(h.removeKeyValueEntriesAtIndexes(r,j)),W([]))},re=(ce,p,Q)=>{const ie=[...r];ie[ce]={...ie[ce],[p]:Q},n(ie)};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:A,disabled:!r.length,onChange:K,"aria-label":_}),e.createElement("span",null,j.length?y.replace("{{count}}",String(j.length)):_)),e.createElement("button",{className:"huanban_rulego_info__kv_batch_del",type:"button",disabled:!j.length,onClick:X},e.createElement(be,{value:o.delete})," ",D,j.length?` (${j.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"},d)),r.map((ce,p)=>e.createElement("div",{className:"huanban_rulego_info__kv_row",key:p},e.createElement("input",{className:"huanban_rulego_info__kv_checkbox",type:"checkbox",checked:j.includes(p),onChange:()=>oe(p),"aria-label":B.replace("{{index}}",String(p+1))}),e.createElement("input",{className:"huanban_rulego_info__kv_input",type:"text",placeholder:s,value:ce.key,onChange:Q=>re(p,"key",Q.target.value)}),e.createElement("input",{className:"huanban_rulego_info__kv_input",type:g,placeholder:u,value:ce.value,onChange:Q=>re(p,"value",Q.target.value)}),e.createElement("button",{className:"huanban_rulego_info__kv_del",onClick:()=>C(p),title:w},e.createElement(be,{value:o.delete})))),e.createElement("button",{className:"huanban_rulego_info__kv_add",onClick:k},e.createElement(be,{value:o.add})," ",S))},qs=t=>{var Ft;const{apiBase:r,apiOptions:n,apiContextKey:o,fetcher:s,workflow:u,theme:g="default",className:d="",style:w,icons:S,defaultTab:D="base",showMaintenance:f=!1,renderBaseInfo:x,renderVarsSecrets:_,renderIntegration:y,renderExtraTabs:B,onSave:j,onError:W,onRefresh:q,locale:v,messages:A,t:$}=t,k={...As,...S},C=e.useMemo(()=>tt({locale:v,messages:A,t:$}),[v,A,$]),oe=e.useRef(null),K=e.useRef(""),X=Bs(r,n,o);s?oe.current!==s&&(oe.current=s,K.current="external"):r?(!oe.current||K.current!==X)&&(oe.current=new h.RuleChainAPI({apiBase:r,...n}),K.current=X):oe.current&&(oe.current=null,K.current="");const re=oe.current,[ce,p]=e.useState(D),[Q,ie]=e.useState(""),[U,te]=e.useState(!1),[ge,Se]=e.useState(!1),[xe,ve]=e.useState(""),[ue,F]=e.useState(""),[Z,O]=e.useState("visual"),[se,Re]=e.useState([]),[ae,Ee]=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
+ }`),[Ie,H]=e.useState(""),[de,pe]=e.useState([]),[J,z]=e.useState([]),[fe,ke]=e.useState(!1),[je,dt]=e.useState(null),We=e.useRef(0);e.useEffect(()=>{var Ce;const le=++We.current;if(!u||!re){ie(""),te(!1),Se(!1),ve(""),F(""),O("visual"),Re([]),Ee(`{
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
+ }`),H(""),pe([]),z([]),dt(null);return}ie(u.name),te(!!u.root),Se(!!u.debugMode),ve(String(((Ce=u.additionalInfo)==null?void 0:Ce.category)??"")),F(u.description),re.getContent(u.id).then(we=>{var $e;if(le!==We.current)return;dt(we);const Te=(we==null?void 0:we.ruleChain)??we,Oe=(Te==null?void 0:Te.additionalInfo)??{};te(!!((Te==null?void 0:Te.root)??u.root)),Se(!!((Te==null?void 0:Te.debugMode)??(Oe==null?void 0:Oe.debugMode)??u.debugMode)),ve(String((Oe==null?void 0:Oe.category)??(($e=u.additionalInfo)==null?void 0:$e.category)??"")),F(String((Oe==null?void 0:Oe.description)??u.description??""));try{const ft=Oe==null?void 0:Oe.inputSchema,ht=Ua(ft);Re(h.parseToolSchemaRows(ht)),Ee(JSON.stringify(ht,null,2)),H("")}catch{Re([]),Ee(`{
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
+ }`),H(C("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}const Ge=Zr(Te==null?void 0:Te.configuration),E=Ge.vars??(Oe==null?void 0:Oe.vars)??(Te==null?void 0:Te.vars)??{};pe(Object.entries(E).map(([ft,ht])=>({key:ft,value:String(ht)})));const _e=Ge.secrets??(Oe==null?void 0:Oe.secrets)??(Te==null?void 0:Te.secrets)??{};z(Object.entries(_e).map(([ft,ht])=>({key:ft,value:String(ht)})))}).catch(we=>{le===We.current&&(W==null||W(we instanceof Error?we:new Error(String(we))))})},[u,re,W,C]);const G=e.useCallback(async()=>{if(!(!re||!u)){ke(!0);try{const le=await re.saveBaseInfo(u.id,ha(u,je,{name:Q.trim(),root:U,debugMode:ge,category:xe.trim(),description:ue.trim()}));if(!le.success)throw new Error(le.msg||C("editor.workflowInfo.saveFailed","保存失败"));j==null||j("base"),q==null||q()}catch(le){W==null||W(le instanceof Error?le:new Error(String(le)))}finally{ke(!1)}}},[re,u,je,Q,U,ge,xe,ue,j,W,q,C]),qe=e.useCallback(le=>{if(Z!==le){if(le==="code"){Ee(JSON.stringify(h.generateToolSchemaFromRows(se),null,2)),H(""),O("code");return}try{const Ce=h.parseToolSchemaRows(h.parseJsonObjectText(ae||"{}",{type:"object",properties:{}}));Re(Ce),H(""),O("visual")}catch(Ce){H(Ce instanceof Error?Ce.message:C("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}}},[ae,Z,se,C]),ct=e.useCallback(le=>{Re(le),Ee(JSON.stringify(h.generateToolSchemaFromRows(le),null,2)),H("")},[]),gt=e.useCallback((le,Ce,we)=>{const Te=h.updateSchemaRowsAtParent(se,le,Oe=>{Oe[Ce]&&(Oe[Ce]={...Oe[Ce],...we,properties:we.type&&we.type!=="object"?[]:Oe[Ce].properties,itemsProperties:we.type&&we.type!=="array"?[]:Oe[Ce].itemsProperties})});ct(Te)},[se,ct]),Ot=e.useCallback((le="")=>{const Ce=h.updateSchemaRowsAtParent(se,le,we=>{we.push(h.emptySchemaEditorRow(Ws(we)+1))});ct(Ce)},[se,ct]),R=e.useCallback((le,Ce)=>{const we=h.updateSchemaRowsAtParent(se,le,Te=>{Te.splice(Ce,1);const Oe=h.renumberSchemaRowOrders(Te);Te.splice(0,Te.length,...Oe)});ct(we)},[se,ct]),Pe=e.useCallback((le,Ce,we)=>{ct(Us(se,le,Ce,we))},[se,ct]),nt=e.useCallback(async()=>{if(!re||!u)return;let le;try{le=Z==="visual"?h.generateToolSchemaFromRows(se):h.parseJsonObjectText(ae||"{}",{type:"object",properties:{}}),Ee(JSON.stringify(le,null,2)),Z==="code"&&Re(h.parseToolSchemaRows(le)),H("")}catch(Ce){H(Ce instanceof Error?Ce.message:C("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"));return}ke(!0);try{const Ce=await re.saveBaseInfo(u.id,ha(u,je,{name:Q.trim()||u.name,root:U,debugMode:ge,category:xe.trim(),description:ue.trim(),inputSchema:le}));if(!Ce.success)throw new Error(Ce.msg||C("editor.workflowInfo.saveFailed","保存失败"));j==null||j("inputSchema"),q==null||q()}catch(Ce){W==null||W(Ce instanceof Error?Ce:new Error(String(Ce)))}finally{ke(!1)}},[re,u,je,Z,se,ae,Q,U,ge,xe,ue,j,W,q,C]),Et=e.useCallback(async le=>{if(!(!re||!u)){ke(!0);try{const Ce=le==="vars"?de:J,we={};Ce.forEach(Oe=>{Oe.key.trim()&&(we[Oe.key.trim()]=Oe.value)});const Te=await re.saveConfig(u.id,le,we);if(!Te.success)throw new Error(Te.msg||C("editor.workflowInfo.saveFailed","保存失败"));j==null||j(le),q==null||q()}catch(Ce){W==null||W(Ce instanceof Error?Ce:new Error(String(Ce)))}finally{ke(!1)}}},[re,u,de,J,j,W,q,C]),at=e.useCallback(le=>{navigator.clipboard.writeText(le).catch(()=>{const Ce=document.createElement("textarea");Ce.value=le,document.body.appendChild(Ce),Ce.select(),document.execCommand("copy"),document.body.removeChild(Ce)})},[]),wt=h.normalizeEditorTheme(g),xt=wt!=="default"?`huanban_rulego_info--${wt}`:"",At=h.getThemeRuntimeVariables(wt);if(!u)return e.createElement("div",{className:`huanban_rulego_info huanban_rulego_info--empty ${xt} ${d}`.trim(),"data-theme":wt,"data-rg-theme":wt,style:{...At,...w}},e.createElement("p",{className:"huanban_rulego_info__no_data"},C("editor.workflowInfo.noData","请选择一个工作流查看详情")));const Tt=r||((Ft=re==null?void 0:re.getApiBase)==null?void 0:Ft.call(re))||"",ze=Hs(Tt,u.id),Rt=[{key:"base",label:C("editor.workflowInfo.baseInfo","基础信息"),icon:"docs"},{key:"inputSchema",label:C("editor.workflowInfo.inputDefinition","输入定义"),icon:"data"},{key:"vars",label:C("editor.workflowInfo.vars","变量"),icon:k.variable},{key:"integration",label:C("editor.workflowInfo.integration","应用集成"),icon:k.api},...f?[{key:"maintenance",label:C("editor.workflowInfo.maintenance","维护验证"),icon:"validate"}]:[]],Bt=B?B(u):[],$t=[...Rt,...Bt.map(le=>({key:le.key,label:le.label,icon:void 0}))],Ht=$t.some(le=>le.key===ce)?ce:"base",Pt=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("label",{className:"huanban_rulego_info__label"},C("editor.panel.name","名称"),e.createElement("input",{className:"huanban_rulego_info__input",type:"text",value:Q,onChange:le=>ie(le.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:U,disabled:!0}),e.createElement("span",{className:"huanban_rulego_info__switch_text"},C("editor.workflowInfo.rootChain","根规则链"),e.createElement("small",null,C("editor.workflowInfo.rootChainHint","开启:主链;关闭:子链")))),e.createElement("label",{className:"huanban_rulego_info__switch_row"},e.createElement("input",{type:"checkbox",checked:ge,onChange:le=>Se(le.target.checked)}),e.createElement("span",{className:"huanban_rulego_info__switch_text"},C("editor.workflowInfo.debugMode","调试模式"),e.createElement("small",null,C("editor.workflowInfo.debugModeHint","开启后每条消息都会记录调试日志,并覆盖节点调试配置;会影响运行性能,生产环境建议关闭。编辑器手动调试不受影响。"))))),e.createElement("label",{className:"huanban_rulego_info__label"},C("editor.workflowInfo.category","分类"),e.createElement("input",{className:"huanban_rulego_info__input",type:"text",placeholder:C("editor.workflowInfo.categoryPlaceholder","如 agent, iot, data-flow"),value:xe,onChange:le=>ve(le.target.value)})),e.createElement("label",{className:"huanban_rulego_info__label"},C("editor.panel.description","描述"),e.createElement("textarea",{className:"huanban_rulego_info__textarea",rows:3,value:ue,onChange:le=>F(le.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?C("editor.workflowInfo.online","运行"):C("editor.workflowInfo.offline","停用"))),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:fe,onClick:G},e.createElement(be,{value:k.save})," ",fe?C("editor.workflowInfo.saving","保存中..."):C("editor.workflowInfo.saveBaseInfo","保存基础信息"))),Kt=(le,Ce="")=>e.createElement("div",{className:"rge-tool-schema-rows"},le.length===0?e.createElement("div",{className:"rge-tool-schema-empty"},C("editor.property.noSchemaProperties","暂无属性,点击下方按钮添加")):le.map((we,Te)=>{const Oe=Ce?`${Ce}.${Te}`:String(Te),Ge=we.type==="array"?`${Oe}.items`:Oe,E=we.type==="array"?we.itemsProperties:we.properties;return e.createElement("div",{key:Oe,className:"rge-tool-schema-row-wrap"},e.createElement("div",{className:"rge-tool-schema-row"},e.createElement("input",{className:"rge-form-input",value:we.name,placeholder:C("editor.property.propertyName","属性名"),onChange:_e=>gt(Ce,Te,{name:_e.target.value})}),e.createElement("input",{className:"rge-form-input",value:we.title,placeholder:C("editor.property.title","标题"),onChange:_e=>gt(Ce,Te,{title:_e.target.value})}),e.createElement("input",{className:"rge-form-input",value:we.description,placeholder:C("editor.property.description","描述"),onChange:_e=>gt(Ce,Te,{description:_e.target.value})}),e.createElement("select",{className:"rge-form-select",value:we.type,onChange:_e=>gt(Ce,Te,{type:_e.target.value})},h.TOOL_SCHEMA_TYPES.map(_e=>e.createElement("option",{key:_e,value:_e},_e))),e.createElement("input",{className:"rge-form-input",type:"number",min:0,value:we.order,onChange:_e=>gt(Ce,Te,{order:Number(_e.target.value||Te+1)})}),e.createElement("label",{className:"rge-inline-checkbox rge-tool-schema-required"},e.createElement("input",{type:"checkbox",checked:we.required,onChange:_e=>gt(Ce,Te,{required:_e.target.checked})}),e.createElement("span",null,C("editor.property.required","必填"))),e.createElement("div",{className:"rge-tool-schema-actions"},e.createElement("button",{type:"button",title:C("editor.property.moveUp","上移"),onClick:()=>Pe(Ce,Te,-1)},"↑"),e.createElement("button",{type:"button",title:C("editor.property.moveDown","下移"),onClick:()=>Pe(Ce,Te,1)},"↓"),e.createElement("button",{type:"button",className:"danger",title:C("editor.workflowInfo.delete","删除"),onClick:()=>R(Ce,Te)},"×"))),we.type==="array"&&e.createElement("div",{className:"rge-tool-schema-nested-head"},e.createElement("span",null,C("editor.property.itemType","项目类型")),e.createElement("select",{className:"rge-form-select",value:we.itemsType||"string",onChange:_e=>gt(Ce,Te,{itemsType:_e.target.value})},h.TOOL_SCHEMA_ITEM_TYPES.map(_e=>e.createElement("option",{key:_e,value:_e},_e)))),(we.type==="object"||we.type==="array")&&e.createElement("div",{className:"rge-tool-schema-nested"},e.createElement("div",{className:"rge-tool-schema-nested-title"},we.type==="array"?C("editor.property.arrayItems","数组项目"):C("editor.property.childProperties","子属性"),we.name?`: ${we.name}`:""),we.type==="array"&&(we.itemsType||"string")!=="object"?e.createElement("div",{className:"rge-tool-schema-empty rge-tool-schema-nested-empty"},C("editor.property.arrayNonObject","当前数组项目不是 object,无需配置项目属性。")):e.createElement(e.Fragment,null,Kt(E||[],Ge),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Ot(Ge)},we.type==="array"?C("editor.property.addItemProperty","添加项目属性"):C("editor.property.addChildProperty","添加子属性")))))})),Jt=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${Z==="visual"?" active":""}`,onClick:()=>qe("visual")},C("editor.workflowInfo.visualMode","可视化")),e.createElement("button",{type:"button",className:`rge-segmented-option${Z==="code"?" active":""}`,onClick:()=>qe("code")},C("editor.workflowInfo.codeMode","JSON代码"))),Z==="visual"?e.createElement("div",{className:"rge-tool-schema-editor"},Kt(se),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Ot("")},C("editor.workflowInfo.addProperty","添加属性")),e.createElement("div",{className:"huanban_rulego_info__hint"},C("editor.workflowInfo.inputSchemaJsonHint","复杂嵌套 object/array 可切换到 JSON 代码模式编辑,已有嵌套结构会被保留。"))):e.createElement("label",{className:"huanban_rulego_info__label"},C("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:ae,onChange:le=>{Ee(le.target.value),H("")}})),Ie&&e.createElement("div",{className:"huanban_rulego_info__maintenance_status huanban_rulego_info__maintenance_status--error"},Ie),e.createElement("div",{className:"huanban_rulego_info__inline_actions"},e.createElement("button",{className:"huanban_rulego_info__copy_btn",type:"button",onClick:()=>{try{const le=Z==="visual"?h.generateToolSchemaFromRows(se):h.parseJsonObjectText(ae||"{}",{type:"object",properties:{}});Ee(JSON.stringify(le,null,2)),Re(h.parseToolSchemaRows(le)),H("")}catch(le){H(le instanceof Error?le.message:C("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}}},C("editor.workflowInfo.formatJson","格式化 JSON")),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:fe,onClick:nt},e.createElement(be,{value:k.save})," ",fe?C("editor.workflowInfo.saving","保存中..."):C("editor.workflowInfo.saveInputDefinition","保存输入定义")))),_t=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},e.createElement(be,{value:k.variable})," ",C("editor.workflowInfo.vars","变量")),e.createElement(ya,{key:`vars:${u.id}`,entries:de,onChange:pe,icons:k,translate:C,keyPlaceholder:C("editor.workflowInfo.varName","变量名"),valuePlaceholder:C("editor.workflowInfo.varValue","变量值"),actionLabel:C("editor.workflowInfo.action","操作"),deleteTitle:C("editor.workflowInfo.delete","删除"),addLabel:C("editor.workflowInfo.add","添加"),batchDeleteLabel:C("editor.workflowInfo.batchDelete","批量删除"),batchDeleteConfirm:C("editor.workflowInfo.batchDeleteConfirm","确定删除选中的 {{count}} 项吗?"),deleteConfirm:C("editor.workflowInfo.deleteEntryConfirm","确定删除“{{key}}”吗?"),selectLabel:C("editor.workflowInfo.select","选择"),selectedCountLabel:C("editor.workflowInfo.selectedCount","已选择 {{count}} 项"),selectRowLabel:C("editor.workflowInfo.selectRow","选择第 {{index}} 项")}),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:fe,onClick:()=>Et("vars")},e.createElement(be,{value:k.save})," ",C("editor.workflowInfo.saveVars","保存变量")),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(be,{value:k.secret})," ",C("editor.workflowInfo.secrets","秘钥")),e.createElement(ya,{key:`secrets:${u.id}`,entries:J,onChange:z,icons:k,translate:C,keyPlaceholder:C("editor.workflowInfo.secretName","秘钥名"),valuePlaceholder:C("editor.workflowInfo.secretValue","秘钥值"),valueType:"password",actionLabel:C("editor.workflowInfo.action","操作"),deleteTitle:C("editor.workflowInfo.delete","删除"),addLabel:C("editor.workflowInfo.add","添加"),batchDeleteLabel:C("editor.workflowInfo.batchDelete","批量删除"),batchDeleteConfirm:C("editor.workflowInfo.batchDeleteConfirm","确定删除选中的 {{count}} 项吗?"),deleteConfirm:C("editor.workflowInfo.deleteEntryConfirm","确定删除“{{key}}”吗?"),selectLabel:C("editor.workflowInfo.select","选择"),selectedCountLabel:C("editor.workflowInfo.selectedCount","已选择 {{count}} 项"),selectRowLabel:C("editor.workflowInfo.selectRow","选择第 {{index}} 项")}),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:fe,onClick:()=>Et("secrets")},e.createElement(be,{value:k.save})," ",C("editor.workflowInfo.saveSecrets","保存秘钥"))),Dt=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},e.createElement(be,{value:k.api})," ",C("editor.workflowInfo.apiIntegration","API 集成")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},C("editor.workflowInfo.executeAPI","执行 API:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",ze.executeUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.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"},C("editor.workflowInfo.notifyAPI","通知 API:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",ze.notifyUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.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"},C("editor.workflowInfo.openaiCompatibleAPI","OpenAI:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",ze.openaiUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.openaiUrl)},e.createElement(be,{value:k.copy}))),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(be,{value:k.api})," ",C("editor.workflowInfo.webSocket","WebSocket")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},C("editor.workflowInfo.debugWS","Debug WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},ze.debugWsUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.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"},C("editor.workflowInfo.runtimeWS","Runtime WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},ze.runtimeWsUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.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"},C("editor.workflowInfo.endpointWS","Endpoint WS:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},ze.endpointWsHint),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.endpointWsHint)},e.createElement(be,{value:k.copy}))),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(be,{value:k.mcp})," ",C("editor.workflowInfo.mcpIntegration","MCP 集成")),e.createElement("div",{className:"huanban_rulego_info__integration_item"},e.createElement("span",{className:"huanban_rulego_info__integration_label"},C("editor.workflowInfo.mcpSSE","MCP SSE:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},ze.mcpSseUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.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"},C("editor.workflowInfo.mcpStreamableHTTP","MCP HTTP:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",ze.mcpStreamableUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.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"},C("editor.workflowInfo.mcpGroupAPI","MCP 分组:")),e.createElement("code",{className:"huanban_rulego_info__integration_url"},"POST ",ze.mcpGroupUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>at(ze.mcpGroupUrl)},e.createElement(be,{value:k.copy})))),vt=()=>{switch(Ht){case"base":return x?x(u,Pt):Pt;case"inputSchema":return Jt;case"vars":return _?_(u,_t):_t;case"integration":return y?y(u,Tt,Dt):Dt;case"maintenance":return e.createElement(Ha,{workflow:u,fetcher:re,content:je,onError:W,locale:v,messages:A,t:$});default:{const le=Bt.find(Ce=>Ce.key===Ht);return le?le.children:null}}};return e.createElement("div",{className:`huanban_rulego_info ${xt} ${d}`.trim(),"data-theme":wt,"data-rg-theme":wt,style:{...At,...w}},e.createElement("div",{className:"huanban_rulego_info__tabs"},$t.map(le=>e.createElement("button",{key:le.key,className:`huanban_rulego_info__tab ${Ht===le.key?"huanban_rulego_info__tab--active":""}`,onClick:()=>p(le.key)},le.icon!==void 0&&e.createElement(be,{value:le.icon}),le.label))),e.createElement("div",{className:"huanban_rulego_info__content"},vt()))};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 Vs(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 Ks(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 Js(t){var n;const r=h.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 zs=0;function _a(t){if(!t)return"none";const r=Ea.get(t);if(r)return r;const n=`ref-${++zs}`;return Ea.set(t,n),n}function Gs(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 Ys(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 Xs(t){return Array.isArray(t)?h.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:Ys(r.toolCalls)}))):[]}const Ka=t=>{var O,se,Re;const{locale:r,messages:n,t:o,initialMessages:s=[],onMessagesChange:u,onError:g,placeholder:d,className:w,style:S,disabled:D=!1}=t,f=e.useMemo(()=>tt({locale:r,messages:n,t:o}),[r,n,o]),x=Gs(t),_=(O=t.persistence)==null?void 0:O.adapter,y=(se=t.persistence)==null?void 0:se.namespace,B=((Re=t.persistence)==null?void 0:Re.mode)||"component",j=e.useMemo(()=>!_||!y?null:{adapter:_,namespace:y,chainId:`${t.ruleChainId}::${x}`,mode:B},[x,_,B,y,t.ruleChainId]),W=e.useMemo(()=>h.buildEditorChatHistoryKey(j||void 0),[j]),q=W||`memory:${t.ruleChainId}:${x}:${B}`,[v,A]=e.useState(()=>va(s)),[$,k]=e.useState(q),[C,oe]=e.useState(""),[K,X]=e.useState(!1),[re,ce]=e.useState(""),p=e.useRef(null),Q=e.useRef(null),ie=e.useRef(!1),U=e.useRef(0);e.useEffect(()=>{var Ee;U.current+=1,(Ee=p.current)==null||Ee.abort(),p.current=null,X(!1),ce(""),ie.current=!0;const ae=j?Xs(h.readEditorChatHistory(j)):va(s);A(ae),k(q)},[q,j]),e.useEffect(()=>{if(u==null||u(v),ie.current){ie.current=!1;return}if(!j||!W||$!==q)return;const ae=h.filterCopilotSuccessfulTurns(v);h.writeEditorChatHistory(j,ae)},[v,$,q,u,W,j]),e.useEffect(()=>()=>{var ae;return(ae=p.current)==null?void 0:ae.abort()},[]),e.useEffect(()=>{const ae=Q.current;if(!ae)return;const Ee=H=>{const de=H.detail;ce(String(de||f("editor.copilot.copyFailed","复制失败")))};ae.addEventListener("copilot-code-copy-error",Ee);const Ie=h.bindCopilotCodeInteractions(ae,{copyLabel:f("editor.copilot.copy","复制"),copiedLabel:f("editor.copilot.copied","已复制"),copyFailedLabel:f("editor.copilot.copyFailed","复制失败"),closeLabel:f("editor.copilot.close","关闭"),codeLabel:f("editor.copilot.code","代码"),codePreviewLabel:f("editor.copilot.preview","预览")});return()=>{ae.removeEventListener("copilot-code-copy-error",Ee),Ie()}},[f]);const te=e.useCallback(async(ae,Ee,Ie,H)=>{X(!0);const de=new AbortController;p.current=de;const pe=U.current,J=()=>U.current===pe&&p.current===de;try{if(await h.streamOpenAiChatCompletion({endpoint:qa(t),model:t.model,stream:t.stream,headers:Vs(t.fetchHeaders),customFetch:t.customFetch,messages:ae.map(({role:z,content:fe})=>({role:z,content:fe})),signal:de.signal,onDelta:z=>{J()&&A(fe=>fe.map(ke=>ke.id===Ee.id?{...ke,content:ke.content+z}:ke))},onReasoningDelta:z=>{J()&&A(fe=>fe.map(ke=>ke.id===Ee.id?{...ke,reasoning:(ke.reasoning||"")+z}:ke))},onToolCallDelta:z=>{J()&&A(fe=>fe.map(ke=>ke.id===Ee.id?{...ke,toolCalls:h.mergeCopilotToolCallDelta(ke.toolCalls,z)}:ke))}}),!J())return;A(z=>z.map(fe=>fe.id===Ee.id?{...fe,status:"complete",toolCalls:h.settleCopilotToolCalls(fe.toolCalls)}:fe))}catch(z){if(!J())return;if((z==null?void 0:z.name)==="AbortError")H?(A(H),ce(f("editor.copilot.cancelled","请求已取消"))):A(fe=>fe.map(ke=>ke.id===Ie?{...ke,status:"error"}:ke.id===Ee.id?{...ke,status:"error",content:f("editor.copilot.cancelled","请求已取消")}:ke));else{const fe=z instanceof Error?z:new Error(String(z));ce(fe.message),A(H||(ke=>ke.filter(je=>je.id!==Ee.id).map(je=>je.id===Ie?{...je,status:"error"}:je))),g==null||g(fe)}}finally{if(!J())return;p.current=null,X(!1)}},[g,t,f]),ge=e.useCallback(async()=>{const ae=C.trim();if(!ae||K||D)return;const Ee=Date.now(),Ie={id:jr(),role:"user",content:ae,status:"complete",timestamp:Ee},H={id:jr(),role:"assistant",content:"",reasoning:"",status:"sending",timestamp:Ee},de=[...h.filterCopilotSuccessfulTurns(v),Ie];A([...de,H]),oe(""),ce(""),await te(de,H,Ie.id)},[K,v,D,C,te]),Se=e.useCallback(async ae=>{var Ee;try{if(!((Ee=navigator.clipboard)!=null&&Ee.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(ae)}catch{ce(f("editor.copilot.copyFailed","复制失败"))}},[f]),xe=e.useCallback(async ae=>{var J,z;if(K||D)return;const Ee=v,Ie=h.filterCopilotSuccessfulTurns(Ee),H=Ie.findIndex(fe=>fe.id===ae);if(H<=0||((J=Ie[H])==null?void 0:J.role)!=="assistant"||((z=Ie[H-1])==null?void 0:z.role)!=="user")return;const de=Ie.slice(0,H),pe={id:jr(),role:"assistant",content:"",reasoning:"",status:"sending",timestamp:Date.now()};A([...de,pe]),ce(""),await te(de,pe,void 0,Ee)},[K,v,D,te]),ve=()=>{var ae;return(ae=p.current)==null?void 0:ae.abort()},ue=()=>{K||(j&&h.clearEditorChatHistory(j),A([]),ce(""))},F=ae=>ae==="user"?f("editor.copilot.userRole","用户"):f("editor.copilot.assistantRole","助手"),Z=e.useMemo(()=>Js(v),[v]);return e.createElement("section",{className:`rge-copilot ${w||""}`,style:S,"aria-label":f("editor.copilot.title","AI 助理")},e.createElement("header",{className:"rge-copilot__header"},e.createElement("strong",null,f("editor.copilot.title","AI 助理")),e.createElement("button",{type:"button",onClick:ue,disabled:K||v.length===0,title:f("editor.copilot.clear","清空对话")},f("editor.copilot.clear","清空"))),e.createElement("div",{ref:Q,className:"rge-copilot__messages","aria-live":"polite"},v.length===0&&e.createElement("div",{className:"rge-copilot__empty"},f("editor.copilot.empty","请输入问题开始对话")),v.map(ae=>{var Ee;return e.createElement("article",{key:ae.id,className:`rge-copilot__message ${ae.role}${ae.status==="error"?" is-error":""}`},e.createElement("div",{className:"rge-copilot__role"},F(ae.role),ae.status==="sending"?` · ${f("editor.copilot.sending","处理中")}`:"",ae.role==="user"&&ae.status==="error"?` · ${f("editor.copilot.failed","未完成")}`:""),ae.reasoning&&e.createElement("details",null,e.createElement("summary",null,f("editor.copilot.reasoning","思考过程")),e.createElement("div",{className:"rge-copilot__reasoning",dangerouslySetInnerHTML:{__html:h.renderCopilotMarkdown(ae.reasoning,{codeCopyLabel:f("editor.copilot.copy","复制"),codeLabel:f("editor.copilot.code","代码"),codePreviewLabel:f("editor.copilot.preview","预览"),codeFullscreenLabel:f("editor.copilot.fullscreen","全屏"),streaming:ae.status==="sending"})}})),(Ee=ae.toolCalls)!=null&&Ee.length?e.createElement("details",{className:"rge-copilot__tools",open:ae.status==="sending","data-copilot-tool-calls":"true"},e.createElement("summary",null,f("editor.copilot.toolCalls","工具调用")," (",ae.toolCalls.length,")"),e.createElement("div",{className:"rge-copilot__tool-list"},ae.toolCalls.map(Ie=>e.createElement("div",{key:Ie.id,className:"rge-copilot__tool","data-copilot-tool-call":Ie.id},e.createElement("div",{className:"rge-copilot__tool-header"},e.createElement("strong",null,Ie.name),e.createElement("span",null,Ie.status==="loading"?f("editor.copilot.toolRunning","处理中"):Ie.status==="success"?f("editor.copilot.toolCompleted","已完成"):Ie.status==="error"?f("editor.copilot.toolFailed","失败"):f("editor.copilot.toolReceived","已收到"))),Ie.arguments&&e.createElement("pre",null,Ie.arguments),Ie.result&&e.createElement("pre",{className:"rge-copilot__tool-result"},Ie.result))))):null,ae.content?e.createElement("div",{className:"rge-copilot__content",dangerouslySetInnerHTML:{__html:h.renderCopilotMarkdown(ae.content,{codeCopyLabel:f("editor.copilot.copy","复制"),codeLabel:f("editor.copilot.code","代码"),codePreviewLabel:f("editor.copilot.preview","预览"),codeFullscreenLabel:f("editor.copilot.fullscreen","全屏"),streaming:ae.status==="sending"})}}):ae.status==="sending"?e.createElement("div",{className:"rge-copilot__content"},f("editor.copilot.sending","处理中")):null,e.createElement("div",{className:"rge-copilot__message-meta"},e.createElement("time",{className:"rge-copilot__message-time"},Ks(ae.timestamp)),e.createElement("div",{className:"rge-copilot__message-actions"},e.createElement("button",{type:"button","data-copilot-message-action":"copy",disabled:!ae.content,onClick:()=>void Se(ae.content),title:f("editor.copilot.copy","复制"),"aria-label":f("editor.copilot.copy","复制")},e.createElement("span",{"aria-hidden":"true"},"⧉")),ae.id===Z&&e.createElement("button",{type:"button","data-copilot-message-action":"regenerate",disabled:K,onClick:()=>void xe(ae.id),title:f("editor.copilot.regenerate","重新生成"),"aria-label":f("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:f("editor.copilot.dismissError","关闭错误提示"),"aria-label":f("editor.copilot.dismissError","关闭错误提示")},"×")),e.createElement("div",{className:"rge-copilot__input"},e.createElement("textarea",{value:C,disabled:D||K,onChange:ae=>oe(ae.target.value),onKeyDown:ae=>{ae.key==="Enter"&&!ae.shiftKey&&(ae.preventDefault(),ge())},placeholder:d||f("editor.copilot.placeholder","输入消息"),rows:2}),K?e.createElement("button",{type:"button",onClick:ve,title:f("editor.copilot.stop","停止请求")},f("editor.copilot.stop","停止")):e.createElement("button",{type:"button",onClick:()=>void ge(),disabled:D||!C.trim()},f("editor.copilot.send","发送"))))},Qs=t=>{const{chainId:r,baseUrl:n,apiPrefix:o,getToken:s,customFetch:u,conversationContextKey:g,...d}=t,w=(r==null?void 0:r.trim())||"",S=h.resolveAIChatEndpoint({chainId:w,baseUrl:n,apiPrefix:o}),D=e.useRef(t);D.current=t;const f=e.useCallback(async(x,_)=>{const y=D.current,B=h.resolveAIChatTransportOptions(y,_);return y.customFetch?y.customFetch(B.endpoint,B.init):fetch(B.endpoint,B.init)},[]);return e.createElement(Ka,{...d,key:w,ruleChainId:w,endpoint:S,conversationContextKey:(g==null?void 0:g.trim())||`AIChat:${S}`,customFetch:f,disabled:t.disabled||!w})},Zs=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 el({editorRef:t,editor:r,options:n,iconOnly:o=!0,label:s="AI助手",className:u,style:g,disabled:d,onOpen:w}){const S=()=>{var f;const D=r||((f=t==null?void 0:t.current)==null?void 0:f.editor);D==null||D.openAiAssistant(n),w==null||w()};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:d?"not-allowed":"pointer",opacity:d?.5:1,...g},disabled:d,title:s,"aria-label":s,onClick:S},Zs,!o&&e.createElement("span",null,s))}const tl=({schema:t,formData:r,onChange:n,locale:o,messages:s,t:u})=>{const g=e.useMemo(()=>tt({locale:o,messages:s,t:u}),[o,s,u]);return e.createElement("div",{className:"hb-node-form"},t.map(d=>e.createElement("div",{key:d.key,className:"rge-dynamic-form-item"},e.createElement("label",{className:"rge-dynamic-form-label"},g(d.labelKey||`fields.${d.key}`,d.label)),d.type==="boolean"?e.createElement("input",{type:"checkbox",checked:!!r[d.key],onChange:w=>n(d.key,w.target.checked)}):d.type==="json"||d.type==="textarea"?e.createElement("textarea",{value:r[d.key]||"",onChange:w=>n(d.key,w.target.value),rows:d.rows||(d.type==="json"?5:3),className:d.type==="json"?"rge-form-textarea mono":"rge-form-textarea",placeholder:d.placeholder}):d.type==="select"?e.createElement(rr,{value:String(r[d.key]??d.defaultValue??""),values:Array.isArray(r[d.key])?r[d.key].map(w=>String(w??"")).filter(Boolean):void 0,multiple:d.multiple,options:d.options||[],placeholder:d.placeholder,searchPlaceholder:g("editor.property.searchOptions","搜索选项..."),noMatchText:g("editor.property.noMatchingOptions","没有匹配的选项"),onChange:w=>n(d.key,w),onMultiChange:w=>n(d.key,w)}):e.createElement("input",{type:d.type==="number"?"number":d.type==="password"?"password":"text",value:r[d.key]||"",onChange:w=>n(d.key,d.type==="number"?w.target.value===""?"":Number(w.target.value):w.target.value),className:"rge-form-input",placeholder:d.placeholder}),d.help&&e.createElement("span",{className:"rge-form-help"},d.help))))},rl=({logs:t,locale:r,messages:n,t:o})=>{const[s,u]=e.useState([]),g=e.useRef(null),d=e.useMemo(()=>tt({locale:r,messages:n,t:o}),[r,n,o]);return e.useEffect(()=>{t.length>200?u(t.slice(t.length-200)):u(t),g.current&&(g.current.scrollTop=g.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"}},d("editor.logViewer.title","调试控制台 (Debug Console)")),e.createElement("div",{ref:g,style:{flex:1,overflowY:"auto",padding:"8px",fontFamily:"monospace",fontSize:"12px"}},s.map(w=>e.createElement("div",{key:w.id,style:{padding:"4px",borderBottom:"1px solid var(--hb-border-light)",color:w.level==="error"?"var(--hb-color-danger)":w.level==="warn"?"var(--hb-color-warning)":"var(--hb-text-primary)"}},e.createElement("span",{style:{color:"var(--hb-text-secondary)",marginRight:"8px"}},"[",new Date(w.timestamp).toLocaleTimeString(),"]"),w.message)),s.length===0&&e.createElement("div",{style:{color:"var(--hb-text-secondary)",textAlign:"center",marginTop:"20px"}},d("editor.logViewer.empty","暂无调试日志"))))},nl={isReady:!1,isDirty:!1,isLoading:!1,selectedNode:null,selectedEdge:null,componentGroups:[],currentNodeView:null,currentNodeModel:{},currentEdgeModel:{},canUndo:!1,canRedo:!1};function al(t={}){const[r,n]=e.useState(nl),o=e.useRef(null),s=e.useRef([]),u=e.useRef(t);e.useEffect(()=>{const f=new h.EditorCore(u.current);o.current=f;const x=f.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(),f.destroy(),o.current=null}},[]);const g=e.useCallback(f=>{o.current&&o.current.init(f)},[]),d=e.useCallback(f=>{o.current&&o.current.loadData(f)},[]),w=e.useCallback((f,x)=>{if(o.current){const _=o.current.eventBus.on(f,x);s.current.push(_)}},[]),S=e.useCallback((f,...x)=>{o.current&&o.current.eventBus.emit(f,...x)},[]),D=e.useCallback(()=>{o.current&&o.current.eventBus.emit("editor:save",{data:{},success:!1})},[]);return{core:o.current,...r,loadData:d,on:w,emit:S,init:g,save:D}}function ol(t){const[r,n]=e.useState("default"),[o,s]=e.useState(()=>h.getThemeList("zh-CN").map(g=>g.id));e.useEffect(()=>{if(t)return n(t.theme.getTheme()),s(t.theme.getAvailableThemes().map(g=>g.name)),t.theme.onChange(g=>{n(g),s(t.theme.getAvailableThemes().map(d=>d.name))})},[t]);const u=e.useCallback(g=>{t&&t.theme.setTheme(g)},[t]);return{currentTheme:r,themes:o,setTheme:u}}function sl(t){const[r,n]=e.useState((t==null?void 0:t.i18n.getLocale())||"zh-CN"),o=e.useCallback((u,g)=>t?t.i18n.t(u,g):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 ll(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 cl(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(),g=w=>{const S=w,D=S.key.toLowerCase();for(const f of s.current){if(D!==f.key.toLowerCase())continue;const x=f.ctrl?u?S.metaKey:S.ctrlKey:!(u?S.metaKey:S.ctrlKey),_=f.shift?S.shiftKey:!S.shiftKey,y=f.alt?S.altKey:!S.altKey;if(!(!x||!_||!y)&&!(!f.enableInInput&&ll(S.target))){S.preventDefault(),S.stopPropagation(),f.handler(S);return}}},d=o||document;return d.addEventListener("keydown",g),()=>{d.removeEventListener("keydown",g)}},[n,o])}function il(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 ul(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 g=o.current,d=e.useRef(new Map),[w,S]=e.useState(()=>({store:g,state:n(g)}));return e.useEffect(()=>{const D=s.current;let f=!1;const x=d.current.get(g);x&&(clearTimeout(x),d.current.delete(g));const _=g.subscribe(y=>{f||S({store:g,state:y})});return S({store:g,state:n(g)}),()=>{if(f=!0,_(),D){const y=setTimeout(()=>{d.current.delete(g),g.destroy()},0);d.current.set(g,y)}}},[g]),{store:g,state:w.store===g?w.state:n(g)}}function ml(t={}){const{store:r,state:n}=Hr(t.workspace,()=>new h.EditorWorkspace(t),y=>y.getState()),o=e.useCallback(y=>r.openTab(y),[r]),s=e.useCallback(y=>r.activateTab(y),[r]),u=e.useCallback((y,B)=>r.renameTab(y,B),[r]),g=e.useCallback(y=>r.togglePinned(y),[r]),d=e.useCallback(y=>r.getCloseOtherTabIds(y),[r]),w=e.useCallback(y=>r.getCloseRightTabIds(y),[r]),S=e.useCallback((y,B)=>r.setDraft(y,B),[r]),D=e.useCallback((y,B)=>r.markSaved(y,B),[r]),f=e.useCallback((y,B)=>r.setLoading(y,B),[r]),x=e.useCallback((y,B)=>r.closeTab(y,B),[r]),_=e.useCallback((y,B,j)=>r.resolveSaveConflict(y,B,j),[r]);return{workspace:r,state:n,tabs:n.tabs,activeTab:n.tabs.find(y=>y.id===n.activeTabId)??null,openTab:o,activateTab:s,renameTab:u,togglePinned:g,getCloseOtherTabIds:d,getCloseRightTabIds:w,setDraft:S,markSaved:D,setLoading:f,closeTab:x,resolveSaveConflict:_}}function dl(t={}){const{dockStore:r,...n}=t,{store:o,state:s}=Hr(r,()=>new h.EditorDockStore(n),u=>u.getDockState());return{dock:o,state:s,setDockVisibility:e.useCallback((u,g)=>o.setDockVisibility(u,g),[o]),setDockWidth:e.useCallback((u,g)=>o.setDockWidth(u,g),[o]),setDockHeight:e.useCallback((u,g)=>o.setDockHeight(u,g),[o]),resetDockState:e.useCallback(()=>o.resetDockState(),[o])}}function pl(t={}){const{serverStatus:r,...n}=t,{store:o,state:s}=Hr(r,()=>new h.ServerStatusStore(n),u=>u.getState());return{server:o,state:s,setServerUrl:e.useCallback((u,g)=>o.setServerUrl(u,g),[o]),setServerStatus:e.useCallback((u,g)=>o.setServerStatus(u,g),[o]),recordHttpStatus:e.useCallback((u,g)=>o.recordHttpStatus(u,g),[o]),recordWebSocketStatus:e.useCallback((u,g,d)=>o.recordWebSocketStatus(u,g,d),[o]),setReconnectAttempt:e.useCallback(u=>o.setReconnectAttempt(u),[o])}}function gl(t={}){const{connectionStatus:r}=t,{store:n,state:o}=Hr(r,()=>new h.ConnectionStatusStore,s=>s.getState());return{connectionStatus:n,state:o}}function fl(t={}){const r=t.panels,n=r instanceof h.EditorPanelRegistry?r:null,o={...t,panels:Array.isArray(r)?r:void 0,syncDockVisibility:!1},{store:s,state:u}=Hr(n,()=>new h.EditorPanelRegistry(o),g=>g.getState());return e.useEffect(()=>{s.syncDockVisibility()},[s]),{panels:s,state:u,openPanel:e.useCallback((g,d)=>s.openPanel(g,d),[s]),closePanel:e.useCallback(g=>s.closePanel(g),[s]),activatePanel:e.useCallback(g=>s.activatePanel(g),[s]),setPanelExpanded:e.useCallback((g,d)=>s.setPanelExpanded(g,d),[s]),togglePanelExpanded:e.useCallback(g=>s.togglePanelExpanded(g),[s]),isPanelExpanded:e.useCallback(g=>s.isPanelExpanded(g),[s]),register:e.useCallback((g,d)=>s.register(g,d),[s]),unregister:e.useCallback(g=>s.unregister(g),[s]),getPanels:e.useCallback(g=>s.getPanels(g),[s]),getActivePanel:e.useCallback(g=>s.getActivePanel(g),[s])}}const bl=30;function hl(){return`node_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`}function yl(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 El(t){var f;const{confirm:r,capture:n}=Br((f=t.getContext)==null?void 0:f.call(t)),[o,s]=e.useState([]),u=e.useRef(0),g=e.useCallback(()=>{var y,B,j;const x=((y=t.getSelectedNodes)==null?void 0:y.call(t))||[];if(x.length===0){(B=t.onNotify)==null||B.call(t,"info","没有选中的节点");return}const _=x.map(_n);s(_),u.current=0,(j=t.onNotify)==null||j.call(t,"success",`已复制 ${_.length} 个节点`)},[t]),d=e.useCallback(async()=>{var q,v,A,$,k,C,oe,K,X;const x=((q=t.getSelectedNodes)==null?void 0:q.call(t))||[];if(x.length===0){(v=t.onNotify)==null||v.call(t,"info","没有选中的节点");return}const _=x.map(re=>re.originalId),y=JSON.stringify([x,(A=t.getContext)==null?void 0:A.call(t)]),B=n();if((($=t.canDeleteNodes)==null?void 0:$.call(t))===!1)return;let j=!1;try{j=t.confirmDeleteNodes?await t.confirmDeleteNodes(_):await r(`确认剪切并删除 ${_.length} 个节点吗?此操作不可撤销。`)}catch{return}if(!j||!B()||((k=t.canDeleteNodes)==null?void 0:k.call(t))===!1||y!==JSON.stringify([((C=t.getSelectedNodes)==null?void 0:C.call(t))||[],(oe=t.getContext)==null?void 0:oe.call(t)]))return;const W=x.map(_n);s(W),u.current=0,(K=t.onDeleteNodes)==null||K.call(t,_),(X=t.onNotify)==null||X.call(t,"success",`已剪切 ${W.length} 个节点`)},[t]),w=e.useCallback(()=>{var B,j,W,q;if(o.length===0){(B=t.onNotify)==null||B.call(t,"info","剪贴板为空");return}u.current+=1;const x=bl*u.current,_=new Set(((j=t.getExistingNodeIds)==null?void 0:j.call(t))||[]);o.forEach(v=>_.add(String(v.originalId)));const y=o.map(v=>{const A=_n(v),$=yl(hl(),_,`node_${v.originalId||"copy"}`),k=v.x+x,C=v.y+x;return{...A,originalId:$,x:k,y:C,properties:h.cloneNodePropertiesForCopy(A.properties||{},{nodeId:$,nodeType:A.type,nodeName:A.name,layoutX:k,layoutY:C})}});(W=t.onAddNodes)==null||W.call(t,y),(q=t.onNotify)==null||q.call(t,"success",`已粘贴 ${y.length} 个节点`)},[o,t]),S=e.useCallback(()=>{var x;(x=t.onSelectAll)==null||x.call(t)},[t]),D=e.useCallback(()=>{s([]),u.current=0},[]);return{copy:g,cut:d,paste:w,selectAll:S,hasContent:o.length>0,clipboardCount:o.length,clear:D}}const za=e.forwardRef((t,r)=>{const n=e.useRef(null),o=e.useRef(null),s=e.useMemo(()=>tt(t),[t.locale,t.messages,t.t]),u=e.useRef({props:t,translate:s});u.current={props:t,translate:s};const g=e.useMemo(()=>h.getThemeRuntimeVariables(t.theme),[t.theme]);return e.useImperativeHandle(r,()=>({reload:()=>{var d;return((d=o.current)==null?void 0:d.reload())??Promise.resolve(!1)},isDirty:()=>{var d;return((d=o.current)==null?void 0:d.isDirty())??!1},requestClose:()=>{var d;return((d=o.current)==null?void 0:d.requestClose())??Promise.resolve(!1)}}),[]),e.useEffect(()=>{if(!n.current)return;const d={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:(S,D)=>u.current.translate(S,"",D)},w=h.createSharedNodeManager(d,n.current);return o.current=w,()=>{w.destroy(),o.current===w&&(o.current=null)}},[t.opts.apiBase,t.opts.fetchTimeout,t.opts.fetchHeaders,t.opts.customFetch,t.opts.onApiAuthRequired,t.serverStatus]),e.useEffect(()=>{var d,w,S;(d=o.current)==null||d.refresh(),t.active===!1?(w=o.current)==null||w.deactivate():(S=o.current)==null||S.activate()}),e.createElement("div",{ref:n,className:["rge-shared-node-manager",t.className].filter(Boolean).join(" "),"data-rg-theme":h.normalizeEditorTheme(t.theme),style:{fontFamily:"var(--hb-font-family, system-ui, sans-serif)",...g,...t.style}})});za.displayName="SharedNodeManager";Object.defineProperty(exports,"ConnectionStatusController",{enumerable:!0,get:()=>h.ConnectionStatusController});Object.defineProperty(exports,"ConnectionStatusStore",{enumerable:!0,get:()=>h.ConnectionStatusStore});Object.defineProperty(exports,"DEFAULT_ROUTES",{enumerable:!0,get:()=>h.DEFAULT_ROUTES});Object.defineProperty(exports,"RuleChainAPI",{enumerable:!0,get:()=>h.RuleChainAPI});Object.defineProperty(exports,"normalizeConnectionStatusMap",{enumerable:!0,get:()=>h.normalizeConnectionStatusMap});Object.defineProperty(exports,"resolveConnectionStatusView",{enumerable:!0,get:()=>h.resolveConnectionStatusView});exports.AIAssistant=el;exports.AIChat=Qs;exports.ComponentSidebar=wa;exports.ContextMenu=Oa;exports.CopilotChat=Ka;exports.DataViewDialog=La;exports.DebugPanel=Da;exports.DynamicForm=tl;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=rl;exports.MiniMap=Aa;exports.NodePropertyDrawer=Ia;exports.ProblemsPanel=Fa;exports.RuleChainSettings=ja;exports.RuleGoEditor=Na;exports.RuleMaintenancePanel=Ha;exports.SearchPanel=Ss;exports.SearchableSelect=rr;exports.SharedNodeManager=za;exports.ValidationPanel=$a;exports.WorkflowExplorer=Os;exports.WorkflowInfoPanel=qs;exports.WorkflowList=Ls;exports.WorkspaceTabs=gs;exports.createFrameworkTranslator=tt;exports.getCanvasContextMenuItems=ms;exports.getDefaultEditorShortcuts=ul;exports.getEdgeContextMenuItems=us;exports.getNodeContextMenuItems=is;exports.getShortcutLabel=il;exports.normalizeFrameworkLocale=ln;exports.relationTypeLabel=Nn;exports.useClipboard=El;exports.useConnectionStatus=gl;exports.useEditorCore=al;exports.useEditorDock=dl;exports.useEditorI18n=sl;exports.useEditorPanels=fl;exports.useEditorTheme=ol;exports.useEditorWorkspace=ml;exports.useKeyboardShortcuts=cl;exports.useServerStatus=pl;