librechat-data-provider 0.4.2 → 0.4.4

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