!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="0ef3d444-a37b-4b1b-afaa-f6a3d3b8bb2f",e._sentryDebugIdIdentifier="sentry-dbid-0ef3d444-a37b-4b1b-afaa-f6a3d3b8bb2f")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[218],{31869:function(e,t,a){a.d(t,{f:function(){return u}});var r=a(57437),i=a(25730),n=a(2265),o=a(45168),s=a(23838),l=a(74468),d=a(86876);let c=(0,r.jsx)(o.tE8,{}),u=()=>{let{state:{showChatbar:e},dispatch:t}=(0,d.IO)(),a=(0,n.useCallback)(()=>{t({field:"showChatbar",value:!e}),s.Z.setItem("showChatbar",JSON.stringify(!e)),(0,l.Qe)({name:"toggledChatbar",data:{value:!e}})},[t,e]);return(0,r.jsx)(i.h,{colorScheme:"secondary",variant:"ghost",size:"md","aria-label":"Show Sidebar",icon:c,onClick:a})}},70218:function(e,t,a){a.r(t),a.d(t,{default:function(){return te}});var r=a(57437),i=a(78796),n=a(42586),o=a(2265),s=a(23838),l=a(25774),d=a(74468);let c=async e=>{let{userId:t,toast:a,translate:r,selectedConversationId:i,veniceShareKey:n,veniceShareNonce:o,conversationContext:s}=e,{fetchConversations:l,saveMessage:c,saveConversations:u,setSelectedConversationFromId:h,loadSharedEncryptedConversation:p}=s;try{let e=await p(i,n,o);if(!e)return;let a={...e.conversation,folderId:null,ownerId:t,updatedAtUnixTimestamp:Date.now()};for(let t of(await u([a]),e.messages))await c({conversationId:a.id,message:t,rerenderMessages:!1});await h(a.id),await l(t),window.history.pushState({},"","/chat/".concat(a.id)),(0,d.Qe)({name:"importedEncryptedConversation",data:{}})}catch(e){a({title:r("encryptedConversation.loadError.title"),description:r("encryptedConversation.loadError.description"),status:"warning",duration:9e3,isClosable:!0,position:"top-right"})}};var u=a(86827),h=a(22048),p=a(29827),m=a(59128),x=a.n(m),g=a(30166),b=a(72760),f=a(29360),v=a(35784),j=a(13449),y=a(1677),w=a(4360),I=a(37354),S=a(6924),C=a(45168),k=a(47672),z=a(8554);let T=e=>{let{characterId:t}=e,{data:a,status:i}=(0,z.sF)(t);return"pending"===i?(0,r.jsx)(b.$,{}):a?(0,r.jsxs)(u.M,{width:"full",height:"100%",flexDir:"column",gap:6,alignItems:"center",children:[(0,r.jsxs)(f.K,{spacing:1,alignItems:"center",children:[(0,r.jsx)(v.q,{mb:2,boxSize:"16rem",src:a.photo,ignoreFallback:!0}),(0,r.jsx)(j.k,{alignItems:"center",children:(0,r.jsx)(k.M,{characterId:a.id,as:y.z,rightIcon:(0,r.jsx)(C.YRR,{}),variant:"ghost",size:"lg",p:3,py:1,height:"auto",iconSpacing:1,minHeight:"auto",color:"text.base",hideNewChat:!0,children:a.name})}),(0,r.jsx)(w.x,{color:"text.subtle",textAlign:"center",maxWidth:"xl",mx:"auto",children:a.description})]}),a.intro&&(0,r.jsx)(I.Z,{children:(0,r.jsx)(S.e,{children:(0,r.jsx)(w.x,{children:a.intro})})})]}):(0,r.jsx)(r.Fragment,{})};var D=a(80022),M=a(31384),P=a(28082),E=a(86876),F=a(18254);let U=(0,o.memo)(e=>{let{onHandleNewConversation:t}=e,a=(0,n.useTranslations)(),{state:{loading:i}}=(0,E.IO)();return(0,r.jsx)(u.M,{width:"full",height:"100%",flexDir:"column",gap:2,alignItems:"center",backgroundSize:"cover",backgroundPosition:"center center",bgImage:"url(/images/circle-bg.svg)",children:(0,r.jsxs)(f.K,{alignItems:"center",px:4,children:[(0,r.jsx)(P.Vp,{colorScheme:"teal",children:a("newChat")}),(0,r.jsx)(w.x,{fontWeight:"semibold",textAlign:"center",children:a("chatCenter.headline")}),(0,r.jsxs)(f.K,{mt:4,spacing:4,children:[(0,r.jsx)(y.z,{isDisabled:i,justifyContent:"space-between",height:"auto",gap:4,p:4,rightIcon:(0,r.jsx)(M.m,{ml:"auto"}),backdropFilter:"blur(20px)",width:"full",whiteSpace:"normal",colorScheme:"primary",onClick:()=>t(F.i.Text),children:(0,r.jsxs)(j.k,{alignItems:"center",gap:4,justifyContent:"flex-start",children:[(0,r.jsx)(u.M,{boxSize:"40px",fontSize:"2xl",children:(0,r.jsx)(C.YsT,{})}),(0,r.jsxs)(f.K,{alignItems:"flex-start",textAlign:"left",children:[(0,r.jsx)(w.x,{fontSize:"md",fontWeight:"semibold",children:a("chatCenter.text.title")}),(0,r.jsx)(w.x,{fontSize:"sm",color:"text.primary.muted",children:a("chatCenter.text.description")})]})]})}),(0,r.jsx)(y.z,{isDisabled:i,justifyContent:"space-between",height:"auto",gap:4,p:4,rightIcon:(0,r.jsx)(M.m,{ml:"auto"}),backdropFilter:"blur(20px)",width:"full",whiteSpace:"normal",colorScheme:"primary",onClick:()=>t(F.i.Image),children:(0,r.jsxs)(j.k,{alignItems:"center",gap:4,children:[(0,r.jsx)(u.M,{boxSize:"40px",fontSize:"2xl",children:(0,r.jsx)(C.msJ,{})}),(0,r.jsxs)(f.K,{alignItems:"flex-start",textAlign:"left",children:[(0,r.jsx)(w.x,{fontSize:"md",fontWeight:"semibold",children:a("chatCenter.image.title")}),(0,r.jsx)(w.x,{fontSize:"sm",color:"text.primary.muted",children:a("chatCenter.image.description")})]})]})}),(0,r.jsx)(y.z,{isDisabled:i,justifyContent:"space-between",height:"auto",gap:4,p:4,rightIcon:(0,r.jsx)(M.m,{ml:"auto"}),backdropFilter:"blur(20px)",width:"full",whiteSpace:"normal",colorScheme:"primary",onClick:()=>t(F.i.Code),children:(0,r.jsxs)(j.k,{alignItems:"center",gap:4,justifyContent:"flex-start",children:[(0,r.jsx)(u.M,{boxSize:"40px",fontSize:"2xl",children:(0,r.jsx)(C.ssl,{})}),(0,r.jsxs)(f.K,{alignItems:"flex-start",textAlign:"left",children:[(0,r.jsx)(w.x,{fontSize:"md",fontWeight:"semibold",children:a("chatCenter.code.title")}),(0,r.jsx)(w.x,{fontSize:"sm",color:"text.primary.muted",children:a("chatCenter.code.description")})]})]})})]})]})})});U.displayName="ChatCenter";var R=a(25730),L=a(99376),_=a(86537),N=a(62128),W=a(58528);let A=e=>{let{children:t}=e;return(0,r.jsx)(r.Fragment,{children:t})};A.Desktop=e=>{let{children:t}=e,[a]=(0,N.a)("(min-width: ".concat(W.AV.md,")"),{ssr:!1});return a?(0,r.jsx)(r.Fragment,{children:t}):null},A.Mobile=e=>{let{children:t}=e,[a]=(0,N.a)("(min-width: ".concat(W.AV.md,")"),{ssr:!1});return a?null:(0,r.jsx)(r.Fragment,{children:t})};var K=a(31869),H=a(22053),O=a(5095),B=a(59745),Q=a(21652),q=a.n(Q),V=a(41528),Z=a(43758),J=a(82129),G=a(3809),X=a(93369);let Y=e=>{let{conversationType:t,isDisabled:a,characterId:i}=e,{onOpen:s}=(0,V.R)("chatSettings"),c=(0,n.useTranslations)(),u=(0,l.Sz)(Z.St,e=>e.id),{data:h}=(0,J.QB)(u),p=(0,X.F)(e=>e.settings.imageSettings),m=(0,X.F)(e=>e.settings.textSettings),x=(0,l.Sz)(Z.St,e=>e.isProUser),[g]=(0,N.a)("(min-width: ".concat(W.AV.md,")"),{ssr:!1}),b=(0,o.useMemo)(()=>(null==h?void 0:h.some(e=>e.active))||!1,[h]),f=(0,o.useMemo)(()=>{switch(t){case F.i.Text:return!q()(m,G.Bj)||b;case F.i.Image:return!q()(p,G.IW);default:return!1}},[t,p,b,m]),v=()=>{(0,d.Qe)({name:"openedChatSettings",data:{}}),s({conversationType:null!=t?t:void 0,characterId:i})};return(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(H.xu,{position:"relative",children:[(0,r.jsx)(O.M,{mode:"wait",children:f&&(0,r.jsx)(B.E.div,{animate:{scale:1},initial:{scale:0},style:{width:"10px",height:"10px",position:"absolute",top:"-1px",right:"-1px",zIndex:2,borderRadius:"100%",backgroundColor:"var(--primary)"}})}),x||!g?(0,r.jsx)(R.h,{colorScheme:"secondary",variant:"ghost",size:"md",icon:(0,r.jsx)(C.AXL,{}),"aria-label":"Chat settings",onClick:v,isDisabled:a}):(0,r.jsx)(y.z,{colorScheme:"secondary",variant:"ghost",size:"md",leftIcon:(0,r.jsx)(C.AXL,{}),"aria-label":"Chat settings",onClick:v,isDisabled:a,children:c("chatSettings.title")})]})})};var $=a(96509);let ee=(0,r.jsx)(C.dKc,{}),et={base:"fixed",md:"absolute"},ea=(0,o.memo)(e=>{let{leftComponent:t,conversationType:a,characterId:i}=e,s=(0,n.useTranslations)(),l=(0,L.useRouter)(),{state:{loading:d,messageIsStreaming:c}}=(0,E.IO)(),{clearSelectedConversation:u,selectedConversation:h}=(0,$.uu)(),p=null!=i?i:null==h?void 0:h.characterId,m=(0,o.useCallback)(()=>(null==h?void 0:h.characterId)?l.push("/characters/".concat(h.characterId)):u(),[u,l,null==h?void 0:h.characterId]);return(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(j.k,{position:et,top:0,left:0,right:0,bg:"var(--background-transparent)",backdropFilter:"blur(15px)",borderBottomWidth:1,borderColor:"border.subtle",zIndex:"sticky",children:(0,r.jsxs)(_.fK,{flexProps:{width:"full"},py:2,minHeight:"auto",children:[(0,r.jsx)(_.ej,{children:t||(0,r.jsxs)(A,{children:[(0,r.jsx)(A.Desktop,{children:(0,r.jsx)(K.f,{})}),(0,r.jsx)(A.Mobile,{children:(0,r.jsx)(K.f,{})})]})}),(0,r.jsxs)(_.y6,{children:[(0,r.jsxs)(A,{children:[(0,r.jsx)(A.Mobile,{children:(0,r.jsx)(R.h,{icon:ee,variant:"ghost",size:"md","aria-label":s("newChat"),isDisabled:d||c,onClick:m})}),(0,r.jsx)(A.Desktop,{children:(0,r.jsx)(y.z,{size:"md",variant:"ghost",onClick:m,leftIcon:ee,isDisabled:d||c,children:s("newChat")})})]}),(0,r.jsx)(Y,{conversationType:a,characterId:p})]})]})})})});ea.displayName="ChatHeader";var er=a(77254),ei=a(65373),en=a(20765),eo=a(12125),es=a(68193),el=a(32191),ed=a(93340),ec=a(17435),eu=a(14735),eh=a(7276),ep=a(61273),em=a(910),ex=a(7847),eg=a(26262);function eb(e){let t=e.type.toLowerCase();if(t.startsWith("text/")||""===t.trim())return"Plain Text";if(t.startsWith("image/"))return"Image";if(t.startsWith("audio/"))return"Audio";{if(t.startsWith("video/"))return"Video";if("application/pdf"===t)return"PDF";if(t.includes("spreadsheet")||"application/vnd.ms-excel"===t)return"Spreadsheet";if(t.includes("wordprocessing")||"application/msword"===t)return"Document";let e=t.split("/");return e[1].charAt(0).toUpperCase()+e[1].slice(1)}}let ef=e=>{let{file:t,fileUploadComplete:a,onRemove:i}=e,n=(0,o.useCallback)(()=>{i(t)},[t,i]),s=(0,o.useMemo)(()=>eb(t),[t]);return(0,r.jsxs)(I.Z,{position:"relative",maxWidth:"250px",bg:"background.input.base",borderWidth:1,borderColor:"border.input",boxShadow:"var(--ring-offset-shadow,0 0 #0000),var(--ring-shadow,0 0 #0000),var(--shadow)",children:[(0,r.jsx)(R.h,{colorScheme:"primary",isRound:!0,boxSize:6,minWidth:"auto",onClick:n,icon:(0,r.jsx)(C.lhV,{}),"aria-label":"remove file",position:"absolute",right:"-5%",top:"-5%",zIndex:2}),(0,r.jsx)(u.M,{children:(0,r.jsx)(P.Vp,{mt:4,children:s})}),(0,r.jsx)(ex.e,{fontSize:"xs",maxWidth:"100%",textOverflow:"ellipsis",overflow:"hidden",children:(0,r.jsxs)(eg.g,{spacing:1,align:"stretch",children:[(0,r.jsx)(w.x,{children:t.name}),!a&&(0,r.jsxs)(w.x,{size:"sm",children:[(0,r.jsx)(b.$,{size:"xs",mr:2})," Uploading..."]})]})})]})};var ev=a(184),ej=a(58055),ey=a(77797);let ew=e=>{let{icon:t}=e,{getInputProps:a,getRadioProps:i}=(0,ey.x)(e),n=a(),o=i();return(0,r.jsx)(H.xu,{as:"label",children:(0,r.jsx)(en.u,{label:e.tooltip,placement:"right",openDelay:1e3,children:(0,r.jsxs)(u.M,{...o,"data-testid":"conversationTypeSelector-".concat(e.label),fontSize:"xl",borderRadius:"lg",boxSize:7,color:"text.subtle",cursor:"pointer",transitionProperty:"common",transitionDuration:"normal",_hover:{color:"text.subtle"},_checked:{bg:"background.button.primary.base",color:"text.primary.base",boxShadow:"0 1px 0 rgba(255,255,255,.15) inset"},children:[(0,r.jsx)("input",{...n}),t]})},e.value)})},eI=(0,r.jsx)(C.YsT,{}),eS=(0,r.jsx)(C.msJ,{}),eC=(0,r.jsx)(C.ssl,{}),ek=[{value:F.i.Text,icon:eI,tooltip:"Chat"},{value:F.i.Image,icon:eS,tooltip:"Generate images"},{value:F.i.Code,icon:eC,tooltip:"Build code"}],ez=e=>{let{value:t,onChange:a,isDisabled:i,options:n=ek,iconOverrides:o}=e,{getRootProps:s,getRadioProps:l}=(0,ev.a)({name:"type",value:t,onChange:a,isDisabled:i}),d=s();return(0,r.jsxs)(H.xu,{position:"relative",children:[(0,r.jsx)(ej.U,{...d,spacing:1,bg:"background.button.secondary.base",borderRadius:"xl",p:1,children:n.map(e=>{let t=l({value:e.value});return(0,r.jsx)(ew,{icon:o&&o[e.value]?o[e.value]:e.icon,tooltip:e.tooltip,label:e.value,isDisabled:i,...t},e.value)})}),i&&(0,r.jsx)(H.xu,{position:"absolute",top:0,right:0,bottom:0,left:0,bg:"rgba(0, 0, 0, 0.05)",borderRadius:"xl",__css:{cursor:"not-allowed"}})]})};var eT=a(2818),eD=a(6235),eM=a(94508),eP=a(61423),eE=a(91825),eF=a(46346),eU=a(13637);let eR=()=>{let{fetchApi:e}=(0,eE.R)(),t=(0,i.p)(),a=(0,n.useTranslations)(),r=(0,l.Sz)(Z.St,e=>e.isSignedIn),o=(0,l.Sz)(Z.St,e=>e.isProUser);return{enhancePrompt:async i=>{let n={requestId:(0,eM.LJ)(),modelId:eF.bO.id,prompt:[{role:"user",content:"".concat(eD.Gm.enhanceImage,"\n\n").concat(i)}],systemPrompt:"",webEnabled:!1,conversationType:F.i.Text,seed:Date.now(),topP:eP.Ht,maxResponseTokens:60},s=await e({type:eU.B.Text,modelPostBody:n}),l=s.status;if(200===l)return s;if(429===l){let e=a("enhanceImagePrompt.errors.rateLimitExceeded.general");throw o?e+=" ".concat(a("enhanceImagePrompt.errors.rateLimitExceeded.pro")):r?e+=" ".concat(a("enhanceImagePrompt.errors.rateLimitExceeded.free")):e+=" ".concat(a("enhanceImagePrompt.errors.rateLimitExceeded.anon")),t({title:e,status:"error",duration:5e3,isClosable:!0,position:"bottom-right"}),Error("Rate limit exceeded")}throw h.uT("Error enhancing image",{extra:{responseStatus:l}}),t({title:a("enhanceImagePrompt.errors.unknownError"),status:"error",duration:5e3,isClosable:!0,position:"bottom-right"}),Error("Error enhancing image prompt")}}};var eL=a(76130),e_=a(11593),eN=a(69786),eW=a(56134),eA=a(87484);let eK=e=>{if(-1===e.lastIndexOf("."))return"txt";let t=e.split(".").pop();return null!=t?t.replaceAll(/\s/g,""):"txt"},eH={base:"calc(env(safe-area-inset-bottom))",lg:4},eO={base:"md",md:"lg"},eB={flex:1},eQ={base:"32px",md:"52px"},eq={borderColor:"border.hover"},eV={borderColor:"border.pressed"},eZ={borderColor:"border.pressed",boxShadow:"none"},eJ={base:"blur(10px)",md:"none"},eG={base:"var(--background-transparent)",md:"transparent"},eX=(0,r.jsx)(ep.JuG,{}),eY=(0,r.jsx)(er.H,{}),e$=(0,r.jsx)(C.DcN,{}),e0={boxShadow:"0 0 0 5px #000"},e1={boxShadow:"0 0 0 5px var(--primary)"},e2=(0,o.memo)(e=>{let{onSend:t,textareaRef:a,isLoading:s,position:c,inputGroupProps:p,flexProps:m,conversationType:x,onMessageTypeChange:g,conversationId:b,characterId:f,onStop:v}=e,w=(0,n.useTranslations)(),{onOpen:I}=(0,V.R)("upgrade"),{state:{messageIsStreaming:S}}=(0,E.IO)(),{data:k}=(0,e_.h)(null!=b?b:""),T=(0,l.Sz)(Z.St,e=>e.issuePoints),D=null!=f?f:null==k?void 0:k.characterId,{data:M}=(0,z.sF)(null!=D?D:""),{getChatFile:P}=(0,eN.Z)(),U=(0,X.F)(e=>e.settings.imageModel),L=(0,X.F)(e=>e.settings.textModel),_=(0,X.F)(e=>e.settings.codeModel),N=(0,X.F)(e=>e.settings.enterBehavior),W=(0,X.F)(e=>e.saveTextModel),A=(0,X.F)(e=>e.saveCodeModel),K=(0,l.Sz)(Z.St,e=>e.isProUser),O=x===F.i.Image,Q=(0,i.p)(),[q,J]=(0,o.useState)(1),[G,Y]=(0,o.useState)(),[$,ee]=(0,o.useState)(!1),[et,ea]=(0,o.useState)([]),[er,ep]=(0,o.useState)(""),[ex,eg]=(0,o.useState)(""),[ev,ej]=(0,o.useState)(""),[ey,ew]=(0,o.useState)(0),[eI,eS]=(0,o.useState)(!1),eC=()=>{ea([]),ep(""),eg(""),ej(""),ew(0)},ek=(0,o.useMemo)(()=>{if(!x)return;let{modelId:e}=(0,eT.v)({conversationType:x,textModel:L,imageModel:U,codeModel:_});return(0,eF.Ho)(e)},[x,U,L,_]),eD=(0,o.useMemo)(()=>({status:"error",duration:1e4,isClosable:!0,position:"top-right"}),[]),{enhancePrompt:eE}=eR(),e2=(0,o.useCallback)(async()=>{if(O&&void 0!==G){(0,d.Qe)({name:"enhancedImagePrompt",data:{}}),ee(!0);try{let e=await eE(G);if(!e.body)return;let t="";await (0,eA.z)(e.body,e=>{"content"===e.kind&&(t+=e.content,Y(t))})}catch(e){}ee(!1)}},[G,eE,O]),e4=(0,o.useCallback)(async(e,t,a)=>{if(a&&a.stopPropagation(),!ek)return alert(w("chatInput.guards.noModelError"));if(t.length>0){let e="";for(let a of t)e+="".concat(a.file.name,":\n").concat(a.errors.map(e=>e.code===eu.jK.FileTooLarge.toString()?w("chatInput.fileUpload.errors.fileSize",{fileSize:(a.file.size/1e6).toFixed(2)}):e.message).join("\n"),"\n"),(0,eL.x)(a.errors);Q({...eD,title:w("chatInput.fileUpload.errors.title"),description:e});return}let r=e[0];ek.type===eU.B.Text&&(0,eF.Pd)(ek)<eF.sI&&(W(eF.dw.id),A(eF.dw.id),Q({...eD,title:w("chatInput.fileUpload.largerContextSelected.title"),description:w("chatInput.fileUpload.largerContextSelected.description"),status:"info"}));try{let e=eK(r.name),t=await (0,ec.ws)("".concat(eP.ju,"/").concat((0,eM.LJ)(),".").concat(e),r,{access:"public",handleUploadUrl:"/api/inference/chat-file/upload"}),a=t.downloadUrl,i=await P(a,t.contentType);if(eS(!0),eg(r.name),ej(eb(r)),(0,d.Qe)({name:"uploadedDocument",data:{mimeType:r.type,tokens:i.tokens}}),""===i.text.trim()){Q({title:w("chatInput.fileUpload.errors.noText.title"),description:w("chatInput.fileUpload.errors.noText.description"),...eD}),ea([]);return}ep(i.text),ew(i.tokens)}catch(e){Q({title:w("chatInput.fileUpload.errors.genericError.title"),description:w("chatInput.fileUpload.errors.genericError.description"),...eD}),ea([]),h.Tb(e)}finally{eS(!0)}},[P,ek,A,W,Q,eD,w]);(0,o.useEffect)(()=>{if((null==ek?void 0:ek.type)!==eU.B.Text)return;let e=ey+((null==G?void 0:G.length)||0)/eP.U_,t=(0,eF.Pd)(ek);ek&&e>t&&(Q({title:w("chatInput.fileUpload.errors.exceedsContext.title"),description:w("chatInput.fileUpload.errors.exceedsContext.description",{excessiveContextSize:new Intl.NumberFormat().format(Number((e/t).toFixed(1)))}),...eD}),eC())},[ey]);let e3=(0,o.useCallback)(e=>ea(e),[]),{getRootProps:e5,getInputProps:e6,open:e7,isFocused:e8,isDragAccept:e9,acceptedFiles:te}=(0,eh.uI)({maxFiles:1,maxSize:10485760,noClick:!0,noKeyboard:!0,onDrop:(e,t,a)=>{e4(e,t,a)},onDropAccepted:e3}),{formRef:tt,onKeyDown:ta}=function(){let e=(0,o.useRef)(null);return{formRef:e,onKeyDown:t=>{if("Enter"===t.key&&!t.shiftKey&&!t.nativeEvent.isComposing){var a,r;(null===(a=e.current)||void 0===a?void 0:a.requestSubmit)&&(null===(r=e.current)||void 0===r||r.requestSubmit()),t.preventDefault()}}}}(),tr=(0,o.useCallback)(e=>{Y(e.target.value)},[]),ti=(0,o.useCallback)(()=>{v()},[v]),tn=(0,o.useCallback)(e=>{let a;if(e.preventDefault(),e.stopPropagation(),S)return;if(!ek)return alert(w("chatInput.guards.noModelError"));if(!G)return alert(w("chatInput.guards.noMessageError"));if(ex&&!eI)return alert(w("chatInput.guards.fileUploading"));let r=ek;x===F.i.Text&&M&&(a=M.id,(null==M?void 0:M.textSettings.model.active)&&M.textSettings.model.id&&(r=(0,eF.Ho)(M.textSettings.model.id)||void 0));let i=[];er&&(i.push({role:"user",content:decodeURIComponent(encodeURIComponent(er)),modelId:r.id,modelType:r.type,isFile:!0,fileName:ex,fileType:ev,characterId:a}),T(ed.PointEventType.DOC_INFERENCE)),i.push({role:"user",content:G,modelId:r.id,modelType:r.type,characterId:a}),eC(),t({newMessages:i}),Y("")},[S,ek,w,G,ex,eI,x,M,er,t,ev,T]);(0,o.useEffect)(()=>{let e=document.body;if(window.visualViewport){let t=window.visualViewport,a=window.innerHeight,r=()=>{e&&(e.style.setProperty("--chat-scroll-offset","".concat(t.height,"px")),e.style.setProperty("--chat-screen-height","".concat(a,"px")))};return t.addEventListener("resize",r),r(),()=>{window.removeEventListener("resize",r)}}},[]);let to=(0,o.useCallback)(e=>{J(e)},[]),ts=(0,o.useMemo)(()=>({base:q>48?"2xl":"lg",md:"xl"}),[q]),tl=(0,o.useMemo)(()=>({...e8?e0:{},...e9?e1:{}}),[e8,e9]),td=(0,o.useCallback)(e=>{let t=[...et];t.splice(te.indexOf(e),1),ea(t)},[te,et]),tc=(0,o.useMemo)(()=>0===et.length?null:(0,r.jsx)(j.k,{px:4,gap:2,pt:4,children:et.map(e=>(0,r.jsx)(ef,{file:e,fileUploadComplete:eI,onRemove:td},e.name))}),[eI,et,td]),tu=(0,o.useMemo)(()=>O?$?(0,r.jsx)(R.h,{colorScheme:"primary","aria-label":"submit",icon:(0,r.jsx)(ei.D,{size:"16px",isIndeterminate:!0,color:"text.base",trackColor:"border.base",position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)"}),size:"sm",isDisabled:!0,mr:2}):(0,r.jsx)(en.u,{label:w("chatInput.enhanceImage"),children:(0,r.jsx)(R.h,{colorScheme:"primary","aria-label":"submit",icon:e$,size:"sm",isLoading:s,isDisabled:!G||$,onClick:e2,mr:2})}):null,[G,e2,$,O,s,w]),th=(0,o.useMemo)(()=>(0,r.jsx)(r.Fragment,{children:s?(0,r.jsxs)(u.M,{position:"relative",children:[(0,r.jsx)(ei.D,{size:"32px",isIndeterminate:!0,color:"text.base",trackColor:"border.base",position:"absolute",left:"50%",top:"50%",transform:"translate(-50%, -50%)"}),(0,r.jsx)(R.h,{variant:"ghost",isRound:!0,onClick:ti,"aria-label":"stop",icon:eX})]}):(0,r.jsxs)(u.M,{position:"relative",children:[O&&tu,(0,r.jsx)(R.h,{colorScheme:"primary","aria-label":"submit",icon:eY,size:"sm",isLoading:s,isDisabled:!G,type:"submit","data-testid":"chatInputSubmitButton"})]})}),[G,ti,tu,O,s]),tp=(0,o.useMemo)(()=>{switch(x){case F.i.Image:return w("chatInput.placeholder.image");case F.i.Text:return w("chatInput.placeholder.text");case F.i.Code:return w("chatInput.placeholder.code");default:return""}},[x,w]),tm=x!==F.i.Image;return(0,r.jsxs)(B.E.div,{layoutId:"chat-input",layoutDependency:c,style:{width:"100%",position:null!=c?c:"static",left:0,right:0,bottom:0},children:[!K&&(0,r.jsx)(j.k,{mx:"auto",maxWidth:"48rem",alignItems:"center",gap:1,px:4,pb:2,pt:12,justifyContent:"center",bg:"var(--footer-gradient)",display:{base:"flex",md:"none"},children:(0,r.jsx)(y.z,{variant:"link",py:2,color:"text.link",leftIcon:(0,r.jsx)(C.c_x,{color:"var(--primary)"}),onClick:()=>I(),children:w("upgradeToPro")})}),(0,r.jsx)(j.k,{width:"full",px:{base:2,md:0},pb:eH,bg:eG,backdropFilter:eJ,children:(0,r.jsx)(j.k,{mx:"auto",width:"full",maxWidth:"48rem",children:(0,r.jsxs)(j.k,{width:"full",mx:"auto",flexDir:"column",gap:0,position:"relative",borderRadius:ts,boxShadow:"var(--ring-offset-shadow,0 0 #0000),var(--ring-shadow,0 0 #0000),var(--shadow)",transitionProperty:"common",transitionDuration:"normal",bg:"background.input.base",...e5({style:tl}),children:[tc,(0,r.jsx)("input",{...e6()}),(0,r.jsx)(j.k,{width:"full",gap:4,alignItems:"flex-end",zIndex:4,...m,children:(0,r.jsxs)("form",{ref:tt,onSubmit:tn,style:eB,children:[(0,r.jsxs)(eo.B,{size:eO,alignItems:"center",transitionProperty:"common",transitionDuration:"normal",bg:"transparent",...p,children:[tm&&(0,r.jsx)(es.Z,{pl:1,height:"100%",alignItems:"flex-end",py:3,children:(0,r.jsx)(R.h,{variant:"ghost",icon:(0,r.jsx)(C.eTK,{}),"aria-label":"Upload PDF or Text File",onClick:e7,size:"sm",disabled:S})}),(0,r.jsx)(el.g,{variant:"filled",borderWidth:0,placeholder:M?w("chatInput.placeholder.character",{character:M.name}):tp,resize:"none",maxHeight:"250px",pl:tm?12:4,pr:16,py:4,fontSize:"md",tabIndex:0,bg:"transparent",as:em.Z,minHeight:eQ,onHeightChange:to,minRows:1,onKeyDown:e=>{N===eW.m.Submit&&ta(e)},onChange:tr,value:G,ref:a,isDisabled:s,_hover:eq,_active:eV,_focus:eZ,required:!0,autoFocus:!0,"data-testid":"chatTextInput"}),D&&(0,r.jsx)(es.x,{alignItems:"flex-end",height:"100%",py:3,pr:{base:3,md:0},children:th})]}),!D&&(0,r.jsxs)(j.k,{px:3,py:3,justifyContent:"space-between",alignItems:"center",children:[(0,r.jsx)(j.k,{gap:2,alignItems:"center",children:(0,r.jsx)(ez,{isDisabled:S,value:x,onChange:g})}),(0,r.jsxs)(j.k,{gap:4,alignItems:"center",children:[(0,r.jsx)(H.xu,{display:{base:"none",md:"flex"},children:!K&&(0,r.jsx)(y.z,{variant:"link",color:"text.link",leftIcon:(0,r.jsx)(C.c_x,{color:"var(--primary)"}),onClick:()=>I(),children:w("upgradeToPro")})}),th]})]})]})})]})})})]})});e2.displayName="ChatInput";var e4=a(10187),e3=a(63649),e5=a(72247);let e6=()=>window.navigator.maxTouchPoints>0,e7=(0,g.default)(()=>Promise.all([a.e(6018),a.e(1477),a.e(6117),a.e(3993),a.e(5878),a.e(2967),a.e(3),a.e(4067),a.e(1413)]).then(a.bind(a,91413)).then(e=>e.ChatMessages),{loadableGenerated:{webpack:()=>[91413]},ssr:!1}),e8={pb:0},e9=(0,o.memo)(e=>{var t;let{characterId:a,demoPrompt:i}=e,n=(0,o.useRef)(!1),c=(0,o.useRef)(null),m=(0,p.NL)(),{handleServerError:g}=(0,e5.j)(),{buildApiBody:b,fetchApi:f,processResponse:v,prepareConversation:j,saveMessages:y,handleOptimisticUI:w,validatePromptLength:I,stop:S}=(0,eE.R)(),C=(0,l.Sz)(Z.St,e=>e.isLoaded),k=(0,l.Sz)(Z.St,e=>e.isSignedIn),M=(0,l.Sz)(Z.St,e=>e.id),P=(0,l.Sz)(Z.St,e=>e.refetchUserProfile),{data:R}=(0,z.PE)(M),[L,_]=(0,o.useState)(!1),[N,W]=(0,o.useState)(null!==(t=s.Z.getItem("introPrompt"))&&void 0!==t&&t),{createNewConversation:A,deleteMessage:K,lastUserMessage:H,lookupMessagesByConversationId:O,selectedConversation:B,setMessagesLastUpdatedAt:Q,setSelectedConversation:q,updateConversation:V,saveMessage:J}=(0,$.uu)(),[G,Y]=(0,o.useState)(F.i.Text),ee=(0,o.useMemo)(()=>{var e;return B?null!==(e=B.type)&&void 0!==e?e:F.i.Text:G},[B,G]),et=(0,o.useMemo)(()=>B,[B]),{codeModel:er,imageModel:ei,textModel:en}=(0,X.F)(e=>e.settings),{state:{messageIsStreaming:eo,chatReady:es,folders:el},dispatch:ed,handleCreateFolder:ec}=(0,E.IO)();(0,o.useEffect)(()=>{!c.current||eo||e6()||c.current.focus()},[eo]);let eu=(0,o.useCallback)(async e=>{await V(e),q(x()(e))},[V,q]),eh=(0,o.useCallback)(async e=>{let t,{newMessages:r,conversation:i}=e,n=Date.now();if(B)t=i||B;else{let e="";if(a){let t=el.find(e=>e.characterId===a);e=t?t.id:(await ec("Character Chat","chat",a)).id}t=await A(null!=ee?ee:F.i.Text,a,e),ed({field:"loading",value:!0}),q(t),window.history.pushState({},"","/chat/".concat(t.id)),(0,d.Qe)({name:"createdNewChat",data:{}}),ed({field:"loading",value:!1})}if(!t||!t.type)return;let o=r[r.length-1],s=null!=a?a:t.characterId,l=s&&(null==R?void 0:R.find(e=>e.id===s)),c=o.modelId;l&&ee===F.i.Text&&l.textSettings.model.active&&l.textSettings.model.id&&(c=l.textSettings.model.id);let u=c&&(0,eF.Ho)(c);if(!u)throw Error("Could not find model");let p=await j(t,r);if(await eu(p),await y({conversation:p,newMessages:r,model:u}),u.type===eU.B.Text&&!await I(t,r,u))return;let x=await w(p,u);Q(Date.now()),ed({field:"loading",value:!0}),ed({field:"messageIsStreaming",value:!0}),ed({field:"abortInference",value:!1}),(k||!L)&&(_(!0),(0,d.Qe)({name:"executedInference",data:{conversationType:t.type,hasFile:r.some(e=>e.isFile),model:u}}));let S=await b(u,p,o,l);if(S)try{let e=await f({type:u.type,modelPostBody:S,clientProcessingTime:Date.now()-n});if(!e)return;let t=Date.now()-n;await v(e,x,p,u,S,t)}catch(e){if("AbortError"===e.name){let e=m.getQueryData(e3.S.message(x));e&&await J({conversationId:t.id,message:{...e,isStopped:!0},rerenderMessages:!1})}else{h.Tb(e),await g({requestId:S.requestId,activeConversation:t,model:u,messageId:x});return}}finally{let e=m.getQueryData(e3.S.message(x));e&&await J({conversationId:t.id,message:e,rerenderMessages:!1}),ed({field:"loading",value:!1}),ed({field:"messageIsStreaming",value:!1}),ed({field:"abortInference",value:!1}),P()}},[B,a,R,ee,j,eu,y,w,Q,ed,k,L,b,A,q,el,ec,I,f,v,g,m,P,J]),ep=async()=>{if(!H||!B)return;let e=(await O(null==B?void 0:B.id)).pop();e&&((null==e?void 0:e.modelType)===eU.B.Text||(null==e?void 0:e.isErrored))&&await K({id:null==e?void 0:e.id,rerenderMessages:!1}),H&&await K({id:null==H?void 0:H.id,rerenderMessages:!1});let t=H.modelType||B.type;if(!t)return;let{modelId:a}=(0,eT.v)({conversationType:t,codeModel:er,textModel:en,imageModel:ei});await eh({newMessages:[{role:"user",content:H.content,modelType:H.modelType,modelId:a}]})},em=(0,o.useCallback)(async e=>{var t;if(B){let t;switch(e){case F.i.Image:t=ei||eF.HX.id;break;case F.i.Text:t=en||eF.bO.id;break;case F.i.Code:t=er||eF.au.id;break;default:throw Error("Invalid conversation type")}B.type=e,B.modelId=t,Y(e),await eu(B)}else Y(e);null===(t=c.current)||void 0===t||t.focus()},[B,eu,ei,en,er]),ex=(0,o.useCallback)(async e=>{await em(e),s.Z.setItem("introPrompt",!0),W(!0)},[em]);(0,o.useEffect)(()=>{let e=async()=>{if(!i)return;let e=JSON.parse(i);await em(e.type);let t=(0,eF.Ho)((0,eT.v)({conversationType:e.type,codeModel:er,textModel:en,imageModel:ei}).modelId),a={modelId:t.id,modelType:t.type,role:"user",content:e.value};await eh({newMessages:[a]})};es&&C&&(n.current=!0,e())},[es,C,i]),(0,o.useEffect)(()=>{var e;B||null===(e=c.current)||void 0===e||e.focus()},[B]);let eg=(0,o.useMemo)(()=>{if(a||!(null==B?void 0:B.characterId))return;let e=null==R?void 0:R.find(e=>e.id===B.characterId);return null==e?void 0:e.photo},[R,a,null==B?void 0:B.characterId]);return C&&es?(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)(D.ChatMainContent,{_before:{content:'""',left:0,top:0,width:"100%",height:"100%",position:"absolute",backgroundImage:eg,backgroundSize:"cover",backgroundPosition:"center center",opacity:.05},children:[(0,r.jsx)(ea,{conversationType:ee,characterId:a}),N||B||a?(0,r.jsxs)(u.M,{width:"full",height:"100%",flexDir:"column",gap:2,alignItems:"center",backgroundSize:"cover",backgroundPosition:"center center",bgImage:B?"none":"url(/images/circle-bg.svg)",children:[B&&(0,r.jsx)(e7,{handleChatSubmit:eh,handleRegenerate:ep,conversationId:null==et?void 0:et.id}),a&&!B&&(0,r.jsx)(T,{characterId:a}),(0,r.jsx)(e2,{onSend:eh,textareaRef:c,isLoading:eo,flexProps:e8,onMessageTypeChange:em,selectedConversation:et,conversationType:ee,position:B?"absolute":"static",conversationId:null==et?void 0:et.id,characterId:a,onStop:()=>S()})]}):(0,r.jsx)(U,{onHandleNewConversation:ex})]},null==B?void 0:B.id)}):(0,r.jsx)(e4.default,{})});function te(e){let{selectedConversationId:t,characterId:a}=e,d=(0,l.Sz)(Z.St,e=>e.id),u=(0,l.Sz)(Z.St,e=>e.isLoaded),h=(0,i.p)(),p=(0,n.useTranslations)(),m=(0,$.uu)(),[x,g]=(0,o.useState)(),{setSelectedConversation:b,setSelectedConversationFromId:f,clearSelectedConversation:v}=(0,$.uu)();return((0,o.useEffect)(()=>{var e;let t=new URLSearchParams(null===(e=window.location.hash)||void 0===e?void 0:e.substring(1)).get("demoPrompt");g(s.Z.getItem("demoPrompt")||t)},[]),(0,o.useEffect)(()=>{let e=async()=>{if(t){var e;let a=new URLSearchParams(null===(e=window.location.hash)||void 0===e?void 0:e.substring(1)),r=a.get("veniceShareKey"),i=a.get("veniceShareNonce");r?await c({userId:d,toast:h,translate:p,selectedConversationId:t,veniceShareKey:r,veniceShareNonce:i,conversationContext:m}):await f(t)}else a?b(void 0):v()};u&&e()},[u]),u)?(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(e9,{characterId:a,demoPrompt:x})}):(0,r.jsx)(e4.default,{altLogo:!0})}e9.displayName="Chat"},11593:function(e,t,a){a.d(t,{h:function(){return o}});var r=a(71632),i=a(718),n=a(63649);let o=e=>{let{getConversationById:t}=(0,i.c)();return(0,r.a)({queryKey:n.S.conversation(e),queryFn:()=>t(e),enabled:!!e})}}}]);