1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6875],{19277:(e,t,l)=>{"use strict";l.d(t,{A:()=>a});var i=l(37876),n=l(72943),r=l(14e3);l(14232);var s=l(19619);let a=e=>t=>{let l=(0,n.J)(),a=(0,r.useRouter)();return l.loading?(0,i.jsx)("div",{children:"Loading..."}):null===l?void a.push("/auth"):(0,i.jsx)(s.SessionAuth,{onSessionExpired:()=>a.refresh(),userContext:l.user||void 0,children:(0,i.jsx)(e,{...t})})}},40950:(e,t,l)=>{"use strict";l.d(t,{A:()=>u});var i=l(37876);l(14232);var n=l(97120),r=l(39822),s=l(43123),a=l(8091),o=l(72953),d=l(21379),c=l(80161);let u=e=>{let{isOpen:t,onClose:l,title:u,onSubmit:h,isSubmitting:g=!1,submitButtonText:x="Submit",children:m,showActions:p=!0,isDisabled:f=!1,playground:j=!1,headerRight:b}=e,{theme:y}=(0,d.D)(),v=c.kY.blockBgColor[y]||c.kY.blockBgColor.dark,w=c.kY.blockBorderColor[y]||c.kY.blockBorderColor.dark,z=c.kY.textColor[y]||c.kY.textColor.dark;return(0,i.jsxs)(n.Dz,{open:t,onOpenChange:e=>e.open?{}:l(),size:"full",motionPreset:"slide-in-right",children:[(0,i.jsx)(n.Xi,{}),(0,i.jsxs)(n.Cf,{bg:v,borderColor:w,width:"50vw",height:"100vh",position:"fixed",right:"0",top:"0",margin:"0",borderRadius:"0",children:[(0,i.jsx)(r.a,{position:"absolute",top:"16px",right:"16px",zIndex:10,children:(0,i.jsx)(n.tK,{})}),(0,i.jsx)(n.c7,{ml:0,fontSize:"sm",fontWeight:"semibold",color:z,children:(0,i.jsxs)(s.s,{justifyContent:"space-between",alignItems:"center",w:"100%",pr:8,children:[u,b]})}),j&&(0,i.jsx)(a.w,{width:"100%",mx:"auto",borderColor:"dark"===y?"gray.600":"white"}),(0,i.jsx)(n.R4,{pb:6,overflowY:"auto",children:m}),p?(0,i.jsxs)(n.Es,{children:[(0,i.jsx)(o.$,{colorScheme:"blue",mr:3,onClick:h,loading:g,disabled:f,title:f?"Admin permissions required":"",children:x}),(0,i.jsx)(o.$,{colorScheme:"blue",variant:"outline",onClick:l,children:"Cancel"})]}):(0,i.jsx)(n.Es,{children:(0,i.jsx)(o.$,{colorScheme:"blue",onClick:l,children:"Close"})})]})]})}},42256:(e,t,l)=>{"use strict";l.d(t,{Aw:()=>f,G7:()=>x,I1:()=>a,SY:()=>h,UZ:()=>c,YA:()=>o,YN:()=>g,am:()=>u,ds:()=>d,uq:()=>p,x4:()=>m});var i=l(75656),n=l(34333),r=l(8863),s=l(72943);let a=5242880,o=".csv,.xls,.xlsx,text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",d=e=>{let{user:t,loading:l}=(0,s.J)();return(0,i.Ay)(!l&&t&&e?["/fetch_faqs?agent_id=".concat(e),t.accessToken]:null,e=>(0,r.we)(e).then(e=>e.data))},c=e=>(0,i.Ay)(e?"/fetch_public_faqs/".concat(e):null,async e=>{let t=await fetch("".concat("https://orygobackend-production.up.railway.app").concat(e));if(!t.ok)throw Error("Failed to fetch FAQs");return(await t.json()).data}),u=e=>{let{user:t,loading:l}=(0,s.J)();return(0,n.A)(!l&&t&&e?["/create_faq?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,r.eh)(e,{arg:{question:l.question,answer:l.answer,intents:l.intents&&l.intents.length>0?l.intents:null,category:l.category||null}})})},h=e=>{let{user:t,loading:l}=(0,s.J)();return(0,n.A)(!l&&t&&e?["/edit_faq?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t,i={faq_id:l.faq_id};return void 0!==l.question&&null!==l.question&&(i.question=l.question),void 0!==l.answer&&null!==l.answer&&(i.answer=l.answer),void 0!==l.enabled&&null!==l.enabled&&(i.enabled=l.enabled),void 0!==l.intents&&(i.intents=l.intents&&l.intents.length>0?l.intents:null),void 0!==l.category&&(i.category=l.category||null),(0,r.wf)(e,{arg:i})})},g=e=>{let{user:t,loading:l}=(0,s.J)();return(0,n.A)(!l&&t&&e?["/import_faqs?agent_id=".concat(e),t.accessToken]:null,async(e,t)=>{let[l]=e,{arg:i}=t,n=new FormData;n.append("file",i);let s=await fetch("".concat("https://orygobackend-production.up.railway.app").concat(l),{method:"POST",body:n});return(0,r.LM)(s)})},x=async(e,t)=>{let l="".concat("https://orygobackend-production.up.railway.app","/export_faqs?agent_id=").concat(e,"&format=").concat(t),i=await fetch(l);if(!i.ok){if((i.headers.get("content-type")||"").includes("application/json")){let e=await i.json();throw Error(e.message||e.detail||"Failed to download FAQs")}throw Error(await i.text()||"Failed to download FAQs")}let n=await i.blob(),r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download="faqs.".concat(t),s.click(),URL.revokeObjectURL(r)},m=e=>{let{user:t,loading:l}=(0,s.J)();return(0,n.A)(!l&&t&&e?["/delete_faq?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,r.Nw)(e,{arg:l})})},p=500,f=e=>{let{user:t,loading:l}=(0,s.J)();return(0,n.A)(!l&&t&&e?["/delete_faqs?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,r.Nw)(e,{arg:{faq_ids:l.faq_ids}})})}},51978:(e,t,l)=>{"use strict";l.r(t),l.d(t,{default:()=>ea}
1);var i=l(37876),n=l(19277),r=l(43123),s=l(39822),a=l(92146),o=l(20529),d=l(72953),c=l(30488),u=l(32485),h=l(14232),g=l(89099),x=l(70294),m=l(49301),p=l(1924),f=l(63132),j=l(8091),b=l(9463),y=l(77362),v=l(76839),w=l(42256),z=l(61385),S=l(91553),k=l(40950);let _=m.cQ,C=m.y3,E=m.rm,A=m.Dr,F=[{bg:"purple.100",text:"purple.700",border:"purple.300"},{bg:"teal.100",text:"teal.700",border:"teal.300"},{bg:"orange.100",text:"orange.700",border:"orange.300"},{bg:"pink.100",text:"pink.700",border:"pink.300"},{bg:"cyan.100",text:"cyan.700",border:"cyan.300"},{bg:"green.100",text:"green.700",border:"green.300"},{bg:"yellow.100",text:"yellow.700",border:"yellow.300"},{bg:"red.100",text:"red.700",border:"red.300"}],T=e=>{let t=0;for(let l=0;l<e.length;l++)t=e.charCodeAt(l)+((t<<5)-t);let l=Math.abs(t)%F.length;return F[l]},D=e=>{let{agentId:t,isDisabled:l=!1}=e,[n,o]=(0,h.useState)(!1),[u,g]=(0,h.useState)(!1),[F,D]=(0,h.useState)(""),[W,q]=(0,h.useState)(""),[X,P]=(0,h.useState)([]),[I,R]=(0,h.useState)(""),[B,Q]=(0,h.useState)(null),[M,N]=(0,h.useState)(""),[G,$]=(0,h.useState)(""),[O,Y]=(0,h.useState)([]),[J,U]=(0,h.useState)(""),[H,L]=(0,h.useState)(null),[K,V]=(0,h.useState)(null),[Z,ee]=(0,h.useState)(new Set),et=(0,h.useRef)(null),el=(0,h.useRef)(null),{data:ei,mutate:en,error:er}=(0,w.ds)(t||null),es=ei?[...new Set(ei.map(e=>e.category).filter(e=>null!=e))]:[],ea=ei?H?ei.filter(e=>e.category===H):ei:[],{trigger:eo,isMutating:ed}=(0,w.am)(t||null),{trigger:ec,isMutating:eu}=(0,w.SY)(t||null),{trigger:eh}=(0,w.x4)(t||null),{trigger:eg}=(0,w.Aw)(t||null),ex=ea.map(e=>e.id),em=ex.filter(e=>Z.has(e)),ep=ex.length>0&&em.length===ex.length,ef=em.length>0&&!ep;(0,h.useEffect)(()=>{el.current&&(el.current.indeterminate=ef)},[ef]);let{trigger:ej,isMutating:eb}=(0,w.YN)(t||null),ey=()=>{o(!1),D(""),q(""),P([]),R("")},ev=async()=>{if(!F.trim()||!W.trim())return void z.X.create({title:"Validation Error",description:"Both question and answer are required.",type:"error",duration:3e3,closable:!0});try{await eo({question:F,answer:W,intents:X.length>0?X:null,category:I.trim()||null}),ey(),en(),z.X.create({title:"FAQ created successfully",description:"The FAQ has been added.",type:"success",duration:3e3,closable:!0})}catch(e){console.error(e),z.X.create({title:"Error creating FAQ",description:"An error occurred while creating the FAQ. Please try again.",type:"error",duration:3e3,closable:!0})}},ew=()=>{g(!1),Q(null),N(""),$(""),Y([]),U("")},ez=async()=>{if(!M.trim()||!G.trim())return void z.X.create({title:"Validation Error",description:"Both question and answer are required.",type:"error",duration:3e3,closable:!0});if(B)try{await ec({faq_id:B,question:M,answer:G,intents:O.length>0?O:null,category:J.trim()||null}),ew(),en(),z.X.create({title:"FAQ updated successfully",description:"The FAQ has been updated.",type:"success",duration:3e3,closable:!0})}catch(e){console.error(e),z.X.create({title:"Error updating FAQ",description:"An error occurred while updating the FAQ. Please try again.",type:"error",duration:3e3,closable:!0})}},eS=async e=>{var l,i,n,r,s,a,o;let d=null==(l=e.target.files)?void 0:l[0];if(e.target.value="",!d||!t)return;let c=d.name.toLowerCase();if(!c.endsWith(".csv")&&!c.endsWith(".xls")&&!c.endsWith(".xlsx"))return void z.X.create({title:"Unsupported file",description:"Upload a .csv, .xls, or .xlsx file.",type:"error",duration:4e3,closable:!0});if(d.size>w.I1)return void z.X.create({title:"File is too large",description:"Maximum size is 5MB.",type:"error",duration:4e3,closable:!0});try{let e=await ej(d),t=null!=(s=null==e||null==(i=e.data)?void 0:i.created)?s:0,l=null!=(a=null==e||null==(n=e.data)?void 0:n.updated)?a:0,c=null!=(o=null==e||null==(r=e.data)?void 0:r.skipped)?o:[];await en();let u=[t?"".concat(t," added"):"",l?"".concat(l," updated"):"",c.length?"".concat(c.length," skipped"):""].filter(Boolean).join(", "),h=c.slice(0,3).map(e=>"Row ".concat(e.row,": ").concat(e.reason)).join(" ");z.X.create({title:"FAQs imported",description:[u,h].filter(Boolean).join(". "),type:c.length?"warning":"success",duration:5e3,closable:!0})}
1catch(e){z.X.create({title:"Error importing FAQs",description:e.message||"Could not import this file. Please try again.",type:"error",duration:5e3,closable:!0})}},ek=async e=>{if(t){V(e);try{await (0,w.G7)(t,e)}catch(e){z.X.create({title:"Error downloading FAQs",description:e.message||"Could not download FAQs. Please try again.",type:"error",duration:4e3,closable:!0})}finally{V(null)}}};return er?(0,i.jsx)(c.E,{color:"red.500",children:"Failed to load FAQs."}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(p.T,{gap:6,align:"stretch",children:[(0,i.jsxs)(a.z,{gap:4,flexWrap:"wrap",justifyContent:"space-between",w:"100%",alignItems:"flex-start",children:[(0,i.jsxs)(p.T,{gap:2,align:"stretch",children:[(0,i.jsxs)(a.z,{gap:2,flexWrap:"wrap",children:[(0,i.jsxs)(d.$,{colorScheme:"blue",onClick:()=>{D(""),q(""),P([]),R(""),o(!0)},disabled:l,size:"sm",children:[(0,i.jsx)(x.GGD,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:"Add New FAQ"})]}),(0,i.jsx)("input",{ref:et,type:"file",accept:w.YA,style:{display:"none"},onChange:eS}),(0,i.jsxs)(d.$,{variant:"outline",size:"sm",onClick:()=>{var e;return null==(e=et.current)?void 0:e.click()},disabled:l||eb||!t,loading:eb,children:[(0,i.jsx)(x.B88,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:"Upload"})]}),(0,i.jsxs)(m.il,{positioning:{placement:"bottom-start"},onSelect:e=>{("csv"===e.value||"xlsx"===e.value||"xls"===e.value)&&ek(e.value)},children:[(0,i.jsx)(_,{asChild:!0,children:(0,i.jsxs)(d.$,{variant:"outline",size:"sm",disabled:!t||null!==K,loading:null!==K,children:[(0,i.jsx)(x.a4x,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:"Download"}),(0,i.jsx)(s.a,{ml:1,display:"inline-flex",children:(0,i.jsx)(x.fK4,{size:14})})]})}),(0,i.jsx)(C,{children:(0,i.jsxs)(E,{minW:"180px",children:[(0,i.jsx)(A,{value:"csv",children:(0,i.jsx)(c.E,{fontSize:"sm",children:"CSV (.csv)"})}),(0,i.jsx)(A,{value:"xlsx",children:(0,i.jsx)(c.E,{fontSize:"sm",children:"Excel (.xlsx)"})}),(0,i.jsx)(A,{value:"xls",children:(0,i.jsx)(c.E,{fontSize:"sm",children:"Excel (.xls)"})})]})})]})]}),(0,i.jsx)(c.E,{fontSize:"xs",color:"gray.500",maxW:"560px",children:"Upload a .csv, .xls, or .xlsx file. Columns: question, answer, intents (separate with ;), category. Include id to update an existing FAQ â download first to get the columns. The first sheet is used."})]}),es.length>0&&(0,i.jsxs)(a.z,{gap:2,children:[(0,i.jsx)(c.E,{fontSize:"sm",color:"gray.600",children:"Category:"}),(0,i.jsx)(f.MQ,{size:"sm",w:"160px",children:(0,i.jsxs)(f.uT,{value:H||"all",onChange:e=>{let t=e.target.value;L("all"===t?null:t),ee(new Set)},children:[(0,i.jsx)("option",{value:"all",children:"All Categories"}),es.map(e=>(0,i.jsx)("option",{value:e,children:e},e))]})})]})]}),ea&&ea.length>0&&(0,i.jsx)(s.a,{borderWidth:"1px",borderRadius:"md",children:(0,i.jsxs)(r.s,{direction:"column",children:[(0,i.jsxs)(a.z,{justifyContent:"space-between",px:4,py:2,gap:3,children:[(0,i.jsxs)(a.z,{gap:2,children:[(0,i.jsx)("input",{id:"faq-select-all",ref:el,type:"checkbox",checked:ep,disabled:l,"aria-label":"Select all FAQs",onChange:()=>{ee(ep?new Set:new Set(ex))},style:{width:16,height:16,accentColor:"#3182ce",cursor:l?"not-allowed":"pointer"}}),(0,i.jsx)(c.E,{asChild:!0,fontSize:"sm",color:"gray.600",cursor:l?"not-allowed":"pointer",children:(0,i.jsx)("label",{htmlFor:"faq-select-all",children:em.length>0?"".concat(em.length," selected"):"Select all"})})]}),em.length>0&&(0,i.jsx)(S.A,{triggerDelete:async()=>{if(em.length>w.uq)throw Error("Delete up to ".concat(w.uq," FAQs at a time."));let e=await eg({faq_ids:em});return ee(new Set),e},alertMessage:1===em.length?"Are you sure you want to delete this FAQ?":"Are you sure you want to delete ".concat(em.length," FAQs?"),buttonText:1===em.length?"Delete":"Delete ".concat(em.length),mutate:en,variant:"solid",isDisabled:l})]}),(0,i.jsx)(j.w,{}),ea.map((e,t)=>(0,i.jsxs)(h.Fragment,{children:[(0,i.jsx)(s.a,{p:4,children:(0,i.jsxs)(a.z,{alignItems:"flex-start",gap:3,children:[(0,i.jsx)(s.a,{pt:"2px",children:(0,i.jsx)("input",{type:"checkbox",checked:Z.has(e.id),disabled:l,"aria-label":"Select FAQ: ".concat(e.question),onChange:()=>{ee(t=>{let l=new Set(t);return l.has(e.id)?l.delete(e.id):l.add(e.id),l})},style:{width:16,height:16,accentColor:"#3182ce",cursor:l?"not-allowed":"pointer"}})}),(0,i.jsxs)(p.T,{gap:1,align:"stretch",flex:1,children:[(0,i.jsxs)(a.z,{justifyContent:"space-between",alignItems:"flex-start",children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"bold",children:e.question}),(0,i.jsxs)(a.z,{gap:1,children:[(0,i.jsx)(b.K,{"aria-label":"Edit FAQ",size:"xs",variant:"ghost",colorPalette:"gray",onClick:()=>(e=>{Q(e.id),N(e.question),$(e.answer),Y(e.intents&&e.intents.length>0?[...e.intents]:[]),U(e.category||""),g(!0)})(e),disabled:l,children:(0,i.jsx)(x.WXf,{})}),(0,i.jsx)(S.A,{triggerDelete:()=>eh({faq_id:e.id}),alertMessage:"Are you sure you want to delete this FAQ?",mutate:()=>{ee(t=>
1{if(!t.has(e.id))return t;let l=new Set(t);return l.delete(e.id),l}),en()},variant:"icon",iconSize:"xs",isDisabled:l})]})]}),e.intents&&e.intents.length>0&&(0,i.jsxs)(c.E,{fontSize:"xs",color:"gray.500",children:[(0,i.jsx)(c.E,{as:"span",fontWeight:"semibold",children:"Alternative Intents: "}),e.intents.join("; ")]}),(0,i.jsxs)(c.E,{fontSize:"sm",color:"gray.600",overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",css:{WebkitLineClamp:3,WebkitBoxOrient:"vertical"},lineHeight:"1.4",children:[(0,i.jsx)(c.E,{as:"span",fontWeight:"semibold",children:"Content: "}),e.answer]}),e.category&&(0,i.jsx)(s.a,{mt:1,children:(0,i.jsx)(s.a,{display:"inline-block",px:2,py:.5,borderRadius:"sm",bg:T(e.category).bg,borderWidth:"1px",borderColor:T(e.category).border,children:(0,i.jsx)(c.E,{fontSize:"xs",fontWeight:"medium",color:T(e.category).text,children:e.category})})})]})]})}),t<ea.length-1&&(0,i.jsx)(j.w,{})]},e.id))]})})]}),(0,i.jsx)(k.A,{isOpen:n,onClose:ey,title:"Add New FAQ",onSubmit:ev,isSubmitting:ed,submitButtonText:"Create FAQ",isDisabled:l,children:(0,i.jsxs)(p.T,{gap:4,align:"stretch",children:[(0,i.jsxs)(s.a,{children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Question"}),(0,i.jsx)(y.p,{type:"text",value:F,onChange:e=>D(e.target.value),placeholder:"Enter question",size:"sm",disabled:l})]}),(0,i.jsxs)(s.a,{children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Answer"}),(0,i.jsx)(v.T,{value:W,onChange:e=>q(e.target.value),placeholder:"Enter answer",size:"sm",height:"200px",disabled:l})]}),(0,i.jsxs)(s.a,{children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Alternative Intents"}),(0,i.jsxs)(p.T,{gap:2,align:"stretch",children:[X.map((e,t)=>(0,i.jsxs)(a.z,{gap:2,children:[(0,i.jsx)(y.p,{type:"text",value:e,onChange:e=>{let l=[...X];l[t]=e.target.value,P(l)},placeholder:"Enter alternative intent",size:"sm",disabled:l}),(0,i.jsx)(b.K,{"aria-label":"Remove intent",size:"sm",variant:"ghost",colorPalette:"red",onClick:()=>{P(X.filter((e,l)=>l!==t))},disabled:l,children:(0,i.jsx)(x.yGN,{})})]},t)),(0,i.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>P([...X,""]),disabled:l,alignSelf:"flex-start",children:[(0,i.jsx)(x.GGD,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:"Add Intent"})]})]})]}),(0,i.jsxs)(s.a,{children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Category"}),(0,i.jsx)(y.p,{type:"text",value:I,onChange:e=>R(e.target.value),placeholder:"Enter category (optional)",size:"sm",disabled:l})]})]})}),(0,i.jsx)(k.A,{isOpen:u,onClose:ew,title:"Edit FAQ",onSubmit:ez,isSubmitting:eu,submitButtonText:"Save Changes",isDisabled:l,children:(0,i.jsxs)(p.T,{gap:4,align:"stretch",children:[(0,i.jsxs)(s.a,{children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Question"}),(0,i.jsx)(y.p,{type:"text",value:M,onChange:e=>N(e.target.value),size:"sm",disabled:l})]}),(0,i.jsxs)(s.a,{children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Answer"}),(0,i.jsx)(v.T,{value:G,onChange:e=>$(e.target.value),size:"sm",height:"200px",disabled:l})]}),(0,i.jsxs)(s.a,{children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Alternative Intents"}),(0,i.jsxs)(p.T,{gap:2,align:"stretch",children:[O.map((e,t)=>(0,i.jsxs)(a.z,{gap:2,children:[(0,i.jsx)(y.p,{type:"text",value:e,onChange:e=>{let l=[...O];l[t]=e.target.value,Y(l)},placeholder:"Enter alternative intent",size:"sm",disabled:l}),(0,i.jsx)(b.K,{"aria-label":"Remove intent",size:"sm",variant:"ghost",colorPalette:"red",onClick:()=>{Y(O.filter((e,l)=>l!==t))},disabled:l,children:(0,i.jsx)(x.yGN,{})})]},t)),(0,i.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>Y([...O,""]),disabled:l,alignSelf:"flex-start",children:[(0,i.jsx)(x.GGD,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:"Add Intent"})]})]})]}),(0,i.jsxs)(s.a,{children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Category"}),(0,i.jsx)(y.p,{type:"text",value:J,onChange:e=>U(e.target.value),placeholder:"Enter category (optional)",size:"sm",disabled:l})]})]})})]})};var W=l(58239),q=l(65955),X=l(21379),P=l(75656),I=l(34333),R=l(8863),B=l(72943);let Q=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,M=["application/pdf"];var N=l(97120),G=l(80161);let $=e=>{let{isOpen:t,onClose:l,title:n,onSubmit:a,isSubmitting:o=!1,submitButtonText:c="Submit",children:u,showActions:h=!0,isDisabled:g=!1,headerRight:x}=e,{theme:m}=(0,X.D)(),p=G.kY.blockBgColor[m]||G.kY.blockBgColor.dark,f=G.kY.blockBorderColor[m]||G.kY.blockBorderColor.dark,j=G.kY.textColor[m]||G.kY.textColor.dark;return(0,i.jsxs)(N.Dz,{open:t,onOpenChange:e=>e.open?{}:l(),size:"full",motionPreset:"none",children:[(0,i.jsx)(N.Xi,{}),(0,i.jsxs)(N.Cf,{bg:p,borderColor:f,width:"100vw",maxWidth:"100vw",height:"100vh",maxHeight:"100vh",position:"fixed",inset:"0",margin:"0",borderRadius:"0",display:"flex",flexDirection:"column",...{},children:[(0,i.jsx)(s.a,{position:"absolute",top:"16px",right:"16px",zIndex:10,children:(0,i.jsx)(N.tK,{})}),(0,i.jsx)(N.c7,{ml:0,fontSize:"sm",fontWeight:"semibold",color:j,flexShrink:0,children:(0,i.jsxs)(r.s,{justifyContent:"space-between",alignItems:"center",w:"100%",pr:8,children:[n,x]})}),(0,i.jsx)(N.R4,{pb:6,overflowY:"auto",flex:"1",minHeight:"0",display:"flex",flexDirection:"column",children:u}),h?(0,i.jsxs)(N.Es,{flexShrink:0,children:[(0,i.jsx)(d.$,{colorScheme:"blue",mr:3,onClick:a,loading:o,disabled:g,title:g?"Admin permissions required":"",children:c}),(0,i.jsx)(d.$,{colorScheme:"blue",variant:"outline",onClick:l,children:"Cancel"})]}):(0,i.jsx)(N.Es,{flexShrink:0,children:(0,i.jsx)(d.$,{colorScheme:"blue",onClick:l,children:"Close"})})]})]})},O=m.cQ,Y=m.y3,J=m.rm,U=m.Dr,H=e=>null==e?"":e<1024?"".concat(e," B"):e<1048576?"".concat((e/1024).toFixed(1)," KB"):"".concat((e/1048576).toFixed(2)," MB"),L=e=>Q.test(e.trim()),K=e=>{var t;let{agentId:l,isDisabled:n=!1}=e,{theme:o}=(0,X.D)(),u="dark"===(null!=o?o:"dark")?"gray.800":"gray.50",[g,f]=(0,h.useState)(!1),[j,w]=(0,h.useState)(""),[k,_]=(0,h.useState)(""),[C,E]=(0,h.useState)(!1),[A,F]=(0,h.useState)(""),[T,D]=(0,h.useState)(null),[Q,N]=(0,h.useState)(null),G=(0,h.useRef)(null),[K,V]=(0,h.useState)(!1),[Z,ee]=(0,h.useState)(null),[et,el]=(0,h.useState)(""),[ei,en]=(0,h.useState)(""),{data:er,mutate:es,error:ea}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,P.Ay)(!l&&t&&e?["/fetch_documents?agent_id=".concat(e),t.accessToken]:null,e=>(0,R.we)(e).then(e=>e.data))})(l||null),{trigger:eo,isMutating:ed}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,I.A)(!l&&t&&e?["/create_document?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,R.eh)(e,{arg:{title:l.title,content:l.content,type:"free_text"}})})})(l||null),{trigger:ec,isMutating:eu}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,I.A)(!l&&t&&e?["/upload_document_pdf?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,R.Xl)(e,{arg:l})})})(l||null),{trigger:eh,isMutating:eg}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,I.A)(!l&&t&&e?["/edit_document?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t,i={document_id:l.documentId};return void 0!==l.title&&null!==l.title&&(i.title=l.title),void 0!==l.content&&null!==l.content&&(i.content=l.content),void 0!==l.type&&null!==l.type&&(i.type=l.type),(0,R.wf)(e,{arg:i})})})(l||null),{trigger:ex}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,I.A)(!l&&t&&e?["/delete_document?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,R.Nw)(e,{arg:{document_id:l.documentId}})})})(l||null),em=()=>{f(!1),w(""),_("")},ep=async()=>{let e=j.trim(),t=k.trim();if(!e||!t)return void z.X.create({title:"Validation Error",description:"Title and content are required.",type:"error",duration:3e3,closable:!0});if(!L(e))return void z.X.create({title:"Invalid title",description:"Title must be snake_case (lowercase letters, digits, and underscores, e.g. 'shipping_policy'). It must start with a letter.",type:"error",duration:4e3,closable:!0});try{await eo({title:e,content:t}),em(),es(),z.X.create({title:"Document created",description:"The document has been added.",type:"success",duration:3e3,closable:!0})}catch(t){let e=(null==t?void 0:t.message)||"Failed to create document.";z.X.create({title:"Error creating document",description:e,type:"error",duration:5e3,closable:!0})}},ef=()=>{E(!1),F(""),D(null),N(null),G.current&&(G.current.value="")},ej=async()=>{let e=A.trim();if(!e)return void z.X.create({title:"Validation Error",description:"Title is required.",type:"error",duration:3e3,closable:!0});if(!L(e))return void z.X.create({title:"Invalid title",description:"Title must be snake_case (lowercase letters, digits, and underscores, e.g. 'shipping_policy'). It must start with a letter.",type:"error",duration:4e3,closable:!0});if(!T)return void z.X.create({title:"No file selected",description:"Please select a PDF file to upload.",type:"error",duration:3e3,closable:!0});try{await ec({file:T,title:e}),ef(),es(),z.X.create({title:"PDF uploaded",description:"The PDF document has been added.",type:"success",duration:3e3,closable:!0})}catch(t){let e=(null==t?void 0:t.message)||"Failed to upload PDF document.";z.X.create({title:"Error uploading PDF",description:e,type:"error",duration:5e3,closable:!0})}},eb=()=>{V(!1),ee(null),el(""),en("")},ey=async()=>
1{if(!Z)return;let e=et.trim();if(!e)return void z.X.create({title:"Validation Error",description:"Title is required.",type:"error",duration:3e3,closable:!0});if(!L(e))return void z.X.create({title:"Invalid title",description:"Title must be snake_case (lowercase letters, digits, and underscores, e.g. 'shipping_policy'). It must start with a letter.",type:"error",duration:4e3,closable:!0});let t="pdf"===Z.type;if(!t&&!ei.trim())return void z.X.create({title:"Validation Error",description:"Content is required.",type:"error",duration:3e3,closable:!0});try{await eh({documentId:Z.id,title:e,content:t?void 0:ei.trim()}),eb(),es(),z.X.create({title:"Document updated",description:"The document has been updated.",type:"success",duration:3e3,closable:!0})}catch(t){let e=(null==t?void 0:t.message)||"Failed to update document.";z.X.create({title:"Error updating document",description:e,type:"error",duration:5e3,closable:!0})}};if(ea)return(0,i.jsx)(c.E,{color:"red.500",children:"Failed to load documents."});let ev=(null==Z?void 0:Z.type)==="pdf",ew="Lowercase letters, digits, and underscores only. Must start with a letter.",ez=e=>0===e.length||L(e);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(p.T,{gap:6,align:"stretch",children:[(0,i.jsxs)(m.il,{positioning:{placement:"bottom-start"},onSelect:e=>{"add_text"===e.value&&(w(""),_(""),f(!0)),"upload_pdf"===e.value&&(F(""),D(null),N(null),E(!0))},children:[(0,i.jsx)(O,{asChild:!0,children:(0,i.jsxs)(d.$,{colorScheme:"blue",disabled:n,size:"sm",alignSelf:"flex-start",children:[(0,i.jsx)(x.GGD,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:"Add document"}),(0,i.jsx)(s.a,{ml:2,display:"inline-flex",children:(0,i.jsx)(x.fK4,{size:14})})]})}),(0,i.jsx)(Y,{children:(0,i.jsxs)(J,{minW:"220px",children:[(0,i.jsx)(U,{value:"add_text",children:(0,i.jsxs)(a.z,{gap:2,children:[(0,i.jsx)(x.jH2,{}),(0,i.jsx)(c.E,{fontSize:"sm",children:"Add text document"})]})}),(0,i.jsx)(U,{value:"upload_pdf",children:(0,i.jsxs)(a.z,{gap:2,children:[(0,i.jsx)(x.B88,{}),(0,i.jsx)(c.E,{fontSize:"sm",children:"Upload PDF"})]})})]})})]}),er&&er.length>0&&(0,i.jsx)(W.r,{columns:{base:1,md:2,lg:3},gap:4,children:er.map(e=>{let t="pdf"===e.type,l=t?"red.500":"blue.500";return(0,i.jsxs)(s.a,{position:"relative",p:4,borderRadius:"lg",borderWidth:"1px",borderLeftWidth:"4px",borderLeftColor:l,bg:u,_hover:{shadow:"md"},transition:"box-shadow 0.15s",children:[(0,i.jsxs)(r.s,{align:"flex-start",gap:2,mb:2,children:[(0,i.jsx)(s.a,{color:l,mt:.5,children:t?(0,i.jsx)(x.jH2,{size:18}):(0,i.jsx)(x.s_k,{size:18})}),(0,i.jsxs)(p.T,{align:"stretch",gap:1,flex:1,minW:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"bold",lineClamp:1,children:e.title}),(0,i.jsxs)(a.z,{gap:2,flexWrap:"wrap",children:[(0,i.jsx)(q.Ex,{size:"sm",colorPalette:t?"red":"gray",children:t?"PDF":e.type||"free_text"}),t&&void 0!==e.file_size_bytes&&null!==e.file_size_bytes&&(0,i.jsx)(c.E,{fontSize:"xs",color:"gray.500",children:H(e.file_size_bytes)})]}),t&&e.original_filename&&(0,i.jsx)(c.E,{fontSize:"xs",color:"gray.500",lineClamp:1,title:e.original_filename,children:e.original_filename})]})]}),(0,i.jsxs)(a.z,{justifyContent:"flex-end",gap:1,mt:2,children:[(0,i.jsx)(b.K,{"aria-label":"Edit document",size:"xs",variant:"ghost",colorPalette:"gray",onClick:()=>(e=>{var t;ee(e),el(e.title),en(null!=(t=e.content)?t:""),V(!0)})(e),disabled:n,children:(0,i.jsx)(x.WXf,{})}),(0,i.jsx)(S.A,{triggerDelete:()=>ex({documentId:e.id}),alertMessage:'Are you sure you want to delete the document "'.concat(e.title,'"?'),mutate:es,variant:"icon",iconSize:"xs",isDisabled:n})]})]},e.id)})}),er&&0===er.length&&(0,i.jsx)(c.E,{fontSize:"sm",color:"gray.500",children:"No documents yet. Add one to provide reusable context to your agent."})]}),(0,i.jsx)($,{isOpen:g,onClose:em,title:"Add text document",onSubmit:ep,isSubmitting:ed,submitButtonText:"Create",isDisabled:n,children:(0,i.jsxs)(p.T,{gap:4,align:"stretch",flex:1,minHeight:"0",children:[(0,i.jsxs)(s.a,{flexShrink:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Title (snake_case)"}),(0,i.jsx)(y.p,{value:j,onChange:e=>w(e.target.value),placeholder:"e.g. shipping_policy",size:"sm",disabled:n,borderColor:ez(j)?void 0:"red.500"}),(0,i.jsx)(c.E,{fontSize:"xs",color:ez(j)?"gray.500":"red.500",mt:1,children:ew})]}),(0,i.jsxs)(s.a,{flex:1,minHeight:"200px",display:"flex",flexDirection:"column",w:"100%",children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Content"}),(0,i.jsx)(v.T,{value:k,onChange:e=>_(e.target.value),placeholder:"Enter document content",size:"sm",flex:1,minHeight:"280px",resize:"vertical",disabled:n})]})]})}),(0,i.jsx)($,{isOpen:C,onClose:ef,title:"Upload PDF document",onSubmit:ej,isSubmitting:eu,submitButtonText:"Upload",isDisabled:n,children:(0,i.jsxs)(p.T,{gap:4,align:"stretch",flex:1,minHeight:"0",children:[(0,i.jsxs)(s.a,{flexShrink:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Title (snake_case)"}),(0,i.jsx)(y.p,{value:A,onChange:e=>F(e.target.value),placeholder:"e.g. shipping_policy",size:"sm",disabled:n,borderColor:ez(A)?void 0:"red.500"}),(0,i.jsx)(c.E,{fontSize:"xs",color:ez(A)?"gray.500":"red.500",mt:1,children:ew})]}),(0,i.jsxs)(s.a,{flexShrink:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"PDF file"}),(0,i.jsx)("input",{ref:G,type:"file",accept:"application/pdf",style:{display:"none"},onChange:e=>{var t,l;let i=null!=(l=null==(t=e.target.files)?void 0:t[0])?l:null;if(!i){D(null),N(null);return}if(!M.includes(i.type)){D(null),N("Only PDF files are allowed. Received: ".concat(i.type||"unknown"));return}if(i.size>0x1400000){D(null),N("File too large. Maximum size is ".concat(20,"MB. Received: ").concat((i.size/1048576).toFixed(2),"MB"));return}N(null),D(i)}}),(0,i.jsxs)(a.z,{gap:3,flexWrap:"wrap",children:[(0,i.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>{var e;return null==(e=G.current)?void 0:e.click()},disabled:n||eu,children:[(0,i.jsx)(x.B88,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:T?"Choose a different file":"Choose PDF file"})]}),T&&(0,i.jsxs)(a.z,{gap:2,flex:1,minW:0,children:[(0,i.jsx)(x.jH2,{}),(0,i.jsx)(c.E,{fontSize:"sm",lineClamp:1,title:T.name,children:T.name}),(0,i.jsxs)(c.E,{fontSize:"xs",color:"gray.500",flexShrink:0,children:["(",H(T.size),")"]})]})]}),(0,i.jsx)(c.E,{fontSize:"xs",color:Q?"red.500":"gray.500",mt:2,children:null!=Q?Q:"PDF only. Maximum file size ".concat(20,"MB.")})]})]})}),(0,i.jsx)($,{isOpen:K,onClose:eb,title:ev?"Edit PDF document":"Edit document",onSubmit:ey,isSubmitting:eg,submitButtonText:"Save changes",isDisabled:n,children:(0,i.jsxs)(p.T,{gap:4,align:"stretch",flex:1,minHeight:"0",children:[(0,i.jsxs)(s.a,{flexShrink:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Title (snake_case)"}),(0,i.jsx)(y.p,{value:et,onChange:e=>el(e.target.value),placeholder:"e.g. shipping_policy",size:"sm",disabled:n,borderColor:ez(et)?void 0:"red.500"}),(0,i.jsx)(c.E,{fontSize:"xs",color:ez(et)?"gray.500":"red.500",mt:1,children:ew})]}),ev?(0,i.jsxs)(s.a,{flexShrink:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"File"}),(0,i.jsx)(s.a,{p:3,borderRadius:"md",borderWidth:"1px",borderLeftWidth:"4px",borderLeftColor:"red.500",children:(0,i.jsxs)(a.z,{gap:2,children:[(0,i.jsx)(s.a,{color:"red.500",children:(0,i.jsx)(x.jH2,{size:16})}),(0,i.jsxs)(p.T,{align:"stretch",gap:0,flex:1,minW:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",lineClamp:1,title:null!=(t=null==Z?void 0:Z.original_filename)?t:void 0,children:(null==Z?void 0:Z.original_filename)||"PDF file"}),(null==Z?void 0:Z.file_size_bytes)!==void 0&&(null==Z?void 0:Z.file_size_bytes)!==null&&(0,i.jsx)(c.E,{fontSize:"xs",color:"gray.500",children:H(null==Z?void 0:Z.file_size_bytes)})]})]})}),(0,i.jsx)(c.E,{fontSize:"xs",color:"gray.500",mt:2,children:"To replace the file, delete this document and upload a new one."})]}):(0,i.jsxs)(s.a,{flex:1,minHeight:"200px",display:"flex",flexDirection:"column",w:"100%",children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Content"}),(0,i.jsx)(v.T,{value:ei,onChange:e=>en(e.target.value),size:"sm",flex:1,minHeight:"280px",resize:"vertical",disabled:n})]})]})})]})};var V=l(98991);let Z=/^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,ee=["image/png","image/jpeg","image/jpg","image/webp"],et=e=>Z.test(e.trim()),el=e=>ee.includes(e.type)?e.size>0xa00000?"File too large. Maximum size is ".concat(10,"MB. Received: ").concat((e.size/1048576).toFixed(2),"MB"):null:"Only PNG, JPEG and WebP images are allowed. Received: ".concat(e.type||"unknown"),ei=e=>{let{agentId:t,isDisabled:l=!1}=e,{theme:n}=(0,X.D)(),o=null!=n?n:"dark",u="dark"===o?"gray.800":"gray.50",g="dark"===o?"gray.900":"gray.100",[m,f]=(0,h.useState)(!1),[v,w]=(0,h.useState)(""),[k,_]=(0,h.useState)([]),[C,E]=(0,h.useState)(null),A=(0,h.useRef)(null),[F,T]=(0,h.useState)(!1),[D,Q]=(0,h.useState)(null),[M,N]=(0,h.useState)(""),{data:G,mutate:O,error:Y}=((e,t)=>{let{user:l,loading:i}=(0,B.J)();return(0,P.Ay)(!i&&l&&e?["/fetch_agent_images?agent_id=".concat(e),l.accessToken]:null,e=>(0,R.we)(e).then(e=>e.data))})(t||null),{trigger:J,isMutating:U}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,I.A)(!l&&t&&e?["/upload_agent_image?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,R.gD)(e,{arg:l})})})(t||null),{trigger:H,isMutating:L}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,I.A)(!l&&t&&e?["/rename_image_folder?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,R.wf)(e,{arg:{old_folder:l.oldFolder,new_folder:l.newFolder}})})})(t||null),{trigger:K}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,I.A)(!l&&t&&e?["/delete_agent_image?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,R.Nw)(e,{arg:{image_id:l.imageId}})})})(t||null),{trigger:Z}=(e=>{let{user:t,loading:l}=(0,B.J)();return(0,I.A)(!l&&t&&e?["/delete_image_folder?agent_id=".concat(e),t.accessToken]:null,(e,t)=>{let{arg:l}=t;return(0,R.Nw)(e,{arg:{folder:l.folder}})})})(t||null),ee=(0,h.useMemo)(()=>{let e=new Map;
1return(G||[]).forEach(t=>{var l;let i=null!=(l=e.get(t.folder))?l:[];i.push(t),e.set(t.folder,i)}),Array.from(e.entries()).map(e=>{let[t,l]=e;return{folder:t,images:l}}).sort((e,t)=>e.folder.localeCompare(t.folder))},[G]),ei=ee.map(e=>e.folder),en=()=>{f(!1),w(""),_([]),E(null),A.current&&(A.current.value="")},er=async()=>{let e=v.trim();if(!e)return void z.X.create({title:"Validation Error",description:"Folder name is required.",type:"error",duration:3e3,closable:!0});if(!et(e))return void z.X.create({title:"Invalid folder name",description:"Folder must be snake_case (lowercase letters, digits, and underscores, e.g. 'infinity_kitchen'). It must start with a letter.",type:"error",duration:4e3,closable:!0});if(0===k.length)return void z.X.create({title:"No files selected",description:"Please select at least one image to upload.",type:"error",duration:3e3,closable:!0});try{for(let t of k)await J({file:t,folder:e});en(),O(),z.X.create({title:"Images uploaded",description:1===k.length?"The image has been added.":"".concat(k.length," images have been added."),type:"success",duration:3e3,closable:!0})}catch(t){let e=(null==t?void 0:t.message)||"Failed to upload images.";O(),z.X.create({title:"Error uploading images",description:e,type:"error",duration:5e3,closable:!0})}},es=()=>{T(!1),Q(null),N("")},ea=async()=>{if(!D)return;let e=M.trim();if(!e)return void z.X.create({title:"Validation Error",description:"Folder name is required.",type:"error",duration:3e3,closable:!0});if(!et(e))return void z.X.create({title:"Invalid folder name",description:"Folder must be snake_case (lowercase letters, digits, and underscores, e.g. 'infinity_kitchen'). It must start with a letter.",type:"error",duration:4e3,closable:!0});if(e===D)return void es();try{await H({oldFolder:D,newFolder:e}),es(),O(),z.X.create({title:"Folder renamed",description:"The folder has been renamed.",type:"success",duration:3e3,closable:!0})}catch(t){let e=(null==t?void 0:t.message)||"Failed to rename folder.";z.X.create({title:"Error renaming folder",description:e,type:"error",duration:5e3,closable:!0})}};if(Y)return(0,i.jsx)(c.E,{color:"red.500",children:"Failed to load images."});let eo="Lowercase letters, digits, and underscores only. Must start with a letter.",ed=e=>0===e.length||et(e);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(p.T,{gap:6,align:"stretch",children:[(0,i.jsxs)(s.a,{children:[(0,i.jsxs)(d.$,{colorScheme:"blue",disabled:l,size:"sm",alignSelf:"flex-start",onClick:()=>{w(""),_([]),E(null),f(!0)},children:[(0,i.jsx)(x.GGD,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:"Upload images"})]}),(0,i.jsx)(c.E,{fontSize:"xs",color:"gray.500",mt:2,children:"Group images into snake_case folders. The AI can show a folder's images to customers as a carousel using the folder name."})]}),ee.length>0&&ee.map(e=>{let{folder:t,images:n}=e;return(0,i.jsxs)(s.a,{p:4,borderRadius:"lg",borderWidth:"1px",bg:u,children:[(0,i.jsxs)(r.s,{align:"center",gap:2,mb:3,flexWrap:"wrap",children:[(0,i.jsx)(s.a,{color:"blue.500",children:(0,i.jsx)(x.fZZ,{size:18})}),(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"bold",title:t,children:t}),(0,i.jsxs)(q.Ex,{size:"sm",colorPalette:"gray",children:[n.length," ",1===n.length?"image":"images"]}),(0,i.jsx)(s.a,{flex:1}),(0,i.jsxs)(d.$,{size:"xs",variant:"ghost",onClick:()=>{w(t),_([]),E(null),f(!0)},disabled:l,children:[(0,i.jsx)(x.B88,{}),(0,i.jsx)(c.E,{fontSize:"xs",ml:1,children:"Add"})]}),(0,i.jsx)(b.K,{"aria-label":"Rename folder",size:"xs",variant:"ghost",colorPalette:"gray",onClick:()=>(e=>{Q(e),N(e),T(!0)})(t),disabled:l,children:(0,i.jsx)(x.WXf,{})}),(0,i.jsx)(S.A,{triggerDelete:()=>Z({folder:t}),alertMessage:'Are you sure you want to delete the folder "'.concat(t,'" and all ').concat(n.length," of its images? This cannot be undone."),mutate:O,variant:"icon",iconSize:"xs",isDisabled:l})]}),(0,i.jsx)(j.w,{mb:3}),(0,i.jsx)(W.r,{columns:{base:2,md:3,lg:4},gap:3,children:n.map(e=>{var t;return(0,i.jsxs)(s.a,{position:"relative",borderRadius:"md",borderWidth:"1px",overflow:"hidden",bg:g,children:[(0,i.jsxs)(s.a,{position:"relative",css:{aspectRatio:"1 / 1"},overflow:"hidden",children:[(0,i.jsx)(V._,{src:e.public_url,alt:e.original_filename||"Gallery image",width:"100%",height:"100%",objectFit:"cover",loading:"lazy"}),(0,i.jsx)(s.a,{position:"absolute",top:1,right:1,children:(0,i.jsx)(S.A,{triggerDelete:()=>K({imageId:e.id}),alertMessage:"Are you sure you want to delete this image".concat(e.original_filename?' ("'.concat(e.original_filename,'")'):"","?"),mutate:O,variant:"icon",iconSize:"xs",isDisabled:l})})]}),(0,i.jsxs)(s.a,{px:2,py:1.5,children:[(0,i.jsx)(c.E,{fontSize:"xs",lineClamp:1,title:null!=(t=e.original_filename)?t:void 0,children:e.original_filename||"image"}),void 0!==e.file_size_bytes&&null!==e.file_size_bytes&&(0,i.jsx)(c.E,{fontSize:"10px",color:"gray.500",children:(e=>null==e?"":e<1024?"".concat(e," B"):e<1048576?"".concat((e/1024).toFixed(1)," KB"):"".concat((e/1048576).toFixed(2)," MB"))(e.file_size_bytes)})]})]},e.id)})})]},t)}),0===ee.length&&(0,i.jsx)(c.E,{fontSize:"sm",color:"gray.500",children:"No images yet. Upload images into a folder so your agent can show them to customers."})]}),(0,i.jsx)($,{isOpen:m,onClose:en,title:"Upload images",onSubmit:er,isSubmitting:U,submitButtonText:"Upload",isDisabled:l,children:(0,i.jsxs)(p.T,{gap:4,align:"stretch",flex:1,minHeight:"0",children:[(0,i.jsxs)(s.a,{flexShrink:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Folder (snake_case)"}
1),(0,i.jsx)(y.p,{value:v,onChange:e=>w(e.target.value),placeholder:"e.g. infinity_kitchen",size:"sm",list:"image-folder-suggestions",disabled:l,borderColor:ed(v)?void 0:"red.500"}),ei.length>0&&(0,i.jsx)("datalist",{id:"image-folder-suggestions",children:ei.map(e=>(0,i.jsx)("option",{value:e},e))}),(0,i.jsxs)(c.E,{fontSize:"xs",color:ed(v)?"gray.500":"red.500",mt:1,children:[eo," Use an existing folder name to add to it."]})]}),(0,i.jsxs)(s.a,{flexShrink:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Images"}),(0,i.jsx)("input",{ref:A,type:"file",accept:"image/png,image/jpeg,image/webp",multiple:!0,style:{display:"none"},onChange:e=>{var t;let l=Array.from(null!=(t=e.target.files)?t:[]);if(0===l.length){_([]),E(null);return}for(let e of l){let t=el(e);if(t){_([]),E(t);return}}E(null),_(l)}}),(0,i.jsxs)(a.z,{gap:3,flexWrap:"wrap",children:[(0,i.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>{var e;return null==(e=A.current)?void 0:e.click()},disabled:l||U,children:[(0,i.jsx)(x.B88,{}),(0,i.jsx)(c.E,{fontSize:"sm",ml:2,children:k.length>0?"Choose different files":"Choose images"})]}),k.length>0&&(0,i.jsxs)(c.E,{fontSize:"sm",color:"gray.500",children:[k.length," ",1===k.length?"file":"files"," selected"]})]}),(0,i.jsx)(c.E,{fontSize:"xs",color:C?"red.500":"gray.500",mt:2,children:null!=C?C:"PNG, JPEG or WebP. Maximum ".concat(10,"MB per image.")}),k.length>0&&(0,i.jsx)(W.r,{columns:{base:3,md:4,lg:5},gap:2,mt:3,children:k.map((e,t)=>(0,i.jsx)(s.a,{css:{aspectRatio:"1 / 1"},borderRadius:"md",borderWidth:"1px",overflow:"hidden",bg:g,children:(0,i.jsx)(V._,{src:URL.createObjectURL(e),alt:e.name,width:"100%",height:"100%",objectFit:"cover"})},"".concat(e.name,"-").concat(t)))})]})]})}),(0,i.jsx)($,{isOpen:F,onClose:es,title:"Rename folder",onSubmit:ea,isSubmitting:L,submitButtonText:"Save",isDisabled:l,children:(0,i.jsx)(p.T,{gap:4,align:"stretch",flex:1,minHeight:"0",children:(0,i.jsxs)(s.a,{flexShrink:0,children:[(0,i.jsx)(c.E,{fontSize:"sm",fontWeight:"semibold",mb:2,children:"Folder name (snake_case)"}),(0,i.jsx)(y.p,{value:M,onChange:e=>N(e.target.value),placeholder:"e.g. infinity_kitchen",size:"sm",disabled:l,borderColor:ed(M)?void 0:"red.500"}),(0,i.jsx)(c.E,{fontSize:"xs",color:ed(M)?"gray.500":"red.500",mt:1,children:eo}),(0,i.jsx)(c.E,{fontSize:"xs",color:"gray.500",mt:2,children:"Renaming only re-labels the folder. Images already shown in past conversations keep working."})]})})})]})};var en=l(90096),er=l(54616);let es=[{id:"faqs",label:"FAQs",icon:(0,i.jsx)(x.H9b,{})},{id:"documents",label:"Documents",icon:(0,i.jsx)(x.s_k,{})},{id:"images",label:"Images",icon:(0,i.jsx)(x.fZZ,{})}],ea=(0,n.A)(function(){let e=(0,en._)(),t=(0,g.useRouter)(),l=function(e){let t=Array.isArray(e)?e[0]:e;return"documents"===t||"images"===t||"faqs"===t?t:"faqs"}(t.query.tab);return(0,i.jsx)(er.G,{scope:"agent_config",excludeRoles:[3],children:(0,i.jsx)(r.s,{w:"100%",flexDirection:"column",alignItems:"center",children:(0,i.jsxs)(s.a,{w:"100%",position:"relative",children:[(0,i.jsxs)(a.z,{justify:"space-between",align:"center",mb:"1",flexWrap:"wrap",gap:3,children:[(0,i.jsx)(o.D,{size:"lg",children:"Knowledge"}),(0,i.jsx)(a.z,{gap:"2px",p:"2px",borderWidth:"1px",borderColor:"gray.200",borderRadius:"md",children:es.map(e=>{let{id:n,label:r,icon:s}=e;return(0,i.jsxs)(d.$,{size:"xs",variant:l===n?"solid":"ghost",colorPalette:l===n?"blue":"gray",onClick:()=>{t.replace({pathname:t.pathname,query:{...t.query,tab:n}},void 0,{shallow:!0})},children:[s," ",r]},n)})})]}),(0,i.jsx)(c.E,{fontSize:"sm",color:"gray.500",mb:"4",children:"FAQs, documents, and images the agent can use to answer customers."}),"faqs"===l&&(0,i.jsx)(D,{agentId:e}),"documents"===l&&(0,i.jsx)(K,{agentId:e}),"images"===l&&(0,i.jsx)(ei,{agentId:e}),(0,i.jsx)(u.h,{my:"2rem"})]})})})})},54616:(e,t,l)=>{"use strict";l.d(t,{G:()=>d});var i=l(37876),n=l(14232),r=l(89099),s=l(39822),a=l(95563),o=l(7446);function d(e){let{scope:t,children:l,fallback:d,excludeRoles:c}=e,u=(0,r.useRouter)(),{isLoading:h,hasAll:g,roleId:x,isGameMaster:m}=(0,o.bV)(),p=Array.isArray(t)?t:[t],f=!m&&!!(null==c?void 0:c.includes(x)),j=!h&&g(...p)&&!f,b=!h&&!j;return((0,n.useEffect)(()=>{b&&!d&&u.replace("/forbidden")},[b,d,u]),h)?(0,i.jsx)(s.a,{w:"100%",minH:"60vh",display:"flex",alignItems:"center",justifyContent:"center",children:(0,i.jsx)(a.y,{size:"md"})}):j?(0,i.jsx)(i.Fragment,{children:l}):d?(0,i.jsx)(i.Fragment,{children:d}):null}},67468:(e,t,l)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/agents/[agent_id]/knowledge",function(){return l(51978)}])},91553:(e,t,l)=>{"use strict";l.d(t,{A:()=>h});var i=l(37876),n=l(14232),r=l(9463),s=l(30488),a=l(72953),o=l(97120),d=l(89099),c=l(70294),u=l(61385);let h=e=>{let{triggerDelete:t,alertMessage:l,deleteParams:h,redirectRoute:g,mutate:x,isDisabled:m=!1,buttonText:p="Delete",modalOnClose:f,variant:j="solid",className:b,iconSize:y="md"}
1=e,[v,w]=(0,n.useState)(!1),z=()=>w(!1),S=(0,n.useRef)(null),k=(0,d.useRouter)(),_=async()=>{try{let e=await t(h);u.X.create({title:"Success",description:e.message,type:"success",duration:9e3,closable:!0}),x&&x(),g&&k.push(g),z(),f&&f()}catch(e){console.error(e),u.X.create({title:"Error",description:e.message,type:"error",duration:9e3,closable:!0})}};return(0,i.jsxs)(i.Fragment,{children:["icon"===j?(0,i.jsx)(r.K,{className:b,colorPalette:"red","aria-label":"Delete",variant:"ghost",onClick:()=>w(!0),disabled:m,size:y,children:(0,i.jsx)(c.IXo,{})}):"underlined"===j?(0,i.jsx)(s.E,{className:b,cursor:"pointer",fontWeight:"bold",fontSize:"xs",onClick:()=>w(!0),opacity:m?.4:1,pointerEvents:m?"none":"auto",_hover:{textDecoration:"underline"},children:p}):(0,i.jsx)(a.$,{className:b,colorPalette:"red",variant:"solid"===j||"outline"===j||"ghost"===j||"subtle"===j||"surface"===j||"plain"===j?j:"solid",onClick:()=>w(!0),disabled:m,size:"sm",children:p}),(0,i.jsxs)(o.Dz,{open:v,onOpenChange:e=>e.open?w(!0):z(),placement:"center",motionPreset:"slide-in-bottom",children:[(0,i.jsx)(o.Xi,{}),(0,i.jsxs)(o.Cf,{maxW:"md",position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)",margin:"0",children:[(0,i.jsx)(o.c7,{fontSize:"lg",fontWeight:"bold",children:"Confirm Deletion"}),(0,i.jsx)(o.R4,{children:(0,i.jsx)(s.E,{children:l})}),(0,i.jsxs)(o.Es,{gap:3,children:[(0,i.jsx)(a.$,{ref:S,onClick:z,variant:"outline",children:"Cancel"}),(0,i.jsx)(a.$,{colorPalette:"red",variant:"solid",onClick:_,children:p})]}
1),(0,i.jsx)(o.tK,{})]})]})]})}}},e=>{e.O(0,[4e3,9704,636,6593,8792],()=>e(e.s=67468)),_N_E=e.O()}]);
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.