1import{r as a,j as e,I as V,aj as $,l as z,b as U,p as O,aO as ce,ai as de,t as me,aP as ue,c as S,ac as fe}from"../index.js";import{B as H,a as o,A as pe,P as xe,b as he}from"./index-b77e11e8.js";import{A as I}from"./agentFlows-e4124dd3.js";import{L as ge}from"./anything-llm-infinity-65574452.js";import"./communityHub-aba61686.js";import"./Brain-24e386d5.js";import"./Browser-1820fad0.js";function be(d){var f,g;const c=d[d.length-2];return c?((f=c==null?void 0:c.config)==null?void 0:f.directOutput)===!1||((g=c==null?void 0:c.config)==null?void 0:g.directOutput)===void 0:!0}function we({blocks:d,showBlockMenu:c,setShowBlockMenu:f,addBlock:g}){const h=a.useRef(null);return a.useEffect(()=>{function m(p){h.current&&!h.current.contains(p.target)&&f(!1)}return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[f]),be(d)===!1?null:e.jsxs("div",{className:"relative mt-4 w-[280px] mx-auto pb-4",ref:h,children:[e.jsxs("button",{onClick:()=>f(!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(V,{className:"w-4 h-4"}),"Add Block",e.jsx($,{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(([m,p])=>m!==o.START&&m!==o.FINISH&&m!==o.FLOW_INFO&&e.jsxs("button",{onClick:()=>{g(m),f(!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:p.icon})}),e.jsxs("div",{className:"text-left flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:p.label}),e.jsx("div",{className:"text-xs text-white/60",children:p.description})]})]},m))})]})}function ve({agentName:d,availableFlows:c=[],onNewFlow:f,onSaveFlow:g,onPublishFlow:h}){const{flowId:m=null}=z(),[p,j]=a.useState(!1),b=U(),N=a.useRef(null),v=c.filter(i=>i.uuid!==m).length>0;return a.useEffect(()=>{function i(u){N.current&&!N.current.contains(u.target)&&j(!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(ce,{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:N,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}j(!p)},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($,{size:10})]})]}),p&&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!==m).map((i,u)=>e.jsx("button",{onClick:()=>{b(O.agents.editAgent(i.uuid)),j(!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)||`flow-${u}`))})]})]})]}),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:f,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(V,{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(me,{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 W=[{id:"flow_info",type:o.FLOW_INFO,config:{name:"",description:""},isExpanded:!0},{id:"start",type:o.START,config:{variables:[{name:"",value:"",type:"optional",description:""}]},isExpanded:!0},{id:"finish",type:o.FINISH,config:{},isExpanded:!1}];function Ie(){var k,B;const{flowId:d}=z(),{theme:c}=ue(),f=U(),[g,h]=a.useState(""),[m,p]=a.useState(""),[j,b]=a.useState(null),[N,v]=a.useState(!0),[i,u]=a.useState(W),[D,K]=a.useState("start"),[A,L]=a.useState(!1),[M,q]=a.useState([]),C=a.useRef(null),_=a.useRef(null),[Y,T]=a.useState(!1);a.useEffect(()=>{P()},[]),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 P=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),S("Failed to load available flows","error",{clear:!0})}},G=async t=>{var s;try{const{success:n,error:r,flow:x}=await I.getFlow(t);if(!n)throw new Error(r);const w=[{id:"flow_info",type:o.FLOW_INFO,config:{name:x.config.name,description:x.config.description},isExpanded:!0},...x.config.steps.map((F,E)=>({id:E===0?"start":`block_${E}`,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(x.config.name),p(x.config.description),v(x.config.active??!0),b(x.uuid),u(w)}catch(n){console.error(n),S("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),u(n),L(!1)},R=(t,s)=>{u(i.map(n=>n.id===t?{...n,config:{...n.config,...s}}:n))},Q=t=>{t!=="start"&&(u(i.filter(s=>s.id!==t)),D===t&&K("start"))},X=async()=>{var x,w,F,E;const t=i.find(l=>l.type===o.FLOW_INFO),s=(x=t==null?void 0:t.config)==null?void 0:x.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||(u(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()||(E=_.current)==null||E.focus():(F=C.current)==null||F.focus(),S("Please provide both a name and description for your flow","error",{clear:!0});return}const r={name:s,description:n,active:N,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:oe,flow:le}=await I.saveFlow(s,r,j);if(!l)throw new Error(oe);b(le.uuid),S("Agent flow saved successfully!","success",{clear:!0}),await P()}catch(l){console.error("Save error details:",l),S(`Failed to save agent flow. ${l.message}`,"error",{clear:!0})}},Z=t=>{u(i.map(s=>s.id===t?{...s,isExpanded:!s.isExpanded}:s))},ee=()=>{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))||[]},te=(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
1-primary",children:n}),ee().map(r=>e.jsx("option",{value:r.name,className:"bg-theme-bg-primary",children:r.name},r.name))]}),se=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)})},ne=()=>{d&&f(O.agents.builder()),h(""),p(""),b(null),v(!0),u(W)},ie=(t,s)=>{const n=[...i],[r]=n.splice(t,1);n.splice(s,0,r),u(n)},re=()=>{T(!0)},y=i.find(t=>t.type===o.FLOW_INFO),ae={name:((k=y==null?void 0:y.config)==null?void 0:k.name)||"",description:((B=y==null?void 0:y.config)==null?void 0:B.description)||"",steps:i.filter(t=>t.type!==o.FINISH&&t.type!==o.FLOW_INFO).map(t=>({type:t.type,config:t.config}))};return e.jsx(pe,{blocks:i,children: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:"relative w-screen h-screen flex flex-col bg-theme-bg-primary overflow-clip",children:[e.jsx(xe,{show:Y,onClose:()=>T(!1),entityType:"agent-flow",entity:ae}),e.jsx(ve,{agentName:g,availableFlows:M,onNewFlow:ne,onSaveFlow:X,onPublishFlow:re}),e.jsx("div",{className:"flex-1 min-h-0 p-6 overflow-y-auto",children:e.jsxs("div",{className:`max-w-xl mx-auto mt-14 ${A?"pb-52":""}`,children:[e.jsx(he,{blocks:i,updateBlockConfig:R,removeBlock:Q,toggleBlockExpansion:Z,renderVariableSelect:te,onDeleteVariable:se,moveBlock:ie,refs:{nameRef:C,descriptionRef:_}}),e.jsx(we,{blocks:i,showBlockMenu:A,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{Ie 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.