import{r as c,D as Y,j as e,S as l,h as C,o as Z,H as ee}from"./vendor-ClLR6ncd.js";import{E as te}from"./Messages-BRmQDxrZ.js";import{B as se}from"./index-BpKmttxq.js";import{n as re,T as p,M as ae,o as oe}from"./index-OtVJl4GC.js";import{N as A}from"./NumberInput-DP8_DN2w.js";import{e as ie,n as K,f as F,a as ne,p as ce}from"./model-B1_e74fU.js";import{u as de}from"./index-PJ52zw2m.js";import{u as ue,e as pe}from"./model-BneMh0-t.js";import{O as le}from"./ui-DG_5mJZa.js";import{u as me}from"./model-CvVGVe3F.js";import{A as he}from"./Autocomplete-Cjt7Q9VV.js";import{A as xe,a as be,b as ye}from"./AccordionDetails-Bqc4B-Ut.js";const ve=ce.filter(a=>a!=="bot"),R=a=>a.replace(/\s+/g,"-"),L=new String("");function fe(a=L){var y;const[i,s]=c.useState(a),S=c.useCallback(n=>{s(typeof n=="string"?R(n):n)},[]),d=ne(),m=!!(Array.isArray((y=d.data)==null?void 0:y.chatBots)?d.data.chatBots.filter(n=>n.id!==a):[]).find(n=>n.id===i),x=i==="",b=m||x;return{chatBotId:i,setChatBotId:S,isNameOverlapped:m,isNameEmpty:x,isInvalidNameInput:b,isInvalidName:b||i===L}}const k={width:300},f=()=>{},Se=/\d+(\.\d+)?/,w=a=>i=>{Se.test(i)&&a(i)};function We({isNew:a=!1,id:i,...s}){const S=c.useRef(Y(5)),d=ie(a),o=d.isLoading,{chatBotId:m,setChatBotId:x,isNameOverlapped:b,isNameEmpty:N,isInvalidNameInput:y,isInvalidName:n}=fe(i),[V,T]=c.useState(s.bot||""),[u,q]=c.useState(s.evdb||""),[j,g]=c.useState(s.hvdb||""),[I,U]=c.useState(s.expertiseMinScore),_=w(U),[E,$]=c.useState(s.historyMinScore),Q=w($),[M,P]=ue(s.apiKey||pe),{vectorDatabases:v}=de("dummy"),z=c.useMemo(()=>[...v,...s.expertiseVdb&&v.every(t=>t.value!==s.expertiseVdb)?[{label:s.expertiseVdb,value:s.expertiseVdb}]:[]],[s.expertiseVdb,v]),{value:G}=re(),O=!j.trim(),J=!me(u).data,W=isNaN(parseFloat(I)),D=isNaN(parseFloat(E)),B=!(u!=null&&u.trim()),H=a?M==="":!1,X=H||J||n||O||W||D||B;return e.jsxs(l,{component:"form",spacing:oe(),onSubmit:t=>{t.preventDefault();const r=new FormData(t.target);d.mutate(Object.assign({id:m,evdb:u,hvdb:j,apiKey:M,expertiseMinScore:I,historyMinScore:E,bot:V},...Array.from(r.keys()).map(h=>({[h]:r.get(h)}))))},children:[e.jsxs(l,{direction:"row",justifyContent:"space-between",children:[e.jsx(C,{variant:"h4",children:a?"New chatbot":`Edit ${i} chatbot`}),e.jsx(se,{disabled:o})]}),e.jsxs(l,{spacing:G?0:1,children:[e.jsxs(l,{direction:"row",spacing:2,children:[e.jsx(p,{required:!0,disabled:!a||o,sx:k,label:"Chatbot ID",value:m,onChange:t=>{const r=t.target.value;x(r),T(r);const h=R(r);g(h===""?"":`${h}-history-vdb-${S.current}`)},error:y,helperText:b?"There is a chatbot with this name":N?"Name must be not empty":void 0}),e.jsx(he,{freeSolo:!0,sx:k,options:z,required:!0,value:u,disabled:o,onChange:(t,r)=>{q(r==null?void 0:r.value)},inputValue:u||"",onInputChange:(t,r)=>{q(r)},isOptionEqualToValue:(t,r)=>t.value===r,renderInput:t=>e.jsx(p,{...t,label:"Expertise vector database",error:B,setter:f,helperText:u?v.length===0?"No vector databases available":B?"Vector database not found":"":"Select a vector database"})})]}),e.jsx(le,{sx:{width:510},required:!0,error:H,label:"OpenAI API key",apiKey:M,setApiKey:P,disabled:o}),e.jsxs(xe,{disabled:o,children:[e.jsx(be,{expandIcon:e.jsx(Z,{}),children:"Advanced Settings"}),e.jsxs(ye,{children:[e.jsx(C,{variant:"h5",children:"Vector databases settings"}),e.jsxs(l,{direction:"row",spacing:2,pt:1,pb:1,children:[e.jsx(A,{required:!0,disabled:o,sx:{maxWidth:"30%"},setter:f,name:"expertiseMaxMatches",defaultValue:s.expertiseMaxMatches,label:"The maximum number of Expertise matches"}),e.jsx(p,{required:!0,disabled:o,sx:{maxWidth:"30%"},setter:_,error:W,value:I,label:"The minimum Expertise matching score"})]}),e.jsxs(l,{direction:"row",spacing:2,children:[e.jsx(p,{required:!0,disabled:o,label:"History vector database",value:j,setter:g,error:O}),e.jsx(A,{required:!0,disabled:o,sx:{maxWidth:"30%"},setter:f,name:"historyMaxMatches",defaultValue:s.historyMaxMatches,label:"The maximum number of History matches"}),e.jsx(p,{required:!0,disabled:o,sx:{maxWidth:"30%"},setter:Q,error:D,value:E,label:"The minimum History matching score"})]}),e.jsx(C,{variant:"h5",children:"LLM prompt settings"}),e.jsx(p,{disabled:o,setter:T,label:K.bot,value:V}),ve.map(t=>{const r=F[t]==="integer"||F[t]==="float"?A:p;return e.jsx(r,{required:!0,disabled:o,setter:f,name:t,label:K[t],defaultValue:s[t]},t)})]})]})]}),e.jsx(te,{error:d.error,resetError:d.reset}),e.jsx(ae,{title:n?"Index name is invalid":void 0,children:e.jsx(ee,{variant:"contained",fullWidth:!0,type:"submit",disabled:o||X,children:d.isLoading?a?"creating...":"updating...":a?"create":"update"})})]})}export{We as C};
