1import{r as l,gN as as,j as e,g as de,am as ke,an as ze,z as L,ao as Me,a2 as me,hM as ts,bM as ns,n as C,gq as Te,P as ue,B as xe,q as N,T as y,L as S,S as k,b4 as rs,b5 as os,b6 as is,hN as ls,du as cs,D as P,Q as Le,R as Pe,U as Fe,_ as De,el as Ee,Y as Ae,em as Qe,en as Q,dY as R,aF as pe,b as X,af as U,ag as W,bK as _,ah as B,t as ds,cE as ms,c3 as ye,cr as hs,c7 as us,eV as xs,fD as ps,f as V,dq as J,hO as gs,u as G,Z as he,a as js,d as fs,cu as bs,hP as vs,cv as ws,er as Cs,es as Ns,et as ie,hQ as le,K,k as ge,aG as ys,aH as Ss,aI as ks,aJ as zs,aK as Ms,aL as Ts,aM as Ls,aN as Ps,dz as Fs,dx as qe,dy as Ue,y as Ds,dr as Es,ap as As}from"./index-CX0TxBUr.js";import{P as je}from"./PageContainer-DlMSxSPT.js";import{P as fe}from"./PageHeader-DFECMuDI.js";import{C as Qs}from"./ChatHeader-DQkQ5s1Y.js";import{C as qs,W as Us}from"./Watermark--9ws6lxQ.js";import{r as We,d as Ws,g as _s,b as Bs,T as Rs,u as Is}from"./chatbot-config-DXj-f8te.js";import{E as Ys}from"./ellipsis-C-saVPCf.js";import{c as H}from"./useChatbotConfigUpdateConfig-LNPT97A9.js";import{I as Os}from"./ImageCropDialog-Ce1MjfHG.js";import{D as ce,T as $s}from"./ThemeCustomizeForm-UztdxFe6.js";import{t as Z}from"./zod-DpDyoOGK.js";import{I as _e}from"./info-BjGxnZVl.js";import{o as ee,e as F,i as Vs,s as f}from"./types-DIt0oyuo.js";import{N as Gs}from"./NotAuthorized-B44MGxnX.js";import"./MessageContent-BBtc7dd5.js";import"./url-BP6whR61.js";import"./helpdesk-providers-DS9dyWiI.js";import"./SiZendesk-CsCKj7A6.js";import"./getActionIcon-Csesw1PF.js";import"./MarkDown-Cl8oMUMD.js";import"./useDataSourceList-7yEfA-bw.js";import"./CodeBlock-BMviCqUv.js";import"./bundle-full-BT1VJ71W.js";import"./calendar-days-DUQvoB_I.js";import"./use-zod-form-D3NivF-1.js";import"./circle-alert-DveCJbSY.js";import"./proxy-werW2hQm.js";function Se({chatbotId:r,name:d,config:o,messages:s,className:a,containerClassName:t}){var m;const g=o.icon,u=o.placeholder,h=o.removeWatermark,b=((m=o.initQuestions)==null?void 0:m.split(` 2`))||[],v=l.useRef(null),[i,c]=l.useState("");l.useEffect(()=>{const z=We(o.theme);as(v==null?void 0:v.current,z)},[o.theme]);const j=e.jsx("div",{className:"flex w-full flex-row",children:e.jsxs("form",{className:"mx-auto flex min-h-12 w-full items-center rounded-xl border border-border p-2 shadow-[0_1px_1px_rgba(0,0,0,0.02),_0_2px_2px_rgba(0,0,0,0.02),_0_4px_4px_rgba(0,0,0,0.02),_0_8px_8px_rgba(0,0,0,0.02)]",children:[e.jsx("textarea",{id:"message",placeholder:u,className:"field-sizing-content ml-2 max-h-20 min-h-5 flex-1 resize-none border-none bg-transparent text-sm text-foreground shadow-none outline-none placeholder:text-muted-foreground/60 focus-visible:ring-0 focus-visible:ring-offset-0",autoComplete:"off",rows:2,value:i,onChange:z=>c(z.target.value)}),e.jsxs(L,{type:"button",size:"icon",onClick:z=>{z.preventDefault(),C.info("It's under preview mode. You cannot send messages here.")},className:"size-8",variant:"default",children:[e.jsx(ns,{className:"size-5"}),e.jsx("span",{className:"sr-only",children:"Send"})]})]})}),x=e.jsx(Qs,{name:d,avatar:g,className:"rounded-t-3xl p-4",children:e.jsx("div",{className:"flex flex-row items-center gap-2",children:e.jsxs(ke,{children:[e.jsx(ze,{asChild:!0,children:e.jsx(L,{size:"icon",variant:"ghost",className:"ml-auto",children:e.jsx(Ys,{className:"h-4 w-4"})})}),e.jsx(Me,{children:e.jsxs(me,{className:"flex flex-row",onClick:()=>{window.open(Ws(r,o),"_blank")},children:[e.jsx(ts,{className:"mr-2 h-4 w-4"}),"Preview"]})})]})})});return e.jsxs("div",{ref:v,className:de("flex min-h-0 w-full max-w-md flex-col overflow-hidden rounded-3xl border bg-card shadow-sm md:max-w-xs lg:max-w-xl","h-full max-h-full",t),children:[x,e.jsx(qs,{messages:s,input:"",setInput:()=>{},questions:b,keepShowingQuestions:!0,readonly:!0,className:de("min-h-0 flex-1",a),messagesClassName:"p-4",inputComponent:j,children:h?e.jsx("div",{className:"pb-2 text-center"}):e.jsx("div",{className:"pb-2 text-center",children:e.jsx(Us,{chatbotId:r,className:"text-xs text-muted-foreground"})})})]})}function Ks({iconUrl:r}){const{versions:d}=Ee(),o=Te(),[s,a]=l.useState(!1),[t,g]=l.useState(""),[u,h]=l.useState(""),b=l.useRef(null),v=o.watch("icon");l.useEffect(()=>{if(v instanceof File){const x=URL.createObjectURL(v);return h(x),()=>{URL.revokeObjectURL(x)}}else h("")},[v]);const i=l.useCallback(x=>{var E;const m=(E=x.target.files)==null?void 0:E[0];if(!m||!["image/jpeg","image/jpg","image/png","image/svg+xml"].includes(m.type))return;const D=new FileReader;D.addEventListener("load",()=>{g(D.result),a(!0)}),D.readAsDataURL(m)},[]),c=l.useCallback(x=>{o.setValue("icon",x,{shouldDirty:!0}),o.trigger("icon")},[o]),j=l.useCallback(()=>{var x;(x=b.current)==null||x.click()},[]);return e.jsxs(e.Fragment,{children:[e.jsx(ue,{children:e.jsxs(xe,{className:"space-y-6 py-6",children:[e.jsx(N,{control:o.control,name:"icon",render:()=>e.jsxs(y,{children:[e.jsx(S,{children:"Chatbot Icon"}),e.jsx(k,{children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(rs,{className:"size-16 border-2 border-border",children:[e.jsx(os,{src:u||r,alt:"Chatbot icon"}),e.jsx(is,{children:e.jsx(ls,{className:"size-6 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex w-fit flex-col gap-2",children:[e.jsx("input",{ref:b,type:"file",accept:"image/jpeg,image/jpg,image/png,image/svg+xml",onChange:i,className:"hidden"}),e.jsxs(L,{type:"button",variant:"outline",size:"sm",onClick:j,className:"w-fit",children:[e.jsx(cs,{className:"mr-2 size-4"}),"Upload Image"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Max size 1MB, format: jpg, jpeg, png, svg"})]})]})}),e.jsx(P,{})]})}),e.jsx(N,{control:o.control,name:"gptVersion",render:({field:x})=>e.jsxs(y,{children:[e.jsx(S,{children:"LLM"}),e.jsx(k,{children:e.jsxs(Le,{...x,onValueChange:m=>{x.onChange(m),o.trigger("gptVersion")},children:[e.jsx(Pe,{className:"w-full",children:e.jsx(Fe,{placeholder:"Select LLM"})}),e.jsx(De,{children:d.map(m=>e.jsx(Ae,{value:m,children:e.jsxs("div",{className:"flex flex-row items-center gap-2",children:[m.startsWith("gpt")?e.
2jsx(Q.gpt,{className:"size-4"}):null,m.startsWith("claude")?e.jsx(Q.claude,{className:"size-4"}):null,m.startsWith("gemini")?e.jsx(Q.gemini,{className:"size-4"}):null,Qe[m]]})},m))})]})}),e.jsx(R,{children:"Select the large language model used by your chatbot"}),e.jsx(P,{})]})}),e.jsx(N,{control:o.control,name:"citation",render:({field:x})=>e.jsxs(y,{className:"flex flex-row items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(S,{children:"Citation"}),e.jsx(R,{children:"Enable to show the data source in the chatbot response"})]}),e.jsx(k,{children:e.jsx(pe,{checked:x.value==="on",onCheckedChange:m=>{x.onChange(m?"on":"off"),o.trigger("citation")}})})]})})]})}),e.jsx(Os,{open:s,onOpenChange:a,imageSrc:t,onCropComplete:c,aspectRatio:1})]})}function Hs(){const{t:r}=X(),d=Te(),o={"AI Agent":`### Role 3You are an AI assistant who helps users with their inquiries, issues and requests. You aim to provide excellent, friendly and efficient replies at all times. If a question is not clear, ask clarifying questions. 4 5### Constraints 61. Prioritize the responses on provided data source. 72. Do not answer questions or perform tasks that are not related to your role.`,"Customer Support":`### Role 8You are a customer support specialist who assists customers with their questions, concerns, and technical issues. You provide helpful, empathetic, and professional support to ensure customer satisfaction. 9 10### Constraints 111. Always maintain a friendly and professional tone. 122. Focus on resolving customer issues efficiently. 133. Escalate complex technical issues when necessary. 144. Do not provide information outside of your support scope.`,"Knowledge Management":`### Role 15You are a knowledge management assistant who helps users find, organize, and understand information from available resources. You excel at searching through documents and providing accurate, well-sourced answers. 16 17### Constraints 181. Always cite sources when providing information. 192. Only provide information that can be verified from available documents. 203. Ask clarifying questions to better understand information requests. 214. Do not speculate or provide information not found in the knowledge base.`,Sales:`### Role 22You are a sales assistant who helps potential customers understand products and services. You provide informative, persuasive, and helpful responses to guide customers through their buying journey. 23 24### Constraints 251. Focus on highlighting product benefits and value propositions. 262. Provide accurate pricing and feature information only. 273. Do not make promises about features or pricing not in your knowledge base.`},s=a=>{if(!a)return"Custom prompt";for(const[t,g]of Object.entries(o))if(a===g)return t;return"Custom prompt"};return e.jsx(ue,{children:e.jsxs(xe,{className:"space-y-6 py-6",children:[e.jsx(N,{control:d.control,name:"initMessages",render:({field:a})=>{var t;return e.jsxs(y,{children:[e.jsxs(S,{className:"flex items-center gap-1",children:[r("initial-messages"),e.jsx("span",{className:"text-xs text-muted-foreground",children:`(${((t=a.value)==null?void 0:t.split(` 28`).length)??0}/4)`}),e.jsxs(U,{children:[e.jsx(W,{children:e.jsx(_,{className:"h-4 w-4"})}),e.jsx(B,{className:"max-w-xs text-balance",children:"Greet users when they open the chat, helping them get started with common questions or topics."})]})]}),e.jsx(k,{children:e.jsx(ce,{value:a.value,onChange:a.onChange,placeholder:r("hi-how-can-i-help-you"),addPlaceholder:"Add another message...",maxItems:4,maxLength:200})}),e.jsx(P,{})]})}}),e.jsx(N,{control:d.control,name:"initQuestions",render:({field:a})=>{var t;return e.jsxs(y,{children:[e.jsxs(S,{className:"flex items-center gap-1",children:[r("suggest-questions"),e.jsx("span",{className:"ml-1.5 text-xs text-muted-foreground",children:`(${((t=a.value)==null?void 0:t.split(` 29`).length)??0}/8)`}),e.jsxs(U,{children:[e.jsx(W,{children:e.jsx(_,{className:"h-4 w-4"})}),e.jsx(B,{className:"max-w-xs text-balance",children:"Questions that appear as clickable suggestions when users open the chat, helping them get started with common questions or topics."})]})]}),e.jsx(k,{children:e.jsx(ce,{value:a.value,onChange:a.onChange,placeholder:r("can-you-summary-this-doc"),addPlaceholder:"Add another question...",maxItems:8,maxLength:100})}),e.jsx(P,{})]})}}),e.jsx(N,{control:d.control,name:"keepShowingQuestions",render:({field:a})=>e.jsxs(y,{className:"flex flex-row items-center justify-between rounded-lg border border-primary/5 bg-primary/10 p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs(S,{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Keep showing suggested questions"}),e.jsxs(U,{children:[e.jsx(W,{children:e.jsx(_,{className:"h-4 w-4"})}),e.jsx(B,{className:"max-w-xs text-balance",children:"When enabled, suggested questions will continue to appear even after the user sends their first message. When disabled, they disappear after the first interaction."})]})]}),e.jsx(R,{children:"Control whether suggested questions remain visible after the user's first message"})]}),e.jsx(k,{children:e.jsx(pe,{checked:a.value==="on",onCheckedChange:t=>a.onChange(t?"on":"off")})})]})}),e.jsx(N,{control:d.control,name:"messageBubbles",render:({field:a})=>{var t;return e.jsxs(y,{children:[e.jsxs(S,{className:"flex items-center gap-1",children:[r("bubble-messages"),e.jsx("span",{className:"text-xs text-muted-foreground",children:`(${((t=a.value)==null?void 0:t.split(` 30`).length)??0}/3)`}),e.jsxs(U,{children:[e.jsx(W,{children:e.jsx(_,{className:"h-4 w-4"})}),e.jsx(B,{className:"max-w-xs text-balance",children:"Messages that appear above the chatbot icon to grab user attention."})]})]}),e.jsx(k,{children:e.jsx(ce,{value:a.value,onChange:a.onChange,placeholder:r("bubble-messages-placeholder"),addPlaceholder:"Add another bubble message...",max
30Items:3,maxLength:100})}),e.jsx(P,{})]})}}),e.jsx(N,{control:d.control,name:"placeholder",render:({field:a})=>e.jsxs(y,{children:[e.jsx(S,{children:r("message-placeholder")}),e.jsx(k,{children:e.jsx(ds,{placeholder:r("type-your-question-here"),...a})}),e.jsx(P,{})]})}),e.jsx(N,{control:d.control,name:"prompt",render:({field:a})=>{var h;const t=r("type-your-prompt-here"),g=((h=a.value)==null?void 0:h.length)||0,u=s(a.value||"");return e.jsxs(y,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{className:"flex items-center gap-1",children:["AI Prompt",e.jsxs(U,{children:[e.jsx(W,{children:e.jsx(_,{className:"h-4 w-4"})}),e.jsx(B,{className:"max-w-xs text-balance",children:"Define how the AI should behave and respond. Use templates for common use cases or create your own custom prompt."})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[g," characters"]}),e.jsxs(ke,{children:[e.jsx(ze,{asChild:!0,children:e.jsxs(L,{type:"button",variant:"outline",size:"sm",className:"h-7 gap-1 border-border bg-background px-2 text-xs hover:bg-muted/50",children:[e.jsx("span",{className:"max-w-24 truncate",children:u}),e.jsx("svg",{className:"h-3 w-3 opacity-50",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"m4.5 6 3 3 3-3",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})})]})}),e.jsxs(Me,{align:"end",className:"w-80",children:[e.jsx(ms,{className:"text-xs font-medium text-muted-foreground",children:"Template Options"}),e.jsxs(me,{onClick:()=>a.onChange(""),className:"flex cursor-pointer items-start justify-between p-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"font-medium",children:"Custom prompt"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Write your own AI behavior instructions"}),e.jsx("span",{className:"rounded bg-blue-50 px-1.5 py-0.5 text-xs text-blue-600",children:"Press Tab for default template"})]}),u==="Custom prompt"&&e.jsx(ye,{className:"mt-1 h-4 w-4 text-primary"})]}),e.jsx(hs,{}),Object.entries(o).map(([b,v])=>{const i=v.split(` 31`).slice(0,2).join(" ").slice(0,80)+"...";return e.jsxs(me,{onClick:()=>a.onChange(v),className:"flex cursor-pointer items-start justify-between p-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[e.jsx("span",{className:"font-medium",children:b}),e.jsx("span",{className:"line-clamp-2 text-xs text-muted-foreground",children:i})]}),u===b&&e.jsx(ye,{className:"ml-2 mt-1 h-4 w-4 flex-shrink-0 text-primary"})]},b)})]})]})]})]}),e.jsx(k,{children:e.jsx("div",{className:"relative",children:e.jsx(us,{className:"min-h-48 resize-y pr-12",placeholder:a.value?t:`${t} 32 33Tip: Press Tab to insert default template`,...a,value:a.value||"",onKeyDown:b=>{b.key==="Tab"&&(!a.value||a.value==="")&&(b.preventDefault(),a.onChange(t))}})})}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:a.value?u==="Custom prompt"?"Custom AI behavior defined":`Using ${u} template`:"Empty prompt will use system default behavior"}),g>32e3&&e.jsx("span",{className:"text-amber-600",children:"Long prompts may affect response speed"})]}),e.jsx(P,{})]})}})]})})}const Zs=ee({gptVersion:F(qe).default(Ue).optional(),icon:Vs(File).refine(r=>Fs(r),{message:"Chatbot icon file size cannot be larger than 1Mb"}).optional(),citation:F(["on","off"]).default("on").optional(),dashboardCitation:F(["on","off"]).default("on").optional()}),Js=ee({initMessages:f().optional(),initQuestions:f().optional(),placeholder:f().optional(),prompt:f().max(32e3,{message:"Prompt is too long"}).optional(),messageBubbles:f().optional(),keepShowingQuestions:F(["on","off"]).default("off")}),Xs=ee({mode:F(Rs).default("light"),bgColor:f(),borderColor:f(),primaryFontColor:f(),primaryBgColor:f(),botMessageFontColor:f(),botMessageBgColor:f(),chatActionFontColor:f(),chatActionBgColor:f(),textFontColor:f(),textBgColor:f(),placeholderFontColor:f()});function ea({chatbotId:r,name:d,iconUrl:o,removeWatermark:s,leadGeneration:a,defaultCommonValues:t,defaultTextualValues:g,defaultThemeValues:u}){const{t:h}
33=X(),[b,v]=xs("tab",ps.withDefault("common")),i=V({resolver:Z(Zs),defaultValues:{gptVersion:J(t==null?void 0:t.gptVersion),citation:t==null?void 0:t.citation,dashboardCitation:t==null?void 0:t.dashboardCitation}}),c=V({resolver:Z(Js),defaultValues:{...g}}),j=V({resolver:Z(Xs),defaultValues:u});l.useEffect(()=>{t&&i.reset({...t,gptVersion:J(t.gptVersion)})},[t,i]),l.useEffect(()=>{g&&c.reset(g)},[g,c]),l.useEffect(()=>{u&&j.reset(u)},[u,j]);const x=i.watch("icon")&&i.formState.isValid?URL.createObjectURL(gs(i.watch("icon"))):o,m=c.watch(),{messages:z,leadMessage:D}=l.useMemo(()=>_s(m.initMessages,m.initQuestions,r,a),[r,m.initMessages,m.initQuestions]),{trigger:E,isMutating:Be}=G(r,async(n,{arg:p})=>H(r,p),{onSuccess:()=>{he(`/api/v2/chatbot-config/${r}`),i.reset(i.getValues()),C.success(h("successfully-saved"))},onError:n=>{C.error(h("failed-to-save"),{description:n.message})}}),{triggerUpload:be}=Bs(r,{onSuccess:n=>{E({...i.getValues(),icon:`${n}?v=${Date.now()}`}).catch(()=>{C.error("Failed to update icon customization")})},onError:n=>{console.log("Failed to upload icon",n),C.error("Failed to upload icon")}}),{trigger:ve,isMutating:Re}=G(r,async(n,{arg:p})=>H(r,p),{onSuccess:()=>{he(`/api/v2/chatbot-config/${r}`),c.reset(c.getValues()),C.success(h("successfully-saved"))},onError:n=>{C.error(h("failed-to-save"),{description:n.message})}}),se=l.useCallback(async n=>{n.icon?await be(n.icon):await E({gptVersion:n.gptVersion,citation:n.citation,dashboardCitation:n.dashboardCitation})},[E,be]),ae=l.useCallback(n=>{ve({initMessages:n.initMessages??"",initQuestions:n.initQuestions??"",messageBubbles:n.messageBubbles??"",placeholder:n.placeholder??"",prompt:n.prompt??"",keepShowingQuestions:n.keepShowingQuestions})},[ve]),{trigger:we,isMutating:Ie}=G(r,async(n,{arg:p})=>H(r,p),{onSuccess:()=>{j.reset(j.getValues()),C.success(h("successfully-saved"))},onError:n=>{C.error(h("failed-to-save"),{description:n.message})}}),te=l.useCallback(n=>{const{mode:p,bgColor:M,borderColor:w,primaryFontColor:T,primaryBgColor:Ge,botMessageFontColor:Ke,botMessageBgColor:He,chatActionFontColor:Ze,chatActionBgColor:Je,textFontColor:Xe,textBgColor:es,placeholderFontColor:ss}=n;we({theme:{mode:p,bgColor:M,borderColor:w,primaryFontColor:T,primaryBgColor:Ge,botMessageFontColor:Ke,botMessageBgColor:He,chatActionFontColor:Ze,chatActionBgColor:Je,textFontColor:Xe,textBgColor:es,placeholderFontColor:ss}})},[we]),I=i.formState.isDirty,Y=c.formState.isDirty,O=j.formState.isDirty,A=I||Y||O,ne=Be||Re||Ie,Ye=l.useCallback(async()=>{const n=[];I&&n.push(new Promise((p,M)=>{i.handleSubmit(async w=>{try{await se(w),p()}catch(T){M(T)}},()=>M(new Error("Common form validation failed")))()})),Y&&n.push(new Promise((p,M)=>{c.handleSubmit(w=>{ae(w),p()},()=>M(new Error("Textual form validation failed")))()})),O&&n.push(new Promise((p,M)=>{j.handleSubmit(w=>{te(w),p()},()=>M(new Error("Theme form validation failed")))()}));try{await Promise.all(n)}catch{}},[I,Y,O,i,c,j,se,ae,te]),re=l.useCallback(()=>{i.reset(),c.reset(),j.reset()},[i,c,j]),[Oe,$]=l.useState(!1),[q,oe]=l.useState(null),Ce=js(),Ne=fs();l.useEffect(()=>{if(!A)return;const n=p=>{const w=p.target.closest("a");if(w!=null&&w.href&&A){const T=new URL(w.href);T.origin===window.location.origin&&T.pathname!==Ne.pathname&&(p.preventDefault(),oe(T.pathname+T.search+T.hash),$(!0))}};return document.addEventListener("click",n,!0),()=>document.removeEventListener("click",n,!0)},[A,Ne.pathname]),l.useEffect(()=>{const n=p=>{A&&(p.preventDefault(),p.returnValue="")};return window.addEventListener("beforeunload",n),()=>window.removeEventListener("beforeunload",n)},[A]);const $e=l.useCallback(()=>{q&&(re(),$(!1),setTimeout(()=>{Ce(q.startsWith("/u")?q.replace("/u/","/"):q),oe(null)},0))},[q,re,Ce]),Ve=l.useCallback(()=>{$(!1),oe(null)},[]);return e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto scrollbar-none",children:e.jsxs(je,{className:"pb-24",children:[e.jsx(fe,{heading:h("chatbots.customize.heading"),text:h("chatbots.customize.description"),children:e.jsxs(bs,{children:[e.jsx(vs,{asChild:!0,children:e.jsx(L,{size:"sm",variant:"outline",className:"lg:hidden",children:h("preview")})}),e.jsx(ws,{children:e.jsx("div",{className:"p-4",children:e.jsx(Se,{chatbotId:r,name:d,config:{theme:j.watch(),icon:x,initQuestions:m.initQuestions,placeholder:m.placeholder,removeWatermark:s?"on":"off"},messages:z})})})]})}),e.jsx("div",{className:"space-y-4",children:e.jsxs(Cs,{value:b,onValueChange:v,children:[e.jsxs(Ns,{className:"mb-6 max-w-md",children:[e.jsx(ie,{value:"common",children:e.jsxs("span",{className:"flex items-center gap-2",children:["Common",I&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500"})]})}),e.jsx(ie,{value:"textual",children:e.jsxs("span",{className:"flex items-center gap-2",children:["Textual",Y&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500"})]})}),e.jsx(ie,{value:"theme",children:e.jsxs("span",{className:"flex items-center gap-2",children:["Theme",O&&e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-amber-500"})]})})]}),e.jsx(le,{value:"common",className:"space-y-4",children:e.jsx(K,{...i,children:e.jsx("form",{onSubmit:i.handleSubmit(se),children:e.jsx(Ks,{iconUrl:o})})})}),e.jsx(le,{value:"textual",children:e.jsx(K,{...c,children:e.jsx("form",{onSubmit:c.handleSubmit(ae),children:e.jsx(Hs,{})})})}),e.jsx(le,{value:"theme",children:e.jsx(K,{...j,children:e.jsx("form",{onSubmit:j.handleSubmit(te),children:e.jsx($s,{})})})})]})})]})}),A&&e.jsx("div",{className:"flex-shrink-0 border-t bg-background shadow-lg",children:e.jsxs("div",{className:"flex h-16 items-center justify-between px-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(_e,{className:"h-4 w-4"}),e.jsx("span",{children:"You have unsaved changes"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:re,disabled:ne,children:"Discard"}),e.jsxs(L,{size:"sm",onClick:Ye,disabled:ne,children:[ne&&e.jsx(ge,{className:"mr-2 h-4 w-4 animate-spin"}),"Save All Changes"]})]})]})})]}),e.jsxs("div",{className:"hidden h-full min-h-0 flex-col overflow-y-hidden border-l bg-sidebar lg:flex lg:w-[420px] xl:w-[470px]",children:[e.jsx("div",{className:"p-6",children:e.jsx("h2",{className:"text-xl font-medium",children:"Preview"})}),e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6 pt-0",children:e.jsx(Se,{chatbotId:r,name:d,config:{theme:j.watch(),icon:x,initQuestions:m.initQuestions,placeholder:m.placeholder,removeWatermark:s?"on":"off"},messages:D?[...z,D]:z})})]}),e.jsx(ys,{open:Oe,onOpenChange:$,children:e.jsxs(Ss,{children:[e.jsxs(ks,{children:[e.jsx(zs,{children:"Unsaved Changes"}),e.jsx(Ms,{children:"You have unsaved changes. Are you sure you want to leave this page? Your changes will be lost."})]}),e.jsxs(Ts,{children:[e.jsx(Ls,{onClick:Ve,children:"Stay on Page"}),e.jsx(Ps,{onClick:$e,className:de("bg-destructive text-destructive-foreground hover:bg-destructive/90"),children:"Leave Without Saving"})]})]})})]})}const sa=ee({gptVersion:F(qe).default(Ue).optional(),dashboardCitation:F(["on","off"]).default("on").optional()});function aa({chatbotId:r,defaultValues:d}){const{t:o}=X(),{versions:s}=Ee(),a=V({resolver:Z(sa),defaultValues:{gptVersion:J(d==null?void 0:d.gptVersion),dashboardCitation:d==null?void 0:d.dashboardCitation}});l.useEffect(()=>{d&&a.reset({...d,gptVersion:J(d.gptVersion)})},[d,a]);const{trigger:t,isMutating:g}=G(r,async(i,{arg:c})=>H(r,c),{onSuccess:()=>{he(`/api/v2/chatbot-config/${r}`),a.reset(a.getValues()),C.success(o("successfully-saved"))},onError:i=>{C.error(o("failed-to-save"),{description:i.message})}}),u=l.useCallback(async i=>{await t({gptVersion:i.gptVersion,dashboardCitation:i.dashboardCitation})},[t]),h=a.formState.isDirty,b=l.useCallback(()=>{a.reset()},[a]),v=l.useCallback(()=>{a.handleSubmit(u)()},[a,u]);return e.jsx("div",{className:"flex h-full min-h-0",children:e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto scrollbar-none",children:e.jsxs(je,{className:"pb-24",children:[e.jsx(fe,{heading:o("chatbots.customize.heading"),text:o("chatbots.customize.description")}),e.jsx(K,{...a,children:e.jsx("form",{onSubmit:a.handleSubmit(u),children:e.jsx(ue,{children:e.jsxs(xe,{className:"space-y-6 py-6",children:[e.jsx(N,{control:a.control,name:"gptVersion",render:({field:i})=>e.jsxs(y,{children:[e.jsx(S,{children:"LLM"}),e.jsx(k,{children:e.jsxs(Le,{...i,onValueChange:c=>{i.onChange(c),a.trigger("gptVersion")},children:[e.jsx(Pe,{className:"w-full",children:e.jsx(Fe,{placeholder:"Select LLM"})}),e.jsx(De,{children:s.map(c=>e.jsx(Ae,{value:c,children:e.jsxs("div",{className:"flex flex-row items-center gap-2",children:[c.startsWith("gpt")?e.
33jsx(Q.gpt,{className:"size-4"}):null,c.startsWith("claude")?e.jsx(Q.claude,{className:"size-4"}):null,c.startsWith("gemini")?e.jsx(Q.gemini,{className:"size-4"}):null,Qe[c]]})},c))})]})}),e.jsx(R,{children:"Select the large language model used by your chatbot"}),e.jsx(P,{})]})}),e.jsx(N,{control:a.control,name:"dashboardCitation",render:({field:i})=>e.jsxs(y,{className:"flex flex-row items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(S,{children:"Citation"}),e.jsx(R,{children:"Enable to view the data source in chatbot response"})]}),e.jsx(k,{children:e.jsx(pe,{checked:i.value==="on",onCheckedChange:c=>{i.onChange(c?"on":"off"),a.trigger("dashboardCitation")}})})]})})]})})})})]})}),h&&e.jsx("div",{className:"flex-shrink-0 border-t bg-background shadow-lg",children:e.jsxs("div",{className:"flex h-16 items-center justify-between px-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(_e,{className:"h-4 w-4"}),e.jsx("span",{children:"You have unsaved changes"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:b,disabled:g,children:"Discard"}),e.jsxs(L,{size:"sm",onClick:v,disabled:g,children:[g&&e.jsx(ge,{className:"mr-2 h-4 w-4 animate-spin"}),"Save Changes"]})]})]})})]})})}function La(){const{t:r}=X(),d=Ds(h=>h.selectedWorkspace),{chatbotProfile:o}=Es(),{config:s,isLoading:a}=Is(),t=l.useMemo(()=>({gptVersion:s==null?void 0:s.gptVersion,leadGeneration:(s==null?void 0:s.leadGeneration)??"off",citation:(s==null?void 0:s.citation)??"on",dashboardCitation:(s==null?void 0:s.dashboardCitation)??"on"}),[s==null?void 0:s.gptVersion,s==null?void 0:s.leadGeneration,s==null?void 0:s.citation,s==null?void 0:s.dashboardCitation]),g=l.useMemo(()=>({initMessages:(s==null?void 0:s.initMessages)??"",initQuestions:(s==null?void 0:s.initQuestions)??"",placeholder:(s==null?void 0:s.placeholder)??"",prompt:(s==null?void 0:s.prompt)??"",messageBubbles:(s==null?void 0:s.messageBubbles)??"",keepShowingQuestions:(s==null?void 0:s.keepShowingQuestions)??"off"}),[s==null?void 0:s.initMessages,s==null?void 0:s.initQuestions,s==null?void 0:s.placeholder,s==null?void 0:s.prompt,s==null?void 0:s.messageBubbles,s==null?void 0:s.keepShowingQuestions]),u=l.useMemo(()=>We(s==null?void 0:s.theme),[s==null?void 0:s.theme]);return d?As(d.role)?a||!o||!s?e.jsxs(je,{children:[e.jsx(fe,{heading:r("chatbots.customize.heading"),text:r("chatbots.customize.description")}),e.jsx("div",{className:"flex h-[60%] items-center justify-center",children:e.jsx(ge,{className:"h-8 w-8 animate-spin"})})]}):o.accessMode!=="public"?e.jsx(aa,{chatbotId:o.chatbotId,defaultValues:{gptVersion:t.gptVersion,dashboardCitation:t.dashboardCitation}}):e.jsx(ea,{chatbotId:o.chatbotId,name:(o==null?void 0:o.title)||"Denser AI Chatbot",iconUrl:s==null?void 0:s.icon,removeWatermark:(s==null?void 0:s.removeWatermark)==="on",leadGeneration:(s==null?void 0:s.leadGeneration)==="on",defaultCommonValues:t,defaultTextualValues:g,defaultThemeValues:u}):e.jsx(Gs,{requiredRole:"admin"}):null}export{La 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.