1import{r as a,j as e,h as W,Q as z,y as U,f as V,p as O,O as de,L as ue,a5 as me,s as E,a1 as fe}from"../index.js";import{B as H,a as o,P as xe,b as pe}from"./index-db2b89a3.js";import{A as I}from"./agentFlows-05257314.js";import{I as he}from"./CaretLeft-399c9685.js";import{L as ge}from"./anything-llm-infinity-65574452.js";import"./communityHub-20506f1e.js";import"./Browser-5909f9d2.js";function be(d){var m,g;const c=d[d.length-2];return c?((m=c==null?void 0:c.config)==null?void 0:m.directOutput)===!1||((g=c==null?void 0:c.config)==null?void 0:g.directOutput)===void 0:!0}function we({blocks:d,showBlockMenu:c,setShowBlockMenu:m,addBlock:g}){const h=a.useRef(null);return a.useEffect(()=>{function u(f){h.current&&!h.current.contains(f.target)&&m(!1)}return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u)}},[m]),be(d)===!1?null:e.jsxs("div",{className:"relative mt-4 w-[280px] mx-auto pb-[50%]",ref:h,children:[e.jsxs("button",{onClick:()=>m(!c),className:"transition-all duration-300 w-full p-2.5 bg-theme-action-menu-bg hover:bg-theme-action-menu-item-hover border border-white/10 rounded-lg text-white flex items-center justify-center gap-2 text-sm font-medium",children:[e.jsx(W,{className:"w-4 h-4"}),"Add Block",e.jsx(z,{className:`w-3.5 h-3.5 transition-transform duration-300 ${c?"rotate-180":""}`})]}),c&&e.jsx("div",{className:"absolute left-0 right-0 mt-2 bg-theme-action-menu-bg border border-white/10 rounded-lg shadow-lg overflow-hidden z-10 animate-fadeUpIn",children:Object.entries(H).map(([u,f])=>u!==o.START&&u!==o.FINISH&&u!==o.FLOW_INFO&&e.jsxs("button",{onClick:()=>{g(u),m(!1)},className:"w-full p-2.5 flex items-center gap-3 hover:bg-theme-action-menu-item-hover text-white transition-colors duration-300 group",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-white/10 flex items-center justify-center",children:e.jsx("div",{className:"w-fit h-fit text-white",children:f.icon})}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:f.label}),e.jsx("div",{className:"text-xs text-white/60",children:f.description})]})]},u))})]})}function ve({agentName:d,availableFlows:c=[],onNewFlow:m,onSaveFlow:g,onPublishFlow:h}){const{flowId:u=null}=U(),[f,N]=a.useState(!1),b=V(),j=a.useRef(null),v=c.filter(i=>i.uuid!==u).length>0;return a.useEffect(()=>{function i(x){j.current&&!j.current.contains(x.target)&&N(!1)}return document.addEventListener("mousedown",i),()=>{document.removeEventListener("mousedown",i)}},[]),e.jsx("div",{className:"absolute top-[calc(40px+16px)] left-4 right-4",children:e.jsxs("div",{className:"flex justify-between items-start max-w-[1700px] mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx("button",{onClick:()=>b(O.settings.agentSkills()),className:"w-8 h-8 flex items-center justify-center rounded-full bg-theme-settings-input-bg border border-white/10 hover:bg-theme-action-menu-bg transition-colors duration-300",children:e.jsx(he,{weight:"bold",className:"w-5 h-5 text-theme-text-primary"})}),e.jsxs("div",{className:"flex items-center bg-theme-settings-input-bg rounded-md border border-white/10 pointer-events-auto",ref:j,children:[e.jsxs("button",{onClick:()=>b(O.settings.agentSkills()),className:"!border-t-transparent !border-l-transparent !border-b-transparent flex items-center gap-x-2 px-4 py-2 border-r border-white/10 hover:bg-theme-action-menu-bg transition-colors duration-300",children:[e.jsx("img",{src:ge,alt:"logo",className:"w-[20px] light:invert"}),e.jsx("span",{className:"text-theme-text-primary text-sm uppercase tracking-widest",children:"Builder"})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{disabled:!v,className:"border-none flex items-center justify-between gap-x-1 text-theme-text-primary text-sm px-4 py-2 enabled:hover:bg-theme-action-menu-bg transition-colors duration-300 min-w-[200px] max-w-[300px]",onClick:()=>{if(!d&&!v){const i=document.getElementById("agent-flow-name-input");i&&i.focus();return}N(!f)},children:[e.jsx("span",{className:`text-sm font-medium truncate ${d?"text-theme-text-primary ":"text-theme-text-secondary"}
1`,children:d||"Untitled Flow"}),v&&e.jsxs("div",{className:"flex flex-col ml-2 shrink-0",children:[e.jsx(de,{size:10}),e.jsx(z,{size:10})]})]}),f&&e.jsx("div",{className:"absolute top-full left-0 mt-1 w-full min-w-[200px] max-w-[350px] bg-theme-settings-input-bg border border-white/10 rounded-md shadow-lg z-50 animate-fadeUpIn",children:c.filter(i=>i.uuid!==u).map(i=>e.jsx("button",{onClick:()=>{b(O.agents.editAgent(i.uuid)),N(!1)},className:"border-none w-full text-left px-2 py-1 text-sm text-theme-text-primary hover:bg-theme-action-menu-bg transition-colors duration-300",children:e.jsx("span",{className:"block truncate",children:(i==null?void 0:i.name)||"Untitled Flow"})},(i==null?void 0:i.uuid)||Math.random()))})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-y-1 items-end",children:[e.jsxs("div",{className:"flex items-center gap-x-[15px]",children:[e.jsxs("button",{onClick:m,className:"flex items-center gap-x-2 text-theme-text-primary text-sm font-medium px-3 py-2 rounded-lg border border-white bg-theme-settings-input-bg hover:bg-theme-action-menu-bg transition-colors duration-300",children:[e.jsx(W,{className:"w-4 h-4"}),"New Flow"]}),e.jsx("button",{onClick:h,className:"px-3 py-2 rounded-lg text-sm font-medium flex items-center justify-center gap-2 border border-white/10 bg-theme-bg-primary text-theme-text-primary hover:bg-theme-action-menu-bg transition-all duration-300",children:"Publish"}),e.jsx("button",{onClick:g,className:"border-none bg-primary-button hover:opacity-80 text-black light:text-white px-3 py-2 rounded-lg text-sm font-medium transition-all duration-300 flex items-center justify-center gap-2",children:"Save"})]}),e.jsx(ue,{to:"https://docs.anythingllm.com/agent-flows/overview",className:"text-theme-text-secondary text-sm hover:underline hover:text-cta-button flex items-center gap-x-1 w-fit float-right",children:"view documentation â"})]})]})})}const B=[{id:"flow_info",type:o.FLOW_INFO,config:{name:"",description:""},isExpanded:!0},{id:"start",type:o.START,config:{variables:[{name:"",value:""}]},isExpanded:!0},{id:"finish",type:o.FINISH,config:{},isExpanded:!1}];function Le(){var k,P;
1const{flowId:d}=U(),{theme:c}=me(),m=V(),[g,h]=a.useState(""),[u,f]=a.useState(""),[N,b]=a.useState(null),[j,v]=a.useState(!0),[i,x]=a.useState(B),[$,D]=a.useState("start"),[M,L]=a.useState(!1),[ye,K]=a.useState(!1),[q,Q]=a.useState([]);a.useState(null);const A=a.useRef(null),C=a.useRef(null),[Y,_]=a.useState(!1);a.useEffect(()=>{T()},[]),a.useEffect(()=>{d&&G(d)},[d]),a.useEffect(()=>{var s;const t=i.find(n=>n.type===o.FLOW_INFO);h(((s=t==null?void 0:t.config)==null?void 0:s.name)||"")},[i]);const T=async()=>{try{const{success:t,error:s,flows:n}=await I.listFlows();if(!t)throw new Error(s);Q(n)}catch(t){console.error(t),E("Failed to load available flows","error",{clear:!0})}},G=async t=>{var s;try{const{success:n,error:r,flow:p}=await I.getFlow(t);if(!n)throw new Error(r);const w=[{id:"flow_info",type:o.FLOW_INFO,config:{name:p.config.name,description:p.config.description},isExpanded:!0},...p.config.steps.map((F,S)=>({id:S===0?"start":`block_${S}`,type:F.type,config:F.config,isExpanded:!0}))];((s=w[w.length-1])==null?void 0:s.type)!==o.FINISH&&w.push({id:"finish",type:o.FINISH,config:{},isExpanded:!1}),h(p.config.name),f(p.config.description),v(p.config.active??!0),b(p.uuid),x(w),K(!1)}catch(n){console.error(n),E("Failed to load flow","error",{clear:!0})}},J=t=>{const s={id:`block_${i.length}`,type:t,config:{...H[t].defaultConfig},isExpanded:!0},n=[...i];n.splice(n.length-1,0,s),x(n),L(!1)},R=(t,s)=>{x(i.map(n=>n.id===t?{...n,config:{...n.config,...s}}:n))},X=t=>{t!=="start"&&(x(i.filter(s=>s.id!==t)),$===t&&D("start"))},Z=async()=>{var p,w,F,S;const t=i.find(l=>l.type===o.FLOW_INFO),s=(p=t==null?void 0:t.config)==null?void 0:p.name,n=(w=t==null?void 0:t.config)==null?void 0:w.description;if(!(s!=null&&s.trim())||!(n!=null&&n.trim())){t.isExpanded||(x(i.map(l=>l.type===o.FLOW_INFO?{...l,isExpanded:!0}:l)),await new Promise(l=>setTimeout(l,100))),s!=null&&s.trim()?n!=null&&n.trim()||(S=C.current)==null||S.focus():(F=A.current)==null||F.focus(),E("Please provide both a name and description for your flow","error",{clear:!0});return}const r={name:s,description:n,active:j,steps:i.filter(l=>l.type!==o.FINISH&&l.type!==o.FLOW_INFO).map(l=>({type:l.type,config:l.config}))};try{const{success:l,error:le,flow:ce}=await I.saveFlow(s,r,N);if(!l)throw new Error(le);b(ce.uuid),E("Agent flow saved successfully!","success",{clear:!0}),await T()}catch(l){console.error("Save error details:",l),E(`Failed to save agent flow. ${l.message}`,"error",{clear:!0})}},ee=t=>{x(i.map(s=>s.id===t?{...s,isExpanded:!s.isExpanded}:s))},te=()=>{var s,n;const t=i.find(r=>r.type===o.START);return((n=(s=t==null?void 0:t.config)==null?void 0:s.variables)==null?void 0:n.filter(r=>r.name))||[]},se=(t,s,n="Select variable")=>e.jsxs("select",{value:t||"",onChange:r=>s(r.target.value),className:"w-full border-none bg-theme-settings-input-bg text-theme-text-primary text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none p-2.5",children:[e.jsx("option",{value:"",className:"bg-theme-bg-primary",children:n}),te().map(r=>e.jsx("option",{value:r.name,className:"bg-theme-bg-primary",children:r.name},r.name))]}),ne=t=>{i.forEach(s=>{if(s.type===o.START)return;let n=!1;const r={...s.config};r.responseVariable===t&&(r.responseVariable="",n=!0),r.resultVariable===t&&(r.resultVariable="",n=!0),n&&R(s.id,r)})},ie=()=>{d&&m(O.agents.builder()),h(""),f(""),b(null),v(!0),x(B)},re=(t,s)=>{const n=[...i],[r]=n.splice(t,1);n.splice(s,0,r),x(n)},ae=()=>{_(!0)},y=i.find(t=>t.type===o.FLOW_INFO),oe={name:((k=y==null?void 0:y.config)==null?void 0:k.name)||"",description:((P=y==null?void 0:y.config)==null?void 0:P.description)||"",steps:i.filter(t=>t.type!==o.FINISH&&t.type!==o.FLOW_INFO).map(t=>({type:t.type,config:t.config}))};return e.jsxs("div",{style:{backgroundImage:c==="light"?"radial-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 0)":"radial-gradient(rgba(255, 255, 255, 0.1) 1px, transparent 0)",backgroundSize:"15px 15px",backgroundPosition:"-7.5px -7.5px"},className:"w-full h-screen flex bg-theme-bg-primary",children:[e.jsx(xe,{show:Y,onClose:()=>_(!1),entityType:"agent-flow",entity:oe}),e.jsxs("div",{className:"w-full flex flex-col",children:[e.jsx(ve,{agentName:g,availableFlows:q,onNewFlow:ie,onSaveFlow:Z,onPublishFlow:ae}),e.jsx("div",{className:"flex-1 p-6 overflow-y-auto",children:e.jsxs("div",{className:"max-w-xl mx-auto mt-14",children:[e.jsx(pe,{blocks:i,updateBlockConfig:R,removeBlock:X,toggleBlockExpansion:ee,renderVariableSelect:se,onDeleteVariable:ne,moveBlock:re,refs:{nameRef:A,descriptionRef:C}}),e.jsx(we,{blocks:i,showBlockMenu:M,setShowBlockMenu:L,addBlock:J})]})})]}),e.jsx(fe,{id:"content-summarization-tooltip",place:"top",delayShow:300,className:"tooltip !text-xs z-99",children:e.jsxs("p",{className:"text-sm",children:["When enabled, long webpage content will be automatically summarized to reduce token usage.",e.jsx("br",{}),e.jsx("br",{}),"Note: This may affect data quality and remove specific details from the original content."]})})]})}export{Le as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.