From da4512478407dfe550bdbed003b165d1440c977f Mon Sep 17 00:00:00 2001 From: bruffridge Date: Tue, 20 Feb 2024 16:48:40 +0000 Subject: [PATCH] deploy: b1cc7498521a38a70d840c297e4f4bfa49444315 --- build/bundle.css | 2 +- build/bundle.js | 2 +- build/bundle.js.map | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/bundle.css b/build/bundle.css index 318b05b..f430ca5 100644 --- a/build/bundle.css +++ b/build/bundle.css @@ -1,5 +1,5 @@ img.svelte-1ng8xwy{width:2em;height:2em;border:1px solid rgb(142, 142, 142);border-radius:2em;max-width:inherit} -.container.svelte-se61fg.svelte-se61fg{width:2em;height:2em;margin-right:4.5em}.menu.svelte-se61fg.svelte-se61fg:hover{cursor:pointer}.menu-image.svelte-se61fg.svelte-se61fg{width:15px;height:15px;transition:transform ease-out 0.3s}.open.svelte-se61fg img.svelte-se61fg{transform:rotate(180deg)}@media only screen and (max-width: 700px){.container.svelte-se61fg.svelte-se61fg{margin-right:0}} +button.svelte-1nou3st.svelte-1nou3st{padding:3px}.container.svelte-1nou3st.svelte-1nou3st{width:2em;height:2em;margin-right:4.5em}.menu.svelte-1nou3st.svelte-1nou3st:hover{cursor:pointer}.menu-image.svelte-1nou3st.svelte-1nou3st{width:15px;height:15px;transition:transform ease-out 0.3s}.open.svelte-1nou3st img.svelte-1nou3st{transform:rotate(180deg)}@media only screen and (max-width: 700px){.container.svelte-1nou3st.svelte-1nou3st{margin-right:0}} header.svelte-cwrdb9{background-color:rgb(229, 229, 234);z-index:10;border-bottom:1px solid rgb(199, 199, 204);max-width:100vw}button.svelte-cwrdb9{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;background-color:rgb(229, 229, 234)} .slider-button-reveal-container.svelte-16iehjd{height:100%;width:100%;position:relative;cursor:pointer;transition:background-color 0.3s ease;transition:margin-right 0.3s ease}.slider-button.svelte-16iehjd{height:100%;width:100%;left:0;top:0;padding:1em;z-index:25 !important;border-bottom:1px solid rgb(199, 199, 204);transition:background-color 0.3s ease}.slider-button-text.svelte-16iehjd{font-size:1em;overflow:hidden;margin-right:1em;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}.reveal.svelte-16iehjd{position:absolute;z-index:20 !important;height:100%;width:100%;left:0;top:0;transition:margin-right 0.3s ease;border-bottom:1px solid rgb(174, 174, 178)}.reveal-image.svelte-16iehjd{width:15px;height:15px;margin-right:1em}.slider-image.svelte-16iehjd{width:15px;height:15px;color:red;transform:rotate(180deg);cursor:grab;margin-right:0.2em;transition:margin-right 0.3s ease}.draggable.svelte-16iehjd{z-index:11;-webkit-touch-callout:none;-ms-touch-action:none;touch-action:none;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}.selected.svelte-16iehjd{transition:background-color 0.3s ease;background-color:rgb(0, 122, 255) !important;color:rgb(242, 242, 247) !important} .chat-slider-button.svelte-1os2k6f{height:3em} diff --git a/build/bundle.js b/build/bundle.js index 609e0bd..a144a8f 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -1,2 +1,2 @@ -var app=function(){"use strict";function e(){}function t(e){return e()}function n(){return Object.create(null)}function r(e){e.forEach(t)}function i(e){return"function"==typeof e}function a(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}let o,s;function l(e,t){return e===t||(o||(o=document.createElement("a")),o.href=t,e===o.href)}function c(e,t){e.appendChild(t)}function d(e,t,n){e.insertBefore(t,n||null)}function u(e){e.parentNode&&e.parentNode.removeChild(e)}function p(e){return document.createElement(e)}function _(e){return document.createTextNode(e)}function m(){return _(" ")}function g(){return _("")}function h(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function f(e,t,n){null==n?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function E(e,t,n){const r=t.toLowerCase();r in e?e[r]="boolean"==typeof e[r]&&""===n||n:t in e?e[t]="boolean"==typeof e[t]&&""===n||n:f(e,t,n)}function S(e,t){t=""+t,e.data!==t&&(e.data=t)}function b(e,t,n,r){null==n?e.style.removeProperty(t):e.style.setProperty(t,n,r?"important":"")}function v(e,t,n){e.classList.toggle(t,!!n)}function y(e){s=e}function T(e){(function(){if(!s)throw new Error("Function called outside component initialization");return s})().$$.on_mount.push(e)}const C=[],R=[];let O=[];const N=[],A=Promise.resolve();let I=!1;function w(e){O.push(e)}function x(e){N.push(e)}const D=new Set;let M=0;function k(){if(0!==M)return;const e=s;do{try{for(;M{P.delete(e),r&&(n&&e.d(1),r())})),e.o(t)}else r&&r()}function H(e){return void 0!==e?.length?e:Array.from(e)}function z(e,t,n){const r=e.$$.props[t];void 0!==r&&(e.$$.bound[r]=n,n(e.$$.ctx[r]))}function q(e){e&&e.c()}function V(e,n,a){const{fragment:o,after_update:s}=e.$$;o&&o.m(n,a),w((()=>{const n=e.$$.on_mount.map(t).filter(i);e.$$.on_destroy?e.$$.on_destroy.push(...n):r(n),e.$$.on_mount=[]})),s.forEach(w)}function j(e,t){const n=e.$$;null!==n.fragment&&(!function(e){const t=[],n=[];O.forEach((r=>-1===e.indexOf(r)?t.push(r):n.push(r))),n.forEach((e=>e())),O=t}(n.after_update),r(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function $(e,t){-1===e.$$.dirty[0]&&(C.push(e),I||(I=!0,A.then(k)),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<{const i=r.length?r[0]:n;return m.ctx&&l(m.ctx[e],m.ctx[e]=i)&&(!m.skip_bound&&m.bound[e]&&m.bound[e](i),g&&$(t,e)),n})):[],m.update(),g=!0,r(m.before_update),m.fragment=!!o&&o(m.ctx),i.target){if(i.hydrate){const e=function(e){return Array.from(e.childNodes)}(i.target);m.fragment&&m.fragment.l(e),e.forEach(u)}else m.fragment&&m.fragment.c();i.intro&&G(t.$$.fragment),V(t,i.target,i.anchor),k()}y(_)}class K{$$=void 0;$$set=void 0;$destroy(){j(this,1),this.$destroy=e}$on(t,n){if(!i(n))return e;const r=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return r.push(n),()=>{const e=r.indexOf(n);-1!==e&&r.splice(e,1)}}$set(e){var t;this.$$set&&(t=e,0!==Object.keys(t).length)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}function Q(e){return function(e){if(Array.isArray(e))return J(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Z(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function X(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=Z(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function Z(e,t){if(e){if("string"==typeof e)return J(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?J(e,t):void 0}}function J(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var l=r.call(o,"catchLoc"),c=r.call(o,"finallyLoc");if(l&&c){if(this.prev=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),I(n),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;I(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:x(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),h}},t}function le(e,t,n,r,i,a,o){try{var s=e[a](o),l=s.value}catch(e){return void n(e)}s.done?t(l):Promise.resolve(l).then(r,i)}function ce(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function o(e){le(a,r,i,o,s,"next",e)}function s(e){le(a,r,i,o,s,"throw",e)}o(void 0)}))}}function de(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function ue(e){for(var t=1;t=t&&!e.PERMITTED_KEYS.has(n.key)&&!e.isKeyCombinationPermitted(n)&&n.preventDefault()}},{key:"isKeyCombinationPermitted",value:function(e){return"a"===e.key&&(e.ctrlKey||e.metaKey)}},{key:"onInput",value:function(e,t,n){var r=n.target,i=r.textContent||"";void 0!==e&&i.length>e&&(r.textContent=i.substring(0,e),we.focusEndOfInput(r)),null==t||t()}}]),e}();Re.PERMITTED_KEYS=new Set([Te.BACKSPACE,Te.DELETE,Te.ARROW_RIGHT,Te.ARROW_LEFT,Te.ARROW_DOWN,Te.ARROW_UP,Te.META,Te.CONTROL,Te.ENTER]);var Oe=Re,Ne=function(){function e(){me(this,e)}return he(e,null,[{key:"sanitizePastedTextContent",value:function(e){var t,n;e.preventDefault();var r=null==(t=e.clipboardData)?void 0:t.getData("text/plain");null==(n=document.execCommand)||n.call(document,"insertText",!1,r)}}]),e}(),Ae=function(){function e(t,n){var r,i=this;me(this,e);var a=e.processConfig(n,t.textInput);this.elementRef=e.createContainerElement(null==(r=null==a?void 0:a.styles)?void 0:r.container),this.inputElementRef=this.createInputElement(a),this._config=a,this.elementRef.appendChild(this.inputElementRef),setTimeout((function(){var e;Oe.add(i.inputElementRef,null==(e=t.textInput)?void 0:e.characterLimit,t._validationHandler)}))}return he(e,[{key:"createInputElement",value:function(t){var n,r,i,a=document.createElement("div");return a.id=e.TEXT_INPUT_ID,a.classList.add("text-input-styling","text-input-placeholder"),a.innerText=(null==(n=null==t?void 0:t.placeholder)?void 0:n.text)||"Ask me anything!",Ce.IS_CHROMIUM&&e.preventAutomaticScrollUpOnNewLine(a),"boolean"==typeof(null==t?void 0:t.disabled)&&!0===t.disabled?(a.contentEditable="false",a.classList.add("text-input-disabled")):(a.contentEditable="true",this.addEventListeners(a,t)),Object.assign(a.style,null==(r=null==t?void 0:t.styles)?void 0:r.text),Object.assign(a.style,null==(i=null==t?void 0:t.placeholder)?void 0:i.style),a}},{key:"removeTextIfPlaceholder",value:function(){var t,n,r,i;this.inputElementRef.classList.contains("text-input-placeholder")&&!this.inputElementRef.classList.contains("text-input-disabled")&&(null!=(t=this._config.placeholder)&&t.style&&(be.unsetStyle(this.inputElementRef,null==(n=this._config.placeholder)?void 0:n.style),Object.assign(this.inputElementRef.style,null==(i=null==(r=this._config)?void 0:r.styles)?void 0:i.text)),e.clear(this.inputElementRef),this.inputElementRef.classList.remove("text-input-placeholder"))}},{key:"addEventListeners",value:function(e,t){var n,r,i;e.onfocus=this.onFocus.bind(this,null==(n=null==t?void 0:t.styles)?void 0:n.focus),null!=(r=null==t?void 0:t.styles)&&r.focus&&(e.onblur=this.onBlur.bind(this,t.styles.focus,null==(i=null==t?void 0:t.styles)?void 0:i.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.onpaste=Ne.sanitizePastedTextContent}},{key:"onFocus",value:function(e){var t=this;Ce.IS_SAFARI?setTimeout((function(){t.removeTextIfPlaceholder()})):this.removeTextIfPlaceholder(),Object.assign(this.elementRef.style,e)}},{key:"onBlur",value:function(e,t){be.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef.style,t)}},{key:"onKeydown",value:function(e){var t;e.key===Te.ENTER&&!e.ctrlKey&&!e.shiftKey&&(e.preventDefault(),null==(t=this.submit)||t.call(this))}}],[{key:"processConfig",value:function(e,t){var n,r,i,a,o;return null!==(n=t)&&void 0!==n||(t={}),null!==(r=t.disabled)&&void 0!==r||(t.disabled=e.isTextInputDisabled),null!==(i=t.placeholder)&&void 0!==i||(t.placeholder={}),null!==(a=(o=t.placeholder).text)&&void 0!==a||(o.text=e.textInputPlaceholderText),t}},{key:"preventAutomaticScrollUpOnNewLine",value:function(e){var t;e.addEventListener("keydown",(function(){t=window.scrollY})),e.addEventListener("input",(function(){t!==window.scrollY&&window.scrollTo({top:t})}))}},{key:"clear",value:function(e){var t=window.scrollY;e.classList.contains("text-input-disabled")||(e.textContent=""),Ce.IS_CHROMIUM&&window.scrollTo({top:t})}},{key:"toggleEditability",value:function(e,t){e.contentEditable=t?"true":"false"}},{key:"createContainerElement",value:function(e){var t=document.createElement("div");return t.id="text-input-container",Object.assign(t.style,e),t}}]),e}();Ae.TEXT_INPUT_ID="text-input";var Ie=Ae,we=function(){function e(){me(this,e)}return he(e,null,[{key:"focusEndOfInput",value:function(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();null==n||n.removeAllRanges(),null==n||n.addRange(t)}},{key:"focusFromParentElement",value:function(t){var n=t.querySelector("#".concat(Ie.TEXT_INPUT_ID));n&&e.focusEndOfInput(n)}}]),e}();function xe(e){return e.charAt(0).toUpperCase()+e.slice(1)}function De(e,t,n,r){var i="\n".concat(xe(t)," message: ").concat(JSON.stringify(e)," \n"),a=n?"".concat(xe(t)," message after interceptor: ").concat(function(e){return e&&JSON.stringify(e)}(r)," \n"):"";return i+a}var Me="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor",ke={INVALID_KEY:"Invalid API Key",CONNECTION_FAILED:"Failed to connect",INVALID_RESPONSE:function(e,t,n,r){return"".concat(De(e,t,n,r),"Make sure the ").concat(t," message is using the Response format: https://deepchat.dev/docs/connect/#Response \nYou can also augment it using the responseInterceptor property: https://deepchat.dev/docs/interceptors#responseInterceptor")},INVALID_MODEL_REQUEST:function(e,t){var n="request";return"".concat(De(e,n,t),"Make sure the ").concat(n,' message is using the {body: {text: string}} format, e.g: {body: {text: "Model Response"}}')},INVALID_MODEL_RESPONSE:function(e,t,n){var r="response";return"".concat(De(e,r,t,n),"Make sure the ").concat(r,' message is using the {text: string} format, e.g: {text: "Model Response"}')},INVALID_STREAM_EVENT:Me,INVALID_STREAM_EVENT_MIX:"Cannot mix {text: string} and {html: string} responses.",NO_VALID_STREAM_EVENTS_SENT:"No valid stream events were sent.\n".concat(Me)},Le=function(){function e(){me(this,e)}return he(e,null,[{key:"addElements",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r=n-r-e.CODE_SNIPPET_GENERATION_JUMP}},{key:"cloneElement",value:function(e){var t=e.cloneNode(!0);return e.parentNode.replaceChild(t,e),t}},{key:"scrollToBottom",value:function(e){e.scrollTop=e.scrollHeight}},{key:"scrollToTop",value:function(e){e.scrollTop=0}}]),e}();Le.CODE_SNIPPET_GENERATION_JUMP=.5;var Pe=Le,Fe=function(){function e(){me(this,e)}return he(e,null,[{key:"speak",value:function(e,t){if(window.SpeechSynthesisUtterance){var n=new SpeechSynthesisUtterance(e);Object.assign(n,t),speechSynthesis.speak(n)}}},{key:"processConfig",value:function(t,n){var r={};setTimeout((function(){if("object"==_e(t)&&(t.lang&&(r.lang=t.lang),t.pitch&&(r.pitch=t.pitch),t.rate&&(r.rate=t.rate),t.volume&&(r.volume=t.volume),t.voiceName)){var e=window.speechSynthesis.getVoices().find((function(e){var n;return e.name.toLocaleLowerCase()===(null==(n=t.voiceName)?void 0:n.toLocaleLowerCase())}));e&&(r.voice=e)}n(r)}),e.LOAD_VOICES_MS)}}]),e}();Fe.LOAD_VOICES_MS=200;var Ue=Fe,Be=function(){function e(){me(this,e)}return he(e,null,[{key:"checkForContainerStyles",value:function(e,t){var n=e.containerStyle;n&&(Object.assign(t.style,n),console.error("The containerStyle property is deprecated since version 1.3.14."),console.error("Please change to using the style property instead: https://deepchat.dev/docs/styles#style"))}},{key:"handleResponseProperty",value:function(e){return console.error("The {result: ....} response object type is deprecated since version 1.3.0."),console.error("Please change to using the new response object: https://deepchat.dev/docs/connect#Response"),e.result}},{key:"processInitialMessageFile",value:function(e){var t=e.file;t&&(console.error("The file property in MessageContent is deprecated since version 1.3.17."),console.error("Please change to using the files array property: https://deepchat.dev/docs/messages/#MessageContent"),e.files=[t])}},{key:"processValidateInput",value:function(e){var t=e.validateMessageBeforeSending;if(t)return console.error("The validateMessageBeforeSending property is deprecated since version 1.3.24."),console.error("Please change to using validateInput: https://deepchat.dev/docs/interceptors#validateInput"),t}},{key:"processSubmitUserMessage",value:function(e){return console.error("The submitUserMessage(text: string) argument string type is deprecated since version 1.4.4."),console.error("Please change to using the new argument type: https://deepchat.dev/docs/methods#submitUserMessage"),{text:e}}},{key:"flagHTMLUpdateClass",value:function(e){var t;null!=(t=e.children[0])&&t.classList.contains("deep-chat-update-message")&&(console.error('The "deep-chat-update-message" html class is deprecated since version 1.4.4.'),console.error("Please change to using {..., overwrite: true} object: https://deepchat.dev/docs/connect#Response"))}}]),e}(),Ge=function(){function e(){me(this,e)}return he(e,null,[{key:"hide",value:function(t){t.getElementsByClassName(e.CONTAINER_CLASS)[0].style.visibility="hidden"}},{key:"applyCustomStylesToElements",value:function(e,t,n){Object.assign(e.style,n.container),Object.assign(t.style,n.avatar)}},{key:"applyCustomStyles",value:function(t,n,r,i){var a,o,s,l;if(null!=(a=r.default)&&a.styles&&e.applyCustomStylesToElements(t,n,r.default.styles),i===je.USER_ROLE)null!=(o=r.user)&&o.styles&&e.applyCustomStylesToElements(t,n,r.user.styles);else{null!=(s=r.ai)&&s.styles&&e.applyCustomStylesToElements(t,n,r.ai.styles);var c=null==(l=r[i])?void 0:l.styles;c&&e.applyCustomStylesToElements(t,n,c)}}},{key:"createAvatar",value:function(t,n){var r,i,a,o,s,l=document.createElement("img");t===je.USER_ROLE?l.src=(null==(r=null==n?void 0:n.user)?void 0:r.src)||(null==(i=null==n?void 0:n.default)?void 0:i.src)||"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAMAAAC/MqoPAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAADNQTFRF////9vX18vLy/Pz86enp4+Li2tnZ1tbWzczM+fn57Ozs4N/f09LS0M/P5uXl7+/v3dzcwtncCAAAAAFiS0dEAIgFHUgAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAZNSURBVHja7d3bdtsqEABQYABZSLH9/3+ZpnUsIcF5iOM6PfElNoMHMfPQdq3GmL0GkLhEUqLaUExnOtOZznSmM53pTGc605nOdKYznelMZzrTmV4LXSqllKyJDkob26xWq8Zae/iH0QoWTm9d1xur4WuypQJtTd+5dqn0VjcxzNO5/57mEBvdLo8Oron6aseWOjYOFkVvjQs3DmgyONMuht52EfztP+4hdu0i6LCO808/M8c1lE/fuPGej41uUzgdtoO/75N+2ELJ9I3b3//hPXbiMenm3pR/Jt4USgcLBIp4Bh10gqKVhvLo0klCxeSky96nKcj3siw6pJIL4XsoiQ7apyvMY/V3HHrSRioLopvEhSpTCn2TPEuwKYMOIX0tAxRBf/Hpa+lfSqBv9gi1FPsNfTrMAiVmIE/vJhz61FGnQxRIEYE4vfNYdN8Rp6MlHaHotHTn8ejekaZPAjEmyvQWdZFTtYTpXqCGJ0zvcek9Yfoel76nS0ffv1NMp1ca+pkgyfRCGind4L7OWWc605l+cxjsyhqy9AGbPpClc1/nvl5VX0c/3Alk6RU3+Am7shNZ+h6bvidLr7jBB+zKBrL0irOOudmIUDzTmf5gIP+iEuXtRuTVaEmY/oZLfyNMrzjryPc0gerMTdpVg0tvjJUU6bLPcGOoUv46SLL6Wi8yhLf06C7TUyekI0efRaaYqdFltkeNpPumRPSMDxgBYvSM035FrKAmH72hRW99PrpvSdEHkTEGUvSsK3yKVDkuJ92RohcZaehzzirPpOg+J92Tolfc4Cumx5xVXpGiZ34+ICX6W84qv5GiR5NPbiIpOv6BCoSvSkTX+eiaGP092zINvBOj4x8mSf9FqejvNo/cvpOji19ZbmviL0GPLsYMFzgzCor0+Bv/ePDvSJKOb9dJ5UlnbnEHiHgzv6cdTpJOWuc/u3FEucLDOL75xGtBiefrcwgoC9NDSH/jkH6pAuXmBqPQ9HSUPVdZBH1GGOrMXAQdYxcKZfxAoK+KKBKFLosoEoX+u4giUehz8jlcnAuhp78I46yDYNAd+QLR6K+pr+yvxdBTHyVDubQh0UfSxaHSd0lbvNkVRE87JGOtc+PQd2QLQ6fHhJkKsSh6yg13tO08JPprsgrrXWH0dJd2vH1MLPprot4eXoujpzrdhngiD40ek2y92lggPcnWa8qN1Yz0BFuvZhRl0uOfR0v4Ewuli/Bg4Qr3lArqGdndQ3UPO1EunXYwnelMZzrTmc50pjOd6UxnOtOZznSmM53pTGf6kuj6oedFKV0s3fX6sX1S3bsi6a4PD7+/YAqYeBw6pIB/4qEgOqxdSPbGiim4NRRCbzs3Jj0L4UfXtQXQVRfn5IdA/Bw7RZzurEV6EtdsLeGXkIPuA+K1UoVeA0l62zmN/LqfSSft9KkepmoRuvi3nd5uKNFB9zbbXEANqdr941XO0NJx2v2jdJenpf+/3bvn0ts16ph+sd6hX7dPo2+2cZzE02Ia43bzDHqr+2Evnhz74ZHU30ffbKOeng1/NPV30Ns1gYQnSP2P6e65Pfxc6h02XZqXQCjhJ6kPL6bFo4NrGvAU4UII4SE2P1vQuZkuOxckVfehisF1MjUddN/MZBN+kvq5uf0O/xa66gyNS9ktMWlz44rO1Z8C19i5FPdHzPamXn+F3hryPfxMr78+4F+kq22kO6Rf6fUQt+puuustyWv4rbG3l/duztFB96GYoe1cTBdXMr+nw9qVM6ZfxOvzezff0nXi/ZOndvrR6Zvpm0c3h6nhdb+5iS7tsIim/qXZD9+97/Jf+rpZ5BET1ayv0GUzLhEuhBBjIy/RdVPgndutIRt9nt7p5cKFEEJ3Z+jQFDZL+XnMDXxHB73gxn5s9Kc3d3/pFciFkN/QTSXHJpX5l66gDrkQoP6hL3xsPw39la4qOiV8tH78XeSbue6N9mvWa6J/ybpc1CT1Wnh5Qq9meP8IOKH3ddH7E/ri1iYux/SXDrXR4UiPdck/wUpU+FtPf6/orja6O9KL3l56LOvVxe5Ib2qjN0d6Vbex4ghWlU3bPqI90If66MNng680FNpbJijH6kCvaF3uMzQ3+IrpFerV4Y9dffQdN3im10ivbuImhD3Qq5u4HdZkua8znelMZ/pS4z9CPVKkxowNxgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNy0wMy0yN1QxNTo0NToxNSswMDowMN1xSg4AAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTctMDMtMjdUMTU6NDU6MTUrMDA6MDCsLPKyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAABJRU5ErkJggg==":l.src=(null==(a=null==n?void 0:n[t])?void 0:a.src)||(null==(o=null==n?void 0:n.ai)?void 0:o.src)||(null==(s=null==n?void 0:n.default)?void 0:s.src)||"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8c3ZnIGZpbGw9IiMwMDAwMDAiIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIAoJCXZpZXdCb3g9IjAgMCAzMiAzMiIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+Cgk8cGF0aCBkPSJNMjMsMzAuMzZIOWMtMi40MDQsMC00LjM2LTEuOTU2LTQuMzYtNC4zNlYxNWMwLTIuNDA0LDEuOTU2LTQuMzYsNC4zNi00LjM2aDMuNjU5CgkJYzAuMTY3LTEuNTY2LDEuNDE1LTIuODEzLDIuOTgxLTIuOTgxVjUuMzMzYy0xLjEzMS0wLjE3NC0yLTEuMTU0LTItMi4zMzNjMC0xLjMwMSwxLjA1OS0yLjM2LDIuMzYtMi4zNgoJCWMxLjMwMiwwLDIuMzYsMS4wNTksMi4zNiwyLjM2YzAsMS4xNzktMC44NjksMi4xNTktMiwyLjMzM1Y3LjY2YzEuNTY2LDAuMTY3LDIuODE0LDEuNDE1LDIuOTgxLDIuOTgxSDIzCgkJYzIuNDA0LDAsNC4zNiwxLjk1Niw0LjM2LDQuMzZ2MTFDMjcuMzYsMjguNDA0LDI1LjQwNCwzMC4zNiwyMywzMC4zNnogTTksMTEuMzZjLTIuMDA3LDAtMy42NCwxLjYzMy0zLjY0LDMuNjR2MTEKCQljMCwyLjAwNywxLjYzMywzLjY0LDMuNjQsMy42NGgxNGMyLjAwNywwLDMuNjQtMS42MzMsMy42NC0zLjY0VjE1YzAtMi4wMDctMS42MzMtMy42NC0zLjY0LTMuNjRIOXogTTEzLjM4NCwxMC42NGg1LjIzMQoJCUMxOC40MzksOS4zNTQsMTcuMzM0LDguMzYsMTYsOC4zNkMxNC42NjcsOC4zNiwxMy41NjEsOS4zNTQsMTMuMzg0LDEwLjY0eiBNMTYsMS4zNmMtMC45MDQsMC0xLjY0LDAuNzM2LTEuNjQsMS42NAoJCVMxNS4wOTYsNC42NCwxNiw0LjY0YzAuOTA0LDAsMS42NC0wLjczNiwxLjY0LTEuNjRTMTYuOTA0LDEuMzYsMTYsMS4zNnogTTIwLDI3LjM2aC04Yy0xLjMwMSwwLTIuMzYtMS4wNTktMi4zNi0yLjM2CgkJczEuMDU5LTIuMzYsMi4zNi0yLjM2aDhjMS4zMDIsMCwyLjM2LDEuMDU5LDIuMzYsMi4zNlMyMS4zMDIsMjcuMzYsMjAsMjcuMzZ6IE0xMiwyMy4zNmMtMC45MDQsMC0xLjY0LDAuNzM1LTEuNjQsMS42NAoJCXMwLjczNiwxLjY0LDEuNjQsMS42NGg4YzAuOTA0LDAsMS42NC0wLjczNSwxLjY0LTEuNjRzLTAuNzM1LTEuNjQtMS42NC0xLjY0SDEyeiBNMzEsMjMuODZoLTJjLTAuMTk5LDAtMC4zNi0wLjE2MS0wLjM2LTAuMzZWMTUKCQljMC0wLjE5OSwwLjE2MS0wLjM2LDAuMzYtMC4zNmgyYzAuMTk5LDAsMC4zNiwwLjE2MSwwLjM2LDAuMzZ2OC41QzMxLjM2LDIzLjY5OSwzMS4xOTksMjMuODYsMzEsMjMuODZ6IE0yOS4zNiwyMy4xNGgxLjI3OXYtNy43OAoJCUgyOS4zNlYyMy4xNHogTTMsMjMuODZIMWMtMC4xOTksMC0wLjM2LTAuMTYxLTAuMzYtMC4zNlYxNWMwLTAuMTk5LDAuMTYxLTAuMzYsMC4zNi0wLjM2aDJjMC4xOTksMCwwLjM2LDAuMTYxLDAuMzYsMC4zNnY4LjUKCQlDMy4zNiwyMy42OTksMy4xOTksMjMuODYsMywyMy44NnogTTEuMzYsMjMuMTRoMS4yOHYtNy43OEgxLjM2VjIzLjE0eiBNMjAsMjAuMzZjLTEuMzAyLDAtMi4zNi0xLjA1OS0yLjM2LTIuMzYKCQlzMS4wNTktMi4zNiwyLjM2LTIuMzZzMi4zNiwxLjA1OSwyLjM2LDIuMzZDMjIuMzYsMTkuMzAyLDIxLjMwMiwyMC4zNiwyMCwyMC4zNnogTTIwLDE2LjM2Yy0wLjkwNCwwLTEuNjQsMC43MzYtMS42NCwxLjY0CgkJczAuNzM1LDEuNjQsMS42NCwxLjY0czEuNjQtMC43MzUsMS42NC0xLjY0UzIwLjkwNCwxNi4zNiwyMCwxNi4zNnogTTEyLDIwLjM2Yy0xLjMwMSwwLTIuMzYtMS4wNTktMi4zNi0yLjM2czEuMDU5LTIuMzYsMi4zNi0yLjM2CgkJczIuMzYsMS4wNTksMi4zNiwyLjM2QzE0LjM2LDE5LjMwMiwxMy4zMDEsMjAuMzYsMTIsMjAuMzZ6IE0xMiwxNi4zNmMtMC45MDQsMC0xLjY0LDAuNzM2LTEuNjQsMS42NHMwLjczNiwxLjY0LDEuNjQsMS42NAoJCXMxLjY0LTAuNzM1LDEuNjQtMS42NFMxMi45MDQsMTYuMzYsMTIsMTYuMzZ6Ii8+Cgk8cmVjdCBzdHlsZT0iZmlsbDpub25lOyIgd2lkdGg9IjMyIiBoZWlnaHQ9IjMyIi8+Cjwvc3ZnPg==",l.classList.add("avatar");var c=document.createElement("div");return c.classList.add(e.CONTAINER_CLASS),c.appendChild(l),n&&e.applyCustomStyles(c,l,n,t),c}},{key:"getPosition",value:function(e,t){var n,r,i,a,o,s,l,c,d,u=null==(o=null==(a=null==t?void 0:t[e])?void 0:a.styles)?void 0:o.position;return e!==je.USER_ROLE&&(null!==(n=u)&&void 0!==n||(u=null==(l=null==(s=null==t?void 0:t.ai)?void 0:s.styles)?void 0:l.position)),null!==(r=u)&&void 0!==r||(u=null==(d=null==(c=null==t?void 0:t.default)?void 0:c.styles)?void 0:d.position),null!==(i=u)&&void 0!==i||(u=e===je.USER_ROLE?"right":"left"),u}},{key:"add",value:function(t,n,r){var i="boolean"==typeof r?void 0:r,a=e.createAvatar(n,i),o=e.getPosition(n,i);a.classList.add("left"===o?"left-item-position":"right-item-position"),t.insertAdjacentElement("left"===o?"beforebegin":"afterend",a)}}]),e}();Ge.CONTAINER_CLASS="avatar-container";var Ye=Ge,He=function(){function e(){me(this,e)}return he(e,null,[{key:"hide",value:function(t){t.getElementsByClassName(e.NAME_CLASS)[0].style.visibility="hidden"}},{key:"getPosition",value:function(e,t){var n,r,i,a,o,s,l=null==(a=null==t?void 0:t[e])?void 0:a.position;return e!==je.USER_ROLE&&(null!==(n=l)&&void 0!==n||(l=null==(o=null==t?void 0:t.ai)?void 0:o.position)),null!==(r=l)&&void 0!==r||(l=null==(s=null==t?void 0:t.default)?void 0:s.position),null!==(i=l)&&void 0!==i||(l=e===je.USER_ROLE?"right":"left"),l}},{key:"applyStyle",value:function(e,t,n){var r,i,a,o;Object.assign(e.style,null==(r=n.default)?void 0:r.style),t===je.USER_ROLE?Object.assign(e.style,null==(i=n.user)?void 0:i.style):(Object.assign(e.style,null==(a=n.ai)?void 0:a.style),Object.assign(e.style,null==(o=n[t])?void 0:o.style))}},{key:"getNameText",value:function(e,t){var n,r,i,a,o,s;return e===je.USER_ROLE?(null==(n=t.user)?void 0:n.text)||(null==(r=t.default)?void 0:r.text)||"User":e===je.AI_ROLE?(null==(i=t.ai)?void 0:i.text)||(null==(a=t.default)?void 0:a.text)||"AI":(null==(o=t[e])?void 0:o.text)||(null==(s=t.default)?void 0:s.text)||e}},{key:"createName",value:function(t,n){var r=document.createElement("div");return r.classList.add(e.NAME_CLASS),r.textContent=e.getNameText(t,n),e.applyStyle(r,t,n),r}},{key:"add",value:function(t,n,r){var i="boolean"==typeof r?{}:r,a=e.createName(n,i),o=e.getPosition(n,i);a.classList.add("left"===o?"left-item-position":"right-item-position"),t.insertAdjacentElement("left"===o?"beforebegin":"afterend",a)}}]),e}();He.NAME_CLASS="name";var ze=He,qe=function(){function e(){me(this,e)}return he(e,null,[{key:"getLastElementsByClass",value:function(e,t,n){for(var r,i=function(){var r=e[a];if(r.bubbleElement.classList.contains(t[0])&&!t.slice(1).find((function(e){return!r.bubbleElement.classList.contains(e)}))){if(!n)return{v:r};if(!n.find((function(e){return r.bubbleElement.classList.contains(e)})))return{v:r}}},a=e.length-1;a>=0;a-=1)if(r=i())return r.v}},{key:"getLastMessage",value:function(e,t,n){for(var r=e.length-1;r>=0;r-=1)if(e[r].role===t){if(!n)return e[r];if(e[r][n])return e[r]}}},{key:"getLastTextToElement",value:function(e,t){for(var n=e.length-1;n>=0;n-=1)if(e[n][0]===t)return e[n]}},{key:"overwriteMessage",value:function(t,n,r,i,a,o){var s=e.getLastElementsByClass(n,[e.getRoleClass(i),o],["loading-message-text"]),l=e.getLastMessage(t,i,a);return l&&(l[a]=r),s}},{key:"getRoleClass",value:function(e){return"".concat(e,"-message")}},{key:"fillEmptyMessageElement",value:function(t,n){0===n.trim().length&&(t.classList.add(e.EMPTY_MESSAGE_CLASS),t.innerHTML='
.
')}},{key:"unfillEmptyMessageElement",value:function(t,n){t.classList.contains(e.EMPTY_MESSAGE_CLASS)&&n.trim().length>0&&t.replaceChildren()}},{key:"getLastMessageBubbleElement",value:function(t){var n,r,i;return Array.from((null==(i=null==(r=null==(n=e.getLastMessageElement(t))?void 0:n.children)?void 0:r[0])?void 0:i.children)||[]).find((function(e){return e.classList.contains("message-bubble")}))}},{key:"getLastMessageElement",value:function(e){return e.children[e.children.length-1]}},{key:"addRoleElements",value:function(e,t,n,r){n&&Ye.add(e,t,n),r&&ze.add(e,t,r)}},{key:"hideRoleElements",value:function(e,t,n){var r=e[e.length-1].innerContainer;t&&Ye.hide(r),n&&ze.hide(r)}}]),e}();qe.AI_ROLE="ai",qe.USER_ROLE="user",qe.EMPTY_MESSAGE_CLASS="empty-message";var Ve,je=qe,$e=function(){function e(){me(this,e)}return he(e,null,[{key:"mouseUp",value:function(e,t){be.unsetAllCSSMouseStates(e,t),Object.assign(e.style,t.default),Object.assign(e.style,t.hover)}},{key:"mouseDown",value:function(e,t){Object.assign(e.style,t.click)}},{key:"mouseLeave",value:function(e,t){be.unsetAllCSSMouseStates(e,t),Object.assign(e.style,t.default)}},{key:"mouseEnter",value:function(e,t){Object.assign(e.style,t.hover)}},{key:"add",value:function(t,n){t.addEventListener("mouseenter",e.mouseEnter.bind(this,t,n)),t.addEventListener("mouseleave",e.mouseLeave.bind(this,t,n)),t.addEventListener("mousedown",e.mouseDown.bind(this,t,n)),t.addEventListener("mouseup",e.mouseUp.bind(this,t,n))}}]),e}(),We={"deep-chat-button":{styles:{default:{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"},hover:{backgroundColor:"#fafafa"},click:{backgroundColor:"#f1f1f1"}}}},Ke=Object.keys(We),Qe=function(){function e(){me(this,e)}return he(e,null,[{key:"applySuggestionEvent",value:function(e,t){setTimeout((function(){t.addEventListener("click",(function(){var n,r;null==(r=e.submitUserMessage)||r.call(e,{text:(null==(n=t.textContent)?void 0:n.trim())||""})}))}))}},{key:"isElementTemporary",value:function(e){var t;return!!e&&(null==(t=e.bubbleElement.children[0])?void 0:t.classList.contains("deep-chat-temporary-message"))}},{key:"doesElementContainDeepChatClass",value:function(e){return Ke.find((function(t){return e.classList.contains(t)}))}},{key:"applyEvents",value:function(e,t){var n=We[t].events;Object.keys(n||[]).forEach((function(t){e.addEventListener(t,null==n?void 0:n[t])}))}},{key:"getProcessedStyles",value:function(e,t,n){var r=Array.from(t.classList).reduce((function(t,n){var r,i=null==(r=e[n])?void 0:r.styles;return i&&e[n].styles&&t.push(i),t}),[]),i=We[n].styles;if(i){var a=JSON.parse(JSON.stringify(i));a.default&&be.overwriteDefaultWithAlreadyApplied(a,t),r.unshift(a)}var o=be.mergeStatefulStyles(r);return be.processStateful(o,{},{})}},{key:"applyDeepChatUtilities",value:function(t,n,r){Ke.forEach((function(t){var i=r.getElementsByClassName(t);Array.from(i||[]).forEach((function(r){var i=e.getProcessedStyles(n,r,t);Xe.applyStylesToElement(r,i),e.applyEvents(r,t)}))}));var i=r.getElementsByClassName("deep-chat-suggestion-button");Array.from(i).forEach((function(n){return e.applySuggestionEvent(t,n)}))}}]),e}(),Xe=function(){function e(){me(this,e)}return he(e,null,[{key:"applyStylesToElement",value:function(e,t){var n=be.processStateful(t,{},{});$e.add(e,n),Object.assign(e.style,n.default)}},{key:"applyEventsToElement",value:function(e,t){Object.keys(t).forEach((function(n){var r=t[n];r&&e.addEventListener(n,r)}))}},{key:"applyClassUtilitiesToElement",value:function(t,n){var r=n.events,i=n.styles;r&&e.applyEventsToElement(t,r),i&&!Qe.doesElementContainDeepChatClass(t)&&e.applyStylesToElement(t,i)}},{key:"applyCustomClassUtilities",value:function(t,n){Object.keys(t).forEach((function(r){var i=n.getElementsByClassName(r);Array.from(i).forEach((function(n){t[r]&&e.applyClassUtilitiesToElement(n,t[r])}))}))}},{key:"apply",value:function(t,n){Qe.applyDeepChatUtilities(t,t.htmlClassUtilities,n),e.applyCustomClassUtilities(t.htmlClassUtilities,n)}}]),e}(),Ze=function(){function e(){me(this,e)}return he(e,null,[{key:"addElement",value:function(e,t){e.elementRef.appendChild(t),e.elementRef.scrollTop=e.elementRef.scrollHeight}},{key:"createElements",value:function(e,t,n){var r=e.createNewMessageElement("",n);return r.bubbleElement.classList.add("html-message"),r.bubbleElement.innerHTML=t,r}},{key:"overwrite",value:function(e,t,n,r){var i=e.messages,a=je.overwriteMessage(i,r,t,n,"html","html-message");return a&&(a.bubbleElement.innerHTML=t,Xe.apply(e,a.outerContainer),Be.flagHTMLUpdateClass(a.bubbleElement)),a}},{key:"add",value:function(t,n,r,i,a){var o;if(null!=a&&a.status){var s=this.overwrite(t,n,r,i);if(s)return s;a.status=!1}var l=e.createElements(t,n,r);return je.fillEmptyMessageElement(l.bubbleElement,n),Xe.apply(t,l.outerContainer),Be.flagHTMLUpdateClass(l.bubbleElement),t.applyCustomStyles(l,r,!1,null==(o=t.messageStyles)?void 0:o.html),e.addElement(t,l.outerContainer),l}}]),e}();function Je(e){return(Ve=Ve||document.createElement("textarea")).innerHTML="&"+e+";",Ve.value}var et=Object.prototype.hasOwnProperty;function tt(e){return[].slice.call(arguments,1).forEach((function(t){if(t){if("object"!=_e(t))throw new TypeError(t+"must be object");Object.keys(t).forEach((function(n){e[n]=t[n]}))}})),e}var nt=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function rt(e){return e.indexOf("\\")<0?e:e.replace(nt,"$1")}function it(e){return!(e>=55296&&e<=57343||e>=64976&&e<=65007||65535==(65535&e)||65534==(65535&e)||e>=0&&e<=8||11===e||e>=14&&e<=31||e>=127&&e<=159||e>1114111)}function at(e){if(e>65535){var t=55296+((e-=65536)>>10),n=56320+(1023&e);return String.fromCharCode(t,n)}return String.fromCharCode(e)}var ot=/&([a-z#][a-z0-9]{1,31});/gi,st=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function lt(e,t){var n=0,r=Je(t);return t!==r?r:35===t.charCodeAt(0)&&st.test(t)&&it(n="x"===t[1].toLowerCase()?parseInt(t.slice(2),16):parseInt(t.slice(1),10))?at(n):e}function ct(e){return e.indexOf("&")<0?e:e.replace(ot,lt)}var dt=/[&<>"]/,ut=/[&<>"]/g,pt={"&":"&","<":"<",">":">",'"':"""};function _t(e){return pt[e]}function mt(e){return dt.test(e)?e.replace(ut,_t):e}var gt={};function ht(e,t){return++t>=e.length-2?t:"paragraph_open"===e[t].type&&e[t].tight&&"inline"===e[t+1].type&&0===e[t+1].content.length&&"paragraph_close"===e[t+2].type&&e[t+2].tight?ht(e,t+2):t}gt.blockquote_open=function(){return"
\n"},gt.blockquote_close=function(e,t){return"
"+ft(e,t)},gt.code=function(e,t){return e[t].block?"
"+mt(e[t].content)+"
"+ft(e,t):""+mt(e[t].content)+""},gt.fence=function(e,t,n,r,i){var a,o,s=e[t],l="",c=n.langPrefix;if(s.params){if(o=(a=s.params.split(/\s+/g)).join(" "),function(e,t){return!!e&&et.call(e,t)}(i.rules.fence_custom,a[0]))return i.rules.fence_custom[a[0]](e,t,n,r,i);l=' class="'+c+mt(ct(rt(o)))+'"'}return"
"+(n.highlight&&n.highlight.apply(n.highlight,[s.content].concat(a))||mt(s.content))+"
"+ft(e,t)},gt.fence_custom={},gt.heading_open=function(e,t){return""},gt.heading_close=function(e,t){return"\n"},gt.hr=function(e,t,n){return(n.xhtmlOut?"
":"
")+ft(e,t)},gt.bullet_list_open=function(){return"
    \n"},gt.bullet_list_close=function(e,t){return"
"+ft(e,t)},gt.list_item_open=function(){return"
  • "},gt.list_item_close=function(){return"
  • \n"},gt.ordered_list_open=function(e,t){var n=e[t];return"1?' start="'+n.order+'"':"")+">\n"},gt.ordered_list_close=function(e,t){return""+ft(e,t)},gt.paragraph_open=function(e,t){return e[t].tight?"":"

    "},gt.paragraph_close=function(e,t){var n=!(e[t].tight&&t&&"inline"===e[t-1].type&&!e[t-1].content);return(e[t].tight?"":"

    ")+(n?ft(e,t):"")},gt.link_open=function(e,t,n){var r=e[t].title?' title="'+mt(ct(e[t].title))+'"':"",i=n.linkTarget?' target="'+n.linkTarget+'"':"";return'"},gt.link_close=function(){return""},gt.image=function(e,t,n){var r=' src="'+mt(e[t].src)+'"',i=e[t].title?' title="'+mt(ct(e[t].title))+'"':"";return""},gt.table_open=function(){return"\n"},gt.table_close=function(){return"
    \n"},gt.thead_open=function(){return"\n"},gt.thead_close=function(){return"\n"},gt.tbody_open=function(){return"\n"},gt.tbody_close=function(){return"\n"},gt.tr_open=function(){return""},gt.tr_close=function(){return"\n"},gt.th_open=function(e,t){var n=e[t];return""},gt.th_close=function(){return""},gt.td_open=function(e,t){var n=e[t];return""},gt.td_close=function(){return""},gt.strong_open=function(){return""},gt.strong_close=function(){return""},gt.em_open=function(){return""},gt.em_close=function(){return""},gt.del_open=function(){return""},gt.del_close=function(){return""},gt.ins_open=function(){return""},gt.ins_close=function(){return""},gt.mark_open=function(){return""},gt.mark_close=function(){return""},gt.sub=function(e,t){return""+mt(e[t].content)+""},gt.sup=function(e,t){return""+mt(e[t].content)+""},gt.hardbreak=function(e,t,n){return n.xhtmlOut?"
    \n":"
    \n"},gt.softbreak=function(e,t,n){return n.breaks?n.xhtmlOut?"
    \n":"
    \n":"\n"},gt.text=function(e,t){return mt(e[t].content)},gt.htmlblock=function(e,t){return e[t].content},gt.htmltag=function(e,t){return e[t].content},gt.abbr_open=function(e,t){return''},gt.abbr_close=function(){return""},gt.footnote_ref=function(e,t){var n=Number(e[t].id+1).toString(),r="fnref"+n;return e[t].subId>0&&(r+=":"+e[t].subId),'['+n+"]"},gt.footnote_block_open=function(e,t,n){return(n.xhtmlOut?'
    \n':'
    \n')+'
    \n
      \n'},gt.footnote_block_close=function(){return"
    \n
    \n"},gt.footnote_open=function(e,t){return'
  • '},gt.footnote_close=function(){return"
  • \n"},gt.footnote_anchor=function(e,t){var n="fnref"+Number(e[t].id+1).toString();return e[t].subId>0&&(n+=":"+e[t].subId),' '},gt.dl_open=function(){return"
    \n"},gt.dt_open=function(){return"
    "},gt.dd_open=function(){return"
    "},gt.dl_close=function(){return"
    \n"},gt.dt_close=function(){return"\n"},gt.dd_close=function(){return"\n"};var ft=gt.getBreak=function(e,t){return(t=ht(e,t))"u"&&(r.abbreviations[":"+l]=c),o)}function Tt(e){var t=ct(e);try{t=decodeURI(t)}catch(e){}return encodeURI(t)}function Ct(e,t){var n,r,i,a=t,o=e.posMax;if(60===e.src.charCodeAt(t)){for(t++;t1||41===n&&--r<0)break;t++}return!(a===t||(i=rt(e.src.slice(a,t)),!e.parser.validateLink(i)))&&(e.linkContent=i,e.pos=t,!0)}function Rt(e,t){var n,r=t,i=e.posMax,a=e.src.charCodeAt(t);if(34!==a&&39!==a&&40!==a)return!1;for(t++,40===a&&(a=41);t"u"&&(r.references[p]={title:u,href:d}),o)}Et.prototype.renderInline=function(e,t,n){for(var r=this.rules,i=e.length,a=0,o="";i--;)o+=r[e[a].type](e,a++,t,n,this);return o},Et.prototype.render=function(e,t,n){for(var r=this.rules,i=e.length,a=-1,o="";++a=e.length)&&!Pt.test(e[t])}function Ut(e,t,n){return e.substr(0,t)+n+e.substr(t+1)}var Bt=[["block",function(e){e.inlineMode?e.tokens.push({type:"inline",content:e.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):e.block.parse(e.src,e.options,e.env,e.tokens)}],["abbr",function(e){var t,n,r,i,a=e.tokens;if(!e.inlineMode)for(t=1,n=a.length-1;t0?o[t].count:1,r=0;r=0;t--)if("text"===(a=i[t]).type){for(l=0,o=a.content,d.lastIndex=0,c=a.level,s=[];u=d.exec(o);)d.lastIndex>l&&s.push({type:"text",content:o.slice(l,u.index+u[1].length),level:c}),s.push({type:"abbr_open",title:e.env.abbreviations[":"+u[2]],level:c++}),s.push({type:"text",content:u[2],level:c}),s.push({type:"abbr_close",level:--c}),l=d.lastIndex-u[3].length;s.length&&(l=0;a--)if("inline"===e.tokens[a].type)for(t=(i=e.tokens[a].children).length-1;t>=0;t--)"text"===(n=i[t]).type&&(r=Mt(r=n.content),wt.test(r)&&(r=r.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/gm,"$1—$2").replace(/(^|\s)--(\s|$)/gm,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/gm,"$1–$2")),n.content=r)}],["smartquotes",function(e){var t,n,r,i,a,o,s,l,c,d,u,p,_,m,g,h,f;if(e.options.typographer)for(f=[],g=e.tokens.length-1;g>=0;g--)if("inline"===e.tokens[g].type)for(h=e.tokens[g].children,f.length=0,t=0;t=0&&!(f[_].level<=s);_--);f.length=_+1,a=0,o=(r=n.content).length;e:for(;a=0&&(d=f[_],!(f[_].level=(i=e.eMarks[t])||42!==(n=e.src.charCodeAt(r++))&&45!==n&&43!==n||r=i||((n=e.src.charCodeAt(r++))<48||n>57))return-1;for(;;){if(r>=i)return-1;if(!((n=e.src.charCodeAt(r++))>=48&&n<=57)){if(41===n||46===n)break;return-1}}return r=this.eMarks[e]},Yt.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;en;)if(t!==this.src.charCodeAt(--e))return e+1;return e},Yt.prototype.getLines=function(e,t,n,r){var i,a,o,s,l,c=e;if(e>=t)return"";if(c+1===t)return a=this.bMarks[c]+Math.min(this.tShift[c],n),o=r?this.eMarks[c]+1:this.eMarks[c],this.src.slice(a,o);for(s=new Array(t-e),i=0;cn&&(l=n),l<0&&(l=0),a=this.bMarks[c]+l,o=c+1]/,jt=/^<\/([a-zA-Z]{1,15})[\s>]/;function $t(e,t){var n=e.bMarks[t]+e.blkIndent,r=e.eMarks[t];return e.src.substr(n,r-n)}function Wt(e,t){var n,r,i=e.bMarks[t]+e.tShift[t],a=e.eMarks[t];return i>=a||126!==(r=e.src.charCodeAt(i++))&&58!==r||i===(n=e.skipSpaces(i))||n>=a?-1:n}var Kt=[["code",function(e,t,n){var r,i;if(e.tShift[t]-e.blkIndent<4)return!1;for(i=r=t+1;r=4))break;i=++r}return e.line=r,e.tokens.push({type:"code",content:e.getLines(t,i,4+e.blkIndent,!0),block:!0,lines:[t,e.line],level:e.level}),!0}],["fences",function(e,t,n,r){var i,a,o,s,l,c=!1,d=e.bMarks[t]+e.tShift[t],u=e.eMarks[t];if(d+3>u||126!==(i=e.src.charCodeAt(d))&&96!==i||(l=d,(a=(d=e.skipChars(d,i))-l)<3)||(o=e.src.slice(d,u).trim()).indexOf("`")>=0)return!1;if(r)return!0;for(s=t;!(++s>=n||(d=l=e.bMarks[s]+e.tShift[s],u=e.eMarks[s],d=4||(d=e.skipChars(d,i),d-lh||62!==e.src.charCodeAt(g++)||e.level>=e.options.maxNesting)return!1;if(r)return!0;for(32===e.src.charCodeAt(g)&&g++,l=e.blkIndent,e.blkIndent=0,s=[e.bMarks[t]],e.bMarks[t]=g,a=(g=g=h,o=[e.tShift[t]],e.tShift[t]=g-e.bMarks[t],u=e.parser.ruler.getRules("blockquote"),i=t+1;i=(h=e.eMarks[i]));i++)if(62!==e.src.charCodeAt(g++)){if(a)break;for(m=!1,p=0,_=u.length;p<_;p++)if(u[p](e,i,n,!0)){m=!0;break}if(m)break;s.push(e.bMarks[i]),o.push(e.tShift[i]),e.tShift[i]=-1337}else 32===e.src.charCodeAt(g)&&g++,s.push(e.bMarks[i]),e.bMarks[i]=g,a=(g=g=h,o.push(e.tShift[i]),e.tShift[i]=g-e.bMarks[i];for(c=e.parentType,e.parentType="blockquote",e.tokens.push({type:"blockquote_open",lines:d=[t,0],level:e.level++}),e.parser.tokenize(e,t,i),e.tokens.push({type:"blockquote_close",level:--e.level}),e.parentType=c,d[1]=e.line,p=0;pl||42!==(i=e.src.charCodeAt(s++))&&45!==i&&95!==i)return!1;for(a=1;s=0)g=!0;else{if(!((u=Ht(e,t))>=0))return!1;g=!1}if(e.level>=e.options.maxNesting)return!1;if(m=e.src.charCodeAt(u-1),r)return!0;for(f=e.tokens.length,g?(d=e.bMarks[t]+e.tShift[t],_=Number(e.src.substr(d,u-d-1)),e.tokens.push({type:"ordered_list_open",order:_,lines:S=[t,0],level:e.level++})):e.tokens.push({type:"bullet_list_open",lines:S=[t,0],level:e.level++}),i=t,E=!1,v=e.parser.ruler.getRules("list");i=e.eMarks[i]?1:h-u)>4&&(p=1),p<1&&(p=1),a=u-e.bMarks[i]+p,e.tokens.push({type:"list_item_open",lines:b=[t,0],level:e.level++}),s=e.blkIndent,l=e.tight,o=e.tShift[t],c=e.parentType,e.tShift[t]=h-e.bMarks[t],e.blkIndent=a,e.tight=!0,e.parentType="list",e.parser.tokenize(e,t,n,!0),(!e.tight||E)&&(R=!1),E=e.line-t>1&&e.isEmpty(e.line-1),e.blkIndent=s,e.tShift[t]=o,e.tight=l,e.parentType=c,e.tokens.push({type:"list_item_close",level:--e.level}),i=t=e.line,b[1]=i,h=e.bMarks[t],!(i>=n||e.isEmpty(i)||e.tShift[i]d||91!==e.src.charCodeAt(c)||94!==e.src.charCodeAt(c+1)||e.level>=e.options.maxNesting)return!1;for(s=c+2;s=d||58!==e.src.charCodeAt(++s))&&(r||(s++,e.env.footnotes||(e.env.footnotes={}),e.env.footnotes.refs||(e.env.footnotes.refs={}),l=e.src.slice(c+2,s-2),e.env.footnotes.refs[":"+l]=-1,e.tokens.push({type:"footnote_reference_open",label:l,level:e.level++}),i=e.bMarks[t],a=e.tShift[t],o=e.parentType,e.tShift[t]=e.skipSpaces(s)-s,e.bMarks[t]=s,e.blkIndent+=4,e.parentType="footnote",e.tShift[t]=l||(35!==(i=e.src.charCodeAt(s))||s>=l))return!1;for(a=1,i=e.src.charCodeAt(++s);35===i&&s6||ss&&32===e.src.charCodeAt(o-1)&&(l=o),e.line=t+1,e.tokens.push({type:"heading_open",hLevel:a,lines:[t,e.line],level:e.level}),s=n||e.tShift[o]3||(i=e.bMarks[o]+e.tShift[o],a=e.eMarks[o],i>=a)||(r=e.src.charCodeAt(i),45!==r&&61!==r)||(i=e.skipChars(i,r),i=e.skipSpaces(i),i3||s+2>=l||60!==e.src.charCodeAt(s))return!1;if(33===(i=e.src.charCodeAt(s+1))||63===i){if(r)return!0}else{if(47!==i&&!function(e){var t=32|e;return t>=97&&t<=122}(i))return!1;if(47===i){if(!(a=e.src.slice(s,l).match(jt)))return!1}else if(!(a=e.src.slice(s,l).match(Vt)))return!1;if(!0!==qt[a[1].toLowerCase()])return!1;if(r)return!0}for(o=t+1;on||(l=t+1,e.tShift[l]=e.eMarks[l]||124!==(i=e.src.charCodeAt(o))&&45!==i&&58!==i||(a=$t(e,t+1),!/^[-:| ]+$/.test(a))||(c=a.split("|"))<=2)return!1;for(u=[],s=0;s=0;if(d=t+1,e.isEmpty(d)&&++d>n||e.tShift[d]=e.options.maxNesting)return!1;c=e.tokens.length,e.tokens.push({type:"dl_open",lines:l=[t,0],level:e.level++}),o=t,a=d;e:for(;;){for(f=!0,h=!1,e.tokens.push({type:"dt_open",lines:[o,o],level:e.level++}),e.tokens.push({type:"inline",content:e.getLines(o,o+1,e.blkIndent,!1).trim(),level:e.level+1,lines:[o,o],children:[]}),e.tokens.push({type:"dt_close",level:--e.level});;){if(e.tokens.push({type:"dd_open",lines:s=[d,0],level:e.level++}),g=e.tight,p=e.ddIndent,u=e.blkIndent,m=e.tShift[a],_=e.parentType,e.blkIndent=e.ddIndent=e.tShift[a]+2,e.tShift[a]=i-e.bMarks[a],e.tight=!0,e.parentType="deflist",e.parser.tokenize(e,a,n,!0),(!e.tight||h)&&(f=!1),h=e.line-a>1&&e.isEmpty(e.line-1),e.tShift[a]=m,e.tight=g,e.parentType=_,e.blkIndent=u,e.ddIndent=p,e.tokens.push({type:"dd_close",level:--e.level}),s[1]=d=e.line,d>=n||e.tShift[d]=n||(o=d,e.isEmpty(o))||e.tShift[o]=n||(e.isEmpty(a)&&a++,a>=n)||e.tShift[a]3)){for(i=!1,a=0,o=s.length;a=n||e.tShift[o]=0&&(e=e.replace(Xt,(function(t,n){var r;return 10===e.charCodeAt(n)?(a=n+1,o=0,t):(r=" ".slice((n-a-o)%4),o=n-a+1,r)}))),i=new Yt(e,this,t,n,r),this.tokenize(i,i.line,i.lineMax)};for(var tn=[],nn=0;nn<256;nn++)tn.push(0);function rn(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122}function an(e,t){var n,r,i,a=t,o=!0,s=!0,l=e.posMax,c=e.src.charCodeAt(t);for(n=t>0?e.src.charCodeAt(t-1):-1;a=l&&(o=!1),(i=a-t)>=4?o=s=!1:((32===(r=a?@[]^_`{|}~-".split("").forEach((function(e){tn[e.charCodeAt(0)]=1}));var on=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;var sn=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;var ln=["coap","doi","javascript","aaa","aaas","about","acap","cap","cid","crid","data","dav","dict","dns","file","ftp","geo","go","gopher","h323","http","https","iax","icap","im","imap","info","ipp","iris","iris.beep","iris.xpc","iris.xpcs","iris.lwz","ldap","mailto","mid","msrp","msrps","mtqp","mupdate","news","nfs","ni","nih","nntp","opaquelocktoken","pop","pres","rtsp","service","session","shttp","sieve","sip","sips","sms","snmp","soap.beep","soap.beeps","tag","tel","telnet","tftp","thismessage","tn3270","tip","tv","urn","vemmi","ws","wss","xcon","xcon-userid","xmlrpc.beep","xmlrpc.beeps","xmpp","z39.50r","z39.50s","adiumxtra","afp","afs","aim","apt","attachment","aw","beshare","bitcoin","bolo","callto","chrome","chrome-extension","com-eventbrite-attendee","content","cvs","dlna-playsingle","dlna-playcontainer","dtn","dvb","ed2k","facetime","feed","finger","fish","gg","git","gizmoproject","gtalk","hcp","icon","ipn","irc","irc6","ircs","itms","jar","jms","keyparc","lastfm","ldaps","magnet","maps","market","message","mms","ms-help","msnim","mumble","mvn","notes","oid","palm","paparazzi","platform","proxy","psyc","query","res","resource","rmi","rsync","rtmp","secondlife","sftp","sgn","skype","smb","soldat","spotify","ssh","steam","svn","teamspeak","things","udp","unreal","ut2004","ventrilo","view-source","webcal","wtai","wyciwyg","xfire","xri","ymsgr"],cn=/^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/,dn=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function un(e,t){return e=e.source,t=t||"",function n(r,i){return r?(i=i.source||i,e=e.replace(r,i),n):new RegExp(e,t)}}var pn=un(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",/[^"'=<>`\x00-\x20]+/)("single_quoted",/'[^']*'/)("double_quoted",/"[^"]*"/)(),_n=un(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",/[a-zA-Z_:][a-zA-Z0-9:._-]*/)("attr_value",pn)(),mn=un(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",_n)(),gn=un(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",mn)("close_tag",/<\/[A-Za-z][A-Za-z0-9]*\s*>/)("comment",/|/)("processing",/<[?].*?[?]>/)("declaration",/]*>/)("cdata",//)();var hn=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,fn=/^&([a-z][a-z0-9]{1,31});/i;var En=[["text",function(e,t){for(var n=e.pos;n=0&&32===e.pending.charCodeAt(n))if(n>=1&&32===e.pending.charCodeAt(n-1)){for(var a=n-2;a>=0;a--)if(32!==e.pending.charCodeAt(a)){e.pending=e.pending.substring(0,a+1);break}e.push({type:"hardbreak",level:e.level})}else e.pending=e.pending.slice(0,-1),e.push({type:"softbreak",level:e.level});else e.push({type:"softbreak",level:e.level});for(i++;i=s||126!==e.src.charCodeAt(l+1)||e.level>=e.options.maxNesting||(a=l>0?e.src.charCodeAt(l-1):-1,o=e.src.charCodeAt(l+2),126===a)||126===o||32===o||10===o)return!1;for(r=l+2;rl+3)return e.pos+=r-l,t||(e.pending+=e.src.slice(l,r)),!0;for(e.pos=l+2,i=1;e.pos+1=s||43!==e.src.charCodeAt(l+1)||e.level>=e.options.maxNesting||(a=l>0?e.src.charCodeAt(l-1):-1,o=e.src.charCodeAt(l+2),43===a)||43===o||32===o||10===o)return!1;for(r=l+2;r=s||61!==e.src.charCodeAt(l+1)||e.level>=e.options.maxNesting||(a=l>0?e.src.charCodeAt(l-1):-1,o=e.src.charCodeAt(l+2),61===a)||61===o||32===o||10===o)return!1;for(r=l+2;r=e.options.maxNesting)return!1;for(e.pos=d+n,s=[n];e.pos=i||e.level>=e.options.maxNesting)return!1;for(e.pos=a+1;e.pos=i||e.level>=e.options.maxNesting)return!1;for(e.pos=a+1;e.pos=e.options.maxNesting||(n=_+1,(r=vt(e,_))<0))return!1;if((s=r+1)=p)return!1;for(_=s,Ct(e,s)?(a=e.linkContent,s=e.pos):a="",_=s;s=p||41!==e.src.charCodeAt(s))return e.pos=u,!1;s++}else{if(e.linkLevel>0)return!1;for(;s=0?i=e.src.slice(_,s++):s=_-1),i||(_e(i)>"u"&&(s=r+1),i=e.src.slice(n,r)),!(l=e.env.references[Ot(i)]))return e.pos=u,!1;a=l.href,o=l.title}return t||(e.pos=n,e.posMax=r,d?e.push({type:"image",src:a,title:o,alt:e.src.substr(n,r-n),level:e.level}):(e.push({type:"link_open",href:a,title:o,level:e.level++}),e.linkLevel++,e.parser.tokenize(e),e.linkLevel--,e.push({type:"link_close",level:--e.level}))),e.pos=s,e.posMax=p,!0}],["footnote_inline",function(e,t){var n,r,i,a,o=e.posMax,s=e.pos;return!(s+2>=o||94!==e.src.charCodeAt(s)||91!==e.src.charCodeAt(s+1)||e.level>=e.options.maxNesting||(n=s+2,r=vt(e,s+1),r<0))&&(t||(e.env.footnotes||(e.env.footnotes={}),e.env.footnotes.list||(e.env.footnotes.list=[]),i=e.env.footnotes.list.length,e.pos=n,e.posMax=r,e.push({type:"footnote_ref",id:i,level:e.level}),e.linkLevel++,a=e.tokens.length,e.parser.tokenize(e),e.env.footnotes.list[i]={tokens:e.tokens.splice(a)},e.linkLevel--),e.pos=r+1,e.posMax=o,!0)}],["footnote_ref",function(e,t){var n,r,i,a,o=e.posMax,s=e.pos;if(s+3>o||!e.env.footnotes||!e.env.footnotes.refs||91!==e.src.charCodeAt(s)||94!==e.src.charCodeAt(s+1)||e.level>=e.options.maxNesting)return!1;for(r=s+2;r=o||(r++,n=e.src.slice(s+2,r-1),_e(e.env.footnotes.refs[":"+n])>"u"))&&(t||(e.env.footnotes.list||(e.env.footnotes.list=[]),e.env.footnotes.refs[":"+n]<0?(i=e.env.footnotes.list.length,e.env.footnotes.list[i]={label:n,count:0},e.env.footnotes.refs[":"+n]=i):i=e.env.footnotes.refs[":"+n],a=e.env.footnotes.list[i].count,e.env.footnotes.list[i].count++,e.push({type:"footnote_ref",id:i,subId:a,level:e.level})),e.pos=r,e.posMax=o,!0)}],["autolink",function(e,t){var n,r,i,a,o,s=e.pos;return!(60!==e.src.charCodeAt(s)||(n=e.src.slice(s),n.indexOf(">")<0))&&((r=n.match(dn))?!(ln.indexOf(r[1].toLowerCase())<0||(a=r[0].slice(1,-1),o=Tt(a),!e.parser.validateLink(a)))&&(t||(e.push({type:"link_open",href:o,level:e.level}),e.push({type:"text",content:a,level:e.level+1}),e.push({type:"link_close",level:e.level})),e.pos+=r[0].length,!0):!!(i=n.match(cn))&&(o=Tt("mailto:"+(a=i[0].slice(1,-1))),!!e.parser.validateLink(o)&&(t||(e.push({type:"link_open",href:o,level:e.level}),e.push({type:"text",content:a,level:e.level+1}),e.push({type:"link_close",level:e.level})),e.pos+=i[0].length,!0)))}],["htmltag",function(e,t){var n,r,i,a=e.pos;return!(!e.options.html||(i=e.posMax,60!==e.src.charCodeAt(a)||a+2>=i)||(n=e.src.charCodeAt(a+1),33!==n&&63!==n&&47!==n&&!function(e){var t=32|e;return t>=97&&t<=122}(n))||(r=e.src.slice(a).match(gn),!r))&&(t||e.push({type:"htmltag",content:e.src.slice(a,a+r[0].length),level:e.level}),e.pos+=r[0].length,!0)}],["entity",function(e,t){var n,r,i=e.pos,a=e.posMax;if(38!==e.src.charCodeAt(i))return!1;if(i+10)e.pos=n;else{for(t=0;t=a)break}else e.pending+=e.src[e.pos++]}e.pending&&e.pushPending()},Sn.prototype.parse=function(e,t,n,r){var i=new bt(e,this,t,n,r);this.tokenize(i)};var vn={default:{options:{html:!1,xhtmlOut:!1,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{rules:["block","inline","references","replacements","smartquotes","references","abbr2","footnote_tail"]},block:{rules:["blockquote","code","fences","footnote","heading","hr","htmlblock","lheading","list","paragraph","table"]},inline:{rules:["autolink","backticks","del","emphasis","entity","escape","footnote_ref","htmltag","links","newline","text"]}}},full:{options:{html:!1,xhtmlOut:!1,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{},block:{},inline:{}}},commonmark:{options:{html:!0,xhtmlOut:!0,breaks:!1,langPrefix:"language-",linkTarget:"",typographer:!1,quotes:"“”‘’",highlight:null,maxNesting:20},components:{core:{rules:["block","inline","references","abbr2"]},block:{rules:["blockquote","code","fences","heading","hr","htmlblock","lheading","list","paragraph"]},inline:{rules:["autolink","backticks","emphasis","entity","escape","htmltag","links","newline","text"]}}}};function yn(e,t,n){this.src=t,this.env=n,this.options=e.options,this.tokens=[],this.inlineMode=!1,this.inline=e.inline,this.block=e.block,this.renderer=e.renderer,this.typographer=e.typographer}function Tn(e,t){"string"!=typeof e&&(t=e,e="default"),t&&null!=t.linkify&&console.warn("linkify option is removed. Use linkify plugin instead:\n\nimport Remarkable from 'remarkable';\nimport linkify from 'remarkable/linkify';\nnew Remarkable().use(linkify)\n"),this.inline=new Sn,this.block=new Qt,this.core=new Gt,this.renderer=new Et,this.ruler=new St,this.options={},this.configure(vn[e]),this.set(t||{})}Tn.prototype.set=function(e){tt(this.options,e)},Tn.prototype.configure=function(e){var t=this;if(!e)throw new Error("Wrong `remarkable` preset, check name/content");e.options&&t.set(e.options),e.components&&Object.keys(e.components).forEach((function(n){e.components[n].rules&&t[n].ruler.enable(e.components[n].rules,!0)}))},Tn.prototype.use=function(e,t){return e(this,t),this},Tn.prototype.parse=function(e,t){var n=new yn(this,e,t);return this.core.process(n),n.tokens},Tn.prototype.render=function(e,t){return t=t||{},this.renderer.render(this.parse(e,t),this.options,t)},Tn.prototype.parseInline=function(e,t){var n=new yn(this,e,t);return n.inlineMode=!0,this.core.process(n),n.tokens},Tn.prototype.renderInline=function(e,t){return t=t||{},this.renderer.render(this.parseInline(e,t),this.options,t)};var Cn=function(){function e(){me(this,e)}return he(e,null,[{key:"instantiate",value:function(){var e=window.hljs;return new Tn(e?{highlight:function(t,n){if(n&&e.getLanguage(n))try{return e.highlight(n,t).value}catch(e){console.error("failed to setup the highlight dependency")}try{return e.highlightAuto(t).value}catch(e){console.error("failed to automatically highlight messages")}return""},html:!1,xhtmlOut:!1,breaks:!1,langPrefix:"language-",linkTarget:"_blank",typographer:!0}:{linkTarget:"_blank"})}},{key:"createNew",value:function(){var t=e.instantiate();return t.inline.validateLink=function(){return!0},t}}]),e}(),Rn=function(){function e(){me(this,e)}return he(e,null,[{key:"addMessage",value:function(e,t,n,r){var i;e.elementRef.appendChild(t.outerContainer),e.applyCustomStyles(t,r,!0,null==(i=e.messageStyles)?void 0:i[n]),e.elementRef.scrollTop=e.elementRef.scrollHeight}},{key:"wrapInLink",value:function(t,n,r){var i=document.createElement("a");return i.href=n,i.download=r||e.DEFAULT_FILE_NAME,i.target="_blank",i.appendChild(t),i}},{key:"isNonLinkableDataUrl",value:function(e,t){return!(!t.startsWith("data")||"image"===e)&&("any"===e&&t.startsWith("data:text/javascript")||!t.startsWith("data:image"))}},{key:"processContent",value:function(t,n,r,i){return!r||e.isNonLinkableDataUrl(t,r)?n:e.wrapInLink(n,r,i)}},{key:"waitToLoadThenScroll",value:function(e){setTimeout((function(){e.scrollTop=e.scrollHeight}),60)}},{key:"scrollDownOnImageLoad",value:function(t,n){if(t.startsWith("data"))e.waitToLoadThenScroll(n);else try{fetch(t,{mode:"no-cors"}).catch((function(){})).finally((function(){e.waitToLoadThenScroll(n)}))}catch(e){n.scrollTop=n.scrollHeight}}},{key:"reAddFileRefToObject",value:function(e,t){var n;null==(n=e.files)||n.forEach((function(e,n){var r;e.ref&&null!=(r=t.message.files)&&r[n]&&(t.message.files[n].ref=e.ref)}))}},{key:"removeFileRef",value:function(e){var t=ue({},e);return delete t.ref,t}}]),e}();Rn.DEFAULT_FILE_NAME="file";var On=Rn,Nn=function(){function e(){me(this,e)}return he(e,null,[{key:"onNewMessage",value:function(e,t,n){var r,i=JSON.parse(JSON.stringify({message:t,isInitial:n}));On.reAddFileRefToObject(t,i),null==(r=e.onNewMessage)||r.call(e,i),e.dispatchEvent(new CustomEvent("new-message",{detail:i}))}},{key:"onClearMessages",value:function(e){var t;null==(t=e.onClearMessages)||t.call(e),e.dispatchEvent(new CustomEvent("clear-messages"))}},{key:"onRender",value:function(e){var t;null==(t=e.onComponentRender)||t.call(e,e),e.dispatchEvent(new CustomEvent("render",{detail:e}))}},{key:"onError",value:function(e,t){var n;null==(n=e.onError)||n.call(e,t),e.dispatchEvent(new CustomEvent("error",{detail:t}))}}]),e}(),An=function(){function e(){me(this,e)}return he(e,null,[{key:"applyCustomStylesToElements",value:function(e,t,n){if(n&&(Object.assign(e.outerContainer.style,n.outerContainer),Object.assign(e.innerContainer.style,n.innerContainer),Object.assign(e.bubbleElement.style,n.bubble),t)){var r=e.bubbleElement.children[0],i="a"!==r.tagName.toLocaleLowerCase()?r:r.children[0];Object.assign(i.style,n.media)}}},{key:"applySideStyles",value:function(t,n,r,i){i&&(e.applyCustomStylesToElements(t,r,i.shared),n===je.USER_ROLE?e.applyCustomStylesToElements(t,r,i.user):(e.applyCustomStylesToElements(t,r,i.ai),e.applyCustomStylesToElements(t,r,i[n])))}},{key:"isMessageSideStyles",value:function(e){return!!(e.ai||e.shared||e.user)}},{key:"applyCustomStyles",value:function(t,n,r,i,a){var o;a&&t.default!==a?e.isMessageSideStyles(a)?(e.applySideStyles(n,r,i,t.default),e.applySideStyles(n,r,i,a)):(e.applyCustomStylesToElements(n,i,null==(o=t.default)?void 0:o.shared),e.applyCustomStylesToElements(n,i,a)):e.applySideStyles(n,r,i,t.default)}},{key:"extractParticularSharedStyles",value:function(e,t){if(null!=t&&t.shared){var n=t.shared,r={outerContainer:{},innerContainer:{},bubble:{},media:{}};return e.forEach((function(e){var t,i,a,o;r.outerContainer[e]=(null==(t=n.outerContainer)?void 0:t[e])||"",r.innerContainer[e]=(null==(i=n.innerContainer)?void 0:i[e])||"",r.bubble[e]=(null==(a=n.bubble)?void 0:a[e])||"",r.media[e]=(null==(o=n.media)?void 0:o[e])||""})),r}}}]),e}(),In=function(){function e(t){var n=this;me(this,e),this.messageElementRefs=[],this.messages=[],this.htmlClassUtilities={},this.textElementsToText=[],this.elementRef=e.createContainerElement(),this.messageStyles=t.messageStyles,this._remarkable=Cn.createNew(),this._avatars=t.avatars,this._names=t.names,this._onNewMessage=Nn.onNewMessage.bind(this,t),t.htmlClassUtilities&&(this.htmlClassUtilities=t.htmlClassUtilities),setTimeout((function(){n.submitUserMessage=t.submitUserMessage}))}return he(e,[{key:"addNewTextMessage",value:function(e,t,n){if(null!=n&&n.status){var r=this.overwriteText(t,e,this.messageElementRefs);if(r)return r;n.status=!1}var i=this.createAndAppendNewMessageElement(e,t);return i.bubbleElement.classList.add("text-message"),this.applyCustomStyles(i,t,!1),je.fillEmptyMessageElement(i.bubbleElement,e),this.textElementsToText.push([i,e]),i}},{key:"overwriteText",value:function(e,t,n){var r=je.overwriteMessage(this.messages,n,t,e,"text","text-message");if(r){this.renderText(r.bubbleElement,t);var i=je.getLastTextToElement(this.textElementsToText,r);i&&(i[1]=t)}return r}},{key:"createAndAppendNewMessageElement",value:function(e,t){var n=this,r=this.createNewMessageElement(e,t);return this.elementRef.appendChild(r.outerContainer),setTimeout((function(){return Pe.scrollToBottom(n.elementRef)})),r}},{key:"createNewMessageElement",value:function(t,n){var r;null==(r=this._introPanel)||r.hide();var i=this.messageElementRefs[this.messageElementRefs.length-1];return e.isTemporaryElement(i)&&(i.outerContainer.remove(),this.messageElementRefs.pop()),this.createMessageElements(t,n)}},{key:"createMessageElements",value:function(t,n){var r=e.createBaseElements(),i=r.outerContainer,a=r.innerContainer,o=r.bubbleElement;return i.appendChild(a),this.addInnerContainerElements(o,t,n),this.messageElementRefs.push(r),r}},{key:"addInnerContainerElements",value:function(e,t,n){var r;return(null==(r=this.messages[this.messages.length-1])?void 0:r.role)===n&&!this.isLastMessageError()&&je.hideRoleElements(this.messageElementRefs,!!this._avatars,!!this._names),e.classList.add("message-bubble",je.getRoleClass(n),n===je.USER_ROLE?"user-message-text":"ai-message-text"),this.renderText(e,t),je.addRoleElements(e,n,this._avatars,this._names),{bubbleElement:e}}},{key:"applyCustomStyles",value:function(e,t,n,r){e&&this.messageStyles&&An.applyCustomStyles(this.messageStyles,e,t,n,r)}},{key:"removeLastMessage",value:function(){this.messageElementRefs[this.messageElementRefs.length-1].outerContainer.remove(),this.messageElementRefs.pop()}},{key:"isLastMessageError",value:function(){var e;return null==(e=je.getLastMessageBubbleElement(this.elementRef))?void 0:e.classList.contains("error-message-text")}},{key:"sendClientUpdate",value:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];null==(t=this._onNewMessage)||t.call(this,e,n)}},{key:"renderText",value:function(e,t){e.innerHTML=this._remarkable.render(t),0===e.innerText.trim().length&&(e.innerText=t)}},{key:"refreshTextMessages",value:function(){var e=this;this._remarkable=Cn.createNew(),this.textElementsToText.forEach((function(t){e.renderText(t[0].bubbleElement,t[1])}))}}],[{key:"createContainerElement",value:function(){var e=document.createElement("div");return e.id="messages",e}},{key:"isTemporaryElement",value:function(e){return(null==e?void 0:e.bubbleElement.classList.contains("loading-message-text"))||Qe.isElementTemporary(e)}},{key:"createBaseElements",value:function(){var e=document.createElement("div"),t=document.createElement("div");t.classList.add("inner-message-container"),e.appendChild(t),e.classList.add("outer-message-container");var n=document.createElement("div");return n.classList.add("message-bubble"),t.appendChild(n),{outerContainer:e,innerContainer:t,bubbleElement:n}}},{key:"createMessageContent",value:function(e){var t=e.text,n=e.files,r=e.html,i=e._sessionId,a={role:e.role||je.AI_ROLE};return t&&(a.text=t),n&&(a.files=n),r&&(a.html=r),!t&&!n&&!r&&(a.text=""),i&&(a._sessionId=i),a}}]),e}(),wn=function(){function e(t){me(this,e),this._fileAdded=!1,this._streamedContent="",this._streamType="",this._hasStreamEnded=!1,this._messages=t}return he(e,[{key:"upsertStreamedMessage",value:function(e){var t;if(!this._hasStreamEnded){if(void 0===(null==e?void 0:e.text)&&void 0===(null==e?void 0:e.html))return console.error(ke.INVALID_STREAM_EVENT);var n=(null==e?void 0:e.text)||(null==e?void 0:e.html)||"",r=Pe.isScrollbarAtBottomOfElement(this._messages.elementRef),i=void 0!==(null==e?void 0:e.text)?"text":"html";if(this._elements||""!==this._streamedContent){if(this._streamType!==i)return console.error(ke.INVALID_STREAM_EVENT_MIX);this.updateBasedOnType(n,i,null==(t=this._elements)?void 0:t.bubbleElement,null==e?void 0:e.overwrite)}else this.setInitialState(i,n,null==e?void 0:e.role);r&&Pe.scrollToBottom(this._messages.elementRef)}}},{key:"setInitialState",value:function(t,n,r){var i;this._streamType=t,null!==(i=r)&&void 0!==i||(r=je.AI_ROLE),this._elements="text"===t?this._messages.addNewTextMessage(n,r):Ze.add(this._messages,n,r,this._messages.messageElementRefs),this._elements.bubbleElement.classList.add(e.MESSAGE_CLASS),this._streamedContent=n,this._activeMessageRole=r,this._message=pe({role:this._activeMessageRole},t,this._streamedContent),this._messages.messages.push(this._message)}},{key:"updateBasedOnType",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];je.unfillEmptyMessageElement(n,e),("text"===t?this.updateText:this.updateHTML).bind(this)(e,n,r)}},{key:"updateText",value:function(e,t,n){this._streamedContent=n?e:this._streamedContent+e,this._messages.textElementsToText[this._messages.textElementsToText.length-1][1]=this._streamedContent,this._messages.renderText(t,this._streamedContent)}},{key:"updateHTML",value:function(t,n,r){if(r)this._streamedContent=t,n.innerHTML=t;else{var i=document.createElement("span");i.innerHTML=t,n.appendChild(i),this._streamedContent=e.HTML_CONTENT_PLACEHOLDER}}},{key:"finaliseStreamedMessage",value:function(){var t,n,r=this._messages.textElementsToText;if(!this._fileAdded||this._elements){if(!this._elements)throw Error(ke.NO_VALID_STREAM_EVENTS_SENT);null!=(t=this._elements.bubbleElement)&&t.classList.contains(e.MESSAGE_CLASS)&&("text"===this._streamType?(r[r.length-1][1]=this._streamedContent,this._message&&(this._message.text=this._streamedContent),this._messages.textToSpeech&&Ue.speak(this._streamedContent,this._messages.textToSpeech)):"html"===this._streamType&&(this._streamedContent===e.HTML_CONTENT_PLACEHOLDER&&(this._streamedContent=(null==(n=this._elements.bubbleElement)?void 0:n.innerHTML)||""),this._elements&&Xe.apply(this._messages,this._elements.outerContainer),this._message&&(this._message.html=this._streamedContent)),this._message&&this._messages.sendClientUpdate(In.createMessageContent(this._message),!1),this._hasStreamEnded=!0)}}},{key:"markFileAded",value:function(){this._fileAdded=!0}}]),e}();wn.MESSAGE_CLASS="streamed-message",wn.HTML_CONTENT_PLACEHOLDER="htmlplaceholder";var xn=wn,Dn=function(){function e(){me(this,e)}var t,n;return he(e,null,[{key:"tempRemoveContentHeader",value:(n=ce(se().mark((function t(n,r,i){var a,o;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(null!=n&&n.headers){t.next=2;break}throw new Error("Request settings have not been set up");case 2:return a=n.headers[e.CONTENT_TYPE],delete n.headers[e.CONTENT_TYPE],t.prev=4,t.next=7,r(i);case 7:o=t.sent,t.next=13;break;case 10:throw t.prev=10,t.t0=t.catch(4),n.headers[e.CONTENT_TYPE]=a,t.t0;case 13:return t.abrupt("return",(n.headers[e.CONTENT_TYPE]=a,o));case 14:case"end":return t.stop()}}),t,null,[[4,10]])}))),function(e,t,r){return n.apply(this,arguments)})},{key:"displayError",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"Service error, please try again.";if(console.error(t),"object"==_e(t))return 0===Object.keys(t).length?e.addNewErrorMessage("service",n):e.addNewErrorMessage("service",JSON.stringify(t));e.addNewErrorMessage("service",t)}},{key:"fetch",value:function(e){function t(t,n,r,i){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}((function(e,t,n,r){var i,a,o={method:(null==(i=e.requestSettings)?void 0:i.method)||"POST",headers:t};return"GET"!==o.method&&(o.body=n?JSON.stringify(r):r),e.requestSettings.credentials&&(o.credentials=e.requestSettings.credentials),fetch((null==(a=e.requestSettings)?void 0:a.url)||e.url||"",o)}))},{key:"processResponseByType",value:function(e){var t=e.headers.get("content-type");return null!=t&&t.includes("application/json")?e.json():null!=t&&t.includes("text/plain")||!t?e:e.blob()}},{key:"processRequestInterceptor",value:(t=ce(se().mark((function e(t,n){var r,i,a,o;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==(r=t.requestInterceptor)?void 0:r.call(t,n);case 2:if(e.t0=e.sent,e.t0){e.next=5;break}e.t0=n;case 5:return i=e.t0,a=i,o=i,e.abrupt("return",{body:a.body,headers:a.headers,error:o.error});case 9:case"end":return e.stop()}}),e)}))),function(e,n){return t.apply(this,arguments)})},{key:"validateResponseFormat",value:function(e){return e&&"object"==_e(e)&&("string"==typeof e.error||"string"==typeof e.text||"string"==typeof e.html||Array.isArray(e.files))}},{key:"onInterceptorError",value:function(e,t,n){e.addNewErrorMessage("service",t),null==n||n()}}]),e}();Dn.CONTENT_TYPE="Content-Type";var Mn=Dn;function kn(e,t){return Ln.apply(this,arguments)}function Ln(){return(Ln=ce(se().mark((function e(t,n){var r,i;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.getReader();case 1:return e.next=3,r.read();case 3:if((i=e.sent).done){e.next=7;break}n(i.value);case 5:e.next=1;break;case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pn(e){var t,n,r,i=!1;return function(a){void 0===t?(t=a,n=0,r=-1):t=function(e,t){var n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}(t,a);for(var o=t.length,s=0;n0){var s=i.decode(a.subarray(0,o)),l=o+(32===a[o+1]?2:1),c=i.decode(a.subarray(l));switch(s){case"data":r.data=r.data?r.data+"\n"+c:c;break;case"event":r.event=c;break;case"id":e(r.id=c);break;case"retry":var d=parseInt(c,10);isNaN(d)||t(r.retry=d)}}}}var Un=globalThis&&globalThis.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i3&&void 0!==T[3])||T[3],p={body:r,headers:null==(o=n.requestSettings)?void 0:o.headers},t.next=4,Mn.processRequestInterceptor(n.deepChat,p);case 4:if(_=t.sent,m=_.body,g=_.headers,h=_.error,f=n.streamHandlers,E=f.onOpen,S=f.onClose,b=f.abortStream,!h){t.next=14;break}return t.abrupt("return",Mn.onInterceptorError(i,h,S));case 14:if(null==(s=n.requestSettings)||!s.handler){t.next=16;break}return t.abrupt("return",$n.stream(n,m,i));case 16:if((null==(l=n.requestSettings)?void 0:l.url)!==Vn.URL){t.next=18;break}return t.abrupt("return",Vn.requestStream(i,n.streamHandlers));case 18:v=new xn(i),y=Mn.fetch.bind(this,n,g,a),Yn((null==(c=n.requestSettings)?void 0:c.url)||n.url||"",{method:(null==(d=n.requestSettings)?void 0:d.method)||"POST",headers:g,credentials:null==(u=n.requestSettings)?void 0:u.credentials,body:a?JSON.stringify(m):m,openWhenHidden:!0,onopen:function(e){return ce(se().mark((function t(){return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.ok){t.next=2;break}return t.abrupt("return",E());case 2:return t.next=4,Mn.processResponseByType(e);case 4:throw t.sent;case 5:case"end":return t.stop()}}),t)})))()},onmessage:function(t){return ce(se().mark((function r(){var a,o,s,l,c;return se().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(JSON.stringify(t.data)===JSON.stringify("[DONE]")){r.next=9;break}try{l=JSON.parse(t.data)}catch(e){l={}}return r.next=4,null==(o=(a=n.deepChat).responseInterceptor)?void 0:o.call(a,l);case 4:if(r.t0=r.sent,r.t0){r.next=7;break}r.t0=l;case 7:c=r.t0,null==(s=n.extractResultData)||s.call(n,c,y,m).then((function(t){n.asyncCallInProgress&&t&&""!==t.text?(e.simulate(i,n.streamHandlers,t),S(),n.asyncCallInProgress=!1):e.upsertWFiles(i,v.upsertStreamedMessage.bind(v),v,t)})).catch((function(e){return Mn.displayError(i,e)}));case 9:case"end":return r.stop()}}),r)})))()},onerror:function(e){throw S(),e},onclose:function(){n.asyncCallInProgress||(v.finaliseStreamedMessage(),S())},signal:b.signal}).catch((function(e){var t;i.isLastMessageError()||null==(t=n.extractResultData)||t.call(n,e).then((function(){Mn.displayError(i,e)})).catch((function(e){Mn.displayError(i,e)}))}));case 20:case"end":return t.stop()}}),t,this)}))),function(e,n,r){return t.apply(this,arguments)})},{key:"simulate",value:function(t,n,r){var i=n;if((r.files||r.html)&&t.addNewMessage(ue({sendUpdate:!1,ignoreText:!0},r),!1),r.text){n.onOpen();var a=r.text.split("");e.populateMessages(a,new xn(t),i)}}},{key:"populateMessages",value:function(t,n,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,a=t[i];if(a){n.upsertStreamedMessage({text:a});var o=setTimeout((function(){e.populateMessages(t,n,r,i+1)}),r.simulationInterim||6);r.abortStream.abort=function(){e.abort(o,n,r.onClose)}}else n.finaliseStreamedMessage(),r.onClose()}},{key:"isSimulation",value:function(e){return"object"==_e(e)&&!!e.simulation}},{key:"isSimulatable",value:function(t,n){return e.isSimulation(t)&&n&&(n.text||n.html)}},{key:"abort",value:function(e,t,n){clearTimeout(e),t.finaliseStreamedMessage(),n()}},{key:"upsertWFiles",value:function(e,t,n,r){if(null!=r&&r.text||null!=r&&r.html){var i,a=t(r);null!==(i=n)&&void 0!==i||(n=a||void 0)}null!=r&&r.files&&(e.addNewMessage({files:r.files}),null==n||n.markFileAded())}}]),e}(),qn=function(){function e(){me(this,e)}return he(e,null,[{key:"generateResponse",value:function(e){var t=e.messages[e.messages.length-1];if(t.files&&t.files.length>0){if(t.files.length>1)return"These are interesting files!";var n=t.files[0];return n.src&&n.src.startsWith("data:image/gif")?"That is a nice gif!":"image"===n.type?"That is a nice image!":"audio"===n.type?"I like the sound of that!":"That is an interesting file!"}if(t.text){if("?"===t.text.charAt(t.text.length-1))return"I'm sorry but I can't answer that question...";if(t.text.includes("updog"))return"What's updog?"}return"Hi there! This is a demo response!"}},{key:"getCustomResponse",value:function(e,t){return"function"==typeof e?e(t):e}},{key:"getResponse",value:function(t){return t.customDemoResponse?e.getCustomResponse(t.customDemoResponse,t.messages[t.messages.length-1]):{text:e.generateResponse(t)}}},{key:"request",value:function(t,n){var r=e.getResponse(n);setTimeout(ce(se().mark((function e(){var i,a,o;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,null==(a=(i=t.deepChat).responseInterceptor)?void 0:a.call(i,r);case 2:if(e.t0=e.sent,e.t0){e.next=5;break}e.t0=r;case 5:(o=e.t0).error?(n.addNewErrorMessage("service",o.error),t.completionsHandlers.onFinish()):zn.isSimulatable(t.deepChat.stream,o)?zn.simulate(n,t.streamHandlers,o):(n.addNewMessage(o),t.completionsHandlers.onFinish());case 7:case"end":return e.stop()}}),e)}))),400)}},{key:"requestStream",value:function(t,n){setTimeout((function(){var r=e.getResponse(t);zn.simulate(t,n,r)}),400)}}]),e}();qn.URL="deep-chat-demo";var Vn=qn,jn=function(){function e(){me(this,e)}var t;return he(e,null,[{key:"setup",value:function(e){e.requestSettings.url!==Vn.URL&&(e.permittedErrorPrefixes=["Connection error","Error in server message"],e.websocket="pending")}},{key:"createConnection",value:function(t,n){if(document.body.contains(t.deepChat)){var r=t.requestSettings.websocket;if(r){if(t.requestSettings.handler)return $n.websocket(t,n);try{var i="boolean"!=typeof r?r:void 0,a=new WebSocket(t.requestSettings.url||"",i);t.websocket=a,t.websocket.onopen=function(){var r,i;n.removeError(),t.websocket&&"object"==_e(t.websocket)&&e.assignListeners(t,a,n),null==(i=(r=t.deepChat)._validationHandler)||i.call(r)},t.websocket.onerror=function(r){console.error(r),e.retryConnection(t,n)}}catch(i){console.error(i),e.retryConnection(t,n)}}}}},{key:"retryConnection",value:function(t,n){var r,i;null==(i=(r=t.deepChat)._validationHandler)||i.call(r),document.body.contains(t.deepChat)&&(t.websocket="pending",n.isLastMessageError()||n.addNewErrorMessage("service","Connection error"),setTimeout((function(){e.createConnection(t,n)}),5e3))}},{key:"assignListeners",value:function(t,n,r){var i=this,a={};n.onmessage=function(){var n=ce(se().mark((function n(o){var s,l,c,d,u,p,_;return se().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(!t.extractResultData){n.next=20;break}return n.prev=1,c=JSON.parse(o.data),n.next=5,null==(l=(s=t.deepChat).responseInterceptor)?void 0:l.call(s,c);case 5:if(n.t0=n.sent,n.t0){n.next=8;break}n.t0=c;case 8:return d=n.t0,n.next=11,t.extractResultData(d);case 11:if((u=n.sent)&&"object"==_e(u)){n.next=14;break}throw Error(ke.INVALID_RESPONSE(c,"server",!!t.deepChat.responseInterceptor,d));case 14:zn.isSimulation(t.deepChat.stream)?(p=e.stream.bind(i,t,r,a),_=a[c.role||je.AI_ROLE],zn.upsertWFiles(r,p,_,u)):r.addNewMessage(u),n.next=20;break;case 17:n.prev=17,n.t1=n.catch(1),Mn.displayError(r,n.t1,"Error in server message");case 20:case"end":return n.stop()}}),n,null,[[1,17]])})));return function(e){return n.apply(this,arguments)}}(),n.onclose=function(){console.error("Connection closed"),r.isLastMessageError()||r.addNewErrorMessage("service","Connection error"),t.deepChat.stream&&t.streamHandlers.abortStream.abort(),e.createConnection(t,r)}}},{key:"sendWebsocket",value:(t=ce(se().mark((function t(n,r,i){var a,o,s,l,c,d,u,p,_,m=arguments;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=!(m.length>3&&void 0!==m[3])||m[3],(l=n.websocket)&&"pending"!==l){t.next=4;break}return t.abrupt("return");case 4:return c={body:r,headers:null==(o=n.requestSettings)?void 0:o.headers},t.next=7,Mn.processRequestInterceptor(n.deepChat,c);case 7:if(d=t.sent,u=d.body,!(p=d.error)){t.next=12;break}return t.abrupt("return",i.addNewErrorMessage("service",p));case 12:if(e.isWebSocket(l)){t.next=14;break}return t.abrupt("return",l.newUserMessage.listener(u));case 14:if(_=a?JSON.stringify(u):u,(null==(s=n.requestSettings)?void 0:s.url)!==Vn.URL){t.next=17;break}return t.abrupt("return",Vn.request(n,i));case 17:void 0===l.readyState||l.readyState!==l.OPEN?(console.error("Connection is not open"),i.isLastMessageError()||i.addNewErrorMessage("service","Connection error")):(l.send(JSON.stringify(_)),n.completionsHandlers.onFinish());case 18:case"end":return t.stop()}}),t)}))),function(e,n,r){return t.apply(this,arguments)})},{key:"canSendMessage",value:function(t){return!t||"pending"!==t&&(e.isWebSocket(t)?void 0!==t.readyState&&t.readyState===t.OPEN:t.isOpen)}},{key:"isWebSocket",value:function(e){return void 0!==e.send}},{key:"stream",value:function(e,t,n,r){if(r){var i=e.deepChat.stream.simulation;if("string"==typeof i){var a,o=r.role||je.AI_ROLE,s=n[o];r.text===i?(null==s||s.finaliseStreamedMessage(),delete n[o]):(null!==(a=n[o])&&void 0!==a||(n[o]=new xn(t)),n[o].upsertStreamedMessage(r))}else zn.simulate(t,e.streamHandlers,r)}}}]),e}(),$n=function(){function e(){me(this,e)}var t;return he(e,null,[{key:"request",value:(t=ce(se().mark((function t(n,r,i){var a,o,s,l,c;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:s=!0,l=function(){var e=ce(se().mark((function e(t){var r,a,o;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(s){e.next=2;break}return e.abrupt("return");case 2:return s=!1,e.next=5,null==(a=(r=n.deepChat).responseInterceptor)?void 0:a.call(r,t);case 5:if(e.t0=e.sent,e.t0){e.next=8;break}e.t0=t;case 8:o=e.t0,Mn.validateResponseFormat(o)?"string"==typeof o.error?(console.error(o.error),i.addNewErrorMessage("service",o.error),n.completionsHandlers.onFinish()):zn.isSimulatable(n.deepChat.stream,o)?zn.simulate(i,n.streamHandlers,o):(i.addNewMessage(o),n.completionsHandlers.onFinish()):(console.error(ke.INVALID_RESPONSE(t,"server",!!n.deepChat.responseInterceptor,o)),i.addNewErrorMessage("service","Error in server message"),n.completionsHandlers.onFinish());case 10:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),c=e.generateOptionalSignals(),null==(o=(a=n.requestSettings).handler)||o.call(a,r,ue(ue({},c),{},{onResponse:l}));case 3:case"end":return t.stop()}}),t)}))),function(e,n,r){return t.apply(this,arguments)})},{key:"attemptToFinaliseStream",value:function(e,t){try{e.finaliseStreamedMessage()}catch(e){console.error(e),t.addNewErrorMessage("service",e)}}},{key:"stream",value:function(t,n,r){var i,a,o=!0,s=!1,l=new xn(r),c=function(){var e=ce(se().mark((function e(n){var i,a,s;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,null==(a=(i=t.deepChat).responseInterceptor)?void 0:a.call(i,n);case 4:if(e.t0=e.sent,e.t0){e.next=7;break}e.t0=n;case 7:s=e.t0,Mn.validateResponseFormat(s)?s.error?(console.error(s.error),l.finaliseStreamedMessage(),r.addNewErrorMessage("service",s.error),t.streamHandlers.onClose(),o=!1):zn.upsertWFiles(r,l.upsertStreamedMessage.bind(l),l,s):console.error(ke.INVALID_RESPONSE(n,"server",!!t.deepChat.responseInterceptor,s));case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();t.streamHandlers.abortStream.abort=function(){e.attemptToFinaliseStream(l,r),t.streamHandlers.onClose(),o=!1};var d=e.generateOptionalSignals();null==(a=(i=t.requestSettings).handler)||a.call(i,n,ue(ue({},d),{},{onOpen:function(){s||!o||(t.streamHandlers.onOpen(),s=!0)},onResponse:c,onClose:function(){o&&(e.attemptToFinaliseStream(l,r),t.streamHandlers.onClose(),o=!1)},stopClicked:t.streamHandlers.stopClicked}))}},{key:"websocket",value:function(t,n){var r,i,a=this,o={isOpen:!1,newUserMessage:{listener:function(){}},roleToStream:{}};t.websocket=o;var s=function(){var e=ce(se().mark((function e(r){var i,s,l,c,d;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o.isOpen){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,null==(s=(i=t.deepChat).responseInterceptor)?void 0:s.call(i,r);case 4:if(e.t0=e.sent,e.t0){e.next=7;break}e.t0=r;case 7:l=e.t0,Mn.validateResponseFormat(l)?"string"==typeof l.error?(console.error(l.error),n.isLastMessageError()||n.addNewErrorMessage("service",l.error)):zn.isSimulation(t.deepChat.stream)?(c=jn.stream.bind(a,t,n,o.roleToStream),d=o.roleToStream[r.role||je.AI_ROLE],zn.upsertWFiles(n,c,d,r)):n.addNewMessage(l):(console.error(ke.INVALID_RESPONSE(r,"server",!!t.deepChat.responseInterceptor,l)),n.addNewErrorMessage("service","Error in server message"));case 9:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),l=e.generateOptionalSignals();null==(i=(r=t.requestSettings).handler)||i.call(r,void 0,ue(ue({},l),{},{onOpen:function(){n.removeError(),o.isOpen=!0},onResponse:s,onClose:function(){o.isOpen=!1},newUserMessage:o.newUserMessage}))}},{key:"generateOptionalSignals",value:function(){return{onClose:function(){},onOpen:function(){},stopClicked:{listener:function(){}},newUserMessage:{listener:function(){}}}}}]),e}(),Wn=function(){function e(){me(this,e)}var t,n;return he(e,null,[{key:"request",value:(n=ce(se().mark((function e(t,n,r){var i,a,o,s,l,c,d,u,p,_,m,g,h=arguments;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=!(h.length>3&&void 0!==h[3])||h[3],l={body:n,headers:null==(a=t.requestSettings)?void 0:a.headers},e.next=4,Mn.processRequestInterceptor(t.deepChat,l);case 4:if(c=e.sent,d=c.body,u=c.headers,p=c.error,_=t.completionsHandlers.onFinish,!p){e.next=11;break}return e.abrupt("return",Mn.onInterceptorError(r,p,_));case 11:if(null==(o=t.requestSettings)||!o.handler){e.next=13;break}return e.abrupt("return",$n.request(t,d,r));case 13:if((null==(s=t.requestSettings)?void 0:s.url)!==Vn.URL){e.next=15;break}return e.abrupt("return",Vn.request(t,r));case 15:m=!0,(g=Mn.fetch.bind(this,t,u,i))(d).then((function(e){return m=!!e.ok,e})).then((function(e){return Mn.processResponseByType(e)})).then(function(){var e=ce(se().mark((function e(n){var i,a,o,s;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.extractResultData){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,null==(a=(i=t.deepChat).responseInterceptor)?void 0:a.call(i,n);case 4:if(e.t0=e.sent,e.t0){e.next=7;break}e.t0=n;case 7:return o=e.t0,e.next=10,t.extractResultData(o,g,d);case 10:if(s=e.sent,m){e.next=13;break}throw n;case 13:if(s&&"object"==_e(s)){e.next=15;break}throw Error(ke.INVALID_RESPONSE(n,"response",!!t.deepChat.responseInterceptor,o));case 15:s.makingAnotherRequest||(zn.isSimulatable(t.deepChat.stream,s)?zn.simulate(r,t.streamHandlers,s):(r.addNewMessage(s),_()));case 16:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){Mn.displayError(r,e),_()}));case 18:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"executePollRequest",value:function(t,n,r,i){var a=t.completionsHandlers.onFinish;fetch(n,r).then((function(e){return e.json()})).then(function(){var o=ce(se().mark((function o(s){var l,c,d;return se().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(t.extractPollResultData){o.next=2;break}return o.abrupt("return");case 2:return o.t0=t,o.next=5,null==(c=(l=t.deepChat).responseInterceptor)?void 0:c.call(l,s);case 5:if(o.t1=o.sent,o.t1){o.next=8;break}o.t1=s;case 8:return o.t2=o.t1,o.next=11,o.t0.extractPollResultData.call(o.t0,o.t2);case 11:(d=o.sent).timeoutMS?setTimeout((function(){e.executePollRequest(t,n,r,i)}),d.timeoutMS):zn.isSimulatable(t.deepChat.stream,s)?zn.simulate(i,t.streamHandlers,d):(i.addNewMessage(d),a());case 13:case"end":return o.stop()}}),o)})));return function(e){return o.apply(this,arguments)}}()).catch((function(e){Mn.displayError(i,e),a()}))}},{key:"poll",value:(t=ce(se().mark((function t(n,r,i){var a,o,s,l,c,d,u,p,_,m,g,h,f,E=arguments;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=!(E.length>3&&void 0!==E[3])||E[3],c={body:r,headers:null==(o=n.requestSettings)?void 0:o.headers},t.next=4,Mn.processRequestInterceptor(n.deepChat,c);case 4:if(d=t.sent,u=d.body,p=d.headers,!(_=d.error)){t.next=10;break}return t.abrupt("return",Mn.onInterceptorError(i,_));case 10:m=(null==(s=n.requestSettings)?void 0:s.url)||n.url||"",g=(null==(l=n.requestSettings)?void 0:l.method)||"POST",h=a?JSON.stringify(u):u,f={method:g,body:h,headers:p},n.requestSettings.credentials&&(f.credentials=n.requestSettings.credentials),e.executePollRequest(n,m,f,i);case 12:case"end":return t.stop()}}),t)}))),function(e,n,r){return t.apply(this,arguments)})},{key:"verifyKey",value:function(e,t,n,r,i,a,o,s,l){if(""===e)return a(ke.INVALID_KEY);o(),fetch(t,{method:r,headers:n,body:l||null}).then((function(e){return Mn.processResponseByType(e)})).then((function(t){s(t,e,i,a)})).catch((function(e){a(ke.CONNECTION_FAILED),console.error(e)}))}}]),e}(),Kn=function(){function e(){me(this,e)}return he(e,null,[{key:"getCharacterLimitMessages",value:function(e,t){var n;if(-1===t)return e;for(var r=0,i=e.length-1;i>=0;i-=1){var a=null==(n=e[i])?void 0:n.text;if(void 0!==a&&(r+=a.length)>t){e[i].text=a.substring(0,a.length-(r-t));break}}return e.slice(Math.max(i,0))}},{key:"getMaxMessages",value:function(e,t){return e.slice(Math.max(e.length-t,0))}},{key:"processMessages",value:function(t,n,r){return void 0!==n?n>0&&(t=e.getMaxMessages(t,n)):t=[t[t.length-1]],t=JSON.parse(JSON.stringify(t)),void 0===r?t:e.getCharacterLimitMessages(t,r)}}]),e}(),Qn=function(){function e(){me(this,e)}return he(e,null,[{key:"parseConfig",value:function(e,t,n,r){var i,a={files:t};if("object"==_e(r)){var o=r.files,s=r.request,l=r.button;o&&(o.infoModal&&(a.files.infoModal=o.infoModal,null!=(i=o.infoModal)&&i.textMarkDown&&(a.infoModalTextMarkUp=n.render(o.infoModal.textMarkDown))),o.acceptedFormats&&(a.files.acceptedFormats=o.acceptedFormats),o.maxNumberOfFiles&&(a.files.maxNumberOfFiles=o.maxNumberOfFiles)),a.button=l,s&&(s.headers||s.method||s.url||s.credentials||e.headers||e.method||e.url||e.credentials)&&(a.request={url:(null==s?void 0:s.url)||e.url,method:(null==s?void 0:s.method)||e.method,headers:(null==s?void 0:s.headers)||e.headers,credentials:(null==s?void 0:s.credentials)||e.credentials})}return a}},{key:"processMixedFiles",value:function(t,n,r){if(r){t.fileTypes.mixedFiles=e.parseConfig(t.requestSettings,{acceptedFormats:""},n,r)}}},{key:"processMicrophone",value:function(t,n,r,i){var a,o,s,l,c,d,u,p,_=ue({acceptedFormats:"audio/*"},(null==(s=t.fileTypes.audio)?void 0:s.files)||{});r&&(void 0!==navigator.mediaDevices.getUserMedia?(t.recordAudio=e.parseConfig(t.requestSettings,_,n,r),"object"==_e(r)&&r.files&&(null!==(a=(l=t.recordAudio).files)&&void 0!==a||(l.files={}),t.recordAudio.files.format=null==(c=r.files)?void 0:c.format,t.recordAudio.files.maxDurationSeconds=null==(d=r.files)?void 0:d.maxDurationSeconds,null!=(u=t.fileTypes.audio)&&u.files&&(null!==(o=(p=t.fileTypes.audio.files).maxNumberOfFiles)&&void 0!==o||(p.maxNumberOfFiles=r.files.maxNumberOfFiles)))):i||(t.fileTypes.audio=e.parseConfig(t.requestSettings,_,n,r)))}},{key:"processAudioConfig",value:function(t,n,r,i){if(r||i){var a=ue({acceptedFormats:"audio/*"},(null==i?void 0:i.files)||{});t.fileTypes.audio=e.parseConfig(t.requestSettings,a,n,r)}}},{key:"processGifConfig",value:function(t,n,r,i){if(r||i){var a=ue({acceptedFormats:"image/gif"},(null==i?void 0:i.files)||{});t.fileTypes.gifs=e.parseConfig(t.requestSettings,a,n,r)}}},{key:"processCamera",value:function(t,n,r,i){var a,o,s,l,c,d=ue({acceptedFormats:"image/*"},(null==(o=t.fileTypes.images)?void 0:o.files)||{});r&&(void 0!==navigator.mediaDevices.getUserMedia?(t.camera=e.parseConfig(t.requestSettings,d,n,r),"object"==_e(r)&&(t.camera.modalContainerStyle=r.modalContainerStyle,r.files&&(null!==(a=(s=t.camera).files)&&void 0!==a||(s.files={}),t.camera.files.format=null==(l=r.files)?void 0:l.format,t.camera.files.dimensions=null==(c=r.files)?void 0:c.dimensions))):i||(t.fileTypes.images=e.parseConfig(t.requestSettings,d,n,r)))}},{key:"processImagesConfig",value:function(t,n,r,i){if(r||i){var a=ue({acceptedFormats:"image/*"},(null==i?void 0:i.files)||{});t.fileTypes.images=e.parseConfig(t.requestSettings,a,n,r)}}},{key:"populateDefaultFileIO",value:function(e,t){var n,r,i,a,o;e&&(null!==(n=e.files)&&void 0!==n||(e.files={}),null!==(r=(a=e.files).acceptedFormats)&&void 0!==r||(a.acceptedFormats=t),null!==(i=(o=e.files).maxNumberOfFiles)&&void 0!==i||(o.maxNumberOfFiles=1))}},{key:"set",value:function(t,n,r){e.populateDefaultFileIO(null==r?void 0:r.audio,".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),e.populateDefaultFileIO(null==r?void 0:r.images,".png,.jpg");var i=Cn.createNew();e.processImagesConfig(n,i,t.images,null==r?void 0:r.images),e.processCamera(n,i,t.camera,t.images),e.processGifConfig(n,i,t.gifs,null==r?void 0:r.gifs),e.processAudioConfig(n,i,t.audio,null==r?void 0:r.audio),e.processMicrophone(n,i,t.microphone,t.audio),e.processMixedFiles(n,i,t.mixedFiles)}}]),e}(),Xn=function(){function e(t,n,r){var i,a,o,s,l;me(this,e),this.rawBody={},this.validateConfigKey=!1,this.canSendMessage=e.canSendMessage,this.requestSettings={},this.fileTypes={},this.completionsHandlers={},this.streamHandlers={},this.deepChat=t,this.demo=r,Object.assign(this.rawBody,null==(a=t.request)?void 0:a.additionalBodyProps),this.totalMessagesMaxCharLength=null==(o=null==t?void 0:t.requestBodyLimits)?void 0:o.totalMessagesMaxCharLength,this.maxMessages=null==(s=null==t?void 0:t.requestBodyLimits)?void 0:s.maxMessages,Qn.set(t,this,n),t.request&&(this.requestSettings=t.request),this.demo&&(null!==(i=(l=this.requestSettings).url)&&void 0!==i||(l.url=Vn.URL)),this.requestSettings.websocket&&jn.setup(this)}var t,n,r,i,a,o;return he(e,[{key:"verifyKey",value:function(e,t){}},{key:"getServiceIOByType",value:function(e){if(e.type.startsWith("audio")&&this.fileTypes.audio)return this.fileTypes.audio;if(e.type.startsWith("image")){if(this.fileTypes.gifs&&e.type.endsWith("/gif"))return this.fileTypes.gifs;if(this.fileTypes.images)return this.fileTypes.images;if(this.camera)return this.camera}return this.fileTypes.mixedFiles}},{key:"request",value:(o=ce(se().mark((function e(t,n){var r,i,a=arguments;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=!(a.length>2&&void 0!==a[2])||a[2],i=this.deepChat.stream,e.abrupt("return",i&&!zn.isSimulation(i)?zn.request(this,t,n):Wn.request(this,t,n,r));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"callAPIWithText",value:(a=ce(se().mark((function e(t,n){var r,i,a,o,s,l,c,d;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c=ue({messages:n},this.rawBody),d=!1,null!=(a=this.requestSettings.headers)&&a["Content-Type"]||(null!==(r=(o=this.requestSettings).headers)&&void 0!==r||(o.headers={}),null!==(i=(s=this.requestSettings.headers)["Content-Type"])&&void 0!==i||(s["Content-Type"]="application/json"),d=!0),e.next=5,this.request(c,t);case 5:d&&(null==(l=this.requestSettings.headers)||delete l["Content-Type"]);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"callApiWithFiles",value:(i=ce(se().mark((function t(n,r,i){var a,o,s;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=e.createCustomFormDataBody(this.rawBody,r,i),o=this.requestSettings,s=this.getServiceIOByType(i[0]),this.requestSettings=(null==s?void 0:s.request)||this.requestSettings,t.next=4,this.request(a,n,!1);case 4:this.requestSettings=o;case 5:case"end":return t.stop()}}),t,this)}))),function(e,t,n){return i.apply(this,arguments)})},{key:"callServiceAPI",value:(r=ce(se().mark((function e(t,n,r){return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r?this.callApiWithFiles(t,n,r):this.callAPIWithText(t,n);case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"callAPI",value:(n=ce(se().mark((function e(t,n){var r,i;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=Kn.processMessages(n.messages,this.maxMessages,this.totalMessagesMaxCharLength),this.requestSettings.websocket?(i=ue({messages:r},this.rawBody),jn.sendWebsocket(this,i,n,!1)):this.callServiceAPI(n,r,t.files);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"extractResultData",value:(t=ce(se().mark((function e(t){return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.error){e.next=2;break}throw t.error;case 2:if(!t.result){e.next=4;break}return e.abrupt("return",Be.handleResponseProperty(t));case 4:if(!Mn.validateResponseFormat(t)){e.next=6;break}return e.abrupt("return",t);case 6:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"isDirectConnection",value:function(){return!1}},{key:"isWebModel",value:function(){return!1}}],[{key:"canSendMessage",value:function(e,t,n){return!!n||(!(!e||""===e.trim())||!!(t&&t.length>0))}},{key:"createCustomFormDataBody",value:function(e,t,n){var r=new FormData;n.forEach((function(e){return r.append("files",e)})),Object.keys(e).forEach((function(t){return r.append(t,String(e[t]))}));var i=0;t.slice(0,t.length-1).forEach((function(e){r.append("message".concat(i+=1),JSON.stringify(e))}));var a=t[t.length-1];return a.text&&(delete a.files,r.append("message".concat(i+=1),JSON.stringify(a))),r}}]),e}(),Zn=function(e){function t(e,n,r,i,a){var o,s;return me(this,t),(o=te(this,t,[e,a])).insertKeyPlaceholderText="API Key",o.keyHelpUrl="",Object.assign(o.rawBody,null==(s=e.request)?void 0:s.additionalBodyProps),o.keyVerificationDetails=n,o.buildHeadersFunc=r,i&&o.setApiKeyProperties(i),o.requestSettings=o.buildRequestSettings(o.key||"",e.request),o}return ae(t,e),he(t,[{key:"setApiKeyProperties",value:function(e){this.key=e.key,e.validateKeyProperty&&(this.validateConfigKey=e.validateKeyProperty)}},{key:"buildRequestSettings",value:function(e,t){var n,r=null!=t?t:{};return null!==(n=r.headers)&&void 0!==n||(r.headers={}),Object.assign(r.headers,this.buildHeadersFunc(e)),r}},{key:"keyAuthenticated",value:function(e,t){this.requestSettings=this.buildRequestSettings(t,this.requestSettings),this.key=t,e()}},{key:"verifyKey",value:function(e,t){var n=this.keyVerificationDetails,r=n.url,i=n.method,a=n.handleVerificationResult,o=n.createHeaders,s=n.body,l=(null==o?void 0:o(e))||this.buildHeadersFunc(e);Wn.verifyKey(e,r,l,i,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,a,s)}},{key:"isDirectConnection",value:function(){return!0}}]),t}(Xn),Jn=function(){function e(){me(this,e)}return he(e,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function(t){t._propUpdated_=!1,setTimeout((function(){t._propUpdated_?e.waitForPropertiesToBeUpdatedBeforeRender(t):(t._waitingToRender_=!1,t.onRender())}))}},{key:"attemptRender",value:function(t){t._propUpdated_=!0,t._waitingToRender_||(t._waitingToRender_=!0,e.waitForPropertiesToBeUpdatedBeforeRender(t))}}]),e}(),er=function(e){function t(){var e;return me(this,t),(e=te(this,t))._waitingToRender_=!1,e._propUpdated_=!1,Object.keys(t._attributeToProperty_).forEach((function(n){var r=t._attributeToProperty_[n];e.constructPropertyAccessors(r),e.hasOwnProperty(n)||e.constructPropertyAccessors(r,n)})),e}return ae(t,e),he(t,[{key:"constructPropertyAccessors",value:function(e,t){var n;Object.defineProperty(this,t||e,{get:function(){return n},set:function(r){n=r,t?this[e]=r:Jn.attemptRender(this)}})}},{key:"attributeChangedCallback",value:function(e,n,r){if(n!==r){var i=t._attributes_[e](r);this[t._attributeToProperty_[e]]=i}}},{key:"onRender",value:function(){}}],[{key:"observedAttributes",get:function(){return Object.keys(t._attributes_)||[]}}]),t}(ee(HTMLElement));er._attributes_={},er._attributeToProperty_={};var tr=er,nr=function(){function e(){me(this,e)}return he(e,null,[{key:"createSVGElement",value:function(e){return(new DOMParser).parseFromString(e,"image/svg+xml").documentElement}}]),e}(),rr=function(){function e(){me(this,e)}return he(e,null,[{key:"changeVisibility",value:function(t,n,r,i){i.target.id===e.VISIBLE_ICON_ID?(n.style.display="none",r.style.display="block",t.type="password"):(n.style.display="block",r.style.display="none",t.type="text")}},{key:"createIconElement",value:function(e,t){var n=nr.createSVGElement(e);return n.id=t,n.classList.add("visibility-icon"),n}},{key:"create",value:function(t){var n=document.createElement("div");n.id="visibility-icon-container";var r=e.createIconElement('\n\n\t\t\n\n',e.VISIBLE_ICON_ID);r.style.display="none",n.appendChild(r);var i=e.createIconElement('\n\n\t\t\n\n',"not-visible-icon");return n.appendChild(i),n.onclick=e.changeVisibility.bind(this,t,r,i),n}}]),e}();rr.VISIBLE_ICON_ID="visible-icon";var ir=rr,ar=function(){function e(){me(this,e)}return he(e,null,[{key:"createCautionText",value:function(){var e=document.createElement("a");return e.classList.add("insert-key-input-help-text"),e.innerText="Please exercise CAUTION when inserting your API key outside of deepchat.dev or localhost!!",e}},{key:"createHelpLink",value:function(e){var t=document.createElement("a");return t.classList.add("insert-key-input-help-text"),t.href=e,t.innerText="Find more info here",t.target="_blank",t}},{key:"createFailText",value:function(){var e=document.createElement("div");return e.id="insert-key-input-invalid-text",e.style.display="none",e}},{key:"createHelpTextContainer",value:function(t){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=document.createElement("div");r.id="insert-key-help-text-container";var i=document.createElement("div");i.id="insert-key-help-text-contents";var a=e.createFailText();if(i.appendChild(a),t){var o=e.createHelpLink(t);i.appendChild(o)}if(!0===n){var s=e.createCautionText();i.appendChild(s)}return r.appendChild(i),{helpTextContainerElement:r,failTextElement:a}}},{key:"onFail",value:function(e,t,n,r){e.classList.replace("insert-key-input-valid","insert-key-input-invalid"),n.innerText=r,n.style.display="block",t.innerText="Start",e.classList.remove("loading")}},{key:"onLoad",value:function(e,t){e.classList.add("loading"),t.innerHTML='
    '}},{key:"verifyKey",value:function(e,t,n){var r=e.value.trim();n.verifyKey(r,t)}},{key:"addVerificationEvents",value:function(t,n,r,i,a){var o={onSuccess:i,onFail:e.onFail.bind(this,t,n,r),onLoad:e.onLoad.bind(this,t,n)},s=e.verifyKey.bind(this,t,o,a);n.onclick=s,t.onkeydown=function(e){!t.classList.contains("loading")&&e.key===Te.ENTER&&s()}}},{key:"createStartButton",value:function(){var e=document.createElement("div");return e.id="start-button",e.innerText="Start",e}},{key:"onInputFocus",value:function(e){e.target.classList.replace("insert-key-input-invalid","insert-key-input-valid")}},{key:"createInput",value:function(t){var n=document.createElement("div");n.id="insert-key-input-container";var r=document.createElement("input");return r.id="insert-key-input",r.placeholder=t||"API Key",r.type="password",r.classList.add("insert-key-input-valid"),r.onfocus=e.onInputFocus,n.appendChild(r),n}},{key:"createContents",value:function(t,n){var r,i=document.createElement("div");i.id="insert-key-contents";var a=e.createInput(n.insertKeyPlaceholderText),o=a.children[0],s=ir.create(o);a.appendChild(s),i.appendChild(a);var l=e.createStartButton(),c=e.createHelpTextContainer(n.keyHelpUrl,null==(r=n.deepChat._insertKeyViewStyles)?void 0:r.displayCautionText),d=c.helpTextContainerElement,u=c.failTextElement;return i.appendChild(l),i.appendChild(d),e.addVerificationEvents(o,l,u,t,n),i}},{key:"createElements",value:function(t,n){var r=document.createElement("div");r.id="insert-key-view";var i=e.createContents(t,n);return r.appendChild(i),r}},{key:"render",value:function(t,n,r){var i=e.createElements(n,r);t.replaceChildren(i)}}]),e}(),or=function(){function e(){me(this,e)}return he(e,null,[{key:"enableButtons",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;window.webLLM?(t&&(t.disabled=!1),n&&(n.disabled=!1)):r<4*dr.MODULE_SEARCH_LIMIT_S&&setTimeout((function(){return e.enableButtons(t,n,r+1)}),250)}},{key:"setUpInitial",value:function(t,n,r,i){var a=(null==n?void 0:n.downloadClass)||e.DOWNLOAD_BUTTON_CLASS,o=(null==n?void 0:n.uploadClass)||e.UPLOAD_BUTTON_CLASS,s=(null==n?void 0:n.fileInputClass)||e.FILE_INPUT_CLASS;return setTimeout((function(){var n=null==r?void 0:r.getElementsByClassName(a)[0],i=null==r?void 0:r.getElementsByClassName(s)[0],l=null==r?void 0:r.getElementsByClassName(o)[0];n&&(n.onclick=function(){return t()}),i&&(i.onchange=function(){i.files&&i.files.length>0&&t(i.files)}),l&&(l.onclick=function(){return i.click()}),(n||l)&&e.enableButtons(n,l)})),(null==n?void 0:n.initialHtml)||'
    \n Download or upload a web model that will run entirely on your browser:
    \n \n ').concat(i?"":'\n '),"\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?"":'
    '),"\n ")}}]),e}();or.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",or.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",or.FILE_INPUT_CLASS="deep-chat-file-input",or.EXPORT_BUTTON_CLASS="deep-chat-export-button";var sr=or,lr={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},cr=function(e){function t(e){var n,r,i;return me(this,t),(n=te(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(e.webModel)&&(n._webModel=e.webModel),null!=(r=n._webModel.load)&&r.clearCache&&t.clearAllCache(),n.findModelInWindow(e),n.canSendMessage=n.canSubmit.bind(ne(n)),n._chatEl=null==(i=e.shadowRoot)?void 0:i.children[0],e.initialMessages&&t.setUpHistory(n._conversationHistory,e.initialMessages),n}var n,r,i,a,o,s,l,c,d,u;return ae(t,e),he(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.shouldAddInitialMessage(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:"shouldAddInitialMessage",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&&Pe.scrollToTop(null==(t=n._messages)?void 0:t.elementRef)}),e)}},{key:"getIntroMessage",value:function(e){if(this.shouldAddInitialMessage(e)&&this._chatEl){var t=sr.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),{role:je.AI_ROLE,html:t,sendUpdate:!1}}}},{key:"configureInit",value:(u=ce(se().mark((function e(t){var n;return se().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 u.apply(this,arguments)})},{key:"init",value:(d=ce(se().mark((function e(t){var n,r;return se().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 d.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 lr.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(lr));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:(c=ce(se().mark((function e(n,r){var i,a,o,s,l,c,d,u,p,_,m,g,h,f,E,S=this;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.scrollToTop(),t.chat=n,this._isModelLoading=!0,u=!1===(null==(i=this._webModel.introMessage)?void 0:i.displayed),p=function(e){var t;null==(t=S._messages)||t.addNewMessage({html:"
    ".concat(e.text,"
    "),overwrite:!0,sendUpdate:!1}),u&&(setTimeout((function(){var e;return Pe.scrollToBottom(null==(e=S._messages)?void 0:e.elementRef)})),u=!1)},t.chat.setInitProgressCallback(p),e.prev=4,m=this.getConfig(),g=m.model,h=m.appConfig,f={},this._webModel.instruction&&(f.conv_config={system:this._webModel.instruction}),this._conversationHistory.length>0&&(f.conversation_history=this._conversationHistory),e.next=10,t.chat.reload(g,f,h,r);case 10:_=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==(o=(a=this.deepChat)._validationHandler)||o.call(a),null!=(s=this._webModel.introMessage)&&s.removeAfterLoad?!1===this._webModel.introMessage.displayed?null==(c=this._messages)||c.removeLastMessage():null==(d=this._removeIntro)||d.call(this):(E=sr.setUpAfterLoad(_,this._webModel.introMessage,this._chatEl,!!this._webModel.worker),null==(l=this._messages)||l.addNewMessage({html:E,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 c.apply(this,arguments)})},{key:"unloadChat",value:(l=ce(se().mark((function e(n){var r;return se().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 l.apply(this,arguments)})},{key:"immediateResp",value:(s=ce(se().mark((function e(n,r,i){var a,o;return se().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,a={text:e.t0},e.next=6,t.processResponse(this.deepChat,n,a);case 6:(o=e.sent)&&n.addNewMessage(o),this.completionsHandlers.onFinish();case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return s.apply(this,arguments)})},{key:"streamResp",value:(o=ce(se().mark((function e(n,r,i){var a,o=this;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.streamHandlers.abortStream.abort=function(){i.interruptGenerate()},this.streamHandlers.onOpen(),a=new xn(n),e.next=4,i.generate(r,function(){var e=ce(se().mark((function e(r,i){var s;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.processResponse(o.deepChat,n,{text:i});case 2:(s=e.sent)&&a.upsertStreamedMessage({text:s.text,overwrite:!0});case 4:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}());case 4:a.finaliseStreamedMessage(),this.streamHandlers.onClose();case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return o.apply(this,arguments)})},{key:"generateRespByType",value:(a=ce(se().mark((function e(t,n,r,i){var a;return se().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==(a=this._messages)||a.addNewErrorMessage("service"),console.log(e.t0);case 13:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(e,t,n,r){return a.apply(this,arguments)})},{key:"generateResp",value:(i=ce(se().mark((function e(t,n,r){var i,a,o,s,l,c,d;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=n[n.length-1].text,e.next=3,Mn.processRequestInterceptor(this.deepChat,{body:{text:i}});case 3:a=e.sent,o=a.body,s=a.error,l=!!this.deepChat.stream;try{s?(Mn.displayError(t,new Error(s)),(l?this.streamHandlers.onClose:this.completionsHandlers.onFinish)()):o&&o.text?this.generateRespByType(t,o.text,!!this.deepChat.stream,r):(c=ke.INVALID_MODEL_REQUEST({body:o},!1),console.error(c),d=l?this.streamHandlers.onClose:this.completionsHandlers.onFinish,Mn.onInterceptorError(t,c,d))}catch(e){this.unloadChat(e)}case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return i.apply(this,arguments)})},{key:"callServiceAPI",value:(r=ce(se().mark((function e(n,r){var i,a;return se().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==(a=this._removeIntro)||a.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===je.USER_ROLE&&n.text){var i=t[r+1];null!=i&&i.text&&i.role!==je.USER_ROLE&&e.push([n.text,i.text])}}))}},{key:"processResponse",value:(n=ce(se().mark((function e(t,n,r){var i,a,o;return se().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(!(a=e.t0).error){e.next=11;break}return Mn.displayError(n,new Error(a.error)),e.abrupt("return");case 11:if(a&&a.text){e.next=15;break}return o=ke.INVALID_MODEL_RESPONSE(r,!!t.responseInterceptor,a),Mn.displayError(n,new Error(o)),e.abrupt("return");case 15:return e.abrupt("return",a);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)}))}))}))}}]),t}(Xn);cr.GENERIC_ERROR="Error, please check the [troubleshooting](https://deepchat.dev/docs/webModel#troubleshooting) section of documentation for help.",cr.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",cr.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",cr.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",cr.MODULE_SEARCH_LIMIT_S=5;var dr=cr,ur=function(){function e(){me(this,e)}return he(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(ke.INVALID_KEY)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api-inference.huggingface.co/models/gpt2",method:"POST",handleVerificationResult:e.handleVerificationResult}}}]),e}(),pr=function(e){function t(e,n,r,i,a,o){var s;return me(this,t),(s=te(this,t,[e,ur.buildKeyVerificationDetails(),ur.buildHeaders,a,o])).insertKeyPlaceholderText="Hugging Face Token",s.keyHelpUrl="https://huggingface.co/settings/tokens",s.introPanelMarkUp='\n
    Hugging Face
    \n

    First message may take an extented amount of time to complete as the model needs to be initialized.

    ',s.permittedErrorPrefixes=["Authorization header"],s.url="".concat(t.URL_PREFIX).concat(r),s.textInputPlaceholderText=n,"object"==_e(i)&&(i.model&&(s.url="".concat(t.URL_PREFIX).concat(i.model)),i.options&&(s.rawBody.options=i.options),i.parameters&&(s.rawBody.parameters=i.parameters)),s}var n;return ae(t,e),he(t,[{key:"preprocessBody",value:function(e,t,n){var r,i=JSON.parse(JSON.stringify(e)),a=t[t.length-1].text;if(a)return null!==(r=i.options)&&void 0!==r||(i.options={}),i.options.wait_for_model=!0,ue({inputs:a},i)}},{key:"callServiceAPI",value:(n=ce(se().mark((function e(t,n,r){var i;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:i=this.preprocessBody(this.rawBody,n,r),Wn.request(this,i,t);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})}]),t}(Zn);pr.URL_PREFIX="https://api-inference.huggingface.co/models/";var _r=pr,mr=function(e){function t(e,n,r,i,a,o){var s;return me(this,t),(s=te(this,t,[e,n,r,i,a,o])).isTextInputDisabled=!0,s.canSendMessage=t.canSendFile,s}var n;return ae(t,e),he(t,[{key:"preprocessBody",value:function(e,t,n){return n[0]}},{key:"callServiceAPI",value:(n=ce(se().mark((function e(t,n,r){return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){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:Wn.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])}}]),t}(_r),gr=function(e){function t(e){var n,r,i;return me(this,t),te(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:{}}])}var n;return ae(t,e),he(t,[{key:"extractPollResultData",value:(n=ce(se().mark((function e(t){var n;return se().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)})}]),t}(mr),hr=function(e){function t(e){var n,r,i;return me(this,t),te(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:{}}])}var n;return ae(t,e),he(t,[{key:"extractPollResultData",value:(n=ce(se().mark((function e(t){var n;return se().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)})}]),t}(mr),fr="data:image/png;base64,",Er=function(){function e(){me(this,e)}return he(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(ke.INVALID_KEY):n(t)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.stability.ai/v1/engines/list",method:"GET",handleVerificationResult:e.handleVerificationResult}}}]),e}(),Sr=function(e){function t(e,n,r,i,a){var o;return me(this,t),(o=te(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 ae(t,e),he(t)}(Zn),br=function(e){function t(e){var n,r;me(this,t);var i=JSON.parse(JSON.stringify(e.directConnection)),a=null==i?void 0:i.stabilityAI;(n=te(this,t,[e,Er.buildKeyVerificationDetails(),Er.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"==_e(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}var n,r;return ae(t,e),he(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=ce(se().mark((function e(t,n,r){var i;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){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]),Mn.tempRemoveContentHeader(this.requestSettings,Wn.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=ce(se().mark((function e(t){return se().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(fr).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])}}]),t}(Sr),vr=function(e){function t(e){var n,r;me(this,t);var i=JSON.parse(JSON.stringify(e.directConnection)),a=null==i?void 0:i.stabilityAI;(n=te(this,t,[e,Er.buildKeyVerificationDetails(),Er.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"==_e(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}var n,r;return ae(t,e),he(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=ce(se().mark((function e(t,n,r){var i,a,o,s;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){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:o=null==(a=null==(i=n[n.length-1])?void 0:i.text)?void 0:a.trim(),s=this.createFormDataBody(this.rawBody,r[0],r[1],o),Mn.tempRemoveContentHeader(this.requestSettings,Wn.request.bind(this,this,s,t),!1);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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(fr).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())}}]),t}(Sr),yr=function(e){function t(e){var n,r,i;return me(this,t),te(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:{}}])}var n;return ae(t,e),he(t,[{key:"extractPollResultData",value:(n=ce(se().mark((function e(t){return se().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)})}]),t}(mr),Tr=function(e){function t(e){var n,r,i;return me(this,t),te(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])}var n;return ae(t,e),he(t,[{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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[0].generated_text||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]),t}(_r),Cr=function(e){function t(e){var n,r,i,a;me(this,t);var o=null==(i=null==(r=e.directConnection)?void 0:r.huggingFace)?void 0:i.questionAnswer;return(n=te(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}var n;return ae(t,e),he(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=ce(se().mark((function e(t){return se().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)})}]),t}(_r),Rr=function(e){function t(e){var n,r,i;return me(this,t),te(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])}var n;return ae(t,e),he(t,[{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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[0].summary_text||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]),t}(_r),Or=function(e){function t(e){var n,r,i,a,o;return me(this,t),null!==(n=(r=te(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}var n;return ae(t,e),he(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,ue({inputs:{past_user_inputs:i.past_user_inputs,generated_responses:i.generated_responses,text:i.mostRecentMessageText}},r)}},{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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)})}]),t}(_r),Nr=function(e){function t(e){var n,r;me(this,t);var i=JSON.parse(JSON.stringify(e.directConnection)),a=i.stabilityAI;(n=te(this,t,[e,Er.buildKeyVerificationDetails(),Er.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"==_e(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}var n,r;return ae(t,e),he(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=ce(se().mark((function e(t,n,r){var i,a,o,s;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){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:o=null==(a=null==(i=n[n.length-1])?void 0:i.text)?void 0:a.trim(),s=this.createFormDataBody(this.rawBody,r[0],o),Mn.tempRemoveContentHeader(this.requestSettings,Wn.request.bind(this,this,s,t),!1);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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(fr).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())}}]),t}(Sr),Ar=function(e){function t(e){var n,r,i;return me(this,t),te(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])}var n;return ae(t,e),he(t,[{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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[0].translation_text||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]),t}(_r),Ir=function(e){function t(e){var n,r;me(this,t);var i=JSON.parse(JSON.stringify(e.directConnection)),a=i.stabilityAI;(n=te(this,t,[e,Er.buildKeyVerificationDetails(),Er.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"==_e(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}var n,r;return ae(t,e),he(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=ce(se().mark((function e(t,n){var r;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){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),Wn.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=ce(se().mark((function e(t){return se().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(fr).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())}}]),t}(Sr),wr=function(e){function t(e){var n,r,i,a;return me(this,t),(n=te(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}var n;return ae(t,e),he(t,[{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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[0].sequence||""});case 3:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]),t}(_r),xr=function(){function e(){me(this,e)}return he(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(ke.INVALID_KEY)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.cohere.ai/v1/generate",method:"POST",handleVerificationResult:e.handleVerificationResult,body:JSON.stringify({prompt:""})}}}]),e}(),Dr=function(e){function t(e,n,r,i,a){var o;return me(this,t),(o=te(this,t,[e,xr.buildKeyVerificationDetails(),xr.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"==_e(i)&&Object.assign(o.rawBody,i),o}return ae(t,e),he(t)}(Zn),Mr=function(e){function t(e){var n,r,i;return me(this,t),te(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])}var n,r;return ae(t,e),he(t,[{key:"preprocessBody",value:function(e,t){var n=JSON.parse(JSON.stringify(e)),r=t[t.length-1].text;if(r)return ue({prompt:r},n)}},{key:"callServiceAPI",value:(r=ce(se().mark((function e(t,n){var r;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),Wn.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=ce(se().mark((function e(t){var n;return se().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)})}]),t}(Dr),kr=function(e){function t(e){var n,r,i;return me(this,t),te(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])}var n,r;return ae(t,e),he(t,[{key:"preprocessBody",value:function(e,t){var n=JSON.parse(JSON.stringify(e)),r=t[t.length-1].text;if(r)return ue({text:r},n)}},{key:"callServiceAPI",value:(r=ce(se().mark((function e(t,n){var r;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),Wn.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=ce(se().mark((function e(t){return se().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)})}]),t}(Dr),Lr=function(){function e(){me(this,e)}var t;return he(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(ke.INVALID_KEY):r(ke.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=ce(se().mark((function e(t,n,r){var i,a,o=arguments;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=!(o.length>3&&void 0!==o[3])||o[3],t.requestSettings.method=r,e.next=4,Mn.fetch(t,t.requestSettings.headers,i,n).then((function(e){return Mn.processResponseByType(e)}));case 4:if(!(a=e.sent).error){e.next=7;break}throw a.error.message;case 7:return e.abrupt("return",a);case 8:case"end":return e.stop()}}),e)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}(),Pr=function(e){function t(e){var n,r,i,a,o,s;me(this,t);var l=JSON.parse(JSON.stringify(e.directConnection)),c=null==l?void 0:l.openAI;(i=te(this,t,[e,Lr.buildKeyVerificationDetails(),Lr.buildHeaders,c])).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==l?void 0:l.openAI)?void 0:a.textToSpeech;return"object"==_e(d)&&Object.assign(i.rawBody,d),null!==(n=(o=i.rawBody).model)&&void 0!==n||(o.model=t.DEFAULT_MODEL),null!==(r=(s=i.rawBody).voice)&&void 0!==r||(s.voice=t.DEFAULT_VOIDE),i.textInputPlaceholderText="Insert text to generate audio",i.rawBody.response_format="mp3",i}var n,r;return ae(t,e),he(t,[{key:"preprocessBody",value:function(e,t){var n,r,i=JSON.parse(JSON.stringify(e)),a=null==(r=null==(n=t[t.length-1])?void 0:n.text)?void 0:r.trim();return a&&""!==a&&(i.input=a),i}},{key:"callServiceAPI",value:(r=ce(se().mark((function e(t,n){var r,i;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(r=this.requestSettings)&&r.headers){e.next=2;break}throw new Error("Request settings have not been set up");case 2:this.url=this.requestSettings.url||this.url,i=this.preprocessBody(this.rawBody,n),Wn.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=ce(se().mark((function e(t){return se().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)})}]),t}(Zn);Pr.DEFAULT_MODEL="tts-1",Pr.DEFAULT_VOIDE="alloy";var Fr=Pr,Ur=function(e){function t(e){var n,r,i,a;me(this,t);var o=JSON.parse(JSON.stringify(e.directConnection)),s=null==o?void 0:o.openAI;(r=te(this,t,[e,Lr.buildKeyVerificationDetails(),Lr.buildHeaders,s,{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 l=null==(i=null==o?void 0:o.openAI)?void 0:i.audio;return"object"==_e(l)&&(r.processConfig(l),t.cleanConfig(l),Object.assign(r.rawBody,l)),null!==(n=(a=r.rawBody).model)&&void 0!==n||(a.model=t.DEFAULT_MODEL),r.rawBody.response_format="json",r.canSendMessage=t.canSendFileMessage,r}var n,r;return ae(t,e),he(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)),a=null==(r=null==(n=t[t.length-1])?void 0:n.text)?void 0:r.trim();return a&&""!==a&&(i.prompt=a),i}},{key:"callServiceAPI",value:(r=ce(se().mark((function e(n,r,i){var a,o,s;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(a=this.requestSettings)&&a.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.requestSettings.url||this._service_url,o=this.preprocessBody(this.rawBody,r),s=t.createFormDataBody(o,i[0]),Mn.tempRemoveContentHeader(this.requestSettings,Wn.request.bind(this,this,s,n),!1);case 7:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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}}]),t}(Zn);Ur.AUDIO_TRANSCRIPTIONS_URL="https://api.openai.com/v1/audio/transcriptions",Ur.AUDIO_TRANSLATIONS_URL="https://api.openai.com/v1/audio/translations",Ur.DEFAULT_MODEL="whisper-1";var Br=Ur,Gr=function(){function e(){me(this,e)}return he(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(ke.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(ke.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(ke.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}}]),e}(),Yr=function(e){function t(e){var n,r,i,a,o,s;me(this,t);var l=null==(a=null==(i=e.directConnection)?void 0:i.azure)?void 0:a.summarization,c=null==(o=e.directConnection)?void 0:o.azure;return(r=te(this,t,[e,Gr.buildSummarizationHeader,l.endpoint,c])).url="",r.textInputPlaceholderText="Insert text to summarize",null!==(n=(s=r.rawBody).language)&&void 0!==n||(s.language="en"),Object.assign(r.rawBody,l),r.url="".concat(l.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),r}var n,r,i;return ae(t,e),he(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:(i=ce(se().mark((function e(t,n){var r;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),Wn.request(this,r,t),this.messages=t;case 4:case"end":return e.stop()}}),e,this)}))),function(e,t){return i.apply(this,arguments)})},{key:"extractResultData",value:(r=ce(se().mark((function e(t){var n,r,i;return se().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.requestSettings)?void 0:n.headers},Wn.executePollRequest(this,r,i,this.messages)),e.abrupt("return",{makingAnotherRequest:!0});case 4:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"extractPollResultData",value:(n=ce(se().mark((function e(t){var n,r,i,a;return se().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="",r=X(t.tasks.items[0].results.documents[0].sentences);try{for(r.s();!(i=r.n()).done;)a=i.value,n+=a.text}catch(e){r.e(e)}finally{r.f()}return e.abrupt("return",{text:n||""});case 12:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})}]),t}(function(e){function t(e,n,r,i,a){var o;return me(this,t),(o=te(this,t,[e,Gr.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 ae(t,e),he(t)}(Zn)),Hr=function(){function e(){me(this,e)}var t;return he(e,null,[{key:"poll",value:(t=ce(se().mark((function e(t,n){var r,i,a,o;return se().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(a){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"!==(o=e.sent).status){e.next=18;break}a=o,e.next=22;break;case 18:if("error"!==o.status){e.next=20;break}throw new Error("Transcription failed: ".concat(o.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",a);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(ke.INVALID_KEY):r(ke.CONNECTION_FAILED):n(t)}},{key:"buildKeyVerificationDetails",value:function(){return{url:"https://api.assemblyai.com/v2/upload",method:"POST",handleVerificationResult:e.handleVerificationResult}}}]),e}(),zr=function(e){function t(e){var n,r;me(this,t);var i=null==(r=e.directConnection)?void 0:r.assemblyAI;return(n=te(this,t,[e,Hr.buildKeyVerificationDetails(),Hr.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}var n,r;return ae(t,e),he(t,[{key:"callServiceAPI",value:(r=ce(se().mark((function e(t,n,r){var i;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(i=this.requestSettings)&&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:Wn.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=ce(se().mark((function e(t){var n,r,i;return se().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.requestSettings)?void 0:n.headers)?void 0:r.Authorization,e.next=5,Hr.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])}}]),t}(Zn),qr=function(e){function t(e,n,r,i,a){var o;return me(this,t),(o=te(this,t,[e,Gr.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 ae(t,e),he(t)}(Zn),Vr=function(e){function t(e){var n,r,i,a,o,s,l,c,d,u;me(this,t);var p=null==(s=null==(o=e.directConnection)?void 0:o.azure)?void 0:s.textToSpeech,_=null==(l=e.directConnection)?void 0:l.azure;return(a=te(this,t,[e,Gr.buildTextToSpeechHeaders.bind({},(null==p?void 0:p.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),p.region,_])).introPanelMarkUp='\n
    Azure Text To Speech
    \n

    Insert text to synthesize it to audio.\n

    \n Click here for more info.\n

    '),a.url="",Object.assign(a.rawBody,p),null!==(n=(c=a.rawBody).lang)&&void 0!==n||(c.lang="en-US"),null!==(r=(d=a.rawBody).name)&&void 0!==r||(d.name="en-US-JennyNeural"),null!==(i=(u=a.rawBody).gender)&&void 0!==i||(u.gender="Female"),a.url="https://".concat(p.region,".tts.speech.microsoft.com/cognitiveservices/v1"),a}var n,r;return ae(t,e),he(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=ce(se().mark((function e(t,n){var r;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),Wn.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=ce(se().mark((function e(t){return se().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)})}]),t}(qr);Vr.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";var jr=Vr,$r=function(e){function t(e){var n,r,i,a;me(this,t);var o=null==(i=null==(r=e.directConnection)?void 0:r.azure)?void 0:i.speechToText,s=null==(a=e.directConnection)?void 0:a.azure;(n=te(this,t,[e,Gr.buildSpeechToTextHeaders,o.region,s,{audio:{files:{acceptedFormats:".wav,.ogg"}}}])).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",n.canSendMessage=t.canFileSendMessage;var l=o.lang||"en-US";return n.url="https://".concat(o.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(l,"&format=detailed"),n.recordAudio=void 0,n}var n,r;return ae(t,e),he(t,[{key:"callServiceAPI",value:(r=ce(se().mark((function e(t,n,r){var i,a;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(i=this.requestSettings)&&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!=(a=this.requestSettings)&&a.headers&&(this.requestSettings.headers["Content-Type"]=r[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),Wn.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=ce(se().mark((function e(t){return se().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])}}]),t}(qr);$r.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";var Wr=$r,Kr=function(e){function t(e){var n,r,i,a;me(this,t);var o=null==(i=null==(r=e.directConnection)?void 0:r.azure)?void 0:i.translation,s=null==(a=e.directConnection)?void 0:a.azure;return(n=te(this,t,[e,Gr.buildTranslationKeyVerificationDetails(o.region),Gr.buildTranslationHeaders.bind({},null==o?void 0:o.region),s])).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}var n,r;return ae(t,e),he(t,[{key:"preprocessBody",value:function(e){var t=e[e.length-1].text;if(t)return[{Text:t}]}},{key:"callServiceAPI",value:(r=ce(se().mark((function e(t,n){var r;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(n),Wn.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=ce(se().mark((function e(t){var n;return se().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)})}]),t}(Zn),Qr=function(){function e(){me(this,e)}var t,n,r,i;return he(e,null,[{key:"storeFiles",value:(i=ce(se().mark((function e(t,n,r){var i,a,o,s;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=t.requestSettings.headers){e.next=3;break}return e.abrupt("return");case 3:return t.url="https://api.openai.com/v1/files",a=i[Mn.CONTENT_TYPE],delete i[Mn.CONTENT_TYPE],o=r.map(function(){var e=ce(se().mark((function e(n){var r;return se().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(Lr.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 s=e.sent.map((function(e){return e.id})),e.abrupt("return",(i[Mn.CONTENT_TYPE]=a,s));case 14:throw e.prev=14,e.t0=e.catch(7),i[Mn.CONTENT_TYPE]=a,Mn.displayError(n,e.t0),t.completionsHandlers.onFinish(),e.t0;case 17:case"end":return e.stop()}}),e,null,[[7,14]])}))),function(e,t,n){return i.apply(this,arguments)})},{key:"getType",value:function(e,t){var n=e[t].path;return!n||n.endsWith("png")?"image":"any"}},{key:"getFiles",value:(r=ce(se().mark((function t(n,r){var i,a;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=r.map((function(e){var t=e.fileId;return n.url="https://api.openai.com/v1/files/".concat(t,"/content"),new Promise((function(e){e(Lr.directFetch(n,void 0,"GET",!1))}))})),t.next=3,Promise.all(i);case 3:return a=t.sent.map((function(t,n){return new Promise((function(i){var a=new FileReader;a.readAsDataURL(t),a.onload=function(t){i({src:t.target.result,name:r[n].name,type:e.getType(r,n)})}}))})),t.next=6,Promise.all(a);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t)}))),function(e,t){return r.apply(this,arguments)})},{key:"getFileName",value:function(e){var t=e.split("/");return t[t.length-1]}},{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:"getFilesAndNewText",value:(n=ce(se().mark((function t(n,r,i,a){var o,s,l;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.t0=r.length>0,!t.t0){t.next=6;break}return t.next=4,e.getFiles(n,r);case 4:l=t.sent,null!=(o=null==a?void 0:a.text)&&o.value&&l.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 6:return t.abrupt("return",{files:l,text:null==(s=null==a?void 0:a.text)?void 0:s.value,role:i});case 7:case"end":return t.stop()}}),t)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"getFilesAndText",value:(t=ce(se().mark((function t(n,r,i){var a;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=e.getFileDetails(r,i),t.next=3,e.getFilesAndNewText(n,a,r.role,i);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t)}))),function(e,n,r){return t.apply(this,arguments)})}]),e}(),Xr=function(e){function t(e){var n,r,i,a,o,s,l,c,d;me(this,t);var u=JSON.parse(JSON.stringify(e.directConnection)),p=u.openAI;(i=te(this,t,[e,Lr.buildKeyVerificationDetails(),Lr.buildHeaders,p])).insertKeyPlaceholderText="OpenAI API Key",i.keyHelpUrl="https://platform.openai.com/account/api-keys",i.url="",i.permittedErrorPrefixes=["Incorrect"],i.searchedForThreadId=!1,i.config={},i.newAssistantDetails={model:"gpt-4"},i.shouldFetchHistory=!1;var _=null==(a=u.openAI)?void 0:a.assistant;if("object"==_e(_)){i.config=_;var m=i.config,g=m.new_assistant,h=m.thread_id,f=m.load_thread_history;Object.assign(i.newAssistantDetails,g),h&&(i.sessionId=h),f&&(i.shouldFetchHistory=!0);var E=(null==(s=null==(o=e.directConnection)?void 0:o.openAI)?void 0:s.assistant).function_handler;E&&(i._functionHandler=E)}else null!=(l=u.openAI)&&l.assistant&&(u.openAI.assistant=_);return null!==(n=(c=i.requestSettings).headers)&&void 0!==n||(c.headers={}),null!==(r=(d=i.requestSettings.headers)["OpenAI-Beta"])&&void 0!==r||(d["OpenAI-Beta"]="assistants=v1"),i.maxMessages=1,i.shouldFetchHistory&&i.sessionId&&(i.fetchHistory=i.fetchHistoryFunc.bind(ne(i))),i}var n,r,i,a,o,s,l,c;return ae(t,e),he(t,[{key:"fetchHistoryFunc",value:(c=ce(se().mark((function e(){var t,n=this;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return setTimeout((function(){return n.deepChat.disableSubmitButton()}),2),e.prev=1,e.next=4,this.getThreadMessages(this.sessionId,!0);case 4:return t=e.sent,e.abrupt("return",(this.deepChat.disableSubmitButton(!1),t.reverse()));case 8:return e.prev=8,e.t0=e.catch(1),e.abrupt("return",[{error:"failed to fetch thread history"}]);case 11:case"end":return e.stop()}}),e,this,[[1,8]])}))),function(){return c.apply(this,arguments)})},{key:"processMessage",value:function(e,t){var n=this.totalMessagesMaxCharLength||-1;return{content:Kn.getCharacterLimitMessages(e,n)[0].text||"",role:"user",file_ids:t}}},{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,n,r){if(this.sessionId){this.url="".concat(t.THREAD_PREFIX,"/").concat(this.sessionId,"/messages");var i=this.processMessage(n,r);Wn.request(this,i,e)}else{this.url="".concat(t.THREAD_PREFIX,"/runs");var a=this.createNewThreadMessages(this.rawBody,n,r);Wn.request(this,a,e)}this.messages=e}},{key:"callServiceAPI",value:(l=ce(se().mark((function e(t,n,r){var i,a,o;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:if(null===(i=(a=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:a.assistant_id=e.t0;case 12:if(this.searchedForThreadId||this.searchPreviousMessagesForThreadId(t.messages),!r){e.next=19;break}return e.next=16,Qr.storeFiles(this,t,r);case 16:e.t1=e.sent,e.next=20;break;case 19:e.t1=void 0;case 20:o=e.t1,this.requestSettings.method="POST",this.callService(t,n,o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return l.apply(this,arguments)})},{key:"createNewAssistant",value:(s=ce(se().mark((function e(){var n;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,this.url=t.NEW_ASSISTANT_URL,e.next=4,Lr.directFetch(this,JSON.parse(JSON.stringify(this.newAssistantDetails)),"POST");case 4:return n=e.sent,e.abrupt("return",(this.config.assistant_id=n.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 s.apply(this,arguments)})},{key:"searchPreviousMessagesForThreadId",value:function(e){var t=e.find((function(e){return e._sessionId}));t&&(this.sessionId=t._sessionId),this.searchedForThreadId=!0}},{key:"extractResultData",value:(o=ce(se().mark((function e(n){var r,i,a;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n.error){e.next=2;break}throw n.error.message;case 2:return e.next=4,this.assignThreadAndRun(n);case 4:return i="".concat(t.THREAD_PREFIX,"/").concat(this.sessionId,"/runs/").concat(this.run_id),a={method:"GET",headers:null==(r=this.requestSettings)?void 0:r.headers},e.abrupt("return",(Wn.executePollRequest(this,i,a,this.messages),{makingAnotherRequest:!0}));case 6:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"assignThreadAndRun",value:(a=ce(se().mark((function e(n){var r;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.sessionId){e.next=8;break}return this.url="".concat(t.THREAD_PREFIX,"/").concat(this.sessionId,"/runs"),e.next=4,Lr.directFetch(this,JSON.parse(JSON.stringify(this.rawBody)),"POST");case 4:r=e.sent,this.run_id=r.id,e.next=9;break;case 8:this.sessionId=n.thread_id,this.run_id=n.id,this.messages&&(this.messages.messages[this.messages.messages.length-1]._sessionId=this.sessionId);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"getThreadMessages",value:(i=ce(se().mark((function e(n){var r,i,a,o,s,l=this,c=arguments;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=c.length>1&&void 0!==c[1]&&c[1],this.url="".concat(t.THREAD_PREFIX,"/").concat(n,"/messages"),e.next=4,Lr.directFetch(this,{},"GET");case 4:if(o=e.sent,e.t0=!r&&this.deepChat.responseInterceptor,!e.t0){e.next=10;break}return e.next=9,null==(a=(i=this.deepChat).responseInterceptor)?void 0:a.call(i,o);case 9:o=e.sent;case 10:return s=(r?o.data:[o.data[0]]).map(function(){var e=ce(se().mark((function e(t){var n;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.content.find((function(e){return!!e.text||!!e.image_file})),e.next=3,Qr.getFilesAndText(l,t,n);case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),e.abrupt("return",Promise.all(s));case 12:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"extractPollResultData",value:(r=ce(se().mark((function e(n){var r,i,a,o,s,l,c,d,u,p,_;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=n.status,s=n.required_action,"queued"!==o&&"in_progress"!==o){e.next=3;break}return e.abrupt("return",{timeoutMS:t.POLLING_TIMEOUT_MS});case 3:if("completed"!==o||!this.messages){e.next=11;break}return e.next=6,this.getThreadMessages(n.thread_id);case 6:return l=e.sent,c=l[0],d=c.text,u=c.files,e.abrupt("return",{text:d,_sessionId:this.sessionId,files:u});case 11:if(p=null==(r=null==s?void 0:s.submit_tool_outputs)?void 0:r.tool_calls,"requires_action"!==o||!p){e.next=22;break}return e.next=15,this.handleTools(p);case 15:return _=e.sent,e.next=18,null==(a=(i=this.deepChat).responseInterceptor)?void 0:a.call(i,_);case 18:if(e.t0=e.sent,e.t0){e.next=21;break}e.t0=_;case 21:return e.abrupt("return",e.t0);case 22:throw Error("Thread run status: ".concat(o));case 23:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"handleTools",value:(n=ce(se().mark((function e(n){var r,i,a;return se().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)&&!i.find((function(e){return"string"!=typeof e}))&&n.length===i.length){e.next=8;break}throw Error("Response must contain an array of strings for each individual function/tool_call, see https://deepchat.dev/docs/directConnection/OpenAI/#assistant-functions.");case 8:return a=i.map((function(e,t){return{tool_call_id:n[t].id,output:e}})),this.url="".concat(t.THREAD_PREFIX,"/").concat(this.sessionId,"/runs/").concat(this.run_id,"/submit_tool_outputs"),e.next=12,Lr.directFetch(this,{tool_outputs:a},"POST");case 12:return e.abrupt("return",{timeoutMS:t.POLLING_TIMEOUT_MS});case 13:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}]),t}(Zn);Xr.THREAD_PREFIX="https://api.openai.com/v1/threads",Xr.NEW_ASSISTANT_URL="https://api.openai.com/v1/assistants",Xr.POLLING_TIMEOUT_MS=800;var Zr=Xr,Jr=function(e){function t(e){var n,r;me(this,t);var i=e.directConnection,a=null==i?void 0:i.openAI;(n=te(this,t,[e,Lr.buildKeyVerificationDetails(),Lr.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·E
    \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 s="object"==_e(o)&&o.size?Number.parseInt(o.size):1024;n.camera.files={dimensions:{width:s,height:s}}}return"object"==_e(o)&&Object.assign(n.rawBody,o),n.canSendMessage=t.canFileSendMessage,n}var n,r;return ae(t,e),he(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,a,o,s=null==(a=null==(i=n[n.length-1])?void 0:i.text)?void 0:a.trim();if(r[1]||s&&""!==s){this.url=t.IMAGE_EDIT_URL;var l=this.preprocessBody(this.rawBody,s);o=t.createFormDataBody(l,r[0],r[1])}else this.url=t.IMAGE_VARIATIONS_URL,o=t.createFormDataBody(this.rawBody,r[0]);Mn.tempRemoveContentHeader(this.requestSettings,Wn.request.bind(this,this,o,e),!1)}},{key:"callServiceAPI",value:(r=ce(se().mark((function e(n,r,i){var a,o;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=(a=this.requestSettings)&&a.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.requestSettings){e.next=8;break}throw new Error("Request settings have not been set up");case 8:this.url=t.IMAGE_GENERATION_URL,o=this.preprocessBody(this.rawBody,r[r.length-1].text),Wn.request(this,o,n);case 11:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"extractResultData",value:(n=ce(se().mark((function e(t){return se().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(fr).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}}]),t}(Zn);Jr.IMAGE_GENERATION_URL="https://api.openai.com/v1/images/generations",Jr.IMAGE_VARIATIONS_URL="https://api.openai.com/v1/images/variations",Jr.IMAGE_EDIT_URL="https://api.openai.com/v1/images/edits";var ei=Jr,ti=function(e){function t(e){var n,r,i,a,o,s,l;me(this,t);var c=JSON.parse(JSON.stringify(e.directConnection)),d=c.openAI;(i=te(this,t,[e,Lr.buildKeyVerificationDetails(),Lr.buildHeaders,d])).insertKeyPlaceholderText="OpenAI API Key",i.keyHelpUrl="https://platform.openai.com/account/api-keys",i.url="https://api.openai.com/v1/chat/completions",i.permittedErrorPrefixes=["Incorrect"],i.asyncCallInProgress=!1,i._systemMessage=t.generateSystemMessage("You are a helpful assistant.");var u=null==(a=c.openAI)?void 0:a.chat;if("object"==_e(u)){u.system_prompt&&(i._systemMessage=t.generateSystemMessage(u.system_prompt));var p=(null==(s=null==(o=e.directConnection)?void 0:o.openAI)?void 0:s.chat).function_handler;p&&(i._functionHandler=p),i.cleanConfig(u),Object.assign(i.rawBody,u)}return null!==(n=i.maxMessages)&&void 0!==n||(i.maxMessages=-1),null!==(r=(l=i.rawBody).model)&&void 0!==r||(l.model="gpt-3.5-turbo"),i}var n,r,i,a;return ae(t,e),he(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)),a=Kn.getCharacterLimitMessages(n,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this._systemMessage.content.length:-1).map((function(e){return{content:t.getContent(e),role:e.role===je.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(Q(a)),i}},{key:"callServiceAPI",value:(a=ce(se().mark((function e(t,n){var r,i;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),(i=this.deepChat.stream)&&("object"!=_e(i)||!i.simulation)||r.stream?(r.stream=!0,zn.request(this,r,t)):Wn.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=ce(se().mark((function e(t,n,r){var i,a,o,s;return se().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!=(a=null==(i=t.choices)?void 0:i[0])&&a.delta?this.extractStreamResult(t.choices[0],n,r):null!=(s=null==(o=t.choices)?void 0:o[0])&&s.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=ce(se().mark((function e(t,n,r){var i,a,o=this;return se().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,a={tool_calls:this._streamToolCalls},e.abrupt("return",(this._streamToolCalls=void 0,this.handleTools(a,n,r)));case 7:null!=i&&i.tool_calls&&(this._streamToolCalls?i.tool_calls.forEach((function(e,t){o._streamToolCalls&&(o._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=ce(se().mark((function e(t,n,r){var i,a,o,s,l,c,d,u,p,_;return se().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)),d=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,d);case 6:if(!(u=e.sent).text){e.next=15;break}return p={text:u.text},e.next=11,null==(o=(a=this.deepChat).responseInterceptor)?void 0:o.call(a,p);case 11:if(e.t0=e.sent,e.t0){e.next=14;break}e.t0=p;case 14:return e.abrupt("return",e.t0);case 15:if(c.messages.push({tool_calls:t.tool_calls,role:"assistant",content:null}),(!Array.isArray(u)||u.find((function(e){return"string"!=typeof e})))&&d.length!==u.length){e.next=35;break}return u.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=17,e.next=20,null==n?void 0:n(c).then((function(e){return Mn.processResponseByType(e)}));case 20:return _=e.sent,e.next=23,null==(l=(s=this.deepChat).responseInterceptor)?void 0:l.call(s,_);case 23:if(e.t1=e.sent,e.t1){e.next=26;break}e.t1=_;case 26:if(!(_=e.t1).error){e.next=29;break}throw _.error.message;case 29:return e.abrupt("return",{text:_.choices[0].message.content||""});case 32:throw e.prev=32,e.t2=e.catch(17),this.asyncCallInProgress=!1,e.t2;case 35:throw 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.");case 36:case"end":return e.stop()}}),e,this,[[17,32]])}))),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}}]),t}(Zn),ni=function(e){function t(e){var n,r,i;me(this,t);var a=JSON.parse(JSON.stringify(e.directConnection)),o=null==(i=a.cohere)?void 0:i.chat;return r=te(this,t,[e,"https://api.cohere.ai/v1/chat","Ask me anything!",o,a.cohere]),"object"==_e(o)&&Object.assign(r.rawBody,o),null!==(n=r.maxMessages)&&void 0!==n||(r.maxMessages=-1),r}var n,r;return ae(t,e),he(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=ce(se().mark((function e(t,n){var r;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.requestSettings){e.next=2;break}throw new Error("Request settings have not been set up");case 2:r=this.preprocessBody(this.rawBody,n),Wn.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=ce(se().mark((function e(t){return se().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)})}]),t}(Dr),ri=function(){function e(){me(this,e)}return he(e,null,[{key:"create",value:function(e){var t=e.directConnection,n=e.request,r=e.demo;if(e.webModel)return new dr(e);if(t){if(t.openAI)return t.openAI.images?new ei(e):t.openAI.speechToText?new Br(e):t.openAI.textToSpeech?new Fr(e):t.openAI.assistant?new Zr(e):new ti(e);if(t.assemblyAI)return new zr(e);if(t.cohere)return t.cohere.textGeneration?new Mr(e):t.cohere.summarization?new kr(e):new ni(e);if(t.huggingFace)return t.huggingFace.textGeneration?new Tr(e):t.huggingFace.summarization?new Rr(e):t.huggingFace.translation?new Ar(e):t.huggingFace.fillMask?new wr(e):t.huggingFace.questionAnswer?new Cr(e):t.huggingFace.audioSpeechRecognition?new yr(e):t.huggingFace.audioClassification?new gr(e):t.huggingFace.imageClassification?new hr(e):new Or(e);if(t.azure){if(t.azure.speechToText)return new Wr(e);if(t.azure.textToSpeech)return new jr(e);if(t.azure.summarization)return new Yr(e);if(t.azure.translation)return new Kr(e)}if(t.stabilityAI)return t.stabilityAI.imageToImage?new Nr(e):t.stabilityAI.imageToImageUpscale?new br(e):t.stabilityAI.imageToImageMasking?new vr(e):new Ir(e)}return n?new Xn(e):new Xn(e,void 0,r||!0)}}]),e}(),ii=function(){function e(){me(this,e)}return he(e,null,[{key:"appendStyleSheetToHead",value:function(){var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some((function(t){return t.getAttribute("href")===e.FONT_URL}))){var n=document.createElement("link");n.rel="stylesheet",n.href=e.FONT_URL,t.appendChild(n)}}}]),e}();ii.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap";var ai=ii,oi=he((function e(){me(this,e)}));function si(e){return function(t,n){Object.defineProperty(t,n,{});var r=t.constructor,i=n.toLocaleLowerCase();r._attributes_[i]=oi.attibutes[e],r._attributeToProperty_[i]=n}}oi.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 li=function(){function e(){me(this,e)}return he(e,null,[{key:"colorToHex",value:function(e){var t=document.createElement("div");return t.style.color=e,document.body.appendChild(t),"#".concat(window.getComputedStyle(t).color.match(/\d+/g).map((function(e){return parseInt(e).toString(16).padStart(2,"0")})).join(""))}},{key:"set",value:function(t,n){var r,i,a,o;if(null!=(i=null==(r=null==n?void 0:n.loading)?void 0:r.bubble)&&i.color){var s=e.colorToHex(null==(o=null==(a=null==n?void 0:n.loading)?void 0:a.bubble)?void 0:o.color);t.style.setProperty("--message-dots-color",s),t.style.setProperty("--message-dots-color-fade","".concat(s,"33"))}else t.style.setProperty("--message-dots-color","#848484"),t.style.setProperty("--message-dots-color-fade","#55555533")}}]),e}(),ci=function(){function e(t,n,r){me(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 he(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}}]),e}(),di=function(){function e(){me(this,e)}return he(e,null,[{key:"getText",value:function(e,t){var n;if(!(e.directConnection||e.request||e.webModel||e.demo))return"Connect to any API using the [request](https://deepchat.dev/docs/connect#Request)\n property or a popular service via\n [directConnection](https://deepchat.dev/docs/directConnection/#directConnection).\n \n Host AI entirely on your browser via a [webModel](https://deepchat.dev/docs/webModel).\n \n To get started checkout the [Start](https://deepchat.dev/start) page and\n live code [examples](https://deepchat.dev/examples/frameworks).\n \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"==_e(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.request&&!e.request.url&&!e.request.handler)return"Please define a `url` or a `handler` property inside the [request](https://deepchat.dev/docs/connect#Request) object.";return null}}]),e}(),ui=function(){function e(){me(this,e)}var t;return he(e,null,[{key:"createImage",value:function(e,t){var n=new Image;return n.src=e.src,On.scrollDownOnImageLoad(n.src,t),On.processContent("image",n,n.src,e.name)}},{key:"addNewImageMessage",value:(t=ce(se().mark((function t(n,r,i){var a,o;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=e.createImage(r,n.elementRef),(o=n.createNewMessageElement("",i)).bubbleElement.appendChild(a),o.bubbleElement.classList.add("image-message"),On.addMessage(n,o,"image",i);case 2:case"end":return t.stop()}}),t)}))),function(e,n,r){return t.apply(this,arguments)})},{key:"createAudioElement",value:function(e,t){var n=document.createElement("audio");return n.src=e.src,n.classList.add("audio-player"),n.controls=!0,Ce.IS_SAFARI&&(n.classList.add("audio-player-safari"),n.classList.add(t===je.USER_ROLE?"audio-player-safari-right":"audio-player-safari-left")),n}},{key:"addNewAudioMessage",value:function(t,n,r){var i=e.createAudioElement(n,r),a=t.createNewMessageElement("",r);a.bubbleElement.appendChild(i),a.bubbleElement.classList.add("audio-message"),On.addMessage(t,a,"audio",r)}},{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=nr.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||On.DEFAULT_FILE_NAME,t.appendChild(n),t.appendChild(i),On.processContent("any",t,e.src,i.textContent)}},{key:"addNewAnyFileMessage",value:function(t,n,r){var i=t.createNewMessageElement("",r),a=e.createAnyFile(n);i.bubbleElement.classList.add("any-file-message-bubble"),i.bubbleElement.appendChild(a),On.addMessage(t,i,"file",r)}},{key:"addMessages",value:function(t,n,r){n.forEach((function(n){var i,a;n.ref&&(n=On.removeFileRef(n)),"audio"===n.type||null!=(i=n.src)&&i.startsWith("data:audio")?e.addNewAudioMessage(t,n,r):"image"===n.type||null!=(a=n.src)&&a.startsWith("data:image")?e.addNewImageMessage(t,n,r):e.addNewAnyFileMessage(t,n,r)}))}}]),e}(),pi=function(e){function t(e,n,r){var i,a,o;me(this,t),i=te(this,t,[e]);var s=n.permittedErrorPrefixes,l=n.introPanelMarkUp,c=n.demo;return i._errorMessageOverrides=null==(a=e.errorMessages)?void 0:a.overrides,i._onClearMessages=Nn.onClearMessages.bind(ne(i),e),i._onError=Nn.onError.bind(ne(i),e),i._displayLoadingMessage=t.getDisplayLoadingMessage(e,n),i._permittedErrorPrefixes=s,i.addSetupMessageIfNeeded(e,n)||i.populateIntroPanel(r,l,e.introPanelStyle),i.addIntroductoryMessage(e,n),e.initialMessages&&i.populateInitialMessages(e.initialMessages),i._displayServiceErrorMessages=null==(o=e.errorMessages)?void 0:o.displayServiceErrorMessages,e.getMessages=function(){return JSON.parse(JSON.stringify(i.messages))},e.clearMessages=i.clearMessages.bind(ne(i),n),e.refreshMessages=i.refreshTextMessages.bind(ne(i)),e.scrollToBottom=Pe.scrollToBottom.bind(ne(i),i.elementRef),e._addMessage=function(e,t){i.addNewMessage(ue(ue({},e),{},{sendUpdate:!!t}),!t)},n.isWebModel()&&n.setUpMessages(ne(i)),c&&i.prepareDemo(c),e.textToSpeech&&Ue.processConfig(e.textToSpeech,(function(e){i.textToSpeech=e})),n.fetchHistory&&i.fetchHistory(n.fetchHistory),i}var n,r;return ae(t,e),he(t,[{key:"prepareDemo",value:function(e){"object"==_e(e)&&(e.response&&(this.customDemoResponse=e.response),e.displayErrors&&(e.displayErrors.default&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage("service",""),e.displayErrors.speechToText&&this.addNewErrorMessage("speechToText","")),e.displayLoadingBubble&&this.addLoadingMessage())}},{key:"addSetupMessageIfNeeded",value:function(e,t){var n=di.getText(e,t);if(n){var r=this.createAndAppendNewMessageElement(n,je.AI_ROLE);this.applyCustomStyles(r,je.AI_ROLE,!1)}return!!n}},{key:"addIntroductoryMessage",value:function(e,t){var n,r;null!=e&&e.shadowRoot&&(this._introMessage=e.introMessage);var i,a=this._introMessage;(null!=t&&t.isWebModel()&&(null!==(n=a)&&void 0!==n||(a=t.getIntroMessage(a))),a)&&(null!=a&&a.text?i=this.createAndAppendNewMessageElement(a.text,je.AI_ROLE):null!=a&&a.html&&(i=Ze.add(this,a.html,je.AI_ROLE,this.messageElementRefs)),i&&(this.applyCustomStyles(i,je.AI_ROLE,!1,null==(r=this.messageStyles)?void 0:r.intro),i.outerContainer.classList.add("deep-chat-intro")))}},{key:"removeIntroductoryMessage",value:function(){var e=this.messageElementRefs[0];e.outerContainer.classList.contains("deep-chat-intro")&&(e.outerContainer.remove(),this.messageElementRefs.shift())}},{key:"populateInitialMessages",value:function(e){var t=this;e.forEach((function(e){Be.processInitialMessageFile(e),t.addNewMessage(e,!0)})),setTimeout((function(){return Pe.scrollToBottom(t.elementRef)}),0)}},{key:"fetchHistory",value:(r=ce(se().mark((function e(t){var n=this;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t();case 2:e.sent.forEach((function(e){e.error?n.addNewErrorMessage("service",e.error):n.addNewMessage(e,!0)})),setTimeout((function(){return Pe.scrollToBottom(n.elementRef)}),0);case 4:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})},{key:"addNewMessage",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=t.createMessageContent(e),i={status:e.overwrite};if(!e.ignoreText&&void 0!==r.text&&null!==e.text&&(this.addNewTextMessage(r.text,r.role,i),!n&&this.textToSpeech&&r.role!==je.USER_ROLE&&Ue.speak(r.text,this.textToSpeech)),r.files&&Array.isArray(r.files)&&ui.addMessages(this,r.files,r.role),void 0!==r.html&&null!==r.html){var a=Ze.add(this,r.html,r.role,this.messageElementRefs,i);Qe.isElementTemporary(a)&&delete r.html}this.isValidMessageContent(r)&&this.updateStateOnMessage(r,e.overwrite,e.sendUpdate,n)}},{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];t||this.messages.push(e),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(xn.MESSAGE_CLASS)&&""===n.textContent||t.isTemporaryElement(e))&&this.removeLastMessage()}},{key:"addNewErrorMessage",value:function(e,n){var r,i,a,o,s;this.removeMessageOnError();var l=t.createBaseElements(),c=l.outerContainer,d=l.bubbleElement;d.classList.add("error-message-text");var u=this.getPermittedMessage(n)||(null==(r=this._errorMessageOverrides)?void 0:r[e])||(null==(i=this._errorMessageOverrides)?void 0:i.default)||"Error, please try again.";this.renderText(d,u);var p=An.extractParticularSharedStyles(["fontSize","fontFamily"],null==(a=this.messageStyles)?void 0:a.default);An.applyCustomStylesToElements(l,!1,p),An.applyCustomStylesToElements(l,!1,null==(o=this.messageStyles)?void 0:o.error),this.elementRef.appendChild(c),Pe.scrollToBottom(this.elementRef),this.textToSpeech&&Ue.speak(u,this.textToSpeech),null==(s=this._onError)||s.call(this,u)}},{key:"getPermittedMessage",value:function(e){if(e){if(this._displayServiceErrorMessages)return e;if("string"==typeof e&&this._permittedErrorPrefixes){var n=t.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,e);if(n)return n}else if(Array.isArray(e)&&this._permittedErrorPrefixes)for(var 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)}}]),e}();_i.INPUT_OUTSIDE_LEFT_ADJUSTMENT_CLASS="text-input-container-left-adjustment",_i.INPUT_OUTSIDE_RIGHT_ADJUSTMENT_CLASS="text-input-container-right-adjustment",_i.INPUT_OUTSIDE_LEFT_SMALL_ADJUSTMENT_CLASS="text-input-container-left-small-adjustment",_i.INPUT_OUTSIDE_RIGHT_SMALL_ADJUSTMENT_CLASS="text-input-container-right-small-adjustment";var mi=_i,gi=function(){function e(){me(this,e)}return he(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")}}]),e}(),hi=["camera","gifs","images","audio","mixedFiles","submit","microphone"],fi=function(){function e(){me(this,e)}return he(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):nr.createSVGElement(t)}},{key:"createCustomElement",value:function(t,n){var r,i,a,o,s=null==n?void 0:n[t];return null!=(r=null==s?void 0:s.text)&&r.content?e.createElement(null==(i=null==s?void 0:s.text)?void 0:i.content,!0):null!=(a=null==s?void 0:s.svg)&&a.content?e.createElement(null==(o=null==s?void 0:s.svg)?void 0:o.content,!1):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:"create",value:function(t,n,r){var i={};if(!r)return e.processElement(t),i;var a=e.createSpecificStateElement(t,n[0],r);i[n[0]]=a;var o=a;return n.slice(1).forEach((function(t){o=e.createCustomElement(t,r)||o,i[t]=o})),i}}]),e}(),Ei=function(){function e(){me(this,e)}return he(e,null,[{key:"unsetAllCSS",value:function(e,t){var n,r;t.container&&be.unsetAllCSSMouseStates(e,t.container),null!=(n=t.svg)&&n.styles&&be.unsetAllCSSMouseStates(e.children[0],t.svg.styles),null!=(r=t.text)&&r.styles&&be.unsetAllCSSMouseStates(e.children[0],t.text.styles)}},{key:"unsetActionCSS",value:function(e,t){var n,r;t.container&&be.unsetActivityCSSMouseStates(e,t.container),null!=(n=t.svg)&&n.styles&&be.unsetActivityCSSMouseStates(e.children[0],t.svg.styles),null!=(r=t.text)&&r.styles&&be.unsetActivityCSSMouseStates(e.children[0],t.text.styles)}},{key:"setElementsCSS",value:function(e,t,n){var r,i,a,o,s;Object.assign(e.style,null==(r=t.container)?void 0:r[n]),Object.assign(e.children[0].style,null==(a=null==(i=t.svg)?void 0:i.styles)?void 0:a[n]),Object.assign(e.children[0].style,null==(s=null==(o=t.text)?void 0:o.styles)?void 0:s[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"))}}]),e}(),Si=function(){function e(t,n,r,i){me(this,e),this._mouseState={state:"default"},this.elementRef=t,this._customStyles=r,this.position=n,this.dropupText=i}return he(e,[{key:"buttonMouseLeave",value:function(e){this._mouseState.state="default",e&&(Ei.unsetAllCSS(this.elementRef,e),Ei.setElementsCSS(this.elementRef,e,"default"))}},{key:"buttonMouseEnter",value:function(e){this._mouseState.state="hover",e&&Ei.setElementsCSS(this.elementRef,e,"hover")}},{key:"buttonMouseUp",value:function(e){e&&Ei.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e)}},{key:"buttonMouseDown",value:function(e){this._mouseState.state="click",e&&Ei.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))}}]),e}(),vi=function(){function e(){me(this,e)}return he(e,null,[{key:"addItemEvents",value:function(e,t,n,r){$e.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 a=t.children[0];a.classList.contains("text-button")?n.appendChild(e.createItemText(a.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,a=n.elementRef,o=n.dropupText,s=document.createElement("div");Object.assign(s.style,null==(i=null==r?void 0:r.item)?void 0:i.default),e.populateItem(a,s,o,r),s.classList.add("dropup-menu-item");var l=be.processStateful((null==r?void 0:r.item)||{},{backgroundColor:"#f3f3f3"},{backgroundColor:"#ebebeb"});return e.addItemEvents(t,s,a,l),s}}]),e}(),yi=function(){function e(t,n){var r,i=this;me(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)}))}return he(e,[{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=vi.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===Te.ESCAPE?(this.close(),null==(n=this.highlightedItem)||n.dispatchEvent(new MouseEvent("mouseleave"))):t.key===Te.ENTER?(null==(r=this.highlightedItem)||r.click(),null==(i=this.highlightedItem)||i.dispatchEvent(new MouseEvent("mouseleave"))):t.key===Te.ARROW_DOWN?bi.focusSiblingItem(this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],this.elementRef,!0):t.key===Te.ARROW_UP&&bi.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}}]),e}(),Ti=function(e){function t(e,n){var r,i;me(this,t);var a=(r=te(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 yi(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 ae(t,e),he(t,[{key:"createInnerElements",value:function(e){return{styles:this.createInnerElement(t.createSVGIconElement(),"styles",e)}}},{key:"createInnerElement",value:function(e,t,n){return fi.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 nr.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"}}]),t}(Si),Ci=function(){function e(){me(this,e)}return he(e,null,[{key:"addToDropup",value:function(e,t,n,r){var i=new Ti(n,r);hi.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 a=Ti.getPosition(t,r);gi.addButton(e,i.buttonContainer,a),t[a].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){gi.addButton(e,t.button.elementRef,r)}))}))}},{key:"setPosition",value:function(e,t,n){var r=ue(ue({},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,a=null==(i=t[r])?void 0:i.button.position;a&&e.setPosition(t,r,n[a])})),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?hi.forEach((function(e){t[e]&&n["dropup-menu"].push(ue(ue({},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 a=e.generatePositions(n);return e.addToSideContainer(t,a),a["dropup-menu"].length>0&&e.addToDropup(t,a,r,i),a}}]),e}(),Ri={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"}},Oi=function(){function e(t,n,r,i){var a=this;me(this,e),this._attachments=[],this._fileCountLimit=99,this._acceptedFormat="",n.maxNumberOfFiles&&(this._fileCountLimit=n.maxNumberOfFiles),this._toggleContainerDisplay=r,this._fileAttachmentsContainerRef=i,n.acceptedFormats&&(this._acceptedFormat=n.acceptedFormats),setTimeout((function(){a._validationHandler=t._validationHandler}))}return he(e,[{key:"attemptAddFile",value:function(t,n){return!!e.isFileTypeValid(t,this._acceptedFormat)&&(this.addAttachmentBasedOnType(t,n,!0),!0)}},{key:"addAttachmentBasedOnType",value:function(t,n,r){var i=e.getTypeFromBlob(t);if("image"===i){var a=e.createImageAttachment(n);this.addFileAttachment(t,"image",a,r)}else if("audio"===i){var o=Ii.createAudioAttachment(n);this.addFileAttachment(t,"audio",o,r)}else{var s=e.createAnyFileAttachment(t.name);this.addFileAttachment(t,"any",s,r)}}},{key:"addFileAttachment",value:function(t,n,r,i){var a,o=e.createContainer(r);if(this._attachments.length>=this._fileCountLimit){var s=this._attachments[this._attachments.length-1].removeButton;null==s||s.click();var l=this._fileAttachmentsContainerRef.children;this._fileAttachmentsContainerRef.insertBefore(o,l[0])}else this._fileAttachmentsContainerRef.appendChild(o);var c={file:t,attachmentContainerElement:o,fileType:n};return i&&(c.removeButton=this.createRemoveAttachmentButton(c),o.appendChild(c.removeButton)),this._toggleContainerDisplay(!0),this._attachments.push(c),this._fileAttachmentsContainerRef.scrollTop=this._fileAttachmentsContainerRef.scrollHeight,null==(a=this._validationHandler)||a.call(this),c}},{key:"createRemoveAttachmentButton",value:function(e){var t=document.createElement("div");t.classList.add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var n=document.createElement("div");return n.classList.add("x-icon"),n.innerText="×",t.appendChild(n),t}},{key:"removeAttachment",value:function(e){var t,n=this._attachments.findIndex((function(t){return t===e})),r=this._attachments[n].attachmentContainerElement;this._attachments.splice(n,1),Ii.stopAttachmentPlayback(r),r.remove(),this._toggleContainerDisplay(!1),null==(t=this._validationHandler)||t.call(this)}},{key:"getFiles",value:function(){return Array.from(this._attachments).map((function(e){return{file:e.file,type:e.fileType}}))}},{key:"removeAllAttachments",value:function(){this._attachments.forEach((function(e){setTimeout((function(){var t;return null==(t=e.removeButton)?void 0:t.click()}))}))}}],[{key:"isFileTypeValid",value:function(e,t){if(""===t)return!0;for(var n=t.split(","),r=0;r\n\n play\n \n');i.classList.add("attachment-icon","play-icon");var a=nr.createSVGElement(Ni);a.classList.add("attachment-icon","stop-icon"),n.replaceChildren(i),r.onplay=function(){n.replaceChildren(a)},r.onpause=function(){n.replaceChildren(i),r.currentTime=0},r.onended=function(){n.replaceChildren(i)},n.onclick=function(){r.paused?r.play():r.pause()}}},{key:"createAudioAttachment",value:function(e){var n=t.createAudioContainer();return t.addAudioElements(n,e),n}},{key:"stopAttachmentPlayback",value:function(e){var t,n,r;null!=(r=null==(n=null==(t=e.children[0])?void 0:t.children)?void 0:n[0])&&r.classList.contains("stop-icon")&&e.children[0].click()}}]),t}(Oi);Ai.TIMER_LIMIT_S=5999;var Ii=Ai,wi=function(){function e(){me(this,e)}return he(e,null,[{key:"create",value:function(e,t,n,r,i){return"audio"===i?new Ii(e,t,n,r):new Oi(e,t,n,r)}}]),e}(),xi=function(){function e(t,n,r){me(this,e),this._fileAttachmentsTypes=[],this.elementRef=this.createAttachmentContainer();var i="object"==_e(r)&&!!r.displayFileAttachmentContainer;this.toggleContainerDisplay(i),t.appendChild(this.elementRef),n&&Object.assign(this.elementRef.style,n)}var t;return he(e,[{key:"addType",value:function(e,t,n){var r=wi.create(e,t,this.toggleContainerDisplay.bind(this),this.elementRef,n);return this._fileAttachmentsTypes.push(r),r}},{key:"createAttachmentContainer",value:function(){var e=document.createElement("div");return e.id="file-attachment-container",e}},{key:"toggleContainerDisplay",value:function(e){e?this.elementRef.style.display="block":0===this.elementRef.children.length&&(this.elementRef.style.display="none")}},{key:"getAllFileData",value:function(){var e=this._fileAttachmentsTypes.map((function(e){return e.getFiles()})).flat();return e.length>0?e:void 0}},{key:"completePlaceholders",value:(t=ce(se().mark((function e(){return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Promise.all(this._fileAttachmentsTypes.map(function(){var e=ce(se().mark((function e(t){var n;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",null==(n=t.stopPlaceholderCallback)?void 0:n.call(t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"addFilesToAnyType",value:function(t){e.addFilesToType(t,this._fileAttachmentsTypes)}},{key:"removeAllFiles",value:function(){this._fileAttachmentsTypes.forEach((function(e){return e.removeAllAttachments()})),this.elementRef.replaceChildren(),this.toggleContainerDisplay(!1)}},{key:"getNumberOfTypes",value:function(){return this._fileAttachmentsTypes.length}}],[{key:"addFilesToType",value:function(e,t){e.forEach((function(e){var n=new FileReader;n.readAsDataURL(e),n.onload=function(n){for(var r=0;r0)}}]),e}(),Pi=function(){function e(){me(this,e)}var t,n;return he(e,null,[{key:"validate",value:function(e,t,n,r,i){var a=e(n,r,i);return a?t.changeToSubmitIcon():t.changeToDisabledIcon(),a}},{key:"useValidationFunc",value:(n=ce(se().mark((function t(n,r,i,a){var o,s,l,c;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=r.inputElementRef,s=o.classList.contains("text-input-placeholder")?"":o.textContent,t.next=3,i.completePlaceholders();case 3:return l=i.getAllFileData(),c=null==l?void 0:l.map((function(e){return e.file})),t.abrupt("return",e.validate(n,a,s,c));case 5:case"end":return t.stop()}}),t)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"useValidationFuncProgrammatic",value:(t=ce(se().mark((function t(n,r,i){var a,o;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=null==(a=r.files)?void 0:a.map((function(e){return e.file})),t.abrupt("return",e.validate(n,i,r.text,o,!0));case 2:case"end":return t.stop()}}),t)}))),function(e,n,r){return t.apply(this,arguments)})},{key:"validateWebsocket",value:function(e,t){return!(e.websocket&&!jn.canSendMessage(e.websocket))||(t.changeToDisabledIcon(),!1)}},{key:"attach",value:function(t,n,r,i,a){var o=t.validateInput||Be.processValidateInput(t);t._validationHandler=function(){var t=ce(se().mark((function t(s){var l;return se().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!a.status.loadingActive&&!a.status.requestInProgress&&!0!==n.isSubmitProgrammaticallyDisabled&&e.validateWebsocket(n,a)){t.next=2;break}return t.abrupt("return",!1);case 2:return l=o||n.canSendMessage,t.abrupt("return",l?s?e.useValidationFuncProgrammatic(l,s,a):e.useValidationFunc(l,r,i,a):null);case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()}}]),e}(),Fi=function(e){function t(e){var n;return me(this,t),"dropup-menu"===(null==e?void 0:e.position)&&(e.position="outside-right"),(n=te(this,t,[t.createMicrophoneElement(),null==e?void 0:e.position,e])).isActive=!1,n._innerElements=n.createInnerElements(n._customStyles),n.changeToDefault(),n}return ae(t,e),he(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 fi.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"),e}},{key:"createSVGIconElement",value:function(){var e=nr.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}}]),t}(Si),Ui={},Bi={},Gi={},Yi={},Hi={};Object.defineProperty(Hi,"__esModule",{value:!0}),Hi.Text=void 0;var zi=function(){function e(){me(this,e)}return he(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&&" "!==e&&" "!==e&&"\n"!==e&&""!==e}},{key:"breakupIntoWordsArr",value:function(e){return e.split(/(\W+)/)}}]),e}();Hi.Text=zi,zi.FIRST_CHAR_REGEX=/\S/,zi.DOUBLE_LINE=/\n\n/g,zi.ONE_LINE=/\n/g,Object.defineProperty(Yi,"__esModule",{value:!0}),Yi.Translate=void 0;var qi=Hi,Vi=function(){function e(){me(this,e)}return he(e,null,[{key:"translate",value:function(e,t){for(var n=qi.Text.breakupIntoWordsArr(e),r=0;re.clientHeight||e.scrollWidth>e.clientWidth}},{key:"isRequired",value:function(t,n){return t&&e.isElementOverflown(n)}}]),e}();na.AutoScroll=ra;var ia={};Object.defineProperty(ia,"__esModule",{value:!0}),ia.Elements=void 0;var aa=function(){function e(){me(this,e)}return he(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}}]),e}();ia.Elements=aa;var oa={};Object.defineProperty(oa,"__esModule",{value:!0}),oa.Cursor=void 0;var sa=function(){function e(){me(this,e)}return he(e,null,[{key:"setOffsetForGeneric",value:function(t,n){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=0,a=0;a0){var s=e.setOffsetForGeneric(o,n,r);if(-1===s)return-1;r+=s}else if(null!==o.textContent){if(r+o.textContent.length>n){var l=document.createRange();l.setStart(o,n-r),l.collapse(!0);var c=window.getSelection();return null==c||c.removeAllRanges(),null==c||c.addRange(l),t.focus(),-1}r+=o.textContent.length,i+=o.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),a=i.cloneRange();a.selectNodeContents(e),n?a.setEnd(i.startContainer,i.startOffset):a.setEnd(i.endContainer,i.endOffset),r=a.toString().length}return r}}]),e}();oa.Cursor=sa,Object.defineProperty(ta,"__esModule",{value:!0}),ta.CommandUtils=void 0;var la=na,ca=ia,da=Wi,ua=oa,pa=Hi,_a=function(){function e(){me(this,e)}return he(e,null,[{key:"processCommand",value:function(e,t){return(!t||!t.caseSensitive)&&(e=e.toLowerCase()),!1===(null==t?void 0:t.substrings)?pa.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),ca.Elements.isPrimitiveElement(i)?(i.value=r,t.isTargetInShadow||ua.Cursor.setOffsetForPrimitive(i,r.length,!0),da.Browser.IS_SAFARI()&&t.autoScroll&&la.AutoScroll.scrollSafariPrimitiveToEnd(i)):(i.textContent=r,t.isTargetInShadow||ua.Cursor.focusEndOfGeneric(i),setTimeout((function(){return la.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 a=i,o=r.length-1;n[a]===r[o]&&o>=0;)a-=1,o-=1;if(o<0)return!0}return!1}},{key:"execCommand",value:function(t,n,r,i,a){var o,s,l,c=t.commands;if(c&&i&&r){var d=!0===(null===(o=c.settings)||void 0===o?void 0:o.caseSensitive)?n:n.toLowerCase(),u=pa.Text.breakupIntoWordsArr(d),p=!1===(null===(s=c.settings)||void 0===s?void 0:s.substrings)?e.checkIfMatchesWord:e.checkIfMatchesSubstring;if(c.commandMode&&p(c.commandMode,d,u))return t.setInterimColorToFinal(),setTimeout((function(){return e.toggleCommandModeOn(t)})),{doNotProcessTranscription:!1};if(!c.commandMode||t.isWaitingForCommand){if(c.stop&&p(c.stop,d,u))return e.toggleCommandModeOff(t),setTimeout((function(){return t.stop()})),{doNotProcessTranscription:!1};if(c.pause&&p(c.pause,d,u))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&&p(c.resume,d,u))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&&p(c.reset,d,u))return void 0!==a&&e.setText(t,r,a,i),{doNotProcessTranscription:!0};if(c.removeAllText&&p(c.removeAllText,d,u))return e.setText(t,r,"",i),{doNotProcessTranscription:!0}}}}}]),e}();ta.CommandUtils=_a;var ma={};Object.defineProperty(ma,"__esModule",{value:!0}),ma.Highlight=void 0;var ga=ia,ha=oa,fa=function(){function e(){me(this,e)}return he(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=ha.Cursor.getGenericElementCursorOffset(t,n,!0),i=ha.Cursor.getGenericElementCursorOffset(t,n,!1);e.isHighlighted=r!==i}}},{key:"setState",value:function(t,n){document.activeElement===n&&(ga.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=ha.Cursor.getGenericElementCursorOffset(t,n,!0);n.deleteFromDocument(),ha.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 a=i.substring(0,n)+i.substring(r);t.value=a,ha.Cursor.setOffsetForPrimitive(t,n,e.autoScroll)}e.isHighlighted=!1}}]),e}();ma.Highlight=fa;var Ea={};Object.defineProperty(Ea,"__esModule",{value:!0}),Ea.Padding=void 0;var Sa=ia,ba=oa,va=Hi,ya=function(){function e(){me(this,e)}return he(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,a=t.value[i];return va.Text.isCharDefined(r)&&(e.startPadding=" ",e.numberOfSpacesBeforeNewText=1),va.Text.isCharDefined(a)&&(e.endPadding=" ",e.numberOfSpacesAfterNewText=1),void(e.isCursorAtEnd=t.value.length===i)}var o=t.value[t.value.length-1];va.Text.isCharDefined(o)&&(e.startPadding=" ",e.numberOfSpacesBeforeNewText=1),e.isCursorAtEnd=!0}},{key:"setStateForGenericElement",value:function(e,t){var n,r,i;if(document.activeElement===t){var a=window.getSelection();if(null!=a&&a.focusNode){var o=ba.Cursor.getGenericElementCursorOffset(t,a,!0),s=null===(n=t.textContent)||void 0===n?void 0:n[o-1],l=ba.Cursor.getGenericElementCursorOffset(t,a,!1),c=null===(r=t.textContent)||void 0===r?void 0:r[l];return va.Text.isCharDefined(s)&&(e.startPadding=" "),va.Text.isCharDefined(c)&&(e.endPadding=" "),void(e.isCursorAtEnd=(null===(i=t.textContent)||void 0===i?void 0:i.length)===l)}}var d=t.innerText.charAt(t.innerText.length-1);va.Text.isCharDefined(d)&&(e.startPadding=" "),e.isCursorAtEnd=!0}},{key:"setState",value:function(t,n){Sa.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)}}]),e}();Ea.Padding=ya,Object.defineProperty(Qi,"__esModule",{value:!0}),Qi.Speech=void 0;var Ta=Xi,Ca=Ji,Ra=ta,Oa=na,Na=ma,Aa=ia,Ia=Ea,wa=Wi,xa=oa,Da=Hi,Ma=function(){function e(){me(this,e),this.finalTranscript="",this.interimSpan=Aa.Elements.createInterimSpan(),this.finalSpan=Aa.Elements.createGenericSpan(),this.scrollingSpan=Aa.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()}return he(e,[{key:"prepareBeforeStart",value:function(e){var t,n;if(null!=e&&e.element)if(Ta.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,Aa.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=Ra.CommandUtils.process(this._options.commands))}},{key:"prepare",value:function(e){Ia.Padding.setState(this,e),Na.Highlight.setState(this,e),this.isTargetInShadow=Aa.Elements.isInsideShadowDOM(e),Aa.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=Da.Text.capitalize(t);if(this.finalTranscript!==i||""!==e){Ca.PreResultUtils.process(this,n,""===e,this._onPreResult,this._options)&&(e="",n="");var a=this.commands&&Ra.CommandUtils.execCommand(this,n,this._options,this._primitiveElement||this._genericElement,this._originalText);if(a){if(a.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 o=""===this.finalTranscript&&""===e;this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,e,o):this._genericElement&&this.updateGenericElement(this._genericElement,e,o)}}}},{key:"updatePrimitiveElement",value:function(e,t,n){this.isHighlighted&&Na.Highlight.removeForPrimitive(this,e),this.primitiveTextRecorded||Ia.Padding.adjustStateAfterRecodingPrimitiveElement(this,e),n&&Ia.Padding.adjustSateForNoTextPrimitiveElement(this);var r=this.startPadding+this.finalTranscript+t;if(e.value=r+this.endPadding,!this.isTargetInShadow){var i=r.length+this.numberOfSpacesAfterNewText;xa.Cursor.setOffsetForPrimitive(e,i,this.autoScroll)}this.autoScroll&&wa.Browser.IS_SAFARI()&&this.isCursorAtEnd&&Oa.AutoScroll.scrollSafariPrimitiveToEnd(e)}},{key:"updateGenericElement",value:function(e,t,n){this.isHighlighted&&Na.Highlight.removeForGeneric(this,e),this.spansPopulated||Aa.Elements.appendSpans(this,e);var r=(n?"":this.startPadding)+Da.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=r;var i=Oa.AutoScroll.isRequired(this.autoScroll,e);Oa.AutoScroll.changeStateIfNeeded(this,i);var a=Da.Text.lineBreak(t)+(n?"":this.endPadding);this.interimSpan.innerHTML=a,wa.Browser.IS_SAFARI()&&this.insertInCursorLocation&&xa.Cursor.setOffsetForSafariGeneric(e,r.length+a.length),i&&Oa.AutoScroll.scrollGeneric(this,e),n&&(this.scrollingSpan.innerHTML="")}},{key:"finalise",value:function(e){this._genericElement&&(e?(this.finalSpan=Aa.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=Aa.Elements.createInterimSpan(),this.scrollingSpan=Aa.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),Ta.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}}]),e}();Qi.Speech=Ma,Object.defineProperty(Bi,"__esModule",{value:!0}),Bi.WebSpeech=void 0;var ka=Gi,La=Wi,Pa=function(e){function t(){return me(this,t),te(this,t)}return ae(t,e),he(t,[{key:"start",value:function(e){var t;void 0===this._extractText&&(this._extractText=La.Browser.IS_SAFARI()?ka.WebSpeechTranscript.extractSafari:ka.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){La.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(_e(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,a=n.newText;e.updateElements(r,i,a)}})}},{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}}]),t}(Qi.Speech);Bi.WebSpeech=Pa;var Fa={};Object.defineProperty(Fa,"__esModule",{value:!0}),Fa.GlobalState=void 0;var Ua=function(){function e(){me(this,e)}return he(e,null,[{key:"doubleClickDetector",value:function(){return!!e.doubleClickPending||(e.doubleClickPending=!0,setTimeout((function(){e.doubleClickPending=!1}),300),!1)}}]),e}();Fa.GlobalState=Ua,Ua.doubleClickPending=!1;var Ba={},Ga={};Object.defineProperty(Ga,"__esModule",{value:!0}),Ga.PreventConnectionStop=void 0;var Ya=function(){function e(){me(this,e)}return he(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}}]),e}();Ga.PreventConnectionStop=Ya;var Ha={},za={};Object.defineProperty(za,"__esModule",{value:!0}),za.README_URL=void 0,za.README_URL="https://github.com/OvidijusParsiunas/speech-to-element",Object.defineProperty(Ha,"__esModule",{value:!0}),Ha.AzureSpeechConfig=void 0;var qa=za,Va=function(){function e(){me(this,e)}var t,n;return he(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(qa.README_URL)),!1):(e("Please define a 'subscriptionKey', 'token' or 'retrieveToken' property - more info: ".concat(qa.README_URL)),!1):(e("Please provide subscription details - more info: ".concat(qa.README_URL)),!1)}},{key:"getNewSpeechConfig",value:(n=ce(se().mark((function e(t,n){return se().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=ce(se().mark((function t(n,r){var i;return se().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)})}]),e}();Ha.AzureSpeechConfig=Va;var ja={};Object.defineProperty(ja,"__esModule",{value:!0}),ja.StopTimeout=void 0;var $a=function(){function e(){me(this,e)}return he(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)}}]),e}();ja.StopTimeout=$a,$a.DEFAULT_MS=2e4;var Wa={};Object.defineProperty(Wa,"__esModule",{value:!0}),Wa.AzureTranscript=void 0;var Ka=Yi,Qa=function(){function e(){me(this,e)}return he(e,null,[{key:"extract",value:function(e,t,n,r){return r&&(e=Ka.Translate.translate(e,r)),n?{interimTranscript:"",finalTranscript:t+e,newText:e}:{interimTranscript:e,finalTranscript:t,newText:e}}}]),e}();Wa.AzureTranscript=Qa,Object.defineProperty(Ba,"__esModule",{value:!0}),Ba.Azure=void 0;var Xa=Ga,Za=Ha,Ja=ja,eo=Wa,to=function(e){function t(){var e;return me(this,t),(e=te(this,t,arguments))._newTextPadding="",e}var n,r;return ae(t,e),he(t,[{key:"start",value:function(e,t){this._newTextPadding="",void 0===this.stopTimeout&&Ja.StopTimeout.reset(this,null==e?void 0:e.stopAfterSilenceMs),this.prepareBeforeStart(e),this.startAsync(e),t||Xa.PreventConnectionStop.applyPrevention(this)}},{key:"startAsync",value:(r=ce(se().mark((function e(t){var n;return se().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()?Za.AzureSpeechConfig.validateOptions(this.error.bind(this),e):(this.moduleNotFound(),!1)}},{key:"instantiateService",value:(n=ce(se().mark((function e(n){var r,i,a,o;return se().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.getAPI(),i=r.AudioConfig.fromDefaultMicrophoneInput(),e.next=4,Za.AzureSpeechConfig.get(r.SpeechConfig,n);case 4:(a=e.sent)?(o=new r.SpeechRecognizer(a,i),this.setEvents(o),this._service=o,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=eo.AzureTranscript.extract(this._newTextPadding+t.result.text,this.finalTranscript,!1,this._translations),r=n.interimTranscript,i=n.finalTranscript,a=n.newText;Ja.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(r,i,a)}}},{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=eo.AzureTranscript.extract(this._newTextPadding+n.text,this.finalTranscript,!0,this._translations),i=r.interimTranscript,a=r.finalTranscript,o=r.newText;Ja.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(i,a,o),""!==a&&(this._newTextPadding=" ")}}}},{key:"onCanceled",value:function(e,t){t.reason===window.SpeechSDK.CancellationReason.Error&&this.error(t.errorDetails)}},{key:"onSessionStarted",value:function(){Xa.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: \";\n\t\tunsubscribe = listen(\n\t\t\twindow,\n\t\t\t'message',\n\t\t\t/** @param {MessageEvent} event */ (event) => {\n\t\t\t\tif (event.source === iframe.contentWindow) fn();\n\t\t\t}\n\t\t);\n\t} else {\n\t\tiframe.src = 'about:blank';\n\t\tiframe.onload = () => {\n\t\t\tunsubscribe = listen(iframe.contentWindow, 'resize', fn);\n\t\t\t// make sure an initial resize event is fired _after_ the iframe is loaded (which is asynchronous)\n\t\t\t// see https://github.com/sveltejs/svelte/issues/4233\n\t\t\tfn();\n\t\t};\n\t}\n\tappend(node, iframe);\n\treturn () => {\n\t\tif (crossorigin) {\n\t\t\tunsubscribe();\n\t\t} else if (unsubscribe && iframe.contentWindow) {\n\t\t\tunsubscribe();\n\t\t}\n\t\tdetach(iframe);\n\t};\n}\nexport const resize_observer_content_box = /* @__PURE__ */ new ResizeObserverSingleton({\n\tbox: 'content-box'\n});\nexport const resize_observer_border_box = /* @__PURE__ */ new ResizeObserverSingleton({\n\tbox: 'border-box'\n});\nexport const resize_observer_device_pixel_content_box = /* @__PURE__ */ new ResizeObserverSingleton(\n\t{ box: 'device-pixel-content-box' }\n);\nexport { ResizeObserverSingleton };\n\n/**\n * @returns {void} */\nexport function toggle_class(element, name, toggle) {\n\t// The `!!` is required because an `undefined` flag means flipping the current state.\n\telement.classList.toggle(name, !!toggle);\n}\n\n/**\n * @template T\n * @param {string} type\n * @param {T} [detail]\n * @param {{ bubbles?: boolean, cancelable?: boolean }} [options]\n * @returns {CustomEvent}\n */\nexport function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {\n\treturn new CustomEvent(type, { detail, bubbles, cancelable });\n}\n\n/**\n * @param {string} selector\n * @param {HTMLElement} parent\n * @returns {ChildNodeArray}\n */\nexport function query_selector_all(selector, parent = document.body) {\n\treturn Array.from(parent.querySelectorAll(selector));\n}\n\n/**\n * @param {string} nodeId\n * @param {HTMLElement} head\n * @returns {any[]}\n */\nexport function head_selector(nodeId, head) {\n\tconst result = [];\n\tlet started = 0;\n\tfor (const node of head.childNodes) {\n\t\tif (node.nodeType === 8 /* comment node */) {\n\t\t\tconst comment = node.textContent.trim();\n\t\t\tif (comment === `HEAD_${nodeId}_END`) {\n\t\t\t\tstarted -= 1;\n\t\t\t\tresult.push(node);\n\t\t\t} else if (comment === `HEAD_${nodeId}_START`) {\n\t\t\t\tstarted += 1;\n\t\t\t\tresult.push(node);\n\t\t\t}\n\t\t} else if (started > 0) {\n\t\t\tresult.push(node);\n\t\t}\n\t}\n\treturn result;\n}\n/** */\nexport class HtmlTag {\n\t/**\n\t * @private\n\t * @default false\n\t */\n\tis_svg = false;\n\t/** parent for creating node */\n\te = undefined;\n\t/** html tag nodes */\n\tn = undefined;\n\t/** target */\n\tt = undefined;\n\t/** anchor */\n\ta = undefined;\n\tconstructor(is_svg = false) {\n\t\tthis.is_svg = is_svg;\n\t\tthis.e = this.n = null;\n\t}\n\n\t/**\n\t * @param {string} html\n\t * @returns {void}\n\t */\n\tc(html) {\n\t\tthis.h(html);\n\t}\n\n\t/**\n\t * @param {string} html\n\t * @param {HTMLElement | SVGElement} target\n\t * @param {HTMLElement | SVGElement} anchor\n\t * @returns {void}\n\t */\n\tm(html, target, anchor = null) {\n\t\tif (!this.e) {\n\t\t\tif (this.is_svg)\n\t\t\t\tthis.e = svg_element(/** @type {keyof SVGElementTagNameMap} */ (target.nodeName));\n\t\t\t/** #7364 target for