librechat-data-provider 0.4.7 → 0.4.8
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 +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react-query/index.es.js +1 -1
- package/dist/react-query/index.es.js.map +1 -1
- package/package.json +1 -1
- package/specs/azure.spec.ts +55 -1
- package/src/api-endpoints.ts +14 -1
- package/src/azure.ts +92 -7
- package/src/config.ts +49 -9
- package/src/data-service.ts +6 -3
- package/src/schemas.ts +1 -1
- package/src/types/mutations.ts +3 -0
- package/src/types.ts +14 -0
package/dist/index.es.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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){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}function u(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 p(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 c(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 d,m=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"}(d||(d={}));var f,g={assistant:"",id:"",name:"",description:"",instructions:"",model:"gpt-3.5-turbo-1106",functions:[],code_interpreter:!1,retrieval:!1},h=((r={})[d.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),v=h[d.google],b=e.nativeEnum(d),y=e.union([b,e.string()]);!function(e){e.low="low",e.auto="auto",e.high="high"}(f||(f={}));var x=((a={})[f.low]=0,a[f.auto]=1,a[f.high]=2,a),_={0:f.low,1:f.auto,2:f.high},E=e.nativeEnum(f),I=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(I),authenticated:e.boolean().optional(),isButton:e.boolean().optional()}),A=e.object({input:e.object({content:e.string()}),output:e.object({content:e.string()})}),P=e.object({agent:e.string(),skipCompletion:e.boolean(),model:e.string(),temperature:e.number()}),L=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()}),w=e.object({conversationId:e.string().nullable(),title:e.string().nullable().or(e.literal("New Chat")).default("New Chat"),user:e.string().optional(),endpoint:b.nullable(),endpointType:b.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(A).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:P.nullable().optional(),file_ids:e.array(e.string()).optional(),resendImages:e.boolean().optional(),imageDetail:E.optional(),assistant_id:e.string().optional(),instructions:e.string().optional(),presetOverride:e.record(e.unknown()).optional()}),k=w.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:y.nullable()})),T=w.merge(e.object({endpoint:y.nullable()})),C=w.merge(e.object({endpoint:y.nullable()})),S=w.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:f.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:f.auto}})),N=w.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?v.maxOutputTokens.maxGeminiPro:v.maxOutputTokens.max,f=d?v.maxOutputTokens.defaultGeminiPro:v.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:v.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:v.temperature.default,maxOutputTokens:g,topP:null!==(p=e.topP)&&void 0!==p?p:v.topP.default,topK:null!==(c=e.topK)&&void 0!==c?c:v.topK.default})})).catch((function(){return{model:v.model.default,modelLabel:null,promptPrefix:null,examples:[{input:{content:""},output:{content:""}}],temperature:v.temperature.default,maxOutputTokens:v.maxOutputTokens.default,topP:v.topP.default,topK:v.topK.default}})),j=w.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}})),M=w.pick({model:!0,modelLabel:!0,promptPrefix:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0,resendImages:!0}).transform((function(e){var t,n,o,i,r,a,l,u;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,resendImages:null!==(u=e.resendImages)&&void 0!==u&&u})})).catch((function(){return{model:"claude-1",modelLabel:null,promptPrefix:null,temperature:1,maxOutputTokens:4e3,topP:.7,topK:5,resendImages:!1}})),G=w.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"}})),R=w.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 z(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 D,U,q,K,B,F,H,V,$,Z=w.pick({model:!0,assistant_id:!0,instructions:!0,promptPrefix:!0}).transform(z).catch((function(){return{}})),Y=w.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===f.auto&&delete t.imageDetail,z(t)})).catch((function(){return{}})),Q=w.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===v.temperature.default&&delete t.temperature,t.maxOutputTokens===v.maxOutputTokens.default&&delete t.maxOutputTokens,t.topP===v.topP.default&&delete t.topP,t.topK===v.topK.default&&delete t.topK,z(t)})).catch((function(){return{}})),W=w.pick({model:!0,modelLabel:!0,promptPrefix:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0,resendImages:!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,!0!==t.resendImages&&delete t.resendImages,z(t)})).catch((function(){return{}})),X=w.pick({model:!0}).transform((function(e){return z(s({},e))})).catch((function(){return{}})),J=w.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,z(n)})).catch((function(){return{}})),ee=((D={})[d.openAI]=!0,D[d.google]=!0,D[d.assistants]=!0,D[d.azureOpenAI]=!0,D[d.anthropic]=!0,D[d.custom]=!0,D),te=["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"],ne=c(["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"],te,!0),oe=c(["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"],te,!0),ie=["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"],re=/\.(jpg|jpeg|png|gif|webp)$/i,ae=/^application\/(vnd\.ms-excel|msexcel|x-msexcel|x-ms-excel|x-excel|x-dos_ms_excel|xls|x-xls|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet)$/,se=/^(text\/(x-c|x-c\+\+|x-java|html|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain|css|javascript|csv))$/,le=/^(application\/(csv|json|pdf|x-tar|typescript|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation|spreadsheetml\.sheet)|xml|zip))$/,ue=/^image\/(jpeg|gif|png|webp)$/,pe=[se,ae,le,ue],ce=[se,ae,le,ue],de=[/^(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)))$/],me=1048576,fe=function(e){return e*me},ge={endpoints:(U={},U[d.assistants]={fileLimit:10,fileSizeLimit:fe(512),totalSizeLimit:fe(512),supportedMimeTypes:pe,disabled:!1},U.default={fileLimit:10,fileSizeLimit:fe(20),totalSizeLimit:fe(25),supportedMimeTypes:[ue],disabled:!1},U),serverFileSizeLimit:fe(512),avatarSizeLimit:fe(2),checkType:function(e,t){return void 0===t&&(t=pe),t.some((function(t){return t.test(e)}))}},he=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."}),ve=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:he.optional()}),be=e.object({endpoints:e.record(ve).optional(),serverFileSizeLimit:e.number().min(0).optional(),avatarSizeLimit:e.number().min(0).optional()}),ye=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 xe(e){var t=ge;if(!e)return t;if(void 0!==e.serverFileSizeLimit&&(t.serverFileSizeLimit=fe(e.serverFileSizeLimit)),void 0!==e.avatarSizeLimit&&(t.avatarSizeLimit=fe(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=fe(o.fileSizeLimit)),void 0!==o.totalSizeLimit&&(i.totalSizeLimit=fe(o.totalSizeLimit));["fileLimit"].forEach((function(e){void 0!==o[e]&&(i[e]=o[e])})),o.supportedMimeTypes&&(i.supportedMimeTypes=ye(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"}(q||(q={})),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"}(K||(K={}));var _e,Ee,Ie=["google","facebook","openid","github","discord"],Oe=e.nativeEnum(q),Ae=e.object({deploymentName:e.string().optional(),version:e.string().optional()}).or(e.boolean()),Pe=e.object({apiKey:e.string(),serverless:e.boolean().optional(),instanceName:e.string().optional(),deploymentName:e.string().optional(),addParams:e.record(e.any()).optional(),dropParams:e.array(e.string()).optional(),forcePrompt:e.boolean().optional(),version:e.string().optional(),baseURL:e.string().optional(),additionalHeaders:e.record(e.any()).optional()}),Le=e.object({group:e.string(),models:e.record(e.string(),Ae)}).required().and(Pe),we=e.array(Le).min(1),ke=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()}),Te=e.object({name:e.string().refine((function(e){return!b.safeParse(e).success}),{message:"Value cannot be one of the default endpoint (EModelEndpoint) values: ".concat(Object.values(d).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()}),Ce=e.object({groups:we,plugins:e.boolean().optional()}).and(Te.pick({titleConvo:!0,titleMethod:!0,titleModel:!0,summarize:!0,summaryModel:!0,customOrder:!0}).partial()),Se=e.object({fileUploads:e.object({ipMax:e.number().optional(),ipWindowInMinutes:e.number().optional(),userMax:e.number().optional(),userWindowInMinutes:e.number().optional()}).optional()}),Ne=e.object({version:e.string(),cache:e.boolean(),fileStrategy:Oe.optional(),registration:e.object({socialLogins:e.array(e.string()).optional(),allowedDomains:e.array(e.string()).optional()}).optional(),rateLimits:Se.optional(),fileConfig:be.optional(),endpoints:e.object((B={},B[d.azureOpenAI]=Ce.optional(),B[d.assistants]=ke.optional(),B.custom=e.array(Te.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",e.groq="groq",e.anyscale="anyscale",e.fireworks="fireworks",e.ollama="ollama",e.perplexity="perplexity",e["together.ai"]="together.ai"}(_e||(_e={})),function(e){e.openrouter="openrouter"}(Ee||(Ee={}));var je=[d.openAI,d.assistants,d.azureOpenAI,d.bingAI,d.chatGPTBrowser,d.gptPlugins,d.google,d.anthropic,d.custom],Me=((F={})[d.openAI]="OpenAI",F[d.assistants]="Assistants",F[d.azureOpenAI]="Azure OpenAI",F[d.bingAI]="Bing",F[d.chatGPTBrowser]="ChatGPT",F[d.gptPlugins]="Plugins",F[d.google]="Google",F[d.anthropic]="Anthropic",F[d.custom]="Custom",F),Ge=((H={})[d.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"],H[d.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"],H[d.anthropic]=["claude-3-opus-20240229","claude-3-sonnet-20240229","claude-2.1","claude-2","claude-1.2","claude-1","claude-1-100k","claude-instant-1","claude-instant-1-100k"],H[d.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"],H),Re=new Set(["gpt-3.5-turbo-0125","gpt-4-0125-preview","gpt-4-turbo-preview","gpt-4-1106-preview","gpt-3.5-turbo-1106"]),ze=((V={})[d.openAI]="/api/ask/".concat(d.openAI),V[d.bingAI]="/api/ask/".concat(d.bingAI),V[d.google]="/api/ask/".concat(d.google),V[d.custom]="/api/ask/".concat(d.custom),V[d.anthropic]="/api/ask/".concat(d.anthropic),V[d.gptPlugins]="/api/ask/".concat(d.gptPlugins),V[d.azureOpenAI]="/api/ask/".concat(d.azureOpenAI),V[d.chatGPTBrowser]="/api/ask/".concat(d.chatGPTBrowser),V[d.assistants]="/api/assistants/chat",V),De=new Set([d.gptPlugins,d.anthropic,d.google,d.openAI,d.azureOpenAI,d.custom]),Ue=(($={})[d.openAI]=!0,$[d.anthropic]=!0,$[d.azureOpenAI]=!0,$[d.gptPlugins]=!0,$[d.custom]=!0,$),qe=["gpt-4-vision","llava-13b","gemini-pro-vision","claude-3"];function Ke(e){var t=e.model,n=e.additionalModels,o=void 0===n?[]:n,i=e.availableModels;return!!t&&(!(i&&!i.includes(t))&&qe.concat(o).some((function(e){return t.includes(e)})))}var Be,Fe,He,Ve,$e,Ze,Ye=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"}(Be||(Be={})),function(e){e.FILE_UPLOAD_LIMIT="file_upload_limit",e.ILLEGAL_MODEL_REQUEST="illegal_model_request"}(Fe||(Fe={})),function(e){e.GOOGLE_SERVICE_KEY="GOOGLE_SERVICE_KEY",e.GOOGLE_API_KEY="GOOGLE_API_KEY"}(He||(He={})),function(e){e[e.LOW=85]="LOW",e[e.HIGH=170]="HIGH",e[e.ADDITIONAL=85]="ADDITIONAL"}(Ve||(Ve={})),function(e){e.GENERAL="general",e.BETA="beta",e.DATA="data",e.ACCOUNT="account"}($e||($e={})),function(e){e.VERSION="v0.6.10",e.CONFIG_VERSION="1.0.4",e.NO_PARENT="00000000-0000-0000-0000-000000000000"}(Ze||(Ze={}));var Qe,We,Xe={order:"asc"},Je=((Qe={})[d.openAI]=S,Qe[d.azureOpenAI]=S,Qe[d.custom]=S,Qe[d.google]=N,Qe[d.bingAI]=j,Qe[d.anthropic]=M,Qe[d.chatGPTBrowser]=G,Qe[d.gptPlugins]=R,Qe[d.assistants]=Z,Qe);function et(){var e=[d.openAI,d.assistants,d.azureOpenAI,d.google,d.bingAI,d.chatGPTBrowser,d.gptPlugins,d.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 tt(e){if(!e)return{};var t=et(),n=Object.keys(e),o=t.indexOf(d.custom);return n.reduce((function(n,i){var r=!(i in d);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 nt(e){return e.map((function(e){var t=e.path.join("."),n=e.message;return"".concat(t,": ").concat(n)})).join(" ")}var ot=/^\${(.+)}$/;function it(e){var t=e.match(ot);return t&&process.env[t[1]]||e}function rt(e){var t=s({},null!=e?e:{});return e&&"object"==typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(n){t[n]=it(e[n])})),t}function at(e){for(var t,n=0,o=e;n<o.length;n++){var i=o[n];if(i){t=i;break}}return t}var st,lt,ut,pt,ct,dt,mt,ft=function(e){var t,n,o=e.endpoint,i=e.endpointType,r=e.conversation,a=e.possibleValues,s=Je[o];if(!s&&!i)throw new Error("Unknown endpoint: ".concat(o));!s&&i&&(s=Je[i]);var l=s.parse(r),u=null!=a?a:{},p=u.models,c=u.secondaryModels;return p&&l&&(l.model=null!==(t=at(p))&&void 0!==t?t:l.model),c&&l.agentOptions&&(l.agentOptions.model=null!==(n=at(c))&&void 0!==n?n:l.agentOptions.model),l},gt=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[d.openAI,d.azureOpenAI,d.gptPlugins,d.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=Me[o])&&void 0!==t?t:"ChatGPT"):o===d.bingAI?l?"Sydney":"BingAI":o===d.anthropic?null!=s?s:"Claude":o===d.google?s||(n&&n.includes("gemini")?"Gemini":n&&n.includes("code")?"Codey":"PaLM2"):o===d.custom||i===d.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")):""},ht=((We={})[d.openAI]=Y,We[d.azureOpenAI]=Y,We[d.custom]=Y,We[d.assistants]=Z,We[d.google]=Q,We[d.bingAI]=j,We[d.anthropic]=W,We[d.chatGPTBrowser]=X,We[d.gptPlugins]=J,We),vt=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=ht[n];if(!a&&!o)throw new Error("Unknown endpoint: ".concat(n));!a&&o&&(a=ht[o]);var s=a.parse(i),l=(null!=r?r:{}).models;return l&&s&&(s.model=null!==(t=at(l))&&void 0!==t?t:s.model),s},bt=[{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"}],yt=[{key:"INSTANCE_NAME"},{key:"DEPLOYMENT_NAME"}];function xt(e){var t=!0,n=[],o={},i={},r=[],a=we.safeParse(e);if(a.success)for(var u=0,p=a.data;u<p.length;u++){var c=p[u],d=c.group,m=c.apiKey,f=c.instanceName,g=c.deploymentName,h=c.version,v=c.baseURL,b=c.additionalHeaders,y=c.models,x=c.serverless,_=l(c,["group","apiKey","instanceName","deploymentName","version","baseURL","additionalHeaders","models","serverless"]);if(i[d])return r.push('Duplicate group name detected: "'.concat(d,'". Group names must be unique.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:i,errors:r};if(x&&!v)return r.push('Group "'.concat(d,'" is serverless but missing mandatory "baseURL."')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:i,errors:r};if(!f&&!x)return r.push('Group "'.concat(d,'" is missing an "instanceName" for non-serverless configuration.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:i,errors:r};for(var E in i[d]=s({apiKey:m,instanceName:f,deploymentName:g,version:h,baseURL:v,additionalHeaders:b,models:y,serverless:x},_),c.models){n.push(E);var I=c.models[E];if(o[E])return r.push('Duplicate model name detected: "'.concat(E,'". Model names must be unique across groups.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:i,errors:r};if(x)o[E]={group:d};else if("boolean"==typeof I){if(!c.deploymentName||!c.version)return r.push('Model "'.concat(E,'" in group "').concat(d,'" is missing a deploymentName or version.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:i,errors:r};o[E]={group:d}}else{if(!I.deploymentName&&!c.deploymentName||!I.version&&!c.version)return r.push('Model "'.concat(E,'" in group "').concat(d,'" is missing a required deploymentName or version.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:i,errors:r};o[E]={group:d}}}}else t=!1,r.push(nt(a.error.errors));return{isValid:t,modelNames:n,modelGroupMap:o,groupMap:i,errors:r}}function _t(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.instanceName;if(!a&&!r.serverless)throw new Error('Group "'.concat(i.group,'" is missing an instanceName for non-serverless configuration.'));if(r.serverless&&!r.baseURL)throw new Error('Group "'.concat(i.group,'" is missing the required base URL for serverless configuration.'));if(r.serverless){var s={azureOptions:{azureOpenAIApiKey:it(r.apiKey)},baseURL:it(r.baseURL),serverless:!0},l=s.azureOptions.azureOpenAIApiKey;if("string"==typeof l&&ot.test(l))throw new Error('Azure configuration environment variable "'.concat(l,'" was not found.'));return r.additionalHeaders&&(s.headers=r.additionalHeaders),s}if(!a)throw new Error('Group "'.concat(i.group,'" is missing an instanceName for non-serverless configuration.'));var u=r.models[t],p="object"==typeof u&&u.deploymentName||r.deploymentName,c="object"==typeof u&&u.version||r.version;if(!p||!c)throw new Error('Model "'.concat(t,'" in group "').concat(i.group,'" is missing a deploymentName ("').concat(p,'") or version ("').concat(c,'").'));for(var d={azureOpenAIApiKey:it(r.apiKey),azureOpenAIApiInstanceName:it(a),azureOpenAIApiDeploymentName:it(p),azureOpenAIApiVersion:it(c)},m=0,f=Object.values(d);m<f.length;m++){var g=f[m];if("string"==typeof g&&ot.test(g))throw new Error('Azure configuration environment variable "'.concat(g,'" was not found.'))}var h={azureOptions:d};return r.baseURL&&(h.baseURL=it(r.baseURL)),r.additionalHeaders&&(h.headers=r.additionalHeaders),h}!function(e){e.code_interpreter="code_interpreter",e.retrieval="retrieval",e.function="function"}(st||(st={})),function(e){e.TEXT="text",e.TOOL_CALL="tool_call",e.IMAGE_FILE="image_file"}(lt||(lt={})),function(e){e.TOOL_CALLS="tool_calls",e.MESSAGE_CREATION="message_creation"}(ut||(ut={})),function(e){e.FUNCTION="function",e.RETRIEVAL="retrieval",e.CODE_INTERPRETER="code_interpreter"}(pt||(pt={})),function(e){e.IN_PROGRESS="in_progress",e.CANCELLED="cancelled",e.FAILED="failed",e.COMPLETED="completed",e.EXPIRED="expired"}(ct||(ct={})),function(e){e.TEXT="text",e.IMAGE_FILE="image_file"}(dt||(dt={})),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"}(mt||(mt={}));var Et,It,Ot,At,Pt,Lt,wt="_action_";function kt(e){t.defaults.headers.common["Accept-Language"]=e}function Tt(e){t.defaults.headers.common.Authorization="Bearer "+e}!function(e){e.ServiceHttp="service_http",e.OAuth="oauth",e.None="none"}(Et||(Et={})),function(e){e.Bearer="bearer",e.Basic="basic",e.Custom="custom"}(It||(It={})),function(e){e.DefaultPost="default_post",e.BasicAuthHeader="basic_auth_header"}(Ot||(Ot={})),function(e){e.FineTune="fine-tune",e.FineTuneResults="fine-tune-results",e.Assistants="assistants",e.AssistantsOutput="assistants_output"}(At||(At={})),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"}(Pt||(Pt={})),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"}(Lt||(Lt={}));var Ct=function(e,t){return"/api/messages/".concat(e).concat(t?"/".concat(t):"")},St="/api/keys",Nt=function(e){return"/api/convos?pageNumber=".concat(e)},jt=function(e,t){return"/api/search?q=".concat(e,"&pageNumber=").concat(t)},Mt=function(e){return"/api/assistants".concat(e?"/".concat(e):"")},Gt=function(){return"".concat("/api/files","/images")};function Rt(e,n){return u(this,void 0,void 0,(function(){return p(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 zt=!1,Dt=[],Ut=function(e){return Rt(function(e){return"/api/auth/refresh".concat(e?"?retry=true":"")}(e))},qt=function(e,t){void 0===t&&(t=null),Dt.forEach((function(n){e?n.reject(e):n.resolve(t)})),Dt=[]};t.interceptors.response.use((function(e){return e}),(function(e){return u(void 0,void 0,void 0,(function(){var n,o,i,r,a;return p(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,!zt)return[3,5];s.label=1;case 1:return s.trys.push([1,4,,5]),[4,new Promise((function(e,t){Dt.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:zt=!0,s.label=6;case 6:return s.trys.push([6,11,12,13]),[4,Ut(!!(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,Tt(i),window.dispatchEvent(new CustomEvent("tokenUpdated",{detail:i})),qt(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(),qt(r,null),[2,Promise.reject(r)];case 12:return zt=!1,[7];case 13:return[2,Promise.reject(e)]}}))}))}));var Kt={get:function(e,n){return u(this,void 0,void 0,(function(){return p(this,(function(o){switch(o.label){case 0:return[4,t.get(e,s({},n))];case 1:return[2,o.sent().data]}}))}))},post:Rt,postMultiPart:function(e,n,o){return u(this,void 0,void 0,(function(){return p(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 u(this,void 0,void 0,(function(){return p(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 u(this,void 0,void 0,(function(){return p(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 u(this,void 0,void 0,(function(){return p(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 u(this,void 0,void 0,(function(){return p(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:Ut};var Bt=Object.freeze({__proto__:null,abortRequestWithMessage:function(e,t,n){return Kt.post(function(e){return"/api/ask/".concat(e,"/abort")}(e),{arg:{abortKey:t,message:n}})},clearAllConversations:function(){return Kt.post("/api/convos/clear",{arg:{}})},createAssistant:function(e){return Kt.post(Mt(),e)},createPreset:function(e){return Kt.post("/api/presets",e)},deleteAction:function(e,t){return u(void 0,void 0,void 0,(function(){return p(this,(function(n){return[2,Kt.delete(Mt("actions/".concat(e,"/").concat(t)))]}))}))},deleteAssistant:function(e){return Kt.delete(Mt(e))},deleteConversation:function(e){return Kt.post("/api/convos/clear",{arg:e})},deleteFiles:function(e,t){return u(void 0,void 0,void 0,(function(){return p(this,(function(n){return[2,Kt.deleteWithOptions("/api/files",{data:{files:e,assistant_id:t}})]}))}))},deletePreset:function(e){return Kt.post("/api/presets/delete",e)},genTitle:function(e){return Kt.post("/api/convos/gen_title",e)},getAIEndpoints:function(){return Kt.get("/api/endpoints")},getActions:function(){return Kt.get(Mt("actions"))},getAssistantById:function(e){return Kt.get(Mt(e))},getAssistantDocs:function(){return Kt.get(Mt("documents"))},getAvailablePlugins:function(){return Kt.get("/api/plugins")},getAvailableTools:function(){return Kt.get("".concat(Mt(),"/tools"))},getConversationById:function(e){return Kt.get(function(e){return"/api/convos/".concat(e)}(e))},getConversations:function(e){return Kt.get(Nt(e))},getEndpointsConfigOverride:function(){return Kt.get("/api/endpoints/config/override")},getFileConfig:function(){return Kt.get("".concat("/api/files","/config"))},getFiles:function(){return Kt.get("/api/files")},getLoginGoogle:function(){return Kt.get("/api/auth/google")},getMessagesByConvoId:function(e){return"new"===e?Promise.resolve([]):Kt.get(Ct(e))},getModels:function(){return u(void 0,void 0,void 0,(function(){return p(this,(function(e){return[2,Kt.get("/api/models")]}))}))},getPresets:function(){return Kt.get("/api/presets")},getSearchEnabled:function(){return Kt.get("/api/search/enable")},getStartupConfig:function(){return Kt.get("/api/config")},getUser:function(){return Kt.get("/api/user")},getUserBalance:function(){return Kt.get("/api/balance")},listAssistants:function(e){return Kt.get(Mt(),{params:e})},listConversations:function(e){var t=(null==e?void 0:e.pageNumber)||"1";return Kt.get(Nt(t))},listConversationsByQuery:function(e){var t=(null==e?void 0:e.pageNumber)||"1",n=(null==e?void 0:e.searchQuery)||"";return""!==n?Kt.get(jt(n,t)):Kt.get(Nt(t))},login:function(e){return Kt.post("/api/auth/login",e)},logout:function(){return Kt.post("/api/auth/logout")},register:function(e){return Kt.post("/api/auth/register",e)},requestPasswordReset:function(e){return Kt.post("/api/auth/requestPasswordReset",e)},resetPassword:function(e){return Kt.post("/api/auth/resetPassword",e)},revokeAllUserKeys:function(){return Kt.delete("".concat(St,"?all=true"))},revokeUserKey:function(e){return Kt.delete(function(e){return"".concat(St,"/").concat(e)}(e))},searchConversations:function(e,t){return u(void 0,void 0,void 0,(function(){return p(this,(function(n){return[2,Kt.get(jt(e,t))]}))}))},updateAction:function(e){var t=e.assistant_id,n=l(e,["assistant_id"]);return Kt.post(Mt("actions/".concat(t)),n)},updateAssistant:function(e,t){return Kt.patch(Mt(e),t)},updateConversation:function(e){return Kt.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 Kt.put(Ct(t,n),{text:o})},updatePreset:function(e){return Kt.post("/api/presets",e)},updateTokenCount:function(e){return Kt.post("/api/tokenizer",{arg:e})},updateUserKey:function(e){if(!e.value)throw new Error("value is required");return Kt.put(St,e)},updateUserPlugins:function(e){return Kt.post("/api/user/plugins",e)},uploadAssistantAvatar:function(e){return Kt.postMultiPart(Mt("avatar/".concat(e.assistant_id)),e.formData)},uploadAvatar:function(e){return Kt.postMultiPart("".concat(Gt(),"/avatar"),e)},uploadFile:function(e){return Kt.postMultiPart("/api/files",e)},uploadImage:function(e){return Kt.postMultiPart(Gt(),e)},userKeyQuery:function(e){return Kt.get(function(e){return"".concat(St,"?name=").concat(e)}(e))}}),Ft=function(e,t){if(!(this instanceof Ft))return new Ft(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 Kt.refreshToken();this.headers={"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},Tt(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 Ht(e){return o.createHash("sha1").update(e).digest("hex")}function Vt(e,t){return new n(t,e).toString()}var $t=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:st.function,function:{name:this.name,description:this.description,parameters:this.parameters}}},e}(),Zt=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 u(this,void 0,void 0,(function(){return p(this,(function(t){return this.operationHash=Ht(JSON.stringify(e)),this.params=e,[2]}))}))},e.prototype.setAuth=function(e){return u(this,void 0,void 0,(function(){var n,o,i,r,a,s,l,u,c,d,m,f,g,h,v;return p(this,(function(p){switch(p.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,u=n.token_exchange_method,c=e.api_key,d=e.oauth_client_id,m=e.oauth_client_secret,f=c&&o===Et.ServiceHttp,g=d&&m&&o===Et.OAuth&&a&&s&&l&&u,f&&i===It.Basic?(h=Buffer.from(c).toString("base64"),this.authHeaders.Authorization="Basic ".concat(h),[3,6]):[3,1]):[2];case 1:return f&&i===It.Bearer?(this.authHeaders.Authorization="Bearer ".concat(c),[3,6]):[3,2];case 2:return f&&i===It.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=p.sent(),this.authToken=v.data.access_token,p.label=5;case 5:this.authHeaders.Authorization="Bearer ".concat(this.authToken),p.label=6;case 6:return[2]}}))}))},e.prototype.execute=function(){return u(this,void 0,void 0,(function(){var e,n,o;return p(this,(function(i){if(e=Vt(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 Yt(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 Yt(i,t)}return e}function Qt(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,I=Yt(null===(i=E[Object.keys(E)[0]])||void 0===i?void 0:i.schema,e.components);_.properties.requestBody=I}if(b.parameters)for(var O=0,A=b.parameters;O<A.length;O++){var P=A[O];I=Yt(s({},P.schema),e.components);_.properties[P.name]=I,P.required&&_.required.push(P.name),P.description&&!("$$ref"in _.properties[P.name])&&(_.properties[P.name].description=P.description)}var L=new $t(y,x,_);r.push(L);var w=new Zt(l,d,v,y,!!b["x-openai-isConsequential"],b.requestBody?"application/json":"application/x-www-form-urlencoded");a[y]=w}return{functionSignatures:r,requestBuilders:a}}function Wt(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 I=E["application/json"].schema;if("$ref"in I&&"string"==typeof I.$ref){var O=I.$ref.split("/").pop();O&&!r[O]&&a.push("In context=('paths', '".concat(p,"', '").concat(g,"', '").concat(_,"', 'response', 'content', 'application/json', 'schema'), reference to unknown component ").concat(O,"; 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 Xt(e){var t=e.conversation,n=e.message;e.messages;var o=e.endpointOption,i=e.isEdited,r=e.isContinued,a=T.parse(t).conversationId,l=o,u=l.endpoint,p=l.endpointType,c=ze[null!=p?p:u];return i&&u===d.assistants?c+="/modify":i&&(c=c.replace("/ask/","/edit/")),{server:c,payload:s(s(s({},n),o),{isContinued:!(!i||!r),conversationId:a})}}export{Zt as ActionRequest,He as AuthKeys,Et as AuthTypeEnum,It as AuthorizationTypeEnum,Be as CacheKeys,Ze as Constants,lt as ContentTypes,d as EModelEndpoint,ze as EndpointURLs,Ee as FetchTokenConfig,K as FileContext,At as FilePurpose,q as FileSources,$t as FunctionSignature,f as ImageDetail,Ve as ImageDetailCost,_e as KnownEndpoints,dt as MessageContentTypes,Lt as MutationKeys,Pt as QueryKeys,mt as RunStatus,Ft as SSE,$e as SettingsTabValues,ct as StepStatus,ut as StepTypes,Ot as TokenExchangeMethodEnum,pt as ToolCallTypes,st as Tools,Fe as ViolationTypes,wt as actionDelimiter,Me as alternateName,M as anthropicSchema,le as applicationMimeTypes,ke as assistantEndpointSchema,Z as assistantSchema,Pe as azureBaseSchema,Ce as azureEndpointSchema,we as azureGroupConfigsSchema,Le as azureGroupSchema,j as bingAISchema,G as chatGPTBrowserSchema,ce as codeInterpreterMimeTypes,oe as codeInterpreterMimeTypesList,W as compactAnthropicSchema,X as compactChatGPTSchema,Q as compactGoogleSchema,Y as compactOpenAISchema,J as compactPluginsSchema,Ne as configSchema,yt as conflictingAzureVariables,ye as convertStringsToRegex,Xt as createPayload,Vt as createURL,Bt as dataService,g as defaultAssistantFormValues,je as defaultEndpoints,Ge as defaultModels,Xe as defaultOrderQuery,Ie as defaultSocialLogins,bt as deprecatedAzureVariables,E as eImageDetailSchema,b as eModelEndpointSchema,ve as endpointFileConfigSchema,Te as endpointSchema,h as endpointSettings,ot as envVarRegex,nt as errorsToString,te as excelFileTypes,ae as excelMimeTypes,y as extendedModelEndpointSchema,it as extractEnvVariable,ge as fileConfig,be as fileConfigSchema,Oe as fileSourceSchema,ne as fullMimeTypesList,et as getEnabledEndpoints,at as getFirstDefinedValue,gt as getResponseSender,N as googleSchema,R as gptPluginsSchema,x as imageDetailNumeric,_ as imageDetailValue,re as imageExtRegex,Ye as imageGenTools,ue as imageMimeTypes,m as isUUID,_t as mapModelToAzureConfig,fe as mbToBytes,me as megabyte,xe as mergeFileConfig,Ae as modelConfigSchema,De as modularEndpoints,S as openAISchema,Qt as openapiToFunction,tt as orderEndpointsConfig,vt as parseCompactConvo,ft as parseConvo,Se as rateLimitSchema,z as removeNullishValues,Kt as request,rt as resolveHeaders,Yt as resolveRef,de as retrievalMimeTypes,ie as retrievalMimeTypesList,kt as setAcceptLanguageHeader,Tt as setTokenHeader,Ht as sha1,pe as supportedMimeTypes,Ue as supportsBalanceCheck,ee as supportsFiles,Re as supportsRetrieval,P as tAgentOptionsSchema,w as tConversationSchema,T as tConvoUpdateSchema,A as tExampleSchema,L as tMessageSchema,I as tPluginAuthConfigSchema,O as tPluginSchema,k as tPresetSchema,C as tPresetUpdateSchema,se as textMimeTypes,Wt as validateAndParseOpenAPISpec,xt as validateAzureGroups,Ke as validateVisionModel,qe 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 r}from"js-yaml";var i,a,s=function(){return s=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},s.apply(this,arguments)};function l(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 r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}function u(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(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 p(e,t){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=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(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}function c(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var d,m=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"}(d||(d={}));var f,g={assistant:"",id:"",name:"",description:"",instructions:"",model:"",functions:[],code_interpreter:!1,retrieval:!1},h=((i={})[d.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}},i),v=h[d.google],b=e.nativeEnum(d),y=e.union([b,e.string()]);!function(e){e.low="low",e.auto="auto",e.high="high"}(f||(f={}));var x=((a={})[f.low]=0,a[f.auto]=1,a[f.high]=2,a),E={0:f.low,1:f.auto,2:f.high},_=e.nativeEnum(f),O=e.object({authField:e.string(),label:e.string(),description:e.string()}),I=e.object({name:e.string(),pluginKey:e.string(),description:e.string(),icon:e.string(),authConfig:e.array(O),authenticated:e.boolean().optional(),isButton:e.boolean().optional()}),A=e.object({input:e.object({content:e.string()}),output:e.object({content:e.string()})}),P=e.object({agent:e.string(),skipCompletion:e.boolean(),model:e.string(),temperature:e.number()}),w=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:b.nullable(),endpointType:b.optional(),suggestions:e.array(e.string()).optional(),messages:e.array(e.string()).optional(),tools:e.array(I).optional(),createdAt:e.string(),updatedAt:e.string(),systemMessage:e.string().nullable().optional(),modelLabel:e.string().nullable().optional(),examples:e.array(A).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:P.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:y.nullable()})),N=L.merge(e.object({endpoint:y.nullable()})),T=L.merge(e.object({endpoint:y.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,r,i,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!==(r=e.temperature)&&void 0!==r?r:1,top_p:null!==(i=e.top_p)&&void 0!==i?i: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:f.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:f.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,r,i,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?v.maxOutputTokens.maxGeminiPro:v.maxOutputTokens.max,f=d?v.maxOutputTokens.defaultGeminiPro:v.maxOutputTokens.default,g=null!==(o=e.maxOutputTokens)&&void 0!==o?o:f;return g=Math.min(g,m),s(s({},e),{model:null!==(r=e.model)&&void 0!==r?r:v.model.default,modelLabel:null!==(i=e.modelLabel)&&void 0!==i?i: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:v.temperature.default,maxOutputTokens:g,topP:null!==(p=e.topP)&&void 0!==p?p:v.topP.default,topK:null!==(c=e.topK)&&void 0!==c?c:v.topK.default})})).catch((function(){return{model:v.model.default,modelLabel:null,promptPrefix:null,examples:[{input:{content:""},output:{content:""}}],temperature:v.temperature.default,maxOutputTokens:v.maxOutputTokens.default,topP:v.topP.default,topK:v.topK.default}})),j=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,r,i,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!==(r=e.toneStyle)&&void 0!==r?r:"creative",jailbreakConversationId:null!==(i=e.jailbreakConversationId)&&void 0!==i?i: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}})),M=L.pick({model:!0,modelLabel:!0,promptPrefix:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0,resendImages:!0}).transform((function(e){var t,n,o,r,i,a,l,u;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!==(r=e.temperature)&&void 0!==r?r:1,maxOutputTokens:null!==(i=e.maxOutputTokens)&&void 0!==i?i:4e3,topP:null!==(a=e.topP)&&void 0!==a?a:.7,topK:null!==(l=e.topK)&&void 0!==l?l:5,resendImages:null!==(u=e.resendImages)&&void 0!==u&&u})})).catch((function(){return{model:"claude-1",modelLabel:null,promptPrefix:null,temperature:1,maxOutputTokens:4e3,topP:.7,topK:5,resendImages:!1}})),G=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"}})),R=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,r,i,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!==(r=e.temperature)&&void 0!==r?r:.8,top_p:null!==(i=e.top_p)&&void 0!==i?i: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 z(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 U,D,q,K,B,F,H,V,$,Z=L.pick({model:!0,assistant_id:!0,instructions:!0,promptPrefix:!0}).transform(z).catch((function(){return{}})),Y=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===f.auto&&delete t.imageDetail,z(t)})).catch((function(){return{}})),Q=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===v.temperature.default&&delete t.temperature,t.maxOutputTokens===v.maxOutputTokens.default&&delete t.maxOutputTokens,t.topP===v.topP.default&&delete t.topP,t.topK===v.topK.default&&delete t.topK,z(t)})).catch((function(){return{}})),W=L.pick({model:!0,modelLabel:!0,promptPrefix:!0,temperature:!0,maxOutputTokens:!0,topP:!0,topK:!0,resendImages:!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,!0!==t.resendImages&&delete t.resendImages,z(t)})).catch((function(){return{}})),X=L.pick({model:!0}).transform((function(e){return z(s({},e))})).catch((function(){return{}})),J=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,z(n)})).catch((function(){return{}})),ee=((U={})[d.openAI]=!0,U[d.google]=!0,U[d.assistants]=!0,U[d.azureOpenAI]=!0,U[d.anthropic]=!0,U[d.custom]=!0,U),te=["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"],ne=c(["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"],te,!0),oe=c(["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"],te,!0),re=["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,ae=/^application\/(vnd\.ms-excel|msexcel|x-msexcel|x-ms-excel|x-excel|x-dos_ms_excel|xls|x-xls|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet)$/,se=/^(text\/(x-c|x-c\+\+|x-java|html|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain|css|javascript|csv))$/,le=/^(application\/(csv|json|pdf|x-tar|typescript|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation|spreadsheetml\.sheet)|xml|zip))$/,ue=/^image\/(jpeg|gif|png|webp)$/,pe=[se,ae,le,ue],ce=[se,ae,le,ue],de=[/^(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)))$/],me=1048576,fe=function(e){return e*me},ge={endpoints:(D={},D[d.assistants]={fileLimit:10,fileSizeLimit:fe(512),totalSizeLimit:fe(512),supportedMimeTypes:pe,disabled:!1},D.default={fileLimit:10,fileSizeLimit:fe(20),totalSizeLimit:fe(25),supportedMimeTypes:[ue],disabled:!1},D),serverFileSizeLimit:fe(512),avatarSizeLimit:fe(2),checkType:function(e,t){return void 0===t&&(t=pe),t.some((function(t){return t.test(e)}))}},he=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."}),ve=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:he.optional()}),be=e.object({endpoints:e.record(ve).optional(),serverFileSizeLimit:e.number().min(0).optional(),avatarSizeLimit:e.number().min(0).optional()}),ye=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 xe(e){var t=ge;if(!e)return t;if(void 0!==e.serverFileSizeLimit&&(t.serverFileSizeLimit=fe(e.serverFileSizeLimit)),void 0!==e.avatarSizeLimit&&(t.avatarSizeLimit=fe(e.avatarSizeLimit)),!e.endpoints)return t;var n=function(n){var o=e.endpoints[n];t.endpoints[n]||(t.endpoints[n]={});var r=t.endpoints[n];if(!0===o.disabled)return r.disabled=!0,r.fileLimit=0,r.fileSizeLimit=0,r.totalSizeLimit=0,r.supportedMimeTypes=[],"continue";void 0!==o.fileSizeLimit&&(r.fileSizeLimit=fe(o.fileSizeLimit)),void 0!==o.totalSizeLimit&&(r.totalSizeLimit=fe(o.totalSizeLimit));["fileLimit"].forEach((function(e){void 0!==o[e]&&(r[e]=o[e])})),o.supportedMimeTypes&&(r.supportedMimeTypes=ye(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"}(q||(q={})),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"}(K||(K={}));var Ee,_e=["google","facebook","openid","github","discord"],Oe=["gpt-4-turbo-preview","gpt-3.5-turbo-0125","gpt-4-0125-preview","gpt-4-1106-preview","gpt-3.5-turbo-1106","gpt-3.5-turbo-0125","gpt-4-turbo","gpt-4-0125","gpt-4-1106"],Ie=e.nativeEnum(q),Ae=e.object({deploymentName:e.string().optional(),version:e.string().optional(),assistants:e.boolean().optional()}).or(e.boolean()),Pe=e.object({apiKey:e.string(),serverless:e.boolean().optional(),instanceName:e.string().optional(),deploymentName:e.string().optional(),assistants:e.boolean().optional(),addParams:e.record(e.any()).optional(),dropParams:e.array(e.string()).optional(),forcePrompt:e.boolean().optional(),version:e.string().optional(),baseURL:e.string().optional(),additionalHeaders:e.record(e.any()).optional()}),we=e.object({group:e.string(),models:e.record(e.string(),Ae)}).required().and(Pe),Le=e.array(we).min(1);!function(e){e.code_interpreter="code_interpreter",e.retrieval="retrieval",e.actions="actions",e.tools="tools"}(Ee||(Ee={}));var ke,Ne,Te=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(),retrievalModels:e.array(e.string()).min(1).optional().default(Oe),capabilities:e.array(e.nativeEnum(Ee)).optional().default([Ee.code_interpreter,Ee.retrieval,Ee.actions,Ee.tools]),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()}),Ce=e.object({name:e.string().refine((function(e){return!b.safeParse(e).success}),{message:"Value cannot be one of the default endpoint (EModelEndpoint) values: ".concat(Object.values(d).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()}),Se=e.object({groups:Le,plugins:e.boolean().optional(),assistants:e.boolean().optional()}).and(Ce.pick({titleConvo:!0,titleMethod:!0,titleModel:!0,summarize:!0,summaryModel:!0,customOrder:!0}).partial()),je=e.object({fileUploads:e.object({ipMax:e.number().optional(),ipWindowInMinutes:e.number().optional(),userMax:e.number().optional(),userWindowInMinutes:e.number().optional()}).optional()}),Me=e.object({version:e.string(),cache:e.boolean(),interface:e.object({privacyPolicy:e.object({externalUrl:e.string().optional(),openNewTab:e.boolean().optional()}).optional(),termsOfService:e.object({externalUrl:e.string().optional(),openNewTab:e.boolean().optional()}).optional()}).optional(),fileStrategy:Ie.optional(),registration:e.object({socialLogins:e.array(e.string()).optional(),allowedDomains:e.array(e.string()).optional()}).optional(),rateLimits:je.optional(),fileConfig:be.optional(),endpoints:e.object((B={},B[d.azureOpenAI]=Se.optional(),B[d.assistants]=Te.optional(),B.custom=e.array(Ce.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",e.groq="groq",e.anyscale="anyscale",e.fireworks="fireworks",e.ollama="ollama",e.perplexity="perplexity",e["together.ai"]="together.ai"}(ke||(ke={})),function(e){e.openrouter="openrouter"}(Ne||(Ne={}));var Ge=[d.openAI,d.assistants,d.azureOpenAI,d.bingAI,d.chatGPTBrowser,d.gptPlugins,d.google,d.anthropic,d.custom],Re=((F={})[d.openAI]="OpenAI",F[d.assistants]="Assistants",F[d.azureOpenAI]="Azure OpenAI",F[d.bingAI]="Bing",F[d.chatGPTBrowser]="ChatGPT",F[d.gptPlugins]="Plugins",F[d.google]="Google",F[d.anthropic]="Anthropic",F[d.custom]="Custom",F),ze=((H={})[d.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"],H[d.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"],H[d.anthropic]=["claude-3-opus-20240229","claude-3-sonnet-20240229","claude-2.1","claude-2","claude-1.2","claude-1","claude-1-100k","claude-instant-1","claude-instant-1-100k"],H[d.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"],H),Ue=((V={})[d.openAI]="/api/ask/".concat(d.openAI),V[d.bingAI]="/api/ask/".concat(d.bingAI),V[d.google]="/api/ask/".concat(d.google),V[d.custom]="/api/ask/".concat(d.custom),V[d.anthropic]="/api/ask/".concat(d.anthropic),V[d.gptPlugins]="/api/ask/".concat(d.gptPlugins),V[d.azureOpenAI]="/api/ask/".concat(d.azureOpenAI),V[d.chatGPTBrowser]="/api/ask/".concat(d.chatGPTBrowser),V[d.assistants]="/api/assistants/chat",V),De=new Set([d.gptPlugins,d.anthropic,d.google,d.openAI,d.azureOpenAI,d.custom]),qe=(($={})[d.openAI]=!0,$[d.anthropic]=!0,$[d.azureOpenAI]=!0,$[d.gptPlugins]=!0,$[d.custom]=!0,$),Ke=["gpt-4-vision","llava-13b","gemini-pro-vision","claude-3"];function Be(e){var t=e.model,n=e.additionalModels,o=void 0===n?[]:n,r=e.availableModels;return!!t&&(!(r&&!r.includes(t))&&Ke.concat(o).some((function(e){return t.includes(e)})))}var Fe,He,Ve,$e,Ze,Ye,Qe=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"}(Fe||(Fe={})),function(e){e.FILE_UPLOAD_LIMIT="file_upload_limit",e.ILLEGAL_MODEL_REQUEST="illegal_model_request"}(He||(He={})),function(e){e.GOOGLE_SERVICE_KEY="GOOGLE_SERVICE_KEY",e.GOOGLE_API_KEY="GOOGLE_API_KEY"}(Ve||(Ve={})),function(e){e[e.LOW=85]="LOW",e[e.HIGH=170]="HIGH",e[e.ADDITIONAL=85]="ADDITIONAL"}($e||($e={})),function(e){e.GENERAL="general",e.BETA="beta",e.DATA="data",e.ACCOUNT="account"}(Ze||(Ze={})),function(e){e.VERSION="v0.6.10",e.CONFIG_VERSION="1.0.5",e.NO_PARENT="00000000-0000-0000-0000-000000000000"}(Ye||(Ye={}));var We,Xe,Je={order:"asc"},et=((We={})[d.openAI]=C,We[d.azureOpenAI]=C,We[d.custom]=C,We[d.google]=S,We[d.bingAI]=j,We[d.anthropic]=M,We[d.chatGPTBrowser]=G,We[d.gptPlugins]=R,We[d.assistants]=Z,We);function tt(){var e=[d.openAI,d.assistants,d.azureOpenAI,d.google,d.bingAI,d.chatGPTBrowser,d.gptPlugins,d.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 nt(e){if(!e)return{};var t=tt(),n=Object.keys(e),o=t.indexOf(d.custom);return n.reduce((function(n,r){var i=!(r in d);if(!t.includes(r)&&!i)return n;var a=t.indexOf(r);return i?n[r]=s({order:o>=0?o:9999},e[r]):e[r]&&(n[r]=s(s({},e[r]),{order:a})),n}),{})}function ot(e){return e.map((function(e){var t=e.path.join("."),n=e.message;return"".concat(t,": ").concat(n)})).join(" ")}var rt=/^\${(.+)}$/;function it(e){var t=e.match(rt);return t&&process.env[t[1]]||e}function at(e){var t=s({},null!=e?e:{});return e&&"object"==typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(n){t[n]=it(e[n])})),t}function st(e){for(var t,n=0,o=e;n<o.length;n++){var r=o[n];if(r){t=r;break}}return t}var lt,ut,pt,ct,dt,mt,ft,gt=function(e){var t,n,o=e.endpoint,r=e.endpointType,i=e.conversation,a=e.possibleValues,s=et[o];if(!s&&!r)throw new Error("Unknown endpoint: ".concat(o));!s&&r&&(s=et[r]);var l=s.parse(i),u=null!=a?a:{},p=u.models,c=u.secondaryModels;return p&&l&&(l.model=null!==(t=st(p))&&void 0!==t?t:l.model),c&&l.agentOptions&&(l.agentOptions.model=null!==(n=st(c))&&void 0!==n?n:l.agentOptions.model),l},ht=function(e){var t,n=e.model,o=e.endpoint,r=e.endpointType,i=e.modelDisplayLabel,a=e.chatGptLabel,s=e.modelLabel,l=e.jailbreak;return[d.openAI,d.azureOpenAI,d.gptPlugins,d.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=Re[o])&&void 0!==t?t:"ChatGPT"):o===d.bingAI?l?"Sydney":"BingAI":o===d.anthropic?null!=s?s:"Claude":o===d.google?s||(n&&n.includes("gemini")?"Gemini":n&&n.includes("code")?"Codey":"PaLM2"):o===d.custom||r===d.custom?s||(a||(n&&n.includes("mistral")?"Mistral":n&&n.includes("gpt-3")?"GPT-3.5":n&&n.includes("gpt-4")?"GPT-4":i||"AI")):""},vt=((Xe={})[d.openAI]=Y,Xe[d.azureOpenAI]=Y,Xe[d.custom]=Y,Xe[d.assistants]=Z,Xe[d.google]=Q,Xe[d.bingAI]=j,Xe[d.anthropic]=W,Xe[d.chatGPTBrowser]=X,Xe[d.gptPlugins]=J,Xe),bt=function(e){var t,n=e.endpoint,o=e.endpointType,r=e.conversation,i=e.possibleValues;if(!n)throw new Error("undefined endpoint: ".concat(n));var a=vt[n];if(!a&&!o)throw new Error("Unknown endpoint: ".concat(n));!a&&o&&(a=vt[o]);var s=a.parse(r),l=(null!=i?i:{}).models;return l&&s&&(s.model=null!==(t=st(l))&&void 0!==t?t:s.model),s},yt=[{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"}],xt=[{key:"INSTANCE_NAME"},{key:"DEPLOYMENT_NAME"}];function Et(e){var t=!0,n=[],o={},r={},i=[],a=Le.safeParse(e);if(a.success)for(var u=0,p=a.data;u<p.length;u++){var c=p[u],d=c.group,m=c.apiKey,f=c.instanceName,g=c.deploymentName,h=c.version,v=c.baseURL,b=c.additionalHeaders,y=c.models,x=c.serverless,E=l(c,["group","apiKey","instanceName","deploymentName","version","baseURL","additionalHeaders","models","serverless"]);if(r[d])return i.push('Duplicate group name detected: "'.concat(d,'". Group names must be unique.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:r,errors:i};if(x&&!v)return i.push('Group "'.concat(d,'" is serverless but missing mandatory "baseURL."')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:r,errors:i};if(!f&&!x)return i.push('Group "'.concat(d,'" is missing an "instanceName" for non-serverless configuration.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:r,errors:i};for(var _ in r[d]=s({apiKey:m,instanceName:f,deploymentName:g,version:h,baseURL:v,additionalHeaders:b,models:y,serverless:x},E),c.models){n.push(_);var O=c.models[_];if(o[_])return i.push('Duplicate model name detected: "'.concat(_,'". Model names must be unique across groups.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:r,errors:i};if(x)o[_]={group:d};else if("boolean"==typeof O){if(!c.deploymentName||!c.version)return i.push('Model "'.concat(_,'" in group "').concat(d,'" is missing a deploymentName or version.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:r,errors:i};o[_]={group:d}}else{if(!O.deploymentName&&!c.deploymentName||!O.version&&!c.version)return i.push('Model "'.concat(_,'" in group "').concat(d,'" is missing a required deploymentName or version.')),{isValid:!1,modelNames:n,modelGroupMap:o,groupMap:r,errors:i};o[_]={group:d}}}}else t=!1,i.push(ot(a.error.errors));return{isValid:t,modelNames:n,modelGroupMap:o,groupMap:r,errors:i}}function _t(e){var t=e.modelName,n=e.modelGroupMap,o=e.groupMap,r=n[t];if(!r)throw new Error('Model named "'.concat(t,'" not found in configuration.'));var i=o[r.group];if(!i)throw new Error('Group "'.concat(r.group,'" for model "').concat(t,'" not found in configuration.'));var a=i.instanceName;if(!a&&!i.serverless)throw new Error('Group "'.concat(r.group,'" is missing an instanceName for non-serverless configuration.'));if(i.serverless&&!i.baseURL)throw new Error('Group "'.concat(r.group,'" is missing the required base URL for serverless configuration.'));if(i.serverless){var s={azureOptions:{azureOpenAIApiKey:it(i.apiKey)},baseURL:it(i.baseURL),serverless:!0},l=s.azureOptions.azureOpenAIApiKey;if("string"==typeof l&&rt.test(l))throw new Error('Azure configuration environment variable "'.concat(l,'" was not found.'));return i.additionalHeaders&&(s.headers=i.additionalHeaders),s}if(!a)throw new Error('Group "'.concat(r.group,'" is missing an instanceName for non-serverless configuration.'));var u=i.models[t],p="object"==typeof u?{deploymentName:u.deploymentName||i.deploymentName,version:u.version||i.version}:{deploymentName:i.deploymentName,version:i.version},c=p.deploymentName,d=p.version;if(!c||!d)throw new Error('Model "'.concat(t,'" in group "').concat(r.group,'" is missing a deploymentName ("').concat(c,'") or version ("').concat(d,'").'));for(var m={azureOpenAIApiKey:it(i.apiKey),azureOpenAIApiInstanceName:it(a),azureOpenAIApiDeploymentName:it(c),azureOpenAIApiVersion:it(d)},f=0,g=Object.values(m);f<g.length;f++){var h=g[f];if("string"==typeof h&&rt.test(h))throw new Error('Azure configuration environment variable "'.concat(h,'" was not found.'))}var v={azureOptions:m};return i.baseURL&&(v.baseURL=it(i.baseURL)),i.additionalHeaders&&(v.headers=i.additionalHeaders),v}function Ot(e){var t,n=e.groupName,o=e.groupMap[n];if(!o)throw new Error('Group named "'.concat(n,'" not found in configuration.'));var r=o.instanceName;if(!r&&!o.serverless)throw new Error('Group "'.concat(n,'" is missing an instanceName for non-serverless configuration.'));if(o.serverless&&!o.baseURL)throw new Error('Group "'.concat(n,'" is missing the required base URL for serverless configuration.'));var i=Object.keys(o.models);if(0===i.length)throw new Error('Group "'.concat(n,'" does not have any models configured.'));var a=i[0],l=o.models[a],u={azureOpenAIApiKey:it(o.apiKey),azureOpenAIApiInstanceName:it(r)};if(o.serverless)return s({azureOptions:u,baseURL:it(null!==(t=o.baseURL)&&void 0!==t?t:""),serverless:!0},o.additionalHeaders&&{headers:o.additionalHeaders});var p="object"==typeof l?{deploymentName:l.deploymentName||o.deploymentName,version:l.version||o.version}:{deploymentName:o.deploymentName,version:o.version},c=p.deploymentName,d=p.version;if(!c||!d)throw new Error('Model "'.concat(a,'" in group "').concat(n,'" or the group itself is missing a deploymentName ("').concat(c,'") or version ("').concat(d,'").'));u.azureOpenAIApiDeploymentName=it(c),u.azureOpenAIApiVersion=it(d);var m={azureOptions:u};return o.baseURL&&(m.baseURL=it(o.baseURL)),o.additionalHeaders&&(m.headers=o.additionalHeaders),m}!function(e){e.code_interpreter="code_interpreter",e.retrieval="retrieval",e.function="function"}(lt||(lt={})),function(e){e.TEXT="text",e.TOOL_CALL="tool_call",e.IMAGE_FILE="image_file"}(ut||(ut={})),function(e){e.TOOL_CALLS="tool_calls",e.MESSAGE_CREATION="message_creation"}(pt||(pt={})),function(e){e.FUNCTION="function",e.RETRIEVAL="retrieval",e.CODE_INTERPRETER="code_interpreter"}(ct||(ct={})),function(e){e.IN_PROGRESS="in_progress",e.CANCELLED="cancelled",e.FAILED="failed",e.COMPLETED="completed",e.EXPIRED="expired"}(dt||(dt={})),function(e){e.TEXT="text",e.IMAGE_FILE="image_file"}(mt||(mt={})),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"}(ft||(ft={}));var It,At,Pt,wt,Lt,kt,Nt="_action_";function Tt(e){t.defaults.headers.common["Accept-Language"]=e}function Ct(e){t.defaults.headers.common.Authorization="Bearer "+e}!function(e){e.ServiceHttp="service_http",e.OAuth="oauth",e.None="none"}(It||(It={})),function(e){e.Bearer="bearer",e.Basic="basic",e.Custom="custom"}(At||(At={})),function(e){e.DefaultPost="default_post",e.BasicAuthHeader="basic_auth_header"}(Pt||(Pt={})),function(e){e.FineTune="fine-tune",e.FineTuneResults="fine-tune-results",e.Assistants="assistants",e.AssistantsOutput="assistants_output"}(wt||(wt={})),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"}(Lt||(Lt={})),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"}(kt||(kt={}));var St=function(e,t){return"/api/messages/".concat(e).concat(t?"/".concat(t):"")},jt="/api/keys",Mt=function(e){return"/api/convos?pageNumber=".concat(e)},Gt=function(e,t){return"/api/search?q=".concat(e,"&pageNumber=").concat(t)},Rt=function(e,t){var n="/api/assistants";if(e&&(n+="/".concat(e)),t&&Object.keys(t).length>0){var o=new URLSearchParams(t).toString();n+="?".concat(o)}return n},zt=function(){return"".concat("/api/files","/images")};function Ut(e,n){return u(this,void 0,void 0,(function(){return p(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 Dt=!1,qt=[],Kt=function(e){return Ut(function(e){return"/api/auth/refresh".concat(e?"?retry=true":"")}(e))},Bt=function(e,t){void 0===t&&(t=null),qt.forEach((function(n){e?n.reject(e):n.resolve(t)})),qt=[]};t.interceptors.response.use((function(e){return e}),(function(e){return u(void 0,void 0,void 0,(function(){var n,o,r,i,a;return p(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,!Dt)return[3,5];s.label=1;case 1:return s.trys.push([1,4,,5]),[4,new Promise((function(e,t){qt.push({resolve:e,reject:t})}))];case 2:return r=s.sent(),n.headers.Authorization="Bearer "+r,[4,t(n)];case 3:return[2,s.sent()];case 4:return o=s.sent(),[2,Promise.reject(o)];case 5:Dt=!0,s.label=6;case 6:return s.trys.push([6,11,12,13]),[4,Kt(!!(null===(a=n.url)||void 0===a?void 0:a.includes("api/auth/refresh")))];case 7:return(r=s.sent().token)?(n.headers.Authorization="Bearer "+r,Ct(r),window.dispatchEvent(new CustomEvent("tokenUpdated",{detail:r})),Bt(null,r),[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 i=s.sent(),Bt(i,null),[2,Promise.reject(i)];case 12:return Dt=!1,[7];case 13:return[2,Promise.reject(e)]}}))}))}));var Ft={get:function(e,n){return u(this,void 0,void 0,(function(){return p(this,(function(o){switch(o.label){case 0:return[4,t.get(e,s({},n))];case 1:return[2,o.sent().data]}}))}))},post:Ut,postMultiPart:function(e,n,o){return u(this,void 0,void 0,(function(){return p(this,(function(r){switch(r.label){case 0:return[4,t.post(e,n,s(s({},o),{headers:{"Content-Type":"multipart/form-data"}}))];case 1:return[2,r.sent().data]}}))}))},put:function(e,n){return u(this,void 0,void 0,(function(){return p(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 u(this,void 0,void 0,(function(){return p(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 u(this,void 0,void 0,(function(){return p(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 u(this,void 0,void 0,(function(){return p(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:Kt};var Ht=Object.freeze({__proto__:null,abortRequestWithMessage:function(e,t,n){return Ft.post(function(e){return"/api/ask/".concat(e,"/abort")}(e),{arg:{abortKey:t,message:n}})},clearAllConversations:function(){return Ft.post("/api/convos/clear",{arg:{}})},createAssistant:function(e){return Ft.post(Rt(),e)},createPreset:function(e){return Ft.post("/api/presets",e)},deleteAction:function(e,t){return u(void 0,void 0,void 0,(function(){return p(this,(function(n){return[2,Ft.delete(Rt("actions/".concat(e,"/").concat(t)))]}))}))},deleteAssistant:function(e,t){return Ft.delete(Rt(e,{model:t}))},deleteConversation:function(e){return Ft.post("/api/convos/clear",{arg:e})},deleteFiles:function(e,t){return u(void 0,void 0,void 0,(function(){return p(this,(function(n){return[2,Ft.deleteWithOptions("/api/files",{data:{files:e,assistant_id:t}})]}))}))},deletePreset:function(e){return Ft.post("/api/presets/delete",e)},genTitle:function(e){return Ft.post("/api/convos/gen_title",e)},getAIEndpoints:function(){return Ft.get("/api/endpoints")},getActions:function(){return Ft.get(Rt("actions"))},getAssistantById:function(e){return Ft.get(Rt(e))},getAssistantDocs:function(){return Ft.get(Rt("documents"))},getAvailablePlugins:function(){return Ft.get("/api/plugins")},getAvailableTools:function(){return Ft.get("".concat(Rt(),"/tools"))},getConversationById:function(e){return Ft.get(function(e){return"/api/convos/".concat(e)}(e))},getConversations:function(e){return Ft.get(Mt(e))},getEndpointsConfigOverride:function(){return Ft.get("/api/endpoints/config/override")},getFileConfig:function(){return Ft.get("".concat("/api/files","/config"))},getFiles:function(){return Ft.get("/api/files")},getLoginGoogle:function(){return Ft.get("/api/auth/google")},getMessagesByConvoId:function(e){return"new"===e?Promise.resolve([]):Ft.get(St(e))},getModels:function(){return u(void 0,void 0,void 0,(function(){return p(this,(function(e){return[2,Ft.get("/api/models")]}))}))},getPresets:function(){return Ft.get("/api/presets")},getSearchEnabled:function(){return Ft.get("/api/search/enable")},getStartupConfig:function(){return Ft.get("/api/config")},getUser:function(){return Ft.get("/api/user")},getUserBalance:function(){return Ft.get("/api/balance")},listAssistants:function(e){return Ft.get(Rt(),{params:e})},listConversations:function(e){var t=(null==e?void 0:e.pageNumber)||"1";return Ft.get(Mt(t))},listConversationsByQuery:function(e){var t=(null==e?void 0:e.pageNumber)||"1",n=(null==e?void 0:e.searchQuery)||"";return""!==n?Ft.get(Gt(n,t)):Ft.get(Mt(t))},login:function(e){return Ft.post("/api/auth/login",e)},logout:function(){return Ft.post("/api/auth/logout")},register:function(e){return Ft.post("/api/auth/register",e)},requestPasswordReset:function(e){return Ft.post("/api/auth/requestPasswordReset",e)},resetPassword:function(e){return Ft.post("/api/auth/resetPassword",e)},revokeAllUserKeys:function(){return Ft.delete("".concat(jt,"?all=true"))},revokeUserKey:function(e){return Ft.delete(function(e){return"".concat(jt,"/").concat(e)}(e))},searchConversations:function(e,t){return u(void 0,void 0,void 0,(function(){return p(this,(function(n){return[2,Ft.get(Gt(e,t))]}))}))},updateAction:function(e){var t=e.assistant_id,n=l(e,["assistant_id"]);return Ft.post(Rt("actions/".concat(t)),n)},updateAssistant:function(e,t){return Ft.patch(Rt(e),t)},updateConversation:function(e){return Ft.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 Ft.put(St(t,n),{text:o})},updatePreset:function(e){return Ft.post("/api/presets",e)},updateTokenCount:function(e){return Ft.post("/api/tokenizer",{arg:e})},updateUserKey:function(e){if(!e.value)throw new Error("value is required");return Ft.put(jt,e)},updateUserPlugins:function(e){return Ft.post("/api/user/plugins",e)},uploadAssistantAvatar:function(e){return Ft.postMultiPart(Rt("avatar/".concat(e.assistant_id),{model:e.model}),e.formData)},uploadAvatar:function(e){return Ft.postMultiPart("".concat(zt(),"/avatar"),e)},uploadFile:function(e){return Ft.postMultiPart("/api/files",e)},uploadImage:function(e){return Ft.postMultiPart(zt(),e)},userKeyQuery:function(e){return Ft.get(function(e){return"".concat(jt,"?name=").concat(e)}(e))}}),Vt=function(e,t){if(!(this instanceof Vt))return new Vt(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 Ft.refreshToken();this.headers={"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},Ct(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 r=e.substring(n+1).trimLeft();"data"===o?t[o]+=r:t[o]=r}}}.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 $t(e){return o.createHash("sha1").update(e).digest("hex")}function Zt(e,t){return new n(t,e).toString()}var Yt=function(){function e(e,t,n){var o,r;this.name=e,this.description=t,(null===(o=n.properties)||void 0===o?void 0:o.requestBody)?this.parameters=null===(r=n.properties)||void 0===r?void 0:r.requestBody:this.parameters=n}return e.prototype.toObjectTool=function(){return{type:lt.function,function:{name:this.name,description:this.description,parameters:this.parameters}}},e}(),Qt=function(){function e(e,t,n,o,r,i){this.authHeaders={},this.domain=e,this.path=t,this.method=n,this.operation=o,this.isConsequential=r,this.contentType=i}return e.prototype.setParams=function(e){return u(this,void 0,void 0,(function(){return p(this,(function(t){return this.operationHash=$t(JSON.stringify(e)),this.params=e,[2]}))}))},e.prototype.setAuth=function(e){return u(this,void 0,void 0,(function(){var n,o,r,i,a,s,l,u,c,d,m,f,g,h,v;return p(this,(function(p){switch(p.label){case 0:return e.auth?(n=e.auth,o=n.type,r=n.authorization_type,i=n.custom_auth_header,a=n.authorization_url,s=n.client_url,l=n.scope,u=n.token_exchange_method,c=e.api_key,d=e.oauth_client_id,m=e.oauth_client_secret,f=c&&o===It.ServiceHttp,g=d&&m&&o===It.OAuth&&a&&s&&l&&u,f&&r===At.Basic?(h=Buffer.from(c).toString("base64"),this.authHeaders.Authorization="Basic ".concat(h),[3,6]):[3,1]):[2];case 1:return f&&r===At.Bearer?(this.authHeaders.Authorization="Bearer ".concat(c),[3,6]):[3,2];case 2:return f&&r===At.Custom&&i?(this.authHeaders[i]=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=p.sent(),this.authToken=v.data.access_token,p.label=5;case 5:this.authHeaders.Authorization="Bearer ".concat(this.authToken),p.label=6;case 6:return[2]}}))}))},e.prototype.execute=function(){return u(this,void 0,void 0,(function(){var e,n,o;return p(this,(function(r){if(e=Zt(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 Wt(e,t){var n;if("$ref"in e&&t){var o=e.$ref.replace(/^#\/components\/schemas\//,""),r=null===(n=t.schemas)||void 0===n?void 0:n[o];if(!r)throw new Error("Reference ".concat(e.$ref," not found"));return Wt(r,t)}return e}function Xt(e){for(var t,n,o,r,i=[],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||"",E={type:"object",properties:{},required:[]};if(b.requestBody){var _=b.requestBody.content,O=Wt(null===(r=_[Object.keys(_)[0]])||void 0===r?void 0:r.schema,e.components);E.properties.requestBody=O}if(b.parameters)for(var I=0,A=b.parameters;I<A.length;I++){var P=A[I];O=Wt(s({},P.schema),e.components);E.properties[P.name]=O,P.required&&E.required.push(P.name),P.description&&!("$$ref"in E.properties[P.name])&&(E.properties[P.name].description=P.description)}var w=new Yt(y,x,E);i.push(w);var L=new Qt(l,d,v,y,!!b["x-openai-isConsequential"],b.requestBody?"application/json":"application/x-www-form-urlencoded");a[y]=L}return{functionSignatures:i,requestBuilders:a}}function Jt(e){var t;try{var n=void 0;try{n=JSON.parse(e)}catch(t){n=r(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 i=(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],E=x[0],_=x[1].content;if(_&&_["application/json"]&&_["application/json"].schema){var O=_["application/json"].schema;if("$ref"in O&&"string"==typeof O.$ref){var I=O.$ref.split("/").pop();I&&!i[I]&&a.push("In context=('paths', '".concat(p,"', '").concat(g,"', '").concat(E,"', '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 en(e){var t=e.conversation,n=e.message;e.messages;var o=e.endpointOption,r=e.isEdited,i=e.isContinued,a=N.parse(t).conversationId,l=o,u=l.endpoint,p=l.endpointType,c=Ue[null!=p?p:u];return r&&u===d.assistants?c+="/modify":r&&(c=c.replace("/ask/","/edit/")),{server:c,payload:s(s(s({},n),o),{isContinued:!(!r||!i),conversationId:a})}}export{Qt as ActionRequest,Ve as AuthKeys,It as AuthTypeEnum,At as AuthorizationTypeEnum,Fe as CacheKeys,Ee as Capabilities,Ye as Constants,ut as ContentTypes,d as EModelEndpoint,Ue as EndpointURLs,Ne as FetchTokenConfig,K as FileContext,wt as FilePurpose,q as FileSources,Yt as FunctionSignature,f as ImageDetail,$e as ImageDetailCost,ke as KnownEndpoints,mt as MessageContentTypes,kt as MutationKeys,Lt as QueryKeys,ft as RunStatus,Vt as SSE,Ze as SettingsTabValues,dt as StepStatus,pt as StepTypes,Pt as TokenExchangeMethodEnum,ct as ToolCallTypes,lt as Tools,He as ViolationTypes,Nt as actionDelimiter,Re as alternateName,M as anthropicSchema,le as applicationMimeTypes,Te as assistantEndpointSchema,Z as assistantSchema,Pe as azureBaseSchema,Se as azureEndpointSchema,Le as azureGroupConfigsSchema,we as azureGroupSchema,j as bingAISchema,G as chatGPTBrowserSchema,ce as codeInterpreterMimeTypes,oe as codeInterpreterMimeTypesList,W as compactAnthropicSchema,X as compactChatGPTSchema,Q as compactGoogleSchema,Y as compactOpenAISchema,J as compactPluginsSchema,Me as configSchema,xt as conflictingAzureVariables,ye as convertStringsToRegex,en as createPayload,Zt as createURL,Ht as dataService,g as defaultAssistantFormValues,Ge as defaultEndpoints,ze as defaultModels,Je as defaultOrderQuery,Oe as defaultRetrievalModels,_e as defaultSocialLogins,yt as deprecatedAzureVariables,_ as eImageDetailSchema,b as eModelEndpointSchema,ve as endpointFileConfigSchema,Ce as endpointSchema,h as endpointSettings,rt as envVarRegex,ot as errorsToString,te as excelFileTypes,ae as excelMimeTypes,y as extendedModelEndpointSchema,it as extractEnvVariable,ge as fileConfig,be as fileConfigSchema,Ie as fileSourceSchema,ne as fullMimeTypesList,tt as getEnabledEndpoints,st as getFirstDefinedValue,ht as getResponseSender,S as googleSchema,R as gptPluginsSchema,x as imageDetailNumeric,E as imageDetailValue,ie as imageExtRegex,Qe as imageGenTools,ue as imageMimeTypes,m as isUUID,Ot as mapGroupToAzureConfig,_t as mapModelToAzureConfig,fe as mbToBytes,me as megabyte,xe as mergeFileConfig,Ae as modelConfigSchema,De as modularEndpoints,C as openAISchema,Xt as openapiToFunction,nt as orderEndpointsConfig,bt as parseCompactConvo,gt as parseConvo,je as rateLimitSchema,z as removeNullishValues,Ft as request,at as resolveHeaders,Wt as resolveRef,de as retrievalMimeTypes,re as retrievalMimeTypesList,Tt as setAcceptLanguageHeader,Ct as setTokenHeader,$t as sha1,pe as supportedMimeTypes,qe as supportsBalanceCheck,ee as supportsFiles,P as tAgentOptionsSchema,L as tConversationSchema,N as tConvoUpdateSchema,A as tExampleSchema,w as tMessageSchema,O as tPluginAuthConfigSchema,I as tPluginSchema,k as tPresetSchema,T as tPresetUpdateSchema,se as textMimeTypes,Jt as validateAndParseOpenAPISpec,Et as validateAzureGroups,Be as validateVisionModel,Ke as visionModels};
|
|
2
2
|
//# sourceMappingURL=index.es.js.map
|