librechat-data-provider 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,2 +1,2 @@
1
- import{z as t}from"zod";import e from"axios";import{URL as n}from"url";import o from"crypto";import{load as i}from"js-yaml";var r,a,s=function(){return s=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},s.apply(this,arguments)};function l(t,e,n,o){return new(n||(n=Promise))((function(i,r){function a(t){try{l(o.next(t))}catch(t){r(t)}}function s(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}l((o=o.apply(t,e||[])).next())}))}function u(t,e){var n,o,i,r,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(n=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],o=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}function p(t,e,n){if(n||2===arguments.length)for(var o,i=0,r=e.length;i<r;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var c,d=t.string().uuid();!function(t){t.azureOpenAI="azureOpenAI",t.openAI="openAI",t.bingAI="bingAI",t.chatGPTBrowser="chatGPTBrowser",t.google="google",t.gptPlugins="gptPlugins",t.anthropic="anthropic",t.assistants="assistants",t.custom="custom"}(c||(c={}));var m,f={assistant:"",id:"",name:"",description:"",instructions:"",model:"gpt-3.5-turbo-1106",functions:[],code_interpreter:!1,retrieval:!1},h=((r={})[c.google]={model:{default:"chat-bison"},maxOutputTokens:{min:1,max:2048,step:1,default:1024,maxGeminiPro:8192,defaultGeminiPro:8192},temperature:{min:0,max:1,step:.01,default:.2},topP:{min:0,max:1,step:.01,default:.8},topK:{min:1,max:40,step:.01,default:40}},r),g=h[c.google],v=t.nativeEnum(c),b=t.union([v,t.string()]);!function(t){t.low="low",t.auto="auto",t.high="high"}(m||(m={}));var x=((a={})[m.low]=0,a[m.auto]=1,a[m.high]=2,a),y={0:m.low,1:m.auto,2:m.high},_=t.nativeEnum(m),I=t.object({authField:t.string(),label:t.string(),description:t.string()}),O=t.object({name:t.string(),pluginKey:t.string(),description:t.string(),icon:t.string(),authConfig:t.array(I),authenticated:t.boolean().optional(),isButton:t.boolean().optional()}),E=t.object({input:t.object({content:t.string()}),output:t.object({content:t.string()})}),P=t.object({agent:t.string(),skipCompletion:t.boolean(),model:t.string(),temperature:t.number()}),w=t.object({messageId:t.string(),endpoint:t.string().optional(),clientId:t.string().nullable().optional(),conversationId:t.string().nullable(),parentMessageId:t.string().nullable(),responseMessageId:t.string().nullable().optional(),overrideParentMessageId:t.string().nullable().optional(),bg:t.string().nullable().optional(),model:t.string().nullable().optional(),title:t.string().nullable().or(t.literal("New Chat")).default("New Chat"),sender:t.string(),text:t.string(),generation:t.string().nullable().optional(),isEdited:t.boolean().optional(),isCreatedByUser:t.boolean(),error:t.boolean(),createdAt:t.string().optional().default((function(){return(new Date).toISOString()})),updatedAt:t.string().optional().default((function(){return(new Date).toISOString()})),current:t.boolean().optional(),unfinished:t.boolean().optional(),searchResult:t.boolean().optional(),finish_reason:t.string().optional(),thread_id:t.string().optional()}),k=t.object({conversationId:t.string().nullable(),title:t.string().nullable().or(t.literal("New Chat")).default("New Chat"),user:t.string().optional(),endpoint:v.nullable(),endpointType:v.optional(),suggestions:t.array(t.string()).optional(),messages:t.array(t.string()).optional(),tools:t.array(O).optional(),createdAt:t.string(),updatedAt:t.string(),systemMessage:t.string().nullable().optional(),modelLabel:t.string().nullable().optional(),examples:t.array(E).optional(),chatGptLabel:t.string().nullable().optional(),userLabel:t.string().optional(),model:t.string().nullable().optional(),promptPrefix:t.string().nullable().optional(),temperature:t.number().optional(),topP:t.number().optional(),topK:t.number().optional(),context:t.string().nullable().optional(),top_p:t.number().optional(),frequency_penalty:t.number().optional(),presence_penalty:t.number().optional(),jailbreak:t.boolean().optional(),jailbreakConversationId:t.string().nullable().optional(),conversationSignature:t.string().nullable().optional(),parentMessageId:t.string().optional(),clientId:t.string().nullable().optional(),invocationId:t.number().nullable().optional(),toneStyle:t.string().nullable().optional(),maxOutputTokens:t.number().optional(),agentOptions:P.nullable().optional(),file_ids:t.array(t.string()).optional(),resendImages:t.boolean().optional(),imageDetail:_.optional(),assistant_id:t.string().optional(),instructions:t.string().optional(),presetOverride:t.record(t.unknown()).optional()}),A=k.omit({conversationId:!0,createdAt:!0,updatedAt:!0,title:!0}).merge(t.object({conversationId:t.string().nullable().optional(),presetId:t.string().nullable().optional(),title:t.string().nullable().optional(),defaultPreset:t.boolean().optional(),order:t.number().optional(),endpoint:b.nullable()})),L=k.merge(t.object({endpoint:b.nullable()})),C=k.merge(t.object({endpoint:b.nullable()})),T=k.pick({model:!0,chatGptLabel:!0,promptPrefix:!0,temperature:!0,top_p:!0,presence_penalty:!0,frequency_penalty:!0,resendImages:!0,imageDetail:!0}).transform((function(t){var e,n,o,i,r,a,l,u,p;return s(s({},t),{model:null!==(e=t.model)&&void 0!==e?e:"gpt-3.5-turbo",chatGptLabel:null!==(n=t.chatGptLabel)&&void 0!==n?n:null,promptPrefix:null!==(o=t.promptPrefix)&&void 0!==o?o:null,temperature:null!==(i=t.temperature)&&void 0!==i?i:1,top_p:null!==(r=t.top_p)&&void 0!==r?r:1,presence_penalty:null!==(a=t.presence_penalty)&&void 0!==a?a:0,frequency_penalty:null!==(l=t.frequency_penalty)&&void 0!==l?l:0,resendImages:null!==(u=t.resendImages)&&void 0!==u&&u,imageDetail:null!==(p=t.imageDetail)&&void 0!==p?p:m.auto})})).catch((function(){return{model:"gpt-3.5-turbo",chatGptLabel:null,promptPrefix:null,temperature:1,top_p:1,presence_penalty:0,frequency_penalty:0,resendImages:!1,imageDetail:m.auto}})),S=k.pick({model:!0,modelLabel:!0,promptPrefix:!0,examples:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0}).transform((function(t){var e,n,o,i,r,a,l,u,p,c,d=null===(n=null===(e=null==t?void 0:t.model)||void 0===e?void 0:e.toLowerCase())||void 0===n?void 0:n.includes("gemini-pro"),m=d?g.maxOutputTokens.maxGeminiPro:g.maxOutputTokens.max,f=d?g.maxOutputTokens.defaultGeminiPro:g.maxOutputTokens.default,h=null!==(o=t.maxOutputTokens)&&void 0!==o?o:f;return h=Math.min(h,m),s(s({},t),{model:null!==(i=t.model)&&void 0!==i?i:g.model.default,modelLabel:null!==(r=t.modelLabel)&&void 0!==r?r:null,promptPrefix:null!==(a=t.promptPrefix)&&void 0!==a?a:null,examples:null!==(l=t.examples)&&void 0!==l?l:[{input:{content:""},output:{content:""}}],temperature:null!==(u=t.temperature)&&void 0!==u?u:g.temperature.default,maxOutputTokens:h,topP:null!==(p=t.topP)&&void 0!==p?p:g.topP.default,topK:null!==(c=t.topK)&&void 0!==c?c:g.topK.default})})).catch((function(){return{model:g.model.default,modelLabel:null,promptPrefix:null,examples:[{input:{content:""},output:{content:""}}],temperature:g.temperature.default,maxOutputTokens:g.maxOutputTokens.default,topP:g.topP.default,topK:g.topK.default}})),j=k.pick({jailbreak:!0,systemMessage:!0,context:!0,toneStyle:!0,jailbreakConversationId:!0,conversationSignature:!0,clientId:!0,invocationId:!0}).transform((function(t){var e,n,o,i,r,a,l,u;return s(s({},t),{model:"",jailbreak:null!==(e=t.jailbreak)&&void 0!==e&&e,systemMessage:null!==(n=t.systemMessage)&&void 0!==n?n:null,context:null!==(o=t.context)&&void 0!==o?o:null,toneStyle:null!==(i=t.toneStyle)&&void 0!==i?i:"creative",jailbreakConversationId:null!==(r=t.jailbreakConversationId)&&void 0!==r?r:null,conversationSignature:null!==(a=t.conversationSignature)&&void 0!==a?a:null,clientId:null!==(l=t.clientId)&&void 0!==l?l:null,invocationId:null!==(u=t.invocationId)&&void 0!==u?u:1})})).catch((function(){return{model:"",jailbreak:!1,systemMessage:null,context:null,toneStyle:"creative",jailbreakConversationId:null,conversationSignature:null,clientId:null,invocationId:1}})),G=k.pick({model:!0,modelLabel:!0,promptPrefix:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0}).transform((function(t){var e,n,o,i,r,a,l;return s(s({},t),{model:null!==(e=t.model)&&void 0!==e?e:"claude-1",modelLabel:null!==(n=t.modelLabel)&&void 0!==n?n:null,promptPrefix:null!==(o=t.promptPrefix)&&void 0!==o?o:null,temperature:null!==(i=t.temperature)&&void 0!==i?i:1,maxOutputTokens:null!==(r=t.maxOutputTokens)&&void 0!==r?r:4e3,topP:null!==(a=t.topP)&&void 0!==a?a:.7,topK:null!==(l=t.topK)&&void 0!==l?l:5})})).catch((function(){return{model:"claude-1",modelLabel:null,promptPrefix:null,temperature:1,maxOutputTokens:4e3,topP:.7,topK:5}})),N=k.pick({model:!0}).transform((function(t){var e;return s(s({},t),{model:null!==(e=t.model)&&void 0!==e?e:"text-davinci-002-render-sha"})})).catch((function(){return{model:"text-davinci-002-render-sha"}})),z=k.pick({model:!0,chatGptLabel:!0,promptPrefix:!0,temperature:!0,top_p:!0,presence_penalty:!0,frequency_penalty:!0,tools:!0,agentOptions:!0}).transform((function(t){var e,n,o,i,r,a,l,u,p;return s(s({},t),{model:null!==(e=t.model)&&void 0!==e?e:"gpt-3.5-turbo",chatGptLabel:null!==(n=t.chatGptLabel)&&void 0!==n?n:null,promptPrefix:null!==(o=t.promptPrefix)&&void 0!==o?o:null,temperature:null!==(i=t.temperature)&&void 0!==i?i:.8,top_p:null!==(r=t.top_p)&&void 0!==r?r:1,presence_penalty:null!==(a=t.presence_penalty)&&void 0!==a?a:0,frequency_penalty:null!==(l=t.frequency_penalty)&&void 0!==l?l:0,tools:null!==(u=t.tools)&&void 0!==u?u:[],agentOptions:null!==(p=t.agentOptions)&&void 0!==p?p:{agent:"functions",skipCompletion:!0,model:"gpt-3.5-turbo",temperature:0}})})).catch((function(){return{model:"gpt-3.5-turbo",chatGptLabel:null,promptPrefix:null,temperature:.8,top_p:1,presence_penalty:0,frequency_penalty:0,tools:[],agentOptions:{agent:"functions",skipCompletion:!0,model:"gpt-3.5-turbo",temperature:0}}}));function M(t){var e=s({},t);return Object.keys(e).forEach((function(t){void 0!==e[t]&&null!==e[t]&&""!==e[t]||delete e[t]})),e}var R,D,B,q,K,U,F,H,$,Q=k.pick({model:!0,assistant_id:!0,instructions:!0,promptPrefix:!0}).transform(M).catch((function(){return{}})),V=k.pick({model:!0,chatGptLabel:!0,promptPrefix:!0,temperature:!0,top_p:!0,presence_penalty:!0,frequency_penalty:!0,resendImages:!0,imageDetail:!0}).transform((function(t){var e=s({},t);return"gpt-3.5-turbo"===e.model&&delete e.model,1===e.temperature&&delete e.temperature,1===e.top_p&&delete e.top_p,0===e.presence_penalty&&delete e.presence_penalty,0===e.frequency_penalty&&delete e.frequency_penalty,!0!==e.resendImages&&delete e.resendImages,e.imageDetail===m.auto&&delete e.imageDetail,M(e)})).catch((function(){return{}})),W=k.pick({model:!0,modelLabel:!0,promptPrefix:!0,examples:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0}).transform((function(t){var e=s({},t);return e.model===g.model.default&&delete e.model,e.temperature===g.temperature.default&&delete e.temperature,e.maxOutputTokens===g.maxOutputTokens.default&&delete e.maxOutputTokens,e.topP===g.topP.default&&delete e.topP,e.topK===g.topK.default&&delete e.topK,M(e)})).catch((function(){return{}})),X=k.pick({model:!0,modelLabel:!0,promptPrefix:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0}).transform((function(t){var e=s({},t);return"claude-1"===e.model&&delete e.model,1===e.temperature&&delete e.temperature,4e3===e.maxOutputTokens&&delete e.maxOutputTokens,.7===e.topP&&delete e.topP,5===e.topK&&delete e.topK,M(e)})).catch((function(){return{}})),J=k.pick({model:!0}).transform((function(t){var e=s({},t);return"text-davinci-002-render-sha"===e.model&&delete e.model,M(e)})).catch((function(){return{}})),Y=k.pick({model:!0,chatGptLabel:!0,promptPrefix:!0,temperature:!0,top_p:!0,presence_penalty:!0,frequency_penalty:!0,tools:!0,agentOptions:!0}).transform((function(t){var e,n=s({},t);return"gpt-3.5-turbo"===n.model&&delete n.model,null===n.chatGptLabel&&delete n.chatGptLabel,null===n.promptPrefix&&delete n.promptPrefix,.8===n.temperature&&delete n.temperature,1===n.top_p&&delete n.top_p,0===n.presence_penalty&&delete n.presence_penalty,0===n.frequency_penalty&&delete n.frequency_penalty,0===(null===(e=n.tools)||void 0===e?void 0:e.length)&&delete n.tools,n.agentOptions&&"functions"===n.agentOptions.agent&&!0===n.agentOptions.skipCompletion&&"gpt-3.5-turbo"===n.agentOptions.model&&0===n.agentOptions.temperature&&delete n.agentOptions,M(n)})).catch((function(){return{}})),Z=((R={})[c.openAI]=!0,R[c.google]=!0,R[c.assistants]=!0,R[c.azureOpenAI]=!0,R[c.custom]=!0,R),tt=["application/vnd.ms-excel","application/msexcel","application/x-msexcel","application/x-ms-excel","application/x-excel","application/x-dos_ms_excel","application/xls","application/x-xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],et=p(["text/x-c","text/x-c++","application/csv","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/html","text/x-java","application/json","text/markdown","application/pdf","text/x-php","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/x-python","text/x-script.python","text/x-ruby","text/x-tex","text/plain","text/css","image/jpeg","text/javascript","image/gif","image/png","application/x-tar","application/typescript","application/xml","application/zip"],tt,!0),nt=p(["text/x-c","text/x-c++","application/csv","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/html","text/x-java","application/json","text/markdown","application/pdf","text/x-php","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/x-python","text/x-script.python","text/x-ruby","text/x-tex","text/plain","text/css","image/jpeg","text/javascript","image/gif","image/png","application/x-tar","application/typescript","application/xml","application/zip"],tt,!0),ot=["text/x-c","text/x-c++","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/html","text/x-java","application/json","text/markdown","application/pdf","text/x-php","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/x-python","text/x-script.python","text/x-ruby","text/x-tex","text/plain"],it=/\.(jpg|jpeg|png|gif|webp)$/i,rt=/^application\/(vnd\.ms-excel|msexcel|x-msexcel|x-ms-excel|x-excel|x-dos_ms_excel|xls|x-xls|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet)$/,at=/^(text\/(x-c|x-c\+\+|x-java|html|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain|css|javascript|csv))$/,st=/^(application\/(csv|json|pdf|x-tar|typescript|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation|spreadsheetml\.sheet)|xml|zip))$/,lt=/^image\/(jpeg|gif|png|webp)$/,ut=[at,rt,st,lt],pt=[at,rt,st,lt],ct=[/^(text\/(x-c|x-c\+\+|html|x-java|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain))$/,/^(application\/(json|pdf|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation)))$/],dt=1048576,mt=function(t){return t*dt},ft={endpoints:(D={},D[c.assistants]={fileLimit:10,fileSizeLimit:mt(512),totalSizeLimit:mt(512),supportedMimeTypes:ut,disabled:!1},D.default={fileLimit:10,fileSizeLimit:mt(20),totalSizeLimit:mt(25),supportedMimeTypes:[lt],disabled:!1},D),serverFileSizeLimit:mt(512),avatarSizeLimit:mt(2),checkType:function(t,e){return void 0===e&&(e=ut),e.some((function(e){return e.test(t)}))}},ht=t.array(t.any()).optional().refine((function(t){return!t||t.every((function(t){return t instanceof RegExp||"string"==typeof t}))}),{message:"Each mimeType must be a string or a RegExp object."}),gt=t.object({disabled:t.boolean().optional(),fileLimit:t.number().min(0).optional(),fileSizeLimit:t.number().min(0).optional(),totalSizeLimit:t.number().min(0).optional(),supportedMimeTypes:ht.optional()}),vt=t.object({endpoints:t.record(gt).optional(),serverFileSizeLimit:t.number().min(0).optional(),avatarSizeLimit:t.number().min(0).optional()}),bt=function(t){return t.reduce((function(t,e){try{var n=new RegExp(e);t.push(n)}catch(t){console.error('Invalid regex pattern "'.concat(e,'" skipped.'))}return t}),[])};function xt(t){var e=ft;if(!t)return e;if(void 0!==t.serverFileSizeLimit&&(e.serverFileSizeLimit=mt(t.serverFileSizeLimit)),void 0!==t.avatarSizeLimit&&(e.avatarSizeLimit=mt(t.avatarSizeLimit)),!t.endpoints)return e;var n=function(n){var o=t.endpoints[n];e.endpoints[n]||(e.endpoints[n]={});var i=e.endpoints[n];if(!0===o.disabled)return i.disabled=!0,i.fileLimit=0,i.fileSizeLimit=0,i.totalSizeLimit=0,i.supportedMimeTypes=[],"continue";void 0!==o.fileSizeLimit&&(i.fileSizeLimit=mt(o.fileSizeLimit)),void 0!==o.totalSizeLimit&&(i.totalSizeLimit=mt(o.totalSizeLimit));["fileLimit"].forEach((function(t){void 0!==o[t]&&(i[t]=o[t])})),o.supportedMimeTypes&&(i.supportedMimeTypes=bt(o.supportedMimeTypes))};for(var o in t.endpoints)n(o);return e}!function(t){t.local="local",t.firebase="firebase",t.openai="openai",t.s3="s3"}(B||(B={})),function(t){t.avatar="avatar",t.unknown="unknown",t.assistants="assistants",t.image_generation="image_generation",t.assistants_output="assistants_output",t.message_attachment="message_attachment"}(q||(q={}));var yt,_t=["google","facebook","openid","github","discord"],It=t.nativeEnum(B),Ot=t.object({disableBuilder:t.boolean().optional(),pollIntervalMs:t.number().optional(),timeoutMs:t.number().optional(),supportedIds:t.array(t.string()).min(1).optional(),excludedIds:t.array(t.string()).min(1).optional(),apiKey:t.string().optional(),baseURL:t.string().optional(),models:t.object({default:t.array(t.string()).min(1),fetch:t.boolean().optional(),userIdQuery:t.boolean().optional()}).optional(),titleConvo:t.boolean().optional(),titleMethod:t.union([t.literal("completion"),t.literal("functions")]).optional(),titleModel:t.string().optional(),headers:t.record(t.any()).optional()}),Et=t.object({name:t.string().refine((function(t){return!v.safeParse(t).success}),{message:"Value cannot be one of the default endpoint (EModelEndpoint) values: ".concat(Object.values(c).join(", "))}),apiKey:t.string(),baseURL:t.string(),models:t.object({default:t.array(t.string()).min(1),fetch:t.boolean().optional(),userIdQuery:t.boolean().optional()}),titleConvo:t.boolean().optional(),titleMethod:t.union([t.literal("completion"),t.literal("functions")]).optional(),titleModel:t.string().optional(),summarize:t.boolean().optional(),summaryModel:t.string().optional(),forcePrompt:t.boolean().optional(),modelDisplayLabel:t.string().optional(),headers:t.record(t.any()).optional(),addParams:t.record(t.any()).optional(),dropParams:t.array(t.string()).optional()}),Pt=t.object({fileUploads:t.object({ipMax:t.number().optional(),ipWindowInMinutes:t.number().optional(),userMax:t.number().optional(),userWindowInMinutes:t.number().optional()}).optional()}),wt=t.object({version:t.string(),cache:t.boolean(),fileStrategy:It.optional(),registration:t.object({socialLogins:t.array(t.string()).optional(),allowedDomains:t.array(t.string()).optional()}).optional(),rateLimits:Pt.optional(),fileConfig:vt.optional(),endpoints:t.object((K={},K[c.assistants]=Ot.optional(),K.custom=t.array(Et.partial()).optional(),K)).strict().refine((function(t){return Object.keys(t).length>0}),{message:"At least one `endpoints` field must be provided."}).optional()});!function(t){t.mistral="mistral",t.openrouter="openrouter"}(yt||(yt={}));var kt=[c.openAI,c.assistants,c.azureOpenAI,c.bingAI,c.chatGPTBrowser,c.gptPlugins,c.google,c.anthropic,c.custom],At=((U={})[c.openAI]="OpenAI",U[c.assistants]="Assistants",U[c.azureOpenAI]="Azure OpenAI",U[c.bingAI]="Bing",U[c.chatGPTBrowser]="ChatGPT",U[c.gptPlugins]="Plugins",U[c.google]="Google",U[c.anthropic]="Anthropic",U[c.custom]="Custom",U),Lt=((F={})[c.assistants]=["gpt-3.5-turbo-0125","gpt-4-0125-preview","gpt-4-turbo-preview","gpt-4-1106-preview","gpt-3.5-turbo-1106","gpt-3.5-turbo-16k-0613","gpt-3.5-turbo-16k","gpt-3.5-turbo","gpt-4","gpt-4-0314","gpt-4-32k-0314","gpt-4-0613","gpt-3.5-turbo-0613"],F[c.google]=["gemini-pro","gemini-pro-vision","chat-bison","chat-bison-32k","codechat-bison","codechat-bison-32k","text-bison","text-bison-32k","text-unicorn","code-gecko","code-bison","code-bison-32k"],F[c.anthropic]=["claude-2.1","claude-2","claude-1.2","claude-1","claude-1-100k","claude-instant-1","claude-instant-1-100k"],F[c.openAI]=["gpt-3.5-turbo-0125","gpt-3.5-turbo-16k-0613","gpt-3.5-turbo-16k","gpt-4-turbo-preview","gpt-4-0125-preview","gpt-4-1106-preview","gpt-3.5-turbo","gpt-3.5-turbo-1106","gpt-4-vision-preview","gpt-4","gpt-3.5-turbo-instruct-0914","gpt-3.5-turbo-0613","gpt-3.5-turbo-0301","gpt-3.5-turbo-instruct","gpt-4-0613","text-davinci-003","gpt-4-0314"],F),Ct=new Set(["gpt-3.5-turbo-0125","gpt-4-0125-preview","gpt-4-turbo-preview","gpt-4-1106-preview","gpt-3.5-turbo-1106"]),Tt=((H={})[c.openAI]="/api/ask/".concat(c.openAI),H[c.bingAI]="/api/ask/".concat(c.bingAI),H[c.google]="/api/ask/".concat(c.google),H[c.custom]="/api/ask/".concat(c.custom),H[c.anthropic]="/api/ask/".concat(c.anthropic),H[c.gptPlugins]="/api/ask/".concat(c.gptPlugins),H[c.azureOpenAI]="/api/ask/".concat(c.azureOpenAI),H[c.chatGPTBrowser]="/api/ask/".concat(c.chatGPTBrowser),H[c.assistants]="/api/assistants/chat",H),St=new Set([c.gptPlugins,c.anthropic,c.google,c.openAI,c.azureOpenAI,c.custom]),jt=(($={})[c.openAI]=!0,$[c.azureOpenAI]=!0,$[c.gptPlugins]=!0,$[c.custom]=!0,$),Gt=["gpt-4-vision","llava-13b","gemini-pro-vision"];function Nt(t,e){return void 0===e&&(e=[]),!!t&&Gt.concat(e).some((function(e){return t.includes(e)}))}var zt,Mt,Rt,Dt,Bt,qt=new Set(["dalle","dall-e","stable-diffusion"]);!function(t){t.CONFIG_STORE="configStore",t.PLUGINS="plugins",t.GEN_TITLE="genTitle",t.TOOLS="tools",t.MODELS_CONFIG="modelsConfig",t.MODEL_QUERIES="modelQueries",t.ENDPOINT_CONFIG="endpointsConfig",t.TOKEN_CONFIG="tokenConfig",t.CUSTOM_CONFIG="customConfig",t.ABORT_KEYS="abortKeys",t.OVERRIDE_CONFIG="overrideConfig",t.FILE_UPLOAD_LIMIT="file_upload_limit"}(zt||(zt={})),function(t){t.GOOGLE_SERVICE_KEY="GOOGLE_SERVICE_KEY",t.GOOGLE_API_KEY="GOOGLE_API_KEY"}(Mt||(Mt={})),function(t){t[t.LOW=85]="LOW",t[t.HIGH=170]="HIGH",t[t.ADDITIONAL=85]="ADDITIONAL"}(Rt||(Rt={})),function(t){t.GENERAL="general",t.BETA="beta",t.DATA="data",t.ACCOUNT="account"}(Dt||(Dt={})),function(t){t.VERSION="v0.6.10",t.CONFIG_VERSION="1.0.3",t.NO_PARENT="00000000-0000-0000-0000-000000000000"}(Bt||(Bt={}));var Kt,Ut,Ft={order:"asc"},Ht=((Kt={})[c.openAI]=T,Kt[c.azureOpenAI]=T,Kt[c.custom]=T,Kt[c.google]=S,Kt[c.bingAI]=j,Kt[c.anthropic]=G,Kt[c.chatGPTBrowser]=N,Kt[c.gptPlugins]=z,Kt[c.assistants]=Q,Kt);function $t(t){for(var e,n=0,o=t;n<o.length;n++){var i=o[n];if(i){e=i;break}}return e}var Qt,Vt,Wt,Xt,Jt,Yt,Zt,te=function(t){var e,n,o=t.endpoint,i=t.endpointType,r=t.conversation,a=t.possibleValues,s=Ht[o];if(!s&&!i)throw new Error("Unknown endpoint: ".concat(o));!s&&i&&(s=Ht[i]);var l=s.parse(r),u=null!=a?a:{},p=u.models,c=u.secondaryModels;return p&&l&&(l.model=null!==(e=$t(p))&&void 0!==e?e:l.model),c&&l.agentOptions&&(l.agentOptions.model=null!==(n=$t(c))&&void 0!==n?n:l.agentOptions.model),l},ee=function(t){var e,n=t.model,o=t.endpoint,i=t.endpointType,r=t.modelDisplayLabel,a=t.chatGptLabel,s=t.modelLabel,l=t.jailbreak;return[c.openAI,c.azureOpenAI,c.gptPlugins,c.chatGPTBrowser].includes(o)?a||(n&&n.includes("gpt-3")?"GPT-3.5":n&&n.includes("gpt-4")?"GPT-4":n&&n.includes("mistral")?"Mistral":null!==(e=At[o])&&void 0!==e?e:"ChatGPT"):o===c.bingAI?l?"Sydney":"BingAI":o===c.anthropic?null!=s?s:"Claude":o===c.google?s||(n&&n.includes("gemini")?"Gemini":n&&n.includes("code")?"Codey":"PaLM2"):o===c.custom||i===c.custom?s||(a||(n&&n.includes("mistral")?"Mistral":n&&n.includes("gpt-3")?"GPT-3.5":n&&n.includes("gpt-4")?"GPT-4":r||"AI")):""},ne=((Ut={})[c.openAI]=V,Ut[c.azureOpenAI]=V,Ut[c.custom]=V,Ut[c.assistants]=Q,Ut[c.google]=W,Ut[c.bingAI]=j,Ut[c.anthropic]=X,Ut[c.chatGPTBrowser]=J,Ut[c.gptPlugins]=Y,Ut),oe=function(t){var e,n=t.endpoint,o=t.endpointType,i=t.conversation,r=t.possibleValues;if(!n)throw new Error("undefined endpoint: ".concat(n));var a=ne[n];if(!a&&!o)throw new Error("Unknown endpoint: ".concat(n));!a&&o&&(a=ne[o]);var s=a.parse(i),l=(null!=r?r:{}).models;return l&&s&&(s.model=null!==(e=$t(l))&&void 0!==e?e:s.model),s};!function(t){t.code_interpreter="code_interpreter",t.retrieval="retrieval",t.function="function"}(Qt||(Qt={})),function(t){t.TEXT="text",t.TOOL_CALL="tool_call",t.IMAGE_FILE="image_file"}(Vt||(Vt={})),function(t){t.TOOL_CALLS="tool_calls",t.MESSAGE_CREATION="message_creation"}(Wt||(Wt={})),function(t){t.FUNCTION="function",t.RETRIEVAL="retrieval",t.CODE_INTERPRETER="code_interpreter"}(Xt||(Xt={})),function(t){t.IN_PROGRESS="in_progress",t.CANCELLED="cancelled",t.FAILED="failed",t.COMPLETED="completed",t.EXPIRED="expired"}(Jt||(Jt={})),function(t){t.TEXT="text",t.IMAGE_FILE="image_file"}(Yt||(Yt={})),function(t){t.QUEUED="queued",t.IN_PROGRESS="in_progress",t.REQUIRES_ACTION="requires_action",t.CANCELLING="cancelling",t.CANCELLED="cancelled",t.FAILED="failed",t.COMPLETED="completed",t.EXPIRED="expired"}(Zt||(Zt={}));var ie,re,ae,se,le,ue,pe="_action_";function ce(t){e.defaults.headers.common["Accept-Language"]=t}function de(t){e.defaults.headers.common.Authorization="Bearer "+t}!function(t){t.ServiceHttp="service_http",t.OAuth="oauth",t.None="none"}(ie||(ie={})),function(t){t.Bearer="bearer",t.Basic="basic",t.Custom="custom"}(re||(re={})),function(t){t.DefaultPost="default_post",t.BasicAuthHeader="basic_auth_header"}(ae||(ae={})),function(t){t.FineTune="fine-tune",t.FineTuneResults="fine-tune-results",t.Assistants="assistants",t.AssistantsOutput="assistants_output"}(se||(se={})),function(t){t.messages="messages",t.allConversations="allConversations",t.searchConversations="searchConversations",t.conversation="conversation",t.searchEnabled="searchEnabled",t.user="user",t.name="name",t.models="models",t.balance="balance",t.endpoints="endpoints",t.presets="presets",t.searchResults="searchResults",t.tokenCount="tokenCount",t.availablePlugins="availablePlugins",t.startupConfig="startupConfig",t.assistants="assistants",t.assistant="assistant",t.endpointsConfigOverride="endpointsConfigOverride",t.files="files",t.fileConfig="fileConfig",t.tools="tools",t.actions="actions",t.assistantDocs="assistantDocs"}(le||(le={})),function(t){t.fileUpload="fileUpload",t.fileDelete="fileDelete",t.updatePreset="updatePreset",t.deletePreset="deletePreset",t.logoutUser="logoutUser",t.avatarUpload="avatarUpload",t.assistantAvatarUpload="assistantAvatarUpload",t.updateAction="updateAction",t.deleteAction="deleteAction"}(ue||(ue={}));var me=function(t,e){return"/api/messages/".concat(t).concat(e?"/".concat(e):"")},fe="/api/keys",he=function(t){return"/api/convos?pageNumber=".concat(t)},ge=function(t,e){return"/api/search?q=".concat(t,"&pageNumber=").concat(e)},ve=function(t){return"/api/assistants".concat(t?"/".concat(t):"")},be=function(){return"".concat("/api/files","/images")};function xe(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.post(t,JSON.stringify(n),{headers:{"Content-Type":"application/json"}})];case 1:return[2,o.sent().data]}}))}))}var ye=!1,_e=[],Ie=function(t){return xe(function(t){return"/api/auth/refresh".concat(t?"?retry=true":"")}(t))},Oe=function(t,e){void 0===e&&(e=null),_e.forEach((function(n){t?n.reject(t):n.resolve(e)})),_e=[]};e.interceptors.response.use((function(t){return t}),(function(t){return l(void 0,void 0,void 0,(function(){var n,o,i,r,a;return u(this,(function(s){switch(s.label){case 0:if(n=t.config,401!==t.response.status||n._retry)return[3,13];if(n._retry=!0,!ye)return[3,5];s.label=1;case 1:return s.trys.push([1,4,,5]),[4,new Promise((function(t,e){_e.push({resolve:t,reject:e})}))];case 2:return i=s.sent(),n.headers.Authorization="Bearer "+i,[4,e(n)];case 3:return[2,s.sent()];case 4:return o=s.sent(),[2,Promise.reject(o)];case 5:ye=!0,s.label=6;case 6:return s.trys.push([6,11,12,13]),[4,Ie(!!(null===(a=n.url)||void 0===a?void 0:a.includes("api/auth/refresh")))];case 7:return(i=s.sent().token)?(n.headers.Authorization="Bearer "+i,de(i),window.dispatchEvent(new CustomEvent("tokenUpdated",{detail:i})),Oe(null,i),[4,e(n)]):[3,9];case 8:return[2,s.sent()];case 9:window.location.href="/login",s.label=10;case 10:return[3,13];case 11:return r=s.sent(),Oe(r,null),[2,Promise.reject(r)];case 12:return ye=!1,[7];case 13:return[2,Promise.reject(t)]}}))}))}));var Ee={get:function(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.get(t,s({},n))];case 1:return[2,o.sent().data]}}))}))},post:xe,postMultiPart:function(t,n,o){return l(this,void 0,void 0,(function(){return u(this,(function(i){switch(i.label){case 0:return[4,e.post(t,n,s(s({},o),{headers:{"Content-Type":"multipart/form-data"}}))];case 1:return[2,i.sent().data]}}))}))},put:function(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.put(t,JSON.stringify(n),{headers:{"Content-Type":"application/json"}})];case 1:return[2,o.sent().data]}}))}))},delete:function(t){return l(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return[4,e.delete(t)];case 1:return[2,n.sent().data]}}))}))},deleteWithOptions:function(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.delete(t,s({},n))];case 1:return[2,o.sent().data]}}))}))},patch:function(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.patch(t,JSON.stringify(n),{headers:{"Content-Type":"application/json"}})];case 1:return[2,o.sent().data]}}))}))},refreshToken:Ie};var Pe=Object.freeze({__proto__:null,abortRequestWithMessage:function(t,e,n){return Ee.post(function(t){return"/api/ask/".concat(t,"/abort")}(t),{arg:{abortKey:e,message:n}})},clearAllConversations:function(){return Ee.post("/api/convos/clear",{arg:{}})},createAssistant:function(t){return Ee.post(ve(),t)},createPreset:function(t){return Ee.post("/api/presets",t)},deleteAction:function(t,e){return l(void 0,void 0,void 0,(function(){return u(this,(function(n){return[2,Ee.delete(ve("actions/".concat(t,"/").concat(e)))]}))}))},deleteAssistant:function(t){return Ee.delete(ve(t))},deleteConversation:function(t){return Ee.post("/api/convos/clear",{arg:t})},deleteFiles:function(t,e){return l(void 0,void 0,void 0,(function(){return u(this,(function(n){return[2,Ee.deleteWithOptions("/api/files",{data:{files:t,assistant_id:e}})]}))}))},deletePreset:function(t){return Ee.post("/api/presets/delete",t)},genTitle:function(t){return Ee.post("/api/convos/gen_title",t)},getAIEndpoints:function(){return Ee.get("/api/endpoints")},getActions:function(){return Ee.get(ve("actions"))},getAssistantById:function(t){return Ee.get(ve(t))},getAssistantDocs:function(){return Ee.get(ve("documents"))},getAvailablePlugins:function(){return Ee.get("/api/plugins")},getAvailableTools:function(){return Ee.get("".concat(ve(),"/tools"))},getConversationById:function(t){return Ee.get(function(t){return"/api/convos/".concat(t)}(t))},getConversations:function(t){return Ee.get(he(t))},getEndpointsConfigOverride:function(){return Ee.get("/api/endpoints/config/override")},getFileConfig:function(){return Ee.get("".concat("/api/files","/config"))},getFiles:function(){return Ee.get("/api/files")},getLoginGoogle:function(){return Ee.get("/api/auth/google")},getMessagesByConvoId:function(t){return"new"===t?Promise.resolve([]):Ee.get(me(t))},getModels:function(){return l(void 0,void 0,void 0,(function(){return u(this,(function(t){return[2,Ee.get("/api/models")]}))}))},getPresets:function(){return Ee.get("/api/presets")},getSearchEnabled:function(){return Ee.get("/api/search/enable")},getStartupConfig:function(){return Ee.get("/api/config")},getUser:function(){return Ee.get("/api/user")},getUserBalance:function(){return Ee.get("/api/balance")},listAssistants:function(t){return Ee.get(ve(),{params:t})},listConversations:function(t){var e=(null==t?void 0:t.pageNumber)||"1";return Ee.get(he(e))},listConversationsByQuery:function(t){var e=(null==t?void 0:t.pageNumber)||"1",n=(null==t?void 0:t.searchQuery)||"";return""!==n?Ee.get(ge(n,e)):Ee.get(he(e))},login:function(t){return Ee.post("/api/auth/login",t)},logout:function(){return Ee.post("/api/auth/logout")},register:function(t){return Ee.post("/api/auth/register",t)},requestPasswordReset:function(t){return Ee.post("/api/auth/requestPasswordReset",t)},resetPassword:function(t){return Ee.post("/api/auth/resetPassword",t)},revokeAllUserKeys:function(){return Ee.delete("".concat(fe,"?all=true"))},revokeUserKey:function(t){return Ee.delete(function(t){return"".concat(fe,"/").concat(t)}(t))},searchConversations:function(t,e){return l(void 0,void 0,void 0,(function(){return u(this,(function(n){return[2,Ee.get(ge(t,e))]}))}))},updateAction:function(t){var e=t.assistant_id,n=function(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}(t,["assistant_id"]);return Ee.post(ve("actions/".concat(e)),n)},updateAssistant:function(t,e){return Ee.patch(ve(t),e)},updateConversation:function(t){return Ee.post("/api/convos/update",{arg:t})},updateMessage:function(t){var e=t.conversationId,n=t.messageId,o=t.text;if(!e)throw new Error("conversationId is required");return Ee.put(me(e,n),{text:o})},updatePreset:function(t){return Ee.post("/api/presets",t)},updateTokenCount:function(t){return Ee.post("/api/tokenizer",{arg:t})},updateUserKey:function(t){if(!t.value)throw new Error("value is required");return Ee.put(fe,t)},updateUserPlugins:function(t){return Ee.post("/api/user/plugins",t)},uploadAssistantAvatar:function(t){return Ee.postMultiPart(ve("avatar/".concat(t.assistant_id)),t.formData)},uploadAvatar:function(t){return Ee.postMultiPart("".concat(be(),"/avatar"),t)},uploadFile:function(t){return Ee.postMultiPart("/api/files",t)},uploadImage:function(t){return Ee.postMultiPart(be(),t)},userKeyQuery:function(t){return Ee.get(function(t){return"".concat(fe,"?name=").concat(t)}(t))}}),we=function(t,e){if(!(this instanceof we))return new we(t,e);this.INITIALIZING=-1,this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this.url=t,e=e||{},this.headers=e.headers||{},this.payload=void 0!==e.payload?e.payload:"",this.method=e.method||this.payload&&"POST"||"GET",this.withCredentials=!!e.withCredentials,this.FIELD_SEPARATOR=":",this.listeners={},this.xhr=null,this.readyState=this.INITIALIZING,this.progress=0,this.chunk="",this.addEventListener=function(t,e){void 0===this.listeners[t]&&(this.listeners[t]=[]),-1===this.listeners[t].indexOf(e)&&this.listeners[t].push(e)},this.removeEventListener=function(t,e){if(void 0!==this.listeners[t]){var n=[];this.listeners[t].forEach((function(t){t!==e&&n.push(t)})),0===n.length?delete this.listeners[t]:this.listeners[t]=n}},this.dispatchEvent=function(t){if(!t)return!0;t.source=this;var e="on"+t.type;return(!this.hasOwnProperty(e)||(this[e].call(this,t),!t.defaultPrevented))&&(!this.listeners[t.type]||this.listeners[t.type].every((function(e){return e(t),!t.defaultPrevented})))},this._setReadyState=function(t){var e=new CustomEvent("readystatechange");e.readyState=t,this.readyState=t,this.dispatchEvent(e)},this._onStreamFailure=function(t){var e=new CustomEvent("error");e.data=t.currentTarget.response,this.dispatchEvent(e),this.close()},this._onStreamAbort=function(t){this.dispatchEvent(new CustomEvent("abort")),this.close()},this._onStreamProgress=async function(t){if(this.xhr){if(401!==this.xhr.status||this._retry){if(200!==this.xhr.status)return void this._onStreamFailure(t)}else{this._retry=!0;try{const t=await Ee.refreshToken();this.headers={"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},de(t.token),window.dispatchEvent(new CustomEvent("tokenUpdated",{detail:t.token})),this.stream()}catch(e){return void this._onStreamFailure(t)}}this.readyState==this.CONNECTING&&(this.dispatchEvent(new CustomEvent("open")),this._setReadyState(this.OPEN));var e=this.xhr.responseText.substring(this.progress);this.progress+=e.length,e.split(/(\r\n|\r|\n){2}/g).forEach(function(t){0===t.trim().length?(this.dispatchEvent(this._parseEventChunk(this.chunk.trim())),this.chunk=""):this.chunk+=t}.bind(this))}},this._onStreamLoaded=function(t){this._onStreamProgress(t),this.dispatchEvent(this._parseEventChunk(this.chunk)),this.chunk=""},this._parseEventChunk=function(t){if(!t||0===t.length)return null;var e={id:null,retry:null,data:"",event:"message"};t.split(/\n|\r\n|\r/).forEach(function(t){var n=(t=t.trimRight()).indexOf(this.FIELD_SEPARATOR);if(!(n<=0)){var o=t.substring(0,n);if(o in e){var i=t.substring(n+1).trimLeft();"data"===o?e[o]+=i:e[o]=i}}}.bind(this));var n=new CustomEvent(e.event);return n.data=e.data,n.id=e.id,n},this._checkStreamClosed=function(){this.xhr&&this.xhr.readyState===XMLHttpRequest.DONE&&this._setReadyState(this.CLOSED)},this.stream=function(){for(var t in this._setReadyState(this.CONNECTING),this.xhr=new XMLHttpRequest,this.xhr.addEventListener("progress",this._onStreamProgress.bind(this)),this.xhr.addEventListener("load",this._onStreamLoaded.bind(this)),this.xhr.addEventListener("readystatechange",this._checkStreamClosed.bind(this)),this.xhr.addEventListener("error",this._onStreamFailure.bind(this)),this.xhr.addEventListener("abort",this._onStreamAbort.bind(this)),this.xhr.open(this.method,this.url),this.headers)this.xhr.setRequestHeader(t,this.headers[t]);this.xhr.withCredentials=this.withCredentials,this.xhr.send(this.payload)},this.close=function(){this.readyState!==this.CLOSED&&(this.xhr.abort(),this.xhr=null,this._setReadyState(this.CLOSED))}};function ke(t){return o.createHash("sha1").update(t).digest("hex")}function Ae(t,e){return new n(e,t).toString()}var Le=function(){function t(t,e,n){var o,i;this.name=t,this.description=e,(null===(o=n.properties)||void 0===o?void 0:o.requestBody)?this.parameters=null===(i=n.properties)||void 0===i?void 0:i.requestBody:this.parameters=n}return t.prototype.toObjectTool=function(){return{type:Qt.function,function:{name:this.name,description:this.description,parameters:this.parameters}}},t}(),Ce=function(){function t(t,e,n,o,i,r){this.authHeaders={},this.domain=t,this.path=e,this.method=n,this.operation=o,this.isConsequential=i,this.contentType=r}return t.prototype.setParams=function(t){return l(this,void 0,void 0,(function(){return u(this,(function(e){return this.operationHash=ke(JSON.stringify(t)),this.params=t,[2]}))}))},t.prototype.setAuth=function(t){return l(this,void 0,void 0,(function(){var n,o,i,r,a,s,l,p,c,d,m,f,h,g,v;return u(this,(function(u){switch(u.label){case 0:return t.auth?(n=t.auth,o=n.type,i=n.authorization_type,r=n.custom_auth_header,a=n.authorization_url,s=n.client_url,l=n.scope,p=n.token_exchange_method,c=t.api_key,d=t.oauth_client_id,m=t.oauth_client_secret,f=c&&o===ie.ServiceHttp,h=d&&m&&o===ie.OAuth&&a&&s&&l&&p,f&&i===re.Basic?(g=Buffer.from(c).toString("base64"),this.authHeaders.Authorization="Basic ".concat(g),[3,6]):[3,1]):[2];case 1:return f&&i===re.Bearer?(this.authHeaders.Authorization="Bearer ".concat(c),[3,6]):[3,2];case 2:return f&&i===re.Custom&&r?(this.authHeaders[r]=c,[3,6]):[3,3];case 3:return h?this.authToken?[3,5]:[4,e.post(s,{client_id:d,client_secret:m,scope:l,grant_type:"client_credentials"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})]:[3,6];case 4:v=u.sent(),this.authToken=v.data.access_token,u.label=5;case 5:this.authHeaders.Authorization="Bearer ".concat(this.authToken),u.label=6;case 6:return[2]}}))}))},t.prototype.execute=function(){return l(this,void 0,void 0,(function(){var t,n,o;return u(this,(function(i){if(t=Ae(this.domain,this.path),n=s(s({},this.authHeaders),{"Content-Type":this.contentType}),"get"===(o=this.method.toLowerCase()))return[2,e.get(t,{headers:n,params:this.params})];if("post"===o)return[2,e.post(t,this.params,{headers:n})];if("put"===o)return[2,e.put(t,this.params,{headers:n})];if("delete"===o)return[2,e.delete(t,{headers:n,data:this.params})];if("patch"===o)return[2,e.patch(t,this.params,{headers:n})];throw new Error("Unsupported HTTP method: ".concat(this.method))}))}))},t}();function Te(t,e){var n;if("$ref"in t&&e){var o=t.$ref.replace(/^#\/components\/schemas\//,""),i=null===(n=e.schemas)||void 0===n?void 0:n[o];if(!i)throw new Error("Reference ".concat(t.$ref," not found"));return Te(i,e)}return t}function Se(t){for(var e,n,o,i,r=[],a={},l=null!==(o=null===(n=null===(e=t.servers)||void 0===e?void 0:e[0])||void 0===n?void 0:n.url)&&void 0!==o?o:"",u=0,p=Object.entries(t.paths);u<p.length;u++)for(var c=p[u],d=c[0],m=c[1],f=0,h=Object.entries(m);f<h.length;f++){var g=h[f],v=g[0],b=g[1],x=b.operationId||"".concat(v,"_").concat(d),y=b.summary||b.description||"",_={type:"object",properties:{},required:[]};if(b.requestBody){var I=b.requestBody.content,O=Te(null===(i=I[Object.keys(I)[0]])||void 0===i?void 0:i.schema,t.components);_.properties.requestBody=O}if(b.parameters)for(var E=0,P=b.parameters;E<P.length;E++){var w=P[E];O=Te(s({},w.schema),t.components);_.properties[w.name]=O,w.required&&_.required.push(w.name),w.description&&!("$$ref"in _.properties[w.name])&&(_.properties[w.name].description=w.description)}var k=new Le(x,y,_);r.push(k);var A=new Ce(l,d,v,x,!!b["x-openai-isConsequential"],b.requestBody?"application/json":"application/x-www-form-urlencoded");a[x]=A}return{functionSignatures:r,requestBuilders:a}}function je(t){var e;try{var n=void 0;try{n=JSON.parse(t)}catch(e){n=i(t)}if(!n.servers||!Array.isArray(n.servers)||0===n.servers.length)return{status:!1,message:"Could not find a valid URL in `servers`"};if(!n.servers[0].url)return{status:!1,message:"Could not find a valid URL in `servers`"};var o=n.paths;if(!o||"object"!=typeof o||0===Object.keys(o).length)return{status:!1,message:"No paths found in the OpenAPI spec."};for(var r=(null===(e=n.components)||void 0===e?void 0:e.schemas)||{},a=[],s=0,l=Object.entries(o);s<l.length;s++)for(var u=l[s],p=u[0],c=u[1],d=0,m=Object.entries(c);d<m.length;d++){var f=m[d],h=f[0],g=f[1],v=g.responses;if("object"==typeof g&&v)for(var b=0,x=Object.entries(v);b<x.length;b++){var y=x[b],_=y[0],I=y[1].content;if(I&&I["application/json"]&&I["application/json"].schema){var O=I["application/json"].schema;if("$ref"in O&&"string"==typeof O.$ref){var E=O.$ref.split("/").pop();E&&!r[E]&&a.push("In context=('paths', '".concat(p,"', '").concat(h,"', '").concat(_,"', 'response', 'content', 'application/json', 'schema'), reference to unknown component ").concat(E,"; using empty schema"))}}}}return{status:!0,message:a.join("\n")||"OpenAPI spec is valid.",spec:n}}catch(t){return{status:!1,message:"Error parsing OpenAPI spec."}}}function Ge(t){var e=t.conversation,n=t.message;t.messages;var o=t.endpointOption,i=t.isEdited,r=t.isContinued,a=L.parse(e).conversationId,l=o,u=l.endpoint,p=l.endpointType,d=Tt[null!=p?p:u];return i&&u===c.assistants?d+="/modify":i&&(d=d.replace("/ask/","/edit/")),{server:d,payload:s(s(s({},n),o),{isContinued:!(!i||!r),conversationId:a})}}export{Ce as ActionRequest,Mt as AuthKeys,ie as AuthTypeEnum,re as AuthorizationTypeEnum,zt as CacheKeys,Bt as Constants,Vt as ContentTypes,c as EModelEndpoint,Tt as EndpointURLs,q as FileContext,se as FilePurpose,B as FileSources,Le as FunctionSignature,m as ImageDetail,Rt as ImageDetailCost,yt as KnownEndpoints,Yt as MessageContentTypes,ue as MutationKeys,le as QueryKeys,Zt as RunStatus,we as SSE,Dt as SettingsTabValues,Jt as StepStatus,Wt as StepTypes,ae as TokenExchangeMethodEnum,Xt as ToolCallTypes,Qt as Tools,pe as actionDelimiter,At as alternateName,G as anthropicSchema,st as applicationMimeTypes,Ot as assistantEndpointSchema,Q as assistantSchema,j as bingAISchema,N as chatGPTBrowserSchema,pt as codeInterpreterMimeTypes,nt as codeInterpreterMimeTypesList,X as compactAnthropicSchema,J as compactChatGPTSchema,W as compactGoogleSchema,V as compactOpenAISchema,Y as compactPluginsSchema,wt as configSchema,bt as convertStringsToRegex,Ge as createPayload,Ae as createURL,Pe as dataService,f as defaultAssistantFormValues,kt as defaultEndpoints,Lt as defaultModels,Ft as defaultOrderQuery,_t as defaultSocialLogins,_ as eImageDetailSchema,v as eModelEndpointSchema,gt as endpointFileConfigSchema,Et as endpointSchema,h as endpointSettings,tt as excelFileTypes,rt as excelMimeTypes,b as extendedModelEndpointSchema,ft as fileConfig,vt as fileConfigSchema,It as fileSourceSchema,et as fullMimeTypesList,$t as getFirstDefinedValue,ee as getResponseSender,S as googleSchema,z as gptPluginsSchema,x as imageDetailNumeric,y as imageDetailValue,it as imageExtRegex,qt as imageGenTools,lt as imageMimeTypes,d as isUUID,mt as mbToBytes,dt as megabyte,xt as mergeFileConfig,St as modularEndpoints,T as openAISchema,Se as openapiToFunction,oe as parseCompactConvo,te as parseConvo,Pt as rateLimitSchema,M as removeNullishValues,Ee as request,Te as resolveRef,ct as retrievalMimeTypes,ot as retrievalMimeTypesList,ce as setAcceptLanguageHeader,de as setTokenHeader,ke as sha1,ut as supportedMimeTypes,jt as supportsBalanceCheck,Z as supportsFiles,Ct as supportsRetrieval,P as tAgentOptionsSchema,k as tConversationSchema,L as tConvoUpdateSchema,E as tExampleSchema,w as tMessageSchema,I as tPluginAuthConfigSchema,O as tPluginSchema,A as tPresetSchema,C as tPresetUpdateSchema,at as textMimeTypes,je as validateAndParseOpenAPISpec,Nt as validateVisionModel,Gt as visionModels};
1
+ import{z as t}from"zod";import e from"axios";import{URL as n}from"url";import o from"crypto";import{load as i}from"js-yaml";var r,a,s=function(){return s=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},s.apply(this,arguments)};function l(t,e,n,o){return new(n||(n=Promise))((function(i,r){function a(t){try{l(o.next(t))}catch(t){r(t)}}function s(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}l((o=o.apply(t,e||[])).next())}))}function u(t,e){var n,o,i,r,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(n=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,o=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],o=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}function p(t,e,n){if(n||2===arguments.length)for(var o,i=0,r=e.length;i<r;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var c,d=t.string().uuid();!function(t){t.azureOpenAI="azureOpenAI",t.openAI="openAI",t.bingAI="bingAI",t.chatGPTBrowser="chatGPTBrowser",t.google="google",t.gptPlugins="gptPlugins",t.anthropic="anthropic",t.assistants="assistants",t.custom="custom"}(c||(c={}));var m,f={assistant:"",id:"",name:"",description:"",instructions:"",model:"gpt-3.5-turbo-1106",functions:[],code_interpreter:!1,retrieval:!1},h=((r={})[c.google]={model:{default:"chat-bison"},maxOutputTokens:{min:1,max:2048,step:1,default:1024,maxGeminiPro:8192,defaultGeminiPro:8192},temperature:{min:0,max:1,step:.01,default:.2},topP:{min:0,max:1,step:.01,default:.8},topK:{min:1,max:40,step:.01,default:40}},r),g=h[c.google],v=t.nativeEnum(c),b=t.union([v,t.string()]);!function(t){t.low="low",t.auto="auto",t.high="high"}(m||(m={}));var x=((a={})[m.low]=0,a[m.auto]=1,a[m.high]=2,a),y={0:m.low,1:m.auto,2:m.high},_=t.nativeEnum(m),I=t.object({authField:t.string(),label:t.string(),description:t.string()}),O=t.object({name:t.string(),pluginKey:t.string(),description:t.string(),icon:t.string(),authConfig:t.array(I),authenticated:t.boolean().optional(),isButton:t.boolean().optional()}),E=t.object({input:t.object({content:t.string()}),output:t.object({content:t.string()})}),P=t.object({agent:t.string(),skipCompletion:t.boolean(),model:t.string(),temperature:t.number()}),w=t.object({messageId:t.string(),endpoint:t.string().optional(),clientId:t.string().nullable().optional(),conversationId:t.string().nullable(),parentMessageId:t.string().nullable(),responseMessageId:t.string().nullable().optional(),overrideParentMessageId:t.string().nullable().optional(),bg:t.string().nullable().optional(),model:t.string().nullable().optional(),title:t.string().nullable().or(t.literal("New Chat")).default("New Chat"),sender:t.string(),text:t.string(),generation:t.string().nullable().optional(),isEdited:t.boolean().optional(),isCreatedByUser:t.boolean(),error:t.boolean(),createdAt:t.string().optional().default((function(){return(new Date).toISOString()})),updatedAt:t.string().optional().default((function(){return(new Date).toISOString()})),current:t.boolean().optional(),unfinished:t.boolean().optional(),searchResult:t.boolean().optional(),finish_reason:t.string().optional(),thread_id:t.string().optional()}),L=t.object({conversationId:t.string().nullable(),title:t.string().nullable().or(t.literal("New Chat")).default("New Chat"),user:t.string().optional(),endpoint:v.nullable(),endpointType:v.optional(),suggestions:t.array(t.string()).optional(),messages:t.array(t.string()).optional(),tools:t.array(O).optional(),createdAt:t.string(),updatedAt:t.string(),systemMessage:t.string().nullable().optional(),modelLabel:t.string().nullable().optional(),examples:t.array(E).optional(),chatGptLabel:t.string().nullable().optional(),userLabel:t.string().optional(),model:t.string().nullable().optional(),promptPrefix:t.string().nullable().optional(),temperature:t.number().optional(),topP:t.number().optional(),topK:t.number().optional(),context:t.string().nullable().optional(),top_p:t.number().optional(),frequency_penalty:t.number().optional(),presence_penalty:t.number().optional(),jailbreak:t.boolean().optional(),jailbreakConversationId:t.string().nullable().optional(),conversationSignature:t.string().nullable().optional(),parentMessageId:t.string().optional(),clientId:t.string().nullable().optional(),invocationId:t.number().nullable().optional(),toneStyle:t.string().nullable().optional(),maxOutputTokens:t.number().optional(),agentOptions:P.nullable().optional(),file_ids:t.array(t.string()).optional(),resendImages:t.boolean().optional(),imageDetail:_.optional(),assistant_id:t.string().optional(),instructions:t.string().optional(),presetOverride:t.record(t.unknown()).optional()}),A=L.omit({conversationId:!0,createdAt:!0,updatedAt:!0,title:!0}).merge(t.object({conversationId:t.string().nullable().optional(),presetId:t.string().nullable().optional(),title:t.string().nullable().optional(),defaultPreset:t.boolean().optional(),order:t.number().optional(),endpoint:b.nullable()})),k=L.merge(t.object({endpoint:b.nullable()})),C=L.merge(t.object({endpoint:b.nullable()})),T=L.pick({model:!0,chatGptLabel:!0,promptPrefix:!0,temperature:!0,top_p:!0,presence_penalty:!0,frequency_penalty:!0,resendImages:!0,imageDetail:!0}).transform((function(t){var e,n,o,i,r,a,l,u,p;return s(s({},t),{model:null!==(e=t.model)&&void 0!==e?e:"gpt-3.5-turbo",chatGptLabel:null!==(n=t.chatGptLabel)&&void 0!==n?n:null,promptPrefix:null!==(o=t.promptPrefix)&&void 0!==o?o:null,temperature:null!==(i=t.temperature)&&void 0!==i?i:1,top_p:null!==(r=t.top_p)&&void 0!==r?r:1,presence_penalty:null!==(a=t.presence_penalty)&&void 0!==a?a:0,frequency_penalty:null!==(l=t.frequency_penalty)&&void 0!==l?l:0,resendImages:null!==(u=t.resendImages)&&void 0!==u&&u,imageDetail:null!==(p=t.imageDetail)&&void 0!==p?p:m.auto})})).catch((function(){return{model:"gpt-3.5-turbo",chatGptLabel:null,promptPrefix:null,temperature:1,top_p:1,presence_penalty:0,frequency_penalty:0,resendImages:!1,imageDetail:m.auto}})),S=L.pick({model:!0,modelLabel:!0,promptPrefix:!0,examples:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0}).transform((function(t){var e,n,o,i,r,a,l,u,p,c,d=null===(n=null===(e=null==t?void 0:t.model)||void 0===e?void 0:e.toLowerCase())||void 0===n?void 0:n.includes("gemini-pro"),m=d?g.maxOutputTokens.maxGeminiPro:g.maxOutputTokens.max,f=d?g.maxOutputTokens.defaultGeminiPro:g.maxOutputTokens.default,h=null!==(o=t.maxOutputTokens)&&void 0!==o?o:f;return h=Math.min(h,m),s(s({},t),{model:null!==(i=t.model)&&void 0!==i?i:g.model.default,modelLabel:null!==(r=t.modelLabel)&&void 0!==r?r:null,promptPrefix:null!==(a=t.promptPrefix)&&void 0!==a?a:null,examples:null!==(l=t.examples)&&void 0!==l?l:[{input:{content:""},output:{content:""}}],temperature:null!==(u=t.temperature)&&void 0!==u?u:g.temperature.default,maxOutputTokens:h,topP:null!==(p=t.topP)&&void 0!==p?p:g.topP.default,topK:null!==(c=t.topK)&&void 0!==c?c:g.topK.default})})).catch((function(){return{model:g.model.default,modelLabel:null,promptPrefix:null,examples:[{input:{content:""},output:{content:""}}],temperature:g.temperature.default,maxOutputTokens:g.maxOutputTokens.default,topP:g.topP.default,topK:g.topK.default}})),j=L.pick({jailbreak:!0,systemMessage:!0,context:!0,toneStyle:!0,jailbreakConversationId:!0,conversationSignature:!0,clientId:!0,invocationId:!0}).transform((function(t){var e,n,o,i,r,a,l,u;return s(s({},t),{model:"",jailbreak:null!==(e=t.jailbreak)&&void 0!==e&&e,systemMessage:null!==(n=t.systemMessage)&&void 0!==n?n:null,context:null!==(o=t.context)&&void 0!==o?o:null,toneStyle:null!==(i=t.toneStyle)&&void 0!==i?i:"creative",jailbreakConversationId:null!==(r=t.jailbreakConversationId)&&void 0!==r?r:null,conversationSignature:null!==(a=t.conversationSignature)&&void 0!==a?a:null,clientId:null!==(l=t.clientId)&&void 0!==l?l:null,invocationId:null!==(u=t.invocationId)&&void 0!==u?u:1})})).catch((function(){return{model:"",jailbreak:!1,systemMessage:null,context:null,toneStyle:"creative",jailbreakConversationId:null,conversationSignature:null,clientId:null,invocationId:1}})),G=L.pick({model:!0,modelLabel:!0,promptPrefix:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0}).transform((function(t){var e,n,o,i,r,a,l;return s(s({},t),{model:null!==(e=t.model)&&void 0!==e?e:"claude-1",modelLabel:null!==(n=t.modelLabel)&&void 0!==n?n:null,promptPrefix:null!==(o=t.promptPrefix)&&void 0!==o?o:null,temperature:null!==(i=t.temperature)&&void 0!==i?i:1,maxOutputTokens:null!==(r=t.maxOutputTokens)&&void 0!==r?r:4e3,topP:null!==(a=t.topP)&&void 0!==a?a:.7,topK:null!==(l=t.topK)&&void 0!==l?l:5})})).catch((function(){return{model:"claude-1",modelLabel:null,promptPrefix:null,temperature:1,maxOutputTokens:4e3,topP:.7,topK:5}})),N=L.pick({model:!0}).transform((function(t){var e;return s(s({},t),{model:null!==(e=t.model)&&void 0!==e?e:"text-davinci-002-render-sha"})})).catch((function(){return{model:"text-davinci-002-render-sha"}})),M=L.pick({model:!0,chatGptLabel:!0,promptPrefix:!0,temperature:!0,top_p:!0,presence_penalty:!0,frequency_penalty:!0,tools:!0,agentOptions:!0}).transform((function(t){var e,n,o,i,r,a,l,u,p;return s(s({},t),{model:null!==(e=t.model)&&void 0!==e?e:"gpt-3.5-turbo",chatGptLabel:null!==(n=t.chatGptLabel)&&void 0!==n?n:null,promptPrefix:null!==(o=t.promptPrefix)&&void 0!==o?o:null,temperature:null!==(i=t.temperature)&&void 0!==i?i:.8,top_p:null!==(r=t.top_p)&&void 0!==r?r:1,presence_penalty:null!==(a=t.presence_penalty)&&void 0!==a?a:0,frequency_penalty:null!==(l=t.frequency_penalty)&&void 0!==l?l:0,tools:null!==(u=t.tools)&&void 0!==u?u:[],agentOptions:null!==(p=t.agentOptions)&&void 0!==p?p:{agent:"functions",skipCompletion:!0,model:"gpt-3.5-turbo",temperature:0}})})).catch((function(){return{model:"gpt-3.5-turbo",chatGptLabel:null,promptPrefix:null,temperature:.8,top_p:1,presence_penalty:0,frequency_penalty:0,tools:[],agentOptions:{agent:"functions",skipCompletion:!0,model:"gpt-3.5-turbo",temperature:0}}}));function R(t){var e=s({},t);return Object.keys(e).forEach((function(t){void 0!==e[t]&&null!==e[t]&&""!==e[t]||delete e[t]})),e}var z,D,B,q,U,K,F,H,$,Q=L.pick({model:!0,assistant_id:!0,instructions:!0,promptPrefix:!0}).transform(R).catch((function(){return{}})),V=L.pick({model:!0,chatGptLabel:!0,promptPrefix:!0,temperature:!0,top_p:!0,presence_penalty:!0,frequency_penalty:!0,resendImages:!0,imageDetail:!0}).transform((function(t){var e=s({},t);return 1===e.temperature&&delete e.temperature,1===e.top_p&&delete e.top_p,0===e.presence_penalty&&delete e.presence_penalty,0===e.frequency_penalty&&delete e.frequency_penalty,!0!==e.resendImages&&delete e.resendImages,e.imageDetail===m.auto&&delete e.imageDetail,R(e)})).catch((function(){return{}})),W=L.pick({model:!0,modelLabel:!0,promptPrefix:!0,examples:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0}).transform((function(t){var e=s({},t);return e.temperature===g.temperature.default&&delete e.temperature,e.maxOutputTokens===g.maxOutputTokens.default&&delete e.maxOutputTokens,e.topP===g.topP.default&&delete e.topP,e.topK===g.topK.default&&delete e.topK,R(e)})).catch((function(){return{}})),X=L.pick({model:!0,modelLabel:!0,promptPrefix:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0}).transform((function(t){var e=s({},t);return 1===e.temperature&&delete e.temperature,4e3===e.maxOutputTokens&&delete e.maxOutputTokens,.7===e.topP&&delete e.topP,5===e.topK&&delete e.topK,R(e)})).catch((function(){return{}})),J=L.pick({model:!0}).transform((function(t){return R(s({},t))})).catch((function(){return{}})),Y=L.pick({model:!0,chatGptLabel:!0,promptPrefix:!0,temperature:!0,top_p:!0,presence_penalty:!0,frequency_penalty:!0,tools:!0,agentOptions:!0}).transform((function(t){var e,n=s({},t);return null===n.chatGptLabel&&delete n.chatGptLabel,null===n.promptPrefix&&delete n.promptPrefix,.8===n.temperature&&delete n.temperature,1===n.top_p&&delete n.top_p,0===n.presence_penalty&&delete n.presence_penalty,0===n.frequency_penalty&&delete n.frequency_penalty,0===(null===(e=n.tools)||void 0===e?void 0:e.length)&&delete n.tools,n.agentOptions&&"functions"===n.agentOptions.agent&&!0===n.agentOptions.skipCompletion&&"gpt-3.5-turbo"===n.agentOptions.model&&0===n.agentOptions.temperature&&delete n.agentOptions,R(n)})).catch((function(){return{}})),Z=((z={})[c.openAI]=!0,z[c.google]=!0,z[c.assistants]=!0,z[c.azureOpenAI]=!0,z[c.custom]=!0,z),tt=["application/vnd.ms-excel","application/msexcel","application/x-msexcel","application/x-ms-excel","application/x-excel","application/x-dos_ms_excel","application/xls","application/x-xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],et=p(["text/x-c","text/x-c++","application/csv","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/html","text/x-java","application/json","text/markdown","application/pdf","text/x-php","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/x-python","text/x-script.python","text/x-ruby","text/x-tex","text/plain","text/css","image/jpeg","text/javascript","image/gif","image/png","application/x-tar","application/typescript","application/xml","application/zip"],tt,!0),nt=p(["text/x-c","text/x-c++","application/csv","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/html","text/x-java","application/json","text/markdown","application/pdf","text/x-php","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/x-python","text/x-script.python","text/x-ruby","text/x-tex","text/plain","text/css","image/jpeg","text/javascript","image/gif","image/png","application/x-tar","application/typescript","application/xml","application/zip"],tt,!0),ot=["text/x-c","text/x-c++","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/html","text/x-java","application/json","text/markdown","application/pdf","text/x-php","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/x-python","text/x-script.python","text/x-ruby","text/x-tex","text/plain"],it=/\.(jpg|jpeg|png|gif|webp)$/i,rt=/^application\/(vnd\.ms-excel|msexcel|x-msexcel|x-ms-excel|x-excel|x-dos_ms_excel|xls|x-xls|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet)$/,at=/^(text\/(x-c|x-c\+\+|x-java|html|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain|css|javascript|csv))$/,st=/^(application\/(csv|json|pdf|x-tar|typescript|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation|spreadsheetml\.sheet)|xml|zip))$/,lt=/^image\/(jpeg|gif|png|webp)$/,ut=[at,rt,st,lt],pt=[at,rt,st,lt],ct=[/^(text\/(x-c|x-c\+\+|html|x-java|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain))$/,/^(application\/(json|pdf|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation)))$/],dt=1048576,mt=function(t){return t*dt},ft={endpoints:(D={},D[c.assistants]={fileLimit:10,fileSizeLimit:mt(512),totalSizeLimit:mt(512),supportedMimeTypes:ut,disabled:!1},D.default={fileLimit:10,fileSizeLimit:mt(20),totalSizeLimit:mt(25),supportedMimeTypes:[lt],disabled:!1},D),serverFileSizeLimit:mt(512),avatarSizeLimit:mt(2),checkType:function(t,e){return void 0===e&&(e=ut),e.some((function(e){return e.test(t)}))}},ht=t.array(t.any()).optional().refine((function(t){return!t||t.every((function(t){return t instanceof RegExp||"string"==typeof t}))}),{message:"Each mimeType must be a string or a RegExp object."}),gt=t.object({disabled:t.boolean().optional(),fileLimit:t.number().min(0).optional(),fileSizeLimit:t.number().min(0).optional(),totalSizeLimit:t.number().min(0).optional(),supportedMimeTypes:ht.optional()}),vt=t.object({endpoints:t.record(gt).optional(),serverFileSizeLimit:t.number().min(0).optional(),avatarSizeLimit:t.number().min(0).optional()}),bt=function(t){return t.reduce((function(t,e){try{var n=new RegExp(e);t.push(n)}catch(t){console.error('Invalid regex pattern "'.concat(e,'" skipped.'))}return t}),[])};function xt(t){var e=ft;if(!t)return e;if(void 0!==t.serverFileSizeLimit&&(e.serverFileSizeLimit=mt(t.serverFileSizeLimit)),void 0!==t.avatarSizeLimit&&(e.avatarSizeLimit=mt(t.avatarSizeLimit)),!t.endpoints)return e;var n=function(n){var o=t.endpoints[n];e.endpoints[n]||(e.endpoints[n]={});var i=e.endpoints[n];if(!0===o.disabled)return i.disabled=!0,i.fileLimit=0,i.fileSizeLimit=0,i.totalSizeLimit=0,i.supportedMimeTypes=[],"continue";void 0!==o.fileSizeLimit&&(i.fileSizeLimit=mt(o.fileSizeLimit)),void 0!==o.totalSizeLimit&&(i.totalSizeLimit=mt(o.totalSizeLimit));["fileLimit"].forEach((function(t){void 0!==o[t]&&(i[t]=o[t])})),o.supportedMimeTypes&&(i.supportedMimeTypes=bt(o.supportedMimeTypes))};for(var o in t.endpoints)n(o);return e}!function(t){t.local="local",t.firebase="firebase",t.openai="openai",t.s3="s3"}(B||(B={})),function(t){t.avatar="avatar",t.unknown="unknown",t.assistants="assistants",t.image_generation="image_generation",t.assistants_output="assistants_output",t.message_attachment="message_attachment"}(q||(q={}));var yt,_t=["google","facebook","openid","github","discord"],It=t.nativeEnum(B),Ot=t.object({disableBuilder:t.boolean().optional(),pollIntervalMs:t.number().optional(),timeoutMs:t.number().optional(),supportedIds:t.array(t.string()).min(1).optional(),excludedIds:t.array(t.string()).min(1).optional(),apiKey:t.string().optional(),baseURL:t.string().optional(),models:t.object({default:t.array(t.string()).min(1),fetch:t.boolean().optional(),userIdQuery:t.boolean().optional()}).optional(),titleConvo:t.boolean().optional(),titleMethod:t.union([t.literal("completion"),t.literal("functions")]).optional(),titleModel:t.string().optional(),headers:t.record(t.any()).optional()}),Et=t.object({name:t.string().refine((function(t){return!v.safeParse(t).success}),{message:"Value cannot be one of the default endpoint (EModelEndpoint) values: ".concat(Object.values(c).join(", "))}),apiKey:t.string(),baseURL:t.string(),models:t.object({default:t.array(t.string()).min(1),fetch:t.boolean().optional(),userIdQuery:t.boolean().optional()}),titleConvo:t.boolean().optional(),titleMethod:t.union([t.literal("completion"),t.literal("functions")]).optional(),titleModel:t.string().optional(),summarize:t.boolean().optional(),summaryModel:t.string().optional(),forcePrompt:t.boolean().optional(),modelDisplayLabel:t.string().optional(),headers:t.record(t.any()).optional(),addParams:t.record(t.any()).optional(),dropParams:t.array(t.string()).optional()}),Pt=t.object({fileUploads:t.object({ipMax:t.number().optional(),ipWindowInMinutes:t.number().optional(),userMax:t.number().optional(),userWindowInMinutes:t.number().optional()}).optional()}),wt=t.object({version:t.string(),cache:t.boolean(),fileStrategy:It.optional(),registration:t.object({socialLogins:t.array(t.string()).optional(),allowedDomains:t.array(t.string()).optional()}).optional(),rateLimits:Pt.optional(),fileConfig:vt.optional(),endpoints:t.object((U={},U[c.assistants]=Ot.optional(),U.custom=t.array(Et.partial()).optional(),U)).strict().refine((function(t){return Object.keys(t).length>0}),{message:"At least one `endpoints` field must be provided."}).optional()});!function(t){t.mistral="mistral",t.openrouter="openrouter"}(yt||(yt={}));var Lt=[c.openAI,c.assistants,c.azureOpenAI,c.bingAI,c.chatGPTBrowser,c.gptPlugins,c.google,c.anthropic,c.custom],At=((K={})[c.openAI]="OpenAI",K[c.assistants]="Assistants",K[c.azureOpenAI]="Azure OpenAI",K[c.bingAI]="Bing",K[c.chatGPTBrowser]="ChatGPT",K[c.gptPlugins]="Plugins",K[c.google]="Google",K[c.anthropic]="Anthropic",K[c.custom]="Custom",K),kt=((F={})[c.assistants]=["gpt-3.5-turbo-0125","gpt-4-0125-preview","gpt-4-turbo-preview","gpt-4-1106-preview","gpt-3.5-turbo-1106","gpt-3.5-turbo-16k-0613","gpt-3.5-turbo-16k","gpt-3.5-turbo","gpt-4","gpt-4-0314","gpt-4-32k-0314","gpt-4-0613","gpt-3.5-turbo-0613"],F[c.google]=["gemini-pro","gemini-pro-vision","chat-bison","chat-bison-32k","codechat-bison","codechat-bison-32k","text-bison","text-bison-32k","text-unicorn","code-gecko","code-bison","code-bison-32k"],F[c.anthropic]=["claude-2.1","claude-2","claude-1.2","claude-1","claude-1-100k","claude-instant-1","claude-instant-1-100k"],F[c.openAI]=["gpt-3.5-turbo-0125","gpt-3.5-turbo-16k-0613","gpt-3.5-turbo-16k","gpt-4-turbo-preview","gpt-4-0125-preview","gpt-4-1106-preview","gpt-3.5-turbo","gpt-3.5-turbo-1106","gpt-4-vision-preview","gpt-4","gpt-3.5-turbo-instruct-0914","gpt-3.5-turbo-0613","gpt-3.5-turbo-0301","gpt-3.5-turbo-instruct","gpt-4-0613","text-davinci-003","gpt-4-0314"],F),Ct=new Set(["gpt-3.5-turbo-0125","gpt-4-0125-preview","gpt-4-turbo-preview","gpt-4-1106-preview","gpt-3.5-turbo-1106"]),Tt=((H={})[c.openAI]="/api/ask/".concat(c.openAI),H[c.bingAI]="/api/ask/".concat(c.bingAI),H[c.google]="/api/ask/".concat(c.google),H[c.custom]="/api/ask/".concat(c.custom),H[c.anthropic]="/api/ask/".concat(c.anthropic),H[c.gptPlugins]="/api/ask/".concat(c.gptPlugins),H[c.azureOpenAI]="/api/ask/".concat(c.azureOpenAI),H[c.chatGPTBrowser]="/api/ask/".concat(c.chatGPTBrowser),H[c.assistants]="/api/assistants/chat",H),St=new Set([c.gptPlugins,c.anthropic,c.google,c.openAI,c.azureOpenAI,c.custom]),jt=(($={})[c.openAI]=!0,$[c.azureOpenAI]=!0,$[c.gptPlugins]=!0,$[c.custom]=!0,$),Gt=["gpt-4-vision","llava-13b","gemini-pro-vision"];function Nt(t,e){return void 0===e&&(e=[]),!!t&&Gt.concat(e).some((function(e){return t.includes(e)}))}var Mt,Rt,zt,Dt,Bt,qt,Ut=new Set(["dalle","dall-e","stable-diffusion"]);!function(t){t.CONFIG_STORE="configStore",t.PLUGINS="plugins",t.GEN_TITLE="genTitle",t.TOOLS="tools",t.MODELS_CONFIG="modelsConfig",t.MODEL_QUERIES="modelQueries",t.ENDPOINT_CONFIG="endpointsConfig",t.TOKEN_CONFIG="tokenConfig",t.CUSTOM_CONFIG="customConfig",t.ABORT_KEYS="abortKeys",t.OVERRIDE_CONFIG="overrideConfig"}(Mt||(Mt={})),function(t){t.FILE_UPLOAD_LIMIT="file_upload_limit",t.ILLEGAL_MODEL_REQUEST="illegal_model_request"}(Rt||(Rt={})),function(t){t.GOOGLE_SERVICE_KEY="GOOGLE_SERVICE_KEY",t.GOOGLE_API_KEY="GOOGLE_API_KEY"}(zt||(zt={})),function(t){t[t.LOW=85]="LOW",t[t.HIGH=170]="HIGH",t[t.ADDITIONAL=85]="ADDITIONAL"}(Dt||(Dt={})),function(t){t.GENERAL="general",t.BETA="beta",t.DATA="data",t.ACCOUNT="account"}(Bt||(Bt={})),function(t){t.VERSION="v0.6.10",t.CONFIG_VERSION="1.0.3",t.NO_PARENT="00000000-0000-0000-0000-000000000000"}(qt||(qt={}));var Kt,Ft,Ht={order:"asc"},$t=((Kt={})[c.openAI]=T,Kt[c.azureOpenAI]=T,Kt[c.custom]=T,Kt[c.google]=S,Kt[c.bingAI]=j,Kt[c.anthropic]=G,Kt[c.chatGPTBrowser]=N,Kt[c.gptPlugins]=M,Kt[c.assistants]=Q,Kt);function Qt(t){for(var e,n=0,o=t;n<o.length;n++){var i=o[n];if(i){e=i;break}}return e}var Vt,Wt,Xt,Jt,Yt,Zt,te,ee=function(t){var e,n,o=t.endpoint,i=t.endpointType,r=t.conversation,a=t.possibleValues,s=$t[o];if(!s&&!i)throw new Error("Unknown endpoint: ".concat(o));!s&&i&&(s=$t[i]);var l=s.parse(r),u=null!=a?a:{},p=u.models,c=u.secondaryModels;return p&&l&&(l.model=null!==(e=Qt(p))&&void 0!==e?e:l.model),c&&l.agentOptions&&(l.agentOptions.model=null!==(n=Qt(c))&&void 0!==n?n:l.agentOptions.model),l},ne=function(t){var e,n=t.model,o=t.endpoint,i=t.endpointType,r=t.modelDisplayLabel,a=t.chatGptLabel,s=t.modelLabel,l=t.jailbreak;return[c.openAI,c.azureOpenAI,c.gptPlugins,c.chatGPTBrowser].includes(o)?a||(n&&n.includes("gpt-3")?"GPT-3.5":n&&n.includes("gpt-4")?"GPT-4":n&&n.includes("mistral")?"Mistral":null!==(e=At[o])&&void 0!==e?e:"ChatGPT"):o===c.bingAI?l?"Sydney":"BingAI":o===c.anthropic?null!=s?s:"Claude":o===c.google?s||(n&&n.includes("gemini")?"Gemini":n&&n.includes("code")?"Codey":"PaLM2"):o===c.custom||i===c.custom?s||(a||(n&&n.includes("mistral")?"Mistral":n&&n.includes("gpt-3")?"GPT-3.5":n&&n.includes("gpt-4")?"GPT-4":r||"AI")):""},oe=((Ft={})[c.openAI]=V,Ft[c.azureOpenAI]=V,Ft[c.custom]=V,Ft[c.assistants]=Q,Ft[c.google]=W,Ft[c.bingAI]=j,Ft[c.anthropic]=X,Ft[c.chatGPTBrowser]=J,Ft[c.gptPlugins]=Y,Ft),ie=function(t){var e,n=t.endpoint,o=t.endpointType,i=t.conversation,r=t.possibleValues;if(!n)throw new Error("undefined endpoint: ".concat(n));var a=oe[n];if(!a&&!o)throw new Error("Unknown endpoint: ".concat(n));!a&&o&&(a=oe[o]);var s=a.parse(i),l=(null!=r?r:{}).models;return l&&s&&(s.model=null!==(e=Qt(l))&&void 0!==e?e:s.model),s};!function(t){t.code_interpreter="code_interpreter",t.retrieval="retrieval",t.function="function"}(Vt||(Vt={})),function(t){t.TEXT="text",t.TOOL_CALL="tool_call",t.IMAGE_FILE="image_file"}(Wt||(Wt={})),function(t){t.TOOL_CALLS="tool_calls",t.MESSAGE_CREATION="message_creation"}(Xt||(Xt={})),function(t){t.FUNCTION="function",t.RETRIEVAL="retrieval",t.CODE_INTERPRETER="code_interpreter"}(Jt||(Jt={})),function(t){t.IN_PROGRESS="in_progress",t.CANCELLED="cancelled",t.FAILED="failed",t.COMPLETED="completed",t.EXPIRED="expired"}(Yt||(Yt={})),function(t){t.TEXT="text",t.IMAGE_FILE="image_file"}(Zt||(Zt={})),function(t){t.QUEUED="queued",t.IN_PROGRESS="in_progress",t.REQUIRES_ACTION="requires_action",t.CANCELLING="cancelling",t.CANCELLED="cancelled",t.FAILED="failed",t.COMPLETED="completed",t.EXPIRED="expired"}(te||(te={}));var re,ae,se,le,ue,pe,ce="_action_";function de(t){e.defaults.headers.common["Accept-Language"]=t}function me(t){e.defaults.headers.common.Authorization="Bearer "+t}!function(t){t.ServiceHttp="service_http",t.OAuth="oauth",t.None="none"}(re||(re={})),function(t){t.Bearer="bearer",t.Basic="basic",t.Custom="custom"}(ae||(ae={})),function(t){t.DefaultPost="default_post",t.BasicAuthHeader="basic_auth_header"}(se||(se={})),function(t){t.FineTune="fine-tune",t.FineTuneResults="fine-tune-results",t.Assistants="assistants",t.AssistantsOutput="assistants_output"}(le||(le={})),function(t){t.messages="messages",t.allConversations="allConversations",t.searchConversations="searchConversations",t.conversation="conversation",t.searchEnabled="searchEnabled",t.user="user",t.name="name",t.models="models",t.balance="balance",t.endpoints="endpoints",t.presets="presets",t.searchResults="searchResults",t.tokenCount="tokenCount",t.availablePlugins="availablePlugins",t.startupConfig="startupConfig",t.assistants="assistants",t.assistant="assistant",t.endpointsConfigOverride="endpointsConfigOverride",t.files="files",t.fileConfig="fileConfig",t.tools="tools",t.actions="actions",t.assistantDocs="assistantDocs"}(ue||(ue={})),function(t){t.fileUpload="fileUpload",t.fileDelete="fileDelete",t.updatePreset="updatePreset",t.deletePreset="deletePreset",t.logoutUser="logoutUser",t.avatarUpload="avatarUpload",t.assistantAvatarUpload="assistantAvatarUpload",t.updateAction="updateAction",t.deleteAction="deleteAction"}(pe||(pe={}));var fe=function(t,e){return"/api/messages/".concat(t).concat(e?"/".concat(e):"")},he="/api/keys",ge=function(t){return"/api/convos?pageNumber=".concat(t)},ve=function(t,e){return"/api/search?q=".concat(t,"&pageNumber=").concat(e)},be=function(t){return"/api/assistants".concat(t?"/".concat(t):"")},xe=function(){return"".concat("/api/files","/images")};function ye(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.post(t,JSON.stringify(n),{headers:{"Content-Type":"application/json"}})];case 1:return[2,o.sent().data]}}))}))}var _e=!1,Ie=[],Oe=function(t){return ye(function(t){return"/api/auth/refresh".concat(t?"?retry=true":"")}(t))},Ee=function(t,e){void 0===e&&(e=null),Ie.forEach((function(n){t?n.reject(t):n.resolve(e)})),Ie=[]};e.interceptors.response.use((function(t){return t}),(function(t){return l(void 0,void 0,void 0,(function(){var n,o,i,r,a;return u(this,(function(s){switch(s.label){case 0:if(n=t.config,401!==t.response.status||n._retry)return[3,13];if(n._retry=!0,!_e)return[3,5];s.label=1;case 1:return s.trys.push([1,4,,5]),[4,new Promise((function(t,e){Ie.push({resolve:t,reject:e})}))];case 2:return i=s.sent(),n.headers.Authorization="Bearer "+i,[4,e(n)];case 3:return[2,s.sent()];case 4:return o=s.sent(),[2,Promise.reject(o)];case 5:_e=!0,s.label=6;case 6:return s.trys.push([6,11,12,13]),[4,Oe(!!(null===(a=n.url)||void 0===a?void 0:a.includes("api/auth/refresh")))];case 7:return(i=s.sent().token)?(n.headers.Authorization="Bearer "+i,me(i),window.dispatchEvent(new CustomEvent("tokenUpdated",{detail:i})),Ee(null,i),[4,e(n)]):[3,9];case 8:return[2,s.sent()];case 9:window.location.href="/login",s.label=10;case 10:return[3,13];case 11:return r=s.sent(),Ee(r,null),[2,Promise.reject(r)];case 12:return _e=!1,[7];case 13:return[2,Promise.reject(t)]}}))}))}));var Pe={get:function(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.get(t,s({},n))];case 1:return[2,o.sent().data]}}))}))},post:ye,postMultiPart:function(t,n,o){return l(this,void 0,void 0,(function(){return u(this,(function(i){switch(i.label){case 0:return[4,e.post(t,n,s(s({},o),{headers:{"Content-Type":"multipart/form-data"}}))];case 1:return[2,i.sent().data]}}))}))},put:function(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.put(t,JSON.stringify(n),{headers:{"Content-Type":"application/json"}})];case 1:return[2,o.sent().data]}}))}))},delete:function(t){return l(this,void 0,void 0,(function(){return u(this,(function(n){switch(n.label){case 0:return[4,e.delete(t)];case 1:return[2,n.sent().data]}}))}))},deleteWithOptions:function(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.delete(t,s({},n))];case 1:return[2,o.sent().data]}}))}))},patch:function(t,n){return l(this,void 0,void 0,(function(){return u(this,(function(o){switch(o.label){case 0:return[4,e.patch(t,JSON.stringify(n),{headers:{"Content-Type":"application/json"}})];case 1:return[2,o.sent().data]}}))}))},refreshToken:Oe};var we=Object.freeze({__proto__:null,abortRequestWithMessage:function(t,e,n){return Pe.post(function(t){return"/api/ask/".concat(t,"/abort")}(t),{arg:{abortKey:e,message:n}})},clearAllConversations:function(){return Pe.post("/api/convos/clear",{arg:{}})},createAssistant:function(t){return Pe.post(be(),t)},createPreset:function(t){return Pe.post("/api/presets",t)},deleteAction:function(t,e){return l(void 0,void 0,void 0,(function(){return u(this,(function(n){return[2,Pe.delete(be("actions/".concat(t,"/").concat(e)))]}))}))},deleteAssistant:function(t){return Pe.delete(be(t))},deleteConversation:function(t){return Pe.post("/api/convos/clear",{arg:t})},deleteFiles:function(t,e){return l(void 0,void 0,void 0,(function(){return u(this,(function(n){return[2,Pe.deleteWithOptions("/api/files",{data:{files:t,assistant_id:e}})]}))}))},deletePreset:function(t){return Pe.post("/api/presets/delete",t)},genTitle:function(t){return Pe.post("/api/convos/gen_title",t)},getAIEndpoints:function(){return Pe.get("/api/endpoints")},getActions:function(){return Pe.get(be("actions"))},getAssistantById:function(t){return Pe.get(be(t))},getAssistantDocs:function(){return Pe.get(be("documents"))},getAvailablePlugins:function(){return Pe.get("/api/plugins")},getAvailableTools:function(){return Pe.get("".concat(be(),"/tools"))},getConversationById:function(t){return Pe.get(function(t){return"/api/convos/".concat(t)}(t))},getConversations:function(t){return Pe.get(ge(t))},getEndpointsConfigOverride:function(){return Pe.get("/api/endpoints/config/override")},getFileConfig:function(){return Pe.get("".concat("/api/files","/config"))},getFiles:function(){return Pe.get("/api/files")},getLoginGoogle:function(){return Pe.get("/api/auth/google")},getMessagesByConvoId:function(t){return"new"===t?Promise.resolve([]):Pe.get(fe(t))},getModels:function(){return l(void 0,void 0,void 0,(function(){return u(this,(function(t){return[2,Pe.get("/api/models")]}))}))},getPresets:function(){return Pe.get("/api/presets")},getSearchEnabled:function(){return Pe.get("/api/search/enable")},getStartupConfig:function(){return Pe.get("/api/config")},getUser:function(){return Pe.get("/api/user")},getUserBalance:function(){return Pe.get("/api/balance")},listAssistants:function(t){return Pe.get(be(),{params:t})},listConversations:function(t){var e=(null==t?void 0:t.pageNumber)||"1";return Pe.get(ge(e))},listConversationsByQuery:function(t){var e=(null==t?void 0:t.pageNumber)||"1",n=(null==t?void 0:t.searchQuery)||"";return""!==n?Pe.get(ve(n,e)):Pe.get(ge(e))},login:function(t){return Pe.post("/api/auth/login",t)},logout:function(){return Pe.post("/api/auth/logout")},register:function(t){return Pe.post("/api/auth/register",t)},requestPasswordReset:function(t){return Pe.post("/api/auth/requestPasswordReset",t)},resetPassword:function(t){return Pe.post("/api/auth/resetPassword",t)},revokeAllUserKeys:function(){return Pe.delete("".concat(he,"?all=true"))},revokeUserKey:function(t){return Pe.delete(function(t){return"".concat(he,"/").concat(t)}(t))},searchConversations:function(t,e){return l(void 0,void 0,void 0,(function(){return u(this,(function(n){return[2,Pe.get(ve(t,e))]}))}))},updateAction:function(t){var e=t.assistant_id,n=function(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}(t,["assistant_id"]);return Pe.post(be("actions/".concat(e)),n)},updateAssistant:function(t,e){return Pe.patch(be(t),e)},updateConversation:function(t){return Pe.post("/api/convos/update",{arg:t})},updateMessage:function(t){var e=t.conversationId,n=t.messageId,o=t.text;if(!e)throw new Error("conversationId is required");return Pe.put(fe(e,n),{text:o})},updatePreset:function(t){return Pe.post("/api/presets",t)},updateTokenCount:function(t){return Pe.post("/api/tokenizer",{arg:t})},updateUserKey:function(t){if(!t.value)throw new Error("value is required");return Pe.put(he,t)},updateUserPlugins:function(t){return Pe.post("/api/user/plugins",t)},uploadAssistantAvatar:function(t){return Pe.postMultiPart(be("avatar/".concat(t.assistant_id)),t.formData)},uploadAvatar:function(t){return Pe.postMultiPart("".concat(xe(),"/avatar"),t)},uploadFile:function(t){return Pe.postMultiPart("/api/files",t)},uploadImage:function(t){return Pe.postMultiPart(xe(),t)},userKeyQuery:function(t){return Pe.get(function(t){return"".concat(he,"?name=").concat(t)}(t))}}),Le=function(t,e){if(!(this instanceof Le))return new Le(t,e);this.INITIALIZING=-1,this.CONNECTING=0,this.OPEN=1,this.CLOSED=2,this.url=t,e=e||{},this.headers=e.headers||{},this.payload=void 0!==e.payload?e.payload:"",this.method=e.method||this.payload&&"POST"||"GET",this.withCredentials=!!e.withCredentials,this.FIELD_SEPARATOR=":",this.listeners={},this.xhr=null,this.readyState=this.INITIALIZING,this.progress=0,this.chunk="",this.addEventListener=function(t,e){void 0===this.listeners[t]&&(this.listeners[t]=[]),-1===this.listeners[t].indexOf(e)&&this.listeners[t].push(e)},this.removeEventListener=function(t,e){if(void 0!==this.listeners[t]){var n=[];this.listeners[t].forEach((function(t){t!==e&&n.push(t)})),0===n.length?delete this.listeners[t]:this.listeners[t]=n}},this.dispatchEvent=function(t){if(!t)return!0;t.source=this;var e="on"+t.type;return(!this.hasOwnProperty(e)||(this[e].call(this,t),!t.defaultPrevented))&&(!this.listeners[t.type]||this.listeners[t.type].every((function(e){return e(t),!t.defaultPrevented})))},this._setReadyState=function(t){var e=new CustomEvent("readystatechange");e.readyState=t,this.readyState=t,this.dispatchEvent(e)},this._onStreamFailure=function(t){var e=new CustomEvent("error");e.data=t.currentTarget.response,this.dispatchEvent(e),this.close()},this._onStreamAbort=function(t){this.dispatchEvent(new CustomEvent("abort")),this.close()},this._onStreamProgress=async function(t){if(this.xhr){if(401!==this.xhr.status||this._retry){if(200!==this.xhr.status)return void this._onStreamFailure(t)}else{this._retry=!0;try{const t=await Pe.refreshToken();this.headers={"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},me(t.token),window.dispatchEvent(new CustomEvent("tokenUpdated",{detail:t.token})),this.stream()}catch(e){return void this._onStreamFailure(t)}}this.readyState==this.CONNECTING&&(this.dispatchEvent(new CustomEvent("open")),this._setReadyState(this.OPEN));var e=this.xhr.responseText.substring(this.progress);this.progress+=e.length,e.split(/(\r\n|\r|\n){2}/g).forEach(function(t){0===t.trim().length?(this.dispatchEvent(this._parseEventChunk(this.chunk.trim())),this.chunk=""):this.chunk+=t}.bind(this))}},this._onStreamLoaded=function(t){this._onStreamProgress(t),this.dispatchEvent(this._parseEventChunk(this.chunk)),this.chunk=""},this._parseEventChunk=function(t){if(!t||0===t.length)return null;var e={id:null,retry:null,data:"",event:"message"};t.split(/\n|\r\n|\r/).forEach(function(t){var n=(t=t.trimRight()).indexOf(this.FIELD_SEPARATOR);if(!(n<=0)){var o=t.substring(0,n);if(o in e){var i=t.substring(n+1).trimLeft();"data"===o?e[o]+=i:e[o]=i}}}.bind(this));var n=new CustomEvent(e.event);return n.data=e.data,n.id=e.id,n},this._checkStreamClosed=function(){this.xhr&&this.xhr.readyState===XMLHttpRequest.DONE&&this._setReadyState(this.CLOSED)},this.stream=function(){for(var t in this._setReadyState(this.CONNECTING),this.xhr=new XMLHttpRequest,this.xhr.addEventListener("progress",this._onStreamProgress.bind(this)),this.xhr.addEventListener("load",this._onStreamLoaded.bind(this)),this.xhr.addEventListener("readystatechange",this._checkStreamClosed.bind(this)),this.xhr.addEventListener("error",this._onStreamFailure.bind(this)),this.xhr.addEventListener("abort",this._onStreamAbort.bind(this)),this.xhr.open(this.method,this.url),this.headers)this.xhr.setRequestHeader(t,this.headers[t]);this.xhr.withCredentials=this.withCredentials,this.xhr.send(this.payload)},this.close=function(){this.readyState!==this.CLOSED&&(this.xhr.abort(),this.xhr=null,this._setReadyState(this.CLOSED))}};function Ae(t){return o.createHash("sha1").update(t).digest("hex")}function ke(t,e){return new n(e,t).toString()}var Ce=function(){function t(t,e,n){var o,i;this.name=t,this.description=e,(null===(o=n.properties)||void 0===o?void 0:o.requestBody)?this.parameters=null===(i=n.properties)||void 0===i?void 0:i.requestBody:this.parameters=n}return t.prototype.toObjectTool=function(){return{type:Vt.function,function:{name:this.name,description:this.description,parameters:this.parameters}}},t}(),Te=function(){function t(t,e,n,o,i,r){this.authHeaders={},this.domain=t,this.path=e,this.method=n,this.operation=o,this.isConsequential=i,this.contentType=r}return t.prototype.setParams=function(t){return l(this,void 0,void 0,(function(){return u(this,(function(e){return this.operationHash=Ae(JSON.stringify(t)),this.params=t,[2]}))}))},t.prototype.setAuth=function(t){return l(this,void 0,void 0,(function(){var n,o,i,r,a,s,l,p,c,d,m,f,h,g,v;return u(this,(function(u){switch(u.label){case 0:return t.auth?(n=t.auth,o=n.type,i=n.authorization_type,r=n.custom_auth_header,a=n.authorization_url,s=n.client_url,l=n.scope,p=n.token_exchange_method,c=t.api_key,d=t.oauth_client_id,m=t.oauth_client_secret,f=c&&o===re.ServiceHttp,h=d&&m&&o===re.OAuth&&a&&s&&l&&p,f&&i===ae.Basic?(g=Buffer.from(c).toString("base64"),this.authHeaders.Authorization="Basic ".concat(g),[3,6]):[3,1]):[2];case 1:return f&&i===ae.Bearer?(this.authHeaders.Authorization="Bearer ".concat(c),[3,6]):[3,2];case 2:return f&&i===ae.Custom&&r?(this.authHeaders[r]=c,[3,6]):[3,3];case 3:return h?this.authToken?[3,5]:[4,e.post(s,{client_id:d,client_secret:m,scope:l,grant_type:"client_credentials"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})]:[3,6];case 4:v=u.sent(),this.authToken=v.data.access_token,u.label=5;case 5:this.authHeaders.Authorization="Bearer ".concat(this.authToken),u.label=6;case 6:return[2]}}))}))},t.prototype.execute=function(){return l(this,void 0,void 0,(function(){var t,n,o;return u(this,(function(i){if(t=ke(this.domain,this.path),n=s(s({},this.authHeaders),{"Content-Type":this.contentType}),"get"===(o=this.method.toLowerCase()))return[2,e.get(t,{headers:n,params:this.params})];if("post"===o)return[2,e.post(t,this.params,{headers:n})];if("put"===o)return[2,e.put(t,this.params,{headers:n})];if("delete"===o)return[2,e.delete(t,{headers:n,data:this.params})];if("patch"===o)return[2,e.patch(t,this.params,{headers:n})];throw new Error("Unsupported HTTP method: ".concat(this.method))}))}))},t}();function Se(t,e){var n;if("$ref"in t&&e){var o=t.$ref.replace(/^#\/components\/schemas\//,""),i=null===(n=e.schemas)||void 0===n?void 0:n[o];if(!i)throw new Error("Reference ".concat(t.$ref," not found"));return Se(i,e)}return t}function je(t){for(var e,n,o,i,r=[],a={},l=null!==(o=null===(n=null===(e=t.servers)||void 0===e?void 0:e[0])||void 0===n?void 0:n.url)&&void 0!==o?o:"",u=0,p=Object.entries(t.paths);u<p.length;u++)for(var c=p[u],d=c[0],m=c[1],f=0,h=Object.entries(m);f<h.length;f++){var g=h[f],v=g[0],b=g[1],x=b.operationId||"".concat(v,"_").concat(d),y=b.summary||b.description||"",_={type:"object",properties:{},required:[]};if(b.requestBody){var I=b.requestBody.content,O=Se(null===(i=I[Object.keys(I)[0]])||void 0===i?void 0:i.schema,t.components);_.properties.requestBody=O}if(b.parameters)for(var E=0,P=b.parameters;E<P.length;E++){var w=P[E];O=Se(s({},w.schema),t.components);_.properties[w.name]=O,w.required&&_.required.push(w.name),w.description&&!("$$ref"in _.properties[w.name])&&(_.properties[w.name].description=w.description)}var L=new Ce(x,y,_);r.push(L);var A=new Te(l,d,v,x,!!b["x-openai-isConsequential"],b.requestBody?"application/json":"application/x-www-form-urlencoded");a[x]=A}return{functionSignatures:r,requestBuilders:a}}function Ge(t){var e;try{var n=void 0;try{n=JSON.parse(t)}catch(e){n=i(t)}if(!n.servers||!Array.isArray(n.servers)||0===n.servers.length)return{status:!1,message:"Could not find a valid URL in `servers`"};if(!n.servers[0].url)return{status:!1,message:"Could not find a valid URL in `servers`"};var o=n.paths;if(!o||"object"!=typeof o||0===Object.keys(o).length)return{status:!1,message:"No paths found in the OpenAPI spec."};for(var r=(null===(e=n.components)||void 0===e?void 0:e.schemas)||{},a=[],s=0,l=Object.entries(o);s<l.length;s++)for(var u=l[s],p=u[0],c=u[1],d=0,m=Object.entries(c);d<m.length;d++){var f=m[d],h=f[0],g=f[1],v=g.responses;if("object"==typeof g&&v)for(var b=0,x=Object.entries(v);b<x.length;b++){var y=x[b],_=y[0],I=y[1].content;if(I&&I["application/json"]&&I["application/json"].schema){var O=I["application/json"].schema;if("$ref"in O&&"string"==typeof O.$ref){var E=O.$ref.split("/").pop();E&&!r[E]&&a.push("In context=('paths', '".concat(p,"', '").concat(h,"', '").concat(_,"', 'response', 'content', 'application/json', 'schema'), reference to unknown component ").concat(E,"; using empty schema"))}}}}return{status:!0,message:a.join("\n")||"OpenAPI spec is valid.",spec:n}}catch(t){return{status:!1,message:"Error parsing OpenAPI spec."}}}function Ne(t){var e=t.conversation,n=t.message;t.messages;var o=t.endpointOption,i=t.isEdited,r=t.isContinued,a=k.parse(e).conversationId,l=o,u=l.endpoint,p=l.endpointType,d=Tt[null!=p?p:u];return i&&u===c.assistants?d+="/modify":i&&(d=d.replace("/ask/","/edit/")),{server:d,payload:s(s(s({},n),o),{isContinued:!(!i||!r),conversationId:a})}}export{Te as ActionRequest,zt as AuthKeys,re as AuthTypeEnum,ae as AuthorizationTypeEnum,Mt as CacheKeys,qt as Constants,Wt as ContentTypes,c as EModelEndpoint,Tt as EndpointURLs,q as FileContext,le as FilePurpose,B as FileSources,Ce as FunctionSignature,m as ImageDetail,Dt as ImageDetailCost,yt as KnownEndpoints,Zt as MessageContentTypes,pe as MutationKeys,ue as QueryKeys,te as RunStatus,Le as SSE,Bt as SettingsTabValues,Yt as StepStatus,Xt as StepTypes,se as TokenExchangeMethodEnum,Jt as ToolCallTypes,Vt as Tools,Rt as ViolationTypes,ce as actionDelimiter,At as alternateName,G as anthropicSchema,st as applicationMimeTypes,Ot as assistantEndpointSchema,Q as assistantSchema,j as bingAISchema,N as chatGPTBrowserSchema,pt as codeInterpreterMimeTypes,nt as codeInterpreterMimeTypesList,X as compactAnthropicSchema,J as compactChatGPTSchema,W as compactGoogleSchema,V as compactOpenAISchema,Y as compactPluginsSchema,wt as configSchema,bt as convertStringsToRegex,Ne as createPayload,ke as createURL,we as dataService,f as defaultAssistantFormValues,Lt as defaultEndpoints,kt as defaultModels,Ht as defaultOrderQuery,_t as defaultSocialLogins,_ as eImageDetailSchema,v as eModelEndpointSchema,gt as endpointFileConfigSchema,Et as endpointSchema,h as endpointSettings,tt as excelFileTypes,rt as excelMimeTypes,b as extendedModelEndpointSchema,ft as fileConfig,vt as fileConfigSchema,It as fileSourceSchema,et as fullMimeTypesList,Qt as getFirstDefinedValue,ne as getResponseSender,S as googleSchema,M as gptPluginsSchema,x as imageDetailNumeric,y as imageDetailValue,it as imageExtRegex,Ut as imageGenTools,lt as imageMimeTypes,d as isUUID,mt as mbToBytes,dt as megabyte,xt as mergeFileConfig,St as modularEndpoints,T as openAISchema,je as openapiToFunction,ie as parseCompactConvo,ee as parseConvo,Pt as rateLimitSchema,R as removeNullishValues,Pe as request,Se as resolveRef,ct as retrievalMimeTypes,ot as retrievalMimeTypesList,de as setAcceptLanguageHeader,me as setTokenHeader,Ae as sha1,ut as supportedMimeTypes,jt as supportsBalanceCheck,Z as supportsFiles,Ct as supportsRetrieval,P as tAgentOptionsSchema,L as tConversationSchema,k as tConvoUpdateSchema,E as tExampleSchema,w as tMessageSchema,I as tPluginAuthConfigSchema,O as tPluginSchema,A as tPresetSchema,C as tPresetUpdateSchema,at as textMimeTypes,Ge as validateAndParseOpenAPISpec,Nt as validateVisionModel,Gt as visionModels};
2
2
  //# sourceMappingURL=index.es.js.map