\n Download or upload a web model that will run entirely on your browser: \n Download \n ').concat(i?"":' \n Upload '),"\n
")}},{key:"exportFile",value:function(e){for(var t=document.createElement("a"),n=function(n){setTimeout((function(){for(var r=4*n,i=r;i\n Model loaded successfully and has been cached for future requests.\n ".concat(i?"":' Export '),"\n ")}}])}();wn.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",wn.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",wn.FILE_INPUT_CLASS="deep-chat-file-input",wn.EXPORT_BUTTON_CLASS="deep-chat-export-button";var Cn=wn,Tn={model_list:[{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f32_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f32_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:9109.03,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:6749.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-7b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-7b-chat-hf-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-7b-chat-hf/Llama-2-7b-chat-hf-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:4618.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-13b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-13b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-13b-chat-hf/Llama-2-13b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:11814.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Llama-2-70b-chat-hf-q4f16_1-MLC/resolve/main/",local_id:"Llama-2-70b-chat-hf-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Llama-2-70b-chat-hf/Llama-2-70b-chat-hf-q4f16_1-ctx4k_cs1k-webgpu.wasm",vram_required_MB:43729.05,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f16_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f16_1-ctx2k-webgpu.wasm",vram_required_MB:2972.09,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f32_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f32_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f32_1-ctx2k-webgpu.wasm",vram_required_MB:3928.09,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f16_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:2041.09,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/RedPajama-INCITE-Chat-3B-v1-q4f32_1-MLC/resolve/main/",local_id:"RedPajama-INCITE-Chat-3B-v1-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/RedPajama-INCITE-Chat-3B-v1/RedPajama-INCITE-Chat-3B-v1-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:2558.09,low_resource_required:!0},{model_url:"https://huggingface.co/mlc-ai/WizardMath-7B-V1.1-q4f16_1-MLC/resolve/main/",local_id:"WizardMath-7B-V1.1-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/Mistral-7B-Instruct-v0.2-q4f16_1-MLC/resolve/main/",local_id:"Mistral-7B-Instruct-v0.2-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/OpenHermes-2.5-Mistral-7B-q4f16_1-MLC/resolve/main/",local_id:"OpenHermes-2.5-Mistral-7B-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/NeuralHermes-2.5-Mistral-7B-q4f16_1-MLC/resolve/main/",local_id:"NeuralHermes-2.5-Mistral-7B-q4f16_1",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/Mistral-7B-Instruct-v0.2/Mistral-7B-Instruct-v0.2-q4f16_1-sw4k_cs1k-webgpu.wasm",vram_required_MB:6079.02,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f16-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f16",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f16-ctx2k-webgpu.wasm",vram_required_MB:5063.52,low_resource_required:!1,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q0f32-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q0f32",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q0f32-ctx2k-webgpu.wasm",vram_required_MB:5394.53,low_resource_required:!1},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f16_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f16_1-ctx1k-webgpu.wasm",vram_required_MB:899.11,low_resource_required:!0,required_features:["shader-f16"]},{model_url:"https://huggingface.co/mlc-ai/TinyLlama-1.1B-Chat-v0.4-q4f32_1-MLC/resolve/main/",local_id:"TinyLlama-1.1B-Chat-v0.4-q4f32_1-1k",model_lib_url:"https://raw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/TinyLlama-1.1B-Chat-v0.4/TinyLlama-1.1B-Chat-v0.4-q4f32_1-ctx1k-webgpu.wasm",vram_required_MB:992.11,low_resource_required:!0}],use_web_worker:!0},An=function(e){function t(e){var n,r,i;return x(this,t),(n=s(this,t,[e]))._isModelLoaded=!1,n._isModelLoading=!1,n._loadOnFirstMessage=!1,n._webModel={},n.permittedErrorPrefixes=[t.MULTIPLE_MODELS_ERROR,t.WEB_LLM_NOT_FOUND_ERROR,t.GENERIC_ERROR],n._conversationHistory=[],"object"==_(e.webModel)&&(n._webModel=e.webModel),null!=(r=n._webModel.load)&&r.clearCache&&t.clearAllCache(),n.findModelInWindow(e),n.canSendMessage=n.canSubmit.bind(a(n)),n._chatEl=null==(i=e.shadowRoot)?void 0:i.children[0],e.history&&t.setUpHistory(n._conversationHistory,e.history),n}return c(t,e),E(t,[{key:"setUpMessages",value:function(e){var t=this;this._messages=e,this._removeIntro=function(){e.removeIntroductoryMessage(),t._removeIntro=void 0}}},{key:"findModelInWindow",value:function(e){var n,r=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;window.webLLM?this.configureInit(this.shouldAddIntroMessage(e.introMessage)):i>t.MODULE_SEARCH_LIMIT_S?(null==(n=this._messages)||n.addNewErrorMessage("service",t.WEB_LLM_NOT_FOUND_ERROR),console.error("The deep-chat-web-llm module has not been attached to the window object. Please see the following guide:"),console.error("https://deepchat.dev/examples/externalModules")):setTimeout((function(){return r.findModelInWindow(e,i+1)}),1e3)}},{key:"shouldAddIntroMessage",value:function(e){var t;return!e&&this._webModel&&!1!==(null==(t=this._webModel.introMessage)?void 0:t.displayed)}},{key:"scrollToTop",value:function(e){var t,n=this;!1!==(null==(t=this._webModel.introMessage)?void 0:t.autoScroll)&&setTimeout((function(){var e,t;null!=(e=n._messages)&&e.elementRef&&K.scrollToTop(null==(t=n._messages)?void 0:t.elementRef)}),e)}},{key:"getIntroMessage",value:function(e){if(this.shouldAddIntroMessage(e)&&this._chatEl){var t=Cn.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:Wt.AI_ROLE,html:t,sendUpdate:!1}}}},{key:"configureInit",value:(v=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n=this._webModel.load)){e.next=8;break}if(!n.onInit){e.next=5;break}return this.init(),e.abrupt("return");case 5:if(!n.onMessage){e.next=8;break}return this._loadOnFirstMessage=!0,e.abrupt("return");case 8:t||this.init();case 9:case"end":return e.stop()}}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"init",value:(m=f(h().mark((function e(t){var n,r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==(n=this._messages)||n.removeError(),r=this.attemptToCreateChat(),e.t0=r,!e.t0){e.next=6;break}return e.next=6,this.loadModel(r,t);case 6:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"attemptToCreateChat",value:function(){var e;if(t.chat)return null==(e=this._messages)||e.addNewErrorMessage("service",t.MULTIPLE_MODELS_ERROR),void console.error(t.MULTIPLE_MODELS_ERROR);if(!this._isModelLoaded&&!this._isModelLoading){var n=this._webModel.worker;return Tn.use_web_worker&&n?new window.webLLM.ChatWorkerClient(n):new window.webLLM.ChatModule}}},{key:"getConfig",value:function(){var e,n=t.DEFAULT_MODEL;this._webModel.model&&(n=this._webModel.model);var r=JSON.parse(JSON.stringify(Tn));if(this._webModel.urls){var i=r.model_list.find((function(e){return e.local_id=n}));i&&(this._webModel.urls.model&&(i.model_url=this._webModel.urls.model),this._webModel.urls.wasm&&(i.model_lib_url=this._webModel.urls.wasm))}return null!=(e=this._webModel.load)&&e.skipCache&&(r.use_cache=!1),{model:n,appConfig:r}}},{key:"loadModel",value:(p=f(h().mark((function e(n,r){var i,s,a,o,l,c,u,d,p,f,m,v,g,y,b,k=this;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.scrollToTop(),t.chat=n,this._isModelLoading=!0,d=!1===(null==(i=this._webModel.introMessage)?void 0:i.displayed),p=function(e){var t;null==(t=k._messages)||t.addNewMessage({html:"".concat(e.text,"
"),overwrite:!0,sendUpdate:!1}),d&&(setTimeout((function(){var e;return K.scrollToBottom(null==(e=k._messages)?void 0:e.elementRef)})),d=!1)},t.chat.setInitProgressCallback(p),e.prev=4,m=this.getConfig(),v=m.model,g=m.appConfig,y={},this._webModel.instruction&&(y.conv_config={system:this._webModel.instruction}),this._conversationHistory.length>0&&(y.conversation_history=this._conversationHistory),e.next=10,t.chat.reload(v,y,g,r);case 10:f=e.sent,e.next=16;break;case 13:return e.prev=13,e.t0=e.catch(4),e.abrupt("return",this.unloadChat(e.t0));case 16:null==(a=(s=this.deepChat)._validationHandler)||a.call(s),null!=(o=this._webModel.introMessage)&&o.removeAfterLoad?!1===this._webModel.introMessage.displayed?null==(c=this._messages)||c.removeLastMessage():null==(u=this._removeIntro)||u.call(this):(b=Cn.setUpAfterLoad(f,this._webModel.introMessage,this._chatEl,!!this._webModel.worker),null==(l=this._messages)||l.addNewMessage({html:b,overwrite:!0,sendUpdate:!1})),this._isModelLoaded=!0,this._isModelLoading=!1;case 18:case"end":return e.stop()}}),e,this,[[4,13]])}))),function(e,t){return p.apply(this,arguments)})},{key:"unloadChat",value:(d=f(h().mark((function e(n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==(r=this._messages)||r.addNewErrorMessage("service",t.GENERIC_ERROR),console.error(n),this._isModelLoaded=!1,this._isModelLoading=!1,e.t0=t.chat,!e.t0){e.next=9;break}return e.next=8,t.chat.unload();case 8:t.chat=void 0;case 9:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"immediateResp",value:(u=f(h().mark((function e(n,r,i){var s,a;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.generate(r,void 0,0);case 2:return e.t0=e.sent,s={text:e.t0},e.next=6,t.processResponse(this.deepChat,n,s);case 6:(a=e.sent)&&n.addNewMessage(a),this.completionsHandlers.onFinish();case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return u.apply(this,arguments)})},{key:"streamResp",value:(l=f(h().mark((function e(n,r,i){var s,a=this;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.streamHandlers.abortStream.abort=function(){i.interruptGenerate()},this.streamHandlers.onOpen(),s=new Jt(n),e.next=4,i.generate(r,function(){var e=f(h().mark((function e(r,i){var o;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.processResponse(a.deepChat,n,{text:i});case 2:(o=e.sent)&&s.upsertStreamedMessage({text:o.text,overwrite:!0});case 4:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}());case 4:s.finaliseStreamedMessage(),this.streamHandlers.onClose();case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return l.apply(this,arguments)})},{key:"generateRespByType",value:(o=f(h().mark((function e(t,n,r,i){var s;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,!r){e.next=6;break}return e.next=4,this.streamResp(t,n,i);case 4:e.next=8;break;case 6:return e.next=8,this.immediateResp(t,n,i);case 8:e.next=13;break;case 10:e.prev=10,e.t0=e.catch(0),null==(s=this._messages)||s.addNewErrorMessage("service"),console.log(e.t0);case 13:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(e,t,n,r){return o.apply(this,arguments)})},{key:"generateResp",value:(i=f(h().mark((function e(t,n,r){var i,s,a,o,l,c,u;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=n[n.length-1].text,e.next=3,Zt.processRequestInterceptor(this.deepChat,{body:{text:i}});case 3:s=e.sent,a=s.body,o=s.error,l=!!this.stream;try{o?(Zt.displayError(t,new Error(o)),(l?this.streamHandlers.onClose:this.completionsHandlers.onFinish)()):a&&a.text?this.generateRespByType(t,a.text,!!this.stream,r):(c=G.INVALID_MODEL_REQUEST({body:a},!1),console.error(c),u=l?this.streamHandlers.onClose:this.completionsHandlers.onFinish,Zt.onInterceptorError(t,c,u))}catch(c){this.unloadChat(c)}case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return i.apply(this,arguments)})},{key:"callServiceAPI",value:(r=f(h().mark((function e(n,r){var i,s;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._isModelLoaded){e.next=7;break}if(!this._loadOnFirstMessage){e.next=6;break}return e.next=4,this.init();case 4:e.next=7;break;case 6:return e.abrupt("return");case 7:!t.chat||this._isModelLoading||(null!=(i=this._webModel.introMessage)&&i.removeAfterMessage&&(null==(s=this._removeIntro)||s.call(this)),n.addLoadingMessage(),this.generateResp(n,r,t.chat));case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"canSubmit",value:function(e){return!(null==e||!e.trim()||this._isModelLoading)&&(!!this._loadOnFirstMessage||!!this._isModelLoaded)}},{key:"isWebModel",value:function(){return!0}}],[{key:"setUpHistory",value:function(e,t){t.forEach((function(n,r){if(n.role===Wt.USER_ROLE&&n.text){var i=t[r+1];null!=i&&i.text&&i.role!==Wt.USER_ROLE&&e.push([n.text,i.text])}}))}},{key:"processResponse",value:(n=f(h().mark((function e(t,n,r){var i,s,a;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==(i=t.responseInterceptor)?void 0:i.call(t,r);case 2:if(e.t0=e.sent,e.t0){e.next=5;break}e.t0=r;case 5:if(!(s=e.t0).error){e.next=11;break}return Zt.displayError(n,new Error(s.error)),e.abrupt("return");case 11:if(s&&s.text){e.next=15;break}return a=G.INVALID_MODEL_RESPONSE(r,!!t.responseInterceptor,s),Zt.displayError(n,new Error(a)),e.abrupt("return");case 15:return e.abrupt("return",s);case 16:case"end":return e.stop()}}),e)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"clearAllCache",value:function(){t.clearCache("webllm/model"),t.clearCache("webllm/wasm")}},{key:"clearCache",value:function(e){caches.open(e).then((function(e){e.keys().then((function(t){t.forEach((function(t){e.delete(t)}))}))}))}}]);var n,r,i,o,l,u,d,p,m,v}(vn);An.GENERIC_ERROR="Error, please check the [troubleshooting](https://deepchat.dev/docs/webModel#troubleshooting) section of documentation for help.",An.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",An.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",An.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",An.MODULE_SEARCH_LIMIT_S=5;var Mn=An,In=function(){function e(){x(this,e)}return E(e,null,[{key:"buildHeaders",value:function(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}}},{key:"handleVerificationResult",value:function(e,t,n,r){var i=e;Array.isArray(i.error)&&"Error in `parameters`: field required"===i.error[0]?n(t):r(G.INVALID_KEY)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api-inference.huggingface.co/models/gpt2",method:"POST",handleVerificationResult:e.handleVerificationResult}}}])}(),Ln=function(e){function t(e,n,r,i,a,o){var l;return x(this,t),(l=s(this,t,[e,In.buildKeyVerificationDetails(),In.buildHeaders,a,o])).insertKeyPlaceholderText="Hugging Face Token",l.keyHelpUrl="https://huggingface.co/settings/tokens",l.introPanelMarkUp='\n Hugging Face
\n First message may take an extented amount of time to complete as the model needs to be initialized.
',l.permittedErrorPrefixes=["Authorization header"],l.url="".concat(t.URL_PREFIX).concat(r),l.textInputPlaceholderText=n,"object"==_(i)&&(i.model&&(l.url="".concat(t.URL_PREFIX).concat(i.model)),i.options&&(l.rawBody.options=i.options),i.parameters&&(l.rawBody.parameters=i.parameters)),l}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t,n){var r,i=JSON.parse(JSON.stringify(e)),s=t[t.length-1].text;if(s)return null!==(r=i.options)&&void 0!==r||(i.options={}),i.options.wait_for_model=!0,b({inputs:s},i)}},{key:"callServiceAPI",value:(n=f(h().mark((function e(t,n,r){var i;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:i=this.preprocessBody(this.rawBody,n,r),dn.request(this,i,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})}]);var n}(gn);Ln.URL_PREFIX="https://api-inference.huggingface.co/models/";var Rn=Ln,On=function(e){function t(e,n,r,i,a,o){var l;return x(this,t),(l=s(this,t,[e,n,r,i,a,o])).isTextInputDisabled=!0,l.canSendMessage=t.canSendFile,l}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t,n){return n[0]}},{key:"callServiceAPI",value:(n=f(h().mark((function e(t,n,r){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(null!=r&&r[0]){e.next=4;break}throw new Error("No file was added");case 4:dn.poll(this,r[0],t,!1);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})}],[{key:"canSendFile",value:function(e,t){return!(null==t||!t[0])}}]);var n}(Rn),Pn=function(e){function t(e){var n,r,i;return x(this,t),s(this,t,[e,"Attach an audio file","ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",null==(r=null==(n=e.directConnection)?void 0:n.huggingFace)?void 0:r.audioClassification,null==(i=e.directConnection)?void 0:i.huggingFace,{audio:{}}])}return c(t,e),E(t,[{key:"extractPollResultData",value:(n=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.estimated_time){e.next=2;break}return e.abrupt("return",{timeoutMS:1e3*(t.estimated_time+1)});case 2:if(!t.error){e.next=4;break}throw t.error;case 4:return e.abrupt("return",{text:(null==(n=t[0])?void 0:n.label)||""});case 5:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(On),Nn=function(e){function t(e){var n,r,i;return x(this,t),s(this,t,[e,"Attach an image file","google/vit-base-patch16-224",null==(r=null==(n=e.directConnection)?void 0:n.huggingFace)?void 0:r.imageClassification,null==(i=e.directConnection)?void 0:i.huggingFace,{images:{}}])}return c(t,e),E(t,[{key:"extractPollResultData",value:(n=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.estimated_time){e.next=2;break}return e.abrupt("return",{timeoutMS:1e3*(t.estimated_time+1)});case 2:if(!t.error){e.next=4;break}throw t.error;case 4:return e.abrupt("return",{text:(null==(n=t[0])?void 0:n.label)||""});case 5:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(On),Bn="data:image/png;base64,",Dn=function(){function e(){x(this,e)}return E(e,null,[{key:"buildHeaders",value:function(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}}},{key:"handleVerificationResult",value:function(e,t,n,r){e.message?r(G.INVALID_KEY):n(t)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.stability.ai/v1/engines/list",method:"GET",handleVerificationResult:e.handleVerificationResult}}}])}(),Fn=function(e){function t(e,n,r,i,a){var o;return x(this,t),(o=s(this,t,[e,n,r,i,a])).insertKeyPlaceholderText="Stability AI API Key",o.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",o.permittedErrorPrefixes=["Incorrect","invalid_"],o}return c(t,e),E(t)}(gn),jn=function(e){function t(e){var n,r;x(this,t);var i=JSON.parse(JSON.stringify(e.directConnection)),a=null==i?void 0:i.stabilityAI;(n=s(this,t,[e,Dn.buildKeyVerificationDetails(),Dn.buildHeaders,a,{images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}}])).url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",n.textInputPlaceholderText="Describe image changes",n.introPanelMarkUp='\n Stability AI
\n Image to Image Upscale
\n Upload an image to generate a new one with higher resolution.
\n Click here for more info.
';var o=null==(r=null==i?void 0:i.stabilityAI)?void 0:r.imageToImageUpscale;return"object"==_(o)&&(o.engine_id&&(n.url="https://api.stability.ai/v1/generation/".concat(o.engine_id,"/image-to-image/upscale")),t.cleanConfig(o),Object.assign(n.rawBody,o)),n.canSendMessage=t.canSendFileMessage,n}return c(t,e),E(t,[{key:"createFormDataBody",value:function(e,t){var n=new FormData;return n.append("image",t),Object.keys(e).forEach((function(t){n.append(t,String(e[t]))})),n}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n,r){var i;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(r){e.next=4;break}throw new Error("Image was not found");case 4:i=this.createFormDataBody(this.rawBody,r[0]),Zt.tempRemoveContentHeader(this.connectSettings,dn.request.bind(this,this,i,t),!1);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.message){e.next=2;break}throw t.message;case 2:return e.abrupt("return",{files:t.artifacts.map((function(e){return{src:"".concat(Bn).concat(e.base64),type:"image"}}))});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}],[{key:"cleanConfig",value:function(e){delete e.engine_id}},{key:"canSendFileMessage",value:function(e,t){return!(null==t||!t[0])}}]);var n,r}(Fn),Un=function(e){function t(e){var n,r;x(this,t);var i=JSON.parse(JSON.stringify(e.directConnection)),a=null==i?void 0:i.stabilityAI;(n=s(this,t,[e,Dn.buildKeyVerificationDetails(),Dn.buildHeaders,a,{images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}}])).url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",n._maskSource="MASK_IMAGE_WHITE",n.textInputPlaceholderText="Describe image changes",n.introPanelMarkUp='\n Stability AI
\n Image to Image Masking
\n Upload an image, its mask image to create a new one based on the changes you have described for the mask area.
\n Click here for more info.
';var o=null==(r=null==i?void 0:i.stabilityAI)?void 0:r.imageToImageMasking;return"object"==_(o)&&(o.engine_id&&(n.url="https://api.stability.ai/v1/generation/".concat(o.engine_id,"/image-to-image/masking")),void 0!==o.weight&&null!==o.weight&&(n._imageWeight=o.weight),void 0!==o.mask_source&&null!==o.mask_source&&(n._maskSource=o.mask_source),t.cleanConfig(o),Object.assign(n.rawBody,o)),n.canSendMessage=t.canSendFileTextMessage,n}return c(t,e),E(t,[{key:"createFormDataBody",value:function(e,t,n,r){var i=new FormData;return i.append("init_image",t),i.append("mask_source",String(this._maskSource)),i.append("mask_image",n),r&&""!==r&&i.append("text_prompts[0][text]",r),void 0!==this._imageWeight&&null!==this._imageWeight&&i.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach((function(t){i.append(t,String(e[t]))})),void 0===i.get("weight")&&i.append("weight",String(1)),i}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n,r){var i,s,a,o;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(r&&r[0]&&r[1]){e.next=4;break}throw new Error("Image was not found");case 4:a=null==(s=null==(i=n[n.length-1])?void 0:i.text)?void 0:s.trim(),o=this.createFormDataBody(this.rawBody,r[0],r[1],a),Zt.tempRemoveContentHeader(this.connectSettings,dn.request.bind(this,this,o,t),!1);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.message){e.next=2;break}throw t.message;case 2:return e.abrupt("return",{files:t.artifacts.map((function(e){return{src:"".concat(Bn).concat(e.base64),type:"image"}}))});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}],[{key:"cleanConfig",value:function(e){delete e.engine_id,delete e.weight}},{key:"canSendFileTextMessage",value:function(e,t){return!(null==t||!t[0]||!e||""===e.trim())}}]);var n,r}(Fn),Hn=function(e){function t(e){var n,r,i;return x(this,t),s(this,t,[e,"Attach an audio file","facebook/wav2vec2-large-960h-lv60-self",null==(r=null==(n=e.directConnection)?void 0:n.huggingFace)?void 0:r.audioSpeechRecognition,null==(i=e.directConnection)?void 0:i.huggingFace,{audio:{}}])}return c(t,e),E(t,[{key:"extractPollResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.estimated_time){e.next=2;break}return e.abrupt("return",{timeoutMS:1e3*(t.estimated_time+1)});case 2:if(!t.error){e.next=4;break}throw t.error;case 4:return e.abrupt("return",{text:t.text||""});case 5:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(On),qn=function(e){function t(e){var n,r,i;return x(this,t),s(this,t,[e,"Once upon a time","gpt2",null==(r=null==(n=e.directConnection)?void 0:n.huggingFace)?void 0:r.textGeneration,null==(i=e.directConnection)?void 0:i.huggingFace])}return c(t,e),E(t,[{key:"extractResultData",value:(n=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:return e.abrupt("return",{text:(null==(n=t[0])?void 0:n.generated_text)||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(Rn),zn=function(e){function t(e){var n,r,i,a;x(this,t);var o=null==(i=null==(r=e.directConnection)?void 0:r.huggingFace)?void 0:i.questionAnswer;return(n=s(this,t,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",o,null==(a=e.directConnection)?void 0:a.huggingFace])).permittedErrorPrefixes=["Authorization header","Error in"],n.context=o.context,n}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n=t[t.length-1].text;if(n)return{inputs:{question:n,context:this.context,options:{wait_for_model:!0}}}}},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:return e.abrupt("return",{text:t.answer||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(Rn),Vn=function(e){function t(e){var n,r,i;return x(this,t),s(this,t,[e,"Insert text to summarize","facebook/bart-large-cnn",null==(r=null==(n=e.directConnection)?void 0:n.huggingFace)?void 0:r.summarization,null==(i=e.directConnection)?void 0:i.huggingFace])}return c(t,e),E(t,[{key:"extractResultData",value:(n=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:return e.abrupt("return",{text:(null==(n=t[0])?void 0:n.summary_text)||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(Rn),Gn=function(e){function t(e){var n,r,i,a,o;return x(this,t),null!==(n=(r=s(this,t,[e,"Ask me anything!","facebook/blenderbot-400M-distill",null==(a=null==(i=e.directConnection)?void 0:i.huggingFace)?void 0:a.conversation,null==(o=e.directConnection)?void 0:o.huggingFace])).maxMessages)&&void 0!==n||(r.maxMessages=-1),r}return c(t,e),E(t,[{key:"processMessages",value:function(e){var t=e.filter((function(e){return e.text})),n=t[t.length-1].text,r=t.slice(0,t.length-1);if(n)return{past_user_inputs:r.filter((function(e){return"user"===e.role})).map((function(e){return e.text})),generated_responses:r.filter((function(e){return"ai"===e.role})).map((function(e){return e.text})),mostRecentMessageText:n}}},{key:"preprocessBody",value:function(e,t){var n,r=JSON.parse(JSON.stringify(e)),i=this.processMessages(t);if(i)return null!==(n=r.options)&&void 0!==n||(r.options={}),r.options.wait_for_model=!0,b({inputs:{past_user_inputs:i.past_user_inputs,generated_responses:i.generated_responses,text:i.mostRecentMessageText}},r)}},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:return e.abrupt("return",{text:t.generated_text||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(Rn),Wn=function(e){function t(e){var n,r;x(this,t);var i=JSON.parse(JSON.stringify(e.directConnection)),a=i.stabilityAI;(n=s(this,t,[e,Dn.buildKeyVerificationDetails(),Dn.buildHeaders,a,{images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}}])).url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",n.textInputPlaceholderText="Describe image changes",n.introPanelMarkUp='\n Stability AI: Image to Image
\n Upload an image to create a new one with the changes you have described.
\n Click here for more info.
';var o=null==(r=i.stabilityAI)?void 0:r.imageToImage;return"object"==_(o)&&(o.engine_id&&(n.url="https://api.stability.ai/v1/generation/".concat(o.engine_id,"/text-to-image")),void 0!==o.weight&&null!==o.weight&&(n._imageWeight=o.weight),t.cleanConfig(o),Object.assign(n.rawBody,o)),n.canSendMessage=t.canSendFileTextMessage,n}return c(t,e),E(t,[{key:"createFormDataBody",value:function(e,t,n){var r=new FormData;return r.append("init_image",t),n&&""!==n&&r.append("text_prompts[0][text]",n),void 0!==this._imageWeight&&null!==this._imageWeight&&r.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach((function(t){r.append(t,String(e[t]))})),void 0===r.get("weight")&&r.append("weight",String(1)),r}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n,r){var i,s,a,o;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(r){e.next=4;break}throw new Error("Image was not found");case 4:a=null==(s=null==(i=n[n.length-1])?void 0:i.text)?void 0:s.trim(),o=this.createFormDataBody(this.rawBody,r[0],a),Zt.tempRemoveContentHeader(this.connectSettings,dn.request.bind(this,this,o,t),!1);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.message){e.next=2;break}throw t.message;case 2:return e.abrupt("return",{files:t.artifacts.map((function(e){return{src:"".concat(Bn).concat(e.base64),type:"image"}}))});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}],[{key:"cleanConfig",value:function(e){delete e.engine_id,delete e.weight}},{key:"canSendFileTextMessage",value:function(e,t){return!(null==t||!t[0]||!e||""===e.trim())}}]);var n,r}(Fn),Kn=function(e){function t(e){var n,r,i;return x(this,t),s(this,t,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",null==(r=null==(n=e.directConnection)?void 0:n.huggingFace)?void 0:r.translation,null==(i=e.directConnection)?void 0:i.huggingFace])}return c(t,e),E(t,[{key:"extractResultData",value:(n=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:return e.abrupt("return",{text:(null==(n=t[0])?void 0:n.translation_text)||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(Rn),Jn=function(e){function t(e){var n,r;x(this,t);var i=JSON.parse(JSON.stringify(e.directConnection)),a=i.stabilityAI;(n=s(this,t,[e,Dn.buildKeyVerificationDetails(),Dn.buildHeaders,a])).url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",n.textInputPlaceholderText="Describe an image",n.introPanelMarkUp='\n Stability AI: Text to Image
\n Insert text to generate an image.
\n Click here for more info.
';var o=null==(r=i.stabilityAI)?void 0:r.textToImage;return"object"==_(o)&&(o.engine_id&&(n.url="https://api.stability.ai/v1/generation/".concat(o.engine_id,"/text-to-image")),void 0!==o.weight&&null!==o.weight&&(n._imageWeight=o.weight),t.cleanConfig(o),Object.assign(n.rawBody,o)),n.canSendMessage=t.canSendTextMessage,n}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n=JSON.parse(JSON.stringify(e)),r={text:t};return this._imageWeight&&(r.weight=this._imageWeight),n.text_prompts=[r],n}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n[n.length-1].text),dn.request(this,r,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.message){e.next=2;break}throw t.message;case 2:return e.abrupt("return",{files:t.artifacts.map((function(e){return{src:"".concat(Bn).concat(e.base64),type:"image"}}))});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}],[{key:"cleanConfig",value:function(e){delete e.engine_id,delete e.weight}},{key:"canSendTextMessage",value:function(e){return!(!e||""===e.trim())}}]);var n,r}(Fn),Yn=function(e){function t(e){var n,r,i,a;return x(this,t),(n=s(this,t,[e,"The goal of life is [MASK].","bert-base-uncased",null==(i=null==(r=e.directConnection)?void 0:r.huggingFace)?void 0:i.fillMask,null==(a=e.directConnection)?void 0:a.huggingFace])).introPanelMarkUp='\n Hugging Face
\n Insert a sentence with the word [MASK] and the model will try to fill it for you. E.g. I want [MASK].
\n First message may take an extented amount of time to complete as the model needs to be initialized.
',n.permittedErrorPrefixes=["Authorization header","No mask_token"],n}return c(t,e),E(t,[{key:"extractResultData",value:(n=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:return e.abrupt("return",{text:(null==(n=t[0])?void 0:n.sequence)||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n}(Rn),Zn=function(){function e(){x(this,e)}return E(e,null,[{key:"buildHeaders",value:function(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}}},{key:"handleVerificationResult",value:function(e,t,n,r){var i=e;i.error?"invalid_api_key"===i.error.code?r(G.INVALID_KEY):r(G.CONNECTION_FAILED):n(t)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.openai.com/v1/models",method:"GET",handleVerificationResult:e.handleVerificationResult}}},{key:"directFetch",value:(t=f(h().mark((function e(t,n,r){var i,s,a=arguments;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=!(a.length>3&&void 0!==a[3])||a[3],t.connectSettings.method=r,e.next=4,Zt.fetch(t,t.connectSettings.headers,i,n).then((function(e){return Zt.processResponseByType(e)}));case 4:if(!(s=e.sent).error){e.next=7;break}throw s.error.message;case 7:return e.abrupt("return",s);case 8:case"end":return e.stop()}}),e)}))),function(e,n,r){return t.apply(this,arguments)})}]);var t}();Zn.FUNCTION_TOOL_RESP_ERROR="Response object must either be {response: string}[] for each individual function or {text: string} for a direct response, see https://deepchat.dev/docs/directConnection/OpenAI#FunctionHandler.";var Xn=Zn,Qn=function(){function e(){x(this,e)}return E(e,null,[{key:"storeFiles",value:(a=f(h().mark((function e(t,n,r,i){var s,a,o,l;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(s=t.connectSettings.headers){e.next=3;break}return e.abrupt("return");case 3:return t.url=i,a=s[Zt.CONTENT_TYPE],delete s[Zt.CONTENT_TYPE],o=r.map(function(){var e=f(h().mark((function e(n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new FormData,e.abrupt("return",(r.append("purpose","assistants"),r.append("file",n),new Promise((function(e){e(Xn.directFetch(t,r,"POST",!1))}))));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),e.prev=7,e.next=10,Promise.all(o);case 10:return l=e.sent.map((function(e){return{id:e.id,name:e.filename}})),e.abrupt("return",(s[Zt.CONTENT_TYPE]=a,l));case 14:throw e.prev=14,e.t0=e.catch(7),s[Zt.CONTENT_TYPE]=a,Zt.displayError(n,e.t0),t.completionsHandlers.onFinish(),e.t0;case 17:case"end":return e.stop()}}),e,null,[[7,14]])}))),function(e,t,n,r){return a.apply(this,arguments)})},{key:"getType",value:function(e,t){var n=e[t].path;return!n||n.endsWith("png")?"image":"any"}},{key:"getFiles",value:(s=f(h().mark((function t(n,r,i,s){var a,o;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=r.map((function(e){var t=e.fileId;return n.url="".concat(i).concat(t).concat(s),new Promise((function(e){e(Xn.directFetch(n,void 0,"GET",!1))}))})),t.next=3,Promise.all(a);case 3:return o=t.sent.map((function(t,n){return new Promise((function(i){var s=new FileReader;s.readAsDataURL(t),s.onload=function(t){i({src:t.target.result,name:r[n].name,type:e.getType(r,n)})}}))})),t.next=6,Promise.all(o);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t)}))),function(e,t,n,r){return s.apply(this,arguments)})},{key:"getFileName",value:function(e){var t=e.split("/");return t[t.length-1]}},{key:"getFilesAndNewText",value:(i=f(h().mark((function t(n,r,i,s,a){var o,l,c,u,d;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(u=i.getFilesPrefix,d=i.getFilesPostfix,t.t0=r.length>0,!t.t0){t.next=7;break}return t.next=5,e.getFiles(n,r,u,d);case 5:c=t.sent,null!=(o=null==a?void 0:a.text)&&o.value&&c.forEach((function(e,t){var n;if(e.src){var i=r[t].path;null!=(n=null==a?void 0:a.text)&&n.value&&i&&(a.text.value=a.text.value.replace(i,e.src))}}));case 7:return t.abrupt("return",null!=(l=null==a?void 0:a.text)&&l.value?{text:a.text.value,role:s}:{files:c,role:s});case 8:case"end":return t.stop()}}),t)}))),function(e,t,n,r,s){return i.apply(this,arguments)})},{key:"getFileDetails",value:function(t,n){var r,i=[];return null!=(r=null==n?void 0:n.text)&&r.value&&t.content.forEach((function(t){var n,r;null==(r=null==(n=t.text)?void 0:n.annotations)||r.forEach((function(t){var n;t.text&&t.text.startsWith("sandbox:")&&null!=(n=t.file_path)&&n.file_id&&i.push({path:t.text,fileId:t.file_path.file_id,name:e.getFileName(t.text)})}))})),null!=n&&n.image_file&&i.push({fileId:n.image_file.file_id}),i}},{key:"getFilesAndText",value:(r=f(h().mark((function t(n,r,i,s){var a;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=e.getFileDetails(r,s),t.next=3,e.getFilesAndNewText(n,a,i,r.role,s);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"parseResult",value:function(e,t){var n=[];if(t)n=e.data;else for(var r=0;r0){var s=this.filesToolType;if("function"==typeof this.filesToolType){var a=this.filesToolType(n.map((function(e){return e.name})));"code_interpreter"===a||"file_search"===a||"images"===a?s=a:(console.error('Tool type "'.concat(a,'" is not valid')),console.error('Expected "code_interpreter" or "file_search" or "images". Going to default to "images"'))}if("file_search"===s)return t.processAttachmentsMessage(i,n,"file_search");if("code_interpreter"===s)return t.processAttachmentsMessage(i,n,"code_interpreter");if(n.find((function(e){var t=e.name;return!$.isImageFileExtension(t)})))console.error("The uploaded files contained a non-image file"),console.error('Make sure only images can be uploaded or define a "code_interpreter" or "file_search" value in the "files_tool_type" property'),console.warn('Make sure your existing assistant supports these "tools" or specify them in the "new_assistant" property');else{var o=t.processImageMessage(i,n);if(o)return o}}return{content:i.text||"",role:"user"}}},{key:"createNewThreadMessages",value:function(e,t,n){var r=JSON.parse(JSON.stringify(e)),i=this.processMessage(t,n);return r.thread={messages:[i]},r}},{key:"callService",value:function(e,t,n){if(this.messages=e,this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/messages").concat(this.urlSegments.createMessagePostfix);var r=this.processMessage(t,n);dn.request(this,r,e)}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var i=this.createNewThreadMessages(this.rawBody,t,n);this.isSSEStream?this.createStreamRun(i):dn.request(this,i,e)}}},{key:"callServiceAPI",value:(v=f(h().mark((function e(t,n,r){var i,s,a;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.waitingForStreamResponse=!1,this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(null===(i=(s=this.rawBody).assistant_id)||void 0===i){e.next=6;break}e.next=12;break;case 6:if(e.t0=this.config.assistant_id,e.t0){e.next=11;break}return e.next=10,this.createNewAssistant();case 10:e.t0=e.sent;case 11:s.assistant_id=e.t0;case 12:if(this.searchedForThreadId||this.searchPreviousMessagesForThreadId(t.messageToElements),!r){e.next=19;break}return e.next=16,$n.storeFiles(this,t,r,this.urlSegments.storeFiles);case 16:e.t1=e.sent,e.next=20;break;case 19:e.t1=void 0;case 20:a=e.t1,this.connectSettings.method="POST",this.callService(t,n,a);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return v.apply(this,arguments)})},{key:"createNewAssistant",value:(m=f(h().mark((function e(){var t;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,this.url=this.urlSegments.newAssistantUrl,e.next=4,Xn.directFetch(this,JSON.parse(JSON.stringify(this.newAssistantDetails)),"POST");case 4:return t=e.sent,e.abrupt("return",(this.config.assistant_id=t.id,this.config.assistant_id));case 8:e.prev=8,e.t0=e.catch(0),console.error(e.t0),console.error("Failed to create a new assistant");case 11:case"end":return e.stop()}}),e,this,[[0,8]])}))),function(){return m.apply(this,arguments)})},{key:"searchPreviousMessagesForThreadId",value:function(e){var t=e.find((function(e){return d(e,1)[0]._sessionId}));t&&(this.sessionId=t[0]._sessionId),this.searchedForThreadId=!0}},{key:"extractResultData",value:(p=f(h().mark((function e(t){var n,r,i;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(this.waitingForStreamResponse||this.isSSEStream&&this.sessionId)){e.next=4;break}return e.next=3,this.handleStream(t);case 3:return e.abrupt("return",e.sent);case 4:if(!t.error){e.next=6;break}throw t.error.message.startsWith($n.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):t.error.message;case 6:return e.next=8,this.assignThreadAndRun(t);case 8:return r="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs/").concat(this.run_id).concat(this.urlSegments.threadsPosfix),i={method:"GET",headers:null==(n=this.connectSettings)?void 0:n.headers},e.abrupt("return",(dn.executePollRequest(this,r,i,this.messages),{makingAnotherRequest:!0}));case 10:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"assignThreadAndRun",value:(u=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.sessionId){e.next=8;break}return this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix),e.next=4,Xn.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),"POST");case 4:n=e.sent,this.run_id=n.id,e.next=9;break;case 8:this.sessionId=t.thread_id,this.run_id=t.id,this.messages&&this.messages.messageToElements.length>0&&(this.messages.messageToElements[this.messages.messageToElements.length-1][0]._sessionId=this.sessionId);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"getThreadMessages",value:(l=f(h().mark((function e(t){var n,r,i,s,a=arguments;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>1&&void 0!==a[1]&&a[1],this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(t,"/messages?").concat(this.urlSegments.listMessagesPostfix),e.next=4,Xn.directFetch(this,{},"GET");case 4:if(s=e.sent,e.t0=!n&&this.deepChat.responseInterceptor,!e.t0){e.next=10;break}return e.next=9,null==(i=(r=this.deepChat).responseInterceptor)?void 0:i.call(r,s);case 9:s=e.sent;case 10:return e.abrupt("return",$n.processAPIMessages(this,s,n,this.urlSegments));case 11:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"extractPollResultData",value:(o=f(h().mark((function e(n){var r,i,s,a,o,l,c,u,d=this;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=n.status,s=n.required_action,"queued"!==i&&"in_progress"!==i){e.next=3;break}return e.abrupt("return",{timeoutMS:t.POLLING_TIMEOUT_MS});case 3:if("completed"!==i||!this.messages){e.next=11;break}return e.next=6,this.getThreadMessages(n.thread_id);case 6:return a=e.sent,o=a.shift(),l=o.text,c=o.files,e.abrupt("return",(setTimeout((function(){a.forEach((function(e){return d.deepChat.addMessage(e)}))})),{text:l,_sessionId:this.sessionId,files:c}));case 11:if(u=null==(r=null==s?void 0:s.submit_tool_outputs)?void 0:r.tool_calls,"requires_action"!==i||!u){e.next=16;break}return e.next=15,this.handleTools(u);case 15:return e.abrupt("return",e.sent);case 16:throw Error("Thread run status: ".concat(i));case 17:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"handleTools",value:(a=f(h().mark((function e(n){var r,i,s,a,o,l;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.functionHandler){e.next=2;break}throw Error("Please define the `function_handler` property inside the [openAI](https://deepchat.dev/docs/directConnection/openAI#Assistant) object.");case 2:return r=n.map((function(e){return{name:e.function.name,arguments:e.function.arguments}})),e.next=5,this.functionHandler(r);case 5:if(i=e.sent,Array.isArray(i)&&n.length===i.length){e.next=8;break}throw Error($n.FUNCTION_TOOL_RESP_ERROR);case 8:return e.next=10,Promise.all(i);case 10:if(!(s=e.sent).find((function(e){return"string"!=typeof e}))){e.next=13;break}throw Error($n.FUNCTION_TOOL_RESP_ERROR);case 13:if(a=s.map((function(e,t){return{tool_call_id:n[t].id,output:e}})),o="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId),l="/runs/".concat(this.run_id,"/submit_tool_outputs").concat(this.urlSegments.threadsPosfix),this.url="".concat(o).concat(l),!this.isSSEStream){e.next=20;break}return e.next=18,this.createStreamRun({tool_outputs:a});case 18:e.next=22;break;case 20:return e.next=22,Xn.directFetch(this,{tool_outputs:a},"POST");case 22:return e.abrupt("return",{timeoutMS:t.POLLING_TIMEOUT_MS});case 23:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"handleStream",value:(i=f(h().mark((function e(t){var n,r,i,s;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=null==(r=null==(n=t.required_action)?void 0:n.submit_tool_outputs)?void 0:r.tool_calls,"requires_action"!==t.status||!i){e.next=6;break}return this.run_id=t.id,e.next=5,this.handleTools(i);case 5:return e.abrupt("return",e.sent);case 6:if(!this.waitingForStreamResponse){e.next=8;break}return e.abrupt("return",this.parseStreamResult(t));case 8:return this.isSSEStream&&this.sessionId&&(this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix),s=JSON.parse(JSON.stringify(this.rawBody)),this.createStreamRun(s)),e.abrupt("return",{makingAnotherRequest:!0});case 10:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"parseStreamResult",value:(r=f(h().mark((function e(t){var n,r,i,s,a,o,l,c,u,d;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(t.content&&t.content.length>0&&this.messages)){e.next=5;break}if(o=t.content.find((function(e){return e.text})),!(null!=(n=null==o?void 0:o.text)&&n.annotations&&o.text.annotations.length>0)){e.next=5;break}return l=t.content.find((function(e){return!!e.text}))||t.content[0],c=$n.getFilesAndText.bind(this,this,{role:"assistant",content:t.content},this.urlSegments,l),e.abrupt("return",(null==(r=this.messageStream)||r.endStreamAfterFileDownloaded(this.messages,c),{text:""}));case 5:if(null==(i=t.delta)||!i.content){e.next=14;break}if(!(t.delta.content.length>1)){e.next=13;break}if(u=t.delta.content.find((function(e){return e.text})),null==(s=null==u?void 0:u.text)||!s.annotations||0!==u.text.annotations.length){e.next=13;break}return e.next=11,$n.processStreamMessages(this,t.delta.content,this.urlSegments);case 11:return d=e.sent,e.abrupt("return",{text:d[0].text,files:d[1].files});case 13:return e.abrupt("return",{text:null==(a=t.delta.content[0].text)?void 0:a.value});case 14:return e.abrupt("return",(!this.sessionId&&t.thread_id&&(this.sessionId=t.thread_id),{makingAnotherRequest:!0}));case 15:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"createStreamRun",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.stream=!0,this.waitingForStreamResponse=!0,e.next=4,an.request(this,t,this.messages,!0,!0);case 4:this.messageStream=e.sent;case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}],[{key:"processImageMessage",value:function(e,t){var n=null==t?void 0:t.filter((function(e){return $.isImageFileExtension(e.name)})).map((function(e){return{type:"image_file",image_file:{file_id:e.id}}}));if(n&&n.length>0)return e.text&&e.text.length>0&&n.push({type:"text",text:e.text}),{content:n,role:"user"}}},{key:"processAttachmentsMessage",value:function(e,t,n){return{attachments:t.map((function(e){return{tools:[{type:n}],file_id:e.id}})),content:[{type:"text",text:e.text}],role:"user"}}}]);var n,r,i,a,o,l,u,p,m,v,g}(gn);er.POLLING_TIMEOUT_MS=800;var tr=er,nr=function(e){function t(e){var n,r,i,o,l,c,u,d;x(this,t);var h=JSON.parse(JSON.stringify(e.directConnection)),p=h.openAI,f=null==(o=h.openAI)?void 0:o.assistant;if(null!==(n=(l=(i=s(this,t,[e,f,t.URL_SEGMENTS,Xn.buildKeyVerificationDetails(),Xn.buildHeaders,p])).connectSettings).headers)&&void 0!==n||(l.headers={}),null!==(r=(c=i.connectSettings.headers)["OpenAI-Beta"])&&void 0!==r||(c["OpenAI-Beta"]="assistants=v2"),i.shouldFetchHistory&&i.sessionId&&(i.fetchHistory=i.fetchHistoryFunc.bind(a(i))),"object"==_(f)){var m=null==(d=null==(u=e.directConnection)?void 0:u.openAI)?void 0:d.assistant,v=m.function_handler,g=m.files_tool_type;v&&(i.functionHandler=v),g&&(i.filesToolType=g)}return i}return c(t,e),E(t)}(tr);nr.URL_SEGMENTS={threadsPrefix:"https://api.openai.com/v1/threads",threadsPosfix:"",newAssistantUrl:"https://api.openai.com/v1/assistants",createMessagePostfix:"",listMessagesPostfix:"order=desc",storeFiles:"https://api.openai.com/v1/files",getFilesPrefix:"https://api.openai.com/v1/files/",getFilesPostfix:"/content"};var rr=nr,ir=function(){function e(){x(this,e)}return E(e,null,[{key:"buildHeaders",value:function(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json",accept:"application/json"}}},{key:"handleVerificationResult",value:function(e,t,n,r){var i;null!=(i=e.message)&&i.includes("invalid request: prompt must be at least 1 token long")?n(t):r(G.INVALID_KEY)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.cohere.ai/v1/generate",method:"POST",handleVerificationResult:e.handleVerificationResult,body:JSON.stringify({prompt:""})}}}])}(),sr=function(e){function t(e,n,r,i,a){var o;return x(this,t),(o=s(this,t,[e,ir.buildKeyVerificationDetails(),ir.buildHeaders,a])).insertKeyPlaceholderText="Cohere API Key",o.keyHelpUrl="https://dashboard.cohere.ai/api-keys",o.permittedErrorPrefixes=["invalid"],o.url=n,o.textInputPlaceholderText=r,i&&"object"==_(i)&&Object.assign(o.rawBody,i),o}return c(t,e),E(t)}(gn),ar=function(e){function t(e){var n,r,i;return x(this,t),s(this,t,[e,"https://api.cohere.ai/v1/generate","Once upon a time",null==(r=null==(n=e.directConnection)?void 0:n.cohere)?void 0:r.textGeneration,null==(i=e.directConnection)?void 0:i.cohere])}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n=JSON.parse(JSON.stringify(e)),r=t[t.length-1].text;if(r)return b({prompt:r},n)}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),dn.request(this,r,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.message){e.next=2;break}throw t.message;case 2:return e.abrupt("return",{text:(null==(n=t.generations)?void 0:n[0].text)||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n,r}(sr),or=function(){return E((function e(){x(this,e)}),null,[{key:"buildHeaders",value:function(e){return{"api-key":e,"Content-Type":"application/json"}}},{key:"buildKeyVerificationDetails",value:function(e){return{url:"".concat(e.endpoint,"/openai/models?api-version=").concat(e.version),method:"GET",handleVerificationResult:Xn.handleVerificationResult}}},{key:"validateURLDetails",value:function(e){var t=e.endpoint,n=e.version,r=e.deploymentId;return t&&n&&r}}])}();or.URL_DETAILS_ERROR_MESSAGE="Please define the Azure URL Details. [More Information](https://deepchat.dev/docs/directConnection/Azure)";var lr=or,cr=function(e){function t(e){var n,r,i,a,o,l,c,u,d,h;x(this,t);var p=JSON.parse(JSON.stringify(e.directConnection)),f=p.azure,m=null==(i=p.azure)?void 0:i.openAI,v=(null==m?void 0:m.urlDetails)||{},g="".concat(null==(a=null==m?void 0:m.urlDetails)?void 0:a.endpoint,"/openai/"),y="?api-version=".concat(null==(o=null==m?void 0:m.urlDetails)?void 0:o.version),b={threadsPrefix:"".concat(g).concat(t.THREAD_RESOURCE),threadsPosfix:y,newAssistantUrl:"".concat(g).concat(t.NEW_ASSISTANT_RESOURCE).concat(y),createMessagePostfix:y,listMessagesPostfix:"order=desc&api-version=".concat(null==(l=null==m?void 0:m.urlDetails)?void 0:l.version),storeFiles:"".concat(g,"files").concat(y),getFilesPrefix:"".concat(g,"files/"),getFilesPostfix:"/content".concat(y)};if((r=s(this,t,[e,null==m?void 0:m.assistant,b,lr.buildKeyVerificationDetails(v),lr.buildHeaders,f])).permittedErrorPrefixes=[lr.URL_DETAILS_ERROR_MESSAGE],r.insertKeyPlaceholderText="Azure OpenAI API Key",r.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",r.isTextInputDisabled=!1,"object"==_(null==m?void 0:m.assistant)){var k=null==(d=null==(u=null==(c=e.directConnection)?void 0:c.azure)?void 0:u.openAI)?void 0:d.assistant,S=k.function_handler,E=k.files_tool_type;S&&(r.functionHandler=S),E&&(r.filesToolType=E)}return lr.validateURLDetails(v)?null!==(n=(h=r.connectSettings).headers)&&void 0!==n||(h.headers={}):(r.isTextInputDisabled=!0,r.canSendMessage=function(){return!1},setTimeout((function(){e.addMessage({error:lr.URL_DETAILS_ERROR_MESSAGE})}))),r}return c(t,e),E(t)}(tr);cr.THREAD_RESOURCE="threads",cr.NEW_ASSISTANT_RESOURCE="assistants";var ur=cr,dr=function(e){function t(e){var n,r,i;return x(this,t),s(this,t,[e,"https://api.cohere.ai/v1/summarize","Insert text to summarize",null==(r=null==(n=e.directConnection)?void 0:n.cohere)?void 0:r.summarization,null==(i=e.directConnection)?void 0:i.cohere])}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n=JSON.parse(JSON.stringify(e)),r=t[t.length-1].text;if(r)return b({text:r},n)}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),dn.request(this,r,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.message){e.next=2;break}throw t.message;case 2:return e.abrupt("return",{text:t.summary||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n,r}(sr),hr=function(e){function t(e){var n,r,i,a,o,l;x(this,t);var c=JSON.parse(JSON.stringify(e.directConnection)),u=null==c?void 0:c.openAI;(i=s(this,t,[e,Xn.buildKeyVerificationDetails(),Xn.buildHeaders,u])).insertKeyPlaceholderText="OpenAI API Key",i.keyHelpUrl="https://platform.openai.com/account/api-keys",i.url="https://api.openai.com/v1/audio/speech",i.permittedErrorPrefixes=["Invalid"],i.introPanelMarkUp='\n OpenAI : Text To Speech
\n Generate an audio file based on your text input.
\n Click here for more information.
';var d=null==(a=null==c?void 0:c.openAI)?void 0:a.textToSpeech;return"object"==_(d)&&Object.assign(i.rawBody,d),null!==(n=(o=i.rawBody).model)&&void 0!==n||(o.model=t.DEFAULT_MODEL),null!==(r=(l=i.rawBody).voice)&&void 0!==r||(l.voice=t.DEFAULT_VOIDE),i.textInputPlaceholderText="Insert text to generate audio",i.rawBody.response_format="mp3",i}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n,r,i=JSON.parse(JSON.stringify(e)),s=null==(r=null==(n=t[t.length-1])?void 0:n.text)?void 0:r.trim();return s&&""!==s&&(i.input=s),i}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n){var r,i;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(r=this.connectSettings)&&r.headers){e.next=2;break}throw new Error("Request settings have not been set up");case 2:this.url=this.connectSettings.url||this.url,i=this.preprocessBody(this.rawBody,n),dn.request(this,i,t);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(t instanceof Blob)){e.next=2;break}return e.abrupt("return",new Promise((function(e){var n=new FileReader;n.readAsDataURL(t),n.onload=function(t){e({files:[{src:t.target.result,type:"audio"}]})}})));case 2:if(!t.error){e.next=4;break}throw t.error.message;case 4:return e.abrupt("return",{error:"error"});case 5:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n,r}(gn);hr.DEFAULT_MODEL="tts-1",hr.DEFAULT_VOIDE="alloy";var pr=hr,fr=function(e){function t(e){var n,r,i,a;x(this,t);var o=JSON.parse(JSON.stringify(e.directConnection)),l=null==o?void 0:o.openAI;(r=s(this,t,[e,Xn.buildKeyVerificationDetails(),Xn.buildHeaders,l,{audio:{}}])).insertKeyPlaceholderText="OpenAI API Key",r.keyHelpUrl="https://platform.openai.com/account/api-keys",r.introPanelMarkUp='\n OpenAI : Speech To Text
\n Upload an audio file to transcribe it into text. You can optionally provide text to guide the audio\n processing.\n
Click here for more info.
',r.url="",r.permittedErrorPrefixes=["Invalid"],r.textInputPlaceholderText="Upload an audio file",r._service_url=t.AUDIO_TRANSCRIPTIONS_URL;var c=null==(i=null==o?void 0:o.openAI)?void 0:i.audio;return"object"==_(c)&&(r.processConfig(c),t.cleanConfig(c),Object.assign(r.rawBody,c)),null!==(n=(a=r.rawBody).model)&&void 0!==n||(a.model=t.DEFAULT_MODEL),r.rawBody.response_format="json",r.canSendMessage=t.canSendFileMessage,r}return c(t,e),E(t,[{key:"processConfig",value:function(e){null!=e&&e.type&&"translation"===e.type&&(this._service_url=t.AUDIO_TRANSLATIONS_URL,delete e.language)}},{key:"preprocessBody",value:function(e,t){var n,r,i=JSON.parse(JSON.stringify(e)),s=null==(r=null==(n=t[t.length-1])?void 0:n.text)?void 0:r.trim();return s&&""!==s&&(i.prompt=s),i}},{key:"callServiceAPI",value:(r=f(h().mark((function e(n,r,i){var s,a,o;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(s=this.connectSettings)&&s.headers){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(null!=i&&i[0]){e.next=4;break}throw new Error("No file was added");case 4:this.url=this.connectSettings.url||this._service_url,a=this.preprocessBody(this.rawBody,r),o=t.createFormDataBody(a,i[0]),Zt.tempRemoveContentHeader(this.connectSettings,dn.request.bind(this,this,o,n),!1);case 7:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error.message;case 2:return e.abrupt("return",{text:t.text});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}],[{key:"canSendFileMessage",value:function(e,t){return!(null==t||!t[0])}},{key:"cleanConfig",value:function(e){delete e.type}},{key:"createFormDataBody",value:function(e,t){var n=new FormData;return n.append("file",t),Object.keys(e).forEach((function(t){n.append(t,String(e[t]))})),n}}]);var n,r}(gn);fr.AUDIO_TRANSCRIPTIONS_URL="https://api.openai.com/v1/audio/transcriptions",fr.AUDIO_TRANSLATIONS_URL="https://api.openai.com/v1/audio/translations",fr.DEFAULT_MODEL="whisper-1";var mr=fr,vr=function(){function e(){x(this,e)}return E(e,null,[{key:"buildTextToSpeechHeaders",value:function(e,t){return{"Ocp-Apim-Subscription-Key":t,"Content-Type":"application/ssml+xml","X-Microsoft-OutputFormat":e}}},{key:"buildSpeechToTextHeaders",value:function(e){return{"Ocp-Apim-Subscription-Key":e,Accept:"application/json"}}},{key:"handleSpeechVerificationResult",value:function(e,t,n,r){e.error?r(G.INVALID_KEY):n(t)}},{key:"buildSpeechKeyVerificationDetails",value:function(t){return{url:"https://".concat(t,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:"POST",createHeaders:function(e){return{"Ocp-Apim-Subscription-Key":"".concat(e)}},handleVerificationResult:e.handleSpeechVerificationResult}}},{key:"buildSummarizationHeader",value:function(e){return{"Ocp-Apim-Subscription-Key":e,"Content-Type":"application/json"}}},{key:"handleLanguageVerificationResult",value:function(e,t,n,r){var i;"401"===(null==(i=e.error)?void 0:i.code)?r(G.INVALID_KEY):n(t)}},{key:"buildLanguageKeyVerificationDetails",value:function(t){return{url:"".concat(t,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:"POST",createHeaders:function(e){return{"Ocp-Apim-Subscription-Key":"".concat(e)}},handleVerificationResult:e.handleLanguageVerificationResult}}},{key:"handleTranslationVerificationResult",value:function(e,t,n,r){e.json().then((function(e){Array.isArray(e)||401e3!==e.error.code?n(t):r(G.INVALID_KEY)}))}},{key:"buildTranslationKeyVerificationDetails",value:function(t){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:"POST",createHeaders:function(n){return e.buildTranslationHeaders(t,n)},handleVerificationResult:e.handleTranslationVerificationResult}}},{key:"buildTranslationHeaders",value:function(e,t){var n={"Ocp-Apim-Subscription-Key":t,"Content-Type":"application/json"};return e&&(n["Ocp-Apim-Subscription-Region"]=e),n}}])}(),gr=function(e){function t(e){var n,r,i,a,o,l;x(this,t);var c=null==(a=null==(i=e.directConnection)?void 0:i.azure)?void 0:a.summarization,u=null==(o=e.directConnection)?void 0:o.azure;return(r=s(this,t,[e,vr.buildSummarizationHeader,c.endpoint,u])).permittedErrorPrefixes=[t.ENDPOINT_ERROR_MESSAGE],r.url="",r.textInputPlaceholderText="Insert text to summarize",r.isTextInputDisabled=!1,c.endpoint?(null!==(n=(l=r.rawBody).language)&&void 0!==n||(l.language="en"),Object.assign(r.rawBody,c),r.url="".concat(c.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(r.isTextInputDisabled=!0,r.canSendMessage=function(){return!1},setTimeout((function(){e.addMessage({error:t.ENDPOINT_ERROR_MESSAGE})}))),r}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n=t[t.length-1].text;if(n)return{analysisInput:{documents:[{id:"1",language:e.language,text:n}]},tasks:[{kind:"ExtractiveSummarization"}]}}},{key:"callServiceAPI",value:(a=f(h().mark((function e(t,n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),dn.request(this,r,t),this.messages=t;case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"extractResultData",value:(i=f(h().mark((function e(t){var n,r,i;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error.message;case 2:return this.messages&&this.completionsHandlers&&(r=t.headers.get("operation-location"),i={method:"GET",headers:null==(n=this.connectSettings)?void 0:n.headers},dn.executePollRequest(this,r,i,this.messages)),e.abrupt("return",{makingAnotherRequest:!0});case 4:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"extractPollResultData",value:(n=f(h().mark((function e(t){var n,i,s,a;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:if("running"!==t.status){e.next=4;break}return e.abrupt("return",{timeoutMS:2e3});case 4:if(!(t.errors.length>0)){e.next=6;break}throw t.errors[0];case 6:if(!(t.tasks.items[0].results.errors.length>0)){e.next=8;break}throw t.tasks.items[0].results.errors[0];case 8:n="",i=r(t.tasks.items[0].results.documents[0].sentences);try{for(i.s();!(s=i.n()).done;)a=s.value,n+=a.text}catch(o){i.e(o)}finally{i.f()}return e.abrupt("return",{text:n||""});case 12:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n,i,a}(function(e){function t(e,n,r,i,a){var o;return x(this,t),(o=s(this,t,[e,vr.buildLanguageKeyVerificationDetails(r),n,i,a])).insertKeyPlaceholderText="Azure Language Subscription Key",o.keyHelpUrl="https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",o.permittedErrorPrefixes=["Access"],o}return c(t,e),E(t)}(gn));gr.ENDPOINT_ERROR_MESSAGE="Please define the azure endpoint. [More Information](https://deepchat.dev/docs/directConnection/Azure#Summarization)";var yr=gr,br=function(){function e(){x(this,e)}return E(e,null,[{key:"poll",value:(t=f(h().mark((function e(t,n){var r,i,s,a;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={authorization:t,"content-type":"application/json"},e.t0="https://api.assemblyai.com/v2/transcript/",e.next=4,fetch("https://api.assemblyai.com/v2/transcript",{method:"POST",body:JSON.stringify({audio_url:n}),headers:r});case 4:return e.next=6,e.sent.json();case 6:e.t1=e.sent.id,i=e.t0.concat.call(e.t0,e.t1);case 8:if(s){e.next=24;break}return e.next=11,fetch(i,{headers:r});case 11:return e.next=13,e.sent.json();case 13:if("completed"!==(a=e.sent).status){e.next=18;break}s=a,e.next=22;break;case 18:if("error"!==a.status){e.next=20;break}throw new Error("Transcription failed: ".concat(a.error));case 20:return e.next=22,new Promise((function(e){return setTimeout(e,3e3)}));case 22:e.next=8;break;case 24:return e.abrupt("return",s);case 25:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"buildHeaders",value:function(e){return{Authorization:e,"Content-Type":"application/octet-stream"}}},{key:"handleVerificationResult",value:function(e,t,n,r){var i=e;i.error?"invalid_api_key"===i.error.code?r(G.INVALID_KEY):r(G.CONNECTION_FAILED):n(t)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.assemblyai.com/v2/upload",method:"POST",handleVerificationResult:e.handleVerificationResult}}}]);var t}(),kr=function(e){function t(e){var n,r;x(this,t);var i=null==(r=e.directConnection)?void 0:r.assemblyAI;return(n=s(this,t,[e,br.buildKeyVerificationDetails(),br.buildHeaders,i,{audio:{}}])).insertKeyPlaceholderText="AssemblyAI API Key",n.keyHelpUrl="https://www.assemblyai.com/app/account",n.introPanelMarkUp='\n AssemblyAI Audio
\n Upload an audio file to transcribe it into text.\n
\n Click here for more info.\n
',n.url="https://api.assemblyai.com/v2/upload",n.isTextInputDisabled=!0,n.textInputPlaceholderText="Upload an audio file",n.permittedErrorPrefixes=["Authentication","Invalid"],n.canSendMessage=t.canFileSendMessage,n}return c(t,e),E(t,[{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n,r){var i;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(i=this.connectSettings)&&i.headers){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(null!=r&&r[0]){e.next=4;break}throw new Error("No file was added");case 4:dn.request(this,r[0],t,!1);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){var n,r,i;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:return i=null==(r=null==(n=this.connectSettings)?void 0:n.headers)?void 0:r.Authorization,e.next=5,br.poll(i,t.upload_url);case 5:return e.t0=e.sent.text,e.abrupt("return",{text:e.t0});case 7:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}],[{key:"canFileSendMessage",value:function(e,t){return!(null==t||!t[0])}}]);var n,r}(gn),_r=function(e){function t(e,n,r,i,a){var o;return x(this,t),(o=s(this,t,[e,vr.buildSpeechKeyVerificationDetails(r),n,i,a])).insertKeyPlaceholderText="Azure Speech Subscription Key",o.keyHelpUrl="https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",o}return c(t,e),E(t)}(gn),xr=function(e){function t(e){var n,r,i,a,o,l,c,u,d,h;x(this,t);var p=null==(l=null==(o=e.directConnection)?void 0:o.azure)?void 0:l.textToSpeech,f=null==(c=e.directConnection)?void 0:c.azure;return(a=s(this,t,[e,vr.buildTextToSpeechHeaders.bind({},(null==p?void 0:p.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),p.region,f])).permittedErrorPrefixes=[t.REGION_ERROR_MESSAGE],a.introPanelMarkUp='\n Azure Text To Speech
\n Insert text to synthesize it to audio.\n
\n Click here for more info.\n
'),a.isTextInputDisabled=!1,a.url="",p.region?(Object.assign(a.rawBody,p),null!==(n=(u=a.rawBody).lang)&&void 0!==n||(u.lang="en-US"),null!==(r=(d=a.rawBody).name)&&void 0!==r||(d.name="en-US-JennyNeural"),null!==(i=(h=a.rawBody).gender)&&void 0!==i||(h.gender="Female"),a.url="https://".concat(p.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(a.isTextInputDisabled=!0,a.canSendMessage=function(){return!1},setTimeout((function(){e.addMessage({error:t.REGION_ERROR_MESSAGE})}))),a}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n=t[t.length-1].text;if(n)return"\n \n ").concat(n,"\n \n ")}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),dn.request(this,r,t,!1);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){var n=new FileReader;n.readAsDataURL(t),n.onload=function(t){e({files:[{src:t.target.result,type:"audio"}]})}})));case 1:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n,r}(_r);xr.HELP_LINK="https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",xr.REGION_ERROR_MESSAGE="Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#TextToSpeech)";var Sr=xr,Er=function(e){function t(e){var n,r,i,a;x(this,t);var o=null==(i=null==(r=e.directConnection)?void 0:r.azure)?void 0:i.speechToText,l=null==(a=e.directConnection)?void 0:a.azure;if((n=s(this,t,[e,vr.buildSpeechToTextHeaders,o.region,l,{audio:{files:{acceptedFormats:".wav,.ogg"}}}])).permittedErrorPrefixes=[t.REGION_ERROR_MESSAGE],n.introPanelMarkUp='\n Azure Speech To Text
\n Upload a .wav or .ogg audio file to transcribe it into text.\n
\n Click here for more info.\n
'),n.url="",n.isTextInputDisabled=!0,n.textInputPlaceholderText="Upload an audio file",o.region){n.canSendMessage=t.canFileSendMessage;var c=o.lang||"en-US";n.url="https://".concat(o.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(c,"&format=detailed"),n.recordAudio=void 0}else n.isTextInputDisabled=!0,n.canSendMessage=function(){return!1},setTimeout((function(){e.addMessage({error:t.REGION_ERROR_MESSAGE})}));return n}return c(t,e),E(t,[{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n,r){var i,s;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(i=this.connectSettings)&&i.headers){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(null!=r&&r[0]){e.next=4;break}throw new Error("No file was added");case 4:null!=(s=this.connectSettings)&&s.headers&&(this.connectSettings.headers["Content-Type"]=r[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),dn.request(this,r[0],t,!1);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:return e.abrupt("return",{text:t.DisplayText||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}],[{key:"canFileSendMessage",value:function(e,t){return!(null==t||!t[0])}}]);var n,r}(_r);Er.HELP_LINK="https://learn.microsoft.com/en-GB/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-rest",Er.REGION_ERROR_MESSAGE="Please define a region config property. [More Information](https://deepchat.dev/docs/directConnection/Azure#SpeechToText)";var wr=Er,Cr=function(e){function t(e){var n,r,i,a;x(this,t);var o=null==(i=null==(r=e.directConnection)?void 0:r.azure)?void 0:i.translation,l=null==(a=e.directConnection)?void 0:a.azure;return(n=s(this,t,[e,vr.buildTranslationKeyVerificationDetails(o.region),vr.buildTranslationHeaders.bind({},null==o?void 0:o.region),l])).insertKeyPlaceholderText="Azure Translate Subscription Key",n.keyHelpUrl="https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",n.url="",n.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(o.language||"es"),n}return c(t,e),E(t,[{key:"preprocessBody",value:function(e){var t=e[e.length-1].text;if(t)return[{Text:t}]}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(n),dn.request(this,r,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Array.isArray(t)){e.next=2;break}return e.abrupt("return",{text:(null==(n=t[0].translations)?void 0:n[0].text)||""});case 2:throw t.error;case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n,r}(gn),Tr=function(e){function t(e,n,r,i,a){var o,l,c,u,d,h,p;x(this,t);var f=JSON.parse(JSON.stringify(e.directConnection));(c=s(this,t,[e,n||Xn.buildKeyVerificationDetails(),r||Xn.buildHeaders,i||f.openAI])).insertKeyPlaceholderText="OpenAI API Key",c.keyHelpUrl="https://platform.openai.com/account/api-keys",c.url="https://api.openai.com/v1/chat/completions",c.permittedErrorPrefixes=["Incorrect"],c.asyncCallInProgress=!1,c._systemMessage=t.generateSystemMessage("You are a helpful assistant.");var m=a||(null==(u=f.openAI)?void 0:u.chat);if("object"==_(m)){m.system_prompt&&(c._systemMessage=t.generateSystemMessage(m.system_prompt));var v=(null==(h=null==(d=e.directConnection)?void 0:d.openAI)?void 0:h.chat).function_handler;v&&(c._functionHandler=v),c.cleanConfig(m),Object.assign(c.rawBody,m)}return null!==(o=c.maxMessages)&&void 0!==o||(c.maxMessages=-1),null!==(l=(p=c.rawBody).model)&&void 0!==l||(p.model="gpt-4o"),c}return c(t,e),E(t,[{key:"cleanConfig",value:function(e){delete e.system_prompt,delete e.function_handler}},{key:"preprocessBody",value:function(e,n){var r,i=JSON.parse(JSON.stringify(e)),s=fn.getCharacterLimitMessages(n,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.content.length:-1).map((function(e){return{content:t.getContent(e),role:e.role===Wt.USER_ROLE?"user":"assistant"}}));return n.find((function(e){return e.files&&e.files.length>0}))&&(null!==(r=i.max_tokens)&&void 0!==r||(i.max_tokens=300)),i.messages=[this._systemMessage].concat(m(s)),i}},{key:"callServiceAPI",value:(a=f(h().mark((function e(t,n){var r,i;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),(i=this.stream)&&("object"!=_(i)||!i.simulation)||r.stream?(r.stream=!0,an.request(this,r,t)):dn.request(this,r,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"extractResultData",value:(i=f(h().mark((function e(t,n,r){var i,s,a,o;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error.message;case 2:return e.abrupt("return",null!=(s=null==(i=t.choices)?void 0:i[0])&&s.delta?this.extractStreamResult(t.choices[0],n,r):null!=(o=null==(a=t.choices)?void 0:a[0])&&o.message?t.choices[0].message.tool_calls?this.handleTools(t.choices[0].message,n,r):{text:t.choices[0].message.content}:{text:""});case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return i.apply(this,arguments)})},{key:"extractStreamResult",value:(r=f(h().mark((function e(t,n,r){var i,s,a=this;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=t.delta,"tool_calls"!==t.finish_reason){e.next=7;break}return this.asyncCallInProgress=!0,s={tool_calls:this._streamToolCalls},e.abrupt("return",(this._streamToolCalls=void 0,this.handleTools(s,n,r)));case 7:null!=i&&i.tool_calls&&(this._streamToolCalls?i.tool_calls.forEach((function(e,t){a._streamToolCalls&&(a._streamToolCalls[t].function.arguments+=e.function.arguments)})):this._streamToolCalls=i.tool_calls);case 8:return e.abrupt("return",{text:(null==i?void 0:i.content)||""});case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"handleTools",value:(n=f(h().mark((function e(t,n,r){var i,s,a,o,l,c,u,d,p,f,m;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.tool_calls&&n&&r&&this._functionHandler){e.next=2;break}throw Error("Please define the `function_handler` property inside the [openAI](https://deepchat.dev/docs/directConnection/openAI#Chat) object.");case 2:return c=JSON.parse(JSON.stringify(r)),u=t.tool_calls.map((function(e){return{name:e.function.name,arguments:e.function.arguments}})),e.next=6,null==(i=this._functionHandler)?void 0:i.call(this,u);case 6:if(d=e.sent,Array.isArray(d)){e.next=17;break}if(!d.text){e.next=16;break}return p={text:d.text},e.next=12,null==(a=(s=this.deepChat).responseInterceptor)?void 0:a.call(s,p);case 12:if(e.t0=e.sent,e.t0){e.next=15;break}e.t0=p;case 15:return e.abrupt("return",e.t0);case 16:throw Error(Xn.FUNCTION_TOOL_RESP_ERROR);case 17:return e.next=19,Promise.all(d);case 19:if(f=e.sent,c.messages.push({tool_calls:t.tool_calls,role:"assistant",content:null}),f.find((function(e){return"string"!=typeof e}))||u.length!==f.length){e.next=40;break}return f.forEach((function(e,n){var r,i=null==(r=t.tool_calls)?void 0:r[n];null==c||c.messages.push({role:"tool",tool_call_id:null==i?void 0:i.id,name:null==i?void 0:i.function.name,content:e.response})})),delete c.tools,delete c.tool_choice,delete c.stream,e.prev=22,e.next=25,null==n?void 0:n(c).then((function(e){return Zt.processResponseByType(e)}));case 25:return m=e.sent,e.next=28,null==(l=(o=this.deepChat).responseInterceptor)?void 0:l.call(o,m);case 28:if(e.t1=e.sent,e.t1){e.next=31;break}e.t1=m;case 31:if(!(m=e.t1).error){e.next=34;break}throw m.error.message;case 34:return e.abrupt("return",{text:m.choices[0].message.content||""});case 37:throw e.prev=37,e.t2=e.catch(22),this.asyncCallInProgress=!1,e.t2;case 40:throw Error(Xn.FUNCTION_TOOL_RESP_ERROR);case 41:case"end":return e.stop()}}),e,this,[[22,37]])}))),function(e,t,r){return n.apply(this,arguments)})}],[{key:"generateSystemMessage",value:function(e){return{role:"system",content:e}}},{key:"getContent",value:function(e){if(e.files&&e.files.length>0){var t=e.files.map((function(e){return{type:"image_url",image_url:{url:e.src}}}));return e.text&&e.text.trim().length>0&&t.unshift({type:"text",text:e.text}),t}return e.text}}]);var n,r,i,a}(gn),Ar=function(e){function t(e){var n,r,i,a,o,l,c,u;x(this,t);var d=JSON.parse(JSON.stringify(e.directConnection)),h=d.azure,p=(null==(i=null==(r=d.azure)?void 0:r.openAI)?void 0:i.urlDetails)||{},f=null==(o=null==(a=d.azure)?void 0:a.openAI)?void 0:o.chat;if((n=s(this,t,[e,lr.buildKeyVerificationDetails(p),lr.buildHeaders,h,f])).permittedErrorPrefixes=[lr.URL_DETAILS_ERROR_MESSAGE],n.isTextInputDisabled=!1,"object"==_(f)){var m=(null==(u=null==(c=null==(l=e.directConnection)?void 0:l.azure)?void 0:c.openAI)?void 0:u.chat).function_handler;m&&(n._functionHandler=m)}return lr.validateURLDetails(p)?n.url=t.buildURL(p):(n.isTextInputDisabled=!0,n.canSendMessage=function(){return!1},setTimeout((function(){e.addMessage({error:lr.URL_DETAILS_ERROR_MESSAGE})}))),n}return c(t,e),E(t,null,[{key:"buildURL",value:function(e){var t=e.endpoint,n=e.deploymentId,r=e.version;return"".concat(t,"/openai/deployments/").concat(n,"/completions?api-version=").concat(r)}}])}(Tr),Mr=function(e){function t(e){var n,r;x(this,t);var i=e.directConnection,a=null==i?void 0:i.openAI;(n=s(this,t,[e,Xn.buildKeyVerificationDetails(),Xn.buildHeaders,a,{images:{files:{acceptedFormats:".png",maxNumberOfFiles:2}}}])).insertKeyPlaceholderText="OpenAI API Key",n.keyHelpUrl="https://platform.openai.com/account/api-keys",n.introPanelMarkUp='\n OpenAI DALL\xb7E
\n Insert text to generate an image.
\n Upload 1 PNG image to generate its variation and optionally insert text to specify the change.
\n Upload 2 PNG images where the second is a copy of the first with a transparent area where the edit should\n take place and text to specify the edit.
\n Click here for more info.
',n.url="",n.permittedErrorPrefixes=["Incorrect","Invalid input image"];var o=null==(r=null==i?void 0:i.openAI)?void 0:r.images;if(n.camera){var l="object"==_(o)&&o.size?Number.parseInt(o.size):1024;n.camera.files={dimensions:{width:l,height:l}}}return"object"==_(o)&&Object.assign(n.rawBody,o),n.canSendMessage=t.canFileSendMessage,n}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n=JSON.parse(JSON.stringify(e));return t&&""!==t&&(n.prompt=t),n}},{key:"callApiWithImage",value:function(e,n,r){var i,s,a,o=null==(s=null==(i=n[n.length-1])?void 0:i.text)?void 0:s.trim();if(r[1]||o&&""!==o){this.url=t.IMAGE_EDIT_URL;var l=this.preprocessBody(this.rawBody,o);a=t.createFormDataBody(l,r[0],r[1])}else this.url=t.IMAGE_VARIATIONS_URL,a=t.createFormDataBody(this.rawBody,r[0]);Zt.tempRemoveContentHeader(this.connectSettings,dn.request.bind(this,this,a,e),!1)}},{key:"callServiceAPI",value:(r=f(h().mark((function e(n,r,i){var s,a;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(s=this.connectSettings)&&s.headers){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(null==i||!i[0]){e.next=6;break}this.callApiWithImage(n,r,i),e.next=11;break;case 6:if(this.connectSettings){e.next=8;break}throw new Error("Request settings have not been set up");case 8:this.url=t.IMAGE_GENERATION_URL,a=this.preprocessBody(this.rawBody,r[r.length-1].text),dn.request(this,a,n);case 11:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error.message;case 2:return e.abrupt("return",{files:t.data.map((function(e){return e.url?{src:e.url,type:"image"}:{src:"".concat(Bn).concat(e.b64_json),type:"image"}}))});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}],[{key:"canFileSendMessage",value:function(e,t){return!(null==t||!t[0])||!(!e||""===e.trim())}},{key:"createFormDataBody",value:function(e,t,n){var r=new FormData;return r.append("image",t),n&&r.append("mask",n),Object.keys(e).forEach((function(t){r.append(t,String(e[t]))})),r}}]);var n,r}(gn);Mr.IMAGE_GENERATION_URL="https://api.openai.com/v1/images/generations",Mr.IMAGE_VARIATIONS_URL="https://api.openai.com/v1/images/variations",Mr.IMAGE_EDIT_URL="https://api.openai.com/v1/images/edits";var Ir=Mr,Lr=function(e){function t(e){var n,r,i;x(this,t);var a=JSON.parse(JSON.stringify(e.directConnection)),o=null==(i=a.cohere)?void 0:i.chat;return r=s(this,t,[e,"https://api.cohere.ai/v1/chat","Ask me anything!",o,a.cohere]),"object"==_(o)&&Object.assign(r.rawBody,o),null!==(n=r.maxMessages)&&void 0!==n||(r.maxMessages=-1),r}return c(t,e),E(t,[{key:"preprocessBody",value:function(e,t){var n=JSON.parse(JSON.stringify(e)),r=t.filter((function(e){return e.text}));return n.query=r[r.length-1].text,n.chat_history=r.slice(0,r.length-1).map((function(e){return{text:e.text,user_name:"ai"===e.role?"CHATBOT":"USER"}})),n}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),dn.request(this,r,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.message){e.next=2;break}throw t.message;case 2:return e.abrupt("return",{text:t.text});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n,r}(sr),Rr=function(){function e(){x(this,e)}return E(e,null,[{key:"buildHeaders",value:function(e){return{Authorization:"Bearer ".concat(e),"Content-Type":"application/json",accept:"application/json"}}},{key:"handleVerificationResult",value:function(e,t,n,r){var i;null!=(i=e.message)&&i.includes("invalid request: prompt must be at least 1 token long")?n(t):r(G.INVALID_KEY)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.mistral.ai/v1/models",method:"GET",handleVerificationResult:e.handleVerificationResult}}}])}(),Or=function(e){function t(e){var n,r,i,a;x(this,t);var o=JSON.parse(JSON.stringify(e.directConnection)).mistral;return(i=s(this,t,[e,Rr.buildKeyVerificationDetails(),Rr.buildHeaders,o])).insertKeyPlaceholderText="Mistral API Key",i.keyHelpUrl="https://console.mistral.ai/api-keys/",i.url="https://api.mistral.ai/v1/chat/completions",i.permittedErrorPrefixes=["invalid"],o&&(i.cleanConfig(o),Object.assign(i.rawBody,o)),null!==(n=i.maxMessages)&&void 0!==n||(i.maxMessages=-1),null!==(r=(a=i.rawBody).model)&&void 0!==r||(a.model="open-mistral-7b"),i}return c(t,e),E(t,[{key:"cleanConfig",value:function(e){delete e.key}},{key:"preprocessBody",value:function(e,t){var n=JSON.parse(JSON.stringify(e)),r=t.filter((function(e){return e.text}));return n.messages=r.slice(0,r.length-1).map((function(e){return{text:e.text,user_name:"ai"===e.role?"system":"user"}})),n}},{key:"callServiceAPI",value:(r=f(h().mark((function e(t,n){var r;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.connectSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),dn.request(this,r,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=f(h().mark((function e(t){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.message){e.next=2;break}throw t.message;case 2:return e.abrupt("return",{text:t.text});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]);var n,r}(gn),Pr=function(){return E((function e(){x(this,e)}),null,[{key:"create",value:function(e){var t=e.directConnection,n=e.connect,r=e.demo;if(e.webModel)return new Mn(e);if(t){if(t.openAI)return t.openAI.images?new Ir(e):t.openAI.speechToText?new mr(e):t.openAI.textToSpeech?new pr(e):t.openAI.assistant?new rr(e):new Tr(e);if(t.assemblyAI)return new kr(e);if(t.cohere)return t.cohere.textGeneration?new ar(e):t.cohere.summarization?new dr(e):new Lr(e);if(t.huggingFace)return t.huggingFace.textGeneration?new qn(e):t.huggingFace.summarization?new Vn(e):t.huggingFace.translation?new Kn(e):t.huggingFace.fillMask?new Yn(e):t.huggingFace.questionAnswer?new zn(e):t.huggingFace.audioSpeechRecognition?new Hn(e):t.huggingFace.audioClassification?new Pn(e):t.huggingFace.imageClassification?new Nn(e):new Gn(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new Ar(e);if(t.azure.openAI.assistant)return new ur(e)}if(t.azure.speechToText)return new wr(e);if(t.azure.textToSpeech)return new Sr(e);if(t.azure.summarization)return new yr(e);if(t.azure.translation)return new Cr(e)}if(t.stabilityAI)return t.stabilityAI.imageToImage?new Wn(e):t.stabilityAI.imageToImageUpscale?new jn(e):t.stabilityAI.imageToImageMasking?new Un(e):new Jn(e);if(t.mistral)return new Or(e)}return!n||r&&n.stream?new vn(e,void 0,r||!0):new vn(e)}}])}(),Nr=E((function e(){x(this,e)}));Nr.attibutes={string:function(e){return e},number:function(e){return parseFloat(e)},boolean:function(e){return"true"===e},object:function(e){return JSON.parse(e)},array:function(e){return JSON.parse(e)},function:function(e){return new Function("return ".concat(e))()}};var Br=Nr;function Dr(e){return function(t,n){Object.defineProperty(t,n,{});var r=t.constructor,i=n.toLocaleLowerCase();r._attributes_[i]=Br.attibutes[e],r._attributeToProperty_[i]=n}}var Fr=function(){function e(t,n,r){x(this,e),this._isDisplayed=!1,t?(this._elementRef=this.createIntroPanelWithChild(t,r),this._isDisplayed=!0):n&&(this._elementRef=this.createInternalIntroPanel(n,r),this._isDisplayed=!0)}return E(e,[{key:"createIntroPanelWithChild",value:function(t,n){var r=e.createIntroPanel(n);return"none"===t.style.display&&(t.style.display="block"),r.appendChild(t),r}},{key:"createInternalIntroPanel",value:function(t,n){var r=e.createIntroPanel(n);return r.id="internal-intro-panel",r.innerHTML=t,r}},{key:"hide",value:function(){this._isDisplayed&&this._elementRef&&(this._elementRef.style.display="none",this._isDisplayed=!1)}},{key:"display",value:function(){!this._isDisplayed&&this._elementRef&&(this._elementRef.style.display="",this._isDisplayed=!0)}}],[{key:"createIntroPanel",value:function(e){var t=document.createElement("div");return t.classList.add("intro-panel"),Object.assign(t.style,e),t}}])}(),jr=function(){function e(){x(this,e)}return E(e,null,[{key:"createImage",value:function(e,t,n){var r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=new Image;return i.src=e.src,!n&&r&&$.scrollDownOnImageLoad(i.src,t),$.processContent("image",i,i.src,e.name)}},{key:"createImageMessage",value:function(t,n,r,i){var s=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=e.createImage(n,t.elementRef,i,s),o=t.createNewMessageElement("",r);return o.bubbleElement.appendChild(a),o.bubbleElement.classList.add(e.IMAGE_BUBBLE_CLASS),{type:"image",elements:o}}},{key:"createAudioElement",value:function(e,t){var n=document.createElement("audio");return n.src=e.src,n.classList.add("audio-player"),n.controls=!0,P.IS_SAFARI&&(n.classList.add("audio-player-safari"),n.classList.add(t===Wt.USER_ROLE?"audio-player-safari-right":"audio-player-safari-left")),n}},{key:"createNewAudioMessage",value:function(t,n,r,i){var s=e.createAudioElement(n,r),a=t.createMessageElementsOnOrientation("",r,i);return a.bubbleElement.appendChild(s),a.bubbleElement.classList.add(e.AUDIO_BUBBLE_CLASS),{type:"audio",elements:a}}},{key:"createAnyFile",value:function(e){var t=document.createElement("div");t.classList.add("any-file-message-contents");var n=document.createElement("div");n.classList.add("any-file-message-icon-container");var r=_n.createSVGElement('\n\n\n\t\n\t\t \n\t \n \n\n\t\n\t\t \n\t \n \n\n\t\n\t\t \n\t \n \n\n\t\n\t\t \n\t \n \n\n\t\n\t\t \n\t \n \n ');r.classList.add("any-file-message-icon"),n.appendChild(r);var i=document.createElement("div");return i.classList.add("any-file-message-text"),i.textContent=e.name||$.DEFAULT_FILE_NAME,t.appendChild(n),t.appendChild(i),$.processContent("any",t,e.src,i.textContent)}},{key:"createNewAnyFileMessage",value:function(t,n,r,i){var s=t.createMessageElementsOnOrientation("",r,i),a=e.createAnyFile(n);return s.bubbleElement.classList.add(e.ANY_FILE_BUBBLE_CLASS),s.bubbleElement.appendChild(a),{type:"file",elements:s}}},{key:"createMessages",value:function(t,n,r){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],s=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];return n.map((function(n){return n.ref&&(n=$.removeFileRef(n)),$.isAudioFile(n)?e.createNewAudioMessage(t,n,r,i):$.isImageFile(n)?e.createImageMessage(t,n,r,i,s):e.createNewAnyFileMessage(t,n,r,i)}))}},{key:"addMessages",value:function(t,n,r,i){e.createMessages(t,n,r,i).forEach((function(e){var n=e.type,s=e.elements;$.addMessage(t,s,n,r,i)}))}}])}();jr.IMAGE_BUBBLE_CLASS="image-message",jr.AUDIO_BUBBLE_CLASS="audio-message",jr.ANY_FILE_BUBBLE_CLASS="any-file-message";var Ur=jr,Hr=function(){function e(){x(this,e)}return E(e,null,[{key:"removeElements",value:function(e,t){if(t){var n=e.findIndex((function(e){return e===t}));e.splice(n,1),null==t||t.outerContainer.remove()}}},{key:"removeFilesMessages",value:function(t,n){var r;null==(r=n[1].files)||r.forEach((function(n){e.removeElements(t.messageElementRefs,n)})),delete n[0].files,delete n[1].files}},{key:"removeTextHTMLMessage",value:function(t,n,r){var i=n[1][r];e.removeElements(t.messageElementRefs,i),delete n[0][r],delete n[1][r]}},{key:"updateHTMLMessage",value:function(e,t,n){var r,i;if(t[1].html)le.overwriteElements(e,n,t[1].html);else{var s=le.create(e,n,t[0].role),a=(null==(i=t[1].files)?void 0:i[(null==(r=t[1].files)?void 0:r.length)-1])||t[1].text;e.elementRef.insertBefore(s.outerContainer,a.outerContainer.nextSibling),e.messageElementRefs.splice(e.messageElementRefs.length-1,1);var o=e.messageElementRefs.findIndex((function(e){return e===a}));e.messageElementRefs.splice(o+1,0,s),t[1].html=s}t[0].html=n}},{key:"updateFileMessages",value:function(t,n,r){var i,s,a=n[0].role,o=Ur.createMessages(t,r,a),l=n[1].html,c=(null==(s=n[1].files)?void 0:s[(null==(i=n[1].files)?void 0:i.length)-1])||n[1].text,u=l||c,d=t.messageElementRefs.findIndex((function(e){return e===u}));c&&(d+=1);var h=(null==l?void 0:l.outerContainer)||(null==c?void 0:c.outerContainer.nextSibling);o.forEach((function(e,n){var r=e.type,i=e.elements;$.setElementProps(t,i,r,a),t.elementRef.insertBefore(i.outerContainer,h),t.messageElementRefs.splice(t.messageElementRefs.length-1,1),t.messageElementRefs.splice(d+n,0,i)})),e.removeFilesMessages(t,n),n[1].files=o.map((function(e){return e.elements})),n[0].files=r}},{key:"updateTextMessage",value:function(e,t,n){var r;if(t[1].text)e.renderText(t[1].text.bubbleElement,n);else{var i=e.createElements(n,t[0].role),s=(null==(r=t[1].files)?void 0:r[0])||t[1].html;e.elementRef.insertBefore(i.outerContainer,s.outerContainer);var a=e.messageElementRefs.findIndex((function(e){return e===s}));e.messageElementRefs.splice(a,0,i),t[1].text=i}t[0].text=n}},{key:"isElementActive",value:function(e){var t,n;return zr.isActiveElement(null==(t=e.text)?void 0:t.bubbleElement.classList)||zr.isActiveElement(null==(n=e.html)?void 0:n.bubbleElement.classList)}},{key:"update",value:function(t,n,r){var i=t.messageToElements[r];if(i){if(e.isElementActive(i[1]))return console.error("Cannot update a message that is being streamed");n.text&&e.updateTextMessage(t,i,n.text),n.html&&e.updateHTMLMessage(t,i,n.html),n.files?e.updateFileMessages(t,i,n.files):e.removeFilesMessages(t,i),!n.text&&i[1].text&&e.removeTextHTMLMessage(t,i,"text"),!n.html&&i[1].html&&e.removeTextHTMLMessage(t,i,"html")}else console.error("Message index not found. Please use the `getMessages` method to find the correct index")}}])}(),qr=function(){return E((function e(){x(this,e)}),null,[{key:"getText",value:function(e,t){var n;if(!(e.directConnection||e.connect||e.webModel||e.demo))return"Connect to any API using the [connect](https://deepchat.dev/docs/connect#connect-1) property or a popular service via [directConnection](https://deepchat.dev/docs/directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](https://deepchat.dev/docs/webModel).\n To get started checkout the [Start](https://deepchat.dev/start) page and live code [examples](https://deepchat.dev/examples/frameworks).\n To remove this message set the [demo](https://deepchat.dev/docs/demo#demo) property to true.";if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](https://deepchat.dev/docs/directConnection/#directConnection) object.";var r=null==(n=e.directConnection.openAI)?void 0:n.chat;if("object"==_(r)&&r.tools&&!r.function_handler)return"Please define the `function_handler` property inside the openAI [chat](https://deepchat.dev/docs/directConnection/openAI#Chat) object."}else if(e.connect&&!e.connect.url&&!e.connect.handler)return e.demo?e.connect.stream?null:"When [demo](https://deepchat.dev/docs/demo) mode is enabled - the [connect](https://deepchat.dev/docs/connect#connect-1) object can only accept the [stream](https://deepchat.dev/docs/connect#Stream) property.":"Please define a `url` or a `handler` property inside the [connect](https://deepchat.dev/docs/connect#connect-1) object.";return null}}])}(),zr=function(e){function t(e,n,r){var i,a,o;x(this,t),i=s(this,t,[e]);var l=n.permittedErrorPrefixes,c=n.introPanelMarkUp,u=n.demo;return i._errorMessageOverrides=null==(a=e.errorMessages)?void 0:a.overrides,i._onClearMessages=Bt.onClearMessages.bind(i,e),i._onError=Bt.onError.bind(i,e),i._displayLoadingMessage=t.getDisplayLoadingMessage(e,n),i._permittedErrorPrefixes=l,i.addSetupMessageIfNeeded(e,n)||i.populateIntroPanel(r,c,e.introPanelStyle),i.addIntroductoryMessages(e,n),new pn(e,i,n),i._displayServiceErrorMessages=null==(o=e.errorMessages)?void 0:o.displayServiceErrorMessages,e.getMessages=function(){return JSON.parse(JSON.stringify(i.messageToElements.map((function(e){return d(e,1)[0]}))))},e.clearMessages=i.clearMessages.bind(i,n),e.refreshMessages=i.refreshTextMessages.bind(i,e.remarkable),e.scrollToBottom=K.scrollToBottom.bind(i,i.elementRef),e.addMessage=function(e,t){i.addAnyMessage(b(b({},e),{},{sendUpdate:!!t}),!t)},e.updateMessage=function(e,t){return Hr.update(i,e,t)},n.isWebModel()&&n.setUpMessages(i),u&&i.prepareDemo(ee.processDemo(u)),e.textToSpeech&&Y.processConfig(e.textToSpeech,(function(e){i.textToSpeech=e})),i}return c(t,e),E(t,[{key:"prepareDemo",value:function(e){var t;if("object"==_(e)){if(e.displayLoading){var n=e.displayLoading.history;null!=n&&n.small&&Ft.addMessage(this,!1),null!=n&&n.full&&Ft.addMessage(this)}e.displayErrors&&(e.displayErrors.default&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage("service",""),e.displayErrors.speechToText&&this.addNewErrorMessage("speechToText","")),null!=(t=e.displayLoading)&&t.message&&this.addLoadingMessage(),e.response&&(this.customDemoResponse=e.response)}}},{key:"addSetupMessageIfNeeded",value:function(e,t){var n=qr.getText(e,t);if(n){var r=this.createAndAppendNewMessageElement(n,Wt.AI_ROLE);this.applyCustomStyles(r,Wt.AI_ROLE,!1)}return!!n}},{key:"addIntroductoryMessages",value:function(e,t){var n,r=this;null!=e&&e.shadowRoot&&(this._introMessage=e.introMessage);var i=this._introMessage;null!=t&&t.isWebModel()&&(null!==(n=i)&&void 0!==n||(i=t.getIntroMessage(i))),i&&(Array.isArray(i)?i.forEach((function(e,t){0!==t&&Wt.hideRoleElements(r.messageElementRefs,!!r._avatars,!!r._names),r.addIntroductoryMessage(e)})):this.addIntroductoryMessage(i))}},{key:"addIntroductoryMessage",value:function(e){var t,n;null!=e&&e.text?n=this.createAndAppendNewMessageElement(e.text,Wt.AI_ROLE):null!=e&&e.html&&(n=le.add(this,e.html,Wt.AI_ROLE,this.messageElementRefs)),n&&(this.applyCustomStyles(n,Wt.AI_ROLE,!1,null==(t=this.messageStyles)?void 0:t.intro),n.outerContainer.classList.add(Ut.INTRO_CLASS))}},{key:"removeIntroductoryMessage",value:function(){var e=this.messageElementRefs[0];e.outerContainer.classList.contains(Ut.INTRO_CLASS)&&(e.outerContainer.remove(),this.messageElementRefs.shift())}},{key:"addAnyMessage",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return e.error?this.addNewErrorMessage("service",e.error):this.addNewMessage(e,t,n)}},{key:"addNewMessage",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=t.createMessageContent(e),s={status:e.overwrite};if(!e.ignoreText&&void 0!==i.text&&null!==e.text&&(this.addNewTextMessage(i.text,i.role,s,r),!n&&this.textToSpeech&&i.role!==Wt.USER_ROLE&&Y.speak(i.text,this.textToSpeech)),i.files&&Array.isArray(i.files)&&Ur.addMessages(this,i.files,i.role,r),void 0!==i.html&&null!==i.html){var a=le.add(this,i.html,i.role,this.messageElementRefs,s,r);ie.isElementTemporary(a)&&delete i.html}return this.isValidMessageContent(i)&&!r&&this.updateStateOnMessage(i,e.overwrite,e.sendUpdate,n),i}},{key:"isValidMessageContent",value:function(e){return e.text||e.html||e.files&&e.files.length>0}},{key:"updateStateOnMessage",value:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!t){var i=Wt.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,i])}n&&this.sendClientUpdate(e,r)}},{key:"removeMessageOnError",value:function(){var e=this.messageElementRefs[this.messageElementRefs.length-1],n=null==e?void 0:e.bubbleElement;(null!=n&&n.classList.contains(Jt.MESSAGE_CLASS)&&""===n.textContent||t.isTemporaryElement(e))&&this.removeLastMessage()}},{key:"addNewErrorMessage",value:function(e,t){var n,r,i,s,a,o=arguments.length>2&&void 0!==arguments[2]&&arguments[2];this.removeMessageOnError();var l=this.getPermittedMessage(t)||(null==(n=this._errorMessageOverrides)?void 0:n[e])||(null==(r=this._errorMessageOverrides)?void 0:r.default)||"Error, please try again.",c=this.createMessageElementsOnOrientation(l,"error",o);Wt.hideRoleElements(this.messageElementRefs,!!this._avatars,!!this._names);var u=c.bubbleElement,d=c.outerContainer;u.classList.add("error-message-text"),this.renderText(u,l);var h=Nt.extractParticularSharedStyles(["fontSize","fontFamily"],null==(i=this.messageStyles)?void 0:i.default);Nt.applyCustomStylesToElements(c,!1,h),Nt.applyCustomStylesToElements(c,!1,null==(s=this.messageStyles)?void 0:s.error),o||this.elementRef.appendChild(d),this.textToSpeech&&Y.speak(l,this.textToSpeech),null==(a=this._onError)||a.call(this,l)}},{key:"getPermittedMessage",value:function(e){if(e)for(var n=t.extractErrorMessages(e),r=0;r0&&e.classList.add("text-input-inner-left-adjustment"),t["inside-right"].length>0&&e.classList.add("text-input-inner-right-adjustment")}},{key:"adjustForOutsideButton",value:function(t,n,r){0===r["outside-right"].length&&r["outside-left"].length>0?(t[0].classList.add(e.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS),n.classList.add(e.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS)):0===r["outside-left"].length&&r["outside-right"].length>0&&(t[3].classList.add(e.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS),n.classList.add(e.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS))}},{key:"adjustOutsideSubmit",value:function(t,n,r){if(!(r["inside-left"].length>0||r["inside-right"].length>0)){if(0===r["outside-right"].length&&r["outside-left"].length>0)return t[0].classList.add(e.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),n.classList.add(e.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS),r["outside-left"].map((function(e){return e.button.elementRef.classList.add("submit-button-enlarged")}));if(0===r["outside-left"].length&&r["outside-right"].length>0)return t[3].classList.add(e.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),n.classList.add(e.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS),r["outside-right"].map((function(e){return e.button.elementRef.classList.add("submit-button-enlarged")}))}}},{key:"set",value:function(t,n,r,i){!!e.adjustOutsideSubmit(n,r,i)||e.adjustForOutsideButton(n,r,i),e.adjustInputPadding(t,i)}}])}();Vr.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment",Vr.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment",Vr.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment",Vr.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var Gr=Vr,Wr=function(){function e(){x(this,e)}return E(e,null,[{key:"create",value:function(){return Array.from({length:4}).map((function(e,t){var n=document.createElement("div");return n.classList.add("input-button-container"),(0===t||3===t)&&n.classList.add("outer-button-container"),(1===t||2===t)&&n.classList.add("inner-button-container"),n}))}},{key:"add",value:function(e,t){e.insertBefore(t[1],e.firstChild),e.insertBefore(t[0],e.firstChild),e.appendChild(t[2]),e.appendChild(t[3])}},{key:"getContainerIndex",value:function(e){return"outside-left"===e?0:"inside-left"===e?1:"inside-right"===e?2:3}},{key:"addButton",value:function(t,n,r){n.classList.add(r);var i=e.getContainerIndex(r);t[i].appendChild(n),3===i&&n.classList.add("outside-right")}}])}(),Kr=["camera","gifs","images","audio","mixedFiles","submit","microphone"],Jr=function(){function e(){x(this,e)}return E(e,null,[{key:"createTextElement",value:function(e){var t=document.createElement("div");return t.classList.add("text-button"),t.innerText=e,t}},{key:"createElement",value:function(t,n){return n?e.createTextElement(t):_n.createSVGElement(t)}},{key:"createCustomElement",value:function(t,n){var r,i,s,a,o=null==n?void 0:n[t];return null!=(r=null==o?void 0:o.svg)&&r.content?e.createElement(null==(i=null==o?void 0:o.svg)?void 0:i.content,!1):null!=(s=null==o?void 0:o.text)&&s.content?e.createElement(null==(a=null==o?void 0:o.text)?void 0:a.content,!0):void 0}},{key:"processElement",value:function(e,t){null!=t&&t.classList.contains("text-button")||e.classList.add("input-button-svg")}},{key:"createSpecificStateElement",value:function(t,n,r){var i;return r&&(i=e.createCustomElement(n,r)),e.processElement(t,i),i}},{key:"createInnerElement",value:function(t,n,r,i){var s,a;return(!(arguments.length>4&&void 0!==arguments[4]&&arguments[4])||null!=(a=null==(s=null==i?void 0:i[r])?void 0:s.svg)&&a.content)&&e.createSpecificStateElement(t,r,i)||n}}])}(),Yr=function(){function e(){x(this,e)}return E(e,null,[{key:"unsetAllCSS",value:function(e,t){var n,r;t.container&&A.unsetAllCSSMouseStates(e,t.container),null!=(n=t.svg)&&n.styles&&A.unsetAllCSSMouseStates(e.children[0],t.svg.styles),null!=(r=t.text)&&r.styles&&A.unsetAllCSSMouseStates(e.children[0],t.text.styles)}},{key:"unsetActionCSS",value:function(e,t){var n,r;t.container&&A.unsetActivityCSSMouseStates(e,t.container),null!=(n=t.svg)&&n.styles&&A.unsetActivityCSSMouseStates(e.children[0],t.svg.styles),null!=(r=t.text)&&r.styles&&A.unsetActivityCSSMouseStates(e.children[0],t.text.styles)}},{key:"setElementsCSS",value:function(e,t,n){var r,i,s,a,o;Object.assign(e.style,null==(r=t.container)?void 0:r[n]),Object.assign(e.children[0].style,null==(s=null==(i=t.svg)?void 0:i.styles)?void 0:s[n]),Object.assign(e.children[0].style,null==(o=null==(a=t.text)?void 0:a.styles)?void 0:o[n])}},{key:"setElementCssUpToState",value:function(t,n,r){e.setElementsCSS(t,n,"default"),"default"!==r&&(e.setElementsCSS(t,n,"hover"),"hover"!==r&&e.setElementsCSS(t,n,"click"))}}])}(),Zr=function(){return E((function e(t,n,r,i){x(this,e),this._mouseState={state:"default"},this.elementRef=t,this._customStyles=r,this.position=n,this.dropupText=i}),[{key:"buttonMouseLeave",value:function(e){this._mouseState.state="default",e&&(Yr.unsetAllCSS(this.elementRef,e),Yr.setElementsCSS(this.elementRef,e,"default"))}},{key:"buttonMouseEnter",value:function(e){this._mouseState.state="hover",e&&Yr.setElementsCSS(this.elementRef,e,"hover")}},{key:"buttonMouseUp",value:function(e){e&&Yr.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e)}},{key:"buttonMouseDown",value:function(e){this._mouseState.state="click",e&&Yr.setElementsCSS(this.elementRef,e,"click")}},{key:"setEvents",value:function(e){this.elementRef.onmousedown=this.buttonMouseDown.bind(this,e),this.elementRef.onmouseup=this.buttonMouseUp.bind(this,e),this.elementRef.onmouseenter=this.buttonMouseEnter.bind(this,e),this.elementRef.onmouseleave=this.buttonMouseLeave.bind(this,e)}},{key:"unsetCustomStateStyles",value:function(e){if(this._customStyles)for(var t=0;t3&&void 0!==arguments[3]&&arguments[3]?t:t[r?"nextSibling":"previousSibling"];i?(t.dispatchEvent(new MouseEvent("mouseleave")),i.dispatchEvent(new MouseEvent("mouseenter"))):(t.dispatchEvent(new MouseEvent("mouseleave")),e.focusItemWhenOnEdge(n,r))}}])}(),Qr=function(){function e(){x(this,e)}return E(e,null,[{key:"addItemEvents",value:function(e,t,n,r){te.add(t,r),t.addEventListener("click",(function(){n.click()})),t.addEventListener("mouseenter",(function(t){e.highlightedItem=t.target})),t.addEventListener("mouseleave",(function(){e.highlightedItem=void 0}))}},{key:"createItemText",value:function(e,t){var n=document.createElement("div");return Object.assign(n.style,t),n.classList.add("dropup-menu-item-text"),n.textContent=e||"File",n}},{key:"createItemIcon",value:function(e,t){var n=document.createElement("div");return Object.assign(n.style,t),n.classList.add("dropup-menu-item-icon"),n.appendChild(e.children[0]),n}},{key:"populateItem",value:function(t,n,r,i){var s=t.children[0];s.classList.contains("text-button")?n.appendChild(e.createItemText(s.textContent,null==i?void 0:i.text)):(n.appendChild(e.createItemIcon(t,null==i?void 0:i.iconContainer)),n.appendChild(e.createItemText(r,null==i?void 0:i.text)))}},{key:"createItem",value:function(t,n,r){var i,s=n.elementRef,a=n.dropupText,o=document.createElement("div");Object.assign(o.style,null==(i=null==r?void 0:r.item)?void 0:i.default),e.populateItem(s,o,a,r),o.classList.add("dropup-menu-item");var l=A.processStateful((null==r?void 0:r.item)||{},{backgroundColor:"#f3f3f3"},{backgroundColor:"#ebebeb"});return e.addItemEvents(t,o,s,l),o}}])}(),$r=function(){return E((function e(t,n){var r,i=this;x(this,e),this._isOpen=!0,this._styles=n,this.elementRef=e.createElement(null==(r=this._styles)?void 0:r.container),this.close(),setTimeout((function(){return i.addWindowEvents(t)}))}),[{key:"open",value:function(){this.elementRef.style.display="block",this._isOpen=!0}},{key:"close",value:function(){this._isOpen&&(this.elementRef.style.display="none",this._isOpen=!1)}},{key:"toggle",value:function(){this._isOpen?this.close():this.open()}},{key:"addItem",value:function(e){var t=Qr.createItem(this,e,this._styles);this.elementRef.appendChild(t)}},{key:"addWindowEvents",value:function(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener("click",this.clickEvent),this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent)}},{key:"windowClick",value:function(e,t){var n;!e.isConnected&&this.clickEvent?window.removeEventListener("click",this.clickEvent):e.parentElement!==(null==(n=t.target.shadowRoot)?void 0:n.children[0])&&this.close()}},{key:"windowKeyDown",value:function(e,t){var n,r,i;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===N.ESCAPE?(this.close(),null==(n=this.highlightedItem)||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===N.ENTER?(null==(r=this.highlightedItem)||r.click(),null==(i=this.highlightedItem)||i.dispatchEvent(new MouseEvent("mouseleave"))):t.key===N.ARROW_DOWN?Xr.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===N.ARROW_UP&&Xr.focusSiblingItem(this.highlightedItem||this.elementRef.children[0],this.elementRef,!1))}}],[{key:"createElement",value:function(e){var t=document.createElement("div");return t.id="dropup-menu",Object.assign(t.style,e),t}}])}(),ei=function(e){function t(e,n){var r,i;x(this,t);var a=(r=s(this,t,[t.createButtonElement(),void 0,{styles:null==(i=null==n?void 0:n.button)?void 0:i.styles}])).createInnerElements(r._customStyles);return r._menu=new $r(e,null==n?void 0:n.menu),r.addClickEvent(),r.buttonContainer=t.createButtonContainer(),r.elementRef.appendChild(a.styles),r.buttonContainer.appendChild(r.elementRef),r.elementRef.classList.add("dropup-icon","upload-file-button"),r.elementRef.children[0].id="dropup-icon",r.buttonContainer.appendChild(r._menu.elementRef),r.reapplyStateStyle("styles"),r.addContainerEvents(e),r}return c(t,e),E(t,[{key:"createInnerElements",value:function(e){return{styles:this.createInnerElement(t.createSVGIconElement(),"styles",e)}}},{key:"createInnerElement",value:function(e,t,n){return Jr.createSpecificStateElement(this.elementRef,t,n)||e}},{key:"addClickEvent",value:function(){this.elementRef.onclick=this._menu.toggle.bind(this._menu)}},{key:"addItem",value:function(e){this._menu.addItem(e)}},{key:"addContainerEvents",value:function(e){var t=this;e.addEventListener("click",(function(e){e.target.classList.contains("dropup-icon")||t._menu.close()}))}}],[{key:"createButtonElement",value:function(){var e=document.createElement("div");return e.classList.add("input-button"),e}},{key:"createSVGIconElement",value:function(){return _n.createSVGElement('\n\n \n ')}},{key:"createButtonContainer",value:function(){var e=document.createElement("div");return e.id="dropup-container",e}},{key:"getPosition",value:function(e,t){var n,r;return null!=(n=null==t?void 0:t.button)&&n.position?null==(r=null==t?void 0:t.button)?void 0:r.position:e["outside-left"].length>0&&0===e["outside-right"].length?"outside-right":"outside-left"}}])}(Zr),ti=function(){function e(){x(this,e)}return E(e,null,[{key:"addToDropup",value:function(e,t,n,r){var i=new ei(n,r);Kr.forEach((function(e){var n=t["dropup-menu"].findIndex((function(t){return t.buttonType===e})),r=t["dropup-menu"][n];r&&(i.addItem(r.button),t["dropup-menu"].splice(n,1))}));var s=ei.getPosition(t,r);Wr.addButton(e,i.buttonContainer,s),t[s].push({})}},{key:"addToSideContainer",value:function(e,t){["inside-left","inside-right","outside-left","outside-right"].forEach((function(n){var r=n;t[r].forEach((function(t){Wr.addButton(e,t.button.elementRef,r)}))}))}},{key:"setPosition",value:function(e,t,n){var r=b(b({},e[t]),{},{buttonType:t});n.push(r),delete e[t]}},{key:"createPositionsObj",value:function(){return{"dropup-menu":[],"outside-left":[],"inside-left":[],"inside-right":[],"outside-right":[]}}},{key:"generatePositions",value:function(t){var n=e.createPositionsObj();Object.keys(t).forEach((function(r){var i,s=null==(i=t[r])?void 0:i.button.position;s&&e.setPosition(t,r,n[s])})),0===n["inside-right"].length&&t.submit&&e.setPosition(t,"submit",n["inside-right"]),0===n["outside-right"].length&&(t.submit?e.setPosition(t,"submit",n["outside-right"]):t.microphone?e.setPosition(t,"microphone",n["outside-right"]):t.camera&&e.setPosition(t,"camera",n["outside-right"])),t.submit&&e.setPosition(t,"submit",0===n["outside-left"].length?n["outside-left"]:n["inside-right"]),t.microphone&&e.setPosition(t,"microphone",0===n["outside-left"].length?n["outside-left"]:n["inside-right"]);var r=Object.keys(t);return r.length>1||n["dropup-menu"].length>0?Kr.forEach((function(e){t[e]&&n["dropup-menu"].push(b(b({},t[e]),{},{buttonType:e}))})):1===r.length&&e.setPosition(t,r[0],0===n["outside-right"].length?n["outside-right"]:n["outside-left"]),n}},{key:"addButtons",value:function(t,n,r,i){var s=e.generatePositions(n);return e.addToSideContainer(t,s),s["dropup-menu"].length>0&&e.addToDropup(t,s,r,i),s}}])}(),ni={images:{id:"upload-images-icon",svgString:'\n\n \n \n',dropupText:"Image"},gifs:{id:"upload-gifs-icon",svgString:'\n\n \n \n \n \n \n',dropupText:"GIF"},audio:{id:"upload-audio-icon",svgString:'\n \n \n \n \n \n \n \n \n \n \n ',dropupText:"Audio"},mixedFiles:{id:"upload-mixed-files-icon",svgString:'\n\nfile \n \n ',dropupText:"File"}},ri=function(){function e(){x(this,e)}return E(e,null,[{key:"addAttributes",value:function(e){e.role="button",e.setAttribute("tabindex","0")}},{key:"addAriaBusy",value:function(e){e.setAttribute("aria-busy","true")}},{key:"removeAriaBusy",value:function(e){e.removeAttribute("aria-busy")}},{key:"addAriaDisabled",value:function(e){e.setAttribute("aria-disabled","true")}},{key:"removeAriaDisabled",value:function(e){e.removeAttribute("aria-disabled")}},{key:"removeAriaAttributes",value:function(t){e.removeAriaBusy(t),e.removeAriaDisabled(t)}}])}(),ii=function(e){function t(e){var n;return x(this,t),"dropup-menu"===(null==e?void 0:e.position)&&(e.position="outside-right"),(n=s(this,t,[t.createMicrophoneElement(),null==e?void 0:e.position,e])).isActive=!1,n._innerElements=n.createInnerElements(n._customStyles),n.changeToDefault(),n}return c(t,e),E(t,[{key:"createInnerElements",value:function(e){var n=t.createSVGIconElement();return{default:this.createInnerElement(n,"default",e),active:this.createInnerElement(n,"active",e),unsupported:this.createInnerElement(n,"unsupported",e),commandMode:this.createInnerElement(n,"commandMode",e)}}},{key:"createInnerElement",value:function(e,t,n){return Jr.createSpecificStateElement(this.elementRef,t,n)||e}},{key:"changeToActive",value:function(){this.elementRef.replaceChildren(this._innerElements.active),this.toggleIconFilter("active"),this.reapplyStateStyle("active",["default","commandMode"]),this.isActive=!0}},{key:"changeToDefault",value:function(){this.elementRef.replaceChildren(this._innerElements.default),this.toggleIconFilter("default"),this.reapplyStateStyle("default",["active","commandMode"]),this.isActive=!1}},{key:"changeToCommandMode",value:function(){this.elementRef.replaceChildren(this._innerElements.unsupported),this.toggleIconFilter("command"),this.reapplyStateStyle("commandMode",["active"])}},{key:"changeToUnsupported",value:function(){this.elementRef.replaceChildren(this._innerElements.unsupported),this.elementRef.classList.add("unsupported-microphone"),this.reapplyStateStyle("unsupported",["active"])}},{key:"toggleIconFilter",value:function(e){var t=this.elementRef.children[0];if("svg"===t.tagName.toLocaleLowerCase())switch(e){case"default":t.classList.remove("active-microphone-icon","command-microphone-icon"),t.classList.add("default-microphone-icon");break;case"active":t.classList.remove("default-microphone-icon","command-microphone-icon"),t.classList.add("active-microphone-icon");break;case"command":t.classList.remove("active-microphone-icon","default-microphone-icon"),t.classList.add("command-microphone-icon")}}}],[{key:"createMicrophoneElement",value:function(){var e=document.createElement("div");return e.id="microphone-button",e.classList.add("input-button"),ri.addAttributes(e),e}},{key:"createSVGIconElement",value:function(){var e=_n.createSVGElement('\n\n\t\n\t\t\n\t\t\t \n\t\t\t \n\t\t \n\t \n \n');return e.id="microphone-icon",e}}])}(Zr),si={},ai={},oi={},li={},ci={};Object.defineProperty(ci,"__esModule",{value:!0}),ci.Text=void 0;var ui=function(){function e(){x(this,e)}return E(e,null,[{key:"capitalize",value:function(t){return t.replace(e.FIRST_CHAR_REGEX,(function(e){return e.toUpperCase()}))}},{key:"lineBreak",value:function(t){return t.replace(e.DOUBLE_LINE,"
").replace(e.ONE_LINE," ")}},{key:"isCharDefined",value:function(e){return void 0!==e&&"\xa0"!==e&&" "!==e&&"\n"!==e&&""!==e}},{key:"breakupIntoWordsArr",value:function(e){return e.split(/(\W+)/)}}])}();ci.Text=ui,ui.FIRST_CHAR_REGEX=/\S/,ui.DOUBLE_LINE=/\n\n/g,ui.ONE_LINE=/\n/g,Object.defineProperty(li,"__esModule",{value:!0}),li.Translate=void 0;var di=ci,hi=function(){return E((function e(){x(this,e)}),null,[{key:"translate",value:function(e,t){for(var n=di.Text.breakupIntoWordsArr(e),r=0;re.clientHeight||e.scrollWidth>e.clientWidth}},{key:"isRequired",value:function(t,n){return t&&e.isElementOverflown(n)}}])}();Si.AutoScroll=Ei;var wi={};Object.defineProperty(wi,"__esModule",{value:!0}),wi.Elements=void 0;var Ci=function(){return E((function e(){x(this,e)}),null,[{key:"isPrimitiveElement",value:function(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName}},{key:"createInterimSpan",value:function(){var e=document.createElement("span");return e.style.color="grey",e.style.pointerEvents="none",e}},{key:"createGenericSpan",value:function(){var e=document.createElement("span");return e.style.pointerEvents="none",e}},{key:"appendSpans",value:function(e,t){if(e.spansPopulated=!0,e.insertInCursorLocation&&document.activeElement===t){var n=window.getSelection();if(null!=n&&n.focusNode){var r=n.getRangeAt(0);return r.insertNode(e.scrollingSpan),r.insertNode(e.interimSpan),r.insertNode(e.finalSpan),r.collapse(!1),n.removeAllRanges(),void n.addRange(r)}}t.appendChild(e.finalSpan),t.appendChild(e.interimSpan),t.appendChild(e.scrollingSpan)}},{key:"applyCustomColors",value:function(e,t){t.interim&&(e.interimSpan.style.color=t.interim),t.final&&(e.finalSpan.style.color=t.final)}},{key:"isInsideShadowDOM",value:function(e){return e.getRootNode()instanceof ShadowRoot}}])}();wi.Elements=Ci;var Ti={};Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.Cursor=void 0;var Ai=function(){function e(){x(this,e)}return E(e,null,[{key:"setOffsetForGeneric",value:function(t,n){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=0,s=0;s0){var o=e.setOffsetForGeneric(a,n,r);if(-1===o)return-1;r+=o}else if(null!==a.textContent){if(r+a.textContent.length>n){var l=document.createRange();l.setStart(a,n-r),l.collapse(!0);var c=window.getSelection();return null==c||c.removeAllRanges(),null==c||c.addRange(l),t.focus(),-1}r+=a.textContent.length,i+=a.textContent.length}}return i}},{key:"focusEndOfGeneric",value:function(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n&&(n.removeAllRanges(),n.addRange(t))}},{key:"setOffsetForSafariGeneric",value:function(t,n){var r=window.getSelection();if(r){var i=e.getGenericElementCursorOffset(t,r,!0);console.log(i),setTimeout((function(){}),100),e.setOffsetForGeneric(t,i+n)}}},{key:"setOffsetForPrimitive",value:function(e,t,n){n&&e.blur(),e.setSelectionRange(t,t),e.focus()}},{key:"getGenericElementCursorOffset",value:function(e,t,n){var r=0;if(t.rangeCount>0){var i=t.getRangeAt(0),s=i.cloneRange();s.selectNodeContents(e),n?s.setEnd(i.startContainer,i.startOffset):s.setEnd(i.endContainer,i.endOffset),r=s.toString().length}return r}}])}();Ti.Cursor=Ai,Object.defineProperty(xi,"__esModule",{value:!0}),xi.CommandUtils=void 0;var Mi=Si,Ii=wi,Li=mi,Ri=Ti,Oi=ci,Pi=function(){function e(){x(this,e)}return E(e,null,[{key:"processCommand",value:function(e,t){return(!t||!t.caseSensitive)&&(e=e.toLowerCase()),!1===(null==t?void 0:t.substrings)?Oi.Text.breakupIntoWordsArr(e):e}},{key:"process",value:function(t){var n;return!0===(null===(n=t.settings)||void 0===n?void 0:n.caseSensitive)?t:Object.keys(t).reduce((function(n,r){var i=t[r];return n[r]="string"==typeof i?e.processCommand(i,t.settings):i,n}),{})}},{key:"toggleCommandModeOn",value:function(e){var t;e.isWaitingForCommand=!0,null===(t=e.onCommandModeTrigger)||void 0===t||t.call(e,!0)}},{key:"toggleCommandModeOff",value:function(e){var t;e.isWaitingForCommand&&(null===(t=e.onCommandModeTrigger)||void 0===t||t.call(e,!1),e.isWaitingForCommand=!1)}},{key:"setText",value:function(t,n,r,i){e.toggleCommandModeOff(t),Ii.Elements.isPrimitiveElement(i)?(i.value=r,t.isTargetInShadow||Ri.Cursor.setOffsetForPrimitive(i,r.length,!0),Li.Browser.IS_SAFARI()&&t.autoScroll&&Mi.AutoScroll.scrollSafariPrimitiveToEnd(i)):(i.textContent=r,t.isTargetInShadow||Ri.Cursor.focusEndOfGeneric(i),setTimeout((function(){return Mi.AutoScroll.scrollGeneric(t,i)}))),t.resetRecording(n)}},{key:"checkIfMatchesSubstring",value:function(e,t){return t.includes(e)}},{key:"checkIfMatchesWord",value:function(e,t,n){for(var r=e,i=n.length-1;i>=0;i-=1){for(var s=i,a=r.length-1;n[s]===r[a]&&a>=0;)s-=1,a-=1;if(a<0)return!0}return!1}},{key:"execCommand",value:function(t,n,r,i,s){var a,o,l,c=t.commands;if(c&&i&&r){var u=!0===(null===(a=c.settings)||void 0===a?void 0:a.caseSensitive)?n:n.toLowerCase(),d=Oi.Text.breakupIntoWordsArr(u),h=!1===(null===(o=c.settings)||void 0===o?void 0:o.substrings)?e.checkIfMatchesWord:e.checkIfMatchesSubstring;if(c.commandMode&&h(c.commandMode,u,d))return t.setInterimColorToFinal(),setTimeout((function(){return e.toggleCommandModeOn(t)})),{doNotProcessTranscription:!1};if(!c.commandMode||t.isWaitingForCommand){if(c.stop&&h(c.stop,u,d))return e.toggleCommandModeOff(t),setTimeout((function(){return t.stop()})),{doNotProcessTranscription:!1};if(c.pause&&h(c.pause,u,d))return e.toggleCommandModeOff(t),t.setInterimColorToFinal(),setTimeout((function(){var e;t.isPaused=!0,null===(e=t.onPauseTrigger)||void 0===e||e.call(t,!0)})),{doNotProcessTranscription:!1};if(c.resume&&h(c.resume,u,d))return t.isPaused=!1,null===(l=t.onPauseTrigger)||void 0===l||l.call(t,!1),e.toggleCommandModeOff(t),t.resetRecording(r),{doNotProcessTranscription:!0};if(c.reset&&h(c.reset,u,d))return void 0!==s&&e.setText(t,r,s,i),{doNotProcessTranscription:!0};if(c.removeAllText&&h(c.removeAllText,u,d))return e.setText(t,r,"",i),{doNotProcessTranscription:!0}}}}}])}();xi.CommandUtils=Pi;var Ni={};Object.defineProperty(Ni,"__esModule",{value:!0}),Ni.Highlight=void 0;var Bi=wi,Di=Ti,Fi=function(){function e(){x(this,e)}return E(e,null,[{key:"setStateForPrimitive",value:function(e,t){var n,r;null!==t.selectionStart&&(n=t.selectionStart),null!==t.selectionEnd&&(r=t.selectionEnd),e.isHighlighted=n!==r}},{key:"setStateForGeneric",value:function(e,t){var n=window.getSelection();if(null!=n&&n.focusNode){var r=Di.Cursor.getGenericElementCursorOffset(t,n,!0),i=Di.Cursor.getGenericElementCursorOffset(t,n,!1);e.isHighlighted=r!==i}}},{key:"setState",value:function(t,n){document.activeElement===n&&(Bi.Elements.isPrimitiveElement(n)?e.setStateForPrimitive(t,n):e.setStateForGeneric(t,n))}},{key:"removeForGeneric",value:function(e,t){var n=window.getSelection();if(n){var r=Di.Cursor.getGenericElementCursorOffset(t,n,!0);n.deleteFromDocument(),Di.Cursor.setOffsetForGeneric(t,r),e.isHighlighted=!1}}},{key:"removeForPrimitive",value:function(e,t){var n=t.selectionStart,r=t.selectionEnd,i=t.value;if(n&&r){var s=i.substring(0,n)+i.substring(r);t.value=s,Di.Cursor.setOffsetForPrimitive(t,n,e.autoScroll)}e.isHighlighted=!1}}])}();Ni.Highlight=Fi;var ji={};Object.defineProperty(ji,"__esModule",{value:!0}),ji.Padding=void 0;var Ui=wi,Hi=Ti,qi=ci,zi=function(){function e(){x(this,e)}return E(e,null,[{key:"setStateForPrimitiveElement",value:function(e,t){if(document.activeElement===t&&null!==t.selectionStart){var n=t.selectionStart,r=t.value[n-1],i=null===t.selectionEnd?n:t.selectionEnd,s=t.value[i];return qi.Text.isCharDefined(r)&&(e.startPadding=" ",e.numberOfSpacesBeforeNewText=1),qi.Text.isCharDefined(s)&&(e.endPadding=" ",e.numberOfSpacesAfterNewText=1),void(e.isCursorAtEnd=t.value.length===i)}var a=t.value[t.value.length-1];qi.Text.isCharDefined(a)&&(e.startPadding=" ",e.numberOfSpacesBeforeNewText=1),e.isCursorAtEnd=!0}},{key:"setStateForGenericElement",value:function(e,t){var n,r,i;if(document.activeElement===t){var s=window.getSelection();if(null!=s&&s.focusNode){var a=Hi.Cursor.getGenericElementCursorOffset(t,s,!0),o=null===(n=t.textContent)||void 0===n?void 0:n[a-1],l=Hi.Cursor.getGenericElementCursorOffset(t,s,!1),c=null===(r=t.textContent)||void 0===r?void 0:r[l];return qi.Text.isCharDefined(o)&&(e.startPadding=" "),qi.Text.isCharDefined(c)&&(e.endPadding=" "),void(e.isCursorAtEnd=(null===(i=t.textContent)||void 0===i?void 0:i.length)===l)}}var u=t.innerText.charAt(t.innerText.length-1);qi.Text.isCharDefined(u)&&(e.startPadding=" "),e.isCursorAtEnd=!0}},{key:"setState",value:function(t,n){Ui.Elements.isPrimitiveElement(n)?e.setStateForPrimitiveElement(t,n):e.setStateForGenericElement(t,n)}},{key:"adjustStateAfterRecodingPrimitiveElement",value:function(e,t){e.primitiveTextRecorded=!0,e.insertInCursorLocation&&document.activeElement===t&&(null!==t.selectionEnd&&(e.endPadding=e.endPadding+t.value.slice(t.selectionEnd)),null!==t.selectionStart)?e.startPadding=t.value.slice(0,t.selectionStart)+e.startPadding:e.startPadding=t.value+e.startPadding}},{key:"adjustSateForNoTextPrimitiveElement",value:function(e){1===e.numberOfSpacesBeforeNewText&&(e.startPadding=e.startPadding.substring(0,e.startPadding.length-1),e.numberOfSpacesBeforeNewText=0),1===e.numberOfSpacesAfterNewText&&(e.endPadding=e.endPadding.substring(1),e.numberOfSpacesAfterNewText=0)}}])}();ji.Padding=zi,Object.defineProperty(gi,"__esModule",{value:!0}),gi.Speech=void 0;var Vi=yi,Gi=ki,Wi=xi,Ki=Si,Ji=Ni,Yi=wi,Zi=ji,Xi=mi,Qi=Ti,$i=ci,es=function(){return E((function e(){x(this,e),this.finalTranscript="",this.interimSpan=Yi.Elements.createInterimSpan(),this.finalSpan=Yi.Elements.createGenericSpan(),this.scrollingSpan=Yi.Elements.createGenericSpan(),this.isCursorAtEnd=!1,this.spansPopulated=!1,this.startPadding="",this.endPadding="",this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.recognizing=!1,this._displayInterimResults=!0,this.insertInCursorLocation=!0,this.autoScroll=!0,this.isRestarting=!1,this.isPaused=!1,this.isWaitingForCommand=!1,this.isTargetInShadow=!1,this.cannotBeStopped=!1,this.resetState()}),[{key:"prepareBeforeStart",value:function(e){var t,n;if(null!=e&&e.element)if(Vi.EventListeners.add(this,e),Array.isArray(e.element)){var r=e.element.find((function(e){return e===document.activeElement}))||e.element[0];if(!r)return;this.prepare(r)}else this.prepare(e.element);void 0!==(null==e?void 0:e.displayInterimResults)&&(this._displayInterimResults=e.displayInterimResults),null!=e&&e.textColor&&(this._finalTextColor=null===(t=null==e?void 0:e.textColor)||void 0===t?void 0:t.final,Yi.Elements.applyCustomColors(this,e.textColor)),void 0!==(null==e?void 0:e.insertInCursorLocation)&&(this.insertInCursorLocation=e.insertInCursorLocation),void 0!==(null==e?void 0:e.autoScroll)&&(this.autoScroll=e.autoScroll),this._onResult=null==e?void 0:e.onResult,this._onPreResult=null==e?void 0:e.onPreResult,this._onStart=null==e?void 0:e.onStart,this._onStop=null==e?void 0:e.onStop,this._onError=null==e?void 0:e.onError,this.onCommandModeTrigger=null==e?void 0:e.onCommandModeTrigger,this.onPauseTrigger=null==e?void 0:e.onPauseTrigger,this._options=e,null!==(n=this._options)&&void 0!==n&&n.commands&&(this.commands=Wi.CommandUtils.process(this._options.commands))}},{key:"prepare",value:function(e){Zi.Padding.setState(this,e),Ji.Highlight.setState(this,e),this.isTargetInShadow=Yi.Elements.isInsideShadowDOM(e),Yi.Elements.isPrimitiveElement(e)?(this._primitiveElement=e,this._originalText=this._primitiveElement.value):(this._genericElement=e,this._originalText=this._genericElement.textContent)}},{key:"resetRecording",value:function(e){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(e,!0)}},{key:"updateElements",value:function(e,t,n){var r,i=$i.Text.capitalize(t);if(this.finalTranscript!==i||""!==e){Gi.PreResultUtils.process(this,n,""===e,this._onPreResult,this._options)&&(e="",n="");var s=this.commands&&Wi.CommandUtils.execCommand(this,n,this._options,this._primitiveElement||this._genericElement,this._originalText);if(s){if(s.doNotProcessTranscription)return;e="",n=""}if(!this.isPaused&&!this.isWaitingForCommand){null===(r=this._onResult)||void 0===r||r.call(this,n,""===e),this.finalTranscript=i,this._displayInterimResults||(e="");var a=""===this.finalTranscript&&""===e;this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,e,a):this._genericElement&&this.updateGenericElement(this._genericElement,e,a)}}}},{key:"updatePrimitiveElement",value:function(e,t,n){this.isHighlighted&&Ji.Highlight.removeForPrimitive(this,e),this.primitiveTextRecorded||Zi.Padding.adjustStateAfterRecodingPrimitiveElement(this,e),n&&Zi.Padding.adjustSateForNoTextPrimitiveElement(this);var r=this.startPadding+this.finalTranscript+t;if(e.value=r+this.endPadding,!this.isTargetInShadow){var i=r.length+this.numberOfSpacesAfterNewText;Qi.Cursor.setOffsetForPrimitive(e,i,this.autoScroll)}this.autoScroll&&Xi.Browser.IS_SAFARI()&&this.isCursorAtEnd&&Ki.AutoScroll.scrollSafariPrimitiveToEnd(e)}},{key:"updateGenericElement",value:function(e,t,n){this.isHighlighted&&Ji.Highlight.removeForGeneric(this,e),this.spansPopulated||Yi.Elements.appendSpans(this,e);var r=(n?"":this.startPadding)+$i.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=r;var i=Ki.AutoScroll.isRequired(this.autoScroll,e);Ki.AutoScroll.changeStateIfNeeded(this,i);var s=$i.Text.lineBreak(t)+(n?"":this.endPadding);this.interimSpan.innerHTML=s,Xi.Browser.IS_SAFARI()&&this.insertInCursorLocation&&Qi.Cursor.setOffsetForSafariGeneric(e,r.length+s.length),i&&Ki.AutoScroll.scrollGeneric(this,e),n&&(this.scrollingSpan.innerHTML="")}},{key:"finalise",value:function(e){this._genericElement&&(e?(this.finalSpan=Yi.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=Yi.Elements.createInterimSpan(),this.scrollingSpan=Yi.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),Vi.EventListeners.remove(this)}},{key:"setInterimColorToFinal",value:function(){this.interimSpan.style.color=this._finalTextColor||"black"}},{key:"resetState",value:function(e){this._primitiveElement=void 0,this._genericElement=void 0,this.finalTranscript="",this.finalSpan.innerHTML="",this.interimSpan.innerHTML="",this.scrollingSpan.innerHTML="",this.startPadding="",this.endPadding="",this.isHighlighted=!1,this.primitiveTextRecorded=!1,this.numberOfSpacesBeforeNewText=0,this.numberOfSpacesAfterNewText=0,e||(this.stopTimeout=void 0)}},{key:"setStateOnStart",value:function(){var e;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:null===(e=this._onStart)||void 0===e||e.call(this)}},{key:"setStateOnStop",value:function(){var e;this.recognizing=!1,this.isRestarting||null===(e=this._onStop)||void 0===e||e.call(this)}},{key:"setStateOnError",value:function(e){var t;null===(t=this._onError)||void 0===t||t.call(this,e),this.recognizing=!1}}])}();gi.Speech=es,Object.defineProperty(ai,"__esModule",{value:!0}),ai.WebSpeech=void 0;var ts=oi,ns=mi,rs=function(e){function t(){return x(this,t),s(this,t)}return c(t,e),E(t,[{key:"start",value:function(e){var t;void 0===this._extractText&&(this._extractText=ns.Browser.IS_SAFARI()?ts.WebSpeechTranscript.extractSafari:ts.WebSpeechTranscript.extract),this.validate()&&(this.prepareBeforeStart(e),this.instantiateService(e),null===(t=this._service)||void 0===t||t.start(),this._translations=null==e?void 0:e.translations)}},{key:"validate",value:function(){return!!t.getAPI()||(this.error("Speech Recognition is unsupported"),!1)}},{key:"instantiateService",value:function(e){var n,r,i=t.getAPI();this._service=new i,this._service.continuous=!0,this._service.interimResults=null===(n=null==e?void 0:e.displayInterimResults)||void 0===n||n,this._service.lang=(null===(r=null==e?void 0:e.language)||void 0===r?void 0:r.trim())||"en-US",this.setEvents()}},{key:"setEvents",value:function(){var e=this;this._service&&(this._service.onstart=function(){e.setStateOnStart()},this._service.onerror=function(t){ns.Browser.IS_SAFARI()&&"Another request is started"===t.message||"aborted"===t.error&&e.isRestarting||"no-speech"!==t.error&&e.error(t.message||t.error)},this._service.onaudioend=function(){e.setStateOnStop()},this._service.onend=function(){e._stopping=!1},this._service.onresult=function(t){if(_(t.results)>"u"&&e._service)e._service.onend=null,e._service.stop();else if(e._extractText&&!e._stopping){var n=e._extractText(t,e.finalTranscript,e._translations),r=n.interimTranscript,i=n.finalTranscript,s=n.newText;e.updateElements(r,i,s)}})}},{key:"stop",value:function(e){var t;this._stopping=!0,null===(t=this._service)||void 0===t||t.stop(),this.finalise(e)}},{key:"error",value:function(e){console.error(e),this.setStateOnError(e),this.stop()}}],[{key:"getAPI",value:function(){return window.webkitSpeechRecognition||window.SpeechRecognition}}])}(gi.Speech);ai.WebSpeech=rs;var is={};Object.defineProperty(is,"__esModule",{value:!0}),is.GlobalState=void 0;var ss=function(){function e(){x(this,e)}return E(e,null,[{key:"doubleClickDetector",value:function(){return!!e.doubleClickPending||(e.doubleClickPending=!0,setTimeout((function(){e.doubleClickPending=!1}),300),!1)}}])}();is.GlobalState=ss,ss.doubleClickPending=!1;var as={},os={};Object.defineProperty(os,"__esModule",{value:!0}),os.PreventConnectionStop=void 0;var ls=function(){return E((function e(){x(this,e)}),null,[{key:"applyPrevention",value:function(e){clearTimeout(e._manualConnectionStopPrevention),e.cannotBeStopped=!0,e._manualConnectionStopPrevention=setTimeout((function(){e.cannotBeStopped=!1}),800)}},{key:"clearPrevention",value:function(e){clearTimeout(e._manualConnectionStopPrevention),e.cannotBeStopped=!1}}])}();os.PreventConnectionStop=ls;var cs={},us={};Object.defineProperty(us,"__esModule",{value:!0}),us.README_URL=void 0,us.README_URL="https://github.com/OvidijusParsiunas/speech-to-element",Object.defineProperty(cs,"__esModule",{value:!0}),cs.AzureSpeechConfig=void 0;var ds=us,hs=function(){function e(){x(this,e)}return E(e,null,[{key:"validateOptions",value:function(e,t){return t?t.subscriptionKey||t.token||t.retrieveToken?!!t.region||(e("Please define a 'region' property - more info: ".concat(ds.README_URL)),!1):(e("Please define a 'subscriptionKey', 'token' or 'retrieveToken' property - more info: ".concat(ds.README_URL)),!1):(e("Please provide subscription details - more info: ".concat(ds.README_URL)),!1)}},{key:"getNewSpeechConfig",value:(n=f(h().mark((function e(t,n){return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n.region){e.next=2;break}return e.abrupt("return",n.subscriptionKey?t.fromSubscription(n.subscriptionKey.trim(),n.region.trim()):n.token?t.fromAuthorizationToken(n.token.trim(),n.region.trim()):n.retrieveToken?n.retrieveToken().then((function(e){return n.region?t.fromAuthorizationToken((null==e?void 0:e.trim())||"",n.region.trim()):null})).catch((function(e){return console.error(e),null})):null);case 2:case"end":return e.stop()}}),e)}))),function(e,t){return n.apply(this,arguments)})},{key:"process",value:function(e,t){t.language&&(e.speechRecognitionLanguage=t.language.trim())}},{key:"get",value:(t=f(h().mark((function t(n,r){var i;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.getNewSpeechConfig(n,r);case 2:return i=t.sent,t.abrupt("return",(i&&e.process(i,r),i));case 4:case"end":return t.stop()}}),t)}))),function(e,n){return t.apply(this,arguments)})}]);var t,n}();cs.AzureSpeechConfig=hs;var ps={};Object.defineProperty(ps,"__esModule",{value:!0}),ps.StopTimeout=void 0;var fs=function(){function e(){x(this,e)}return E(e,null,[{key:"set",value:function(e){e.stopTimeout=setTimeout((function(){return e.stop()}),e.stopTimeoutMS)}},{key:"reset",value:function(t,n){t.stopTimeoutMS=n||e.DEFAULT_MS,t.stopTimeout&&clearTimeout(t.stopTimeout),e.set(t)}}])}();ps.StopTimeout=fs,fs.DEFAULT_MS=2e4;var ms={};Object.defineProperty(ms,"__esModule",{value:!0}),ms.AzureTranscript=void 0;var vs=li,gs=function(){return E((function e(){x(this,e)}),null,[{key:"extract",value:function(e,t,n,r){return r&&(e=vs.Translate.translate(e,r)),n?{interimTranscript:"",finalTranscript:t+e,newText:e}:{interimTranscript:e,finalTranscript:t,newText:e}}}])}();ms.AzureTranscript=gs,Object.defineProperty(as,"__esModule",{value:!0}),as.Azure=void 0;var ys=os,bs=cs,ks=ps,_s=ms,xs=function(e){function t(){var e;return x(this,t),(e=s(this,t,arguments))._newTextPadding="",e}return c(t,e),E(t,[{key:"start",value:function(e,t){this._newTextPadding="",void 0===this.stopTimeout&&ks.StopTimeout.reset(this,null==e?void 0:e.stopAfterSilenceMs),this.prepareBeforeStart(e),this.startAsync(e),t||ys.PreventConnectionStop.applyPrevention(this)}},{key:"startAsync",value:(r=f(h().mark((function e(t){var n;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.t0=this.validate(t),!e.t0){e.next=6;break}return e.next=4,this.instantiateService(t);case 4:this._translations=null==t?void 0:t.translations,null===(n=this._service)||void 0===n||n.startContinuousRecognitionAsync((function(){}),this.error);case 6:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"validate",value:function(e){return t.getAPI()?bs.AzureSpeechConfig.validateOptions(this.error.bind(this),e):(this.moduleNotFound(),!1)}},{key:"instantiateService",value:(n=f(h().mark((function e(n){var r,i,s,a;return h().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.getAPI(),i=r.AudioConfig.fromDefaultMicrophoneInput(),e.next=4,bs.AzureSpeechConfig.get(r.SpeechConfig,n);case 4:(s=e.sent)?(a=new r.SpeechRecognizer(s,i),this.setEvents(a),this._service=a,n.retrieveToken&&this.retrieveTokenInterval(n.retrieveToken)):this.error("Unable to contact Azure server");case 6:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"setEvents",value:function(e){e.recognizing=this.onRecognizing.bind(this),e.recognized=this.onRecognized.bind(this),e.sessionStarted=this.onSessionStarted.bind(this),e.canceled=this.onCanceled.bind(this),e.sessionStopped=this.onSessionStopped.bind(this)}},{key:"onRecognizing",value:function(e,t){if(!this._stopping){var n=_s.AzureTranscript.extract(this._newTextPadding+t.result.text,this.finalTranscript,!1,this._translations),r=n.interimTranscript,i=n.finalTranscript,s=n.newText;ks.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(r,i,s)}}},{key:"onRecognized",value:function(e,t){var n=t.result;switch(n.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(n.text&&!this._stopping){var r=_s.AzureTranscript.extract(this._newTextPadding+n.text,this.finalTranscript,!0,this._translations),i=r.interimTranscript,s=r.finalTranscript,a=r.newText;ks.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(i,s,a),""!==s&&(this._newTextPadding=" ")}}}},{key:"onCanceled",value:function(e,t){t.reason===window.SpeechSDK.CancellationReason.Error&&this.error(t.errorDetails)}},{key:"onSessionStarted",value:function(){ys.PreventConnectionStop.clearPrevention(this),this.setStateOnStart()}},{key:"onSessionStopped",value:function(){this._retrieveTokenInterval||clearInterval(this._retrieveTokenInterval),this._stopping=!1,this.setStateOnStop()}},{key:"retrieveTokenInterval",value:function(e){var t=this;this._retrieveTokenInterval=setInterval((function(){null==e||e().then((function(e){t._service&&(t._service.authorizationToken=(null==e?void 0:e.trim())||"")})).catch((function(e){t.error(e)}))}),1e4)}},{key:"stop",value:function(e){var t;!e&&this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),this._stopping=!0,null===(t=this._service)||void 0===t||t.stopContinuousRecognitionAsync(),this.finalise(e)}},{key:"moduleNotFound",value:function(){console.error("speech recognition module not found:"),console.error("please install the 'microsoft-cognitiveservices-speech-sdk' npm package or add a script tag:
+
diff --git a/docs/demo/index.html b/docs/demo/index.html
index f1e49cf35..1b11ff4c5 100644
--- a/docs/demo/index.html
+++ b/docs/demo/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/directConnection/AssemblyAI/index.html b/docs/directConnection/AssemblyAI/index.html
index f5f93883e..036c93a06 100644
--- a/docs/directConnection/AssemblyAI/index.html
+++ b/docs/directConnection/AssemblyAI/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/directConnection/Azure/index.html b/docs/directConnection/Azure/index.html
index 4d168777e..284f66045 100644
--- a/docs/directConnection/Azure/index.html
+++ b/docs/directConnection/Azure/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/directConnection/Cohere/index.html b/docs/directConnection/Cohere/index.html
index d89b0563d..449ae3870 100644
--- a/docs/directConnection/Cohere/index.html
+++ b/docs/directConnection/Cohere/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/directConnection/HuggingFace/index.html b/docs/directConnection/HuggingFace/index.html
index 9d5a429a9..e36df39cf 100644
--- a/docs/directConnection/HuggingFace/index.html
+++ b/docs/directConnection/HuggingFace/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/directConnection/OpenAI/index.html b/docs/directConnection/OpenAI/index.html
index 266edfe68..52cf4e975 100644
--- a/docs/directConnection/OpenAI/index.html
+++ b/docs/directConnection/OpenAI/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/directConnection/StabilityAI/index.html b/docs/directConnection/StabilityAI/index.html
index 329294d78..dcde81e17 100644
--- a/docs/directConnection/StabilityAI/index.html
+++ b/docs/directConnection/StabilityAI/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/directConnection/index.html b/docs/directConnection/index.html
index b8e524559..9403340c4 100644
--- a/docs/directConnection/index.html
+++ b/docs/directConnection/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/events/index.html b/docs/events/index.html
index d73d6f02b..fe3b82609 100644
--- a/docs/events/index.html
+++ b/docs/events/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/files/index.html b/docs/files/index.html
index 1b3e50110..69295555e 100644
--- a/docs/files/index.html
+++ b/docs/files/index.html
@@ -13,7 +13,7 @@
-
+
diff --git a/docs/installation/index.html b/docs/installation/index.html
index 9ad6207a0..c69c2b8b4 100644
--- a/docs/installation/index.html
+++ b/docs/installation/index.html
@@ -13,7 +13,7 @@
-
+
@@ -23,6 +23,6 @@
For React, install the following instead:
npm install deep-chat-react
Access the component via CDN:
-https://unpkg.com/deep-chat@2.1.0/dist/deepChat.bundle.js
+https://unpkg.com/deep-chat@2.1.1/dist/deepChat.bundle.js