import{a$ as oe,r as a,be as te,l as Ke,am as xt,an as mt,e as t,N as ve,Q as he,cL as xe,aH as ce,bp as Te,a7 as K,dl as Me,a4 as Ae,aA as De,bU as Se,a0 as se,es as Qe,et as Ze,ei as Pe,B as P,L as pe,T as ge,e0 as W,M as Re,aR as le,e1 as ae,eq as et,a1 as qe,P as N,w as tt,G as ot,e6 as ft,d1 as yt,y as bt,H as Ye,D as vt,g as wt,S as ke,$ as Ce,b0 as jt,ac as kt}from"./index-_6SmYgWK.js";import{N as rt,I as Ct}from"./NodeInfoDialog-BSQc04od.js";import{r as nt,e as Ne,o as It,t as Ee,h as st,j as Q,s as St,d as Nt,v as Et,k as Tt,w as Mt,x as Ue,i as $e,H as be,g as At,q as Dt,N as Pt}from"./DocStoreInputHandler-CaPW_OoW.js";import{B as Rt}from"./style-Djw-NCXs.js";/**
 * @license @tabler/icons-react v3.31.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var $t=oe("outline","brand-google","IconBrandGoogle",[["path",{d:"M20.945 11a9 9 0 1 1 -3.284 -5.997l-2.655 2.392a5.5 5.5 0 1 0 2.119 6.605h-4.125v-3h7.945z",key:"svg-0"}]]);/**
 * @license @tabler/icons-react v3.31.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var zt=oe("outline","browser-check","IconBrowserCheck",[["path",{d:"M4 4m0 1a1 1 0 0 1 1 -1h14a1 1 0 0 1 1 1v14a1 1 0 0 1 -1 1h-14a1 1 0 0 1 -1 -1z",key:"svg-0"}],["path",{d:"M4 8h16",key:"svg-1"}],["path",{d:"M8 4v4",key:"svg-2"}],["path",{d:"M9.5 14.5l1.5 1.5l3 -3",key:"svg-3"}]]);/**
 * @license @tabler/icons-react v3.31.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var it=oe("outline","exclamation-mark","IconExclamationMark",[["path",{d:"M12 19v.01",key:"svg-0"}],["path",{d:"M12 15v-10",key:"svg-1"}]]);/**
 * @license @tabler/icons-react v3.31.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Bt=oe("outline","photo","IconPhoto",[["path",{d:"M15 8h.01",key:"svg-0"}],["path",{d:"M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12z",key:"svg-1"}],["path",{d:"M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5",key:"svg-2"}],["path",{d:"M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3",key:"svg-3"}]]);/**
 * @license @tabler/icons-react v3.31.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Ie=oe("outline","world-www","IconWorldWww",[["path",{d:"M19.5 7a9 9 0 0 0 -7.5 -4a8.991 8.991 0 0 0 -7.484 4",key:"svg-0"}],["path",{d:"M11.5 3a16.989 16.989 0 0 0 -1.826 4",key:"svg-1"}],["path",{d:"M12.5 3a16.989 16.989 0 0 1 1.828 4",key:"svg-2"}],["path",{d:"M19.5 17a9 9 0 0 1 -7.5 4a8.991 8.991 0 0 1 -7.484 -4",key:"svg-3"}],["path",{d:"M11.5 21a16.989 16.989 0 0 1 -1.826 -4",key:"svg-4"}],["path",{d:"M12.5 21a16.989 16.989 0 0 0 1.828 -4",key:"svg-5"}],["path",{d:"M2 10l1 4l1.5 -4l1.5 4l1 -4",key:"svg-6"}],["path",{d:"M17 10l1 4l1.5 -4l1.5 4l1 -4",key:"svg-7"}],["path",{d:"M9.5 10l1 4l1.5 -4l1.5 4l1 -4",key:"svg-8"}]]);/**
 * @license @tabler/icons-react v3.31.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var Ot=oe("filled","alert-circle-filled","IconAlertCircleFilled",[["path",{d:"M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -19.995 .324l-.005 -.324l.004 -.28c.148 -5.393 4.566 -9.72 9.996 -9.72zm.01 13l-.127 .007a1 1 0 0 0 0 1.986l.117 .007l.127 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-.01 -8a1 1 0 0 0 -.993 .883l-.007 .117v4l.007 .117a1 1 0 0 0 1.986 0l.007 -.117v-4l-.007 -.117a1 1 0 0 0 -.993 -.883z",key:"svg-0"}]]);/**
 * @license @tabler/icons-react v3.31.0 - MIT
 *
 * This source code is licensed under the MIT license.
 * See the LICENSE file in the root directory of this source tree.
 */var lt=oe("filled","circle-chevron-right-filled","IconCircleChevronRightFilled",[["path",{d:"M12 2c5.523 0 10 4.477 10 10a10 10 0 0 1 -20 0c0 -5.523 4.477 -10 10 -10m-.293 6.293a1 1 0 0 0 -1.414 0l-.083 .094a1 1 0 0 0 .083 1.32l2.292 2.293l-2.292 2.293a1 1 0 0 0 1.414 1.414l3 -3a1 1 0 0 0 0 -1.414z",key:"svg-0"}]]);const Ht=e=>{var o;return(o=e.domNode)==null?void 0:o.querySelector(".react-flow__renderer")};function _t({children:e}){const o=Ne(Ht);return o?Ke.createPortal(e,o):null}const Lt=(e,o)=>{var l,c,u,s,x,r;return((l=e==null?void 0:e.positionAbsolute)==null?void 0:l.x)===((c=o==null?void 0:o.positionAbsolute)==null?void 0:c.x)&&((u=e==null?void 0:e.positionAbsolute)==null?void 0:u.y)===((s=o==null?void 0:o.positionAbsolute)==null?void 0:s.y)&&(e==null?void 0:e.width)===(o==null?void 0:o.width)&&(e==null?void 0:e.height)===(o==null?void 0:o.height)&&(e==null?void 0:e.selected)===(o==null?void 0:o.selected)&&((x=e==null?void 0:e[Ee])==null?void 0:x.z)===((r=o==null?void 0:o[Ee])==null?void 0:r.z)},Ft=(e,o)=>e.length===o.length&&e.every((l,c)=>Lt(l,o[c])),Wt=e=>({transform:e.transform,nodeOrigin:e.nodeOrigin,selectedNodesCount:e.getNodes().filter(o=>o.selected).length});function Gt(e,o,l,c,u){let s=.5;u==="start"?s=0:u==="end"&&(s=1);let x=[(e.x+e.width*s)*o[2]+o[0],e.y*o[2]+o[1]-c],r=[-100*s,-100];switch(l){case Q.Right:x=[(e.x+e.width)*o[2]+o[0]+c,(e.y+e.height*s)*o[2]+o[1]],r=[0,-100*s];break;case Q.Bottom:x[1]=(e.y+e.height)*o[2]+o[1]+c,r[1]=0;break;case Q.Left:x=[e.x*o[2]+o[0]-c,(e.y+e.height*s)*o[2]+o[1]],r=[-100,-100*s];break}return`translate(${x[0]}px, ${x[1]}px) translate(${r[0]}%, ${r[1]}%)`}function we({nodeId:e,children:o,className:l,style:c,isVisible:u,position:s=Q.Top,offset:x=10,align:r="center",...p}){const f=nt(),E=a.useCallback(C=>(Array.isArray(e)?e:[e||f||""]).reduce((n,v)=>{const V=C.nodeInternals.get(v);return V&&n.push(V),n},[]),[e,f]),d=Ne(E,Ft),{transform:h,nodeOrigin:w,selectedNodesCount:j}=Ne(Wt,St);if(!(typeof u=="boolean"?u:d.length===1&&d[0].selected&&j===1)||!d.length)return null;const A=It(d,w),k=Math.max(...d.map(C=>{var y;return(((y=C[Ee])==null?void 0:y.z)||1)+1})),R={position:"absolute",transform:Gt(A,h,s,x,r),zIndex:k,...c};return te.createElement(_t,null,te.createElement("div",{style:R,className:st(["react-flow__node-toolbar",l]),...p},o))}var ie;(function(e){e.Line="line",e.Handle="handle"})(ie||(ie={}));function Vt({width:e,prevWidth:o,height:l,prevHeight:c,invertX:u,invertY:s}){const x=e-o,r=l-c,p=[x>0?1:x<0?-1:0,r>0?1:r<0?-1:0];return x&&u&&(p[0]=p[0]*-1),r&&s&&(p[1]=p[1]*-1),p}const at={width:0,height:0,x:0,y:0},Xt={...at,pointerX:0,pointerY:0,aspectRatio:1};function qt({nodeId:e,position:o,variant:l=ie.Handle,className:c,style:u={},children:s,color:x,minWidth:r=10,minHeight:p=10,maxWidth:f=Number.MAX_VALUE,maxHeight:E=Number.MAX_VALUE,keepAspectRatio:d=!1,shouldResize:h,onResizeStart:w,onResize:j,onResizeEnd:S}){const A=nt(),k=typeof e=="string"?e:A,R=Nt(),C=a.useRef(null),y=a.useRef(Xt),n=a.useRef(at),v=Et(),V=l===ie.Line?"right":"bottom-right",$=o??V;a.useEffect(()=>{if(!C.current||!k)return;const q=Tt(C.current),g=$.includes("right")||$.includes("left"),i=$.includes("bottom")||$.includes("top"),b=$.includes("left"),m=$.includes("top"),T=Mt().on("start",M=>{const I=R.getState().nodeInternals.get(k),{xSnapped:Y,ySnapped:B}=v(M);n.current={width:(I==null?void 0:I.width)??0,height:(I==null?void 0:I.height)??0,x:(I==null?void 0:I.position.x)??0,y:(I==null?void 0:I.position.y)??0},y.current={...n.current,pointerX:Y,pointerY:B,aspectRatio:n.current.width/n.current.height},w==null||w(M,{...n.current})}).on("drag",M=>{const{nodeInternals:I,triggerNodeChanges:Y}=R.getState(),{xSnapped:B,ySnapped:re}=v(M),de=I.get(k);if(de){const Z=[],{pointerX:D,pointerY:U,width:ne,height:J,x:_,y:L,aspectRatio:G}=y.current,{x:Oe,y:He,width:_e,height:Le}=n.current,Fe=Math.floor(g?B-D:0),We=Math.floor(i?re-U:0);let O=Ue(ne+(b?-Fe:Fe),r,f),H=Ue(J+(m?-We:We),p,E);if(d){const ee=O/H,ue=g&&i,me=g&&!i,fe=i&&!g;O=ee<=G&&ue||fe?H*G:O,H=ee>G&&ue||me?O/G:H,O>=f?(O=f,H=f/G):O<=r&&(O=r,H=r/G),H>=E?(H=E,O=E*G):H<=p&&(H=p,O=p*G)}const Ge=O!==_e,Ve=H!==Le;if(b||m){const ee=b?_-(O-ne):_,ue=m?L-(H-J):L,me=ee!==Oe&&Ge,fe=ue!==He&&Ve;if(me||fe){const je={id:de.id,type:"position",position:{x:me?ee:Oe,y:fe?ue:He}};Z.push(je),n.current.x=je.position.x,n.current.y=je.position.y}}if(Ge||Ve){const ee={id:k,type:"dimensions",updateStyle:!0,resizing:!0,dimensions:{width:O,height:H}};Z.push(ee),n.current.width=O,n.current.height=H}if(Z.length===0)return;const gt=Vt({width:n.current.width,prevWidth:_e,height:n.current.height,prevHeight:Le,invertX:b,invertY:m}),Xe={...n.current,direction:gt};if((h==null?void 0:h(M,Xe))===!1)return;j==null||j(M,Xe),Y(Z)}}).on("end",M=>{const I={id:k,type:"dimensions",resizing:!1};S==null||S(M,{...n.current}),R.getState().triggerNodeChanges([I])});return q.call(T),()=>{q.on(".drag",null)}},[k,$,r,p,f,E,d,v,w,j,S]);const z=$.split("-"),F=l===ie.Line?"borderColor":"backgroundColor",X=x?{...u,[F]:x}:u;return te.createElement("div",{className:st(["react-flow__resize-control","nodrag",...z,l,c]),ref:C,style:X},s)}var Je=a.memo(qt);const Yt=["top-left","top-right","bottom-left","bottom-right"],Ut=["top","right","bottom","left"];function Jt({nodeId:e,isVisible:o=!0,handleClassName:l,handleStyle:c,lineClassName:u,lineStyle:s,color:x,minWidth:r=10,minHeight:p=10,maxWidth:f=Number.MAX_VALUE,maxHeight:E=Number.MAX_VALUE,keepAspectRatio:d=!1,shouldResize:h,onResizeStart:w,onResize:j,onResizeEnd:S}){return o?te.createElement(te.Fragment,null,Ut.map(A=>te.createElement(Je,{key:A,className:u,style:s,nodeId:e,position:A,variant:ie.Line,color:x,minWidth:r,minHeight:p,maxWidth:f,maxHeight:E,onResizeStart:w,keepAspectRatio:d,shouldResize:h,onResize:j,onResizeEnd:S})),Yt.map(A=>te.createElement(Je,{key:A,className:l,style:c,nodeId:e,position:A,color:x,minWidth:r,minHeight:p,maxWidth:f,maxHeight:E,onResizeStart:w,keepAspectRatio:d,shouldResize:h,onResize:j,onResizeEnd:S}))):null}var ze={},Kt=xt;Object.defineProperty(ze,"__esModule",{value:!0});var Be=ze.default=void 0,Qt=Kt(mt()),Zt=t,eo=(0,Qt.default)((0,Zt.jsx)("path",{d:"M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z"}),"Cancel");Be=ze.default=eo;const to=ce(Re)(({theme:e})=>({background:e.palette.card.main,color:e.darkTextPrimary,border:"solid 1px",width:"max-content",height:"auto",padding:"10px",boxShadow:"none"})),oo=ce(we)(({theme:e})=>({backgroundColor:e.palette.card.main,color:e.darkTextPrimary,padding:"5px",borderRadius:"10px",boxShadow:"0 2px 14px 0 rgb(32 40 45 / 8%)"})),ct=({data:e})=>{const o=ve(),l=he(i=>i.customization),c=he(i=>i.canvas),u=a.useRef(null),s=$e(),[x,r]=a.useState(0),[p,f]=a.useState(!1),[E,d]=a.useState(""),{deleteNode:h,duplicateNode:w}=a.useContext(xe),[j,S]=a.useState(!1),[A,k]=a.useState({}),C=e.color||"#666666",y=()=>e.selected?C:p?le(C,.8):le(C,.5),n=()=>e.outputAnchors??[],v=i=>{var M;const T=(((M=u.current)==null?void 0:M.clientHeight)||0)/(n().length+1)*(i+1);return T>0&&s(e.id),T},V=()=>{const i=n().length;return Math.max(60,i*20+40)},$=()=>l.isDarkMode?p?W(C,.7):W(C,.8):p?ae(C,.8):ae(C,.9),z=i=>{switch(i){case"ERROR":return o.palette.error.dark;case"INPROGRESS":return o.palette.warning.dark;case"STOPPED":case"TERMINATED":return o.palette.error.main;case"FINISHED":return o.palette.success.dark;default:return o.palette.primary.dark}},F=i=>{const b=et.find(m=>m.name===i.name);return b?t.jsx(b.icon,{size:24,color:"white"}):null},X=i=>{switch(i){case"web_search_preview":return t.jsx(Ie,{size:14,color:"white"});case"code_interpreter":return t.jsx(qe,{size:14,color:"white"});case"image_generation":return t.jsx(Bt,{size:14,color:"white"});default:return null}},q=i=>{switch(i){case"urlContext":return t.jsx(Ie,{size:14,color:"white"});case"googleSearch":return t.jsx($t,{size:14,color:"white"});case"codeExecution":return t.jsx(qe,{size:14,color:"white"});default:return null}},g=i=>{switch(i){case"web_search_20250305":return t.jsx(Ie,{size:14,color:"white"});case"web_fetch_20250910":return t.jsx(zt,{size:14,color:"white"});default:return null}};return a.useEffect(()=>{u.current&&setTimeout(()=>{var i,b;r(((i=u.current)==null?void 0:i.offsetTop)+((b=u.current)==null?void 0:b.clientHeight)/2),s(e.id)},10)},[e,u,s]),a.useEffect(()=>{const i=(T,M)=>`Node version ${T} outdated
Update to latest version ${M}`,b=T=>`Node outdated
Update to latest version ${T}`,m=c.componentNodes.find(T=>T.name===e.name);m&&(e.version?e.version&&m.version>e.version?d(i(e.version,m.version)):m.badge==="DEPRECATING"?d((m==null?void 0:m.deprecateMessage)??"This node will be deprecated in the next release. Change to a new node tagged with NEW"):m.warning?d(m.warning):d(""):d(b(m.version)))},[c.componentNodes,e.name,e.version]),t.jsxs("div",{ref:u,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[t.jsx(oo,{children:t.jsxs(Te,{sx:{gap:1},variant:"outlined","aria-label":"Basic button group",children:[e.name!=="startAgentflow"&&t.jsx(K,{size:"small",title:"Duplicate",onClick:()=>{w(e.id)},sx:{color:l.isDarkMode?"white":"inherit","&:hover":{color:o.palette.primary.main}},children:t.jsx(Me,{size:20})}),t.jsx(K,{size:"small",title:"Delete",onClick:()=>{h(e.id)},sx:{color:l.isDarkMode?"white":"inherit","&:hover":{color:o.palette.error.main}},children:t.jsx(Ae,{size:20})}),t.jsx(K,{size:"small",title:"Info",onClick:()=>{k({data:e}),S(!0)},sx:{color:l.isDarkMode?"white":"inherit","&:hover":{color:o.palette.info.main}},children:t.jsx(De,{size:20})})]})}),t.jsxs(to,{content:!1,sx:{borderColor:y(),borderWidth:"1px",boxShadow:e.selected?`0 0 0 1px ${y()} !important`:"none",minHeight:V(),height:"auto",backgroundColor:$(),display:"flex",alignItems:"center","&:hover":{boxShadow:e.selected?`0 0 0 1px ${y()} !important`:"none"}},border:!1,children:[e&&e.status&&t.jsx(Se,{title:e.status==="ERROR"?e.error||"Error":"",children:t.jsx(se,{variant:"rounded",sx:{...o.typography.smallAvatar,borderRadius:"50%",background:e.status==="STOPPED"||e.status==="TERMINATED"?"white":z(e.status),color:"white",ml:2,position:"absolute",top:-10,right:-10},children:e.status==="INPROGRESS"?t.jsx(Qe,{className:"spin-animation"}):e.status==="ERROR"?t.jsx(it,{}):e.status==="TERMINATED"?t.jsx(Be,{sx:{color:z(e.status)}}):e.status==="STOPPED"?t.jsx(Ze,{sx:{color:z(e.status)}}):t.jsx(Pe,{})})}),E&&t.jsx(Se,{placement:"right-start",title:t.jsx("span",{style:{whiteSpace:"pre-line"},children:E}),children:t.jsx(se,{variant:"rounded",sx:{...o.typography.smallAvatar,borderRadius:"50%",background:"white",position:"absolute",top:-10,left:-10},children:t.jsx(Ot,{color:"orange"})})}),t.jsxs(P,{sx:{width:"100%"},children:[!e.hideInput&&t.jsx(be,{type:"target",position:Q.Left,id:e.id,style:{width:5,height:20,backgroundColor:"transparent",border:"none",position:"absolute",left:-2},children:t.jsx("div",{style:{width:5,height:20,backgroundColor:C,position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)"}})}),t.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"},children:[t.jsx(P,{item:!0,style:{width:50},children:e.color&&!e.icon?t.jsx("div",{style:{...o.typography.commonAvatar,...o.typography.largeAvatar,borderRadius:"15px",backgroundColor:e.color,cursor:"grab",display:"flex",justifyContent:"center",alignItems:"center",background:e.color},children:F(e)}):t.jsx("div",{style:{...o.typography.commonAvatar,...o.typography.largeAvatar,borderRadius:"50%",backgroundColor:"white",cursor:"grab"},children:t.jsx("img",{style:{width:"100%",height:"100%",padding:5,objectFit:"contain"},src:`${pe}/api/v1/node-icon/${e.name}`,alt:e.name})})}),t.jsxs(P,{children:[t.jsx(ge,{sx:{fontSize:"0.85rem",fontWeight:500},children:e.label}),(()=>{var b,m,T,M,I,Y;return[{model:(b=e.inputs)==null?void 0:b.llmModel,config:(m=e.inputs)==null?void 0:m.llmModelConfig},{model:(T=e.inputs)==null?void 0:T.agentModel,config:(M=e.inputs)==null?void 0:M.agentModelConfig},{model:(I=e.inputs)==null?void 0:I.conditionAgentModel,config:(Y=e.inputs)==null?void 0:Y.conditionAgentModelConfig}].filter(B=>B.model&&B.config).map((B,re)=>t.jsx(P,{sx:{display:"flex",gap:1,mt:1},children:t.jsxs(P,{sx:{backgroundColor:l.isDarkMode?"rgba(255, 255, 255, 0.2)":"rgba(255, 255, 255, 0.9)",borderRadius:"16px",width:"max-content",height:24,pl:1,pr:1,display:"flex",justifyContent:"center",alignItems:"center"},children:[t.jsx("img",{style:{width:20,height:20,objectFit:"contain"},src:`${pe}/api/v1/node-icon/${B.model}`,alt:B.model}),t.jsx(ge,{sx:{fontSize:"0.7rem",ml:.5},children:B.config.modelName||B.config.model})]})},`model-${re}`))})(),(()=>{var b,m,T,M,I,Y,B,re,de,Z;return[{tools:(b=e.inputs)==null?void 0:b.llmTools,toolProperty:"llmSelectedTool"},{tools:(m=e.inputs)==null?void 0:m.agentTools,toolProperty:"agentSelectedTool"},{tools:((T=e.inputs)==null?void 0:T.selectedTool)??((M=e.inputs)==null?void 0:M.toolAgentflowSelectedTool)?[{selectedTool:((I=e.inputs)==null?void 0:I.selectedTool)??((Y=e.inputs)==null?void 0:Y.toolAgentflowSelectedTool)}]:[],toolProperty:["selectedTool","toolAgentflowSelectedTool"]},{tools:(B=e.inputs)==null?void 0:B.agentKnowledgeVSEmbeddings,toolProperty:["vectorStore","embeddingModel"]},{tools:(re=e.inputs)!=null&&re.agentToolsBuiltInOpenAI?(typeof e.inputs.agentToolsBuiltInOpenAI=="string"?JSON.parse(e.inputs.agentToolsBuiltInOpenAI):e.inputs.agentToolsBuiltInOpenAI).map(D=>({builtInTool:D})):[],toolProperty:"builtInTool",isBuiltInOpenAI:!0},{tools:(de=e.inputs)!=null&&de.agentToolsBuiltInGemini?(typeof e.inputs.agentToolsBuiltInGemini=="string"?JSON.parse(e.inputs.agentToolsBuiltInGemini):e.inputs.agentToolsBuiltInGemini).map(D=>({builtInTool:D})):[],toolProperty:"builtInTool",isBuiltInGemini:!0},{tools:(Z=e.inputs)!=null&&Z.agentToolsBuiltInAnthropic?(typeof e.inputs.agentToolsBuiltInAnthropic=="string"?JSON.parse(e.inputs.agentToolsBuiltInAnthropic):e.inputs.agentToolsBuiltInAnthropic).map(D=>({builtInTool:D})):[],toolProperty:"builtInTool",isBuiltInAnthropic:!0}].filter(D=>D.tools&&D.tools.length>0).map((D,U)=>t.jsx(P,{sx:{display:"flex",gap:1,mt:1},children:D.tools.flatMap((ne,J)=>{if(Array.isArray(D.toolProperty))return D.toolProperty.filter(_=>ne[_]).map((_,L)=>{const G=ne[_];return t.jsx(P,{component:"img",src:`${pe}/api/v1/node-icon/${G}`,alt:G,sx:{width:20,height:20,borderRadius:"50%",backgroundColor:"rgba(255, 255, 255, 0.2)",padding:.3}},`tool-${U}-${J}-${L}`)});{const _=ne[D.toolProperty];if(!_)return[];if(D.isBuiltInOpenAI){const L=X(_);return L?[t.jsx(P,{sx:{width:20,height:20,borderRadius:"50%",backgroundColor:l.isDarkMode?W(e.color,.5):W(e.color,.2),display:"flex",justifyContent:"center",alignItems:"center",padding:.2},children:L},`tool-${U}-${J}`)]:[]}if(D.isBuiltInGemini){const L=q(_);return L?[t.jsx(P,{sx:{width:20,height:20,borderRadius:"50%",backgroundColor:l.isDarkMode?W(e.color,.5):W(e.color,.2),display:"flex",justifyContent:"center",alignItems:"center",padding:.2},children:L},`tool-${U}-${J}`)]:[]}if(D.isBuiltInAnthropic){const L=g(_);return L?[t.jsx(P,{sx:{width:20,height:20,borderRadius:"50%",backgroundColor:l.isDarkMode?W(e.color,.5):W(e.color,.2),display:"flex",justifyContent:"center",alignItems:"center",padding:.2},children:L},`tool-${U}-${J}`)]:[]}return[t.jsx(P,{component:"img",src:`${pe}/api/v1/node-icon/${_}`,alt:_,sx:{width:20,height:20,borderRadius:"50%",backgroundColor:"rgba(255, 255, 255, 0.2)",padding:.3}},`tool-${U}-${J}`)]}})},`tools-${U}`))})()]})]}),n().map((i,b)=>t.jsxs(be,{type:"source",position:Q.Right,id:i.id,style:{height:20,width:20,top:v(b),backgroundColor:"transparent",border:"none",position:"absolute",right:-10,opacity:p?1:0,transition:"opacity 0.2s"},children:[t.jsx("div",{style:{position:"absolute",width:20,height:20,borderRadius:"50%",backgroundColor:o.palette.background.paper,pointerEvents:"none"}}),t.jsx(lt,{size:20,color:C,style:{pointerEvents:"none",position:"relative",zIndex:1}})]},i.id))]})]}),t.jsx(rt,{show:j,dialogProps:A,onCancel:()=>S(!1)})]})};ct.propTypes={data:N.object};const go=a.memo(ct),ro=ce(Re)(({theme:e})=>({background:e.palette.card.main,color:e.darkTextPrimary,border:"solid 1px",width:"max-content",height:"auto",padding:"10px",boxShadow:"none"})),no=ce(we)(({theme:e})=>({backgroundColor:e.palette.card.main,color:e.darkTextPrimary,padding:"5px",borderRadius:"10px",boxShadow:"0 2px 14px 0 rgb(32 40 45 / 8%)"})),dt=({data:e})=>{const o=ve(),l=he(g=>g.customization),c=a.useRef(null),u=a.useRef(null),s=$e(),[x,r]=a.useState(0),[p,f]=a.useState(!1),{deleteNode:E,duplicateNode:d,reactFlowInstance:h}=a.useContext(xe),[w,j]=a.useState(!1),[S,A]=a.useState({}),[k,R]=a.useState({width:"300px",height:"250px"});a.useEffect(()=>{if(h){const g=h.getNodes().find(i=>i.id===e.id);g&&g.width&&g.height&&R({width:`${g.width}px`,height:`${g.height}px`})}},[h,e.id]);const y=e.color||"#666666",n=()=>e.selected?y:p?le(y,.8):le(y,.5),v=()=>e.outputAnchors??[],V=g=>{var T;const m=(((T=c.current)==null?void 0:T.clientHeight)||0)/(v().length+1)*(g+1);return m>0&&s(e.id),m},$=()=>{const g=v().length;return Math.max(60,g*20+40)},z=()=>l.isDarkMode?p?W(y,.7):W(y,.8):p?ae(y,.8):ae(y,.9),F=g=>{switch(g){case"ERROR":return o.palette.error.dark;case"INPROGRESS":return o.palette.warning.dark;case"STOPPED":case"TERMINATED":return o.palette.error.main;case"FINISHED":return o.palette.success.dark;default:return o.palette.primary.dark}},X=g=>{const i=et.find(b=>b.name===g.name);return i?t.jsx(i.icon,{size:24,color:"white"}):null};a.useEffect(()=>{c.current&&setTimeout(()=>{var g,i;r(((g=c.current)==null?void 0:g.offsetTop)+((i=c.current)==null?void 0:i.clientHeight)/2),s(e.id)},10)},[e,c,s]);const q=a.useCallback((g,i)=>{c.current&&R({width:`${i.width}px`,height:`${i.height}px`})},[c,R]);return t.jsxs("div",{ref:c,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[t.jsx(we,{align:"start",isVisible:!0,children:t.jsxs(P,{style:{display:"flex",alignItems:"center",flexDirection:"row"},children:[e.color&&!e.icon?t.jsx("div",{style:{...o.typography.commonAvatar,...o.typography.largeAvatar,borderRadius:"15px",backgroundColor:e.color,cursor:"grab",display:"flex",justifyContent:"center",alignItems:"center",background:e.color},children:X(e)}):t.jsx("div",{style:{...o.typography.commonAvatar,...o.typography.largeAvatar,borderRadius:"50%",backgroundColor:"white",cursor:"grab"},children:t.jsx("img",{style:{width:"100%",height:"100%",padding:5,objectFit:"contain"},src:`${pe}/api/v1/node-icon/${e.name}`,alt:e.name})}),t.jsx(ge,{sx:{fontSize:"0.85rem",fontWeight:500,ml:1},children:e.label})]})}),t.jsx(no,{align:"end",children:t.jsxs(Te,{sx:{gap:1},variant:"outlined","aria-label":"Basic button group",children:[t.jsx(K,{size:"small",title:"Duplicate",onClick:()=>{d(e.id)},sx:{color:l.isDarkMode?"white":"inherit","&:hover":{color:o.palette.primary.main}},children:t.jsx(Me,{size:20})}),t.jsx(K,{size:"small",title:"Delete",onClick:()=>{E(e.id)},sx:{color:l.isDarkMode?"white":"inherit","&:hover":{color:o.palette.error.main}},children:t.jsx(Ae,{size:20})}),t.jsx(K,{size:"small",title:"Info",onClick:()=>{A({data:e}),j(!0)},sx:{color:l.isDarkMode?"white":"inherit","&:hover":{color:o.palette.info.main}},children:t.jsx(De,{size:20})})]})}),t.jsx(Jt,{minWidth:300,minHeight:Math.max($(),250),onResizeEnd:q}),t.jsxs(ro,{content:!1,sx:{borderColor:n(),borderWidth:"1px",boxShadow:e.selected?`0 0 0 1px ${n()} !important`:"none",minHeight:Math.max($(),250),minWidth:300,width:k.width,height:k.height,backgroundColor:z(),display:"flex","&:hover":{boxShadow:e.selected?`0 0 0 1px ${n()} !important`:"none"}},border:!1,children:[e&&e.status&&t.jsx(Se,{title:e.status==="ERROR"?e.error||"Error":"",children:t.jsx(se,{variant:"rounded",sx:{...o.typography.smallAvatar,borderRadius:"50%",background:e.status==="STOPPED"||e.status==="TERMINATED"?"white":F(e.status),color:"white",ml:2,position:"absolute",top:-10,right:-10},children:e.status==="INPROGRESS"?t.jsx(Qe,{className:"spin-animation"}):e.status==="ERROR"?t.jsx(it,{}):e.status==="TERMINATED"?t.jsx(Be,{sx:{color:F(e.status)}}):e.status==="STOPPED"?t.jsx(Ze,{sx:{color:F(e.status)}}):t.jsx(Pe,{})})}),t.jsxs(P,{sx:{width:"100%"},children:[!e.hideInput&&t.jsx(be,{type:"target",position:Q.Left,id:e.id,style:{width:5,height:20,backgroundColor:"transparent",border:"none",position:"absolute",left:-2},children:t.jsx("div",{style:{width:5,height:20,backgroundColor:y,position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)"}})}),t.jsx("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"},children:t.jsx(P,{sx:{height:`calc(${k.height} - 20px)`,width:`${k.width}`,overflow:"hidden",position:"relative",borderRadius:"10px"},children:t.jsx("div",{ref:u,style:{width:"100%",height:"100%",position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:o.palette.background.default},children:t.jsx(Rt,{color:"#aaa",gap:16})})})}),v().map((g,i)=>t.jsxs(be,{type:"source",position:Q.Right,id:g.id,style:{height:20,width:20,top:V(i),backgroundColor:"transparent",border:"none",position:"absolute",right:-10,opacity:p?1:0,transition:"opacity 0.2s"},children:[t.jsx("div",{style:{position:"absolute",width:20,height:20,borderRadius:"50%",backgroundColor:o.palette.background.paper,pointerEvents:"none"}}),t.jsx(lt,{size:20,color:y,style:{pointerEvents:"none",position:"relative",zIndex:1}})]},g.id))]})]}),t.jsx(rt,{show:w,dialogProps:S,onCancel:()=>j(!1)})]})};dt.propTypes={data:N.object};const xo=a.memo(dt);function ut({transform:e,isHumanInput:o,label:l,color:c}){return t.jsx("div",{style:{position:"absolute",background:"transparent",left:o?10:0,paddingTop:1,color:c,fontSize:"0.5rem",fontWeight:700,transform:e,zIndex:1e3},className:"nodrag nopan",children:l})}ut.propTypes={transform:N.string,isHumanInput:N.bool,label:N.string,color:N.string};const ye=40,pt=({id:e,sourceX:o,sourceY:l,targetX:c,targetY:u,sourcePosition:s,targetPosition:x,data:r,markerEnd:p,selected:f})=>{const[E,d]=a.useState(!1),{deleteEdge:h}=a.useContext(xe),w=tt(),j=(n,v)=>{n.stopPropagation(),h(v),w({type:ft})},S=o===c,A=l===u,[k,R,C]=At({sourceX:S?o+1e-4:o,sourceY:A?l+1e-4:l,sourcePosition:s,targetX:c,targetY:u,targetPosition:x}),y=`edge-gradient-${e}`;return t.jsxs(t.Fragment,{children:[t.jsx("defs",{children:t.jsxs("linearGradient",{id:y,children:[t.jsx("stop",{offset:"0%",stopColor:(r==null?void 0:r.sourceColor)||"#ae53ba"}),t.jsx("stop",{offset:"100%",stopColor:(r==null?void 0:r.targetColor)||"#2a8af6"})]})}),t.jsx("path",{id:`${e}-selector`,className:"agent-flow-edge-selector",style:{stroke:"transparent",strokeWidth:15,fill:"none",cursor:"pointer"},d:k,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1)}),t.jsx("path",{id:e,className:"agent-flow-edge",style:{strokeWidth:f?3:2,stroke:`url(#${y})`,filter:f?"drop-shadow(0 0 3px rgba(0,0,0,0.3))":"none",cursor:"pointer",opacity:f?1:.75,fill:"none"},d:k,markerEnd:p,onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1)}),(r==null?void 0:r.edgeLabel)&&t.jsx(Dt,{children:t.jsx(ut,{isHumanInput:r==null?void 0:r.isHumanInput,color:(r==null?void 0:r.sourceColor)||"#ae53ba",label:r.edgeLabel,transform:`translate(-50%, 0%) translate(${o}px,${l}px)`})}),E&&t.jsx("foreignObject",{width:ye,height:ye,x:R-ye/2,y:C-ye/2,className:"edgebutton-foreignobject",requiredExtensions:"http://www.w3.org/1999/xhtml",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:t.jsx("div",{style:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",pointerEvents:"all"},children:t.jsx("button",{className:"edgebutton",onClick:n=>j(n,e),style:{width:"12px",height:"12px",background:`linear-gradient(to right, ${(r==null?void 0:r.sourceColor)||"#ae53ba"}, ${(r==null?void 0:r.targetColor)||"#2a8af6"})`,border:"none",borderRadius:"50%",cursor:"pointer",fontSize:"10px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",boxShadow:"0 0 4px rgba(0,0,0,0.3)",transition:"all 0.2s ease-in-out",padding:"2px"},onMouseOver:n=>{n.currentTarget.style.transform="scale(1.2)",n.currentTarget.style.boxShadow="0 0 8px rgba(0,0,0,0.4)"},onFocus:n=>{n.currentTarget.style.transform="scale(1.2)",n.currentTarget.style.boxShadow="0 0 8px rgba(0,0,0,0.4)"},onMouseOut:n=>{n.currentTarget.style.transform="scale(1)",n.currentTarget.style.boxShadow="0 0 4px rgba(0,0,0,0.3)"},onBlur:n=>{n.currentTarget.style.transform="scale(1)",n.currentTarget.style.boxShadow="0 0 4px rgba(0,0,0,0.3)"},children:t.jsx(ot,{stroke:2,size:"12",color:"white"})})})})]})};pt.propTypes={id:N.string,sourceX:N.number,sourceY:N.number,targetX:N.number,targetY:N.number,sourcePosition:N.any,targetPosition:N.any,style:N.object,data:N.object,markerEnd:N.any,selected:N.bool};const mo=a.memo(pt),so=ce(Re)(({theme:e})=>({background:e.palette.card.main,color:e.darkTextPrimary,border:"solid 1px",width:"max-content",height:"auto",padding:"10px",boxShadow:"none"})),io=ce(we)(({theme:e})=>({backgroundColor:e.palette.card.main,color:e.darkTextPrimary,padding:"5px",borderRadius:"10px",boxShadow:"0 2px 14px 0 rgb(32 40 45 / 8%)"})),lo=({data:e})=>{const o=ve(),l=he(j=>j.customization),c=a.useRef(null),{reactFlowInstance:u,deleteNode:s,duplicateNode:x}=a.useContext(xe),[r]=e.inputParams,[p,f]=a.useState(!1),d=e.color||"#666666",h=()=>e.selected?d:p?le(d,.8):le(d,.5),w=()=>l.isDarkMode?p?W(d,.7):W(d,.8):p?ae(d,.8):ae(d,.9);return t.jsxs("div",{ref:c,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),children:[t.jsx(io,{children:t.jsxs(Te,{sx:{gap:1},variant:"outlined","aria-label":"Basic button group",children:[t.jsx(K,{size:"small",title:"Duplicate",onClick:()=>{x(e.id)},sx:{color:l.isDarkMode?"white":"inherit","&:hover":{color:o.palette.primary.main}},children:t.jsx(Me,{size:20})}),t.jsx(K,{size:"small",title:"Delete",onClick:()=>{s(e.id)},sx:{color:l.isDarkMode?"white":"inherit","&:hover":{color:o.palette.error.main}},children:t.jsx(Ae,{size:20})})]})}),t.jsx(so,{content:!1,sx:{borderColor:h(),borderWidth:"1px",boxShadow:e.selected?`0 0 0 1px ${h()} !important`:"none",minHeight:60,height:"auto",backgroundColor:w(),display:"flex",alignItems:"center","&:hover":{boxShadow:e.selected?`0 0 0 1px ${h()} !important`:"none"}},border:!1,children:t.jsx(P,{children:t.jsx(yt,{placeholder:r.placeholder,inputParam:r,onChange:j=>e.inputs[r.name]=j,value:e.inputs[r.name]??r.default??"",nodes:u?u.getNodes():[],edges:u?u.getEdges():[],nodeId:e.id},e.id)})})]})};lo.propTypes={data:N.object};const ht=({show:e,dialogProps:o,onCancel:l})=>{const c=document.getElementById("portal"),u=tt(),s=ve(),x=he(n=>n.customization),r=a.useRef(),{reactFlowInstance:p}=a.useContext(xe),f=$e(),[E,d]=a.useState([]),[h,w]=a.useState({}),[j,S]=a.useState(null),[A,k]=a.useState(""),R=()=>{p.setNodes(n=>n.map(v=>(v.id===h.id&&(v.data={...v.data,label:r.current.value},w(v.data)),v))),f(h.id)},C=({nodeId:n,inputParam:v,newValue:V})=>{p.setNodes($=>$.map(z=>{if(z.id===n){const F={...z.data.inputs,[v.name]:V},X=kt({...z.data,inputs:F});Object.keys(F).forEach(q=>{const g=X.find(i=>i.name===q);g&&g.display===!1&&delete F[q]}),z.data={...z.data,inputParams:X,inputs:F},d(X),w(z.data)}return z}))};a.useEffect(()=>(o.inputParams&&d(o.inputParams),o.data&&(w(o.data),o.data.label&&k(o.data.label)),()=>{d([]),w({})}),[o]),a.useEffect(()=>(u(e?{type:bt}:{type:Ye}),()=>u({type:Ye})),[e,u]);const y=e?t.jsx(vt,{onClose:l,open:e,fullWidth:!0,maxWidth:"sm","aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:t.jsxs(wt,{children:[h&&h.name&&t.jsx(P,{sx:{width:"100%"},children:j?t.jsxs(ke,{flexDirection:"row",sx:{width:"100%"},children:[t.jsx(jt,{autoFocus:!0,size:"small",sx:{width:"100%",ml:2},inputRef:r,defaultValue:A,onKeyDown:n=>{n.key==="Enter"?(h.label=r.current.value,k(r.current.value),R(),S(!1)):n.key==="Escape"&&S(!1)}}),t.jsx(Ce,{title:"Save Name",sx:{borderRadius:"50%"},children:t.jsx(se,{variant:"rounded",sx:{...s.typography.commonAvatar,...s.typography.mediumAvatar,transition:"all .2s ease-in-out",background:s.palette.success.light,color:s.palette.success.dark,ml:1,"&:hover":{background:s.palette.success.dark,color:s.palette.success.light}},color:"inherit",onClick:()=>{h.label=r.current.value,k(r.current.value),R(),S(!1)},children:t.jsx(Pe,{stroke:1.5,size:"1rem"})})}),t.jsx(Ce,{title:"Cancel",sx:{borderRadius:"50%"},children:t.jsx(se,{variant:"rounded",sx:{...s.typography.commonAvatar,...s.typography.mediumAvatar,transition:"all .2s ease-in-out",background:s.palette.error.light,color:s.palette.error.dark,ml:1,"&:hover":{background:s.palette.error.dark,color:s.palette.error.light}},color:"inherit",onClick:()=>S(!1),children:t.jsx(ot,{stroke:1.5,size:"1rem"})})})]}):t.jsxs(ke,{flexDirection:"row",sx:{display:"flex",alignItems:"center",mb:2},children:[t.jsx(ge,{sx:{ml:2,textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap"},variant:"h4",children:A}),(h==null?void 0:h.id)&&t.jsx(Ce,{title:"Edit Name",sx:{borderRadius:"50%"},children:t.jsx(se,{variant:"rounded",sx:{...s.typography.commonAvatar,...s.typography.mediumAvatar,transition:"all .2s ease-in-out",ml:1,background:s.palette.secondary.light,color:s.palette.secondary.dark,"&:hover":{background:s.palette.secondary.dark,color:s.palette.secondary.light}},color:"inherit",onClick:()=>S(!0),children:t.jsx(Ct,{stroke:1.5,size:"1rem"})})})]})}),(h==null?void 0:h.hint)&&t.jsxs(ke,{direction:"row",alignItems:"center",sx:{ml:2,backgroundColor:x.isDarkMode?"rgba(255, 255, 255, 0.05)":"rgba(0, 0, 0, 0.03)",borderRadius:"8px",mr:2,px:1.5,py:1,mt:1,mb:1,border:`1px solid ${x.isDarkMode?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.08)"}`},children:[t.jsx(De,{size:"1rem",stroke:1.5,color:s.palette.info.main,style:{marginRight:"6px"}}),t.jsx(ge,{variant:"caption",color:"text.secondary",sx:{fontStyle:"italic",lineHeight:1.2},children:h.hint})]}),E.filter(n=>n.display!==!1).map((n,v)=>t.jsx(Pt,{disabled:o.disabled,inputParam:n,data:h,isAdditionalParams:!0,onCustomDataChange:C},v))]})}):null;return Ke.createPortal(y,c)};ht.propTypes={show:N.bool,dialogProps:N.object,onCancel:N.func};const fo=a.memo(ht);export{mo as A,fo as E,xo as I,lo as S,go as a};
