import{w as T,x as M,r as n,y as P,H as w,e as s,D as G,f as J,z as V,g as $,B as g,T as F,O as R,i as q,A as C,k as H,F as W,l as _,d as I,G as k,J as z,K as U,P as h,n as K,u as X,M as Y,E as Q,S as b,V as Z,p as ss,q as es,s as E,t as S,v as ts,L as as}from"./index-_6SmYgWK.js";import{A as ns}from"./assistant_empty-BAOmXGQM.js";import{v as is}from"./v4-CtRu48qb.js";const B=({show:o,dialogProps:t,onCancel:c,onConfirm:x})=>{const m=document.getElementById("portal"),i=T();M();const p=(...a)=>i(z(...a)),l=(...a)=>i(U(...a)),[u,f]=n.useState("");n.useEffect(()=>(i(o?{type:P}:{type:w}),()=>i({type:w})),[o,i]);const j=async()=>{try{const a={details:JSON.stringify({name:u}),credential:is(),type:"CUSTOM"},d=await I.createNewAssistant(a);d.data&&(p({message:"New Custom Assistant created.",options:{key:new Date().getTime()+Math.random(),variant:"success",action:A=>s.jsx(C,{style:{color:"white"},onClick:()=>l(A),children:s.jsx(k,{})})}}),x(d.data.id))}catch(a){p({message:`Failed to add new Custom Assistant: ${typeof a.response.data=="object"?a.response.data.message:a.response.data}`,options:{key:new Date().getTime()+Math.random(),variant:"error",persist:!0,action:d=>s.jsx(C,{style:{color:"white"},onClick:()=>l(d),children:s.jsx(k,{})})}}),c()}},y=o?s.jsxs(G,{fullWidth:!0,maxWidth:"sm",open:o,onClose:c,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[s.jsx(J,{style:{fontSize:"1rem"},id:"alert-dialog-title",children:s.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"},children:[s.jsx(V,{style:{marginRight:"10px"}}),t.title]})}),s.jsx($,{children:s.jsxs(g,{sx:{p:2},children:[s.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[s.jsxs(F,{children:["Name",s.jsx("span",{style:{color:"red"},children:" *"})]}),s.jsx("div",{style:{flexGrow:1}})]}),s.jsx(R,{size:"small",sx:{mt:1},type:"string",fullWidth:!0,onChange:a=>f(a.target.value),value:u??""},"customAssistantName")]})}),s.jsxs(q,{children:[s.jsx(C,{onClick:()=>c(),children:"Cancel"}),s.jsx(H,{disabled:!u,variant:"contained",onClick:()=>j(),children:t.confirmButtonName})]}),s.jsx(W,{})]}):null;return _.createPortal(y,m)};B.propTypes={show:h.bool,dialogProps:h.object,onCancel:h.func,onConfirm:h.func};const ls=()=>{var D;const o=K(),t=X(I.getAllAssistants),[c,x]=n.useState(!0),[m,i]=n.useState(null),[p,l]=n.useState(!1),[u,f]=n.useState({}),[j,y]=n.useState(""),a=e=>{y(e.target.value)},d=()=>{f({title:"Add New Custom Assistant",type:"ADD",cancelButtonName:"Cancel",confirmButtonName:"Add"}),l(!0)},A=e=>{l(!1),o(`/assistants/custom/${e}`)};function O(e){const r=JSON.parse(e.details);return r&&r.name&&r.name.toLowerCase().indexOf(j.toLowerCase())>-1}const L=e=>{const r=[];return e&&e.chatModel&&e.chatModel.name&&r.push({imageSrc:`${as}/api/v1/node-icon/${e.chatModel.name}`}),r};return n.useEffect(()=>{t.request("CUSTOM")},[]),n.useEffect(()=>{x(t.loading)},[t.loading]),n.useEffect(()=>{t.error&&i(t.error)},[t.error]),s.jsxs(s.Fragment,{children:[s.jsx(Y,{children:m?s.jsx(Q,{error:m}):s.jsxs(b,{flexDirection:"column",sx:{gap:3},children:[s.jsx(Z,{isBackButton:!0,onSearchChange:a,search:!0,searchPlaceholder:"Search Assistants",title:"Custom Assistant",description:"Create custom assistants with your choice of LLMs",onBack:()=>o(-1),children:s.jsx(ss,{permissionId:"assistants:create",variant:"contained",sx:{borderRadius:2,height:40},onClick:d,startIcon:s.jsx(es,{}),children:"Add"})}),c?s.jsxs(g,{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:E,children:[s.jsx(S,{variant:"rounded",height:160}),s.jsx(S,{variant:"rounded",height:160}),s.jsx(S,{variant:"rounded",height:160})]}):s.jsx(g,{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:E,children:t.data&&((D=t.data)==null?void 0:D.filter(O).map((e,r)=>{var v,N;return s.jsx(ts,{data:{name:(v=JSON.parse(e.details))==null?void 0:v.name,description:(N=JSON.parse(e.details))==null?void 0:N.instruction},images:L(JSON.parse(e.details)),onClick:()=>o("/assistants/custom/"+e.id)},r)}))}),!c&&(!t.data||t.data.length===0)&&s.jsxs(b,{sx:{alignItems:"center",justifyContent:"center"},flexDirection:"column",children:[s.jsx(g,{sx:{p:2,height:"auto"},children:s.jsx("img",{style:{objectFit:"cover",height:"20vh",width:"auto"},src:ns,alt:"AssistantEmptySVG"})}),s.jsx("div",{children:"No Custom Assistants Added Yet"})]})]})}),s.jsx(B,{show:p,dialogProps:u,onCancel:()=>l(!1),onConfirm:A,setError:i})]})};export{ls as default};
