Files
qhmes/web-dist/js/WorkflowView-f6TDQNjS-BI8W0EwH.js
2026-06-16 18:19:57 +08:00

27 lines
66 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{B as Ao,L as fe,a as ko,s as bo,T as Rt,P as Re,k as L,c as M,b as D,u as To,_ as $o,d as Co,i as Le,A as Oo}from"./NodeStyle-Bo2gmgjj-CM4kHPNz.js";import"./index-D9GWo192.js";import{s as Mo,bo as _t,a4 as Lo,j7 as kt,aQ as Do,w as Ro}from"./index-X7Y8jykP.js";import _o from"./AddNodeDrawer-Bq5MtQ5T-Dx6Rkn2-.js";import Go from"./DebugRunDrawer-CqRtIE_v-5OE-iftJ.js";import Bo from"./NodeSettingDrawer-dOi12yvt-GYUTtPjD.js";import{L as Wo,E as A,G as ie}from"./LoopSetting-DFRTL4YJ-B9dqSzwu.js";import{U as m,D as lt}from"./NodeContainer-D9PNfjwh-CawrgSrv.js";import{b as ut,g as Ae,a as Ho,S as Gt}from"./SwitchSetting-Ci0cQTuz-COKTphJu.js";import{b as ct,g as ke,a as Fo,C as Bt}from"./ClassifierSetting-CxiJ9gbO-DtCF_hfx.js";import{n as ue,o as ee,h as Wt,r as ht}from"./index-Crt100Db-CDbHzweT.js";import{l as qo}from"./runStore-Oe6fP2qb-CrdxkpS7.js";import{l as jo,P as Ht}from"./propStore-Cl0CojEU-BjnqDV4W.js";import Yo from"./ControlRender-Vix8_5tS-FVArTilo.js";import{p as _e,E as Xo,d as R,n as Vo,c as Uo,F as Ko,H as Ft,B as zo}from"./LoopBodyNode-wLHHxX8A-D3_JcFF8.js";import{C as re}from"./useSettings-CFG4Ykt4-CKCQ4yAA.js";import Jo from"./StartIcon-Dubb8UTR-0jdh0Lpu.js";import Qo from"./StartSetting-gRqJlalx-CdfyR7-J.js";import Zo from"./StartNode-CMHcuenf-DPrjjpV4.js";import{L as qt,G as en}from"./cron-BgP3IAPd-riMowXKQ.js";import tn from"./EndIcon-D5MjTL-5-Dw57QBMA.js";import on from"./EndSetting-C2bFJMMj-BY_o6Rkt.js";import nn from"./EndNode-CGbO5P9l-CoP7oy0r.js";import rn from"./LLMIcon-CsVBLVQT-D3VxISiq.js";import sn from"./LLMSetting-DGQyHzhq-7j2F0FBd.js";import an from"./LLMNode-CNuOY9fJ-Ce3M0YDW.js";import dn from"./ClassifierIcon-DiVVowKy-Cuq-EoEF.js";import pn from"./ClassifierNode-DDKcVL7a-DMSaAZdG.js";import ln from"./SwitchIcon-B1WwvmQy-Bt-wixKc.js";import un from"./SwitchNode-Cz7OTBF--BZq29tjg.js";import cn from"./KnowledgeIcon-CdOxc1Q--p4ql_M6-.js";import hn from"./KnowledgeSetting-DlRj2U5K-BBBfO8Yc.js";import mn from"./KnowledgeNode-W9n4j42C-DnOBJ5yU.js";import fn from"./KnowledgeWriteIcon-CY27u26C-BdZQUyS3.js";import gn from"./KnowledgeWriteSetting-ByvSTi6A-D4ZaMdwz.js";import yn from"./KnowledgeWriteNode-Bwfv35IQ-BzTJHKYI.js";import Nn from"./CodeIcon-B0ATCs-I-B938ilX8.js";import vn from"./CodeSetting-NKr5I0D_-ZZwu9U4Y.js";import xn from"./CodeNode-C_Qjcyx9-C0qLEk7y.js";import In from"./SubflowIcon-OszYMa9Q-DlMCtI2x.js";import En from"./SubflowSetting-B0aBbxVo-Cfd4BZae.js";import Sn from"./SubflowNode-BcLpETRW-CZBpRtv5.js";import Pn from"./EnhanceJavaIcon-BPSLyKTR-EM7JWADu.js";import wn from"./EnhanceJavaSetting-DbcAg6Rg-BbaIUVHS.js";import An from"./EnhanceJavaNode-BJJ2Pimb-Vw7mGpMd.js";import kn from"./HTTPIcon-B1ShouOi-CrU8TvDv.js";import bn from"./HTTPSetting-B6l6BI2e-MIqyLC4i.js";import Tn from"./HTTPNode-B_UL-pCL-Cc8WXshH.js";import $n from"./VarMergeIcon-BlKCD9o--8xNeQ_Lz.js";import{V as Cn,b as On,c as Mn}from"./VarMergeSetting-yNUDKo9n-BHmMVOoR.js";import Ln from"./VarMergeNode-Uwf7dW3o-Wt1aYX6a.js";import Dn from"./VarExtractIcon-DCuj6qM2-8H3CtU0Q.js";import Rn from"./VarExtractSetting-BOAqQc3_-Yzy3AJLE.js";import _n from"./VarExtractNode-BELyPf2Q-CLcCZujR.js";import{t as se,l as jt}from"./VarDefineModal-CEI5IHr7-0fS42-kw.js";import Gn from"./ToolsIcon-DjCXPpfC-C6GIK5Nz.js";import Bn from"./ToolsSetting-3eda9Btb-DqJsvyg3.js";import Wn from"./ToolsNode-FKwzAffR-J01ucmU8.js";import Hn from"./BraveSearchIcon-CPY-t0PC-gGLUjxQU.js";import Fn from"./BraveSearchSetting-B4xAAQuR-D0lzdqXS.js";import qn from"./BraveSearchNode-C0b8eUU--CLgfbVFq.js";import jn from"./ReplyIcon-Sh3DRjXl-Cg0I_7Cp.js";import Yn from"./ReplySetting-CiInLDZO-DdF4JtRJ.js";import Xn from"./ReplyNode-BDrBoChI-9p4cZdRi.js";import Vn from"./SqlIcon-Cxx5wVdB-BH_yRa2q.js";import Un from"./SqlSetting-CLtDuYeW-BcKPOXht.js";import Kn from"./SqlNode-CT5Ct1zf-DmSZRkFd.js";import zn from"./LoopIcon-BnGR9e2Y-QnRawAik.js";import Jn from"./LoopNode-DOQOa7vA-tGYrNpV6.js";import Qn from"./LoopBreakIcon-BMZmxYcb-DF8XURNQ.js";import Zn from"./LoopBreakNode-d_rBXNID-DTwRcyB4.js";import er from"./LoopContinueIcon-BEeXpCcy-Bn4M4v2i.js";import tr from"./LoopContinueNode-C77a9z9x-DCHZFnYm.js";import or from"./SetLoopVarIcon-DPIst0zq-BVR-Vv1E.js";import nr from"./SetLoopVarNode-BRQKv9Dw-DZcozIgP.js";import rr from"./SetLoopVarSetting-D4un6roe-BBaQDNcq.js";import ir from"./ChatVarGetIcon-DzeMWAZN-CrS_Tz54.js";import sr from"./ChatVarGetSetting-Bm0osnHv-L2RaHctr.js";import ar from"./ChatVarGetNode-KKff1USH-BB_aCc3p.js";import dr from"./ChatVarSetIcon-BJlOGbar-pi59vPvi.js";import pr from"./ChatVarSetSetting-CQrHwzlE-BgrH_CGL.js";import lr from"./ChatVarSetNode-m7wKR9ju-cl2PQ1Cn.js";import ur from"./ChatMemoryGetIcon-t164NmFW-B8QedctF.js";import cr from"./ChatMemoryGetSetting-DWqDQWzn-CWAc03WW.js";import hr from"./ChatMemoryGetNode-p9QDS-AQ-JG-3HlW_.js";import mr from"./ChatMemorySetIcon-BqqyT08t-B3vLT5BV.js";import fr from"./ChatMemorySetSetting-Ce8X28T3-DIMco562.js";import gr from"./ChatMemorySetNode-Dm5Rqxdf-Cl65feFL.js";import{a as bt}from"./useDrawer-BDPywy9W.js";import{t as yr}from"./throttle-De_jAmBh.js";import{u as Nr}from"./uniqBy--vsL0WVB.js";import{e as vr,o as xr,r as he,n as Se,b as be,u as q,C as Ir,d as Er,z as Tt,Q as $t,f as Pe,y as Sr,H as Pr,J as wr,M as Ct,N as Ar,B as kr,Y as br,F as Tr,a2 as Ot}from"./vue-vendor-DNhG1Cve.js";var $r=Object.defineProperty,Cr=Object.defineProperties,Or=Object.getOwnPropertyDescriptors,Mt=Object.getOwnPropertySymbols,Mr=Object.prototype.hasOwnProperty,Lr=Object.prototype.propertyIsEnumerable,Lt=(o,e,t)=>e in o?$r(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,ne=(o,e)=>{for(var t in e||(e={}))Mr.call(e,t)&&Lt(o,t,e[t]);if(Mt)for(var t of Mt(e))Lr.call(e,t)&&Lt(o,t,e[t]);return o},ye=(o,e)=>Cr(o,Or(e)),me=(o,e,t)=>new Promise((r,i)=>{var n=d=>{try{p(t.next(d))}catch(u){i(u)}},s=d=>{try{p(t.throw(d))}catch(u){i(u)}},p=d=>d.done?r(d.value):Promise.resolve(d.value).then(n,s);p((t=t.apply(o,e)).next())});class z{constructor(e=""){this.originType="",this.anchorsNextIds=[],e&&(this.id=e),this.child=[],this.maxLineNum=25}addChild(e){this.child||(this.child=[]),this.child.push(e)}get childFirstId(){if(!Array.isArray(this.child)||this.child.length===0)return"";const e=this.child[0];switch(e.type){case A.WHEN:case A.THEN:return e.childFirstId}return e.id}getElString(){var e,t,r,i;const n=this.type===A.GROUP?"":(e=this.properties)!=null&&e.tag?`.tag('${(t=this.properties)==null?void 0:t.tag}')`:"",s=(r=this.properties)!=null&&r.data?`.data('${(i=this.properties)==null?void 0:i.data}')`:"";return`${this.getElStringRaw()}${n}${s}`}getElStringRaw(){if(this.type===A.ID)return this.nodeId;if(this.elString)return this.elString;switch(this.type){case A.IF:return this.getELString_IF();case A.GROUP:return this.getELString_Group();case A.SWITCH:return this.getELString_SWITCH();case A.WHEN:case A.THEN:return this.getElString_WHEN_THEN();case m.CODE:return this.id;default:return this.type}}insertSpace(e){return` ${e.split(`
`).join(`
`)}`}getElString_WHEN_THEN(){const e=this.child||[];let t="",r="";this.aliasId&&(t=this.aliasId.startsWith("tag:")?`.tag("${this.aliasId.substring(4)}")`:`.id("${this.aliasId}")`),this.childFirstId&&(r=`.tag("${this.childFirstId}")`);const i=e.map(p=>p.getElString()),n=i.join(",");if(e.length===1&&(!this.aliasId||e[0].type===A.THEN||e[0].type===A.WHEN))return`${n}${t}`;if(n.length<this.maxLineNum-6)return`${this.type}(${n})${r||t}`;const s=this.insertSpace(i.join(`,
`));return`${this.type}(
${s}
)${r||t}`}getELString_Group(){var e,t,r,i,n;const s=this.child||[],p=s.map(g=>g.getElString()).join(",");if(this.groupType===ie.CONFIG){const g=(e=this.properties)!=null&&e.ignoreError?".ignoreError(true)":"",E=(t=this.properties)!=null&&t.any?"any(true)":"",x=(r=this.properties)!=null&&r.must?`must(${(i=this.properties)==null?void 0:i.must})`:"";return`${p}${g}${E}${x}`}if(this.groupType===ie.LOGIC)return this.elString;const d=this.groupType;if(this.groupType===ie.CATCH){const g=this.exceptionNode.getElString();return`${d}(${p}).DO(${g})`}const u=this.breakNode?`.BREAK(${this.breakNode.getElString()})`:"";let f;return this.originType===m.LOOP?f=`${this.originType}.tag('${this.id}')`:f=(n=this.startNode)!=null&&n.nodeId?this.startNode.getElString():this.startNum,s.length===1?`${d}(${f}).DO(${p})${u}`:`${d}(${f}).DO(WHEN(${p}))${u}`}getELString_IF(){const e=(this.child||[]).map(r=>r.getElString()),t=e.join(",");return t.length<this.maxLineNum-4?`IF(${t})`:`IF(
${this.insertSpace(e.join(`,
`))}
)`}getELString_SWITCH(){this.parseSwitchChildren();const e=(this.child||[]).map(p=>p.getElString()),t=e.join(","),r=this.originType,i=`${r||m.SWITCH}.tag('${this.nodeId}')`,n=`.tag('${this.id}')`;if(t.length<this.maxLineNum-13-this.nodeId.length)return`SWITCH(${i}).to(${t})${n}`;const s=this.insertSpace(e.join(`,
`));return`SWITCH(${i}).to(
${s}
)${n}`}parseSwitchChildren(){if(this.anchorsNextIds.length===0)return;const e=this.child||[];if(!(e.length<=this.anchorsNextIds.length)){for(const{nextIds:t}of this.anchorsNextIds){if(t.length<=1)continue;const r=new z;r.type=A.WHEN;for(let i=0;i<t.length;i++){const n=t[i],s=e.findIndex(p=>{let d=p.id;return!d&&p.child.length>0&&(d=p.child[0].id),d===n||p.childFirstId===n});s!==-1&&(i===0?r.addChild(e.splice(s,1,r)[0]):r.addChild(e.splice(s,1)[0]))}}this.child=e}}}class Dr{constructor(){this.stack=[],this.ebpStack=[]}peek(e){return e[e.length-1]}pop(){return this.stack.pop()}push(e){this.stack.push(e)}clear(){this.stack=[]}resolve(){const e=this.peek(this.ebpStack),t=this.stack[e+1];for(let r=e+2;r<this.stack.length;r++){const i=this.stack[r];t.addChild(i)}return t}quit(){const e=this.resolve(),t=this.stack[this.peek(this.ebpStack)];for(;this.stack.length>this.peek(this.ebpStack);)this.stack.pop();return this.stack.push(e),this.ebpStack.pop(),t}create(){this.ebpStack.push(this.stack.length),this.stack.push(new z)}addEndPoint(e){this.stack[this.peek(this.ebpStack)]=e}getEndPoint(){return this.stack[this.peek(this.ebpStack)]}}class Rr{constructor(e){this.endPoints={},this.sourceNum={},this.nodeMap={},this.inGrooupNode={},this.elStack=new Dr,this.startId="start",this.endId="end",this.CUSTOM_SWITCH_NODE=[m.SWITCH,m.CLASSIFIER,m.VAR_EXTRACT],this.anchorNextIdsMap=e}isEnd(e){return this.endId===e}isStart(e){return this.startId===e}getNodeById(e){return this.nodeMap[e]}initEdge(e,t,r=""){if(this.inGrooupNode[e]||this.inGrooupNode[t])return;this.endPoints[e]||(this.endPoints[e]=[]);const i=this.nodeMap[t];i.comingEdgeText=r,this.endPoints[e].push(i),this.sourceNum[t]||(this.sourceNum[t]=0),this.sourceNum[t]++}init(e){const t=[];e.nodes.forEach(n=>{if(n.id){if(this.typeFormat(n.type)===A.GROUP){t.push(n);return}this.initELNode(n)}}),t.forEach(n=>{this.initLoopELNode(n)});const r=new z;r.id=this.startId,this.nodeMap[this.startId]=r;const i=new z;i.id=this.endId,this.nodeMap[this.endId]=i,e.edges.forEach(n=>{var s,p;const d=n.sourceNodeId,u=n.targetNodeId;!d||!u||(this.nodeMap[d].type===A.IF?this.parseIFEdge((s=n.text)==null?void 0:s.value,d,u):this.initEdge(d,u,(p=n.text)==null?void 0:p.value))}),e.nodes.forEach(n=>{!n.id||this.inGrooupNode[n.id]||(this.endPoints[n.id]||this.initEdge(n.id,this.endId),this.sourceNum[n.id]||this.initEdge(this.startId,n.id))}),e.nodes.length===0&&this.initEdge(this.startId,this.endId)}parseIFEdge(e,t,r){const i=this.nodeMap[r];let n=this.endPoints[t];n||(n=[void 0,void 0]),this.isTrueText(e)?(n[0]&&(n[1]=n[0]),n[0]=i):this.isFalseText(e)?(n[1]&&(n[0]=n[1]),n[1]=i):n[0]?n[1]=i:n[0]=i,this.endPoints[t]=n,this.sourceNum[r]||(this.sourceNum[r]=0),this.sourceNum[r]++}isTrueText(e){return!!["","true","True","TRUE"].find(t=>t===e)}isFalseText(e){return!!["","false","False","FALSE"].find(t=>t===e)}initELNode(e){var t,r,i,n,s,p,d;e.properties=ne({},e.properties),e.properties.nodeId=e.id,e.properties.name=e.properties.text,e.properties.tag=e.id;const u=new z;return u.id=e.id,u.type=this.typeFormat(e.type),u.originType=e.type,this.handleSwitchNode(u,e),u.properties=e.properties,u.nodeId=(t=e.properties)==null?void 0:t.nodeId,u.name=(r=e.properties)==null?void 0:r.name,u.groupType=(i=e.properties)==null?void 0:i.groupType,u.data=(n=e.properties)==null?void 0:n.data,u.aliasId=(s=e.properties)==null?void 0:s.aliasId,u.tag=(p=e.properties)==null?void 0:p.tag,u.startNum=(d=e.properties)==null?void 0:d.startNum,this.nodeMap[u.id]=u,u}handleSwitchNode(e,t){if(e.type!==A.SWITCH)return;const r=e.originType===m.SWITCH?Gt:Bt,i=r.getCaseList(t);for(let n=0;n<i.length;n++){const s=i[n],p=r.getAnchorId(t.id,s.type,n+1),d=this.anchorNextIdsMap.get(p);d&&d.length>0&&e.anchorsNextIds.push({anchorId:p,nextIds:d})}}initLoopELNode(e){var t,r,i;(t=e.flowData)!=null&&t.nodes||(e.flowData={nodes:[],edges:[]});const n=this.initELNode(e);n.groupType==ie.LOGIC?n.elString=this.getLogicStr(e.flowData):n.addChild(new Yt(e.flowData,this.anchorNextIdsMap).parse()),this.nodeMap[n.id]=n,e.flowData.nodes.forEach(s=>{const p=s.id;this.inGrooupNode[p]=!0}),(r=e.sourceNodeIds)==null||r.forEach(s=>{this.initEdge(s,n.id)}),(i=e.targetNodeIds)==null||i.forEach(s=>{this.initEdge(n.id,s)})}typeFormat(e){return this.CUSTOM_SWITCH_NODE.includes(e)?A.SWITCH:e===m.LOOP?A.GROUP:e==="IF"?A.IF:e==="SWITCH"?A.SWITCH:e==="GROUP"?A.GROUP:e==="AND"?A.AND:e==="NOT"?A.NOT:e==="OR"?A.OR:e}setSourceNum(e,t){this.sourceNum[e.id]=t}getSourceNum(e){return this.sourceNum[e.id]||0}getEndNum(e){const t=this.endPoints[e.id];return t?t.length:0}getEndList(e){return this.endPoints[e.id]||[]}push(e){this.elStack.push(e)}pop(){return this.elStack.pop()}createStackEnv(e){this.elStack.create();const t=new z;t.id=e.id,t.type=e.type,t.originType=e.originType,t.groupType=e.groupType,t.aliasId=e.aliasId,t.name=e.name,t.data=e.data,t.tag=e.tag,t.nodeId=e.nodeId,t.child=e.child,t.comingEdgeText=e.comingEdgeText,t.elString=e.elString,t.anchorsNextIds=e.anchorsNextIds,t.startNode=e.startNode,t.breakNode=e.breakNode,t.exceptionNode=e.exceptionNode,t.startNum=e.startNum,this.elStack.push(t)}quitStackEnv(){return this.elStack.quit()}setStackEndPoint(e){this.elStack.addEndPoint(e)}getLogicStr(e){const t={};e.nodes.forEach(s=>t[s.id]=s);const r={};e.edges.forEach(s=>{r[s.sourceNodeId]?r[s.sourceNodeId]++:r[s.sourceNodeId]=1});const i=e.nodes.map(s=>s.id).find(s=>!r[s]),n=s=>{const p=t[s],d=e.edges.filter(u=>u.targetNodeId===s).map(u=>u.sourceNodeId).map(u=>{var f;const g=t[u];if(g.type===A.ID)return(f=g.properties)==null?void 0:f.nodeId;if(g.type===A.AND||g.type===A.OR||g.type===A.NOT)return n(g.id);throw new Error("未知的节点类型")}).join(",");return`${p.type}(${d})`};return n(i)}}class Yt{constructor(e,t){this.logicFlow=e,this.context=new Rr(t),this.context.init(this.logicFlow)}parse(){const e=this.context.startId,t=new z;return t.id=e,this.parseThenChain(t),this.context.pop()}parseThenChain(e,t,r,i=""){return this.context.createStackEnv({type:A.THEN,aliasId:i}),r&&this.context.push(r),this.parseSingleNode(e,{targetNode:t}),this.context.quitStackEnv()}parseSingleNode(e,t){const r=e.id,i=this.context.getEndNum(e),n={targetNode:t.targetNode};if(this.context.isEnd(r))return this.context.setStackEndPoint(e),null;if(t.targetNode&&t.targetNode.id===e.id)return this.context.setStackEndPoint(e),null;if(this.context.isStart(r)||this.context.push(e),A.IF===e.type){const p=this.parseIF(this.context.pop());return this.parseSingleNode(p,n)}if(A.SWITCH===e.type){const p=this.parseWhich(this.context.pop());return this.parseSingleNode(p,n)}if(A.GROUP===e.type){let p=this.parseGroup(this.context.pop());if(e.groupType===ie.LOGIC&&i>0&&!this.context.isEnd(this.context.getEndList(e)[0].id)){const d=this.context.pop();p=this.parseIF(d)}return this.parseSingleNode(p,n)}if(i===1)return this.parseSingleNode(this.context.getEndList(e)[0],n);const s=this.parseWhenChain(e);return this.parseSingleNode(s,n)}parseBranch(e){const t=this.context.getEndList(e);let r=this.getBranchEnd(e);return t.forEach(i=>{i.id!=r.id&&this.parseThenChain(i,r,void 0,e.type===A.SWITCH?i.comingEdgeText:"")}),r}parseIF(e){const t=new z;t.type=A.IF,this.context.createStackEnv(t),e.type===A.IF&&(e.type=A.ID),this.context.push(e);const r=this.context.getEndList(e).filter(s=>!!s),i=r.length;if(i==1){let s,p;try{if(s=r[0],p=this.context.endPoints[s.id][0],!this.context.isEnd(p.id))throw new Error}catch(d){throw new Error("IF 判断节点的分支数必须为2")}return this.context.push(s),p}if(i!=2)throw new Error("IF 判断节点的分支数必须为2");const n=this.parseBranch(e);return this.context.setStackEndPoint(n),this.context.quitStackEnv()}parseWhich(e){if(this.context.getEndList(e).length<=1)throw new Error("WHICH 分支节点的分支数必须大于1");this.context.createStackEnv(e);const t=this.parseBranch(e);return this.context.setStackEndPoint(t),this.context.quitStackEnv()}parseWhenBase(e,t,r){return this.context.createStackEnv({type:A.WHEN}),e.forEach((i,n)=>{i.id!=t.id&&this.parseThenChain(i,t,r[n])}),this.context.quitStackEnv(),this.context.pop()}parseWhenChain(e){this.context.createStackEnv({type:A.WHEN});const t=this.context.getEndList(e),r=this.getBranchEnd(e),i=this.getBranchEnd(e,r),n={},s={};return Object.entries(i).sort(([,p],[,d])=>p.length-d.length).forEach(([p,d])=>{const u=this.context.getNodeById(p);if(d.length==1)return;const f=[];d.forEach(x=>{const N=t[x];n[N.id]?f.push(n[N.id]):f.push(N.id)}),d.forEach(x=>{const N=t[x];n[N.id]=p});const g=Array.from(new Set(f)).map(x=>this.context.getNodeById(x)),E=this.parseWhenBase(g,u,g.map(x=>s[x.id]));s[p]=E}),this.context.push(s[r.id]),this.context.setStackEndPoint(r),this.context.quitStackEnv()}parseGroup(e){const t=this.context.getEndList(e);let r,i=!0;return t.forEach(n=>{if(n.comingEdgeText){this.parseThenChain(n);const s=this.context.elStack.pop();switch(n.comingEdgeText){case"START":e.startNode=s.child[0];break;case"BREAK":e.breakNode=s.child[0];break;case"EXCEPTION":e.exceptionNode=s.child[0];break}}else r=n,i=!1}),this.context.elStack.push(e),i?new z(this.context.endId):r}getBranchEnd(e,t){const r={};let i=this.context.getEndNum(e);const n=this.context.getEndList(e).map(p=>p.id),s={};for(;;)for(let p=0;p<n.length;p++){const d=n[p];if(!d)continue;const u=this.context.getNodeById(d);if(s[u.id]||(s[u.id]=0),s[u.id]++,r[u.id]||(r[u.id]=[]),r[u.id].push(p),s[u.id]===i)return e.type===A.SWITCH&&this.context.getEndList(e).some(f=>f.id===u.id)?this.getBranchEnd(u):t?r:u;this.context.isEnd(u.id)||u.id===(t==null?void 0:t.id)?n[p]="":this.context.getEndNum(u)>1?n[p]=this.getBranchEnd(u).id:n[p]=this.context.getEndList(u)[0].id}}}function _r(o,e){return o=Do(o),new Yt(o,e).parse().getElString()}function Gr(o,e){const t=()=>q(o);function r(){const s=t();if(!s)return;s.focusOn("start-node");const p=-(s.graphModel.width/2-M/2)+20;s.translate(p,0)}function i(){e.transformModel.zoom(!0),e.transformModel.zoom(!1)}function n(s){const p=[],d=u=>{const f=e.edges.filter(E=>!(E.targetNodeId!==u.id||E.targetAnchorId.endsWith(fe.LOOP_END)));if(f.length===0)return;const g=f.flatMap(E=>{const x=e.nodes.find(N=>N.id===E.sourceNodeId);return x?[x]:[]});g.length!==0&&(p.push(...g),g.forEach(E=>d(E)))};return d(s),Nr(p,"id")}return{focusOnStartNode:r,repaintGraph:i,getAllPrevNodes:n}}const Xt=class{constructor({lf:e,options:t}){this.lf=e;const{prefixCls:r}=_t("aiflow-plugin-control");this.prefixCls=r;const{use:{componentProps:i}}=t;i.visible=!0}render(e,t){this.destroy();const r=this.getControlTool();this.toolEl=r,t.appendChild(r),this.domContainer=t}destroy(){this.domContainer&&this.toolEl&&this.domContainer.contains(this.toolEl)&&this.domContainer.removeChild(this.toolEl)}getControlTool(){const e=document.createElement("div");return e.className=this.prefixCls,e}register(e){e.mount(this.lf,this.toolEl,this)}};Xt.pluginName="super-control";let Ge=Xt;function Br(o){const e=be({visible:!1}),t=be({onRegister:r,onResetGraph:i});function r(n){if(!o.value)return;const s=o.value.extension[Ge.pluginName];s&&s.register(n)}function i(){if(!o.value)return;const n=o.value;n.resetZoom(),n.graphModel.$J.focusOnStartNode()}return{SuperControl:{pluginName:Ge.pluginName,componentProps:e,componentIs:Yo,superControlProps:t}}}const ge=40,Wr={top:100,right:120,bottom:ge,left:120},we=.5,Hr=Ht();function Vt(o,e){const t=()=>q(o);function r(g){n({groupId:g,deltaX:0,deltaY:0})}function i(g){if(!g)return;const E=Hr.nodeGroupMap.get(g);E&&r(E)}function n(g){const E=t();if(!E)return;const{groupId:x,nodeId:N}=g,I=E.getNodeModelById(x);if(!I||!I.isRestrict||!I.autoResize)return;const G=N?E.getNodeModelById(N):void 0,B=s(g.deltaX,g.deltaY,G,g.nodeData),_=p(I,N,B);if(!_)return;const W=d(I),te={minX:_.minX-W.left,minY:_.minY-W.top,maxX:_.maxX+W.right,maxY:_.maxY+W.bottom};f(I,te)}function s(g,E,x,N){var I,G;if(N||(N=x==null?void 0:x.getData()),!N)return;const{x:B,y:_,properties:W}=N,te=(I=W==null?void 0:W.width)!=null?I:x==null?void 0:x.width,ae=(G=W==null?void 0:W.height)!=null?G:x==null?void 0:x.height;if(!te||!ae)return;const oe=B+g/2,Ne=_+E/2;return{minX:oe-te/2,minY:Ne-ae/2,maxX:oe+te/2,maxY:Ne+ae/2}}function p(g,E,x){const N=t();if(!N||!g.children||g.children.size===0)return;let I;return g.children.forEach(G=>{let B;if(G===E&&x)B=x;else{const _=N.getNodeModelById(G);B=_==null?void 0:_.getBounds()}B&&(I?(I.minX=Math.min(I.minX,B.minX),I.minY=Math.min(I.minY,B.minY),I.maxX=Math.max(I.maxX,B.maxX),I.maxY=Math.max(I.maxY,B.maxY)):I=ne({},B))}),I}function d(g){var E,x,N,I,G,B;const _=(x=(E=g.properties)==null?void 0:E.autoResizePadding)!=null?x:Wr;return typeof _=="number"?{top:_,right:_,bottom:_,left:_}:{top:(N=_.top)!=null?N:ge,right:(I=_.right)!=null?I:ge,bottom:(G=_.bottom)!=null?G:ge,left:(B=_.left)!=null?B:ge}}const u=yr(g=>{e.getNodeEdges(g).forEach(E=>{const x=E.getData();delete x.startPoint,delete x.endPoint,delete x.pointsList,e.deleteEdgeById(E.id),e.addEdge(x)})},15);function f(g,E){const x=E.maxX-E.minX,N=E.maxY-E.minY;if(x<=0||N<=0)return;const I=E.minX+x/2,G=E.minY+N/2,B=Math.abs(I-g.x)>we||Math.abs(G-g.y)>we,_=Math.abs(x-g.width)>we||Math.abs(N-g.height)>we;!B&&!_||(g.moveTo(I,G),g.width=x,g.height=N,u(g.id))}return{recalcGroupSize:r,recalcGroupSizeByNode:i,updateGroupSize:n}}const De=Ht();class Fr extends zo{constructor(e){super(e),this.originOnNodeMove=this.onNodeMove,this.addNodeToGroup=t=>{const r=this.$lf.getNodeModelById(t.id),i=r==null?void 0:r.getBounds();if(!r||!i)return;const n=this.getGroupByBounds(i,t),s=this.nodeGroupMap.get(t.id);if(s){const p=this.$lf.getNodeModelById(s),d=!n||n.id!==s,u=n&&n.id!==s;if(!d&&!u)return;p&&(p.removeChild(t.id),p.setAllowAppendChild(!1)),this.nodeGroupMap.delete(t.id)}if(r.isGroup){const p=r;p.children&&Array.from(p.children).forEach(d=>{this.nodeGroupMap.set(d,t.id)}),this.calibrateTopGroupZIndex([t]),this.onNodeSelect({data:t,isSelected:!1,isMultiple:!1})}n&&(n.isAllowAppendIn(t)?(n.addChild(t.id),n.setAllowAppendChild(!1)):this.$lf.emit("group:not-allowed",{group:n.getData(),node:t}))},this.$lf=e.lf,this.graphModel=e.lf.graphModel,this.$utils=Vt(this.$lf,this.graphModel),this.$lf.off("node:mousemove",this.originOnNodeMove),this.onNodeMove=this.enhancedOnNodeMove.bind(this),this.$lf.on("node:mousemove",this.onNodeMove),this.overrideNodeGroupMap()}overrideNodeGroupMap(){const e=this.nodeGroupMap.set.bind(this.nodeGroupMap);this.nodeGroupMap.set=function(i,n){return De.nodeGroupMap.set(i,n),e(i,n)}.bind(this.nodeGroupMap);const t=this.nodeGroupMap.delete.bind(this.nodeGroupMap);this.nodeGroupMap.delete=function(i){return De.nodeGroupMap.delete(i),t(i)}.bind(this.nodeGroupMap);const r=this.nodeGroupMap.clear.bind(this.nodeGroupMap);this.nodeGroupMap.clear=function(){return De.nodeGroupMap.clear(),r()}.bind(this.nodeGroupMap)}enhancedOnNodeMove({deltaX:e,deltaY:t,data:r}){const i=r==null?void 0:r.id;if(!i)return;const n=this.nodeGroupMap.get(i);n&&this.$utils.updateGroupSize({groupId:n,nodeId:i,deltaX:e,deltaY:t,nodeData:r})}}function qr(){return{plugins:[Ge,Fr]}}class jr extends Co{constructor(){super(),this.$hook=Uo(this)}getEdge(){const e=super.getEdge(),t=this.props.model.isHovered,{isSilentMode:r}=this.props.graphModel.editConfigModel;return!r&&t&&(e.props.stroke="#1890ff"),e}getAppendWidth(){const e=this.$hook;return Le("g",{},super.getAppendWidth(),e.getActionShape())}getStartArrow(){return Le("g",{})}getEndArrow(){return Le("g",{})}toFront(){}}class Yr extends To{get isDisabled(){var e,t;return(t=(e=this.properties)==null?void 0:e.disabled)!=null?t:!1}initEdgeData(e){e.id||(e.id=$o()),super.initEdgeData(e)}getData(){return{id:this.id,type:this.type,sourceNodeId:this.sourceNodeId,targetNodeId:this.targetNodeId,sourceAnchorId:this.sourceAnchorId,targetAnchorId:this.targetAnchorId,pointsList:this.pointsList,properties:this.properties}}getEdgeStyle(){const e=super.getEdgeStyle();return e.stroke="#afafaf",e.strokeWidth=2,e}getOutlineStyle(){const e=super.getOutlineStyle();return e.stroke="none",e.hover&&(e.hover.stroke="none"),e}getEdgeAnimationStyle(){var e;const t=super.getEdgeAnimationStyle(),r=(e=this.properties)==null?void 0:e.runStatus;return r==="running"?t.stroke="#67b7ff":r==="success"?t.stroke="#52c41a":r==="fail"&&(t.stroke="#f5222d"),t}}const mt={type:"base-edge",view:jr,model:Yr},Be={type:m.START,label:"开始",docs:["https://help.jeecg.com/aigc/flowNodes/nodeStart"],components:{icon:Jo,setting:Qo},lfNode:{type:m.START,view:R,model:D,component:Zo},params:{width:M,height:L},methods:{createNode:Vr,updateNodeSetting:Ur,checkNode:Kr,getDefaultAnchor(o){return o.filter(e=>e.type==="right")}},hooks:{beforeRemoveNode(){return!1}}};function Xr(o){return o==null?!1:!Ro(o)}const Ut=()=>({inputParams:[{field:"content",name:"用户问题",type:"string",required:!1},{field:"history",name:"历史记录",type:"string[]",required:!1},{field:"images",name:"图片",type:"picture",required:!1}]});function Kt(){return{enabled:!1,cronType:"day",cronExp:en(null,"day"),beginTime:null,endTime:null,inputParams:{},custom:qt(null)}}function Vr(o){const e=Ut();return{id:"start-node",type:Be.type,x:o.x,y:o.y,properties:{text:Be.label,remarks:"",options:{cronTrigger:Kt()},inputParams:e.inputParams,outputParams:[]}}}function Ur(o){var e;const{mergeIOParams:t}=re(o,Ut);t(),o.properties.options||(o.properties.options={}),o.properties.options.cronTrigger||(o.properties.options.cronTrigger=Kt()),o.properties.options.cronTrigger.custom||(o.properties.options.cronTrigger.custom=qt((e=o.properties.options.cronTrigger.beginTime)!=null?e:null)),o.properties.options.cronTrigger.importParams&&!o.properties.options.cronTrigger.inputParams&&(o.properties.options.cronTrigger.inputParams=o.properties.options.cronTrigger.importParams,delete o.properties.options.cronTrigger.importParams);const r=o.properties.inputParams.find(i=>i.field==="history");r&&(r.required=!1)}function Kr(o,e,t){var r,i,n,s;const p=[],d=(r=e==null?void 0:e.properties)!=null?r:{},u=(i=d.options)!=null?i:{},f=d.inputParams,g=(n=u.cronTrigger)!=null?n:{};if(g.enabled){const E=(s=g.inputParams)!=null?s:{};f.find(x=>x.required&&x.field!=="history"?!Xr(E[x.field]):!1)&&p.push("定时触发器:存在必填参数未配置默认值")}return p}const We={type:m.END,label:"结束",docs:["https://help.jeecg.com/aigc/flowNodes/nodeEnd"],components:{icon:tn,setting:on},lfNode:{type:m.END,view:R,model:D,component:nn},params:{width:M,height:L},methods:{createNode:zr,checkNode:Jr,getDefaultAnchor(o){return o.filter(e=>e.type==="left")}}};function zr(o){return{id:o.id,remarks:"",type:We.type,x:o.x,y:o.y,properties:{text:We.label,options:{outputText:!1,outputContent:"",outputType:"text",cardConfig:null},inputParams:[],outputParams:[]}}}function Jr(o,e,{checkOutputParams:t}){const{properties:r}=e,{options:i}=r,n=i.outputText,s=i.outputContent,p=i.outputType,d=i.cardConfig,u=[...t({text:"输出变量",required:!n})];return n&&!s&&u.push("返回文本不能为空"),p==="text"&&!s&&u.push("返回文本不能为空"),p==="card"&&!d&&u.push("需要绑定卡片"),u}const He={type:m.LLM,label:"LLM",docs:["https://help.jeecg.com/aigc/flowNodes/nodeLLM"],components:{icon:rn,setting:sn},lfNode:{type:m.LLM,view:R,model:D,component:an},params:{width:M,height:L},methods:{createNode:Qr,checkNode:Zr,updateNodeSetting:ei}},zt=()=>({options:{showToolExecution:!1},inputParams:[],outputParams:[{field:"text",name:"回复内容",type:"string"}]});function Qr(o){var e;const t=zt();return{id:o.id,remarks:"",type:He.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:He.label,options:ne({model:{modeId:"",params:{model:"",temperature:.7,timeout:60}},history:3,messages:[{role:"system",content:`**人物设定**
- 你是李白
- 人称第一人称
- 出生地安西都护府碎叶城
- 性格特点豪放不羁自信豁达重情重义浪漫洒脱
- 语言风格富有想象力优美流畅
- 经典台词
- 仰天大笑出门去我辈岂是蓬蒿人
- 天生我材必有用千金散尽还复来`},{role:"user",content:""}]},t.options),inputParams:t.inputParams,outputParams:t.outputParams}}}function Zr(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1})];if(i.model.modeId||n.push("必须选择模型"),i.structuredOutput){const s=i.structuredOutputFields;!Array.isArray(s)||s.length===0?n.push("启用结构化输出时,至少需要配置一个输出字段"):s.some(p=>!p.field)&&n.push("结构化输出字段名不能为空")}return n}function ei(o){var e;const{mergeIOParams:t,updateOption:r}=re(o,zt);t(),r("showToolExecution",n=>typeof n!="boolean"),r("structuredOutput",n=>typeof n!="boolean"),r("structuredOutputFields",n=>!Array.isArray(n));const i=(e=o.properties)==null?void 0:e.options;(i==null?void 0:i.systemPromptMode)==="ref"&&!(i!=null&&i.systemPromptRefId)&&(o.properties.options.systemPromptMode="fill")}class ti extends D{get $caseList(){return ct(this)}}const Fe={type:m.CLASSIFIER,label:"分类器",docs:["https://help.jeecg.com/aigc/flowNodes/nodeClassifier"],components:{icon:dn,setting:Fo},lfNode:{type:m.CLASSIFIER,view:R,model:ti,component:pn},params:{width:M,height:L},methods:{createNode:oi,checkNode:ni,updateNodeSetting:ri,getAnchorId:ke,getDefaultAnchor(o){const[e,t]=o,r=[e];if(!this.$caseList.length)return r;for(let i=0;i<this.$caseList.length;i++){const n=this.$caseList[i];r.push({id:ke(this.id,n.type,i+1),x:t.x,y:t.y+34+22*i+22*i,type:"right"})}return r}}},Jt=()=>({outputParams:[{field:"index",name:"分类索引",type:"number"},{field:"content",name:"分类描述",type:"string"}]});function oi(o){var e;const t=Jt();return{id:o.id,remarks:"",type:Fe.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Fe.label,options:{model:{modeId:"",params:{model:"",temperature:.7}},categories:[{category:"",next:""},{category:"",next:""}],else:{next:""}},inputParams:[],outputParams:t.outputParams}}}function ni(o,e,{findNextIdsByAnchorId:t}){const{edges:r}=o.graphModel,{properties:i}=e,{options:n}=i,s=[];(!Array.isArray(n==null?void 0:n.categories)||n.categories.length===0)&&s.push("“分类”不能为空");const p=ct(e);for(let d=0;d<p.length;d++){const u=p[d],f=ke(e.id,u.type,d+1);t(f,r).length===0&&s.push(`${u.label}未连接下一个节点`)}return s}function ri(o){const{mergeIOParams:e}=re(o,Jt);e();const t=o.properties.outputParams.find(r=>r.field==="content");t&&(t.name="分类描述")}class ii extends D{get $caseList(){return ut(this)}}const qe={type:m.SWITCH,label:"条件分支",docs:["https://help.jeecg.com/aigc/flowNodes/nodeSwitch"],components:{icon:ln,setting:Ho},lfNode:{type:m.SWITCH,view:R,model:ii,component:un},params:{width:M,height:L},methods:{createNode:si,checkNode:di,updateNodeSetting:ai,getAnchorId:Ae,getDefaultAnchor(o){const[e,t]=o,r=[e];if(!this.$caseList.length)return r;for(let i=0;i<this.$caseList.length;i++){const n=this.$caseList[i];r.push({id:Ae(this.id,n.type,i+1),x:t.x,y:t.y+34+26*i,type:"right"})}return r}}},Qt=()=>({outputParams:[{field:"index",name:"分支索引",type:"number"}]});function si(o){var e;const t=Qt();return{id:o.id,remarks:"",type:qe.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:qe.label,options:{if:[{logic:"AND",conditions:[{nodeId:"",field:"",operator:"EQUALS",value:""}],next:""}],else:{next:""}},inputParams:[],outputParams:t.outputParams}}}function ai(o){const{mergeIOParams:e}=re(o,Qt);e()}function di(o,e,{findNextIdsByAnchorId:t}){const{edges:r}=o.graphModel,{properties:i}=e,{options:n}=i,s=[];(!Array.isArray(n==null?void 0:n.if)||n.if.length===0)&&s.push("“IF”分支条件不能为空");const p=ut(e);for(let d=0;d<p.length;d++){const u=p[d],f=Ae(e.id,u.type,d+1);t(f,r).length===0&&s.push(`${u.label}分支未连接下一个节点`)}return s}const je={type:m.KNOWLEDGE,label:"知识库",docs:["https://help.jeecg.com/aigc/flowNodes/nodeKnow"],components:{icon:cn,setting:hn},lfNode:{type:m.KNOWLEDGE,view:R,model:D,component:mn},params:{width:M,height:L},methods:{createNode:pi,checkNode:li}};function pi(o){var e;return{id:o.id,remarks:"",type:je.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:je.label,options:{knowIds:[],topNumber:5,similarity:.7},inputParams:[],outputParams:[{field:"documents",name:"文档列表",type:"object[]"},{field:"data",name:"文档内容",type:"string"}]}}}function li(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"查询变量",required:!0,requiredName:!1})];return(!Array.isArray(i.knowIds)||i.knowIds.length===0)&&n.push("必须选择至少一个知识库"),n}const Ye={type:m.KNOWLEDGE_WRITE,label:"知识库写入",components:{icon:fn,setting:gn},lfNode:{type:m.KNOWLEDGE_WRITE,view:R,model:D,component:yn},params:{width:M,height:L},methods:{createNode:ui,checkNode:hi,updateNodeSetting:ci}};function ui(o){var e;return{id:o.id,remarks:"",type:Ye.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Ye.label,options:{knowIds:[],content:"",segmentStrategy:"auto",separator:"\\n",customSeparator:"",maxSegment:800,overlap:10,textRules:[]},inputParams:[],outputParams:[{field:"documentId",name:"documentId",type:"string"}]}}}function ci(o){o.properties.options||(o.properties.options={});const e=o.properties.options;e.segmentStrategy==null&&(e.segmentStrategy="auto"),e.separator==null&&(e.separator="\\n"),e.customSeparator==null&&(e.customSeparator=""),e.maxSegment==null&&(e.maxSegment=800),e.overlap==null&&(e.overlap=10),Array.isArray(e.textRules)||(e.textRules=[])}function hi(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1,requiredName:!0})];return!i||!Array.isArray(i.knowIds)||i.knowIds.length===0?n.push("请选择 1 个知识库"):i.knowIds.length>1&&n.push("仅支持选择 1 个知识库"),i!=null&&i.content||n.push("写入内容不能为空"),n}class mi extends D{constructor(e,t){super(e,t),this.id.startsWith(m.CODE+"_")||super.updateId(m.CODE+"_"+this.id)}}const Xe={type:m.CODE,label:"脚本执行",docs:["https://help.jeecg.com/aigc/flowNodes/nodeCode"],components:{icon:Nn,setting:vn},lfNode:{type:m.CODE,view:R,model:mi,component:xn},params:{width:M,height:L},methods:{createNode:fi,checkNode:gi,initNodeData(){this.id.startsWith(m.CODE+"_")||(this.id=m.CODE+"_"+this.id)}}};function fi(o){var e;return{id:o.id,remarks:"",type:Xe.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Xe.label,options:{codeType:"javascript",code:`
function main(params) {
return {
result: params.arg1 + '_拼接_' + params.arg2,
}
}
`.trim()},inputParams:[{field:"",name:"arg1",nodeId:""},{field:"",name:"arg2",nodeId:""}],outputParams:[{field:"result",name:"返回结果",type:"string"}]}}}function gi(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1})];return i.code||n.push("脚本内容不能为空"),n}const Ve={type:m.SUBFLOW,label:"子流程",docs:["https://help.jeecg.com/aigc/flowNodes/nodeSubFlow"],components:{icon:In,setting:En},lfNode:{type:m.SUBFLOW,view:R,model:D,component:Sn},params:{width:M,height:L},methods:{createNode:yi,checkNode:Ni}};function yi(o){var e;return{id:o.id,remarks:"",type:Ve.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Ve.label,options:{subflowId:""},inputParams:[],outputParams:[]}}}function Ni(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1})];return i.subflowId||n.push("必须选择子流程"),n}const Ue={type:m.ENHANCE_JAVA,label:"Java 增强",docs:["https://help.jeecg.com/aigc/flowNodes/nodeJava"],components:{icon:Pn,setting:wn},lfNode:{type:m.ENHANCE_JAVA,view:R,model:D,component:An},params:{width:M,height:L},methods:{createNode:vi,checkNode:xi}};function vi(o){var e;return{id:o.id,remarks:"",type:Ue.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Ue.label,options:{enhance:{type:"class",path:""}},inputParams:[{field:"",name:"arg1",nodeId:""},{field:"",name:"arg2",nodeId:""}],outputParams:[{field:"result",name:"返回结果",type:"string"}]}}}function xi(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1})],s=i.enhance.type==="class";return i.enhance.path||n.push(`${s?"类路径":"Spring Bean 名称"}必须填写`),n}const Ke={type:m.HTTP,label:"HTTP 请求",docs:["https://help.jeecg.com/aigc/flowNodes/nodeHttp"],components:{icon:kn,setting:bn},lfNode:{type:m.HTTP,view:R,model:D,component:Tn},params:{width:M,height:L},methods:{createNode:Ii,checkNode:Si,updateNodeSetting:Ei}},Zt=()=>({inputParams:[],outputParams:[{field:"body",name:"回复内容",type:"string"},{field:"statusCode",name:"状态码",type:"number"}]});function Ii(o){var e;const t=Zt();return{id:o.id,remarks:"",type:Ke.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Ke.label,options:{http:{url:"",method:"GET",headers:{},requestBody:{type:"none",body:""},requestParams:{},timeout:120,retriesTimes:0}},inputParams:t.inputParams,outputParams:t.outputParams}}}function Ei(o){const{mergeIOParams:e}=re(o,Zt);e();const{requestBody:t}=o.properties.options.http;(!t||typeof t=="string")&&(o.properties.options.http.requestBody={type:"none",body:t||""})}function Si(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1})];return i.http.url||n.push("请求地址必须填写"),n}const ze={type:m.VAR_MERGE,label:"变量聚合",components:{icon:$n,setting:Cn},lfNode:{type:m.VAR_MERGE,view:R,model:D,component:Ln},params:{width:M,height:L},methods:{createNode:Pi,checkNode:wi}};function Pi(o){var e;const t=[Mn(1)];return{id:o.id,remarks:"",type:ze.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:ze.label,options:{varGroups:t},inputParams:[],outputParams:On(t)}}}function wi(o,e){var t,r,i;const n=[],s=(i=(r=(t=e==null?void 0:e.properties)==null?void 0:t.options)==null?void 0:r.varGroups)!=null?i:[];if(!Array.isArray(s)||s.length===0)return n.push("请至少配置一个变量分组"),n;const p=new Set;return s.forEach(d=>{const u=d.name;if(p.has(u)){n.push(`${u}的名称与其他分组重复`);return}if(p.add(d.name),!(d!=null&&d.type)){n.push(`${u}未确定类型请先选择上游变量`);return}const f=Array.isArray(d==null?void 0:d.vars)?d.vars:[];if(f.length===0){n.push(`${u}至少需要一个变量`);return}for(const g of f)if((g==null?void 0:g.isCustom)!==!0&&(!(g!=null&&g.nodeId)||!(g!=null&&g.field))){n.push(`${u}存在未选择的变量`);break}}),n}const Je={type:m.VAR_EXTRACT,label:"变量提取器",components:{icon:Dn,setting:Rn},lfNode:{type:m.VAR_EXTRACT,view:R,model:D,component:_n},params:{width:M,height:L},methods:{createNode:Ai,checkNode:bi,updateNodeSetting:ki,getAnchorId:se,getDefaultAnchor(o){const[e,t]=o;return[e,ye(ne({},t),{id:se(this.id,"success"),y:t.y+34}),ye(ne({},t),{id:se(this.id,"fail"),y:t.y+60})]}}};function eo(){const o=[];return{inputParams:[{field:"input",name:"",nodeId:"",type:"string"}],outputParams:jt(o),variables:o}}function Ai(o){var e;const t=eo();return{id:o.id,remarks:"",type:Je.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Je.label,options:{model:{modeId:"",params:{model:"",temperature:.3,timeout:60}},variables:t.variables},inputParams:t.inputParams,outputParams:t.outputParams}}}function ki(o){var e,t,r;const{mergeIOParams:i,updateProp:n}=re(o,eo);i();const s=(r=(t=(e=o.properties)==null?void 0:e.options)==null?void 0:t.variables)!=null?r:[];n("outputParams",jt(s))}function bi(o,e,{findNextIdsByAnchorId:t}){var r,i;const{edges:n}=o.graphModel,{properties:s}=e,{options:p}=s,d=[],u=(r=s==null?void 0:s.inputParams)==null?void 0:r[0];(!(u!=null&&u.nodeId)||!(u!=null&&u.field))&&d.push("请选择输入变量"),u!=null&&u.type&&u.type!=="string"&&d.push("输入变量仅支持 string 类型"),(i=p==null?void 0:p.model)!=null&&i.modeId||d.push("必须选择模型");const f=Array.isArray(p==null?void 0:p.variables)?p.variables:[];f.length===0&&d.push("请至少添加一个提取变量");const g=new Set;for(const N of f){if(!N.name){d.push("提取变量名称不能为空");continue}g.has(N.name)?d.push(`变量名称${N.name}重复`):g.add(N.name),N.required&&!N.failTip&&d.push(`必填变量${N.name}需要失败提示`)}const E=se(e.id,"success"),x=se(e.id,"fail");return t(E,n).length===0&&d.push("“成功”分支未连接下一个节点"),t(x,n).length===0&&d.push("“失败”分支未连接下一个节点"),d}const Qe={type:m.TOOLS,label:"工具调用",docs:["https://help.jeecg.com/aigc/flowNodes/nodeTools"],components:{icon:Gn,setting:Bn},lfNode:{type:m.TOOLS,view:R,model:D,component:Wn},params:{width:M,height:L},methods:{createNode:Ti,checkNode:Ci,updateNodeSetting:$i}},to=()=>({inputParams:[],outputParams:[{field:"result",name:"执行结果",type:"string"}]});function Ti(o){var e;const t=to();return{id:o.id,remarks:"",type:Qe.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Qe.label,options:{tools:{pluginId:"",pluginName:"",pluginCategory:"plugin",toolName:"",toolDescr:"",toolParameters:[],endpoint:"",path:"",method:"",headers:{}}},inputParams:t.inputParams,outputParams:t.outputParams}}}function $i(o){const{mergeIOParams:e}=re(o,to);e()}function Ci(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1})],s=i.tools||{};s.pluginId||n.push("请选择插件或MCP"),s.toolName||n.push("请选择工具"),s.path||n.push("缺少path配置"),s.method||n.push("缺少method配置");const p=s.toolParameters||[];for(const d of p)d.required&&!d.value&&n.push(`必填参数未配置: ${d.name}`);return n}const Ze={type:m.BRAVE_SEARCH,label:"Brave搜索",docs:["https://help.jeecg.com/aigc/flowNodes/nodeBraveSearch"],components:{icon:Hn,setting:Fn},lfNode:{type:m.BRAVE_SEARCH,view:R,model:D,component:qn},params:{width:M,height:L},methods:{createNode:Oi,checkNode:Li,updateNodeSetting:Mi}},oo=()=>({inputParams:[],outputParams:[{field:"result",name:"搜索结果",type:"object[]"}]});function Oi(o){var e;const t=oo();return{id:o.id,remarks:"",type:Ze.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:Ze.label,options:{braveSearch:{count:5,country:""}},inputParams:t.inputParams,outputParams:t.outputParams}}}function Mi(o){const{mergeIOParams:e}=re(o,oo);e()}function Li(o,e,{checkInputParams:t}){return[...t({text:"搜索关键词",required:!0})]}const et={type:m.REPLY,label:"直接回复",docs:["https://help.jeecg.com/aigc/flowNodes/nodeEnd"],components:{icon:jn,setting:Yn},lfNode:{type:m.REPLY,view:R,model:D,component:Xn},params:{width:M,height:L},methods:{createNode:Di,checkNode:Ri,updateNodeSetting:_i}};function Di(o){var e;return{id:o.id,remarks:"",type:et.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:et.label,options:{content:"",stream:!1},inputParams:[],outputParams:[]}}}function Ri(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1})];return i.content||n.push("回复内容不能为空"),n}function _i(o){let{stream:e}=o.properties.options;e==null&&(o.properties.options.stream=!1)}const tt={type:m.SQL,label:"SQL自定义",docs:["https://help.jeecg.com/aigc/flowNodes/nodeHttp"],components:{icon:Vn,setting:Un},lfNode:{type:m.SQL,view:R,model:D,component:Kn},params:{width:M,height:L},methods:{createNode:Bi,checkNode:Wi}},Gi=()=>({inputParams:[],outputParams:[{field:"body",name:"sql执行返回结果",type:"string"}]});function Bi(o){var e;const t=Gi();return{id:o.id,remarks:"",type:tt.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:tt.label,options:{sql:{dataSourceName:"",dataSourceId:"",dataSourceCode:"",outputSql:""}},inputParams:t.inputParams,outputParams:t.outputParams}}}function Wi(o,e,{checkInputParams:t}){const r=[...t({text:"输入变量",required:!1})],{properties:i}=e,{options:n}=i;return n.sql.dataSourceId||r.push("数据源不能为空"),n.sql.outputSql||r.push("自定义sql不能为空"),r}const ot={type:m.LOOP,label:"循环",components:{icon:zn,setting:Wo},lfNode:{type:m.LOOP,view:R,model:D,component:Jn},params:{width:M,height:L},methods:{createNode:Fi,checkNode:qi,getDefaultAnchor(o){const e=[...o],t=`${this.id}_${Re.LINK_BODY}`;return e.push({id:t,x:this.x,y:this.y+this.height/2,type:Re.LINK_BODY}),e}},hooks:{afterAddNode(o,e){Ko(o,e)},afterRemoveNode(o,e){const t=o.id+Rt;e.deleteNode(t)}}},Hi=()=>({type:"counted",maxLoopTimes:3,loopParams:[],loopItemsParam:{}});function Fi(o){var e;const t=Hi();return{id:o.id,remarks:"",type:ot.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:ot.label,groupType:no(t.type),options:t,inputParams:[],outputParams:[]}}}function qi(o,e,{}){var t,r,i,n,s,p,d;const u=(r=(t=e==null?void 0:e.properties)==null?void 0:t.options)!=null?r:{},f=[],g=(i=u.type)!=null?i:"counted";return no(g)||f.push("请选择有效的循环类型"),g==="counted"?ji(u.maxLoopTimes)||f.push("请设置大于 0 的循环次数"):g==="infinite"?Yi(o,e==null?void 0:e.id)||f.push("无限循环必须在循环体内添加“终止循环”节点"):g==="array"&&((!u.loopItemsParam||!((n=u.loopItemsParam)!=null&&n.nodeId)||!((s=u.loopItemsParam)!=null&&s.field))&&f.push("请选择迭代数组变量"),(p=u.loopItemsParam)!=null&&p.type&&!`${u.loopItemsParam.type}`.endsWith("[]")&&f.push("迭代变量必须是数组类型")),(Array.isArray((d=e==null?void 0:e.properties)==null?void 0:d.outputParams)?e.properties.outputParams:[]).length>0,f}function ji(o){return typeof o=="number"&&Number.isInteger(o)&&o>0}function no(o){switch(o){case"array":return ie.ITERATOR;case"infinite":case"counted":default:return ie.WHILE}}function Yi(o,e){var t,r;if(!o||!e)return!1;const i=(t=o.getGraphData)==null?void 0:t.call(o);if(!i)return!1;const n=i,s=Array.isArray(n==null?void 0:n.nodes)?n.nodes:[],p=Array.isArray(n==null?void 0:n.edges)?n.edges:[],d=new Map;s.forEach(N=>{N!=null&&N.id&&d.set(N.id,N.type)});const u=new Map;p.forEach(N=>{var I;if(!(N!=null&&N.sourceNodeId)||!(N!=null&&N.targetNodeId))return;const G=(I=u.get(N.sourceNodeId))!=null?I:[];G.push(N.targetNodeId),u.set(N.sourceNodeId,G)});const f=new Set,g=[e],E=Math.max(s.length*2,50);let x=0;for(;g.length>0&&x<E;){x++;const N=g.shift();if(f.has(N))continue;f.add(N);const I=(r=u.get(N))!=null?r:[];for(const G of I){if(d.get(G)===m.LOOP_BREAK)return!0;f.has(G)||g.push(G)}}return!1}class Xi extends D{constructor(e,t){super(e,t)}getData(){const e=super.getData();return e.properties||(e.properties={}),e.properties.loopNodeId=Ft(this.id),e}}const nt={type:m.LOOP_BREAK,label:"终止循环",components:{icon:Qn,setting:lt},lfNode:{type:m.LOOP_BREAK,view:R,model:Xi,component:Zn},params:{width:M,height:L},methods:{createNode:Vi,getDefaultAnchor(o){return o.filter(e=>e.type==="left")}}};function Vi(o){var e;return{id:o.id,type:nt.type,x:o.x,y:o.y,remarks:"",properties:{text:(e=o.text)!=null?e:nt.label,options:{},inputParams:[],outputParams:[]}}}const rt={type:m.LOOP_CONTINUE,label:"继续循环",components:{icon:er,setting:lt},lfNode:{type:m.LOOP_CONTINUE,view:R,model:D,component:tr},params:{width:M,height:L},methods:{createNode:Ui,getDefaultAnchor(o){return o.filter(e=>e.type==="left")}}};function Ui(o){var e;return{id:o.id,type:rt.type,x:o.x,y:o.y,remarks:"",properties:{text:(e=o.text)!=null?e:rt.label,options:{},inputParams:[],outputParams:[]}}}class Ki extends D{constructor(e,t){super(e,t)}getData(){const e=super.getData();return e.properties||(e.properties={}),e.properties.loopNodeId=Ft(this.id),e}}const it={type:m.SET_LOOP_VAR,label:"设置循环变量",components:{icon:or,setting:rr},lfNode:{type:m.SET_LOOP_VAR,view:R,model:Ki,component:nr},params:{width:M,height:L},methods:{createNode:zi,checkNode:Ji}};function zi(o){var e;return{id:o.id,type:it.type,x:o.x,y:o.y,remarks:"",properties:{text:(e=o.text)!=null?e:it.label,options:{targetField:"",sourceVar:{}},inputParams:[],outputParams:[]}}}function Ji(o,e){var t,r;const i=(r=(t=e==null?void 0:e.properties)==null?void 0:t.options)!=null?r:{},n=[];i.targetField||n.push("请选择要设置的循环变量");const s=i.sourceVar;return(!s||(!s.nodeId||!s.field)&&!s.customValue&&s.customValue!=="")&&n.push("请选择或输入变量值"),n}const st={type:m.CHAT_VAR_GET,label:"变量读取",components:{icon:ir,setting:sr},lfNode:{type:m.CHAT_VAR_GET,view:R,model:D,component:ar},params:{width:M,height:L},methods:{createNode:Qi,checkNode:Zi}};function Qi(o){var e;return{id:o.id,type:st.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:st.label,options:{variables:[{name:""}]},inputParams:[],outputParams:[]}}}function Zi(o,e){var t,r,i;const n=[],s=(i=(r=(t=e==null?void 0:e.properties)==null?void 0:t.options)==null?void 0:r.variables)!=null?i:[];if(!Array.isArray(s)||s.length===0)return n.push("请至少配置一个变量"),n;const p=new Set;for(const d of s){if(!d.name){n.push("存在未填写变量名的变量");break}if(p.has(d.name)){n.push(`变量名"${d.name}"重复`);break}p.add(d.name)}return n}const at={type:m.CHAT_VAR_SET,label:"变量赋值",components:{icon:dr,setting:pr},lfNode:{type:m.CHAT_VAR_SET,view:R,model:D,component:lr},params:{width:M,height:L},methods:{createNode:es,checkNode:ts}};function es(o){var e;return{id:o.id,type:at.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:at.label,options:{variables:[{name:""}]},inputParams:[],outputParams:[]}}}function ts(o,e){var t,r,i;const n=[],s=(i=(r=(t=e==null?void 0:e.properties)==null?void 0:t.options)==null?void 0:r.variables)!=null?i:[];if(!Array.isArray(s)||s.length===0)return n.push("请至少配置一个变量"),n;const p=new Set;for(const d of s){if(!d.name){n.push("存在未填写变量名的变量");break}if(p.has(d.name)){n.push(`变量名"${d.name}"重复`);break}if(p.add(d.name),!(d.nodeId&&d.field||d.isCustom)){n.push(`变量"${d.name}"未设置值`);break}}return n}const dt={type:m.CHAT_MEMORY_GET,label:"记忆检索",components:{icon:ur,setting:cr},lfNode:{type:m.CHAT_MEMORY_GET,view:R,model:D,component:hr},params:{width:M,height:L},methods:{createNode:os,checkNode:ns}};function os(o){var e;return{id:o.id,remarks:"",type:dt.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:dt.label,options:{content:"",topNumber:5,similarity:.7},inputParams:[],outputParams:[{field:"documents",name:"文档列表",type:"object[]"},{field:"data",name:"文档内容",type:"string"}]}}}function ns(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1,requiredName:!0})];return i!=null&&i.content||n.push("检索内容不能为空"),n}const pt={type:m.CHAT_MEMORY_SET,label:"记忆写入",components:{icon:mr,setting:fr},lfNode:{type:m.CHAT_MEMORY_SET,view:R,model:D,component:gr},params:{width:M,height:L},methods:{createNode:rs,checkNode:is}};function rs(o){var e;return{id:o.id,remarks:"",type:pt.type,x:o.x,y:o.y,properties:{text:(e=o.text)!=null?e:pt.label,options:{title:"",content:""},inputParams:[],outputParams:[{field:"documentId",name:"documentId",type:"string"}]}}}function is(o,e,{checkInputParams:t}){const{properties:r}=e,{options:i}=r,n=[...t({text:"输入变量",required:!1,requiredName:!0})];return i!=null&&i.content||n.push("写入内容不能为空"),n}const ss=mt.type;function as(o){Wt.clear(),ht.clear(),ue.clear(),ee.clear(),o.register(mt),o.register(_e);const e=ds(o);e(Be,{show:!1}),e(He),e(Fe),e(Je),ee.addDivider(),e(je),e(Ye),e(st),e(at),e(dt),e(pt),ee.addDivider(),e(qe),e(ze),e(Xe),e(Ue),e(Ke),e(tt),e(Qe),e(Ze),ee.addDivider(),e(ot),e(Vo,{show:!1}),e(nt,{show:!1}),e(rt,{show:!1}),e(it,{show:!1}),ee.addDivider(),e(Ve),ee.addDivider(),e(et),e(We)}function ds(o){return(e,t)=>{e.docs=ps(e),ue.set(e.type,e),Oo(e.lfNode,o),e.components.icon&&Wt.set(e.type,e.components.icon),e.components.setting&&ht.set(e.type,e.components.setting),ee.add(e.type,t)}}function ps(o){const{docs:e}=o;if(e){if(typeof e=="string")return e;if(!(!Array.isArray(e)||e.length===0))return e.length>1?e[1]:e[0]}}const Dt=800,ls=vr({__name:"WorkflowView",props:{data:{type:Object,default:()=>({})},width:{type:Number,default:2048},height:{type:Number,default:800},openCheckListPop:Function},emits:["save","close","init"],setup(o,{expose:e,emit:t}){const{createWarningModal:r}=Mo(),i=bo(),n=o,s=t,p=qo(),d=jo(),{prefixCls:u}=_t("airag-work-flow-box"),f=he(null),g=he(null),E=he(null),x=he(""),N=be({isSilentMode:!1});Ot("lfRef",f),Ot("editConfigModel",N);const I=be({visible:!1,triggerNodeId:"",payload:{},isShow:lo,onAdd:uo}),[G,B]=bt(),[_,W]=bt(),te=a=>ve.value.length>0?(r({title:"存在问题",content:`存在尚未修复的节点问题请先修复后再进行${a}`,okText:"立即修复",cancelText:"取消",okCancel:!0,maskClosable:!0,onOk:()=>{var l;return(l=n==null?void 0:n.openCheckListPop)==null?void 0:l.call(n)}}),!1):!0,ae=()=>{te("调试")&&(q(W.getOpen)&&W.closeDrawer(),B.openDrawer(!0,{}))},{SuperControl:oe}=Br(f);xr(()=>{E.value&&(p.initStatus(),d.clearProps(),f.value=Ne({container:E.value}),window.addEventListener("keydown",At),s("init",f.value))});function Ne({container:a}){var l,h,c;f.value&&f.value.destroy();const y=new Ao(ye(ne({container:a,width:n.width,height:n.height,edgeType:ss,textEdit:!1,adjustEdge:!1,adjustEdgeStartAndEnd:!1,background:{backgroundColor:"#f5f6f7"},grid:{size:10,type:"dot",config:{color:"#E0E0E0",thickness:1}}},qr()),{pluginsOptions:{[oe.pluginName]:{use:oe,debugRun:ae,save:()=>s("save"),close:()=>s("close")}}}));if(as(y),io(y),(h=(l=n.data)==null?void 0:l.nodes)!=null&&h.length)for(const S of n.data.nodes){const v=ue.get(S.type);typeof((c=v==null?void 0:v.methods)==null?void 0:c.updateNodeSetting)=="function"&&v.methods.updateNodeSetting(S)}return y.render(n.data),Se(()=>ao()),Se(()=>y.graphModel.$J.focusOnStartNode()),y}const J=new Map,Te=Lo(()=>J.forEach(a=>a.events.onNodeUpdated()),50),ro=function(a){const l=J.get(a);l&&(l.events.onNodeUpdated(),$e())};function io(a){a.on("graph:rendered",({graphModel:c})=>{x.value=c.flowId,fo(c),setTimeout(()=>gt(),150)}),a.on("edge:add",c=>{var y;if(!((y=c==null?void 0:c.data)!=null&&y.targetAnchorId))return;const{sourceNodeId:S,targetNodeId:v}=c.data;if(S===v){a.deleteEdge(c.data.id);return}const{id:P,type:$,sourceAnchorId:k,targetAnchorId:w}=c.data;($!==_e.type&&w.endsWith(fe.LOOP_END)||k!=null&&k.endsWith(fe.LOOP_START))&&a.graphModel.changeEdgeType(P,_e.type)});let l=!1;a.on("connection:not-allowed",()=>{l=!0}),a.on("anchor:dragend",c=>{if(c.edgeModel)return;if(l){l=!1;return}if(N.isSilentMode)return;const{e:y,nodeModel:S,data:v}=c;if(!y||!S)return;const P=a.getPointByClient(y.clientX,y.clientY);if(!P)return;const $=P.canvasOverlayPosition.x-v.x,k=P.canvasOverlayPosition.y-v.y;if(Math.sqrt($*$+k*k)<100)return;const w=P.canvasOverlayPosition.x<v.x,b={isDragend:!0,event:{target:{getBoundingClientRect:()=>({top:y.clientY,left:y.clientX,width:0,height:0,right:y.clientX,bottom:y.clientY,x:y.clientX,y:y.clientY,toJSON(){}})}},prevData:{node:S,anchor:v,targetPosition:P.canvasOverlayPosition,dragToLeft:w}};a.selectElementById(S.id),a.graphModel.$J.setAddNodeDrawerVisible(!0,b,S.id)}),a.on("node:click",c=>{Ce(c)});let h=null;a.on("node:dragstart",c=>{h=c.data}),a.on("node:drop",c=>{if(h==null)return;if(po(c.e,P=>(P==null?void 0:P.dataset)&&P.dataset.hasOwnProperty("isNodeAction"))!=null){c.e.preventDefault(),c.e.stopPropagation();return}const y=Math.abs(c.data.x-h.x),S=Math.abs(c.data.y-h.y);h=null;const v=1;if(y<=v&&S<=v){c.e.preventDefault(),c.e.stopPropagation(),a.graphModel.selectNodeById(c.data.id),Te(),Ce(c);return}a.graphModel.editConfigModel.isSilentMode&&(c.e.preventDefault(),c.e.stopPropagation())}),a.on("node:delete",c=>co(c)),a.on("node:properties-change",c=>{const y=J.get(c.id);if(!y)return;const S=y.node;ko[S.type]&&c.id===S.id&&y.events.onPropertiesChange(c)}),a.on("graph:updated",c=>so())}function so(a){Te(),$e()}const ve=he([]);let ft=0,xe=0;const gt=()=>$e({now:!0});function $e({now:a=!1}={}){if(xe&&clearTimeout(xe),a){xe=0,yt({now:!0});return}else xe=setTimeout(()=>{yt()},Dt)}function yt({now:a=!1}={}){var l;if(!f.value||!a&&Date.now()-ft<Dt)return;ft=Date.now();const h=f.value;ve.value=[];const c=h.graphModel.nodes;for(const y of c){const S=ue.get(y.type);if(typeof((l=S==null?void 0:S.methods)==null?void 0:l.checkNode)=="function"){const v=S.methods.checkNode(h,y,{checkInputParams:(...P)=>Nt(y,"input",...P),checkOutputParams:(...P)=>Nt(y,"output",...P),findNextIdsByAnchorId:ce});Array.isArray(v)&&v.length>0&&ve.value.push({node:y,nodeText:y.properties.text,problems:v,onClick:()=>{xt(),h.graphModel.selectNodeById(y.id),Ce({data:y,e:new Event("click")}),Me(y),h.focusOn({id:y.id})}})}}}function Nt(a,l,{required:h=!0,text:c="",requiredName:y=!0}){var S;const v=[],P=l==="input",$=c||(P?"输入参数":"输出参数"),k=(S=a==null?void 0:a.properties)==null?void 0:S[l+"Params"];if((!Array.isArray(k)||k.length===0)&&h)return v.push(`${$}不能为空`),v;for(let w=0;w<k.length;w++){const b=k[w];if(P&&a.type===m.START)continue;let C=y?!b.name:!1;if(!b.nodeId||!b.field||C)if(a.type===m.KNOWLEDGE){v.push(`${$}不能为空`);break}else v.push(`${$}的第${w+1}项配置不完整`)}return v}function ao(a){const l=E.value.querySelector("div.lf-graph svg.lf-canvas-overlay");l&&l.addEventListener("click",function(h){if(h.target===l){ho();return}})}function po(a,l){if(typeof(a==null?void 0:a.composedPath)=="function"&&(a=a.composedPath()),!Array.isArray(a))return null;for(let h=0;h<a.length;h++){const c=a[h];if(c.classList.contains("lf-canvas-overlay"))return null;if(l(c))return c}return null}function Ce(a){const l=J.get(a.data.id);l&&(vt(l),l.events.onNodeClick(a))}function lo(a){const l=I.payload;if(typeof(l==null?void 0:l.isShow)=="function")return l.isShow(a);const h=I.triggerNodeId;return h?!h.endsWith(Rt)&&!d.nodeGroupMap.get(h)?ee.isShow(a):Xo(a):ee.isShow(a)}function uo(a){var l,h;if(!f.value)return;const c=f.value.graphModel,y=(l=I.payload)==null?void 0:l.prevData;y&&(h=I.payload)!=null&&h.anchor&&(y.anchor=I.payload.anchor);const S={nodeType:a,prevData:y};c.$J.doAction("add-node",S);const v=J.get(I.triggerNodeId);v&&v.events.onAfterAddNode(a,S),c.$J.setAddNodeDrawerVisible(!1)}let Ie=null;function co(a){const{model:l}=a;J.delete(l.id),q(W.getOpen)&&Ie===l.id&&W.closeDrawer(),gt()}function vt(a){return me(this,null,function*(){var l;q(W.getOpen)&&Ie===a.node.id||(q(B.getOpen)&&B.closeDrawer(),Ie=a.node.id,W.closeDrawer(),ht.get((l=a.node)==null?void 0:l.type)!==lt&&(yield Se(),W.openDrawer(!0,{node:a.node})))})}function ho(){Ie=null,q(W.getOpen)&&W.closeDrawer()}function xt(){const a=f.value;if(!a)return;const l=a.graphModel.selectNodes;a.graphModel.clearSelectElements();for(const h of l)Me(h)}function mo(a){return new Promise(l=>{function h(){const c=J.get(a);c?l(c):setTimeout(h,50)}h()})}function fo(a){a.$J=ye(ne({},Gr(f,a)),{$groupUtils:Vt(f,a),on(...l){},register(l,h){J.set(l.id,{node:l,events:h})},doAction(l,h){if(!f.value)return;const c=f.value;if(l==="copy"){xt();const y=d.nodeGroupMap.get(h.node.id),S=c.cloneNode(h.node.id);if(Se(()=>me(null,null,function*(){if(q(W.getOpen)){const v=yield mo(S.id);vt(v)}Te()})),y){const v=c.graphModel.getNodeModelById(y);v&&v.addChild(S.id)}}else if(l==="delete")It(h.node);else if(l==="toggle-add-node-drawer"){const y=J.get(h.node.id);if(!y)return;c.selectElementById(h.node.id),y.events.toggleAddNodeDrawer(h,I)}else l==="add-node"&&St(h.nodeType,h.prevData,h.edgeType)},updateEditConfig(l){f.value&&(Object.assign(N,l),f.value.updateEditConfig(l))},setEdgeRunStatus(l,h){var c;if(!f.value||l.type===m.START)return;const y=a.getNodeIncomingEdge(l.id);if(!(!y||y.length===0))for(const S of y)if(S.setProperties({runStatus:h}),h&&h!=="waiting"){const v=p.getStep(S.sourceNodeId);if((v==null?void 0:v.status)==="success"){const P=v.node.type===m.SWITCH?Gt:v.node.type===m.CLASSIFIER?Bt:null;if(P){const $=(c=v.outputParams)==null?void 0:c[`${v.node.id}.index`];if(typeof $=="number"&&P.getAnchorIdByChooseIndex(v.node.id,$)!==S.sourceAnchorId)continue}S.openEdgeAnimation()}}else S.closeEdgeAnimation()},getAddNodeDrawerVisible(){return I.visible},setAddNodeDrawerVisible(l,h,c){I.visible&&!l&&c&&I.triggerNodeId!==c||(I.visible=l,I.payload=h||{},I.triggerNodeId=c||"")}})}function It(a){return me(this,null,function*(){Oe(a)})}function go(a){if(!f.value)return;const l=f.value.getNodeModelById(a);l&&Oe(l)}function Oe(a){var l;if(!f.value||!(a!=null&&a.id))return;const h=(l=a.nodeConfig)!=null?l:ue.get(a.type);if(!h)return;const{hooks:c}=h;if(typeof(c==null?void 0:c.beforeRemoveNode)=="function"&&!c.beforeRemoveNode(a,f.value))return;const y=a.getData();f.value.deleteNode(a.id)&&typeof(c==null?void 0:c.afterRemoveNode)=="function"&&c.afterRemoveNode(y,f.value)}function Me(a){a!=null&&a.id&&ro(a.id)}function yo(a,l){if(!f.value)return;const h=f.value.getNodeModelById(a);h&&h.setProperties({text:l})}function Et(a,l,h,c){return{x:a,y:l,width:h,height:c,left:a-h/2,right:a+h/2,top:l-c/2,bottom:l+c/2}}function St(a,l,h){return me(this,null,function*(){var c,y,S,v;if(!f.value)return;const P=f.value,$=ue.get(a);if(!$)return;const k={};let w=null;if(l!=null&&l.node){const T=l.node,F=l.anchor;if(l.targetPosition){const V=((y=(c=$.params)==null?void 0:c.width)!=null?y:332)/2;k.x=l.targetPosition.x+V,k.y=l.targetPosition.y}else{const V=(S=F==null?void 0:F.x)!=null?S:T.x,Q=(v=F==null?void 0:F.y)!=null?v:T.y,U=F?120:T.width;k.x=V+U+200,k.y=Q}if(w={type:h||mt.type,sourceNodeId:T.id,targetNodeId:""},F!=null&&F.id&&(w.sourceAnchorId=F.id),T.type===m.LOOP_BODY)k.groupId=T.id;else{const V=d.nodeGroupMap.get(T.id);V&&(k.groupId=V)}}else{const T=P.getTransform(),F=P.container,V=F.clientWidth,Q=F.clientHeight,U=V/2,Z=Q/2,j=(U-T.TRANSLATE_X)/T.SCALE_X,pe=(Z-T.TRANSLATE_Y)/T.SCALE_Y;k.x=j,k.y=pe}const{methods:b,hooks:C}=$,H=b.createNode(k);let O={up:{y:0},down:{y:0}};const Y=(T,F)=>{if(F>999)return;const V=[...P.graphModel.nodes],Q=20,U=F%2===0?"up":"down";let Z=O[U].y;if(Z=Z||T.y,V.length>0){let j=Q*1.5;$.type===m.CLASSIFIER?j=U==="up"?j+80:j:$.type===m.SWITCH?j=U==="up"?j+60:j:$.type===m.LLM&&(j=U==="up"?j+40:j);const pe=Et(T.x,Z,$.params.width,$.params.height),Io=V.map(K=>Et(K.x,K.y,K.width,K.height));let le=null;for(const K of Io){const Eo=Math.abs(K.left-pe.left),So=Math.abs(K.right-pe.right);if(!(Eo<Q||So<Q))continue;const Po=Math.abs(K.top-pe.top),wo=Math.abs(K.bottom-pe.bottom);(Po<Q||wo<Q)&&(le=K)}le?(U==="up"?Z=le.y-le.height-j:Z=le.y+le.height+j,O[U].y=Z,Y(T,F+1)):T.y=Z}};if(Y(H,0),typeof(C==null?void 0:C.beforeAddNode)=="function"&&(yield C.beforeAddNode({node:H,nodeArgs:k,edgeArgs:w},P))===!1)return;const X=P.addNode(H);if(k.groupId){const T=P.graphModel.getNodeModelById(k.groupId);T&&T.addChild(X.id)}if(w){const T=ye(ne({},w),{targetNodeId:X.id});l!=null&&l.targetPosition&&(T.targetAnchorId=`${X.id}_input`),P.addEdge(T)}return typeof(C==null?void 0:C.afterAddNode)=="function"&&(yield C.afterAddNode(X,P)),X})}function Pt(){if(f.value)return f.value.getGraphData()}const de=new Map;function No(){var a;if(!f.value)return"";let{nodes:l,edges:h}=f.value.getGraphRawData();const c=new Map;h=h.filter(P=>{var $,k,w;let b=!(($=P.targetAnchorId)!=null&&$.endsWith(fe.LOOP_END));return b&&(b=!((k=P.sourceAnchorId)!=null&&k.endsWith(fe.LOOP_START))),b&&(w=P.sourceAnchorId)!=null&&w.endsWith(Re.LINK_BODY)&&(b=!1,c.set(P.sourceNodeId,P.targetNodeId)),b});let y,S=new Set;do{y=!1;for(const P of l){if(P.type!==m.LOOP)continue;const $=P.id;if(S.has($))continue;S.add($);const k=c.get($);if(!k)continue;const w=l.find(O=>O.id===k);if(!w)continue;const b=((a=w.properties)!=null?a:{}).children;if(!Array.isArray(b)||b.length===0)continue;y=!0;let C=[];if([C,l]=kt(l,O=>b.includes(O.id)),C.length===0)continue;let H=[];[H,h]=kt(h,O=>b.includes(O.sourceNodeId)||b.includes(O.targetNodeId)),P.flowData={nodes:C,edges:H},l=l.filter(O=>O.id!==k)}}while(y);const v={nodes:l,edges:h};try{return _r(v,de)}catch(P){}return""}function vo(){var a,l;const h=Pt();if(!h)throw new Error("尚未初始化");const{nodes:c,edges:y}=h;if(c.length===0)throw new Error("请添加节点");de.clear();const S=[m.END,m.SWITCH,m.CLASSIFIER,m.VAR_EXTRACT],v=new Map;for(const w of c)if(S.includes(w.type)){let b=v.get(w.type);Array.isArray(b)||(b=[]),b.push(w),v.set(w.type,b)}if(!v.has(m.END))throw new Error("请添加结束节点");const P=v.get(m.SWITCH);if(Array.isArray(P)&&P.length>0)for(const w of P){const{text:b,options:C}=w.properties;if(!Array.isArray(C==null?void 0:C.if)||C.if.length===0)break;const H=ut(w);for(let O=0;O<H.length;O++){const Y=H[O],X=Ae(w.id,Y.type,O+1),T=ce(X,y);if(T.length===0)break;Y.type==="ELSE"?C.else.next=T[0]:C.if[O].next=T[0],de.set(X,T)}}const $=v.get(m.CLASSIFIER);if(Array.isArray($)&&$.length>0)for(const w of $){const{text:b,options:C}=w.properties;if(!Array.isArray(C==null?void 0:C.categories)||C.categories.length===0)break;const H=ct(w);for(let O=0;O<H.length;O++){const Y=H[O],X=ke(w.id,Y.type,O+1);let T=ce(X,y);if(T.length===0)break;Y.type==="ELSE"?C.else.next=T[0]:C.categories[O].next=T[0],de.set(X,T)}}const k=v.get(m.VAR_EXTRACT);if(Array.isArray(k)&&k.length>0)for(const w of k){const b=w.properties.options||(w.properties.options={}),C=se(w.id,"success"),H=se(w.id,"fail"),O=ce(C,y),Y=ce(H,y);O.length>0&&(b.success=(a=b.success)!=null?a:{},b.success.next=O[0],de.set(C,O)),Y.length>0&&(b.fail=(l=b.fail)!=null?l:{},b.fail.next=Y[0],de.set(H,Y))}return h}function ce(a,l){const h=l.filter(c=>c.sourceAnchorId===a);return!h||h.length===0?[]:h.map(c=>c.targetNodeId)}function xo(a){wt(l=>{l.graphModel.$J.updateEditConfig({isSilentMode:a})})}function wt(a){return me(this,null,function*(){f.value&&(yield a(f.value))})}function At(a){var l;if(a.key==="s"&&a.ctrlKey)return s("save"),Ee(a);const h=a.target,c=(l=h==null?void 0:h.tagName)==null?void 0:l.toLowerCase(),y=c==="input"||c==="textarea"||(h==null?void 0:h.contentEditable)==="true";wt(S=>{if(!y){if(a.key==="z"&&a.ctrlKey)return S.undo(),Ee(a);if(a.key==="y"&&a.ctrlKey)return S.redo(),Ee(a);if(a.key==="Delete"){const v=S.graphModel.selectNodes;return v.length>0&&It(v[0]),Ee(a)}}})}function Ee(a){a.preventDefault(),a.stopPropagation()}return Er(()=>{f.value&&f.value.destroy(),window.removeEventListener("keydown",At)}),e({getLogicFlow:()=>f.value,doDebugRun:ae,updateText:yo,addNode:St,deleteNode:Oe,deleteNodeById:go,getGraphData:Pt,validateData:vo,getLiteFlowData:No,nodeChecklist:ve,setSilentMode:xo,checkProblemCount:te,closeSettingDrawer:()=>W.closeDrawer()}),(a,l)=>(Tt(),Ir(Tr,null,[$t("div",{ref_key:"containerRef",ref:g,class:wr([q(u)])},[$t("div",{ref_key:"renderRef",ref:E},null,512),Pe(q(i),{"flow-id":x.value},null,8,["flow-id"])],2),Pe(_o,Ct(Ar(I)),null,16),Pe(Go,{onRegister:q(G)},null,8,["onRegister"]),Pe(Bo,{isSilentMode:N.isSilentMode,onRegister:q(_),onUpdate:Me},null,8,["isSilentMode","onRegister"]),q(oe).componentProps.visible?(Tt(),Sr(br(q(oe).componentIs),Ct(kr({key:0},q(oe).superControlProps)),null,16)):Pr("",!0)],64))}}),za=Object.freeze(Object.defineProperty({__proto__:null,default:ls},Symbol.toStringTag,{value:"Module"}));export{za as W,Vr as X,ls as e};