@huanban/rulego-editor-react 1.4.1 → 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"),C=require("@huanban/rulego-editor-core");function ln(t){return Object.fromEntries(Object.entries(t).filter(([,n])=>n!==void 0))}function Or(t){return Array.isArray(t)?t.length>0:!!t}const jn=["onAuthExpired","onApiAuthRequired","clearToken","onSettingsClick","onSettingsSubmit","onLoginClick","onSaveConflict","onRestartConfirm"],rr=["onReady","onSave","saveHandler","onSaveRequest","onSaveSuccess","onSaveError","onExternalDataConflict","onNodeClick","onNodeDbClick","onEdgeClick","onChange","onInfoClick","onExportDSL","onImportDSL","onRunClick","onTraceClick","onComponentManage","onLocaleChange","onDeploy","onRestart","onSelectRuleChain","onDeleteRuleChain","onRunHistory"];function mr(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)=>mr(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)&&mr(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]):mr(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:D,customFetch:g,data:w,dataUpdatePolicy:E,components:k,enableConnectionStatus:O,onConnectionStatusChange:F,mode:A,capabilities:W,disabled:_,showToolbar:I,toolbarTitle:P,showToolbarButtonLabels:y,toolbarIconOnly:u,showSidebar:te,sidebarWidth:re,sidebarCollapsed:B,showInfoButton:U,showAiChatButton:pe,showSettingsButton:V,showDebugConsoleButton:se,showDiagnosticsButton:me,showClearDebugHighlightButton:j,showSelectionButton:be,showExportDialog:De,showRunButton:$e,showComponentManage:X,showDeployButton:b,showRestartButton:$,showReloadButton:Y,showRunHistory:ae,runHistoryUrl:L,showTraceButton:Ce,showDebugTab:Se,locale:oe,theme:he,lfOptions:Te,lfPlugins:Ee,coreOptions:Me,options:xe,onReady:ce,onSave:le,saveMode:ke,saveHandler:ye,onSaveSuccess:J,onSaveError:Oe,onExternalDataConflict:Ze,onNodeClick:z,onNodeDbClick:Ge,onEdgeClick:dt,onChange:ot,onInfoClick:Ht,onExportDSL:Ft,onImportDSL:Bt,onRunClick:Rt,onTraceClick:Ct,onComponentManage:rt,onLocaleChange:Mt,onDeploy:Ve,onRestart:$t,onSelectRuleChain:wt,onDeleteRuleChain:At,onRunHistory:yt,ruleItems:Ot,rulesApi:Dt,renderNode:Wt}=n,_t=e.useRef(null),Re=e.useRef(null),[Ut,pt]=e.useState([]),Be=e.useRef({onSave:le,saveHandler:ye,onSaveSuccess:J,onSaveError:Oe,onExternalDataConflict:Ze,onReady:ce,onNodeClick:z,onNodeDbClick:Ge,onEdgeClick:dt,onChange:ot,onInfoClick:Ht,onExportDSL:Ft,onImportDSL:Bt,onRunClick:Rt,onTraceClick:Ct,onComponentManage:rt,onLocaleChange:Mt,onDeploy:Ve,onRestart:$t,onSelectRuleChain:wt,onDeleteRuleChain:At,onRunHistory:yt}),ne=e.useRef(F);ne.current=F;const Q=e.useRef(xe),_e=e.useRef({onAuthExpired:v=>{var S,q;return(q=(S=Q.current)==null?void 0:S.onAuthExpired)==null?void 0:q.call(S,v)},onApiAuthRequired:v=>{var S,q;return(q=(S=Q.current)==null?void 0:S.onApiAuthRequired)==null?void 0:q.call(S,v)},clearToken:()=>{var v,S;return(S=(v=Q.current)==null?void 0:v.clearToken)==null?void 0:S.call(v)},onSettingsClick:v=>{var S,q;return(q=(S=Q.current)==null?void 0:S.onSettingsClick)==null?void 0:q.call(S,v)},onSettingsSubmit:v=>{var S,q;return(q=(S=Q.current)==null?void 0:S.onSettingsSubmit)==null?void 0:q.call(S,v)},onLoginClick:()=>{var v,S;return(S=(v=Q.current)==null?void 0:v.onLoginClick)==null?void 0:S.call(v)},onSaveConflict:v=>{var S,q;return(q=(S=Q.current)==null?void 0:S.onSaveConflict)==null?void 0:q.call(S,v)},onRestartConfirm:v=>{var S,q;return(q=(S=Q.current)==null?void 0:S.onRestartConfirm)==null?void 0:q.call(S,v)}}),Ne=e.useRef({}),Le=e.useRef({}),Je=e.useRef({}),St=e.useRef({}),Ie=e.useRef(null);e.useEffect(()=>{Q.current=xe;const v=Ne.current,S={};jn.forEach(ee=>{S[ee]=typeof(xe==null?void 0:xe[ee])=="function"}),Le.current=v,Ne.current=S;const q=Je.current,H={};rr.forEach(ee=>{H[ee]=typeof n[ee]=="function"||typeof(xe==null?void 0:xe[ee])=="function"}),St.current=q,Je.current=H,Be.current={onSave:le,saveHandler:ye,onSaveSuccess:J,onSaveError:Oe,onExternalDataConflict:Ze,onReady:ce,onNodeClick:z,onNodeDbClick:Ge,onEdgeClick:dt,onChange:ot,onInfoClick:Ht,onExportDSL:Ft,onImportDSL:Bt,onRunClick:Rt,onTraceClick:Ct,onComponentManage:rt,onLocaleChange:Mt,onDeploy:Ve,onRestart:$t,onSelectRuleChain:wt,onDeleteRuleChain:At,onRunHistory:yt}});const d=e.useRef({request:v=>{var S,q,H,ee;(q=(S=Be.current).onSave)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onSaveRequest)==null||ee.call(H,v)},handler:v=>{var q,H;const S=Be.current.saveHandler;return S?S(v):(H=(q=Q.current)==null?void 0:q.saveHandler)==null?void 0:H.call(q,v)},legacyHandler:v=>{var S,q;return(q=(S=Q.current)==null?void 0:S.onSave)==null?void 0:q.call(S,v)},success:v=>{var S,q,H,ee;(q=(S=Be.current).onSaveSuccess)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onSaveSuccess)==null||ee.call(H,v)},error:v=>{var S,q,H,ee;(q=(S=Be.current).onSaveError)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onSaveError)==null||ee.call(H,v)},conflict:v=>{var S,q,H,ee;(q=(S=Be.current).onExternalDataConflict)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onExternalDataConflict)==null||ee.call(H,v)}}),ve=e.useRef({onReady:v=>{var S,q,H,ee;(q=(S=Be.current).onReady)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onReady)==null||ee.call(H,v)},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:v=>{var S,q,H,ee;(q=(S=Be.current).onNodeClick)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onNodeClick)==null||ee.call(H,v)},onNodeDbClick:v=>{var S,q,H,ee;(q=(S=Be.current).onNodeDbClick)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onNodeDbClick)==null||ee.call(H,v)},onEdgeClick:v=>{var S,q,H,ee;(q=(S=Be.current).onEdgeClick)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onEdgeClick)==null||ee.call(H,v)},onChange:()=>{var v,S,q,H;(S=(v=Be.current).onChange)==null||S.call(v),(H=(q=Q.current)==null?void 0:q.onChange)==null||H.call(q)},onInfoClick:v=>{var S,q,H,ee;(q=(S=Be.current).onInfoClick)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onInfoClick)==null||ee.call(H,v)},onExportDSL:v=>{var S,q,H,ee;(q=(S=Be.current).onExportDSL)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onExportDSL)==null||ee.call(H,v)},onImportDSL:v=>{var S,q,H,ee;(q=(S=Be.current).onImportDSL)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onImportDSL)==null||ee.call(H,v)},onRunClick:v=>{var S,q,H,ee;(q=(S=Be.current).onRunClick)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onRunClick)==null||ee.call(H,v)},onTraceClick:v=>{var S,q,H,ee;(q=(S=Be.current).onTraceClick)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onTraceClick)==null||ee.call(H,v)},onComponentManage:v=>{var S,q,H,ee;(q=(S=Be.current).onComponentManage)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onComponentManage)==null||ee.call(H,v)},onLocaleChange:v=>{var S,q,H,ee;(q=(S=Be.current).onLocaleChange)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onLocaleChange)==null||ee.call(H,v)},onDeploy:(v,S)=>{var ee,qe,He,it;const q=(qe=(ee=Be.current).onDeploy)==null?void 0:qe.call(ee,v,S),H=(it=(He=Q.current)==null?void 0:He.onDeploy)==null?void 0:it.call(He,v,S);return q!==void 0?q:H},onRestart:v=>{var H,ee,qe,He;const S=(ee=(H=Be.current).onRestart)==null?void 0:ee.call(H,v),q=(He=(qe=Q.current)==null?void 0:qe.onRestart)==null?void 0:He.call(qe,v);return S!==void 0?S:q},onSelectRuleChain:v=>{var S,q,H,ee;(q=(S=Be.current).onSelectRuleChain)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onSelectRuleChain)==null||ee.call(H,v)},onDeleteRuleChain:v=>{var S,q,H,ee;(q=(S=Be.current).onDeleteRuleChain)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onDeleteRuleChain)==null||ee.call(H,v)},onRunHistory:v=>{var S,q,H,ee;(q=(S=Be.current).onRunHistory)==null||q.call(S,v),(ee=(H=Q.current)==null?void 0:H.onRunHistory)==null||ee.call(H,v)}});e.useEffect(()=>{var kt;if(!_t.current)return;const v=!!(ye||xe!=null&&xe.saveHandler),S=!v&&typeof(xe==null?void 0:xe.onSave)=="function",q={...(()=>{const je={...xe};return jn.forEach(ut=>{typeof je[ut]=="function"&&(je[ut]=_e.current[ut])}),je})(),container:_t.current,...ln({apiBase:f,fetchTimeout:M,fetchHeaders:N,apiCacheKey:D,customFetch:g,data:w??void 0,components:Or(k)?k:void 0,dataUpdatePolicy:E,enableConnectionStatus:O}),...ln({mode:A,capabilities:W,disabled:_,showToolbar:I,toolbarTitle:P,showToolbarButtonLabels:y,toolbarIconOnly:u,showSidebar:te,sidebarWidth:re,sidebarCollapsed:B,showInfoButton:U,showAiChatButton:pe,showSettingsButton:V,showDebugConsoleButton:se,showDiagnosticsButton:me,showClearDebugHighlightButton:j,showSelectionButton:be,showExportDialog:De,showRunButton:$e,showComponentManage:X,showDeployButton:b,showRestartButton:$,showReloadButton:Y,showRunHistory:ae,runHistoryUrl:L,showTraceButton:Ce,showDebugTab:Se}),...ln({locale:oe,theme:he}),...ln({lfOptions:Te,lfPlugins:Ee,coreOptions:Me}),...ln({ruleItems:Ot,rulesApi:Dt}),onReady:ve.current.onReady,...ln({saveMode:ke??(xe==null?void 0:xe.saveMode),saveHandler:v?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:ve.current.onNodeClick,onNodeDbClick:ve.current.onNodeDbClick,onEdgeClick:ve.current.onEdgeClick,onChange:ve.current.onChange,onInfoClick:Je.current.onInfoClick?ve.current.onInfoClick:void 0,onExportDSL:Je.current.onExportDSL?ve.current.onExportDSL:void 0,onImportDSL:Je.current.onImportDSL?ve.current.onImportDSL:void 0,onRunClick:Je.current.onRunClick?ve.current.onRunClick:void 0,onTraceClick:Je.current.onTraceClick?ve.current.onTraceClick:void 0,onComponentManage:Je.current.onComponentManage?ve.current.onComponentManage:void 0,onLocaleChange:ve.current.onLocaleChange,onDeploy:Je.current.onDeploy?ve.current.onDeploy:void 0,onRestart:Je.current.onRestart?ve.current.onRestart:void 0,onSelectRuleChain:ve.current.onSelectRuleChain,onDeleteRuleChain:ve.current.onDeleteRuleChain,onRunHistory:Je.current.onRunHistory?ve.current.onRunHistory:void 0},H=new C.HuanbanRulegoEditor(q);Re.current=H,Ie.current=null;const ee=H.connectionStatus.subscribe(je=>{var ut;(ut=ne.current)==null||ut.call(ne,je)});(kt=ne.current)==null||kt.call(ne,H.connectionStatus.getState());let qe=null;const He=setTimeout(()=>{qe=requestAnimationFrame(()=>{if(qe=null,H.lf&&_t.current){const{clientWidth:je,clientHeight:ut}=_t.current;if(je>0&&ut>0)try{H.lf.resize(je,ut)}catch{}}})},100),it=je=>{pt(ut=>{const Vt=ut.findIndex(It=>It.id===je.id),lt={...je};if(Vt>=0){const It=[...ut];return It[Vt]=lt,It}return[...ut,lt]})},et=je=>{pt(ut=>ut.filter(Vt=>Vt.id!==je.id))};return H.core&&(H.core.eventBus.on("node:html-mount",it),H.core.eventBus.on("node:html-unmount",et)),()=>{H.core&&(H.core.eventBus.off("node:html-mount",it),H.core.eventBus.off("node:html-unmount",et)),clearTimeout(He),qe!==null&&(cancelAnimationFrame(qe),qe=null),ee(),H.destroy(),Re.current=null}},[]),e.useEffect(()=>{var it,et,kt;const v=Re.current;if(!v)return;const S={...Q.current||{}};delete S.container,delete S.data,delete S.components,delete S.lfOptions,delete S.lfPlugins,delete S.persistence,rr.forEach(je=>{delete S[je]}),jn.forEach(je=>{delete S[je]});const q=!!(ye||(it=Q.current)!=null&&it.saveHandler),H=!q&&typeof((et=Q.current)==null?void 0:et.onSave)=="function",ee={};jn.forEach(je=>{Ne.current[je]?ee[je]=_e.current[je]:Le.current[je]&&(ee[je]=void 0)});const qe={};rr.forEach(je=>{Je.current[je]?qe[je]=ve.current[je]:St.current[je]&&(qe[je]=void 0)});const He={...S,...ln({apiBase:f,fetchTimeout:M,fetchHeaders:N,apiCacheKey:D,customFetch:g,dataUpdatePolicy:E,enableConnectionStatus:O,mode:A,capabilities:W,disabled:_,showToolbar:I,toolbarTitle:P,showToolbarButtonLabels:y,toolbarIconOnly:u,showSidebar:te,sidebarWidth:re,sidebarCollapsed:B,showInfoButton:U,showAiChatButton:pe,showSettingsButton:V,showDebugConsoleButton:se,showDiagnosticsButton:me,showClearDebugHighlightButton:j,showSelectionButton:be,showExportDialog:De,showRunButton:$e,showComponentManage:X,showDeployButton:b,showRestartButton:$,showReloadButton:Y,showRunHistory:ae,runHistoryUrl:L,showTraceButton:Ce,showDebugTab:Se,locale:oe,theme:he,coreOptions:Me,ruleItems:Ot,rulesApi:Dt,saveMode:ke??((kt=Q.current)==null?void 0:kt.saveMode)}),...ee,...qe,saveHandler:q?d.current.handler:void 0,onSave:H?d.current.legacyHandler:void 0,onSaveRequest:d.current.request,onSaveSuccess:d.current.success,onSaveError:d.current.error,onExternalDataConflict:d.current.conflict};co(Ie.current,He)||(Ie.current=He,v.updateOptions(He))}),e.useEffect(()=>{he&&Re.current&&Re.current.setTheme(he)},[he]),e.useEffect(()=>{w&&Re.current&&Re.current.updateOptions({data:w})},[w]),e.useEffect(()=>{Or(k)&&Re.current&&Re.current.updateOptions({components:k})},[k]),e.useImperativeHandle(r,()=>({get editor(){return Re.current},get lf(){var v;return((v=Re.current)==null?void 0:v.lf)??null},get core(){var v;return((v=Re.current)==null?void 0:v.core)??null},get capabilities(){var v;return((v=Re.current)==null?void 0:v.capabilities)??null},get connectionStatus(){var v;return((v=Re.current)==null?void 0:v.connectionStatus)??null},get runtimeFields(){var v;return((v=Re.current)==null?void 0:v.runtimeFields)??null},loadData(v,S){var q;(q=Re.current)==null||q.loadData(v,S)},activateWorkspaceTab(v){var S;return((S=Re.current)==null?void 0:S.activateWorkspaceTab(v))??!1},loadComponents(v){var S;(S=Re.current)==null||S.loadComponents(v)},exportData(){var v;return((v=Re.current)==null?void 0:v.exportData())??null},toggleMiniMap(){var v;(v=Re.current)==null||v.toggleMiniMap()},autoLayout(){var v;(v=Re.current)==null||v.autoLayout()},openSettings(v="user"){var S;(S=Re.current)==null||S.openSettings(v)},openAiAssistant(v){var S;(S=Re.current)==null||S.openAiAssistant(v)},closeAiAssistant(){var v;(v=Re.current)==null||v.closeAiAssistant()},startTour(){var v;return((v=Re.current)==null?void 0:v.startTour())??!1},closeTour(){var v;(v=Re.current)==null||v.closeTour()},setTheme(v){var S;(S=Re.current)==null||S.setTheme(v)},updateOptions(v){var S;return((S=Re.current)==null?void 0:S.updateOptions(v))??null},refreshConnectionStatuses(){var v;(v=Re.current)==null||v.refreshConnectionStatuses()},acquireSharedConnectionStatuses(){var v;return((v=Re.current)==null?void 0:v.acquireSharedConnectionStatuses())??(()=>{})},invokeAction(v,S="api"){const q=Re.current;return q?q.invokeAction(v,S):Promise.reject(new Error("Editor is not ready"))},openCommandPalette(){var v;(v=Re.current)==null||v.openCommandPalette()},openShortcutHelp(){var v;(v=Re.current)==null||v.openShortcutHelp()},openNodePicker(v){var S;(S=Re.current)==null||S.openNodePicker(v)},openComponentDocs(v){const S=Re.current;return S?S.openComponentDocs(v):Promise.reject(new Error("Editor is not ready"))},openComponentManager(v="installed"){var S;(S=Re.current)==null||S.openComponentManager(v)},closeOverlay(){var v;(v=Re.current)==null||v.closeOverlay()},closeAllOverlays(){var v;(v=Re.current)==null||v.closeAllOverlays()}}),[]);const 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:_t,className:`rulego-editor-wrapper ${i||""}`,"data-rg-theme":he||(xe==null?void 0:xe.theme)||"default",style:Fe}),Wt&&Ut.map(v=>ca.createPortal(Wt(v.type,v.data,v.model),v.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 _r(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 Xe(t={}){const n=_r(t.locale),r=new C.I18nManager({locale:n,fallback:n==="en-US"?"zh-CN":"en-US"});return r.register("zh-CN",C.localeZhCN),r.register("en-US",C.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 dr(t,n){const r=t(`relationTypes.${n}`,n);return r&&r!==n?`${r} (${n})`:n}const pn={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 C.buildComponentPalette(s,o,{categoryOrder:C.DEFAULT_COMPONENT_CATEGORY_ORDER,categoryLabel:i=>{const m=pn[i]||(i==="endpoints"?pn.endpoint:pn.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=pn[i.category]||(i.category==="endpoints"?pn.endpoint:pn.other);return{category:i.category,label:i.label,background:m.bg,iconUrl:C.resolveIconUrl(m.icon,{theme:r}),nodeIconUrl:C.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 D=C.normalizeIconTheme(M),[g,w]=e.useState(""),[E,k]=e.useState(new Set),[O,F]=e.useState(new Set),[A,W]=e.useState({}),_=e.useMemo(()=>Xe({locale:i,messages:m,t:f}),[i,m,f]),I=e.useMemo(()=>mo(t,_,D,g),[t,D,g,_]),P=s||_("editor.sidebar.search","搜索组件..."),y=g.trim().length>0,u=I.map(X=>X.category),te=I.flatMap(X=>X.subgroups.filter(b=>!!b.id).map(b=>`${X.category}/${b.id||"default"}`));e.useEffect(()=>{y&&(k(X=>{const b=new Set(X);return u.forEach($=>b.add($)),b}),F(X=>{const b=new Set(X);return te.forEach($=>b.delete($)),b}))},[y,u.join("|"),te.join("|")]);const re=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]),B=u.length>0&&u.every(X=>E.has(X)),U=X=>_(`components.${X.type}`,X.label||X.type.split("/").pop()||X.type),pe=X=>_(`fields.${X.type}`,X.desc||""),V=(X,b)=>X.icon?C.resolveIconUrl(String(X.icon),{theme:D}):b.nodeIconUrl,se={enabled:(N==null?void 0:N.enabled)!==!1,threshold:Math.max(1,(N==null?void 0:N.threshold)??C.DEFAULT_VIRTUAL_WINDOW_THRESHOLD),itemHeight:Math.max(1,(N==null?void 0:N.itemHeight)??C.DEFAULT_VIRTUAL_WINDOW_ITEM_HEIGHT),viewportHeight:Math.max(1,(N==null?void 0:N.viewportHeight)??C.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),overscan:Math.max(0,(N==null?void 0:N.overscan)??C.DEFAULT_VIRTUAL_WINDOW_OVERSCAN)},me=(X,b,$)=>{if(!(se.enabled&&X.length>se.threshold))return X.map($);const ae=C.calculateVirtualWindow({total:X.length,itemHeight:se.itemHeight,viewportHeight:se.viewportHeight,scrollTop:A[b]||0,overscan:se.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:`${ae.viewportHeight}px`},onScroll:L=>{const Ce=L.currentTarget.scrollTop;W(Se=>Se[b]===Ce?Se:{...Se,[b]:Ce})}},e.createElement("div",{className:"rge-sidebar-virtual-list__canvas",style:{height:`${ae.totalHeight}px`}},e.createElement("div",{className:"rge-sidebar-virtual-list__items",style:{transform:`translateY(${ae.offsetTop}px)`}},X.slice(ae.start,ae.end).map($))))},j=X=>{k(b=>{const $=new Set(b);return $.has(X)?$.delete(X):$.add(X),$})},be=X=>{F(b=>{const $=new Set(b);return $.has(X)?$.delete(X):$.add(X),$})},De=()=>{if(u.length!==0){if(B){k(new Set),F(new Set);return}k(new Set(u)),F(new Set)}},$e=(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":D},e.createElement("div",{className:"rge-sidebar-search"},e.createElement("span",{className:"rge-search-icon","aria-hidden":"true"}),e.createElement("input",{type:"text",placeholder:P,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:_(B?"editor.sidebar.collapseAll":"editor.sidebar.expandAll",B?"全部折叠":"全部展开"),"aria-label":_(B?"editor.sidebar.collapseAll":"editor.sidebar.expandAll",B?"全部折叠":"全部展开"),"aria-pressed":B,disabled:u.length===0,onClick:De},B?"↙":"↗")),e.createElement("div",{className:"rge-sidebar-groups"},re.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"},_("editor.sidebar.recentComponents","最近使用")),e.createElement("span",{className:"rge-group-count"},re.length)),e.createElement("div",{className:"rge-group-content"},re.map(X=>{const b=I.find(ae=>ae.components.some(L=>L.type===X.type));if(!b)return null;const $=U(X),Y=pe(X);return e.createElement("div",{key:X.type,className:"rge-node-block",draggable:!0,onDragStart:ae=>$e(ae,X),style:{backgroundColor:X.background||b.background},title:`${X.type}
2
- ${Y||$}`},e.createElement("div",{className:"rge-node-block__icon"},e.createElement("img",{src:V(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,$=E.has(b),Y=X.subgroups.some(L=>!!L.id),ae=L=>{const Ce=L.background||X.background,Se=U(L),oe=pe(L),he=V(L,X);return e.createElement("div",{key:L.type,className:"rge-node-block",draggable:!0,onDragStart:Te=>$e(Te,L),style:{backgroundColor:Ce},title:`${L.type}
3
- ${oe||Se}`},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"},Se),!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:()=>j(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&&me(X.components,b,ae),Y&&X.subgroups.map(L=>{const Ce=`${b}/${L.id||"default"}`,Se=!O.has(Ce);return e.createElement("section",{key:Ce,className:"rge-sidebar-subgroup"},e.createElement("button",{type:"button",className:"rge-subgroup-header",onClick:()=>be(Ce),"aria-expanded":Se,title:L.description||L.label},e.createElement("span",{className:`rge-subgroup-arrow ${Se?"rotated":""}`},"›"),e.createElement("span",null,L.label),e.createElement("small",null,L.components.length)),Se&&e.createElement("div",{className:"rge-subgroup-content"},me(L.components,Ce,ae)))})))}),I.length===0&&e.createElement("div",{className:"rge-sidebar-empty"},e.createElement("img",{src:C.resolveIconUrl("images/common.svg",{theme:D}),alt:"",className:"rge-empty-icon"}),e.createElement("p",null,_("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 Kt=({name:t,value:n="",values:r,options:o=[],multiple:s=!1,allowCreate:i=!1,disabled:m=!1,placeholder:f="",searchPlaceholder:M="搜索选项...",noMatchText:N="没有匹配的选项",createOptionText:D="使用",selectedCountText:g="已选 {{count}} 项",resultCountText:w="显示 {{shown}} / {{total}} 项",moreOptionsText:E="结果较多,请继续输入关键词缩小范围",className:k="rge-form-select",threshold:O=po,maxVisibleOptions:F=Fr,onChange:A,onMultiChange:W})=>{const _=e.useRef(null),I=e.useRef(null),[P,y]=e.useState(!1),[u,te]=e.useState(""),[re,B]=e.useState(0),U=e.useMemo(()=>o.map(go),[o]),pe=U.some(J=>J.value===""),V=i||U.length>O,se=e.useMemo(()=>r||(s&&n?n.split(",").map(J=>J.trim()).filter(Boolean):[]),[s,n,r]),me=U.find(J=>J.value===n),j=se.map(J=>{var Oe;return((Oe=U.find(Ze=>Ze.value===J))==null?void 0:Oe.label)||J}).filter(Boolean),be=j.length,De=be>0?Br(g,{count:be}):"",$e=j.slice(0,2).join(", "),X=s?be?`${De}: ${$e}${j.length>2?" ...":""}`:f:(me==null?void 0:me.label)||n||f,b=s?j.length?j.join(", "):f:X,$=u.trim().toLowerCase(),Y=e.useMemo(()=>$?U.filter(J=>J.label.toLowerCase().includes($)||J.value.toLowerCase().includes($)||String(J.description||"").toLowerCase().includes($)):U,[$,U]),ae=Math.max(1,Number(F)||Fr),L=e.useMemo(()=>Y.slice(0,ae),[Y,ae]),Ce=Math.max(0,Y.length-L.length),Se=Br(w,{shown:L.length,total:Y.length,selected:be,hidden:Ce}),oe=u.trim(),he=i&&!s&&oe.length>0&&!U.some(J=>J.value.toLowerCase()===$||J.label.toLowerCase()===$),Te=L.length+(he?1:0);e.useEffect(()=>{if(!P)return;const J=Ze=>{var z;(z=_.current)!=null&&z.contains(Ze.target)||Ee()},Oe=Ze=>{Ze.key==="Escape"&&Ee()};return document.addEventListener("mousedown",J),document.addEventListener("keydown",Oe),()=>{document.removeEventListener("mousedown",J),document.removeEventListener("keydown",Oe)}},[P]),e.useEffect(()=>{P&&window.setTimeout(()=>{var J;return(J=I.current)==null?void 0:J.focus()},0)},[P]),e.useEffect(()=>{if(!P)return;const J=L.findIndex(Oe=>s?se.includes(Oe.value):Oe.value===n);B(J>=0?J:0)},[P,u,s,se,n,L]);const Ee=()=>{y(!1),te(""),B(0)},Me=()=>{m||(y(!0),te(""))},xe=J=>{W==null||W(J)},ce=J=>{const Oe=se.includes(J)?se.filter(Ze=>Ze!==J):[...se,J];xe(Oe)},le=J=>{A(J),Ee()},ke=()=>{if(!(!P||Te<=0)){if(re<L.length){const J=L[re];if(!J)return;if(s){ce(J.value);return}le(J.value);return}he&&le(oe)}},ye=J=>{if(!m){if(!P&&["ArrowDown","Enter"," "].includes(J.key)){J.preventDefault(),Me();return}P&&(J.key==="ArrowDown"?(J.preventDefault(),B(Oe=>Math.min(Te-1,Oe+1))):J.key==="ArrowUp"?(J.preventDefault(),B(Oe=>Math.max(0,Oe-1))):J.key==="Home"?(J.preventDefault(),B(0)):J.key==="End"?(J.preventDefault(),B(Math.max(0,Te-1))):J.key==="Enter"?(J.preventDefault(),ke()):J.key==="Escape"&&(J.preventDefault(),Ee()))}};return V?e.createElement("div",{className:"rge-search-select",ref:_,"data-searchable-select":t||void 0},e.createElement("button",{type:"button",className:`rge-search-select-trigger ${k}`,disabled:m,"aria-haspopup":"listbox","aria-expanded":P,"aria-multiselectable":s||void 0,"data-selected-count":be,title:b,onKeyDown:ye,onClick:()=>{m||(P?Ee():Me())}},e.createElement("span",{className:`rge-search-select-display${X&&X!==f?"":" is-placeholder"}`},s&&be>0&&e.createElement("span",{className:"rge-search-select-count"},De),e.createElement("span",{className:"rge-search-select-display-text"},s&&be>0?$e:X||f)),e.createElement("span",{className:"rge-search-select-arrow"},"▾")),P&&e.createElement("div",{className:"rge-search-select-popover",role:"listbox"},e.createElement("input",{ref:I,className:"rge-search-select-input",value:u,onChange:J=>{te(J.target.value),B(0)},onKeyDown:ye,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,Oe)=>e.createElement("button",{type:"button",key:J.value,className:`rge-search-select-option${(s?se.includes(J.value):J.value===n)?" selected":""}${Oe===re?" active":""}`,role:"option","aria-selected":s?se.includes(J.value):J.value===n,onMouseEnter:()=>B(Oe),onClick:()=>{if(s){ce(J.value);return}le(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${re===L.length?" active":""}`,role:"option","aria-selected":!1,onMouseEnter:()=>B(L.length),onClick:()=>{le(oe)}},e.createElement("span",{className:"rge-search-select-label"},D," ",oe))),e.createElement("div",{className:"rge-search-select-footer","data-searchable-select-count":!0},e.createElement("span",null,Se),Ce>0&&e.createElement("span",{className:"rge-search-select-more"},E)))):s?e.createElement("select",{className:k,value:se,multiple:!0,onChange:J=>{xe(Array.from(J.target.selectedOptions).map(Oe=>Oe.value))},disabled:m},U.map(J=>e.createElement("option",{key:J.value,value:J.value},J.label))):e.createElement("select",{className:k,value:n,onChange:J=>A(J.target.value),disabled:m},f&&!pe&&e.createElement("option",{value:""},f),U.map(J=>e.createElement("option",{key:J.value,value:J.value},J.label)))};Kt.displayName="SearchableSelect";const fe=({value:t,className:n=""})=>{const r=typeof t=="string"?C.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 _n(t){if(t==null)return t;if(Array.isArray(t))return t.map(n=>_n(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]=_n(o)}),n}return t}const Lt=t=>String(t.type||"").toLowerCase(),pr=t=>String(t||"").toLowerCase().includes("float"),da=t=>{const n=String(t||"").toLowerCase();return n==="number"||n.includes("int")||n.includes("float")},mt=t=>{var n;return String(((n=t.component)==null?void 0:n.type)||"").toLowerCase()},Kn=t=>{var n;return String(((n=t.component)==null?void 0:n.source)||"").toLowerCase()},zn=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)),gr=(t,n)=>{const r=[...t],o=new Set(r.map(zn));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:zn(i),description:fo(i)}))},gn=t=>{var n;return mt(t)==="select"||Lt(t)==="select"||Kn(t)==="nodes"||Kn(t)==="rulechains"||Array.isArray((n=t.component)==null?void 0:n.options)&&!ho(t.component.options)||Array.isArray(t.options)},Eo=t=>mt(t)==="rulechainselector"||Kn(t)==="rulechains",Gn=t=>mt(t)==="switch"||["boolean","bool"].includes(Lt(t)),Hr=t=>["textarea","json-editor"].includes(mt(t))||["textarea","json"].includes(Lt(t)),Tn=t=>{const n=mt(t),r=Lt(t),o=t.name.toLowerCase();return n==="password"||r==="password"||/password|passwd|secret|token|api[_-]?key|private[_-]?key|pem/.test(o)},Yn=t=>da(t.type)||["input-number","slider"].includes(mt(t)),fr=t=>{const n=mt(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("执行")},Hn=t=>t.name==="jsScript"||t.name==="JsScript"||t.name==="script"||t.name.toLowerCase()==="template"||fr(t)||["codeeditor","code-editor","code","javascript","sql","monaco","json-editor","command","shell"].includes(mt(t))||["jsscript","json"].includes(Lt(t)),Wr=t=>t==null?"":typeof t=="object"?JSON.stringify(t,null,2):String(t),Ur=t=>mt(t)==="switchnode",fn=t=>{const n=mt(t);return n==="tools"||n==="subagents"},Vr=t=>mt(t)==="subagents"?"subagent":"tool",Yt=t=>{const n=Lt(t),r=mt(t);return n==="array"||r==="array"||r==="table"},qr=t=>{const n=Lt(t),r=mt(t);return n==="struct"||n==="object"||r==="struct"||r==="object"},sn=t=>Lt(t)==="map"||mt(t)==="map",Jr=t=>{const n=mt(t),r=Lt(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(mt(t)),zr=t=>Lt(t)==="duration"||mt(t)==="duration",kn=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):[]},bn=(t,n)=>{if(!Yt(t))return!1;if(kn(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 hn=(t,n)=>n===t||n.startsWith(`${t}.`);function ko({field:t,value:n,onChange:r,onChildChange:o,translate:s}){const i=kn(t),m=C.decodeTableRowsForEditing(i,n),f=b=>r(C.encodeTableRowsForStorage(i,b)),M=C.getTableColumns(i,m),N=C.getTableDetailFields(i),D=i.some(b=>String(b.name).trim().toLowerCase()==="type"),[g,w]=e.useState(1),[E,k]=e.useState(50),[O,F]=e.useState(""),[A,W]=e.useState([]),[_,I]=e.useState(null),[P,y]=e.useState(""),[u,te]=e.useState({prefix:"",start:0,count:10,step:1,type:"",namePrefix:""}),re=C.findDuplicateRowValues(m),B=m.map((b,$)=>({row:b,index:$})).filter(({row:b})=>{const $=O.trim().toLowerCase();return $?M.some(Y=>String(b[Y]??"").toLowerCase().includes($)):!0}),U=C.paginateTableRows(B,g,E);e.useEffect(()=>{w(b=>Math.min(b,U.totalPages)),W(b=>b.filter($=>$>=0&&$<m.length)),I(b=>b!==null&&b>=m.length?null:b)},[m.length,U.totalPages]);const pe=(b,$,Y)=>{const ae=i.find(oe=>oe.name===$),L=C.coerceTableCellValue(ae,Y),Ce=m.map((oe,he)=>he===b?{...oe,[$]:L}:oe),Se=f(Ce);ae&&o(ae,`${t.name}.${b}.${$}`,L,Se)},V=(b,$,Y)=>{var Te,Ee;const ae=i.find(Me=>Me.name===Y),L=b[Y]??"",Ce=String(L),Se=ae?mt(ae):"",oe=Array.isArray((Te=ae==null?void 0:ae.component)==null?void 0:Te.options)?ae.component.options:Array.isArray(ae==null?void 0:ae.options)?ae.options:[];if(!!(ae&&Se==="select"&&!((Ee=ae.component)!=null&&Ee.allowCreate))){const Me=gr(oe,L),xe=Ce===""&&!Me.some(ce=>ce.value==="")?[{label:"",value:""},...Me]:Me;return e.createElement("select",{className:"rge-form-input",value:Ce,"data-point-cell":Y,onChange:ce=>pe($,Y,ce.target.value)},xe.map(ce=>e.createElement("option",{key:ce.value,value:ce.value},ce.label)))}return ae&&Gn(ae)?e.createElement("input",{type:"checkbox",checked:!!L,"data-point-cell":Y,onChange:Me=>pe($,Y,Me.target.checked)}):e.createElement("input",{className:"rge-form-input",type:ae&&Yn(ae)?"number":"text",value:Ce,"data-point-cell":Y,onChange:Me=>pe($,Y,Me.target.value)})},se=()=>{f([...m,C.createEmptyTableRow(i)]),w(Math.max(1,Math.ceil((m.length+1)/E))),N.length>0&&I(m.length)},me=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((ae,L)=>!Y.has(L))),W([]),I(null)},j=b=>{if(!b)return;y("");const $=new FileReader;$.onload=()=>{const Y=C.parseCsvTable(String($.result||""));if(Y.length===0)return;(!C.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)},be=async b=>{if(b){y("");try{const $=await C.parseExcelTable(await b.arrayBuffer());if($.length===0){y(s("editor.property.emptyExcelTable","Excel 中没有有效数据"));return}(!C.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($){y(s("editor.property.excelImportFailed","Excel 导入失败: {{message}}",{message:$ instanceof Error?$.message:String($)}))}}},De=()=>{y("");const b=C.serializeCsvTable(m,M),$=new Blob([`\uFEFF${b}`],{type:"text/csv;charset=utf-8"}),Y=URL.createObjectURL($),ae=document.createElement("a");ae.href=Y,ae.download=`${t.name||"table"}.csv`,ae.click(),URL.revokeObjectURL(Y)},$e=async()=>{y("");try{const b=await C.serializeExcelTable(m,M),$=b.buffer.slice(b.byteOffset,b.byteOffset+b.byteLength),Y=new Blob([$],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),ae=URL.createObjectURL(Y),L=document.createElement("a");L.href=ae,L.download=`${t.name||"table"}.xlsx`,L.click(),URL.revokeObjectURL(ae)}catch(b){y(s("editor.property.excelExportFailed","Excel 导出失败: {{message}}",{message:b instanceof Error?b.message:String(b)}))}},X=()=>{const b=C.generatePointRows({...u,type:D?u.type:void 0,existing:m});b.length>0&&f([...m,...b]),w(Math.max(1,Math.ceil((m.length+b.length)/E)))};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:O,placeholder:s("editor.property.searchTable","搜索表格"),onChange:b=>{F(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 $;j(($=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="",be($)}})),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:De,disabled:m.length===0},s("editor.property.exportCsv","导出 CSV")),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:()=>{$e()},disabled:m.length===0},s("editor.property.exportExcel","导出 Excel")),e.createElement("button",{type:"button",className:"rge-btn-secondary",onClick:()=>me(A),disabled:A.length===0},s("editor.property.deleteSelected","删除所选")),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:se},s("editor.panel.addPair","+ 添加"))),P&&e.createElement("span",{className:"rge-point-table-error",role:"alert"},P)),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=>te({...u,prefix:b.target.value})}),e.createElement("input",{className:"rge-form-input",type:"number",value:u.start,placeholder:s("editor.property.pointStart","起始编号"),onChange:b=>te({...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=>te({...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=>te({...u,step:Math.max(1,Number(b.target.value)||1)})}),D&&e.createElement("input",{className:"rge-form-input",value:u.type,placeholder:s("editor.property.pointType","数据类型"),onChange:b=>te({...u,type:b.target.value})}),e.createElement("input",{className:"rge-form-input",value:u.namePrefix,placeholder:s("editor.property.pointNamePrefix","名称前缀"),onChange:b=>te({...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:U.items.length>0&&U.items.every(b=>A.includes(b.index)),onChange:b=>W(b.target.checked?[...new Set([...A,...U.items.map($=>$.index)])]:A.filter($=>!U.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,U.items.map(({row:b,index:$})=>e.createElement(e.Fragment,{key:$},e.createElement("tr",{className:re.has(String(b.name??"").trim())?"is-duplicate":void 0},e.createElement("td",null,e.createElement("input",{type:"checkbox",checked:A.includes($),onChange:Y=>W(ae=>Y.target.checked?[...new Set([...ae,$])]:ae.filter(L=>L!==$))})),M.map(Y=>e.createElement("td",{key:Y},V(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":_===$,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:()=>me([$])},"×"))),N.length>0&&_===$&&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),V(b,$,Y.name),tn(Y.desc)&&e.createElement("small",null,tn(Y.desc))))))))))),U.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",`共 ${U.total} 条`,{count:String(U.total)})),e.createElement("select",{value:E,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,U.page," / ",U.totalPages),e.createElement("button",{type:"button",disabled:g>=U.totalPages,onClick:()=>w(b=>b+1)},s("editor.property.nextPage","下一页"))))}const No=(t,n)=>{const r=kn(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(Gn(t))return!!n;if(Yn(t)){const r=String(n??"");return r?pr(t.type)||Lt(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},br=12,En=(t=br)=>({items:[],total:0,page:1,size:t,loading:!1,error:""}),Xn=(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}},hr=t=>{if(!t||typeof t!="object")return Xn(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 Xn(s,o,r)},Wn=(t,n,r)=>{const o=C.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`:""},Un=(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,D=String(N.id||f.id||"").trim();if(!D||D===r||o.has(D))continue;const g=typeof f.text=="object"?(i=f.text)==null?void 0:i.value:f.text,w=fa(N.name||g||D,D);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=Xn(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=Xn(pa(o),zn(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,yn=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=yn(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),ar=(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 C.stringifyToolJson(r,"{}")},or=t=>{var s;if(!t||typeof t!="object")return hr(t);const n=t,r=n.ruleChain&&typeof n.ruleChain=="object"?n.ruleChain:n,o=hr(n);return o?{...o,description:o.description||String(((s=r.additionalInfo)==null?void 0:s.description)||r.description||r.desc||""),raw:r}:null},lr=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)=>C.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=C.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:D,rulesApi:g,apiBase:w,rulePageSize:E,fetchRuleChains:k,componentsPayload:O,componentPayload:F,builtinTools:A,tools:W,skillPath:_,fetchBuiltinTools:I,onOpenAiAssistant:P,aiProviders:y,aiEmbeddingProviders:u,resolveFieldsByType:te,optionSourceRegistry:re,fieldChangeRegistry:B,onFieldChangeError:U,initializeDefaults:pe=!1})=>{var Ar;const[V,se]=e.useState({}),[me,j]=e.useState("{}"),[be,De]=e.useState(""),[$e,X]=e.useState({}),[b,$]=e.useState({}),[Y,ae]=e.useState({}),[L,Ce]=e.useState("custom"),[Se,oe]=e.useState(""),[he,Te]=e.useState("custom"),[Ee,Me]=e.useState(""),[xe,ce]=e.useState([]),[le,ke]=e.useState(null),[ye,J]=e.useState(()=>En()),[Oe,Ze]=e.useState({}),[z,Ge]=e.useState(null),[dt,ot]=e.useState([]),[Ht,Ft]=e.useState(!1),[Bt,Rt]=e.useState(""),[Ct,rt]=e.useState(()=>En()),[Mt,Ve]=e.useState({}),[$t,wt]=e.useState(""),[At,yt]=e.useState(""),[Ot,Dt]=e.useState({}),[Wt,_t]=e.useState(0),[Re]=e.useState(()=>`react-drawer-${++Co}`),Ut=e.useRef(""),pt=e.useRef({}),Be=e.useRef({}),ne=e.useRef({}),Q=e.useRef(null),_e=e.useRef(new Map),Ne=e.useRef({}),Le=e.useRef(new Set),Je=e.useRef(new Set),St=e.useRef(""),Ie=e.useMemo(()=>new C.OptionSourceRegistry,[]),d=e.useMemo(()=>Xe({locale:i,messages:m,t:f}),[i,m,f]);pt.current=V,Be.current=$e,ne.current=b,St.current=String((n==null?void 0:n.nodeId)||(n==null?void 0:n.id)||"");const ve=e.useCallback(a=>{const l=a(pt.current);return pt.current=l,se(l),l},[]),Fe=e.useCallback(a=>{const l=a(Be.current);return Be.current=l,X(l),l},[]),v=e.useCallback(a=>{const l=a(ne.current);return ne.current=l,$(l),l},[]);e.useEffect(()=>{var l;const a=new AbortController;return(l=Q.current)==null||l.abort(),Q.current=a,_e.current.clear(),_t(0),Ne.current={},Je.current.clear(),Dt({}),()=>{a.abort(),Q.current===a&&(Q.current=null)}},[B,n==null?void 0:n.id,n==null?void 0:n.nodeId,t]);const S=e.useCallback(a=>{if(typeof window>"u")return;const l=d("editor.property.confirmDeleteRows","确认删除 1 行?",{count:"1"});window.confirm(l)&&a()},[d]),q=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]),H=e.useCallback(a=>uo(a,d,f,m),[m,f,d]),ee=e.useMemo(()=>xo(M,n),[M,n]),qe=e.useMemo(()=>Ro(N),[N]),He=e.useMemo(()=>Math.max(1,Number(E||br)||br),[E]),it=e.useMemo(()=>So(g,w),[w,g]),et=!!(k||it),kt=e.useMemo(()=>C.getBuiltinToolOptionsFromSources(A,W,O,F),[A,F,O,W]),je=e.useMemo(()=>dt.length>0?dt:kt,[dt,kt]),ut=e.useMemo(()=>C.getSkillPathFromSources(_,O,F),[F,O,_]),Vt=e.useMemo(()=>qe.map(a=>({label:a.label,value:a.value})),[qe]),lt=e.useMemo(()=>To(D),[D]),It=e.useCallback(a=>r?C.resolveComponentFields(r,{configuration:a,getFieldsByType:te}):[],[r,te]),Qe=e.useMemo(()=>It(V.configuration||(n==null?void 0:n.configuration)||{}),[V.configuration,n==null?void 0:n.configuration,It]),cn=e.useMemo(()=>C.getVisibleComponentFields(Qe,V.configuration||{}),[V.configuration,Qe]),nn=e.useMemo(()=>C.buildFieldAttachments(Qe),[Qe]),Ln=e.useMemo(()=>new Set([...nn.values()].flatMap(a=>a.map(l=>l.field.name))),[nn]);Le.current=Ln;const un=$t?nn.get($t)||[]:[],Mn=un.filter(a=>C.isFieldDependencySatisfied(a.field,V.configuration)),$n=new Set(un.map(a=>a.field.name)),rn=[..._e.current.keys()].filter(a=>[...$n].some(l=>hn(l,a))).length,zt=Object.entries(Ot).filter(([a])=>Je.current.has(a)||[...Ln].some(l=>hn(l,a))),An=zt.filter(([a])=>[...$n].some(l=>hn(l,a))),K=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=cn.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),h=cn.filter(p=>!l.has(p.name));return h.length>0&&c.unshift({id:"",label:"",description:void 0,collapsed:!1,fields:h}),c},[r==null?void 0:r.groups,cn]),de=e.useMemo(()=>Qe.find(a=>a.ref==="primary")||null,[Qe]),ie=e.useMemo(()=>de?null:Qe.find(a=>a.aiProvider||a.name==="provider")||null,[de,Qe]),we=e.useMemo(()=>{var a,l,c;return{provider:((a=ie==null?void 0:ie.aiProvider)==null?void 0:a.providerField)||(ie==null?void 0:ie.name)||"provider",url:((l=ie==null?void 0:ie.aiProvider)==null?void 0:l.urlField)||"url",model:((c=ie==null?void 0:ie.aiProvider)==null?void 0:c.modelField)||"model"}},[ie]),We=e.useMemo(()=>ie?(ie.providerType==="embedding"?C.getAiEmbeddingProviders(u):C.getAiProviders(y)).map(l=>jr(l,d)).filter(Boolean):[],[u,y,ie,d]),st=e.useCallback(a=>{var p;const l=Mt[a.name];if(a.optionsSource&&(l!=null&&l.options))return l.options;if(a.name===we.model&&xe.length>0)return xe;const c=((p=a.component)==null?void 0:p.options)||a.options||[],h=Kn(a);return h==="nodes"&&ee.length>0?ee:h==="rulechains"&&Vt.length>0?Vt:c},[ee,Mt,we.model,xe,Vt]),tt=e.useMemo(()=>C.buildOptionSourceRequestKey(Qe,{configuration:V.configuration||{},currentNodeId:String((n==null?void 0:n.nodeId)||(n==null?void 0:n.id)||""),graphNodes:(M||[]).map(a=>{var l,c,h;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||((h=(c=a.properties)==null?void 0:c.model)==null?void 0:h.type)||"")}}).filter(a=>!!a.id)}),[V.configuration,M,n==null?void 0:n.id,n==null?void 0:n.nodeId,Qe]);e.useEffect(()=>{const a=Qe.filter(R=>R.optionsSource);if(a.length===0){Ve({});return}const l=new AbortController,c=re||Ie,h=V.configuration||{},p=String((n==null?void 0:n.nodeId)||(n==null?void 0:n.id)||""),T=(M||[]).map(R=>{var x,G,Z;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||((Z=(G=R.properties)==null?void 0:G.model)==null?void 0:Z.type)||"")}}).filter(R=>!!R.id);return Ve(R=>Object.fromEntries(a.map(x=>{var G,Z;return[x.name,{options:((G=R[x.name])==null?void 0:G.options)||((Z=x.component)==null?void 0:Z.options)||x.options||[],loading:!0,error:""}]}))),Promise.all(a.map(async R=>{try{const x=await c.resolve(R,{configuration:h,currentNodeId:p,graphNodes:T,signal:l.signal});if(l.signal.aborted)return;Ve(G=>({...G,[R.name]:{options:x,loading:!1,error:""}}))}catch(x){if(l.signal.aborted)return;Ve(G=>{var Z,ue;return{...G,[R.name]:{options:((Z=G[R.name])==null?void 0:Z.options)||((ue=R.component)==null?void 0:ue.options)||R.options||[],loading:!1,error:x instanceof Error?x.message:String(x)}}})}})),()=>l.abort()},[Ie,re,tt]);const Ye=e.useCallback((a,l,c=!1)=>{const h=gr(st(a),l);return!c||!lt?h:h.filter(p=>p.value!==lt)},[lt,st]),gt=e.useCallback((a,l)=>{var R;const h=[...qe.length>0?qe:Io(((R=a.component)==null?void 0:R.options)||a.options||[])],p=new Set(h.map(x=>x.value));Object.values(Oe).forEach(x=>{p.has(x.value)||(h.push(x),p.add(x.value))});const T=String(l??"").trim();return T&&!p.has(T)&&h.push({label:T,value:T}),h},[Oe,qe]),ct=e.useCallback((a,l)=>{var h;const c=String(l??"").trim();return c?((h=gt(a,c).find(p=>p.value===c))==null?void 0:h.label)||c:""},[gt]),vt=e.useCallback(()=>{const a=Object.values(Oe).map(c=>({...c})),l=qe.map(c=>({...c}));return lr([...l,...a].map(or).filter(Boolean)).filter(c=>!lt||c.value!==lt)},[lt,Oe,qe]),ft=e.useMemo(()=>de?Ye(de,Se):[],[Ye,de,Se]);e.useEffect(()=>{var at,jt,qt;if(!n)return;const a=_n(n.configuration||{}),l=It(a);pe&&l.forEach(Ke=>{!(Ke.name in a)&&Ke.defaultValue!==void 0&&(a[Ke.name]=_n(Ke.defaultValue))});const c={id:n.id||"",nodeId:n.nodeId||"",type:n.type||"",name:n.name||"",debugMode:n.debugMode||!1,configuration:a,additionalInfo:n.additionalInfo||{}};pt.current=c,se(c);const h={},p={},T=new Map(l.map(Ke=>[Ke.name,Ke]));Object.entries(a).forEach(([Ke,ze])=>{const nt=T.get(Ke);nt&&Yt(nt)&&!(gn(nt)||Ur(nt)||bn(nt,ze)||fn(nt))&&(Array.isArray(ze)||typeof ze=="string")?p[Ke]=C.normalizeSimpleArrayValues(ze).map(Zt=>({value:Zt})):nt&&sn(nt)&&!Array.isArray(ze)&&ze&&typeof ze=="object"&&!(ze instanceof Date)&&(h[Ke]=Object.entries(ze).map(([Zt,nr])=>({key:Zt,value:C.formatMapEntryValue(nr,C.getMapValueMode(nt))})))}),Be.current=h,ne.current=p,X(h),$(p),ae({});const R=l.find(Ke=>Ke.ref==="primary"),x=R!=null&&R.name?a[R.name]:"",G=String(x??""),Z=G.startsWith("ref://");Ce(Z?"shared":"custom"),oe(Z?G:"");const ue=R?null:l.find(Ke=>Ke.aiProvider||Ke.name==="provider")||null,ge={provider:((at=ue==null?void 0:ue.aiProvider)==null?void 0:at.providerField)||(ue==null?void 0:ue.name)||"provider",url:((jt=ue==null?void 0:ue.aiProvider)==null?void 0:jt.urlField)||"url",model:((qt=ue==null?void 0:ue.aiProvider)==null?void 0:qt.modelField)||"model"},Ue=ue?(ue.providerType==="embedding"?C.getAiEmbeddingProviders(u):C.getAiProviders(y)).map(Ke=>jr(Ke,d)).filter(Boolean):[],Ae={...a};if(ue){const Ke=String(a[ge.provider]??""),ze=Ue.find(Zt=>Zt.value===Ke),nt=!!(ze&&Ke!=="custom");Te(nt?"preset":"custom"),Me(nt?Ke:""),ce(nt?(ze==null?void 0:ze.models)||[]:[]),nt&&(Ae[ge.provider]=Ke,ze!=null&&ze.url&&(Ae[ge.url]=ze.url),ze!=null&&ze.defaultModel&&!Ae[ge.model]&&(Ae[ge.model]=ze.defaultModel))}else Te("custom"),Me(""),ce([]);ke(null),J(En(He)),Ge(null),rt(En(He)),j(JSON.stringify(a,null,2)),De(""),wt(""),yt(""),Ut.current=JSON.stringify(C.normalizeEditableNodeModel(n,{name:n.name||"",debugMode:n.debugMode||!1,configuration:Ae,additionalInfo:n.additionalInfo||{}},{graphNodeId:n.id||n.nodeId||"",nodeViewType:r==null?void 0:r.type,graphNodeType:n.type,keepNodeId:!0}))},[pe,n,r,It]),e.useEffect(()=>{if(he!=="preset"||!Ee)return;const a=We.find(l=>l.value===Ee);a&&ce(a.models||[])},[he,We,Ee]),e.useEffect(()=>{kt.length!==0&&(ot(kt),Rt(""))},[kt]);const an=e.useCallback((a,l)=>{ve(c=>({...c,[a]:l}))},[ve]),xt=e.useCallback(()=>{const a={...pt.current.configuration||{}},l=new Map(Qe.map(c=>[c.name,c]));return Object.entries(Be.current).forEach(([c,h])=>{const p=l.get(c);if(!p||!sn(p))return;const T={},R=C.getMapValueMode(p);h.forEach(x=>{x.key&&(T[x.key]=C.parseMapEntryValue(x.value,R))}),a[c]=T}),Object.entries(ne.current).forEach(([c,h])=>{const p=l.get(c);!p||!Yt(p)||bn(p,a[c])||fn(p)||gn(p)||(a[c]=h.map(T=>T.value).filter(Boolean))}),a},[Qe]),bt=e.useCallback((a,l)=>{const c={...xt(),[a]:l};return ve(h=>({...h,configuration:c})),c},[xt,ve]),Gt=e.useCallback(a=>{const l=xt();for(const p of a.remove||[])delete l[p];Object.assign(l,_n(a.patch||{})),ve(p=>({...p,configuration:l}));const c=new Set([...Object.keys(a.patch||{}),...a.remove||[]]),h=new Map(Qe.map(p=>[p.name,p]));if([...c].some(p=>sn(h.get(p)||{}))&&Fe(p=>{const T={...p};return c.forEach(R=>{const x=h.get(R);if(!x||!sn(x))return;const G=l[R];!G||typeof G!="object"||Array.isArray(G)?delete T[R]:T[R]=Object.entries(G).map(([Z,ue])=>({key:Z,value:C.formatMapEntryValue(ue,C.getMapValueMode(x))}))}),T}),[...c].some(p=>{const T=h.get(p);return T&&Yt(T)&&!bn(T,l[p])&&!fn(T)&&!gn(T)})&&v(p=>{const T={...p};return c.forEach(R=>{const x=h.get(R);!x||!Yt(x)||bn(x,l[R])||fn(x)||gn(x)||(Object.prototype.hasOwnProperty.call(l,R)?T[R]=C.normalizeSimpleArrayValues(l[R]).map(G=>({value:G})):delete T[R])}),T}),de!=null&&de.name&&c.has(de.name)){const p=String(l[de.name]??"");oe(p.startsWith("ref://")?p:""),Ce(p.startsWith("ref://")?"shared":"custom")}if(c.has(we.provider)){const p=String(l[we.provider]??""),T=We.find(R=>R.value===p);Te(T&&p!=="custom"?"preset":"custom"),Me(T&&p!=="custom"?p:""),ce((T==null?void 0:T.models)||[])}},[xt,de,we.provider,We,v,ve,Fe,Qe]),Nt=e.useCallback((a,l,c,h)=>{const p=C.getFieldChangeHandlerName(a);if(!p)return;const T=St.current,R=Q.current,x=(ge,Ue=0)=>{if(R!=null&&R.signal.aborted||St.current!==T)return;const Ae=ge instanceof Error?ge.message:String(ge);(Le.current.has(a.name)||a.attachTo)&&Je.current.add(l);const at={...Ne.current,[l]:Ae};Ne.current=at,Dt(at),U==null||U(ge,{field:a,fieldPath:l,handlerName:p,generation:Ue})};if(!B||!R){x(new Error(d("editor.property.fieldChangeUnavailable","字段联动处理器不可用: {{name}}",{name:p})));return}Je.current.delete(l);const G={...Ne.current};delete G[l],Ne.current=G,Dt(G);const Z=(M||[]).map(ge=>{var Ue,Ae,at;return{id:String(ge.id||ge.nodeId||""),name:String(ge.name||(typeof ge.text=="object"?(Ue=ge.text)==null?void 0:Ue.value:ge.text)||ge.id||ge.nodeId||""),type:String(ge.type||((at=(Ae=ge.properties)==null?void 0:Ae.model)==null?void 0:at.type)||"")}}).filter(ge=>!!ge.id);let ue;ue=B.execute(a,c,{configuration:h,currentNodeId:T,graphNodes:Z,requestKey:`${Re}:${T||"__draft__"}:${l}`,signal:R.signal,fieldPath:l}).then(ge=>{ge.status!=="applied"||R.signal.aborted||St.current!==T||Gt(ge)}).catch(ge=>{R.signal.aborted||ge instanceof Error&&ge.name==="AbortError"||x(ge)}).finally(()=>{_e.current.get(l)===ue&&(_e.current.delete(l),_t(_e.current.size))}),_e.current.set(l,ue),_t(_e.current.size)},[Gt,Re,B,M,U,d]),Tt=e.useCallback((a,l,c)=>{const h=bt(a.name,c);Nt(a,l,c,h)},[Nt,bt]),vr=e.useCallback((a,l)=>{J(En(He)),ke({fieldName:a.name,value:String(l??""),tab:"sub",keyword:"",page:1})},[He]),On=e.useCallback(a=>{ke(l=>l&&{...l,...a})},[]),La=e.useCallback(a=>{if(!le)return;Ze(c=>Un(c,[a]));const l=Qe.find(c=>c.name===le.fieldName);l?Tt(l,l.name,a.value):bt(le.fieldName,a.value),ke(null)},[Tt,Qe,le,bt]);e.useEffect(()=>{if(!le||!et)return;const a=new AbortController,l=le.tab,c=le.keyword.trim(),h=le.page,p=He,T=window.setTimeout(()=>{J(R=>({...R,page:h,size:p,loading:!0,error:""})),(async()=>{try{let R;if(k)R=await k({root:l==="root",keywords:c,page:h,size:p,signal:a.signal});else{const ue=new URLSearchParams;ue.set("root",l==="root"?"true":"false"),c&&ue.set("keywords",c),ue.set("page",String(h)),ue.set("size",String(p));const ge=await fetch(`${it}?${ue.toString()}`,{signal:a.signal});if(!ge.ok)throw new Error(`HTTP ${ge.status}`);R=await ge.json()}const x=Wn(R,h,p),G=x.items.map(hr).filter(Boolean),Z=lt?G.filter(ue=>ue.value!==lt):G;if(a.signal.aborted)return;Ze(ue=>Un(ue,Z)),J({items:Z,total:Math.max(0,x.total-(G.length-Z.length)),page:x.page||h,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:h,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()}},[lt,He,k,le,it,d,et]);const Cr=e.useCallback(async()=>{if(kt.length>0){ot(kt),Rt("");return}const a=String(w||"").trim().replace(/\/+$/,"");if(!I&&!a)return;const l=new AbortController;Ft(!0),Rt("");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()}),h=c&&typeof c=="object"&&"data"in c?c.data:c,p=C.getBuiltinToolOptionsFromSources(h,c);ot(p)}catch(c){(c==null?void 0:c.name)!=="AbortError"&&Rt(d("editor.panel.loadFailed",`加载失败: ${(c==null?void 0:c.message)||String(c)}`,{message:String((c==null?void 0:c.message)||c)}))}finally{Ft(!1)}},[w,I,kt,d]);e.useEffect(()=>{if(!z||z.step!=="select"||z.activeTab!=="rulechain"||!et)return;const a=new AbortController,l=z.keyword.trim(),c=z.ruleChainPage,h=He,p=window.setTimeout(()=>{rt(T=>({...T,page:c,size:h,loading:!0,error:""})),(async()=>{try{let T;if(k){const[Z,ue]=await Promise.all([k({root:!1,keywords:l,page:c,size:h,signal:a.signal}),k({root:!0,keywords:l,page:c,size:h,signal:a.signal})]),ge=Wn(Z,c,h),Ue=Wn(ue,c,h);T={items:[...ge.items,...Ue.items],total:ge.total+Ue.total,page:c,size:h}}else{const Z=new URLSearchParams;l&&Z.set("keywords",l),Z.set("page",String(c)),Z.set("size",String(h));const ue=await fetch(`${it}?${Z.toString()}`,{signal:a.signal});if(!ue.ok)throw new Error(`HTTP ${ue.status}`);T=await ue.json()}const R=Wn(T,c,h),x=R.items.map(or).filter(Boolean),G=lr(x).filter(Z=>!lt||Z.value!==lt);if(a.signal.aborted)return;Ze(Z=>Un(Z,G)),rt({items:G,total:Math.max(0,R.total-(x.length-G.length)),page:R.page||c,size:R.size||h,loading:!1,error:""})}catch(T){if(a.signal.aborted||(T==null?void 0:T.name)==="AbortError")return;rt({items:[],total:0,page:c,size:h,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()}},[lt,He,k,it,z,d,et]);const kr=e.useCallback(a=>{if(a===L||(Ce(a),!(de!=null&&de.name)))return;const l=xt(),c=String(l[de.name]??""),h=a==="shared"?Se.trim():c.startsWith("ref://")?"":c;if(h===c)return;const p={...l,[de.name]:h};ve(T=>({...T,configuration:p})),Nt(de,de.name,h,p)},[xt,de,L,ve,Nt,Se]),Ma=e.useCallback(a=>{if(oe(a),!(de!=null&&de.name))return;const l=a.trim(),c={...xt(),[de.name]:l};ve(h=>({...h,configuration:c})),Nt(de,de.name,l,c)},[xt,de,ve,Nt]),$a=e.useCallback(a=>{const l=We.find(R=>R.value===a);if(!l||!ie)return;Me(l.value),ce(l.models);const c=xt(),h=l.models.map(zn).filter(Boolean),p=String(c[we.model]??""),T={...c,[we.provider]:l.value,...l.url?{[we.url]:l.url}:{},[we.model]:l.defaultModel||(p&&h.includes(p)?p:h[0]||p)};ve(R=>({...R,configuration:T})),Nt(ie,we.provider,l.value,T)},[xt,ie,we,We,ve,Nt]),Nr=e.useCallback(a=>{if(!ie)return;const l=xt(),c=String(l[we.provider]??"");if(a===he&&!(a==="custom"&&c!=="custom")||(Te(a),a!=="custom"))return;Me(""),ce([]);const h={...l,[we.provider]:"custom",[we.url]:"",[we.model]:""};ve(p=>({...p,configuration:h})),c!=="custom"&&Nt(ie,we.provider,"custom",h)},[xt,ie,we,he,ve,Nt]),Aa=e.useCallback(a=>gn(a)||a.name===we.model&&xe.length>0,[we.model,xe.length]),Oa=a=>{Fe(l=>({...l,[a]:[...l[a]||[],{key:"",value:""}]}))},Fa=(a,l)=>{S(()=>{Fe(c=>({...c,[a]:c[a].filter((h,p)=>p!==l)}))})},wr=(a,l,c,h)=>{Fe(p=>({...p,[a]:p[a].map((T,R)=>R===l?{...T,[c]:h}:T)}))},Ba=(a,l)=>{S(()=>{v(c=>({...c,[a]:c[a].filter((h,p)=>p!==l)}))})},Xt=e.useCallback((a,l)=>{const c=C.parseSimpleArrayInput(l);c.length>0&&v(h=>({...h,[a]:[...h[a]||[],...c.map(p=>({value:p}))]})),ae(h=>({...h,[a]:""}))},[v]),ja=e.useCallback((a,l)=>{if(/[,,;;\n\t]/.test(l)){Xt(a,l);return}ae(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=>{S(()=>{v(l=>({...l,[a]:[]})),ae(l=>({...l,[a]:""}))})},[S,v]),Va=e.useCallback((a,l,c)=>{l!==c&&v(h=>{const p=[...h[a]||[]];if(l<0||c<0||l>=p.length||c>=p.length)return h;const[T]=p.splice(l,1);return p.splice(c,0,T),{...h,[a]:p}})},[v]),Nn=e.useCallback((a,l)=>{ve(c=>{const h={...c.configuration};return h[a]=l(C.normalizeToolRows(h[a])),{...c,configuration:h}})},[ve]),ht=e.useCallback(a=>{Ge(l=>l&&{...l,...a})},[]),Zn=e.useCallback(a=>{Ge(l=>l&&{...l,draft:{...l.draft,...a},error:""})},[]),mn=e.useCallback((a,l)=>{Ge(c=>{if(!c)return c;const h=c.draft.config&&typeof c.draft.config=="object"&&!Array.isArray(c.draft.config)?c.draft.config:{};return{...c,draft:{...c.draft,config:{...h,[a]:l}},error:""}})},[]),Qt=e.useCallback(a=>{Ge(l=>l&&{...l,schemaRows:a,parametersText:JSON.stringify(C.generateToolSchemaFromRows(a),null,2),error:""})},[]),Sr=e.useCallback(a=>{Ge(l=>{if(!l||l.schemaMode===a)return l;if(a==="code")return{...l,schemaMode:"code",parametersText:JSON.stringify(C.generateToolSchemaFromRows(l.schemaRows),null,2),error:""};try{return{...l,schemaMode:"visual",schemaRows:C.parseToolSchemaRows(C.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]),on=e.useCallback((a,l,c)=>{if(!z)return;const h=C.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(h)},[Qt,z]),xr=e.useCallback((a="")=>{if(!z)return;const l=C.updateSchemaRowsAtParent(z.schemaRows,a,c=>{c.push(C.emptySchemaEditorRow($o(c)+1))});Qt(l)},[Qt,z]),qa=e.useCallback((a,l)=>{z&&S(()=>{const c=C.updateSchemaRowsAtParent(z.schemaRows,a,h=>{h.splice(l,1);const p=C.renumberSchemaRowOrders(h);h.splice(0,h.length,...p)});Qt(c)})},[S,Qt,z]),Tr=e.useCallback((a,l,c)=>{z&&Qt(Ao(z.schemaRows,a,l,c))},[Qt,z]),dn=e.useCallback(a=>C.normalizeToolRows((V.configuration||{})[a]),[V.configuration]),Rr=e.useCallback((a,l=-1)=>{const c=Vr(a),h=dn(a.name),p=l>=0?h[l]:null,T=C.stringifyToolJson(p==null?void 0:p.parameters,"{}");let R=[];try{R=C.parseToolSchemaRows(C.parseJsonObjectText(T))}catch{R=[]}Ge({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:""}),rt(En(He)),Cr()},[He,dn,Cr]),wn=e.useCallback(()=>{Ge(null),Rt("")},[]),Sn=e.useCallback((a,l,c)=>dn(a).some((h,p)=>p!==c&&String(h.type||"")==="builtin"&&yn(h)===l),[dn]),xn=e.useCallback((a,l,c)=>dn(a).some((h,p)=>p!==c&&String(h.type||"")==="rulechain"&&String(h.targetId||"")===l),[dn]),Ja=e.useCallback(a=>{if(!z)return;if(Sn(z.fieldName,a.value,z.editIndex)){ht({error:d("editor.property.builtinToolAlreadyAdded","该内置工具已添加")});return}const l={};a.fields.forEach(h=>{const p=String((h==null?void 0:h.name)||"");p&&h.defaultValue!==void 0&&(l[p]=_n(h.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){Nn(z.fieldName,h=>[...h,c]),Ge(null);return}Ge(h=>h&&{...h,step:"config",activeTab:"builtin",draft:c,parametersText:JSON.stringify(a.parameters||{},null,2),schemaRows:C.parseToolSchemaRows(a.parameters||{}),schemaMode:"visual",error:""})},[Sn,ht,z,d,Nn]),Ir=e.useCallback(a=>{if(!z)return;if(xn(z.fieldName,a.value,z.editIndex)){ht({error:d("editor.property.ruleChainAlreadyAdded","该规则链已添加")});return}const l=Mo(a.raw);Ze(c=>Un(c,[a])),Ge(c=>c&&{...c,step:"config",activeTab:"rulechain",draft:{type:"rulechain",targetId:a.value,name:a.label,description:a.description||"",parameters:l},parametersText:l,schemaRows:C.parseToolSchemaRows(C.parseJsonObjectText(l)),schemaMode:"visual",error:""})},[xn,ht,z,d]),Ka=e.useCallback(()=>{Ge(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(),h=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(C.generateToolSchemaFromRows(z.schemaRows),null,2);else try{C.parseJsonObjectText(p||"{}")}catch(x){ht({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){ht({error:d("editor.property.ruleChainRequired","规则链是必须的")});return}if(a==="rulechain"&&xn(z.fieldName,c,z.editIndex)){ht({error:d("editor.property.ruleChainAlreadyAdded","该规则链已添加")});return}if(a==="builtin"&&Sn(z.fieldName,l,z.editIndex)){ht({error:d("editor.property.builtinToolAlreadyAdded","该内置工具已添加")});return}if(a!=="rulechain"&&!l){const x=z.mode==="subagent"?d("editor.property.agentName","智能体名称"):d("editor.property.toolName","工具名称");ht({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:h};z.mode==="tool"&&(T.parameters=a==="builtin"?C.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,Nn(z.fieldName,x=>{const G=[...x];return z.editIndex>=0?G[z.editIndex]=T:G.push(T),G}),Ge(null)},[Sn,xn,ht,z,d,Nn]),Ga=e.useCallback(()=>{P==null||P({section:"skills"}),window.dispatchEvent(new CustomEvent("rulego-editor:openAiAssistant",{detail:{section:"skills"}})),wn()},[wn,P]),Pr=(a=!0)=>{if(!n)return null;const l=pt.current;let c={...l.configuration};if(Qe.length===0)try{c=C.parseUnknownConfiguration(me),a&&De("")}catch(T){return a&&De(T instanceof Error?T.message:String(T)),null}const h=new Map(Qe.map(T=>[T.name,T]));if(de!=null&&de.name&&(L==="shared"?c[de.name]=Se.trim():String(c[de.name]??"").startsWith("ref://")&&(c[de.name]="")),ie&&he==="preset"&&Ee){c[we.provider]=Ee;const T=We.find(R=>R.value===Ee);T!=null&&T.url&&(c[we.url]=T.url),T!=null&&T.defaultModel&&!c[we.model]&&(c[we.model]=T.defaultModel)}Object.entries(Be.current).forEach(([T,R])=>{const x=h.get(T);if(!x||!sn(x))return;const G={},Z=C.getMapValueMode(x);R.forEach(ue=>{ue.key&&(G[ue.key]=C.parseMapEntryValue(ue.value,Z))}),c[T]=G}),Object.entries(ne.current).forEach(([T,R])=>{const x=h.get(T);!x||!Yt(x)||bn(x,c[T])||fn(x)||(c[T]=R.map(G=>G.value).filter(Boolean))}),c=C.sanitizeConfigurationByFields(c,Qe);const p=C.validateComponentFields(Qe,c);return p.length>0?(a&&yt(p.map(T=>`${T.field}: ${T.message}`).join(`
4
- `)),null):C.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(;_e.current.size>0;)await Promise.all([..._e.current.values()]);const a=Object.entries(Ne.current).filter(([c])=>Je.current.has(c)||[...Le.current].some(h=>hn(h,c)));if(a.length>0)return yt(d("editor.property.fieldChangeFailedMessage","关联字段更新失败: {{message}}",{message:a.map(([,c])=>c).join("; ")})),!1;const l=Pr(!0);if(!l)return!1;try{return yt(""),await o(l),Ut.current=JSON.stringify(l),!0}catch(c){return yt(c instanceof Error?c.message:String(c)),!1}},er=()=>s(),tr=async()=>{const a=Pr(!1);if(!(!a||JSON.stringify(a)!==Ut.current)){er();return}const c=await C.confirmDrawerUnsavedClose({t:h=>d(h,h)});c==="discard"&&er(),c==="save"&&await Dr()&&er()},Et=a=>tn(a.desc)?e.createElement("span",{className:"rge-field-desc"},tn(a.desc)):null,Fn=a=>{const l=[..._e.current.keys()].some(h=>hn(a,h)),c=Object.entries(Ot).filter(([h])=>hn(a,h));return e.createElement(e.Fragment,null,l&&e.createElement("span",{className:"rge-field-desc",role:"status"},d("editor.property.fieldChangeLoading","正在更新关联字段...")),c.map(([h,p])=>e.createElement("span",{key:h,className:"rge-field-error",role:"alert"},p)))},Lr=a=>{if(L==="shared"&&(a.ref==="primary"||a.ref==="shared")||ie&&a.name===ie.name)return null;const l=nn.get(a.name)||[],c=Mt[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"},H(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:()=>wt(a.name)},e.createElement(fe,{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),Fn(a.name))},Ya=()=>de?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(Kt,{name:"sharedRef",value:Se,options:ft,allowCreate:!0,threshold:0,placeholder:d("editor.form.sharedConnectionPlaceholder","选择或输入 ref:// 共享连接"),...q,onChange:Ma})),e.createElement("span",{className:"rge-field-desc"},d("editor.form.sharedConnectionDesc","共享连接会写入 ref:// 引用,自定义连接会直接写入服务地址。")),Fn(de.name)):null,Xa=()=>ie?e.createElement("div",{className:"rge-form-section rge-provider-mode-section"},e.createElement("label",{className:"rge-form-label"},ie.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(Kt,{name:"provider",value:Ee,options:We.map(a=>({label:a.label,value:a.value,description:a.url})),threshold:0,placeholder:d("editor.form.providerPlaceholder","选择AI供应商"),...q,onChange:$a})),e.createElement("span",{className:"rge-field-desc"},d("editor.form.providerDesc","预设供应商会自动填充 API 地址和模型,自定义供应商保留手工填写。")),Fn(we.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),h=a.component&&typeof a.component=="object"?a.component:{},p=String(h.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 ge=gr(Array.isArray(h.options)?h.options:[],R);return e.createElement("label",{key:l,className:"rge-tool-config-field"},e.createElement("span",null,c),e.createElement(Kt,{name:`tool-config-${l}`,value:String(R??""),options:ge,placeholder:String(h.placeholder||""),...q,onChange:Ue=>mn(l,Ue)}))}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:ge=>mn(l,ge.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:ge=>{const Ue=x==="array"||p==="array"?[]:{};try{mn(l,ge.target.value?JSON.parse(ge.target.value):Ue)}catch{mn(l,ge.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:ge=>mn(l,ge.target.value)}));const Z=p==="input-number"||p==="number"||x==="number"||da(String(a.type||"")),ue=p==="password"||x==="password"||Tn({name:l,type:x,component:h})?"password":p==="date"||p==="datepicker"?"date":p==="time"||p==="timepicker"?"time":p==="datetime"||p==="datetimepicker"||p==="datetime-local"?"datetime-local":Z?"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:ue,value:String(R??""),placeholder:String(h.placeholder||(p==="duration"||x==="duration"?"1s / 5m / 2h":"")),autoComplete:ue==="password"?"new-password":void 0,onChange:ge=>mn(l,Z?Number(ge.target.value||0):ge.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,h)=>{const p=l?`${l}.${h}`:String(h),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=>on(l,h,{name:x.target.value})}),e.createElement("input",{className:"rge-form-input",value:c.title,placeholder:d("editor.property.title","标题"),onChange:x=>on(l,h,{title:x.target.value})}),e.createElement("input",{className:"rge-form-input",value:c.description,placeholder:d("editor.property.description","描述"),onChange:x=>on(l,h,{description:x.target.value})}),e.createElement("select",{className:"rge-form-select",value:c.type,onChange:x=>on(l,h,{type:x.target.value})},C.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=>on(l,h,{order:Number(x.target.value||h+1)})}),e.createElement("label",{className:"rge-inline-checkbox rge-tool-schema-required"},e.createElement("input",{type:"checkbox",checked:c.required,onChange:x=>on(l,h,{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,h,-1)},"↑"),e.createElement("button",{type:"button",title:d("editor.property.moveDown","下移"),onClick:()=>Tr(l,h,1)},"↓"),e.createElement("button",{type:"button",className:"danger",onClick:()=>qa(l,h)},"×"))),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=>on(l,h,{itemsType:x.target.value})},C.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=C.normalizeToolRows(l),h=Vr(a),p=h==="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)},h==="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:yn(T)},yn(T)||"-"),e.createElement("td",null,e.createElement("span",{className:`rge-tool-type rge-tool-type-${x.toLowerCase()}`},Qa(x,h))),e.createElement("td",{title:Gr(T)},ar(Gr(T),80)),e.createElement("td",{className:"rge-tools-actions"},Lo(T,h,je)&&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:()=>S(()=>{Nn(a.name,G=>G.filter((Z,ue)=>ue!==R))})},"×")))})))),Et(a))},to=()=>{if(!z)return null;const a=z.editIndex>=0,l=z.mode,c=String(z.draft.type||z.activeTab||"builtin"),h=je.find(Pe=>Pe.value===yn(z.draft)),p=c==="builtin"?(h==null?void 0:h.fields)||[]:[],T=c==="builtin"&&yn(z.draft)==="skill",R=ut||(h==null?void 0:h.defaultGlobalDir)||d("editor.property.notConfigured","未配置"),x=z.keyword.trim().toLowerCase(),G=je.filter(Pe=>x?Pe.value.toLowerCase().includes(x)||Pe.label.toLowerCase().includes(x)||Pe.desc.toLowerCase().includes(x):!0),Z=Math.max(1,Math.ceil(G.length/He)),ue=Math.min(Math.max(1,z.page),Z),ge=G.slice((ue-1)*He,ue*He),Ue=vt(),Ae=Ct.items.map(or).filter(Boolean),at=lr([...Ae,...Ue]),jt=z.keyword.trim().toLowerCase(),qt=et?at:at.filter(Pe=>jt?Pe.label.toLowerCase().includes(jt)||Pe.value.toLowerCase().includes(jt)||String(Pe.description||"").toLowerCase().includes(jt):!0),Ke=et?Ct.total:qt.length,ze=Math.max(1,Math.ceil(Ke/He)),nt=Math.min(Math.max(1,z.ruleChainPage),ze),Zt=et?qt:qt.slice((nt-1)*He,nt*He),nr=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:wn},e.createElement("div",{className:"rge-tools-modal-panel",role:"dialog","aria-modal":"true",onClick:Pe=>Pe.stopPropagation()},e.createElement("div",{className:"rge-tools-modal-header"},e.createElement("strong",null,nr),e.createElement("button",{type:"button",className:"rge-rule-chain-modal-close",onClick:wn},"×")),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(Pe=>e.createElement("button",{key:Pe,type:"button",className:z.activeTab===Pe?"active":"",onClick:()=>ht({activeTab:Pe,keyword:"",page:1,ruleChainPage:1,error:""})},Pe==="builtin"?d("editor.property.builtinTool","内置工具"):Pe==="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:Pe=>ht({keyword:Pe.target.value,page:1,ruleChainPage:1})}),z.activeTab==="builtin"&&e.createElement("div",{className:"rge-tool-card-grid"},Ht?e.createElement("div",{className:"rge-tools-empty"},d("editor.panel.loading","加载中...")):Bt?e.createElement("div",{className:"rge-tools-empty"},Bt):ge.length===0?e.createElement("div",{className:"rge-tools-empty"},d("editor.property.noMatchingOptions","没有匹配的选项")):ge.map(Pe=>{const Jt=Sn(z.fieldName,Pe.value,z.editIndex);return e.createElement("button",{key:Pe.value,type:"button",className:`rge-tool-card${Jt?" disabled":""}`,disabled:Jt,onClick:()=>Ja(Pe)},e.createElement("span",{className:"rge-tool-card-icon builtin"},e.createElement(fe,{value:"settings"})),e.createElement("span",{className:"rge-tool-card-content"},e.createElement("strong",null,Pe.label),e.createElement("small",null,ar(Pe.desc||d("editor.property.noDescription","暂无描述"),96))),e.createElement("span",{className:"rge-tool-card-action"},Jt?d("editor.property.added","已添加"):"+"))})),z.activeTab==="rulechain"&&e.createElement("div",{className:"rge-tool-card-grid"},Ct.loading&&et?e.createElement("div",{className:"rge-tools-empty"},d("editor.panel.loading","加载中...")):Ct.error&&et?e.createElement("div",{className:"rge-tools-empty"},Ct.error):Zt.length===0?e.createElement("div",{className:"rge-tools-empty"},d("editor.property.noMatchingOptions","没有匹配的选项")):Zt.map(Pe=>{const Jt=xn(z.fieldName,Pe.value,z.editIndex);return e.createElement("button",{key:Pe.value,type:"button",className:`rge-tool-card${Jt?" disabled":""}`,disabled:Jt,onClick:()=>Ir(Pe)},e.createElement("span",{className:"rge-tool-card-icon rulechain"},e.createElement(fe,{value:"link"})),e.createElement("span",{className:"rge-tool-card-content"},e.createElement("strong",null,Pe.label),e.createElement("small",null,ar(Pe.description||Pe.value,96))),e.createElement("span",{className:"rge-tool-card-action"},Jt?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(Kt,{name:"tool-rulechain",value:String(z.draft.targetId||""),options:at.map(Pe=>({label:Pe.label,value:Pe.value,description:Pe.description})),placeholder:d("editor.form.selectRuleChain","请选择规则链"),...q,onChange:Pe=>{const Jt=at.find(so=>so.value===Pe);Jt?Ir(Jt):Zn({targetId:Pe})}})),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:Pe=>Zn({name:Pe.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:Pe=>Zn({description:Pe.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(Pe=>Za(Pe)))),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:Pe=>ht({parametersText:Pe.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:ue<=1,onClick:()=>ht({page:Math.max(1,ue-1)})},d("editor.property.prevPage","上一页")),e.createElement("span",null,d("editor.property.pageInfo",`第 ${ue}/${Z} 页,共 ${G.length} 条`,{page:ue,pages:Z,total:G.length})),e.createElement("button",{type:"button",disabled:ue>=Z,onClick:()=>ht({page:Math.min(Z,ue+1)})},d("editor.property.nextPage","下一页"))),z.activeTab==="rulechain"&&Ke>0&&e.createElement(e.Fragment,null,e.createElement("button",{type:"button",disabled:nt<=1||Ct.loading,onClick:()=>ht({ruleChainPage:Math.max(1,nt-1)})},d("editor.property.prevPage","上一页")),e.createElement("span",null,d("editor.property.pageInfo",`第 ${nt}/${ze} 页,共 ${Ke} 条`,{page:nt,pages:ze,total:Ke})),e.createElement("button",{type:"button",disabled:nt>=ze||Ct.loading,onClick:()=>ht({ruleChainPage:Math.min(ze,nt+1)})},d("editor.property.nextPage","下一页")))):e.createElement("div",{className:"rge-tools-modal-actions"},!a&&e.createElement("button",{type:"button",onClick:()=>ht({step:"select",error:""})},d("editor.property.back","返回选择")),e.createElement("button",{type:"button",onClick:wn},d("editor.panel.cancel","取消")),e.createElement("button",{type:"button",className:"primary",onClick:za},d("editor.panel.confirm","确认"))))))},no=(a,l,c,h)=>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:ct(a,l),placeholder:h||d("editor.form.selectRuleChain","请选择规则链"),disabled:c,readOnly:!0,onClick:()=>{c||vr(a,l)}}),e.createElement("button",{type:"button",className:"rge-rule-chain-picker-button",disabled:c,title:d("editor.form.selectRuleChain","选择规则链"),onClick:()=>vr(a,l)},d("editor.property.search","搜索"))),Et(a)),Bn=(a,l,c,h)=>{var G,Z,ue,ge,Ue;const p=a||{name:"value",type:"string"},T=!!(p.disabled||(G=p.component)!=null&&G.disabled),R=((Z=p.component)==null?void 0:Z.placeholder)||p.label||p.name,x=Ae=>{const at=c(Ae);Nt(p,h||p.name,Ae,at)};if(gn(p)){const Ae=Ye(p,l),at=!!((ue=p.component)!=null&&ue.multiple),jt=Array.isArray(l)?l.map(qt=>String(qt??"")).filter(Boolean):String(l??"").split(",").map(qt=>qt.trim()).filter(Boolean);return e.createElement(Kt,{name:h||p.name,value:String(l??""),values:at?jt:void 0,multiple:at,allowCreate:!!((ge=p.component)!=null&&ge.allowCreate),disabled:T,options:Ae,placeholder:R,...q,onChange:x,onMultiChange:x})}if(Gn(p))return e.createElement("label",{className:"rge-inline-checkbox"},e.createElement("input",{type:"checkbox",checked:!!l,disabled:T,onChange:Ae=>x(Ae.target.checked)}),e.createElement("span",null,p.label||p.name));if(Yn(p)){const Ae=pr(p.type)||Lt(p)==="number";return e.createElement("input",{type:"number",className:"rge-form-input",step:Ae?"0.01":void 0,value:String(l??""),disabled:T,placeholder:R,onChange:at=>x(wo(p,at.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:Ae=>x(Ae.target.value)});if(Hr(p)||Hn(p))return e.createElement("textarea",{className:Hn(p)?"rge-code-textarea":"rge-form-textarea",rows:Hn(p)?6:3,value:typeof l=="object"&&l!==null?JSON.stringify(l,null,2):String(l??""),disabled:T,placeholder:R,spellCheck:!1,onChange:Ae=>x(Ae.target.value)});if(Kr(p)){const at=mt(p).startsWith("time")?"time":"date";return e.createElement("input",{type:at,className:"rge-form-input",value:String(l??""),disabled:T,placeholder:R,onChange:jt=>x(jt.target.value)})}return zr(p)?e.createElement("input",{type:"text",className:"rge-form-input rge-duration-input",value:String(l??""),disabled:T,placeholder:((Ue=p.component)==null?void 0:Ue.placeholder)||"10s / 1m",onChange:Ae=>x(Ae.target.value)}):qr(p)||Yt(p)||sn(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:Ae=>{try{x(Ae.target.value?JSON.parse(Ae.target.value):Yt(p)?[]:{})}catch{x(Ae.target.value)}}}):e.createElement("input",{type:Tn(p)?"password":"text",className:"rge-form-input",value:String(l??""),disabled:T,placeholder:R,autoComplete:Tn(p)?"new-password":void 0,onChange:Ae=>x(Ae.target.value)})},ro=(a,l)=>{var T;const c=_o(l),h=String(((T=a.component)==null?void 0:T.caseType)||"").toLowerCase(),p=(R,x,G)=>{bt(a.name,c.map((Z,ue)=>ue===R?{...Z,[x]:G}:Z))};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${h==="expr"||h==="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:()=>S(()=>{bt(a.name,c.filter((G,Z)=>Z!==x))})},"×"))),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>bt(a.name,[...c,{case:"",then:""}])},d("editor.property.addBranch","添加分支")),Et(a))},ao=(a,l)=>{const c=vo(l),h=No(a,c),p=kn(a),T=new Map(p.map(x=>[x.name,x])),R=h.reduce((x,G)=>{const Z=T.get(G);return x[G]=(Z==null?void 0:Z.defaultValue)??"",x},{});return h.length===0?e.createElement("div",{className:"rge-array-editor"},e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>bt(a.name,[...c,{}])},d("editor.panel.addPair","+ 添加")),Et(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(${h.length}, minmax(120px, 1fr)) 32px`}},h.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(${h.length}, minmax(120px, 1fr)) 32px`}},h.map(Z=>{const ue=T.get(Z);return e.createElement("div",{key:Z,className:"rge-structured-array-cell"},Bn(ue,x[Z],ge=>bt(a.name,c.map((Ue,Ae)=>Ae===G?{...Ue,[Z]:ge}:Ue)),`${a.name}.${G}.${Z}`))}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",onClick:()=>S(()=>{bt(a.name,c.filter((Z,ue)=>ue!==G))})},"×")))),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>bt(a.name,[...c,R])},d("editor.panel.addPair","+ 添加")),Et(a))},oo=(a,l)=>{const c=l&&typeof l=="object"&&!Array.isArray(l)?l:{},h=kn(a),p=h.length>0?h.map(R=>R.name).filter(Boolean):Object.keys(c),T=new Map(h.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),Bn(x,c[R]??(x==null?void 0:x.defaultValue)??"",G=>bt(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)))}),Et(a))},$r=a=>{var T,R,x,G;const c=(V.configuration||{})[a.name],h=!!(a.disabled||(T=a.component)!=null&&T.disabled),p=((R=a.component)==null?void 0:R.placeholder)||"";if(Eo(a))return no(a,c,h,p);if(Aa(a)){const Z=!!((x=a.component)!=null&&x.multiple),ue=Ye(a,c),ge=Array.isArray(c)?c.map(Ue=>String(Ue??"")).filter(Boolean):String(c??"").split(",").map(Ue=>Ue.trim()).filter(Boolean);return e.createElement(e.Fragment,null,e.createElement(Kt,{name:a.name,value:String(c??""),values:Z?ge:void 0,multiple:Z,allowCreate:!!((G=a.component)!=null&&G.allowCreate),disabled:h,options:ue,placeholder:p,...q,onChange:Ue=>Tt(a,a.name,Ue),onMultiChange:Ue=>Tt(a,a.name,Ue)}),Et(a))}if(Ur(a))return ro(a,c);if(Gn(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:h,onChange:Z=>Tt(a,a.name,Z.target.checked)}),e.createElement("span",{className:"rge-switch-slider"})),Et(a));if(Kr(a))return e.createElement(e.Fragment,null,Bn(a,c,Z=>bt(a.name,Z)),Et(a));if(zr(a))return e.createElement(e.Fragment,null,Bn(a,c,Z=>bt(a.name,Z)),Et(a));if(sn(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)),($e[a.name]||[]).map((Z,ue)=>e.createElement("div",{key:ue,className:"rge-map-row"},e.createElement("input",{type:"text",className:"rge-form-input",placeholder:d("editor.form.keyPlaceholder","键"),value:Z.key,onChange:ge=>wr(a.name,ue,"key",ge.target.value)}),e.createElement("input",{type:"text",className:"rge-form-input",placeholder:d("editor.form.valuePlaceholder","值"),value:Z.value,onChange:ge=>wr(a.name,ue,"value",ge.target.value)}),e.createElement("button",{type:"button",className:"rge-btn-icon-danger",title:d("editor.property.delete","删除"),onClick:()=>Fa(a.name,ue)},e.createElement(fe,{value:"delete"})))),e.createElement("button",{className:"rge-btn-add",onClick:()=>Oa(a.name)},d("editor.panel.addPair","+ 添加")),Et(a));if(bn(a,c))return C.isPointTableFields(kn(a))?e.createElement(ko,{field:a,value:c,onChange:Z=>bt(a.name,Z),onChildChange:Nt,translate:d}):ao(a,c);if(fn(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((Z,ue)=>e.createElement("div",{key:`${Z.value}-${ue}`,className:"rge-array-row rge-array-tag",role:"listitem",draggable:!0,onDragStart:ge=>ge.dataTransfer.setData("text/plain",String(ue)),onDragOver:ge=>ge.preventDefault(),onDrop:ge=>{var Ae;ge.preventDefault();const Ue=Number((Ae=ge.dataTransfer)==null?void 0:Ae.getData("text"));Number.isInteger(Ue)&&Va(a.name,Ue,ue)}},e.createElement("span",{className:"rge-array-tag-value"},Z.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,ue)},"×")))),e.createElement("input",{type:"text",className:"rge-form-input rge-array-tag-input",value:Y[a.name]||"",placeholder:d("editor.property.simpleArrayPlaceholder","输入后回车添加,支持粘贴批量内容"),onChange:Z=>ja(a.name,Z.target.value),onKeyDown:Z=>Ha(a.name,Z),onPaste:Z=>Wa(a.name,Z),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","清空")),Et(a));if(Hn(a))return e.createElement("div",{className:`rge-script-editor${fr(a)?" rge-command-editor":""}`},e.createElement("textarea",{className:"rge-code-textarea",rows:fr(a)?4:10,value:Wr(c),onChange:Z=>Tt(a,a.name,Z.target.value),placeholder:d("editor.form.jsScriptPlaceholder","请输入 JS 脚本..."),spellCheck:!1}),Et(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:h,onChange:Z=>Tt(a,a.name,Z.target.value)}),Et(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:h,onChange:Z=>Tt(a,a.name,Z.target.value)}),Et(a));if(Yn(a)){const Z=pr(a.type)||Lt(a)==="number";return e.createElement(e.Fragment,null,e.createElement("input",{type:"number",step:Z?"0.01":void 0,className:"rge-form-input",value:String(c??""),disabled:h,onChange:ue=>{const ge=ue.target.value;Tt(a,a.name,ge===""?"":Z?Number(ge):parseInt(ge,10))}}),Et(a))}return e.createElement(e.Fragment,null,e.createElement("input",{type:Tn(a)?"password":"text",className:"rge-form-input",value:String(c??""),placeholder:p,disabled:h,autoComplete:Tn(a)?"new-password":void 0,onChange:Z=>Tt(a,a.name,Z.target.value)}),Et(a))},lo=()=>{if(!le)return null;const a=Qe.find(G=>G.name===le.fieldName);if(!a)return null;const l=le.keyword.trim().toLowerCase(),c=gt(a,le.value).filter(G=>!lt||G.value!==lt).filter(G=>Po(G,le.tab)).filter(G=>l?G.label.toLowerCase().includes(l)||G.value.toLowerCase().includes(l)||String(G.description||"").toLowerCase().includes(l):!0),h=et?ye.total:c.length,p=et&&ye.size||He,T=Math.max(1,Math.ceil(h/p)),R=Math.min(le.page,T),x=et?ye.items:c.slice((R-1)*p,R*p);return e.createElement("div",{className:"rge-rule-chain-modal",onClick:()=>ke(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:()=>ke(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":le.tab===G,className:le.tab===G?"active":"",onClick:()=>On({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:le.keyword,placeholder:d("editor.property.searchRuleChains","搜索规则链..."),onChange:G=>On({keyword:G.target.value,page:1}),autoFocus:!0})),e.createElement("div",{className:"rge-rule-chain-modal-body"},ye.loading&&et?e.createElement("div",{className:"rge-rule-chain-empty"},d("editor.property.loading","加载中...")):ye.error&&et?e.createElement("div",{className:"rge-rule-chain-empty"},ye.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 Z=G.value===le.value;return e.createElement("tr",{key:G.value,className:Z?"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"},Z?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(h)})),e.createElement("button",{type:"button",disabled:R<=1||et&&ye.loading,onClick:()=>On({page:Math.max(1,R-1)})},d("editor.property.prevPage","上一页")),e.createElement("button",{type:"button",disabled:R>=T||et&&ye.loading,onClick:()=>On({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:()=>{tr()}},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(fe,{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:()=>{tr()}},"✕")),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:V.id||"",readOnly:!0,"aria-readonly":"true",title:d("editor.panel.nodeIdLocked","节点 ID 已绑定画布,编辑属性时不会改写"),onChange:a=>an("id",a.target.value)}),e.createElement("label",{className:"rge-debug-toggle"},e.createElement("input",{type:"checkbox",checked:V.debugMode||!1,onChange:a=>an("debugMode",a.target.checked)}),e.createElement(fe,{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:V.name||"",onChange:a=>an("name",a.target.value)})),Ya(),Xa(),K.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)),$t&&(()=>{if(un.length===0)return null;const a=()=>{rn>0||wt("")},l=()=>{rn>0||An.length>0||wt("")};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:rn>0,"aria-label":d("editor.panel.close","关闭"),onClick:a},"×")),e.createElement("div",{className:"rge-field-attachment-body"},Mn.map(c=>e.createElement("div",{key:c.field.name,className:"rge-form-section"},e.createElement("label",{className:"rge-form-label"},H(c.field)),$r(c.field),Et(c.field),Fn(c.field.name)))),e.createElement("footer",{className:"rge-drawer-footer"},rn>0&&e.createElement("span",{className:"rge-field-desc",role:"status"},d("editor.property.fieldChangeLoading","正在更新关联字段...")),e.createElement("button",{type:"button",className:"rge-btn-submit",disabled:rn>0||An.length>0,onClick:l},d("editor.panel.apply","应用")))))})(),Qe.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:me,onChange:a=>{j(a.target.value),De("")},spellCheck:!1}),be&&e.createElement("span",{className:"rge-field-error"},be)),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=V.additionalInfo)==null?void 0:Ar.description)??""),onChange:a=>an("additionalInfo",{...V.additionalInfo,description:a.target.value})})))),lo(),to(),e.createElement("div",{className:"rge-drawer-footer"},At&&e.createElement("span",{className:"rge-drawer-submit-error",role:"alert"},At),!At&&zt.length>0&&e.createElement("span",{className:"rge-drawer-submit-error",role:"alert"},d("editor.property.fieldChangeFailedMessage","关联字段更新失败: {{message}}",{message:zt.map(([,a])=>a).join("; ")})),Wt>0&&e.createElement("span",{className:"rge-field-desc",role:"status"},d("editor.property.fieldChangeLoading","正在更新关联字段...")),e.createElement("button",{className:"rge-btn-cancel",onClick:()=>{tr()}},d("editor.panel.cancel","取消")),e.createElement("button",{className:"rge-btn-submit",disabled:Wt>0||zt.length>0,onClick:()=>{Dr()}},d("editor.panel.confirm","确认")))))};ba.displayName="NodePropertyDrawer";const Rn=[{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(""),[D,g]=e.useState(""),[w,E]=e.useState(!1),k=e.useMemo(()=>Xe({locale:i,messages:m,t:f}),[i,m,f]),O=e.useMemo(()=>{const _=!(r!=null&&r.length);return(r!=null&&r.length?r:Rn).map((P,y)=>{var u,te;return typeof P=="string"?{value:P,label:dr(k,P),color:((u=Rn[y%Rn.length])==null?void 0:u.color)||"#409eff"}:{value:P.value,label:!_&&P.label?P.label:dr(k,P.value),color:P.color||((te=Rn[y%Rn.length])==null?void 0:te.color)||"#409eff"}})},[r,k]);e.useEffect(()=>{if(!n)return;const _=n.relationType||"Success";O.some(P=>P.value===_)?(N(_),E(!1),g("")):(N(""),E(!0),g(_))},[n,O]);const F=_=>{N(_),E(!1),g("")},A=()=>{E(!0),N("")},W=()=>{if(!n)return;const _=w?D.trim()||"Success":M||"Success";o({...n,relationType:_})};return!t||!n?null:e.createElement("div",{className:`rge-edge-drawer-overlay ${t?"visible":""}`,onClick:s},e.createElement("div",{className:"rge-edge-drawer",onClick:_=>_.stopPropagation()},e.createElement("div",{className:"rge-drawer-header"},e.createElement("div",{className:"rge-drawer-title"},e.createElement(fe,{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"},O.map(_=>e.createElement("button",{key:_.value,className:`rge-relation-type-btn ${!w&&M===_.value?"active":""}`,style:{borderColor:!w&&M===_.value?_.color:void 0,color:!w&&M===_.value?_.color:void 0},onClick:()=>F(_.value)},!w&&M===_.value&&e.createElement("span",null,"✓"),_.label)),e.createElement("button",{className:`rge-relation-type-btn ${w?"active custom":""}`,onClick:A},k("editor.edge.custom","自定义"))),w&&e.createElement("input",{type:"text",className:"rge-form-input rge-mt-8",placeholder:k("editor.edge.customPlaceholder","请输入自定义关系类型"),value:D,onChange:_=>g(_.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:W},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:D,messages:g,t:w})=>{const[E,k]=e.useState("send"),[O,F]=e.useState("TEST_MSG"),[A,W]=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
- }`),[_,I]=e.useState(!1),[P,y]=e.useState(!1),[u,te]=e.useState(!1),[re,B]=e.useState(""),[U,pe]=e.useState([]),[V,se]=e.useState(!1),[me,j]=e.useState([]),[be,De]=e.useState(!1),[$e,X]=e.useState({visible:!1,title:"",data:""}),b=e.useRef(0),$=e.useRef(0),Y=e.useRef(0),ae=e.useRef(n);e.useEffect(()=>{ae.current!==n&&(ae.current=n,b.current+=1,$.current+=1,Y.current+=1,pe([]),j([]),F("TEST_MSG"),W("{}"),B(""),se(!1),De(!1),I(!1),y(!1),te(!1),X({visible:!1,title:"",data:""}))},[n]);const L=e.useMemo(()=>Xe({locale:D,messages:g,t:w}),[D,g,w]),Ce=_r(D);e.useEffect(()=>{i==="running"&&te(!1)},[i]);const Se=e.useCallback(async(ce=!1)=>{if(!n){N("warning",L("editor.debugPanel.selectChainFirst","请先选择规则链"));return}if(!s){N("warning",L("editor.debugPanel.noSendCallback","未配置发送消息回调"));return}if(!ce&&(i==="undeployed"||i==="stopped")){const ye=L("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");te(!0),B(ye),N("warning",ye);return}const le=++Y.current,ke=C.createDebugPanelRequestSnapshot(n,le);try{I(!0);let ye;try{ye=JSON.parse(A)}catch{N("error",L("editor.debugPanel.invalidJson","消息体 JSON 格式错误"));return}const J=await s(n,O,ye);if(!C.isDebugPanelRequestCurrent(ke,n,Y.current))return;if(J.success)te(!1),N("success",L("editor.debugPanel.sendSuccess","消息发送成功")),B(JSON.stringify(J.data,null,2));else{const Oe=J.msg||L("editor.debugPanel.unknownError","未知错误");if(C.isRuleChainNotDeployedError(Oe,n)){const Ze=L("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");te(!0),B(Ze),N("warning",Ze);return}N("error",L("editor.debugPanel.sendFailed","发送失败: {{message}}",{message:Oe})),B(J.msg||L("editor.debugPanel.sendTestMessage","发送测试消息"))}}catch(ye){if(!C.isDebugPanelRequestCurrent(ke,n,Y.current))return;if(C.isRuleChainNotDeployedError(ye,n)){const J=L("editor.debugPanel.deployRequired","当前规则链未上线,请先部署后再调试");te(!0),B(J),N("warning",J);return}N("error",L("editor.debugPanel.sendException","发送异常: {{message}}",{message:ye instanceof Error?ye.message:String(ye)}))}finally{C.isDebugPanelRequestCurrent(ke,n,Y.current)&&I(!1)}},[n,i,O,A,s,N,L]),oe=e.useCallback(async()=>{if(!m||P)return;const ce=n;try{y(!0);const le=await m(ce);if(ae.current!==ce)return;if(le===!1||le&&typeof le=="object"&&le.success===!1){const ke=le&&typeof le=="object"&&le.msg?le.msg:L("editor.debugPanel.deployFailed","部署失败");N("error",L("editor.debugPanel.deployFailedWithMessage","部署失败: {{message}}",{message:ke}));return}te(!1),N("success",L("editor.debugPanel.deploySucceeded","规则链已部署,正在重新发送")),await Se(!0)}catch(le){if(ae.current!==ce)return;N("error",L("editor.debugPanel.deployFailedWithMessage","部署失败: {{message}}",{message:le instanceof Error?le.message:String(le)}))}finally{ae.current===ce&&y(!1)}},[n,P,Se,m,N,L]),he=e.useCallback(async()=>{if(!n||!f)return;const ce=++b.current,le=C.createDebugPanelRequestSnapshot(n,ce);try{se(!0);const ke=await f(n,r);if(!C.isDebugPanelRequestCurrent(le,n,b.current))return;pe(ke.items||[])}catch{C.isDebugPanelRequestCurrent(le,n,b.current)&&N("error",L("editor.debugPanel.loadDebugLogsFailed","加载调试日志失败"))}finally{C.isDebugPanelRequestCurrent(le,n,b.current)&&se(!1)}},[n,r,f,N,L]),Te=e.useCallback(async()=>{if(!M)return;const ce=++$.current,le=C.createDebugPanelRequestSnapshot(n,ce);try{De(!0);const ke=await M(n);if(!C.isDebugPanelRequestCurrent(le,n,$.current))return;j(ke||[])}catch{C.isDebugPanelRequestCurrent(le,n,$.current)&&N("error",L("editor.debugPanel.loadRunLogsFailed","加载运行日志失败"))}finally{C.isDebugPanelRequestCurrent(le,n,$.current)&&De(!1)}},[n,M,N,L]),Ee=(ce,le)=>{let ke=le;try{ke=JSON.stringify(JSON.parse(le),null,2)}catch{}X({visible:!0,title:ce,data:ke})},Me=ce=>new Date(ce).toLocaleString(Ce,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}),xe=async ce=>{try{await navigator.clipboard.writeText(ce),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 ${E==="send"?"active":""}`,onClick:()=>k("send")},e.createElement(fe,{value:"send"})," ",L("editor.debugPanel.sendMessage","发送消息")),e.createElement("button",{className:`rge-debug-tab ${E==="debug"?"active":""}`,onClick:()=>{k("debug"),he()}},e.createElement(fe,{value:"debug"})," ",L("editor.debugPanel.debugLogs","调试日志")),e.createElement("button",{className:`rge-debug-tab ${E==="logs"?"active":""}`,onClick:()=>{k("logs"),Te()}},e.createElement(fe,{value:"data"})," ",L("editor.debugPanel.runLogs","运行日志"))),e.createElement("button",{className:"rge-drawer-close",onClick:o},"✕")),E==="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:O,onChange:ce=>F(ce.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:A,onChange:ce=>W(ce.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:P||_,onClick:()=>{oe()}},P?L("editor.debugPanel.deploying","部署中..."):L("editor.debugPanel.deployAndRetry","部署并重试"))),e.createElement("button",{className:"rge-btn-submit rge-full-width",onClick:()=>{Se()},disabled:_},e.createElement(fe,{value:"send"})," ",_?L("editor.debugPanel.sending","发送中..."):L("editor.debugPanel.sendTestMessage","发送测试消息")),re&&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:()=>xe(re)},e.createElement(fe,{value:"copy"})," ",L("editor.panel.copy","复制"))),e.createElement("pre",{className:"rge-response-pre"},re))),E==="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:V},e.createElement(fe,{value:"refresh",className:V?"is-spinning":""})," ",V?L("editor.debugPanel.loading","加载中..."):L("editor.debugPanel.refresh","刷新"))),U.length===0?e.createElement("div",{className:"rge-empty-tip"},e.createElement(fe,{value:"debug",className:"rge-empty-graphic"}),e.createElement("p",null,V?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","操作"))),U.map((ce,le)=>e.createElement("div",{key:le,className:`rge-log-table-row ${ce.err?"error":""}`},e.createElement("span",null,Me(ce.ts)),e.createElement("span",{className:"rge-tag-small"},ce.flowType),e.createElement("span",{className:"rge-tag-small"},ce.relationType),e.createElement("span",{title:ce.msg.type},ce.msg.type.length>12?ce.msg.type.slice(0,12)+"...":ce.msg.type),e.createElement("span",{className:"rge-log-actions"},e.createElement("button",{className:"rge-btn-link",onClick:()=>Ee(L("editor.debugPanel.data","数据"),ce.msg.data)},L("editor.debugPanel.data","数据")),e.createElement("button",{className:"rge-btn-link",onClick:()=>Ee(L("editor.debugPanel.metadata","元数据"),JSON.stringify(ce.msg.metadata))},L("editor.debugPanel.metadata","元数据")),ce.err&&e.createElement("button",{className:"rge-btn-link danger",onClick:()=>Ee(L("editor.debugPanel.error","错误"),ce.err||"")},L("editor.debugPanel.error","错误"))))))),E==="logs"&&e.createElement("div",{className:"rge-debug-body"},e.createElement("div",{className:"rge-toolbar-row"},e.createElement("button",{className:"rge-btn-mini",onClick:Te,disabled:be},e.createElement(fe,{value:"refresh",className:be?"is-spinning":""})," ",be?L("editor.debugPanel.loading","加载中..."):L("editor.debugPanel.refresh","刷新"))),me.length===0?e.createElement("div",{className:"rge-empty-tip"},e.createElement(fe,{value:"data",className:"rge-empty-graphic"}),e.createElement("p",null,be?L("editor.debugPanel.loading","加载中..."):L("editor.debugPanel.noRunLogs","暂无运行日志"))):e.createElement("div",{className:"rge-log-list"},me.map((ce,le)=>e.createElement("div",{key:le,className:"rge-run-log-item",onClick:()=>Ee(L("editor.debugPanel.runLogDetail","日志详情"),JSON.stringify(ce))},e.createElement("pre",null,typeof ce=="string"?ce:JSON.stringify(ce,null,2)))))),$e.visible&&e.createElement("div",{className:"rge-detail-overlay",onClick:()=>X({...$e,visible:!1})},e.createElement("div",{className:"rge-detail-modal",onClick:ce=>ce.stopPropagation()},e.createElement("div",{className:"rge-detail-header"},e.createElement("span",null,$e.title),e.createElement("div",null,e.createElement("button",{className:"rge-btn-mini",onClick:()=>xe($e.data)},e.createElement(fe,{value:"copy"})),e.createElement("button",{className:"rge-drawer-close",onClick:()=>X({...$e,visible:!1})},"✕"))),e.createElement("pre",{className:"rge-detail-pre"},$e.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(()=>Xe({locale:m,messages:f,t:M}),[m,f,M]),D=r||N("editor.dataView.title","规则链数据"),g=e.useMemo(()=>Fo(n??{}),[n]),w=e.useMemo(()=>{const O=g?g.split(/\r\n|\r|\n/).length:0,F=typeof Blob<"u"?new Blob([g]).size:new TextEncoder().encode(g).length;return{lineCount:O,byteSize:Bo(F)}},[g]),E=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 O=new Blob([g],{type:"application/json"}),F=URL.createObjectURL(O),A=new Date().toISOString().slice(0,19).replace(/[:]/g,"-"),W=`${o}_${A}.json`,_=document.createElement("a");_.href=F,_.download=W,document.body.appendChild(_),_.click(),document.body.removeChild(_),URL.revokeObjectURL(F),i==null||i("success",N("editor.dataView.downloaded","已下载 {{fileName}}",{fileName:W}))}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:O=>O.stopPropagation()},e.createElement("div",{className:"rge-dialog-header"},e.createElement("div",{className:"rge-dialog-title"},e.createElement(fe,{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"},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:E},e.createElement(fe,{value:"copy"})," ",N("editor.dataView.copyJson","复制")),e.createElement("button",{type:"button",className:"rge-btn-outline",onClick:k},e.createElement(fe,{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":D})))):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:D,onZoomOut:g,onZoomChange:w,onFitView:E,onResetZoom:k,onFullscreen:O,onToggleDebug:F,onViewData:A,onSettings:W,onValidate:_,onNew:I,onImport:P,onExport:y,onAutoLayout:u,extraButtons:te=[],hiddenButtons:re=[],chainName:B,locale:U,messages:pe,t:V})=>{const[se,me]=e.useState(!1),j=e.useMemo(()=>Xe({locale:U,messages:pe,t:V}),[U,pe,V]),be=b=>re.includes(b),De=b=>{const $=C.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:j("editor.toolbar.newChain","新建规则链"),onClick:()=>I==null?void 0:I(),hidden:be("new")||!I},{key:"save",icon:"save",tooltip:`${j("editor.toolbar.save","保存")} (Ctrl+S)`,onClick:()=>m==null?void 0:m(),hidden:be("save")},{key:"import",icon:"import",tooltip:j("editor.toolbar.import","导入"),onClick:()=>P==null?void 0:P(),hidden:be("import")||!P},{key:"export",icon:"export",tooltip:j("editor.toolbar.export","导出"),onClick:()=>y==null?void 0:y(),hidden:be("export")||!y},{key:"undo",icon:"undo",tooltip:`${j("editor.toolbar.undo","撤销")} (Ctrl+Z)`,onClick:()=>f==null?void 0:f(),disabled:!t,hidden:be("undo"),dividerBefore:!0},{key:"redo",icon:"redo",tooltip:`${j("editor.toolbar.redo","重做")} (Ctrl+Y)`,onClick:()=>M==null?void 0:M(),disabled:!n,hidden:be("redo")},{key:"delete",icon:"delete",tooltip:`${j("editor.toolbar.delete","删除选中")} (Del)`,onClick:()=>N==null?void 0:N(),disabled:!i,hidden:be("delete")},{key:"zoomIn",icon:"zoom-in",tooltip:j("editor.toolbar.zoomIn","放大"),onClick:()=>D==null?void 0:D(),hidden:be("zoomIn"),dividerBefore:!0},{key:"zoomOut",icon:"zoom-out",tooltip:j("editor.toolbar.zoomOut","缩小"),onClick:()=>g==null?void 0:g(),hidden:be("zoomOut")},{key:"fitView",icon:"fit",tooltip:j("editor.toolbar.fitView","适应画布"),onClick:()=>E==null?void 0:E(),hidden:be("fitView")},{key:"autoLayout",icon:"auto-layout",tooltip:j("editor.toolbar.autoLayout","自动排版"),onClick:()=>u==null?void 0:u(),hidden:be("autoLayout")||!u},{key:"resetZoom",icon:"1:1",tooltip:j("editor.toolbar.resetZoom","重置缩放"),onClick:()=>k==null?void 0:k(),hidden:be("resetZoom")},{key:"validate",icon:"validate",tooltip:j("editor.toolbar.validate","校验规则链"),onClick:()=>_==null?void 0:_(),hidden:be("validate")||!_,dividerBefore:!0},{key:"debug",icon:"debug",tooltip:o?j("editor.toolbar.debugOff","关闭调试"):j("editor.toolbar.debugOn","开启调试"),onClick:()=>F==null?void 0:F(),active:o,hidden:be("debug")},{key:"viewData",icon:"data",tooltip:j("editor.toolbar.viewData","查看数据"),onClick:()=>A==null?void 0:A(),hidden:be("viewData")},{key:"settings",icon:"settings",tooltip:j("editor.toolbar.settings","设置"),onClick:()=>W==null?void 0:W(),hidden:be("settings")||!W},{key:"fullscreen",icon:r?"fullscreen-exit":"fullscreen",tooltip:r?j("editor.toolbar.exitFullscreen","退出全屏"):j("editor.toolbar.fullscreen","全屏"),onClick:()=>O==null?void 0:O(),hidden:be("fullscreen")},...te].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},De(b.icon))))),B&&e.createElement("div",{className:"rge-toolbar-center"},e.createElement("span",{className:"rge-chain-name"},B)),e.createElement("div",{className:"rge-toolbar-right"},e.createElement("button",{className:"rge-toolbar-zoom-btn",onClick:()=>me(!se),title:j("editor.toolbar.zoomOptions","缩放选项")},s,"%"),se&&e.createElement("div",{className:"rge-zoom-menu",onMouseLeave:()=>me(!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()),me(!1)}},b,"%")),e.createElement("div",{className:"rge-toolbar-divider horizontal"}),e.createElement("button",{className:"rge-zoom-option",onClick:()=>{E==null||E(),me(!1)}},j("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 E=Array.from(w.children).find(A=>A.classList.contains("rge-ctx-submenu"));if(!E)return;E.style.display="block",E.style.visibility="hidden";const k=w.getBoundingClientRect(),O=E.getBoundingClientRect(),F=C.resolveContextSubmenuPosition(k,{width:O.width,height:O.height},{width:window.innerWidth,height:window.innerHeight});E.dataset.placement=F.placement,E.style.left=`${F.left}px`,E.style.top=`${F.top}px`,E.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(),E=C.clampContextMenuPosition({left:n,top:r},{width:w.width,height:w.height},{width:window.innerWidth,height:window.innerHeight});i.current.style.left=`${E.left}px`,i.current.style.top=`${E.top}px`}},[t,n,r]),!t)return null;const N=o.filter(w=>!w.hidden),D=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:E=>M(E.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(E=>!E.hidden).map(D)))):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 E;w.disabled||((E=w.onClick)==null||E.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 E=C.getEditorToolbarIconSvg(w);return E?e.createElement("span",{className:"rge-ctx-menu-icon rge-ctx-menu-icon-svg","aria-hidden":"true",dangerouslySetInnerHTML:{__html:E}}):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(D))};va.displayName="ContextMenu";function jo(t,n){const r=Xe(n),o=t.nodeType===void 0||C.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=Xe(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=Xe(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 sr={"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&&sr[t]?sr[t]:sr.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:D})=>{const[g,w]=e.useState(s),E=e.useRef(null),k=e.useRef(!1),O=e.useMemo(()=>Xe({locale:M,messages:N,t:D}),[M,N,D]),F=e.useCallback(()=>{if(t.length===0)return{minX:0,minY:0,maxX:100,maxY:100};let y=1/0,u=1/0,te=-1/0,re=-1/0;t.forEach(U=>{const pe=U.width||60,V=U.height||40;y=Math.min(y,U.x),u=Math.min(u,U.y),te=Math.max(te,U.x+pe),re=Math.max(re,U.y+V)});const B=50;return{minX:y-B,minY:u-B,maxX:te+B,maxY:re+B}},[t]);e.useEffect(()=>{if(g||!E.current)return;const y=E.current.getContext("2d");if(!y)return;const u=F(),te=u.maxX-u.minX,re=u.maxY-u.minY,B=Math.min(r/te,o/re);if(y.clearRect(0,0,r,o),y.fillStyle="rgba(30, 30, 30, 0.85)",y.fillRect(0,0,r,o),t.forEach(U=>{const pe=(U.x-u.minX)*B,V=(U.y-u.minY)*B,se=Math.max((U.width||60)*B,4),me=Math.max((U.height||40)*B,3);y.fillStyle=U.selected?"#ff4d4f":Uo(U.type,U.color),y.fillRect(pe,V,se,me),U.selected&&(y.strokeStyle="#fff",y.lineWidth=1,y.strokeRect(pe-1,V-1,se+2,me+2))}),n){const U=(n.x-u.minX)*B,pe=(n.y-u.minY)*B,V=n.width*B,se=n.height*B;y.strokeStyle="rgba(64, 169, 255, 0.8)",y.lineWidth=2,y.strokeRect(U,pe,V,se),y.fillStyle="rgba(64, 169, 255, 0.1)",y.fillRect(U,pe,V,se)}},[t,n,g,r,o,F]);const A=e.useCallback(y=>{if(!m||!E.current)return;const u=E.current.getBoundingClientRect(),te=y.clientX-u.left,re=y.clientY-u.top,B=F(),U=B.maxX-B.minX,pe=B.maxY-B.minY,V=Math.min(r/U,o/pe),se=te/V+B.minX,me=re/V+B.minY;m({x:se,y:me})},[m,F,r,o]),W=e.useCallback(y=>{k.current=!0,A(y)},[A]),_=e.useCallback(y=>{k.current&&A(y)},[A]),I=e.useCallback(()=>{k.current=!1},[]),P={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:P},e.createElement("div",{className:"rge-minimap-header",onClick:()=>w(!g)},e.createElement("span",{className:"rge-minimap-title"},e.createElement(fe,{value:"map"})," ",O("editor.toolbar.minimap","小地图")),e.createElement("span",{className:"rge-minimap-toggle"},g?"▶":"▼")),!g&&e.createElement("canvas",{ref:E,width:r,height:o,className:"rge-minimap-canvas",onMouseDown:W,onMouseMove:_,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 C.isWorkspaceTabPinned(n)?"取消固定":"固定";case"edit-info":return"编辑信息";case"run-history":return"运行记录";case"debug":return"调试";case"toggle-disabled":return C.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 y;const D=e.useMemo(()=>Xe({locale:r,t:o}),[r,o]),[g,w]=e.useState(!1),[E,k]=e.useState(null),[O,F]=e.useState(null),A=e.useRef(null),W=n||((y=t[0])==null?void 0:y.id)||"",_=t.find(u=>u.id===W),I=E?t.find(u=>u.id===E.tabId):void 0,P=I?C.getEditorWorkspaceTabActions(I):[];return e.useLayoutEffect(()=>{if(!E||!A.current)return;const u=A.current.getBoundingClientRect(),te=C.clampContextMenuPosition({left:E.x,top:E.y},{width:u.width,height:u.height},{width:window.innerWidth,height:window.innerHeight});F(re=>(re==null?void 0:re.left)===te.left&&re.top===te.top?re:te)},[E,P.length]),e.useEffect(()=>{if(!E)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)}},[E]),e.createElement("div",{className:"rge-workspace-tabs",role:"tablist","aria-label":D("editor.workspace.tabs","规则链标签")},e.createElement("div",{className:"rge-workspace-tabs__strip"},t.map(u=>{var pe,V,se;const te=u.id===W,re=((pe=u.metadata)==null?void 0:pe.root)!==!1&&((se=(V=u.data)==null?void 0:V.ruleChain)==null?void 0:se.root)!==!1,B=C.getWorkspaceTabLifecycleState(u),U=C.isWorkspaceTabPinned(u);return e.createElement("div",{key:u.id,className:`rge-workspace-tab${te?" is-active":""}${u.isDirty?" is-dirty":""}`,"data-workspace-tab-id":u.id,role:"tab","aria-selected":te,"aria-busy":u.isLoading||void 0,title:u.isDirty?`${u.title} · ${D("editor.workspace.unsaved","有未保存修改")}`:u.title,onClick:()=>s==null?void 0:s(u.id),onDoubleClick:()=>f==null?void 0:f(u.id),onContextMenu:me=>{me.preventDefault(),me.stopPropagation(),s==null||s(u.id),F({left:me.clientX,top:me.clientY}),k({tabId:u.id,x:me.clientX,y:me.clientY})}},B!=="undeployed"&&e.createElement("span",{className:`rge-workspace-tab__lifecycle is-${B}`,"aria-label":D(`editor.workspace.${B}`,B==="running"?"运行中":"已停止"),title:D(`editor.workspace.${B}`,B==="running"?"运行中":"已停止")}),e.createElement("span",{className:`rge-workspace-tab__kind${re?" is-root":" is-child"}`,"aria-hidden":"true"},U?"★":re?"◆":"↳"),e.createElement("span",{className:"rge-workspace-tab__title"},u.title||u.chainId),u.isLoading&&e.createElement("span",{className:"rge-workspace-tab__loading","aria-label":D("editor.workspace.loading","加载中")}),e.createElement("button",{type:"button",className:"rge-workspace-tab__close","data-workspace-close-id":u.id,"aria-label":`${D("editor.workspace.close","关闭")} ${u.title||u.chainId}`,title:D("editor.workspace.close","关闭"),onClick:me=>{me.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"},D("editor.workspace.empty","打开规则链后显示标签"))),!N&&e.createElement("button",{type:"button",className:"rge-workspace-tabs__icon",title:D("editor.workspace.add","新建规则链"),"aria-label":D("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:D("editor.workspace.all","全部规则链"),"aria-label":D("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 te=C.getWorkspaceTabLifecycleState(u);return e.createElement("button",{key:u.id,type:"button",role:"menuitem",className:u.id===W?"is-active":"",onClick:()=>{s==null||s(u.id),w(!1)}},te!=="undeployed"&&e.createElement("span",{className:`rge-workspace-tab__lifecycle is-${te}`,"aria-hidden":"true"}),C.isWorkspaceTabPinned(u)?"★ ":"",u.isDirty?"● ":"",u.title||u.chainId)}))),_&&e.createElement("span",{className:"rge-workspace-tabs__status","aria-live":"polite"},_.isDirty?"●":""),E&&I&&e.createElement("div",{className:"rge-workspace-tabs__context-menu",ref:A,role:"menu",style:{left:(O==null?void 0:O.left)??E.x,top:(O==null?void 0:O.top)??E.y},onClick:u=>u.stopPropagation()},P.map(u=>{const te=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||!te,onClick:()=>{u.disabled||!te||(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))}},D(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:D="",locale:g,messages:w,t:E}){const k=e.useMemo(()=>Xe({locale:g,messages:w,t:E}),[g,w,E]),[O,F]=e.useState(()=>Xr(t));e.useEffect(()=>{const B=()=>F(Xr(t));if(B(),!!(t!=null&&t.on))return Yr.forEach(U=>{var pe;return(pe=t.on)==null?void 0:pe.call(t,U,B)}),()=>Yr.forEach(U=>{var pe;return(pe=t.off)==null?void 0:pe.call(t,U,B)})},[t]);const A=n??O.nodeCount,W=r??O.edgeCount,_=o??O.selectedCount,I=s??O.zoom,P=B=>{t!=null&&t.zoom&&t.zoom((I>0?I:1)*B)},y=()=>m?m():P(1.2),u=()=>f?f():P(1/1.2),te=()=>{var B;return M?M():(B=t==null?void 0:t.resetZoom)==null?void 0:B.call(t)},re=["rge-status-bar",D].filter(Boolean).join(" ");return e.createElement("div",{className:re,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:te},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:y},"+"),e.createElement("span",{className:"rge-status-bar__separator","aria-hidden":"true"},"|"),e.createElement("span",{className:"rge-status-bar__item"},k("editor.statusBar.nodes","节点")," ",A),e.createElement("span",{className:"rge-status-bar__item"},k("editor.statusBar.edges","边")," ",W),_>0&&e.createElement("span",{className:"rge-status-bar__item"},k("editor.statusBar.selected","已选")," ",_),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(()=>Xe({locale:i,messages:m,t:f}),[i,m,f]),N=String((t==null?void 0:t.status)||"unknown"),D=Qr[N]||Qr.unknown,g=(t==null?void 0:t.api)||"unknown",w=(t==null?void 0:t.ws)||"idle",E=`${M("editor.connection.api","API")}: ${g} · ${M("editor.connection.ws","WS")}: ${w}`,k=["rge-connection-status",`is-${D.kind}`,n?"is-compact":"",s].filter(Boolean).join(" "),O=N==="unauthorized"?o:N==="offline"||N==="error"?r:void 0,F=N==="unauthorized"?M("editor.connection.login","登录"):M("editor.connection.retry","重试");return e.createElement("div",{className:k,role:"status","aria-live":"polite",title:E},e.createElement("span",{className:"rge-connection-status__dot","aria-hidden":"true"}),e.createElement("span",{className:"rge-connection-status__label"},M(D.key,D.fallback)),!n&&e.createElement("span",{className:"rge-connection-status__detail"},E),O&&e.createElement("button",{type:"button",className:"rge-connection-status__action",onClick:O},F))}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:D}){var P;const g=e.useRef(null),w=e.useRef(null),[E,k]=e.useState(!1),O=e.useMemo(()=>Go(r,t),[r,t]),F=r.activeByDock[t]&&O.some(y=>y.id===r.activeByDock[t])?r.activeByDock[t]:((P=O[0])==null?void 0:P.id)||null,A=t==="bottom"?n.bottom.height:n[t].width,W=n[t].visible&&O.length>0,_=t==="left";e.useEffect(()=>()=>{const y=w.current;w.current=null,y==null||y(!1)},[]);const I=y=>{var me,j;if(!D)return;y.preventDefault();const u=t==="bottom"?y.clientY:y.clientX,te=A,re=t==="left"?1:-1,B=y.currentTarget,U=y.pointerId;(me=B.setPointerCapture)==null||me.call(B,U);const pe=be=>{const De=t==="bottom"?be.clientY:be.clientX;D(t,te+(De-u)*re)},V=be=>{var De,$e;window.removeEventListener("pointermove",pe),window.removeEventListener("pointerup",se),window.removeEventListener("pointercancel",se),(De=B.hasPointerCapture)!=null&&De.call(B,U)&&(($e=B.releasePointerCapture)==null||$e.call(B,U)),be&&k(!1),w.current=null},se=()=>V(!0);(j=w.current)==null||j.call(w,!0),w.current=V,k(!0),window.addEventListener("pointermove",pe),window.addEventListener("pointerup",se,{once:!0}),window.addEventListener("pointercancel",se,{once:!0})};return W?e.createElement("section",{ref:g,className:["rge-panel-dock",`rge-panel-dock--${t}`,E&&"is-resizing",i].filter(Boolean).join(" "),style:t==="bottom"?{height:A}:{width:A},"aria-label":s},e.createElement("div",{className:"rge-panel-dock__header"},_?e.createElement("strong",{className:"rge-panel-dock__title"},s||"模块"):e.createElement("div",{className:"rge-panel-dock__tabs",role:"tablist"},O.map(y=>e.createElement("button",{key:y.id,type:"button",role:"tab","aria-selected":y.id===F,className:y.id===F?"is-active":"",onClick:()=>f==null?void 0:f(y.id)},y.icon&&e.createElement("span",{"aria-hidden":"true"},y.icon),y.title||y.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"},_?O.map(y=>e.createElement("div",{key:y.id,className:"rge-panel-dock__stack-panel"},(()=>{const u=en(r,y);return e.createElement(e.Fragment,null,e.createElement("div",{className:"rge-panel-dock__stack-title"},e.createElement("span",null,y.title||y.id),e.createElement("button",{type:"button",title:u?"收起内容":"展开内容","aria-label":`${u?"收起":"展开"}${y.title||y.id}`,"aria-expanded":u,onClick:()=>N==null?void 0:N(y.id,!u)},u?"−":"+"),y.closeable!==!1&&e.createElement("button",{type:"button",title:"关闭面板","aria-label":`关闭${y.title||y.id}`,onClick:()=>M==null?void 0:M(y.id)},"×")),e.createElement("div",{className:"rge-panel-dock__panel-content",hidden:!u},o==null?void 0:o(y)))})())):O.map(y=>e.createElement("div",{key:y.id,className:`rge-panel-dock__tab-panel${en(r,y)?"":" is-collapsed"}`,hidden:y.id!==F},e.createElement("div",{className:"rge-panel-dock__tab-tools"},e.createElement("button",{type:"button",title:en(r,y)?"收起内容":"展开内容","aria-label":`${en(r,y)?"收起":"展开"}${y.title||y.id}`,"aria-expanded":en(r,y),onClick:()=>N==null?void 0:N(y.id,!en(r,y))},en(r,y)?"−":"+"),y.closeable!==!1&&e.createElement("button",{type:"button",title:"关闭面板","aria-label":`关闭${y.title||y.id}`,onClick:()=>M==null?void 0:M(y.id)},"×")),e.createElement("div",{className:"rge-panel-dock__tab-content",hidden:!en(r,y)},o==null?void 0:o(y))))),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:D,onDelete:g,onRunFrom:w,onRunOnly:E,locale:k,messages:O,t:F}){const A=e.useMemo(()=>Xe({locale:k,messages:O,t:F}),[k,O,F]);if(!t||!s)return null;const W=i&&C.isEditorNodeRunTarget(m||"simple-node"),_=(P,y)=>{(P==="run-from"||P==="run-only")&&!W||(y==null||y(s),M==null||M(P,s))},I=(P,y,u,te,re="")=>e.createElement("button",{key:P,type:"button",className:`rge-hover-tools__button ${re}`,title:y,"aria-label":y,onClick:()=>_(P,te)},e.createElement(fe,{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":A("editor.hoverTools.nodeActions","节点操作")},I("edit",A("editor.hoverTools.edit","编辑节点"),"edit",N),I("copy",A("editor.hoverTools.copy","复制节点"),"copy",D),W&&I("run-from",A("editor.hoverTools.runFrom","从此节点开始执行"),"play",w,"is-primary"),W&&I("run-only",A("editor.hoverTools.runOnly","仅执行此节点"),"play-single",E,"is-warning"),I("delete",A("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:D,t:g}){const w=e.useMemo(()=>Xe({locale:N,messages:D,t:g}),[N,D,g]);if(!t||!s)return null;const E=(F,A)=>{A==null||A(s),m==null||m(F,s)},k=w("editor.hoverTools.insertNode","在连线中插入组件"),O=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:()=>E("insert-node",f)},e.createElement(fe,{value:"add"})),e.createElement("button",{type:"button",className:"rge-hover-tools__button is-danger",title:O,"aria-label":O,onClick:()=>E("delete",M)},e.createElement(fe,{value:"delete"})))}const Vn={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:D,t:g})=>{const[w,E]=e.useState("all"),k=e.useMemo(()=>Xe({locale:N,messages:D,t:g}),[N,D,g]),O=s||k("editor.validation.title","规则链校验"),F=e.useMemo(()=>{const W={error:0,warning:0,info:0};return t.forEach(_=>{W[_.level]!==void 0&&W[_.level]++}),W},[t]),A=e.useMemo(()=>w==="all"?t:t.filter(W=>W.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(fe,{value:n?"validate":"error"}),O),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(fe,{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(fe,{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:()=>E("all")},k("editor.validation.all","全部")," (",t.length,")"),e.createElement("button",{className:`rge-validation-stat error ${w==="error"?"active":""}`,onClick:()=>E("error")},e.createElement(fe,{value:Vn.error})," ",F.error),e.createElement("button",{className:`rge-validation-stat warning ${w==="warning"?"active":""}`,onClick:()=>E("warning")},e.createElement(fe,{value:Vn.warning})," ",F.warning),e.createElement("button",{className:`rge-validation-stat info ${w==="info"?"active":""}`,onClick:()=>E("info")},e.createElement(fe,{value:Vn.info})," ",F.info)),e.createElement("div",{className:"rge-validation-body"},o&&e.createElement("div",{className:"rge-validation-loading"},e.createElement(fe,{value:"refresh",className:"is-spinning"}),k("editor.validation.validating","正在校验...")),!o&&A.length===0&&e.createElement("div",{className:"rge-validation-empty"},t.length===0?e.createElement(e.Fragment,null,e.createElement(fe,{value:"validate"})," ",k("editor.validation.empty","无校验结果,请点击校验按钮开始")):k("editor.validation.noFilteredResults","当前筛选无结果")),!o&&A.map((W,_)=>e.createElement("div",{key:`${W.rule}-${W.elementId||_}`,className:`rge-validation-item level-${W.level}`,onClick:()=>m==null?void 0:m(W),role:"button",tabIndex:0},e.createElement("span",{className:"rge-validation-item-icon"},e.createElement(fe,{value:Vn[W.level]})),e.createElement("div",{className:"rge-validation-item-content"},e.createElement("div",{className:"rge-validation-item-message"},W.message),e.createElement("div",{className:"rge-validation-item-meta"},e.createElement("span",{className:"rge-validation-item-rule"},W.rule),W.elementId&&e.createElement("span",{className:"rge-validation-item-element"},e.createElement(fe,{value:W.elementType==="node"?"package":"link"}),W.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:D}){const[g,w]=e.useState("all"),E=e.useMemo(()=>Xe({locale:M,messages:N,t:D}),[M,N,D]),k=e.useMemo(()=>t.reduce((_,I)=>(_[I.severity]+=1,_),{error:0,warning:0,info:0}),[t]),O=e.useMemo(()=>{const _=new Map;return t.filter(I=>g==="all"||I.severity===g).forEach(I=>{const P=el(I),y=_.get(P)||[];y.push(I),_.set(P,y)}),Array.from(_.entries()).map(([I,P])=>({key:I,items:P.sort((y,u)=>Zr[y.severity]-Zr[u.severity])}))},[g,t]);if(!n)return null;const F=o||E("editor.problems.title","链路诊断"),A=_=>E(Zo[_],_==="error"?"错误":_==="warning"?"警告":"提示"),W=(_,I,P,y="")=>e.createElement("button",{type:"button",className:`rge-problems__filter ${y} ${g===_?"is-active":""}`,"aria-pressed":g===_,onClick:()=>w(_)},I," ",e.createElement("span",null,P));return e.createElement("section",{className:"rge-problems","aria-label":F},e.createElement("header",{className:"rge-problems__header"},e.createElement("div",{className:"rge-problems__heading"},e.createElement("strong",null,F),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:E("editor.problems.validate","重新校验")},r?"…":"↻"),m&&t.length>0&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:m,title:E("editor.problems.clear","清除问题")},"⌫"),f&&e.createElement("button",{type:"button",className:"rge-problems__action",onClick:f,title:E("editor.problems.close","关闭")},"×"))),e.createElement("div",{className:"rge-problems__filters",role:"toolbar","aria-label":E("editor.problems.filter","筛选问题")},W("all",E("editor.problems.all","全部"),t.length),W("error",A("error"),k.error,"is-error"),W("warning",A("warning"),k.warning,"is-warning"),W("info",A("info"),k.info,"is-info")),e.createElement("div",{className:"rge-problems__body"},r&&e.createElement("div",{className:"rge-problems__empty"},E("editor.problems.loading","正在校验…")),!r&&O.length===0&&e.createElement("div",{className:"rge-problems__empty"},t.length?E("editor.problems.noFiltered","当前筛选无问题"):E("editor.problems.empty","未发现链路问题")),!r&&O.map(_=>{const I=_.items[0];return e.createElement("div",{className:"rge-problems__group",key:_.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,(P,y)=>E(P,y))),e.createElement("span",{className:"rge-problems__group-count"},_.items.length)),_.items.map(P=>e.createElement("button",{type:"button",className:`rge-problems__item is-${P.severity}`,key:P.id,onClick:()=>i==null?void 0:i(P)},e.createElement("span",{className:"rge-problems__item-severity"},A(P.severity)),e.createElement("span",{className:"rge-problems__item-message"},P.message),e.createElement("span",{className:"rge-problems__item-rule"},P.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[D,g]=e.useState(n),[w,E]=e.useState({}),k=e.useMemo(()=>Xe({locale:f,messages:M,t:N}),[f,M,N]),O=o||k("editor.ruleChainSettings.title","规则链设置");e.useEffect(()=>{g(n),E({})},[n,t]);const F=(_,I)=>{g(P=>({...P,[_]:I})),w[_]&&E(P=>{const y={...P};return delete y[_],y})},A=()=>{const _={};return(!D.name||D.name.trim()==="")&&(_.name=k("editor.ruleChainSettings.nameRequired","规则链名称不能为空")),E(_),Object.keys(_).length===0},W=()=>{r||A()&&(i==null||i(D),m())};return e.useEffect(()=>{const _=I=>{I.key==="Escape"&&t&&m()};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[t,m]),t?e.createElement("div",{className:"rge-modal-overlay",onClick:m},e.createElement("div",{className:"rge-modal",onClick:_=>_.stopPropagation()},e.createElement("div",{className:"rge-modal-header"},e.createElement("span",{className:"rge-modal-title"},e.createElement(fe,{value:"settings"})," ",O),e.createElement("button",{className:"rge-modal-close",onClick:m},"✕")),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"},k("editor.panel.name","名称")," ",e.createElement("span",{className:"rge-required"},"*")),e.createElement("input",{className:`rge-form-input ${w.name?"error":""}`,value:D.name,onChange:_=>F("name",_.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:D.description||"",onChange:_=>F("description",_.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:D.root||!1,onChange:_=>F("root",_.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:D.debugMode||!1,onChange:_=>F("debugMode",_.target.checked),disabled:r}),e.createElement("span",{className:"rge-switch-slider"})))),s.map(_=>e.createElement("div",{className:"rge-form-group",key:_.key},e.createElement("label",{className:"rge-form-label"},_.label),_.type==="text"&&e.createElement("input",{className:"rge-form-input",value:String((D[_.key]??_.defaultValue)||""),onChange:I=>F(_.key,I.target.value),placeholder:_.placeholder,disabled:r}),_.type==="number"&&e.createElement("input",{className:"rge-form-input",type:"number",value:D[_.key]??_.defaultValue??"",onChange:I=>F(_.key,Number(I.target.value)),placeholder:_.placeholder,disabled:r}),_.type==="textarea"&&e.createElement("textarea",{className:"rge-form-textarea",value:String((D[_.key]??_.defaultValue)||""),onChange:I=>F(_.key,I.target.value),placeholder:_.placeholder,rows:3,disabled:r}),_.type==="select"&&e.createElement(Kt,{value:String((D[_.key]??_.defaultValue)||""),options:_.options||[],onChange:I=>F(_.key,I),disabled:r,placeholder:_.placeholder,searchPlaceholder:k("editor.property.searchOptions","搜索选项..."),noMatchText:k("editor.property.noMatchingOptions","没有匹配的选项")}),_.type==="switch"&&e.createElement("label",{className:"rge-switch"},e.createElement("input",{type:"checkbox",checked:D[_.key]??_.defaultValue??!1,onChange:I=>F(_.key,I.target.checked),disabled:r}),e.createElement("span",{className:"rge-switch-slider"})),_.help&&e.createElement("span",{className:"rge-form-help"},_.help))),D.additionalInfo&&Object.keys(D.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(D.additionalInfo,null,2),onChange:_=>{try{F("additionalInfo",JSON.parse(_.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:W},e.createElement(fe,{value:"save"})," ",k("editor.toolbar.save","保存"))))):null};wa.displayName="RuleChainSettings";const Pt=({name:t,className:n=""})=>{const r=C.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 pe,V,se,me,j,be,De,$e,X;const[N,D]=e.useState(t),[g,w]=e.useState(""),[E,k]=e.useState(null),[O,F]=e.useState(""),[A,W]=e.useState(!1),_=e.useRef(null),I=e.useMemo(()=>Xe({locale:m,messages:f,t:M}),[m,f,M]),P=n?JSON.stringify(n,null,2):"",y=e.useCallback(b=>{F(""),w(b);try{const $=JSON.parse(b);if(!$.ruleChain&&!$.metadata){F(I("editor.importExport.invalidRuleChainJson","JSON 格式不符合 RuleGo 规则链规范(缺少 ruleChain 或 metadata 字段)")),k(null);return}k($)}catch($){F(I("editor.importExport.jsonParseFailed","JSON 解析失败: {{message}}",{message:$.message})),k(null)}},[I]),u=e.useCallback(b=>{var ae;const $=(ae=b.target.files)==null?void 0:ae[0];if(!$)return;if(!$.name.endsWith(".json")){F(I("editor.importExport.selectJsonFile","请选择 .json 文件"));return}const Y=new FileReader;Y.onload=L=>{var Se;const Ce=(Se=L.target)==null?void 0:Se.result;y(Ce)},Y.readAsText($)},[y]),te=e.useCallback(b=>{var ae;b.preventDefault(),W(!1);const $=(ae=b.dataTransfer.files)==null?void 0:ae[0];if(!$)return;if(!$.name.endsWith(".json")){F(I("editor.importExport.selectJsonFile","请选择 .json 文件"));return}const Y=new FileReader;Y.onload=L=>{var Se;const Ce=(Se=L.target)==null?void 0:Se.result;y(Ce)},Y.readAsText($)},[y]),re=e.useCallback(()=>{navigator.clipboard.writeText(P).then(()=>{i==null||i("success",I("editor.importExport.copied","已复制到剪贴板"))}).catch(()=>{const b=document.createElement("textarea");b.value=P,document.body.appendChild(b),b.select(),document.execCommand("copy"),document.body.removeChild(b),i==null||i("success",I("editor.importExport.copied","已复制到剪贴板"))})},[P,i,I]),B=e.useCallback(()=>{const $=`${r.replace(/[^a-zA-Z0-9_\-\u4e00-\u9fa5]/g,"_")}_${new Date().toISOString().slice(0,10)}.json`,Y=new Blob([P],{type:"application/json"}),ae=URL.createObjectURL(Y),L=document.createElement("a");L.href=ae,L.download=$,document.body.appendChild(L),L.click(),document.body.removeChild(L),URL.revokeObjectURL(ae),i==null||i("success",I("editor.importExport.downloaded","已下载: {{fileName}}",{fileName:$}))},[P,r,i,I]),U=e.useCallback(()=>{if(!E){i==null||i("error",I("editor.importExport.noImportData","没有可导入的数据"));return}o==null||o(E),i==null||i("success",I("editor.importExport.importSuccess","规则链导入成功")),s()},[E,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(Pt,{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:()=>D("export")},e.createElement(Pt,{name:"export"}),e.createElement("span",null,I("editor.importExport.exportTab","导出"))),e.createElement("button",{type:"button",className:`rge-ie-tab ${N==="import"?"active":""}`,onClick:()=>D("import")},e.createElement(Pt,{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(Pt,{name:"package"}),I("editor.importExport.nodes","节点"),": ",((V=(pe=n==null?void 0:n.metadata)==null?void 0:pe.nodes)==null?void 0:V.length)||0),e.createElement("span",null,e.createElement(Pt,{name:"link"}),I("editor.importExport.edges","连线"),": ",((me=(se=n==null?void 0:n.metadata)==null?void 0:se.connections)==null?void 0:me.length)||0),e.createElement("span",null,e.createElement(Pt,{name:"data"}),I("editor.importExport.size","大小"),": ",(P.length/1024).toFixed(1)," KB")),e.createElement("pre",{className:"rge-ie-preview"},P)):e.createElement(e.Fragment,null,e.createElement("div",{className:`rge-ie-dropzone ${A?"dragover":""} ${g?"has-file":""}`,onDragOver:b=>{b.preventDefault(),W(!0)},onDragLeave:()=>W(!1),onDrop:te,onClick:()=>{var b;return(b=_.current)==null?void 0:b.click()}},e.createElement("input",{ref:_,type:"file",accept:".json",style:{display:"none"},onChange:u}),g?e.createElement("span",{className:"rge-ie-file-name"},e.createElement(Pt,{name:"validate"}),I("editor.importExport.fileLoaded","文件已加载,点击重新选择")):e.createElement(e.Fragment,null,e.createElement(Pt,{name:"import",className:"rge-ie-drop-icon"}),e.createElement("span",{className:"rge-ie-drop-text"},I("editor.importExport.dropHint","拖拽 JSON 文件到此处,或点击选择文件")))),O&&e.createElement("div",{className:"rge-ie-error",role:"alert"},O),E&&e.createElement("div",{className:"rge-ie-import-info"},e.createElement("div",{className:"rge-ie-info"},e.createElement("span",null,e.createElement(Pt,{name:"package"}),I("editor.importExport.nodes","节点"),": ",((be=(j=E==null?void 0:E.metadata)==null?void 0:j.nodes)==null?void 0:be.length)||0),e.createElement("span",null,e.createElement(Pt,{name:"link"}),I("editor.importExport.edges","连线"),": ",(($e=(De=E==null?void 0:E.metadata)==null?void 0:De.connections)==null?void 0:$e.length)||0),e.createElement("span",null,e.createElement(Pt,{name:"edit"}),I("editor.importExport.name","名称"),": ",((X=E==null?void 0:E.ruleChain)==null?void 0:X.name)||I("editor.status.unknown","未知"))),e.createElement("pre",{className:"rge-ie-preview",style:{maxHeight:200}},JSON.stringify(E,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:re},e.createElement(Pt,{name:"copy"}),e.createElement("span",null,I("editor.panel.copy","复制"))),e.createElement("button",{type:"button",className:"rge-btn primary",onClick:B},e.createElement(Pt,{name:"export"}),e.createElement("span",null,I("editor.importExport.downloadFile","下载文件")))):e.createElement("button",{type:"button",className:"rge-btn primary",onClick:U,disabled:!E},e.createElement(Pt,{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,D]=e.useState(0),g=e.useRef(null),w=e.useMemo(()=>Xe({locale:s,messages:i,t:m}),[s,i,m]);e.useEffect(()=>{var A;(A=g.current)==null||A.focus()},[]);const E=e.useMemo(()=>{if(!f.trim())return[];const A=f.toLowerCase().trim();return t.filter(W=>W.name.toLowerCase().includes(A)||W.type.toLowerCase().includes(A)||W.id.toLowerCase().includes(A)||W.typeLabel&&W.typeLabel.toLowerCase().includes(A)||W.extra&&W.extra.toLowerCase().includes(A))},[t,f]),k=e.useCallback(A=>{switch(A.key){case"ArrowDown":A.preventDefault(),D(W=>Math.min(W+1,E.length-1));break;case"ArrowUp":A.preventDefault(),D(W=>Math.max(W-1,0));break;case"Enter":A.preventDefault(),E[N]&&(n==null||n(E[N].id));break;case"Escape":A.preventDefault(),r();break}},[E,N,n,r]),O=e.useCallback(A=>{M(A.target.value),D(0)},[]),F=e.useCallback(A=>{n==null||n(A)},[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:O,onKeyDown:k}),f&&e.createElement("span",{className:"rge-search-count"},w("editor.searchPanel.resultCount","{{count}} 个结果",{count:E.length})),e.createElement("button",{className:"rge-search-close",onClick:r},"✕")),f&&E.length>0&&e.createElement("div",{className:"rge-search-results"},E.map((A,W)=>e.createElement("div",{key:A.id,className:`rge-search-result-item ${W===N?"active":""}`,onClick:()=>F(A.id),onMouseEnter:()=>D(W)},e.createElement("div",{className:"rge-search-result-main"},e.createElement("span",{className:"rge-search-result-name"},ea(A.name,f)),e.createElement("span",{className:"rge-search-result-type"},A.typeLabel||A.type)),e.createElement("div",{className:"rge-search-result-id"},"ID: ",ea(A.id,f))))),f&&E.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=/[\\/.]/,cr=180,ir=260,In=12,ta=new WeakMap;let ll=1;const Qn=t=>{const n=ta.get(t);if(n!==void 0)return n;const r=ll++;return ta.set(t,r),r},vn=(t,n=new WeakSet)=>{if(typeof t=="function")return`[reference:${Qn(t)}]`;if(!t||typeof t!="object")return t;if(n.has(t))return`[circular:${Qn(t)}]`;if(n.add(t),Array.isArray(t))return t.map(o=>vn(o,n));const r=t;return Object.keys(r).sort().reduce((o,s)=>(o[s]=vn(r[s],n),o),{})},Er=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:Er(r),timeout:o.timeout,authToken:o.authToken,headers:vn(o.headers),credentials:o.credentials,customFetch:vn(o.customFetch),onAuthRequired:vn(o.onAuthRequired),serverStatus:o.serverStatus?`[reference:${Qn(o.serverStatus)}]`:void 0,includeStoredToken:o.includeStoredToken,routes:vn(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:D,icons:g,showSearch:w=!0,showCreate:E=!0,showRefresh:k=!0,disabled:O=!1,disabledMessage:F,locale:A,messages:W,t:_,renderHeader:I,renderActions:P,renderEmpty:y,renderCreateForm:u,renderRow:te,onDesign:re,onInfo:B,onViewLogs:U,onChange:pe,onError:V,onCreateSuccess:se}=t,me={...al,...g},j=e.useMemo(()=>Xe({locale:A,messages:W,t:_}),[A,W,_]),be=e.useRef(null),De=e.useRef(""),$e=il(n,r,o),X=s?`external:${Qn(s)}`:"";s?(be.current!==s||De.current!==X)&&(be.current=s,De.current=X):n?(!be.current||De.current!==$e)&&(be.current=new C.RuleChainAPI({apiBase:n,...r}),De.current=$e):be.current&&(be.current=null,De.current="");const b=be.current,$=s?`${X}|context:${Er(o)}`:n?`internal:${$e}`:`none:${Er(o)}`,Y=e.useRef({api:null,identity:"",disabled:!1,generation:0});(Y.current.api!==b||Y.current.identity!==$||Y.current.disabled!==O)&&(Y.current={api:b,identity:$,disabled:O,generation:Y.current.generation+1});const ae=e.useRef(!1),L=e.useRef(0),Ce=e.useRef(0),[Se,oe]=e.useState([]),[he,Te]=e.useState(0),[Ee,Me]=e.useState(1),xe=i,[ce,le]=e.useState(""),[ke,ye]=e.useState(!1),[J,Oe]=e.useState(!1),[Ze,z]=e.useState(""),[Ge,dt]=e.useState(null),[ot,Ht]=e.useState(null),[Ft,Bt]=e.useState(()=>C.RuleChainAPI.generateChainId()),[Rt,Ct]=e.useState(""),[rt,Mt]=e.useState(""),[Ve,$t]=e.useState(!0),[wt,At]=e.useState(!1),[yt,Ot]=e.useState(!0),[Dt,Wt]=e.useState(""),[_t,Re]=e.useState(()=>f??!!re),[Ut,pt]=e.useState(""),[Be,ne]=e.useState(null),[Q,_e]=e.useState(null),Ne=Q===Y.current.generation,Le=Ne?Se:[],Je=Ne?he:0,St=e.useRef({page:Ee,keywords:ce,onError:V});St.current={page:Ee,keywords:ce,onError:V};const Ie=e.useRef({onChange:pe,onError:V,onCreateSuccess:se,onDesign:re});Ie.current={onChange:pe,onError:V,onCreateSuccess:se,onDesign:re};const d=e.useCallback(K=>ae.current&&Y.current===K,[]),ve=e.useCallback((K,de)=>d(K)&&Ce.current===de,[d]);e.useEffect(()=>(ae.current=!0,()=>{ae.current=!1,L.current+=1,Ce.current+=1}),[]),e.useEffect(()=>{Ce.current+=1,ne(null)},[$,O]);const Fe=e.useCallback(()=>{dt(null),Ht(null)},[]);e.useEffect(()=>{z(""),Me(1),Fe(),Oe(!1),pt("")},[$,O,Fe]);const v=e.useCallback((K,de)=>{if(K.stopPropagation(),Ge===de){Fe();return}const ie=K.currentTarget.getBoundingClientRect(),we=window.innerWidth||document.documentElement.clientWidth||cr,We=window.innerHeight||document.documentElement.clientHeight||ir,st=Math.max(In,we-cr-In),tt=Math.min(Math.max(In,ie.right-cr),st);let Ye=ie.bottom+8;Ye+ir>We-In&&(Ye=Math.max(In,ie.top-ir-8)),dt(de),Ht({id:de,top:Ye,left:tt})},[Fe,Ge]);e.useEffect(()=>{if(!Ge)return;const K=ie=>{var We;const we=ie.target;(We=we==null?void 0:we.closest)!=null&&We.call(we,".huanban_rulego_list__actions--floating, .huanban_rulego_list__row_more")||Fe()},de=ie=>{ie.key==="Escape"&&Fe()};return document.addEventListener("pointerdown",K),document.addEventListener("keydown",de),window.addEventListener("resize",Fe),window.addEventListener("scroll",Fe,!0),()=>{document.removeEventListener("pointerdown",K),document.removeEventListener("keydown",de),window.removeEventListener("resize",Fe),window.removeEventListener("scroll",Fe,!0)}},[Fe,Ge]);const S=e.useCallback(()=>{Bt(C.RuleChainAPI.generateChainId()),Ct(""),Mt(""),$t(!0),At(!1),Ot(!0),Wt(""),Re(f??!!re),pt("")},[f,re]),q=e.useCallback(()=>{S(),Oe(!0)},[S]),H=e.useCallback(()=>{Oe(!1),pt("")},[]),ee=e.useCallback(async(K,de)=>{var Ye,gt;const ie=Y.current,we=ie.api,{page:We,keywords:st}=St.current;if(!we||ie.disabled){d(ie)&&ye(!1);return}const tt=++L.current;ye(!0);try{const ct=await we.list(K??We,xe,de??st);if(!d(ie)||L.current!==tt)return;oe(ct.items),Te(ct.total),_e(ie.generation)}catch(ct){if(!d(ie)||L.current!==tt)return;(gt=(Ye=St.current).onError)==null||gt.call(Ye,ct instanceof Error?ct:new Error(String(ct)))}finally{d(ie)&&L.current===tt&&ye(!1)}},[d,xe]);e.useEffect(()=>{if(O){L.current+=1,ye(!1);return}ee(1)},[$,O,ee]);const qe=e.useCallback(()=>{Me(1),ee(1,ce),Fe()},[Fe,ce,ee]),He=e.useCallback(K=>{K.key==="Enter"&&qe()},[qe]),it=Math.max(1,Math.ceil(Je/xe)),et=e.useCallback(()=>{Ee>1&&(Me(Ee-1),ee(Ee-1))},[Ee,ee]),kt=e.useCallback(()=>{Ee<it&&(Me(Ee+1),ee(Ee+1))},[Ee,it,ee]),je=e.useCallback(async(K,de)=>{var st,tt,Ye,gt,ct,vt;const ie=Y.current,we=ie.api;if(!we||ie.disabled)return;const We=++Ce.current;ne(K);try{const ft=await we.operate(K,de);if(!ve(ie,We))return;if(!ft.success){(tt=(st=Ie.current).onError)==null||tt.call(st,new Error(ft.msg||j("editor.workflowList.operateFailed","操作失败")));return}if(Fe(),await ee(),!ve(ie,We))return;(gt=(Ye=Ie.current).onChange)==null||gt.call(Ye)}catch(ft){ve(ie,We)&&((vt=(ct=Ie.current).onError)==null||vt.call(ct,ft instanceof Error?ft:new Error(String(ft))))}finally{ve(ie,We)&&ne(null)}},[Fe,ve,ee,j]),ut=e.useCallback(async K=>{var We,st,tt,Ye,gt,ct;const de=Y.current,ie=de.api;if(!ie||de.disabled)return;const we=++Ce.current;ne(K);try{const vt=await ie.copy(K);if(!ve(de,we))return;if(!vt.success){(st=(We=Ie.current).onError)==null||st.call(We,new Error(vt.msg||j("editor.workflowList.copyFailed","复制失败")));return}if(Fe(),await ee(),!ve(de,we))return;(Ye=(tt=Ie.current).onChange)==null||Ye.call(tt)}catch(vt){ve(de,we)&&((ct=(gt=Ie.current).onError)==null||ct.call(gt,vt instanceof Error?vt:new Error(String(vt))))}finally{ve(de,we)&&ne(null)}},[Fe,ve,ee,j]),Vt=e.useCallback(async(K,de)=>{var st,tt,Ye,gt,ct,vt;if(!window.confirm(j("editor.workflowList.confirmDelete","确定删除工作流「{{name}}」吗?此操作不可恢复。",{name:de})))return;const ie=Y.current,we=ie.api;if(!we||ie.disabled)return;const We=++Ce.current;ne(K);try{const ft=await we.remove(K);if(!ve(ie,We))return;if(!ft.success){(tt=(st=Ie.current).onError)==null||tt.call(st,new Error(ft.msg||j("editor.workflowList.deleteFailed","删除失败")));return}if(Fe(),await ee(),!ve(ie,We))return;(gt=(Ye=Ie.current).onChange)==null||gt.call(Ye)}catch(ft){ve(ie,We)&&((vt=(ct=Ie.current).onError)==null||vt.call(ct,ft instanceof Error?ft:new Error(String(ft))))}finally{ve(ie,We)&&ne(null)}},[Fe,ve,ee,j]),lt=e.useCallback(async K=>{var Ye,gt,ct,vt,ft,an,xt,bt;const de=Y.current,ie=de.api;if(!ie||de.disabled)return;const we=++Ce.current,We=Ft.trim();if(!K){if(!We||ol.test(We)){pt(j("editor.workflowList.idInvalid","ID 不能为空,且不能包含 /、\\ 或 ."));return}pt("")}const st=new Date().toISOString(),tt=K||{ruleChain:{id:We,name:Rt.trim()||j("editor.workflowList.defaultName","新工作流"),root:Ve,disabled:yt,debugMode:wt,additionalInfo:{description:rt.trim(),category:Dt.trim(),createTime:st,updateTime:st,debugMode:wt}},metadata:{firstNodeIndex:0,nodes:[],connections:[],endpoints:[]}};try{const Gt=await ie.create(tt);if(!ve(de,we))return;if(!Gt.success){(gt=(Ye=Ie.current).onError)==null||gt.call(Ye,new Error(Gt.msg||j("editor.workflowList.createFailed","创建失败")));return}if(Oe(!1),S(),await ee(),!ve(de,we))return;(vt=(ct=Ie.current).onChange)==null||vt.call(ct);const Nt=tt.ruleChain,Tt=String((Nt==null?void 0:Nt.id)??"");Tt&&((an=(ft=Ie.current).onCreateSuccess)==null||an.call(ft,Tt)),Tt&&_t&&Ie.current.onDesign&&Ie.current.onDesign(Tt)}catch(Gt){ve(de,we)&&((bt=(xt=Ie.current).onError)==null||bt.call(xt,Gt instanceof Error?Gt:new Error(String(Gt))))}},[Ft,Rt,rt,Ve,yt,wt,Dt,ee,_t,S,d,ve,j]),It=e.useCallback(K=>{z(K.id),Fe(),B==null||B(K)},[Fe,B]),Qe=e.useCallback((K,de)=>{if(K.key==="Enter"){K.preventDefault(),re&&re(de.id);return}K.key===" "&&(K.preventDefault(),It(de))},[It,re]),cn=K=>{const de=Be===K.id;return e.createElement(e.Fragment,null,re&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--design",disabled:de,onClick:ie=>{ie.stopPropagation(),Fe(),re(K.id)},title:j("editor.workflowList.design","设计")},e.createElement(fe,{value:me.design})," ",e.createElement("span",null,j("editor.workflowList.design","设计"))),B&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--info",disabled:de,onClick:ie=>{ie.stopPropagation(),It(K)},title:j("editor.workflowList.info","信息")},e.createElement(fe,{value:me.info})," ",e.createElement("span",null,j("editor.workflowList.info","信息"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--operate",disabled:de,onClick:ie=>{ie.stopPropagation(),je(K.id,K.deployed?"stop":"start")},title:K.deployed?j("editor.workflowList.offlineAction","下线"):j("editor.workflowList.onlineAction","部署")},e.createElement(fe,{value:K.deployed?me.stop:me.start}),e.createElement("span",null,K.deployed?j("editor.workflowList.offlineAction","下线"):j("editor.workflowList.onlineAction","部署"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--copy",disabled:de,onClick:ie=>{ie.stopPropagation(),ut(K.id)},title:j("editor.panel.copy","复制")},e.createElement(fe,{value:me.copy})," ",e.createElement("span",null,j("editor.panel.copy","复制"))),e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--delete",disabled:de,onClick:ie=>{ie.stopPropagation(),Vt(K.id,K.name)},title:j("editor.panel.delete","删除")},e.createElement(fe,{value:me.delete})," ",e.createElement("span",null,j("editor.panel.delete","删除"))),U&&e.createElement("button",{className:"huanban_rulego_list__action_btn huanban_rulego_list__action_btn--logs",disabled:de,onClick:ie=>{ie.stopPropagation(),Fe(),U(K.id,K)},title:j("editor.workflowList.logs","日志")},e.createElement(fe,{value:me.logs})," ",e.createElement("span",null,j("editor.workflowList.logs","日志"))))},nn=(K,de="huanban_rulego_list__actions")=>e.createElement("div",{className:de},cn(K)),Ln=(K,de)=>{const ie=nn(K),we=P?P(K,ie):ie,We=Ze===K.id,st=K.deployed?j("editor.workflowList.online","运行"):j("editor.workflowList.offline","停用"),tt=cl(K,"category");return e.createElement("article",{className:`huanban_rulego_list__row ${K.deployed?"huanban_rulego_list__row--deployed":"huanban_rulego_list__row--offline"} ${We?"huanban_rulego_list__row--selected":""}`,key:K.id,"data-id":K.id,role:"button",tabIndex:0,title:j("editor.workflowList.rowHint","单击查看信息,双击进入设计"),onClick:()=>It(K),onDoubleClick:()=>re==null?void 0:re(K.id),onKeyDown:Ye=>Qe(Ye,K)},e.createElement("div",{className:"huanban_rulego_list__row_main"},e.createElement("span",{className:`huanban_rulego_list__row_icon ${K.root?"huanban_rulego_list__row_icon--root":"huanban_rulego_list__row_icon--sub"}`},e.createElement(fe,{value:K.root?me.workflow:me.subWorkflow})),e.createElement("div",{className:"huanban_rulego_list__row_info"},e.createElement("span",{className:"huanban_rulego_list__row_name"},K.name),e.createElement("span",{className:"huanban_rulego_list__row_id"},K.id),(tt||K.root)&&e.createElement("span",{className:"huanban_rulego_list__row_meta"},K.root?j("editor.workflowList.rootChain","主链"):j("editor.workflowList.subChain","子链"),tt?` · ${tt}`:"")),e.createElement("div",{className:`huanban_rulego_list__row_menu ${Ge===K.id?"huanban_rulego_list__row_menu--open":""}`},e.createElement("button",{className:"huanban_rulego_list__row_more",type:"button",title:j("editor.workflowList.more","更多操作"),onClick:Ye=>{v(Ye,K.id)}},"•••"),m==="list"?we:null)),K.description&&e.createElement("div",{className:"huanban_rulego_list__row_desc"},K.description),e.createElement("div",{className:"huanban_rulego_list__row_footer"},e.createElement("span",{className:"huanban_rulego_list__row_time"},j("editor.workflowList.updateTime","更新时间"),": ",sl(K.updateTime||K.createTime)),e.createElement("span",{className:`huanban_rulego_list__row_status ${K.deployed?"huanban_rulego_list__row_status--on":"huanban_rulego_list__row_status--off"}`},st)))},un=e.createElement("div",{className:"huanban_rulego_list__header"},e.createElement("h3",{className:"huanban_rulego_list__title"},e.createElement(fe,{value:me.workflow})," ",j("editor.workflowList.title","工作流列表"),e.createElement("span",{className:"huanban_rulego_list__count"},"(",Je,")")),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:j("editor.workflowList.searchPlaceholder","搜索工作流..."),value:ce,onChange:K=>le(K.target.value),onKeyDown:He}),e.createElement("button",{className:"huanban_rulego_list__search_btn",onClick:qe,title:j("editor.toolbar.searchNode","搜索")},e.createElement(fe,{value:me.search}))),k&&e.createElement("button",{className:"huanban_rulego_list__toolbar_btn",onClick:()=>ee(),title:j("editor.chainSelector.refresh","刷新"),disabled:ke||O},e.createElement(fe,{value:me.refresh})),E&&e.createElement("button",{className:"huanban_rulego_list__toolbar_btn huanban_rulego_list__toolbar_btn--primary",onClick:q,title:j("editor.workflowList.createTitle","新建工作流"),disabled:O},e.createElement(fe,{value:me.add})," ",j("editor.workflowList.create","新建")))),Mn=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"},j("editor.workflowList.id","ID"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:Ft,onChange:K=>{Bt(K.target.value),pt("")},placeholder:j("editor.workflowList.idPlaceholder","规则链 ID,不可包含 /、\\ 或 ."),autoFocus:!0})),e.createElement("label",{className:"huanban_rulego_list__form_label"},j("editor.panel.name","名称"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:Rt,onChange:K=>Ct(K.target.value),placeholder:j("editor.workflowList.namePlaceholder","输入工作流名称")}))),e.createElement("div",{className:"huanban_rulego_list__form_group"},e.createElement("span",{className:"huanban_rulego_list__form_group_label"},j("editor.workflowList.chainType","规则链类型")),e.createElement("div",{className:"huanban_rulego_list__segmented",role:"group"},e.createElement("button",{type:"button",className:Ve?"active":"",onClick:()=>$t(!0)},j("editor.workflowList.rootChain","主链")),e.createElement("button",{type:"button",className:Ve?"":"active",onClick:()=>$t(!1)},j("editor.workflowList.subChain","子链")))),e.createElement("div",{className:"huanban_rulego_list__form_group"},e.createElement("span",{className:"huanban_rulego_list__form_group_label"},j("editor.workflowList.initialStatus","初始状态")),e.createElement("div",{className:"huanban_rulego_list__segmented",role:"group"},e.createElement("button",{type:"button",className:yt?"active":"",onClick:()=>Ot(!0)},j("editor.workflowList.initialStopped","停用")),e.createElement("button",{type:"button",className:yt?"":"active",onClick:()=>Ot(!1)},j("editor.workflowList.initialRunning","运行")))),e.createElement("label",{className:"huanban_rulego_list__form_switch",title:j("editor.workflowList.debugModeHint","开启后每条消息都会记录调试日志,并覆盖节点调试配置;会影响运行性能,生产环境建议关闭。编辑器手动调试不受影响。")},e.createElement("input",{type:"checkbox",checked:wt,onChange:K=>At(K.target.checked)}),e.createElement("span",null,j("editor.workflowList.debugMode","调试模式"))),e.createElement("label",{className:"huanban_rulego_list__form_label"},j("editor.workflowList.category","分类"),e.createElement("input",{className:"huanban_rulego_list__form_input",type:"text",value:Dt,onChange:K=>Wt(K.target.value),placeholder:j("editor.workflowList.categoryPlaceholder","可选分类,如 IoT / AI / 数据同步")})),e.createElement("label",{className:"huanban_rulego_list__form_label"},j("editor.panel.description","描述"),e.createElement("textarea",{className:"huanban_rulego_list__form_textarea",value:rt,onChange:K=>Mt(K.target.value),placeholder:j("editor.workflowList.descriptionPlaceholder","可选描述"),rows:3})),re&&e.createElement("label",{className:"huanban_rulego_list__form_switch"},e.createElement("input",{type:"checkbox",checked:_t,onChange:K=>Re(K.target.checked)}),e.createElement("span",null,j("editor.workflowList.openAfterCreate","创建后进入编辑器"))),Ut&&e.createElement("div",{className:"huanban_rulego_list__form_error"},Ut)),$n=e.createElement("div",{className:"huanban_rulego_list__empty"},e.createElement("span",{className:"huanban_rulego_list__empty_icon"},e.createElement(fe,{value:me.workflow})),e.createElement("p",null,j("editor.workflowList.empty","暂无工作流")),E&&e.createElement("button",{className:"huanban_rulego_list__empty_btn",onClick:q},e.createElement(fe,{value:me.add})," ",j("editor.workflowList.createFirst","创建第一个工作流"))),rn=M!=="light"?`huanban_rulego_list--${M}`:"",zt=Ge?Le.find(K=>K.id===Ge):void 0,An=m==="grid"&&ot&&zt&&typeof document<"u"?ca.createPortal(P?e.createElement("div",{className:"huanban_rulego_list__actions huanban_rulego_list__actions--floating",style:{top:ot.top,left:ot.left},onClick:K=>K.stopPropagation(),onPointerDown:K=>K.stopPropagation()},P(zt,nn(zt))):e.createElement("div",{className:"huanban_rulego_list__actions huanban_rulego_list__actions--floating",style:{top:ot.top,left:ot.left},onClick:K=>K.stopPropagation(),onPointerDown:K=>K.stopPropagation()},cn(zt)),document.body):null;return e.createElement("div",{className:`huanban_rulego_list huanban_rulego_list--layout-${m} ${rn} ${N}`.trim(),style:D},I?I(un):un,e.createElement("div",{className:"huanban_rulego_list__body"},O&&e.createElement("div",{className:"huanban_rulego_list__empty"},e.createElement("span",{className:"huanban_rulego_list__empty_icon"},e.createElement(fe,{value:me.workflow})),e.createElement("p",null,F||j("editor.workflowList.loginRequired","请先登录后查看工作流。"))),!O&&ke&&e.createElement("div",{className:"huanban_rulego_list__loading"},e.createElement("span",{className:"huanban_rulego_list__spinner"}),j("editor.panel.loading","加载中...")),!O&&!ke&&Le.length===0&&(y?y():$n),!O&&!ke&&Le.length>0&&e.createElement("div",{className:`huanban_rulego_list__rows huanban_rulego_list__rows--${m}`},Le.map((K,de)=>{const ie=Ln(K);return te?e.createElement(e.Fragment,{key:K.id},te(K,de,ie)):e.createElement(e.Fragment,{key:K.id},ie)}))),An,!O&&Je>xe&&e.createElement("div",{className:"huanban_rulego_list__pagination"},e.createElement("button",{className:"huanban_rulego_list__page_btn",disabled:Ee<=1,onClick:et},j("editor.chainSelector.prevPage","上一页")),e.createElement("span",{className:"huanban_rulego_list__page_info"},Ee," / ",it),e.createElement("button",{className:"huanban_rulego_list__page_btn",disabled:Ee>=it,onClick:kt},j("editor.chainSelector.nextPage","下一页"))),J&&e.createElement("div",{className:"huanban_rulego_list__modal_mask",onClick:H},e.createElement("div",{className:"huanban_rulego_list__modal",onClick:K=>K.stopPropagation()},e.createElement("div",{className:"huanban_rulego_list__modal_header"},e.createElement("h4",null,j("editor.workflowList.createTitle","新建工作流")),e.createElement("button",{className:"huanban_rulego_list__modal_close",onClick:H},"✕")),e.createElement("div",{className:"huanban_rulego_list__modal_body"},u?u(Mn,{close:H,submit:K=>lt(K)}):Mn),e.createElement("div",{className:"huanban_rulego_list__modal_footer"},e.createElement("button",{className:"huanban_rulego_list__btn huanban_rulego_list__btn--cancel",onClick:H},j("editor.panel.cancel","取消")),e.createElement("button",{className:"huanban_rulego_list__btn huanban_rulego_list__btn--primary",onClick:()=>lt()},_t&&re?j("editor.workflowList.createAndOpen","创建并打开"):j("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:D,virtualization:g}){const w=e.useMemo(()=>n?null:new C.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]),E=n||w,[k,O]=e.useState(()=>E.getState()),[F,A]=e.useState(s||""),[W,_]=e.useState(0),I=e.useRef(null);e.useEffect(()=>E.subscribe(O),[E]),e.useEffect(()=>()=>{w==null||w.destroy()},[w]),e.useEffect(()=>{E.setWorkflows(t)},[E,t]),e.useEffect(()=>{E.setActiveChainId(o)},[E,o]),e.useEffect(()=>{s===void 0||s===F||(A(s),E.setKeyword(s))},[s,F,E]);const P=e.useMemo(()=>Sa(k.tree,new Set(k.expandedKeys)),[k.tree,k.expandedKeys]),y=e.useMemo(()=>({enabled:(g==null?void 0:g.enabled)!==!1,threshold:Math.max(1,(g==null?void 0:g.threshold)??C.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)??C.DEFAULT_VIRTUAL_WINDOW_VIEWPORT_HEIGHT),overscan:Math.max(0,(g==null?void 0:g.overscan)??C.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=y.enabled&&P.length>y.threshold,te=e.useMemo(()=>C.calculateVirtualWindow({total:P.length,itemHeight:y.itemHeight,viewportHeight:y.viewportHeight,scrollTop:W,overscan:y.overscan}),[P.length,y,W]),re=u?P.slice(te.start,te.end):P,B=e.useMemo(()=>P.findIndex(V=>{var se;return V.node.kind==="chain"&&((se=V.node.chain)==null?void 0:se.id)===o}),[P,o]);e.useEffect(()=>{if(!u||B<0)return;const V=Math.floor(W/y.itemHeight),se=Math.ceil((W+y.viewportHeight)/y.itemHeight);let me=W;B<V?me=B*y.itemHeight:B>=se&&(me=(B+1)*y.itemHeight-y.viewportHeight),me!==W&&_(me)},[o,B,u,P,y.itemHeight,y.viewportHeight]),e.useEffect(()=>{const V=I.current;if(!V)return;const se=u?te.scrollTop:0;V.scrollTop!==se&&(V.scrollTop=se)},[u,te.scrollTop]);const U=V=>{A(V),E.setKeyword(V),N==null||N(V)},pe=({node:V,depth:se},me)=>{var $e,X;const j=!!(($e=V.children)!=null&&$e.length),be=k.expandedKeys.includes(V.key),De=V.kind==="chain"&&((X=V.chain)==null?void 0:X.id)===o;return e.createElement("button",{key:V.key,type:"button",role:"treeitem","aria-level":se+1,"aria-posinset":me+1,"aria-setsize":P.length,"aria-expanded":j?be:void 0,"aria-selected":V.kind==="chain"?De:void 0,className:`huanban_workflow_explorer__row is-${V.kind}${De?" is-active":""}`,style:{paddingInlineStart:8+se*14},onClick:()=>{j?E.setExpanded(V.key,!be):V.chain&&(D==null||D(V.chain))},title:V.chain?`${V.chain.name}
8
- ${V.chain.id}`:V.label},e.createElement("span",{className:`huanban_workflow_explorer__chevron${j&&be?" is-open":""}`,"aria-hidden":"true"}),e.createElement("span",{className:`huanban_workflow_explorer__kind is-${V.kind}`,"aria-hidden":"true"}),e.createElement("span",{className:"huanban_workflow_explorer__label"},V.label),V.kind==="chain"&&V.chain?e.createElement("span",{className:`huanban_workflow_explorer__status${V.chain.disabled?" is-offline":" is-online"}`,title:V.chain.disabled?"已下线":"运行中"}):null,V.count!==void 0?e.createElement("span",{className:"huanban_workflow_explorer__count"},V.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:F,onChange:V=>U(V.target.value),placeholder:i,"aria-label":i}),F?e.createElement("button",{type:"button",className:"huanban_workflow_explorer__clear",onClick:()=>U(""),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?P.length:void 0,style:u?{height:`${te.viewportHeight}px`}:void 0,onScroll:V=>{if(!u)return;const se=V.currentTarget.scrollTop;_(me=>me===se?me:se)}},P.length===0?e.createElement("div",{className:"huanban_workflow_explorer__empty"},m):u?e.createElement("div",{className:"huanban_workflow_explorer__virtual-canvas",style:{height:`${te.totalHeight}px`}},e.createElement("div",{className:"huanban_workflow_explorer__virtual-items",style:{transform:`translateY(${te.offsetTop}px)`}},re.map((V,se)=>pe(V,te.start+se)))):P.map(pe)))}function qn(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,D]=e.useState(null),[g,w]=e.useState(null),[E,k]=e.useState(null),[O,F]=e.useState(null),[A,W]=e.useState(null),_=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)),P=e.useMemo(()=>Xe({locale:s,messages:i,t:m}),[s,i,m]),y=e.useMemo(()=>({validate:P("editor.maintenance.runValidate","运行校验"),schemaDiff:P("editor.maintenance.schemaDiff","结构差异"),repairPlan:P("editor.maintenance.repairPlan","修复建议"),patchPreview:P("editor.maintenance.patchPreview","补丁预览")}),[P]),u=e.useCallback(async te=>{if(!n||!I){D({type:"error",text:P("editor.maintenance.noApi","当前请求适配器未提供维护接口")});return}M(te),D({type:"info",text:`${y[te]}...`});try{switch(te){case"validate":w(await n.validateUpstream(t.id,_));break;case"schemaDiff":k(await n.getSchemaDiff(t.id));break;case"repairPlan":F(await n.getRepairPlan(t.id,_));break;case"patchPreview":{const re=[];W(await n.previewPatch(t.id,_,re));break}}D({type:"success",text:`${y[te]}${P("editor.maintenance.finished","已完成")}`})}catch(re){const B=re instanceof Error?re:new Error(String(re));D({type:"error",text:`${y[te]}${P("editor.maintenance.failed","失败")}: ${B.message}`}),o==null||o(B)}finally{M(null)}},[y,_,n,I,o,P,t.id]);return I?e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},P("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"?P("editor.maintenance.validating","校验中..."):P("editor.maintenance.runValidate","运行校验")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:f!==null,onClick:()=>u("schemaDiff")},P("editor.maintenance.schemaDiff","结构差异")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:f!==null,onClick:()=>u("repairPlan")},P("editor.maintenance.repairPlan","修复建议")),e.createElement("button",{className:"huanban_rulego_info__copy_btn",disabled:f!==null,onClick:()=>u("patchPreview")},P("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,P("editor.maintenance.validateResult","校验结果"),":",g.valid?P("editor.maintenance.valid","通过"):P("editor.maintenance.invalid","未通过")),qn(g.issues,P)),E&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,P("editor.maintenance.schemaDiff","结构差异")),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(E.changes||[],null,2)),qn(E.issues,P)),O&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,P("editor.maintenance.repairPlan","修复建议")),O.summary&&e.createElement("p",null,O.summary),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(O.plan||[],null,2)),qn(O.issues,P)),A&&e.createElement("section",{className:"huanban_rulego_info__maintenance_section"},e.createElement("h5",null,P("editor.maintenance.patchPreview","补丁预览")),qn(A.rejected,P),e.createElement("pre",{className:"huanban_rulego_info__maintenance_pre"},JSON.stringify(A.preview||{},null,2)))):e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},P("editor.maintenance.title","维护验证")),e.createElement("div",{className:"huanban_rulego_info__maintenance_empty"},P("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 yr=t=>{const n=na.get(t);if(n!==void 0)return n;const r=fl++;return na.set(t,r),r},Cn=(t,n=new WeakSet)=>{if(typeof t=="function")return`[reference:${yr(t)}]`;if(!t||typeof t!="object")return t;if(n.has(t))return`[circular:${yr(t)}]`;if(n.add(t),Array.isArray(t))return t.map(o=>Cn(o,n));const r=t;return Object.keys(r).sort().reduce((o,s)=>(o[s]=Cn(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:Cn(o.headers),credentials:o.credentials,customFetch:Cn(o.customFetch),onAuthRequired:Cn(o.onAuthRequired),serverStatus:o.serverStatus?`[reference:${yr(o.serverStatus)}]`:void 0,includeStoredToken:o.includeStoredToken,routes:Cn(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 Jn(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 C.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=C.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=Jn((n==null?void 0:n.ruleChain)??n),s=Jn(o.additionalInfo),m={...Jn(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:D="确定删除选中的 {{count}} 项吗?",deleteConfirm:g="确定删除“{{key}}”吗?",selectLabel:w="选择",selectedCountLabel:E="已选择 {{count}} 项",selectRowLabel:k="选择第 {{index}} 项"})=>{const[O,F]=e.useState([]),A=e.useRef(null),W=t.length>0&&O.length===t.length,_=O.length>0&&!W;e.useEffect(()=>{F(B=>C.normalizeKeyValueSelection(B,t.length))},[t.length]),e.useEffect(()=>{A.current&&(A.current.indeterminate=_)},[_]);const I=()=>n([...t,{key:"",value:""}]),P=B=>{var pe;const U=g.replace("{{key}}",((pe=t[B])==null?void 0:pe.key)||o);typeof window<"u"&&!window.confirm(U)||(n(C.removeKeyValueEntriesAtIndexes(t,[B])),F(V=>V.filter(se=>se!==B).map(se=>se>B?se-1:se)))},y=B=>{F(U=>U.includes(B)?U.filter(pe=>pe!==B):C.normalizeKeyValueSelection([...U,B],t.length))},u=()=>{F(W?[]:t.map((B,U)=>U))},te=()=>{if(!O.length)return;const B=D.replace("{{count}}",String(O.length));typeof window<"u"&&!window.confirm(B)||(n(C.removeKeyValueEntriesAtIndexes(t,O)),F([]))},re=(B,U,pe)=>{const V=[...t];V[B]={...V[B],[U]:pe},n(V)};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:A,type:"checkbox",checked:W,disabled:!t.length,onChange:u,"aria-label":w}),e.createElement("span",null,O.length?E.replace("{{count}}",String(O.length)):w)),e.createElement("button",{className:"huanban_rulego_info__kv_batch_del",type:"button",disabled:!O.length,onClick:te},e.createElement(fe,{value:r.delete})," ",N,O.length?` (${O.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((B,U)=>e.createElement("div",{className:"huanban_rulego_info__kv_row",key:U},e.createElement("input",{className:"huanban_rulego_info__kv_checkbox",type:"checkbox",checked:O.includes(U),onChange:()=>y(U),"aria-label":k.replace("{{index}}",String(U+1))}),e.createElement("input",{className:"huanban_rulego_info__kv_input",type:"text",placeholder:o,value:B.key,onChange:pe=>re(U,"key",pe.target.value)}),e.createElement("input",{className:"huanban_rulego_info__kv_input",type:i,placeholder:s,value:B.value,onChange:pe=>re(U,"value",pe.target.value)}),e.createElement("button",{className:"huanban_rulego_info__kv_del",onClick:()=>P(U),title:f},e.createElement(fe,{value:r.delete})))),e.createElement("button",{className:"huanban_rulego_info__kv_add",onClick:I},e.createElement(fe,{value:r.add})," ",M))},vl=t=>{var Be;const{apiBase:n,apiOptions:r,apiContextKey:o,fetcher:s,workflow:i,theme:m="light",className:f="",style:M,icons:N,defaultTab:D="base",showMaintenance:g=!1,renderBaseInfo:w,renderVarsSecrets:E,renderIntegration:k,renderExtraTabs:O,onSave:F,onError:A,onRefresh:W,locale:_,messages:I,t:P}=t,y={...pl,...N},u=e.useMemo(()=>Xe({locale:_,messages:I,t:P}),[_,I,P]),te=e.useRef(null),re=e.useRef(""),B=hl(n,r,o);s?te.current!==s&&(te.current=s,re.current="external"):n?(!te.current||re.current!==B)&&(te.current=new C.RuleChainAPI({apiBase:n,...r}),re.current=B):te.current&&(te.current=null,re.current="");const U=te.current,[pe,V]=e.useState(D),[se,me]=e.useState(""),[j,be]=e.useState(!1),[De,$e]=e.useState(!1),[X,b]=e.useState(""),[$,Y]=e.useState(""),[ae,L]=e.useState("visual"),[Ce,Se]=e.useState([]),[oe,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
- }`),[Te,Ee]=e.useState(""),[Me,xe]=e.useState([]),[ce,le]=e.useState([]),[ke,ye]=e.useState(!1),[J,Oe]=e.useState(null),Ze=e.useRef(0);e.useEffect(()=>{var Q;const ne=++Ze.current;if(!i||!U){me(""),be(!1),$e(!1),b(""),Y(""),L("visual"),Se([]),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(""),xe([]),le([]),Oe(null);return}me(i.name),be(!!i.root),$e(!!i.debugMode),b(String(((Q=i.additionalInfo)==null?void 0:Q.category)??"")),Y(i.description),U.getContent(i.id).then(_e=>{var d;if(ne!==Ze.current)return;Oe(_e);const Ne=(_e==null?void 0:_e.ruleChain)??_e,Le=(Ne==null?void 0:Ne.additionalInfo)??{};be(!!((Ne==null?void 0:Ne.root)??i.root)),$e(!!((Ne==null?void 0:Ne.debugMode)??(Le==null?void 0:Le.debugMode)??i.debugMode)),b(String((Le==null?void 0:Le.category)??((d=i.additionalInfo)==null?void 0:d.category)??"")),Y(String((Le==null?void 0:Le.description)??i.description??""));try{const ve=Le==null?void 0:Le.inputSchema,Fe=Ra(ve);Se(C.parseToolSchemaRows(Fe)),he(JSON.stringify(Fe,null,2)),Ee("")}catch{Se([]),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 Je=Jn(Ne==null?void 0:Ne.configuration),St=Je.vars??(Le==null?void 0:Le.vars)??(Ne==null?void 0:Ne.vars)??{};xe(Object.entries(St).map(([ve,Fe])=>({key:ve,value:String(Fe)})));const Ie=Je.secrets??(Le==null?void 0:Le.secrets)??(Ne==null?void 0:Ne.secrets)??{};le(Object.entries(Ie).map(([ve,Fe])=>({key:ve,value:String(Fe)})))}).catch(_e=>{ne===Ze.current&&(A==null||A(_e instanceof Error?_e:new Error(String(_e))))})},[i,U,A,u]);const z=e.useCallback(async()=>{if(!(!U||!i)){ye(!0);try{const ne=await U.saveBaseInfo(i.id,ra(i,J,{name:se.trim(),root:j,debugMode:De,category:X.trim(),description:$.trim()}));if(!ne.success)throw new Error(ne.msg||u("editor.workflowInfo.saveFailed","保存失败"));F==null||F("base"),W==null||W()}catch(ne){A==null||A(ne instanceof Error?ne:new Error(String(ne)))}finally{ye(!1)}}},[U,i,J,se,j,De,X,$,F,A,W,u]),Ge=e.useCallback(ne=>{if(ae!==ne){if(ne==="code"){he(JSON.stringify(C.generateToolSchemaFromRows(Ce),null,2)),Ee(""),L("code");return}try{const Q=C.parseToolSchemaRows(C.parseJsonObjectText(oe||"{}",{type:"object",properties:{}}));Se(Q),Ee(""),L("visual")}catch(Q){Ee(Q instanceof Error?Q.message:u("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}}},[oe,ae,Ce,u]),dt=e.useCallback(ne=>{Se(ne),he(JSON.stringify(C.generateToolSchemaFromRows(ne),null,2)),Ee("")},[]),ot=e.useCallback((ne,Q,_e)=>{const Ne=C.updateSchemaRowsAtParent(Ce,ne,Le=>{Le[Q]&&(Le[Q]={...Le[Q],..._e,properties:_e.type&&_e.type!=="object"?[]:Le[Q].properties,itemsProperties:_e.type&&_e.type!=="array"?[]:Le[Q].itemsProperties})});dt(Ne)},[Ce,dt]),Ht=e.useCallback((ne="")=>{const Q=C.updateSchemaRowsAtParent(Ce,ne,_e=>{_e.push(C.emptySchemaEditorRow(yl(_e)+1))});dt(Q)},[Ce,dt]),Ft=e.useCallback((ne,Q)=>{const _e=C.updateSchemaRowsAtParent(Ce,ne,Ne=>{Ne.splice(Q,1);const Le=C.renumberSchemaRowOrders(Ne);Ne.splice(0,Ne.length,...Le)});dt(_e)},[Ce,dt]),Bt=e.useCallback((ne,Q,_e)=>{dt(_l(Ce,ne,Q,_e))},[Ce,dt]),Rt=e.useCallback(async()=>{if(!U||!i)return;let ne;try{ne=ae==="visual"?C.generateToolSchemaFromRows(Ce):C.parseJsonObjectText(oe||"{}",{type:"object",properties:{}}),he(JSON.stringify(ne,null,2)),ae==="code"&&Se(C.parseToolSchemaRows(ne)),Ee("")}catch(Q){Ee(Q instanceof Error?Q.message:u("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"));return}ye(!0);try{const Q=await U.saveBaseInfo(i.id,ra(i,J,{name:se.trim()||i.name,root:j,debugMode:De,category:X.trim(),description:$.trim(),inputSchema:ne}));if(!Q.success)throw new Error(Q.msg||u("editor.workflowInfo.saveFailed","保存失败"));F==null||F("inputSchema"),W==null||W()}catch(Q){A==null||A(Q instanceof Error?Q:new Error(String(Q)))}finally{ye(!1)}},[U,i,J,ae,Ce,oe,se,j,De,X,$,F,A,W,u]),Ct=e.useCallback(async ne=>{if(!(!U||!i)){ye(!0);try{const Q=ne==="vars"?Me:ce,_e={};Q.forEach(Le=>{Le.key.trim()&&(_e[Le.key.trim()]=Le.value)});const Ne=await U.saveConfig(i.id,ne,_e);if(!Ne.success)throw new Error(Ne.msg||u("editor.workflowInfo.saveFailed","保存失败"));F==null||F(ne),W==null||W()}catch(Q){A==null||A(Q instanceof Error?Q:new Error(String(Q)))}finally{ye(!1)}}},[U,i,Me,ce,F,A,W,u]),rt=e.useCallback(ne=>{navigator.clipboard.writeText(ne).catch(()=>{const Q=document.createElement("textarea");Q.value=ne,document.body.appendChild(Q),Q.select(),document.execCommand("copy"),document.body.removeChild(Q)})},[]);if(!i)return e.createElement("div",{className:`huanban_rulego_info huanban_rulego_info--empty ${f}`.trim(),style:M},e.createElement("p",{className:"huanban_rulego_info__no_data"},u("editor.workflowInfo.noData","请选择一个工作流查看详情")));const Mt=n||((Be=U==null?void 0:U.getApiBase)==null?void 0:Be.call(U))||"",Ve=El(Mt,i.id),$t=[{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:y.variable},{key:"integration",label:u("editor.workflowInfo.integration","应用集成"),icon:y.api},...g?[{key:"maintenance",label:u("editor.workflowInfo.maintenance","维护验证"),icon:"validate"}]:[]],wt=O?O(i):[],At=[...$t,...wt.map(ne=>({key:ne.key,label:ne.label,icon:void 0}))],yt=At.some(ne=>ne.key===pe)?pe:"base",Ot=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:se,onChange:ne=>me(ne.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:j,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:De,onChange:ne=>$e(ne.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:ne=>b(ne.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:ne=>Y(ne.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:ke,onClick:z},e.createElement(fe,{value:y.save})," ",ke?u("editor.workflowInfo.saving","保存中..."):u("editor.workflowInfo.saveBaseInfo","保存基础信息"))),Dt=(ne,Q="")=>e.createElement("div",{className:"rge-tool-schema-rows"},ne.length===0?e.createElement("div",{className:"rge-tool-schema-empty"},u("editor.property.noSchemaProperties","暂无属性,点击下方按钮添加")):ne.map((_e,Ne)=>{const Le=Q?`${Q}.${Ne}`:String(Ne),Je=_e.type==="array"?`${Le}.items`:Le,St=_e.type==="array"?_e.itemsProperties:_e.properties;return e.createElement("div",{key:Le,className:"rge-tool-schema-row-wrap"},e.createElement("div",{className:"rge-tool-schema-row"},e.createElement("input",{className:"rge-form-input",value:_e.name,placeholder:u("editor.property.propertyName","属性名"),onChange:Ie=>ot(Q,Ne,{name:Ie.target.value})}),e.createElement("input",{className:"rge-form-input",value:_e.title,placeholder:u("editor.property.title","标题"),onChange:Ie=>ot(Q,Ne,{title:Ie.target.value})}),e.createElement("input",{className:"rge-form-input",value:_e.description,placeholder:u("editor.property.description","描述"),onChange:Ie=>ot(Q,Ne,{description:Ie.target.value})}),e.createElement("select",{className:"rge-form-select",value:_e.type,onChange:Ie=>ot(Q,Ne,{type:Ie.target.value})},C.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:_e.order,onChange:Ie=>ot(Q,Ne,{order:Number(Ie.target.value||Ne+1)})}),e.createElement("label",{className:"rge-inline-checkbox rge-tool-schema-required"},e.createElement("input",{type:"checkbox",checked:_e.required,onChange:Ie=>ot(Q,Ne,{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:()=>Bt(Q,Ne,-1)},"↑"),e.createElement("button",{type:"button",title:u("editor.property.moveDown","下移"),onClick:()=>Bt(Q,Ne,1)},"↓"),e.createElement("button",{type:"button",className:"danger",title:u("editor.workflowInfo.delete","删除"),onClick:()=>Ft(Q,Ne)},"×"))),_e.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:_e.itemsType||"string",onChange:Ie=>ot(Q,Ne,{itemsType:Ie.target.value})},C.TOOL_SCHEMA_ITEM_TYPES.map(Ie=>e.createElement("option",{key:Ie,value:Ie},Ie)))),(_e.type==="object"||_e.type==="array")&&e.createElement("div",{className:"rge-tool-schema-nested"},e.createElement("div",{className:"rge-tool-schema-nested-title"},_e.type==="array"?u("editor.property.arrayItems","数组项目"):u("editor.property.childProperties","子属性"),_e.name?`: ${_e.name}`:""),_e.type==="array"&&(_e.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,Dt(St||[],Je),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Ht(Je)},_e.type==="array"?u("editor.property.addItemProperty","添加项目属性"):u("editor.property.addChildProperty","添加子属性")))))})),Wt=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${ae==="visual"?" active":""}`,onClick:()=>Ge("visual")},u("editor.workflowInfo.visualMode","可视化")),e.createElement("button",{type:"button",className:`rge-segmented-option${ae==="code"?" active":""}`,onClick:()=>Ge("code")},u("editor.workflowInfo.codeMode","JSON代码"))),ae==="visual"?e.createElement("div",{className:"rge-tool-schema-editor"},Dt(Ce),e.createElement("button",{type:"button",className:"rge-btn-add",onClick:()=>Ht("")},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:oe,onChange:ne=>{he(ne.target.value),Ee("")}})),Te&&e.createElement("div",{className:"huanban_rulego_info__maintenance_status huanban_rulego_info__maintenance_status--error"},Te),e.createElement("div",{className:"huanban_rulego_info__inline_actions"},e.createElement("button",{className:"huanban_rulego_info__copy_btn",type:"button",onClick:()=>{try{const ne=ae==="visual"?C.generateToolSchemaFromRows(Ce):C.parseJsonObjectText(oe||"{}",{type:"object",properties:{}});he(JSON.stringify(ne,null,2)),Se(C.parseToolSchemaRows(ne)),Ee("")}catch(ne){Ee(ne instanceof Error?ne.message:u("editor.workflowInfo.inputSchemaInvalid","输入定义 JSON 格式错误"))}}},u("editor.workflowInfo.formatJson","格式化 JSON")),e.createElement("button",{className:"huanban_rulego_info__save_btn",disabled:ke,onClick:Rt},e.createElement(fe,{value:y.save})," ",ke?u("editor.workflowInfo.saving","保存中..."):u("editor.workflowInfo.saveInputDefinition","保存输入定义")))),_t=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},e.createElement(fe,{value:y.variable})," ",u("editor.workflowInfo.vars","变量")),e.createElement(aa,{entries:Me,onChange:xe,icons:y,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:ke,onClick:()=>Ct("vars")},e.createElement(fe,{value:y.save})," ",u("editor.workflowInfo.saveVars","保存变量")),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(fe,{value:y.secret})," ",u("editor.workflowInfo.secrets","秘钥")),e.createElement(aa,{entries:ce,onChange:le,icons:y,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:ke,onClick:()=>Ct("secrets")},e.createElement(fe,{value:y.save})," ",u("editor.workflowInfo.saveSecrets","保存秘钥"))),Re=e.createElement("div",{className:"huanban_rulego_info__panel"},e.createElement("h4",{className:"huanban_rulego_info__subtitle"},e.createElement(fe,{value:y.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 ",Ve.executeUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.executeUrl)},e.createElement(fe,{value:y.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 ",Ve.notifyUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.notifyUrl)},e.createElement(fe,{value:y.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 ",Ve.openaiUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.openaiUrl)},e.createElement(fe,{value:y.copy}))),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(fe,{value:y.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"},Ve.debugWsUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.debugWsUrl)},e.createElement(fe,{value:y.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"},Ve.runtimeWsUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.runtimeWsUrl)},e.createElement(fe,{value:y.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"},Ve.endpointWsHint),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.endpointWsHint)},e.createElement(fe,{value:y.copy}))),e.createElement("h4",{className:"huanban_rulego_info__subtitle",style:{marginTop:20}},e.createElement(fe,{value:y.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"},Ve.mcpSseUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.mcpSseUrl)},e.createElement(fe,{value:y.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 ",Ve.mcpStreamableUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.mcpStreamableUrl)},e.createElement(fe,{value:y.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 ",Ve.mcpGroupUrl),e.createElement("button",{className:"huanban_rulego_info__copy_btn",onClick:()=>rt(Ve.mcpGroupUrl)},e.createElement(fe,{value:y.copy})))),Ut=()=>{switch(yt){case"base":return w?w(i,Ot):Ot;case"inputSchema":return Wt;case"vars":return E?E(i,_t):_t;case"integration":return k?k(i,Mt,Re):Re;case"maintenance":return e.createElement(xa,{workflow:i,fetcher:U,content:J,onError:A,locale:_,messages:I,t:P});default:{const ne=wt.find(Q=>Q.key===yt);return ne?ne.children:null}}},pt=m!=="light"?`huanban_rulego_info--${m}`:"";return e.createElement("div",{className:`huanban_rulego_info ${pt} ${f}`.trim(),style:M},e.createElement("div",{className:"huanban_rulego_info__tabs"},At.map(ne=>e.createElement("button",{key:ne.key,className:`huanban_rulego_info__tab ${yt===ne.key?"huanban_rulego_info__tab--active":""}`,onClick:()=>V(ne.key)},ne.icon!==void 0&&e.createElement(fe,{value:ne.icon}),ne.label))),e.createElement("div",{className:"huanban_rulego_info__content"},Ut()))};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 Pn(){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=C.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:Pn(),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)?C.filterCopilotSuccessfulTurns(t.filter(n=>n&&typeof n=="object"&&n.role&&typeof n.content=="string").map(n=>({...n,id:String(n.id||Pn()),status:n.status==="error"?"error":"complete",timestamp:Pa(n.timestamp),toolCalls:xl(n.toolCalls)}))):[]}const Rl=t=>{var L,Ce,Se;const{locale:n,messages:r,t:o,initialMessages:s=[],onMessagesChange:i,onError:m,placeholder:f,className:M,style:N,disabled:D=!1}=t,g=e.useMemo(()=>Xe({locale:n,messages:r,t:o}),[n,r,o]),w=Sl(t),E=(L=t.persistence)==null?void 0:L.adapter,k=(Ce=t.persistence)==null?void 0:Ce.namespace,O=((Se=t.persistence)==null?void 0:Se.mode)||"component",F=e.useMemo(()=>!E||!k?null:{adapter:E,namespace:k,chainId:`${t.ruleChainId}::${w}`,mode:O},[w,E,O,k,t.ruleChainId]),A=e.useMemo(()=>C.buildEditorChatHistoryKey(F||void 0),[F]),W=A||`memory:${t.ruleChainId}:${w}:${O}`,[_,I]=e.useState(()=>sa(s)),[P,y]=e.useState(W),[u,te]=e.useState(""),[re,B]=e.useState(!1),[U,pe]=e.useState(""),V=e.useRef(null),se=e.useRef(null),me=e.useRef(!1),j=e.useRef(0);e.useEffect(()=>{var he;j.current+=1,(he=V.current)==null||he.abort(),V.current=null,B(!1),pe(""),me.current=!0;const oe=F?Tl(C.readEditorChatHistory(F)):sa(s);I(oe),y(W)},[W,F]),e.useEffect(()=>{if(i==null||i(_),me.current){me.current=!1;return}if(!F||!A||P!==W)return;const oe=C.filterCopilotSuccessfulTurns(_);C.writeEditorChatHistory(F,oe)},[_,P,W,i,A,F]),e.useEffect(()=>()=>{var oe;return(oe=V.current)==null?void 0:oe.abort()},[]),e.useEffect(()=>{const oe=se.current;if(!oe)return;const he=Ee=>{const Me=Ee.detail;pe(String(Me||g("editor.copilot.copyFailed","复制失败")))};oe.addEventListener("copilot-code-copy-error",he);const Te=C.bindCopilotCodeInteractions(oe,{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()=>{oe.removeEventListener("copilot-code-copy-error",he),Te()}},[g]);const be=e.useCallback(async(oe,he,Te,Ee)=>{B(!0);const Me=new AbortController;V.current=Me;const xe=j.current,ce=()=>j.current===xe&&V.current===Me;try{if(await C.streamOpenAiChatCompletion({endpoint:Ia(t),model:t.model,stream:t.stream,headers:Cl(t.fetchHeaders),customFetch:t.customFetch,messages:oe.map(({role:le,content:ke})=>({role:le,content:ke})),signal:Me.signal,onDelta:le=>{ce()&&I(ke=>ke.map(ye=>ye.id===he.id?{...ye,content:ye.content+le}:ye))},onReasoningDelta:le=>{ce()&&I(ke=>ke.map(ye=>ye.id===he.id?{...ye,reasoning:(ye.reasoning||"")+le}:ye))},onToolCallDelta:le=>{ce()&&I(ke=>ke.map(ye=>ye.id===he.id?{...ye,toolCalls:C.mergeCopilotToolCallDelta(ye.toolCalls,le)}:ye))}}),!ce())return;I(le=>le.map(ke=>ke.id===he.id?{...ke,status:"complete",toolCalls:C.settleCopilotToolCalls(ke.toolCalls)}:ke))}catch(le){if(!ce())return;if((le==null?void 0:le.name)==="AbortError")Ee?(I(Ee),pe(g("editor.copilot.cancelled","请求已取消"))):I(ke=>ke.map(ye=>ye.id===Te?{...ye,status:"error"}:ye.id===he.id?{...ye,status:"error",content:g("editor.copilot.cancelled","请求已取消")}:ye));else{const ke=le instanceof Error?le:new Error(String(le));pe(ke.message),I(Ee||(ye=>ye.filter(J=>J.id!==he.id).map(J=>J.id===Te?{...J,status:"error"}:J))),m==null||m(ke)}}finally{if(!ce())return;V.current=null,B(!1)}},[m,t,g]),De=e.useCallback(async()=>{const oe=u.trim();if(!oe||re||D)return;const he=Date.now(),Te={id:Pn(),role:"user",content:oe,status:"complete",timestamp:he},Ee={id:Pn(),role:"assistant",content:"",reasoning:"",status:"sending",timestamp:he},Me=[...C.filterCopilotSuccessfulTurns(_),Te];I([...Me,Ee]),te(""),pe(""),await be(Me,Ee,Te.id)},[re,_,D,u,be]),$e=e.useCallback(async oe=>{var he;try{if(!((he=navigator.clipboard)!=null&&he.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(oe)}catch{pe(g("editor.copilot.copyFailed","复制失败"))}},[g]),X=e.useCallback(async oe=>{var ce,le;if(re||D)return;const he=_,Te=C.filterCopilotSuccessfulTurns(he),Ee=Te.findIndex(ke=>ke.id===oe);if(Ee<=0||((ce=Te[Ee])==null?void 0:ce.role)!=="assistant"||((le=Te[Ee-1])==null?void 0:le.role)!=="user")return;const Me=Te.slice(0,Ee),xe={id:Pn(),role:"assistant",content:"",reasoning:"",status:"sending",timestamp:Date.now()};I([...Me,xe]),pe(""),await be(Me,xe,void 0,he)},[re,_,D,be]),b=()=>{var oe;return(oe=V.current)==null?void 0:oe.abort()},$=()=>{re||(F&&C.clearEditorChatHistory(F),I([]),pe(""))},Y=oe=>oe==="user"?g("editor.copilot.userRole","用户"):g("editor.copilot.assistantRole","助手"),ae=e.useMemo(()=>Nl(_),[_]);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:re||_.length===0,title:g("editor.copilot.clear","清空对话")},g("editor.copilot.clear","清空"))),e.createElement("div",{ref:se,className:"rge-copilot__messages","aria-live":"polite"},_.length===0&&e.createElement("div",{className:"rge-copilot__empty"},g("editor.copilot.empty","请输入问题开始对话")),_.map(oe=>{var he;return e.createElement("article",{key:oe.id,className:`rge-copilot__message ${oe.role}${oe.status==="error"?" is-error":""}`},e.createElement("div",{className:"rge-copilot__role"},Y(oe.role),oe.status==="sending"?` · ${g("editor.copilot.sending","处理中")}`:"",oe.role==="user"&&oe.status==="error"?` · ${g("editor.copilot.failed","未完成")}`:""),oe.reasoning&&e.createElement("details",null,e.createElement("summary",null,g("editor.copilot.reasoning","思考过程")),e.createElement("div",{className:"rge-copilot__reasoning",dangerouslySetInnerHTML:{__html:C.renderCopilotMarkdown(oe.reasoning,{codeCopyLabel:g("editor.copilot.copy","复制"),codeLabel:g("editor.copilot.code","代码"),codePreviewLabel:g("editor.copilot.preview","预览"),codeFullscreenLabel:g("editor.copilot.fullscreen","全屏"),streaming:oe.status==="sending"})}})),(he=oe.toolCalls)!=null&&he.length?e.createElement("details",{className:"rge-copilot__tools",open:oe.status==="sending","data-copilot-tool-calls":"true"},e.createElement("summary",null,g("editor.copilot.toolCalls","工具调用")," (",oe.toolCalls.length,")"),e.createElement("div",{className:"rge-copilot__tool-list"},oe.toolCalls.map(Te=>e.createElement("div",{key:Te.id,className:"rge-copilot__tool","data-copilot-tool-call":Te.id},e.createElement("div",{className:"rge-copilot__tool-header"},e.createElement("strong",null,Te.name),e.createElement("span",null,Te.status==="loading"?g("editor.copilot.toolRunning","处理中"):Te.status==="success"?g("editor.copilot.toolCompleted","已完成"):Te.status==="error"?g("editor.copilot.toolFailed","失败"):g("editor.copilot.toolReceived","已收到"))),Te.arguments&&e.createElement("pre",null,Te.arguments),Te.result&&e.createElement("pre",{className:"rge-copilot__tool-result"},Te.result))))):null,oe.content?e.createElement("div",{className:"rge-copilot__content",dangerouslySetInnerHTML:{__html:C.renderCopilotMarkdown(oe.content,{codeCopyLabel:g("editor.copilot.copy","复制"),codeLabel:g("editor.copilot.code","代码"),codePreviewLabel:g("editor.copilot.preview","预览"),codeFullscreenLabel:g("editor.copilot.fullscreen","全屏"),streaming:oe.status==="sending"})}}):oe.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(oe.timestamp)),e.createElement("div",{className:"rge-copilot__message-actions"},e.createElement("button",{type:"button","data-copilot-message-action":"copy",disabled:!oe.content,onClick:()=>void $e(oe.content),title:g("editor.copilot.copy","复制"),"aria-label":g("editor.copilot.copy","复制")},e.createElement("span",{"aria-hidden":"true"},"⧉")),oe.id===ae&&e.createElement("button",{type:"button","data-copilot-message-action":"regenerate",disabled:re,onClick:()=>void X(oe.id),title:g("editor.copilot.regenerate","重新生成"),"aria-label":g("editor.copilot.regenerate","重新生成")},e.createElement("span",{"aria-hidden":"true"},"↻")))))})),U&&e.createElement("div",{className:"rge-copilot__error",role:"alert","aria-live":"assertive"},e.createElement("span",null,U),e.createElement("button",{type:"button",onClick:()=>pe(""),title:g("editor.copilot.dismissError","关闭错误提示"),"aria-label":g("editor.copilot.dismissError","关闭错误提示")},"×")),e.createElement("div",{className:"rge-copilot__input"},e.createElement("textarea",{value:u,disabled:D||re,onChange:oe=>te(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&!oe.shiftKey&&(oe.preventDefault(),De())},placeholder:f||g("editor.copilot.placeholder","输入消息"),rows:2}),re?e.createElement("button",{type:"button",onClick:b,title:g("editor.copilot.stop","停止请求")},g("editor.copilot.stop","停止")):e.createElement("button",{type:"button",onClick:()=>void De(),disabled:D||!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 D=n||((g=t==null?void 0:t.current)==null?void 0:g.editor);D==null||D.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(()=>Xe({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(Kt,{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(()=>Xe({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 C.EditorCore(i.current);o.current=g;const w=g.store.subscribe(E=>{r({isReady:E.isReady,isDirty:E.isDirty,isLoading:E.isLoading,selectedNode:E.selectedNode,selectedEdge:E.selectedEdge,componentGroups:E.componentGroups,currentNodeView:E.currentNodeView,currentNodeModel:E.currentNodeModel,currentEdgeModel:E.currentEdgeModel,canUndo:E.canUndo,canRedo:E.canRedo})});return()=>{for(const E of s.current)E();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 E=o.current.eventBus.on(g,w);s.current.push(E)}},[]),N=e.useCallback((g,...w)=>{o.current&&o.current.eventBus.emit(g,...w)},[]),D=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:D}}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,D=N.key.toLowerCase();for(const g of s.current){if(D!==g.key.toLowerCase())continue;const w=g.ctrl?i?N.metaKey:N.ctrlKey:!(i?N.metaKey:N.ctrlKey),E=g.shift?N.shiftKey:!N.shiftKey,k=g.alt?N.altKey:!N.altKey;if(!(!w||!E||!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 Dn(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 D=s.current;let g=!1;const w=f.current.get(m);w&&(clearTimeout(w),f.current.delete(m));const E=m.subscribe(k=>{g||N({store:m,state:k})});return N({store:m,state:r(m)}),()=>{if(g=!0,E(),D){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}=Dn(t.workspace,()=>new C.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,O)=>n.renameTab(k,O),[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,O)=>n.setDraft(k,O),[n]),D=e.useCallback((k,O)=>n.markSaved(k,O),[n]),g=e.useCallback((k,O)=>n.setLoading(k,O),[n]),w=e.useCallback((k,O)=>n.closeTab(k,O),[n]),E=e.useCallback((k,O,F)=>n.resolveSaveConflict(k,O,F),[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:D,setLoading:g,closeTab:w,resolveSaveConflict:E}}function Ul(t={}){const{dockStore:n,...r}=t,{store:o,state:s}=Dn(n,()=>new C.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}=Dn(n,()=>new C.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}=Dn(n,()=>new C.ConnectionStatusStore,s=>s.getState());return{connectionStatus:r,state:o}}function Jl(t={}){const n=t.panels,r=n instanceof C.EditorPanelRegistry?n:null,o={...t,panels:Array.isArray(n)?n:void 0,syncDockVisibility:!1},{store:s,state:i}=Dn(r,()=>new C.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 ur(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,E;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 D=N.map(ur);r(D),o.current=0,(E=t.onNotify)==null||E.call(t,"success",`已复制 ${D.length} 个节点`)},[t]),i=e.useCallback(()=>{var E,k,O,F;const N=((E=t.getSelectedNodes)==null?void 0:E.call(t))||[];if(N.length===0){(k=t.onNotify)==null||k.call(t,"info","没有选中的节点");return}const D=N.map(A=>A.originalId);if(!(t.confirmDeleteNodes?t.confirmDeleteNodes(D):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(`确认剪切并删除 ${D.length} 个节点吗?此操作不可撤销。`):!1))return;const w=N.map(ur);r(w),o.current=0,(O=t.onDeleteNodes)==null||O.call(t,D),(F=t.onNotify)==null||F.call(t,"success",`已剪切 ${w.length} 个节点`)},[t]),m=e.useCallback(()=>{var w,E,k,O;if(n.length===0){(w=t.onNotify)==null||w.call(t,"info","剪贴板为空");return}o.current+=1;const N=Kl*o.current,D=new Set(((E=t.getExistingNodeIds)==null?void 0:E.call(t))||[]);n.forEach(F=>D.add(String(F.originalId)));const g=n.map(F=>{const A=ur(F),W=Gl(zl(),D,`node_${F.originalId||"copy"}`),_=F.x+N,I=F.y+N;return{...A,originalId:W,x:_,y:I,properties:C.cloneNodePropertiesForCopy(A.properties||{},{nodeId:W,nodeType:A.type,nodeName:A.name,layoutX:_,layoutY:I})}});(k=t.onAddNodes)==null||k.call(t,g),(O=t.onNotify)==null||O.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:()=>C.ConnectionStatusController});Object.defineProperty(exports,"ConnectionStatusStore",{enumerable:!0,get:()=>C.ConnectionStatusStore});Object.defineProperty(exports,"DEFAULT_ROUTES",{enumerable:!0,get:()=>C.DEFAULT_ROUTES});Object.defineProperty(exports,"RuleChainAPI",{enumerable:!0,get:()=>C.RuleChainAPI});Object.defineProperty(exports,"normalizeConnectionStatusMap",{enumerable:!0,get:()=>C.normalizeConnectionStatusMap});Object.defineProperty(exports,"resolveConnectionStatusView",{enumerable:!0,get:()=>C.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=fe;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=Kt;exports.ValidationPanel=ka;exports.WorkflowExplorer=dl;exports.WorkflowInfoPanel=vl;exports.WorkflowList=ul;exports.WorkspaceTabs=qo;exports.createFrameworkTranslator=Xe;exports.getCanvasContextMenuItems=Wo;exports.getDefaultEditorShortcuts=Hl;exports.getEdgeContextMenuItems=Ho;exports.getNodeContextMenuItems=jo;exports.getShortcutLabel=jl;exports.normalizeFrameworkLocale=_r;exports.relationTypeLabel=dr;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;