deep-chat-dev 9.0.362 → 9.0.363

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/deepChat.js CHANGED
@@ -1,21 +1,17 @@
1
- function _objectWithoutProperties(e,t){if(null==e)return{};var o,r,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r<n.length;r++)o=n[r],-1===t.indexOf(o)&&{}.propertyIsEnumerable.call(e,o)&&(i[o]=e[o]);}return i;}function _objectWithoutPropertiesLoose(r,e){if(null==r)return{};var t={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(-1!==e.indexOf(n))continue;t[n]=r[n];}return t;}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,F=function F(){};return{s:F,n:function(_n20){function n(){return _n20.apply(this,arguments);}n.toString=function(){return _n20.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),e:function e(r){throw r;},f:F};}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 o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _wrapNativeSuper(t){var r="function"==typeof Map?new Map():void 0;return _wrapNativeSuper=function _wrapNativeSuper(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,Wrapper);}function Wrapper(){return _construct(t,arguments,_getPrototypeOf(this).constructor);}return Wrapper.prototype=Object.create(t.prototype,{constructor:{value:Wrapper,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(Wrapper,t);},_wrapNativeSuper(t);}function _construct(t,e,r){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var p=new(t.bind.apply(t,o))();return r&&_setPrototypeOf(p,r.prototype),p;}function _isNativeFunction(t){try{return-1!==Function.toString.call(t).indexOf("[native code]");}catch(n){return"function"==typeof t;}}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1;}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r;}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return;}finally{if(o)throw n;}}return a;}}function _arrayWithHoles(r){if(Array.isArray(r))return r;}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}function _nonIterableSpread(){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 _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof Generator?n:Generator,u=Object.create(c.prototype);return _regeneratorDefine2(u,"_invoke",function(r,n,o){var i,c,u,f=0,p=o||[],y=!1,G={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function d(t,r){return i=t,c=0,u=e,G.n=r,a;}};function d(r,n){for(c=r,u=n,t=0;!y&&f&&!o&&t<p.length;t++){var o,i=p[t],d=G.p,l=i[2];r>3?(o=l===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,G.v=n,G.n=i[1]):d<l&&(o=r<3||i[0]>n||n>l)&&(i[4]=r,i[5]=n,G.n=l,c=0));}if(o||r>1)return a;throw y=!0,n;}return function(o,p,l){if(f>1)throw TypeError("Generator is already running");for(y&&1===p&&d(p,l),c=p,u=l;(t=c<2?e:u)||!y;){i||(c?c<3?(c>1&&(G.n=-1),d(c,u)):G.n=u:G.v=u);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0);}else 1===c&&(t=i["return"])&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e;}else if((t=(y=G.n<0)?u:r.call(n,G))!==a)break;}catch(t){i=e,c=1,u=t;}finally{f=1;}}return{value:t,done:y};};}(r,o,i),!0),u;}var a={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(_regeneratorDefine2(t={},n,function(){return this;}),t),u=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,GeneratorFunctionPrototype):(e.__proto__=GeneratorFunctionPrototype,_regeneratorDefine2(e,o,"GeneratorFunction")),e.prototype=Object.create(u),e;}return GeneratorFunction.prototype=GeneratorFunctionPrototype,_regeneratorDefine2(u,"constructor",GeneratorFunctionPrototype),_regeneratorDefine2(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName="GeneratorFunction",_regeneratorDefine2(GeneratorFunctionPrototype,o,"GeneratorFunction"),_regeneratorDefine2(u),_regeneratorDefine2(u,o,"Generator"),_regeneratorDefine2(u,n,function(){return this;}),_regeneratorDefine2(u,"toString",function(){return"[object Generator]";}),(_regenerator=function _regenerator(){return{w:i,m:f};})();}function _regeneratorDefine2(e,r,n,t){var i=Object.defineProperty;try{i({},"",{});}catch(e){i=0;}_regeneratorDefine2=function _regeneratorDefine(e,r,n,t){function o(r,n){_regeneratorDefine2(e,r,function(e){return this._invoke(r,n,e);});}r?i?i(e,r,{value:n,enumerable:!t,configurable:!t,writable:!t}):e[r]=n:(o("next",0),o("throw",1),o("return",2));},_regeneratorDefine2(e,r,n,t);}function asyncGeneratorStep(n,t,e,r,o,a,c){try{var i=n[a](c),u=i.value;}catch(n){return void e(n);}i.done?t(u):Promise.resolve(u).then(r,o);}function _asyncToGenerator(n){return function(){var t=this,e=arguments;return new Promise(function(r,o){var a=n.apply(t,e);function _next(n){asyncGeneratorStep(a,r,o,_next,_throw,"next",n);}function _throw(n){asyncGeneratorStep(a,r,o,_next,_throw,"throw",n);}_next(void 0);});};}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e;}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}var m="classList",v="style",ba="unset",ya="html-wrapper",X="length",A=function A(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var _a=/*#__PURE__*/function(){function _a(){_classCallCheck(this,_a);}return _createClass(_a,null,[{key:"render",value:function render(e,t){var n=A();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var Vs=/*#__PURE__*/function(){function Vs(){_classCallCheck(this,Vs);}return _createClass(Vs,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=A();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=Vs.createElements(),r={onSuccess:t,onFail:_a.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:Vs.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var ae="service",h="text",L="html",f="error",Z="https://deepchat.dev/docs/",ne="ai",F="user",gt="assistant",Ks="error-message-text",Bs="deep-chat-outer-container-role-",Nr="empty-message",ki="deep-chat-top-message",Br="deep-chat-middle-message",Pi="deep-chat-bottom-message",T="src",E="type",se="file",b="files",W="image",ee="images",Fe="camera",Cn="gifs",$="audio",ct="microphone",Oo="mixedFiles",rn="any",No="file-message",$t="start",Bo="end",Do="messages",Dr="0",Fr="1",x="role",Ee="string",le=function le(i){return JSON.stringify(i);},C=function C(i){return JSON.parse(le(i));};function Ur(i){return i.charAt(0).toUpperCase()+i.slice(1);}function Ea(i){return i&&le(i);}function or(i,e,t,n){var s="\n".concat(Ur(e)," message: ").concat(le(i)," \n"),r=t?"".concat(Ur(e)," message after interceptor: ").concat(Ea(n)," \n"):"";return s+r;}function va(i,e,t,n){return"".concat(or(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat(Z,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat(Z,"interceptors#responseInterceptor");}function Sa(i,e,t){var n="response";return"".concat(or(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function xa(i,e){var t="request";return"".concat(or(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function Aa(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var Tn=va,wa=xa,Ca=Sa,Hr=Aa,pe="Invalid API Key",Ue="Failed to connect",He="Request settings have not been set up",_i="No file was added",ar="Image was not found",Fo="Multi-response arrays are not supported for streaming",Uo="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat(Z,"interceptors#responseInterceptor"),Ta="Cannot mix {text: string} and {html: string} responses.",Ra="No valid stream events were sent.\n".concat(Uo),Ia="Readable Stream connection error.",qt="Please define a `function_handler` property inside the service config.",on="Function tool response must be an array or contain a text property",Ho="Failed to fetch history",In="inside-start",ft="inside-end",Le="outside-start",ve="outside-end",et="dropup-menu",w="default",De="hover",J="click",H="active",j="disabled",G="svg",Nt="unavailable",R="styles",Ps="mouseenter",an="mouseleave",Ma="mousedown",ka="mouseup",st="submit",It="loading",Fi="stop",Un="unsupported",gn="commandMode";var ce=/*#__PURE__*/function(){function ce(){_classCallCheck(this,ce);}return _createClass(ce,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var n=Object.keys(t).reduce(function(s,r){return s[r]="",s;},{});Object.assign(e[v],n);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t[J]&&ce.unsetStyle(e,t[J]),t[De]&&ce.unsetStyle(e,t[De]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){ce.unsetActivityCSSMouseStates(e,t),t[w]&&ce.unsetStyle(e,t[w]);}// if you want to asdd default styling - use pure css classes
2
- },{key:"processStateful",value:function processStateful(e){var t=e[w]||{},n=Object.assign(C(t),e==null?void 0:e[De]),s=Object.assign(C(n),e==null?void 0:e[J]);return _defineProperty(_defineProperty(_defineProperty({},w,t),De,n),J,s);}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t=_defineProperty(_defineProperty(_defineProperty({},w,{}),De,{}),J,{});return e.forEach(function(n){t[w]=Object.assign(t[w],n[w]),t[De]=Object.assign(t[De],n[De]),t[J]=Object.assign(t[J],n[J]);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e[w]||[]).forEach(function(n){var r;var s=n;t[v][s]&&(r=e[w])!=null&&r[s]&&(e[w][n]=t[v][s]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var n in t){var s=t[n];e[n]===""&&s&&(e[n]=s);}}}]);}();var Wt=/*#__PURE__*/function(){function Wt(){_classCallCheck(this,Wt);}return _createClass(Wt,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e){if(e.fontFamily&&e.fontFamily!==Wt.DEFAULT_FONT_FAMILY)return;var t=document.getElementsByTagName("head")[0];if(!Array.from(t.getElementsByTagName("link")).some(function(s){return s.getAttribute("href")===Wt.FONT_URL;})){var s=A("link");s.rel="stylesheet",s.href=Wt.FONT_URL,t.appendChild(s);}}}]);}();Wt.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",Wt.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var Ws=Wt;var vn=/*#__PURE__*/function(){function vn(){_classCallCheck(this,vn);}return _createClass(vn,null,[{key:"apply",value:function apply(e,t){if(t)try{vn.applyStyleSheet(e,t);}catch(_unused){vn.addStyleElement(e,t);}}},{key:"applyStyleSheet",value:function applyStyleSheet(e,t){var n=new CSSStyleSheet();n.replaceSync(e),t.adoptedStyleSheets.push(n);}},{key:"addStyleElement",value:function addStyleElement(e,t){var n=A("style");n.innerHTML=e,t.appendChild(n);}},{key:"applyDefaultStyleToComponent",value:function applyDefaultStyleToComponent(e,t){t&&ce.applyToStyleIfNotDefined(e,t),ce.applyToStyleIfNotDefined(e,vn.DEFAULT_COMPONENT_STYLE);}}]);}();vn.DEFAULT_COMPONENT_STYLE={height:"350px",width:"320px",borderTop:"1px solid #cacaca",borderRight:"1px solid #cacaca",borderLeft:"1px solid #cacaca",borderBottom:"1px solid #cacaca",fontFamily:Ws.DEFAULT_FONT_FAMILY,fontSize:"0.9rem",backgroundColor:"white",position:"relative",// this is used to prevent inputAreaStyle background color from going beyond the container's rounded border
3
- // it will cause issues if there are elements that are meant to be outside of the chat component and in
4
- // that instance they should overwrite this
5
- // this is also causing the chat to squeeze when there is no space
6
- overflow:"hidden"};var hs=vn;var Xt=/*#__PURE__*/function(){function Xt(){_classCallCheck(this,Xt);}return _createClass(Xt,null,[{key:"buildElement",value:function buildElement(){var e=A();e[m].add("tooltip");var t=A("span");return t[m].add("tooltip-text"),e.appendChild(t),e;}},{key:"tryCreateConfig",value:function tryCreateConfig(e,t){if(t)return typeof t=="boolean"?_defineProperty({},h,e):_defineProperty(_defineProperty(_defineProperty({},h,t[h]||e),"timeout",t.timeout||0),"style",t[v]);}},{key:"traverseParentUntilContainer",value:function traverseParentUntilContainer(e){var t=e;for(;t.parentElement;)t=t.parentElement;return t;}},{key:"setPosition",value:function setPosition(e,t){var s=t.getRootNode().host.getBoundingClientRect(),r=e.getBoundingClientRect(),a=t.getBoundingClientRect().width/2,c=r.left+r.width/2;t[v].left="".concat(c-a-s.left,"px"),t[v].top="".concat(r.top-36-s.top,"px");var l=t.getBoundingClientRect();l.left<s.left?t[v].left="".concat(Xt.OVERFLOW_NEW_POSITION_PX,"px"):l.right>s.right&&(t[v].left="".concat(s.width-l.width-Xt.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,n){return n||(n=Xt.traverseParentUntilContainer(e).nextSibling),t[h]&&(n.children[0].textContent=t[h]),{timeout:setTimeout(function(){n[v].visibility="visible",Xt.setPosition(e,n),t[v]&&Object.assign(n[v],t[v]);},t.timeout||0),element:n};}},{key:"hide",value:function hide(e,t){clearTimeout(e.timeout),e.element[v].visibility="hidden",t[v]&&ce.unsetStyle(e.element,t[v]),e.element[v].left="",e.element[v].top="";}}]);}();Xt.OVERFLOW_NEW_POSITION_PX=4;var ut=Xt;var bs=/*#__PURE__*/_createClass(function bs(){_classCallCheck(this,bs);});bs.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),bs.IS_CHROMIUM=window.chrome,bs.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var $e=bs;var _e=/* @__PURE__ */function(i){return i.ESCAPE="Escape",i.ENTER="Enter",i.TAB="Tab",i.ARROW_UP="ArrowUp",i.ARROW_DOWN="ArrowDown",i.ARROW_RIGHT="ArrowRight",i.ARROW_LEFT="ArrowLeft",i.BACKSPACE="Backspace",i.DELETE="Delete",i.META="Meta",i.CONTROL="Control",i;}(_e||{});var Zt=/*#__PURE__*/function(){function Zt(){_classCallCheck(this,Zt);}return _createClass(Zt,null,[{key:"add",value:// prettier-ignore
7
- function add(e,t,n,s){n!==void 0&&e.addEventListener("keydown",Zt.onKeyDown.bind(this,n)),e.oninput=Zt.onInput.bind(this,n,s),e.addEventListener("paste",function(r){var o;console.log(r),r.preventDefault(),(o=r.clipboardData)!=null&&o[b].length&&t.addFilesToAnyType(Array.from(r.clipboardData[b]));});}// preventing insertion early for a nicer UX
1
+ function _objectWithoutProperties(e,t){if(null==e)return{};var o,r,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r<n.length;r++)o=n[r],-1===t.indexOf(o)&&{}.propertyIsEnumerable.call(e,o)&&(i[o]=e[o]);}return i;}function _objectWithoutPropertiesLoose(r,e){if(null==r)return{};var t={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(-1!==e.indexOf(n))continue;t[n]=r[n];}return t;}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,F=function F(){};return{s:F,n:function(_n20){function n(){return _n20.apply(this,arguments);}n.toString=function(){return _n20.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),e:function e(r){throw r;},f:F};}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 o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _wrapNativeSuper(t){var r="function"==typeof Map?new Map():void 0;return _wrapNativeSuper=function _wrapNativeSuper(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,Wrapper);}function Wrapper(){return _construct(t,arguments,_getPrototypeOf(this).constructor);}return Wrapper.prototype=Object.create(t.prototype,{constructor:{value:Wrapper,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(Wrapper,t);},_wrapNativeSuper(t);}function _construct(t,e,r){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var p=new(t.bind.apply(t,o))();return r&&_setPrototypeOf(p,r.prototype),p;}function _isNativeFunction(t){try{return-1!==Function.toString.call(t).indexOf("[native code]");}catch(n){return"function"==typeof t;}}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}function _nonIterableSpread(){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 _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function _regenerator(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof Generator?n:Generator,u=Object.create(c.prototype);return _regeneratorDefine2(u,"_invoke",function(r,n,o){var i,c,u,f=0,p=o||[],y=!1,G={p:0,n:0,v:e,a:d,f:d.bind(e,4),d:function d(t,r){return i=t,c=0,u=e,G.n=r,a;}};function d(r,n){for(c=r,u=n,t=0;!y&&f&&!o&&t<p.length;t++){var o,i=p[t],d=G.p,l=i[2];r>3?(o=l===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,G.v=n,G.n=i[1]):d<l&&(o=r<3||i[0]>n||n>l)&&(i[4]=r,i[5]=n,G.n=l,c=0));}if(o||r>1)return a;throw y=!0,n;}return function(o,p,l){if(f>1)throw TypeError("Generator is already running");for(y&&1===p&&d(p,l),c=p,u=l;(t=c<2?e:u)||!y;){i||(c?c<3?(c>1&&(G.n=-1),d(c,u)):G.n=u:G.v=u);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0);}else 1===c&&(t=i["return"])&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e;}else if((t=(y=G.n<0)?u:r.call(n,G))!==a)break;}catch(t){i=e,c=1,u=t;}finally{f=1;}}return{value:t,done:y};};}(r,o,i),!0),u;}var a={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(_regeneratorDefine2(t={},n,function(){return this;}),t),u=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,GeneratorFunctionPrototype):(e.__proto__=GeneratorFunctionPrototype,_regeneratorDefine2(e,o,"GeneratorFunction")),e.prototype=Object.create(u),e;}return GeneratorFunction.prototype=GeneratorFunctionPrototype,_regeneratorDefine2(u,"constructor",GeneratorFunctionPrototype),_regeneratorDefine2(GeneratorFunctionPrototype,"constructor",GeneratorFunction),GeneratorFunction.displayName="GeneratorFunction",_regeneratorDefine2(GeneratorFunctionPrototype,o,"GeneratorFunction"),_regeneratorDefine2(u),_regeneratorDefine2(u,o,"Generator"),_regeneratorDefine2(u,n,function(){return this;}),_regeneratorDefine2(u,"toString",function(){return"[object Generator]";}),(_regenerator=function _regenerator(){return{w:i,m:f};})();}function _regeneratorDefine2(e,r,n,t){var i=Object.defineProperty;try{i({},"",{});}catch(e){i=0;}_regeneratorDefine2=function _regeneratorDefine(e,r,n,t){function o(r,n){_regeneratorDefine2(e,r,function(e){return this._invoke(r,n,e);});}r?i?i(e,r,{value:n,enumerable:!t,configurable:!t,writable:!t}):e[r]=n:(o("next",0),o("throw",1),o("return",2));},_regeneratorDefine2(e,r,n,t);}function asyncGeneratorStep(n,t,e,r,o,a,c){try{var i=n[a](c),u=i.value;}catch(n){return void e(n);}i.done?t(u):Promise.resolve(u).then(r,o);}function _asyncToGenerator(n){return function(){var t=this,e=arguments;return new Promise(function(r,o){var a=n.apply(t,e);function _next(n){asyncGeneratorStep(a,r,o,_next,_throw,"next",n);}function _throw(n){asyncGeneratorStep(a,r,o,_next,_throw,"throw",n);}_next(void 0);});};}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e;}function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1;}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r;}finally{try{if(!f&&null!=t["return"]&&(u=t["return"](),Object(u)!==u))return;}finally{if(o)throw n;}}return a;}}function _arrayWithHoles(r){if(Array.isArray(r))return r;}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}var m="classList",v="style",ga="unset",ba="html-wrapper",X="length",A=function A(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"div";return document.createElement(i);};var ya=/*#__PURE__*/function(){function ya(){_classCallCheck(this,ya);}return _createClass(ya,null,[{key:"render",value:function render(e,t){var n=A();n.id="error-view",n.innerText=t,e.replaceChildren(n);}}]);}();var zs=/*#__PURE__*/function(){function zs(){_classCallCheck(this,zs);}return _createClass(zs,null,[{key:"onLoad",value:function onLoad(e){e.innerHTML='<div id="loading-validate-key-property"></div>';}},{key:"createElements",value:function createElements(){var e=A();return e.id="validate-property-key-view",e;}},{key:"render",value:function render(e,t,n){var s=zs.createElements(),r={onSuccess:t,onFail:ya.render.bind(this,e,"Your 'key' has failed authentication"),onLoad:zs.onLoad.bind(this,s)};n.key&&n.verifyKey(n.key,r),e.replaceChildren(s);}}]);}();var ae="service",h="text",L="html",f="error",Z="https://deepchat.dev/docs/",ne="ai",F="user",gt="assistant",Vs="error-message-text",Ns="deep-chat-outer-container-role-",Or="empty-message",Ii="deep-chat-top-message",Nr="deep-chat-middle-message",Mi="deep-chat-bottom-message",T="src",E="type",se="file",b="files",W="image",ee="images",Fe="camera",Cn="gifs",$="audio",ct="microphone",Lo="mixedFiles",on="any",Oo="file-message",qt="start",No="end",Bo="messages",Br="0",Dr="1",x="role",Ee="string",ce=function ce(i){return JSON.stringify(i);},C=function C(i){return JSON.parse(ce(i));};function Fr(i){return i.charAt(0).toUpperCase()+i.slice(1);}function _a(i){return i&&ce(i);}function rr(i,e,t,n){var s="\n".concat(Fr(e)," message: ").concat(ce(i)," \n"),r=t?"".concat(Fr(e)," message after interceptor: ").concat(_a(n)," \n"):"";return s+r;}function Ea(i,e,t,n){return"".concat(rr(i,e,t,n),"Make sure the ").concat(e," message is using the Response format: ").concat(Z,"connect/#Response \nYou can also augment it using the responseInterceptor property: ").concat(Z,"interceptors#responseInterceptor");}function va(i,e,t){var n="response";return"".concat(rr(i,n,e,t),"Make sure the ").concat(n," message is using the {text: string} format, e.g: {text: \"Model Response\"}");}function Sa(i,e){var t="request";return"".concat(rr(i,t,e),"Make sure the ").concat(t," message is using the {body: {text: string}} format, e.g: {body: {text: \"Model Response\"}}");}function xa(i){return"".concat(i," failed - please wait for chat view to render before calling this property.");}var Tn=Ea,Aa=Sa,wa=va,Ur=xa,pe="Invalid API Key",Ue="Failed to connect",He="Request settings have not been set up",bi="No file was added",or="Image was not found",Do="Multi-response arrays are not supported for streaming",Fo="Make sure the events are using {text: string} or {html: string} format.\nYou can also augment them using the responseInterceptor property: ".concat(Z,"interceptors#responseInterceptor"),Ca="Cannot mix {text: string} and {html: string} responses.",Ta="No valid stream events were sent.\n".concat(Fo),Ra="Readable Stream connection error.",Gt="Please define a `function_handler` property inside the service config.",an="Function tool response must be an array or contain a text property",Uo="Failed to fetch history";var jt=/*#__PURE__*/function(){function jt(){_classCallCheck(this,jt);}return _createClass(jt,null,[{key:"apply",value:function apply(e,t){if(t)try{jt.applyStyleSheet(e,t);}catch(_unused){jt.addStyleElement(e,t);}}},{key:"applyStyleSheet",value:function applyStyleSheet(e,t){var n=new CSSStyleSheet();n.replaceSync(e),t.adoptedStyleSheets.push(n);}},{key:"addStyleElement",value:function addStyleElement(e,t){var n=A("style");n.innerHTML=e,t.appendChild(n);}},{key:"camelToKebab",value:function camelToKebab(e){return e.replace(/[A-Z]/g,function(t){return"-".concat(t.toLowerCase());});}},{key:"applyChatStyle",value:function applyChatStyle(e,t){if(!e||!t)return;var n=Object.entries(e).filter(function(_ref){var _ref2=_slicedToArray(_ref,2),s=_ref2[1];return s;}).map(function(_ref3){var _ref4=_slicedToArray(_ref3,2),s=_ref4[0],r=_ref4[1];return"".concat(jt.camelToKebab(s),": ").concat(r,";");}).join(" ");n&&jt.apply(":host { ".concat(n," }"),t);}}]);}();var In="inside-start",ft="inside-end",Le="outside-start",ve="outside-end",et="dropup-menu",w="default",De="hover",J="click",H="active",j="disabled",G="svg",Nt="unavailable",R="styles",ks="mouseenter",cn="mouseleave",Ia="mousedown",Ma="mouseup",st="submit",It="loading",Bi="stop",Un="unsupported",bn="commandMode";var de=/*#__PURE__*/function(){function de(){_classCallCheck(this,de);}return _createClass(de,null,[{key:"unsetStyle",value:function unsetStyle(e,t){var n=Object.keys(t).reduce(function(s,r){return s[r]="",s;},{});Object.assign(e[v],n);}},{key:"unsetActivityCSSMouseStates",value:function unsetActivityCSSMouseStates(e,t){t[J]&&de.unsetStyle(e,t[J]),t[De]&&de.unsetStyle(e,t[De]);}},{key:"unsetAllCSSMouseStates",value:function unsetAllCSSMouseStates(e,t){de.unsetActivityCSSMouseStates(e,t),t[w]&&de.unsetStyle(e,t[w]);}// if you want to asdd default styling - use pure css classes
2
+ },{key:"processStateful",value:function processStateful(e){var t=e[w]||{},n=Object.assign(C(t),e==null?void 0:e[De]),s=Object.assign(C(n),e==null?void 0:e[J]);return _defineProperty(_defineProperty(_defineProperty({},w,t),De,n),J,s);}},{key:"mergeStatefulStyles",value:function mergeStatefulStyles(e){var t=_defineProperty(_defineProperty(_defineProperty({},w,{}),De,{}),J,{});return e.forEach(function(n){t[w]=Object.assign(t[w],n[w]),t[De]=Object.assign(t[De],n[De]),t[J]=Object.assign(t[J],n[J]);}),t;}},{key:"overwriteDefaultWithAlreadyApplied",value:function overwriteDefaultWithAlreadyApplied(e,t){Object.keys(e[w]||[]).forEach(function(n){var r;var s=n;t[v][s]&&(r=e[w])!=null&&r[s]&&(e[w][n]=t[v][s]);});}},{key:"applyToStyleIfNotDefined",value:function applyToStyleIfNotDefined(e,t){for(var n in t){var s=t[n];e[n]===""&&s&&(e[n]=s);}}}]);}();var Xt=/*#__PURE__*/function(){function Xt(){_classCallCheck(this,Xt);}return _createClass(Xt,null,[{key:"buildElement",value:function buildElement(){var e=A();e[m].add("tooltip");var t=A("span");return t[m].add("tooltip-text"),e.appendChild(t),e;}},{key:"tryCreateConfig",value:function tryCreateConfig(e,t){if(t)return typeof t=="boolean"?_defineProperty({},h,e):_defineProperty(_defineProperty(_defineProperty({},h,t[h]||e),"timeout",t.timeout||0),"style",t[v]);}},{key:"traverseParentUntilContainer",value:function traverseParentUntilContainer(e){var t=e;for(;t.parentElement;)t=t.parentElement;return t;}},{key:"setPosition",value:function setPosition(e,t){var s=t.getRootNode().host.getBoundingClientRect(),r=e.getBoundingClientRect(),a=t.getBoundingClientRect().width/2,c=r.left+r.width/2;t[v].left="".concat(c-a-s.left,"px"),t[v].top="".concat(r.top-36-s.top,"px");var l=t.getBoundingClientRect();l.left<s.left?t[v].left="".concat(Xt.OVERFLOW_NEW_POSITION_PX,"px"):l.right>s.right&&(t[v].left="".concat(s.width-l.width-Xt.OVERFLOW_NEW_POSITION_PX,"px"));}},{key:"display",value:function display(e,t,n){return n||(n=Xt.traverseParentUntilContainer(e).nextSibling),t[h]&&(n.children[0].textContent=t[h]),{timeout:setTimeout(function(){n[v].visibility="visible",Xt.setPosition(e,n),t[v]&&Object.assign(n[v],t[v]);},t.timeout||0),element:n};}},{key:"hide",value:function hide(e,t){clearTimeout(e.timeout),e.element[v].visibility="hidden",t[v]&&de.unsetStyle(e.element,t[v]),e.element[v].left="",e.element[v].top="";}}]);}();Xt.OVERFLOW_NEW_POSITION_PX=4;var ut=Xt;var gs=/*#__PURE__*/_createClass(function gs(){_classCallCheck(this,gs);});gs.IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),gs.IS_CHROMIUM=window.chrome,gs.IS_MOBILE=/iPhone|iPad|iPod|Android/i.test(navigator.userAgent);var $e=gs;var _e=/* @__PURE__ */function(i){return i.ESCAPE="Escape",i.ENTER="Enter",i.TAB="Tab",i.ARROW_UP="ArrowUp",i.ARROW_DOWN="ArrowDown",i.ARROW_RIGHT="ArrowRight",i.ARROW_LEFT="ArrowLeft",i.BACKSPACE="Backspace",i.DELETE="Delete",i.META="Meta",i.CONTROL="Control",i;}(_e||{});var Zt=/*#__PURE__*/function(){function Zt(){_classCallCheck(this,Zt);}return _createClass(Zt,null,[{key:"add",value:// prettier-ignore
3
+ function add(e,t,n,s){n!==void 0&&e.addEventListener("keydown",Zt.onKeyDown.bind(this,n)),e.oninput=Zt.onInput.bind(this,n,s),e.addEventListener("paste",function(r){var o;r.preventDefault(),(o=r.clipboardData)!=null&&o[b].length&&t.addFilesToAnyType(Array.from(r.clipboardData[b]));});}// preventing insertion early for a nicer UX
8
4
  // prettier-ignore
9
- },{key:"onKeyDown",value:function onKeyDown(e,t){var s=t.target.textContent;s&&s.length>=e&&!Zt.PERMITTED_KEYS.has(t.key)&&!Zt.isKeyCombinationPermitted(t)&&t.preventDefault();}},{key:"isKeyCombinationPermitted",value:function isKeyCombinationPermitted(e){return e.key==="a"?e.ctrlKey||e.metaKey:!1;}},{key:"onInput",value:function onInput(e,t,n){var s=n.target,r=s.textContent||"";e!==void 0&&r.length>e&&(s.textContent=r.substring(0,e),cn.focusEndOfInput(s)),t==null||t();}}]);}();Zt.PERMITTED_KEYS=/* @__PURE__ */new Set([_e.BACKSPACE,_e.DELETE,_e.ARROW_RIGHT,_e.ARROW_LEFT,_e.ARROW_DOWN,_e.ARROW_UP,_e.META,_e.CONTROL,_e.ENTER]);var Ui=Zt;var Pa=/*#__PURE__*/function(){function Pa(){_classCallCheck(this,Pa);}return _createClass(Pa,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var s;e.preventDefault();var t=(s=e.clipboardData)==null?void 0:s.getData("text/plain");if(!t)return;var n=t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>");document.execCommand("insertHTML",!1,n);}}]);}();var Bt=/*#__PURE__*/function(){function Bt(e,t,n,s){var _this=this;_classCallCheck(this,Bt);var o,a,c,l;this._isComposing=!1;var r=Bt.processConfig(t,e.textInput);this.elementRef=Bt.createContainerElement((o=r==null?void 0:r[R])==null?void 0:o.container),this._config=r,this.inputElementRef=this.createInputElement((a=e.defaultInput)==null?void 0:a[h],s),Bt.addFilesToAnyType(n,(c=e.defaultInput)==null?void 0:c[b]),this.elementRef.appendChild(this.inputElementRef),e.setPlaceholderText=this.setPlaceholderText.bind(this),e.setPlaceholderText(((l=this._config.placeholder)==null?void 0:l[h])||"Ask me anything!"),this._browserStorage=s,setTimeout(function(){Ui.add(_this.inputElementRef,n,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(Bt,[{key:"clear",value:// this also similarly prevents scroll up
10
- function clear(){var t,n,s;var e=window.scrollY;this.inputElementRef[m].contains("text-input-".concat(j))||(Object.assign(this.inputElementRef[v],(t=this._config.placeholder)==null?void 0:t[v]),this.inputElementRef.textContent="",cn.focusEndOfInput(this.inputElementRef),(n=this._onInput)==null||n.call(this,!1),(s=this._browserStorage)==null||s.addInputText("")),$e.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(e,t){var s,r,o,a;var n=A();return n.id=Bt.TEXT_INPUT_ID,n[m].add("text-input-styling"),n[x]="textbox",typeof e=="string"?n.innerText=e:t!=null&&t.trackInputText&&(n.innerText=t.get().inputText||""),$e.IS_MOBILE&&n.setAttribute("tabindex","0"),$e.IS_CHROMIUM&&Bt.preventAutomaticScrollUpOnNewLine(n),typeof this._config[j]=="boolean"&&this._config[j]===!0?(n.contentEditable="false",n[m].add("text-input-".concat(j)),n.setAttribute("aria-".concat(j),"true")):(n.contentEditable="true",n.removeAttribute("aria-".concat(j)),this.addEventListeners(n)),Object.assign(n[v],(s=this._config[R])==null?void 0:s[h]),Object.assign(n[v],(r=this._config.placeholder)==null?void 0:r[v]),(a=(o=this._config.placeholder)==null?void 0:o[v])!=null&&a.color||n.setAttribute("textcolor",""),n;}},{key:"removePlaceholderStyle",value:function removePlaceholderStyle(){var e,t,n,s;!this.inputElementRef[m].contains("text-input-".concat(j))&&(e=this._config.placeholder)!=null&&e[v]&&(ce.unsetStyle(this.inputElementRef,(t=this._config.placeholder)==null?void 0:t[v]),Object.assign(this.inputElementRef[v],(s=(n=this._config)==null?void 0:n[R])==null?void 0:s[h]));}},{key:"addEventListeners",value:function addEventListeners(e){var _this2=this;var t,n;(t=this._config[R])!=null&&t.focus&&(e.onfocus=function(){var s;return Object.assign(_this2.elementRef[v],(s=_this2._config[R])==null?void 0:s.focus);},e.onblur=this.onBlur.bind(this,this._config[R].focus,(n=this._config[R])==null?void 0:n.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",Pa.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){ce.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef[v],t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===_e.ENTER&&!$e.IS_MOBILE&&!this._isComposing&&!e.ctrlKey&&!e.shiftKey&&(e.preventDefault(),(t=this.submit)==null||t.call(this));}},{key:"onInput",value:function onInput(){var e,t;this.isTextInputEmpty()?Object.assign(this.inputElementRef[v],(e=this._config.placeholder)==null?void 0:e[v]):this.removePlaceholderStyle(),(t=this._onInput)==null||t.call(this,!0);}},{key:"setPlaceholderText",value:function setPlaceholderText(e){this.inputElementRef.setAttribute("deep-chat-placeholder-text",e),this.inputElementRef.setAttribute("aria-label",e);}},{key:"isTextInputEmpty",value:function isTextInputEmpty(){return this.inputElementRef.textContent==="";}}],[{key:"processConfig",value:function processConfig(e,t){var _t$j,_t$placeholder,_n$h;var n;return t!==null&&t!==void 0?t:t={},(_t$j=t[j])!==null&&_t$j!==void 0?_t$j:t[j]=e.isTextInputDisabled,(_t$placeholder=t.placeholder)!==null&&_t$placeholder!==void 0?_t$placeholder:t.placeholder={},(_n$h=(n=t.placeholder)[h])!==null&&_n$h!==void 0?_n$h:n[h]=e.textInputPlaceholderText,t;}},{key:"createContainerElement",value:function createContainerElement(e){var t=A();return t.id="text-input-container",Object.assign(t[v],e),t;}// this is is a bug fix where if the browser is scrolled down and the user types in text that creates new line
5
+ },{key:"onKeyDown",value:function onKeyDown(e,t){var s=t.target.textContent;s&&s.length>=e&&!Zt.PERMITTED_KEYS.has(t.key)&&!Zt.isKeyCombinationPermitted(t)&&t.preventDefault();}},{key:"isKeyCombinationPermitted",value:function isKeyCombinationPermitted(e){return e.key==="a"?e.ctrlKey||e.metaKey:!1;}},{key:"onInput",value:function onInput(e,t,n){var s=n.target,r=s.textContent||"";e!==void 0&&r.length>e&&(s.textContent=r.substring(0,e),ln.focusEndOfInput(s)),t==null||t();}}]);}();Zt.PERMITTED_KEYS=/* @__PURE__ */new Set([_e.BACKSPACE,_e.DELETE,_e.ARROW_RIGHT,_e.ARROW_LEFT,_e.ARROW_DOWN,_e.ARROW_UP,_e.META,_e.CONTROL,_e.ENTER]);var Di=Zt;var ka=/*#__PURE__*/function(){function ka(){_classCallCheck(this,ka);}return _createClass(ka,null,[{key:"sanitizePastedTextContent",value:function sanitizePastedTextContent(e){var s;e.preventDefault();var t=(s=e.clipboardData)==null?void 0:s.getData("text/plain");if(!t)return;var n=t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>");document.execCommand("insertHTML",!1,n);}}]);}();var Bt=/*#__PURE__*/function(){function Bt(e,t,n,s){var _this=this;_classCallCheck(this,Bt);var o,a,c,l;this._isComposing=!1;var r=Bt.processConfig(t,e.textInput);this.elementRef=Bt.createContainerElement((o=r==null?void 0:r[R])==null?void 0:o.container),this._config=r,this.inputElementRef=this.createInputElement((a=e.defaultInput)==null?void 0:a[h],s),Bt.addFilesToAnyType(n,(c=e.defaultInput)==null?void 0:c[b]),this.elementRef.appendChild(this.inputElementRef),e.setPlaceholderText=this.setPlaceholderText.bind(this),e.setPlaceholderText(((l=this._config.placeholder)==null?void 0:l[h])||"Ask me anything!"),this._browserStorage=s,setTimeout(function(){Di.add(_this.inputElementRef,n,_this._config.characterLimit,e._validationHandler),_this._onInput=t.onInput;});}return _createClass(Bt,[{key:"clear",value:// this also similarly prevents scroll up
6
+ function clear(){var t,n,s;var e=window.scrollY;this.inputElementRef[m].contains("text-input-".concat(j))||(Object.assign(this.inputElementRef[v],(t=this._config.placeholder)==null?void 0:t[v]),this.inputElementRef.textContent="",ln.focusEndOfInput(this.inputElementRef),(n=this._onInput)==null||n.call(this,!1),(s=this._browserStorage)==null||s.addInputText("")),$e.IS_CHROMIUM&&window.scrollTo({top:e});}},{key:"createInputElement",value:function createInputElement(e,t){var s,r,o,a;var n=A();return n.id=Bt.TEXT_INPUT_ID,n[m].add("text-input-styling"),n[x]="textbox",typeof e=="string"?n.innerText=e:t!=null&&t.trackInputText&&(n.innerText=t.get().inputText||""),$e.IS_MOBILE&&n.setAttribute("tabindex","0"),$e.IS_CHROMIUM&&Bt.preventAutomaticScrollUpOnNewLine(n),typeof this._config[j]=="boolean"&&this._config[j]===!0?(n.contentEditable="false",n[m].add("text-input-".concat(j)),n.setAttribute("aria-".concat(j),"true")):(n.contentEditable="true",n.removeAttribute("aria-".concat(j)),this.addEventListeners(n)),Object.assign(n[v],(s=this._config[R])==null?void 0:s[h]),Object.assign(n[v],(r=this._config.placeholder)==null?void 0:r[v]),(a=(o=this._config.placeholder)==null?void 0:o[v])!=null&&a.color||n.setAttribute("textcolor",""),n;}},{key:"removePlaceholderStyle",value:function removePlaceholderStyle(){var e,t,n,s;!this.inputElementRef[m].contains("text-input-".concat(j))&&(e=this._config.placeholder)!=null&&e[v]&&(de.unsetStyle(this.inputElementRef,(t=this._config.placeholder)==null?void 0:t[v]),Object.assign(this.inputElementRef[v],(s=(n=this._config)==null?void 0:n[R])==null?void 0:s[h]));}},{key:"addEventListeners",value:function addEventListeners(e){var _this2=this;var t,n;(t=this._config[R])!=null&&t.focus&&(e.onfocus=function(){var s;return Object.assign(_this2.elementRef[v],(s=_this2._config[R])==null?void 0:s.focus);},e.onblur=this.onBlur.bind(this,this._config[R].focus,(n=this._config[R])==null?void 0:n.container)),e.addEventListener("keydown",this.onKeydown.bind(this)),e.addEventListener("input",this.onInput.bind(this)),e.addEventListener("paste",ka.sanitizePastedTextContent),e.addEventListener("compositionstart",function(){return _this2._isComposing=!0;}),e.addEventListener("compositionend",function(){return _this2._isComposing=!1;});}},{key:"onBlur",value:function onBlur(e,t){de.unsetStyle(this.elementRef,e),t&&Object.assign(this.elementRef[v],t);}},{key:"onKeydown",value:function onKeydown(e){var t;e.key===_e.ENTER&&!$e.IS_MOBILE&&!this._isComposing&&!e.ctrlKey&&!e.shiftKey&&(e.preventDefault(),(t=this.submit)==null||t.call(this));}},{key:"onInput",value:function onInput(){var e,t;this.isTextInputEmpty()?Object.assign(this.inputElementRef[v],(e=this._config.placeholder)==null?void 0:e[v]):this.removePlaceholderStyle(),(t=this._onInput)==null||t.call(this,!0);}},{key:"setPlaceholderText",value:function setPlaceholderText(e){this.inputElementRef.setAttribute("deep-chat-placeholder-text",e),this.inputElementRef.setAttribute("aria-label",e);}},{key:"isTextInputEmpty",value:function isTextInputEmpty(){return this.inputElementRef.textContent==="";}}],[{key:"processConfig",value:function processConfig(e,t){var _t$j,_t$placeholder,_n$h;var n;return t!==null&&t!==void 0?t:t={},(_t$j=t[j])!==null&&_t$j!==void 0?_t$j:t[j]=e.isTextInputDisabled,(_t$placeholder=t.placeholder)!==null&&_t$placeholder!==void 0?_t$placeholder:t.placeholder={},(_n$h=(n=t.placeholder)[h])!==null&&_n$h!==void 0?_n$h:n[h]=e.textInputPlaceholderText,t;}},{key:"createContainerElement",value:function createContainerElement(e){var t=A();return t.id="text-input-container",Object.assign(t[v],e),t;}// this is is a bug fix where if the browser is scrolled down and the user types in text that creates new line
11
7
  // the browser scrollbar will move up which leads to undesirable UX.
12
8
  // More details in this Stack Overflow question:
13
9
  // https://stackoverflow.com/questions/76285135/prevent-automatic-scroll-when-text-is-inserted-into-contenteditable-div
14
10
  // prettier-ignore
15
- },{key:"preventAutomaticScrollUpOnNewLine",value:function preventAutomaticScrollUpOnNewLine(e){var t;e.addEventListener("keydown",function(){t=window.scrollY;}),e.addEventListener("input",function(){t!==window.scrollY&&window.scrollTo({top:t});});}},{key:"addFilesToAnyType",value:function addFilesToAnyType(e,t){t&&e.addFilesToAnyType(Array.from(t).map(function(n){return n;}));}}]);}();Bt.TEXT_INPUT_ID="text-input";var Xs=Bt;var cn=/*#__PURE__*/function(){function cn(){_classCallCheck(this,cn);}return _createClass(cn,null,[{key:"focusEndOfInput",value:function focusEndOfInput(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n==null||n.removeAllRanges(),n==null||n.addRange(t),($e.IS_MOBILE||$e.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(Xs.TEXT_INPUT_ID));t&&cn.focusEndOfInput(t);}}]);}();var jo="Authentication",he="Authorization",La="authorization",Ei="Unauthorized",cr="Authorization header",Gt="Invalid",Ls="Incorrect",Te="authentication_error",it="invalid_request_error",q="Content-Type",Oa="content-type",te="application/json",U="object",lr="completed",Ce="Bearer ",ue="GET",ye="POST",dr="Upload an audio file",qs="function_call",nn="input_audio",qe="image_url",Mn="system",mi=/*#__PURE__*/function(){function mi(){_classCallCheck(this,mi);}return _createClass(mi,null,[{key:"addElements",value:function addElements(e){for(var _len=arguments.length,t=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){t[_key-1]=arguments[_key];}t.forEach(function(n){return e.appendChild(n);});}},{key:"isScrollbarAtBottomOfElement",value:function isScrollbarAtBottomOfElement(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:mi.CODE_SNIPPET_GENERATION_JUMP;var n=e.scrollHeight,s=e.clientHeight,r=e.scrollTop,o=n-s;return r>=o-t;}},{key:"cloneElement",value:function cloneElement(e){var t=e.cloneNode(!0);return e.parentNode.replaceChild(t,e),t;}},{key:"scrollToBottom",value:function scrollToBottom(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2?arguments[2]:undefined;e.scrollButton&&e.scrollButton.hiddenElements.size>0&&e.scrollButton.clearHidden(),n?e.elementRef.scrollTo({left:0,top:n.offsetTop}):t?e.elementRef.scrollTo({left:0,top:e.elementRef.scrollHeight,behavior:"smooth"}):e.elementRef.scrollTop=e.elementRef.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}},{key:"isVisibleInParent",value:function isVisibleInParent(e,t){var n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return n.bottom>s.top&&n.top<s.bottom;}},{key:"waitForScrollEnd",value:function waitForScrollEnd(e,t){var n=-1,s=0;var _r2=function r(){var o=e.scrollTop;if(o===n){if(s++,s>2){t();return;}}else s=0,n=o;requestAnimationFrame(_r2);};requestAnimationFrame(_r2);}},{key:"assignButtonEvents",value:function assignButtonEvents(e,t){e.onclick=t,e.onkeydown=function(n){n.key===_e.ENTER&&setTimeout(t);};}}]);}();mi.CODE_SNIPPET_GENERATION_JUMP=1;var z=mi;var gi=/*#__PURE__*/function(){function gi(){_classCallCheck(this,gi);}return _createClass(gi,null,[{key:"speak",value:function speak(e,t){if(!t.audio&&window.SpeechSynthesisUtterance){var n=new SpeechSynthesisUtterance(e);Object.assign(n,t),speechSynthesis.speak(n);}}},{key:"processConfig",value:function processConfig(e,t){var n={};setTimeout(function(){if(_typeof(e)=="object"&&(e.audio&&(n.audio=e.audio),e.lang&&(n.lang=e.lang),e.pitch&&(n.pitch=e.pitch),e.rate&&(n.rate=e.rate),e.volume&&(n.volume=e.volume),e.voiceName)){var s=window.speechSynthesis.getVoices().find(function(r){var o;return r.name.toLocaleLowerCase()===((o=e.voiceName)==null?void 0:o.toLocaleLowerCase());});s&&(n.voice=s);}t(n);},gi.LOAD_VOICES_MS);}}]);}();gi.LOAD_VOICES_MS=200;var Rn=gi;var Sn=/*#__PURE__*/function(){function Sn(){_classCallCheck(this,Sn);}return _createClass(Sn,null,[{key:"colorToHex",value:function colorToHex(e){var t=A();return t[v].color=e,document.body.appendChild(t),"#".concat(window.getComputedStyle(t).color.match(/\d+/g).map(function(r){return parseInt(r).toString(16).padStart(2,"0");}).join(""));}},{key:"setDots",value:function setDots(e,t){var n,s;if((s=(n=t==null?void 0:t[R])==null?void 0:n.bubble)!=null&&s.color){var r=Sn.colorToHex(t[R].bubble.color);e[v].setProperty("--loading-message-color",r),e[v].setProperty("--loading-message-color-fade","".concat(r,"33"));}else e[v].setProperty("--loading-message-color","#848484"),e[v].setProperty("--loading-message-color-fade","#55555533");}},{key:"setRing",value:function setRing(e,t){var _ref4=t||{},n=_ref4.color,s=_ref4.width,r=_ref4.height,o=_ref4.margin,a=_ref4.border;if(n){var c=Sn.colorToHex(n);e[v].setProperty("--loading-history-color",c);}else e[v].setProperty("--loading-history-color","#dbdbdb");e[v].setProperty("--loading-history-height",r||"57px"),e[v].setProperty("--loading-history-width",s||"57px"),e[v].setProperty("--loading-history-margin",o||"7px"),e[v].setProperty("--loading-history-border",a||"6px solid");}}]);}();Sn.BUBBLE_CLASS="deep-chat-loading-message-bubble",Sn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var mt=Sn;var de=/*#__PURE__*/function(){function de(){_classCallCheck(this,de);}return _createClass(de,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var n=e.containerStyle;n&&(Object.assign(t[v],n),console[f]("The containerStyle property".concat(Je,"1.3.14.")),console[f]("".concat(zt,"the style property instead: ").concat(Z,"styles#style")));}// eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- },{key:"handleResponseProperty",value:function handleResponseProperty(e){return console[f]("The {result: ....} response object type".concat(Je,"1.3.0.")),console[f]("".concat(zt,"the new response object: ").concat(Z,"connect#Response")),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console[f]("The initialMessages property".concat(Je,"2.0.0.")),console[f]("".concat(zt,"the history property instead: ").concat(Z,"messages/#history")),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e[se];t&&(console[f]("The file property in MessageContent".concat(Je,"1.3.17.")),console[f]("".concat(zt,"the files array property: ").concat(Z,"messages/#MessageContent")),e[b]=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console[f]("The validateMessageBeforeSending property".concat(Je,"1.3.24.")),console[f]("".concat(zt,"validateInput: ").concat(Z,"interceptors#validateInput")),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console[f]("The submitUserMessage(text: string) argument string type".concat(Je,"1.4.4.")),console[f]("".concat(zt,"the new argument type: ").concat(Z,"methods#submitUserMessage")),_defineProperty({},h,e);}},{key:"flagHTMLUpdateClass",value:function flagHTMLUpdateClass(e){var t;(t=e.children[0])!=null&&t[m].contains("deep-chat-update-message")&&(console[f]("The \"deep-chat-update-message\" html class".concat(Je,"1.4.4.")),console[f]("".concat(zt,"using {..., overwrite: true} object: ").concat(Z,"connect#Response")));}},{key:"processConnect",value:function processConnect(e){var t=e;t.request&&(t.connect?Object.assign(t.connect,t.request):t.connect=t.request,console[f]("The request property".concat(Je,"2.0.0.")),console[f]("".concat(Ds,"connect object: ").concat(Z,"connect#connect-1")));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console[f]("The stream property".concat($r,"the connect object in version 2.0.0.")),console[f]("".concat(Ds,"connect object: ").concat(Z,"connect#connect-1")),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var s;var n=e;n.onNewMessage&&(console[f]("The onNewMessage event".concat(Je,"2.0.0.")),console[f]("".concat(Ds,"onMessage event: ").concat(Z,"events#onMessage")),(s=n.onNewMessage)==null||s.call(n,t)),e.dispatchEvent(new CustomEvent("new-message",{detail:t}));}},{key:"processFileConfigConnect",value:function processFileConfigConnect(e){var t=e;t.request&&(console[f]("The request property in file configuration".concat(Je,"2.0.0.")),console[f]("Please use the connect property instead: ".concat(Z,"files")),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=C(e),n=t.loading;return n&&(n.outerContainer||n.innerContainer||n.bubble||n.media)&&(console[f]("The loading message styles are defined using LoadingMessageStyles interface".concat(_n,"2.1.0.")),console[f]("Check it out here: ".concat(Z,"messages/styles#LoadingMessageStyles")),t.loading={message:{styles:n}}),t;}},{key:"processDemo",value:function processDemo(e){return typeof e=="boolean"||e.displayLoadingBubble&&(console[f]("The demo displayLoadingBubble property".concat(Je,"2.1.0.")),console[f]("Please use displayLoading instead: ".concat(Z,"modes#demo")),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,n="".concat(Ds,"official documentation: ").concat(Z,"directConnection/Cohere");return t.chat&&(console[f]("Cohere chat property".concat(Je,"2.2.3.")),console[f](n),delete t.chat),t.textGeneration?(console[f]("Cohere textGeneration".concat(jr,"2.2.3.")),console[f](n),delete t.textGeneration,!1):t.summarization?(console[f]("Cohere summarization".concat(jr,"2.2.3.")),console[f](n),delete t.summarization,!1):!0;}},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==U)return;var t=e.htmlWrappers;if(t)return console[f]("The htmlWrappers property".concat($r,"Deep Chat's base").concat(_n,"2.3.0.")),console[f]("Check it out here: ".concat(Z,"messages/HTML#htmlWrappers")),t;}},{key:"processFocusMode",value:function processFocusMode(e){return!e||typeof e=="boolean"||e.scroll&&(console[f]("The scroll property in focusMode has been changed to smoothScroll".concat(_n,"2.3.0.")),console[f]("Check it out here: ".concat(Z,"modes#focusMode")),e.smoothScroll=!0),e;}},{key:"processPosition",value:function processPosition(e){if(!e)return e;var t="Position names have been updated".concat(_n,"2.3.1.");return e==="inside-left"?(console[f](t),In):e==="inside-right"?(console[f](t),ft):e==="outside-left"?(console[f](t),Le):e==="outside-right"?(console[f](t),ve):e;}},{key:"processBrowserStorage",value:function processBrowserStorage(e){var t=e.get();t&&Array.isArray(t)&&e.addMessages(t);}}]);}();var _n=" since version ",Je=" is deprecated ".concat(_n),zt="Please change to using ",Ds="Please see the ",jr=" is not supported ".concat(_n),$r=" has been moved to ";var Rt=/*#__PURE__*/function(){function Rt(){_classCallCheck(this,Rt);}return _createClass(Rt,null,[{key:"mouseUp",value:function mouseUp(e,t){ce.unsetAllCSSMouseStates(e,t),Object.assign(e[v],t[w]),Object.assign(e[v],t[De]);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e[v],t[J]);}},{key:"mouseLeave",value:function mouseLeave(e,t){ce.unsetAllCSSMouseStates(e,t),Object.assign(e[v],t[w]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e[v],t[De]);}},{key:"add",value:function add(e,t){e.addEventListener(Ps,Rt.mouseEnter.bind(this,e,t)),e.addEventListener(an,Rt.mouseLeave.bind(this,e,t)),e.addEventListener(Ma,Rt.mouseDown.bind(this,e,t)),e.addEventListener(ka,Rt.mouseUp.bind(this,e,t));}}]);}();var Na="deep-chat-temporary-message",Ba="deep-chat-suggestion-button",Hi={"deep-chat-button":{styles:_defineProperty(_defineProperty(_defineProperty({},w,{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"}),De,{backgroundColor:"#fafafa"}),J,{backgroundColor:"#f1f1f1"})}},qr=Object.keys(Hi);var bt=/*#__PURE__*/function(){function bt(){_classCallCheck(this,bt);}return _createClass(bt,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener(J,function(){var n,s;(s=e.submitUserMessage)==null||s.call(e,_defineProperty({},h,((n=t.textContent)==null?void 0:n.trim())||""));});});}},{key:"isElementTemporary",value:function isElementTemporary(e){var t;return e?(t=e.bubbleElement.children[0])==null?void 0:t[m].contains(Na):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return qr.find(function(t){return e[m].contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var n=Hi[t].events;Object.keys(n||[]).forEach(function(s){e.addEventListener(s,n==null?void 0:n[s]);});}},{key:"getProcessedStyles",value:function getProcessedStyles(e,t,n){var s=Array.from(t[m]).reduce(function(a,c){var d;var l=(d=e[c])==null?void 0:d[R];return l&&e[c][R]&&a.push(l),a;},[]),r=Hi[n][R];if(r){var a=C(r);a[w]&&ce.overwriteDefaultWithAlreadyApplied(a,t),s.unshift(a);}var o=ce.mergeStatefulStyles(s);return ce.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,n){qr.forEach(function(r){var o=n.getElementsByClassName(r);Array.from(o||[]).forEach(function(a){var c=bt.getProcessedStyles(t,a,r);oe.applyStylesToElement(a,c),bt.applyEvents(a,r);});});var s=n.getElementsByClassName(Ba);Array.from(s).forEach(function(r){return bt.applySuggestionEvent(e,r);});}}]);}();var oe=/*#__PURE__*/function(){function oe(){_classCallCheck(this,oe);}return _createClass(oe,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var n=ce.processStateful(t);Rt.add(e,n),Object.assign(e[v],n[w]);}},{key:"applyEventsToElement",value:function applyEventsToElement(e,t){Object.keys(t).forEach(function(n){var s=t[n];s&&e.addEventListener(n,s);});}},{key:"applyClassUtilitiesToElement",value:function applyClassUtilitiesToElement(e,t){var n=t.events,s=t.styles;n&&oe.applyEventsToElement(e,n),s&&!bt.doesElementContainDeepChatClass(e)&&oe.applyStylesToElement(e,s);}},{key:"applyCustomClassUtilities",value:function applyCustomClassUtilities(e,t){Object.keys(e).forEach(function(n){var s=t.getElementsByClassName(n);Array.from(s).forEach(function(r){e[n]&&oe.applyClassUtilitiesToElement(r,e[n]);});});}},{key:"apply",value:function apply(e,t){bt.applyDeepChatUtilities(e,e.htmlClassUtilities,t),oe.applyCustomClassUtilities(e.htmlClassUtilities,t);}},{key:"traverseNodes",value:function traverseNodes(e,t){e.nodeType===Node.ELEMENT_NODE&&t.push(e.outerHTML),e.childNodes.forEach(function(n){oe.traverseNodes(n,t);});}},{key:"splitHTML",value:function splitHTML(e){var n=new DOMParser().parseFromString(e,"text/html"),s=[];return n.body.childNodes.forEach(function(r){oe.traverseNodes(r,s);}),s;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=A();return t.innerHTML=e,bt.isElementTemporary({outerContainer:t,bubbleElement:t,innerContainer:t});}// useful for removing event listeners
17
- },{key:"replaceElementWithNewClone",value:function replaceElementWithNewClone(e,t){var s;var n=(t||e).cloneNode(!0);return(s=e.parentNode)==null||s.replaceChild(n,e),n;}},{key:"tryAddWrapper",value:function tryAddWrapper(e,t,n,s){if(t&&s){var r=(n==null?void 0:n[s])||(n==null?void 0:n[w]);if(r)return e.innerHTML=r,{contentEl:oe.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(ya)[0]||e;}}]);}();var Dt=/*#__PURE__*/function(){function Dt(){_classCallCheck(this,Dt);}return _createClass(Dt,null,[{key:"createElements",value:function createElements(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;var o=e.createMessageElementsOnOrientation("",n,s,r);o.bubbleElement[m].add(Dt.HTML_BUBBLE_CLASS);var _oe$tryAddWrapper=oe.tryAddWrapper(o.bubbleElement,t,e._customWrappers,n),a=_oe$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,n){n.bubbleElement.innerHTML=t,oe.apply(e,n.outerContainer),de.flagHTMLUpdateClass(n.bubbleElement);}// prettier-ignore
18
- },{key:"overwrite",value:function overwrite(e,t,n,s){var r=e.messageToElements,o=B.overwriteMessage(r,s,t,n,L,Dt.HTML_BUBBLE_CLASS);return o&&Dt.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var r=Dt.createElements(e,t,n,s);return B.fillEmptyMessageElement(r.bubbleElement,t),oe.apply(e,r.outerContainer),de.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,n,!1,(o=e.messageStyles)==null?void 0:o[L]),r;}},{key:"add",value:function add(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(s!=null&&s.status){var a=this.overwrite(e,t,n,e.messageElementRefs);if(a)return a;s.status=!1;}if(r&&e.messageElementRefs.length>0&&oe.isTemporaryBasedOnHTML(t))return;var o=Dt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();Dt.HTML_BUBBLE_CLASS="html-message";var yt=Dt;var Da=/*#__PURE__*/function(){function Da(){_classCallCheck(this,Da);}return _createClass(Da,null,[{key:"katex",value:function katex(e,t,n){var a=(n||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var c=function c(p,u){var g;return((g=window.katex)==null?void 0:g.renderToString(p,_objectSpread({displayMode:u,throwOnError:!1,output:"mathml"},e)))||"";},l=function l(p,u,g){var y=!1,_=p.bMarks[u]+p.tShift[u],S=p.eMarks[u];if(_+1>S)return!1;var M=p[T].charAt(_);if(M!==a)return!1;var K=_;_=p.skipChars(_,M);var ie=_-K;if(ie!==2)return!1;var re=u;for(;++re,!(re>=g||(_=K=p.bMarks[re]+p.tShift[re],S=p.eMarks[re],_<S&&p.tShift[re]<p.blkIndent));)if(p[T].charAt(_)===a&&!(p.tShift[re]-p.blkIndent>=4)&&(_=p.skipChars(_,M),!(_-K<ie)&&(_=p.skipSpaces(_),!(_<S)))){y=!0;break;}ie=p.tShift[u],p.line=re+(y?1:0);var Re=p.getLines(u+1,re,ie,!0).replace(/[ \n]+/g," ").trim();return p.tokens.push({type:"katex",params:null,content:Re,lines:[u,p.line],level:p.level,block:!0}),!0;},d=function d(p,u){var g=p.pos,y=p.posMax;var _=g;if(p[T].charAt(_)!==a)return!1;for(++_;_<y&&p[T].charAt(_)===a;)++_;var S=p[T].slice(g,_);if(S.length>2)return!1;var M=_;var K=0;for(;_<y;){var ie=p[T].charAt(_);if(ie==="{"&&(_===0||p[T].charAt(_-1)!=="\\"))K+=1;else if(ie==="}"&&(_===0||p[T].charAt(_-1)!=="\\")){if(K-=1,K<0)return!1;}else if(ie===a&&K===0){var re=_;var Re=_+1;for(;Re<y&&p[T].charAt(Re)===a;)++Re;if(Re-re===S.length){if(!u){var Lt=p[T].slice(M,re).replace(/[ \n]+/g," ").trim();p.push({type:"katex",content:Lt,block:S.length>1,level:p.level});}return p.pos=Re,!0;}}_+=1;}return u||(p.pending+=S),p.pos+=S.length,!0;};t.inline.ruler.push("katex",d,n),t.block.ruler.push("katex",l,n),t.renderer.rules.katex=function(p,u){return c(p[u].content,p[u].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var Fs;function $o(i){return Fs=Fs||document.createElement("textarea"),Fs.innerHTML="&"+i+";",Fs.value;}var Fa=Object.prototype.hasOwnProperty;function Ua(i,e){return i?Fa.call(i,e):!1;}function qo(i){var e=[].slice.call(arguments,1);return e.forEach(function(t){if(t){if(_typeof(t)!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(n){i[n]=t[n];});}}),i;}var Ha=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function As(i){return i.indexOf("\\")<0?i:i.replace(Ha,"$1");}function Go(i){return!(i>=55296&&i<=57343||i>=64976&&i<=65007||(i&65535)===65535||(i&65535)===65534||i>=0&&i<=8||i===11||i>=14&&i<=31||i>=127&&i<=159||i>1114111);}function ji(i){if(i>65535){i-=65536;var e=55296+(i>>10),t=56320+(i&1023);return String.fromCharCode(e,t);}return String.fromCharCode(i);}var ja=/&([a-z#][a-z0-9]{1,31});/gi,$a=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function qa(i,e){var t=0,n=$o(e);return e!==n?n:e.charCodeAt(0)===35&&$a.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),Go(t))?ji(t):i;}function ln(i){return i.indexOf("&")<0?i:i.replace(ja,qa);}var Ga=/[&<>"]/,za=/[&<>"]/g,Va={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function Ka(i){return Va[i];}function Ge(i){return Ga.test(i)?i.replace(za,Ka):i;}var I={};I.blockquote_open=function(){return"<blockquote>\n";};I.blockquote_close=function(i,e){return"</blockquote>"+un(i,e);};I.code=function(i,e){return i[e].block?"<pre><code>"+Ge(i[e].content)+"</code></pre>"+un(i,e):"<code>"+Ge(i[e].content)+"</code>";};I.fence=function(i,e,t,n,s){var r=i[e],o="",a=t.langPrefix,c="",l,d,p;if(r.params){if(l=r.params.split(/\s+/g),d=l.join(" "),Ua(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=Ge(ln(As(d))),o=' class="'+a+c+'"';}return t.highlight?p=t.highlight.apply(t.highlight,[r.content].concat(l))||Ge(r.content):p=Ge(r.content),"<pre><code"+o+">"+p+"</code></pre>"+un(i,e);};I.fence_custom={};I.heading_open=function(i,e){return"<h"+i[e].hLevel+">";};I.heading_close=function(i,e){return"</h"+i[e].hLevel+">\n";};I.hr=function(i,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+un(i,e);};I.bullet_list_open=function(){return"<ul>\n";};I.bullet_list_close=function(i,e){return"</ul>"+un(i,e);};I.list_item_open=function(){return"<li>";};I.list_item_close=function(){return"</li>\n";};I.ordered_list_open=function(i,e){var t=i[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};I.ordered_list_close=function(i,e){return"</ol>"+un(i,e);};I.paragraph_open=function(i,e){return i[e].tight?"":"<p>";};I.paragraph_close=function(i,e){var t=!(i[e].tight&&e&&i[e-1].type==="inline"&&!i[e-1].content);return(i[e].tight?"":"</p>")+(t?un(i,e):"");};I.link_open=function(i,e,t){var n=i[e].title?' title="'+Ge(ln(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Ge(i[e].href)+'"'+n+s+">";};I.link_close=function(){return"</a>";};I.image=function(i,e,t){var n=' src="'+Ge(i[e].src)+'"',s=i[e].title?' title="'+Ge(ln(i[e].title))+'"':"",r=' alt="'+(i[e].alt?Ge(ln(As(i[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+r+s+o+">";};I.table_open=function(){return"<table>\n";};I.table_close=function(){return"</table>\n";};I.thead_open=function(){return"<thead>\n";};I.thead_close=function(){return"</thead>\n";};I.tbody_open=function(){return"<tbody>\n";};I.tbody_close=function(){return"</tbody>\n";};I.tr_open=function(){return"<tr>";};I.tr_close=function(){return"</tr>\n";};I.th_open=function(i,e){var t=i[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.th_close=function(){return"</th>";};I.td_open=function(i,e){var t=i[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.td_close=function(){return"</td>";};I.strong_open=function(){return"<strong>";};I.strong_close=function(){return"</strong>";};I.em_open=function(){return"<em>";};I.em_close=function(){return"</em>";};I.del_open=function(){return"<del>";};I.del_close=function(){return"</del>";};I.ins_open=function(){return"<ins>";};I.ins_close=function(){return"</ins>";};I.mark_open=function(){return"<mark>";};I.mark_close=function(){return"</mark>";};I.sub=function(i,e){return"<sub>"+Ge(i[e].content)+"</sub>";};I.sup=function(i,e){return"<sup>"+Ge(i[e].content)+"</sup>";};I.hardbreak=function(i,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};I.softbreak=function(i,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};I.text=function(i,e){return Ge(i[e].content);};I.htmlblock=function(i,e){return i[e].content;};I.htmltag=function(i,e){return i[e].content;};I.abbr_open=function(i,e){return'<abbr title="'+Ge(ln(i[e].title))+'">';};I.abbr_close=function(){return"</abbr>";};I.footnote_ref=function(i,e){var t=Number(i[e].id+1).toString(),n="fnref"+t;return i[e].subId>0&&(n+=":"+i[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+n+'">['+t+"]</a></sup>";};I.footnote_block_open=function(i,e,t){var n=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return n+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};I.footnote_block_close=function(){return"</ol>\n</section>\n";};I.footnote_open=function(i,e){var t=Number(i[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};I.footnote_close=function(){return"</li>\n";};I.footnote_anchor=function(i,e){var t=Number(i[e].id+1).toString(),n="fnref"+t;return i[e].subId>0&&(n+=":"+i[e].subId),' <a href="#'+n+'" class="footnote-backref">↩</a>';};I.dl_open=function(){return"<dl>\n";};I.dt_open=function(){return"<dt>";};I.dd_open=function(){return"<dd>";};I.dl_close=function(){return"</dl>\n";};I.dt_close=function(){return"</dt>\n";};I.dd_close=function(){return"</dd>\n";};function zo(i,e){return++e>=i.length-2?e:i[e].type==="paragraph_open"&&i[e].tight&&i[e+1].type==="inline"&&i[e+1].content.length===0&&i[e+2].type==="paragraph_close"&&i[e+2].tight?zo(i,e+2):e;}var un=I.getBreak=function(e,t){return t=zo(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function hr(){this.rules=qo({},I),this.getBreak=I.getBreak;}hr.prototype.renderInline=function(i,e,t){for(var n=this.rules,s=i.length,r=0,o="";s--;)o+=n[i[r].type](i,r++,e,t,this);return o;};hr.prototype.render=function(i,e,t){for(var n=this.rules,s=i.length,r=-1,o="";++r<s;)i[r].type==="inline"?o+=this.renderInline(i[r].children,e,t):o+=n[i[r].type](i,r,e,t,this);return o;};function Ye(){this.__rules__=[],this.__cache__=null;}Ye.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};Ye.prototype.__compile__=function(){var i=this,e=[""];i.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(n){e.indexOf(n)<0&&e.push(n);});}),i.__cache__={},e.forEach(function(t){i.__cache__[t]=[],i.__rules__.forEach(function(n){n.enabled&&(t&&n.alt.indexOf(t)<0||i.__cache__[t].push(n.fn));});});};Ye.prototype.at=function(i,e,t){var n=this.__find__(i),s=t||{};if(n===-1)throw new Error("Parser rule not found: "+i);this.__rules__[n].fn=e,this.__rules__[n].alt=s.alt||[],this.__cache__=null;};Ye.prototype.before=function(i,e,t,n){var s=this.__find__(i),r=n||{};if(s===-1)throw new Error("Parser rule not found: "+i);this.__rules__.splice(s,0,{name:e,enabled:!0,fn:t,alt:r.alt||[]}),this.__cache__=null;};Ye.prototype.after=function(i,e,t,n){var s=this.__find__(i),r=n||{};if(s===-1)throw new Error("Parser rule not found: "+i);this.__rules__.splice(s+1,0,{name:e,enabled:!0,fn:t,alt:r.alt||[]}),this.__cache__=null;};Ye.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};Ye.prototype.enable=function(i,e){i=Array.isArray(i)?i:[i],e&&this.__rules__.forEach(function(t){t.enabled=!1;}),i.forEach(function(t){var n=this.__find__(t);if(n<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[n].enabled=!0;},this),this.__cache__=null;};Ye.prototype.disable=function(i){i=Array.isArray(i)?i:[i],i.forEach(function(e){var t=this.__find__(e);if(t<0)throw new Error("Rules manager: invalid rule name "+e);this.__rules__[t].enabled=!1;},this),this.__cache__=null;};Ye.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function Wa(i){i.inlineMode?i.tokens.push({type:"inline",content:i.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):i.block.parse(i.src,i.options,i.env,i.tokens);}function pn(i,e,t,n,s){this.src=i,this.env=n,this.options=t,this.parser=e,this.tokens=s,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0;}pn.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};pn.prototype.push=function(i){this.pending&&this.pushPending(),this.tokens.push(i),this.pendingLevel=this.level;};pn.prototype.cacheSet=function(i,e){for(var t=this.cache.length;t<=i;t++)this.cache.push(0);this.cache[i]=e;};pn.prototype.cacheGet=function(i){return i<this.cache.length?this.cache[i]:0;};function ws(i,e){var t,n,s,r=-1,o=i.posMax,a=i.pos,c=i.isInLabel;if(i.isInLabel)return-1;if(i.labelUnmatchedScopes)return i.labelUnmatchedScopes--,-1;for(i.pos=e+1,i.isInLabel=!0,t=1;i.pos<o;){if(s=i.src.charCodeAt(i.pos),s===91)t++;else if(s===93&&(t--,t===0)){n=!0;break;}i.parser.skipToken(i);}return n?(r=i.pos,i.labelUnmatchedScopes=0):i.labelUnmatchedScopes=t-1,i.pos=a,i.isInLabel=c,r;}function Xa(i,e,t,n){var s,r,o,a,c,l;if(i.charCodeAt(0)!==42||i.charCodeAt(1)!==91||i.indexOf("]:")===-1||(s=new pn(i,e,t,n,[]),r=ws(s,1),r<0||i.charCodeAt(r+1)!==58))return-1;for(a=s.posMax,o=r+2;o<a&&s.src.charCodeAt(o)!==10;o++);return c=i.slice(2,r),l=i.slice(r+2,o).trim(),l.length===0?-1:(n.abbreviations||(n.abbreviations={}),_typeof(n.abbreviations[":"+c])>"u"&&(n.abbreviations[":"+c]=l),o);}function Za(i){var e=i.tokens,t,n,s,r;if(!i.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(r=Xa(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function $i(i){var e=ln(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function Vo(i,e){var t,n,s,r=e,o=i.posMax;if(i.src.charCodeAt(e)===60){for(e++;e<o;){if(t=i.src.charCodeAt(e),t===10)return!1;if(t===62)return s=$i(As(i.src.slice(r+1,e))),i.parser.validateLink(s)?(i.pos=e+1,i.linkContent=s,!0):!1;if(t===92&&e+1<o){e+=2;continue;}e++;}return!1;}for(n=0;e<o&&(t=i.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue;}if(t===40&&(n++,n>1)||t===41&&(n--,n<0))break;e++;}return r===e||(s=As(i.src.slice(r,e)),!i.parser.validateLink(s))?!1:(i.linkContent=s,i.pos=e,!0);}function Ko(i,e){var t,n=e,s=i.posMax,r=i.src.charCodeAt(e);if(r!==34&&r!==39&&r!==40)return!1;for(e++,r===40&&(r=41);e<s;){if(t=i.src.charCodeAt(e),t===r)return i.pos=e+1,i.linkContent=As(i.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function Wo(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function Ya(i,e,t,n){var s,r,o,a,c,l,d,p,u;if(i.charCodeAt(0)!==91||i.indexOf("]:")===-1||(s=new pn(i,e,t,n,[]),r=ws(s,0),r<0||i.charCodeAt(r+1)!==58))return-1;for(a=s.posMax,o=r+2;o<a&&(c=s.src.charCodeAt(o),!(c!==32&&c!==10));o++);if(!Vo(s,o))return-1;for(d=s.linkContent,o=s.pos,l=o,o=o+1;o<a&&(c=s.src.charCodeAt(o),!(c!==32&&c!==10));o++);for(o<a&&l!==o&&Ko(s,o)?(p=s.linkContent,o=s.pos):(p="",o=l);o<a&&s.src.charCodeAt(o)===32;)o++;return o<a&&s.src.charCodeAt(o)!==10?-1:(u=Wo(i.slice(1,r)),_typeof(n.references[u])>"u"&&(n.references[u]={title:p,href:d}),o);}function Ja(i){var e=i.tokens,t,n,s,r;if(i.env.references=i.env.references||{},!i.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(r=Ya(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Qa(i){var e=i.tokens,t,n,s;for(n=0,s=e.length;n<s;n++)t=e[n],t.type==="inline"&&i.inline.parse(t.content,i.options,i.env,t.children);}function ec(i){var e,t,n,s,r,o,a,c,l,d=0,p=!1,u={};if(i.env.footnotes&&(i.tokens=i.tokens.filter(function(g){return g.type==="footnote_reference_open"?(p=!0,c=[],l=g.label,!1):g.type==="footnote_reference_close"?(p=!1,u[":"+l]=c,!1):(p&&c.push(g),!p);}),!!i.env.footnotes.list)){for(o=i.env.footnotes.list,i.tokens.push({type:"footnote_block_open",level:d++}),e=0,t=o.length;e<t;e++){for(i.tokens.push({type:"footnote_open",id:e,level:d++}),o[e].tokens?(a=[],a.push({type:"paragraph_open",tight:!1,level:d++}),a.push({type:"inline",content:"",level:d,children:o[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--d})):o[e].label&&(a=u[":"+o[e].label]),i.tokens=i.tokens.concat(a),i.tokens[i.tokens.length-1].type==="paragraph_close"?r=i.tokens.pop():r=null,s=o[e].count>0?o[e].count:1,n=0;n<s;n++)i.tokens.push({type:"footnote_anchor",id:e,subId:n,level:d});r&&i.tokens.push(r),i.tokens.push({type:"footnote_close",level:--d});}i.tokens.push({type:"footnote_block_close",level:--d});}}var Gr=" \n()[]'\".,!?-";function Li(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function tc(i){var e,t,n,s,r,o,a,c,l,d,p,u,g=i.tokens;if(i.env.abbreviations){for(i.env.abbrRegExp||(u="(^|["+Gr.split("").map(Li).join("")+"])("+Object.keys(i.env.abbreviations).map(function(y){return y.substr(1);}).sort(function(y,_){return _.length-y.length;}).map(Li).join("|")+")($|["+Gr.split("").map(Li).join("")+"])",i.env.abbrRegExp=new RegExp(u,"g")),d=i.env.abbrRegExp,t=0,n=g.length;t<n;t++)if(g[t].type==="inline"){for(s=g[t].children,e=s.length-1;e>=0;e--)if(r=s[e],r.type==="text"){for(c=0,o=r.content,d.lastIndex=0,l=r.level,a=[];p=d.exec(o);)d.lastIndex>c&&a.push({type:"text",content:o.slice(c,p.index+p[1].length),level:l}),a.push({type:"abbr_open",title:i.env.abbreviations[":"+p[2]],level:l++}),a.push({type:"text",content:p[2],level:l}),a.push({type:"abbr_close",level:--l}),c=d.lastIndex-p[3].length;a.length&&(c<o.length&&a.push({type:"text",content:o.slice(c),level:l}),g[t].children=s=[].concat(s.slice(0,e),a,s.slice(e+1)));}}}}var nc=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,sc=/\((c|tm|r|p)\)/ig,ic={c:"©",r:"®",p:"§",tm:"™"};function rc(i){return i.indexOf("(")<0?i:i.replace(sc,function(e,t){return ic[t.toLowerCase()];});}function oc(i){var e,t,n,s,r;if(i.options.typographer){for(r=i.tokens.length-1;r>=0;r--)if(i.tokens[r].type==="inline")for(s=i.tokens[r].children,e=s.length-1;e>=0;e--)t=s[e],t.type==="text"&&(n=t.content,n=rc(n),nc.test(n)&&(n=n.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=n);}}var ac=/['"]/,zr=/['"]/g,cc=/[-\s()\[\]]/,Vr="’";function Kr(i,e){return e<0||e>=i.length?!1:!cc.test(i[e]);}function bn(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function lc(i){var e,t,n,s,r,o,a,c,l,d,p,u,g,y,_,S,M;if(i.options.typographer){for(M=[],_=i.tokens.length-1;_>=0;_--)if(i.tokens[_].type==="inline"){for(S=i.tokens[_].children,M.length=0,e=0;e<S.length;e++)if(t=S[e],!(t.type!=="text"||ac.test(t.text))){for(a=S[e].level,g=M.length-1;g>=0&&!(M[g].level<=a);g--);M.length=g+1,n=t.content,r=0,o=n.length;e:for(;r<o&&(zr.lastIndex=r,s=zr.exec(n),!!s);){if(c=!Kr(n,s.index-1),r=s.index+1,y=s[0]==="'",l=!Kr(n,r),!l&&!c){y&&(t.content=bn(t.content,s.index,Vr));continue;}if(p=!l,u=!c,u){for(g=M.length-1;g>=0&&(d=M[g],!(M[g].level<a));g--)if(d.single===y&&M[g].level===a){d=M[g],y?(S[d.token].content=bn(S[d.token].content,d.pos,i.options.quotes[2]),t.content=bn(t.content,s.index,i.options.quotes[3])):(S[d.token].content=bn(S[d.token].content,d.pos,i.options.quotes[0]),t.content=bn(t.content,s.index,i.options.quotes[1])),M.length=g;continue e;}}p?M.push({token:e,pos:s.index,single:y,level:a}):u&&y&&(t.content=bn(t.content,s.index,Vr));}}}}}var Oi=[["block",Wa],["abbr",Za],["references",Ja],["inline",Qa],["footnote_tail",ec],["abbr2",tc],["replacements",oc],["smartquotes",lc]];function Xo(){this.options={},this.ruler=new Ye();for(var i=0;i<Oi.length;i++)this.ruler.push(Oi[i][0],Oi[i][1]);}Xo.prototype.process=function(i){var e,t,n;for(n=this.ruler.getRules(""),e=0,t=n.length;e<t;e++)n[e](i);};function fn(i,e,t,n,s){var r,o,a,c,l,d,p;for(this.src=i,this.parser=e,this.options=t,this.env=n,this.tokens=s,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,d=0,p=!1,a=c=d=0,l=o.length;c<l;c++){if(r=o.charCodeAt(c),!p)if(r===32){d++;continue;}else p=!0;(r===10||c===l-1)&&(r!==10&&c++,this.bMarks.push(a),this.eMarks.push(c),this.tShift.push(d),p=!1,d=0,a=c+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}fn.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};fn.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};fn.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};fn.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};fn.prototype.skipCharsBack=function(e,t,n){if(e<=n)return e;for(;e>n;)if(t!==this.src.charCodeAt(--e))return e+1;return e;};fn.prototype.getLines=function(e,t,n,s){var r,o,a,c,l,d=e;if(e>=t)return"";if(d+1===t)return o=this.bMarks[d]+Math.min(this.tShift[d],n),a=s?this.eMarks[d]+1:this.eMarks[d],this.src.slice(o,a);for(c=new Array(t-e),r=0;d<t;d++,r++)l=this.tShift[d],l>n&&(l=n),l<0&&(l=0),o=this.bMarks[d]+l,d+1<t||s?a=this.eMarks[d]+1:a=this.eMarks[d],c[r]=this.src.slice(o,a);return c.join("");};function dc(i,e,t){var n,s;if(i.tShift[e]-i.blkIndent<4)return!1;for(s=n=e+1;n<t;){if(i.isEmpty(n)){n++;continue;}if(i.tShift[n]-i.blkIndent>=4){n++,s=n;continue;}break;}return i.line=n,i.tokens.push({type:"code",content:i.getLines(e,s,4+i.blkIndent,!0),block:!0,lines:[e,i.line],level:i.level}),!0;}function hc(i,e,t,n){var s,r,o,a,c,l=!1,d=i.bMarks[e]+i.tShift[e],p=i.eMarks[e];if(d+3>p||(s=i.src.charCodeAt(d),s!==126&&s!==96)||(c=d,d=i.skipChars(d,s),r=d-c,r<3)||(o=i.src.slice(d,p).trim(),o.indexOf("`")>=0))return!1;if(n)return!0;for(a=e;a++,!(a>=t||(d=c=i.bMarks[a]+i.tShift[a],p=i.eMarks[a],d<p&&i.tShift[a]<i.blkIndent));)if(i.src.charCodeAt(d)===s&&!(i.tShift[a]-i.blkIndent>=4)&&(d=i.skipChars(d,s),!(d-c<r)&&(d=i.skipSpaces(d),!(d<p)))){l=!0;break;}return r=i.tShift[e],i.line=a+(l?1:0),i.tokens.push({type:"fence",params:o,content:i.getLines(e+1,a,r,!0),lines:[e,i.line],level:i.level}),!0;}function uc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_=i.bMarks[e]+i.tShift[e],S=i.eMarks[e];if(_>S||i.src.charCodeAt(_++)!==62||i.level>=i.options.maxNesting)return!1;if(n)return!0;for(i.src.charCodeAt(_)===32&&_++,c=i.blkIndent,i.blkIndent=0,a=[i.bMarks[e]],i.bMarks[e]=_,_=_<S?i.skipSpaces(_):_,r=_>=S,o=[i.tShift[e]],i.tShift[e]=_-i.bMarks[e],p=i.parser.ruler.getRules("blockquote"),s=e+1;s<t&&(_=i.bMarks[s]+i.tShift[s],S=i.eMarks[s],!(_>=S));s++){if(i.src.charCodeAt(_++)===62){i.src.charCodeAt(_)===32&&_++,a.push(i.bMarks[s]),i.bMarks[s]=_,_=_<S?i.skipSpaces(_):_,r=_>=S,o.push(i.tShift[s]),i.tShift[s]=_-i.bMarks[s];continue;}if(r)break;for(y=!1,u=0,g=p.length;u<g;u++)if(p[u](i,s,t,!0)){y=!0;break;}if(y)break;a.push(i.bMarks[s]),o.push(i.tShift[s]),i.tShift[s]=-1337;}for(l=i.parentType,i.parentType="blockquote",i.tokens.push({type:"blockquote_open",lines:d=[e,0],level:i.level++}),i.parser.tokenize(i,e,s),i.tokens.push({type:"blockquote_close",level:--i.level}),i.parentType=l,d[1]=i.line,u=0;u<o.length;u++)i.bMarks[u+e]=a[u],i.tShift[u+e]=o[u];return i.blkIndent=c,!0;}function pc(i,e,t,n){var s,r,o,a=i.bMarks[e],c=i.eMarks[e];if(a+=i.tShift[e],a>c||(s=i.src.charCodeAt(a++),s!==42&&s!==45&&s!==95))return!1;for(r=1;a<c;){if(o=i.src.charCodeAt(a++),o!==s&&o!==32)return!1;o===s&&r++;}return r<3?!1:(n||(i.line=e+1,i.tokens.push({type:"hr",lines:[e,i.line],level:i.level})),!0);}function Wr(i,e){var t,n,s;return n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e],n>=s||(t=i.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<s&&i.src.charCodeAt(n)!==32?-1:n;}function Xr(i,e){var t,n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e];if(n+1>=s||(t=i.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=s)return-1;if(t=i.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return n<s&&i.src.charCodeAt(n)!==32?-1:n;}function fc(i,e){var t,n,s=i.level+2;for(t=e+2,n=i.tokens.length-2;t<n;t++)i.tokens[t].level===s&&i.tokens[t].type==="paragraph_open"&&(i.tokens[t+2].tight=!0,i.tokens[t].tight=!0,t+=2);}function mc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_,S,M,K,ie,re,Re,Lt=!0,Ot,ze,Or,Mi;if((p=Xr(i,e))>=0)S=!0;else if((p=Wr(i,e))>=0)S=!1;else return!1;if(i.level>=i.options.maxNesting)return!1;if(_=i.src.charCodeAt(p-1),n)return!0;for(K=i.tokens.length,S?(d=i.bMarks[e]+i.tShift[e],y=Number(i.src.substr(d,p-d-1)),i.tokens.push({type:"ordered_list_open",order:y,lines:re=[e,0],level:i.level++})):i.tokens.push({type:"bullet_list_open",lines:re=[e,0],level:i.level++}),s=e,ie=!1,Ot=i.parser.ruler.getRules("list");s<t&&(M=i.skipSpaces(p),u=i.eMarks[s],M>=u?g=1:g=M-p,g>4&&(g=1),g<1&&(g=1),r=p-i.bMarks[s]+g,i.tokens.push({type:"list_item_open",lines:Re=[e,0],level:i.level++}),a=i.blkIndent,c=i.tight,o=i.tShift[e],l=i.parentType,i.tShift[e]=M-i.bMarks[e],i.blkIndent=r,i.tight=!0,i.parentType="list",i.parser.tokenize(i,e,t,!0),(!i.tight||ie)&&(Lt=!1),ie=i.line-e>1&&i.isEmpty(i.line-1),i.blkIndent=a,i.tShift[e]=o,i.tight=c,i.parentType=l,i.tokens.push({type:"list_item_close",level:--i.level}),s=e=i.line,Re[1]=s,M=i.bMarks[e],!(s>=t||i.isEmpty(s)||i.tShift[s]<i.blkIndent));){for(Mi=!1,ze=0,Or=Ot.length;ze<Or;ze++)if(Ot[ze](i,s,t,!0)){Mi=!0;break;}if(Mi)break;if(S){if(p=Xr(i,s),p<0)break;}else if(p=Wr(i,s),p<0)break;if(_!==i.src.charCodeAt(p-1))break;}return i.tokens.push({type:S?"ordered_list_close":"bullet_list_close",level:--i.level}),re[1]=s,i.line=s,Lt&&fc(i,K),!0;}function gc(i,e,t,n){var s,r,o,a,c,l=i.bMarks[e]+i.tShift[e],d=i.eMarks[e];if(l+4>d||i.src.charCodeAt(l)!==91||i.src.charCodeAt(l+1)!==94||i.level>=i.options.maxNesting)return!1;for(a=l+2;a<d;a++){if(i.src.charCodeAt(a)===32)return!1;if(i.src.charCodeAt(a)===93)break;}return a===l+2||a+1>=d||i.src.charCodeAt(++a)!==58?!1:(n||(a++,i.env.footnotes||(i.env.footnotes={}),i.env.footnotes.refs||(i.env.footnotes.refs={}),c=i.src.slice(l+2,a-2),i.env.footnotes.refs[":"+c]=-1,i.tokens.push({type:"footnote_reference_open",label:c,level:i.level++}),s=i.bMarks[e],r=i.tShift[e],o=i.parentType,i.tShift[e]=i.skipSpaces(a)-a,i.bMarks[e]=a,i.blkIndent+=4,i.parentType="footnote",i.tShift[e]<i.blkIndent&&(i.tShift[e]+=i.blkIndent,i.bMarks[e]-=i.blkIndent),i.parser.tokenize(i,e,t,!0),i.parentType=o,i.blkIndent-=4,i.tShift[e]=r,i.bMarks[e]=s,i.tokens.push({type:"footnote_reference_close",level:--i.level})),!0);}function bc(i,e,t,n){var s,r,o,a=i.bMarks[e]+i.tShift[e],c=i.eMarks[e];if(a>=c||(s=i.src.charCodeAt(a),s!==35||a>=c))return!1;for(r=1,s=i.src.charCodeAt(++a);s===35&&a<c&&r<=6;)r++,s=i.src.charCodeAt(++a);return r>6||a<c&&s!==32?!1:(n||(c=i.skipCharsBack(c,32,a),o=i.skipCharsBack(c,35,a),o>a&&i.src.charCodeAt(o-1)===32&&(c=o),i.line=e+1,i.tokens.push({type:"heading_open",hLevel:r,lines:[e,i.line],level:i.level}),a<c&&i.tokens.push({type:"inline",content:i.src.slice(a,c).trim(),level:i.level+1,lines:[e,i.line],children:[]}),i.tokens.push({type:"heading_close",hLevel:r,level:i.level})),!0);}function yc(i,e,t){var n,s,r,o=e+1;return o>=t||i.tShift[o]<i.blkIndent||i.tShift[o]-i.blkIndent>3||(s=i.bMarks[o]+i.tShift[o],r=i.eMarks[o],s>=r)||(n=i.src.charCodeAt(s),n!==45&&n!==61)||(s=i.skipChars(s,n),s=i.skipSpaces(s),s<r)?!1:(s=i.bMarks[e]+i.tShift[e],i.line=o+1,i.tokens.push({type:"heading_open",hLevel:n===61?1:2,lines:[e,i.line],level:i.level}),i.tokens.push({type:"inline",content:i.src.slice(s,i.eMarks[e]).trim(),level:i.level+1,lines:[e,i.line-1],children:[]}),i.tokens.push({type:"heading_close",hLevel:n===61?1:2,level:i.level}),!0);}var Zo={};["article","aside","button","blockquote","body","canvas","caption","col","colgroup","dd","div","dl","dt","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","iframe","li","map","object","ol","output","p","pre","progress","script","section","style","table","tbody","td","textarea","tfoot","th","tr","thead","ul","video"].forEach(function(i){Zo[i]=!0;});var _c=/^<([a-zA-Z]{1,15})[\s\/>]/,Ec=/^<\/([a-zA-Z]{1,15})[\s>]/;function vc(i){var e=i|32;return e>=97&&e<=122;}function Sc(i,e,t,n){var s,r,o,a=i.bMarks[e],c=i.eMarks[e],l=i.tShift[e];if(a+=l,!i.options.html||l>3||a+2>=c||i.src.charCodeAt(a)!==60)return!1;if(s=i.src.charCodeAt(a+1),s===33||s===63){if(n)return!0;}else if(s===47||vc(s)){if(s===47){if(r=i.src.slice(a,c).match(Ec),!r)return!1;}else if(r=i.src.slice(a,c).match(_c),!r)return!1;if(Zo[r[1].toLowerCase()]!==!0)return!1;if(n)return!0;}else return!1;for(o=e+1;o<i.lineMax&&!i.isEmpty(o);)o++;return i.line=o,i.tokens.push({type:"htmlblock",level:i.level,lines:[e,i.line],content:i.getLines(e,o,0,!0)}),!0;}function Ni(i,e){var t=i.bMarks[e]+i.blkIndent,n=i.eMarks[e];return i.src.substr(t,n-t);}function xc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y;if(e+2>t||(c=e+1,i.tShift[c]<i.blkIndent)||(o=i.bMarks[c]+i.tShift[c],o>=i.eMarks[c])||(s=i.src.charCodeAt(o),s!==124&&s!==45&&s!==58)||(r=Ni(i,e+1),!/^[-:| ]+$/.test(r))||(l=r.split("|"),l<=2))return!1;for(p=[],a=0;a<l.length;a++){if(u=l[a].trim(),!u){if(a===0||a===l.length-1)continue;return!1;}if(!/^:?-+:?$/.test(u))return!1;u.charCodeAt(u.length-1)===58?p.push(u.charCodeAt(0)===58?"center":"right"):u.charCodeAt(0)===58?p.push("left"):p.push("");}if(r=Ni(i,e).trim(),r.indexOf("|")===-1||(l=r.replace(/^\||\|$/g,"").split("|"),p.length!==l.length))return!1;if(n)return!0;for(i.tokens.push({type:"table_open",lines:g=[e,0],level:i.level++}),i.tokens.push({type:"thead_open",lines:[e,e+1],level:i.level++}),i.tokens.push({type:"tr_open",lines:[e,e+1],level:i.level++}),a=0;a<l.length;a++)i.tokens.push({type:"th_open",align:p[a],lines:[e,e+1],level:i.level++}),i.tokens.push({type:"inline",content:l[a].trim(),lines:[e,e+1],level:i.level,children:[]}),i.tokens.push({type:"th_close",level:--i.level});for(i.tokens.push({type:"tr_close",level:--i.level}),i.tokens.push({type:"thead_close",level:--i.level}),i.tokens.push({type:"tbody_open",lines:y=[e+2,0],level:i.level++}),c=e+2;c<t&&!(i.tShift[c]<i.blkIndent||(r=Ni(i,c).trim(),r.indexOf("|")===-1));c++){for(l=r.replace(/^\||\|$/g,"").split("|"),i.tokens.push({type:"tr_open",level:i.level++}),a=0;a<l.length;a++)i.tokens.push({type:"td_open",align:p[a],level:i.level++}),d=l[a].substring(l[a].charCodeAt(0)===124?1:0,l[a].charCodeAt(l[a].length-1)===124?l[a].length-1:l[a].length).trim(),i.tokens.push({type:"inline",content:d,level:i.level,children:[]}),i.tokens.push({type:"td_close",level:--i.level});i.tokens.push({type:"tr_close",level:--i.level});}return i.tokens.push({type:"tbody_close",level:--i.level}),i.tokens.push({type:"table_close",level:--i.level}),g[1]=y[1]=c,i.line=c,!0;}function Us(i,e){var t,n,s=i.bMarks[e]+i.tShift[e],r=i.eMarks[e];return s>=r||(n=i.src.charCodeAt(s++),n!==126&&n!==58)||(t=i.skipSpaces(s),s===t)||t>=r?-1:t;}function Ac(i,e){var t,n,s=i.level+2;for(t=e+2,n=i.tokens.length-2;t<n;t++)i.tokens[t].level===s&&i.tokens[t].type==="paragraph_open"&&(i.tokens[t+2].tight=!0,i.tokens[t].tight=!0,t+=2);}function wc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_,S,M;if(n)return i.ddIndent<0?!1:Us(i,e)>=0;if(d=e+1,i.isEmpty(d)&&++d>t||i.tShift[d]<i.blkIndent||(s=Us(i,d),s<0)||i.level>=i.options.maxNesting)return!1;l=i.tokens.length,i.tokens.push({type:"dl_open",lines:c=[e,0],level:i.level++}),o=e,r=d;e:for(;;){for(M=!0,S=!1,i.tokens.push({type:"dt_open",lines:[o,o],level:i.level++}),i.tokens.push({type:"inline",content:i.getLines(o,o+1,i.blkIndent,!1).trim(),level:i.level+1,lines:[o,o],children:[]}),i.tokens.push({type:"dt_close",level:--i.level});;){if(i.tokens.push({type:"dd_open",lines:a=[d,0],level:i.level++}),_=i.tight,u=i.ddIndent,p=i.blkIndent,y=i.tShift[r],g=i.parentType,i.blkIndent=i.ddIndent=i.tShift[r]+2,i.tShift[r]=s-i.bMarks[r],i.tight=!0,i.parentType="deflist",i.parser.tokenize(i,r,t,!0),(!i.tight||S)&&(M=!1),S=i.line-r>1&&i.isEmpty(i.line-1),i.tShift[r]=y,i.tight=_,i.parentType=g,i.blkIndent=p,i.ddIndent=u,i.tokens.push({type:"dd_close",level:--i.level}),a[1]=d=i.line,d>=t||i.tShift[d]<i.blkIndent)break e;if(s=Us(i,d),s<0)break;r=d;}if(d>=t||(o=d,i.isEmpty(o))||i.tShift[o]<i.blkIndent||(r=o+1,r>=t)||(i.isEmpty(r)&&r++,r>=t)||i.tShift[r]<i.blkIndent||(s=Us(i,r),s<0))break;}return i.tokens.push({type:"dl_close",level:--i.level}),c[1]=d,i.line=d,M&&Ac(i,l),!0;}function Cc(i,e){var t,n,s,r,o,a=e+1,c;if(t=i.lineMax,a<t&&!i.isEmpty(a)){for(c=i.parser.ruler.getRules("paragraph");a<t&&!i.isEmpty(a);a++)if(!(i.tShift[a]-i.blkIndent>3)){for(s=!1,r=0,o=c.length;r<o;r++)if(c[r](i,a,t,!0)){s=!0;break;}if(s)break;}}return n=i.getLines(e,a,i.blkIndent,!1).trim(),i.line=a,n.length&&(i.tokens.push({type:"paragraph_open",tight:!1,lines:[e,i.line],level:i.level}),i.tokens.push({type:"inline",content:n,level:i.level+1,lines:[e,i.line],children:[]}),i.tokens.push({type:"paragraph_close",tight:!1,level:i.level})),!0;}var Hs=[["code",dc],["fences",hc,["paragraph","blockquote","list"]],["blockquote",uc,["paragraph","blockquote","list"]],["hr",pc,["paragraph","blockquote","list"]],["list",mc,["paragraph","blockquote"]],["footnote",gc,["paragraph"]],["heading",bc,["paragraph","blockquote"]],["lheading",yc],["htmlblock",Sc,["paragraph","blockquote"]],["table",xc,["paragraph"]],["deflist",wc,["paragraph"]],["paragraph",Cc]];function ur(){this.ruler=new Ye();for(var i=0;i<Hs.length;i++)this.ruler.push(Hs[i][0],Hs[i][1],{alt:(Hs[i][2]||[]).slice()});}ur.prototype.tokenize=function(i,e,t){for(var n=this.ruler.getRules(""),s=n.length,r=e,o=!1,a,c;r<t&&(i.line=r=i.skipEmptyLines(r),!(r>=t||i.tShift[r]<i.blkIndent));){for(c=0;c<s&&(a=n[c](i,r,t,!1),!a);c++);if(i.tight=!o,i.isEmpty(i.line-1)&&(o=!0),r=i.line,r<t&&i.isEmpty(r)){if(o=!0,r++,r<t&&i.parentType==="list"&&i.isEmpty(r))break;i.line=r;}}};var Tc=/[\n\t]/g,Rc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,Ic=/\u00a0/g;ur.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(Ic," "),i=i.replace(Rc,"\n"),i.indexOf(" ")>=0&&(i=i.replace(Tc,function(a,c){var l;return i.charCodeAt(c)===10?(r=c+1,o=0,a):(l=" ".slice((c-r-o)%4),o=c-r+1,l);})),s=new fn(i,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function Mc(i){switch(i){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1;}}function kc(i,e){for(var t=i.pos;t<i.posMax&&!Mc(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function Pc(i,e){var t,n,s=i.pos;if(i.src.charCodeAt(s)!==10)return!1;if(t=i.pending.length-1,n=i.posMax,!e)if(t>=0&&i.pending.charCodeAt(t)===32){if(t>=1&&i.pending.charCodeAt(t-1)===32){for(var r=t-2;r>=0;r--)if(i.pending.charCodeAt(r)!==32){i.pending=i.pending.substring(0,r+1);break;}i.push({type:"hardbreak",level:i.level});}else i.pending=i.pending.slice(0,-1),i.push({type:"softbreak",level:i.level});}else i.push({type:"softbreak",level:i.level});for(s++;s<n&&i.src.charCodeAt(s)===32;)s++;return i.pos=s,!0;}var pr=[];for(var Zr=0;Zr<256;Zr++)pr.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){pr[i.charCodeAt(0)]=1;});function Lc(i,e){var t,n=i.pos,s=i.posMax;if(i.src.charCodeAt(n)!==92)return!1;if(n++,n<s){if(t=i.src.charCodeAt(n),t<256&&pr[t]!==0)return e||(i.pending+=i.src[n]),i.pos+=2,!0;if(t===10){for(e||i.push({type:"hardbreak",level:i.level}),n++;n<s&&i.src.charCodeAt(n)===32;)n++;return i.pos=n,!0;}}return e||(i.pending+="\\"),i.pos++,!0;}function Oc(i,e){var t,n,s,r,o,a=i.pos,c=i.src.charCodeAt(a);if(c!==96)return!1;for(t=a,a++,n=i.posMax;a<n&&i.src.charCodeAt(a)===96;)a++;for(s=i.src.slice(t,a),r=o=a;(r=i.src.indexOf("`",o))!==-1;){for(o=r+1;o<n&&i.src.charCodeAt(o)===96;)o++;if(o-r===s.length)return e||i.push({type:"code",content:i.src.slice(a,r).replace(/[ \n]+/g," ").trim(),block:!1,level:i.level}),i.pos=o,!0;}return e||(i.pending+=s),i.pos+=s.length,!0;}function Nc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==126||e||o+4>=r||i.src.charCodeAt(o+1)!==126||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===126)||c===126||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===126;)n++;if(n>o+3)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===126&&i.src.charCodeAt(i.pos+1)===126&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==126&&a!==126&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"del_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"del_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function Bc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==43||e||o+4>=r||i.src.charCodeAt(o+1)!==43||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===43)||c===43||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===43;)n++;if(n!==o+2)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===43&&i.src.charCodeAt(i.pos+1)===43&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==43&&a!==43&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"ins_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"ins_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function Dc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==61||e||o+4>=r||i.src.charCodeAt(o+1)!==61||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===61)||c===61||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===61;)n++;if(n!==o+2)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===61&&i.src.charCodeAt(i.pos+1)===61&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==61&&a!==61&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"mark_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"mark_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function Yr(i){return i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122;}function Jr(i,e){var t=e,n,s,r,o=!0,a=!0,c=i.posMax,l=i.src.charCodeAt(e);for(n=e>0?i.src.charCodeAt(e-1):-1;t<c&&i.src.charCodeAt(t)===l;)t++;return t>=c&&(o=!1),r=t-e,r>=4?o=a=!1:(s=t<c?i.src.charCodeAt(t):-1,(s===32||s===10)&&(o=!1),(n===32||n===10)&&(a=!1),l===95&&(Yr(n)&&(o=!1),Yr(s)&&(a=!1))),{can_open:o,can_close:a,delims:r};}function Fc(i,e){var t,n,s,r,o,a,c,l=i.posMax,d=i.pos,p=i.src.charCodeAt(d);if(p!==95&&p!==42||e)return!1;if(c=Jr(i,d),t=c.delims,!c.can_open)return i.pos+=t,e||(i.pending+=i.src.slice(d,i.pos)),!0;if(i.level>=i.options.maxNesting)return!1;for(i.pos=d+t,a=[t];i.pos<l;){if(i.src.charCodeAt(i.pos)===p){if(c=Jr(i,i.pos),n=c.delims,c.can_close){for(r=a.pop(),o=n;r!==o;){if(o<r){a.push(r-o);break;}if(o-=r,a.length===0)break;i.pos+=r,r=a.pop();}if(a.length===0){t=r,s=!0;break;}i.pos+=n;continue;}c.can_open&&a.push(n),i.pos+=n;continue;}i.parser.skipToken(i);}return s?(i.posMax=i.pos,i.pos=d+t,e||((t===2||t===3)&&i.push({type:"strong_open",level:i.level++}),(t===1||t===3)&&i.push({type:"em_open",level:i.level++}),i.parser.tokenize(i),(t===1||t===3)&&i.push({type:"em_close",level:--i.level}),(t===2||t===3)&&i.push({type:"strong_close",level:--i.level})),i.pos=i.posMax+t,i.posMax=l,!0):(i.pos=d,!1);}var Uc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Hc(i,e){var t,n,s=i.posMax,r=i.pos;if(i.src.charCodeAt(r)!==126||e||r+2>=s||i.level>=i.options.maxNesting)return!1;for(i.pos=r+1;i.pos<s;){if(i.src.charCodeAt(i.pos)===126){t=!0;break;}i.parser.skipToken(i);}return!t||r+1===i.pos||(n=i.src.slice(r+1,i.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(i.pos=r,!1):(i.posMax=i.pos,i.pos=r+1,e||i.push({type:"sub",level:i.level,content:n.replace(Uc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var jc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function $c(i,e){var t,n,s=i.posMax,r=i.pos;if(i.src.charCodeAt(r)!==94||e||r+2>=s||i.level>=i.options.maxNesting)return!1;for(i.pos=r+1;i.pos<s;){if(i.src.charCodeAt(i.pos)===94){t=!0;break;}i.parser.skipToken(i);}return!t||r+1===i.pos||(n=i.src.slice(r+1,i.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(i.pos=r,!1):(i.posMax=i.pos,i.pos=r+1,e||i.push({type:"sup",level:i.level,content:n.replace(jc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function qc(i,e){var t,n,s,r,o,a,c,l,d=!1,p=i.pos,u=i.posMax,g=i.pos,y=i.src.charCodeAt(g);if(y===33&&(d=!0,y=i.src.charCodeAt(++g)),y!==91||i.level>=i.options.maxNesting||(t=g+1,n=ws(i,g),n<0))return!1;if(a=n+1,a<u&&i.src.charCodeAt(a)===40){for(a++;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a>=u)return!1;for(g=a,Vo(i,a)?(r=i.linkContent,a=i.pos):r="",g=a;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<u&&g!==a&&Ko(i,a))for(o=i.linkContent,a=i.pos;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);else o="";if(a>=u||i.src.charCodeAt(a)!==41)return i.pos=p,!1;a++;}else{if(i.linkLevel>0)return!1;for(;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<u&&i.src.charCodeAt(a)===91&&(g=a+1,a=ws(i,a),a>=0?s=i.src.slice(g,a++):a=g-1),s||(_typeof(s)>"u"&&(a=n+1),s=i.src.slice(t,n)),c=i.env.references[Wo(s)],!c)return i.pos=p,!1;r=c.href,o=c.title;}return e||(i.pos=t,i.posMax=n,d?i.push({type:"image",src:r,title:o,alt:i.src.substr(t,n-t),level:i.level}):(i.push({type:"link_open",href:r,title:o,level:i.level++}),i.linkLevel++,i.parser.tokenize(i),i.linkLevel--,i.push({type:"link_close",level:--i.level}))),i.pos=a,i.posMax=u,!0;}function Gc(i,e){var t,n,s,r,o=i.posMax,a=i.pos;return a+2>=o||i.src.charCodeAt(a)!==94||i.src.charCodeAt(a+1)!==91||i.level>=i.options.maxNesting||(t=a+2,n=ws(i,a+1),n<0)?!1:(e||(i.env.footnotes||(i.env.footnotes={}),i.env.footnotes.list||(i.env.footnotes.list=[]),s=i.env.footnotes.list.length,i.pos=t,i.posMax=n,i.push({type:"footnote_ref",id:s,level:i.level}),i.linkLevel++,r=i.tokens.length,i.parser.tokenize(i),i.env.footnotes.list[s]={tokens:i.tokens.splice(r)},i.linkLevel--),i.pos=n+1,i.posMax=o,!0);}function zc(i,e){var t,n,s,r,o=i.posMax,a=i.pos;if(a+3>o||!i.env.footnotes||!i.env.footnotes.refs||i.src.charCodeAt(a)!==91||i.src.charCodeAt(a+1)!==94||i.level>=i.options.maxNesting)return!1;for(n=a+2;n<o;n++){if(i.src.charCodeAt(n)===32||i.src.charCodeAt(n)===10)return!1;if(i.src.charCodeAt(n)===93)break;}return n===a+2||n>=o||(n++,t=i.src.slice(a+2,n-1),_typeof(i.env.footnotes.refs[":"+t])>"u")?!1:(e||(i.env.footnotes.list||(i.env.footnotes.list=[]),i.env.footnotes.refs[":"+t]<0?(s=i.env.footnotes.list.length,i.env.footnotes.list[s]={label:t,count:0},i.env.footnotes.refs[":"+t]=s):s=i.env.footnotes.refs[":"+t],r=i.env.footnotes.list[s].count,i.env.footnotes.list[s].count++,i.push({type:"footnote_ref",id:s,subId:r,level:i.level})),i.pos=n,i.posMax=o,!0);}var Vc=["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"],Kc=/^<([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])?)*)>/,Wc=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Xc(i,e){var t,n,s,r,o,a=i.pos;return i.src.charCodeAt(a)!==60||(t=i.src.slice(a),t.indexOf(">")<0)?!1:(n=t.match(Wc),n?Vc.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=$i(r),!i.parser.validateLink(r))?!1:(e||(i.push({type:"link_open",href:o,level:i.level}),i.push({type:"text",content:r,level:i.level+1}),i.push({type:"link_close",level:i.level})),i.pos+=n[0].length,!0):(s=t.match(Kc),s?(r=s[0].slice(1,-1),o=$i("mailto:"+r),i.parser.validateLink(o)?(e||(i.push({type:"link_open",href:o,level:i.level}),i.push({type:"text",content:r,level:i.level+1}),i.push({type:"link_close",level:i.level})),i.pos+=s[0].length,!0):!1):!1));}function vi(i,e){return i=i.source,e=e||"",function t(n,s){return n?(s=s.source||s,i=i.replace(n,s),t):new RegExp(i,e);};}var Zc=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Yc=/[^"'=<>`\x00-\x20]+/,Jc=/'[^']*'/,Qc=/"[^"]*"/,el=vi(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Yc)("single_quoted",Jc)("double_quoted",Qc)(),tl=vi(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Zc)("attr_value",el)(),nl=vi(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",tl)(),sl=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,il=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,rl=/<[?].*?[?]>/,ol=/<![A-Z]+\s+[^>]*>/,al=/<!\[CDATA\[[\s\S]*?\]\]>/,cl=vi(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",nl)("close_tag",sl)("comment",il)("processing",rl)("declaration",ol)("cdata",al)();function ll(i){var e=i|32;return e>=97&&e<=122;}function dl(i,e){var t,n,s,r=i.pos;return!i.options.html||(s=i.posMax,i.src.charCodeAt(r)!==60||r+2>=s)||(t=i.src.charCodeAt(r+1),t!==33&&t!==63&&t!==47&&!ll(t))||(n=i.src.slice(r).match(cl),!n)?!1:(e||i.push({type:"htmltag",content:i.src.slice(r,r+n[0].length),level:i.level}),i.pos+=n[0].length,!0);}var hl=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,ul=/^&([a-z][a-z0-9]{1,31});/i;function pl(i,e){var t,n,s,r=i.pos,o=i.posMax;if(i.src.charCodeAt(r)!==38)return!1;if(r+1<o){if(t=i.src.charCodeAt(r+1),t===35){if(s=i.src.slice(r).match(hl),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=Go(n)?ji(n):ji(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match(ul),s){var a=$o(s[1]);if(s[1]!==a)return e||(i.pending+=a),i.pos+=s[0].length,!0;}}return e||(i.pending+="&"),i.pos++,!0;}var Bi=[["text",kc],["newline",Pc],["escape",Lc],["backticks",Oc],["del",Nc],["ins",Bc],["mark",Dc],["emphasis",Fc],["sub",Hc],["sup",$c],["links",qc],["footnote_inline",Gc],["footnote_ref",zc],["autolink",Xc],["htmltag",dl],["entity",pl]];function Si(){this.ruler=new Ye();for(var i=0;i<Bi.length;i++)this.ruler.push(Bi[i][0],Bi[i][1]);this.validateLink=fl;}Si.prototype.skipToken=function(i){var e=this.ruler.getRules(""),t=e.length,n=i.pos,s,r;if((r=i.cacheGet(n))>0){i.pos=r;return;}for(s=0;s<t;s++)if(e[s](i,!0)){i.cacheSet(n,i.pos);return;}i.pos++,i.cacheSet(n,i.pos);};Si.prototype.tokenize=function(i){for(var e=this.ruler.getRules(""),t=e.length,n=i.posMax,s,r;i.pos<n;){for(r=0;r<t&&(s=e[r](i,!1),!s);r++);if(s){if(i.pos>=n)break;continue;}i.pending+=i.src[i.pos++];}i.pending&&i.pushPending();};Si.prototype.parse=function(i,e,t,n){var s=new pn(i,this,e,t,n);this.tokenize(s);};function fl(i){var e=["vbscript","javascript","file","data"],t=i.trim().toLowerCase();return t=ln(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var ml={options:{html:!1,// Enable HTML tags in source
11
+ },{key:"preventAutomaticScrollUpOnNewLine",value:function preventAutomaticScrollUpOnNewLine(e){var t;e.addEventListener("keydown",function(){t=window.scrollY;}),e.addEventListener("input",function(){t!==window.scrollY&&window.scrollTo({top:t});});}},{key:"addFilesToAnyType",value:function addFilesToAnyType(e,t){t&&e.addFilesToAnyType(Array.from(t).map(function(n){return n;}));}}]);}();Bt.TEXT_INPUT_ID="text-input";var Ks=Bt;var ln=/*#__PURE__*/function(){function ln(){_classCallCheck(this,ln);}return _createClass(ln,null,[{key:"focusEndOfInput",value:function focusEndOfInput(e){var t=document.createRange();t.selectNodeContents(e),t.collapse(!1);var n=window.getSelection();n==null||n.removeAllRanges(),n==null||n.addRange(t),($e.IS_MOBILE||$e.IS_SAFARI)&&e.focus();}},{key:"focusFromParentElement",value:function focusFromParentElement(e){var t=e.querySelector("#".concat(Ks.TEXT_INPUT_ID));t&&ln.focusEndOfInput(t);}}]);}();var Ho="Authentication",he="Authorization",Pa="authorization",yi="Unauthorized",ar="Authorization header",zt="Invalid",Ps="Incorrect",Te="authentication_error",it="invalid_request_error",q="Content-Type",La="content-type",te="application/json",U="object",cr="completed",Ce="Bearer ",ue="GET",ye="POST",lr="Upload an audio file",$s="function_call",sn="input_audio",qe="image_url",Mn="system",pi=/*#__PURE__*/function(){function pi(){_classCallCheck(this,pi);}return _createClass(pi,null,[{key:"addElements",value:function addElements(e){for(var _len=arguments.length,t=new Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){t[_key-1]=arguments[_key];}t.forEach(function(n){return e.appendChild(n);});}},{key:"isScrollbarAtBottomOfElement",value:function isScrollbarAtBottomOfElement(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:pi.CODE_SNIPPET_GENERATION_JUMP;var n=e.scrollHeight,s=e.clientHeight,r=e.scrollTop,o=n-s;return r>=o-t;}},{key:"cloneElement",value:function cloneElement(e){var t=e.cloneNode(!0);return e.parentNode.replaceChild(t,e),t;}},{key:"scrollToBottom",value:function scrollToBottom(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2?arguments[2]:undefined;e.scrollButton&&e.scrollButton.hiddenElements.size>0&&e.scrollButton.clearHidden(),n?e.elementRef.scrollTo({left:0,top:n.offsetTop}):t?e.elementRef.scrollTo({left:0,top:e.elementRef.scrollHeight,behavior:"smooth"}):e.elementRef.scrollTop=e.elementRef.scrollHeight;}},{key:"scrollToTop",value:function scrollToTop(e){e.scrollTop=0;}},{key:"isVisibleInParent",value:function isVisibleInParent(e,t){var n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return n.bottom>s.top&&n.top<s.bottom;}},{key:"waitForScrollEnd",value:function waitForScrollEnd(e,t){var n=-1,s=0;var _r2=function r(){var o=e.scrollTop;if(o===n){if(s++,s>2){t();return;}}else s=0,n=o;requestAnimationFrame(_r2);};requestAnimationFrame(_r2);}},{key:"assignButtonEvents",value:function assignButtonEvents(e,t){e.onclick=t,e.onkeydown=function(n){n.key===_e.ENTER&&setTimeout(t);};}}]);}();pi.CODE_SNIPPET_GENERATION_JUMP=1;var z=pi;var fi=/*#__PURE__*/function(){function fi(){_classCallCheck(this,fi);}return _createClass(fi,null,[{key:"speak",value:function speak(e,t){if(!t.audio&&window.SpeechSynthesisUtterance){var n=new SpeechSynthesisUtterance(e);Object.assign(n,t),speechSynthesis.speak(n);}}},{key:"processConfig",value:function processConfig(e,t){var n={};setTimeout(function(){if(_typeof(e)=="object"&&(e.audio&&(n.audio=e.audio),e.lang&&(n.lang=e.lang),e.pitch&&(n.pitch=e.pitch),e.rate&&(n.rate=e.rate),e.volume&&(n.volume=e.volume),e.voiceName)){var s=window.speechSynthesis.getVoices().find(function(r){var o;return r.name.toLocaleLowerCase()===((o=e.voiceName)==null?void 0:o.toLocaleLowerCase());});s&&(n.voice=s);}t(n);},fi.LOAD_VOICES_MS);}}]);}();fi.LOAD_VOICES_MS=200;var Rn=fi;var Sn=/*#__PURE__*/function(){function Sn(){_classCallCheck(this,Sn);}return _createClass(Sn,null,[{key:"colorToHex",value:function colorToHex(e){var t=A();return t[v].color=e,document.body.appendChild(t),"#".concat(window.getComputedStyle(t).color.match(/\d+/g).map(function(r){return parseInt(r).toString(16).padStart(2,"0");}).join(""));}},{key:"setDots",value:function setDots(e,t){var n,s;if((s=(n=t==null?void 0:t[R])==null?void 0:n.bubble)!=null&&s.color){var r=Sn.colorToHex(t[R].bubble.color);e[v].setProperty("--loading-message-color",r),e[v].setProperty("--loading-message-color-fade","".concat(r,"33"));}else e[v].setProperty("--loading-message-color","#848484"),e[v].setProperty("--loading-message-color-fade","#55555533");}},{key:"setRing",value:function setRing(e,t){var _ref8=t||{},n=_ref8.color,s=_ref8.width,r=_ref8.height,o=_ref8.margin,a=_ref8.border;if(n){var c=Sn.colorToHex(n);e[v].setProperty("--loading-history-color",c);}else e[v].setProperty("--loading-history-color","#dbdbdb");e[v].setProperty("--loading-history-height",r||"57px"),e[v].setProperty("--loading-history-width",s||"57px"),e[v].setProperty("--loading-history-margin",o||"7px"),e[v].setProperty("--loading-history-border",a||"6px solid");}}]);}();Sn.BUBBLE_CLASS="deep-chat-loading-message-bubble",Sn.DOTS_CONTAINER_CLASS="deep-chat-loading-message-dots-container";var mt=Sn;var le=/*#__PURE__*/function(){function le(){_classCallCheck(this,le);}return _createClass(le,null,[{key:"checkForContainerStyles",value:function checkForContainerStyles(e,t){var n=e.containerStyle;n&&(Object.assign(t[v],n),console[f]("The containerStyle property".concat(Je,"1.3.14.")),console[f]("".concat(Vt,"the style property instead: ").concat(Z,"styles#style")));}// eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ },{key:"handleResponseProperty",value:function handleResponseProperty(e){return console[f]("The {result: ....} response object type".concat(Je,"1.3.0.")),console[f]("".concat(Vt,"the new response object: ").concat(Z,"connect#Response")),e.result;}},{key:"processHistory",value:function processHistory(e){var t=e.initialMessages;if(t)return console[f]("The initialMessages property".concat(Je,"2.0.0.")),console[f]("".concat(Vt,"the history property instead: ").concat(Z,"messages/#history")),t;}},{key:"processHistoryFile",value:function processHistoryFile(e){var t=e[se];t&&(console[f]("The file property in MessageContent".concat(Je,"1.3.17.")),console[f]("".concat(Vt,"the files array property: ").concat(Z,"messages/#MessageContent")),e[b]=[t]);}},{key:"processValidateInput",value:function processValidateInput(e){var t=e.validateMessageBeforeSending;if(t)return console[f]("The validateMessageBeforeSending property".concat(Je,"1.3.24.")),console[f]("".concat(Vt,"validateInput: ").concat(Z,"interceptors#validateInput")),t;}},{key:"processSubmitUserMessage",value:function processSubmitUserMessage(e){return console[f]("The submitUserMessage(text: string) argument string type".concat(Je,"1.4.4.")),console[f]("".concat(Vt,"the new argument type: ").concat(Z,"methods#submitUserMessage")),_defineProperty({},h,e);}},{key:"flagHTMLUpdateClass",value:function flagHTMLUpdateClass(e){var t;(t=e.children[0])!=null&&t[m].contains("deep-chat-update-message")&&(console[f]("The \"deep-chat-update-message\" html class".concat(Je,"1.4.4.")),console[f]("".concat(Vt,"using {..., overwrite: true} object: ").concat(Z,"connect#Response")));}},{key:"processConnect",value:function processConnect(e){var t=e;t.request&&(t.connect?Object.assign(t.connect,t.request):t.connect=t.request,console[f]("The request property".concat(Je,"2.0.0.")),console[f]("".concat(Bs,"connect object: ").concat(Z,"connect#connect-1")));}},{key:"checkForStream",value:function checkForStream(e){var t=e.stream;if(t)return console[f]("The stream property".concat(jr,"the connect object in version 2.0.0.")),console[f]("".concat(Bs,"connect object: ").concat(Z,"connect#connect-1")),t;}},{key:"fireOnNewMessage",value:function fireOnNewMessage(e,t){var s;var n=e;n.onNewMessage&&(console[f]("The onNewMessage event".concat(Je,"2.0.0.")),console[f]("".concat(Bs,"onMessage event: ").concat(Z,"events#onMessage")),(s=n.onNewMessage)==null||s.call(n,t)),e.dispatchEvent(new CustomEvent("new-message",{detail:t}));}},{key:"processFileConfigConnect",value:function processFileConfigConnect(e){var t=e;t.request&&(console[f]("The request property in file configuration".concat(Je,"2.0.0.")),console[f]("Please use the connect property instead: ".concat(Z,"files")),t.connect||(t.connect=t.request));}},{key:"processMessageStyles",value:function processMessageStyles(e){if(!e)return;var t=C(e),n=t.loading;return n&&(n.outerContainer||n.innerContainer||n.bubble||n.media)&&(console[f]("The loading message styles are defined using LoadingMessageStyles interface".concat(En,"2.1.0.")),console[f]("Check it out here: ".concat(Z,"messages/styles#LoadingMessageStyles")),t.loading={message:{styles:n}}),t;}},{key:"processDemo",value:function processDemo(e){return typeof e=="boolean"||e.displayLoadingBubble&&(console[f]("The demo displayLoadingBubble property".concat(Je,"2.1.0.")),console[f]("Please use displayLoading instead: ".concat(Z,"modes#demo")),e.displayLoading={message:!0}),e;}},{key:"processCohere",value:function processCohere(e){var t=e,n="".concat(Bs,"official documentation: ").concat(Z,"directConnection/Cohere");return t.chat&&(console[f]("Cohere chat property".concat(Je,"2.2.3.")),console[f](n),delete t.chat),t.textGeneration?(console[f]("Cohere textGeneration".concat(Hr,"2.2.3.")),console[f](n),delete t.textGeneration,!1):t.summarization?(console[f]("Cohere summarization".concat(Hr,"2.2.3.")),console[f](n),delete t.summarization,!1):!0;}},{key:"processStreamHTMLWrappers",value:function processStreamHTMLWrappers(e){if(!e||_typeof(e)!==U)return;var t=e.htmlWrappers;if(t)return console[f]("The htmlWrappers property".concat(jr,"Deep Chat's base").concat(En,"2.3.0.")),console[f]("Check it out here: ".concat(Z,"messages/HTML#htmlWrappers")),t;}},{key:"processFocusMode",value:function processFocusMode(e){return!e||typeof e=="boolean"||e.scroll&&(console[f]("The scroll property in focusMode has been changed to smoothScroll".concat(En,"2.3.0.")),console[f]("Check it out here: ".concat(Z,"modes#focusMode")),e.smoothScroll=!0),e;}},{key:"processPosition",value:function processPosition(e){if(!e)return e;var t="Position names have been updated".concat(En,"2.3.1.");return e==="inside-left"?(console[f](t),In):e==="inside-right"?(console[f](t),ft):e==="outside-left"?(console[f](t),Le):e==="outside-right"?(console[f](t),ve):e;}},{key:"processBrowserStorage",value:function processBrowserStorage(e){var t=e.get();t&&Array.isArray(t)&&e.addMessages(t);}}]);}();var En=" since version ",Je=" is deprecated ".concat(En),Vt="Please change to using ",Bs="Please see the ",Hr=" is not supported ".concat(En),jr=" has been moved to ";var Rt=/*#__PURE__*/function(){function Rt(){_classCallCheck(this,Rt);}return _createClass(Rt,null,[{key:"mouseUp",value:function mouseUp(e,t){de.unsetAllCSSMouseStates(e,t),Object.assign(e[v],t[w]),Object.assign(e[v],t[De]);}},{key:"mouseDown",value:function mouseDown(e,t){Object.assign(e[v],t[J]);}},{key:"mouseLeave",value:function mouseLeave(e,t){de.unsetAllCSSMouseStates(e,t),Object.assign(e[v],t[w]);}},{key:"mouseEnter",value:function mouseEnter(e,t){Object.assign(e[v],t[De]);}},{key:"add",value:function add(e,t){e.addEventListener(ks,Rt.mouseEnter.bind(this,e,t)),e.addEventListener(cn,Rt.mouseLeave.bind(this,e,t)),e.addEventListener(Ia,Rt.mouseDown.bind(this,e,t)),e.addEventListener(Ma,Rt.mouseUp.bind(this,e,t));}}]);}();var Oa="deep-chat-temporary-message",Na="deep-chat-suggestion-button",Fi={"deep-chat-button":{styles:_defineProperty(_defineProperty(_defineProperty({},w,{backgroundColor:"white",padding:"5px",paddingLeft:"7px",paddingRight:"7px",border:"1px solid #c2c2c2",borderRadius:"6px",cursor:"pointer"}),De,{backgroundColor:"#fafafa"}),J,{backgroundColor:"#f1f1f1"})}},$r=Object.keys(Fi);var bt=/*#__PURE__*/function(){function bt(){_classCallCheck(this,bt);}return _createClass(bt,null,[{key:"applySuggestionEvent",value:function applySuggestionEvent(e,t){setTimeout(function(){t.addEventListener(J,function(){var n,s;(s=e.submitUserMessage)==null||s.call(e,_defineProperty({},h,((n=t.textContent)==null?void 0:n.trim())||""));});});}},{key:"isElementTemporary",value:function isElementTemporary(e){var t;return e?(t=e.bubbleElement.children[0])==null?void 0:t[m].contains(Oa):!1;}},{key:"doesElementContainDeepChatClass",value:function doesElementContainDeepChatClass(e){return $r.find(function(t){return e[m].contains(t);});}},{key:"applyEvents",value:function applyEvents(e,t){var n=Fi[t].events;Object.keys(n||[]).forEach(function(s){e.addEventListener(s,n==null?void 0:n[s]);});}},{key:"getProcessedStyles",value:function getProcessedStyles(e,t,n){var s=Array.from(t[m]).reduce(function(a,c){var d;var l=(d=e[c])==null?void 0:d[R];return l&&e[c][R]&&a.push(l),a;},[]),r=Fi[n][R];if(r){var a=C(r);a[w]&&de.overwriteDefaultWithAlreadyApplied(a,t),s.unshift(a);}var o=de.mergeStatefulStyles(s);return de.processStateful(o);}},{key:"applyDeepChatUtilities",value:function applyDeepChatUtilities(e,t,n){$r.forEach(function(r){var o=n.getElementsByClassName(r);Array.from(o||[]).forEach(function(a){var c=bt.getProcessedStyles(t,a,r);oe.applyStylesToElement(a,c),bt.applyEvents(a,r);});});var s=n.getElementsByClassName(Na);Array.from(s).forEach(function(r){return bt.applySuggestionEvent(e,r);});}}]);}();var oe=/*#__PURE__*/function(){function oe(){_classCallCheck(this,oe);}return _createClass(oe,null,[{key:"applyStylesToElement",value:function applyStylesToElement(e,t){var n=de.processStateful(t);Rt.add(e,n),Object.assign(e[v],n[w]);}},{key:"applyEventsToElement",value:function applyEventsToElement(e,t){Object.keys(t).forEach(function(n){var s=t[n];s&&e.addEventListener(n,s);});}},{key:"applyClassUtilitiesToElement",value:function applyClassUtilitiesToElement(e,t){var n=t.events,s=t.styles;n&&oe.applyEventsToElement(e,n),s&&!bt.doesElementContainDeepChatClass(e)&&oe.applyStylesToElement(e,s);}},{key:"applyCustomClassUtilities",value:function applyCustomClassUtilities(e,t){Object.keys(e).forEach(function(n){var s=t.getElementsByClassName(n);Array.from(s).forEach(function(r){e[n]&&oe.applyClassUtilitiesToElement(r,e[n]);});});}},{key:"apply",value:function apply(e,t){bt.applyDeepChatUtilities(e,e.htmlClassUtilities,t),oe.applyCustomClassUtilities(e.htmlClassUtilities,t);}},{key:"traverseNodes",value:function traverseNodes(e,t){e.nodeType===Node.ELEMENT_NODE&&t.push(e.outerHTML),e.childNodes.forEach(function(n){oe.traverseNodes(n,t);});}},{key:"splitHTML",value:function splitHTML(e){var n=new DOMParser().parseFromString(e,"text/html"),s=[];return n.body.childNodes.forEach(function(r){oe.traverseNodes(r,s);}),s;}},{key:"isTemporaryBasedOnHTML",value:function isTemporaryBasedOnHTML(e){var t=A();return t.innerHTML=e,bt.isElementTemporary({outerContainer:t,bubbleElement:t,innerContainer:t});}// useful for removing event listeners
13
+ },{key:"replaceElementWithNewClone",value:function replaceElementWithNewClone(e,t){var s;var n=(t||e).cloneNode(!0);return(s=e.parentNode)==null||s.replaceChild(n,e),n;}},{key:"tryAddWrapper",value:function tryAddWrapper(e,t,n,s){if(t&&s){var r=(n==null?void 0:n[s])||(n==null?void 0:n[w]);if(r)return e.innerHTML=r,{contentEl:oe.getTargetWrapper(e),wrapper:!0};}return{contentEl:e,wrapper:!1};}},{key:"getTargetWrapper",value:function getTargetWrapper(e){return e.getElementsByClassName(ba)[0]||e;}}]);}();var Dt=/*#__PURE__*/function(){function Dt(){_classCallCheck(this,Dt);}return _createClass(Dt,null,[{key:"createElements",value:function createElements(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;var o=e.createMessageElementsOnOrientation("",n,s,r);o.bubbleElement[m].add(Dt.HTML_BUBBLE_CLASS);var _oe$tryAddWrapper=oe.tryAddWrapper(o.bubbleElement,t,e._customWrappers,n),a=_oe$tryAddWrapper.contentEl;return a.innerHTML=t,o;}},{key:"overwriteElements",value:function overwriteElements(e,t,n){n.bubbleElement.innerHTML=t,oe.apply(e,n.outerContainer),le.flagHTMLUpdateClass(n.bubbleElement);}// prettier-ignore
14
+ },{key:"overwrite",value:function overwrite(e,t,n,s){var r=e.messageToElements,o=B.overwriteMessage(r,s,t,n,L,Dt.HTML_BUBBLE_CLASS);return o&&Dt.overwriteElements(e,t,o),o;}},{key:"create",value:function create(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var r=Dt.createElements(e,t,n,s);return B.fillEmptyMessageElement(r.bubbleElement,t),oe.apply(e,r.outerContainer),le.flagHTMLUpdateClass(r.bubbleElement),e.applyCustomStyles(r,n,!1,(o=e.messageStyles)==null?void 0:o[L]),r;}},{key:"add",value:function add(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;if(s!=null&&s.status){var a=this.overwrite(e,t,n,e.messageElementRefs);if(a)return a;s.status=!1;}if(r&&e.messageElementRefs.length>0&&oe.isTemporaryBasedOnHTML(t))return;var o=Dt.create(e,t,n,r);return r||e.appendOuterContainerElemet(o.outerContainer),o;}}]);}();Dt.HTML_BUBBLE_CLASS="html-message";var yt=Dt;var Ba=/*#__PURE__*/function(){function Ba(){_classCallCheck(this,Ba);}return _createClass(Ba,null,[{key:"katex",value:function katex(e,t,n){var a=(n||{}).delimiter||"$";if(a.length!==1)throw new Error("invalid delimiter");var c=function c(p,u){var g;return((g=window.katex)==null?void 0:g.renderToString(p,_objectSpread({displayMode:u,throwOnError:!1,output:"mathml"},e)))||"";},l=function l(p,u,g){var y=!1,_=p.bMarks[u]+p.tShift[u],S=p.eMarks[u];if(_+1>S)return!1;var M=p[T].charAt(_);if(M!==a)return!1;var K=_;_=p.skipChars(_,M);var ie=_-K;if(ie!==2)return!1;var re=u;for(;++re,!(re>=g||(_=K=p.bMarks[re]+p.tShift[re],S=p.eMarks[re],_<S&&p.tShift[re]<p.blkIndent));)if(p[T].charAt(_)===a&&!(p.tShift[re]-p.blkIndent>=4)&&(_=p.skipChars(_,M),!(_-K<ie)&&(_=p.skipSpaces(_),!(_<S)))){y=!0;break;}ie=p.tShift[u],p.line=re+(y?1:0);var Re=p.getLines(u+1,re,ie,!0).replace(/[ \n]+/g," ").trim();return p.tokens.push({type:"katex",params:null,content:Re,lines:[u,p.line],level:p.level,block:!0}),!0;},d=function d(p,u){var g=p.pos,y=p.posMax;var _=g;if(p[T].charAt(_)!==a)return!1;for(++_;_<y&&p[T].charAt(_)===a;)++_;var S=p[T].slice(g,_);if(S.length>2)return!1;var M=_;var K=0;for(;_<y;){var ie=p[T].charAt(_);if(ie==="{"&&(_===0||p[T].charAt(_-1)!=="\\"))K+=1;else if(ie==="}"&&(_===0||p[T].charAt(_-1)!=="\\")){if(K-=1,K<0)return!1;}else if(ie===a&&K===0){var re=_;var Re=_+1;for(;Re<y&&p[T].charAt(Re)===a;)++Re;if(Re-re===S.length){if(!u){var Lt=p[T].slice(M,re).replace(/[ \n]+/g," ").trim();p.push({type:"katex",content:Lt,block:S.length>1,level:p.level});}return p.pos=Re,!0;}}_+=1;}return u||(p.pending+=S),p.pos+=S.length,!0;};t.inline.ruler.push("katex",d,n),t.block.ruler.push("katex",l,n),t.renderer.rules.katex=function(p,u){return c(p[u].content,p[u].block);},t.renderer.rules.katex.delimiter=a;}}]);}();var Ds;function jo(i){return Ds=Ds||document.createElement("textarea"),Ds.innerHTML="&"+i+";",Ds.value;}var Da=Object.prototype.hasOwnProperty;function Fa(i,e){return i?Da.call(i,e):!1;}function $o(i){var e=[].slice.call(arguments,1);return e.forEach(function(t){if(t){if(_typeof(t)!="object")throw new TypeError(t+"must be object");Object.keys(t).forEach(function(n){i[n]=t[n];});}}),i;}var Ua=/\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function xs(i){return i.indexOf("\\")<0?i:i.replace(Ua,"$1");}function qo(i){return!(i>=55296&&i<=57343||i>=64976&&i<=65007||(i&65535)===65535||(i&65535)===65534||i>=0&&i<=8||i===11||i>=14&&i<=31||i>=127&&i<=159||i>1114111);}function Ui(i){if(i>65535){i-=65536;var e=55296+(i>>10),t=56320+(i&1023);return String.fromCharCode(e,t);}return String.fromCharCode(i);}var Ha=/&([a-z#][a-z0-9]{1,31});/gi,ja=/^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;function $a(i,e){var t=0,n=jo(e);return e!==n?n:e.charCodeAt(0)===35&&ja.test(e)&&(t=e[1].toLowerCase()==="x"?parseInt(e.slice(2),16):parseInt(e.slice(1),10),qo(t))?Ui(t):i;}function dn(i){return i.indexOf("&")<0?i:i.replace(Ha,$a);}var qa=/[&<>"]/,Ga=/[&<>"]/g,za={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function Va(i){return za[i];}function Ge(i){return qa.test(i)?i.replace(Ga,Va):i;}var I={};I.blockquote_open=function(){return"<blockquote>\n";};I.blockquote_close=function(i,e){return"</blockquote>"+pn(i,e);};I.code=function(i,e){return i[e].block?"<pre><code>"+Ge(i[e].content)+"</code></pre>"+pn(i,e):"<code>"+Ge(i[e].content)+"</code>";};I.fence=function(i,e,t,n,s){var r=i[e],o="",a=t.langPrefix,c="",l,d,p;if(r.params){if(l=r.params.split(/\s+/g),d=l.join(" "),Fa(s.rules.fence_custom,l[0]))return s.rules.fence_custom[l[0]](i,e,t,n,s);c=Ge(dn(xs(d))),o=' class="'+a+c+'"';}return t.highlight?p=t.highlight.apply(t.highlight,[r.content].concat(l))||Ge(r.content):p=Ge(r.content),"<pre><code"+o+">"+p+"</code></pre>"+pn(i,e);};I.fence_custom={};I.heading_open=function(i,e){return"<h"+i[e].hLevel+">";};I.heading_close=function(i,e){return"</h"+i[e].hLevel+">\n";};I.hr=function(i,e,t){return(t.xhtmlOut?"<hr />":"<hr>")+pn(i,e);};I.bullet_list_open=function(){return"<ul>\n";};I.bullet_list_close=function(i,e){return"</ul>"+pn(i,e);};I.list_item_open=function(){return"<li>";};I.list_item_close=function(){return"</li>\n";};I.ordered_list_open=function(i,e){var t=i[e],n=t.order>1?' start="'+t.order+'"':"";return"<ol"+n+">\n";};I.ordered_list_close=function(i,e){return"</ol>"+pn(i,e);};I.paragraph_open=function(i,e){return i[e].tight?"":"<p>";};I.paragraph_close=function(i,e){var t=!(i[e].tight&&e&&i[e-1].type==="inline"&&!i[e-1].content);return(i[e].tight?"":"</p>")+(t?pn(i,e):"");};I.link_open=function(i,e,t){var n=i[e].title?' title="'+Ge(dn(i[e].title))+'"':"",s=t.linkTarget?' target="'+t.linkTarget+'"':"";return'<a href="'+Ge(i[e].href)+'"'+n+s+">";};I.link_close=function(){return"</a>";};I.image=function(i,e,t){var n=' src="'+Ge(i[e].src)+'"',s=i[e].title?' title="'+Ge(dn(i[e].title))+'"':"",r=' alt="'+(i[e].alt?Ge(dn(xs(i[e].alt))):"")+'"',o=t.xhtmlOut?" /":"";return"<img"+n+r+s+o+">";};I.table_open=function(){return"<table>\n";};I.table_close=function(){return"</table>\n";};I.thead_open=function(){return"<thead>\n";};I.thead_close=function(){return"</thead>\n";};I.tbody_open=function(){return"<tbody>\n";};I.tbody_close=function(){return"</tbody>\n";};I.tr_open=function(){return"<tr>";};I.tr_close=function(){return"</tr>\n";};I.th_open=function(i,e){var t=i[e];return"<th"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.th_close=function(){return"</th>";};I.td_open=function(i,e){var t=i[e];return"<td"+(t.align?' style="text-align:'+t.align+'"':"")+">";};I.td_close=function(){return"</td>";};I.strong_open=function(){return"<strong>";};I.strong_close=function(){return"</strong>";};I.em_open=function(){return"<em>";};I.em_close=function(){return"</em>";};I.del_open=function(){return"<del>";};I.del_close=function(){return"</del>";};I.ins_open=function(){return"<ins>";};I.ins_close=function(){return"</ins>";};I.mark_open=function(){return"<mark>";};I.mark_close=function(){return"</mark>";};I.sub=function(i,e){return"<sub>"+Ge(i[e].content)+"</sub>";};I.sup=function(i,e){return"<sup>"+Ge(i[e].content)+"</sup>";};I.hardbreak=function(i,e,t){return t.xhtmlOut?"<br />\n":"<br>\n";};I.softbreak=function(i,e,t){return t.breaks?t.xhtmlOut?"<br />\n":"<br>\n":"\n";};I.text=function(i,e){return Ge(i[e].content);};I.htmlblock=function(i,e){return i[e].content;};I.htmltag=function(i,e){return i[e].content;};I.abbr_open=function(i,e){return'<abbr title="'+Ge(dn(i[e].title))+'">';};I.abbr_close=function(){return"</abbr>";};I.footnote_ref=function(i,e){var t=Number(i[e].id+1).toString(),n="fnref"+t;return i[e].subId>0&&(n+=":"+i[e].subId),'<sup class="footnote-ref"><a href="#fn'+t+'" id="'+n+'">['+t+"]</a></sup>";};I.footnote_block_open=function(i,e,t){var n=t.xhtmlOut?"<hr class=\"footnotes-sep\" />\n":"<hr class=\"footnotes-sep\">\n";return n+"<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n";};I.footnote_block_close=function(){return"</ol>\n</section>\n";};I.footnote_open=function(i,e){var t=Number(i[e].id+1).toString();return'<li id="fn'+t+'" class="footnote-item">';};I.footnote_close=function(){return"</li>\n";};I.footnote_anchor=function(i,e){var t=Number(i[e].id+1).toString(),n="fnref"+t;return i[e].subId>0&&(n+=":"+i[e].subId),' <a href="#'+n+'" class="footnote-backref">↩</a>';};I.dl_open=function(){return"<dl>\n";};I.dt_open=function(){return"<dt>";};I.dd_open=function(){return"<dd>";};I.dl_close=function(){return"</dl>\n";};I.dt_close=function(){return"</dt>\n";};I.dd_close=function(){return"</dd>\n";};function Go(i,e){return++e>=i.length-2?e:i[e].type==="paragraph_open"&&i[e].tight&&i[e+1].type==="inline"&&i[e+1].content.length===0&&i[e+2].type==="paragraph_close"&&i[e+2].tight?Go(i,e+2):e;}var pn=I.getBreak=function(e,t){return t=Go(e,t),t<e.length&&e[t].type==="list_item_close"?"":"\n";};function dr(){this.rules=$o({},I),this.getBreak=I.getBreak;}dr.prototype.renderInline=function(i,e,t){for(var n=this.rules,s=i.length,r=0,o="";s--;)o+=n[i[r].type](i,r++,e,t,this);return o;};dr.prototype.render=function(i,e,t){for(var n=this.rules,s=i.length,r=-1,o="";++r<s;)i[r].type==="inline"?o+=this.renderInline(i[r].children,e,t):o+=n[i[r].type](i,r,e,t,this);return o;};function Ye(){this.__rules__=[],this.__cache__=null;}Ye.prototype.__find__=function(i){for(var e=this.__rules__.length,t=-1;e--;)if(this.__rules__[++t].name===i)return t;return-1;};Ye.prototype.__compile__=function(){var i=this,e=[""];i.__rules__.forEach(function(t){t.enabled&&t.alt.forEach(function(n){e.indexOf(n)<0&&e.push(n);});}),i.__cache__={},e.forEach(function(t){i.__cache__[t]=[],i.__rules__.forEach(function(n){n.enabled&&(t&&n.alt.indexOf(t)<0||i.__cache__[t].push(n.fn));});});};Ye.prototype.at=function(i,e,t){var n=this.__find__(i),s=t||{};if(n===-1)throw new Error("Parser rule not found: "+i);this.__rules__[n].fn=e,this.__rules__[n].alt=s.alt||[],this.__cache__=null;};Ye.prototype.before=function(i,e,t,n){var s=this.__find__(i),r=n||{};if(s===-1)throw new Error("Parser rule not found: "+i);this.__rules__.splice(s,0,{name:e,enabled:!0,fn:t,alt:r.alt||[]}),this.__cache__=null;};Ye.prototype.after=function(i,e,t,n){var s=this.__find__(i),r=n||{};if(s===-1)throw new Error("Parser rule not found: "+i);this.__rules__.splice(s+1,0,{name:e,enabled:!0,fn:t,alt:r.alt||[]}),this.__cache__=null;};Ye.prototype.push=function(i,e,t){var n=t||{};this.__rules__.push({name:i,enabled:!0,fn:e,alt:n.alt||[]}),this.__cache__=null;};Ye.prototype.enable=function(i,e){i=Array.isArray(i)?i:[i],e&&this.__rules__.forEach(function(t){t.enabled=!1;}),i.forEach(function(t){var n=this.__find__(t);if(n<0)throw new Error("Rules manager: invalid rule name "+t);this.__rules__[n].enabled=!0;},this),this.__cache__=null;};Ye.prototype.disable=function(i){i=Array.isArray(i)?i:[i],i.forEach(function(e){var t=this.__find__(e);if(t<0)throw new Error("Rules manager: invalid rule name "+e);this.__rules__[t].enabled=!1;},this),this.__cache__=null;};Ye.prototype.getRules=function(i){return this.__cache__===null&&this.__compile__(),this.__cache__[i]||[];};function Ka(i){i.inlineMode?i.tokens.push({type:"inline",content:i.src.replace(/\n/g," ").trim(),level:0,lines:[0,1],children:[]}):i.block.parse(i.src,i.options,i.env,i.tokens);}function fn(i,e,t,n,s){this.src=i,this.env=n,this.options=t,this.parser=e,this.tokens=s,this.pos=0,this.posMax=this.src.length,this.level=0,this.pending="",this.pendingLevel=0,this.cache=[],this.isInLabel=!1,this.linkLevel=0,this.linkContent="",this.labelUnmatchedScopes=0;}fn.prototype.pushPending=function(){this.tokens.push({type:"text",content:this.pending,level:this.pendingLevel}),this.pending="";};fn.prototype.push=function(i){this.pending&&this.pushPending(),this.tokens.push(i),this.pendingLevel=this.level;};fn.prototype.cacheSet=function(i,e){for(var t=this.cache.length;t<=i;t++)this.cache.push(0);this.cache[i]=e;};fn.prototype.cacheGet=function(i){return i<this.cache.length?this.cache[i]:0;};function As(i,e){var t,n,s,r=-1,o=i.posMax,a=i.pos,c=i.isInLabel;if(i.isInLabel)return-1;if(i.labelUnmatchedScopes)return i.labelUnmatchedScopes--,-1;for(i.pos=e+1,i.isInLabel=!0,t=1;i.pos<o;){if(s=i.src.charCodeAt(i.pos),s===91)t++;else if(s===93&&(t--,t===0)){n=!0;break;}i.parser.skipToken(i);}return n?(r=i.pos,i.labelUnmatchedScopes=0):i.labelUnmatchedScopes=t-1,i.pos=a,i.isInLabel=c,r;}function Wa(i,e,t,n){var s,r,o,a,c,l;if(i.charCodeAt(0)!==42||i.charCodeAt(1)!==91||i.indexOf("]:")===-1||(s=new fn(i,e,t,n,[]),r=As(s,1),r<0||i.charCodeAt(r+1)!==58))return-1;for(a=s.posMax,o=r+2;o<a&&s.src.charCodeAt(o)!==10;o++);return c=i.slice(2,r),l=i.slice(r+2,o).trim(),l.length===0?-1:(n.abbreviations||(n.abbreviations={}),_typeof(n.abbreviations[":"+c])>"u"&&(n.abbreviations[":"+c]=l),o);}function Xa(i){var e=i.tokens,t,n,s,r;if(!i.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t-1].type==="paragraph_open"&&e[t].type==="inline"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(r=Wa(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Hi(i){var e=dn(i);try{e=decodeURI(e);}catch(_unused2){}return encodeURI(e);}function zo(i,e){var t,n,s,r=e,o=i.posMax;if(i.src.charCodeAt(e)===60){for(e++;e<o;){if(t=i.src.charCodeAt(e),t===10)return!1;if(t===62)return s=Hi(xs(i.src.slice(r+1,e))),i.parser.validateLink(s)?(i.pos=e+1,i.linkContent=s,!0):!1;if(t===92&&e+1<o){e+=2;continue;}e++;}return!1;}for(n=0;e<o&&(t=i.src.charCodeAt(e),!(t===32||t<32||t===127));){if(t===92&&e+1<o){e+=2;continue;}if(t===40&&(n++,n>1)||t===41&&(n--,n<0))break;e++;}return r===e||(s=xs(i.src.slice(r,e)),!i.parser.validateLink(s))?!1:(i.linkContent=s,i.pos=e,!0);}function Vo(i,e){var t,n=e,s=i.posMax,r=i.src.charCodeAt(e);if(r!==34&&r!==39&&r!==40)return!1;for(e++,r===40&&(r=41);e<s;){if(t=i.src.charCodeAt(e),t===r)return i.pos=e+1,i.linkContent=xs(i.src.slice(n+1,e)),!0;if(t===92&&e+1<s){e+=2;continue;}e++;}return!1;}function Ko(i){return i.trim().replace(/\s+/g," ").toUpperCase();}function Za(i,e,t,n){var s,r,o,a,c,l,d,p,u;if(i.charCodeAt(0)!==91||i.indexOf("]:")===-1||(s=new fn(i,e,t,n,[]),r=As(s,0),r<0||i.charCodeAt(r+1)!==58))return-1;for(a=s.posMax,o=r+2;o<a&&(c=s.src.charCodeAt(o),!(c!==32&&c!==10));o++);if(!zo(s,o))return-1;for(d=s.linkContent,o=s.pos,l=o,o=o+1;o<a&&(c=s.src.charCodeAt(o),!(c!==32&&c!==10));o++);for(o<a&&l!==o&&Vo(s,o)?(p=s.linkContent,o=s.pos):(p="",o=l);o<a&&s.src.charCodeAt(o)===32;)o++;return o<a&&s.src.charCodeAt(o)!==10?-1:(u=Ko(i.slice(1,r)),_typeof(n.references[u])>"u"&&(n.references[u]={title:p,href:d}),o);}function Ya(i){var e=i.tokens,t,n,s,r;if(i.env.references=i.env.references||{},!i.inlineMode){for(t=1,n=e.length-1;t<n;t++)if(e[t].type==="inline"&&e[t-1].type==="paragraph_open"&&e[t+1].type==="paragraph_close"){for(s=e[t].content;s.length&&(r=Za(s,i.inline,i.options,i.env),!(r<0));)s=s.slice(r).trim();e[t].content=s,s.length||(e[t-1].tight=!0,e[t+1].tight=!0);}}}function Ja(i){var e=i.tokens,t,n,s;for(n=0,s=e.length;n<s;n++)t=e[n],t.type==="inline"&&i.inline.parse(t.content,i.options,i.env,t.children);}function Qa(i){var e,t,n,s,r,o,a,c,l,d=0,p=!1,u={};if(i.env.footnotes&&(i.tokens=i.tokens.filter(function(g){return g.type==="footnote_reference_open"?(p=!0,c=[],l=g.label,!1):g.type==="footnote_reference_close"?(p=!1,u[":"+l]=c,!1):(p&&c.push(g),!p);}),!!i.env.footnotes.list)){for(o=i.env.footnotes.list,i.tokens.push({type:"footnote_block_open",level:d++}),e=0,t=o.length;e<t;e++){for(i.tokens.push({type:"footnote_open",id:e,level:d++}),o[e].tokens?(a=[],a.push({type:"paragraph_open",tight:!1,level:d++}),a.push({type:"inline",content:"",level:d,children:o[e].tokens}),a.push({type:"paragraph_close",tight:!1,level:--d})):o[e].label&&(a=u[":"+o[e].label]),i.tokens=i.tokens.concat(a),i.tokens[i.tokens.length-1].type==="paragraph_close"?r=i.tokens.pop():r=null,s=o[e].count>0?o[e].count:1,n=0;n<s;n++)i.tokens.push({type:"footnote_anchor",id:e,subId:n,level:d});r&&i.tokens.push(r),i.tokens.push({type:"footnote_close",level:--d});}i.tokens.push({type:"footnote_block_close",level:--d});}}var qr=" \n()[]'\".,!?-";function ki(i){return i.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1");}function ec(i){var e,t,n,s,r,o,a,c,l,d,p,u,g=i.tokens;if(i.env.abbreviations){for(i.env.abbrRegExp||(u="(^|["+qr.split("").map(ki).join("")+"])("+Object.keys(i.env.abbreviations).map(function(y){return y.substr(1);}).sort(function(y,_){return _.length-y.length;}).map(ki).join("|")+")($|["+qr.split("").map(ki).join("")+"])",i.env.abbrRegExp=new RegExp(u,"g")),d=i.env.abbrRegExp,t=0,n=g.length;t<n;t++)if(g[t].type==="inline"){for(s=g[t].children,e=s.length-1;e>=0;e--)if(r=s[e],r.type==="text"){for(c=0,o=r.content,d.lastIndex=0,l=r.level,a=[];p=d.exec(o);)d.lastIndex>c&&a.push({type:"text",content:o.slice(c,p.index+p[1].length),level:l}),a.push({type:"abbr_open",title:i.env.abbreviations[":"+p[2]],level:l++}),a.push({type:"text",content:p[2],level:l}),a.push({type:"abbr_close",level:--l}),c=d.lastIndex-p[3].length;a.length&&(c<o.length&&a.push({type:"text",content:o.slice(c),level:l}),g[t].children=s=[].concat(s.slice(0,e),a,s.slice(e+1)));}}}}var tc=/\+-|\.\.|\?\?\?\?|!!!!|,,|--/,nc=/\((c|tm|r|p)\)/ig,sc={c:"©",r:"®",p:"§",tm:"™"};function ic(i){return i.indexOf("(")<0?i:i.replace(nc,function(e,t){return sc[t.toLowerCase()];});}function rc(i){var e,t,n,s,r;if(i.options.typographer){for(r=i.tokens.length-1;r>=0;r--)if(i.tokens[r].type==="inline")for(s=i.tokens[r].children,e=s.length-1;e>=0;e--)t=s[e],t.type==="text"&&(n=t.content,n=ic(n),tc.test(n)&&(n=n.replace(/\+-/g,"±").replace(/\.{2,}/g,"…").replace(/([?!])…/g,"$1..").replace(/([?!]){4,}/g,"$1$1$1").replace(/,{2,}/g,",").replace(/(^|[^-])---([^-]|$)/mg,"$1—$2").replace(/(^|\s)--(\s|$)/mg,"$1–$2").replace(/(^|[^-\s])--([^-\s]|$)/mg,"$1–$2")),t.content=n);}}var oc=/['"]/,Gr=/['"]/g,ac=/[-\s()\[\]]/,zr="’";function Vr(i,e){return e<0||e>=i.length?!1:!ac.test(i[e]);}function yn(i,e,t){return i.substr(0,e)+t+i.substr(e+1);}function cc(i){var e,t,n,s,r,o,a,c,l,d,p,u,g,y,_,S,M;if(i.options.typographer){for(M=[],_=i.tokens.length-1;_>=0;_--)if(i.tokens[_].type==="inline"){for(S=i.tokens[_].children,M.length=0,e=0;e<S.length;e++)if(t=S[e],!(t.type!=="text"||oc.test(t.text))){for(a=S[e].level,g=M.length-1;g>=0&&!(M[g].level<=a);g--);M.length=g+1,n=t.content,r=0,o=n.length;e:for(;r<o&&(Gr.lastIndex=r,s=Gr.exec(n),!!s);){if(c=!Vr(n,s.index-1),r=s.index+1,y=s[0]==="'",l=!Vr(n,r),!l&&!c){y&&(t.content=yn(t.content,s.index,zr));continue;}if(p=!l,u=!c,u){for(g=M.length-1;g>=0&&(d=M[g],!(M[g].level<a));g--)if(d.single===y&&M[g].level===a){d=M[g],y?(S[d.token].content=yn(S[d.token].content,d.pos,i.options.quotes[2]),t.content=yn(t.content,s.index,i.options.quotes[3])):(S[d.token].content=yn(S[d.token].content,d.pos,i.options.quotes[0]),t.content=yn(t.content,s.index,i.options.quotes[1])),M.length=g;continue e;}}p?M.push({token:e,pos:s.index,single:y,level:a}):u&&y&&(t.content=yn(t.content,s.index,zr));}}}}}var Pi=[["block",Ka],["abbr",Xa],["references",Ya],["inline",Ja],["footnote_tail",Qa],["abbr2",ec],["replacements",rc],["smartquotes",cc]];function Wo(){this.options={},this.ruler=new Ye();for(var i=0;i<Pi.length;i++)this.ruler.push(Pi[i][0],Pi[i][1]);}Wo.prototype.process=function(i){var e,t,n;for(n=this.ruler.getRules(""),e=0,t=n.length;e<t;e++)n[e](i);};function mn(i,e,t,n,s){var r,o,a,c,l,d,p;for(this.src=i,this.parser=e,this.options=t,this.env=n,this.tokens=s,this.bMarks=[],this.eMarks=[],this.tShift=[],this.blkIndent=0,this.line=0,this.lineMax=0,this.tight=!1,this.parentType="root",this.ddIndent=-1,this.level=0,this.result="",o=this.src,d=0,p=!1,a=c=d=0,l=o.length;c<l;c++){if(r=o.charCodeAt(c),!p)if(r===32){d++;continue;}else p=!0;(r===10||c===l-1)&&(r!==10&&c++,this.bMarks.push(a),this.eMarks.push(c),this.tShift.push(d),p=!1,d=0,a=c+1);}this.bMarks.push(o.length),this.eMarks.push(o.length),this.tShift.push(0),this.lineMax=this.bMarks.length-1;}mn.prototype.isEmpty=function(e){return this.bMarks[e]+this.tShift[e]>=this.eMarks[e];};mn.prototype.skipEmptyLines=function(e){for(var t=this.lineMax;e<t&&!(this.bMarks[e]+this.tShift[e]<this.eMarks[e]);e++);return e;};mn.prototype.skipSpaces=function(e){for(var t=this.src.length;e<t&&this.src.charCodeAt(e)===32;e++);return e;};mn.prototype.skipChars=function(e,t){for(var n=this.src.length;e<n&&this.src.charCodeAt(e)===t;e++);return e;};mn.prototype.skipCharsBack=function(e,t,n){if(e<=n)return e;for(;e>n;)if(t!==this.src.charCodeAt(--e))return e+1;return e;};mn.prototype.getLines=function(e,t,n,s){var r,o,a,c,l,d=e;if(e>=t)return"";if(d+1===t)return o=this.bMarks[d]+Math.min(this.tShift[d],n),a=s?this.eMarks[d]+1:this.eMarks[d],this.src.slice(o,a);for(c=new Array(t-e),r=0;d<t;d++,r++)l=this.tShift[d],l>n&&(l=n),l<0&&(l=0),o=this.bMarks[d]+l,d+1<t||s?a=this.eMarks[d]+1:a=this.eMarks[d],c[r]=this.src.slice(o,a);return c.join("");};function lc(i,e,t){var n,s;if(i.tShift[e]-i.blkIndent<4)return!1;for(s=n=e+1;n<t;){if(i.isEmpty(n)){n++;continue;}if(i.tShift[n]-i.blkIndent>=4){n++,s=n;continue;}break;}return i.line=n,i.tokens.push({type:"code",content:i.getLines(e,s,4+i.blkIndent,!0),block:!0,lines:[e,i.line],level:i.level}),!0;}function dc(i,e,t,n){var s,r,o,a,c,l=!1,d=i.bMarks[e]+i.tShift[e],p=i.eMarks[e];if(d+3>p||(s=i.src.charCodeAt(d),s!==126&&s!==96)||(c=d,d=i.skipChars(d,s),r=d-c,r<3)||(o=i.src.slice(d,p).trim(),o.indexOf("`")>=0))return!1;if(n)return!0;for(a=e;a++,!(a>=t||(d=c=i.bMarks[a]+i.tShift[a],p=i.eMarks[a],d<p&&i.tShift[a]<i.blkIndent));)if(i.src.charCodeAt(d)===s&&!(i.tShift[a]-i.blkIndent>=4)&&(d=i.skipChars(d,s),!(d-c<r)&&(d=i.skipSpaces(d),!(d<p)))){l=!0;break;}return r=i.tShift[e],i.line=a+(l?1:0),i.tokens.push({type:"fence",params:o,content:i.getLines(e+1,a,r,!0),lines:[e,i.line],level:i.level}),!0;}function hc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_=i.bMarks[e]+i.tShift[e],S=i.eMarks[e];if(_>S||i.src.charCodeAt(_++)!==62||i.level>=i.options.maxNesting)return!1;if(n)return!0;for(i.src.charCodeAt(_)===32&&_++,c=i.blkIndent,i.blkIndent=0,a=[i.bMarks[e]],i.bMarks[e]=_,_=_<S?i.skipSpaces(_):_,r=_>=S,o=[i.tShift[e]],i.tShift[e]=_-i.bMarks[e],p=i.parser.ruler.getRules("blockquote"),s=e+1;s<t&&(_=i.bMarks[s]+i.tShift[s],S=i.eMarks[s],!(_>=S));s++){if(i.src.charCodeAt(_++)===62){i.src.charCodeAt(_)===32&&_++,a.push(i.bMarks[s]),i.bMarks[s]=_,_=_<S?i.skipSpaces(_):_,r=_>=S,o.push(i.tShift[s]),i.tShift[s]=_-i.bMarks[s];continue;}if(r)break;for(y=!1,u=0,g=p.length;u<g;u++)if(p[u](i,s,t,!0)){y=!0;break;}if(y)break;a.push(i.bMarks[s]),o.push(i.tShift[s]),i.tShift[s]=-1337;}for(l=i.parentType,i.parentType="blockquote",i.tokens.push({type:"blockquote_open",lines:d=[e,0],level:i.level++}),i.parser.tokenize(i,e,s),i.tokens.push({type:"blockquote_close",level:--i.level}),i.parentType=l,d[1]=i.line,u=0;u<o.length;u++)i.bMarks[u+e]=a[u],i.tShift[u+e]=o[u];return i.blkIndent=c,!0;}function uc(i,e,t,n){var s,r,o,a=i.bMarks[e],c=i.eMarks[e];if(a+=i.tShift[e],a>c||(s=i.src.charCodeAt(a++),s!==42&&s!==45&&s!==95))return!1;for(r=1;a<c;){if(o=i.src.charCodeAt(a++),o!==s&&o!==32)return!1;o===s&&r++;}return r<3?!1:(n||(i.line=e+1,i.tokens.push({type:"hr",lines:[e,i.line],level:i.level})),!0);}function Kr(i,e){var t,n,s;return n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e],n>=s||(t=i.src.charCodeAt(n++),t!==42&&t!==45&&t!==43)||n<s&&i.src.charCodeAt(n)!==32?-1:n;}function Wr(i,e){var t,n=i.bMarks[e]+i.tShift[e],s=i.eMarks[e];if(n+1>=s||(t=i.src.charCodeAt(n++),t<48||t>57))return-1;for(;;){if(n>=s)return-1;if(t=i.src.charCodeAt(n++),!(t>=48&&t<=57)){if(t===41||t===46)break;return-1;}}return n<s&&i.src.charCodeAt(n)!==32?-1:n;}function pc(i,e){var t,n,s=i.level+2;for(t=e+2,n=i.tokens.length-2;t<n;t++)i.tokens[t].level===s&&i.tokens[t].type==="paragraph_open"&&(i.tokens[t+2].tight=!0,i.tokens[t].tight=!0,t+=2);}function fc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_,S,M,K,ie,re,Re,Lt=!0,Ot,ze,Lr,Ri;if((p=Wr(i,e))>=0)S=!0;else if((p=Kr(i,e))>=0)S=!1;else return!1;if(i.level>=i.options.maxNesting)return!1;if(_=i.src.charCodeAt(p-1),n)return!0;for(K=i.tokens.length,S?(d=i.bMarks[e]+i.tShift[e],y=Number(i.src.substr(d,p-d-1)),i.tokens.push({type:"ordered_list_open",order:y,lines:re=[e,0],level:i.level++})):i.tokens.push({type:"bullet_list_open",lines:re=[e,0],level:i.level++}),s=e,ie=!1,Ot=i.parser.ruler.getRules("list");s<t&&(M=i.skipSpaces(p),u=i.eMarks[s],M>=u?g=1:g=M-p,g>4&&(g=1),g<1&&(g=1),r=p-i.bMarks[s]+g,i.tokens.push({type:"list_item_open",lines:Re=[e,0],level:i.level++}),a=i.blkIndent,c=i.tight,o=i.tShift[e],l=i.parentType,i.tShift[e]=M-i.bMarks[e],i.blkIndent=r,i.tight=!0,i.parentType="list",i.parser.tokenize(i,e,t,!0),(!i.tight||ie)&&(Lt=!1),ie=i.line-e>1&&i.isEmpty(i.line-1),i.blkIndent=a,i.tShift[e]=o,i.tight=c,i.parentType=l,i.tokens.push({type:"list_item_close",level:--i.level}),s=e=i.line,Re[1]=s,M=i.bMarks[e],!(s>=t||i.isEmpty(s)||i.tShift[s]<i.blkIndent));){for(Ri=!1,ze=0,Lr=Ot.length;ze<Lr;ze++)if(Ot[ze](i,s,t,!0)){Ri=!0;break;}if(Ri)break;if(S){if(p=Wr(i,s),p<0)break;}else if(p=Kr(i,s),p<0)break;if(_!==i.src.charCodeAt(p-1))break;}return i.tokens.push({type:S?"ordered_list_close":"bullet_list_close",level:--i.level}),re[1]=s,i.line=s,Lt&&pc(i,K),!0;}function mc(i,e,t,n){var s,r,o,a,c,l=i.bMarks[e]+i.tShift[e],d=i.eMarks[e];if(l+4>d||i.src.charCodeAt(l)!==91||i.src.charCodeAt(l+1)!==94||i.level>=i.options.maxNesting)return!1;for(a=l+2;a<d;a++){if(i.src.charCodeAt(a)===32)return!1;if(i.src.charCodeAt(a)===93)break;}return a===l+2||a+1>=d||i.src.charCodeAt(++a)!==58?!1:(n||(a++,i.env.footnotes||(i.env.footnotes={}),i.env.footnotes.refs||(i.env.footnotes.refs={}),c=i.src.slice(l+2,a-2),i.env.footnotes.refs[":"+c]=-1,i.tokens.push({type:"footnote_reference_open",label:c,level:i.level++}),s=i.bMarks[e],r=i.tShift[e],o=i.parentType,i.tShift[e]=i.skipSpaces(a)-a,i.bMarks[e]=a,i.blkIndent+=4,i.parentType="footnote",i.tShift[e]<i.blkIndent&&(i.tShift[e]+=i.blkIndent,i.bMarks[e]-=i.blkIndent),i.parser.tokenize(i,e,t,!0),i.parentType=o,i.blkIndent-=4,i.tShift[e]=r,i.bMarks[e]=s,i.tokens.push({type:"footnote_reference_close",level:--i.level})),!0);}function gc(i,e,t,n){var s,r,o,a=i.bMarks[e]+i.tShift[e],c=i.eMarks[e];if(a>=c||(s=i.src.charCodeAt(a),s!==35||a>=c))return!1;for(r=1,s=i.src.charCodeAt(++a);s===35&&a<c&&r<=6;)r++,s=i.src.charCodeAt(++a);return r>6||a<c&&s!==32?!1:(n||(c=i.skipCharsBack(c,32,a),o=i.skipCharsBack(c,35,a),o>a&&i.src.charCodeAt(o-1)===32&&(c=o),i.line=e+1,i.tokens.push({type:"heading_open",hLevel:r,lines:[e,i.line],level:i.level}),a<c&&i.tokens.push({type:"inline",content:i.src.slice(a,c).trim(),level:i.level+1,lines:[e,i.line],children:[]}),i.tokens.push({type:"heading_close",hLevel:r,level:i.level})),!0);}function bc(i,e,t){var n,s,r,o=e+1;return o>=t||i.tShift[o]<i.blkIndent||i.tShift[o]-i.blkIndent>3||(s=i.bMarks[o]+i.tShift[o],r=i.eMarks[o],s>=r)||(n=i.src.charCodeAt(s),n!==45&&n!==61)||(s=i.skipChars(s,n),s=i.skipSpaces(s),s<r)?!1:(s=i.bMarks[e]+i.tShift[e],i.line=o+1,i.tokens.push({type:"heading_open",hLevel:n===61?1:2,lines:[e,i.line],level:i.level}),i.tokens.push({type:"inline",content:i.src.slice(s,i.eMarks[e]).trim(),level:i.level+1,lines:[e,i.line-1],children:[]}),i.tokens.push({type:"heading_close",hLevel:n===61?1:2,level:i.level}),!0);}var Xo={};["article","aside","button","blockquote","body","canvas","caption","col","colgroup","dd","div","dl","dt","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","iframe","li","map","object","ol","output","p","pre","progress","script","section","style","table","tbody","td","textarea","tfoot","th","tr","thead","ul","video"].forEach(function(i){Xo[i]=!0;});var yc=/^<([a-zA-Z]{1,15})[\s\/>]/,_c=/^<\/([a-zA-Z]{1,15})[\s>]/;function Ec(i){var e=i|32;return e>=97&&e<=122;}function vc(i,e,t,n){var s,r,o,a=i.bMarks[e],c=i.eMarks[e],l=i.tShift[e];if(a+=l,!i.options.html||l>3||a+2>=c||i.src.charCodeAt(a)!==60)return!1;if(s=i.src.charCodeAt(a+1),s===33||s===63){if(n)return!0;}else if(s===47||Ec(s)){if(s===47){if(r=i.src.slice(a,c).match(_c),!r)return!1;}else if(r=i.src.slice(a,c).match(yc),!r)return!1;if(Xo[r[1].toLowerCase()]!==!0)return!1;if(n)return!0;}else return!1;for(o=e+1;o<i.lineMax&&!i.isEmpty(o);)o++;return i.line=o,i.tokens.push({type:"htmlblock",level:i.level,lines:[e,i.line],content:i.getLines(e,o,0,!0)}),!0;}function Li(i,e){var t=i.bMarks[e]+i.blkIndent,n=i.eMarks[e];return i.src.substr(t,n-t);}function Sc(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y;if(e+2>t||(c=e+1,i.tShift[c]<i.blkIndent)||(o=i.bMarks[c]+i.tShift[c],o>=i.eMarks[c])||(s=i.src.charCodeAt(o),s!==124&&s!==45&&s!==58)||(r=Li(i,e+1),!/^[-:| ]+$/.test(r))||(l=r.split("|"),l<=2))return!1;for(p=[],a=0;a<l.length;a++){if(u=l[a].trim(),!u){if(a===0||a===l.length-1)continue;return!1;}if(!/^:?-+:?$/.test(u))return!1;u.charCodeAt(u.length-1)===58?p.push(u.charCodeAt(0)===58?"center":"right"):u.charCodeAt(0)===58?p.push("left"):p.push("");}if(r=Li(i,e).trim(),r.indexOf("|")===-1||(l=r.replace(/^\||\|$/g,"").split("|"),p.length!==l.length))return!1;if(n)return!0;for(i.tokens.push({type:"table_open",lines:g=[e,0],level:i.level++}),i.tokens.push({type:"thead_open",lines:[e,e+1],level:i.level++}),i.tokens.push({type:"tr_open",lines:[e,e+1],level:i.level++}),a=0;a<l.length;a++)i.tokens.push({type:"th_open",align:p[a],lines:[e,e+1],level:i.level++}),i.tokens.push({type:"inline",content:l[a].trim(),lines:[e,e+1],level:i.level,children:[]}),i.tokens.push({type:"th_close",level:--i.level});for(i.tokens.push({type:"tr_close",level:--i.level}),i.tokens.push({type:"thead_close",level:--i.level}),i.tokens.push({type:"tbody_open",lines:y=[e+2,0],level:i.level++}),c=e+2;c<t&&!(i.tShift[c]<i.blkIndent||(r=Li(i,c).trim(),r.indexOf("|")===-1));c++){for(l=r.replace(/^\||\|$/g,"").split("|"),i.tokens.push({type:"tr_open",level:i.level++}),a=0;a<l.length;a++)i.tokens.push({type:"td_open",align:p[a],level:i.level++}),d=l[a].substring(l[a].charCodeAt(0)===124?1:0,l[a].charCodeAt(l[a].length-1)===124?l[a].length-1:l[a].length).trim(),i.tokens.push({type:"inline",content:d,level:i.level,children:[]}),i.tokens.push({type:"td_close",level:--i.level});i.tokens.push({type:"tr_close",level:--i.level});}return i.tokens.push({type:"tbody_close",level:--i.level}),i.tokens.push({type:"table_close",level:--i.level}),g[1]=y[1]=c,i.line=c,!0;}function Fs(i,e){var t,n,s=i.bMarks[e]+i.tShift[e],r=i.eMarks[e];return s>=r||(n=i.src.charCodeAt(s++),n!==126&&n!==58)||(t=i.skipSpaces(s),s===t)||t>=r?-1:t;}function xc(i,e){var t,n,s=i.level+2;for(t=e+2,n=i.tokens.length-2;t<n;t++)i.tokens[t].level===s&&i.tokens[t].type==="paragraph_open"&&(i.tokens[t+2].tight=!0,i.tokens[t].tight=!0,t+=2);}function Ac(i,e,t,n){var s,r,o,a,c,l,d,p,u,g,y,_,S,M;if(n)return i.ddIndent<0?!1:Fs(i,e)>=0;if(d=e+1,i.isEmpty(d)&&++d>t||i.tShift[d]<i.blkIndent||(s=Fs(i,d),s<0)||i.level>=i.options.maxNesting)return!1;l=i.tokens.length,i.tokens.push({type:"dl_open",lines:c=[e,0],level:i.level++}),o=e,r=d;e:for(;;){for(M=!0,S=!1,i.tokens.push({type:"dt_open",lines:[o,o],level:i.level++}),i.tokens.push({type:"inline",content:i.getLines(o,o+1,i.blkIndent,!1).trim(),level:i.level+1,lines:[o,o],children:[]}),i.tokens.push({type:"dt_close",level:--i.level});;){if(i.tokens.push({type:"dd_open",lines:a=[d,0],level:i.level++}),_=i.tight,u=i.ddIndent,p=i.blkIndent,y=i.tShift[r],g=i.parentType,i.blkIndent=i.ddIndent=i.tShift[r]+2,i.tShift[r]=s-i.bMarks[r],i.tight=!0,i.parentType="deflist",i.parser.tokenize(i,r,t,!0),(!i.tight||S)&&(M=!1),S=i.line-r>1&&i.isEmpty(i.line-1),i.tShift[r]=y,i.tight=_,i.parentType=g,i.blkIndent=p,i.ddIndent=u,i.tokens.push({type:"dd_close",level:--i.level}),a[1]=d=i.line,d>=t||i.tShift[d]<i.blkIndent)break e;if(s=Fs(i,d),s<0)break;r=d;}if(d>=t||(o=d,i.isEmpty(o))||i.tShift[o]<i.blkIndent||(r=o+1,r>=t)||(i.isEmpty(r)&&r++,r>=t)||i.tShift[r]<i.blkIndent||(s=Fs(i,r),s<0))break;}return i.tokens.push({type:"dl_close",level:--i.level}),c[1]=d,i.line=d,M&&xc(i,l),!0;}function wc(i,e){var t,n,s,r,o,a=e+1,c;if(t=i.lineMax,a<t&&!i.isEmpty(a)){for(c=i.parser.ruler.getRules("paragraph");a<t&&!i.isEmpty(a);a++)if(!(i.tShift[a]-i.blkIndent>3)){for(s=!1,r=0,o=c.length;r<o;r++)if(c[r](i,a,t,!0)){s=!0;break;}if(s)break;}}return n=i.getLines(e,a,i.blkIndent,!1).trim(),i.line=a,n.length&&(i.tokens.push({type:"paragraph_open",tight:!1,lines:[e,i.line],level:i.level}),i.tokens.push({type:"inline",content:n,level:i.level+1,lines:[e,i.line],children:[]}),i.tokens.push({type:"paragraph_close",tight:!1,level:i.level})),!0;}var Us=[["code",lc],["fences",dc,["paragraph","blockquote","list"]],["blockquote",hc,["paragraph","blockquote","list"]],["hr",uc,["paragraph","blockquote","list"]],["list",fc,["paragraph","blockquote"]],["footnote",mc,["paragraph"]],["heading",gc,["paragraph","blockquote"]],["lheading",bc],["htmlblock",vc,["paragraph","blockquote"]],["table",Sc,["paragraph"]],["deflist",Ac,["paragraph"]],["paragraph",wc]];function hr(){this.ruler=new Ye();for(var i=0;i<Us.length;i++)this.ruler.push(Us[i][0],Us[i][1],{alt:(Us[i][2]||[]).slice()});}hr.prototype.tokenize=function(i,e,t){for(var n=this.ruler.getRules(""),s=n.length,r=e,o=!1,a,c;r<t&&(i.line=r=i.skipEmptyLines(r),!(r>=t||i.tShift[r]<i.blkIndent));){for(c=0;c<s&&(a=n[c](i,r,t,!1),!a);c++);if(i.tight=!o,i.isEmpty(i.line-1)&&(o=!0),r=i.line,r<t&&i.isEmpty(r)){if(o=!0,r++,r<t&&i.parentType==="list"&&i.isEmpty(r))break;i.line=r;}}};var Cc=/[\n\t]/g,Tc=/\r[\n\u0085]|[\u2424\u2028\u0085]/g,Rc=/\u00a0/g;hr.prototype.parse=function(i,e,t,n){var s,r=0,o=0;if(!i)return[];i=i.replace(Rc," "),i=i.replace(Tc,"\n"),i.indexOf(" ")>=0&&(i=i.replace(Cc,function(a,c){var l;return i.charCodeAt(c)===10?(r=c+1,o=0,a):(l=" ".slice((c-r-o)%4),o=c-r+1,l);})),s=new mn(i,this,e,t,n),this.tokenize(s,s.line,s.lineMax);};function Ic(i){switch(i){case 10:case 92:case 96:case 42:case 95:case 94:case 91:case 93:case 33:case 38:case 60:case 62:case 123:case 125:case 36:case 37:case 64:case 126:case 43:case 61:case 58:return!0;default:return!1;}}function Mc(i,e){for(var t=i.pos;t<i.posMax&&!Ic(i.src.charCodeAt(t));)t++;return t===i.pos?!1:(e||(i.pending+=i.src.slice(i.pos,t)),i.pos=t,!0);}function kc(i,e){var t,n,s=i.pos;if(i.src.charCodeAt(s)!==10)return!1;if(t=i.pending.length-1,n=i.posMax,!e)if(t>=0&&i.pending.charCodeAt(t)===32){if(t>=1&&i.pending.charCodeAt(t-1)===32){for(var r=t-2;r>=0;r--)if(i.pending.charCodeAt(r)!==32){i.pending=i.pending.substring(0,r+1);break;}i.push({type:"hardbreak",level:i.level});}else i.pending=i.pending.slice(0,-1),i.push({type:"softbreak",level:i.level});}else i.push({type:"softbreak",level:i.level});for(s++;s<n&&i.src.charCodeAt(s)===32;)s++;return i.pos=s,!0;}var ur=[];for(var Xr=0;Xr<256;Xr++)ur.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(i){ur[i.charCodeAt(0)]=1;});function Pc(i,e){var t,n=i.pos,s=i.posMax;if(i.src.charCodeAt(n)!==92)return!1;if(n++,n<s){if(t=i.src.charCodeAt(n),t<256&&ur[t]!==0)return e||(i.pending+=i.src[n]),i.pos+=2,!0;if(t===10){for(e||i.push({type:"hardbreak",level:i.level}),n++;n<s&&i.src.charCodeAt(n)===32;)n++;return i.pos=n,!0;}}return e||(i.pending+="\\"),i.pos++,!0;}function Lc(i,e){var t,n,s,r,o,a=i.pos,c=i.src.charCodeAt(a);if(c!==96)return!1;for(t=a,a++,n=i.posMax;a<n&&i.src.charCodeAt(a)===96;)a++;for(s=i.src.slice(t,a),r=o=a;(r=i.src.indexOf("`",o))!==-1;){for(o=r+1;o<n&&i.src.charCodeAt(o)===96;)o++;if(o-r===s.length)return e||i.push({type:"code",content:i.src.slice(a,r).replace(/[ \n]+/g," ").trim(),block:!1,level:i.level}),i.pos=o,!0;}return e||(i.pending+=s),i.pos+=s.length,!0;}function Oc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==126||e||o+4>=r||i.src.charCodeAt(o+1)!==126||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===126)||c===126||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===126;)n++;if(n>o+3)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===126&&i.src.charCodeAt(i.pos+1)===126&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==126&&a!==126&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"del_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"del_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function Nc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==43||e||o+4>=r||i.src.charCodeAt(o+1)!==43||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===43)||c===43||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===43;)n++;if(n!==o+2)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===43&&i.src.charCodeAt(i.pos+1)===43&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==43&&a!==43&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"ins_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"ins_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function Bc(i,e){var t,n,s,r=i.posMax,o=i.pos,a,c;if(i.src.charCodeAt(o)!==61||e||o+4>=r||i.src.charCodeAt(o+1)!==61||i.level>=i.options.maxNesting||(a=o>0?i.src.charCodeAt(o-1):-1,c=i.src.charCodeAt(o+2),a===61)||c===61||c===32||c===10)return!1;for(n=o+2;n<r&&i.src.charCodeAt(n)===61;)n++;if(n!==o+2)return i.pos+=n-o,e||(i.pending+=i.src.slice(o,n)),!0;for(i.pos=o+2,s=1;i.pos+1<r;){if(i.src.charCodeAt(i.pos)===61&&i.src.charCodeAt(i.pos+1)===61&&(a=i.src.charCodeAt(i.pos-1),c=i.pos+2<r?i.src.charCodeAt(i.pos+2):-1,c!==61&&a!==61&&(a!==32&&a!==10?s--:c!==32&&c!==10&&s++,s<=0))){t=!0;break;}i.parser.skipToken(i);}return t?(i.posMax=i.pos,i.pos=o+2,e||(i.push({type:"mark_open",level:i.level++}),i.parser.tokenize(i),i.push({type:"mark_close",level:--i.level})),i.pos=i.posMax+2,i.posMax=r,!0):(i.pos=o,!1);}function Zr(i){return i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122;}function Yr(i,e){var t=e,n,s,r,o=!0,a=!0,c=i.posMax,l=i.src.charCodeAt(e);for(n=e>0?i.src.charCodeAt(e-1):-1;t<c&&i.src.charCodeAt(t)===l;)t++;return t>=c&&(o=!1),r=t-e,r>=4?o=a=!1:(s=t<c?i.src.charCodeAt(t):-1,(s===32||s===10)&&(o=!1),(n===32||n===10)&&(a=!1),l===95&&(Zr(n)&&(o=!1),Zr(s)&&(a=!1))),{can_open:o,can_close:a,delims:r};}function Dc(i,e){var t,n,s,r,o,a,c,l=i.posMax,d=i.pos,p=i.src.charCodeAt(d);if(p!==95&&p!==42||e)return!1;if(c=Yr(i,d),t=c.delims,!c.can_open)return i.pos+=t,e||(i.pending+=i.src.slice(d,i.pos)),!0;if(i.level>=i.options.maxNesting)return!1;for(i.pos=d+t,a=[t];i.pos<l;){if(i.src.charCodeAt(i.pos)===p){if(c=Yr(i,i.pos),n=c.delims,c.can_close){for(r=a.pop(),o=n;r!==o;){if(o<r){a.push(r-o);break;}if(o-=r,a.length===0)break;i.pos+=r,r=a.pop();}if(a.length===0){t=r,s=!0;break;}i.pos+=n;continue;}c.can_open&&a.push(n),i.pos+=n;continue;}i.parser.skipToken(i);}return s?(i.posMax=i.pos,i.pos=d+t,e||((t===2||t===3)&&i.push({type:"strong_open",level:i.level++}),(t===1||t===3)&&i.push({type:"em_open",level:i.level++}),i.parser.tokenize(i),(t===1||t===3)&&i.push({type:"em_close",level:--i.level}),(t===2||t===3)&&i.push({type:"strong_close",level:--i.level})),i.pos=i.posMax+t,i.posMax=l,!0):(i.pos=d,!1);}var Fc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function Uc(i,e){var t,n,s=i.posMax,r=i.pos;if(i.src.charCodeAt(r)!==126||e||r+2>=s||i.level>=i.options.maxNesting)return!1;for(i.pos=r+1;i.pos<s;){if(i.src.charCodeAt(i.pos)===126){t=!0;break;}i.parser.skipToken(i);}return!t||r+1===i.pos||(n=i.src.slice(r+1,i.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(i.pos=r,!1):(i.posMax=i.pos,i.pos=r+1,e||i.push({type:"sub",level:i.level,content:n.replace(Fc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}var Hc=/\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;function jc(i,e){var t,n,s=i.posMax,r=i.pos;if(i.src.charCodeAt(r)!==94||e||r+2>=s||i.level>=i.options.maxNesting)return!1;for(i.pos=r+1;i.pos<s;){if(i.src.charCodeAt(i.pos)===94){t=!0;break;}i.parser.skipToken(i);}return!t||r+1===i.pos||(n=i.src.slice(r+1,i.pos),n.match(/(^|[^\\])(\\\\)*\s/))?(i.pos=r,!1):(i.posMax=i.pos,i.pos=r+1,e||i.push({type:"sup",level:i.level,content:n.replace(Hc,"$1")}),i.pos=i.posMax+1,i.posMax=s,!0);}function $c(i,e){var t,n,s,r,o,a,c,l,d=!1,p=i.pos,u=i.posMax,g=i.pos,y=i.src.charCodeAt(g);if(y===33&&(d=!0,y=i.src.charCodeAt(++g)),y!==91||i.level>=i.options.maxNesting||(t=g+1,n=As(i,g),n<0))return!1;if(a=n+1,a<u&&i.src.charCodeAt(a)===40){for(a++;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a>=u)return!1;for(g=a,zo(i,a)?(r=i.linkContent,a=i.pos):r="",g=a;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<u&&g!==a&&Vo(i,a))for(o=i.linkContent,a=i.pos;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);else o="";if(a>=u||i.src.charCodeAt(a)!==41)return i.pos=p,!1;a++;}else{if(i.linkLevel>0)return!1;for(;a<u&&(l=i.src.charCodeAt(a),!(l!==32&&l!==10));a++);if(a<u&&i.src.charCodeAt(a)===91&&(g=a+1,a=As(i,a),a>=0?s=i.src.slice(g,a++):a=g-1),s||(_typeof(s)>"u"&&(a=n+1),s=i.src.slice(t,n)),c=i.env.references[Ko(s)],!c)return i.pos=p,!1;r=c.href,o=c.title;}return e||(i.pos=t,i.posMax=n,d?i.push({type:"image",src:r,title:o,alt:i.src.substr(t,n-t),level:i.level}):(i.push({type:"link_open",href:r,title:o,level:i.level++}),i.linkLevel++,i.parser.tokenize(i),i.linkLevel--,i.push({type:"link_close",level:--i.level}))),i.pos=a,i.posMax=u,!0;}function qc(i,e){var t,n,s,r,o=i.posMax,a=i.pos;return a+2>=o||i.src.charCodeAt(a)!==94||i.src.charCodeAt(a+1)!==91||i.level>=i.options.maxNesting||(t=a+2,n=As(i,a+1),n<0)?!1:(e||(i.env.footnotes||(i.env.footnotes={}),i.env.footnotes.list||(i.env.footnotes.list=[]),s=i.env.footnotes.list.length,i.pos=t,i.posMax=n,i.push({type:"footnote_ref",id:s,level:i.level}),i.linkLevel++,r=i.tokens.length,i.parser.tokenize(i),i.env.footnotes.list[s]={tokens:i.tokens.splice(r)},i.linkLevel--),i.pos=n+1,i.posMax=o,!0);}function Gc(i,e){var t,n,s,r,o=i.posMax,a=i.pos;if(a+3>o||!i.env.footnotes||!i.env.footnotes.refs||i.src.charCodeAt(a)!==91||i.src.charCodeAt(a+1)!==94||i.level>=i.options.maxNesting)return!1;for(n=a+2;n<o;n++){if(i.src.charCodeAt(n)===32||i.src.charCodeAt(n)===10)return!1;if(i.src.charCodeAt(n)===93)break;}return n===a+2||n>=o||(n++,t=i.src.slice(a+2,n-1),_typeof(i.env.footnotes.refs[":"+t])>"u")?!1:(e||(i.env.footnotes.list||(i.env.footnotes.list=[]),i.env.footnotes.refs[":"+t]<0?(s=i.env.footnotes.list.length,i.env.footnotes.list[s]={label:t,count:0},i.env.footnotes.refs[":"+t]=s):s=i.env.footnotes.refs[":"+t],r=i.env.footnotes.list[s].count,i.env.footnotes.list[s].count++,i.push({type:"footnote_ref",id:s,subId:r,level:i.level})),i.pos=n,i.posMax=o,!0);}var zc=["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"],Vc=/^<([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])?)*)>/,Kc=/^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;function Wc(i,e){var t,n,s,r,o,a=i.pos;return i.src.charCodeAt(a)!==60||(t=i.src.slice(a),t.indexOf(">")<0)?!1:(n=t.match(Kc),n?zc.indexOf(n[1].toLowerCase())<0||(r=n[0].slice(1,-1),o=Hi(r),!i.parser.validateLink(r))?!1:(e||(i.push({type:"link_open",href:o,level:i.level}),i.push({type:"text",content:r,level:i.level+1}),i.push({type:"link_close",level:i.level})),i.pos+=n[0].length,!0):(s=t.match(Vc),s?(r=s[0].slice(1,-1),o=Hi("mailto:"+r),i.parser.validateLink(o)?(e||(i.push({type:"link_open",href:o,level:i.level}),i.push({type:"text",content:r,level:i.level+1}),i.push({type:"link_close",level:i.level})),i.pos+=s[0].length,!0):!1):!1));}function _i(i,e){return i=i.source,e=e||"",function t(n,s){return n?(s=s.source||s,i=i.replace(n,s),t):new RegExp(i,e);};}var Xc=/[a-zA-Z_:][a-zA-Z0-9:._-]*/,Zc=/[^"'=<>`\x00-\x20]+/,Yc=/'[^']*'/,Jc=/"[^"]*"/,Qc=_i(/(?:unquoted|single_quoted|double_quoted)/)("unquoted",Zc)("single_quoted",Yc)("double_quoted",Jc)(),el=_i(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name",Xc)("attr_value",Qc)(),tl=_i(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute",el)(),nl=/<\/[A-Za-z][A-Za-z0-9]*\s*>/,sl=/<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/,il=/<[?].*?[?]>/,rl=/<![A-Z]+\s+[^>]*>/,ol=/<!\[CDATA\[[\s\S]*?\]\]>/,al=_i(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag",tl)("close_tag",nl)("comment",sl)("processing",il)("declaration",rl)("cdata",ol)();function cl(i){var e=i|32;return e>=97&&e<=122;}function ll(i,e){var t,n,s,r=i.pos;return!i.options.html||(s=i.posMax,i.src.charCodeAt(r)!==60||r+2>=s)||(t=i.src.charCodeAt(r+1),t!==33&&t!==63&&t!==47&&!cl(t))||(n=i.src.slice(r).match(al),!n)?!1:(e||i.push({type:"htmltag",content:i.src.slice(r,r+n[0].length),level:i.level}),i.pos+=n[0].length,!0);}var dl=/^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i,hl=/^&([a-z][a-z0-9]{1,31});/i;function ul(i,e){var t,n,s,r=i.pos,o=i.posMax;if(i.src.charCodeAt(r)!==38)return!1;if(r+1<o){if(t=i.src.charCodeAt(r+1),t===35){if(s=i.src.slice(r).match(dl),s)return e||(n=s[1][0].toLowerCase()==="x"?parseInt(s[1].slice(1),16):parseInt(s[1],10),i.pending+=qo(n)?Ui(n):Ui(65533)),i.pos+=s[0].length,!0;}else if(s=i.src.slice(r).match(hl),s){var a=jo(s[1]);if(s[1]!==a)return e||(i.pending+=a),i.pos+=s[0].length,!0;}}return e||(i.pending+="&"),i.pos++,!0;}var Oi=[["text",Mc],["newline",kc],["escape",Pc],["backticks",Lc],["del",Oc],["ins",Nc],["mark",Bc],["emphasis",Dc],["sub",Uc],["sup",jc],["links",$c],["footnote_inline",qc],["footnote_ref",Gc],["autolink",Wc],["htmltag",ll],["entity",ul]];function Ei(){this.ruler=new Ye();for(var i=0;i<Oi.length;i++)this.ruler.push(Oi[i][0],Oi[i][1]);this.validateLink=pl;}Ei.prototype.skipToken=function(i){var e=this.ruler.getRules(""),t=e.length,n=i.pos,s,r;if((r=i.cacheGet(n))>0){i.pos=r;return;}for(s=0;s<t;s++)if(e[s](i,!0)){i.cacheSet(n,i.pos);return;}i.pos++,i.cacheSet(n,i.pos);};Ei.prototype.tokenize=function(i){for(var e=this.ruler.getRules(""),t=e.length,n=i.posMax,s,r;i.pos<n;){for(r=0;r<t&&(s=e[r](i,!1),!s);r++);if(s){if(i.pos>=n)break;continue;}i.pending+=i.src[i.pos++];}i.pending&&i.pushPending();};Ei.prototype.parse=function(i,e,t,n){var s=new fn(i,this,e,t,n);this.tokenize(s);};function pl(i){var e=["vbscript","javascript","file","data"],t=i.trim().toLowerCase();return t=dn(t),!(t.indexOf(":")!==-1&&e.indexOf(t.split(":")[0])!==-1);}var fl={options:{html:!1,// Enable HTML tags in source
19
15
  xhtmlOut:!1,// Use '/' to close single tags (<br />)
20
16
  breaks:!1,// Convert '\n' in paragraphs into <br>
21
17
  langPrefix:"language-",// CSS language prefix for fenced blocks
@@ -29,7 +25,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
29
25
  // function (/*str, lang*/) { return ''; }
30
26
  //
31
27
  highlight:null,maxNesting:20// Internal protection, recursion limit
32
- },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"]}}},gl={options:{html:!1,// Enable HTML tags in source
28
+ },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"]}}},ml={options:{html:!1,// Enable HTML tags in source
33
29
  xhtmlOut:!1,// Use '/' to close single tags (<br />)
34
30
  breaks:!1,// Convert '\n' in paragraphs into <br>
35
31
  langPrefix:"language-",// CSS language prefix for fenced blocks
@@ -44,7 +40,7 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
44
40
  //
45
41
  highlight:null,maxNesting:20// Internal protection, recursion limit
46
42
  },components:{// Don't restrict core/block/inline rules
47
- core:{},block:{},inline:{}}},bl={options:{html:!0,// Enable HTML tags in source
43
+ core:{},block:{},inline:{}}},gl={options:{html:!0,// Enable HTML tags in source
48
44
  xhtmlOut:!0,// Use '/' to close single tags (<br />)
49
45
  breaks:!1,// Convert '\n' in paragraphs into <br>
50
46
  langPrefix:"language-",// CSS language prefix for fenced blocks
@@ -58,64 +54,64 @@ quotes:"“”‘’",// Highlighter function. Should return escaped HTML,
58
54
  // function (/*str, lang*/) { return ''; }
59
55
  //
60
56
  highlight:null,maxNesting:20// Internal protection, recursion limit
61
- },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"]}}},yl={"default":ml,full:gl,commonmark:bl};function Yo(i,e,t){this.src=e,this.env=t,this.options=i.options,this.tokens=[],this.inlineMode=!1,this.inline=i.inline,this.block=i.block,this.renderer=i.renderer,this.typographer=i.typographer;}function _t(i,e){typeof i!="string"&&(e=i,i="default"),e&&e.linkify!=null&&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 Si(),this.block=new ur(),this.core=new Xo(),this.renderer=new hr(),this.ruler=new Ye(),this.options={},this.configure(yl[i]),this.set(e||{});}_t.prototype.set=function(i){qo(this.options,i);};_t.prototype.configure=function(i){var e=this;if(!i)throw new Error("Wrong `remarkable` preset, check name/content");i.options&&e.set(i.options),i.components&&Object.keys(i.components).forEach(function(t){i.components[t].rules&&e[t].ruler.enable(i.components[t].rules,!0);});};_t.prototype.use=function(i,e){return i(this,e),this;};_t.prototype.parse=function(i,e){var t=new Yo(this,i,e);return this.core.process(t),t.tokens;};_t.prototype.render=function(i,e){return e=e||{},this.renderer.render(this.parse(i,e),this.options,e);};_t.prototype.parseInline=function(i,e){var t=new Yo(this,i,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};_t.prototype.renderInline=function(i,e){return e=e||{},this.renderer.render(this.parseInline(i,e),this.options,e);};var Yt=/*#__PURE__*/function(){function Yt(){_classCallCheck(this,Yt);}return _createClass(Yt,null,[{key:"addPlugins",value:function addPlugins(e,t){var n=window.remarkable_plugins;if(n&&n.forEach(function(s){e.use(s.plugin,s.options);}),t!=null&&t.math){window.katex||(console.warn("window.katex not found, use chatElementRef.refreshMessages to re-render messages"),console.warn("See https://deepchat.dev/examples/externalModules"));var s=_typeof(t.math)=="object"?t.math.delimiter:"",r=_typeof(t.math)=="object"&&t.math.options?t.math.options:{};e.use(Da.katex.bind(this,r),{delimiter:s});}}},{key:"instantiate",value:function instantiate(e){if(e)return new _t(_objectSpread(_objectSpread({},Yt.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new _t({highlight:function highlight(n,s){if(s&&t.getLanguage(s))try{return t.highlight(n,{language:s}).value;}catch(_unused3){console[f]("failed to setup the highlight dependency");}try{return t.highlightAuto(n).value;}catch(_unused4){console[f]("failed to automatically highlight messages");}return"";},html:!1,// Enable HTML tags in source
57
+ },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"]}}},bl={"default":fl,full:ml,commonmark:gl};function Zo(i,e,t){this.src=e,this.env=t,this.options=i.options,this.tokens=[],this.inlineMode=!1,this.inline=i.inline,this.block=i.block,this.renderer=i.renderer,this.typographer=i.typographer;}function _t(i,e){typeof i!="string"&&(e=i,i="default"),e&&e.linkify!=null&&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 Ei(),this.block=new hr(),this.core=new Wo(),this.renderer=new dr(),this.ruler=new Ye(),this.options={},this.configure(bl[i]),this.set(e||{});}_t.prototype.set=function(i){$o(this.options,i);};_t.prototype.configure=function(i){var e=this;if(!i)throw new Error("Wrong `remarkable` preset, check name/content");i.options&&e.set(i.options),i.components&&Object.keys(i.components).forEach(function(t){i.components[t].rules&&e[t].ruler.enable(i.components[t].rules,!0);});};_t.prototype.use=function(i,e){return i(this,e),this;};_t.prototype.parse=function(i,e){var t=new Zo(this,i,e);return this.core.process(t),t.tokens;};_t.prototype.render=function(i,e){return e=e||{},this.renderer.render(this.parse(i,e),this.options,e);};_t.prototype.parseInline=function(i,e){var t=new Zo(this,i,e);return t.inlineMode=!0,this.core.process(t),t.tokens;};_t.prototype.renderInline=function(i,e){return e=e||{},this.renderer.render(this.parseInline(i,e),this.options,e);};var Yt=/*#__PURE__*/function(){function Yt(){_classCallCheck(this,Yt);}return _createClass(Yt,null,[{key:"addPlugins",value:function addPlugins(e,t){var n=window.remarkable_plugins;if(n&&n.forEach(function(s){e.use(s.plugin,s.options);}),t!=null&&t.math){window.katex||(console.warn("window.katex not found, use chatElementRef.refreshMessages to re-render messages"),console.warn("See https://deepchat.dev/examples/externalModules"));var s=_typeof(t.math)=="object"?t.math.delimiter:"",r=_typeof(t.math)=="object"&&t.math.options?t.math.options:{};e.use(Ba.katex.bind(this,r),{delimiter:s});}}},{key:"instantiate",value:function instantiate(e){if(e)return new _t(_objectSpread(_objectSpread({},Yt.DEFAULT_PROPERTIES),e));if(window.hljs){var t=window.hljs;return new _t({highlight:function highlight(n,s){if(s&&t.getLanguage(s))try{return t.highlight(n,{language:s}).value;}catch(_unused3){console[f]("failed to setup the highlight dependency");}try{return t.highlightAuto(n).value;}catch(_unused4){console[f]("failed to automatically highlight messages");}return"";},html:!1,// Enable HTML tags in source
62
58
  xhtmlOut:!1,// Use '/' to close single tags (<br />)
63
59
  breaks:!0,// Convert '\n' in paragraphs into <br>
64
60
  langPrefix:"language-",// CSS language prefix for fenced blocks
65
61
  linkTarget:"_blank",// set target to open in a new tab
66
62
  typographer:!0// Enable smartypants and other sweet transforms
67
63
  });}else return new _t(Yt.DEFAULT_PROPERTIES);}},{key:"createNew",value:function createNew(e){var t=Yt.instantiate(e);return Yt.addPlugins(t,e),t.inline.validateLink=function(){return!0;},t;}}]);}();Yt.DEFAULT_PROPERTIES={breaks:!0,linkTarget:"_blank"// set target to open in a new tab
68
- };var Cs=Yt;var _l=/*#__PURE__*/function(){function _l(e){_classCallCheck(this,_l);this.storageKey="deep-chat-storage",this.maxMessages=1e3,this.trackInputText=!1,this.trackScrollHeight=!1,_typeof(e)=="object"&&(e.key&&(this.storageKey=e.key),e.maxMessages&&(this.maxMessages=e.maxMessages),e.inputText!==void 0&&(this.trackInputText=e.inputText),e.scrollHeight!==void 0&&(this.trackScrollHeight=e.scrollHeight),e.clear=this.clear.bind(this),de.processBrowserStorage(this));}return _createClass(_l,[{key:"get",value:function get(){var e=localStorage.getItem(this.storageKey);return e?JSON.parse(e):{messages:[]};}},{key:"set",value:function set(e,t,n){var s={messages:e,inputText:t,scrollHeight:n};localStorage.setItem(this.storageKey,le(s));}},{key:"addMessages",value:function addMessages(e){var t=e.length-this.maxMessages;t<0&&(t=0);var n=e.slice(t,e.length),s=this.trackInputText||this.trackScrollHeight?localStorage.getItem(this.storageKey):void 0,r=s?JSON.parse(s):void 0;this.set(n,this.trackInputText?r==null?void 0:r.inputText:void 0,this.trackScrollHeight?r==null?void 0:r.scrollHeight:void 0);}},{key:"addInputText",value:function addInputText(e){if(!this.trackInputText)return;var t=localStorage.getItem(this.storageKey),n=t?JSON.parse(t):void 0;this.set((n==null?void 0:n.messages)||[],e,this.trackScrollHeight?n==null?void 0:n.scrollHeight:void 0);}},{key:"addScrollHeight",value:function addScrollHeight(e){if(!this.trackScrollHeight)return;var t=localStorage.getItem(this.storageKey),n=t?JSON.parse(t):void 0;this.set((n==null?void 0:n.messages)||[],this.trackInputText?n==null?void 0:n.inputText:void 0,e);}},{key:"clear",value:function clear(){localStorage.removeItem(this.storageKey);}}]);}();var Be=/*#__PURE__*/function(){function Be(){_classCallCheck(this,Be);}return _createClass(Be,null,[{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){if(n&&(Object.assign(e.outerContainer[v],n.outerContainer),Object.assign(e.innerContainer[v],n.innerContainer),Object.assign(e.bubbleElement[v],n.bubble),t)){var s=e.bubbleElement.children[0],r=s.tagName.toLocaleLowerCase()!=="a"?s:s.children[0];Object.assign(r[v],n.media);}}},{key:"applySideStyles",value:function applySideStyles(e,t,n,s){s&&(Be.applyCustomStylesToElements(e,n,s.shared),t===F?Be.applyCustomStylesToElements(e,n,s.user):(Be.applyCustomStylesToElements(e,n,s.ai),Be.applyCustomStylesToElements(e,n,s[t])));}},{key:"isElementsStyles",value:function isElementsStyles(e){return!!(e.outerContainer||e.innerContainer||e.bubble||e.media);}// prettier-ignore
64
+ };var ws=Yt;var yl=/*#__PURE__*/function(){function yl(e){_classCallCheck(this,yl);this.storageKey="deep-chat-storage",this.maxMessages=1e3,this.trackInputText=!1,this.trackScrollHeight=!1,_typeof(e)=="object"&&(e.key&&(this.storageKey=e.key),e.maxMessages&&(this.maxMessages=e.maxMessages),e.inputText!==void 0&&(this.trackInputText=e.inputText),e.scrollHeight!==void 0&&(this.trackScrollHeight=e.scrollHeight),e.clear=this.clear.bind(this),le.processBrowserStorage(this));}return _createClass(yl,[{key:"get",value:function get(){var e=localStorage.getItem(this.storageKey);return e?JSON.parse(e):{messages:[]};}},{key:"set",value:function set(e,t,n){var s={messages:e,inputText:t,scrollHeight:n};localStorage.setItem(this.storageKey,ce(s));}},{key:"addMessages",value:function addMessages(e){var t=e.length-this.maxMessages;t<0&&(t=0);var n=e.slice(t,e.length),s=this.trackInputText||this.trackScrollHeight?localStorage.getItem(this.storageKey):void 0,r=s?JSON.parse(s):void 0;this.set(n,this.trackInputText?r==null?void 0:r.inputText:void 0,this.trackScrollHeight?r==null?void 0:r.scrollHeight:void 0);}},{key:"addInputText",value:function addInputText(e){if(!this.trackInputText)return;var t=localStorage.getItem(this.storageKey),n=t?JSON.parse(t):void 0;this.set((n==null?void 0:n.messages)||[],e,this.trackScrollHeight?n==null?void 0:n.scrollHeight:void 0);}},{key:"addScrollHeight",value:function addScrollHeight(e){if(!this.trackScrollHeight)return;var t=localStorage.getItem(this.storageKey),n=t?JSON.parse(t):void 0;this.set((n==null?void 0:n.messages)||[],this.trackInputText?n==null?void 0:n.inputText:void 0,e);}},{key:"clear",value:function clear(){localStorage.removeItem(this.storageKey);}}]);}();var Be=/*#__PURE__*/function(){function Be(){_classCallCheck(this,Be);}return _createClass(Be,null,[{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){if(n&&(Object.assign(e.outerContainer[v],n.outerContainer),Object.assign(e.innerContainer[v],n.innerContainer),Object.assign(e.bubbleElement[v],n.bubble),t)){var s=e.bubbleElement.children[0],r=s.tagName.toLocaleLowerCase()!=="a"?s:s.children[0];Object.assign(r[v],n.media);}}},{key:"applySideStyles",value:function applySideStyles(e,t,n,s){s&&(Be.applyCustomStylesToElements(e,n,s.shared),t===F?Be.applyCustomStylesToElements(e,n,s.user):(Be.applyCustomStylesToElements(e,n,s.ai),Be.applyCustomStylesToElements(e,n,s[t])));}},{key:"isElementsStyles",value:function isElementsStyles(e){return!!(e.outerContainer||e.innerContainer||e.bubble||e.media);}// prettier-ignore
69
65
  },{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s,r){var o;r&&e[w]!==r?Be.isElementsStyles(r)?(Be.applyCustomStylesToElements(t,s,(o=e[w])==null?void 0:o.shared),Be.applyCustomStylesToElements(t,s,r)):(Be.applySideStyles(t,n,s,e[w]),Be.applySideStyles(t,n,s,r)):Be.applySideStyles(t,n,s,e[w]);}// prettier-ignore
70
66
  },{key:"extractParticularSharedStyles",value:function extractParticularSharedStyles(e,t){if(!(t!=null&&t.shared))return;var n=t.shared,s={outerContainer:{},innerContainer:{},bubble:{},media:{}};return e.forEach(function(r){var o,a,c,l;s.outerContainer[r]=((o=n.outerContainer)==null?void 0:o[r])||"",s.innerContainer[r]=((a=n.innerContainer)==null?void 0:a[r])||"",s.bubble[r]=((c=n.bubble)==null?void 0:c[r])||"",s.media[r]=((l=n.media)==null?void 0:l[r])||"";}),s;}}]);}();var Se=/*#__PURE__*/function(){function Se(){_classCallCheck(this,Se);}return _createClass(Se,null,[{key:"setElementProps",value:// prettier-ignore
71
- function setElementProps(e,t,n,s){var r;n!==It&&(e.applyCustomStyles(t,s,!0,(r=e.messageStyles)==null?void 0:r[n]),t.bubbleElement[m].add(No));}// prettier-ignore
72
- },{key:"addMessage",value:function addMessage(e,t,n,s,r){Se.setElementProps(e,t,n,s),r?e.elementRef.insertBefore(t.outerContainer,e.elementRef.firstChild):e.appendOuterContainerElemet(t.outerContainer);}},{key:"wrapInLink",value:function wrapInLink(e,t,n){var s=A("a");return s.href=t,s.download=n||se,s.target="_blank",s.appendChild(e),s;}},{key:"isNonLinkableDataUrl",value:function isNonLinkableDataUrl(e,t){return!t.startsWith("data")||e===W?!1:e===rn&&t.startsWith("data:text/javascript")||!t.startsWith("data:image")&&!t.startsWith("data:application");}},{key:"processContent",value:function processContent(e,t,n,s){return!n||Se.isNonLinkableDataUrl(e,n)?t:Se.wrapInLink(t,n,s);}},{key:"waitToLoadThenScroll",value:function waitToLoadThenScroll(e){setTimeout(function(){e();},60);}},{key:"scrollDownOnImageLoad",value:function scrollDownOnImageLoad(e,t){if(e.startsWith("data"))Se.waitToLoadThenScroll(t);else try{fetch(e,{mode:"no-cors"})["catch"](function(){})["finally"](function(){Se.waitToLoadThenScroll(t);});}catch(_unused5){t();}}// The strategy is to emit the actual file reference in the `onMessage` event for the user to inspect it
67
+ function setElementProps(e,t,n,s){var r;n!==It&&(e.applyCustomStyles(t,s,!0,(r=e.messageStyles)==null?void 0:r[n]),t.bubbleElement[m].add(Oo));}// prettier-ignore
68
+ },{key:"addMessage",value:function addMessage(e,t,n,s,r){Se.setElementProps(e,t,n,s),r?e.elementRef.insertBefore(t.outerContainer,e.elementRef.firstChild):e.appendOuterContainerElemet(t.outerContainer);}},{key:"wrapInLink",value:function wrapInLink(e,t,n){var s=A("a");return s.href=t,s.download=n||se,s.target="_blank",s.appendChild(e),s;}},{key:"isNonLinkableDataUrl",value:function isNonLinkableDataUrl(e,t){return!t.startsWith("data")||e===W?!1:e===on&&t.startsWith("data:text/javascript")||!t.startsWith("data:image")&&!t.startsWith("data:application");}},{key:"processContent",value:function processContent(e,t,n,s){return!n||Se.isNonLinkableDataUrl(e,n)?t:Se.wrapInLink(t,n,s);}},{key:"waitToLoadThenScroll",value:function waitToLoadThenScroll(e){setTimeout(function(){e();},60);}},{key:"scrollDownOnImageLoad",value:function scrollDownOnImageLoad(e,t){if(e.startsWith("data"))Se.waitToLoadThenScroll(t);else try{fetch(e,{mode:"no-cors"})["catch"](function(){})["finally"](function(){Se.waitToLoadThenScroll(t);});}catch(_unused5){t();}}// The strategy is to emit the actual file reference in the `onMessage` event for the user to inspect it
73
69
  // But it is not actually used by anything in the chat, hence it is removed when adding a message
74
70
  // after the body has been stringified and parsed - the file reference will disappear, hence this readds it
75
71
  },{key:"reAddFileRefToObject",value:function reAddFileRefToObject(e,t){var n;(n=e[b])==null||n.forEach(function(s,r){var o;s.ref&&(o=t[b])!=null&&o[r]&&(t[b][r].ref=s.ref);});}// the chat does not use the actual file
76
- },{key:"removeFileRef",value:function removeFileRef(e){var t=_objectSpread({},e);return delete t.ref,t;}},{key:"isAudioFile",value:function isAudioFile(e){var t=/\.(mp3|ogg|wav|aac|webm|4a)$/i,n=e.type,s=e.src;return n===$||(s==null?void 0:s.startsWith("data:audio"))||s&&t.test(s);}},{key:"isImageFile",value:function isImageFile(e){var t=e.type,n=e.src;return t===W||(n==null?void 0:n.startsWith("data:image"))||n&&Se.isImageFileExtension(n);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();var dn=/*#__PURE__*/function(){function dn(){_classCallCheck(this,dn);}return _createClass(dn,null,[{key:"onMessage",value:function onMessage(e,t,n){var r;var s=C({message:t,isHistory:n,isInitial:n});Se.reAddFileRefToObject(t,s.message),(r=e.onMessage)==null||r.call(e,s),e.dispatchEvent(new CustomEvent("message",{detail:s})),de.fireOnNewMessage(e,s);}},{key:"onClearMessages",value:function onClearMessages(e){var t;(t=e.onClearMessages)==null||t.call(e),e.dispatchEvent(new CustomEvent("clear-messages"));}},{key:"onRender",value:function onRender(e){var t;(t=e.onComponentRender)==null||t.call(e,e),e.dispatchEvent(new CustomEvent("render",{detail:e}));}},{key:"onInput",value:function onInput(e,t,n){var r,o;var s=C({content:t,isUser:n});t[b]&&Se.reAddFileRefToObject(_defineProperty({},b,(r=t[b])==null?void 0:r.map(function(a){return{ref:a};})),s.content),(o=e.onInput)==null||o.call(e,s),e.dispatchEvent(new CustomEvent("input",{detail:s}));}},{key:"onError",value:function onError(e,t){var n;(n=e.onError)==null||n.call(e,t),e.dispatchEvent(new CustomEvent(f,{detail:t}));}}]);}();var we=/*#__PURE__*/function(){function we(){_classCallCheck(this,we);}return _createClass(we,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=A();return e[m].add("loading-history"),e.appendChild(A()),e.appendChild(A()),e.appendChild(A()),e.appendChild(A()),e;}},{key:"apply",value:function apply(e,t,n){mt.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=C(n),delete n.bubble),e.applyCustomStyles(t,"history",!1,n);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var a,c,l,d,p,u,g,y;e.bubbleElement[m].add(we.CLASS);var s=n?we.FULL_VIEW_CLASS:we.SMALL_CLASS;e.outerContainer[m].add(s);var r=n?(d=(l=(c=(a=t.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.full)==null?void 0:d[R]:(y=(g=(u=(p=t.messageStyles)==null?void 0:p.loading)==null?void 0:u.history)==null?void 0:g.small)==null?void 0:y[R];we.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==Do&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",ne),n=t.bubbleElement,s=we.generateLoadingRingElement();return n.appendChild(s),t;}},{key:"addMessage",value:function addMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var r,o,a,c;var n=(c=(a=(o=(r=e.messageStyles)==null?void 0:r.loading)==null?void 0:o.history)==null?void 0:a.full)==null?void 0:c[L],s=n?yt.createElements(e,n,ne,!0,!0):we.createDefaultElements(e);return we.addLoadHistoryMessage(s,e,t),B.softRemRoleElements(s.innerContainer,e.avatar,e.name),s;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var n,s,r,o,a,c,l,d;if(t!=null&&t.outerContainer[m].contains(we.FULL_VIEW_CLASS)){t.outerContainer[m].replace(we.FULL_VIEW_CLASS,we.SMALL_CLASS);var p=(o=(r=(s=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:s.history)==null?void 0:r.small)==null?void 0:o[R];p&&we.apply(e,t,p);var u=(d=(l=(c=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.small)==null?void 0:d[L];return u&&(t.bubbleElement.innerHTML=u),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];we.tryChangeViewToSmall(e,t)||we.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();we.CLASS="loading-history-message",we.FULL_VIEW_CLASS="loading-history-message-full-view",we.SMALL_CLASS="loading-history-message-small";var Mt=we;var ys=/*#__PURE__*/function(){function ys(){_classCallCheck(this,ys);}return _createClass(ys,null,[{key:"setFade",value:function setFade(e,t){e[v].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(ys.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e,t){var n;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:e[v].opacity="0";n=typeof t=="number"?t:ys.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(s){setTimeout(function(){return s();},n);});case 1:e[v].opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();ys.DEFAULT_FADE_MS=500;var Zs=ys;var Vt=/*#__PURE__*/function(){function Vt(e,t,n){_classCallCheck(this,Vt);if(this.hiddenElements=/* @__PURE__ */new Set(),this.isScrollButton=!1,this.isScrollingToBottom=!1,this._messages=e,t){var _s$R;var s={};_typeof(t)=="object"&&(s=C(t),s.onUpdate=t.onUpdate),(_s$R=s[R])!==null&&_s$R!==void 0?_s$R:s[R]={};var r="fit-content";s[R]["default"]=_objectSpread({borderRadius:"10px",width:r,height:r},s[R]["default"]),this.hiddenMessagesConfig=s,this.io=this.initIntersectionObserver(this._messages.elementRef);}if(n){var _s2$R;var _s2=_typeof(n)=="object"?C(n):{};(_s2$R=_s2[R])!==null&&_s2$R!==void 0?_s2$R:_s2[R]={},_s2[R]["default"]=_objectSpread({borderRadius:"50%",width:"1.4rem",height:"1.4rem"},_s2[R]["default"]),this.scrollButtonConfig=_s2;}this.element=this.createElement(),this._messages.elementRef.appendChild(this.element);}return _createClass(Vt,[{key:"initIntersectionObserver",value:function initIntersectionObserver(e){var _this3=this;return new IntersectionObserver(function(t){t.forEach(function(n){var s;n.isIntersecting&&_this3.hiddenElements.has(n.target)&&(_this3.hiddenElements["delete"](n.target),(s=_this3.io)==null||s.unobserve(n.target),_this3.updateHiddenElement());});},{root:e,threshold:0.1});}},{key:"createElement",value:function createElement(){var _this4=this;var e=A();return e.id="scroll-button",z.assignButtonEvents(e,function(){var s,r,o;var t=_this4.isScrollButton?(s=_this4.scrollButtonConfig)==null?void 0:s.smoothScroll:(r=_this4.hiddenMessagesConfig)==null?void 0:r.smoothScroll,n=typeof t=="boolean"?t:!0;if(_this4.isScrollButton||((o=_this4.hiddenMessagesConfig)==null?void 0:o.clickScroll)==="last")z.scrollToBottom(_this4._messages,n),n&&_this4.element&&(Vt.hideElement(_this4.element),_this4.isScrollingToBottom=!0,z.waitForScrollEnd(_this4._messages.elementRef,function(){_this4.isScrollingToBottom=!1;}));else{var a=_this4.hiddenElements.values().next().value;a&&_this4._messages.elementRef.scrollTo({left:0,top:a.offsetTop,behavior:n?"smooth":"auto"});}}),oe.apply(this._messages,e),e;}},{key:"assignStyles",value:function assignStyles(e){if(!this.element)return;Object.assign(this.element[v],e[w]);var t=ce.processStateful(e);Rt.add(this.element,t);}},{key:"updateHiddenElement",value:function updateHiddenElement(){var e,t;if(this.element){this.isScrollButton=!1;var n=this.hiddenElements.size;if(n===0){Vt.hideElement(this.element);return;}var s="".concat(n," new message").concat(n===1?"":"s");if((e=this.hiddenMessagesConfig)!=null&&e.onUpdate){var r=this.hiddenMessagesConfig.onUpdate(s,n);this.element.innerHTML=r,oe.apply(this._messages,this.element);}else this.element.innerHTML=s;(t=this.hiddenMessagesConfig)!=null&&t[R]&&this.assignStyles(this.hiddenMessagesConfig[R]),Vt.displayElement(this.element);}}},{key:"updateHidden",value:function updateHidden(){var e,t;if(!this.isScrollingToBottom)if(this.hiddenMessagesConfig){var n=(e=this._messages.getFirstMessageContentEl())==null?void 0:e.outerContainer;n&&!z.isVisibleInParent(n,this._messages.elementRef)&&(this.hiddenElements.add(n),(t=this.io)==null||t.observe(n),this.updateHiddenElement());}else this.updateScroll();}},{key:"clearHidden",value:function clearHidden(){var _this5=this;this.hiddenElements.forEach(function(e){var t;return(t=_this5.io)==null?void 0:t.unobserve(e);}),this.hiddenElements.clear(),this.updateHiddenElement();}},{key:"displayScroll",value:function displayScroll(){var e,t;this.element&&this.element[v].opacity!==Fr&&(Vt.displayElement(this.element),this.element.innerHTML=((e=this.scrollButtonConfig)==null?void 0:e.content)||'<span style="font-size: 1.2rem; user-select: none;">&darr;</span>',(t=this.scrollButtonConfig)!=null&&t[R]&&this.assignStyles(this.scrollButtonConfig[R]));}},{key:"updateScroll",value:function updateScroll(){var e;this.isScrollingToBottom||!this.scrollButtonConfig||(z.isScrollbarAtBottomOfElement(this._messages.elementRef,((e=this.scrollButtonConfig)==null?void 0:e.scrollDelta)||80)?this.element&&this.element[v].opacity!==Dr&&Vt.hideElement(this.element):(this.displayScroll(),this.isScrollButton=!0));}}],[{key:"displayElement",value:function displayElement(e){e[v].opacity=Fr,e[v].pointerEvents="auto";}},{key:"hideElement",value:function hideElement(e){e[v].opacity=Dr,e[v].pointerEvents="none";}}]);}();var Qr="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='iso-8859-1'?%3e%3csvg%20fill='%23000000'%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%2032%2032'%20xml:space='preserve'%3e%3cpath%20d='M23,30.36H9c-2.404,0-4.36-1.956-4.36-4.36V15c0-2.404,1.956-4.36,4.36-4.36h3.659%20c0.167-1.566,1.415-2.813,2.981-2.981V5.333c-1.131-0.174-2-1.154-2-2.333c0-1.301,1.059-2.36,2.36-2.36%20c1.302,0,2.36,1.059,2.36,2.36c0,1.179-0.869,2.159-2,2.333V7.66c1.566,0.167,2.814,1.415,2.981,2.981H23%20c2.404,0,4.36,1.956,4.36,4.36v11C27.36,28.404,25.404,30.36,23,30.36z%20M9,11.36c-2.007,0-3.64,1.633-3.64,3.64v11%20c0,2.007,1.633,3.64,3.64,3.64h14c2.007,0,3.64-1.633,3.64-3.64V15c0-2.007-1.633-3.64-3.64-3.64H9z%20M13.384,10.64h5.231%20C18.439,9.354,17.334,8.36,16,8.36C14.667,8.36,13.561,9.354,13.384,10.64z%20M16,1.36c-0.904,0-1.64,0.736-1.64,1.64%20S15.096,4.64,16,4.64c0.904,0,1.64-0.736,1.64-1.64S16.904,1.36,16,1.36z%20M20,27.36h-8c-1.301,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36h8c1.302,0,2.36,1.059,2.36,2.36S21.302,27.36,20,27.36z%20M12,23.36c-0.904,0-1.64,0.735-1.64,1.64%20s0.736,1.64,1.64,1.64h8c0.904,0,1.64-0.735,1.64-1.64s-0.735-1.64-1.64-1.64H12z%20M31,23.86h-2c-0.199,0-0.36-0.161-0.36-0.36V15%20c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5C31.36,23.699,31.199,23.86,31,23.86z%20M29.36,23.14h1.279v-7.78%20H29.36V23.14z%20M3,23.86H1c-0.199,0-0.36-0.161-0.36-0.36V15c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5%20C3.36,23.699,3.199,23.86,3,23.86z%20M1.36,23.14h1.28v-7.78H1.36V23.14z%20M20,20.36c-1.302,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36s2.36,1.059,2.36,2.36C22.36,19.302,21.302,20.36,20,20.36z%20M20,16.36c-0.904,0-1.64,0.736-1.64,1.64%20s0.735,1.64,1.64,1.64s1.64-0.735,1.64-1.64S20.904,16.36,20,16.36z%20M12,20.36c-1.301,0-2.36-1.059-2.36-2.36s1.059-2.36,2.36-2.36%20s2.36,1.059,2.36,2.36C14.36,19.302,13.301,20.36,12,20.36z%20M12,16.36c-0.904,0-1.64,0.736-1.64,1.64s0.736,1.64,1.64,1.64%20s1.64-0.735,1.64-1.64S12.904,16.36,12,16.36z'/%3e%3crect%20style='fill:none;'%20width='32'%20height='32'/%3e%3c/svg%3e",qi="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==";var Jo=/*#__PURE__*/function(){function Jo(e){_classCallCheck(this,Jo);this.className=e;}return _createClass(Jo,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e)[v]).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e)[v].visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e)[m].add("role-hidden");}}]);}();var vt=/*#__PURE__*/function(_Jo){function vt(e){var _this6;_classCallCheck(this,vt);_this6=_callSuper(this,vt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(vt,_Jo);return _createClass(vt,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._avatars=="boolean"?void 0:this._avatars,s=this.createAvatar(t,n),r=this.getPosition(t,n);s[m].add(r===$t?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===$t?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var r,o,a,c,l;var n=A("img");e===F?(n[T]=((r=t==null?void 0:t[F])==null?void 0:r[T])||((o=t==null?void 0:t[w])==null?void 0:o[T])||qi,n.onerror=vt.errorFallback.bind(this,qi)):(n[T]=((a=t==null?void 0:t[e])==null?void 0:a[T])||((c=t==null?void 0:t[ne])==null?void 0:c[T])||((l=t==null?void 0:t[w])==null?void 0:l[T])||Qr,n.onerror=vt.errorFallback.bind(this,Qr)),n[m].add("avatar"),n.alt="".concat(e," avatar");var s=A();return s[m].add(this.className),s.appendChild(n),t&&vt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,r,o,a,c,l;var n=de.processPosition((r=(s=t==null?void 0:t[e])==null?void 0:s[R])==null?void 0:r.position);return e!==F&&(n!==null&&n!==void 0?n:n=(a=(o=t==null?void 0:t.ai)==null?void 0:o[R])==null?void 0:a.position),n!==null&&n!==void 0?n:n=(l=(c=t==null?void 0:t[w])==null?void 0:c[R])==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===F?Bo:$t,n;}}],[{key:"errorFallback",value:function errorFallback(e,t){var n=t.target;n.onerror=null,n[T]=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){Object.assign(e[v],n.container),Object.assign(t[v],n.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){var r,o,a,c;if((r=n[w])!=null&&r[R]&&vt.applyCustomStylesToElements(e,t,n[w][R]),s===F)(o=n.user)!=null&&o[R]&&vt.applyCustomStylesToElements(e,t,n.user[R]);else{(a=n.ai)!=null&&a[R]&&vt.applyCustomStylesToElements(e,t,n.ai[R]);var l=(c=n[s])==null?void 0:c[R];l&&vt.applyCustomStylesToElements(e,t,l);}}}]);}(Jo);var us=/*#__PURE__*/function(_Jo2){function us(e){var _this7;_classCallCheck(this,us);_this7=_callSuper(this,us,["name"]),_this7._names=e;return _this7;}_inherits(us,_Jo2);return _createClass(us,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),r=us.getPosition(t,n);s[m].add(r===$t?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===$t?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=A();return n[m].add(this.className),n.textContent=us.getNameText(e,t),us.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,r,o;var n=de.processPosition((s=t==null?void 0:t[e])==null?void 0:s.position);return e!==F&&(n!==null&&n!==void 0?n:n=(r=t==null?void 0:t[ne])==null?void 0:r.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[w])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===F?Bo:$t,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,r,o,a;Object.assign(e[v],(s=n[w])==null?void 0:s[v]),t===F?Object.assign(e[v],(r=n[F])==null?void 0:r[v]):(Object.assign(e[v],(o=n[ne])==null?void 0:o[v]),Object.assign(e[v],(a=n[t])==null?void 0:a[v]));}},{key:"getNameText",value:function getNameText(e,t){var n,s,r,o,a,c;return e===F?((n=t[F])==null?void 0:n[h])||((s=t[w])==null?void 0:s[h])||"User":e===ne?((r=t[ne])==null?void 0:r[h])||((o=t[w])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[w])==null?void 0:c[h])||e;}}]);}(Jo);var je=/*#__PURE__*/function(){function je(e){var _this8=this;_classCallCheck(this,je);var t,n,s,r;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=je.createContainerElement(),this.messageStyles=de.processMessageStyles(e.messageStyles),this._remarkable=Cs.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new vt(e.avatars)),e.names&&(this.name=new us(e.names)),e.browserStorage&&(this.browserStorage=new _l(e.browserStorage)),this._onMessage=dn.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),(e.hiddenMessages||e.scrollButton)&&(this.scrollButton=new Vt(this,e.hiddenMessages,e.scrollButton)),this.focusMode=de.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=A(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Zs.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||de.processStreamHTMLWrappers((s=e.connect)==null?void 0:s.stream),typeof this.focusMode!="boolean"&&((r=this.focusMode)==null?void 0:r.streamAutoScroll)===!1&&(this.autoScrollAllowed=!1),e.maxVisibleMessages&&(this.maxVisibleMessages=e.maxVisibleMessages),setTimeout(function(){_this8.submitUserMessage=e.submitUserMessage;});}return _createClass(je,[{key:"addNewTextMessage",value:function addNewTextMessage(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(n!=null&&n.status){var o=this.overwriteText(t,e,this.messageElementRefs);if(o)return o;n.status=!1;}var r=s?this.createAndPrependNewMessageElement(e,t,s):this.createAndAppendNewMessageElement(e,t);return r.bubbleElement[m].add(je.TEXT_BUBBLE_CLASS),this.applyCustomStyles(r,t,!1),B.fillEmptyMessageElement(r.bubbleElement,e),r;}// prettier-ignore
72
+ },{key:"removeFileRef",value:function removeFileRef(e){var t=_objectSpread({},e);return delete t.ref,t;}},{key:"isAudioFile",value:function isAudioFile(e){var t=/\.(mp3|ogg|wav|aac|webm|4a)$/i,n=e.type,s=e.src;return n===$||(s==null?void 0:s.startsWith("data:audio"))||s&&t.test(s);}},{key:"isImageFile",value:function isImageFile(e){var t=e.type,n=e.src;return t===W||(n==null?void 0:n.startsWith("data:image"))||n&&Se.isImageFileExtension(n);}},{key:"isImageFileExtension",value:function isImageFileExtension(e){return /\.(jpg|jpeg|png|gif|bmp)$/i.test(e);}}]);}();var hn=/*#__PURE__*/function(){function hn(){_classCallCheck(this,hn);}return _createClass(hn,null,[{key:"onMessage",value:function onMessage(e,t,n){var r;var s=C({message:t,isHistory:n,isInitial:n});Se.reAddFileRefToObject(t,s.message),(r=e.onMessage)==null||r.call(e,s),e.dispatchEvent(new CustomEvent("message",{detail:s})),le.fireOnNewMessage(e,s);}},{key:"onClearMessages",value:function onClearMessages(e){var t;(t=e.onClearMessages)==null||t.call(e),e.dispatchEvent(new CustomEvent("clear-messages"));}},{key:"onRender",value:function onRender(e){var t;(t=e.onComponentRender)==null||t.call(e,e),e.dispatchEvent(new CustomEvent("render",{detail:e}));}},{key:"onInput",value:function onInput(e,t,n){var r,o;var s=C({content:t,isUser:n});t[b]&&Se.reAddFileRefToObject(_defineProperty({},b,(r=t[b])==null?void 0:r.map(function(a){return{ref:a};})),s.content),(o=e.onInput)==null||o.call(e,s),e.dispatchEvent(new CustomEvent("input",{detail:s}));}},{key:"onError",value:function onError(e,t){var n;(n=e.onError)==null||n.call(e,t),e.dispatchEvent(new CustomEvent(f,{detail:t}));}}]);}();var we=/*#__PURE__*/function(){function we(){_classCallCheck(this,we);}return _createClass(we,null,[{key:"generateLoadingRingElement",value:function generateLoadingRingElement(){var e=A();return e[m].add("loading-history"),e.appendChild(A()),e.appendChild(A()),e.appendChild(A()),e.appendChild(A()),e;}},{key:"apply",value:function apply(e,t,n){mt.setRing(t.bubbleElement,n==null?void 0:n.bubble),n!=null&&n.bubble&&(n=C(n),delete n.bubble),e.applyCustomStyles(t,"history",!1,n);}},{key:"addLoadHistoryMessage",value:function addLoadHistoryMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var a,c,l,d,p,u,g,y;e.bubbleElement[m].add(we.CLASS);var s=n?we.FULL_VIEW_CLASS:we.SMALL_CLASS;e.outerContainer[m].add(s);var r=n?(d=(l=(c=(a=t.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.full)==null?void 0:d[R]:(y=(g=(u=(p=t.messageStyles)==null?void 0:p.loading)==null?void 0:u.history)==null?void 0:g.small)==null?void 0:y[R];we.apply(t,e,r);var o=t.elementRef;n&&t.elementRef.id!==Bo&&(o=t.elementRef.parentElement),o==null||o.prepend(e.outerContainer);}},{key:"createDefaultElements",value:function createDefaultElements(e){var t=e.createMessageElements("",ne),n=t.bubbleElement,s=we.generateLoadingRingElement();return n.appendChild(s),t;}},{key:"addMessage",value:function addMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var r,o,a,c;var n=(c=(a=(o=(r=e.messageStyles)==null?void 0:r.loading)==null?void 0:o.history)==null?void 0:a.full)==null?void 0:c[L],s=n?yt.createElements(e,n,ne,!0,!0):we.createDefaultElements(e);return we.addLoadHistoryMessage(s,e,t),B.softRemRoleElements(s.innerContainer,e.avatar,e.name),s;}},{key:"tryChangeViewToSmall",value:function tryChangeViewToSmall(e,t){var n,s,r,o,a,c,l,d;if(t!=null&&t.outerContainer[m].contains(we.FULL_VIEW_CLASS)){t.outerContainer[m].replace(we.FULL_VIEW_CLASS,we.SMALL_CLASS);var p=(o=(r=(s=(n=e.messageStyles)==null?void 0:n.loading)==null?void 0:s.history)==null?void 0:r.small)==null?void 0:o[R];p&&we.apply(e,t,p);var u=(d=(l=(c=(a=e.messageStyles)==null?void 0:a.loading)==null?void 0:c.history)==null?void 0:l.small)==null?void 0:d[L];return u&&(t.bubbleElement.innerHTML=u),!0;}return!1;}},{key:"changeFullViewToSmall",value:function changeFullViewToSmall(e){var t=e.messageElementRefs[e.messageElementRefs.length-1];we.tryChangeViewToSmall(e,t)||we.tryChangeViewToSmall(e,e.messageElementRefs[0]);}}]);}();we.CLASS="loading-history-message",we.FULL_VIEW_CLASS="loading-history-message-full-view",we.SMALL_CLASS="loading-history-message-small";var Mt=we;var bs=/*#__PURE__*/function(){function bs(){_classCallCheck(this,bs);}return _createClass(bs,null,[{key:"setFade",value:function setFade(e,t){e[v].transitionDuration=typeof t=="number"?"".concat(t,"ms"):"".concat(bs.DEFAULT_FADE_MS,"ms");}},{key:"fadeAnimation",value:function(){var _fadeAnimation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e,t){var n;return _regenerator().w(function(_context){while(1)switch(_context.n){case 0:e[v].opacity="0";n=typeof t=="number"?t:bs.DEFAULT_FADE_MS;_context.n=1;return new Promise(function(s){setTimeout(function(){return s();},n);});case 1:e[v].opacity="1";case 2:return _context.a(2);}},_callee);}));function fadeAnimation(_x,_x2){return _fadeAnimation.apply(this,arguments);}return fadeAnimation;}()}]);}();bs.DEFAULT_FADE_MS=500;var Ws=bs;var Kt=/*#__PURE__*/function(){function Kt(e,t,n){_classCallCheck(this,Kt);if(this.hiddenElements=/* @__PURE__ */new Set(),this.isScrollButton=!1,this.isScrollingToBottom=!1,this._messages=e,t){var _s$R;var s={};_typeof(t)=="object"&&(s=C(t),s.onUpdate=t.onUpdate),(_s$R=s[R])!==null&&_s$R!==void 0?_s$R:s[R]={};var r="fit-content";s[R]["default"]=_objectSpread({borderRadius:"10px",width:r,height:r},s[R]["default"]),this.hiddenMessagesConfig=s,this.io=this.initIntersectionObserver(this._messages.elementRef);}if(n){var _s2$R;var _s2=_typeof(n)=="object"?C(n):{};(_s2$R=_s2[R])!==null&&_s2$R!==void 0?_s2$R:_s2[R]={},_s2[R]["default"]=_objectSpread({borderRadius:"50%",width:"1.4rem",height:"1.4rem"},_s2[R]["default"]),this.scrollButtonConfig=_s2;}this.element=this.createElement(),this._messages.elementRef.appendChild(this.element);}return _createClass(Kt,[{key:"initIntersectionObserver",value:function initIntersectionObserver(e){var _this3=this;return new IntersectionObserver(function(t){t.forEach(function(n){var s;n.isIntersecting&&_this3.hiddenElements.has(n.target)&&(_this3.hiddenElements["delete"](n.target),(s=_this3.io)==null||s.unobserve(n.target),_this3.updateHiddenElement());});},{root:e,threshold:0.1});}},{key:"createElement",value:function createElement(){var _this4=this;var e=A();return e.id="scroll-button",z.assignButtonEvents(e,function(){var s,r,o;var t=_this4.isScrollButton?(s=_this4.scrollButtonConfig)==null?void 0:s.smoothScroll:(r=_this4.hiddenMessagesConfig)==null?void 0:r.smoothScroll,n=typeof t=="boolean"?t:!0;if(_this4.isScrollButton||((o=_this4.hiddenMessagesConfig)==null?void 0:o.clickScroll)==="last")z.scrollToBottom(_this4._messages,n),n&&_this4.element&&(Kt.hideElement(_this4.element),_this4.isScrollingToBottom=!0,z.waitForScrollEnd(_this4._messages.elementRef,function(){_this4.isScrollingToBottom=!1;}));else{var a=_this4.hiddenElements.values().next().value;a&&_this4._messages.elementRef.scrollTo({left:0,top:a.offsetTop,behavior:n?"smooth":"auto"});}}),oe.apply(this._messages,e),e;}},{key:"assignStyles",value:function assignStyles(e){if(!this.element)return;Object.assign(this.element[v],e[w]);var t=de.processStateful(e);Rt.add(this.element,t);}},{key:"updateHiddenElement",value:function updateHiddenElement(){var e,t;if(this.element){this.isScrollButton=!1;var n=this.hiddenElements.size;if(n===0){Kt.hideElement(this.element);return;}var s="".concat(n," new message").concat(n===1?"":"s");if((e=this.hiddenMessagesConfig)!=null&&e.onUpdate){var r=this.hiddenMessagesConfig.onUpdate(s,n);this.element.innerHTML=r,oe.apply(this._messages,this.element);}else this.element.innerHTML=s;(t=this.hiddenMessagesConfig)!=null&&t[R]&&this.assignStyles(this.hiddenMessagesConfig[R]),Kt.displayElement(this.element);}}},{key:"updateHidden",value:function updateHidden(){var e,t;if(!this.isScrollingToBottom)if(this.hiddenMessagesConfig){var n=(e=this._messages.getFirstMessageContentEl())==null?void 0:e.outerContainer;n&&!z.isVisibleInParent(n,this._messages.elementRef)&&(this.hiddenElements.add(n),(t=this.io)==null||t.observe(n),this.updateHiddenElement());}else this.updateScroll();}},{key:"clearHidden",value:function clearHidden(){var _this5=this;this.hiddenElements.forEach(function(e){var t;return(t=_this5.io)==null?void 0:t.unobserve(e);}),this.hiddenElements.clear(),this.updateHiddenElement();}},{key:"displayScroll",value:function displayScroll(){var e,t;this.element&&this.element[v].opacity!==Dr&&(Kt.displayElement(this.element),this.element.innerHTML=((e=this.scrollButtonConfig)==null?void 0:e.content)||'<span style="font-size: 1.2rem; user-select: none;">&darr;</span>',(t=this.scrollButtonConfig)!=null&&t[R]&&this.assignStyles(this.scrollButtonConfig[R]));}},{key:"updateScroll",value:function updateScroll(){var e;this.isScrollingToBottom||!this.scrollButtonConfig||(z.isScrollbarAtBottomOfElement(this._messages.elementRef,((e=this.scrollButtonConfig)==null?void 0:e.scrollDelta)||80)?this.element&&this.element[v].opacity!==Br&&Kt.hideElement(this.element):(this.displayScroll(),this.isScrollButton=!0));}}],[{key:"displayElement",value:function displayElement(e){e[v].opacity=Dr,e[v].pointerEvents="auto";}},{key:"hideElement",value:function hideElement(e){e[v].opacity=Br,e[v].pointerEvents="none";}}]);}();var Jr="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='iso-8859-1'?%3e%3csvg%20fill='%23000000'%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%2032%2032'%20xml:space='preserve'%3e%3cpath%20d='M23,30.36H9c-2.404,0-4.36-1.956-4.36-4.36V15c0-2.404,1.956-4.36,4.36-4.36h3.659%20c0.167-1.566,1.415-2.813,2.981-2.981V5.333c-1.131-0.174-2-1.154-2-2.333c0-1.301,1.059-2.36,2.36-2.36%20c1.302,0,2.36,1.059,2.36,2.36c0,1.179-0.869,2.159-2,2.333V7.66c1.566,0.167,2.814,1.415,2.981,2.981H23%20c2.404,0,4.36,1.956,4.36,4.36v11C27.36,28.404,25.404,30.36,23,30.36z%20M9,11.36c-2.007,0-3.64,1.633-3.64,3.64v11%20c0,2.007,1.633,3.64,3.64,3.64h14c2.007,0,3.64-1.633,3.64-3.64V15c0-2.007-1.633-3.64-3.64-3.64H9z%20M13.384,10.64h5.231%20C18.439,9.354,17.334,8.36,16,8.36C14.667,8.36,13.561,9.354,13.384,10.64z%20M16,1.36c-0.904,0-1.64,0.736-1.64,1.64%20S15.096,4.64,16,4.64c0.904,0,1.64-0.736,1.64-1.64S16.904,1.36,16,1.36z%20M20,27.36h-8c-1.301,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36h8c1.302,0,2.36,1.059,2.36,2.36S21.302,27.36,20,27.36z%20M12,23.36c-0.904,0-1.64,0.735-1.64,1.64%20s0.736,1.64,1.64,1.64h8c0.904,0,1.64-0.735,1.64-1.64s-0.735-1.64-1.64-1.64H12z%20M31,23.86h-2c-0.199,0-0.36-0.161-0.36-0.36V15%20c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5C31.36,23.699,31.199,23.86,31,23.86z%20M29.36,23.14h1.279v-7.78%20H29.36V23.14z%20M3,23.86H1c-0.199,0-0.36-0.161-0.36-0.36V15c0-0.199,0.161-0.36,0.36-0.36h2c0.199,0,0.36,0.161,0.36,0.36v8.5%20C3.36,23.699,3.199,23.86,3,23.86z%20M1.36,23.14h1.28v-7.78H1.36V23.14z%20M20,20.36c-1.302,0-2.36-1.059-2.36-2.36%20s1.059-2.36,2.36-2.36s2.36,1.059,2.36,2.36C22.36,19.302,21.302,20.36,20,20.36z%20M20,16.36c-0.904,0-1.64,0.736-1.64,1.64%20s0.735,1.64,1.64,1.64s1.64-0.735,1.64-1.64S20.904,16.36,20,16.36z%20M12,20.36c-1.301,0-2.36-1.059-2.36-2.36s1.059-2.36,2.36-2.36%20s2.36,1.059,2.36,2.36C14.36,19.302,13.301,20.36,12,20.36z%20M12,16.36c-0.904,0-1.64,0.736-1.64,1.64s0.736,1.64,1.64,1.64%20s1.64-0.735,1.64-1.64S12.904,16.36,12,16.36z'/%3e%3crect%20style='fill:none;'%20width='32'%20height='32'/%3e%3c/svg%3e",ji="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==";var Yo=/*#__PURE__*/function(){function Yo(e){_classCallCheck(this,Yo);this.className=e;}return _createClass(Yo,[{key:"getAvatarContainer",value:function getAvatarContainer(e){return e.getElementsByClassName(this.className)[0];}},{key:"tryHide",value:function tryHide(e){var t;(t=this.getAvatarContainer(e)[v]).visibility||(t.visibility="hidden");}},{key:"tryReveal",value:function tryReveal(e){this.getAvatarContainer(e)[v].visibility="";}},{key:"trySoftRem",value:function trySoftRem(e){this.getAvatarContainer(e)[m].add("role-hidden");}}]);}();var vt=/*#__PURE__*/function(_Yo){function vt(e){var _this6;_classCallCheck(this,vt);_this6=_callSuper(this,vt,["avatar-container"]),_this6._avatars=e;return _this6;}_inherits(vt,_Yo);return _createClass(vt,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._avatars=="boolean"?void 0:this._avatars,s=this.createAvatar(t,n),r=this.getPosition(t,n);s[m].add(r===qt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===qt?"beforebegin":"afterend",s);}},{key:"createAvatar",value:function createAvatar(e,t){var r,o,a,c,l;var n=A("img");e===F?(n[T]=((r=t==null?void 0:t[F])==null?void 0:r[T])||((o=t==null?void 0:t[w])==null?void 0:o[T])||ji,n.onerror=vt.errorFallback.bind(this,ji)):(n[T]=((a=t==null?void 0:t[e])==null?void 0:a[T])||((c=t==null?void 0:t[ne])==null?void 0:c[T])||((l=t==null?void 0:t[w])==null?void 0:l[T])||Jr,n.onerror=vt.errorFallback.bind(this,Jr)),n[m].add("avatar"),n.alt="".concat(e," avatar");var s=A();return s[m].add(this.className),s.appendChild(n),t&&vt.applyCustomStyles(s,n,t,e),s;}},{key:"getPosition",value:function getPosition(e,t){var s,r,o,a,c,l;var n=le.processPosition((r=(s=t==null?void 0:t[e])==null?void 0:s[R])==null?void 0:r.position);return e!==F&&(n!==null&&n!==void 0?n:n=(a=(o=t==null?void 0:t.ai)==null?void 0:o[R])==null?void 0:a.position),n!==null&&n!==void 0?n:n=(l=(c=t==null?void 0:t[w])==null?void 0:c[R])==null?void 0:l.position,n!==null&&n!==void 0?n:n=e===F?No:qt,n;}}],[{key:"errorFallback",value:function errorFallback(e,t){var n=t.target;n.onerror=null,n[T]=e;}},{key:"applyCustomStylesToElements",value:function applyCustomStylesToElements(e,t,n){Object.assign(e[v],n.container),Object.assign(t[v],n.avatar);}},{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){var r,o,a,c;if((r=n[w])!=null&&r[R]&&vt.applyCustomStylesToElements(e,t,n[w][R]),s===F)(o=n.user)!=null&&o[R]&&vt.applyCustomStylesToElements(e,t,n.user[R]);else{(a=n.ai)!=null&&a[R]&&vt.applyCustomStylesToElements(e,t,n.ai[R]);var l=(c=n[s])==null?void 0:c[R];l&&vt.applyCustomStylesToElements(e,t,l);}}}]);}(Yo);var hs=/*#__PURE__*/function(_Yo2){function hs(e){var _this7;_classCallCheck(this,hs);_this7=_callSuper(this,hs,["name"]),_this7._names=e;return _this7;}_inherits(hs,_Yo2);return _createClass(hs,[{key:"addBesideBubble",value:function addBesideBubble(e,t){var n=typeof this._names=="boolean"?{}:this._names,s=this.createName(t,n),r=hs.getPosition(t,n);s[m].add(r===qt?"start-item-position":"end-item-position"),e.insertAdjacentElement(r===qt?"beforebegin":"afterend",s);}},{key:"createName",value:function createName(e,t){var n=A();return n[m].add(this.className),n.textContent=hs.getNameText(e,t),hs.applyStyle(n,e,t),n;}}],[{key:"getPosition",value:function getPosition(e,t){var s,r,o;var n=le.processPosition((s=t==null?void 0:t[e])==null?void 0:s.position);return e!==F&&(n!==null&&n!==void 0?n:n=(r=t==null?void 0:t[ne])==null?void 0:r.position),n!==null&&n!==void 0?n:n=(o=t==null?void 0:t[w])==null?void 0:o.position,n!==null&&n!==void 0?n:n=e===F?No:qt,n;}},{key:"applyStyle",value:function applyStyle(e,t,n){var s,r,o,a;Object.assign(e[v],(s=n[w])==null?void 0:s[v]),t===F?Object.assign(e[v],(r=n[F])==null?void 0:r[v]):(Object.assign(e[v],(o=n[ne])==null?void 0:o[v]),Object.assign(e[v],(a=n[t])==null?void 0:a[v]));}},{key:"getNameText",value:function getNameText(e,t){var n,s,r,o,a,c;return e===F?((n=t[F])==null?void 0:n[h])||((s=t[w])==null?void 0:s[h])||"User":e===ne?((r=t[ne])==null?void 0:r[h])||((o=t[w])==null?void 0:o[h])||"AI":((a=t[e])==null?void 0:a[h])||((c=t[w])==null?void 0:c[h])||e;}}]);}(Yo);var je=/*#__PURE__*/function(){function je(e){var _this8=this;_classCallCheck(this,je);var t,n,s,r;this.messageElementRefs=[],this.htmlClassUtilities={},this.messageToElements=[],this.maxVisibleMessages=4e3,this.autoScrollAllowed=!0,this.elementRef=je.createContainerElement(),this.messageStyles=le.processMessageStyles(e.messageStyles),this._remarkable=ws.createNew(e.remarkable),this._applyHTMLToRemarkable=(t=e.remarkable)==null?void 0:t.applyHTML,e.avatars&&(this.avatar=new vt(e.avatars)),e.names&&(this.name=new hs(e.names)),e.browserStorage&&(this.browserStorage=new yl(e.browserStorage)),this._onMessage=hn.onMessage.bind(this,e),e.htmlClassUtilities&&(this.htmlClassUtilities=e.htmlClassUtilities),(e.hiddenMessages||e.scrollButton)&&(this.scrollButton=new Kt(this,e.hiddenMessages,e.scrollButton)),this.focusMode=le.processFocusMode(e.focusMode),this.focusMode||(this._lastGroupMessagesElement=A(),this.elementRef.appendChild(this._lastGroupMessagesElement),e.upwardsMode&&(this.elementRef=this._lastGroupMessagesElement)),typeof this.focusMode!="boolean"&&(n=this.focusMode)!=null&&n.fade&&Ws.setFade(this.elementRef,this.focusMode.fade),this._customWrappers=e.htmlWrappers||le.processStreamHTMLWrappers((s=e.connect)==null?void 0:s.stream),typeof this.focusMode!="boolean"&&((r=this.focusMode)==null?void 0:r.streamAutoScroll)===!1&&(this.autoScrollAllowed=!1),e.maxVisibleMessages&&(this.maxVisibleMessages=e.maxVisibleMessages),setTimeout(function(){_this8.submitUserMessage=e.submitUserMessage;});}return _createClass(je,[{key:"addNewTextMessage",value:function addNewTextMessage(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(n!=null&&n.status){var o=this.overwriteText(t,e,this.messageElementRefs);if(o)return o;n.status=!1;}var r=s?this.createAndPrependNewMessageElement(e,t,s):this.createAndAppendNewMessageElement(e,t);return r.bubbleElement[m].add(je.TEXT_BUBBLE_CLASS),this.applyCustomStyles(r,t,!1),B.fillEmptyMessageElement(r.bubbleElement,e),r;}// prettier-ignore
77
73
  },{key:"overwriteText",value:function overwriteText(e,t,n){var s=B.overwriteMessage(this.messageToElements,n,t,e,"text",je.TEXT_BUBBLE_CLASS);return s&&this.renderText(s.bubbleElement,t,e),s;}},{key:"createAndAppendNewMessageElement",value:function createAndAppendNewMessageElement(e,t){var n=this.createNewMessageElement(e,t);return this.appendOuterContainerElemet(n.outerContainer,this.focusMode?t:void 0),n;}},{key:"createNewGroupElementFocusMode",value:function createNewGroupElementFocusMode(){var t;(t=this._lastGroupMessagesElement)==null||t[m].remove(je.LAST_GROUP_MESSAGES_ACTIVE);var e=A();(this.messageToElements.length>1||this.messageToElements.length===1&&this.messageToElements[0][0][x]!==F)&&e[m].add(je.LAST_GROUP_MESSAGES_ACTIVE),this._lastGroupMessagesElement=e;}},{key:"appendOuterContainerElemet",value:function appendOuterContainerElemet(e,t){var n;this.focusMode&&(t===F||!this._lastGroupMessagesElement)&&this.createNewGroupElementFocusMode(),(n=this._lastGroupMessagesElement)==null||n.appendChild(e),this._lastGroupMessagesElement&&(this.focusMode||!this.elementRef.contains(this._lastGroupMessagesElement))&&this.elementRef.appendChild(this._lastGroupMessagesElement);}},{key:"createAndPrependNewMessageElement",value:function createAndPrependNewMessageElement(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;var r=this.createNewMessageElement(e,t,n,s);if(n&&(o=this.elementRef.firstChild)!=null&&o[m].contains(je.INTRO_CLASS)){this.elementRef.firstChild.insertAdjacentElement("afterend",r.outerContainer);var a=this.messageElementRefs[0];this.messageElementRefs[0]=this.messageElementRefs[1],this.messageElementRefs[1]=a;}else this.elementRef.insertBefore(r.outerContainer,this.elementRef.firstChild);return r;}},{key:"createMessageElementsOnOrientation",value:function createMessageElementsOnOrientation(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;return n?this.createAndPrependNewMessageElement(e,t,n,s):this.createNewMessageElement(e,t,n,s);}},{key:"getNumberOfContentMessages",value:function getNumberOfContentMessages(){var t,n;var e=this.messageElementRefs.length;return(n=(t=this.messageElementRefs[e-1])==null?void 0:t.bubbleElement)!=null&&n[m].contains(mt.BUBBLE_CLASS)?e-1:e;}},{key:"createNewMessageElement",value:function createNewMessageElement(e,t){var _this9=this;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var o;!s&&this.getNumberOfContentMessages()>=this.maxVisibleMessages&&setTimeout(function(){return _this9.removeFirstMessage();}),s||(o=this._introPanel)==null||o.hide();var r=this.messageElementRefs[this.messageElementRefs.length-1];return Mt.changeFullViewToSmall(this),!n&&je.isTemporaryElement(r)&&(this.revealRoleElementsIfTempRemoved(r,t),this.removeLastMessage()),this.createMessageElements(e,t,n);}// this can be tested by having an ai message, then a temp ai message with html that submits new user message:
78
74
  // https://github.com/OvidijusParsiunas/deep-chat/issues/258
79
75
  // prettier-ignore
80
76
  },{key:"revealRoleElementsIfTempRemoved",value:function revealRoleElementsIfTempRemoved(e,t){if((this.avatar||this.name)&&bt.isElementTemporary(e)){var n=this.messageElementRefs[this.messageElementRefs.length-2];n&&this.messageToElements.length>0&&!e.bubbleElement[m].contains(B.getRoleClass(t))&&B.revealRoleElements(n.innerContainer,this.avatar,this.name);}}},{key:"createElements",value:function createElements(e,t){var n=je.createBaseElements(t),s=n.outerContainer,r=n.innerContainer,o=n.bubbleElement;return s.appendChild(r),this.addInnerContainerElements(o,e,t),n;}},{key:"createMessageElements",value:function createMessageElements(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=this.createElements(e,t);return B.updateRefArr(this.messageElementRefs,s,n),B.classifyRoleMessages(this.messageElementRefs,t),s;}},{key:"addInnerContainerElements",value:// prettier-ignore
81
77
  function addInnerContainerElements(e,t,n){var s=this.messageElementRefs[this.messageElementRefs.length-1];return B.areOuterContainerClassRolesSame(n,s)&&!this.isLastMessageError()&&B.hideRoleElements(s.innerContainer,this.avatar,this.name),e[m].add("message-bubble",B.getRoleClass(n),n===F?"user-message-text":"ai-message-text"),this.renderText(e,t,n),B.addRoleElements(e,n,this.avatar,this.name),{bubbleElement:e};}// prettier-ignore
82
- },{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){e&&this.messageStyles&&Be.applyCustomStyles(this.messageStyles,e,t,n,s);}},{key:"removeMessage",value:function removeMessage(e){e.outerContainer.remove();var t=this.messageElementRefs.findIndex(function(n){return n===e;});this.messageElementRefs.splice(t,1);}},{key:"removeFirstMessage",value:function removeFirstMessage(){this.messageElementRefs[0].outerContainer.remove(),this.messageElementRefs.shift();}},{key:"removeLastMessage",value:function removeLastMessage(){this.messageElementRefs[this.messageElementRefs.length-1].outerContainer.remove(),this.messageElementRefs.pop();}},{key:"isLastMessageError",value:function isLastMessageError(){var e;return(e=B.getLastMessageBubbleElement(this.elementRef))==null?void 0:e[m].contains(Ks);}},{key:"sendClientUpdate",value:function sendClientUpdate(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n;(n=this._onMessage)==null||n.call(this,e,t);}// role is optional to not add wrapper to error
78
+ },{key:"applyCustomStyles",value:function applyCustomStyles(e,t,n,s){e&&this.messageStyles&&Be.applyCustomStyles(this.messageStyles,e,t,n,s);}},{key:"removeMessage",value:function removeMessage(e){e.outerContainer.remove();var t=this.messageElementRefs.findIndex(function(n){return n===e;});this.messageElementRefs.splice(t,1);}},{key:"removeFirstMessage",value:function removeFirstMessage(){this.messageElementRefs[0].outerContainer.remove(),this.messageElementRefs.shift();}},{key:"removeLastMessage",value:function removeLastMessage(){this.messageElementRefs[this.messageElementRefs.length-1].outerContainer.remove(),this.messageElementRefs.pop();}},{key:"isLastMessageError",value:function isLastMessageError(){var e;return(e=B.getLastMessageBubbleElement(this.elementRef))==null?void 0:e[m].contains(Vs);}},{key:"sendClientUpdate",value:function sendClientUpdate(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n;(n=this._onMessage)==null||n.call(this,e,t);}// role is optional to not add wrapper to error
83
79
  },{key:"renderText",value:function renderText(e,t,n){var _oe$tryAddWrapper2=oe.tryAddWrapper(e,t,this._customWrappers,n),s=_oe$tryAddWrapper2.contentEl,r=_oe$tryAddWrapper2.wrapper;r&&oe.apply(this,e),s.innerHTML=this._remarkable.render(t),this._applyHTMLToRemarkable&&oe.apply(this,s),s.innerText.trim().length===0&&s.children.length>0&&s.children[0].tagName!=="P"&&(s.innerText=t);}// this is mostly used for enabling highlight.js to highlight code if it downloads later
84
- },{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this0=this;this._remarkable=Cs.createNew(e),this.messageToElements.forEach(function(t){t[1][h]&&t[0][h]&&_this0.renderText(t[1][h].bubbleElement,t[0][h],t[0][x]);});}},{key:"getFirstMessageContentEl",value:function getFirstMessageContentEl(){var _this$messageToElemen=this.messageToElements[this.messageToElements.length-1][1],e=_this$messageToElemen.text,t=_this$messageToElemen.html,n=_this$messageToElemen.files;return e||t||(n==null?void 0:n[0]);}},{key:"scrollToFirstElement",value:function scrollToFirstElement(e,t){var n;if(e===F){var s=typeof this.focusMode!="boolean"&&((n=this.focusMode)==null?void 0:n.smoothScroll);z.scrollToBottom(this,s);}else if(t&&this.autoScrollAllowed){var _s3=this.getFirstMessageContentEl();z.scrollToBottom(this,!1,_s3==null?void 0:_s3.outerContainer);}}}],[{key:"createContainerElement",value:function createContainerElement(){var e=A();return e.id=Do,e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return je.isLoadingMessage(e)||bt.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=A(),n=A();n[m].add("inner-message-container"),t.appendChild(n),t[m].add("outer-message-container"),t[m].add(B.buildRoleOuterContainerClass(e));var s=A();return s[m].add("message-bubble"),n.appendChild(s),{outerContainer:t,innerContainer:n,bubbleElement:s};}},{key:"createMessageContent",value:function createMessageContent(e){var t=e.text,n=e.files,s=e.html,r=e.custom,o=e._sessionId,a=e.role,c=_defineProperty({},x,a||ne);return t&&(c[h]=t),n&&(c[b]=n),s&&(c[L]=s),!t&&!n&&!s&&(c[h]=""),r&&(c.custom=r),o&&(c._sessionId=o),c;}},{key:"isLoadingMessage",value:function isLoadingMessage(e){return e==null?void 0:e.bubbleElement[m].contains(mt.BUBBLE_CLASS);}}]);}();je.TEXT_BUBBLE_CLASS="text-message",je.INTRO_CLASS="deep-chat-intro",je.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var nt=je;var B=/*#__PURE__*/function(){function B(){_classCallCheck(this,B);}return _createClass(B,null,[{key:"getLastElementsByClass",value:function getLastElementsByClass(e,t,n){var _loop=function _loop(){var r=e[s];if(r.bubbleElement[m].contains(t[0])&&!t.slice(1).find(function(a){return!r.bubbleElement[m].contains(a);}))if(n){if(!n.find(function(c){return r.bubbleElement[m].contains(c);}))return{v:r};}else return{v:r};},_ret;for(var s=e.length-1;s>=0;s-=1){_ret=_loop();if(_ret)return _ret.v;}}},{key:"getLastMessage",value:function getLastMessage(e,t,n){for(var s=e.length-1;s>=0;s-=1)if(e[s][0][x]===t)if(n){if(e[s][0][n])return e[s][0];}else return e[s][0];}},{key:"getLastTextToElement",value:function getLastTextToElement(e,t){for(var n=e.length-1;n>=0;n-=1)if(e[n][0]===t)return e[n];}// IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message
80
+ },{key:"refreshTextMessages",value:function refreshTextMessages(e){var _this0=this;this._remarkable=ws.createNew(e),this.messageToElements.forEach(function(t){t[1][h]&&t[0][h]&&_this0.renderText(t[1][h].bubbleElement,t[0][h],t[0][x]);});}},{key:"getFirstMessageContentEl",value:function getFirstMessageContentEl(){var _this$messageToElemen=this.messageToElements[this.messageToElements.length-1][1],e=_this$messageToElemen.text,t=_this$messageToElemen.html,n=_this$messageToElemen.files;return e||t||(n==null?void 0:n[0]);}},{key:"scrollToFirstElement",value:function scrollToFirstElement(e,t){var n;if(e===F){var s=typeof this.focusMode!="boolean"&&((n=this.focusMode)==null?void 0:n.smoothScroll);z.scrollToBottom(this,s);}else if(t&&this.autoScrollAllowed){var _s3=this.getFirstMessageContentEl();z.scrollToBottom(this,!1,_s3==null?void 0:_s3.outerContainer);}}}],[{key:"createContainerElement",value:function createContainerElement(){var e=A();return e.id=Bo,e;}},{key:"isTemporaryElement",value:function isTemporaryElement(e){return je.isLoadingMessage(e)||bt.isElementTemporary(e);}},{key:"createBaseElements",value:function createBaseElements(e){var t=A(),n=A();n[m].add("inner-message-container"),t.appendChild(n),t[m].add("outer-message-container"),t[m].add(B.buildRoleOuterContainerClass(e));var s=A();return s[m].add("message-bubble"),n.appendChild(s),{outerContainer:t,innerContainer:n,bubbleElement:s};}},{key:"createMessageContent",value:function createMessageContent(e){var t=e.text,n=e.files,s=e.html,r=e.custom,o=e._sessionId,a=e.role,c=_defineProperty({},x,a||ne);return t&&(c[h]=t),n&&(c[b]=n),s&&(c[L]=s),!t&&!n&&!s&&(c[h]=""),r&&(c.custom=r),o&&(c._sessionId=o),c;}},{key:"isLoadingMessage",value:function isLoadingMessage(e){return e==null?void 0:e.bubbleElement[m].contains(mt.BUBBLE_CLASS);}}]);}();je.TEXT_BUBBLE_CLASS="text-message",je.INTRO_CLASS="deep-chat-intro",je.LAST_GROUP_MESSAGES_ACTIVE="deep-chat-last-group-messages-active";var nt=je;var B=/*#__PURE__*/function(){function B(){_classCallCheck(this,B);}return _createClass(B,null,[{key:"getLastElementsByClass",value:function getLastElementsByClass(e,t,n){var _loop=function _loop(){var r=e[s];if(r.bubbleElement[m].contains(t[0])&&!t.slice(1).find(function(a){return!r.bubbleElement[m].contains(a);}))if(n){if(!n.find(function(c){return r.bubbleElement[m].contains(c);}))return{v:r};}else return{v:r};},_ret;for(var s=e.length-1;s>=0;s-=1){_ret=_loop();if(_ret)return _ret.v;}}},{key:"getLastMessage",value:function getLastMessage(e,t,n){for(var s=e.length-1;s>=0;s-=1)if(e[s][0][x]===t)if(n){if(e[s][0][n])return e[s][0];}else return e[s][0];}},{key:"getLastTextToElement",value:function getLastTextToElement(e,t){for(var n=e.length-1;n>=0;n-=1)if(e[n][0]===t)return e[n];}// IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message
85
81
  // and if messages have custom roles, it will still look to update the last 'ai' role message
86
82
  // prettier-ignore
87
83
  },{key:"overwriteMessage",value:function overwriteMessage(e,t,n,s,r,o){var a=B.getLastElementsByClass(t,[B.getRoleClass(s),o],[mt.BUBBLE_CLASS]),c=B.getLastMessage(e,s,r);return c&&(c[r]=n),a;}},{key:"getRoleClass",value:function getRoleClass(e){return"".concat(e,"-message");}// makes sure the bubble has dimensions when there is no text
88
- },{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e[m].add(Nr),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e[m].contains(Nr)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,n,s;return Array.from(((s=(n=(t=B.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:n[0])==null?void 0:s.children)||[]).find(function(r){return r[m].contains("message-bubble");});}},{key:"getLastMessageElement",value:function getLastMessageElement(e){var n;var t=(n=e.children[e.children.length-1])==null?void 0:n.children;return t==null?void 0:t[t.length-1];}},{key:"addRoleElements",value:function addRoleElements(e,t,n,s){n==null||n.addBesideBubble(e,t),s==null||s.addBesideBubble(e,t);}},{key:"hideRoleElements",value:function hideRoleElements(e,t,n){t==null||t.tryHide(e),n==null||n.tryHide(e);}},{key:"revealRoleElements",value:function revealRoleElements(e,t,n){t==null||t.tryReveal(e),n==null||n.tryReveal(e);}},{key:"softRemRoleElements",value:function softRemRoleElements(e,t,n){t==null||t.trySoftRem(e),n==null||n.trySoftRem(e);}},{key:"updateRefArr",value:function updateRefArr(e,t,n){n?e.unshift(t):e.push(t);}},{key:"buildRoleOuterContainerClass",value:function buildRoleOuterContainerClass(e){return"".concat(Bs).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$m;e.outerContainer[m].remove(ki,Br,Pi),(_e$outerContainer$m=e.outerContainer[m]).add.apply(_e$outerContainer$m,_toConsumableArray(t));}},{key:"getNumberOfElements",value:function getNumberOfElements(e){var t=0;return e[h]!==void 0&&(t+=1),e[L]!==void 0&&(t+=1),e[b]&&(t+=e[b].length),t;}},{key:"filterdMessageElements",value:function filterdMessageElements(e,t){return e.filter(function(n){return n.bubbleElement[m].contains(t);});}},{key:"findMessageElements",value:function findMessageElements(e,t){return e.find(function(n){return n.bubbleElement[m].contains(t);});}},{key:"generateMessageBodyElements",value:function generateMessageBodyElements(e,t){var n={};return e[h]&&(n[h]=B.findMessageElements(t,nt.TEXT_BUBBLE_CLASS)),e[L]&&(n[L]=B.findMessageElements(t,yt.HTML_BUBBLE_CLASS)),e[b]&&(n[b]=B.filterdMessageElements(t,No)),n;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=B.getNumberOfElements(e),r=n?t.slice(0,s):t.slice(t.length-s);return B.generateMessageBodyElements(e,r);}// if role not present - traverse all, if present - traverse last messages
89
- },{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var n=t?B.buildRoleOuterContainerClass(t):void 0;for(var s=e.length-1;s>=0;s-=1){if(t||(n=Array.from(e[s].outerContainer[m]).find(function(p){return p.startsWith(Bs);})),!n)continue;var r=e[s],o=r.outerContainer[m].contains(n),a=e[s-1],c=e[s+1],l=a==null?void 0:a.outerContainer[m].contains(n),d=c==null?void 0:c.outerContainer[m].contains(n);if(o)!l&&d?B.addNewPositionClasses(r,[ki]):l&&d?B.addNewPositionClasses(r,[Br]):l&&!d?B.addNewPositionClasses(r,[Pi]):!l&&!d&&B.addNewPositionClasses(r,[ki,Pi]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer[m]).find(function(s){return s.startsWith(Bs);})===B.buildRoleOuterContainerClass(e):!1;}},{key:"resetAllRoleElements",value:function resetAllRoleElements(e,t,n){if(!t&&!n)return;var s="";e.forEach(function(r,o){r.bubbleElement[m].contains(Ks)||B.revealRoleElements(r.innerContainer,t,n);var a=Array.from(r.outerContainer[m]).find(function(c){return c.startsWith(Bs);});s===a&&B.hideRoleElements(e[o-1].innerContainer,t,n),s=a;});}// this is a workaround to prevent JSON.parse(JSON.stringify()) from removing the files' 'ref' property values
84
+ },{key:"fillEmptyMessageElement",value:function fillEmptyMessageElement(e,t){t.trim().length===0&&(e[m].add(Or),e.innerHTML='<div style="color:#00000000">.</div>');}},{key:"unfillEmptyMessageElement",value:function unfillEmptyMessageElement(e,t){e[m].contains(Or)&&t.trim().length>0&&e.replaceChildren();}},{key:"getLastMessageBubbleElement",value:function getLastMessageBubbleElement(e){var t,n,s;return Array.from(((s=(n=(t=B.getLastMessageElement(e))==null?void 0:t.children)==null?void 0:n[0])==null?void 0:s.children)||[]).find(function(r){return r[m].contains("message-bubble");});}},{key:"getLastMessageElement",value:function getLastMessageElement(e){var n;var t=(n=e.children[e.children.length-1])==null?void 0:n.children;return t==null?void 0:t[t.length-1];}},{key:"addRoleElements",value:function addRoleElements(e,t,n,s){n==null||n.addBesideBubble(e,t),s==null||s.addBesideBubble(e,t);}},{key:"hideRoleElements",value:function hideRoleElements(e,t,n){t==null||t.tryHide(e),n==null||n.tryHide(e);}},{key:"revealRoleElements",value:function revealRoleElements(e,t,n){t==null||t.tryReveal(e),n==null||n.tryReveal(e);}},{key:"softRemRoleElements",value:function softRemRoleElements(e,t,n){t==null||t.trySoftRem(e),n==null||n.trySoftRem(e);}},{key:"updateRefArr",value:function updateRefArr(e,t,n){n?e.unshift(t):e.push(t);}},{key:"buildRoleOuterContainerClass",value:function buildRoleOuterContainerClass(e){return"".concat(Ns).concat(e);}},{key:"addNewPositionClasses",value:function addNewPositionClasses(e,t){var _e$outerContainer$m;e.outerContainer[m].remove(Ii,Nr,Mi),(_e$outerContainer$m=e.outerContainer[m]).add.apply(_e$outerContainer$m,_toConsumableArray(t));}},{key:"getNumberOfElements",value:function getNumberOfElements(e){var t=0;return e[h]!==void 0&&(t+=1),e[L]!==void 0&&(t+=1),e[b]&&(t+=e[b].length),t;}},{key:"filterdMessageElements",value:function filterdMessageElements(e,t){return e.filter(function(n){return n.bubbleElement[m].contains(t);});}},{key:"findMessageElements",value:function findMessageElements(e,t){return e.find(function(n){return n.bubbleElement[m].contains(t);});}},{key:"generateMessageBodyElements",value:function generateMessageBodyElements(e,t){var n={};return e[h]&&(n[h]=B.findMessageElements(t,nt.TEXT_BUBBLE_CLASS)),e[L]&&(n[L]=B.findMessageElements(t,yt.HTML_BUBBLE_CLASS)),e[b]&&(n[b]=B.filterdMessageElements(t,Oo)),n;}},{key:"generateMessageBody",value:function generateMessageBody(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var s=B.getNumberOfElements(e),r=n?t.slice(0,s):t.slice(t.length-s);return B.generateMessageBodyElements(e,r);}// if role not present - traverse all, if present - traverse last messages
85
+ },{key:"classifyRoleMessages",value:function classifyRoleMessages(e,t){var n=t?B.buildRoleOuterContainerClass(t):void 0;for(var s=e.length-1;s>=0;s-=1){if(t||(n=Array.from(e[s].outerContainer[m]).find(function(p){return p.startsWith(Ns);})),!n)continue;var r=e[s],o=r.outerContainer[m].contains(n),a=e[s-1],c=e[s+1],l=a==null?void 0:a.outerContainer[m].contains(n),d=c==null?void 0:c.outerContainer[m].contains(n);if(o)!l&&d?B.addNewPositionClasses(r,[Ii]):l&&d?B.addNewPositionClasses(r,[Nr]):l&&!d?B.addNewPositionClasses(r,[Mi]):!l&&!d&&B.addNewPositionClasses(r,[Ii,Mi]);else if(t)break;}}},{key:"areOuterContainerClassRolesSame",value:function areOuterContainerClassRolesSame(e,t){return t?Array.from(t.outerContainer[m]).find(function(s){return s.startsWith(Ns);})===B.buildRoleOuterContainerClass(e):!1;}},{key:"resetAllRoleElements",value:function resetAllRoleElements(e,t,n){if(!t&&!n)return;var s="";e.forEach(function(r,o){r.bubbleElement[m].contains(Vs)||B.revealRoleElements(r.innerContainer,t,n);var a=Array.from(r.outerContainer[m]).find(function(c){return c.startsWith(Ns);});s===a&&B.hideRoleElements(e[o-1].innerContainer,t,n),s=a;});}// this is a workaround to prevent JSON.parse(JSON.stringify()) from removing the files' 'ref' property values
90
86
  // and 'custom' property value if it is not shallow copyable
91
87
  // note - structuredClone can fix this but it doesn't have good legacy compatibility
92
- },{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return B.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!==U)return e;if(Array.isArray(e))return e.map(function(n){return B.processMessageContent(n);});var t={};return Object.entries(e).forEach(function(_ref6){var _ref7=_slicedToArray(_ref6,2),n=_ref7[0],s=_ref7[1];n==="ref"&&s instanceof File||n==="custom"?t[n]=s:s!==null&&_typeof(s)===U?t[n]=B.processMessageContent(s):t[n]=s;}),t;}}]);}();var xt=/*#__PURE__*/function(){function xt(e,t){_classCallCheck(this,xt);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialContent="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(xt,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e[h])===void 0&&(e==null?void 0:e[L])===void 0)return console[f](Uo);var t=(e==null?void 0:e[h])||(e==null?void 0:e[L])||"",n=z.isScrollbarAtBottomOfElement(this._messages.elementRef),s=(e==null?void 0:e[h])!==void 0?h:L;if(!this._elements&&!this._message)this.setInitialState(s,t,e==null?void 0:e[x]);else{if(this._streamType!==s)return console[f](Ta);e!=null&&e[x]&&(e==null?void 0:e[x])!==this._activeMessageRole?(this.finaliseStreamedMessage(!1),this.setInitialState(s,t,e==null?void 0:e[x])):this.updateBasedOnType(t,s,e==null?void 0:e.overwrite);}e!=null&&e._sessionId&&(this._sessionId=e==null?void 0:e._sessionId),e!=null&&e.custom&&this._message&&(this._message.custom=e.custom),n&&this._messages.autoScrollAllowed&&z.scrollToBottom(this._messages);}},{key:"setInitialState",value:function setInitialState(e,t,n){var o,a,c;this._streamType=e,this._targetWrapper=void 0,this._fileAdded=!1,this._partialContent="",this._partialBubble=void 0,n!==null&&n!==void 0?n:n=ne;var s=((o=this._messages._customWrappers)==null?void 0:o[n])||((a=this._messages._customWrappers)==null?void 0:a[w]),r=s?"":t;this._elements=e===h?this._messages.addNewTextMessage(r,n):yt.add(this._messages,r,n),this._elements&&(this._elements.bubbleElement[m].add(xt.MESSAGE_CLASS),this._activeMessageRole=n,this._message=_defineProperty(_defineProperty({},x,this._activeMessageRole),e,r),this._messages.messageToElements.push([this._message,_defineProperty({},e,this._elements)]),s&&this.setTargetWrapperIfNeeded(this._elements,t,this._streamType,s),(c=this._messages.scrollButton)==null||c.updateHidden());}// not using existing htmlUtils htmlWrappers logic to be able to stream html
93
- },{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,n,s){e.bubbleElement.innerHTML=s,this._targetWrapper=oe.getTargetWrapper(e.bubbleElement),this._elements&&oe.apply(this._messages,this._elements.bubbleElement),this.updateBasedOnType(t,n);}},{key:"updateBasedOnType",value:function updateBasedOnType(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var o;var s=this._targetWrapper||((o=this._elements)==null?void 0:o.bubbleElement);this._partialRender||B.unfillEmptyMessageElement(s,e),(t===h?this.updateText:this.updateHTML).bind(this)(e,s,n);}},{key:"updateText",value:function updateText(e,t,n){this._message&&(this._message[h]=n?e:this._message[h]+e,this._partialRender&&this.isNewPartialRenderParagraph(t,n)&&this.partialRenderNewParagraph(t),this._partialBubble?this.updatePartialRenderBubble(e):this._messages.renderText(t,this._message[h]));}},{key:"containsPartialRenderMark",value:function containsPartialRenderMark(e){var t=e.indexOf(xt.PARTIAL_RENDER_MARK);return t===-1?!1:!e.substring(t+xt.PARTIAL_RENDER_MARK.length).startsWith("---");}},{key:"isNewPartialRenderParagraph",value:function isNewPartialRenderParagraph(e,t){var s;if(t)return e.innerHTML="",!0;var n=this._streamType;if(!this._partialBubble){var r=(s=this._message)==null?void 0:s[n];return!!r&&this.containsPartialRenderMark(r);}return!!this._partialContent&&this.containsPartialRenderMark(this._partialContent);}},{key:"partialRenderNewParagraph",value:function partialRenderNewParagraph(e){this._partialContent="",this._partialBubble=A(),this._partialBubble[m].add("partial-render-message"),e.appendChild(this._partialBubble);}},{key:"updatePartialRenderBubble",value:function updatePartialRenderBubble(e){this._partialContent+=e,this._streamType===h?this._messages.renderText(this._partialBubble,this._partialContent):this._partialBubble.innerHTML=this._partialContent;}},{key:"updateHTML",value:function updateHTML(e,t,n){if(this._message)if(this._message[L]=n?e:(this._message[L]||"")+e,this._partialRender&&this.isNewPartialRenderParagraph(t,n)&&this.partialRenderNewParagraph(t),this._partialBubble)this.updatePartialRenderBubble(e);else if(n)t.innerHTML=e;else{var s=A("span");s.innerHTML=e,t.appendChild(s);}}},{key:"finaliseStreamedMessage",value:function finaliseStreamedMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!0;var t,n;if(!this._endStreamAfterOperation&&!(this._fileAdded&&!this._elements)){if(!this._elements)throw Error(Ra);this._message&&(t=this._elements.bubbleElement)!=null&&t[m].contains(xt.MESSAGE_CLASS)&&(this._streamType===h?this._messages.textToSpeech&&Rn.speak(this._message[h]||"",this._messages.textToSpeech):this._streamType===L&&this._elements&&oe.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement[m].remove(xt.MESSAGE_CLASS),this._message&&(this._sessionId&&(this._message._sessionId=this._sessionId),this._messages.sendClientUpdate(nt.createMessageContent(this._message),!1),(n=this._messages.browserStorage)==null||n.addMessages(this._messages.messageToElements.map(function(_ref9){var _ref0=_slicedToArray(_ref9,1),s=_ref0[0];return s;}))),this._hasStreamEnded=e);}}},{key:"markFileAdded",value:function markFileAdded(){this._fileAdded=!0;}// prettier-ignore
88
+ },{key:"deepCloneMessagesWithReferences",value:function deepCloneMessagesWithReferences(e){return e.map(function(t){return B.processMessageContent(t);});}},{key:"processMessageContent",value:function processMessageContent(e){if(e==null||_typeof(e)!==U)return e;if(Array.isArray(e))return e.map(function(n){return B.processMessageContent(n);});var t={};return Object.entries(e).forEach(function(_ref0){var _ref1=_slicedToArray(_ref0,2),n=_ref1[0],s=_ref1[1];n==="ref"&&s instanceof File||n==="custom"?t[n]=s:s!==null&&_typeof(s)===U?t[n]=B.processMessageContent(s):t[n]=s;}),t;}}]);}();var xt=/*#__PURE__*/function(){function xt(e,t){_classCallCheck(this,xt);this._fileAdded=!1,this._streamType="",this._hasStreamEnded=!1,this._partialContent="",this._messages=e,_typeof(t)=="object"&&(this._partialRender=t.partialRender);}return _createClass(xt,[{key:"upsertStreamedMessage",value:function upsertStreamedMessage(e){if(this._hasStreamEnded)return;if((e==null?void 0:e[h])===void 0&&(e==null?void 0:e[L])===void 0)return console[f](Fo);var t=(e==null?void 0:e[h])||(e==null?void 0:e[L])||"",n=z.isScrollbarAtBottomOfElement(this._messages.elementRef),s=(e==null?void 0:e[h])!==void 0?h:L;if(!this._elements&&!this._message)this.setInitialState(s,t,e==null?void 0:e[x]);else{if(this._streamType!==s)return console[f](Ca);e!=null&&e[x]&&(e==null?void 0:e[x])!==this._activeMessageRole?(this.finaliseStreamedMessage(!1),this.setInitialState(s,t,e==null?void 0:e[x])):this.updateBasedOnType(t,s,e==null?void 0:e.overwrite);}e!=null&&e._sessionId&&(this._sessionId=e==null?void 0:e._sessionId),e!=null&&e.custom&&this._message&&(this._message.custom=e.custom),n&&this._messages.autoScrollAllowed&&z.scrollToBottom(this._messages);}},{key:"setInitialState",value:function setInitialState(e,t,n){var o,a,c;this._streamType=e,this._targetWrapper=void 0,this._fileAdded=!1,this._partialContent="",this._partialBubble=void 0,n!==null&&n!==void 0?n:n=ne;var s=((o=this._messages._customWrappers)==null?void 0:o[n])||((a=this._messages._customWrappers)==null?void 0:a[w]),r=s?"":t;this._elements=e===h?this._messages.addNewTextMessage(r,n):yt.add(this._messages,r,n),this._elements&&(this._elements.bubbleElement[m].add(xt.MESSAGE_CLASS),this._activeMessageRole=n,this._message=_defineProperty(_defineProperty({},x,this._activeMessageRole),e,r),this._messages.messageToElements.push([this._message,_defineProperty({},e,this._elements)]),s&&this.setTargetWrapperIfNeeded(this._elements,t,this._streamType,s),(c=this._messages.scrollButton)==null||c.updateHidden());}// not using existing htmlUtils htmlWrappers logic to be able to stream html
89
+ },{key:"setTargetWrapperIfNeeded",value:function setTargetWrapperIfNeeded(e,t,n,s){e.bubbleElement.innerHTML=s,this._targetWrapper=oe.getTargetWrapper(e.bubbleElement),this._elements&&oe.apply(this._messages,this._elements.bubbleElement),this.updateBasedOnType(t,n);}},{key:"updateBasedOnType",value:function updateBasedOnType(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var o;var s=this._targetWrapper||((o=this._elements)==null?void 0:o.bubbleElement);this._partialRender||B.unfillEmptyMessageElement(s,e),(t===h?this.updateText:this.updateHTML).bind(this)(e,s,n);}},{key:"updateText",value:function updateText(e,t,n){this._message&&(this._message[h]=n?e:this._message[h]+e,this._partialRender&&this.isNewPartialRenderParagraph(t,n)&&this.partialRenderNewParagraph(t),this._partialBubble?this.updatePartialRenderBubble(e):this._messages.renderText(t,this._message[h]));}},{key:"containsPartialRenderMark",value:function containsPartialRenderMark(e){var t=e.indexOf(xt.PARTIAL_RENDER_MARK);return t===-1?!1:!e.substring(t+xt.PARTIAL_RENDER_MARK.length).startsWith("---");}},{key:"isNewPartialRenderParagraph",value:function isNewPartialRenderParagraph(e,t){var s;if(t)return e.innerHTML="",!0;var n=this._streamType;if(!this._partialBubble){var r=(s=this._message)==null?void 0:s[n];return!!r&&this.containsPartialRenderMark(r);}return!!this._partialContent&&this.containsPartialRenderMark(this._partialContent);}},{key:"partialRenderNewParagraph",value:function partialRenderNewParagraph(e){this._partialContent="",this._partialBubble=A(),this._partialBubble[m].add("partial-render-message"),e.appendChild(this._partialBubble);}},{key:"updatePartialRenderBubble",value:function updatePartialRenderBubble(e){this._partialContent+=e,this._streamType===h?this._messages.renderText(this._partialBubble,this._partialContent):this._partialBubble.innerHTML=this._partialContent;}},{key:"updateHTML",value:function updateHTML(e,t,n){if(this._message)if(this._message[L]=n?e:(this._message[L]||"")+e,this._partialRender&&this.isNewPartialRenderParagraph(t,n)&&this.partialRenderNewParagraph(t),this._partialBubble)this.updatePartialRenderBubble(e);else if(n)t.innerHTML=e;else{var s=A("span");s.innerHTML=e,t.appendChild(s);}}},{key:"finaliseStreamedMessage",value:function finaliseStreamedMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!0;var t,n;if(!this._endStreamAfterOperation&&!(this._fileAdded&&!this._elements)){if(!this._elements)throw Error(Ta);this._message&&(t=this._elements.bubbleElement)!=null&&t[m].contains(xt.MESSAGE_CLASS)&&(this._streamType===h?this._messages.textToSpeech&&Rn.speak(this._message[h]||"",this._messages.textToSpeech):this._streamType===L&&this._elements&&oe.apply(this._messages,this._elements.outerContainer),this._elements.bubbleElement[m].remove(xt.MESSAGE_CLASS),this._message&&(this._sessionId&&(this._message._sessionId=this._sessionId),this._messages.sendClientUpdate(nt.createMessageContent(this._message),!1),(n=this._messages.browserStorage)==null||n.addMessages(this._messages.messageToElements.map(function(_ref11){var _ref12=_slicedToArray(_ref11,1),s=_ref12[0];return s;}))),this._hasStreamEnded=e);}}},{key:"markFileAdded",value:function markFileAdded(){this._fileAdded=!0;}// prettier-ignore
94
90
  },{key:"endStreamAfterFileDownloaded",value:function(){var _endStreamAfterFileDownloaded=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e,t){var _yield$t,n,s;return _regenerator().w(function(_context2){while(1)switch(_context2.n){case 0:this._endStreamAfterOperation=!0;_context2.n=1;return t();case 1:_yield$t=_context2.v;n=_yield$t.text;s=_yield$t.files;n&&this.updateBasedOnType(n,h,!0),this._endStreamAfterOperation=!1,this.finaliseStreamedMessage(),s&&e.addNewMessage(_defineProperty({},b,s));case 2:return _context2.a(2);}},_callee2,this);}));function endStreamAfterFileDownloaded(_x3,_x4){return _endStreamAfterFileDownloaded.apply(this,arguments);}return endStreamAfterFileDownloaded;}()}]);}();xt.MESSAGE_CLASS="streamed-message",xt.PARTIAL_RENDER_MARK="\n\n";var ht=xt;var D=/*#__PURE__*/function(){function D(){_classCallCheck(this,D);}return _createClass(D,null,[{key:"tempRemoveContentHeader",value:// need to pass stringifyBody boolean separately as binding is throwing an error for some reason
95
91
  // prettier-ignore
96
- function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,n){var s,r,_t3;return _regenerator().w(function(_context3){while(1)switch(_context3.p=_context3.n){case 0:if(e!=null&&e.headers){_context3.n=1;break;}throw new Error(He);case 1:s=e.headers[q];delete e.headers[q];_context3.p=2;_context3.n=3;return t(n);case 3:r=_context3.v;_context3.n=5;break;case 4:_context3.p=4;_t3=_context3.v;throw e.headers[q]=s,_t3;case 5:return _context3.a(2,(e.headers[q]=s,r));}},_callee3,null,[[2,4]]);}));function tempRemoveContentHeader(_x9,_x0,_x1){return _tempRemoveContentHeader.apply(this,arguments);}return tempRemoveContentHeader;}()},{key:"displayError",value:function displayError(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"Service error, please try again.";if(console[f](t),_typeof(t)===U)return t instanceof Error?e.addNewErrorMessage(ae,t.message):Array.isArray(t)||_typeof(t[f])===Ee?e.addNewErrorMessage(ae,t):Object.keys(t).length===0?e.addNewErrorMessage(ae,n):e.addNewErrorMessage(ae,le(t));e.addNewErrorMessage(ae,t);}// eslint-disable-next-line @typescript-eslint/no-explicit-any
97
- },{key:"fetch",value:function(_fetch){function fetch(_x5,_x6,_x7,_x8){return _fetch.apply(this,arguments);}fetch.toString=function(){return _fetch.toString();};return fetch;}(function(e,t,n,s){var o,a;var r={method:((o=e.connectSettings)==null?void 0:o.method)||ye,headers:t};return r.method!==ue&&(r.body=n?le(s):s),e.connectSettings.credentials&&(r.credentials=e.connectSettings.credentials),fetch(((a=e.connectSettings)==null?void 0:a.url)||e.url||"",r);})},{key:"processResponseByType",value:function processResponseByType(e){var t=e.headers.get("content-type");return t!=null&&t.includes(te)?e.json():t!=null&&t.includes("text/plain")||!t?e:e.blob();}},{key:"processRequestInterceptor",value:function(){var _processRequestInterceptor=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(e,t){var o,n,s,r,_t4;return _regenerator().w(function(_context4){while(1)switch(_context4.n){case 0:_context4.n=1;return(o=e.requestInterceptor)==null?void 0:o.call(e,t);case 1:_t4=_context4.v;if(_t4){_context4.n=2;break;}_t4=t;case 2:n=_t4;s=n;r=n;return _context4.a(2,{body:s.body,headers:s.headers,error:r[f]});}},_callee4);}));function processRequestInterceptor(_x10,_x11){return _processRequestInterceptor.apply(this,arguments);}return processRequestInterceptor;}()},{key:"validateResponseFormat",value:function validateResponseFormat(e,t){if(!e)return!1;var n=Array.isArray(e)?e:[e];return t&&n.length>1?(console[f](Fo),!1):!n.find(function(r){return _typeof(r)!="object"||!(_typeof(r[f])===Ee||_typeof(r[h])===Ee||_typeof(r[L])===Ee||Array.isArray(r[b]));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,n){e.addNewErrorMessage(ae,t),n==null||n();}// prettier-ignore
98
- },{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e,t){var n,s,_n$displayError,r,_n$useRI,o,a,c,l,d,_args5=arguments,_t5;return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:n=_args5.length>2&&_args5[2]!==undefined?_args5[2]:{};s=n.io,_n$displayError=n.displayError,r=_n$displayError===void 0?!0:_n$displayError,_n$useRI=n.useRI,o=_n$useRI===void 0?!0:_n$useRI;if(s!=null&&s.extractResultData){_context5.n=1;break;}return _context5.a(2,t);case 1:a=o?s.deepChat.responseInterceptor:void 0;_context5.n=2;return a==null?void 0:a(t);case 2:_t5=_context5.v;if(_t5){_context5.n=3;break;}_t5=t;case 3:c=_t5;_context5.n=4;return s.extractResultData(c);case 4:l=_context5.v;if(!(!l||_typeof(l)!="object"&&!Array.isArray(l))){_context5.n=5;break;}if(r){d=Tn(t,"response",!!a,c);D.displayError(e,d);}return _context5.a(2);case 5:return _context5.a(2,l);}},_callee5);}));function basicResponseProcessing(_x12,_x13){return _basicResponseProcessing.apply(this,arguments);}return basicResponseProcessing;}()}]);}();function El(_x14,_x15){return _El.apply(this,arguments);}function _El(){_El=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee196(i,e){var t,n;return _regenerator().w(function(_context196){while(1)switch(_context196.n){case 0:t=i.getReader();case 1:_context196.n=2;return t.read();case 2:if((n=_context196.v).done){_context196.n=4;break;}e(n.value);case 3:_context196.n=1;break;case 4:return _context196.a(2);}},_callee196);}));return _El.apply(this,arguments);}function vl(i){var e,t,n,s=!1;return function(o){e===void 0?(e=o,t=0,n=-1):e=xl(e,o);var a=e.length;var c=0;for(;t<a;){s&&(e[t]===10&&(c=++t),s=!1);var l=-1;for(;t<a&&l===-1;++t)switch(e[t]){case 58:n===-1&&(n=t-c);break;case 13:s=!0;case 10:l=t;break;}if(l===-1)break;i(e.subarray(c,l),n),c=t,n=-1;}c===a?e=void 0:c!==0&&(e=e.subarray(c),t-=c);};}function Sl(i,e,t){var n=eo();var s=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(n),n=eo();else if(a>0){var c=s.decode(o.subarray(0,a)),l=a+(o[a+1]===32?2:1),d=s.decode(o.subarray(l));switch(c){case"data":n.data=n.data?n.data+"\n"+d:d;break;case"event":n.event=d;break;case"id":i(n.id=d);break;case"retry":var p=parseInt(d,10);isNaN(p)||e(n.retry=p);break;}}};}function xl(i,e){var t=new Uint8Array(i.length+e.length);return t.set(i),t.set(e,i.length),t;}function eo(){return{data:"",event:"",id:"",retry:void 0};}var Al=function Al(i,e){var t={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&e.indexOf(n)<0&&(t[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(i);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(i,n[s])&&(t[n[s]]=i[n[s]]);return t;};var Gi="text/event-stream",wl=1e3,to="last-event-id";function Cl(i,e){var t=e.signal,n=e.headers,s=e.onopen,r=e.onmessage,o=e.onclose,a=e.onerror,c=e.openWhenHidden,l=e.fetch,d=Al(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(p,u){var g=Object.assign({},n);g.accept||(g.accept=Gi);var y;function _(){y.abort(),document.hidden||Re();}c||document.addEventListener("visibilitychange",_);var S=wl,M=0;function K(){document.removeEventListener("visibilitychange",_),window.clearTimeout(M),y.abort();}t==null||t.addEventListener("abort",function(){K(),p();});var ie=l!==null&&l!==void 0?l:window.fetch,re=s!==null&&s!==void 0?s:Tl;function Re(){return _Re.apply(this,arguments);}function _Re(){_Re=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var Lt,Ot,ze,_t6;return _regenerator().w(function(_context6){while(1)switch(_context6.p=_context6.n){case 0:y=new AbortController();_context6.p=1;_context6.n=2;return ie(i,Object.assign(Object.assign({},d),{headers:g,signal:y.signal}));case 2:Ot=_context6.v;_context6.n=3;return re(Ot);case 3:_context6.n=4;return El(Ot.body,vl(Sl(function(ze){ze?g[to]=ze:delete g[to];},function(ze){S=ze;},r)));case 4:o==null||o();K();p();_context6.n=6;break;case 5:_context6.p=5;_t6=_context6.v;if(!y.signal.aborted)try{ze=(Lt=a==null?void 0:a(_t6))!==null&&Lt!==void 0?Lt:S;window.clearTimeout(M),M=window.setTimeout(Re,ze);}catch(ze){K(),u(ze);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _Re.apply(this,arguments);}Re();});}function Tl(i){var e=i.headers.get("content-type");if(!(e!=null&&e.startsWith(Gi)))throw new Error("Expected content-type to be ".concat(Gi,", Actual: ").concat(e));}var V=/*#__PURE__*/function(){function V(){_classCallCheck(this,V);}return _createClass(V,null,[{key:"request",value:// prettier-ignore
99
- function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,n){var s,r,u,g,y,_,S,o,_yield$D$processReque,a,c,l,d,p,_args7=arguments;return _regenerator().w(function(_context7){while(1)switch(_context7.n){case 0:s=_args7.length>3&&_args7[3]!==undefined?_args7[3]:!0;r=_args7.length>4&&_args7[4]!==undefined?_args7[4]:!1;o={body:t,headers:(u=e.connectSettings)==null?void 0:u.headers};_context7.n=1;return D.processRequestInterceptor(e.deepChat,o);case 1:_yield$D$processReque=_context7.v;a=_yield$D$processReque.body;c=_yield$D$processReque.headers;l=_yield$D$processReque.error;if(!l){_context7.n=2;break;}return _context7.a(2,D.onInterceptorError(n,l,e.streamHandlers.onClose));case 2:if(!((g=e.connectSettings)!=null&&g.handler)){_context7.n=3;break;}return _context7.a(2,dt.stream(e,a,n));case 3:if(!(((y=e.connectSettings)==null?void 0:y.url)===pt.URL)){_context7.n=4;break;}return _context7.a(2,pt.requestStream(n,e));case 4:d=new ht(n,e.stream),p={method:((_=e.connectSettings)==null?void 0:_.method)||ye,headers:c,credentials:(S=e.connectSettings)==null?void 0:S.credentials,body:s?le(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?V.handleReadableStream(e,n,d,p,r,a):V.handleEventStream(e,n,d,p,r,a),d));}},_callee7);}));function request(_x16,_x17,_x18){return _request.apply(this,arguments);}return request;}()// prettier-ignore
100
- },{key:"handleReadableStream",value:function handleReadableStream(e,t,n,s,r,o){var d;var _e$streamHandlers=e.streamHandlers,a=_e$streamHandlers.onOpen,c=_e$streamHandlers.onClose;var l=!1;fetch(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",s).then(/*#__PURE__*/function(){var _ref1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(p){var _,S,u,g,y,_yield$u$read,M,K,ie,re,Re,_t7;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(p.body){_context8.n=1;break;}throw new Error(Ia);case 1:u=p.body.getReader(),g=new TextDecoder();a();y=!1;case 2:if(!(!y&&!l)){_context8.n=8;break;}_context8.n=3;return u.read();case 3:_yield$u$read=_context8.v;M=_yield$u$read.value;K=_yield$u$read.done;if(!(y=K,y)){_context8.n=4;break;}V.handleClose(e,n,c,r);_context8.n=7;break;case 4:ie=g.decode(M,{stream:!0});_context8.n=5;return(S=(_=e.deepChat).responseInterceptor)==null?void 0:S.call(_,ie);case 5:_t7=_context8.v;if(_t7){_context8.n=6;break;}_t7=ie;case 6:re=_t7;Re=_typeof(re)=="object"?re:_defineProperty({},h,ie);V.handleMessage(e,t,n,Re,o);case 7:_context8.n=2;break;case 8:return _context8.a(2);}},_callee8);}));return function(_x19){return _ref1.apply(this,arguments);};}())["catch"](function(p){V.handleError(e,t,p);}),e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l=!0;};}// prettier-ignore
101
- },{key:"handleEventStream",value:function handleEventStream(e,t,n,s,r,o){var d;var _e$streamHandlers2=e.streamHandlers,a=_e$streamHandlers2.onOpen,c=_e$streamHandlers2.onClose,l=new AbortController();e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l.abort();},Cl(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",_objectSpread(_objectSpread({},s),{},{openWhenHidden:!0,// keep stream open when browser tab not open
102
- onopen:function onopen(p){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(){return _regenerator().w(function(_context9){while(1)switch(_context9.n){case 0:if(!p.ok){_context9.n=1;break;}return _context9.a(2,a());case 1:_context9.n=2;return D.processResponseByType(p);case 2:throw _context9.v;case 3:return _context9.a(2);}},_callee9);}))();},onmessage:function onmessage(p){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(){var u,g,y,_,_t8;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(le(p.data)!==le("[DONE]"))){_context0.n=3;break;}try{y=JSON.parse(p.data);}catch(_unused6){y={};}_context0.n=1;return(g=(u=e.deepChat).responseInterceptor)==null?void 0:g.call(u,y);case 1:_t8=_context0.v;if(_t8){_context0.n=2;break;}_t8=y;case 2:_=_t8;V.handleMessage(e,t,n,_,o);case 3:return _context0.a(2);}},_callee0);}))();},onerror:function onerror(p){throw c(),p;},onclose:function onclose(){V.handleClose(e,n,c,r);},signal:l.signal}))["catch"](function(p){V.handleError(e,t,p);});}//prettier-ignore
92
+ function(){var _tempRemoveContentHeader=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e,t,n){var s,r,_t3;return _regenerator().w(function(_context3){while(1)switch(_context3.p=_context3.n){case 0:if(e!=null&&e.headers){_context3.n=1;break;}throw new Error(He);case 1:s=e.headers[q];delete e.headers[q];_context3.p=2;_context3.n=3;return t(n);case 3:r=_context3.v;_context3.n=5;break;case 4:_context3.p=4;_t3=_context3.v;throw e.headers[q]=s,_t3;case 5:return _context3.a(2,(e.headers[q]=s,r));}},_callee3,null,[[2,4]]);}));function tempRemoveContentHeader(_x9,_x0,_x1){return _tempRemoveContentHeader.apply(this,arguments);}return tempRemoveContentHeader;}()},{key:"displayError",value:function displayError(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"Service error, please try again.";if(console[f](t),_typeof(t)===U)return t instanceof Error?e.addNewErrorMessage(ae,t.message):Array.isArray(t)||_typeof(t[f])===Ee?e.addNewErrorMessage(ae,t):Object.keys(t).length===0?e.addNewErrorMessage(ae,n):e.addNewErrorMessage(ae,ce(t));e.addNewErrorMessage(ae,t);}// eslint-disable-next-line @typescript-eslint/no-explicit-any
93
+ },{key:"fetch",value:function(_fetch){function fetch(_x5,_x6,_x7,_x8){return _fetch.apply(this,arguments);}fetch.toString=function(){return _fetch.toString();};return fetch;}(function(e,t,n,s){var o,a;var r={method:((o=e.connectSettings)==null?void 0:o.method)||ye,headers:t};return r.method!==ue&&(r.body=n?ce(s):s),e.connectSettings.credentials&&(r.credentials=e.connectSettings.credentials),fetch(((a=e.connectSettings)==null?void 0:a.url)||e.url||"",r);})},{key:"processResponseByType",value:function processResponseByType(e){var t=e.headers.get("content-type");return t!=null&&t.includes(te)?e.json():t!=null&&t.includes("text/plain")||!t?e:e.blob();}},{key:"processRequestInterceptor",value:function(){var _processRequestInterceptor=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(e,t){var o,n,s,r,_t4;return _regenerator().w(function(_context4){while(1)switch(_context4.n){case 0:_context4.n=1;return(o=e.requestInterceptor)==null?void 0:o.call(e,t);case 1:_t4=_context4.v;if(_t4){_context4.n=2;break;}_t4=t;case 2:n=_t4;s=n;r=n;return _context4.a(2,{body:s.body,headers:s.headers,error:r[f]});}},_callee4);}));function processRequestInterceptor(_x10,_x11){return _processRequestInterceptor.apply(this,arguments);}return processRequestInterceptor;}()},{key:"validateResponseFormat",value:function validateResponseFormat(e,t){if(!e)return!1;var n=Array.isArray(e)?e:[e];return t&&n.length>1?(console[f](Do),!1):!n.find(function(r){return _typeof(r)!="object"||!(_typeof(r[f])===Ee||_typeof(r[h])===Ee||_typeof(r[L])===Ee||Array.isArray(r[b]));});}},{key:"onInterceptorError",value:function onInterceptorError(e,t,n){e.addNewErrorMessage(ae,t),n==null||n();}// prettier-ignore
94
+ },{key:"basicResponseProcessing",value:function(){var _basicResponseProcessing=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(e,t){var n,s,_n$displayError,r,_n$useRI,o,a,c,l,d,_args5=arguments,_t5;return _regenerator().w(function(_context5){while(1)switch(_context5.n){case 0:n=_args5.length>2&&_args5[2]!==undefined?_args5[2]:{};s=n.io,_n$displayError=n.displayError,r=_n$displayError===void 0?!0:_n$displayError,_n$useRI=n.useRI,o=_n$useRI===void 0?!0:_n$useRI;if(s!=null&&s.extractResultData){_context5.n=1;break;}return _context5.a(2,t);case 1:a=o?s.deepChat.responseInterceptor:void 0;_context5.n=2;return a==null?void 0:a(t);case 2:_t5=_context5.v;if(_t5){_context5.n=3;break;}_t5=t;case 3:c=_t5;_context5.n=4;return s.extractResultData(c);case 4:l=_context5.v;if(!(!l||_typeof(l)!="object"&&!Array.isArray(l))){_context5.n=5;break;}if(r){d=Tn(t,"response",!!a,c);D.displayError(e,d);}return _context5.a(2);case 5:return _context5.a(2,l);}},_callee5);}));function basicResponseProcessing(_x12,_x13){return _basicResponseProcessing.apply(this,arguments);}return basicResponseProcessing;}()}]);}();function _l(_x14,_x15){return _l2.apply(this,arguments);}function _l2(){_l2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee196(i,e){var t,n;return _regenerator().w(function(_context196){while(1)switch(_context196.n){case 0:t=i.getReader();case 1:_context196.n=2;return t.read();case 2:if((n=_context196.v).done){_context196.n=4;break;}e(n.value);case 3:_context196.n=1;break;case 4:return _context196.a(2);}},_callee196);}));return _l2.apply(this,arguments);}function El(i){var e,t,n,s=!1;return function(o){e===void 0?(e=o,t=0,n=-1):e=Sl(e,o);var a=e.length;var c=0;for(;t<a;){s&&(e[t]===10&&(c=++t),s=!1);var l=-1;for(;t<a&&l===-1;++t)switch(e[t]){case 58:n===-1&&(n=t-c);break;case 13:s=!0;case 10:l=t;break;}if(l===-1)break;i(e.subarray(c,l),n),c=t,n=-1;}c===a?e=void 0:c!==0&&(e=e.subarray(c),t-=c);};}function vl(i,e,t){var n=Qr();var s=new TextDecoder();return function(o,a){if(o.length===0)t==null||t(n),n=Qr();else if(a>0){var c=s.decode(o.subarray(0,a)),l=a+(o[a+1]===32?2:1),d=s.decode(o.subarray(l));switch(c){case"data":n.data=n.data?n.data+"\n"+d:d;break;case"event":n.event=d;break;case"id":i(n.id=d);break;case"retry":var p=parseInt(d,10);isNaN(p)||e(n.retry=p);break;}}};}function Sl(i,e){var t=new Uint8Array(i.length+e.length);return t.set(i),t.set(e,i.length),t;}function Qr(){return{data:"",event:"",id:"",retry:void 0};}var xl=function xl(i,e){var t={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&e.indexOf(n)<0&&(t[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(i);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(i,n[s])&&(t[n[s]]=i[n[s]]);return t;};var $i="text/event-stream",Al=1e3,eo="last-event-id";function wl(i,e){var t=e.signal,n=e.headers,s=e.onopen,r=e.onmessage,o=e.onclose,a=e.onerror,c=e.openWhenHidden,l=e.fetch,d=xl(e,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise(function(p,u){var g=Object.assign({},n);g.accept||(g.accept=$i);var y;function _(){y.abort(),document.hidden||Re();}c||document.addEventListener("visibilitychange",_);var S=Al,M=0;function K(){document.removeEventListener("visibilitychange",_),window.clearTimeout(M),y.abort();}t==null||t.addEventListener("abort",function(){K(),p();});var ie=l!==null&&l!==void 0?l:window.fetch,re=s!==null&&s!==void 0?s:Cl;function Re(){return _Re.apply(this,arguments);}function _Re(){_Re=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var Lt,Ot,ze,_t6;return _regenerator().w(function(_context6){while(1)switch(_context6.p=_context6.n){case 0:y=new AbortController();_context6.p=1;_context6.n=2;return ie(i,Object.assign(Object.assign({},d),{headers:g,signal:y.signal}));case 2:Ot=_context6.v;_context6.n=3;return re(Ot);case 3:_context6.n=4;return _l(Ot.body,El(vl(function(ze){ze?g[eo]=ze:delete g[eo];},function(ze){S=ze;},r)));case 4:o==null||o();K();p();_context6.n=6;break;case 5:_context6.p=5;_t6=_context6.v;if(!y.signal.aborted)try{ze=(Lt=a==null?void 0:a(_t6))!==null&&Lt!==void 0?Lt:S;window.clearTimeout(M),M=window.setTimeout(Re,ze);}catch(ze){K(),u(ze);}case 6:return _context6.a(2);}},_callee6,null,[[1,5]]);}));return _Re.apply(this,arguments);}Re();});}function Cl(i){var e=i.headers.get("content-type");if(!(e!=null&&e.startsWith($i)))throw new Error("Expected content-type to be ".concat($i,", Actual: ").concat(e));}var V=/*#__PURE__*/function(){function V(){_classCallCheck(this,V);}return _createClass(V,null,[{key:"request",value:// prettier-ignore
95
+ function(){var _request=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(e,t,n){var s,r,u,g,y,_,S,o,_yield$D$processReque,a,c,l,d,p,_args7=arguments;return _regenerator().w(function(_context7){while(1)switch(_context7.n){case 0:s=_args7.length>3&&_args7[3]!==undefined?_args7[3]:!0;r=_args7.length>4&&_args7[4]!==undefined?_args7[4]:!1;o={body:t,headers:(u=e.connectSettings)==null?void 0:u.headers};_context7.n=1;return D.processRequestInterceptor(e.deepChat,o);case 1:_yield$D$processReque=_context7.v;a=_yield$D$processReque.body;c=_yield$D$processReque.headers;l=_yield$D$processReque.error;if(!l){_context7.n=2;break;}return _context7.a(2,D.onInterceptorError(n,l,e.streamHandlers.onClose));case 2:if(!((g=e.connectSettings)!=null&&g.handler)){_context7.n=3;break;}return _context7.a(2,dt.stream(e,a,n));case 3:if(!(((y=e.connectSettings)==null?void 0:y.url)===pt.URL)){_context7.n=4;break;}return _context7.a(2,pt.requestStream(n,e));case 4:d=new ht(n,e.stream),p={method:((_=e.connectSettings)==null?void 0:_.method)||ye,headers:c,credentials:(S=e.connectSettings)==null?void 0:S.credentials,body:s?ce(a):a};return _context7.a(2,(_typeof(e.stream)=="object"&&e.stream.readable?V.handleReadableStream(e,n,d,p,r,a):V.handleEventStream(e,n,d,p,r,a),d));}},_callee7);}));function request(_x16,_x17,_x18){return _request.apply(this,arguments);}return request;}()// prettier-ignore
96
+ },{key:"handleReadableStream",value:function handleReadableStream(e,t,n,s,r,o){var d;var _e$streamHandlers=e.streamHandlers,a=_e$streamHandlers.onOpen,c=_e$streamHandlers.onClose;var l=!1;fetch(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",s).then(/*#__PURE__*/function(){var _ref13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(p){var _,S,u,g,y,_yield$u$read,M,K,ie,re,Re,_t7;return _regenerator().w(function(_context8){while(1)switch(_context8.n){case 0:if(p.body){_context8.n=1;break;}throw new Error(Ra);case 1:u=p.body.getReader(),g=new TextDecoder();a();y=!1;case 2:if(!(!y&&!l)){_context8.n=8;break;}_context8.n=3;return u.read();case 3:_yield$u$read=_context8.v;M=_yield$u$read.value;K=_yield$u$read.done;if(!(y=K,y)){_context8.n=4;break;}V.handleClose(e,n,c,r);_context8.n=7;break;case 4:ie=g.decode(M,{stream:!0});_context8.n=5;return(S=(_=e.deepChat).responseInterceptor)==null?void 0:S.call(_,ie);case 5:_t7=_context8.v;if(_t7){_context8.n=6;break;}_t7=ie;case 6:re=_t7;Re=_typeof(re)=="object"?re:_defineProperty({},h,ie);V.handleMessage(e,t,n,Re,o);case 7:_context8.n=2;break;case 8:return _context8.a(2);}},_callee8);}));return function(_x19){return _ref13.apply(this,arguments);};}())["catch"](function(p){V.handleError(e,t,p);}),e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l=!0;};}// prettier-ignore
97
+ },{key:"handleEventStream",value:function handleEventStream(e,t,n,s,r,o){var d;var _e$streamHandlers2=e.streamHandlers,a=_e$streamHandlers2.onOpen,c=_e$streamHandlers2.onClose,l=new AbortController();e.streamHandlers.onAbort=function(){n.finaliseStreamedMessage(),e.streamHandlers.onClose(),l.abort();},wl(((d=e.connectSettings)==null?void 0:d.url)||e.url||"",_objectSpread(_objectSpread({},s),{},{openWhenHidden:!0,// keep stream open when browser tab not open
98
+ onopen:function onopen(p){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(){return _regenerator().w(function(_context9){while(1)switch(_context9.n){case 0:if(!p.ok){_context9.n=1;break;}return _context9.a(2,a());case 1:_context9.n=2;return D.processResponseByType(p);case 2:throw _context9.v;case 3:return _context9.a(2);}},_callee9);}))();},onmessage:function onmessage(p){return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(){var u,g,y,_,_t8;return _regenerator().w(function(_context0){while(1)switch(_context0.n){case 0:if(!(ce(p.data)!==ce("[DONE]"))){_context0.n=3;break;}try{y=JSON.parse(p.data);}catch(_unused6){y={};}_context0.n=1;return(g=(u=e.deepChat).responseInterceptor)==null?void 0:g.call(u,y);case 1:_t8=_context0.v;if(_t8){_context0.n=2;break;}_t8=y;case 2:_=_t8;V.handleMessage(e,t,n,_,o);case 3:return _context0.a(2);}},_callee0);}))();},onerror:function onerror(p){throw c(),p;},onclose:function onclose(){V.handleClose(e,n,c,r);},signal:l.signal}))["catch"](function(p){V.handleError(e,t,p);});}//prettier-ignore
103
99
  },{key:"handleMessage",value:function handleMessage(e,t,n,s,r){var o;(o=e.extractResultData)==null||o.call(e,s,r).then(function(a){V.upsertContent(t,n.upsertStreamedMessage.bind(n),n,a),t.removeError();})["catch"](function(a){t.isLastMessageError()||D.displayError(t,a);});}// eslint-disable-next-line @typescript-eslint/no-explicit-any
104
100
  },{key:"handleError",value:function handleError(e,t,n){var s;t.isLastMessageError()||(s=e.extractResultData)==null||s.call(e,n).then(function(){D.displayError(t,n);})["catch"](function(r){D.displayError(t,r);});}},{key:"handleClose",value:function handleClose(e,t,n,s){if(e.asyncCallInProgress){t.finaliseStreamedMessage(!1),e.asyncCallInProgress=!1;return;}try{t.finaliseStreamedMessage(),n();}catch(r){if(!s)throw r;}}// io is only passed for demo to simulate a real stream
105
101
  },{key:"simulate",value:function(){var _simulate=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(e,t,n,s){var r,o,_r3,_r4,_o2;return _regenerator().w(function(_context1){while(1)switch(_context1.n){case 0:_context1.n=1;return D.basicResponseProcessing(e,n,{io:s,useRI:!1});case 1:if(_context1.v){_context1.n=2;break;}return _context1.a(2,t.onClose());case 2:if(Array.isArray(n)&&(n=n[0]),n[L]){t.onOpen();r=oe.splitHTML(n[L]);r.length===0&&(r=n[L].split(""));o=new ht(e,s==null?void 0:s.stream);V.populateMessages(e,r,o,t,L,0,s);}if(!n[b]){_context1.n=4;break;}_context1.n=3;return D.basicResponseProcessing(e,_defineProperty({},b,n[b]),{io:s});case 3:_r3=_context1.v;e.addNewMessage(_objectSpread({sendUpdate:!1},_r3)),!n[L]&&!n[h]&&(new ht(e,s==null?void 0:s.stream).finaliseStreamedMessage(),t.onClose());case 4:if(n[h]){t.onOpen();_r4=n[h].split(""),_o2=new ht(e,s==null?void 0:s.stream);V.populateMessages(e,_r4,_o2,t,h,0,s);}n[f]&&(D.displayError(e,n[f]),t.onClose()),t.onAbort=function(){t.onClose();};case 5:return _context1.a(2);}},_callee1);}));function simulate(_x20,_x21,_x22,_x23){return _simulate.apply(this,arguments);}return simulate;}()// prettier-ignore
106
102
  // io is only passed for demo to simulate a real stream
107
- },{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,n,s,r,o,a){var c,d,l,_t9;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:c=t[o];if(!c){_context10.n=5;break;}_context10.p=1;_context10.n=2;return D.basicResponseProcessing(e,_defineProperty({},r,c),{io:a});case 2:d=_context10.v;V.upsertContent(e,n.upsertStreamedMessage.bind(n),n,d),e.removeError();_context10.n=4;break;case 3:_context10.p=3;_t9=_context10.v;e.isLastMessageError()||D.displayError(e,_t9);case 4:l=setTimeout(function(){V.populateMessages(e,t,n,s,r,o+1,a);},s.simulationInterim||6);s.onAbort=function(){V.abort(l,n,s.onClose);};_context10.n=6;break;case 5:n.finaliseStreamedMessage(),s.onClose();case 6:return _context10.a(2);}},_callee10,null,[[1,3]]);}));function populateMessages(_x24,_x25,_x26,_x27,_x28,_x29,_x30){return _populateMessages.apply(this,arguments);}return populateMessages;}()},{key:"isSimulation",value:function isSimulation(e){return _typeof(e)=="object"&&!!e.simulation;}},{key:"isSimulatable",value:function isSimulatable(e,t){return V.isSimulation(e)&&t&&(t[h]||t[L]);}},{key:"abort",value:function abort(e,t,n){clearTimeout(e),t.finaliseStreamedMessage(),n();}},{key:"upsertContent",value:function upsertContent(e,t,n,s){if(s&&Array.isArray(s)&&(s=s[0]),s!=null&&s[h]||s!=null&&s[L]){var r=t(s);n!==null&&n!==void 0?n:n=r||void 0;}if(s!=null&&s[b]&&(e.addNewMessage(_defineProperty({},b,s[b])),n==null||n.markFileAdded()),s!=null&&s[f])throw s[f];}}]);}();var Jt=/*#__PURE__*/function(){function Jt(){_classCallCheck(this,Jt);}return _createClass(Jt,null,[{key:"generateResponse",value:function generateResponse(e){var t=e[e.length-1][0];if(t[b]&&t[b].length>0){if(t[b].length>1)return"These are interesting files!";var n=t[b][0];return n[T]&&n[T].startsWith("data:image/gif")?"That is a nice gif!":n[E]===W?"That is a nice image!":n[E]===$?"I like the sound of that!":"That is an interesting file!";}if(t[h]){if(t[h].charAt(t[h].length-1)==="?")return"I'm sorry but I can't answer that question...";if(t[h].includes("updog"))return"What's updog?";}return"Hi there! This is a demo response!";}},{key:"getCustomResponse",value:function getCustomResponse(e,t){return typeof e=="function"?e(t):e;}},{key:"getResponse",value:function getResponse(_ref11){var e=_ref11.customDemoResponse,t=_ref11.messageToElements;return e?Jt.getCustomResponse(e,t[t.length-1][0]):_defineProperty({},h,Jt.generateResponse(t));}// timeout is used to simulate a timeout for a response to come back
103
+ },{key:"populateMessages",value:function(){var _populateMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(e,t,n,s,r,o,a){var c,d,l,_t9;return _regenerator().w(function(_context10){while(1)switch(_context10.p=_context10.n){case 0:c=t[o];if(!c){_context10.n=5;break;}_context10.p=1;_context10.n=2;return D.basicResponseProcessing(e,_defineProperty({},r,c),{io:a});case 2:d=_context10.v;V.upsertContent(e,n.upsertStreamedMessage.bind(n),n,d),e.removeError();_context10.n=4;break;case 3:_context10.p=3;_t9=_context10.v;e.isLastMessageError()||D.displayError(e,_t9);case 4:l=setTimeout(function(){V.populateMessages(e,t,n,s,r,o+1,a);},s.simulationInterim||6);s.onAbort=function(){V.abort(l,n,s.onClose);};_context10.n=6;break;case 5:n.finaliseStreamedMessage(),s.onClose();case 6:return _context10.a(2);}},_callee10,null,[[1,3]]);}));function populateMessages(_x24,_x25,_x26,_x27,_x28,_x29,_x30){return _populateMessages.apply(this,arguments);}return populateMessages;}()},{key:"isSimulation",value:function isSimulation(e){return _typeof(e)=="object"&&!!e.simulation;}},{key:"isSimulatable",value:function isSimulatable(e,t){return V.isSimulation(e)&&t&&(t[h]||t[L]);}},{key:"abort",value:function abort(e,t,n){clearTimeout(e),t.finaliseStreamedMessage(),n();}},{key:"upsertContent",value:function upsertContent(e,t,n,s){if(s&&Array.isArray(s)&&(s=s[0]),s!=null&&s[h]||s!=null&&s[L]){var r=t(s);n!==null&&n!==void 0?n:n=r||void 0;}if(s!=null&&s[b]&&(e.addNewMessage(_defineProperty({},b,s[b])),n==null||n.markFileAdded()),s!=null&&s[f])throw s[f];}}]);}();var Jt=/*#__PURE__*/function(){function Jt(){_classCallCheck(this,Jt);}return _createClass(Jt,null,[{key:"generateResponse",value:function generateResponse(e){var t=e[e.length-1][0];if(t[b]&&t[b].length>0){if(t[b].length>1)return"These are interesting files!";var n=t[b][0];return n[T]&&n[T].startsWith("data:image/gif")?"That is a nice gif!":n[E]===W?"That is a nice image!":n[E]===$?"I like the sound of that!":"That is an interesting file!";}if(t[h]){if(t[h].charAt(t[h].length-1)==="?")return"I'm sorry but I can't answer that question...";if(t[h].includes("updog"))return"What's updog?";}return"Hi there! This is a demo response!";}},{key:"getCustomResponse",value:function getCustomResponse(e,t){return typeof e=="function"?e(t):e;}},{key:"getResponse",value:function getResponse(_ref15){var e=_ref15.customDemoResponse,t=_ref15.messageToElements;return e?Jt.getCustomResponse(e,t[t.length-1][0]):_defineProperty({},h,Jt.generateResponse(t));}// timeout is used to simulate a timeout for a response to come back
108
104
  },{key:"request",value:function request(e,t){var n=Jt.getResponse(t);setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(){var s,r,o;return _regenerator().w(function(_context11){while(1)switch(_context11.n){case 0:_context11.n=1;return D.basicResponseProcessing(t,n,{io:e});case 1:s=_context11.v;if(s){_context11.n=2;break;}return _context11.a(2,e.completionsHandlers.onFinish());case 2:r=Array.isArray(s)?s:[s],o=r.find(function(a){return _typeof(a[f])===Ee;});o?(t.addNewErrorMessage(ae,o[f]),e.completionsHandlers.onFinish()):V.isSimulatable(e.stream,s)?V.simulate(t,e.streamHandlers,s):(r.forEach(function(a){return t.addNewMessage(a);}),e.completionsHandlers.onFinish());case 3:return _context11.a(2);}},_callee11);})),400);}// timeout is used to simulate a timeout for a response to come back
109
- },{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var n=Jt.getResponse(e);V.simulate(e,t.streamHandlers,n,t);},400);}}]);}();Jt.URL="deep-chat-demo";var pt=Jt;var ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,null,[{key:"setup",value:function setup(e){e.permittedErrorPrefixes=["Connection error","Error in server message"],e.websocket="pending";}},{key:"isElementPresentInDOM",value:function isElementPresentInDOM(e){return e.getRootNode({composed:!0})instanceof Document;}},{key:"createConnection",value:function createConnection(e,t){if(!ke.isElementPresentInDOM(e.deepChat))return;var n=e.connectSettings.websocket;if(n){if(e.connectSettings.handler)return dt.websocket(e,t);try{var s=typeof n!="boolean"?n:void 0,r=new WebSocket(e.connectSettings.url||"",s);e.websocket=r,e.websocket.onopen=function(){var o,a;t.removeError(),e.websocket&&_typeof(e.websocket)===U&&ke.assignListeners(e,r,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console[f](o),ke.retryConnection(e,t);};}catch(s){console[f](s),ke.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var n,s;(s=(n=e.deepChat)._validationHandler)==null||s.call(n),ke.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage(ae,"Connection error"),setTimeout(function(){ke.createConnection(e,t);},5e3));}},{key:"assignListeners",value:function assignListeners(e,t,n){var _this1=this;var s={};t.onmessage=/*#__PURE__*/function(){var _ref14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(r){var o,a,c,l,_c3,_l2,_t0;return _regenerator().w(function(_context12){while(1)switch(_context12.p=_context12.n){case 0:if(!e.extractResultData){_context12.n=8;break;}_context12.p=1;o=JSON.parse(r.data);_context12.n=2;return D.basicResponseProcessing(n,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(Tn(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!V.isSimulation(e.stream)){_context12.n=4;break;}c=ke.stream.bind(_this1,e,n,s),l=s[o[x]||ne];V.upsertContent(n,c,l,a);_context12.n=6;break;case 4:_c3=Array.isArray(a)?a:[a],_l2=_c3.find(function(d){return _typeof(d[f])===Ee;});if(!_l2){_context12.n=5;break;}throw _l2[f];case 5:_c3.forEach(function(d){return n.addNewMessage(d);});case 6:_context12.n=8;break;case 7:_context12.p=7;_t0=_context12.v;D.displayError(n,_t0,"Error in server message");case 8:return _context12.a(2);}},_callee12,null,[[1,7]]);}));return function(_x31){return _ref14.apply(this,arguments);};}(),t.onclose=function(){var r,o;console[f]("Connection closed"),n.isLastMessageError()||n.addNewErrorMessage(ae,"Connection error"),e.stream&&((o=(r=e.streamHandlers).onAbort)==null||o.call(r)),ke.createConnection(e,n);};}},{key:"sendWebsocket",value:function(){var _sendWebsocket=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e,t,n){var s,d,p,r,o,_yield$D$processReque2,a,c,l,_args13=arguments;return _regenerator().w(function(_context13){while(1)switch(_context13.n){case 0:s=_args13.length>3&&_args13[3]!==undefined?_args13[3]:!0;if(!(((d=e.connectSettings)==null?void 0:d.url)===pt.URL)){_context13.n=1;break;}return _context13.a(2,pt.request(e,n));case 1:r=e.websocket;if(!(!r||r==="pending")){_context13.n=2;break;}return _context13.a(2);case 2:o={body:t,headers:(p=e.connectSettings)==null?void 0:p.headers};_context13.n=3;return D.processRequestInterceptor(e.deepChat,o);case 3:_yield$D$processReque2=_context13.v;a=_yield$D$processReque2.body;c=_yield$D$processReque2.error;if(!c){_context13.n=4;break;}return _context13.a(2,n.addNewErrorMessage(ae,c));case 4:if(ke.isWebSocket(r)){_context13.n=5;break;}return _context13.a(2,r.newUserMessage.listener(a));case 5:l=s?le(a):a;r.readyState===void 0||r.readyState!==r.OPEN?(console[f]("Connection is not open"),n.isLastMessageError()||n.addNewErrorMessage(ae,"Connection error")):(r.send(le(l)),e.completionsHandlers.onFinish());case 6:return _context13.a(2);}},_callee13);}));function sendWebsocket(_x32,_x33,_x34){return _sendWebsocket.apply(this,arguments);}return sendWebsocket;}()},{key:"canSendMessage",value:function canSendMessage(e){return e?e==="pending"?!1:ke.isWebSocket(e)?e.readyState!==void 0&&e.readyState===e.OPEN:e.isOpen:!0;}// if false then it is the internal websocket handler
110
- },{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,n,s){if(!s)return;var r=e.stream.simulation;if(_typeof(r)===Ee){var _n$o;var o=s[x]||ne,a=n[o];s[h]===r||s[L]===r?(a==null||a.finaliseStreamedMessage(),delete n[o]):((_n$o=n[o])!==null&&_n$o!==void 0?_n$o:n[o]=new ht(t,e.stream),n[o].upsertStreamedMessage(s));}else V.simulate(t,e.streamHandlers,s);}}]);}();var dt=/*#__PURE__*/function(){function dt(){_classCallCheck(this,dt);}return _createClass(dt,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(e,t,n){var a,c,s,r,o;return _regenerator().w(function(_context15){while(1)switch(_context15.n){case 0:s=!0;r=/*#__PURE__*/function(){var _ref15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(l){var d,p,u;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(s){_context14.n=1;break;}return _context14.a(2);case 1:s=!1;_context14.n=2;return D.basicResponseProcessing(n,l,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console[f](Tn(l,"server",!!e.deepChat.responseInterceptor,d)),n.addNewErrorMessage(ae,"Error in server message"),e.completionsHandlers.onFinish();else{p=Array.isArray(d)?d:[d],u=p.find(function(g){return _typeof(g[f])===Ee;});u?(console[f](u[f]),n.addNewErrorMessage(ae,u[f]),e.completionsHandlers.onFinish()):V.isSimulatable(e.stream,d)?V.simulate(n,e.streamHandlers,d):(p.forEach(function(g){return n.addNewMessage(g);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function r(_x38){return _ref15.apply(this,arguments);};}(),o=dt.generateOptionalSignals();(c=(a=e.connectSettings).handler)==null||c.call(a,t,_objectSpread(_objectSpread({},o),{},{onResponse:r}));case 1:return _context15.a(2);}},_callee15);}));function request(_x35,_x36,_x37){return _request2.apply(this,arguments);}return request;}()},{key:"attemptToFinaliseStream",value:function attemptToFinaliseStream(e,t){try{var n=t.messageElementRefs[t.messageElementRefs.length-1];nt.isLoadingMessage(n)?t.removeLastMessage():e.finaliseStreamedMessage();}catch(n){console[f](n),t.addNewErrorMessage(ae,n);}}// prettier-ignore
111
- },{key:"stream",value:function stream(e,t,n){var p,u;var s=!0,r=!1;var o=new ht(n,e.stream),a=function a(){r||!s||(e.streamHandlers.onOpen(),r=!0);},c=function c(){s&&(dt.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1);},l=/*#__PURE__*/function(){var _ref16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(g){var y,_;return _regenerator().w(function(_context16){while(1)switch(_context16.n){case 0:if(s){_context16.n=1;break;}return _context16.a(2);case 1:_context16.n=2;return D.basicResponseProcessing(n,g,{io:e,displayError:!1});case 2:y=_context16.v;if(y)y[f]?(dt.streamError(y[f],o,e,n),s=!1):V.upsertContent(n,o.upsertStreamedMessage.bind(o),o,y);else{_=Tn(g,"server",!!e.deepChat.responseInterceptor,y);dt.streamError(_,o,e,n),s=!1;}case 3:return _context16.a(2);}},_callee16);}));return function l(_x39){return _ref16.apply(this,arguments);};}();e.streamHandlers.onAbort=function(){dt.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1;};var d=dt.generateOptionalSignals();(u=(p=e.connectSettings).handler)==null||u.call(p,t,_objectSpread(_objectSpread({},d),{},{onOpen:a,onResponse:l,onClose:c,stopClicked:e.streamHandlers.stopClicked}));}},{key:"streamError",value:function streamError(e,t,n,s){console[f](e),t.finaliseStreamedMessage(),s.addNewErrorMessage(ae,e),n.streamHandlers.onClose();}// prettier-ignore
112
- },{key:"websocket",value:function websocket(e,t){var _this10=this;var c,l;var n={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=n;var s=function s(){t.removeError(),n.isOpen=!0;},r=function r(){n.isOpen=!1;},o=/*#__PURE__*/function(){var _ref17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(d){var p,u,g,y,_,S;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:_context17.n=1;return D.basicResponseProcessing(t,d,{io:e,displayError:!1});case 1:p=_context17.v;if(!p)console[f](Tn(d,"server",!!e.deepChat.responseInterceptor,p)),t.addNewErrorMessage(ae,"Error in server message");else{u=Array.isArray(p)?p:[p],g=u.find(function(y){return _typeof(y[f])===Ee;});if(g)console[f](g[f]),t.isLastMessageError()||t.addNewErrorMessage(ae,g[f]);else if(V.isSimulation(e.stream)){y=p,_=ke.stream.bind(_this10,e,t,n.roleToStream),S=n.roleToStream[y[x]||ne];V.upsertContent(t,_,S,y);}else u.forEach(function(y){return t.addNewMessage(y);});}case 2:return _context17.a(2);}},_callee17);}));return function o(_x40){return _ref17.apply(this,arguments);};}(),a=dt.generateOptionalSignals();(l=(c=e.connectSettings).handler)==null||l.call(c,void 0,_objectSpread(_objectSpread({},a),{},{onOpen:s,onResponse:o,onClose:r,newUserMessage:n.newUserMessage}));}},{key:"generateOptionalSignals",value:function generateOptionalSignals(){return{onClose:function onClose(){},onOpen:function onOpen(){},stopClicked:{listener:function listener(){}},newUserMessage:{listener:function listener(){}}};}}]);}();var ge=/*#__PURE__*/function(){function ge(){_classCallCheck(this,ge);}return _createClass(ge,null,[{key:"request",value:// prettier-ignore
113
- function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,n){var s,p,u,g,r,_yield$D$processReque3,o,a,c,l,d,_args19=arguments;return _regenerator().w(function(_context19){while(1)switch(_context19.n){case 0:s=_args19.length>3&&_args19[3]!==undefined?_args19[3]:!0;r={body:t,headers:(p=e.connectSettings)==null?void 0:p.headers};_context19.n=1;return D.processRequestInterceptor(e.deepChat,r);case 1:_yield$D$processReque3=_context19.v;o=_yield$D$processReque3.body;a=_yield$D$processReque3.headers;c=_yield$D$processReque3.error;l=e.completionsHandlers.onFinish;if(!c){_context19.n=2;break;}return _context19.a(2,D.onInterceptorError(n,c,l));case 2:if(!((u=e.connectSettings)!=null&&u.handler)){_context19.n=3;break;}return _context19.a(2,dt.request(e,o,n));case 3:if(!(((g=e.connectSettings)==null?void 0:g.url)===pt.URL)){_context19.n=4;break;}return _context19.a(2,pt.request(e,n));case 4:d=!0;D.fetch(e,a,s,o).then(function(y){return d=!!y.ok,y;}).then(function(y){return D.processResponseByType(y);}).then(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(y){var M,K,_,S,_t1;return _regenerator().w(function(_context18){while(1)switch(_context18.n){case 0:if(e.extractResultData){_context18.n=1;break;}return _context18.a(2);case 1:_context18.n=2;return(K=(M=e.deepChat).responseInterceptor)==null?void 0:K.call(M,y);case 2:_t1=_context18.v;if(_t1){_context18.n=3;break;}_t1=y;case 3:_=_t1;_context18.n=4;return e.extractResultData(_,o);case 4:S=_context18.v;if(d){_context18.n=5;break;}throw y;case 5:if(!(!S||_typeof(S)!==U&&!Array.isArray(S))){_context18.n=6;break;}throw Error(Tn(y,"response",!!e.deepChat.responseInterceptor,_));case 6:if(!S[f]){_context18.n=7;break;}throw S[f];case 7:if(!e.asyncCallInProgress){_context18.n=8;break;}e.asyncCallInProgress=!1;return _context18.a(2);case 8:V.isSimulatable(e.stream,S)?V.simulate(n,e.streamHandlers,S):((Array.isArray(S)?S:[S]).forEach(function(re){return n.addNewMessage(re);}),l());case 9:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref18.apply(this,arguments);};}())["catch"](function(y){D.displayError(n,y),l();});case 5:return _context19.a(2);}},_callee19);}));function request(_x41,_x42,_x43){return _request3.apply(this,arguments);}return request;}()},{key:"executePollRequest",value:function executePollRequest(e,t,n,s){var r=e.completionsHandlers.onFinish;fetch(t,n).then(function(o){return o.json();}).then(/*#__PURE__*/function(){var _ref19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(o){var c,l,a,_t10,_t11;return _regenerator().w(function(_context20){while(1)switch(_context20.n){case 0:if(e.extractPollResultData){_context20.n=1;break;}return _context20.a(2);case 1:_t10=e;_context20.n=2;return(l=(c=e.deepChat).responseInterceptor)==null?void 0:l.call(c,o);case 2:_t11=_context20.v;if(_t11){_context20.n=3;break;}_t11=o;case 3:_context20.n=4;return _t10.extractPollResultData.call(_t10,_t11);case 4:a=_context20.v;a.timeoutMS?setTimeout(function(){ge.executePollRequest(e,t,n,s);},a.timeoutMS):V.isSimulatable(e.stream,a)?V.simulate(s,e.streamHandlers,a):(s.addNewMessage(a),r());case 5:return _context20.a(2);}},_callee20);}));return function(_x45){return _ref19.apply(this,arguments);};}())["catch"](function(o){D.displayError(s,o),r();});}// prettier-ignore
114
- },{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,n){var s,g,y,_,r,_yield$D$processReque4,o,a,c,l,d,p,u,_args21=arguments;return _regenerator().w(function(_context21){while(1)switch(_context21.n){case 0:s=_args21.length>3&&_args21[3]!==undefined?_args21[3]:!0;r={body:t,headers:(g=e.connectSettings)==null?void 0:g.headers};_context21.n=1;return D.processRequestInterceptor(e.deepChat,r);case 1:_yield$D$processReque4=_context21.v;o=_yield$D$processReque4.body;a=_yield$D$processReque4.headers;c=_yield$D$processReque4.error;if(!c){_context21.n=2;break;}return _context21.a(2,D.onInterceptorError(n,c));case 2:l=((y=e.connectSettings)==null?void 0:y.url)||e.url||"",d=((_=e.connectSettings)==null?void 0:_.method)||ye,p=s?le(o):o,u={method:d,body:p,headers:a};e.connectSettings.credentials&&(u.credentials=e.connectSettings.credentials),ge.executePollRequest(e,l,u,n);case 3:return _context21.a(2);}},_callee21);}));function poll(_x46,_x47,_x48){return _poll.apply(this,arguments);}return poll;}()// prettier-ignore
105
+ },{key:"requestStream",value:function requestStream(e,t){setTimeout(function(){var n=Jt.getResponse(e);V.simulate(e,t.streamHandlers,n,t);},400);}}]);}();Jt.URL="deep-chat-demo";var pt=Jt;var ke=/*#__PURE__*/function(){function ke(){_classCallCheck(this,ke);}return _createClass(ke,null,[{key:"setup",value:function setup(e){e.permittedErrorPrefixes=["Connection error","Error in server message"],e.websocket="pending";}},{key:"isElementPresentInDOM",value:function isElementPresentInDOM(e){return e.getRootNode({composed:!0})instanceof Document;}},{key:"createConnection",value:function createConnection(e,t){if(!ke.isElementPresentInDOM(e.deepChat))return;var n=e.connectSettings.websocket;if(n){if(e.connectSettings.handler)return dt.websocket(e,t);try{var s=typeof n!="boolean"?n:void 0,r=new WebSocket(e.connectSettings.url||"",s);e.websocket=r,e.websocket.onopen=function(){var o,a;t.removeError(),e.websocket&&_typeof(e.websocket)===U&&ke.assignListeners(e,r,t),(a=(o=e.deepChat)._validationHandler)==null||a.call(o);},e.websocket.onerror=function(o){console[f](o),ke.retryConnection(e,t);};}catch(s){console[f](s),ke.retryConnection(e,t);}}}},{key:"retryConnection",value:function retryConnection(e,t){var n,s;(s=(n=e.deepChat)._validationHandler)==null||s.call(n),ke.isElementPresentInDOM(e.deepChat)&&(e.websocket="pending",t.isLastMessageError()||t.addNewErrorMessage(ae,"Connection error"),setTimeout(function(){ke.createConnection(e,t);},5e3));}},{key:"assignListeners",value:function assignListeners(e,t,n){var _this1=this;var s={};t.onmessage=/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(r){var o,a,c,l,_c3,_l3,_t0;return _regenerator().w(function(_context12){while(1)switch(_context12.p=_context12.n){case 0:if(!e.extractResultData){_context12.n=8;break;}_context12.p=1;o=JSON.parse(r.data);_context12.n=2;return D.basicResponseProcessing(n,o,{io:e,displayError:!1});case 2:a=_context12.v;if(a){_context12.n=3;break;}throw Error(Tn(o,"server",!!e.deepChat.responseInterceptor,a));case 3:if(!V.isSimulation(e.stream)){_context12.n=4;break;}c=ke.stream.bind(_this1,e,n,s),l=s[o[x]||ne];V.upsertContent(n,c,l,a);_context12.n=6;break;case 4:_c3=Array.isArray(a)?a:[a],_l3=_c3.find(function(d){return _typeof(d[f])===Ee;});if(!_l3){_context12.n=5;break;}throw _l3[f];case 5:_c3.forEach(function(d){return n.addNewMessage(d);});case 6:_context12.n=8;break;case 7:_context12.p=7;_t0=_context12.v;D.displayError(n,_t0,"Error in server message");case 8:return _context12.a(2);}},_callee12,null,[[1,7]]);}));return function(_x31){return _ref18.apply(this,arguments);};}(),t.onclose=function(){var r,o;console[f]("Connection closed"),n.isLastMessageError()||n.addNewErrorMessage(ae,"Connection error"),e.stream&&((o=(r=e.streamHandlers).onAbort)==null||o.call(r)),ke.createConnection(e,n);};}},{key:"sendWebsocket",value:function(){var _sendWebsocket=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(e,t,n){var s,d,p,r,o,_yield$D$processReque2,a,c,l,_args13=arguments;return _regenerator().w(function(_context13){while(1)switch(_context13.n){case 0:s=_args13.length>3&&_args13[3]!==undefined?_args13[3]:!0;if(!(((d=e.connectSettings)==null?void 0:d.url)===pt.URL)){_context13.n=1;break;}return _context13.a(2,pt.request(e,n));case 1:r=e.websocket;if(!(!r||r==="pending")){_context13.n=2;break;}return _context13.a(2);case 2:o={body:t,headers:(p=e.connectSettings)==null?void 0:p.headers};_context13.n=3;return D.processRequestInterceptor(e.deepChat,o);case 3:_yield$D$processReque2=_context13.v;a=_yield$D$processReque2.body;c=_yield$D$processReque2.error;if(!c){_context13.n=4;break;}return _context13.a(2,n.addNewErrorMessage(ae,c));case 4:if(ke.isWebSocket(r)){_context13.n=5;break;}return _context13.a(2,r.newUserMessage.listener(a));case 5:l=s?ce(a):a;r.readyState===void 0||r.readyState!==r.OPEN?(console[f]("Connection is not open"),n.isLastMessageError()||n.addNewErrorMessage(ae,"Connection error")):(r.send(ce(l)),e.completionsHandlers.onFinish());case 6:return _context13.a(2);}},_callee13);}));function sendWebsocket(_x32,_x33,_x34){return _sendWebsocket.apply(this,arguments);}return sendWebsocket;}()},{key:"canSendMessage",value:function canSendMessage(e){return e?e==="pending"?!1:ke.isWebSocket(e)?e.readyState!==void 0&&e.readyState===e.OPEN:e.isOpen:!0;}// if false then it is the internal websocket handler
106
+ },{key:"isWebSocket",value:function isWebSocket(e){return e.send!==void 0;}},{key:"stream",value:function stream(e,t,n,s){if(!s)return;var r=e.stream.simulation;if(_typeof(r)===Ee){var _n$o;var o=s[x]||ne,a=n[o];s[h]===r||s[L]===r?(a==null||a.finaliseStreamedMessage(),delete n[o]):((_n$o=n[o])!==null&&_n$o!==void 0?_n$o:n[o]=new ht(t,e.stream),n[o].upsertStreamedMessage(s));}else V.simulate(t,e.streamHandlers,s);}}]);}();var dt=/*#__PURE__*/function(){function dt(){_classCallCheck(this,dt);}return _createClass(dt,null,[{key:"request",value:function(){var _request2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(e,t,n){var a,c,s,r,o;return _regenerator().w(function(_context15){while(1)switch(_context15.n){case 0:s=!0;r=/*#__PURE__*/function(){var _ref19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(l){var d,p,u;return _regenerator().w(function(_context14){while(1)switch(_context14.n){case 0:if(s){_context14.n=1;break;}return _context14.a(2);case 1:s=!1;_context14.n=2;return D.basicResponseProcessing(n,l,{io:e,displayError:!1});case 2:d=_context14.v;if(!d)console[f](Tn(l,"server",!!e.deepChat.responseInterceptor,d)),n.addNewErrorMessage(ae,"Error in server message"),e.completionsHandlers.onFinish();else{p=Array.isArray(d)?d:[d],u=p.find(function(g){return _typeof(g[f])===Ee;});u?(console[f](u[f]),n.addNewErrorMessage(ae,u[f]),e.completionsHandlers.onFinish()):V.isSimulatable(e.stream,d)?V.simulate(n,e.streamHandlers,d):(p.forEach(function(g){return n.addNewMessage(g);}),e.completionsHandlers.onFinish());}case 3:return _context14.a(2);}},_callee14);}));return function r(_x38){return _ref19.apply(this,arguments);};}(),o=dt.generateOptionalSignals();(c=(a=e.connectSettings).handler)==null||c.call(a,t,_objectSpread(_objectSpread({},o),{},{onResponse:r}));case 1:return _context15.a(2);}},_callee15);}));function request(_x35,_x36,_x37){return _request2.apply(this,arguments);}return request;}()},{key:"attemptToFinaliseStream",value:function attemptToFinaliseStream(e,t){try{var n=t.messageElementRefs[t.messageElementRefs.length-1];nt.isLoadingMessage(n)?t.removeLastMessage():e.finaliseStreamedMessage();}catch(n){console[f](n),t.addNewErrorMessage(ae,n);}}// prettier-ignore
107
+ },{key:"stream",value:function stream(e,t,n){var p,u;var s=!0,r=!1;var o=new ht(n,e.stream),a=function a(){r||!s||(e.streamHandlers.onOpen(),r=!0);},c=function c(){s&&(dt.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1);},l=/*#__PURE__*/function(){var _ref20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(g){var y,_;return _regenerator().w(function(_context16){while(1)switch(_context16.n){case 0:if(s){_context16.n=1;break;}return _context16.a(2);case 1:_context16.n=2;return D.basicResponseProcessing(n,g,{io:e,displayError:!1});case 2:y=_context16.v;if(y)y[f]?(dt.streamError(y[f],o,e,n),s=!1):V.upsertContent(n,o.upsertStreamedMessage.bind(o),o,y);else{_=Tn(g,"server",!!e.deepChat.responseInterceptor,y);dt.streamError(_,o,e,n),s=!1;}case 3:return _context16.a(2);}},_callee16);}));return function l(_x39){return _ref20.apply(this,arguments);};}();e.streamHandlers.onAbort=function(){dt.attemptToFinaliseStream(o,n),e.streamHandlers.onClose(),s=!1;};var d=dt.generateOptionalSignals();(u=(p=e.connectSettings).handler)==null||u.call(p,t,_objectSpread(_objectSpread({},d),{},{onOpen:a,onResponse:l,onClose:c,stopClicked:e.streamHandlers.stopClicked}));}},{key:"streamError",value:function streamError(e,t,n,s){console[f](e),t.finaliseStreamedMessage(),s.addNewErrorMessage(ae,e),n.streamHandlers.onClose();}// prettier-ignore
108
+ },{key:"websocket",value:function websocket(e,t){var _this10=this;var c,l;var n={isOpen:!1,newUserMessage:{listener:function listener(){}},roleToStream:{}};e.websocket=n;var s=function s(){t.removeError(),n.isOpen=!0;},r=function r(){n.isOpen=!1;},o=/*#__PURE__*/function(){var _ref21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(d){var p,u,g,y,_,S;return _regenerator().w(function(_context17){while(1)switch(_context17.n){case 0:_context17.n=1;return D.basicResponseProcessing(t,d,{io:e,displayError:!1});case 1:p=_context17.v;if(!p)console[f](Tn(d,"server",!!e.deepChat.responseInterceptor,p)),t.addNewErrorMessage(ae,"Error in server message");else{u=Array.isArray(p)?p:[p],g=u.find(function(y){return _typeof(y[f])===Ee;});if(g)console[f](g[f]),t.isLastMessageError()||t.addNewErrorMessage(ae,g[f]);else if(V.isSimulation(e.stream)){y=p,_=ke.stream.bind(_this10,e,t,n.roleToStream),S=n.roleToStream[y[x]||ne];V.upsertContent(t,_,S,y);}else u.forEach(function(y){return t.addNewMessage(y);});}case 2:return _context17.a(2);}},_callee17);}));return function o(_x40){return _ref21.apply(this,arguments);};}(),a=dt.generateOptionalSignals();(l=(c=e.connectSettings).handler)==null||l.call(c,void 0,_objectSpread(_objectSpread({},a),{},{onOpen:s,onResponse:o,onClose:r,newUserMessage:n.newUserMessage}));}},{key:"generateOptionalSignals",value:function generateOptionalSignals(){return{onClose:function onClose(){},onOpen:function onOpen(){},stopClicked:{listener:function listener(){}},newUserMessage:{listener:function listener(){}}};}}]);}();var ge=/*#__PURE__*/function(){function ge(){_classCallCheck(this,ge);}return _createClass(ge,null,[{key:"request",value:// prettier-ignore
109
+ function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19(e,t,n){var s,p,u,g,r,_yield$D$processReque3,o,a,c,l,d,_args19=arguments;return _regenerator().w(function(_context19){while(1)switch(_context19.n){case 0:s=_args19.length>3&&_args19[3]!==undefined?_args19[3]:!0;r={body:t,headers:(p=e.connectSettings)==null?void 0:p.headers};_context19.n=1;return D.processRequestInterceptor(e.deepChat,r);case 1:_yield$D$processReque3=_context19.v;o=_yield$D$processReque3.body;a=_yield$D$processReque3.headers;c=_yield$D$processReque3.error;l=e.completionsHandlers.onFinish;if(!c){_context19.n=2;break;}return _context19.a(2,D.onInterceptorError(n,c,l));case 2:if(!((u=e.connectSettings)!=null&&u.handler)){_context19.n=3;break;}return _context19.a(2,dt.request(e,o,n));case 3:if(!(((g=e.connectSettings)==null?void 0:g.url)===pt.URL)){_context19.n=4;break;}return _context19.a(2,pt.request(e,n));case 4:d=!0;D.fetch(e,a,s,o).then(function(y){return d=!!y.ok,y;}).then(function(y){return D.processResponseByType(y);}).then(/*#__PURE__*/function(){var _ref22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18(y){var M,K,_,S,_t1;return _regenerator().w(function(_context18){while(1)switch(_context18.n){case 0:if(e.extractResultData){_context18.n=1;break;}return _context18.a(2);case 1:_context18.n=2;return(K=(M=e.deepChat).responseInterceptor)==null?void 0:K.call(M,y);case 2:_t1=_context18.v;if(_t1){_context18.n=3;break;}_t1=y;case 3:_=_t1;_context18.n=4;return e.extractResultData(_,o);case 4:S=_context18.v;if(d){_context18.n=5;break;}throw y;case 5:if(!(!S||_typeof(S)!==U&&!Array.isArray(S))){_context18.n=6;break;}throw Error(Tn(y,"response",!!e.deepChat.responseInterceptor,_));case 6:if(!S[f]){_context18.n=7;break;}throw S[f];case 7:if(!e.asyncCallInProgress){_context18.n=8;break;}e.asyncCallInProgress=!1;return _context18.a(2);case 8:V.isSimulatable(e.stream,S)?V.simulate(n,e.streamHandlers,S):((Array.isArray(S)?S:[S]).forEach(function(re){return n.addNewMessage(re);}),l());case 9:return _context18.a(2);}},_callee18);}));return function(_x44){return _ref22.apply(this,arguments);};}())["catch"](function(y){D.displayError(n,y),l();});case 5:return _context19.a(2);}},_callee19);}));function request(_x41,_x42,_x43){return _request3.apply(this,arguments);}return request;}()},{key:"executePollRequest",value:function executePollRequest(e,t,n,s){var r=e.completionsHandlers.onFinish;fetch(t,n).then(function(o){return o.json();}).then(/*#__PURE__*/function(){var _ref23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee20(o){var c,l,a,_t10,_t11;return _regenerator().w(function(_context20){while(1)switch(_context20.n){case 0:if(e.extractPollResultData){_context20.n=1;break;}return _context20.a(2);case 1:_t10=e;_context20.n=2;return(l=(c=e.deepChat).responseInterceptor)==null?void 0:l.call(c,o);case 2:_t11=_context20.v;if(_t11){_context20.n=3;break;}_t11=o;case 3:_context20.n=4;return _t10.extractPollResultData.call(_t10,_t11);case 4:a=_context20.v;a.timeoutMS?setTimeout(function(){ge.executePollRequest(e,t,n,s);},a.timeoutMS):V.isSimulatable(e.stream,a)?V.simulate(s,e.streamHandlers,a):(s.addNewMessage(a),r());case 5:return _context20.a(2);}},_callee20);}));return function(_x45){return _ref23.apply(this,arguments);};}())["catch"](function(o){D.displayError(s,o),r();});}// prettier-ignore
110
+ },{key:"poll",value:function(){var _poll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee21(e,t,n){var s,g,y,_,r,_yield$D$processReque4,o,a,c,l,d,p,u,_args21=arguments;return _regenerator().w(function(_context21){while(1)switch(_context21.n){case 0:s=_args21.length>3&&_args21[3]!==undefined?_args21[3]:!0;r={body:t,headers:(g=e.connectSettings)==null?void 0:g.headers};_context21.n=1;return D.processRequestInterceptor(e.deepChat,r);case 1:_yield$D$processReque4=_context21.v;o=_yield$D$processReque4.body;a=_yield$D$processReque4.headers;c=_yield$D$processReque4.error;if(!c){_context21.n=2;break;}return _context21.a(2,D.onInterceptorError(n,c));case 2:l=((y=e.connectSettings)==null?void 0:y.url)||e.url||"",d=((_=e.connectSettings)==null?void 0:_.method)||ye,p=s?ce(o):o,u={method:d,body:p,headers:a};e.connectSettings.credentials&&(u.credentials=e.connectSettings.credentials),ge.executePollRequest(e,l,u,n);case 3:return _context21.a(2);}},_callee21);}));function poll(_x46,_x47,_x48){return _poll.apply(this,arguments);}return poll;}()// prettier-ignore
115
111
  },{key:"verifyKey",value:function verifyKey(e,t,n,s,r,o,a,c,l){if(e==="")return o(pe);a(),fetch(t,{method:s,headers:n,body:l||null}).then(function(d){return D.processResponseByType(d);}).then(function(d){c(d,e,r,o);})["catch"](function(d){o(Ue),console[f](d);});}}]);}();var kn=/*#__PURE__*/function(){function kn(){_classCallCheck(this,kn);}return _createClass(kn,null,[{key:"getCharacterLimitMessages",value:function getCharacterLimitMessages(e,t){var r;if(t===-1)return e;var n=0,s=e[X]-1;for(s;s>=0;s-=1){var o=(r=e[s])==null?void 0:r[h];if(o!==void 0&&(n+=o[X],n>t)){e[s][h]=o.substring(0,o[X]-(n-t));break;}}return e.slice(Math.max(s,0));}},{key:"getMaxMessages",value:function getMaxMessages(e,t){return e.slice(Math.max(e[X]-t,0));}// if maxMessages is not defined we send all messages
116
112
  // if maxMessages above 0 we send that number
117
113
  // if maxMessages 0 or below we send only what is in the request
118
- },{key:"processMessages",value:function processMessages(e,t,n){return t!==void 0?t>0&&(e=kn.getMaxMessages(e,t)):e=[e[e[X]-1]],e=C(e),n===void 0?e:kn.getCharacterLimitMessages(e,n);}}]);}();var Ft=/*#__PURE__*/function(){function Ft(e,t,n){_classCallCheck(this,Ft);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,n.fetchHistory&&this.fetchHistory(n.fetchHistory),this.setupInitialHistory(e);}return _createClass(Ft,[{key:"fetchHistory",value:function(){var _fetchHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(e){var _this11=this;var t,n;return _regenerator().w(function(_context22){while(1)switch(_context22.n){case 0:t=Mt.addMessage(this._messages);_context22.n=1;return e();case 1:n=_context22.v;this._messages.removeMessage(t),Ft.displayIntroMessages(this._messages.messageElementRefs),n.forEach(function(s){return _this11._messages.addAnyMessage(s,!0);}),setTimeout(function(){return z.scrollToBottom(_this11._messages);},0);case 2:return _context22.a(2);}},_callee22,this);}));function fetchHistory(_x49){return _fetchHistory.apply(this,arguments);}return fetchHistory;}()},{key:"scrollToPreloadFirstEl",value:function scrollToPreloadFirstEl(e,t){this._messages.elementRef.scrollTop=t+e.offsetTop-40;}},{key:"processLoadedHistory",value:function processLoadedHistory(e){var _this12=this;var a;var _this$_messages=this._messages,t=_this$_messages.messageElementRefs,n=_this$_messages.messageToElements,s=_this$_messages.elementRef,r=(a=t.find(function(c){return!c.outerContainer[m].contains(nt.INTRO_CLASS);}))==null?void 0:a.outerContainer,o=s.scrollTop;e==null||e.reverse().map(function(c){var l=_this12._messages.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!0}),!0,!0);if(l){var d=B.generateMessageBody(l,t,!0);n.unshift([l,d]);}return l;}).filter(function(c){return!!c;}).reverse().forEach(function(c){return _this12._messages.sendClientUpdate(c,!0);}),r&&(this._messages.messageElementRefs.length>=this._messages.maxVisibleMessages?setTimeout(function(){return _this12.scrollToPreloadFirstEl(r,o);}):this.scrollToPreloadFirstEl(r,o));}},{key:"populateMessages",value:function populateMessages(e,t){this._messages.removeMessage(e),this._isPaginationComplete=t.findIndex(function(a){return!a;})<0;var n=t.filter(function(a){return!!a;});this.processLoadedHistory(n);var _this$_messages2=this._messages,s=_this$_messages2.messageElementRefs,r=_this$_messages2.avatar,o=_this$_messages2.name;B.resetAllRoleElements(s,r,o);}},{key:"loadHistoryOnScroll",value:function(){var _loadHistoryOnScroll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(e){var _this13=this;return _regenerator().w(function(_context24){while(1)switch(_context24.n){case 0:this._messages.elementRef.onscroll=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23(){var t,n,_t12;return _regenerator().w(function(_context23){while(1)switch(_context23.p=_context23.n){case 0:if(!(!_this13._isLoading&&!_this13._isPaginationComplete&&_this13._messages.elementRef.scrollTop===0)){_context23.n=4;break;}_this13._isLoading=!0;t=Mt.addMessage(_this13._messages,!1);_context23.p=1;_context23.n=2;return e(_this13._index++);case 2:n=_context23.v;_this13.populateMessages(t,n),_this13._isLoading=!1;_context23.n=4;break;case 3:_context23.p=3;_t12=_context23.v;_this13._messages.removeMessage(t),_this13._isPaginationComplete=!0,_this13._messages.addNewErrorMessage(ae,Ft.FAILED_ERROR_MESSAGE,!0),console[f](_t12);case 4:return _context23.a(2);}},_callee23,null,[[1,3]]);}));case 1:return _context24.a(2);}},_callee24,this);}));function loadHistoryOnScroll(_x50){return _loadHistoryOnScroll.apply(this,arguments);}return loadHistoryOnScroll;}()},{key:"populateInitialHistory",value:function populateInitialHistory(e){var _this14=this;e.forEach(function(t){de.processHistoryFile(t),_this14._messages.addAnyMessage(t,!0);});}},{key:"loadInitialHistory",value:function(){var _loadInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(e){var t,n,s,_t13;return _regenerator().w(function(_context25){while(1)switch(_context25.p=_context25.n){case 0:this._isLoading=!0;t=Mt.addMessage(this._messages);_context25.p=1;_context25.n=2;return e(this._index++);case 2:n=_context25.v;s=this._messages.elementRef.scrollTop;this.populateMessages(t,n),this.restoreScrollOrScrollToBottom(s===0);_context25.n=4;break;case 3:_context25.p=3;_t13=_context25.v;this._messages.removeMessage(t),this._isPaginationComplete=!0,this._messages.addNewErrorMessage(ae,Ft.FAILED_ERROR_MESSAGE,!0),console[f](_t13);case 4:Ft.displayIntroMessages(this._messages.messageElementRefs),this._isLoading=!1;case 5:return _context25.a(2);}},_callee25,this,[[1,3]]);}));function loadInitialHistory(_x51){return _loadInitialHistory.apply(this,arguments);}return loadInitialHistory;}()},{key:"setupInitialHistory",value:function(){var _setupInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(e){var s,t,n;return _regenerator().w(function(_context26){while(1)switch(_context26.n){case 0:e.loadHistory&&this.loadInitialHistory(e.loadHistory);t=(s=this._messages.browserStorage)==null?void 0:s.get(),n=e.history||de.processHistory(e)||(t==null?void 0:t.messages);n&&(this.populateInitialHistory(n),this.restoreScrollOrScrollToBottom(!0),this._index+=1);case 1:return _context26.a(2);}},_callee26,this);}));function setupInitialHistory(_x52){return _setupInitialHistory.apply(this,arguments);}return setupInitialHistory;}()},{key:"restoreScrollOrScrollToBottom",value:function restoreScrollOrScrollToBottom(e){var _this15=this;var n,s,r;var t=(s=(n=this._messages.browserStorage)==null?void 0:n.get())==null?void 0:s.scrollHeight;t!==void 0&&(r=this._messages.browserStorage)!=null&&r.trackScrollHeight?setTimeout(function(){_this15._messages.elementRef.scrollTop=t;},0):e&&setTimeout(function(){return z.scrollToBottom(_this15._messages);},0);}}],[{key:"addErrorPrefix",value:function addErrorPrefix(e){var _e$permittedErrorPref;(_e$permittedErrorPref=e.permittedErrorPrefixes)!==null&&_e$permittedErrorPref!==void 0?_e$permittedErrorPref:e.permittedErrorPrefixes=[],e.permittedErrorPrefixes.push(Ft.FAILED_ERROR_MESSAGE);}},{key:"displayIntroMessages",value:function displayIntroMessages(e){for(var t=0;t<e.length;t+=1){var n=e[0];if(n.outerContainer[m].contains(nt.INTRO_CLASS))n.outerContainer[v].display="";else break;}}}]);}();Ft.FAILED_ERROR_MESSAGE="Failed to load history";var Ts=Ft;var Ae=/*#__PURE__*/function(){function Ae(){_classCallCheck(this,Ae);}return _createClass(Ae,null,[{key:"parseConfig",value:function parseConfig(e,t,n){var r;var s={files:e};if(_typeof(n)=="object"){de.processFileConfigConnect(n);var o=n.files,a=n.connect,c=n.button;o&&(o.infoModal&&(s[b].infoModal=o.infoModal,(r=o.infoModal)!=null&&r.textMarkDown&&(s.infoModalTextMarkUp=t.render(o.infoModal.textMarkDown))),o.acceptedFormats&&(s[b].acceptedFormats=o.acceptedFormats),o.maxNumberOfFiles&&(s[b].maxNumberOfFiles=o.maxNumberOfFiles)),s.button=c,a&&Object.keys(a).length>0&&(s.connect=a);}return s;}},{key:"processMixedFiles",value:function processMixedFiles(e,t,n){if(n){var s={acceptedFormats:""};e.fileTypes.mixedFiles=Ae.parseConfig(s,t,n);}}// needs to be set after audio to overwrite maxNumberOfFiles
114
+ },{key:"processMessages",value:function processMessages(e,t,n){return t!==void 0?t>0&&(e=kn.getMaxMessages(e,t)):e=[e[e[X]-1]],e=C(e),n===void 0?e:kn.getCharacterLimitMessages(e,n);}}]);}();var Ft=/*#__PURE__*/function(){function Ft(e,t,n){_classCallCheck(this,Ft);this._isLoading=!1,this._isPaginationComplete=!1,this._index=0,this._messages=t,n.fetchHistory&&this.fetchHistory(n.fetchHistory),this.setupInitialHistory(e);}return _createClass(Ft,[{key:"fetchHistory",value:function(){var _fetchHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee22(e){var _this11=this;var t,n;return _regenerator().w(function(_context22){while(1)switch(_context22.n){case 0:t=Mt.addMessage(this._messages);_context22.n=1;return e();case 1:n=_context22.v;this._messages.removeMessage(t),Ft.displayIntroMessages(this._messages.messageElementRefs),n.forEach(function(s){return _this11._messages.addAnyMessage(s,!0);}),setTimeout(function(){return z.scrollToBottom(_this11._messages);},0);case 2:return _context22.a(2);}},_callee22,this);}));function fetchHistory(_x49){return _fetchHistory.apply(this,arguments);}return fetchHistory;}()},{key:"scrollToPreloadFirstEl",value:function scrollToPreloadFirstEl(e,t){this._messages.elementRef.scrollTop=t+e.offsetTop-40;}},{key:"processLoadedHistory",value:function processLoadedHistory(e){var _this12=this;var a;var _this$_messages=this._messages,t=_this$_messages.messageElementRefs,n=_this$_messages.messageToElements,s=_this$_messages.elementRef,r=(a=t.find(function(c){return!c.outerContainer[m].contains(nt.INTRO_CLASS);}))==null?void 0:a.outerContainer,o=s.scrollTop;e==null||e.reverse().map(function(c){var l=_this12._messages.addAnyMessage(_objectSpread(_objectSpread({},c),{},{sendUpdate:!0}),!0,!0);if(l){var d=B.generateMessageBody(l,t,!0);n.unshift([l,d]);}return l;}).filter(function(c){return!!c;}).reverse().forEach(function(c){return _this12._messages.sendClientUpdate(c,!0);}),r&&(this._messages.messageElementRefs.length>=this._messages.maxVisibleMessages?setTimeout(function(){return _this12.scrollToPreloadFirstEl(r,o);}):this.scrollToPreloadFirstEl(r,o));}},{key:"populateMessages",value:function populateMessages(e,t){this._messages.removeMessage(e),this._isPaginationComplete=t.findIndex(function(a){return!a;})<0;var n=t.filter(function(a){return!!a;});this.processLoadedHistory(n);var _this$_messages2=this._messages,s=_this$_messages2.messageElementRefs,r=_this$_messages2.avatar,o=_this$_messages2.name;B.resetAllRoleElements(s,r,o);}},{key:"loadHistoryOnScroll",value:function(){var _loadHistoryOnScroll=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee24(e){var _this13=this;return _regenerator().w(function(_context24){while(1)switch(_context24.n){case 0:this._messages.elementRef.onscroll=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee23(){var t,n,_t12;return _regenerator().w(function(_context23){while(1)switch(_context23.p=_context23.n){case 0:if(!(!_this13._isLoading&&!_this13._isPaginationComplete&&_this13._messages.elementRef.scrollTop===0)){_context23.n=4;break;}_this13._isLoading=!0;t=Mt.addMessage(_this13._messages,!1);_context23.p=1;_context23.n=2;return e(_this13._index++);case 2:n=_context23.v;_this13.populateMessages(t,n),_this13._isLoading=!1;_context23.n=4;break;case 3:_context23.p=3;_t12=_context23.v;_this13._messages.removeMessage(t),_this13._isPaginationComplete=!0,_this13._messages.addNewErrorMessage(ae,Ft.FAILED_ERROR_MESSAGE,!0),console[f](_t12);case 4:return _context23.a(2);}},_callee23,null,[[1,3]]);}));case 1:return _context24.a(2);}},_callee24,this);}));function loadHistoryOnScroll(_x50){return _loadHistoryOnScroll.apply(this,arguments);}return loadHistoryOnScroll;}()},{key:"populateInitialHistory",value:function populateInitialHistory(e){var _this14=this;e.forEach(function(t){le.processHistoryFile(t),_this14._messages.addAnyMessage(t,!0);});}},{key:"loadInitialHistory",value:function(){var _loadInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee25(e){var t,n,s,_t13;return _regenerator().w(function(_context25){while(1)switch(_context25.p=_context25.n){case 0:this._isLoading=!0;t=Mt.addMessage(this._messages);_context25.p=1;_context25.n=2;return e(this._index++);case 2:n=_context25.v;s=this._messages.elementRef.scrollTop;this.populateMessages(t,n),this.restoreScrollOrScrollToBottom(s===0);_context25.n=4;break;case 3:_context25.p=3;_t13=_context25.v;this._messages.removeMessage(t),this._isPaginationComplete=!0,this._messages.addNewErrorMessage(ae,Ft.FAILED_ERROR_MESSAGE,!0),console[f](_t13);case 4:Ft.displayIntroMessages(this._messages.messageElementRefs),this._isLoading=!1;case 5:return _context25.a(2);}},_callee25,this,[[1,3]]);}));function loadInitialHistory(_x51){return _loadInitialHistory.apply(this,arguments);}return loadInitialHistory;}()},{key:"setupInitialHistory",value:function(){var _setupInitialHistory=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee26(e){var s,t,n;return _regenerator().w(function(_context26){while(1)switch(_context26.n){case 0:e.loadHistory&&this.loadInitialHistory(e.loadHistory);t=(s=this._messages.browserStorage)==null?void 0:s.get(),n=e.history||le.processHistory(e)||(t==null?void 0:t.messages);n&&(this.populateInitialHistory(n),this.restoreScrollOrScrollToBottom(!0),this._index+=1);case 1:return _context26.a(2);}},_callee26,this);}));function setupInitialHistory(_x52){return _setupInitialHistory.apply(this,arguments);}return setupInitialHistory;}()},{key:"restoreScrollOrScrollToBottom",value:function restoreScrollOrScrollToBottom(e){var _this15=this;var n,s,r;var t=(s=(n=this._messages.browserStorage)==null?void 0:n.get())==null?void 0:s.scrollHeight;t!==void 0&&(r=this._messages.browserStorage)!=null&&r.trackScrollHeight?setTimeout(function(){_this15._messages.elementRef.scrollTop=t;},0):e&&setTimeout(function(){return z.scrollToBottom(_this15._messages);},0);}}],[{key:"addErrorPrefix",value:function addErrorPrefix(e){var _e$permittedErrorPref;(_e$permittedErrorPref=e.permittedErrorPrefixes)!==null&&_e$permittedErrorPref!==void 0?_e$permittedErrorPref:e.permittedErrorPrefixes=[],e.permittedErrorPrefixes.push(Ft.FAILED_ERROR_MESSAGE);}},{key:"displayIntroMessages",value:function displayIntroMessages(e){for(var t=0;t<e.length;t+=1){var n=e[0];if(n.outerContainer[m].contains(nt.INTRO_CLASS))n.outerContainer[v].display="";else break;}}}]);}();Ft.FAILED_ERROR_MESSAGE="Failed to load history";var Cs=Ft;var Ae=/*#__PURE__*/function(){function Ae(){_classCallCheck(this,Ae);}return _createClass(Ae,null,[{key:"parseConfig",value:function parseConfig(e,t,n){var r;var s={files:e};if(_typeof(n)=="object"){le.processFileConfigConnect(n);var o=n.files,a=n.connect,c=n.button;o&&(o.infoModal&&(s[b].infoModal=o.infoModal,(r=o.infoModal)!=null&&r.textMarkDown&&(s.infoModalTextMarkUp=t.render(o.infoModal.textMarkDown))),o.acceptedFormats&&(s[b].acceptedFormats=o.acceptedFormats),o.maxNumberOfFiles&&(s[b].maxNumberOfFiles=o.maxNumberOfFiles)),s.button=c,a&&Object.keys(a).length>0&&(s.connect=a);}return s;}},{key:"processMixedFiles",value:function processMixedFiles(e,t,n){if(n){var s={acceptedFormats:""};e.fileTypes.mixedFiles=Ae.parseConfig(s,t,n);}}// needs to be set after audio to overwrite maxNumberOfFiles
119
115
  // prettier-ignore
120
116
  },{key:"processMicrophone",value:function processMicrophone(e,t,n,s){var _c$b,_u$maxNumberOfFiles;var a,c,l,d,p,u;var o=_objectSpread({acceptedFormats:"audio/*"},((a=e.fileTypes[$])==null?void 0:a[b])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e.recordAudio=Ae.parseConfig(o,t,n),_typeof(n)=="object"&&n[b]&&((_c$b=(c=e.recordAudio)[b])!==null&&_c$b!==void 0?_c$b:c[b]={},e.recordAudio[b].format=(l=n[b])==null?void 0:l.format,e.recordAudio[b].maxDurationSeconds=(d=n[b])==null?void 0:d.maxDurationSeconds,(p=e.fileTypes[$])!=null&&p[b]&&((_u$maxNumberOfFiles=(u=e.fileTypes[$][b]).maxNumberOfFiles)!==null&&_u$maxNumberOfFiles!==void 0?_u$maxNumberOfFiles:u.maxNumberOfFiles=n[b].maxNumberOfFiles))):s||(e.fileTypes[$]=Ae.parseConfig(o,t,n)));}// prettier-ignore
121
117
  },{key:"processAudioConfig",value:function processAudioConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"audio/*"},(s==null?void 0:s[b])||{});e.fileTypes[$]=Ae.parseConfig(o,t,n);}// prettier-ignore
@@ -123,35 +119,35 @@ function(){var _request3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(functio
123
119
  // prettier-ignore
124
120
  },{key:"processCamera",value:function processCamera(e,t,n,s){var _c$b2;var a,c,l,d;var o=_objectSpread({acceptedFormats:"image/*"},((a=e.fileTypes[ee])==null?void 0:a[b])||{});n&&(navigator.mediaDevices.getUserMedia!==void 0?(e[Fe]=Ae.parseConfig(o,t,n),_typeof(n)=="object"&&(e[Fe].modalContainerStyle=n.modalContainerStyle,n[b]&&((_c$b2=(c=e[Fe])[b])!==null&&_c$b2!==void 0?_c$b2:c[b]={},e[Fe][b].format=(l=n[b])==null?void 0:l.format,e[Fe][b].dimensions=(d=n[b])==null?void 0:d.dimensions))):s||(e.fileTypes[ee]=Ae.parseConfig(o,t,n)));}// prettier-ignore
125
121
  },{key:"processImagesConfig",value:function processImagesConfig(e,t,n,s){if(!n&&!s)return;var o=_objectSpread({acceptedFormats:"image/*"},(s==null?void 0:s[b])||{});e.fileTypes[ee]=Ae.parseConfig(o,t,n);}// default for direct service
126
- },{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$b,_n$acceptedFormats,_s$maxNumberOfFiles;var n,s;e&&((_e$b=e[b])!==null&&_e$b!==void 0?_e$b:e[b]={},(_n$acceptedFormats=(n=e[b]).acceptedFormats)!==null&&_n$acceptedFormats!==void 0?_n$acceptedFormats:n.acceptedFormats=t,(_s$maxNumberOfFiles=(s=e[b]).maxNumberOfFiles)!==null&&_s$maxNumberOfFiles!==void 0?_s$maxNumberOfFiles:s.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,n){Ae.populateDefaultFileIO(n==null?void 0:n[$],".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),Ae.populateDefaultFileIO(n==null?void 0:n[ee],".png,.jpg");var s=Cs.createNew(e.remarkable);Ae.processImagesConfig(t,s,e[ee],n==null?void 0:n[ee]),Ae.processCamera(t,s,e[Fe],e[ee]),Ae.processGifConfig(t,s,e[Cn],n==null?void 0:n[Cn]),Ae.processAudioConfig(t,s,e[$],n==null?void 0:n[$]),Ae.processMicrophone(t,s,e[ct],e[$]),Ae.processMixedFiles(t,s,e[Oo]);}}]);}();var hn=/*#__PURE__*/function(){function hn(e,t,n){var _a$url;_classCallCheck(this,hn);var s,r,o,a,c;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=hn.canSendMessage,this.connectSettings={},this.fileTypes={},this.completionsHandlers={},this.streamHandlers={},this.deepChat=e,this.demo=n,Object.assign(this.rawBody,(s=e.connect)==null?void 0:s.additionalBodyProps),this.totalMessagesMaxCharLength=(r=e==null?void 0:e.requestBodyLimits)==null?void 0:r.totalMessagesMaxCharLength,this.maxMessages=(o=e==null?void 0:e.requestBodyLimits)==null?void 0:o.maxMessages,Ae.set(e,this,t),e.connect&&(this.connectSettings=e.connect),this.demo&&((_a$url=(a=this.connectSettings).url)!==null&&_a$url!==void 0?_a$url:a.url=pt.URL),this.connectSettings.websocket&&ke.setup(this),this.stream=((c=this.deepChat.connect)==null?void 0:c.stream)||de.checkForStream(this.deepChat),e.loadHistory&&Ts.addErrorPrefix(this);}return _createClass(hn,[{key:"verifyKey",value:function verifyKey(e,t){}},{key:"getServiceIOByType",value:function getServiceIOByType(e){if(e[E].startsWith($)&&this.fileTypes[$])return this.fileTypes[$];if(e[E].startsWith(W)){if(this.fileTypes[Cn]&&e[E].endsWith("/gif"))return this.fileTypes[Cn];if(this.fileTypes[ee])return this.fileTypes[ee];if(this[Fe])return this[Fe];}return this.fileTypes[Oo];}},{key:"request",value:function(){var _request4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(e,t){var n,_args27=arguments;return _regenerator().w(function(_context27){while(1)switch(_context27.n){case 0:n=_args27.length>2&&_args27[2]!==undefined?_args27[2]:!0;return _context27.a(2,this.stream&&!V.isSimulation(this.stream)?V.request(this,e,t,n):ge.request(this,e,t,n));}},_callee27,this);}));function request(_x53,_x54){return _request4.apply(this,arguments);}return request;}()},{key:"callAPIWithText",value:function(){var _callAPIWithText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(e,t){var _o$headers,_a$q;var r,o,a,c,n,s;return _regenerator().w(function(_context28){while(1)switch(_context28.n){case 0:n=_objectSpread({messages:t},this.rawBody);s=!1;(r=this.connectSettings.headers)!=null&&r[q]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$q=(a=this.connectSettings.headers)[q])!==null&&_a$q!==void 0?_a$q:a[q]=te,s=!0);_context28.n=1;return this.request(n,e);case 1:s&&((c=this.connectSettings.headers)==null||delete c[q]);case 2:return _context28.a(2);}},_callee28,this);}));function callAPIWithText(_x55,_x56){return _callAPIWithText.apply(this,arguments);}return callAPIWithText;}()},{key:"callApiWithFiles",value:function(){var _callApiWithFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(e,t,n){var s,r,o;return _regenerator().w(function(_context29){while(1)switch(_context29.n){case 0:s=hn.createCustomFormDataBody(this.rawBody,t,n),r=this.connectSettings,o=this.getServiceIOByType(n[0]);this.connectSettings=(o==null?void 0:o.connect)||this.connectSettings;_context29.n=1;return this.request(s,e,!1);case 1:this.connectSettings=r;case 2:return _context29.a(2);}},_callee29,this);}));function callApiWithFiles(_x57,_x58,_x59){return _callApiWithFiles.apply(this,arguments);}return callApiWithFiles;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(e,t,n){return _regenerator().w(function(_context30){while(1)switch(_context30.n){case 0:n?this.callApiWithFiles(e,t,n):this.callAPIWithText(e,t);case 1:return _context30.a(2);}},_callee30,this);}));function callServiceAPI(_x60,_x61,_x62){return _callServiceAPI.apply(this,arguments);}return callServiceAPI;}()// prettier-ignore
127
- },{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(e,t){var s,n,r;return _regenerator().w(function(_context31){while(1)switch(_context31.n){case 0:if(this.connectSettings){_context31.n=1;break;}throw new Error(He);case 1:n=kn.processMessages(t.messageToElements.map(function(_ref21){var _ref22=_slicedToArray(_ref21,1),r=_ref22[0];return r;}),this.maxMessages,this.totalMessagesMaxCharLength);if(this.connectSettings.websocket&&(!this.connectSettings.handler||this.connectSettings.url!==pt.URL)){r=_objectSpread({messages:n},this.rawBody);e[b]&&(s=this.getServiceIOByType(e[b][0]))!=null&&s.connect?this.callApiWithFiles(t,n,e[b]):ke.sendWebsocket(this,r,t,!1);}else this.callServiceAPI(t,n,e[b]);case 2:return _context31.a(2);}},_callee31,this);}));function callAPI(_x63,_x64){return _callAPI.apply(this,arguments);}return callAPI;}()},{key:"extractResultData",value:function(){var _extractResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(e){return _regenerator().w(function(_context32){while(1)switch(_context32.n){case 0:if(!e.result){_context32.n=1;break;}return _context32.a(2,de.handleResponseProperty(e));case 1:if(!D.validateResponseFormat(e,!!this.stream)){_context32.n=2;break;}return _context32.a(2,e);case 2:return _context32.a(2);}},_callee32,this);}));function extractResultData(_x65){return _extractResultData.apply(this,arguments);}return extractResultData;}()},{key:"isDirectConnection",value:function isDirectConnection(){return!1;}},{key:"isWebModel",value:function isWebModel(){return!1;}},{key:"isCustomView",value:function isCustomView(){return!1;}}],[{key:"canSendMessage",value:function canSendMessage(e,t,n){return n?!0:!!(e&&e.trim()!=="")||!!(t&&t[X]>0);}},{key:"createCustomFormDataBody",value:function createCustomFormDataBody(e,t,n){var s=new FormData();n.forEach(function(a){return s.append("files",a);}),Object.keys(e).forEach(function(a){return s.append(a,String(e[a]));});var r=0;t.slice(0,t[X]-1).forEach(function(a){s.append("message".concat(r+=1),le(a));});var o=t[t[X]-1];return o[h]&&(delete o[b],s.append("message".concat(r+=1),le(o))),s;}}]);}();var k=/*#__PURE__*/function(_hn){// prettier-ignore
128
- function k(e,t,n,s,r){var _this16;_classCallCheck(this,k);var o;_this16=_callSuper(this,k,[e,r]),_this16.insertKeyPlaceholderText="API Key",_this16.keyHelpUrl="",_this16.asyncCallInProgress=!1,_this16.systemMessage="",Object.assign(_this16.rawBody,(o=e.connect)==null?void 0:o.additionalBodyProps),_this16._keyVerificationDetails=t,_this16._buildHeadersFunc=n,s&&_this16.setApiKeyProperties(s),_this16.connectSettings=_this16.buildConnectSettings(_this16.key||"",e.connect);return _this16;}_inherits(k,_hn);return _createClass(k,[{key:"setApiKeyProperties",value:function setApiKeyProperties(e){this.key=e.key,e.validateKeyProperty&&(this.validateKeyProperty=e.validateKeyProperty);}},{key:"buildConnectSettings",value:function buildConnectSettings(e,t){var _n$headers;var n=t!==null&&t!==void 0?t:{};return(_n$headers=n.headers)!==null&&_n$headers!==void 0?_n$headers:n.headers={},Object.assign(n.headers,this._buildHeadersFunc(e)),n;}},{key:"completeConfig",value:function completeConfig(e,t){e.system_prompt&&(this.systemMessage=e.system_prompt),t&&(this.functionHandler=t),delete e.system_prompt,delete e.key,delete e.function_handler,Object.assign(this.rawBody,e);}},{key:"keyAuthenticated",value:function keyAuthenticated(e,t){this.connectSettings=this.buildConnectSettings(t,this.connectSettings),this.key=t,e();}// prettier-ignore
129
- },{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,n=_this$_keyVerificatio.url,s=_this$_keyVerificatio.method,r=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,c=_this$_keyVerificatio.augmentUrl,l=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(c==null?void 0:c(e))||n;ge.verifyKey(e,d,l,s,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,r,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}},{key:"processMessages",value:function processMessages(e){return kn.getCharacterLimitMessages(e,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this.systemMessage[X]:-1);}},{key:"addSystemMessage",value:function addSystemMessage(e){this.systemMessage&&e.unshift(_defineProperty(_defineProperty({},x,Mn),"content",this.systemMessage));}},{key:"callDirectServiceServiceAPI",value:function(){var _callDirectServiceServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(e,t,n,s,r){var o,a;return _regenerator().w(function(_context33){while(1)switch(_context33.n){case 0:if(this.connectSettings){_context33.n=1;break;}throw new Error(He);case 1:o=n(this.rawBody,t),a=s?this.stream:!1;if(!(a&&(_typeof(a)!==U||!a.simulation)||o.stream)){_context33.n=2;break;}o.stream=!0,s!=null&&s.readable&&(this.stream={readable:!0}),V.request(this,o,e);_context33.n=4;break;case 2:_context33.n=3;return ge.request(this,o,e,r);case 3:return _context33.a(2,_context33.v);case 4:return _context33.a(2);}},_callee33,this);}));function callDirectServiceServiceAPI(_x66,_x67,_x68,_x69,_x70){return _callDirectServiceServiceAPI.apply(this,arguments);}return callDirectServiceServiceAPI;}()},{key:"callToolFunction",value:function(){var _callToolFunction=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(e,t){var r,o,n,a,c,_t14,_t15;return _regenerator().w(function(_context34){while(1)switch(_context34.n){case 0:this.asyncCallInProgress=!0;_context34.n=1;return e(t);case 1:n=_context34.v;if(Array.isArray(n)){_context34.n=6;break;}if(!n[h]){_context34.n=5;break;}a=_defineProperty({},h,n[h]);_context34.n=2;return(o=(r=this.deepChat).responseInterceptor)==null?void 0:o.call(r,a);case 2:_t14=_context34.v;if(_t14){_context34.n=3;break;}_t14=a;case 3:c=_t14;if(!Array.isArray(c)){_context34.n=4;break;}throw Error("Function tool response interceptor cannot return an array");case 4:return _context34.a(2,{processedResponse:c});case 5:throw Error(on);case 6:_context34.n=7;return Promise.all(n);case 7:_t15=_context34.v;return _context34.a(2,{responses:_t15});}},_callee34,this);}));function callToolFunction(_x71,_x72){return _callToolFunction.apply(this,arguments);}return callToolFunction;}()},{key:"makeAnotherRequest",value:function makeAnotherRequest(e,t,n){try{return t&&(this.stream?V.request(this,e,t):ge.request(this,e,t)),_defineProperty({},h,n||"");}catch(s){throw this.asyncCallInProgress=!1,s;}}},{key:"genereteAPIKeyName",value:function genereteAPIKeyName(e){return"".concat(e," API Key");}},{key:"extractStreamResultWToolsGeneric",value:function(){var _extractStreamResultWToolsGeneric=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(e,t,n,s,r){var o,a,c;return _regenerator().w(function(_context35){while(1)switch(_context35.n){case 0:o=t.delta,a=t.finish_reason;if(!(a==="tool_calls")){_context35.n=1;break;}c={tool_calls:e._streamToolCalls};return _context35.a(2,(e._streamToolCalls=void 0,this.handleToolsGeneric(c,n,e.messages,s,r)));case 1:o!=null&&o.tool_calls&&(e._streamToolCalls?o.tool_calls.forEach(function(c,l){e._streamToolCalls&&(e._streamToolCalls[l]["function"].arguments+=c["function"].arguments);}):e._streamToolCalls=o.tool_calls);case 2:return _context35.a(2,_defineProperty({},h,(o==null?void 0:o.content)||""));}},_callee35,this);}));function extractStreamResultWToolsGeneric(_x73,_x74,_x75,_x76,_x77){return _extractStreamResultWToolsGeneric.apply(this,arguments);}return extractStreamResultWToolsGeneric;}()},{key:"handleToolsGeneric",value:function(){var _handleToolsGeneric=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(e,t,n,s,r){var o,a,_yield$this$callToolF,c,l;return _regenerator().w(function(_context36){while(1)switch(_context36.n){case 0:if(!(!e.tool_calls||!s||!t)){_context36.n=1;break;}throw Error(qt);case 1:o=C(s);a=e.tool_calls.map(function(d){return{name:d["function"].name,arguments:d["function"].arguments};});_context36.n=2;return this.callToolFunction(t,a);case 2:_yield$this$callToolF=_context36.v;c=_yield$this$callToolF.responses;l=_yield$this$callToolF.processedResponse;if(!l){_context36.n=3;break;}return _context36.a(2,l);case 3:if(!(r&&(o.messages=o.messages.slice(o.messages[X]-1),r.message&&o.messages.unshift(_defineProperty(_defineProperty({},x,Mn),"content",r.message))),o.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},x,gt),"content",null)),!c.find(function(_ref25){var d=_ref25.response;return _typeof(d)!==Ee;})&&a[X]===c[X])){_context36.n=4;break;}return _context36.a(2,(c.forEach(function(d,p){var g;var u=(g=e.tool_calls)==null?void 0:g[p];o==null||o.messages.push(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},x,"tool"),"tool_call_id",u==null?void 0:u.id),"name",u==null?void 0:u["function"].name),"content",d.response));}),this.makeAnotherRequest(o,n)));case 4:throw Error(on);case 5:return _context36.a(2);}},_callee36,this);}));function handleToolsGeneric(_x78,_x79,_x80,_x81,_x82){return _handleToolsGeneric.apply(this,arguments);}return handleToolsGeneric;}()},{key:"updateSessionId",value:function updateSessionId(e){this.messages&&this.messages.messageToElements[X]>0&&(this.messages.messageToElements[this.messages.messageToElements[X]-1][0]._sessionId=e);}}],[{key:"getRoleViaUser",value:function getRoleViaUser(e){return e===F?F:gt;}},{key:"getRoleViaAI",value:function getRoleViaAI(e){return e===ne?gt:F;}},{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t[E]===W;}).map(function(t){return _defineProperty(_defineProperty({},E,qe),qe,{url:t[T]||""});}).filter(function(t){return t[qe].url[X]>0;});}},{key:"getTextWImagesContent",value:function getTextWImagesContent(e){if(e[b]&&e[b][X]>0){var t=this.getImageContent(e[b]);return e[h]&&e[h].trim()[X]>0&&t.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),t[X]>0?t:e[h]||"";}return e[h]||"";}},{key:"getTextWFilesContent",value:function getTextWFilesContent(e,t){if(e[b]&&e[b][X]>0){var n=t(e[b]);return e[h]&&e[h].trim()[X]>0&&n.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),n;}return e[h]||"";}}]);}(hn);var Ys=/*#__PURE__*/function(){function Ys(){_classCallCheck(this,Ys);}return _createClass(Ys,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?Ys.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,Ys.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var At=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
122
+ },{key:"populateDefaultFileIO",value:function populateDefaultFileIO(e,t){var _e$b,_n$acceptedFormats,_s$maxNumberOfFiles;var n,s;e&&((_e$b=e[b])!==null&&_e$b!==void 0?_e$b:e[b]={},(_n$acceptedFormats=(n=e[b]).acceptedFormats)!==null&&_n$acceptedFormats!==void 0?_n$acceptedFormats:n.acceptedFormats=t,(_s$maxNumberOfFiles=(s=e[b]).maxNumberOfFiles)!==null&&_s$maxNumberOfFiles!==void 0?_s$maxNumberOfFiles:s.maxNumberOfFiles=1);}},{key:"set",value:function set(e,t,n){Ae.populateDefaultFileIO(n==null?void 0:n[$],".4a,.mp3,.webm,.mp4,.mpga,.wav,.mpeg,.m4a"),Ae.populateDefaultFileIO(n==null?void 0:n[ee],".png,.jpg");var s=ws.createNew(e.remarkable);Ae.processImagesConfig(t,s,e[ee],n==null?void 0:n[ee]),Ae.processCamera(t,s,e[Fe],e[ee]),Ae.processGifConfig(t,s,e[Cn],n==null?void 0:n[Cn]),Ae.processAudioConfig(t,s,e[$],n==null?void 0:n[$]),Ae.processMicrophone(t,s,e[ct],e[$]),Ae.processMixedFiles(t,s,e[Lo]);}}]);}();var un=/*#__PURE__*/function(){function un(e,t,n){var _a$url;_classCallCheck(this,un);var s,r,o,a,c;this.rawBody={},this.validateKeyProperty=!1,this.canSendMessage=un.canSendMessage,this.connectSettings={},this.fileTypes={},this.completionsHandlers={},this.streamHandlers={},this.deepChat=e,this.demo=n,Object.assign(this.rawBody,(s=e.connect)==null?void 0:s.additionalBodyProps),this.totalMessagesMaxCharLength=(r=e==null?void 0:e.requestBodyLimits)==null?void 0:r.totalMessagesMaxCharLength,this.maxMessages=(o=e==null?void 0:e.requestBodyLimits)==null?void 0:o.maxMessages,Ae.set(e,this,t),e.connect&&(this.connectSettings=e.connect),this.demo&&((_a$url=(a=this.connectSettings).url)!==null&&_a$url!==void 0?_a$url:a.url=pt.URL),this.connectSettings.websocket&&ke.setup(this),this.stream=((c=this.deepChat.connect)==null?void 0:c.stream)||le.checkForStream(this.deepChat),e.loadHistory&&Cs.addErrorPrefix(this);}return _createClass(un,[{key:"verifyKey",value:function verifyKey(e,t){}},{key:"getServiceIOByType",value:function getServiceIOByType(e){if(e[E].startsWith($)&&this.fileTypes[$])return this.fileTypes[$];if(e[E].startsWith(W)){if(this.fileTypes[Cn]&&e[E].endsWith("/gif"))return this.fileTypes[Cn];if(this.fileTypes[ee])return this.fileTypes[ee];if(this[Fe])return this[Fe];}return this.fileTypes[Lo];}},{key:"request",value:function(){var _request4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee27(e,t){var n,_args27=arguments;return _regenerator().w(function(_context27){while(1)switch(_context27.n){case 0:n=_args27.length>2&&_args27[2]!==undefined?_args27[2]:!0;return _context27.a(2,this.stream&&!V.isSimulation(this.stream)?V.request(this,e,t,n):ge.request(this,e,t,n));}},_callee27,this);}));function request(_x53,_x54){return _request4.apply(this,arguments);}return request;}()},{key:"callAPIWithText",value:function(){var _callAPIWithText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee28(e,t){var _o$headers,_a$q;var r,o,a,c,n,s;return _regenerator().w(function(_context28){while(1)switch(_context28.n){case 0:n=_objectSpread({messages:t},this.rawBody);s=!1;(r=this.connectSettings.headers)!=null&&r[q]||((_o$headers=(o=this.connectSettings).headers)!==null&&_o$headers!==void 0?_o$headers:o.headers={},(_a$q=(a=this.connectSettings.headers)[q])!==null&&_a$q!==void 0?_a$q:a[q]=te,s=!0);_context28.n=1;return this.request(n,e);case 1:s&&((c=this.connectSettings.headers)==null||delete c[q]);case 2:return _context28.a(2);}},_callee28,this);}));function callAPIWithText(_x55,_x56){return _callAPIWithText.apply(this,arguments);}return callAPIWithText;}()},{key:"callApiWithFiles",value:function(){var _callApiWithFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee29(e,t,n){var s,r,o;return _regenerator().w(function(_context29){while(1)switch(_context29.n){case 0:s=un.createCustomFormDataBody(this.rawBody,t,n),r=this.connectSettings,o=this.getServiceIOByType(n[0]);this.connectSettings=(o==null?void 0:o.connect)||this.connectSettings;_context29.n=1;return this.request(s,e,!1);case 1:this.connectSettings=r;case 2:return _context29.a(2);}},_callee29,this);}));function callApiWithFiles(_x57,_x58,_x59){return _callApiWithFiles.apply(this,arguments);}return callApiWithFiles;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee30(e,t,n){return _regenerator().w(function(_context30){while(1)switch(_context30.n){case 0:n?this.callApiWithFiles(e,t,n):this.callAPIWithText(e,t);case 1:return _context30.a(2);}},_callee30,this);}));function callServiceAPI(_x60,_x61,_x62){return _callServiceAPI.apply(this,arguments);}return callServiceAPI;}()// prettier-ignore
123
+ },{key:"callAPI",value:function(){var _callAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee31(e,t){var s,n,r;return _regenerator().w(function(_context31){while(1)switch(_context31.n){case 0:if(this.connectSettings){_context31.n=1;break;}throw new Error(He);case 1:n=kn.processMessages(t.messageToElements.map(function(_ref25){var _ref26=_slicedToArray(_ref25,1),r=_ref26[0];return r;}),this.maxMessages,this.totalMessagesMaxCharLength);if(this.connectSettings.websocket&&(!this.connectSettings.handler||this.connectSettings.url!==pt.URL)){r=_objectSpread({messages:n},this.rawBody);e[b]&&(s=this.getServiceIOByType(e[b][0]))!=null&&s.connect?this.callApiWithFiles(t,n,e[b]):ke.sendWebsocket(this,r,t,!1);}else this.callServiceAPI(t,n,e[b]);case 2:return _context31.a(2);}},_callee31,this);}));function callAPI(_x63,_x64){return _callAPI.apply(this,arguments);}return callAPI;}()},{key:"extractResultData",value:function(){var _extractResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee32(e){return _regenerator().w(function(_context32){while(1)switch(_context32.n){case 0:if(!e.result){_context32.n=1;break;}return _context32.a(2,le.handleResponseProperty(e));case 1:if(!D.validateResponseFormat(e,!!this.stream)){_context32.n=2;break;}return _context32.a(2,e);case 2:return _context32.a(2);}},_callee32,this);}));function extractResultData(_x65){return _extractResultData.apply(this,arguments);}return extractResultData;}()},{key:"isDirectConnection",value:function isDirectConnection(){return!1;}},{key:"isWebModel",value:function isWebModel(){return!1;}},{key:"isCustomView",value:function isCustomView(){return!1;}}],[{key:"canSendMessage",value:function canSendMessage(e,t,n){return n?!0:!!(e&&e.trim()!=="")||!!(t&&t[X]>0);}},{key:"createCustomFormDataBody",value:function createCustomFormDataBody(e,t,n){var s=new FormData();n.forEach(function(a){return s.append("files",a);}),Object.keys(e).forEach(function(a){return s.append(a,String(e[a]));});var r=0;t.slice(0,t[X]-1).forEach(function(a){s.append("message".concat(r+=1),ce(a));});var o=t[t[X]-1];return o[h]&&(delete o[b],s.append("message".concat(r+=1),ce(o))),s;}}]);}();var k=/*#__PURE__*/function(_un){// prettier-ignore
124
+ function k(e,t,n,s,r){var _this16;_classCallCheck(this,k);var o;_this16=_callSuper(this,k,[e,r]),_this16.insertKeyPlaceholderText="API Key",_this16.keyHelpUrl="",_this16.asyncCallInProgress=!1,_this16.systemMessage="",Object.assign(_this16.rawBody,(o=e.connect)==null?void 0:o.additionalBodyProps),_this16._keyVerificationDetails=t,_this16._buildHeadersFunc=n,s&&_this16.setApiKeyProperties(s),_this16.connectSettings=_this16.buildConnectSettings(_this16.key||"",e.connect);return _this16;}_inherits(k,_un);return _createClass(k,[{key:"setApiKeyProperties",value:function setApiKeyProperties(e){this.key=e.key,e.validateKeyProperty&&(this.validateKeyProperty=e.validateKeyProperty);}},{key:"buildConnectSettings",value:function buildConnectSettings(e,t){var _n$headers;var n=t!==null&&t!==void 0?t:{};return(_n$headers=n.headers)!==null&&_n$headers!==void 0?_n$headers:n.headers={},Object.assign(n.headers,this._buildHeadersFunc(e)),n;}},{key:"completeConfig",value:function completeConfig(e,t){e.system_prompt&&(this.systemMessage=e.system_prompt),t&&(this.functionHandler=t),delete e.system_prompt,delete e.key,delete e.function_handler,Object.assign(this.rawBody,e);}},{key:"keyAuthenticated",value:function keyAuthenticated(e,t){this.connectSettings=this.buildConnectSettings(t,this.connectSettings),this.key=t,e();}// prettier-ignore
125
+ },{key:"verifyKey",value:function verifyKey(e,t){var _this$_keyVerificatio=this._keyVerificationDetails,n=_this$_keyVerificatio.url,s=_this$_keyVerificatio.method,r=_this$_keyVerificatio.handleVerificationResult,o=_this$_keyVerificatio.createHeaders,a=_this$_keyVerificatio.body,c=_this$_keyVerificatio.augmentUrl,l=(o==null?void 0:o(e))||this._buildHeadersFunc(e),d=(c==null?void 0:c(e))||n;ge.verifyKey(e,d,l,s,this.keyAuthenticated.bind(this,t.onSuccess),t.onFail,t.onLoad,r,a);}},{key:"isDirectConnection",value:function isDirectConnection(){return!0;}},{key:"processMessages",value:function processMessages(e){return kn.getCharacterLimitMessages(e,this.totalMessagesMaxCharLength?this.totalMessagesMaxCharLength-this.systemMessage[X]:-1);}},{key:"addSystemMessage",value:function addSystemMessage(e){this.systemMessage&&e.unshift(_defineProperty(_defineProperty({},x,Mn),"content",this.systemMessage));}},{key:"callDirectServiceServiceAPI",value:function(){var _callDirectServiceServiceAPI=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee33(e,t,n,s,r){var o,a;return _regenerator().w(function(_context33){while(1)switch(_context33.n){case 0:if(this.connectSettings){_context33.n=1;break;}throw new Error(He);case 1:o=n(this.rawBody,t),a=s?this.stream:!1;if(!(a&&(_typeof(a)!==U||!a.simulation)||o.stream)){_context33.n=2;break;}o.stream=!0,s!=null&&s.readable&&(this.stream={readable:!0}),V.request(this,o,e);_context33.n=4;break;case 2:_context33.n=3;return ge.request(this,o,e,r);case 3:return _context33.a(2,_context33.v);case 4:return _context33.a(2);}},_callee33,this);}));function callDirectServiceServiceAPI(_x66,_x67,_x68,_x69,_x70){return _callDirectServiceServiceAPI.apply(this,arguments);}return callDirectServiceServiceAPI;}()},{key:"callToolFunction",value:function(){var _callToolFunction=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee34(e,t){var r,o,n,a,c,_t14,_t15;return _regenerator().w(function(_context34){while(1)switch(_context34.n){case 0:this.asyncCallInProgress=!0;_context34.n=1;return e(t);case 1:n=_context34.v;if(Array.isArray(n)){_context34.n=6;break;}if(!n[h]){_context34.n=5;break;}a=_defineProperty({},h,n[h]);_context34.n=2;return(o=(r=this.deepChat).responseInterceptor)==null?void 0:o.call(r,a);case 2:_t14=_context34.v;if(_t14){_context34.n=3;break;}_t14=a;case 3:c=_t14;if(!Array.isArray(c)){_context34.n=4;break;}throw Error("Function tool response interceptor cannot return an array");case 4:return _context34.a(2,{processedResponse:c});case 5:throw Error(an);case 6:_context34.n=7;return Promise.all(n);case 7:_t15=_context34.v;return _context34.a(2,{responses:_t15});}},_callee34,this);}));function callToolFunction(_x71,_x72){return _callToolFunction.apply(this,arguments);}return callToolFunction;}()},{key:"makeAnotherRequest",value:function makeAnotherRequest(e,t,n){try{return t&&(this.stream?V.request(this,e,t):ge.request(this,e,t)),_defineProperty({},h,n||"");}catch(s){throw this.asyncCallInProgress=!1,s;}}},{key:"genereteAPIKeyName",value:function genereteAPIKeyName(e){return"".concat(e," API Key");}},{key:"extractStreamResultWToolsGeneric",value:function(){var _extractStreamResultWToolsGeneric=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee35(e,t,n,s,r){var o,a,c;return _regenerator().w(function(_context35){while(1)switch(_context35.n){case 0:o=t.delta,a=t.finish_reason;if(!(a==="tool_calls")){_context35.n=1;break;}c={tool_calls:e._streamToolCalls};return _context35.a(2,(e._streamToolCalls=void 0,this.handleToolsGeneric(c,n,e.messages,s,r)));case 1:o!=null&&o.tool_calls&&(e._streamToolCalls?o.tool_calls.forEach(function(c,l){e._streamToolCalls&&(e._streamToolCalls[l]["function"].arguments+=c["function"].arguments);}):e._streamToolCalls=o.tool_calls);case 2:return _context35.a(2,_defineProperty({},h,(o==null?void 0:o.content)||""));}},_callee35,this);}));function extractStreamResultWToolsGeneric(_x73,_x74,_x75,_x76,_x77){return _extractStreamResultWToolsGeneric.apply(this,arguments);}return extractStreamResultWToolsGeneric;}()},{key:"handleToolsGeneric",value:function(){var _handleToolsGeneric=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee36(e,t,n,s,r){var o,a,_yield$this$callToolF,c,l;return _regenerator().w(function(_context36){while(1)switch(_context36.n){case 0:if(!(!e.tool_calls||!s||!t)){_context36.n=1;break;}throw Error(Gt);case 1:o=C(s);a=e.tool_calls.map(function(d){return{name:d["function"].name,arguments:d["function"].arguments};});_context36.n=2;return this.callToolFunction(t,a);case 2:_yield$this$callToolF=_context36.v;c=_yield$this$callToolF.responses;l=_yield$this$callToolF.processedResponse;if(!l){_context36.n=3;break;}return _context36.a(2,l);case 3:if(!(r&&(o.messages=o.messages.slice(o.messages[X]-1),r.message&&o.messages.unshift(_defineProperty(_defineProperty({},x,Mn),"content",r.message))),o.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},x,gt),"content",null)),!c.find(function(_ref29){var d=_ref29.response;return _typeof(d)!==Ee;})&&a[X]===c[X])){_context36.n=4;break;}return _context36.a(2,(c.forEach(function(d,p){var g;var u=(g=e.tool_calls)==null?void 0:g[p];o==null||o.messages.push(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},x,"tool"),"tool_call_id",u==null?void 0:u.id),"name",u==null?void 0:u["function"].name),"content",d.response));}),this.makeAnotherRequest(o,n)));case 4:throw Error(an);case 5:return _context36.a(2);}},_callee36,this);}));function handleToolsGeneric(_x78,_x79,_x80,_x81,_x82){return _handleToolsGeneric.apply(this,arguments);}return handleToolsGeneric;}()},{key:"updateSessionId",value:function updateSessionId(e){this.messages&&this.messages.messageToElements[X]>0&&(this.messages.messageToElements[this.messages.messageToElements[X]-1][0]._sessionId=e);}}],[{key:"getRoleViaUser",value:function getRoleViaUser(e){return e===F?F:gt;}},{key:"getRoleViaAI",value:function getRoleViaAI(e){return e===ne?gt:F;}},{key:"getImageContent",value:function getImageContent(e){return e.filter(function(t){return t[E]===W;}).map(function(t){return _defineProperty(_defineProperty({},E,qe),qe,{url:t[T]||""});}).filter(function(t){return t[qe].url[X]>0;});}},{key:"getTextWImagesContent",value:function getTextWImagesContent(e){if(e[b]&&e[b][X]>0){var t=this.getImageContent(e[b]);return e[h]&&e[h].trim()[X]>0&&t.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),t[X]>0?t:e[h]||"";}return e[h]||"";}},{key:"getTextWFilesContent",value:function getTextWFilesContent(e,t){if(e[b]&&e[b][X]>0){var n=t(e[b]);return e[h]&&e[h].trim()[X]>0&&n.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),n;}return e[h]||"";}}]);}(un);var Xs=/*#__PURE__*/function(){function Xs(){_classCallCheck(this,Xs);}return _createClass(Xs,null,[{key:"waitForPropertiesToBeUpdatedBeforeRender",value:function waitForPropertiesToBeUpdatedBeforeRender(e){e._propUpdated_=!1,setTimeout(function(){e._propUpdated_?Xs.waitForPropertiesToBeUpdatedBeforeRender(e):(e._waitingToRender_=!1,e.onRender());});}},{key:"attemptRender",value:function attemptRender(e){e._propUpdated_=!0,e._waitingToRender_||(e._waitingToRender_=!0,Xs.waitForPropertiesToBeUpdatedBeforeRender(e));}}]);}();var At=/*#__PURE__*/function(_HTMLElement){// If this is not working, try using propertyName directly
130
126
  function At(){var _this17;_classCallCheck(this,At);_this17=_callSuper(this,At),_this17._waitingToRender_=!1,_this17._propUpdated_=!1,Object.keys(At._attributeToProperty_).forEach(function(e){var t=At._attributeToProperty_[e];_this17.constructPropertyAccessors(t),_this17.hasOwnProperty(e)||_this17.constructPropertyAccessors(t,e);});return _this17;}_inherits(At,_HTMLElement);return _createClass(At,[{key:"constructPropertyAccessors",value:// need to be called here as accessors need to be set for the class instance
131
- function constructPropertyAccessors(e,t){var n;Object.defineProperty(this,t||e,{get:function get(){return n;},set:function set(o){n=o,t?this[e]=o:Ys.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,n){if(t===n)return;var s=At._attributes_[e](n),r=At._attributeToProperty_[e];this[r]=s;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(At._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));At._attributes_={},At._attributeToProperty_={};var zi=At;var Rl="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path d=\"\n\t\t\tM669.727,273.516c-22.891-2.476-46.15-3.895-69.727-4.248c-103.025,0.457-209.823,25.517-310.913,73.536\n\t\t\tc-75.058,37.122-148.173,89.529-211.67,154.174C46.232,529.978,6.431,577.76,0,628.74c0.76,44.162,48.153,98.67,77.417,131.764\n\t\t\tc59.543,62.106,130.754,113.013,211.67,154.174c2.75,1.335,5.51,2.654,8.276,3.955l-75.072,131.102l102.005,60.286l551.416-960.033\n\t\t\tl-98.186-60.008L669.727,273.516z M902.563,338.995l-74.927,129.857c34.47,44.782,54.932,100.006,54.932,159.888\n\t\t\tc0,149.257-126.522,270.264-282.642,270.264c-6.749,0-13.29-0.728-19.922-1.172l-49.585,85.84c22.868,2.449,45.99,4.233,69.58,4.541\n\t\t\tc103.123-0.463,209.861-25.812,310.84-73.535c75.058-37.122,148.246-89.529,211.743-154.174\n\t\t\tc31.186-32.999,70.985-80.782,77.417-131.764c-0.76-44.161-48.153-98.669-77.417-131.763\n\t\t\tc-59.543-62.106-130.827-113.013-211.743-154.175C908.108,341.478,905.312,340.287,902.563,338.995L902.563,338.995z\n\t\t\tM599.927,358.478c6.846,0,13.638,0.274,20.361,0.732l-58.081,100.561c-81.514,16.526-142.676,85.88-142.676,168.897\n\t\t\tc0,20.854,3.841,40.819,10.913,59.325c0.008,0.021-0.008,0.053,0,0.074l-58.228,100.854\n\t\t\tc-34.551-44.823-54.932-100.229-54.932-160.182C317.285,479.484,443.808,358.477,599.927,358.478L599.927,358.478z M768.896,570.513\n\t\t\tL638.013,797.271c81.076-16.837,141.797-85.875,141.797-168.603C779.81,608.194,775.724,588.729,768.896,570.513L768.896,570.513z\"\n\t\t\t/>\n</svg>\n",Il="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path id=\"path6686\" inkscape:connector-curvature=\"0\" d=\"M779.843,599.925c0,95.331-80.664,172.612-180.169,172.612\n\t\t\tc-99.504,0-180.168-77.281-180.168-172.612c0-95.332,80.664-172.612,180.168-172.612\n\t\t\tC699.179,427.312,779.843,504.594,779.843,599.925z M600,240.521c-103.025,0.457-209.814,25.538-310.904,73.557\n\t\t\tc-75.058,37.122-148.206,89.496-211.702,154.141C46.208,501.218,6.431,549,0,599.981c0.76,44.161,48.13,98.669,77.394,131.763\n\t\t\tc59.543,62.106,130.786,113.018,211.702,154.179c94.271,45.751,198.616,72.092,310.904,73.557\n\t\t\tc103.123-0.464,209.888-25.834,310.866-73.557c75.058-37.122,148.243-89.534,211.74-154.179\n\t\t\tc31.185-32.999,70.962-80.782,77.394-131.763c-0.76-44.161-48.13-98.671-77.394-131.764\n\t\t\tc-59.543-62.106-130.824-112.979-211.74-154.141C816.644,268.36,712.042,242.2,600,240.521z M599.924,329.769\n\t\t\tc156.119,0,282.675,120.994,282.675,270.251c0,149.256-126.556,270.25-282.675,270.25S317.249,749.275,317.249,600.02\n\t\t\tC317.249,450.763,443.805,329.769,599.924,329.769L599.924,329.769z\"/>\n</svg>\n";var kt=/*#__PURE__*/function(){function kt(){_classCallCheck(this,kt);}return _createClass(kt,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Ut=/*#__PURE__*/function(){function Ut(){_classCallCheck(this,Ut);}return _createClass(Ut,null,[{key:"changeVisibility",value:// prettier-ignore
127
+ function constructPropertyAccessors(e,t){var n;Object.defineProperty(this,t||e,{get:function get(){return n;},set:function set(o){n=o,t?this[e]=o:Xs.attemptRender(this);}});}},{key:"attributeChangedCallback",value:function attributeChangedCallback(e,t,n){if(t===n)return;var s=At._attributes_[e](n),r=At._attributeToProperty_[e];this[r]=s;}},{key:"onRender",value:function onRender(){}}],[{key:"observedAttributes",get:function get(){return Object.keys(At._attributes_)||[];}}]);}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));At._attributes_={},At._attributeToProperty_={};var qi=At;var Tl="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path d=\"\n\t\t\tM669.727,273.516c-22.891-2.476-46.15-3.895-69.727-4.248c-103.025,0.457-209.823,25.517-310.913,73.536\n\t\t\tc-75.058,37.122-148.173,89.529-211.67,154.174C46.232,529.978,6.431,577.76,0,628.74c0.76,44.162,48.153,98.67,77.417,131.764\n\t\t\tc59.543,62.106,130.754,113.013,211.67,154.174c2.75,1.335,5.51,2.654,8.276,3.955l-75.072,131.102l102.005,60.286l551.416-960.033\n\t\t\tl-98.186-60.008L669.727,273.516z M902.563,338.995l-74.927,129.857c34.47,44.782,54.932,100.006,54.932,159.888\n\t\t\tc0,149.257-126.522,270.264-282.642,270.264c-6.749,0-13.29-0.728-19.922-1.172l-49.585,85.84c22.868,2.449,45.99,4.233,69.58,4.541\n\t\t\tc103.123-0.463,209.861-25.812,310.84-73.535c75.058-37.122,148.246-89.529,211.743-154.174\n\t\t\tc31.186-32.999,70.985-80.782,77.417-131.764c-0.76-44.161-48.153-98.669-77.417-131.763\n\t\t\tc-59.543-62.106-130.827-113.013-211.743-154.175C908.108,341.478,905.312,340.287,902.563,338.995L902.563,338.995z\n\t\t\tM599.927,358.478c6.846,0,13.638,0.274,20.361,0.732l-58.081,100.561c-81.514,16.526-142.676,85.88-142.676,168.897\n\t\t\tc0,20.854,3.841,40.819,10.913,59.325c0.008,0.021-0.008,0.053,0,0.074l-58.228,100.854\n\t\t\tc-34.551-44.823-54.932-100.229-54.932-160.182C317.285,479.484,443.808,358.477,599.927,358.478L599.927,358.478z M768.896,570.513\n\t\t\tL638.013,797.271c81.076-16.837,141.797-85.875,141.797-168.603C779.81,608.194,775.724,588.729,768.896,570.513L768.896,570.513z\"\n\t\t\t/>\n</svg>\n",Rl="<?xml version=\"1.0\" standalone=\"no\"?>\n<svg version=\"1.1\"\n\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\"\n\txmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0.9em\" height=\"0.9em\"\n\tviewBox=\"0 0 1200 1200\" enable-background=\"new 0 0 1200 1200\">\n\t\t<path id=\"path6686\" inkscape:connector-curvature=\"0\" d=\"M779.843,599.925c0,95.331-80.664,172.612-180.169,172.612\n\t\t\tc-99.504,0-180.168-77.281-180.168-172.612c0-95.332,80.664-172.612,180.168-172.612\n\t\t\tC699.179,427.312,779.843,504.594,779.843,599.925z M600,240.521c-103.025,0.457-209.814,25.538-310.904,73.557\n\t\t\tc-75.058,37.122-148.206,89.496-211.702,154.141C46.208,501.218,6.431,549,0,599.981c0.76,44.161,48.13,98.669,77.394,131.763\n\t\t\tc59.543,62.106,130.786,113.018,211.702,154.179c94.271,45.751,198.616,72.092,310.904,73.557\n\t\t\tc103.123-0.464,209.888-25.834,310.866-73.557c75.058-37.122,148.243-89.534,211.74-154.179\n\t\t\tc31.185-32.999,70.962-80.782,77.394-131.763c-0.76-44.161-48.13-98.671-77.394-131.764\n\t\t\tc-59.543-62.106-130.824-112.979-211.74-154.141C816.644,268.36,712.042,242.2,600,240.521z M599.924,329.769\n\t\t\tc156.119,0,282.675,120.994,282.675,270.251c0,149.256-126.556,270.25-282.675,270.25S317.249,749.275,317.249,600.02\n\t\t\tC317.249,450.763,443.805,329.769,599.924,329.769L599.924,329.769z\"/>\n</svg>\n";var kt=/*#__PURE__*/function(){function kt(){_classCallCheck(this,kt);}return _createClass(kt,null,[{key:"createSVGElement",value:function createSVGElement(e){return new DOMParser().parseFromString(e,"image/svg+xml").documentElement;}}]);}();var Ut=/*#__PURE__*/function(){function Ut(){_classCallCheck(this,Ut);}return _createClass(Ut,null,[{key:"changeVisibility",value:// prettier-ignore
132
128
  function changeVisibility(e,t,n,s){s.target.id===Ut.VISIBLE_ICON_ID?(t[v].display="none",n[v].display="block",e[E]="password"):(t[v].display="block",n[v].display="none",e[E]=h);}},{key:"createIconElement",value:function createIconElement(e,t){var n=kt.createSVGElement(e);return n.id=t,n[m].add("visibility-icon"),n;}// prettier-ignore
133
- },{key:"create",value:function create(e){var t=A();t.id="visibility-icon-container";var n=Ut.createIconElement(Il,Ut.VISIBLE_ICON_ID);n[v].display="none",t.appendChild(n);var s=Ut.createIconElement(Rl,"not-visible-icon");return t.appendChild(s),t.onclick=Ut.changeVisibility.bind(this,e,n,s),t;}}]);}();Ut.VISIBLE_ICON_ID="visible-icon";var Vi=Ut;var Oe=/*#__PURE__*/function(){function Oe(){_classCallCheck(this,Oe);}return _createClass(Oe,null,[{key:"createCautionText",value:function createCautionText(){var e=A("a");return e[m].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 createHelpLink(e){var t=A("a");return t[m].add("insert-key-input-help-text"),t.href=e,t.innerText="Find more info here",t.target="_blank",t;}},{key:"createFailText",value:function createFailText(){var e=A();return e.id="insert-key-input-invalid-text",e[v].display="none",e;}},{key:"createHelpTextContainer",value:function createHelpTextContainer(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var n=A();n.id="insert-key-help-text-container";var s=A();s.id="insert-key-help-text-contents";var r=Oe.createFailText();if(s.appendChild(r),e){var o=Oe.createHelpLink(e);s.appendChild(o);}if(t===!0){var _o3=Oe.createCautionText();s.appendChild(_o3);}return n.appendChild(s),{helpTextContainerElement:n,failTextElement:r};}},{key:"onFail",value:function onFail(e,t,n,s){e[m].replace("insert-key-input-valid","insert-key-input-invalid"),n.innerText=s,n[v].display="block",t.innerText="Start",e[m].remove(It);}},{key:"onLoad",value:function onLoad(e,t){e[m].add(It),t.innerHTML='<div id="loading-key"></div>';}// prettier-ignore
129
+ },{key:"create",value:function create(e){var t=A();t.id="visibility-icon-container";var n=Ut.createIconElement(Rl,Ut.VISIBLE_ICON_ID);n[v].display="none",t.appendChild(n);var s=Ut.createIconElement(Tl,"not-visible-icon");return t.appendChild(s),t.onclick=Ut.changeVisibility.bind(this,e,n,s),t;}}]);}();Ut.VISIBLE_ICON_ID="visible-icon";var Gi=Ut;var Oe=/*#__PURE__*/function(){function Oe(){_classCallCheck(this,Oe);}return _createClass(Oe,null,[{key:"createCautionText",value:function createCautionText(){var e=A("a");return e[m].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 createHelpLink(e){var t=A("a");return t[m].add("insert-key-input-help-text"),t.href=e,t.innerText="Find more info here",t.target="_blank",t;}},{key:"createFailText",value:function createFailText(){var e=A();return e.id="insert-key-input-invalid-text",e[v].display="none",e;}},{key:"createHelpTextContainer",value:function createHelpTextContainer(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var n=A();n.id="insert-key-help-text-container";var s=A();s.id="insert-key-help-text-contents";var r=Oe.createFailText();if(s.appendChild(r),e){var o=Oe.createHelpLink(e);s.appendChild(o);}if(t===!0){var _o3=Oe.createCautionText();s.appendChild(_o3);}return n.appendChild(s),{helpTextContainerElement:n,failTextElement:r};}},{key:"onFail",value:function onFail(e,t,n,s){e[m].replace("insert-key-input-valid","insert-key-input-invalid"),n.innerText=s,n[v].display="block",t.innerText="Start",e[m].remove(It);}},{key:"onLoad",value:function onLoad(e,t){e[m].add(It),t.innerHTML='<div id="loading-key"></div>';}// prettier-ignore
134
130
  },{key:"verifyKey",value:function verifyKey(e,t,n){var s=e.value.trim();n.verifyKey(s,t);}// prettier-ignore
135
131
  },{key:"addVerificationEvents",value:function addVerificationEvents(e,t,n,s,r){var o={onSuccess:s,onFail:Oe.onFail.bind(this,e,t,n),onLoad:Oe.onLoad.bind(this,e,t)},a=Oe.verifyKey.bind(this,e,o,r);t.onclick=a,e.onkeydown=function(c){!e[m].contains(It)&&c.key===_e.ENTER&&a();};}},{key:"createStartButton",value:function createStartButton(){var e=A();return e.id="start-button",e.innerText="Start",e;}},{key:"onInputFocus",value:function onInputFocus(e){e.target[m].replace("insert-key-input-invalid","insert-key-input-valid");}},{key:"createInput",value:function createInput(e){var t=A();t.id="insert-key-input-container";var n=A("input");return n.id="insert-key-input",n.placeholder=e||"API Key",n[E]="password",n[m].add("insert-key-input-valid"),n.onfocus=Oe.onInputFocus,t.appendChild(n),t;}// prettier-ignore
136
- },{key:"createContents",value:function createContents(e,t){var d;var n=A();n.id="insert-key-contents";var s=Oe.createInput(t.insertKeyPlaceholderText),r=s.children[0],o=Vi.create(r);s.appendChild(o),n.appendChild(s);var a=Oe.createStartButton(),_Oe$createHelpTextCon=Oe.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),c=_Oe$createHelpTextCon.helpTextContainerElement,l=_Oe$createHelpTextCon.failTextElement;return n.appendChild(a),n.appendChild(c),Oe.addVerificationEvents(r,a,l,e,t),n;}},{key:"createElements",value:function createElements(e,t){var n=A();n.id="insert-key-view";var s=Oe.createContents(e,t);return n.appendChild(s),n;}},{key:"render",value:function render(e,t,n){var s=Oe.createElements(t,n);e.replaceChildren(s);}}]);}();var Ve=/*#__PURE__*/function(){function Ve(){_classCallCheck(this,Ve);}return _createClass(Ve,null,[{key:"enableButtons",value:function enableButtons(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;window.webLLM?(e&&(e[j]=!1),t&&(t[j]=!1)):n<Rs.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return Ve.enableButtons(e,t,n+1);},250);}// prettier-ignore
132
+ },{key:"createContents",value:function createContents(e,t){var d;var n=A();n.id="insert-key-contents";var s=Oe.createInput(t.insertKeyPlaceholderText),r=s.children[0],o=Gi.create(r);s.appendChild(o),n.appendChild(s);var a=Oe.createStartButton(),_Oe$createHelpTextCon=Oe.createHelpTextContainer(t.keyHelpUrl,(d=t.deepChat._insertKeyViewStyles)==null?void 0:d.displayCautionText),c=_Oe$createHelpTextCon.helpTextContainerElement,l=_Oe$createHelpTextCon.failTextElement;return n.appendChild(a),n.appendChild(c),Oe.addVerificationEvents(r,a,l,e,t),n;}},{key:"createElements",value:function createElements(e,t){var n=A();n.id="insert-key-view";var s=Oe.createContents(e,t);return n.appendChild(s),n;}},{key:"render",value:function render(e,t,n){var s=Oe.createElements(t,n);e.replaceChildren(s);}}]);}();var Ve=/*#__PURE__*/function(){function Ve(){_classCallCheck(this,Ve);}return _createClass(Ve,null,[{key:"enableButtons",value:function enableButtons(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;window.webLLM?(e&&(e[j]=!1),t&&(t[j]=!1)):n<Ts.MODULE_SEARCH_LIMIT_S*4&&setTimeout(function(){return Ve.enableButtons(e,t,n+1);},250);}// prettier-ignore
137
133
  },{key:"setUpInitial",value:function setUpInitial(e,t,n,s){var r=(t==null?void 0:t.downloadClass)||Ve.DOWNLOAD_BUTTON_CLASS,o=(t==null?void 0:t.uploadClass)||Ve.UPLOAD_BUTTON_CLASS,a=(t==null?void 0:t.fileInputClass)||Ve.FILE_INPUT_CLASS;return setTimeout(function(){var c=n==null?void 0:n.getElementsByClassName(r)[0],l=n==null?void 0:n.getElementsByClassName(a)[0],d=n==null?void 0:n.getElementsByClassName(o)[0];c&&(c.onclick=function(){return e();}),l&&(l.onchange=function(){l[b]&&l[b].length>0&&e(l[b]);}),d&&(d.onclick=function(){return l[J]();}),(c||d)&&Ve.enableButtons(c,d);}),(t==null?void 0:t.initialHtml)||"<div>\n Download or upload a web model that will run entirely on your browser: <br/> \n <button disabled class=\"".concat(r," deep-chat-button deep-chat-web-model-button\">Download</button>\n ").concat(s?"":"<input type=\"file\" class=\"".concat(a,"\" hidden multiple />\n <button disabled class=\"").concat(o," deep-chat-button deep-chat-web-model-button\">Upload</button>"),"\n </div>");}},{key:"exportFile",value:function exportFile(e){var t=A("a"),n=4;var _loop2=function _loop2(s){setTimeout(function(){var r=s*n;for(var o=r;o<Math.min(r+n,e.length);o+=1){var a=URL.createObjectURL(e[o]);t.href=a,t.download=e[o].name,document.body.appendChild(t),t[J](),URL.revokeObjectURL(a);}},500*s);};for(var s=0;s<e.length/n;s+=1){_loop2(s);}}// prettier-ignore
138
- },{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,n,s){var r=(t==null?void 0:t.exportFilesClass)||Ve.EXPORT_BUTTON_CLASS;return setTimeout(function(){var o=n==null?void 0:n.getElementsByClassName(r)[0];o&&(o.onclick=function(){return Ve.exportFile(e);});}),(t==null?void 0:t.afterLoadHtml)||"<div>\n Model loaded successfully and has been cached for future requests.\n ".concat(s?"":"<br/> <button style=\"margin-top: 5px\" class=\"".concat(r," deep-chat-button\">Export</button>"),"\n </div>");}}]);}();Ve.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",Ve.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",Ve.FILE_INPUT_CLASS="deep-chat-file-input",Ve.EXPORT_BUTTON_CLASS="deep-chat-export-button";var Js=Ve;var no={model_list:[// Llama-2
134
+ },{key:"setUpAfterLoad",value:function setUpAfterLoad(e,t,n,s){var r=(t==null?void 0:t.exportFilesClass)||Ve.EXPORT_BUTTON_CLASS;return setTimeout(function(){var o=n==null?void 0:n.getElementsByClassName(r)[0];o&&(o.onclick=function(){return Ve.exportFile(e);});}),(t==null?void 0:t.afterLoadHtml)||"<div>\n Model loaded successfully and has been cached for future requests.\n ".concat(s?"":"<br/> <button style=\"margin-top: 5px\" class=\"".concat(r," deep-chat-button\">Export</button>"),"\n </div>");}}]);}();Ve.DOWNLOAD_BUTTON_CLASS="deep-chat-download-button",Ve.UPLOAD_BUTTON_CLASS="deep-chat-upload-button",Ve.FILE_INPUT_CLASS="deep-chat-file-input",Ve.EXPORT_BUTTON_CLASS="deep-chat-export-button";var Zs=Ve;var to={model_list:[// Llama-2
139
135
  {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"]},// RedPajama
140
136
  {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},// Mistral variants
141
137
  {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"]},// TinyLlama
142
- {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},Y=/*#__PURE__*/function(_hn2){function Y(e){var _this18;_classCallCheck(this,Y);var t,n;_this18=_callSuper(this,Y,[e]),_this18._isModelLoaded=!1,_this18._isModelLoading=!1,_this18._loadOnFirstMessage=!1,_this18._webModel={},_this18.permittedErrorPrefixes=[Y.MULTIPLE_MODELS_ERROR,Y.WEB_LLM_NOT_FOUND_ERROR,Y.GENERIC_ERROR],_this18._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this18._webModel=e.webModel),(t=_this18._webModel.load)!=null&&t.clearCache&&Y.clearAllCache(),_this18.findModelInWindow(e),_this18.canSendMessage=_this18.canSubmit.bind(_assertThisInitialized(_this18)),_this18._chatEl=(n=e.shadowRoot)==null?void 0:n.children[0],e.history&&Y.setUpHistory(_this18._conversationHistory,e.history);return _this18;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
143
- _inherits(Y,_hn2);return _createClass(Y,[{key:"setUpMessages",value:function setUpMessages(e){var _this19=this;this._messages=e,this._removeIntro=function(){e.removeIntroductoryMessage(),_this19._removeIntro=void 0;};}},{key:"findModelInWindow",value:function findModelInWindow(e){var _this20=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var n;window.webLLM?this.configureInit(this.shouldAddIntroMessage(e.introMessage)):t>Y.MODULE_SEARCH_LIMIT_S?((n=this._messages)==null||n.addNewErrorMessage(ae,Y.WEB_LLM_NOT_FOUND_ERROR),console[f]("The deep-chat-web-llm module has not been attached to the window object. Please see the following guide:"),console[f]("https://deepchat.dev/examples/externalModules")):setTimeout(function(){return _this20.findModelInWindow(e,t+1);},1e3);}},{key:"shouldAddIntroMessage",value:function shouldAddIntroMessage(e){var t;return!e&&this._webModel&&((t=this._webModel.introMessage)==null?void 0:t.displayed)!==!1;}},{key:"scrollToTop",value:function scrollToTop(e){var _this21=this;var t;((t=this._webModel.introMessage)==null?void 0:t.autoScroll)!==!1&&setTimeout(function(){var n,s;(n=_this21._messages)!=null&&n.elementRef&&z.scrollToTop((s=_this21._messages)==null?void 0:s.elementRef);},e);}// prettier-ignore
144
- },{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Js.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),_defineProperty(_defineProperty(_defineProperty({},x,ne),"html",t),"sendUpdate",!1);}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e){var t;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:t=this._webModel.load;if(!t){_context37.n=2;break;}if(!t.onInit){_context37.n=1;break;}this.init();return _context37.a(2);case 1:if(!t.onMessage){_context37.n=2;break;}this._loadOnFirstMessage=!0;return _context37.a(2);case 2:e||this.init();case 3:return _context37.a(2);}},_callee37,this);}));function configureInit(_x83){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(e){var n,t,_t16;return _regenerator().w(function(_context38){while(1)switch(_context38.n){case 0:(n=this._messages)==null||n.removeError();t=this.attemptToCreateChat();_t16=t;if(!_t16){_context38.n=1;break;}_context38.n=1;return this.loadModel(t,e);case 1:return _context38.a(2);}},_callee38,this);}));function init(_x84){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var t;if(Y.chat){(t=this._messages)==null||t.addNewErrorMessage(ae,Y.MULTIPLE_MODELS_ERROR),console[f](Y.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return no.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var n;var e=Y.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=C(no);if(this._webModel.urls){var s=t.model_list.find(function(r){return r.local_id=e;});s&&(this._webModel.urls.model&&(s.model_url=this._webModel.urls.model),this._webModel.urls.wasm&&(s.model_lib_url=this._webModel.urls.wasm));}return(n=this._webModel.load)!=null&&n.skipCache&&(t.use_cache=!1),{model:e,appConfig:t};}// prettier-ignore
145
- },{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(e,t){var _this22=this;var o,a,c,l,d,p,u,n,s,r,_this$getConfig,g,y,_,_g,_t17;return _regenerator().w(function(_context39){while(1)switch(_context39.p=_context39.n){case 0:this.scrollToTop(),Y.chat=e,this._isModelLoading=!0;n=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;s=function s(g){var y;(y=_this22._messages)==null||y.addNewMessage({html:"<div>".concat(g[h],"</div>"),overwrite:!0,sendUpdate:!1}),n&&(setTimeout(function(){return z.scrollToBottom(_this22._messages);}),n=!1);};Y.chat.setInitProgressCallback(s);_context39.p=1;_this$getConfig=this.getConfig(),g=_this$getConfig.model,y=_this$getConfig.appConfig,_={};this._webModel.instruction&&(_.conv_config=_defineProperty({},Mn,this._webModel.instruction));this._conversationHistory.length>0&&(_.conversation_history=this._conversationHistory);_context39.n=2;return Y.chat.reload(g,_,y,t);case 2:r=_context39.v;_context39.n=4;break;case 3:_context39.p=3;_t17=_context39.v;return _context39.a(2,this.unloadChat(_t17));case 4:if((c=(a=this.deepChat)._validationHandler)==null||c.call(a),(l=this._webModel.introMessage)!=null&&l.removeAfterLoad)this._webModel.introMessage.displayed===!1?(p=this._messages)==null||p.removeLastMessage():(u=this._removeIntro)==null||u.call(this);else{_g=Js.setUpAfterLoad(r,this._webModel.introMessage,this._chatEl,!!this._webModel.worker);(d=this._messages)==null||d.addNewMessage({html:_g,overwrite:!0,sendUpdate:!1});}this._isModelLoaded=!0,this._isModelLoading=!1;case 5:return _context39.a(2);}},_callee39,this,[[1,3]]);}));function loadModel(_x85,_x86){return _loadModel.apply(this,arguments);}return loadModel;}()},{key:"unloadChat",value:function(){var _unloadChat=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(e){var t,_t18;return _regenerator().w(function(_context40){while(1)switch(_context40.n){case 0:(t=this._messages)==null||t.addNewErrorMessage(ae,Y.GENERIC_ERROR);console[f](e);this._isModelLoaded=!1;this._isModelLoading=!1;_t18=Y.chat;if(!_t18){_context40.n=2;break;}_context40.n=1;return Y.chat.unload();case 1:Y.chat=void 0;case 2:return _context40.a(2);}},_callee40,this);}));function unloadChat(_x87){return _unloadChat.apply(this,arguments);}return unloadChat;}()},{key:"immediateResp",value:function(){var _immediateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(e,t,n){var s,r,_t19,_t20,_t21;return _regenerator().w(function(_context41){while(1)switch(_context41.n){case 0:_t19=_defineProperty;_t20={};_t21=h;_context41.n=1;return n.generate(t,void 0,0);case 1:s=_t19(_t20,_t21,_context41.v);_context41.n=2;return Y.processResponse(this.deepChat,e,s);case 2:r=_context41.v;r&&r.forEach(function(o){return e.addNewMessage(o);}),this.completionsHandlers.onFinish();case 3:return _context41.a(2);}},_callee41,this);}));function immediateResp(_x88,_x89,_x90){return _immediateResp.apply(this,arguments);}return immediateResp;}()},{key:"streamResp",value:function(){var _streamResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43(e,t,n){var _this23=this;var s;return _regenerator().w(function(_context43){while(1)switch(_context43.n){case 0:this.streamHandlers.onAbort=function(){n.interruptGenerate();},this.streamHandlers.onOpen();s=new ht(e);_context43.n=1;return n.generate(t,/*#__PURE__*/function(){var _ref28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(r,o){var a;return _regenerator().w(function(_context42){while(1)switch(_context42.n){case 0:_context42.n=1;return Y.processResponse(_this23.deepChat,e,_defineProperty({},h,o));case 1:a=_context42.v;a&&s.upsertStreamedMessage(_defineProperty(_defineProperty({},h,a[0][h]),"overwrite",!0));case 2:return _context42.a(2);}},_callee42);}));return function(_x94,_x95){return _ref28.apply(this,arguments);};}());case 1:s.finaliseStreamedMessage();this.streamHandlers.onClose();case 2:return _context43.a(2);}},_callee43,this);}));function streamResp(_x91,_x92,_x93){return _streamResp.apply(this,arguments);}return streamResp;}()},{key:"generateRespByType",value:function(){var _generateRespByType=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44(e,t,n,s){var r,_t22;return _regenerator().w(function(_context44){while(1)switch(_context44.p=_context44.n){case 0:_context44.p=0;if(!n){_context44.n=2;break;}_context44.n=1;return this.streamResp(e,t,s);case 1:_context44.n=3;break;case 2:_context44.n=3;return this.immediateResp(e,t,s);case 3:_context44.n=5;break;case 4:_context44.p=4;_t22=_context44.v;(r=this._messages)==null||r.addNewErrorMessage(ae),console.log(_t22);case 5:return _context44.a(2);}},_callee44,this,[[0,4]]);}));function generateRespByType(_x96,_x97,_x98,_x99){return _generateRespByType.apply(this,arguments);}return generateRespByType;}()},{key:"generateResp",value:function(){var _generateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45(e,t,n){var s,_yield$D$processReque5,r,o,a,c,l;return _regenerator().w(function(_context45){while(1)switch(_context45.n){case 0:s=t[t.length-1][h];_context45.n=1;return D.processRequestInterceptor(this.deepChat,{body:_defineProperty({},h,s)});case 1:_yield$D$processReque5=_context45.v;r=_yield$D$processReque5.body;o=_yield$D$processReque5.error;a=!!this.stream;try{if(o)D.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!r||!r[h]){c=wa({body:r},!1);console[f](c);l=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;D.onInterceptorError(e,c,l);}else this.generateRespByType(e,r[h],!!this.stream,n);}catch(c){this.unloadChat(c);}case 2:return _context45.a(2);}},_callee45,this);}));function generateResp(_x100,_x101,_x102){return _generateResp.apply(this,arguments);}return generateResp;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46(e,t){var n,s;return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:if(this._isModelLoaded){_context46.n=3;break;}if(!this._loadOnFirstMessage){_context46.n=2;break;}_context46.n=1;return this.init();case 1:_context46.n=3;break;case 2:return _context46.a(2);case 3:!Y.chat||this._isModelLoading||((n=this._webModel.introMessage)!=null&&n.removeAfterMessage&&((s=this._removeIntro)==null||s.call(this)),e.addLoadingMessage(),this.generateResp(e,t,Y.chat));case 4:return _context46.a(2);}},_callee46,this);}));function callServiceAPI(_x103,_x104){return _callServiceAPI2.apply(this,arguments);}return callServiceAPI;}()},{key:"canSubmit",value:function canSubmit(e){return!(e!=null&&e.trim())||this._isModelLoading?!1:this._loadOnFirstMessage?!0:!!this._isModelLoaded;}},{key:"isWebModel",value:function isWebModel(){return!0;}}],[{key:"setUpHistory",value:function setUpHistory(e,t){t.forEach(function(n,s){if(n[x]===F&&n[h]){var r=t[s+1];r!=null&&r[h]&&r[x]!==F&&e.push([n[h],r[h]]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e,t,n){var a,c,s,r,o,d,_t23;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:_context47.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,n);case 1:_t23=_context47.v;if(_t23){_context47.n=2;break;}_t23=n;case 2:s=_t23;if(!((c=e.connect)!=null&&c.stream&&Array.isArray(s)&&s.length>1)){_context47.n=3;break;}console[f](Fo);return _context47.a(2);case 3:r=Array.isArray(s)?s:[s],o=r.find(function(l){return _typeof(l[f])===Ee;});if(!o){_context47.n=4;break;}D.displayError(t,new Error(o[f]));return _context47.a(2);case 4:if(!r.find(function(d){return!d||!d[h];})){_context47.n=5;break;}d=Ca(n,!!e.responseInterceptor,s);D.displayError(t,new Error(d));return _context47.a(2);case 5:return _context47.a(2,r);}},_callee47);}));function processResponse(_x105,_x106,_x107){return _processResponse.apply(this,arguments);}return processResponse;}()},{key:"clearAllCache",value:function clearAllCache(){Y.clearCache("webllm/model"),Y.clearCache("webllm/wasm");}},{key:"clearCache",value:function clearCache(e){caches.open(e).then(function(t){t.keys().then(function(n){n.forEach(function(s){t["delete"](s);});});});}}]);}(hn);Y.GENERIC_ERROR="Error, please check the [troubleshooting](".concat(Z,"webModel#troubleshooting) section of documentation for help."),Y.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",Y.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",Y.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",Y.MODULE_SEARCH_LIMIT_S=5;var Rs=Y;var be=function be(i,e,t,n){return{url:i,method:e,handleVerificationResult:t,augmentUrl:n};},Ml=function Ml(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},kl=function kl(i,e,t,n){var s=i;Array.isArray(s[f])&&s[f][0]==="Error in `parameters`: field required"?t(e):n(pe);},Pl=function Pl(){return be("https://api-inference.huggingface.co/models/gpt2",ye,kl);},_s=/*#__PURE__*/function(_k){// prettier-ignore
146
- function _s(e,t,n,s,r,o){var _this24;_classCallCheck(this,_s);_this24=_callSuper(this,_s,[e,Pl(),Ml,r,o]),_this24.insertKeyPlaceholderText="Hugging Face Token",_this24.keyHelpUrl="https://huggingface.co/settings/tokens",_this24.permittedErrorPrefixes=[cr],_this24.url="".concat(_s.URL_PREFIX).concat(n),_this24.textInputPlaceholderText=t,_typeof(s)=="object"&&(s.model&&(_this24.url="".concat(_s.URL_PREFIX).concat(s.model)),s.options&&(_this24.rawBody.options=s.options),s.parameters&&(_this24.rawBody.parameters=s.parameters));return _this24;}_inherits(_s,_k);return _createClass(_s,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var _s$options;var s=C(e),r=t[t.length-1][h];if(r)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:r},s);}},{key:"callServiceAPI",value:function(){var _callServiceAPI3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48(e,t,n){var s;return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:if(this.connectSettings){_context48.n=1;break;}throw new Error(He);case 1:s=this.preprocessBody(this.rawBody,t,n);ge.request(this,s,e);case 2:return _context48.a(2);}},_callee48,this);}));function callServiceAPI(_x108,_x109,_x110){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(k);_s.URL_PREFIX="https://api-inference.huggingface.co/models/";var Pt=_s;var Os=/*#__PURE__*/function(_Pt){// prettier-ignore
147
- function Os(e,t,n,s,r,o){var _this25;_classCallCheck(this,Os);_this25=_callSuper(this,Os,[e,t,n,s,r,o]),_this25.isTextInputDisabled=!0,_this25.canSendMessage=Os.canSendFile;return _this25;}_inherits(Os,_Pt);return _createClass(Os,[{key:"preprocessBody",value:function preprocessBody(e,t,n){return n[0];}// prettier-ignore
148
- },{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49(e,t,n){return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(this.connectSettings){_context49.n=1;break;}throw new Error(He);case 1:if(n!=null&&n[0]){_context49.n=2;break;}throw new Error(_i);case 2:ge.poll(this,n[0],e,!1);case 3:return _context49.a(2);}},_callee49,this);}));function callServiceAPI(_x111,_x112,_x113){return _callServiceAPI4.apply(this,arguments);}return callServiceAPI;}()}],[{key:"canSendFile",value:function canSendFile(e,t){return!!(t!=null&&t[0]);}}]);}(Pt);var Ll=/*#__PURE__*/function(_Os){// prettier-ignore
149
- function Ll(e){_classCallCheck(this,Ll);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.audioClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ll,[e,"Attach an audio ".concat(se),"ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,n,{audio:{}}]);}_inherits(Ll,_Os);return _createClass(Ll,[{key:"extractPollResultData",value:function(){var _extractPollResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(e){var t;return _regenerator().w(function(_context50){while(1)switch(_context50.n){case 0:if(!e.estimated_time){_context50.n=1;break;}return _context50.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[f]){_context50.n=2;break;}throw e[f];case 2:return _context50.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee50);}));function extractPollResultData(_x114){return _extractPollResultData.apply(this,arguments);}return extractPollResultData;}()}]);}(Os);var Ol=/*#__PURE__*/function(_Os2){function Ol(e){_classCallCheck(this,Ol);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.imageClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ol,[e,"Attach an image ".concat(se),"google/vit-base-patch16-224",t,n,{images:{}}]);}_inherits(Ol,_Os2);return _createClass(Ol,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e){var t;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(!e.estimated_time){_context51.n=1;break;}return _context51.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[f]){_context51.n=2;break;}throw e[f];case 2:return _context51.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee51);}));function extractPollResultData(_x115){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(Os);var xi=function xi(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Nl=function Nl(i,e,t,n){i.message?n(pe):t(e);},Ai=function Ai(){return be("https://api.stability.ai/v1/engines/list",ue,Nl);},On="data:image/png;base64,";var wi=/*#__PURE__*/function(_k2){// prettier-ignore
150
- function wi(e,t,n,s,r){var _this26;_classCallCheck(this,wi);_this26=_callSuper(this,wi,[e,t,n,s,r]),_this26.insertKeyPlaceholderText=_this26.genereteAPIKeyName("Stability AI"),_this26.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this26.permittedErrorPrefixes=[Ls,"invalid_"];return _this26;}_inherits(wi,_k2);return _createClass(wi);}(k);var Qs=/*#__PURE__*/function(_wi){function Qs(e){var _this27;_classCallCheck(this,Qs);var o;var t=C(e.directConnection),n=t==null?void 0:t.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this27=_callSuper(this,Qs,[e,Ai(),xi,n,s]),_this27.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",_this27.textInputPlaceholderText="Describe image changes";var r=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageUpscale;_typeof(r)=="object"&&(r.engine_id&&(_this27.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/image-to-image/upscale")),Qs.cleanConfig(r),Object.assign(_this27.rawBody,r)),_this27.canSendMessage=Qs.canSendFileMessage;return _this27;}_inherits(Qs,_wi);return _createClass(Qs,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(W,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}// prettier-ignore
151
- },{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e,t,n){var s;return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(this.connectSettings){_context52.n=1;break;}throw new Error(He);case 1:if(n){_context52.n=2;break;}throw new Error(ar);case 2:s=this.createFormDataBody(this.rawBody,n[0]);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,s,e),!1);case 3:return _context52.a(2);}},_callee52,this);}));function callServiceAPI(_x116,_x117,_x118){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e){var t;return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(!e.message){_context53.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(On).concat(n.base64)),E,W);});return _context53.a(2,_defineProperty({},b,t));}},_callee53);}));function extractResultData(_x119){return _extractResultData2.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id;}},{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}}]);}(wi);var ei=/*#__PURE__*/function(_wi2){function ei(e){var _this28;_classCallCheck(this,ei);var o;var t=C(e.directConnection),n=t==null?void 0:t.stabilityAI,s=_defineProperty({},ee,_defineProperty({},b,{acceptedFormats:".png",maxNumberOfFiles:2}));_this28=_callSuper(this,ei,[e,Ai(),xi,n,s]),_this28.url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",_this28._maskSource="MASK_IMAGE_WHITE",_this28.textInputPlaceholderText="Describe image changes";var r=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageMasking;_typeof(r)=="object"&&(r.engine_id&&(_this28.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/image-to-image/masking")),r.weight!==void 0&&r.weight!==null&&(_this28._imageWeight=r.weight),r.mask_source!==void 0&&r.mask_source!==null&&(_this28._maskSource=r.mask_source),ei.cleanConfig(r),Object.assign(_this28.rawBody,r)),_this28.canSendMessage=ei.canSendFileTextMessage;return _this28;}_inherits(ei,_wi2);return _createClass(ei,[{key:"createFormDataBody",value:function createFormDataBody(e,t,n,s){var r=new FormData();return r.append("init_image",t),r.append("mask_source",String(this._maskSource)),r.append("mask_image",n),s&&s!==""&&r.append("text_prompts[0][text]",s),this._imageWeight!==void 0&&this._imageWeight!==null&&r.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(o){r.append(o,String(e[o]));}),r.get("weight")===void 0&&r.append("weight",String(1)),r;}// prettier-ignore
152
- },{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54(e,t,n){var o,a,s,r;return _regenerator().w(function(_context54){while(1)switch(_context54.n){case 0:if(this.connectSettings){_context54.n=1;break;}throw new Error(He);case 1:if(!(!n||!n[0]||!n[1])){_context54.n=2;break;}throw new Error(ar);case 2:s=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim(),r=this.createFormDataBody(this.rawBody,n[0],n[1],s);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,r,e),!1);case 3:return _context54.a(2);}},_callee54,this);}));function callServiceAPI(_x120,_x121,_x122){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(e){var t;return _regenerator().w(function(_context55){while(1)switch(_context55.n){case 0:if(!e.message){_context55.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(On).concat(n.base64)),E,W);});return _context55.a(2,_defineProperty({},b,t));}},_callee55);}));function extractResultData(_x123){return _extractResultData3.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(wi);var Bl=/*#__PURE__*/function(_Os3){function Bl(e){_classCallCheck(this,Bl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.audioSpeechRecognition,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Bl,[e,"Attach an audio ".concat(se),"facebook/wav2vec2-large-960h-lv60-self",t,n,{audio:{}}]);}_inherits(Bl,_Os3);return _createClass(Bl,[{key:"extractPollResultData",value:function(){var _extractPollResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56(e){return _regenerator().w(function(_context56){while(1)switch(_context56.n){case 0:if(!e.estimated_time){_context56.n=1;break;}return _context56.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[f]){_context56.n=2;break;}throw e[f];case 2:return _context56.a(2,_defineProperty({},h,e[h]||""));}},_callee56);}));function extractPollResultData(_x124){return _extractPollResultData3.apply(this,arguments);}return extractPollResultData;}()}]);}(Os);var Dl=/*#__PURE__*/function(_Pt2){function Dl(e){_classCallCheck(this,Dl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.textGeneration,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Dl,[e,"Once upon a time","gpt2",t,n]);}_inherits(Dl,_Pt2);return _createClass(Dl,[{key:"extractResultData",value:function(){var _extractResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57(e){var t;return _regenerator().w(function(_context57){while(1)switch(_context57.n){case 0:if(!e[f]){_context57.n=1;break;}throw e[f];case 1:return _context57.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.generated_text)||""));}},_callee57);}));function extractResultData(_x125){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var Fl=/*#__PURE__*/function(_Pt3){function Fl(e){var _this29;_classCallCheck(this,Fl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.questionAnswer,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this29=_callSuper(this,Fl,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,n]),_this29.permittedErrorPrefixes=[cr,"Error in"],_this29._context=t.context;return _this29;}_inherits(Fl,_Pt3);return _createClass(Fl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return{inputs:{question:n,context:this._context,options:{wait_for_model:!0}}};}},{key:"extractResultData",value:function(){var _extractResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58(e){return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(!e[f]){_context58.n=1;break;}throw e[f];case 1:return _context58.a(2,_defineProperty({},h,e.answer||""));}},_callee58);}));function extractResultData(_x126){return _extractResultData5.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var Ul=/*#__PURE__*/function(_Pt4){function Ul(e){_classCallCheck(this,Ul);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.summarization,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ul,[e,"Insert text to summarize","facebook/bart-large-cnn",t,n]);}_inherits(Ul,_Pt4);return _createClass(Ul,[{key:"extractResultData",value:function(){var _extractResultData6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){var t;return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e[f]){_context59.n=1;break;}throw e[f];case 1:return _context59.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.summary_text)||""));}},_callee59);}));function extractResultData(_x127){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var Hl=/*#__PURE__*/function(_Pt5){function Hl(e){var _this30$maxMessages;var _this30;_classCallCheck(this,Hl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.conversation,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this30=_callSuper(this,Hl,[e,"Ask me anything!","facebook/blenderbot-400M-distill",t,n]),(_this30$maxMessages=_this30.maxMessages)!==null&&_this30$maxMessages!==void 0?_this30$maxMessages:_this30.maxMessages=-1;return _this30;}// prettier-ignore
153
- _inherits(Hl,_Pt5);return _createClass(Hl,[{key:"processMessagesI",value:function processMessagesI(e){var t=e.filter(function(a){return a[h];}),n=t[t.length-1][h],s=t.slice(0,t.length-1);if(!n)return;var r=s.filter(function(a){return a[x]===F;}).map(function(a){return a[h];}),o=s.filter(function(a){return a[x]===ne;}).map(function(a){return a[h];});return{past_user_inputs:r,generated_responses:o,mostRecentMessageText:n};}},{key:"preprocessBody",value:function preprocessBody(e,t){var _n$options;var n=C(e),s=this.processMessagesI(t);if(s)return(_n$options=n.options)!==null&&_n$options!==void 0?_n$options:n.options={},n.options.wait_for_model=!0,_objectSpread({inputs:_defineProperty({past_user_inputs:s.past_user_inputs,generated_responses:s.generated_responses},h,s.mostRecentMessageText)},n);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(!e[f]){_context60.n=1;break;}throw e[f];case 1:return _context60.a(2,_defineProperty({},h,e.generated_text||""));}},_callee60);}));function extractResultData(_x128){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var ti=/*#__PURE__*/function(_wi3){function ti(e){var _this31;_classCallCheck(this,ti);var o;var t=C(e.directConnection),n=t.stabilityAI,s=_defineProperty({},ee,_defineProperty({},b,{acceptedFormats:".png",maxNumberOfFiles:1}));_this31=_callSuper(this,ti,[e,Ai(),xi,n,s]),_this31.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this31.textInputPlaceholderText="Describe image changes";var r=(o=t.stabilityAI)==null?void 0:o.imageToImage;_typeof(r)=="object"&&(r.engine_id&&(_this31.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/text-to-image")),r.weight!==void 0&&r.weight!==null&&(_this31._imageWeight=r.weight),ti.cleanConfig(r),Object.assign(_this31.rawBody,r)),_this31.canSendMessage=ti.canSendFileTextMessage;return _this31;}_inherits(ti,_wi3);return _createClass(ti,[{key:"createFormDataBody",value:function createFormDataBody(e,t,n){var s=new FormData();return s.append("init_image",t),n&&n!==""&&s.append("text_prompts[0][text]",n),this._imageWeight!==void 0&&this._imageWeight!==null&&s.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s.get("weight")===void 0&&s.append("weight",String(1)),s;}// prettier-ignore
154
- },{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e,t,n){var o,a,s,r;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(this.connectSettings){_context61.n=1;break;}throw new Error(He);case 1:if(n){_context61.n=2;break;}throw new Error(ar);case 2:s=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim(),r=this.createFormDataBody(this.rawBody,n[0],s);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,r,e),!1);case 3:return _context61.a(2);}},_callee61,this);}));function callServiceAPI(_x129,_x130,_x131){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e){var t;return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(!e.message){_context62.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(On).concat(n.base64)),E,W);});return _context62.a(2,_defineProperty({},b,t));}},_callee62);}));function extractResultData(_x132){return _extractResultData8.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(wi);var jl=/*#__PURE__*/function(_Pt6){function jl(e){_classCallCheck(this,jl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.translation,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,jl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(jl,_Pt6);return _createClass(jl,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e){var t;return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:if(!e[f]){_context63.n=1;break;}throw e[f];case 1:return _context63.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.translation_text)||""));}},_callee63);}));function extractResultData(_x133){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var ni=/*#__PURE__*/function(_wi4){function ni(e){var _this32;_classCallCheck(this,ni);var r;var t=C(e.directConnection),n=t.stabilityAI;_this32=_callSuper(this,ni,[e,Ai(),xi,n]),_this32.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this32.textInputPlaceholderText="Describe an image";var s=(r=t.stabilityAI)==null?void 0:r.textToImage;_typeof(s)=="object"&&(s.engine_id&&(_this32.url="https://api.stability.ai/v1/generation/".concat(s.engine_id,"/text-to-image")),s.weight!==void 0&&s.weight!==null&&(_this32._imageWeight=s.weight),ni.cleanConfig(s),Object.assign(_this32.rawBody,s)),_this32.canSendMessage=ni.canSendTextMessage;return _this32;}_inherits(ni,_wi4);return _createClass(ni,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=C(e),r=_defineProperty({},h,n);return this._imageWeight&&(r.weight=this._imageWeight),s.text_prompts=[r],s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e,t){return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context64.a(2);}},_callee64,this);}));function callServiceAPI(_x134,_x135){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){var t;return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:if(!e.message){_context65.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(On).concat(n.base64)),E,W);});return _context65.a(2,_defineProperty({},b,t));}},_callee65);}));function extractResultData(_x136){return _extractResultData0.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendTextMessage",value:function canSendTextMessage(e){return!!(e&&e.trim()!=="");}}]);}(wi);var $l=/*#__PURE__*/function(_Pt7){function $l(e){var _this33;_classCallCheck(this,$l);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.fillMask,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this33=_callSuper(this,$l,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this33.permittedErrorPrefixes=[cr,"No mask_token"];return _this33;}_inherits($l,_Pt7);return _createClass($l,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e){var t;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(!e[f]){_context66.n=1;break;}throw e[f];case 1:return _context66.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.sequence)||""));}},_callee66);}));function extractResultData(_x137){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var fr=function fr(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},ql=function ql(i,e,t,n){var s=i;s[f]?s[f].message===Ei?n(pe):n(Ue):t(e);},mr=function mr(){return be("https://open.bigmodel.cn/api/paas/v4/models",ue,ql);};var Gl=/*#__PURE__*/function(_k3){function Gl(e){var _o$model,_a$voice;var _this34;_classCallCheck(this,Gl);var r,o,a;var t=C(e.directConnection),n=t.bigModel;_this34=_callSuper(this,Gl,[e,mr(),fr,n]),_this34.insertKeyPlaceholderText=_this34.genereteAPIKeyName("BigModel"),_this34.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this34.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this34.permittedErrorPrefixes=[he,Te];var s=(r=t.bigModel)==null?void 0:r.textToSpeech;_typeof(s)===U&&(_this34.cleanConfig(s),Object.assign(_this34.rawBody,s)),(_o$model=(o=_this34.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this34.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this34;}_inherits(Gl,_k3);return _createClass(Gl,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e,t){return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:return _context67.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee67,this);}));function callServiceAPI(_x138,_x139){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e){var t,n;return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:t=new Blob([e],_defineProperty({},E,"audio/mpeg")),n=URL.createObjectURL(t);return _context68.a(2,_defineProperty({},b,[_defineProperty(_defineProperty({},T,n),E,$)]));}},_callee68);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(k);var gr=function gr(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},zl=function zl(i,e,t,n){var s=i;s[f]?s[f].message===Ei?n(pe):n(Ue):t(e);},br=function br(){return be("https://api.together.xyz/v1/models",ue,zl);};var Vl=/*#__PURE__*/function(_k4){function Vl(e){var _o$model2,_a$voice2;var _this35;_classCallCheck(this,Vl);var r,o,a;var t=C(e.directConnection),n=t.together;_this35=_callSuper(this,Vl,[e,br(),gr,n]),_this35.insertKeyPlaceholderText=_this35.genereteAPIKeyName("Together AI"),_this35.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this35.url="https://api.together.xyz/v1/audio/speech",_this35.permittedErrorPrefixes=[it,Te];var s=(r=t.together)==null?void 0:r.textToSpeech;_typeof(s)===U&&_this35.completeConfig(s),(_o$model2=(o=_this35.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this35.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this35;}_inherits(Vl,_k4);return _createClass(Vl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee69(e,t){return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:return _context69.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee69,this);}));function callServiceAPI(_x141,_x142){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(e){var t,n;return _regenerator().w(function(_context70){while(1)switch(_context70.n){case 0:t=new Blob([e],_defineProperty({},E,"audio/mpeg")),n=URL.createObjectURL(t);return _context70.a(2,_defineProperty({},b,[_defineProperty(_defineProperty({},T,n),E,$)]));}},_callee70);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(k);var Ze="https://api.openai.com/v1/",Nn="https://platform.openai.com/account/api-keys",Ki="input_text",so="input_image",io="output_text",Di="image_generation_call",Qo="function_call_output",Hn="response",Bn=function Bn(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},ea=function ea(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(pe):n(Ue):t(e);},Dn=function Dn(){return be("".concat(Ze,"models"),ue,ea);},jt=/*#__PURE__*/function(){var _ref55=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(i,e,t){var n,s,r,o,a,c,_yield$D$processReque6,l,d,p,u,g,_args71=arguments;return _regenerator().w(function(_context71){while(1)switch(_context71.n){case 0:n=_args71.length>3&&_args71[3]!==undefined?_args71[3]:!0;s=i.connectSettings,r=i.deepChat,o=i.completionsHandlers,a=i.messages;s.method=t;c={body:e,headers:s.headers};_context71.n=1;return D.processRequestInterceptor(r,c);case 1:_yield$D$processReque6=_context71.v;l=_yield$D$processReque6.body;d=_yield$D$processReque6.headers;p=_yield$D$processReque6.error;u=o.onFinish;if(!(p&&a)){_context71.n=2;break;}return _context71.a(2,D.onInterceptorError(a,p,u));case 2:_context71.n=3;return D.fetch(i,d,n,l).then(function(y){return D.processResponseByType(y);});case 3:g=_context71.v;if(!g[f]){_context71.n=4;break;}throw g[f].message;case 4:return _context71.a(2,g);}},_callee71);}));return function jt(_x144,_x145,_x146){return _ref55.apply(this,arguments);};}(),Ke=/*#__PURE__*/function(){function Ke(){_classCallCheck(this,Ke);}return _createClass(Ke,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73(e,t,n,s){var r,o,a,c,_t24;return _regenerator().w(function(_context73){while(1)switch(_context73.p=_context73.n){case 0:r=e.connectSettings.headers;if(r){_context73.n=1;break;}return _context73.a(2);case 1:e.url=s;o=r[q];delete r[q];a=n.map(/*#__PURE__*/function(){var _ref56=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(c){var l;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:l=new FormData();return _context72.a(2,(l.append("purpose","assistants"),l.append("file",c),new Promise(function(d){d(jt(e,l,ye,!1));})));}},_callee72);}));return function(_x151){return _ref56.apply(this,arguments);};}());_context73.p=2;_context73.n=3;return Promise.all(a);case 3:c=_context73.v.map(function(l){return{id:l.id,name:l.filename};});return _context73.a(2,(r[q]=o,c));case 4:_context73.p=4;_t24=_context73.v;throw r[q]=o,D.displayError(t,_t24),e.completionsHandlers.onFinish(),_t24;case 5:return _context73.a(2);}},_callee73,null,[[2,4]]);}));function storeFiles(_x147,_x148,_x149,_x150){return _storeFiles.apply(this,arguments);}return storeFiles;}()},{key:"getType",value:function getType(e,t){var n=e[t].path;return!n||n.endsWith("png")?W:rn;}},{key:"getFiles",value:function(){var _getFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee74(e,t,n,s){var r,a;return _regenerator().w(function(_context74){while(1)switch(_context74.n){case 0:r=t.map(function(_ref57){var c=_ref57.fileId;return e.url="".concat(n).concat(c).concat(s),new Promise(function(l){l(jt(e,void 0,"GET",!1));});});_context74.n=1;return Promise.all(r);case 1:a=_context74.v.map(function(c,l){return new Promise(function(d){var p=new FileReader();p.readAsDataURL(c),p.onload=function(u){d(_defineProperty(_defineProperty(_defineProperty({},T,u.target.result),"name",t[l].name),E,Ke.getType(t,l)));};});});_context74.n=2;return Promise.all(a);case 2:return _context74.a(2,_context74.v);}},_callee74);}));function getFiles(_x152,_x153,_x154,_x155){return _getFiles.apply(this,arguments);}return getFiles;}()},{key:"getFileName",value:function getFileName(e){var t=e.split("/");return t[t.length-1];}// prettier-ignore
138
+ {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},Y=/*#__PURE__*/function(_un2){function Y(e){var _this18;_classCallCheck(this,Y);var t,n;_this18=_callSuper(this,Y,[e]),_this18._isModelLoaded=!1,_this18._isModelLoading=!1,_this18._loadOnFirstMessage=!1,_this18._webModel={},_this18.permittedErrorPrefixes=[Y.MULTIPLE_MODELS_ERROR,Y.WEB_LLM_NOT_FOUND_ERROR,Y.GENERIC_ERROR],_this18._conversationHistory=[],_typeof(e.webModel)=="object"&&(_this18._webModel=e.webModel),(t=_this18._webModel.load)!=null&&t.clearCache&&Y.clearAllCache(),_this18.findModelInWindow(e),_this18.canSendMessage=_this18.canSubmit.bind(_assertThisInitialized(_this18)),_this18._chatEl=(n=e.shadowRoot)==null?void 0:n.children[0],e.history&&Y.setUpHistory(_this18._conversationHistory,e.history);return _this18;}// need ref of messages object as web model exhibits unique behaviour to manipulate chat
139
+ _inherits(Y,_un2);return _createClass(Y,[{key:"setUpMessages",value:function setUpMessages(e){var _this19=this;this._messages=e,this._removeIntro=function(){e.removeIntroductoryMessage(),_this19._removeIntro=void 0;};}},{key:"findModelInWindow",value:function findModelInWindow(e){var _this20=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var n;window.webLLM?this.configureInit(this.shouldAddIntroMessage(e.introMessage)):t>Y.MODULE_SEARCH_LIMIT_S?((n=this._messages)==null||n.addNewErrorMessage(ae,Y.WEB_LLM_NOT_FOUND_ERROR),console[f]("The deep-chat-web-llm module has not been attached to the window object. Please see the following guide:"),console[f]("https://deepchat.dev/examples/externalModules")):setTimeout(function(){return _this20.findModelInWindow(e,t+1);},1e3);}},{key:"shouldAddIntroMessage",value:function shouldAddIntroMessage(e){var t;return!e&&this._webModel&&((t=this._webModel.introMessage)==null?void 0:t.displayed)!==!1;}},{key:"scrollToTop",value:function scrollToTop(e){var _this21=this;var t;((t=this._webModel.introMessage)==null?void 0:t.autoScroll)!==!1&&setTimeout(function(){var n,s;(n=_this21._messages)!=null&&n.elementRef&&z.scrollToTop((s=_this21._messages)==null?void 0:s.elementRef);},e);}// prettier-ignore
140
+ },{key:"getIntroMessage",value:function getIntroMessage(e){if(!this.shouldAddIntroMessage(e)||!this._chatEl)return;var t=Zs.setUpInitial(this.init.bind(this),this._webModel.introMessage,this._chatEl,!!this._webModel.worker);return this.scrollToTop(1),_defineProperty(_defineProperty(_defineProperty({},x,ne),"html",t),"sendUpdate",!1);}},{key:"configureInit",value:function(){var _configureInit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee37(e){var t;return _regenerator().w(function(_context37){while(1)switch(_context37.n){case 0:t=this._webModel.load;if(!t){_context37.n=2;break;}if(!t.onInit){_context37.n=1;break;}this.init();return _context37.a(2);case 1:if(!t.onMessage){_context37.n=2;break;}this._loadOnFirstMessage=!0;return _context37.a(2);case 2:e||this.init();case 3:return _context37.a(2);}},_callee37,this);}));function configureInit(_x83){return _configureInit.apply(this,arguments);}return configureInit;}()},{key:"init",value:function(){var _init=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee38(e){var n,t,_t16;return _regenerator().w(function(_context38){while(1)switch(_context38.n){case 0:(n=this._messages)==null||n.removeError();t=this.attemptToCreateChat();_t16=t;if(!_t16){_context38.n=1;break;}_context38.n=1;return this.loadModel(t,e);case 1:return _context38.a(2);}},_callee38,this);}));function init(_x84){return _init.apply(this,arguments);}return init;}()},{key:"attemptToCreateChat",value:function attemptToCreateChat(){var t;if(Y.chat){(t=this._messages)==null||t.addNewErrorMessage(ae,Y.MULTIPLE_MODELS_ERROR),console[f](Y.MULTIPLE_MODELS_ERROR);return;}if(this._isModelLoaded||this._isModelLoading)return;var e=this._webModel.worker;return to.use_web_worker&&e?new window.webLLM.ChatWorkerClient(e):new window.webLLM.ChatModule();}},{key:"getConfig",value:function getConfig(){var n;var e=Y.DEFAULT_MODEL;this._webModel.model&&(e=this._webModel.model);var t=C(to);if(this._webModel.urls){var s=t.model_list.find(function(r){return r.local_id=e;});s&&(this._webModel.urls.model&&(s.model_url=this._webModel.urls.model),this._webModel.urls.wasm&&(s.model_lib_url=this._webModel.urls.wasm));}return(n=this._webModel.load)!=null&&n.skipCache&&(t.use_cache=!1),{model:e,appConfig:t};}// prettier-ignore
141
+ },{key:"loadModel",value:function(){var _loadModel=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee39(e,t){var _this22=this;var o,a,c,l,d,p,u,n,s,r,_this$getConfig,g,y,_,_g,_t17;return _regenerator().w(function(_context39){while(1)switch(_context39.p=_context39.n){case 0:this.scrollToTop(),Y.chat=e,this._isModelLoading=!0;n=((o=this._webModel.introMessage)==null?void 0:o.displayed)===!1;s=function s(g){var y;(y=_this22._messages)==null||y.addNewMessage({html:"<div>".concat(g[h],"</div>"),overwrite:!0,sendUpdate:!1}),n&&(setTimeout(function(){return z.scrollToBottom(_this22._messages);}),n=!1);};Y.chat.setInitProgressCallback(s);_context39.p=1;_this$getConfig=this.getConfig(),g=_this$getConfig.model,y=_this$getConfig.appConfig,_={};this._webModel.instruction&&(_.conv_config=_defineProperty({},Mn,this._webModel.instruction));this._conversationHistory.length>0&&(_.conversation_history=this._conversationHistory);_context39.n=2;return Y.chat.reload(g,_,y,t);case 2:r=_context39.v;_context39.n=4;break;case 3:_context39.p=3;_t17=_context39.v;return _context39.a(2,this.unloadChat(_t17));case 4:if((c=(a=this.deepChat)._validationHandler)==null||c.call(a),(l=this._webModel.introMessage)!=null&&l.removeAfterLoad)this._webModel.introMessage.displayed===!1?(p=this._messages)==null||p.removeLastMessage():(u=this._removeIntro)==null||u.call(this);else{_g=Zs.setUpAfterLoad(r,this._webModel.introMessage,this._chatEl,!!this._webModel.worker);(d=this._messages)==null||d.addNewMessage({html:_g,overwrite:!0,sendUpdate:!1});}this._isModelLoaded=!0,this._isModelLoading=!1;case 5:return _context39.a(2);}},_callee39,this,[[1,3]]);}));function loadModel(_x85,_x86){return _loadModel.apply(this,arguments);}return loadModel;}()},{key:"unloadChat",value:function(){var _unloadChat=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee40(e){var t,_t18;return _regenerator().w(function(_context40){while(1)switch(_context40.n){case 0:(t=this._messages)==null||t.addNewErrorMessage(ae,Y.GENERIC_ERROR);console[f](e);this._isModelLoaded=!1;this._isModelLoading=!1;_t18=Y.chat;if(!_t18){_context40.n=2;break;}_context40.n=1;return Y.chat.unload();case 1:Y.chat=void 0;case 2:return _context40.a(2);}},_callee40,this);}));function unloadChat(_x87){return _unloadChat.apply(this,arguments);}return unloadChat;}()},{key:"immediateResp",value:function(){var _immediateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee41(e,t,n){var s,r,_t19,_t20,_t21;return _regenerator().w(function(_context41){while(1)switch(_context41.n){case 0:_t19=_defineProperty;_t20={};_t21=h;_context41.n=1;return n.generate(t,void 0,0);case 1:s=_t19(_t20,_t21,_context41.v);_context41.n=2;return Y.processResponse(this.deepChat,e,s);case 2:r=_context41.v;r&&r.forEach(function(o){return e.addNewMessage(o);}),this.completionsHandlers.onFinish();case 3:return _context41.a(2);}},_callee41,this);}));function immediateResp(_x88,_x89,_x90){return _immediateResp.apply(this,arguments);}return immediateResp;}()},{key:"streamResp",value:function(){var _streamResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee43(e,t,n){var _this23=this;var s;return _regenerator().w(function(_context43){while(1)switch(_context43.n){case 0:this.streamHandlers.onAbort=function(){n.interruptGenerate();},this.streamHandlers.onOpen();s=new ht(e);_context43.n=1;return n.generate(t,/*#__PURE__*/function(){var _ref32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee42(r,o){var a;return _regenerator().w(function(_context42){while(1)switch(_context42.n){case 0:_context42.n=1;return Y.processResponse(_this23.deepChat,e,_defineProperty({},h,o));case 1:a=_context42.v;a&&s.upsertStreamedMessage(_defineProperty(_defineProperty({},h,a[0][h]),"overwrite",!0));case 2:return _context42.a(2);}},_callee42);}));return function(_x94,_x95){return _ref32.apply(this,arguments);};}());case 1:s.finaliseStreamedMessage();this.streamHandlers.onClose();case 2:return _context43.a(2);}},_callee43,this);}));function streamResp(_x91,_x92,_x93){return _streamResp.apply(this,arguments);}return streamResp;}()},{key:"generateRespByType",value:function(){var _generateRespByType=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee44(e,t,n,s){var r,_t22;return _regenerator().w(function(_context44){while(1)switch(_context44.p=_context44.n){case 0:_context44.p=0;if(!n){_context44.n=2;break;}_context44.n=1;return this.streamResp(e,t,s);case 1:_context44.n=3;break;case 2:_context44.n=3;return this.immediateResp(e,t,s);case 3:_context44.n=5;break;case 4:_context44.p=4;_t22=_context44.v;(r=this._messages)==null||r.addNewErrorMessage(ae),console.log(_t22);case 5:return _context44.a(2);}},_callee44,this,[[0,4]]);}));function generateRespByType(_x96,_x97,_x98,_x99){return _generateRespByType.apply(this,arguments);}return generateRespByType;}()},{key:"generateResp",value:function(){var _generateResp=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee45(e,t,n){var s,_yield$D$processReque5,r,o,a,c,l;return _regenerator().w(function(_context45){while(1)switch(_context45.n){case 0:s=t[t.length-1][h];_context45.n=1;return D.processRequestInterceptor(this.deepChat,{body:_defineProperty({},h,s)});case 1:_yield$D$processReque5=_context45.v;r=_yield$D$processReque5.body;o=_yield$D$processReque5.error;a=!!this.stream;try{if(o)D.displayError(e,new Error(o)),(a?this.streamHandlers.onClose:this.completionsHandlers.onFinish)();else if(!r||!r[h]){c=Aa({body:r},!1);console[f](c);l=a?this.streamHandlers.onClose:this.completionsHandlers.onFinish;D.onInterceptorError(e,c,l);}else this.generateRespByType(e,r[h],!!this.stream,n);}catch(c){this.unloadChat(c);}case 2:return _context45.a(2);}},_callee45,this);}));function generateResp(_x100,_x101,_x102){return _generateResp.apply(this,arguments);}return generateResp;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee46(e,t){var n,s;return _regenerator().w(function(_context46){while(1)switch(_context46.n){case 0:if(this._isModelLoaded){_context46.n=3;break;}if(!this._loadOnFirstMessage){_context46.n=2;break;}_context46.n=1;return this.init();case 1:_context46.n=3;break;case 2:return _context46.a(2);case 3:!Y.chat||this._isModelLoading||((n=this._webModel.introMessage)!=null&&n.removeAfterMessage&&((s=this._removeIntro)==null||s.call(this)),e.addLoadingMessage(),this.generateResp(e,t,Y.chat));case 4:return _context46.a(2);}},_callee46,this);}));function callServiceAPI(_x103,_x104){return _callServiceAPI2.apply(this,arguments);}return callServiceAPI;}()},{key:"canSubmit",value:function canSubmit(e){return!(e!=null&&e.trim())||this._isModelLoading?!1:this._loadOnFirstMessage?!0:!!this._isModelLoaded;}},{key:"isWebModel",value:function isWebModel(){return!0;}}],[{key:"setUpHistory",value:function setUpHistory(e,t){t.forEach(function(n,s){if(n[x]===F&&n[h]){var r=t[s+1];r!=null&&r[h]&&r[x]!==F&&e.push([n[h],r[h]]);}});}},{key:"processResponse",value:function(){var _processResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee47(e,t,n){var a,c,s,r,o,d,_t23;return _regenerator().w(function(_context47){while(1)switch(_context47.n){case 0:_context47.n=1;return(a=e.responseInterceptor)==null?void 0:a.call(e,n);case 1:_t23=_context47.v;if(_t23){_context47.n=2;break;}_t23=n;case 2:s=_t23;if(!((c=e.connect)!=null&&c.stream&&Array.isArray(s)&&s.length>1)){_context47.n=3;break;}console[f](Do);return _context47.a(2);case 3:r=Array.isArray(s)?s:[s],o=r.find(function(l){return _typeof(l[f])===Ee;});if(!o){_context47.n=4;break;}D.displayError(t,new Error(o[f]));return _context47.a(2);case 4:if(!r.find(function(d){return!d||!d[h];})){_context47.n=5;break;}d=wa(n,!!e.responseInterceptor,s);D.displayError(t,new Error(d));return _context47.a(2);case 5:return _context47.a(2,r);}},_callee47);}));function processResponse(_x105,_x106,_x107){return _processResponse.apply(this,arguments);}return processResponse;}()},{key:"clearAllCache",value:function clearAllCache(){Y.clearCache("webllm/model"),Y.clearCache("webllm/wasm");}},{key:"clearCache",value:function clearCache(e){caches.open(e).then(function(t){t.keys().then(function(n){n.forEach(function(s){t["delete"](s);});});});}}]);}(un);Y.GENERIC_ERROR="Error, please check the [troubleshooting](".concat(Z,"webModel#troubleshooting) section of documentation for help."),Y.MULTIPLE_MODELS_ERROR="Cannot run multiple web models",Y.WEB_LLM_NOT_FOUND_ERROR="WebLLM module not found",Y.DEFAULT_MODEL="Llama-2-7b-chat-hf-q4f32_1",Y.MODULE_SEARCH_LIMIT_S=5;var Ts=Y;var be=function be(i,e,t,n){return{url:i,method:e,handleVerificationResult:t,augmentUrl:n};},Il=function Il(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Ml=function Ml(i,e,t,n){var s=i;Array.isArray(s[f])&&s[f][0]==="Error in `parameters`: field required"?t(e):n(pe);},kl=function kl(){return be("https://api-inference.huggingface.co/models/gpt2",ye,Ml);},ys=/*#__PURE__*/function(_k){// prettier-ignore
142
+ function ys(e,t,n,s,r,o){var _this24;_classCallCheck(this,ys);_this24=_callSuper(this,ys,[e,kl(),Il,r,o]),_this24.insertKeyPlaceholderText="Hugging Face Token",_this24.keyHelpUrl="https://huggingface.co/settings/tokens",_this24.permittedErrorPrefixes=[ar],_this24.url="".concat(ys.URL_PREFIX).concat(n),_this24.textInputPlaceholderText=t,_typeof(s)=="object"&&(s.model&&(_this24.url="".concat(ys.URL_PREFIX).concat(s.model)),s.options&&(_this24.rawBody.options=s.options),s.parameters&&(_this24.rawBody.parameters=s.parameters));return _this24;}_inherits(ys,_k);return _createClass(ys,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var _s$options;var s=C(e),r=t[t.length-1][h];if(r)return(_s$options=s.options)!==null&&_s$options!==void 0?_s$options:s.options={},s.options.wait_for_model=!0,_objectSpread({inputs:r},s);}},{key:"callServiceAPI",value:function(){var _callServiceAPI3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee48(e,t,n){var s;return _regenerator().w(function(_context48){while(1)switch(_context48.n){case 0:if(this.connectSettings){_context48.n=1;break;}throw new Error(He);case 1:s=this.preprocessBody(this.rawBody,t,n);ge.request(this,s,e);case 2:return _context48.a(2);}},_callee48,this);}));function callServiceAPI(_x108,_x109,_x110){return _callServiceAPI3.apply(this,arguments);}return callServiceAPI;}()}]);}(k);ys.URL_PREFIX="https://api-inference.huggingface.co/models/";var Pt=ys;var Ls=/*#__PURE__*/function(_Pt){// prettier-ignore
143
+ function Ls(e,t,n,s,r,o){var _this25;_classCallCheck(this,Ls);_this25=_callSuper(this,Ls,[e,t,n,s,r,o]),_this25.isTextInputDisabled=!0,_this25.canSendMessage=Ls.canSendFile;return _this25;}_inherits(Ls,_Pt);return _createClass(Ls,[{key:"preprocessBody",value:function preprocessBody(e,t,n){return n[0];}// prettier-ignore
144
+ },{key:"callServiceAPI",value:function(){var _callServiceAPI4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee49(e,t,n){return _regenerator().w(function(_context49){while(1)switch(_context49.n){case 0:if(this.connectSettings){_context49.n=1;break;}throw new Error(He);case 1:if(n!=null&&n[0]){_context49.n=2;break;}throw new Error(bi);case 2:ge.poll(this,n[0],e,!1);case 3:return _context49.a(2);}},_callee49,this);}));function callServiceAPI(_x111,_x112,_x113){return _callServiceAPI4.apply(this,arguments);}return callServiceAPI;}()}],[{key:"canSendFile",value:function canSendFile(e,t){return!!(t!=null&&t[0]);}}]);}(Pt);var Pl=/*#__PURE__*/function(_Ls){// prettier-ignore
145
+ function Pl(e){_classCallCheck(this,Pl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.audioClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Pl,[e,"Attach an audio ".concat(se),"ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition",t,n,{audio:{}}]);}_inherits(Pl,_Ls);return _createClass(Pl,[{key:"extractPollResultData",value:function(){var _extractPollResultData=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee50(e){var t;return _regenerator().w(function(_context50){while(1)switch(_context50.n){case 0:if(!e.estimated_time){_context50.n=1;break;}return _context50.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[f]){_context50.n=2;break;}throw e[f];case 2:return _context50.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee50);}));function extractPollResultData(_x114){return _extractPollResultData.apply(this,arguments);}return extractPollResultData;}()}]);}(Ls);var Ll=/*#__PURE__*/function(_Ls2){function Ll(e){_classCallCheck(this,Ll);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.imageClassification,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Ll,[e,"Attach an image ".concat(se),"google/vit-base-patch16-224",t,n,{images:{}}]);}_inherits(Ll,_Ls2);return _createClass(Ll,[{key:"extractPollResultData",value:function(){var _extractPollResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee51(e){var t;return _regenerator().w(function(_context51){while(1)switch(_context51.n){case 0:if(!e.estimated_time){_context51.n=1;break;}return _context51.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[f]){_context51.n=2;break;}throw e[f];case 2:return _context51.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.label)||""));}},_callee51);}));function extractPollResultData(_x115){return _extractPollResultData2.apply(this,arguments);}return extractPollResultData;}()}]);}(Ls);var vi=function vi(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Ol=function Ol(i,e,t,n){i.message?n(pe):t(e);},Si=function Si(){return be("https://api.stability.ai/v1/engines/list",ue,Ol);},On="data:image/png;base64,";var xi=/*#__PURE__*/function(_k2){// prettier-ignore
146
+ function xi(e,t,n,s,r){var _this26;_classCallCheck(this,xi);_this26=_callSuper(this,xi,[e,t,n,s,r]),_this26.insertKeyPlaceholderText=_this26.genereteAPIKeyName("Stability AI"),_this26.keyHelpUrl="https://platform.stability.ai/docs/getting-started/authentication",_this26.permittedErrorPrefixes=[Ps,"invalid_"];return _this26;}_inherits(xi,_k2);return _createClass(xi);}(k);var Ys=/*#__PURE__*/function(_xi){function Ys(e){var _this27;_classCallCheck(this,Ys);var o;var t=C(e.directConnection),n=t==null?void 0:t.stabilityAI,s={images:{files:{acceptedFormats:".png",maxNumberOfFiles:1}}};_this27=_callSuper(this,Ys,[e,Si(),vi,n,s]),_this27.url="https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale",_this27.textInputPlaceholderText="Describe image changes";var r=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageUpscale;_typeof(r)=="object"&&(r.engine_id&&(_this27.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/image-to-image/upscale")),Ys.cleanConfig(r),Object.assign(_this27.rawBody,r)),_this27.canSendMessage=Ys.canSendFileMessage;return _this27;}_inherits(Ys,_xi);return _createClass(Ys,[{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(W,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}// prettier-ignore
147
+ },{key:"callServiceAPI",value:function(){var _callServiceAPI5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee52(e,t,n){var s;return _regenerator().w(function(_context52){while(1)switch(_context52.n){case 0:if(this.connectSettings){_context52.n=1;break;}throw new Error(He);case 1:if(n){_context52.n=2;break;}throw new Error(or);case 2:s=this.createFormDataBody(this.rawBody,n[0]);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,s,e),!1);case 3:return _context52.a(2);}},_callee52,this);}));function callServiceAPI(_x116,_x117,_x118){return _callServiceAPI5.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee53(e){var t;return _regenerator().w(function(_context53){while(1)switch(_context53.n){case 0:if(!e.message){_context53.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(On).concat(n.base64)),E,W);});return _context53.a(2,_defineProperty({},b,t));}},_callee53);}));function extractResultData(_x119){return _extractResultData2.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id;}},{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}}]);}(xi);var Js=/*#__PURE__*/function(_xi2){function Js(e){var _this28;_classCallCheck(this,Js);var o;var t=C(e.directConnection),n=t==null?void 0:t.stabilityAI,s=_defineProperty({},ee,_defineProperty({},b,{acceptedFormats:".png",maxNumberOfFiles:2}));_this28=_callSuper(this,Js,[e,Si(),vi,n,s]),_this28.url="https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/image-to-image/masking",_this28._maskSource="MASK_IMAGE_WHITE",_this28.textInputPlaceholderText="Describe image changes";var r=(o=t==null?void 0:t.stabilityAI)==null?void 0:o.imageToImageMasking;_typeof(r)=="object"&&(r.engine_id&&(_this28.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/image-to-image/masking")),r.weight!==void 0&&r.weight!==null&&(_this28._imageWeight=r.weight),r.mask_source!==void 0&&r.mask_source!==null&&(_this28._maskSource=r.mask_source),Js.cleanConfig(r),Object.assign(_this28.rawBody,r)),_this28.canSendMessage=Js.canSendFileTextMessage;return _this28;}_inherits(Js,_xi2);return _createClass(Js,[{key:"createFormDataBody",value:function createFormDataBody(e,t,n,s){var r=new FormData();return r.append("init_image",t),r.append("mask_source",String(this._maskSource)),r.append("mask_image",n),s&&s!==""&&r.append("text_prompts[0][text]",s),this._imageWeight!==void 0&&this._imageWeight!==null&&r.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(o){r.append(o,String(e[o]));}),r.get("weight")===void 0&&r.append("weight",String(1)),r;}// prettier-ignore
148
+ },{key:"callServiceAPI",value:function(){var _callServiceAPI6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee54(e,t,n){var o,a,s,r;return _regenerator().w(function(_context54){while(1)switch(_context54.n){case 0:if(this.connectSettings){_context54.n=1;break;}throw new Error(He);case 1:if(!(!n||!n[0]||!n[1])){_context54.n=2;break;}throw new Error(or);case 2:s=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim(),r=this.createFormDataBody(this.rawBody,n[0],n[1],s);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,r,e),!1);case 3:return _context54.a(2);}},_callee54,this);}));function callServiceAPI(_x120,_x121,_x122){return _callServiceAPI6.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee55(e){var t;return _regenerator().w(function(_context55){while(1)switch(_context55.n){case 0:if(!e.message){_context55.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(On).concat(n.base64)),E,W);});return _context55.a(2,_defineProperty({},b,t));}},_callee55);}));function extractResultData(_x123){return _extractResultData3.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(xi);var Nl=/*#__PURE__*/function(_Ls3){function Nl(e){_classCallCheck(this,Nl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.audioSpeechRecognition,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Nl,[e,"Attach an audio ".concat(se),"facebook/wav2vec2-large-960h-lv60-self",t,n,{audio:{}}]);}_inherits(Nl,_Ls3);return _createClass(Nl,[{key:"extractPollResultData",value:function(){var _extractPollResultData3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee56(e){return _regenerator().w(function(_context56){while(1)switch(_context56.n){case 0:if(!e.estimated_time){_context56.n=1;break;}return _context56.a(2,{timeoutMS:(e.estimated_time+1)*1e3});case 1:if(!e[f]){_context56.n=2;break;}throw e[f];case 2:return _context56.a(2,_defineProperty({},h,e[h]||""));}},_callee56);}));function extractPollResultData(_x124){return _extractPollResultData3.apply(this,arguments);}return extractPollResultData;}()}]);}(Ls);var Bl=/*#__PURE__*/function(_Pt2){function Bl(e){_classCallCheck(this,Bl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.textGeneration,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Bl,[e,"Once upon a time","gpt2",t,n]);}_inherits(Bl,_Pt2);return _createClass(Bl,[{key:"extractResultData",value:function(){var _extractResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee57(e){var t;return _regenerator().w(function(_context57){while(1)switch(_context57.n){case 0:if(!e[f]){_context57.n=1;break;}throw e[f];case 1:return _context57.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.generated_text)||""));}},_callee57);}));function extractResultData(_x125){return _extractResultData4.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var Dl=/*#__PURE__*/function(_Pt3){function Dl(e){var _this29;_classCallCheck(this,Dl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.questionAnswer,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this29=_callSuper(this,Dl,[e,"Ask a question","bert-large-uncased-whole-word-masking-finetuned-squad",t,n]),_this29.permittedErrorPrefixes=[ar,"Error in"],_this29._context=t.context;return _this29;}_inherits(Dl,_Pt3);return _createClass(Dl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return{inputs:{question:n,context:this._context,options:{wait_for_model:!0}}};}},{key:"extractResultData",value:function(){var _extractResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee58(e){return _regenerator().w(function(_context58){while(1)switch(_context58.n){case 0:if(!e[f]){_context58.n=1;break;}throw e[f];case 1:return _context58.a(2,_defineProperty({},h,e.answer||""));}},_callee58);}));function extractResultData(_x126){return _extractResultData5.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var Fl=/*#__PURE__*/function(_Pt4){function Fl(e){_classCallCheck(this,Fl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.summarization,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Fl,[e,"Insert text to summarize","facebook/bart-large-cnn",t,n]);}_inherits(Fl,_Pt4);return _createClass(Fl,[{key:"extractResultData",value:function(){var _extractResultData6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee59(e){var t;return _regenerator().w(function(_context59){while(1)switch(_context59.n){case 0:if(!e[f]){_context59.n=1;break;}throw e[f];case 1:return _context59.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.summary_text)||""));}},_callee59);}));function extractResultData(_x127){return _extractResultData6.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var Ul=/*#__PURE__*/function(_Pt5){function Ul(e){var _this30$maxMessages;var _this30;_classCallCheck(this,Ul);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.conversation,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this30=_callSuper(this,Ul,[e,"Ask me anything!","facebook/blenderbot-400M-distill",t,n]),(_this30$maxMessages=_this30.maxMessages)!==null&&_this30$maxMessages!==void 0?_this30$maxMessages:_this30.maxMessages=-1;return _this30;}// prettier-ignore
149
+ _inherits(Ul,_Pt5);return _createClass(Ul,[{key:"processMessagesI",value:function processMessagesI(e){var t=e.filter(function(a){return a[h];}),n=t[t.length-1][h],s=t.slice(0,t.length-1);if(!n)return;var r=s.filter(function(a){return a[x]===F;}).map(function(a){return a[h];}),o=s.filter(function(a){return a[x]===ne;}).map(function(a){return a[h];});return{past_user_inputs:r,generated_responses:o,mostRecentMessageText:n};}},{key:"preprocessBody",value:function preprocessBody(e,t){var _n$options;var n=C(e),s=this.processMessagesI(t);if(s)return(_n$options=n.options)!==null&&_n$options!==void 0?_n$options:n.options={},n.options.wait_for_model=!0,_objectSpread({inputs:_defineProperty({past_user_inputs:s.past_user_inputs,generated_responses:s.generated_responses},h,s.mostRecentMessageText)},n);}},{key:"extractResultData",value:function(){var _extractResultData7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee60(e){return _regenerator().w(function(_context60){while(1)switch(_context60.n){case 0:if(!e[f]){_context60.n=1;break;}throw e[f];case 1:return _context60.a(2,_defineProperty({},h,e.generated_text||""));}},_callee60);}));function extractResultData(_x128){return _extractResultData7.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var Qs=/*#__PURE__*/function(_xi3){function Qs(e){var _this31;_classCallCheck(this,Qs);var o;var t=C(e.directConnection),n=t.stabilityAI,s=_defineProperty({},ee,_defineProperty({},b,{acceptedFormats:".png",maxNumberOfFiles:1}));_this31=_callSuper(this,Qs,[e,Si(),vi,n,s]),_this31.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/image-to-image",_this31.textInputPlaceholderText="Describe image changes";var r=(o=t.stabilityAI)==null?void 0:o.imageToImage;_typeof(r)=="object"&&(r.engine_id&&(_this31.url="https://api.stability.ai/v1/generation/".concat(r.engine_id,"/text-to-image")),r.weight!==void 0&&r.weight!==null&&(_this31._imageWeight=r.weight),Qs.cleanConfig(r),Object.assign(_this31.rawBody,r)),_this31.canSendMessage=Qs.canSendFileTextMessage;return _this31;}_inherits(Qs,_xi3);return _createClass(Qs,[{key:"createFormDataBody",value:function createFormDataBody(e,t,n){var s=new FormData();return s.append("init_image",t),n&&n!==""&&s.append("text_prompts[0][text]",n),this._imageWeight!==void 0&&this._imageWeight!==null&&s.append("text_prompts[0][weight]",String(this._imageWeight)),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s.get("weight")===void 0&&s.append("weight",String(1)),s;}// prettier-ignore
150
+ },{key:"callServiceAPI",value:function(){var _callServiceAPI7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee61(e,t,n){var o,a,s,r;return _regenerator().w(function(_context61){while(1)switch(_context61.n){case 0:if(this.connectSettings){_context61.n=1;break;}throw new Error(He);case 1:if(n){_context61.n=2;break;}throw new Error(or);case 2:s=(a=(o=t[t.length-1])==null?void 0:o[h])==null?void 0:a.trim(),r=this.createFormDataBody(this.rawBody,n[0],s);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,r,e),!1);case 3:return _context61.a(2);}},_callee61,this);}));function callServiceAPI(_x129,_x130,_x131){return _callServiceAPI7.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee62(e){var t;return _regenerator().w(function(_context62){while(1)switch(_context62.n){case 0:if(!e.message){_context62.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(On).concat(n.base64)),E,W);});return _context62.a(2,_defineProperty({},b,t));}},_callee62);}));function extractResultData(_x132){return _extractResultData8.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendFileTextMessage",value:function canSendFileTextMessage(e,t){return!!(t!=null&&t[0])&&!!(e&&e.trim()!=="");}}]);}(xi);var Hl=/*#__PURE__*/function(_Pt6){function Hl(e){_classCallCheck(this,Hl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.translation,n=(o=e.directConnection)==null?void 0:o.huggingFace;return _callSuper(this,Hl,[e,"Insert text to translate","Helsinki-NLP/opus-tatoeba-en-ja",t,n]);}_inherits(Hl,_Pt6);return _createClass(Hl,[{key:"extractResultData",value:function(){var _extractResultData9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee63(e){var t;return _regenerator().w(function(_context63){while(1)switch(_context63.n){case 0:if(!e[f]){_context63.n=1;break;}throw e[f];case 1:return _context63.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.translation_text)||""));}},_callee63);}));function extractResultData(_x133){return _extractResultData9.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var ei=/*#__PURE__*/function(_xi4){function ei(e){var _this32;_classCallCheck(this,ei);var r;var t=C(e.directConnection),n=t.stabilityAI;_this32=_callSuper(this,ei,[e,Si(),vi,n]),_this32.url="https://api.stability.ai/v1/generation/stable-diffusion-v1-6/text-to-image",_this32.textInputPlaceholderText="Describe an image";var s=(r=t.stabilityAI)==null?void 0:r.textToImage;_typeof(s)=="object"&&(s.engine_id&&(_this32.url="https://api.stability.ai/v1/generation/".concat(s.engine_id,"/text-to-image")),s.weight!==void 0&&s.weight!==null&&(_this32._imageWeight=s.weight),ei.cleanConfig(s),Object.assign(_this32.rawBody,s)),_this32.canSendMessage=ei.canSendTextMessage;return _this32;}_inherits(ei,_xi4);return _createClass(ei,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=C(e),r=_defineProperty({},h,n);return this._imageWeight&&(r.weight=this._imageWeight),s.text_prompts=[r],s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI8=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee64(e,t){return _regenerator().w(function(_context64){while(1)switch(_context64.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context64.a(2);}},_callee64,this);}));function callServiceAPI(_x134,_x135){return _callServiceAPI8.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee65(e){var t;return _regenerator().w(function(_context65){while(1)switch(_context65.n){case 0:if(!e.message){_context65.n=1;break;}throw e.message;case 1:t=e.artifacts.map(function(n){return _defineProperty(_defineProperty({},T,"".concat(On).concat(n.base64)),E,W);});return _context65.a(2,_defineProperty({},b,t));}},_callee65);}));function extractResultData(_x136){return _extractResultData0.apply(this,arguments);}return extractResultData;}()}],[{key:"cleanConfig",value:function cleanConfig(e){delete e.engine_id,delete e.weight;}},{key:"canSendTextMessage",value:function canSendTextMessage(e){return!!(e&&e.trim()!=="");}}]);}(xi);var jl=/*#__PURE__*/function(_Pt7){function jl(e){var _this33;_classCallCheck(this,jl);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.huggingFace)==null?void 0:r.fillMask,n=(o=e.directConnection)==null?void 0:o.huggingFace;_this33=_callSuper(this,jl,[e,"The goal of life is [MASK].","bert-base-uncased",t,n]),_this33.permittedErrorPrefixes=[ar,"No mask_token"];return _this33;}_inherits(jl,_Pt7);return _createClass(jl,[{key:"extractResultData",value:function(){var _extractResultData1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee66(e){var t;return _regenerator().w(function(_context66){while(1)switch(_context66.n){case 0:if(!e[f]){_context66.n=1;break;}throw e[f];case 1:return _context66.a(2,_defineProperty({},h,((t=e[0])==null?void 0:t.sequence)||""));}},_callee66);}));function extractResultData(_x137){return _extractResultData1.apply(this,arguments);}return extractResultData;}()}]);}(Pt);var pr=function pr(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},$l=function $l(i,e,t,n){var s=i;s[f]?s[f].message===yi?n(pe):n(Ue):t(e);},fr=function fr(){return be("https://open.bigmodel.cn/api/paas/v4/models",ue,$l);};var ql=/*#__PURE__*/function(_k3){function ql(e){var _o$model,_a$voice;var _this34;_classCallCheck(this,ql);var r,o,a;var t=C(e.directConnection),n=t.bigModel;_this34=_callSuper(this,ql,[e,fr(),pr,n]),_this34.insertKeyPlaceholderText=_this34.genereteAPIKeyName("BigModel"),_this34.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this34.url="https://open.bigmodel.cn/api/paas/v4/audio/speech",_this34.permittedErrorPrefixes=[he,Te];var s=(r=t.bigModel)==null?void 0:r.textToSpeech;_typeof(s)===U&&(_this34.cleanConfig(s),Object.assign(_this34.rawBody,s)),(_o$model=(o=_this34.rawBody).model)!==null&&_o$model!==void 0?_o$model:o.model="cogtts",(_a$voice=(a=_this34.rawBody).voice)!==null&&_a$voice!==void 0?_a$voice:a.voice="tongtong";return _this34;}_inherits(ql,_k3);return _createClass(ql,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI9=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee67(e,t){return _regenerator().w(function(_context67){while(1)switch(_context67.n){case 0:return _context67.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee67,this);}));function callServiceAPI(_x138,_x139){return _callServiceAPI9.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee68(e){var t,n;return _regenerator().w(function(_context68){while(1)switch(_context68.n){case 0:t=new Blob([e],_defineProperty({},E,"audio/mpeg")),n=URL.createObjectURL(t);return _context68.a(2,_defineProperty({},b,[_defineProperty(_defineProperty({},T,n),E,$)]));}},_callee68);}));function extractResultData(_x140){return _extractResultData10.apply(this,arguments);}return extractResultData;}()}]);}(k);var mr=function mr(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},Gl=function Gl(i,e,t,n){var s=i;s[f]?s[f].message===yi?n(pe):n(Ue):t(e);},gr=function gr(){return be("https://api.together.xyz/v1/models",ue,Gl);};var zl=/*#__PURE__*/function(_k4){function zl(e){var _o$model2,_a$voice2;var _this35;_classCallCheck(this,zl);var r,o,a;var t=C(e.directConnection),n=t.together;_this35=_callSuper(this,zl,[e,gr(),mr,n]),_this35.insertKeyPlaceholderText=_this35.genereteAPIKeyName("Together AI"),_this35.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this35.url="https://api.together.xyz/v1/audio/speech",_this35.permittedErrorPrefixes=[it,Te];var s=(r=t.together)==null?void 0:r.textToSpeech;_typeof(s)===U&&_this35.completeConfig(s),(_o$model2=(o=_this35.rawBody).model)!==null&&_o$model2!==void 0?_o$model2:o.model="cartesia/sonic",(_a$voice2=(a=_this35.rawBody).voice)!==null&&_a$voice2!==void 0?_a$voice2:a.voice="laidback woman";return _this35;}_inherits(zl,_k4);return _createClass(zl,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI0=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee69(e,t){return _regenerator().w(function(_context69){while(1)switch(_context69.n){case 0:return _context69.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee69,this);}));function callServiceAPI(_x141,_x142){return _callServiceAPI0.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee70(e){var t,n;return _regenerator().w(function(_context70){while(1)switch(_context70.n){case 0:t=new Blob([e],_defineProperty({},E,"audio/mpeg")),n=URL.createObjectURL(t);return _context70.a(2,_defineProperty({},b,[_defineProperty(_defineProperty({},T,n),E,$)]));}},_callee70);}));function extractResultData(_x143){return _extractResultData11.apply(this,arguments);}return extractResultData;}()}]);}(k);var Ze="https://api.openai.com/v1/",Nn="https://platform.openai.com/account/api-keys",zi="input_text",no="input_image",so="output_text",Ni="image_generation_call",Jo="function_call_output",Hn="response",Bn=function Bn(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Qo=function Qo(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(pe):n(Ue):t(e);},Dn=function Dn(){return be("".concat(Ze,"models"),ue,Qo);},$t=/*#__PURE__*/function(){var _ref59=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee71(i,e,t){var n,s,r,o,a,c,_yield$D$processReque6,l,d,p,u,g,_args71=arguments;return _regenerator().w(function(_context71){while(1)switch(_context71.n){case 0:n=_args71.length>3&&_args71[3]!==undefined?_args71[3]:!0;s=i.connectSettings,r=i.deepChat,o=i.completionsHandlers,a=i.messages;s.method=t;c={body:e,headers:s.headers};_context71.n=1;return D.processRequestInterceptor(r,c);case 1:_yield$D$processReque6=_context71.v;l=_yield$D$processReque6.body;d=_yield$D$processReque6.headers;p=_yield$D$processReque6.error;u=o.onFinish;if(!(p&&a)){_context71.n=2;break;}return _context71.a(2,D.onInterceptorError(a,p,u));case 2:_context71.n=3;return D.fetch(i,d,n,l).then(function(y){return D.processResponseByType(y);});case 3:g=_context71.v;if(!g[f]){_context71.n=4;break;}throw g[f].message;case 4:return _context71.a(2,g);}},_callee71);}));return function $t(_x144,_x145,_x146){return _ref59.apply(this,arguments);};}(),Ke=/*#__PURE__*/function(){function Ke(){_classCallCheck(this,Ke);}return _createClass(Ke,null,[{key:"storeFiles",value:function(){var _storeFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee73(e,t,n,s){var r,o,a,c,_t24;return _regenerator().w(function(_context73){while(1)switch(_context73.p=_context73.n){case 0:r=e.connectSettings.headers;if(r){_context73.n=1;break;}return _context73.a(2);case 1:e.url=s;o=r[q];delete r[q];a=n.map(/*#__PURE__*/function(){var _ref60=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee72(c){var l;return _regenerator().w(function(_context72){while(1)switch(_context72.n){case 0:l=new FormData();return _context72.a(2,(l.append("purpose","assistants"),l.append("file",c),new Promise(function(d){d($t(e,l,ye,!1));})));}},_callee72);}));return function(_x151){return _ref60.apply(this,arguments);};}());_context73.p=2;_context73.n=3;return Promise.all(a);case 3:c=_context73.v.map(function(l){return{id:l.id,name:l.filename};});return _context73.a(2,(r[q]=o,c));case 4:_context73.p=4;_t24=_context73.v;throw r[q]=o,D.displayError(t,_t24),e.completionsHandlers.onFinish(),_t24;case 5:return _context73.a(2);}},_callee73,null,[[2,4]]);}));function storeFiles(_x147,_x148,_x149,_x150){return _storeFiles.apply(this,arguments);}return storeFiles;}()},{key:"getType",value:function getType(e,t){var n=e[t].path;return!n||n.endsWith("png")?W:on;}},{key:"getFiles",value:function(){var _getFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee74(e,t,n,s){var r,a;return _regenerator().w(function(_context74){while(1)switch(_context74.n){case 0:r=t.map(function(_ref61){var c=_ref61.fileId;return e.url="".concat(n).concat(c).concat(s),new Promise(function(l){l($t(e,void 0,"GET",!1));});});_context74.n=1;return Promise.all(r);case 1:a=_context74.v.map(function(c,l){return new Promise(function(d){var p=new FileReader();p.readAsDataURL(c),p.onload=function(u){d(_defineProperty(_defineProperty(_defineProperty({},T,u.target.result),"name",t[l].name),E,Ke.getType(t,l)));};});});_context74.n=2;return Promise.all(a);case 2:return _context74.a(2,_context74.v);}},_callee74);}));function getFiles(_x152,_x153,_x154,_x155){return _getFiles.apply(this,arguments);}return getFiles;}()},{key:"getFileName",value:function getFileName(e){var t=e.split("/");return t[t.length-1];}// prettier-ignore
155
151
  },{key:"getFilesAndNewText",value:function(){var _getFilesAndNewText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee75(e,t,n,s,r){var l,d,o,a,c,_t25;return _regenerator().w(function(_context75){while(1)switch(_context75.n){case 0:a=n.getFilesPrefix,c=n.getFilesPostfix;_t25=t.length>0;if(!_t25){_context75.n=2;break;}_context75.n=1;return Ke.getFiles(e,t,a,c);case 1:o=_context75.v;(l=r==null?void 0:r[h])!=null&&l.value&&o.forEach(function(p,u){var y;if(!p[T])return;var g=t[u].path;(y=r==null?void 0:r[h])!=null&&y.value&&g&&(r[h].value=r[h].value.replace(g,p[T]));});case 2:return _context75.a(2,(d=r==null?void 0:r[h])!=null&&d.value?_defineProperty(_defineProperty({},h,r[h].value),x,s):_defineProperty(_defineProperty({},b,o),x,s));}},_callee75);}));function getFilesAndNewText(_x156,_x157,_x158,_x159,_x160){return _getFilesAndNewText.apply(this,arguments);}return getFilesAndNewText;}()// Noticed an issue where text contains a sandbox hyperlink to a csv, but no annotation provided
156
152
  // To reproduce use the following text:
157
153
  // give example data for a csv and create a suitable bar chart for it with a link
@@ -160,33 +156,33 @@ _inherits(Hl,_Pt5);return _createClass(Hl,[{key:"processMessagesI",value:functio
160
156
  },{key:"getFileDetails",value:function getFileDetails(e,t){var s;var n=[];return(s=t==null?void 0:t[h])!=null&&s.value&&e.content.forEach(function(r){var o,a;(a=(o=r[h])==null?void 0:o.annotations)==null||a.forEach(function(c){var l;c[h]&&c[h].startsWith("sandbox:")&&(l=c.file_path)!=null&&l.file_id&&n.push({path:c[h],fileId:c.file_path.file_id,name:Ke.getFileName(c[h])});});}),t!=null&&t.image_file&&n.push({fileId:t.image_file.file_id}),n;}// prettier-ignore
161
157
  },{key:"getFilesAndText",value:function(){var _getFilesAndText=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee76(e,t,n,s){var r;return _regenerator().w(function(_context76){while(1)switch(_context76.n){case 0:r=Ke.getFileDetails(t,s);_context76.n=1;return Ke.getFilesAndNewText(e,r,n,t.role,s);case 1:return _context76.a(2,_context76.v);}},_callee76);}));function getFilesAndText(_x161,_x162,_x163,_x164){return _getFilesAndText.apply(this,arguments);}return getFilesAndText;}()},{key:"parseResult",value:function parseResult(e,t){var n=[];if(t)n=e.data;else for(var s=0;s<e.data.length;s+=1){var r=e.data[s];if(r.role===gt)n.push(r);else break;}return n.reverse();}// test this using this prompt and it should give 2 text mesages and a file:
162
158
  // "give example data for a csv and create a suitable bar chart"
163
- },{key:"parseMessages",value:function parseMessages(e,t,n){var s=[];return t.forEach(/*#__PURE__*/function(){var _ref60=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(r){return _regenerator().w(function(_context78){while(1)switch(_context78.n){case 0:r.content.filter(function(o){return!!o[h]||!!o.image_file;}).sort(function(o){return o[h]?-1:o.image_file?1:0;}).forEach(/*#__PURE__*/function(){var _ref61=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(o){return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:s.push(Ke.getFilesAndText(e,r,n,o));case 1:return _context77.a(2);}},_callee77);}));return function(_x166){return _ref61.apply(this,arguments);};}());case 1:return _context78.a(2);}},_callee78);}));return function(_x165){return _ref60.apply(this,arguments);};}()),Promise.all(s);}},{key:"processStreamMessages",value:function(){var _processStreamMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,n){return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:return _context79.a(2,Ke.parseMessages(e,[{content:t,role:gt}],n));}},_callee79);}));function processStreamMessages(_x167,_x168,_x169){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
159
+ },{key:"parseMessages",value:function parseMessages(e,t,n){var s=[];return t.forEach(/*#__PURE__*/function(){var _ref64=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee78(r){return _regenerator().w(function(_context78){while(1)switch(_context78.n){case 0:r.content.filter(function(o){return!!o[h]||!!o.image_file;}).sort(function(o){return o[h]?-1:o.image_file?1:0;}).forEach(/*#__PURE__*/function(){var _ref65=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee77(o){return _regenerator().w(function(_context77){while(1)switch(_context77.n){case 0:s.push(Ke.getFilesAndText(e,r,n,o));case 1:return _context77.a(2);}},_callee77);}));return function(_x166){return _ref65.apply(this,arguments);};}());case 1:return _context78.a(2);}},_callee78);}));return function(_x165){return _ref64.apply(this,arguments);};}()),Promise.all(s);}},{key:"processStreamMessages",value:function(){var _processStreamMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee79(e,t,n){return _regenerator().w(function(_context79){while(1)switch(_context79.n){case 0:return _context79.a(2,Ke.parseMessages(e,[{content:t,role:gt}],n));}},_callee79);}));function processStreamMessages(_x167,_x168,_x169){return _processStreamMessages.apply(this,arguments);}return processStreamMessages;}()// prettier-ignore
164
160
  },{key:"processAPIMessages",value:function(){var _processAPIMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee80(e,t,n,s){var r;return _regenerator().w(function(_context80){while(1)switch(_context80.n){case 0:r=Ke.parseResult(t,n);return _context80.a(2,Ke.parseMessages(e,r,s));}},_callee80);}));function processAPIMessages(_x170,_x171,_x172,_x173){return _processAPIMessages.apply(this,arguments);}return processAPIMessages;}()}]);}();Ke.FILES_WITH_TEXT_ERROR="content with type `text` must have `text` values",Ke.FUNCTION_TOOL_RESP_ERROR="Response must contain an array of strings for each individual function/tool_call, see ".concat(Z,"directConnection/OpenAI/#assistant-functions.");var St=Ke;var Ht=/*#__PURE__*/function(_k5){// prettier-ignore
165
- function Ht(e,t,n,s,r,o){var _this36;_classCallCheck(this,Ht);if(_this36=_callSuper(this,Ht,[e,s,r,o]),_this36.insertKeyPlaceholderText=_this36.genereteAPIKeyName("OpenAI"),_this36.keyHelpUrl=Nn,_this36.url="",_this36.permittedErrorPrefixes=[Ls,"Please send text",Ts.FAILED_ERROR_MESSAGE],_this36.shouldFetchHistory=!1,_this36._searchedForThreadId=!1,_this36._config={},_this36._newAssistantDetails={model:"gpt-4"},_this36._waitingForStreamResponse=!1,_this36._isSSEStream=!1,_this36.urlSegments=n,_typeof(t)=="object"){_this36._config=t;var _this36$_config=_this36._config,a=_this36$_config.new_assistant,c=_this36$_config.thread_id,l=_this36$_config.load_thread_history;Object.assign(_this36._newAssistantDetails,a),c&&(_this36.sessionId=c),l&&(_this36.shouldFetchHistory=!0);}_this36.maxMessages=1,_this36._isSSEStream=!!(_this36.stream&&(_typeof(_this36.stream)!="object"||!_this36.stream.simulation));return _this36;}_inherits(Ht,_k5);return _createClass(Ht,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(){var _this37=this;var e,_t26;return _regenerator().w(function(_context81){while(1)switch(_context81.p=_context81.n){case 0:setTimeout(function(){return _this37.deepChat.disableSubmitButton();},2);_context81.p=1;_context81.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context81.v;return _context81.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context81.p=3;_t26=_context81.v;return _context81.a(2,[_defineProperty({},f,Ho)]);}},_callee81,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processMessage",value:function processMessage(e,t){var n=this.totalMessagesMaxCharLength||-1,s=kn.getCharacterLimitMessages(e,n)[0];if(t&&t.length>0){var r=this.filesToolType;if(typeof this.filesToolType=="function"){var a=this.filesToolType(t.map(function(_ref63){var c=_ref63.name;return c;}));a==="code_interpreter"||a==="file_search"||a===ee?r=a:(console[f]("Tool type \"".concat(a,"\" is not valid")),console[f]('Expected "code_interpreter" or "file_search" or "images". Going to default to "images"'));}if(r==="file_search")return Ht.processAttachmentsMessage(s,t,"file_search");if(r==="code_interpreter")return Ht.processAttachmentsMessage(s,t,"code_interpreter");if(t.find(function(_ref64){var a=_ref64.name;return!Se.isImageFileExtension(a);}))console[f]("The uploaded files contained a non-image file"),console[f]('Make sure only images can be uploaded or define a "code_interpreter" or "file_search" value in the "files_tool_type" property'),console.warn('Make sure your existing assistant supports these "tools" or specify them in the "new_assistant" property');else{var _a3=Ht.processImageMessage(s,t);if(_a3)return _a3;}}return _defineProperty({content:s[h]||""},x,F);}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,n){var s=C(e),r=this.processMessage(t,n);return s.thread={messages:[r]},s;}},{key:"callService",value:function callService(e,t,n){if(this.messages=e,this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/messages").concat(this.urlSegments.createMessagePostfix);var s=this.processMessage(t,n);ge.request(this,s,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _s7=this.createNewThreadMessages(this.rawBody,t,n);this._isSSEStream?this.createStreamRun(_s7):ge.request(this,_s7,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(e,t,n){var _r$assistant_id;var r,s,_t27,_t28;return _regenerator().w(function(_context82){while(1)switch(_context82.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context82.n=1;break;}throw new Error(He);case 1:if(!((_r$assistant_id=(r=this.rawBody).assistant_id)!==null&&_r$assistant_id!==void 0)){_context82.n=2;break;}_r$assistant_id;_context82.n=5;break;case 2:_t27=this._config.assistant_id;if(_t27){_context82.n=4;break;}_context82.n=3;return this.createNewAssistant();case 3:_t27=_context82.v;case 4:r.assistant_id=_t27;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!n){_context82.n=7;break;}_context82.n=6;return St.storeFiles(this,e,n,this.urlSegments.storeFiles);case 6:_t28=_context82.v;_context82.n=8;break;case 7:_t28=void 0;case 8:s=_t28;this.connectSettings.method=ye,this.callService(e,t,s);case 9:return _context82.a(2);}},_callee82,this);}));function callServiceAPI(_x174,_x175,_x176){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(){var e,_t29;return _regenerator().w(function(_context83){while(1)switch(_context83.p=_context83.n){case 0:_context83.p=0;this.url=this.urlSegments.newAssistantUrl;_context83.n=1;return jt(this,C(this._newAssistantDetails),ye);case 1:e=_context83.v;return _context83.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context83.p=2;_t29=_context83.v;console[f](_t29),console[f]("Failed to create a new assistant");case 3:return _context83.a(2);}},_callee83,this,[[0,2]]);}));function createNewAssistant(){return _createNewAssistant.apply(this,arguments);}return createNewAssistant;}()},{key:"searchPreviousMessagesForThreadId",value:function searchPreviousMessagesForThreadId(e){var t=e.find(function(_ref66){var _ref67=_slicedToArray(_ref66,1),n=_ref67[0];return n._sessionId;});t&&(this.sessionId=t[0]._sessionId),this._searchedForThreadId=!0;}},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(e){var s,t,n;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context84.n=2;break;}_context84.n=1;return this.handleStream(e);case 1:return _context84.a(2,_context84.v);case 2:if(!e[f]){_context84.n=3;break;}throw e[f].message.startsWith(St.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e[f].message;case 3:this.asyncCallInProgress=!0;_context84.n=4;return this.assignThreadAndRun(e);case 4:t="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs/").concat(this.run_id).concat(this.urlSegments.threadsPosfix),n={method:ue,headers:(s=this.connectSettings)==null?void 0:s.headers};return _context84.a(2,(ge.executePollRequest(this,t,n,this.messages),_defineProperty({},h,"")));}},_callee84,this);}));function extractResultData(_x177){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var t;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:if(!this.sessionId){_context85.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context85.n=1;return jt(this,C(this.rawBody),ye);case 1:t=_context85.v;this.run_id=t.id;_context85.n=3;break;case 2:this.sessionId=e.thread_id,this.run_id=e.id,this.updateSessionId(this.sessionId);case 3:return _context85.a(2);}},_callee85,this);}));function assignThreadAndRun(_x178){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){var t,s,r,n,_args86=arguments,_t30;return _regenerator().w(function(_context86){while(1)switch(_context86.n){case 0:t=_args86.length>1&&_args86[1]!==undefined?_args86[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context86.n=1;return jt(this,{},ue);case 1:n=_context86.v;_t30=!t&&this.deepChat.responseInterceptor;if(!_t30){_context86.n=3;break;}_context86.n=2;return(r=(s=this.deepChat).responseInterceptor)==null?void 0:r.call(s,n);case 2:n=_context86.v;case 3:return _context86.a(2,St.processAPIMessages(this,n,t,this.urlSegments));}},_callee86,this);}));function getThreadMessages(_x179){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var _this38=this;var r,t,n,o,_o$shift,a,c,s;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:t=e.status,n=e.required_action;if(!(t==="queued"||t==="in_progress")){_context87.n=1;break;}return _context87.a(2,{timeoutMS:Ht.POLLING_TIMEOUT_MS});case 1:if(!(t===lr&&this.messages)){_context87.n=3;break;}_context87.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context87.v;_o$shift=o.shift();a=_o$shift.text;c=_o$shift.files;return _context87.a(2,(setTimeout(function(){o.forEach(function(l){return _this38.deepChat.addMessage(l);});}),_defineProperty({text:a,_sessionId:this.sessionId},b,c)));case 3:s=(r=n==null?void 0:n.submit_tool_outputs)==null?void 0:r.tool_calls;if(!(t==="requires_action"&&s)){_context87.n=5;break;}_context87.n=4;return this.handleTools(s);case 4:return _context87.a(2,_context87.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context87.a(2);}},_callee87,this);}));function extractPollResultData(_x180){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
166
- },{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){var t,n,s,r,o,a;return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:if(this._functionHandlerI){_context88.n=1;break;}throw Error(qt);case 1:t=e.map(function(c){return{name:c["function"].name,arguments:c["function"].arguments};});_context88.n=2;return this._functionHandlerI(t);case 2:n=_context88.v;if(!(!Array.isArray(n)||e.length!==n.length)){_context88.n=3;break;}throw Error(St.FUNCTION_TOOL_RESP_ERROR);case 3:_context88.n=4;return Promise.all(n);case 4:s=_context88.v;if(!s.find(function(c){return _typeof(c)!==Ee;})){_context88.n=5;break;}throw Error(St.FUNCTION_TOOL_RESP_ERROR);case 5:r=s.map(function(c,l){return{tool_call_id:e[l].id,output:c};}),o="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId),a="/runs/".concat(this.run_id,"/submit_tool_outputs").concat(this.urlSegments.threadsPosfix);this.url="".concat(o).concat(a);if(!this._isSSEStream){_context88.n=7;break;}_context88.n=6;return this.createStreamRun({tool_outputs:r});case 6:_context88.n=8;break;case 7:_context88.n=8;return jt(this,{tool_outputs:r},ye);case 8:return _context88.a(2,{timeoutMS:Ht.POLLING_TIMEOUT_MS});}},_callee88,this);}));function handleTools(_x181){return _handleTools.apply(this,arguments);}return handleTools;}()},{key:"handleStream",value:function(){var _handleStream=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(e){var n,s,t,r;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:t=(s=(n=e.required_action)==null?void 0:n.submit_tool_outputs)==null?void 0:s.tool_calls;if(!(e.status==="requires_action"&&t)){_context89.n=2;break;}this.run_id=e.id;_context89.n=1;return this.handleTools(t);case 1:return _context89.a(2,_context89.v);case 2:if(!this._waitingForStreamResponse){_context89.n=3;break;}return _context89.a(2,this.parseStreamResult(e));case 3:if(this._isSSEStream&&this.sessionId){this.asyncCallInProgress=!0,this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);r=C(this.rawBody);this.createStreamRun(r);}return _context89.a(2,_defineProperty({},h,""));}},_callee89,this);}));function handleStream(_x182){return _handleStream.apply(this,arguments);}return handleStream;}()// prettier-ignore
161
+ function Ht(e,t,n,s,r,o){var _this36;_classCallCheck(this,Ht);if(_this36=_callSuper(this,Ht,[e,s,r,o]),_this36.insertKeyPlaceholderText=_this36.genereteAPIKeyName("OpenAI"),_this36.keyHelpUrl=Nn,_this36.url="",_this36.permittedErrorPrefixes=[Ps,"Please send text",Cs.FAILED_ERROR_MESSAGE],_this36.shouldFetchHistory=!1,_this36._searchedForThreadId=!1,_this36._config={},_this36._newAssistantDetails={model:"gpt-4"},_this36._waitingForStreamResponse=!1,_this36._isSSEStream=!1,_this36.urlSegments=n,_typeof(t)=="object"){_this36._config=t;var _this36$_config=_this36._config,a=_this36$_config.new_assistant,c=_this36$_config.thread_id,l=_this36$_config.load_thread_history;Object.assign(_this36._newAssistantDetails,a),c&&(_this36.sessionId=c),l&&(_this36.shouldFetchHistory=!0);}_this36.maxMessages=1,_this36._isSSEStream=!!(_this36.stream&&(_typeof(_this36.stream)!="object"||!_this36.stream.simulation));return _this36;}_inherits(Ht,_k5);return _createClass(Ht,[{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee81(){var _this37=this;var e,_t26;return _regenerator().w(function(_context81){while(1)switch(_context81.p=_context81.n){case 0:setTimeout(function(){return _this37.deepChat.disableSubmitButton();},2);_context81.p=1;_context81.n=2;return this.getThreadMessages(this.sessionId,!0);case 2:e=_context81.v;return _context81.a(2,(this.deepChat.disableSubmitButton(!1),e));case 3:_context81.p=3;_t26=_context81.v;return _context81.a(2,[_defineProperty({},f,Uo)]);}},_callee81,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processMessage",value:function processMessage(e,t){var n=this.totalMessagesMaxCharLength||-1,s=kn.getCharacterLimitMessages(e,n)[0];if(t&&t.length>0){var r=this.filesToolType;if(typeof this.filesToolType=="function"){var a=this.filesToolType(t.map(function(_ref67){var c=_ref67.name;return c;}));a==="code_interpreter"||a==="file_search"||a===ee?r=a:(console[f]("Tool type \"".concat(a,"\" is not valid")),console[f]('Expected "code_interpreter" or "file_search" or "images". Going to default to "images"'));}if(r==="file_search")return Ht.processAttachmentsMessage(s,t,"file_search");if(r==="code_interpreter")return Ht.processAttachmentsMessage(s,t,"code_interpreter");if(t.find(function(_ref68){var a=_ref68.name;return!Se.isImageFileExtension(a);}))console[f]("The uploaded files contained a non-image file"),console[f]('Make sure only images can be uploaded or define a "code_interpreter" or "file_search" value in the "files_tool_type" property'),console.warn('Make sure your existing assistant supports these "tools" or specify them in the "new_assistant" property');else{var _a3=Ht.processImageMessage(s,t);if(_a3)return _a3;}}return _defineProperty({content:s[h]||""},x,F);}},{key:"createNewThreadMessages",value:function createNewThreadMessages(e,t,n){var s=C(e),r=this.processMessage(t,n);return s.thread={messages:[r]},s;}},{key:"callService",value:function callService(e,t,n){if(this.messages=e,this.sessionId){this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/messages").concat(this.urlSegments.createMessagePostfix);var s=this.processMessage(t,n);ge.request(this,s,e);}else{this.url="".concat(this.urlSegments.threadsPrefix,"/runs").concat(this.urlSegments.threadsPosfix);var _s7=this.createNewThreadMessages(this.rawBody,t,n);this._isSSEStream?this.createStreamRun(_s7):ge.request(this,_s7,e);}}},{key:"callServiceAPI",value:function(){var _callServiceAPI1=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee82(e,t,n){var _r$assistant_id;var r,s,_t27,_t28;return _regenerator().w(function(_context82){while(1)switch(_context82.n){case 0:if(!(this._waitingForStreamResponse=!1,!this.connectSettings)){_context82.n=1;break;}throw new Error(He);case 1:if(!((_r$assistant_id=(r=this.rawBody).assistant_id)!==null&&_r$assistant_id!==void 0)){_context82.n=2;break;}_r$assistant_id;_context82.n=5;break;case 2:_t27=this._config.assistant_id;if(_t27){_context82.n=4;break;}_context82.n=3;return this.createNewAssistant();case 3:_t27=_context82.v;case 4:r.assistant_id=_t27;case 5:this._searchedForThreadId||this.searchPreviousMessagesForThreadId(e.messageToElements);if(!n){_context82.n=7;break;}_context82.n=6;return St.storeFiles(this,e,n,this.urlSegments.storeFiles);case 6:_t28=_context82.v;_context82.n=8;break;case 7:_t28=void 0;case 8:s=_t28;this.connectSettings.method=ye,this.callService(e,t,s);case 9:return _context82.a(2);}},_callee82,this);}));function callServiceAPI(_x174,_x175,_x176){return _callServiceAPI1.apply(this,arguments);}return callServiceAPI;}()},{key:"createNewAssistant",value:function(){var _createNewAssistant=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee83(){var e,_t29;return _regenerator().w(function(_context83){while(1)switch(_context83.p=_context83.n){case 0:_context83.p=0;this.url=this.urlSegments.newAssistantUrl;_context83.n=1;return $t(this,C(this._newAssistantDetails),ye);case 1:e=_context83.v;return _context83.a(2,(this._config.assistant_id=e.id,this._config.assistant_id));case 2:_context83.p=2;_t29=_context83.v;console[f](_t29),console[f]("Failed to create a new assistant");case 3:return _context83.a(2);}},_callee83,this,[[0,2]]);}));function createNewAssistant(){return _createNewAssistant.apply(this,arguments);}return createNewAssistant;}()},{key:"searchPreviousMessagesForThreadId",value:function searchPreviousMessagesForThreadId(e){var t=e.find(function(_ref70){var _ref71=_slicedToArray(_ref70,1),n=_ref71[0];return n._sessionId;});t&&(this.sessionId=t[0]._sessionId),this._searchedForThreadId=!0;}},{key:"extractResultData",value:function(){var _extractResultData12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee84(e){var s,t,n;return _regenerator().w(function(_context84){while(1)switch(_context84.n){case 0:if(!(this._waitingForStreamResponse||this._isSSEStream&&this.sessionId)){_context84.n=2;break;}_context84.n=1;return this.handleStream(e);case 1:return _context84.a(2,_context84.v);case 2:if(!e[f]){_context84.n=3;break;}throw e[f].message.startsWith(St.FILES_WITH_TEXT_ERROR)?Error("Please send text with your file(s)"):e[f].message;case 3:this.asyncCallInProgress=!0;_context84.n=4;return this.assignThreadAndRun(e);case 4:t="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs/").concat(this.run_id).concat(this.urlSegments.threadsPosfix),n={method:ue,headers:(s=this.connectSettings)==null?void 0:s.headers};return _context84.a(2,(ge.executePollRequest(this,t,n,this.messages),_defineProperty({},h,"")));}},_callee84,this);}));function extractResultData(_x177){return _extractResultData12.apply(this,arguments);}return extractResultData;}()},{key:"assignThreadAndRun",value:function(){var _assignThreadAndRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee85(e){var t;return _regenerator().w(function(_context85){while(1)switch(_context85.n){case 0:if(!this.sessionId){_context85.n=2;break;}this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);_context85.n=1;return $t(this,C(this.rawBody),ye);case 1:t=_context85.v;this.run_id=t.id;_context85.n=3;break;case 2:this.sessionId=e.thread_id,this.run_id=e.id,this.updateSessionId(this.sessionId);case 3:return _context85.a(2);}},_callee85,this);}));function assignThreadAndRun(_x178){return _assignThreadAndRun.apply(this,arguments);}return assignThreadAndRun;}()},{key:"getThreadMessages",value:function(){var _getThreadMessages=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee86(e){var t,s,r,n,_args86=arguments,_t30;return _regenerator().w(function(_context86){while(1)switch(_context86.n){case 0:t=_args86.length>1&&_args86[1]!==undefined?_args86[1]:!1;this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(e,"/messages?").concat(this.urlSegments.listMessagesPostfix);_context86.n=1;return $t(this,{},ue);case 1:n=_context86.v;_t30=!t&&this.deepChat.responseInterceptor;if(!_t30){_context86.n=3;break;}_context86.n=2;return(r=(s=this.deepChat).responseInterceptor)==null?void 0:r.call(s,n);case 2:n=_context86.v;case 3:return _context86.a(2,St.processAPIMessages(this,n,t,this.urlSegments));}},_callee86,this);}));function getThreadMessages(_x179){return _getThreadMessages.apply(this,arguments);}return getThreadMessages;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee87(e){var _this38=this;var r,t,n,o,_o$shift,a,c,s;return _regenerator().w(function(_context87){while(1)switch(_context87.n){case 0:t=e.status,n=e.required_action;if(!(t==="queued"||t==="in_progress")){_context87.n=1;break;}return _context87.a(2,{timeoutMS:Ht.POLLING_TIMEOUT_MS});case 1:if(!(t===cr&&this.messages)){_context87.n=3;break;}_context87.n=2;return this.getThreadMessages(e.thread_id);case 2:o=_context87.v;_o$shift=o.shift();a=_o$shift.text;c=_o$shift.files;return _context87.a(2,(setTimeout(function(){o.forEach(function(l){return _this38.deepChat.addMessage(l);});}),_defineProperty({text:a,_sessionId:this.sessionId},b,c)));case 3:s=(r=n==null?void 0:n.submit_tool_outputs)==null?void 0:r.tool_calls;if(!(t==="requires_action"&&s)){_context87.n=5;break;}_context87.n=4;return this.handleTools(s);case 4:return _context87.a(2,_context87.v);case 5:throw Error("Thread run status: ".concat(t));case 6:return _context87.a(2);}},_callee87,this);}));function extractPollResultData(_x180){return _extractPollResultData4.apply(this,arguments);}return extractPollResultData;}()// prettier-ignore
162
+ },{key:"handleTools",value:function(){var _handleTools=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee88(e){var t,n,s,r,o,a;return _regenerator().w(function(_context88){while(1)switch(_context88.n){case 0:if(this._functionHandlerI){_context88.n=1;break;}throw Error(Gt);case 1:t=e.map(function(c){return{name:c["function"].name,arguments:c["function"].arguments};});_context88.n=2;return this._functionHandlerI(t);case 2:n=_context88.v;if(!(!Array.isArray(n)||e.length!==n.length)){_context88.n=3;break;}throw Error(St.FUNCTION_TOOL_RESP_ERROR);case 3:_context88.n=4;return Promise.all(n);case 4:s=_context88.v;if(!s.find(function(c){return _typeof(c)!==Ee;})){_context88.n=5;break;}throw Error(St.FUNCTION_TOOL_RESP_ERROR);case 5:r=s.map(function(c,l){return{tool_call_id:e[l].id,output:c};}),o="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId),a="/runs/".concat(this.run_id,"/submit_tool_outputs").concat(this.urlSegments.threadsPosfix);this.url="".concat(o).concat(a);if(!this._isSSEStream){_context88.n=7;break;}_context88.n=6;return this.createStreamRun({tool_outputs:r});case 6:_context88.n=8;break;case 7:_context88.n=8;return $t(this,{tool_outputs:r},ye);case 8:return _context88.a(2,{timeoutMS:Ht.POLLING_TIMEOUT_MS});}},_callee88,this);}));function handleTools(_x181){return _handleTools.apply(this,arguments);}return handleTools;}()},{key:"handleStream",value:function(){var _handleStream=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee89(e){var n,s,t,r;return _regenerator().w(function(_context89){while(1)switch(_context89.n){case 0:t=(s=(n=e.required_action)==null?void 0:n.submit_tool_outputs)==null?void 0:s.tool_calls;if(!(e.status==="requires_action"&&t)){_context89.n=2;break;}this.run_id=e.id;_context89.n=1;return this.handleTools(t);case 1:return _context89.a(2,_context89.v);case 2:if(!this._waitingForStreamResponse){_context89.n=3;break;}return _context89.a(2,this.parseStreamResult(e));case 3:if(this._isSSEStream&&this.sessionId){this.asyncCallInProgress=!0,this.url="".concat(this.urlSegments.threadsPrefix,"/").concat(this.sessionId,"/runs").concat(this.urlSegments.threadsPosfix);r=C(this.rawBody);this.createStreamRun(r);}return _context89.a(2,_defineProperty({},h,""));}},_callee89,this);}));function handleStream(_x182){return _handleStream.apply(this,arguments);}return handleStream;}()// prettier-ignore
167
163
  },{key:"parseStreamResult",value:function(){var _parseStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee90(e){var t,n,s,r,o,a,c,l,_a4,_c4;return _regenerator().w(function(_context90){while(1)switch(_context90.n){case 0:if(!(e.content&&e.content.length>0&&this.messages)){_context90.n=1;break;}a=e.content.find(function(c){return c[h];});if(!((t=a==null?void 0:a[h])!=null&&t.annotations&&a[h].annotations.length>0)){_context90.n=1;break;}c=e.content.find(function(d){return!!d[h];})||e.content[0],l=St.getFilesAndText.bind(this,this,_defineProperty(_defineProperty({},x,gt),"content",e.content),this.urlSegments,c);return _context90.a(2,((n=this._messageStream)==null||n.endStreamAfterFileDownloaded(this.messages,l),_defineProperty({},h,"")));case 1:if(!((s=e.delta)!=null&&s.content)){_context90.n=4;break;}if(!(e.delta.content.length>1)){_context90.n=3;break;}_a4=e.delta.content.find(function(c){return c[h];});if(!((r=_a4==null?void 0:_a4[h])!=null&&r.annotations&&_a4[h].annotations.length===0)){_context90.n=3;break;}_context90.n=2;return St.processStreamMessages(this,e.delta.content,this.urlSegments);case 2:_c4=_context90.v;return _context90.a(2,_defineProperty(_defineProperty({},h,_c4[0][h]),b,_c4[1][b]));case 3:return _context90.a(2,_defineProperty({},h,(o=e.delta.content[0][h])==null?void 0:o.value));case 4:return _context90.a(2,(!this.sessionId&&e.thread_id&&(this.sessionId=e.thread_id),_defineProperty({},h,"")));}},_callee90,this);}));function parseStreamResult(_x183){return _parseStreamResult.apply(this,arguments);}return parseStreamResult;}()// https://platform.openai.com/docs/api-reference/assistants-streaming
168
164
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
- },{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context91.n=1;return V.request(this,e,this.messages,!0,!0);case 1:this._messageStream=_context91.v;case 2:return _context91.a(2);}},_callee91,this);}));function createStreamRun(_x184){return _createStreamRun.apply(this,arguments);}return createStreamRun;}()}],[{key:"processImageMessage",value:function processImageMessage(e,t){var n=t==null?void 0:t.filter(function(s){return Se.isImageFileExtension(s.name);}).map(function(s){return _defineProperty(_defineProperty({},E,"image_file"),"image_file",{file_id:s.id});});if(n&&n.length>0)return e[h]&&e[h].length>0&&n.push(_defineProperty(_defineProperty({},E,h),h,e[h])),_defineProperty({content:n},x,F);}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,n){return _defineProperty({attachments:t.map(function(r){return{tools:[_defineProperty({},E,n)],file_id:r.id};}),content:[_defineProperty(_defineProperty({},E,h),h,e[h])]},x,F);}}]);}(k);Ht.POLLING_TIMEOUT_MS=500;var si=Ht;var yr=/*#__PURE__*/function(_si){function yr(e){var _a$headers,_c$OpenAIBeta;var _this39;_classCallCheck(this,yr);var o,a,c,l,d;var t=C(e.directConnection),n=t.openAI,s=(o=t.openAI)==null?void 0:o.assistant,r=yr.buildUrlSegments(s);if(_this39=_callSuper(this,yr,[e,s,r,Dn(),Bn,n]),(_a$headers=(a=_this39.connectSettings).headers)!==null&&_a$headers!==void 0?_a$headers:a.headers={},(_c$OpenAIBeta=(c=_this39.connectSettings.headers)["OpenAI-Beta"])!==null&&_c$OpenAIBeta!==void 0?_c$OpenAIBeta:c["OpenAI-Beta"]="assistants=v2",_this39.shouldFetchHistory&&_this39.sessionId&&(_this39.fetchHistory=_this39.fetchHistoryFunc.bind(_assertThisInitialized(_this39))),_typeof(s)===U){var _ref80=(d=(l=e.directConnection)==null?void 0:l.openAI)==null?void 0:d.assistant,p=_ref80.function_handler,u=_ref80.files_tool_type;p&&(_this39._functionHandlerI=p),u&&(_this39.filesToolType=u);}return _this39;}_inherits(yr,_si);return _createClass(yr,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||Ze;return{threadsPrefix:"".concat(t,"/threads"),threadsPosfix:"",newAssistantUrl:"".concat(t,"/assistants"),createMessagePostfix:"",listMessagesPostfix:"order=desc",storeFiles:"".concat(t,"/").concat(b),getFilesPrefix:"".concat(t,"/").concat(b,"/"),getFilesPostfix:"/content"};}}]);}(si);var ii="Please define the Azure URL Details. [More Information](".concat(Z,"directConnection/Azure)"),ta=function ta(i){return _defineProperty({"api-key":i},q,te);},na=function na(i){return be("".concat(i.endpoint,"/openai/models?api-version=").concat(i.version),ue,ea);},sa=function sa(i){var e=i.endpoint,t=i.version,n=i.deploymentId;return e&&t&&n;},xn=/*#__PURE__*/function(_si2){function xn(e){var _S$headers;var _this40;_classCallCheck(this,xn);var l,d,p,u,g,y,_,S;var t=C(e.directConnection),n=t.azure,s=(l=t.azure)==null?void 0:l.openAI,r=(s==null?void 0:s.urlDetails)||{},o="".concat((d=s==null?void 0:s.urlDetails)==null?void 0:d.endpoint,"/openai/"),a="?api-version=".concat((p=s==null?void 0:s.urlDetails)==null?void 0:p.version),c={threadsPrefix:"".concat(o).concat(xn.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(xn.NEW_ASSISTANT_RESOURCE).concat(a),createMessagePostfix:a,listMessagesPostfix:"order=desc&api-version=".concat((u=s==null?void 0:s.urlDetails)==null?void 0:u.version),storeFiles:"".concat(o).concat(b).concat(a),getFilesPrefix:"".concat(o).concat(b,"/"),getFilesPostfix:"/content".concat(a)};if(_this40=_callSuper(this,xn,[e,s==null?void 0:s.assistant,c,na(r),ta,n]),_this40.permittedErrorPrefixes=[ii],_this40.insertKeyPlaceholderText=_this40.genereteAPIKeyName("Azure OpenAI"),_this40.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",_this40.isTextInputDisabled=!1,_typeof(s==null?void 0:s.assistant)===U){var _ref82=(_=(y=(g=e.directConnection)==null?void 0:g.azure)==null?void 0:y.openAI)==null?void 0:_.assistant,M=_ref82.function_handler,K=_ref82.files_tool_type;M&&(_this40._functionHandlerI=M),K&&(_this40.filesToolType=K);}sa(r)?(_S$headers=(S=_this40.connectSettings).headers)!==null&&_S$headers!==void 0?_S$headers:S.headers={}:(_this40.isTextInputDisabled=!0,_this40.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,ii));}));return _this40;}_inherits(xn,_si2);return _createClass(xn);}(si);xn.THREAD_RESOURCE="threads",xn.NEW_ASSISTANT_RESOURCE="assistants";var Wi=xn;var Kl="sts-session-started",Wl="sts-session-stopped";var me=/*#__PURE__*/function(){function me(){_classCallCheck(this,me);}return _createClass(me,null,[{key:"addAttributes",value:function addAttributes(e){e[x]="button",e.setAttribute("tabindex","0");}},{key:"addAriaBusy",value:function addAriaBusy(e){e.setAttribute("aria-busy","true");}},{key:"removeAriaBusy",value:function removeAriaBusy(e){e.removeAttribute("aria-busy");}},{key:"addAriaDisabled",value:function addAriaDisabled(e){e.setAttribute("aria-".concat(j),"true");}},{key:"removeAriaDisabled",value:function removeAriaDisabled(e){e.removeAttribute("aria-".concat(j));}},{key:"removeAriaAttributes",value:function removeAriaAttributes(e){me.removeAriaBusy(e),me.removeAriaDisabled(e);}}]);}();var ia="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<svg height=\"1.4em\" width=\"1.4em\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n\t viewBox=\"0 0 490.9 490.9\" xml:space=\"preserve\">\n\t<g>\n\t\t<g>\n\t\t\t<path d=\"M245.5,322.9c53,0,96.2-43.2,96.2-96.2V96.2c0-53-43.2-96.2-96.2-96.2s-96.2,43.2-96.2,96.2v130.5\n\t\t\t\tC149.3,279.8,192.5,322.9,245.5,322.9z M173.8,96.2c0-39.5,32.2-71.7,71.7-71.7s71.7,32.2,71.7,71.7v130.5\n\t\t\t\tc0,39.5-32.2,71.7-71.7,71.7s-71.7-32.2-71.7-71.7V96.2z\"/>\n\t\t\t<path d=\"M94.4,214.5c-6.8,0-12.3,5.5-12.3,12.3c0,85.9,66.7,156.6,151.1,162.8v76.7h-63.9c-6.8,0-12.3,5.5-12.3,12.3\n\t\t\t\ts5.5,12.3,12.3,12.3h152.3c6.8,0,12.3-5.5,12.3-12.3s-5.5-12.3-12.3-12.3h-63.9v-76.7c84.4-6.3,151.1-76.9,151.1-162.8\n\t\t\t\tc0-6.8-5.5-12.3-12.3-12.3s-12.3,5.5-12.3,12.3c0,76.6-62.3,138.9-138.9,138.9s-138.9-62.3-138.9-138.9\n\t\t\t\tC106.6,220,101.2,214.5,94.4,214.5z\"/>\n\t\t</g>\n\t</g>\n</svg>\n",We=/*#__PURE__*/function(){function We(){_classCallCheck(this,We);}return _createClass(We,null,[{key:"createTextElement",value:function createTextElement(e){var t=A();return t[m].add(We.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,n,s){n?e.push(kt.createSVGElement(n)):n!==""&&s&&e.push(t);}},{key:"createCustomElements",value:function createCustomElements(e,t,n){var c,l;var s=n==null?void 0:n[e],r=(c=s==null?void 0:s[h])==null?void 0:c.content,o=(l=s==null?void 0:s[G])==null?void 0:l.content,a=[];return We.tryAddSVGElement(a,t,o,r),r&&a.push(We.createTextElement(r)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e[m].remove(We.INPUT_BUTTON_SVG_CLASS,We.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(n){return n[m].contains(We.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e[m].add(We.INPUT_BUTTON_SVG_TEXT_CLASS):e[m].add(We.INPUT_BUTTON_SVG_CLASS);}}]);}();We.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",We.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",We.INPUT_BUTTON_SVG_CLASS="input-button-svg";var Et=We;var ps=/*#__PURE__*/function(){function ps(){_classCallCheck(this,ps);}return _createClass(ps,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return _defineProperty(_defineProperty({},G,e.find(function(t){return t.tagName.toLowerCase()===G;})),h,e.find(function(t){return t.tagName.toLowerCase()==="div";}));}}]);}();var xe=/*#__PURE__*/function(){function xe(){_classCallCheck(this,xe);}return _createClass(xe,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var r,o;t.container&&ce.unsetAllCSSMouseStates(e,t.container);var _ps$parseSVGTextEleme=ps.parseSVGTextElements(Array.from(e.children)),n=_ps$parseSVGTextEleme.svg,s=_ps$parseSVGTextEleme.text;(r=t[G])!=null&&r[R]&&n&&ce.unsetAllCSSMouseStates(n,t[G][R]),(o=t[h])!=null&&o[R]&&s&&ce.unsetAllCSSMouseStates(s,t[h][R]);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var r,o;t.container&&ce.unsetActivityCSSMouseStates(e,t.container);var _ps$parseSVGTextEleme2=ps.parseSVGTextElements(Array.from(e.children)),n=_ps$parseSVGTextEleme2.svg,s=_ps$parseSVGTextEleme2.text;(r=t[G])!=null&&r[R]&&n&&ce.unsetActivityCSSMouseStates(n,t[G][R]),(o=t[h])!=null&&o[R]&&s&&ce.unsetActivityCSSMouseStates(s,t[h][R]);}},{key:"setElementsCSS",value:function setElementsCSS(e,t,n){var o,a,c,l,d;Object.assign(e[v],(o=t.container)==null?void 0:o[n]);var _ps$parseSVGTextEleme3=ps.parseSVGTextElements(Array.from(e.children)),s=_ps$parseSVGTextEleme3.svg,r=_ps$parseSVGTextEleme3.text;s&&Object.assign(s[v],(c=(a=t[G])==null?void 0:a[R])==null?void 0:c[n]),r&&Object.assign(r[v],(d=(l=t[h])==null?void 0:l[R])==null?void 0:d[n]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,n){xe.setElementsCSS(e,t,w),n!==w&&(xe.setElementsCSS(e,t,De),n!==De&&xe.setElementsCSS(e,t,J));}}]);}();var mn=/*#__PURE__*/function(){// prettier-ignore
170
- function mn(e,t,n,s,r,o){_classCallCheck(this,mn);this._mouseState={state:"default"},this.isCustom=!1,me.addAttributes(e),this.elementRef=e,this[G]=kt.createSVGElement(t),this.customStyles=r,this.position=de.processPosition(n),this._tooltipSettings=s,this.dropupText=o;}return _createClass(mn,[{key:"buttonMouseLeave",value:function buttonMouseLeave(e){var t;this._mouseState.state=w,((t=this._activeTooltip)==null?void 0:t.element[v].visibility)==="visible"&&this._tooltipSettings&&ut.hide(this._activeTooltip,this._tooltipSettings),e&&(xe.unsetAllCSS(this.elementRef,e),xe.setElementsCSS(this.elementRef,e,w));}},{key:"buttonMouseEnter",value:function buttonMouseEnter(e){var t;this._mouseState.state=De,this._tooltipSettings&&(this._activeTooltip=ut.display(this.elementRef,this._tooltipSettings,(t=this._activeTooltip)==null?void 0:t.element)),e&&xe.setElementsCSS(this.elementRef,e,De);}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&xe.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state=J,e&&xe.setElementsCSS(this.elementRef,e,J);}// be careful not to use onclick as that is used for button functionality
171
- },{key:"setEvents",value:function setEvents(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 unsetCustomStateStyles(e){if(this.customStyles)for(var t=0;t<e.length;t+=1){var _n2=e[t],s=_n2&&this.customStyles[_n2];s&&xe.unsetActionCSS(this.elementRef,s);}}},{key:"reapplyStateStyle",value:function reapplyStateStyle(e,t){if(!this.customStyles)return;t&&this.unsetCustomStateStyles(t);var n=this.customStyles[e];n&&xe.setElementCssUpToState(this.elementRef,n,this._mouseState.state),this.setEvents(n);}},{key:"changeElementsByState",value:function changeElementsByState(e){var _this$elementRef;(_this$elementRef=this.elementRef).replaceChildren.apply(_this$elementRef,_toConsumableArray(e)),Et.reassignClassBasedOnChildren(this.elementRef,e);}},{key:"buildDefaultIconElement",value:function buildDefaultIconElement(e){var t=this[G].cloneNode(!0);return t.id=e,[t];}},{key:"createInnerElements",value:function createInnerElements(e,t,n){var s=Et.createCustomElements(t,this[G],n);if(s&&s.length>0){if(this.position===et){var r=s[0].cloneNode(!0);r.id=s[0]===this[G]?e:"dropup-menu-item-icon-element-custom",s[0]=r;}return s;}return this.buildDefaultIconElement(e);}}]);}();var bi=/*#__PURE__*/function(_mn){function bi(e){var _this41;_classCallCheck(this,bi);var n,s;var t=((s=(n=e==null?void 0:e[w])==null?void 0:n[G])==null?void 0:s.content)||bi.EMPTY_SVG;_this41=_callSuper(this,bi,[A(),t,void 0,void 0,e]),_this41.isActive=!1,_this41._innerElements=_this41.createInnerElementsForStates(_this41.customStyles),_this41.changeToDefault();return _this41;}_inherits(bi,_mn);return _createClass(bi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty(_defineProperty(_defineProperty({},w,this.createInnerButtonElements(w,e)),H,this.createInnerButtonElements(H,e)),Nt,this.createInnerButtonElements(Nt,e));}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return Et.createCustomElements(e,this[G],t)||[this[G]];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef[m].replace(Et.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements[H]),this.reapplyStateStyle(H,[Nt,w]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,n,s;this.changeState(this._innerElements[w]),(e=this.customStyles)!=null&&e[H]&&xe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[H]),(n=this.customStyles)!=null&&n[Nt]&&xe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[Nt]),this.reapplyStateStyle(w,[H,Nt]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,n,s;this.changeState(this._innerElements[Nt]),(e=this.customStyles)!=null&&e[H]&&xe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[H]),(n=this.customStyles)!=null&&n[w]&&xe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[w]),this.reapplyStateStyle(Nt,[w,H]),this.isActive=!1;}}]);}(mn);bi.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var ri=bi;var Pe=/*#__PURE__*/function(){function Pe(){_classCallCheck(this,Pe);}return _createClass(Pe,null,[{key:"setPropertyValueIfDoesNotExist",value:function setPropertyValueIfDoesNotExist(e,t,n){var _e$s,_e$s2;var s=t[0];t.length===1?(_e$s=e[s])!==null&&_e$s!==void 0?_e$s:e[s]=n:((_e$s2=e[s])!==null&&_e$s2!==void 0?_e$s2:e[s]={},t.shift(),Pe.setPropertyValueIfDoesNotExist(e[s],t,n));}},{key:"setPropertyValue",value:function setPropertyValue(e,t,n){var _e$s3;var s=t[0];t.length===1?e[s]=n:((_e$s3=e[s])!==null&&_e$s3!==void 0?_e$s3:e[s]={},t.shift(),Pe.setPropertyValue(e[s],t,n));}},{key:"getObjectValue",value:function getObjectValue(e,t){var n=t[0],s=e[n];return s===void 0||t.length===1?s:Pe.getObjectValue(s,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,n){var s=Pe.getObjectValue(t,n);if(s){var r=_objectSpread(_objectSpread({},s),Pe.getObjectValue(e,n)||{});Pe.setPropertyValue(e,n,r);}}},{key:"isJson",value:function isJson(e){try{return le(e),!0;}catch(_unused8){return!1;}}// prettier-ignore
172
- },{key:"assignPropertyFromOneToAnother",value:function assignPropertyFromOneToAnother(e,t,n){var _t$e;(_t$e=t[e])!==null&&_t$e!==void 0?_t$e:t[e]={},Object.assign(t[e],n==null?void 0:n[e]);}}]);}();var ra="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M5.92 24.096q0 1.088 0.928 1.728 0.512 0.288 1.088 0.288 0.448 0 0.896-0.224l16.16-8.064q0.48-0.256 0.8-0.736t0.288-1.088-0.288-1.056-0.8-0.736l-16.16-8.064q-0.448-0.224-0.896-0.224-0.544 0-1.088 0.288-0.928 0.608-0.928 1.728v16.16z\"></path>\n</svg>",Xi="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M5.92 24.096q0 0.832 0.576 1.408t1.44 0.608h16.128q0.832 0 1.44-0.608t0.576-1.408v-16.16q0-0.832-0.576-1.44t-1.44-0.576h-16.128q-0.832 0-1.44 0.576t-0.576 1.44v16.16z\"></path>\n</svg>",Q=/*#__PURE__*/function(_k6){function Q(e){var _l$model;var _this42;_classCallCheck(this,Q);var r,o,a,c,l;var t=C(e.directConnection),n=Q.getKey(e);_this42=_callSuper(this,Q,[e,Dn(),Bn,{key:n}]),_this42.insertKeyPlaceholderText=_this42.genereteAPIKeyName("OpenAI"),_this42.keyHelpUrl=Nn,_this42._microphoneButton=null,_this42._toggleButton=null,_this42._errorElement=null,_this42._loadingElement=null,_this42._pc=null,_this42._mediaStream=null,_this42._isMuted=!1;var s=(r=t.openAI)==null?void 0:r.realtime;if(_typeof(s)===U){_this42._avatarConfig=s.avatar,_this42._ephemeralKey=s.ephemeralKey,_this42._errorConfig=s[f],_this42._loadingConfig=s.loading,Object.assign(_this42.rawBody,s.config);var d=(a=(o=e.directConnection)==null?void 0:o.openAI)==null?void 0:a.realtime,_ref85=d.config||{},p=_ref85.function_handler;p&&(_this42._functionHandlerI=p),_this42._events=s.events,d.methods=_this42.generateMethods(),_this42.setInputAudioTranscribe(e,(c=d.config)==null?void 0:c.input_audio_transcription);}(_l$model=(l=_this42.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="gpt-4o-realtime-preview-2025-06-03",_this42._avatarConfig=Q.buildAvatarConfig(s),_this42._buttonsConfig=Q.buildButtonsConfig(s),_this42._avatarEl=Q.createAvatar(_this42._avatarConfig),_this42._containerEl=_this42.createContainer(),_this42._deepChat=e;return _this42;}_inherits(Q,_k6);return _createClass(Q,[{key:"setInputAudioTranscribe",value:// https://community.openai.com/t/unable-to-access-user-audio-transcript-in-realtime-api/1001570/3
165
+ },{key:"createStreamRun",value:function(){var _createStreamRun=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee91(e){return _regenerator().w(function(_context91){while(1)switch(_context91.n){case 0:e.stream=!0;this._waitingForStreamResponse=!0;_context91.n=1;return V.request(this,e,this.messages,!0,!0);case 1:this._messageStream=_context91.v;case 2:return _context91.a(2);}},_callee91,this);}));function createStreamRun(_x184){return _createStreamRun.apply(this,arguments);}return createStreamRun;}()}],[{key:"processImageMessage",value:function processImageMessage(e,t){var n=t==null?void 0:t.filter(function(s){return Se.isImageFileExtension(s.name);}).map(function(s){return _defineProperty(_defineProperty({},E,"image_file"),"image_file",{file_id:s.id});});if(n&&n.length>0)return e[h]&&e[h].length>0&&n.push(_defineProperty(_defineProperty({},E,h),h,e[h])),_defineProperty({content:n},x,F);}},{key:"processAttachmentsMessage",value:function processAttachmentsMessage(e,t,n){return _defineProperty({attachments:t.map(function(r){return{tools:[_defineProperty({},E,n)],file_id:r.id};}),content:[_defineProperty(_defineProperty({},E,h),h,e[h])]},x,F);}}]);}(k);Ht.POLLING_TIMEOUT_MS=500;var ti=Ht;var br=/*#__PURE__*/function(_ti){function br(e){var _a$headers,_c$OpenAIBeta;var _this39;_classCallCheck(this,br);var o,a,c,l,d;var t=C(e.directConnection),n=t.openAI,s=(o=t.openAI)==null?void 0:o.assistant,r=br.buildUrlSegments(s);if(_this39=_callSuper(this,br,[e,s,r,Dn(),Bn,n]),(_a$headers=(a=_this39.connectSettings).headers)!==null&&_a$headers!==void 0?_a$headers:a.headers={},(_c$OpenAIBeta=(c=_this39.connectSettings.headers)["OpenAI-Beta"])!==null&&_c$OpenAIBeta!==void 0?_c$OpenAIBeta:c["OpenAI-Beta"]="assistants=v2",_this39.shouldFetchHistory&&_this39.sessionId&&(_this39.fetchHistory=_this39.fetchHistoryFunc.bind(_assertThisInitialized(_this39))),_typeof(s)===U){var _ref84=(d=(l=e.directConnection)==null?void 0:l.openAI)==null?void 0:d.assistant,p=_ref84.function_handler,u=_ref84.files_tool_type;p&&(_this39._functionHandlerI=p),u&&(_this39.filesToolType=u);}return _this39;}_inherits(br,_ti);return _createClass(br,null,[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&e.custom_base_url||Ze;return{threadsPrefix:"".concat(t,"/threads"),threadsPosfix:"",newAssistantUrl:"".concat(t,"/assistants"),createMessagePostfix:"",listMessagesPostfix:"order=desc",storeFiles:"".concat(t,"/").concat(b),getFilesPrefix:"".concat(t,"/").concat(b,"/"),getFilesPostfix:"/content"};}}]);}(ti);var ni="Please define the Azure URL Details. [More Information](".concat(Z,"directConnection/Azure)"),ea=function ea(i){return _defineProperty({"api-key":i},q,te);},ta=function ta(i){return be("".concat(i.endpoint,"/openai/models?api-version=").concat(i.version),ue,Qo);},na=function na(i){var e=i.endpoint,t=i.version,n=i.deploymentId;return e&&t&&n;},xn=/*#__PURE__*/function(_ti2){function xn(e){var _S$headers;var _this40;_classCallCheck(this,xn);var l,d,p,u,g,y,_,S;var t=C(e.directConnection),n=t.azure,s=(l=t.azure)==null?void 0:l.openAI,r=(s==null?void 0:s.urlDetails)||{},o="".concat((d=s==null?void 0:s.urlDetails)==null?void 0:d.endpoint,"/openai/"),a="?api-version=".concat((p=s==null?void 0:s.urlDetails)==null?void 0:p.version),c={threadsPrefix:"".concat(o).concat(xn.THREAD_RESOURCE),threadsPosfix:a,newAssistantUrl:"".concat(o).concat(xn.NEW_ASSISTANT_RESOURCE).concat(a),createMessagePostfix:a,listMessagesPostfix:"order=desc&api-version=".concat((u=s==null?void 0:s.urlDetails)==null?void 0:u.version),storeFiles:"".concat(o).concat(b).concat(a),getFilesPrefix:"".concat(o).concat(b,"/"),getFilesPostfix:"/content".concat(a)};if(_this40=_callSuper(this,xn,[e,s==null?void 0:s.assistant,c,ta(r),ea,n]),_this40.permittedErrorPrefixes=[ni],_this40.insertKeyPlaceholderText=_this40.genereteAPIKeyName("Azure OpenAI"),_this40.keyHelpUrl="https://learn.microsoft.com/en-us/answers/questions/1193991/how-to-get-the-value-of-openai-api-key",_this40.isTextInputDisabled=!1,_typeof(s==null?void 0:s.assistant)===U){var _ref86=(_=(y=(g=e.directConnection)==null?void 0:g.azure)==null?void 0:y.openAI)==null?void 0:_.assistant,M=_ref86.function_handler,K=_ref86.files_tool_type;M&&(_this40._functionHandlerI=M),K&&(_this40.filesToolType=K);}na(r)?(_S$headers=(S=_this40.connectSettings).headers)!==null&&_S$headers!==void 0?_S$headers:S.headers={}:(_this40.isTextInputDisabled=!0,_this40.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,ni));}));return _this40;}_inherits(xn,_ti2);return _createClass(xn);}(ti);xn.THREAD_RESOURCE="threads",xn.NEW_ASSISTANT_RESOURCE="assistants";var Vi=xn;var Vl="sts-session-started",Kl="sts-session-stopped";var me=/*#__PURE__*/function(){function me(){_classCallCheck(this,me);}return _createClass(me,null,[{key:"addAttributes",value:function addAttributes(e){e[x]="button",e.setAttribute("tabindex","0");}},{key:"addAriaBusy",value:function addAriaBusy(e){e.setAttribute("aria-busy","true");}},{key:"removeAriaBusy",value:function removeAriaBusy(e){e.removeAttribute("aria-busy");}},{key:"addAriaDisabled",value:function addAriaDisabled(e){e.setAttribute("aria-".concat(j),"true");}},{key:"removeAriaDisabled",value:function removeAriaDisabled(e){e.removeAttribute("aria-".concat(j));}},{key:"removeAriaAttributes",value:function removeAriaAttributes(e){me.removeAriaBusy(e),me.removeAriaDisabled(e);}}]);}();var sa="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<svg height=\"1.4em\" width=\"1.4em\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n\t viewBox=\"0 0 490.9 490.9\" xml:space=\"preserve\">\n\t<g>\n\t\t<g>\n\t\t\t<path d=\"M245.5,322.9c53,0,96.2-43.2,96.2-96.2V96.2c0-53-43.2-96.2-96.2-96.2s-96.2,43.2-96.2,96.2v130.5\n\t\t\t\tC149.3,279.8,192.5,322.9,245.5,322.9z M173.8,96.2c0-39.5,32.2-71.7,71.7-71.7s71.7,32.2,71.7,71.7v130.5\n\t\t\t\tc0,39.5-32.2,71.7-71.7,71.7s-71.7-32.2-71.7-71.7V96.2z\"/>\n\t\t\t<path d=\"M94.4,214.5c-6.8,0-12.3,5.5-12.3,12.3c0,85.9,66.7,156.6,151.1,162.8v76.7h-63.9c-6.8,0-12.3,5.5-12.3,12.3\n\t\t\t\ts5.5,12.3,12.3,12.3h152.3c6.8,0,12.3-5.5,12.3-12.3s-5.5-12.3-12.3-12.3h-63.9v-76.7c84.4-6.3,151.1-76.9,151.1-162.8\n\t\t\t\tc0-6.8-5.5-12.3-12.3-12.3s-12.3,5.5-12.3,12.3c0,76.6-62.3,138.9-138.9,138.9s-138.9-62.3-138.9-138.9\n\t\t\t\tC106.6,220,101.2,214.5,94.4,214.5z\"/>\n\t\t</g>\n\t</g>\n</svg>\n",We=/*#__PURE__*/function(){function We(){_classCallCheck(this,We);}return _createClass(We,null,[{key:"createTextElement",value:function createTextElement(e){var t=A();return t[m].add(We.INPUT_BUTTON_INNER_TEXT_CLASS),t.innerText=e,t;}},{key:"tryAddSVGElement",value:function tryAddSVGElement(e,t,n,s){n?e.push(kt.createSVGElement(n)):n!==""&&s&&e.push(t);}},{key:"createCustomElements",value:function createCustomElements(e,t,n){var c,l;var s=n==null?void 0:n[e],r=(c=s==null?void 0:s[h])==null?void 0:c.content,o=(l=s==null?void 0:s[G])==null?void 0:l.content,a=[];return We.tryAddSVGElement(a,t,o,r),r&&a.push(We.createTextElement(r)),a.length>0?a:void 0;}},{key:"reassignClassBasedOnChildren",value:function reassignClassBasedOnChildren(e,t){e[m].remove(We.INPUT_BUTTON_SVG_CLASS,We.INPUT_BUTTON_SVG_TEXT_CLASS),t.find(function(n){return n[m].contains(We.INPUT_BUTTON_INNER_TEXT_CLASS);})?t.length>1&&e[m].add(We.INPUT_BUTTON_SVG_TEXT_CLASS):e[m].add(We.INPUT_BUTTON_SVG_CLASS);}}]);}();We.INPUT_BUTTON_SVG_TEXT_CLASS="input-button-svg-text",We.INPUT_BUTTON_INNER_TEXT_CLASS="text-button",We.INPUT_BUTTON_SVG_CLASS="input-button-svg";var Et=We;var us=/*#__PURE__*/function(){function us(){_classCallCheck(this,us);}return _createClass(us,null,[{key:"parseSVGTextElements",value:function parseSVGTextElements(e){return _defineProperty(_defineProperty({},G,e.find(function(t){return t.tagName.toLowerCase()===G;})),h,e.find(function(t){return t.tagName.toLowerCase()==="div";}));}}]);}();var xe=/*#__PURE__*/function(){function xe(){_classCallCheck(this,xe);}return _createClass(xe,null,[{key:"unsetAllCSS",value:function unsetAllCSS(e,t){var r,o;t.container&&de.unsetAllCSSMouseStates(e,t.container);var _us$parseSVGTextEleme=us.parseSVGTextElements(Array.from(e.children)),n=_us$parseSVGTextEleme.svg,s=_us$parseSVGTextEleme.text;(r=t[G])!=null&&r[R]&&n&&de.unsetAllCSSMouseStates(n,t[G][R]),(o=t[h])!=null&&o[R]&&s&&de.unsetAllCSSMouseStates(s,t[h][R]);}},{key:"unsetActionCSS",value:function unsetActionCSS(e,t){var r,o;t.container&&de.unsetActivityCSSMouseStates(e,t.container);var _us$parseSVGTextEleme2=us.parseSVGTextElements(Array.from(e.children)),n=_us$parseSVGTextEleme2.svg,s=_us$parseSVGTextEleme2.text;(r=t[G])!=null&&r[R]&&n&&de.unsetActivityCSSMouseStates(n,t[G][R]),(o=t[h])!=null&&o[R]&&s&&de.unsetActivityCSSMouseStates(s,t[h][R]);}},{key:"setElementsCSS",value:function setElementsCSS(e,t,n){var o,a,c,l,d;Object.assign(e[v],(o=t.container)==null?void 0:o[n]);var _us$parseSVGTextEleme3=us.parseSVGTextElements(Array.from(e.children)),s=_us$parseSVGTextEleme3.svg,r=_us$parseSVGTextEleme3.text;s&&Object.assign(s[v],(c=(a=t[G])==null?void 0:a[R])==null?void 0:c[n]),r&&Object.assign(r[v],(d=(l=t[h])==null?void 0:l[R])==null?void 0:d[n]);}},{key:"setElementCssUpToState",value:function setElementCssUpToState(e,t,n){xe.setElementsCSS(e,t,w),n!==w&&(xe.setElementsCSS(e,t,De),n!==De&&xe.setElementsCSS(e,t,J));}}]);}();var gn=/*#__PURE__*/function(){// prettier-ignore
166
+ function gn(e,t,n,s,r,o){_classCallCheck(this,gn);this._mouseState={state:"default"},this.isCustom=!1,me.addAttributes(e),this.elementRef=e,this[G]=kt.createSVGElement(t),this.customStyles=r,this.position=le.processPosition(n),this._tooltipSettings=s,this.dropupText=o;}return _createClass(gn,[{key:"buttonMouseLeave",value:function buttonMouseLeave(e){var t;this._mouseState.state=w,((t=this._activeTooltip)==null?void 0:t.element[v].visibility)==="visible"&&this._tooltipSettings&&ut.hide(this._activeTooltip,this._tooltipSettings),e&&(xe.unsetAllCSS(this.elementRef,e),xe.setElementsCSS(this.elementRef,e,w));}},{key:"buttonMouseEnter",value:function buttonMouseEnter(e){var t;this._mouseState.state=De,this._tooltipSettings&&(this._activeTooltip=ut.display(this.elementRef,this._tooltipSettings,(t=this._activeTooltip)==null?void 0:t.element)),e&&xe.setElementsCSS(this.elementRef,e,De);}},{key:"buttonMouseUp",value:function buttonMouseUp(e){e&&xe.unsetActionCSS(this.elementRef,e),this.buttonMouseEnter(e);}},{key:"buttonMouseDown",value:function buttonMouseDown(e){this._mouseState.state=J,e&&xe.setElementsCSS(this.elementRef,e,J);}// be careful not to use onclick as that is used for button functionality
167
+ },{key:"setEvents",value:function setEvents(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 unsetCustomStateStyles(e){if(this.customStyles)for(var t=0;t<e.length;t+=1){var _n2=e[t],s=_n2&&this.customStyles[_n2];s&&xe.unsetActionCSS(this.elementRef,s);}}},{key:"reapplyStateStyle",value:function reapplyStateStyle(e,t){if(!this.customStyles)return;t&&this.unsetCustomStateStyles(t);var n=this.customStyles[e];n&&xe.setElementCssUpToState(this.elementRef,n,this._mouseState.state),this.setEvents(n);}},{key:"changeElementsByState",value:function changeElementsByState(e){var _this$elementRef;(_this$elementRef=this.elementRef).replaceChildren.apply(_this$elementRef,_toConsumableArray(e)),Et.reassignClassBasedOnChildren(this.elementRef,e);}},{key:"buildDefaultIconElement",value:function buildDefaultIconElement(e){var t=this[G].cloneNode(!0);return t.id=e,[t];}},{key:"createInnerElements",value:function createInnerElements(e,t,n){var s=Et.createCustomElements(t,this[G],n);if(s&&s.length>0){if(this.position===et){var r=s[0].cloneNode(!0);r.id=s[0]===this[G]?e:"dropup-menu-item-icon-element-custom",s[0]=r;}return s;}return this.buildDefaultIconElement(e);}}]);}();var mi=/*#__PURE__*/function(_gn){function mi(e){var _this41;_classCallCheck(this,mi);var n,s;var t=((s=(n=e==null?void 0:e[w])==null?void 0:n[G])==null?void 0:s.content)||mi.EMPTY_SVG;_this41=_callSuper(this,mi,[A(),t,void 0,void 0,e]),_this41.isActive=!1,_this41._innerElements=_this41.createInnerElementsForStates(_this41.customStyles),_this41.changeToDefault();return _this41;}_inherits(mi,_gn);return _createClass(mi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty(_defineProperty(_defineProperty({},w,this.createInnerButtonElements(w,e)),H,this.createInnerButtonElements(H,e)),Nt,this.createInnerButtonElements(Nt,e));}},{key:"createInnerButtonElements",value:function createInnerButtonElements(e,t){return Et.createCustomElements(e,this[G],t)||[this[G]];}},{key:"changeState",value:function changeState(e){this.changeElementsByState(e),this.elementRef[m].replace(Et.INPUT_BUTTON_SVG_CLASS,"deep-chat-openai-realtime-button");}},{key:"changeToActive",value:function changeToActive(){this.changeState(this._innerElements[H]),this.reapplyStateStyle(H,[Nt,w]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){var e,t,n,s;this.changeState(this._innerElements[w]),(e=this.customStyles)!=null&&e[H]&&xe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[H]),(n=this.customStyles)!=null&&n[Nt]&&xe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[Nt]),this.reapplyStateStyle(w,[H,Nt]),this.isActive=!1;}},{key:"changeToUnavailable",value:function changeToUnavailable(){var e,t,n,s;this.changeState(this._innerElements[Nt]),(e=this.customStyles)!=null&&e[H]&&xe.unsetAllCSS(this.elementRef,(t=this.customStyles)==null?void 0:t[H]),(n=this.customStyles)!=null&&n[w]&&xe.unsetAllCSS(this.elementRef,(s=this.customStyles)==null?void 0:s[w]),this.reapplyStateStyle(Nt,[w,H]),this.isActive=!1;}}]);}(gn);mi.EMPTY_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"></svg>';var si=mi;var Pe=/*#__PURE__*/function(){function Pe(){_classCallCheck(this,Pe);}return _createClass(Pe,null,[{key:"setPropertyValueIfDoesNotExist",value:function setPropertyValueIfDoesNotExist(e,t,n){var _e$s,_e$s2;var s=t[0];t.length===1?(_e$s=e[s])!==null&&_e$s!==void 0?_e$s:e[s]=n:((_e$s2=e[s])!==null&&_e$s2!==void 0?_e$s2:e[s]={},t.shift(),Pe.setPropertyValueIfDoesNotExist(e[s],t,n));}},{key:"setPropertyValue",value:function setPropertyValue(e,t,n){var _e$s3;var s=t[0];t.length===1?e[s]=n:((_e$s3=e[s])!==null&&_e$s3!==void 0?_e$s3:e[s]={},t.shift(),Pe.setPropertyValue(e[s],t,n));}},{key:"getObjectValue",value:function getObjectValue(e,t){var n=t[0],s=e[n];return s===void 0||t.length===1?s:Pe.getObjectValue(s,t.slice(1));}},{key:"overwritePropertyObjectFromAnother",value:function overwritePropertyObjectFromAnother(e,t,n){var s=Pe.getObjectValue(t,n);if(s){var r=_objectSpread(_objectSpread({},s),Pe.getObjectValue(e,n)||{});Pe.setPropertyValue(e,n,r);}}},{key:"isJson",value:function isJson(e){try{return ce(e),!0;}catch(_unused8){return!1;}}// prettier-ignore
168
+ },{key:"assignPropertyFromOneToAnother",value:function assignPropertyFromOneToAnother(e,t,n){var _t$e;(_t$e=t[e])!==null&&_t$e!==void 0?_t$e:t[e]={},Object.assign(t[e],n==null?void 0:n[e]);}}]);}();var ia="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M5.92 24.096q0 1.088 0.928 1.728 0.512 0.288 1.088 0.288 0.448 0 0.896-0.224l16.16-8.064q0.48-0.256 0.8-0.736t0.288-1.088-0.288-1.056-0.8-0.736l-16.16-8.064q-0.448-0.224-0.896-0.224-0.544 0-1.088 0.288-0.928 0.608-0.928 1.728v16.16z\"></path>\n</svg>",Ki="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M5.92 24.096q0 0.832 0.576 1.408t1.44 0.608h16.128q0.832 0 1.44-0.608t0.576-1.408v-16.16q0-0.832-0.576-1.44t-1.44-0.576h-16.128q-0.832 0-1.44 0.576t-0.576 1.44v16.16z\"></path>\n</svg>",Q=/*#__PURE__*/function(_k6){function Q(e){var _l$model;var _this42;_classCallCheck(this,Q);var r,o,a,c,l;var t=C(e.directConnection),n=Q.getKey(e);_this42=_callSuper(this,Q,[e,Dn(),Bn,{key:n}]),_this42.insertKeyPlaceholderText=_this42.genereteAPIKeyName("OpenAI"),_this42.keyHelpUrl=Nn,_this42._microphoneButton=null,_this42._toggleButton=null,_this42._errorElement=null,_this42._loadingElement=null,_this42._pc=null,_this42._mediaStream=null,_this42._isMuted=!1;var s=(r=t.openAI)==null?void 0:r.realtime;if(_typeof(s)===U){_this42._avatarConfig=s.avatar,_this42._ephemeralKey=s.ephemeralKey,_this42._errorConfig=s[f],_this42._loadingConfig=s.loading,Object.assign(_this42.rawBody,s.config);var d=(a=(o=e.directConnection)==null?void 0:o.openAI)==null?void 0:a.realtime,_ref89=d.config||{},p=_ref89.function_handler;p&&(_this42._functionHandlerI=p),_this42._events=s.events,d.methods=_this42.generateMethods(),_this42.setInputAudioTranscribe(e,(c=d.config)==null?void 0:c.input_audio_transcription);}(_l$model=(l=_this42.rawBody).model)!==null&&_l$model!==void 0?_l$model:l.model="gpt-4o-realtime-preview-2025-06-03",_this42._avatarConfig=Q.buildAvatarConfig(s),_this42._buttonsConfig=Q.buildButtonsConfig(s),_this42._avatarEl=Q.createAvatar(_this42._avatarConfig),_this42._containerEl=_this42.createContainer(),_this42._deepChat=e;return _this42;}_inherits(Q,_k6);return _createClass(Q,[{key:"setInputAudioTranscribe",value:// https://community.openai.com/t/unable-to-access-user-audio-transcript-in-realtime-api/1001570/3
173
169
  function setInputAudioTranscribe(e,t){if(t){var _n3="whisper-1";_typeof(t)=="object"?this.rawBody.input_audio_transcription={model:t.model||_n3,language:t.language,prompt:t.prompt}:this.rawBody.input_audio_transcription={model:_n3};}else e.onMessage&&(console.warn("To get user audio transcription, set `input_audio_transcription` in the `realtime` config."),console.warn("See: ".concat(Z,"directConnection/OpenAI/OpenAIRealtime#OpenAIRealtimeConfig")));}// called after API key was inserted
174
- },{key:"setUpView",value:function setUpView(e,t){e[v].display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(){var s,e,t,n;return _regenerator().w(function(_context92){while(1)switch(_context92.n){case 0:e=(s=this._deepChat.directConnection)==null?void 0:s.openAI;if(e){_context92.n=1;break;}return _context92.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context92.n=2;break;}return _context92.a(2);case 2:n=this.key||e.key;(t.fetchEphemeralKey||n)&&t.autoStart&&(this.changeToUnavailable(),this.displayLoading()),this.fetchEphemeralKey(t.autoStart);case 3:return _context92.a(2);}},_callee92,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(e){var o,t,n,s,r,a,_t31,_t32,_t33;return _regenerator().w(function(_context93){while(1)switch(_context93.p=_context93.n){case 0:t=(o=this._deepChat.directConnection)==null?void 0:o.openAI,n=_typeof(t==null?void 0:t.realtime)=="object"?t==null?void 0:t.realtime.fetchEphemeralKey:void 0,s=t==null?void 0:t.realtime,r=this.key||t.key;if(!(_typeof(s)=="object")){_context93.n=8;break;}if(this._ephemeralKey){_context93.n=7;break;}_context93.p=1;if(!n){_context93.n=3;break;}a=n();a.then&&(this._retrievingEphemeralKey=a);_context93.n=2;return a;case 2:this._ephemeralKey=_context93.v;_context93.n=5;break;case 3:_t31=r;if(!_t31){_context93.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(r);_context93.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context93.v;case 5:_context93.n=7;break;case 6:_context93.p=6;_t32=_context93.v;this.displayFailedToRetrieveEphemeralKey(_t32);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context93.n=12;break;case 8:if(!r){_context93.n=12;break;}_context93.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(r);_context93.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context93.v;e&&this.init(this._ephemeralKey);_context93.n=12;break;case 11:_context93.p=11;_t33=_context93.v;this.displayFailedToRetrieveEphemeralKey(_t33);case 12:return _context93.a(2);}},_callee93,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x185){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(e){return _regenerator().w(function(_context94){while(1)switch(_context94.n){case 0:_context94.n=1;return fetch("".concat(Ze,"realtime/sessions"),{method:ye,body:le(this.rawBody),headers:_defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(e))});case 1:_context94.n=2;return _context94.v.json();case 2:return _context94.a(2,_context94.v.client_secret.value);}},_callee94,this);}));function getEphemeralKey(_x186){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this43=this;return{updateConfig:function updateConfig(e){var t;(t=_this43._dc)==null||t.send(le(_defineProperty(_defineProperty({},E,"session.update"),"session",e)));},sendMessage:function sendMessage(e,t){var n=t||Mn,s=[_defineProperty(_defineProperty({},E,n===Mn||n===F?Ki:h),"text",e)],r=_defineProperty(_defineProperty(_defineProperty({},x,n),E,"message"),"content",s);_this43.sendMessage(r);}};}},{key:"createContainer",value:function createContainer(){var e=A();return e.id="deep-chat-openai-realtime-container",e.appendChild(this.createAvatarContainer()),e.appendChild(this.createButtonsContainer()),e.appendChild(this.createError()),e;}},{key:"createAvatarContainer",value:function createAvatarContainer(){var t,n;var e=A();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[v],(n=(t=this._avatarConfig)==null?void 0:t[R])==null?void 0:n.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var s;var e=A();e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e[v],(s=this._buttonsConfig)==null?void 0:s.container),this._microphoneButton=this.createMicophoneButton();var t=Q.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var n=Q.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(n),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this44=this;var t;var e=new ri((t=this._buttonsConfig)==null?void 0:t[ct]);return e.elementRef[m].add(Q.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),z.assignButtonEvents(e.elementRef,function(){e.isActive?(_this44.toggleMicorphone(!0),e.elementRef[m].replace(Q.MICROPHONE_ACTIVE,Q.BUTTON_DEFAULT),e.changeToDefault(),_this44._isMuted=!1):(_this44.toggleMicorphone(!1),e.elementRef[m].replace(Q.BUTTON_DEFAULT,Q.MICROPHONE_ACTIVE),me.removeAriaAttributes(e.elementRef),e.changeToActive(),_this44._isMuted=!0);}),e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(n){return n.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this45=this;var t;var e=new ri((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[m].add(Q.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),z.assignButtonEvents(e.elementRef,/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(){var n,s,_t34,_t35;return _regenerator().w(function(_context95){while(1)switch(_context95.p=_context95.n){case 0:if(!e.isActive){_context95.n=1;break;}e.changeToDefault(),_this45.stop();_context95.n=9;break;case 1:_context95.p=1;if(!_this45._ephemeralKey){_context95.n=3;break;}_this45.displayLoading();_context95.n=2;return _this45.init(_this45._ephemeralKey);case 2:_context95.n=7;break;case 3:if(!_this45._retrievingEphemeralKey){_context95.n=6;break;}_this45.displayLoading();_context95.n=4;return _this45._retrievingEphemeralKey;case 4:s=_context95.v;_t34=(n=_this45._toggleButton)!=null&&n.isActive;if(!_t34){_context95.n=5;break;}_context95.n=5;return _this45.init(s);case 5:_context95.n=7;break;case 6:_this45.displayLoading();_context95.n=7;return _this45.fetchEphemeralKey(!0);case 7:_context95.n=9;break;case 8:_context95.p=8;_t35=_context95.v;console[f]("Failed to start conversation:",_t35),_this45.displayError(),_this45.hideLoading();case 9:return _context95.a(2);}},_callee95,null,[[1,8]]);}))),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(e){var _this46=this;var t,n,s,r,o,a,c,l,_t38,_t39,_t40,_t41,_t42;return _regenerator().w(function(_context98){while(1)switch(_context98.p=_context98.n){case 0:t=new RTCPeerConnection();this._pc=t;n=A($);n.autoplay=!0;s=new AudioContext(),r=s.createAnalyser();r.fftSize=256;o=new Uint8Array(r.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref88=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(a){var c,_t36;return _regenerator().w(function(_context96){while(1)switch(_context96.n){case 0:if(!a.streams[0]){_context96.n=2;break;}n.srcObject=a.streams[0];c=s.createMediaStreamSource(a.streams[0]);_t36=s.state==="suspended";if(!_t36){_context96.n=1;break;}_context96.n=1;return s.resume();case 1:c.connect(r);_this46.monitorFrequencies(r,o);_context96.n=3;break;case 2:console[f]("No streams found in the ontrack event."),_this46.displayError();case 3:return _context96.a(2);}},_callee96);}));return function(_x188){return _ref88.apply(this,arguments);};}();_context98.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var c;t===_this46._pc&&(_this46._mediaStream=a,(c=_this46._pc)==null||c.addTrack(_this46._mediaStream.getTracks()[0]),_this46._isMuted&&_this46.toggleMicorphone(!1));})["catch"](function(a){console[f]("Error accessing microphone:",a),_this46.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref89=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(a){var l,d,p,c,g,y,_,_t37;return _regenerator().w(function(_context97){while(1)switch(_context97.p=_context97.n){case 0:c=JSON.parse(a.data);if(!(c[E]==="session.created")){_context97.n=1;break;}_this46.removeUnavailable(),_this46._toggleButton&&(me.removeAriaAttributes(_this46._toggleButton.elementRef),_this46._toggleButton.changeToActive()),(d=(l=_this46._events)==null?void 0:l.started)==null||d.call(l),_this46._deepChat.dispatchEvent(new CustomEvent(Kl)),_this46.hideLoading();_context97.n=7;break;case 1:if(!(c[E]==="response.done")){_context97.n=6;break;}g=(p=JSON.parse(a.data).response.output)==null?void 0:p[0];if(!((g==null?void 0:g[E])===qs)){_context97.n=5;break;}y=g.name,_=g.call_id;_context97.p=2;_context97.n=3;return _this46.handleTool(y,g.arguments,_);case 3:_context97.n=5;break;case 4:_context97.p=4;_t37=_context97.v;_this46.stopOnError(_t37);case 5:_context97.n=7;break;case 6:c[E]===f?_this46.stopOnError(c[f].message):c[E]===it?_this46.stopOnError(c.message):c[E]==="response.audio_transcript.delta"||(c[E]==="response.audio_transcript.done"?c.transcript&&dn.onMessage(_this46._deepChat,_defineProperty(_defineProperty({},x,ne),h,c.transcript),!1):c[E]==="conversation.item.input_audio_transcription.completed"&&c.transcript&&dn.onMessage(_this46._deepChat,_defineProperty(_defineProperty({},x,F),h,c.transcript),!1));case 7:return _context97.a(2);}},_callee97,null,[[2,4]]);}));return function(_x189){return _ref89.apply(this,arguments);};}());_context98.p=2;_context98.n=3;return this._pc.createOffer();case 3:a=_context98.v;_t38=t!==this._pc;if(_t38){_context98.n=5;break;}_context98.n=4;return this._pc.setLocalDescription(a);case 4:_t38=t!==this._pc;case 5:if(!_t38){_context98.n=6;break;}return _context98.a(2);case 6:_context98.n=7;return fetch("".concat(Ze,"realtime"),{method:ye,body:a.sdp,headers:_defineProperty(_defineProperty({},he,"".concat(Ce).concat(e)),q,"application/sdp")});case 7:c=_context98.v;if(!(t!==this._pc)){_context98.n=8;break;}return _context98.a(2);case 8:_t39=_defineProperty;_t40=_defineProperty({},E,"answer");_context98.n=9;return c[h]();case 9:l=_t39(_t40,"sdp",_context98.v);_t41=t!==this._pc;if(_t41){_context98.n=11;break;}_context98.n=10;return this._pc.setRemoteDescription(l);case 10:_t41=t!==this._pc;case 11:if(!_t41){_context98.n=12;break;}return _context98.a(2);case 12:_context98.n=14;break;case 13:_context98.p=13;_t42=_context98.v;console[f](_t42),this.displayError();case 14:return _context98.a(2);}},_callee98,this,[[2,13]]);}));function init(_x187){return _init2.apply(this,arguments);}return init;}()// there is a bug where sometimes upon refreshing the browser too many times the frequencyData is all 0s
170
+ },{key:"setUpView",value:function setUpView(e,t){e[v].display="none",t.appendChild(this._containerEl),this.setup();}},{key:"setup",value:function(){var _setup=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee92(){var s,e,t,n;return _regenerator().w(function(_context92){while(1)switch(_context92.n){case 0:e=(s=this._deepChat.directConnection)==null?void 0:s.openAI;if(e){_context92.n=1;break;}return _context92.a(2);case 1:t=e==null?void 0:e.realtime;if(!(_typeof(t)!="object"||!t.autoStart&&!t.autoFetchEphemeralKey)){_context92.n=2;break;}return _context92.a(2);case 2:n=this.key||e.key;(t.fetchEphemeralKey||n)&&t.autoStart&&(this.changeToUnavailable(),this.displayLoading()),this.fetchEphemeralKey(t.autoStart);case 3:return _context92.a(2);}},_callee92,this);}));function setup(){return _setup.apply(this,arguments);}return setup;}()},{key:"fetchEphemeralKey",value:function(){var _fetchEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee93(e){var o,t,n,s,r,a,_t31,_t32,_t33;return _regenerator().w(function(_context93){while(1)switch(_context93.p=_context93.n){case 0:t=(o=this._deepChat.directConnection)==null?void 0:o.openAI,n=_typeof(t==null?void 0:t.realtime)=="object"?t==null?void 0:t.realtime.fetchEphemeralKey:void 0,s=t==null?void 0:t.realtime,r=this.key||t.key;if(!(_typeof(s)=="object")){_context93.n=8;break;}if(this._ephemeralKey){_context93.n=7;break;}_context93.p=1;if(!n){_context93.n=3;break;}a=n();a.then&&(this._retrievingEphemeralKey=a);_context93.n=2;return a;case 2:this._ephemeralKey=_context93.v;_context93.n=5;break;case 3:_t31=r;if(!_t31){_context93.n=5;break;}this._retrievingEphemeralKey=this.getEphemeralKey(r);_context93.n=4;return this._retrievingEphemeralKey;case 4:this._ephemeralKey=_context93.v;case 5:_context93.n=7;break;case 6:_context93.p=6;_t32=_context93.v;this.displayFailedToRetrieveEphemeralKey(_t32);case 7:this._ephemeralKey&&(e?this.init(this._ephemeralKey):this.changeToAvailable());_context93.n=12;break;case 8:if(!r){_context93.n=12;break;}_context93.p=9;this._retrievingEphemeralKey=this.getEphemeralKey(r);_context93.n=10;return this._retrievingEphemeralKey;case 10:this._ephemeralKey=_context93.v;e&&this.init(this._ephemeralKey);_context93.n=12;break;case 11:_context93.p=11;_t33=_context93.v;this.displayFailedToRetrieveEphemeralKey(_t33);case 12:return _context93.a(2);}},_callee93,this,[[9,11],[1,6]]);}));function fetchEphemeralKey(_x185){return _fetchEphemeralKey.apply(this,arguments);}return fetchEphemeralKey;}()},{key:"getEphemeralKey",value:function(){var _getEphemeralKey=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee94(e){return _regenerator().w(function(_context94){while(1)switch(_context94.n){case 0:_context94.n=1;return fetch("".concat(Ze,"realtime/sessions"),{method:ye,body:ce(this.rawBody),headers:_defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(e))});case 1:_context94.n=2;return _context94.v.json();case 2:return _context94.a(2,_context94.v.client_secret.value);}},_callee94,this);}));function getEphemeralKey(_x186){return _getEphemeralKey.apply(this,arguments);}return getEphemeralKey;}()},{key:"generateMethods",value:function generateMethods(){var _this43=this;return{updateConfig:function updateConfig(e){var t;(t=_this43._dc)==null||t.send(ce(_defineProperty(_defineProperty({},E,"session.update"),"session",e)));},sendMessage:function sendMessage(e,t){var n=t||Mn,s=[_defineProperty(_defineProperty({},E,n===Mn||n===F?zi:h),"text",e)],r=_defineProperty(_defineProperty(_defineProperty({},x,n),E,"message"),"content",s);_this43.sendMessage(r);}};}},{key:"createContainer",value:function createContainer(){var e=A();return e.id="deep-chat-openai-realtime-container",e.appendChild(this.createAvatarContainer()),e.appendChild(this.createButtonsContainer()),e.appendChild(this.createError()),e;}},{key:"createAvatarContainer",value:function createAvatarContainer(){var t,n;var e=A();return e.id="deep-chat-openai-realtime-avatar-container",Object.assign(e[v],(n=(t=this._avatarConfig)==null?void 0:t[R])==null?void 0:n.container),e.appendChild(this._avatarEl),e;}},{key:"createButtonsContainer",value:function createButtonsContainer(){var s;var e=A();e.id="deep-chat-openai-realtime-buttons-container",Object.assign(e[v],(s=this._buttonsConfig)==null?void 0:s.container),this._microphoneButton=this.createMicophoneButton();var t=Q.createButtonContainer(this._microphoneButton.elementRef);this._toggleButton=this.createToggleButton();var n=Q.createButtonContainer(this._toggleButton.elementRef);return e.appendChild(t),e.appendChild(n),e.appendChild(this.createLoading()),e;}},{key:"createMicophoneButton",value:function createMicophoneButton(){var _this44=this;var t;var e=new si((t=this._buttonsConfig)==null?void 0:t[ct]);return e.elementRef[m].add(Q.BUTTON_DEFAULT,"deep-chat-openai-realtime-microphone"),z.assignButtonEvents(e.elementRef,function(){e.isActive?(_this44.toggleMicorphone(!0),e.elementRef[m].replace(Q.MICROPHONE_ACTIVE,Q.BUTTON_DEFAULT),e.changeToDefault(),_this44._isMuted=!1):(_this44.toggleMicorphone(!1),e.elementRef[m].replace(Q.BUTTON_DEFAULT,Q.MICROPHONE_ACTIVE),me.removeAriaAttributes(e.elementRef),e.changeToActive(),_this44._isMuted=!0);}),e;}},{key:"toggleMicorphone",value:function toggleMicorphone(e){var t;(t=this._mediaStream)==null||t.getAudioTracks().forEach(function(n){return n.enabled=e;});}},{key:"createToggleButton",value:function createToggleButton(){var _this45=this;var t;var e=new si((t=this._buttonsConfig)==null?void 0:t.toggle);return e.elementRef[m].add(Q.BUTTON_DEFAULT,"deep-chat-openai-realtime-toggle"),z.assignButtonEvents(e.elementRef,/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee95(){var n,s,_t34,_t35;return _regenerator().w(function(_context95){while(1)switch(_context95.p=_context95.n){case 0:if(!e.isActive){_context95.n=1;break;}e.changeToDefault(),_this45.stop();_context95.n=9;break;case 1:_context95.p=1;if(!_this45._ephemeralKey){_context95.n=3;break;}_this45.displayLoading();_context95.n=2;return _this45.init(_this45._ephemeralKey);case 2:_context95.n=7;break;case 3:if(!_this45._retrievingEphemeralKey){_context95.n=6;break;}_this45.displayLoading();_context95.n=4;return _this45._retrievingEphemeralKey;case 4:s=_context95.v;_t34=(n=_this45._toggleButton)!=null&&n.isActive;if(!_t34){_context95.n=5;break;}_context95.n=5;return _this45.init(s);case 5:_context95.n=7;break;case 6:_this45.displayLoading();_context95.n=7;return _this45.fetchEphemeralKey(!0);case 7:_context95.n=9;break;case 8:_context95.p=8;_t35=_context95.v;console[f]("Failed to start conversation:",_t35),_this45.displayError(),_this45.hideLoading();case 9:return _context95.a(2);}},_callee95,null,[[1,8]]);}))),e;}},{key:"init",value:function(){var _init2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee98(e){var _this46=this;var t,n,s,r,o,a,c,l,_t38,_t39,_t40,_t41,_t42;return _regenerator().w(function(_context98){while(1)switch(_context98.p=_context98.n){case 0:t=new RTCPeerConnection();this._pc=t;n=A($);n.autoplay=!0;s=new AudioContext(),r=s.createAnalyser();r.fftSize=256;o=new Uint8Array(r.frequencyBinCount);this._pc.ontrack=/*#__PURE__*/function(){var _ref92=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee96(a){var c,_t36;return _regenerator().w(function(_context96){while(1)switch(_context96.n){case 0:if(!a.streams[0]){_context96.n=2;break;}n.srcObject=a.streams[0];c=s.createMediaStreamSource(a.streams[0]);_t36=s.state==="suspended";if(!_t36){_context96.n=1;break;}_context96.n=1;return s.resume();case 1:c.connect(r);_this46.monitorFrequencies(r,o);_context96.n=3;break;case 2:console[f]("No streams found in the ontrack event."),_this46.displayError();case 3:return _context96.a(2);}},_callee96);}));return function(_x188){return _ref92.apply(this,arguments);};}();_context98.n=1;return navigator.mediaDevices.getUserMedia({audio:!0}).then(function(a){var c;t===_this46._pc&&(_this46._mediaStream=a,(c=_this46._pc)==null||c.addTrack(_this46._mediaStream.getTracks()[0]),_this46._isMuted&&_this46.toggleMicorphone(!1));})["catch"](function(a){console[f]("Error accessing microphone:",a),_this46.displayError();});case 1:this._dc=this._pc.createDataChannel("oai-events");this._dc.addEventListener("message",/*#__PURE__*/function(){var _ref93=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee97(a){var l,d,p,c,g,y,_,_t37;return _regenerator().w(function(_context97){while(1)switch(_context97.p=_context97.n){case 0:c=JSON.parse(a.data);if(!(c[E]==="session.created")){_context97.n=1;break;}_this46.removeUnavailable(),_this46._toggleButton&&(me.removeAriaAttributes(_this46._toggleButton.elementRef),_this46._toggleButton.changeToActive()),(d=(l=_this46._events)==null?void 0:l.started)==null||d.call(l),_this46._deepChat.dispatchEvent(new CustomEvent(Vl)),_this46.hideLoading();_context97.n=7;break;case 1:if(!(c[E]==="response.done")){_context97.n=6;break;}g=(p=JSON.parse(a.data).response.output)==null?void 0:p[0];if(!((g==null?void 0:g[E])===$s)){_context97.n=5;break;}y=g.name,_=g.call_id;_context97.p=2;_context97.n=3;return _this46.handleTool(y,g.arguments,_);case 3:_context97.n=5;break;case 4:_context97.p=4;_t37=_context97.v;_this46.stopOnError(_t37);case 5:_context97.n=7;break;case 6:c[E]===f?_this46.stopOnError(c[f].message):c[E]===it?_this46.stopOnError(c.message):c[E]==="response.audio_transcript.delta"||(c[E]==="response.audio_transcript.done"?c.transcript&&hn.onMessage(_this46._deepChat,_defineProperty(_defineProperty({},x,ne),h,c.transcript),!1):c[E]==="conversation.item.input_audio_transcription.completed"&&c.transcript&&hn.onMessage(_this46._deepChat,_defineProperty(_defineProperty({},x,F),h,c.transcript),!1));case 7:return _context97.a(2);}},_callee97,null,[[2,4]]);}));return function(_x189){return _ref93.apply(this,arguments);};}());_context98.p=2;_context98.n=3;return this._pc.createOffer();case 3:a=_context98.v;_t38=t!==this._pc;if(_t38){_context98.n=5;break;}_context98.n=4;return this._pc.setLocalDescription(a);case 4:_t38=t!==this._pc;case 5:if(!_t38){_context98.n=6;break;}return _context98.a(2);case 6:_context98.n=7;return fetch("".concat(Ze,"realtime"),{method:ye,body:a.sdp,headers:_defineProperty(_defineProperty({},he,"".concat(Ce).concat(e)),q,"application/sdp")});case 7:c=_context98.v;if(!(t!==this._pc)){_context98.n=8;break;}return _context98.a(2);case 8:_t39=_defineProperty;_t40=_defineProperty({},E,"answer");_context98.n=9;return c[h]();case 9:l=_t39(_t40,"sdp",_context98.v);_t41=t!==this._pc;if(_t41){_context98.n=11;break;}_context98.n=10;return this._pc.setRemoteDescription(l);case 10:_t41=t!==this._pc;case 11:if(!_t41){_context98.n=12;break;}return _context98.a(2);case 12:_context98.n=14;break;case 13:_context98.p=13;_t42=_context98.v;console[f](_t42),this.displayError();case 14:return _context98.a(2);}},_callee98,this,[[2,13]]);}));function init(_x187){return _init2.apply(this,arguments);}return init;}()// there is a bug where sometimes upon refreshing the browser too many times the frequencyData is all 0s
175
171
  // in such instance please wait and refresh at a later time
176
- },{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this47=this;var n=function(_n4){function n(){return _n4.apply(this,arguments);}n.toString=function(){return _n4.toString();};return n;}(function(){var l;e.getByteFrequencyData(t);var s=t.reduce(function(d,p){return d+p;},0),r=t.length*255,o=s/r*100,a=1,c=a+o/100*(((l=_this47._avatarConfig)==null?void 0:l.maxScale)-a);_this47._avatarEl[v].transform="scale(".concat(c,")"),requestAnimationFrame(n);});n();}},{key:"stopOnError",value:function stopOnError(e){this.stop(),console[f](e),this.displayError();}},{key:"stop",value:function stop(){var e,t,n;(e=this._mediaStream)==null||e.getTracks().forEach(function(s){return s.stop();}),this._mediaStream=null,this._pc&&(this._pc.close(),this._pc=null,(n=(t=this._events)==null?void 0:t.stopped)==null||n.call(t),this._deepChat.dispatchEvent(new CustomEvent(Wl)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&Q.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&Q.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&Q.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&Q.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&Q.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&Q.removeButtonUnavailable(this._toggleButton);}},{key:"createError",value:function createError(){var t;var e=A();return e.id="deep-chat-openai-realtime-error",Object.assign(e[v],(t=this._errorConfig)==null?void 0:t[v]),this._errorElement=e,e;}},{key:"displayFailedToRetrieveEphemeralKey",value:function displayFailedToRetrieveEphemeralKey(e){console[f]("Failed to retrieve ephemeral key"),console[f](e),this.displayError();}},{key:"displayError",value:function displayError(){var e;this._errorElement&&(this._errorElement[v].display="block",this._errorElement.textContent=((e=this._errorConfig)==null?void 0:e[h])||"Error",this.changeToUnavailable()),this.hideLoading();}},{key:"createLoading",value:function createLoading(){var t,n;var e=A();return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t[L]&&(this._loadingElement.innerHTML=this._loadingConfig[L]),Object.assign(e[v],(n=this._loadingConfig)==null?void 0:n[v]),e[v].display="none",e;}},{key:"displayLoading",value:function displayLoading(){var e,t,n;this._toggleButton&&(this._toggleButton.changeToActive(),this._toggleButton.elementRef[m].add(Q.BUTTON_LOADING),me.removeAriaDisabled(this._toggleButton.elementRef),me.addAriaBusy(this._toggleButton.elementRef)),(typeof((e=this._loadingConfig)==null?void 0:e.display)!="boolean"||this._loadingConfig.display)&&this._loadingElement&&(this._loadingElement[v].display="block",(t=this._loadingConfig)!=null&&t[L]||(this._loadingElement.textContent=((n=this._loadingConfig)==null?void 0:n[h])||"Loading"));}},{key:"hideLoading",value:function hideLoading(){this._toggleButton&&(this._toggleButton.elementRef[m].remove(Q.BUTTON_LOADING),me.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement[v].display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
177
- },{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t,n){var s,r;return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:if(this._functionHandlerI){_context99.n=1;break;}throw Error(qt);case 1:_context99.n=2;return this._functionHandlerI({name:e,arguments:t});case 2:s=_context99.v;if(!(_typeof(s)!="object"||!Pe.isJson(s))){_context99.n=3;break;}throw Error('The `function_handler` response must be a JSON object, e.g. {response: "My response"}');case 3:r=_defineProperty(_defineProperty(_defineProperty({},E,Qo),"call_id",n),"output",le(s));this.sendMessage(r);case 4:return _context99.a(2);}},_callee99,this);}));function handleTool(_x190,_x191,_x192){return _handleTool.apply(this,arguments);}return handleTool;}()// https://platform.openai.com/docs/api-reference/realtime-client-events/conversation/item/create
178
- },{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=le(_defineProperty(_defineProperty({},E,"conversation.item.create"),"item",e));this._dc.send(t);var n=_defineProperty({},E,"response.create");this._dc.send(le(n));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var n=t==null?void 0:t.realtime;if(_typeof(n)=="object"&&(n.ephemeralKey||n.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?C(e.avatar):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$ct,_o$w,_a$G,_c$content,_t$toggle,_u$w,_g$G,_y$content,_$H,_S$G,_M$content;var n,s,r,o,a,c,l,d,p,u,g,y,_,S,M;var t=_typeof(e)=="object"&&e.buttons?C(e.buttons):{};return(r=(s=(n=t[ct])==null?void 0:n[w])==null?void 0:s[h])!=null&&r.content||((_t$ct=t[ct])!==null&&_t$ct!==void 0?_t$ct:t[ct]={},(_o$w=(o=t[ct])[w])!==null&&_o$w!==void 0?_o$w:o[w]={},(_a$G=(a=t[ct][w])[G])!==null&&_a$G!==void 0?_a$G:a[G]={},(_c$content=(c=t[ct][w][G]).content)!==null&&_c$content!==void 0?_c$content:c.content=ia),(p=(d=(l=t.toggle)==null?void 0:l[w])==null?void 0:d[h])!=null&&p.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_u$w=(u=t.toggle)[w])!==null&&_u$w!==void 0?_u$w:u[w]={},(_g$G=(g=t.toggle[w])[G])!==null&&_g$G!==void 0?_g$G:g[G]={},(_y$content=(y=t.toggle[w][G]).content)!==null&&_y$content!==void 0?_y$content:y.content=ra,(_$H=(_=t.toggle)[H])!==null&&_$H!==void 0?_$H:_[H]={},(_S$G=(S=t.toggle[H])[G])!==null&&_S$G!==void 0?_S$G:S[G]={},(_M$content=(M=t.toggle[H][G]).content)!==null&&_M$content!==void 0?_M$content:M.content=Xi),t;}},{key:"createAvatar",value:function createAvatar(e){var n;var t=A("img");return t.id="deep-chat-openai-realtime-avatar",Object.assign(t[v],(n=e==null?void 0:e[R])==null?void 0:n[W]),t[T]=(e==null?void 0:e[T])||qi,t;}},{key:"createButtonContainer",value:function createButtonContainer(e){var t=A();return t[m].add("deep-chat-openai-realtime-button-container"),t.appendChild(e),t;}},{key:"changeButtonToUnavailable",value:function changeButtonToUnavailable(e){e.elementRef[m].add(Q.UNAVAILABLE),me.removeAriaBusy(e.elementRef),me.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){Q.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){me.removeAriaDisabled(e.elementRef),e.elementRef[m].remove(Q.UNAVAILABLE);}}]);}(k);Q.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",Q.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",Q.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",Q.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var Zi=Q;var An=/*#__PURE__*/function(_k7){function An(e){var _o$model3,_a$voice3;var _this48;_classCallCheck(this,An);var r,o,a;var t=C(e.directConnection),n=t==null?void 0:t.openAI;_this48=_callSuper(this,An,[e,Dn(),Bn,n]),_this48.insertKeyPlaceholderText=_this48.genereteAPIKeyName("OpenAI"),_this48.keyHelpUrl=Nn,_this48.url="".concat(Ze,"audio/speech"),_this48.permittedErrorPrefixes=[Gt];var s=(r=t==null?void 0:t.openAI)==null?void 0:r.textToSpeech;_typeof(s)===U&&Object.assign(_this48.rawBody,s),(_o$model3=(o=_this48.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=An.DEFAULT_MODEL,(_a$voice3=(a=_this48.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=An.DEFAULT_VOIDE,_this48.textInputPlaceholderText="Insert text to generate audio",_this48.rawBody.response_format="mp3";return _this48;}_inherits(An,_k7);return _createClass(An,[{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=C(e),s=(o=(r=t[t[X]-1])==null?void 0:r[h])==null?void 0:o.trim();return s&&s!==""&&(n.input=s),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee100(e,t){return _regenerator().w(function(_context100){while(1)switch(_context100.n){case 0:this.url=this.connectSettings.url||this.url,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context100.a(2);}},_callee100,this);}));function callServiceAPI(_x193,_x194){return _callServiceAPI10.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e){return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if(!(e instanceof Blob)){_context101.n=1;break;}return _context101.a(2,new Promise(function(t){var n=new FileReader();n.readAsDataURL(e),n.onload=function(s){t(_defineProperty({},b,[_defineProperty(_defineProperty({},T,s.target.result),E,$)]));};}));case 1:if(!e[f]){_context101.n=2;break;}throw e[f].message;case 2:return _context101.a(2,_defineProperty({},f,f));}},_callee101);}));function extractResultData(_x195){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(k);An.DEFAULT_MODEL="tts-1",An.DEFAULT_VOIDE="alloy";var Yi=An;var rt=/*#__PURE__*/function(_k8){function rt(e){var _o$model4;var _this49;_classCallCheck(this,rt);var r,o;var t=C(e.directConnection),n=t==null?void 0:t.openAI;_this49=_callSuper(this,rt,[e,Dn(),Bn,n,{audio:{}}]),_this49.insertKeyPlaceholderText=_this49.genereteAPIKeyName("OpenAI"),_this49.keyHelpUrl=Nn,_this49.url="",_this49.permittedErrorPrefixes=[Gt],_this49.textInputPlaceholderText=dr,_this49._service_url=rt.AUDIO_TRANSCRIPTIONS_URL;var s=(r=t==null?void 0:t.openAI)==null?void 0:r[$];_typeof(s)=="object"&&(_this49.processConfig(s),rt.cleanConfig(s),Object.assign(_this49.rawBody,s)),(_o$model4=(o=_this49.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=rt.DEFAULT_MODEL,_this49.rawBody.response_format="json",_this49.canSendMessage=rt.canSendFileMessage;return _this49;}_inherits(rt,_k8);return _createClass(rt,[{key:"processConfig",value:function processConfig(e){e!=null&&e[E]&&e[E]==="translation"&&(this._service_url=rt.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=C(e),s=(o=(r=t[t[X]-1])==null?void 0:r[h])==null?void 0:o.trim();return s&&s!==""&&(n.prompt=s),n;}// prettier-ignore
179
- },{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(e,t,n){var o,s,r;return _regenerator().w(function(_context102){while(1)switch(_context102.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context102.n=1;break;}throw new Error(He);case 1:if(n!=null&&n[0]){_context102.n=2;break;}throw new Error(_i);case 2:this.url=this.connectSettings.url||this._service_url;s=this.preprocessBody(this.rawBody,t),r=rt.createFormDataBody(s,n[0]);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,r,e),!1);case 3:return _context102.a(2);}},_callee102,this);}));function callServiceAPI(_x196,_x197,_x198){return _callServiceAPI11.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103(e){return _regenerator().w(function(_context103){while(1)switch(_context103.n){case 0:if(!e[f]){_context103.n=1;break;}throw e[f].message;case 1:return _context103.a(2,_defineProperty({},h,e[h]));}},_callee103);}));function extractResultData(_x199){return _extractResultData14.apply(this,arguments);}return extractResultData;}()}],[{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e[E];}},{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(se,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}}]);}(k);rt.AUDIO_TRANSCRIPTIONS_URL="".concat(Ze,"audio/transcriptions"),rt.AUDIO_TRANSLATIONS_URL="".concat(Ze,"audio/translations"),rt.DEFAULT_MODEL="whisper-1";var Ji=rt;var Fn="Ocp-Apim-Subscription-Key",oa=// eslint-disable-next-line max-len
180
- "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",Xl=function Xl(i,e){return _defineProperty(_defineProperty(_defineProperty({},Fn,e),q,"application/ssml+xml"),"X-Microsoft-OutputFormat",i);},Zl=function Zl(i){return _defineProperty(_defineProperty({},Fn,i),"Accept",te);},Yl=function Yl(i,e,t,n){i[f]?n(pe):t(e);},Jl=function Jl(i){return{url:"https://".concat(i,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:ye,createHeaders:function createHeaders(e){return _defineProperty({},Fn,"".concat(e));},handleVerificationResult:Yl};},Ql=function Ql(i){return _defineProperty(_defineProperty({},Fn,i),q,te);},ed=function ed(i,e,t,n){var r;((r=i[f])==null?void 0:r.code)==="401"?n(pe):t(e);},td=function td(i){return{url:"".concat(i,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:ye,createHeaders:function createHeaders(e){return _defineProperty({},Fn,"".concat(e));},handleVerificationResult:ed};},nd=function nd(i,e,t,n){i.json().then(function(r){!Array.isArray(r)&&r[f].code===401e3?n(pe):t(e);});},sd=function sd(i){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:ye,createHeaders:function createHeaders(e){return aa(i,e);},handleVerificationResult:nd};},aa=function aa(i,e){var t=_defineProperty(_defineProperty({},Fn,e),q,te);return i&&(t["Ocp-Apim-Subscription-Region"]=i),t;};var id=/*#__PURE__*/function(_k9){// prettier-ignore
181
- function id(e,t,n,s,r){var _this50;_classCallCheck(this,id);_this50=_callSuper(this,id,[e,td(n),t,s,r]),_this50.insertKeyPlaceholderText="Azure Language Subscription Key",_this50.keyHelpUrl=oa,_this50.permittedErrorPrefixes=["Access"];return _this50;}_inherits(id,_k9);return _createClass(id);}(k);var Es=/*#__PURE__*/function(_id){function Es(e){var _a$language;var _this51;_classCallCheck(this,Es);var s,r,o,a;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.summarization,n=(o=e.directConnection)==null?void 0:o.azure;_this51=_callSuper(this,Es,[e,Ql,t.endpoint,n]),_this51.permittedErrorPrefixes=[Es.ENDPOINT_ERROR_MESSAGE],_this51.url="",_this51.textInputPlaceholderText="Insert text to summarize",_this51.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this51.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this51.rawBody,t),_this51.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this51.isTextInputDisabled=!0,_this51.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,Es.ENDPOINT_ERROR_MESSAGE));}));return _this51;}_inherits(Es,_id);return _createClass(Es,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return{analysisInput:{documents:[_defineProperty({id:"1",language:e.language},h,n)]},tasks:[{kind:"ExtractiveSummarization"}]};}},{key:"callServiceAPI",value:function(){var _callServiceAPI12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(e,t){return _regenerator().w(function(_context104){while(1)switch(_context104.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)),this.messages=e;case 1:return _context104.a(2);}},_callee104,this);}));function callServiceAPI(_x200,_x201){return _callServiceAPI12.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e){var t,_n6,s;return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:if(!e[f]){_context105.n=1;break;}throw e[f].message;case 1:if(this.messages&&this.completionsHandlers){this.asyncCallInProgress=!0;_n6=e.headers.get("operation-location"),s={method:ue,headers:(t=this.connectSettings)==null?void 0:t.headers};ge.executePollRequest(this,_n6,s,this.messages);}return _context105.a(2,_defineProperty({},h,""));}},_callee105,this);}));function extractResultData(_x202){return _extractResultData15.apply(this,arguments);}return extractResultData;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(e){var t,_iterator,_step,_n7;return _regenerator().w(function(_context106){while(1)switch(_context106.n){case 0:if(!e[f]){_context106.n=1;break;}throw e[f];case 1:if(!(e.status==="running"||e.status==="notStarted")){_context106.n=2;break;}return _context106.a(2,{timeoutMS:2e3});case 2:if(!(e.errors.length>0)){_context106.n=3;break;}throw e.errors[0];case 3:if(!(e.tasks.items[0].results.errors.length>0)){_context106.n=4;break;}throw e.tasks.items[0].results.errors[0];case 4:t="";_iterator=_createForOfIteratorHelper(e.tasks.items[0].results.documents[0].sentences);try{for(_iterator.s();!(_step=_iterator.n()).done;){_n7=_step.value;t+=_n7[h];}}catch(err){_iterator.e(err);}finally{_iterator.f();}return _context106.a(2,_defineProperty({},h,t||""));}},_callee106);}));function extractPollResultData(_x203){return _extractPollResultData5.apply(this,arguments);}return extractPollResultData;}()}]);}(id);Es.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
182
- "Please define the azure endpoint. [More Information](".concat(Z,"directConnection/Azure#Summarization)");var Qi=Es;var rd=/*#__PURE__*/function(){var _ref101=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(i,e){var t,o,a,l,_t46;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:t=_defineProperty(_defineProperty({},La,i),Oa,te);_t46="https://api.assemblyai.com/v2/transcript/";_context107.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:ye,body:le({audio_url:e}),headers:t});case 1:_context107.n=2;return _context107.v.json();case 2:o=_t46.concat.call(_t46,_context107.v.id);case 3:if(a){_context107.n=9;break;}_context107.n=4;return fetch(o,{headers:t});case 4:_context107.n=5;return _context107.v.json();case 5:l=_context107.v;if(!(l.status===lr)){_context107.n=6;break;}a=l;_context107.n=8;break;case 6:if(!(l.status===f)){_context107.n=7;break;}throw new Error("Transcription failed: ".concat(l[f]));case 7:_context107.n=8;return new Promise(function(d){return setTimeout(d,3e3);});case 8:_context107.n=3;break;case 9:return _context107.a(2,a);}},_callee107);}));return function rd(_x204,_x205){return _ref101.apply(this,arguments);};}(),od=function od(i){return _defineProperty(_defineProperty({},he,i),q,"application/octet-stream");},ad=function ad(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(pe):n(Ue):t(e);},cd=function cd(){return be("https://api.assemblyai.com/v2/upload",ye,ad);};var _r=/*#__PURE__*/function(_k0){function _r(e){var _this52;_classCallCheck(this,_r);var n;var t=(n=e.directConnection)==null?void 0:n.assemblyAI;_this52=_callSuper(this,_r,[e,cd(),od,t,{audio:{}}]),_this52.insertKeyPlaceholderText=_this52.genereteAPIKeyName("AssemblyAI"),_this52.keyHelpUrl="https://www.assemblyai.com/app/account",_this52.url="https://api.assemblyai.com/v2/upload",_this52.isTextInputDisabled=!0,_this52.textInputPlaceholderText=dr,_this52.permittedErrorPrefixes=[jo,Gt],_this52.canSendMessage=_r.canFileSendMessage;return _this52;}_inherits(_r,_k0);return _createClass(_r,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(e,t,n){var s;return _regenerator().w(function(_context108){while(1)switch(_context108.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context108.n=1;break;}throw new Error(He);case 1:if(n!=null&&n[0]){_context108.n=2;break;}throw new Error(_i);case 2:ge.request(this,n[0],e,!1);case 3:return _context108.a(2);}},_callee108,this);}));function callServiceAPI(_x206,_x207,_x208){return _callServiceAPI13.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e){var s,r,t,n;return _regenerator().w(function(_context109){while(1)switch(_context109.n){case 0:if(!e[f]){_context109.n=1;break;}throw e[f];case 1:t=(r=(s=this.connectSettings)==null?void 0:s.headers)==null?void 0:r[he];_context109.n=2;return rd(t,e.upload_url);case 2:n=_context109.v;return _context109.a(2,_defineProperty({},h,n[h]));}},_callee109,this);}));function extractResultData(_x209){return _extractResultData16.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(k);var oi=/*#__PURE__*/function(_k1){// prettier-ignore
183
- function oi(e,t,n,s,r){var _this53$maxMessages,_u$model;var _this53;_classCallCheck(this,oi);var p,u;var o=C(e.directConnection),a=t||Dn(),c=n||Bn,l=s||o.openAI;_this53=_callSuper(this,oi,[e,a,c,l]),_this53.insertKeyPlaceholderText=_this53.genereteAPIKeyName("OpenAI"),_this53.keyHelpUrl="https://platform.openai.com/account/api-keys",_this53.permittedErrorPrefixes=[Ls,"Invalid value"];var d=r||((p=o.openAI)==null?void 0:p.chat);_typeof(d)===U&&_this53.processConfig(d,e),(_this53$maxMessages=_this53.maxMessages)!==null&&_this53$maxMessages!==void 0?_this53$maxMessages:_this53.maxMessages=-1,(_u$model=(u=_this53.rawBody).model)!==null&&_u$model!==void 0?_u$model:u.model="gpt-4o";return _this53;}_inherits(oi,_k1);return _createClass(oi,[{key:"processConfig",value:function processConfig(e,t){var n,s,r;this.completeConfig(e,(r=(s=(n=t.directConnection)==null?void 0:n.openAI)==null?void 0:s.chat)==null?void 0:r.function_handler);}}],[{key:"getBaseFileContent",value:function getBaseFileContent(e){return e.map(function(t){var n,s,r;if(t[E]===$){var o=(n=t[T])==null?void 0:n.split(",")[1],a=((r=(s=t.name)==null?void 0:s.split(".").pop())==null?void 0:r.toLowerCase())||"wav";return _defineProperty(_defineProperty({},E,nn),nn,{data:o,format:a});}return t;});}},{key:"getBaseContent",value:function getBaseContent(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;if(t&&e[b]&&e[b][X]>0){var s=this.getBaseFileContent(e[b]);return e[h]&&e[h].trim()[X]>0&&s.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),s;}return e[h];}}]);}(k);var ai=/*#__PURE__*/function(_oi){function ai(){var _this54;_classCallCheck(this,ai);_this54=_callSuper(this,ai,arguments),_this54.url="".concat(Ze,"chat/completions");return _this54;}_inherits(ai,_oi);return _createClass(ai,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:ai.getContent(r)},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(e,t){var _this$messages;return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:(_this$messages=this.messages)!==null&&_this$messages!==void 0?_this$messages:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context110.a(2);}},_callee110,this);}));function callServiceAPI(_x210,_x211){return _callServiceAPI14.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context111){while(1)switch(_context111.n){case 0:if(!e[f]){_context111.n=1;break;}throw e[f].message;case 1:if(!((s=(n=e.choices)==null?void 0:n[0])!=null&&s.delta)){_context111.n=2;break;}return _context111.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(r=e.choices)==null?void 0:r[0])!=null&&o.message)){_context111.n=5;break;}if(!e.choices[0].message.tool_calls){_context111.n=3;break;}return _context111.a(2,this.handleToolsGeneric(e.choices[0].message,this.functionHandler,this.messages,t));case 3:if(!((a=e.choices[0].message)!=null&&a[$])){_context111.n=4;break;}l=this.deepChat.textToSpeech,d=_typeof(l)=="object"&&typeof((c=l==null?void 0:l[$])==null?void 0:c.displayText)=="boolean";return _context111.a(2,_defineProperty(_defineProperty({},b,[_defineProperty(_defineProperty({},T,"data:audio/wav;base64,".concat(e.choices[0].message[$].data)),E,$)]),h,d?e.choices[0].message[$].transcript:void 0));case 4:return _context111.a(2,_defineProperty({},h,e.choices[0].message.content));case 5:return _context111.a(2,_defineProperty({},h,""));}},_callee111,this);}));function extractResultData(_x212,_x213){return _extractResultData17.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(e,t){return _regenerator().w(function(_context112){while(1)switch(_context112.n){case 0:return _context112.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee112,this);}));function extractStreamResult(_x214,_x215){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return oi.getBaseFileContent(e).map(function(n){return n[E]===nn?n:_defineProperty(_defineProperty({},E,qe),qe,{url:n[T]});});}},{key:"getContent",value:function getContent(e){if(e[b]&&e[b][X]>0){var t=ai.getFileContent(e[b]);return e[h]&&e[h].trim()[X]>0&&t.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),t;}return e[h];}}]);}(oi);var Pr=/*#__PURE__*/function(_k10){// prettier-ignore
184
- function Pr(e,t,n,s,r){var _this55;_classCallCheck(this,Pr);_this55=_callSuper(this,Pr,[e,Jl(n),t,s,r]),_this55.insertKeyPlaceholderText="Azure Speech Subscription Key",_this55.keyHelpUrl=oa;return _this55;}_inherits(Pr,_k10);return _createClass(Pr);}(k);Pr.REGION_ERROR_PREFIX="Please define a region config property. [More Information](".concat(Z,"directConnection/Azure#");var Pn=Pr;var vs=/*#__PURE__*/function(_Pn){// prettier-ignore
185
- function vs(e){var _a$lang,_c$name,_l$gender;var _this56;_classCallCheck(this,vs);var s,r,o,a,c,l;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.textToSpeech,n=(o=e.directConnection)==null?void 0:o.azure;_this56=_callSuper(this,vs,[e,Xl.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,n]),_this56.permittedErrorPrefixes=[vs.REGION_ERROR_MESSAGE],_this56.isTextInputDisabled=!1,_this56.url="",t.region?(Object.assign(_this56.rawBody,t),(_a$lang=(a=_this56.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_c$name=(c=_this56.rawBody).name)!==null&&_c$name!==void 0?_c$name:c.name="en-US-JennyNeural",(_l$gender=(l=_this56.rawBody).gender)!==null&&_l$gender!==void 0?_l$gender:l.gender="Female",_this56.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this56.isTextInputDisabled=!0,_this56.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,vs.REGION_ERROR_MESSAGE));}));return _this56;}_inherits(vs,_Pn);return _createClass(vs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return"<speak version='1.0' xml:lang='".concat(e.lang,"'>\n <voice xml:lang='").concat(e.lang,"' xml:gender='").concat(e.gender,"' name='").concat(e.name,"'>\n ").concat(n,"\n </voice>\n </speak>");}},{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113(e,t){return _regenerator().w(function(_context113){while(1)switch(_context113.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),void 0,!1);case 1:return _context113.a(2);}},_callee113,this);}));function callServiceAPI(_x216,_x217){return _callServiceAPI15.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee114(e){return _regenerator().w(function(_context114){while(1)switch(_context114.n){case 0:return _context114.a(2,new Promise(function(t){var n=new FileReader();n.readAsDataURL(e),n.onload=function(s){t(_defineProperty({},b,[_defineProperty(_defineProperty({},T,s.target.result),E,$)]));};}));}},_callee114);}));function extractResultData(_x218){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}]);}(Pn);vs.REGION_ERROR_MESSAGE="".concat(Pn.REGION_ERROR_PREFIX,"TextToSpeech)");var er=vs;var wn=/*#__PURE__*/function(_Pn2){function wn(e){var _this57;_classCallCheck(this,wn);var r,o,a;var t=(o=(r=e.directConnection)==null?void 0:r.azure)==null?void 0:o.speechToText,n=(a=e.directConnection)==null?void 0:a.azure,s={audio:_defineProperty({},b,{acceptedFormats:".wav,.ogg"})};if(_this57=_callSuper(this,wn,[e,Zl,t.region,n,s]),_this57.permittedErrorPrefixes=[wn.REGION_ERROR_MESSAGE],_this57.url="",_this57.isTextInputDisabled=!0,_this57.textInputPlaceholderText=dr,!t.region)_this57.isTextInputDisabled=!0,_this57.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,wn.REGION_ERROR_MESSAGE));});else{_this57.canSendMessage=wn.canFileSendMessage;var c=t.lang||"en-US";_this57.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(c,"&format=detailed"),_this57.recordAudio=void 0;}return _this57;}_inherits(wn,_Pn2);return _createClass(wn,[{key:"callServiceAPI",value:function(){var _callServiceAPI16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(e,t,n){var s,r;return _regenerator().w(function(_context115){while(1)switch(_context115.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context115.n=1;break;}throw new Error(He);case 1:if(n!=null&&n[0]){_context115.n=2;break;}throw new Error(_i);case 2:(r=this.connectSettings)!=null&&r.headers&&(this.connectSettings.headers[q]=n[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),ge.request(this,n[0],e,!1);case 3:return _context115.a(2);}},_callee115,this);}));function callServiceAPI(_x219,_x220,_x221){return _callServiceAPI16.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee116(e){return _regenerator().w(function(_context116){while(1)switch(_context116.n){case 0:if(!e[f]){_context116.n=1;break;}throw e[f];case 1:return _context116.a(2,_defineProperty({},h,e.DisplayText||""));}},_callee116);}));function extractResultData(_x222){return _extractResultData19.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(Pn);wn.REGION_ERROR_MESSAGE="".concat(Pn.REGION_ERROR_PREFIX,"SpeechToText)");var tr=wn;var ld=/*#__PURE__*/function(_k11){// prettier-ignore
186
- function ld(e){var _this58;_classCallCheck(this,ld);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.translation,n=(o=e.directConnection)==null?void 0:o.azure;_this58=_callSuper(this,ld,[e,sd(t.region),aa.bind({},t==null?void 0:t.region),n]),_this58.insertKeyPlaceholderText="Azure Translate Subscription Key",_this58.keyHelpUrl=// eslint-disable-next-line max-len
187
- "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this58.url="",_this58.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this58;}_inherits(ld,_k11);return _createClass(ld,[{key:"preprocessBody",value:function preprocessBody(e){var t=e[e.length-1][h];if(t)return[{Text:t}];}},{key:"callServiceAPI",value:function(){var _callServiceAPI17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee117(e,t){return _regenerator().w(function(_context117){while(1)switch(_context117.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context117.a(2);}},_callee117,this);}));function callServiceAPI(_x223,_x224){return _callServiceAPI17.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee118(e){var t;return _regenerator().w(function(_context118){while(1)switch(_context118.n){case 0:if(!Array.isArray(e)){_context118.n=1;break;}return _context118.a(2,_defineProperty({},h,((t=e[0].translations)==null?void 0:t[0][h])||""));case 1:throw e[f];case 2:return _context118.a(2);}},_callee118);}));function extractResultData(_x225){return _extractResultData20.apply(this,arguments);}return extractResultData;}()}]);}(k);var dd=/*#__PURE__*/function(_k12){function dd(e){var _o$model5;var _this59;_classCallCheck(this,dd);var r,o;var t=C(e.directConnection),n=t.bigModel;_this59=_callSuper(this,dd,[e,mr(),fr,n]),_this59.insertKeyPlaceholderText=_this59.genereteAPIKeyName("BigModel"),_this59.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this59.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this59.permittedErrorPrefixes=[he,Te];var s=(r=t.bigModel)==null?void 0:r[ee];_typeof(s)===U&&(_this59.cleanConfig(s),Object.assign(_this59.rawBody,s)),(_o$model5=(o=_this59.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this59;}_inherits(dd,_k12);return _createClass(dd,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.prompt=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e,t){return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:return _context119.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee119,this);}));function callServiceAPI(_x226,_x227){return _callServiceAPI18.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee120(e){var t;return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:t=e.data.map(function(n){return n!=null&&n.url?_defineProperty(_defineProperty({},T,n.url),E,W):_defineProperty(_defineProperty({},T,""),E,W);});return _context120.a(2,_defineProperty({},b,t));}},_callee120);}));function extractResultData(_x228){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(k);var ca=function ca(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},hd=function hd(i,e,t,n){var s=i;s[f]?s[f].message===Ei?n(pe):n(Ue):t(e);},la=function la(){return be("https://api.groq.com/openai/v1/models",ue,hd);};var ud=/*#__PURE__*/function(_k13){function ud(e){var _o$model6,_a$voice4,_c$response_format;var _this60;_classCallCheck(this,ud);var r,o,a,c;var t=C(e.directConnection),n=t.groq;_this60=_callSuper(this,ud,[e,la(),ca,n]),_this60.insertKeyPlaceholderText=_this60.genereteAPIKeyName("Groq"),_this60.keyHelpUrl="https://console.groq.com/keys",_this60.url="https://api.groq.com/openai/v1/audio/speech",_this60.permittedErrorPrefixes=[Gt,"property"];var s=(r=t.groq)==null?void 0:r.textToSpeech;_typeof(s)===U&&_this60.completeConfig(s),(_o$model6=(o=_this60.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this60.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_c$response_format=(c=_this60.rawBody).response_format)!==null&&_c$response_format!==void 0?_c$response_format:c.response_format="mp3";return _this60;}_inherits(ud,_k13);return _createClass(ud,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e,t){return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:return _context121.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee121,this);}));function callServiceAPI(_x229,_x230){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e){var t,n,s;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:t=this.rawBody.response_format||"mp3",n=new Blob([e],_defineProperty({},E,"audio/".concat(t))),s=URL.createObjectURL(n);return _context122.a(2,_defineProperty({},b,[_defineProperty(_defineProperty({},T,s),E,$)]));}},_callee122,this);}));function extractResultData(_x231){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(k);var pd=/*#__PURE__*/function(_k14){function pd(e){var _o$model7;var _this61;_classCallCheck(this,pd);var r,o;var t=C(e.directConnection),n=t.together;_this61=_callSuper(this,pd,[e,br(),gr,n]),_this61.insertKeyPlaceholderText=_this61.genereteAPIKeyName("Together AI"),_this61.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this61.url="https://api.together.xyz/v1/images/generations",_this61.permittedErrorPrefixes=[it,Te];var s=(r=t.together)==null?void 0:r[ee];_typeof(s)===U&&_this61.completeConfig(s),(_o$model7=(o=_this61.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this61;}_inherits(pd,_k14);return _createClass(pd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.prompt=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e,t){return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:return _context123.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee123,this);}));function callServiceAPI(_x232,_x233){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e){var t;return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:t=e.data.map(function(n){return n!=null&&n.url?_defineProperty(_defineProperty({},T,n.url),E,W):n!=null&&n.b64_json?_defineProperty(_defineProperty({},T,"data:image/png;base64,".concat(n.b64_json)),E,W):_defineProperty(_defineProperty({},T,""),E,W);});return _context124.a(2,_defineProperty({},b,t));}},_callee124);}));function extractResultData(_x234){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(k);var Xe=/*#__PURE__*/function(_oi2){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
172
+ },{key:"monitorFrequencies",value:function monitorFrequencies(e,t){var _this47=this;var n=function(_n4){function n(){return _n4.apply(this,arguments);}n.toString=function(){return _n4.toString();};return n;}(function(){var l;e.getByteFrequencyData(t);var s=t.reduce(function(d,p){return d+p;},0),r=t.length*255,o=s/r*100,a=1,c=a+o/100*(((l=_this47._avatarConfig)==null?void 0:l.maxScale)-a);_this47._avatarEl[v].transform="scale(".concat(c,")"),requestAnimationFrame(n);});n();}},{key:"stopOnError",value:function stopOnError(e){this.stop(),console[f](e),this.displayError();}},{key:"stop",value:function stop(){var e,t,n;(e=this._mediaStream)==null||e.getTracks().forEach(function(s){return s.stop();}),this._mediaStream=null,this._pc&&(this._pc.close(),this._pc=null,(n=(t=this._events)==null?void 0:t.stopped)==null||n.call(t),this._deepChat.dispatchEvent(new CustomEvent(Kl)),this._dc=void 0);}},{key:"changeToUnavailable",value:function changeToUnavailable(){this._microphoneButton&&Q.changeButtonToUnavailable(this._microphoneButton),this._toggleButton&&Q.changeButtonToUnavailable(this._toggleButton);}},{key:"changeToAvailable",value:function changeToAvailable(){this._microphoneButton&&Q.changeButtonToAvailable(this._microphoneButton),this._toggleButton&&Q.changeButtonToAvailable(this._toggleButton);}},{key:"removeUnavailable",value:function removeUnavailable(){this._microphoneButton&&Q.removeButtonUnavailable(this._microphoneButton),this._toggleButton&&Q.removeButtonUnavailable(this._toggleButton);}},{key:"createError",value:function createError(){var t;var e=A();return e.id="deep-chat-openai-realtime-error",Object.assign(e[v],(t=this._errorConfig)==null?void 0:t[v]),this._errorElement=e,e;}},{key:"displayFailedToRetrieveEphemeralKey",value:function displayFailedToRetrieveEphemeralKey(e){console[f]("Failed to retrieve ephemeral key"),console[f](e),this.displayError();}},{key:"displayError",value:function displayError(){var e;this._errorElement&&(this._errorElement[v].display="block",this._errorElement.textContent=((e=this._errorConfig)==null?void 0:e[h])||"Error",this.changeToUnavailable()),this.hideLoading();}},{key:"createLoading",value:function createLoading(){var t,n;var e=A();return e.id="deep-chat-openai-realtime-loading",this._loadingElement=e,(t=this._loadingConfig)!=null&&t[L]&&(this._loadingElement.innerHTML=this._loadingConfig[L]),Object.assign(e[v],(n=this._loadingConfig)==null?void 0:n[v]),e[v].display="none",e;}},{key:"displayLoading",value:function displayLoading(){var e,t,n;this._toggleButton&&(this._toggleButton.changeToActive(),this._toggleButton.elementRef[m].add(Q.BUTTON_LOADING),me.removeAriaDisabled(this._toggleButton.elementRef),me.addAriaBusy(this._toggleButton.elementRef)),(typeof((e=this._loadingConfig)==null?void 0:e.display)!="boolean"||this._loadingConfig.display)&&this._loadingElement&&(this._loadingElement[v].display="block",(t=this._loadingConfig)!=null&&t[L]||(this._loadingElement.textContent=((n=this._loadingConfig)==null?void 0:n[h])||"Loading"));}},{key:"hideLoading",value:function hideLoading(){this._toggleButton&&(this._toggleButton.elementRef[m].remove(Q.BUTTON_LOADING),me.removeAriaBusy(this._toggleButton.elementRef)),this._loadingElement&&(this._loadingElement[v].display="none");}// https://platform.openai.com/docs/guides/function-calling?api-mode=responses
173
+ },{key:"handleTool",value:function(){var _handleTool=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee99(e,t,n){var s,r;return _regenerator().w(function(_context99){while(1)switch(_context99.n){case 0:if(this._functionHandlerI){_context99.n=1;break;}throw Error(Gt);case 1:_context99.n=2;return this._functionHandlerI({name:e,arguments:t});case 2:s=_context99.v;if(!(_typeof(s)!="object"||!Pe.isJson(s))){_context99.n=3;break;}throw Error('The `function_handler` response must be a JSON object, e.g. {response: "My response"}');case 3:r=_defineProperty(_defineProperty(_defineProperty({},E,Jo),"call_id",n),"output",ce(s));this.sendMessage(r);case 4:return _context99.a(2);}},_callee99,this);}));function handleTool(_x190,_x191,_x192){return _handleTool.apply(this,arguments);}return handleTool;}()// https://platform.openai.com/docs/api-reference/realtime-client-events/conversation/item/create
174
+ },{key:"sendMessage",value:function sendMessage(e){if(!this._dc)return;var t=ce(_defineProperty(_defineProperty({},E,"conversation.item.create"),"item",e));this._dc.send(t);var n=_defineProperty({},E,"response.create");this._dc.send(ce(n));}},{key:"isCustomView",value:function isCustomView(){return!0;}}],[{key:"getKey",value:function getKey(e){var t=e.directConnection.openAI;if(t!=null&&t.key)return t.key;var n=t==null?void 0:t.realtime;if(_typeof(n)=="object"&&(n.ephemeralKey||n.fetchEphemeralKey))return"placeholder";}},{key:"buildAvatarConfig",value:function buildAvatarConfig(e){var t=_typeof(e)=="object"&&e.avatar?C(e.avatar):{};return t.maxScale=t.maxScale&&t.maxScale>=1?t.maxScale:2.5,t;}},{key:"buildButtonsConfig",value:function buildButtonsConfig(e){var _t$ct,_o$w,_a$G,_c$content,_t$toggle,_u$w,_g$G,_y$content,_$H,_S$G,_M$content;var n,s,r,o,a,c,l,d,p,u,g,y,_,S,M;var t=_typeof(e)=="object"&&e.buttons?C(e.buttons):{};return(r=(s=(n=t[ct])==null?void 0:n[w])==null?void 0:s[h])!=null&&r.content||((_t$ct=t[ct])!==null&&_t$ct!==void 0?_t$ct:t[ct]={},(_o$w=(o=t[ct])[w])!==null&&_o$w!==void 0?_o$w:o[w]={},(_a$G=(a=t[ct][w])[G])!==null&&_a$G!==void 0?_a$G:a[G]={},(_c$content=(c=t[ct][w][G]).content)!==null&&_c$content!==void 0?_c$content:c.content=sa),(p=(d=(l=t.toggle)==null?void 0:l[w])==null?void 0:d[h])!=null&&p.content||((_t$toggle=t.toggle)!==null&&_t$toggle!==void 0?_t$toggle:t.toggle={},(_u$w=(u=t.toggle)[w])!==null&&_u$w!==void 0?_u$w:u[w]={},(_g$G=(g=t.toggle[w])[G])!==null&&_g$G!==void 0?_g$G:g[G]={},(_y$content=(y=t.toggle[w][G]).content)!==null&&_y$content!==void 0?_y$content:y.content=ia,(_$H=(_=t.toggle)[H])!==null&&_$H!==void 0?_$H:_[H]={},(_S$G=(S=t.toggle[H])[G])!==null&&_S$G!==void 0?_S$G:S[G]={},(_M$content=(M=t.toggle[H][G]).content)!==null&&_M$content!==void 0?_M$content:M.content=Ki),t;}},{key:"createAvatar",value:function createAvatar(e){var n;var t=A("img");return t.id="deep-chat-openai-realtime-avatar",Object.assign(t[v],(n=e==null?void 0:e[R])==null?void 0:n[W]),t[T]=(e==null?void 0:e[T])||ji,t;}},{key:"createButtonContainer",value:function createButtonContainer(e){var t=A();return t[m].add("deep-chat-openai-realtime-button-container"),t.appendChild(e),t;}},{key:"changeButtonToUnavailable",value:function changeButtonToUnavailable(e){e.elementRef[m].add(Q.UNAVAILABLE),me.removeAriaBusy(e.elementRef),me.addAriaDisabled(e.elementRef),e.changeToUnavailable();}},{key:"changeButtonToAvailable",value:function changeButtonToAvailable(e){Q.removeButtonUnavailable(e),e.changeToDefault();}},{key:"removeButtonUnavailable",value:function removeButtonUnavailable(e){me.removeAriaDisabled(e.elementRef),e.elementRef[m].remove(Q.UNAVAILABLE);}}]);}(k);Q.BUTTON_DEFAULT="deep-chat-openai-realtime-button-default",Q.BUTTON_LOADING="deep-chat-openai-realtime-button-loading",Q.MICROPHONE_ACTIVE="deep-chat-openai-realtime-microphone-active",Q.UNAVAILABLE="deep-chat-openai-realtime-button-unavailable";var Wi=Q;var An=/*#__PURE__*/function(_k7){function An(e){var _o$model3,_a$voice3;var _this48;_classCallCheck(this,An);var r,o,a;var t=C(e.directConnection),n=t==null?void 0:t.openAI;_this48=_callSuper(this,An,[e,Dn(),Bn,n]),_this48.insertKeyPlaceholderText=_this48.genereteAPIKeyName("OpenAI"),_this48.keyHelpUrl=Nn,_this48.url="".concat(Ze,"audio/speech"),_this48.permittedErrorPrefixes=[zt];var s=(r=t==null?void 0:t.openAI)==null?void 0:r.textToSpeech;_typeof(s)===U&&Object.assign(_this48.rawBody,s),(_o$model3=(o=_this48.rawBody).model)!==null&&_o$model3!==void 0?_o$model3:o.model=An.DEFAULT_MODEL,(_a$voice3=(a=_this48.rawBody).voice)!==null&&_a$voice3!==void 0?_a$voice3:a.voice=An.DEFAULT_VOIDE,_this48.textInputPlaceholderText="Insert text to generate audio",_this48.rawBody.response_format="mp3";return _this48;}_inherits(An,_k7);return _createClass(An,[{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=C(e),s=(o=(r=t[t[X]-1])==null?void 0:r[h])==null?void 0:o.trim();return s&&s!==""&&(n.input=s),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI10=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee100(e,t){return _regenerator().w(function(_context100){while(1)switch(_context100.n){case 0:this.url=this.connectSettings.url||this.url,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context100.a(2);}},_callee100,this);}));function callServiceAPI(_x193,_x194){return _callServiceAPI10.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee101(e){return _regenerator().w(function(_context101){while(1)switch(_context101.n){case 0:if(!(e instanceof Blob)){_context101.n=1;break;}return _context101.a(2,new Promise(function(t){var n=new FileReader();n.readAsDataURL(e),n.onload=function(s){t(_defineProperty({},b,[_defineProperty(_defineProperty({},T,s.target.result),E,$)]));};}));case 1:if(!e[f]){_context101.n=2;break;}throw e[f].message;case 2:return _context101.a(2,_defineProperty({},f,f));}},_callee101);}));function extractResultData(_x195){return _extractResultData13.apply(this,arguments);}return extractResultData;}()}]);}(k);An.DEFAULT_MODEL="tts-1",An.DEFAULT_VOIDE="alloy";var Xi=An;var rt=/*#__PURE__*/function(_k8){function rt(e){var _o$model4;var _this49;_classCallCheck(this,rt);var r,o;var t=C(e.directConnection),n=t==null?void 0:t.openAI;_this49=_callSuper(this,rt,[e,Dn(),Bn,n,{audio:{}}]),_this49.insertKeyPlaceholderText=_this49.genereteAPIKeyName("OpenAI"),_this49.keyHelpUrl=Nn,_this49.url="",_this49.permittedErrorPrefixes=[zt],_this49.textInputPlaceholderText=lr,_this49._service_url=rt.AUDIO_TRANSCRIPTIONS_URL;var s=(r=t==null?void 0:t.openAI)==null?void 0:r[$];_typeof(s)=="object"&&(_this49.processConfig(s),rt.cleanConfig(s),Object.assign(_this49.rawBody,s)),(_o$model4=(o=_this49.rawBody).model)!==null&&_o$model4!==void 0?_o$model4:o.model=rt.DEFAULT_MODEL,_this49.rawBody.response_format="json",_this49.canSendMessage=rt.canSendFileMessage;return _this49;}_inherits(rt,_k8);return _createClass(rt,[{key:"processConfig",value:function processConfig(e){e!=null&&e[E]&&e[E]==="translation"&&(this._service_url=rt.AUDIO_TRANSLATIONS_URL,delete e.language);}},{key:"preprocessBody",value:function preprocessBody(e,t){var r,o;var n=C(e),s=(o=(r=t[t[X]-1])==null?void 0:r[h])==null?void 0:o.trim();return s&&s!==""&&(n.prompt=s),n;}// prettier-ignore
175
+ },{key:"callServiceAPI",value:function(){var _callServiceAPI11=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee102(e,t,n){var o,s,r;return _regenerator().w(function(_context102){while(1)switch(_context102.n){case 0:if((o=this.connectSettings)!=null&&o.headers){_context102.n=1;break;}throw new Error(He);case 1:if(n!=null&&n[0]){_context102.n=2;break;}throw new Error(bi);case 2:this.url=this.connectSettings.url||this._service_url;s=this.preprocessBody(this.rawBody,t),r=rt.createFormDataBody(s,n[0]);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,r,e),!1);case 3:return _context102.a(2);}},_callee102,this);}));function callServiceAPI(_x196,_x197,_x198){return _callServiceAPI11.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee103(e){return _regenerator().w(function(_context103){while(1)switch(_context103.n){case 0:if(!e[f]){_context103.n=1;break;}throw e[f].message;case 1:return _context103.a(2,_defineProperty({},h,e[h]));}},_callee103);}));function extractResultData(_x199){return _extractResultData14.apply(this,arguments);}return extractResultData;}()}],[{key:"canSendFileMessage",value:function canSendFileMessage(e,t){return!!(t!=null&&t[0]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e[E];}},{key:"createFormDataBody",value:function createFormDataBody(e,t){var n=new FormData();return n.append(se,t),Object.keys(e).forEach(function(s){n.append(s,String(e[s]));}),n;}}]);}(k);rt.AUDIO_TRANSCRIPTIONS_URL="".concat(Ze,"audio/transcriptions"),rt.AUDIO_TRANSLATIONS_URL="".concat(Ze,"audio/translations"),rt.DEFAULT_MODEL="whisper-1";var Zi=rt;var Fn="Ocp-Apim-Subscription-Key",ra=// eslint-disable-next-line max-len
176
+ "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",Wl=function Wl(i,e){return _defineProperty(_defineProperty(_defineProperty({},Fn,e),q,"application/ssml+xml"),"X-Microsoft-OutputFormat",i);},Xl=function Xl(i){return _defineProperty(_defineProperty({},Fn,i),"Accept",te);},Zl=function Zl(i,e,t,n){i[f]?n(pe):t(e);},Yl=function Yl(i){return{url:"https://".concat(i,".api.cognitive.microsoft.com/sts/v1.0/issuetoken"),method:ye,createHeaders:function createHeaders(e){return _defineProperty({},Fn,"".concat(e));},handleVerificationResult:Zl};},Jl=function Jl(i){return _defineProperty(_defineProperty({},Fn,i),q,te);},Ql=function Ql(i,e,t,n){var r;((r=i[f])==null?void 0:r.code)==="401"?n(pe):t(e);},ed=function ed(i){return{url:"".concat(i,"/language/analyze-text/jobs?api-version=2022-10-01-preview"),method:ye,createHeaders:function createHeaders(e){return _defineProperty({},Fn,"".concat(e));},handleVerificationResult:Ql};},td=function td(i,e,t,n){i.json().then(function(r){!Array.isArray(r)&&r[f].code===401e3?n(pe):t(e);});},nd=function nd(i){return{url:"https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es",method:ye,createHeaders:function createHeaders(e){return oa(i,e);},handleVerificationResult:td};},oa=function oa(i,e){var t=_defineProperty(_defineProperty({},Fn,e),q,te);return i&&(t["Ocp-Apim-Subscription-Region"]=i),t;};var sd=/*#__PURE__*/function(_k9){// prettier-ignore
177
+ function sd(e,t,n,s,r){var _this50;_classCallCheck(this,sd);_this50=_callSuper(this,sd,[e,ed(n),t,s,r]),_this50.insertKeyPlaceholderText="Azure Language Subscription Key",_this50.keyHelpUrl=ra,_this50.permittedErrorPrefixes=["Access"];return _this50;}_inherits(sd,_k9);return _createClass(sd);}(k);var _s=/*#__PURE__*/function(_sd){function _s(e){var _a$language;var _this51;_classCallCheck(this,_s);var s,r,o,a;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.summarization,n=(o=e.directConnection)==null?void 0:o.azure;_this51=_callSuper(this,_s,[e,Jl,t.endpoint,n]),_this51.permittedErrorPrefixes=[_s.ENDPOINT_ERROR_MESSAGE],_this51.url="",_this51.textInputPlaceholderText="Insert text to summarize",_this51.isTextInputDisabled=!1,t.endpoint?((_a$language=(a=_this51.rawBody).language)!==null&&_a$language!==void 0?_a$language:a.language="en",Object.assign(_this51.rawBody,t),_this51.url="".concat(t.endpoint,"/language/analyze-text/jobs?api-version=2022-10-01-preview")):(_this51.isTextInputDisabled=!0,_this51.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,_s.ENDPOINT_ERROR_MESSAGE));}));return _this51;}_inherits(_s,_sd);return _createClass(_s,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return{analysisInput:{documents:[_defineProperty({id:"1",language:e.language},h,n)]},tasks:[{kind:"ExtractiveSummarization"}]};}},{key:"callServiceAPI",value:function(){var _callServiceAPI12=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee104(e,t){return _regenerator().w(function(_context104){while(1)switch(_context104.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)),this.messages=e;case 1:return _context104.a(2);}},_callee104,this);}));function callServiceAPI(_x200,_x201){return _callServiceAPI12.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee105(e){var t,_n6,s;return _regenerator().w(function(_context105){while(1)switch(_context105.n){case 0:if(!e[f]){_context105.n=1;break;}throw e[f].message;case 1:if(this.messages&&this.completionsHandlers){this.asyncCallInProgress=!0;_n6=e.headers.get("operation-location"),s={method:ue,headers:(t=this.connectSettings)==null?void 0:t.headers};ge.executePollRequest(this,_n6,s,this.messages);}return _context105.a(2,_defineProperty({},h,""));}},_callee105,this);}));function extractResultData(_x202){return _extractResultData15.apply(this,arguments);}return extractResultData;}()},{key:"extractPollResultData",value:function(){var _extractPollResultData5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee106(e){var t,_iterator,_step,_n7;return _regenerator().w(function(_context106){while(1)switch(_context106.n){case 0:if(!e[f]){_context106.n=1;break;}throw e[f];case 1:if(!(e.status==="running"||e.status==="notStarted")){_context106.n=2;break;}return _context106.a(2,{timeoutMS:2e3});case 2:if(!(e.errors.length>0)){_context106.n=3;break;}throw e.errors[0];case 3:if(!(e.tasks.items[0].results.errors.length>0)){_context106.n=4;break;}throw e.tasks.items[0].results.errors[0];case 4:t="";_iterator=_createForOfIteratorHelper(e.tasks.items[0].results.documents[0].sentences);try{for(_iterator.s();!(_step=_iterator.n()).done;){_n7=_step.value;t+=_n7[h];}}catch(err){_iterator.e(err);}finally{_iterator.f();}return _context106.a(2,_defineProperty({},h,t||""));}},_callee106);}));function extractPollResultData(_x203){return _extractPollResultData5.apply(this,arguments);}return extractPollResultData;}()}]);}(sd);_s.ENDPOINT_ERROR_MESSAGE=// eslint-disable-next-line max-len
178
+ "Please define the azure endpoint. [More Information](".concat(Z,"directConnection/Azure#Summarization)");var Yi=_s;var id=/*#__PURE__*/function(){var _ref105=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee107(i,e){var t,o,a,l,_t46;return _regenerator().w(function(_context107){while(1)switch(_context107.n){case 0:t=_defineProperty(_defineProperty({},Pa,i),La,te);_t46="https://api.assemblyai.com/v2/transcript/";_context107.n=1;return fetch("https://api.assemblyai.com/v2/transcript",{method:ye,body:ce({audio_url:e}),headers:t});case 1:_context107.n=2;return _context107.v.json();case 2:o=_t46.concat.call(_t46,_context107.v.id);case 3:if(a){_context107.n=9;break;}_context107.n=4;return fetch(o,{headers:t});case 4:_context107.n=5;return _context107.v.json();case 5:l=_context107.v;if(!(l.status===cr)){_context107.n=6;break;}a=l;_context107.n=8;break;case 6:if(!(l.status===f)){_context107.n=7;break;}throw new Error("Transcription failed: ".concat(l[f]));case 7:_context107.n=8;return new Promise(function(d){return setTimeout(d,3e3);});case 8:_context107.n=3;break;case 9:return _context107.a(2,a);}},_callee107);}));return function id(_x204,_x205){return _ref105.apply(this,arguments);};}(),rd=function rd(i){return _defineProperty(_defineProperty({},he,i),q,"application/octet-stream");},od=function od(i,e,t,n){var s=i;s[f]?s[f].code==="invalid_api_key"?n(pe):n(Ue):t(e);},ad=function ad(){return be("https://api.assemblyai.com/v2/upload",ye,od);};var yr=/*#__PURE__*/function(_k0){function yr(e){var _this52;_classCallCheck(this,yr);var n;var t=(n=e.directConnection)==null?void 0:n.assemblyAI;_this52=_callSuper(this,yr,[e,ad(),rd,t,{audio:{}}]),_this52.insertKeyPlaceholderText=_this52.genereteAPIKeyName("AssemblyAI"),_this52.keyHelpUrl="https://www.assemblyai.com/app/account",_this52.url="https://api.assemblyai.com/v2/upload",_this52.isTextInputDisabled=!0,_this52.textInputPlaceholderText=lr,_this52.permittedErrorPrefixes=[Ho,zt],_this52.canSendMessage=yr.canFileSendMessage;return _this52;}_inherits(yr,_k0);return _createClass(yr,[{key:"callServiceAPI",value:function(){var _callServiceAPI13=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee108(e,t,n){var s;return _regenerator().w(function(_context108){while(1)switch(_context108.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context108.n=1;break;}throw new Error(He);case 1:if(n!=null&&n[0]){_context108.n=2;break;}throw new Error(bi);case 2:ge.request(this,n[0],e,!1);case 3:return _context108.a(2);}},_callee108,this);}));function callServiceAPI(_x206,_x207,_x208){return _callServiceAPI13.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee109(e){var s,r,t,n;return _regenerator().w(function(_context109){while(1)switch(_context109.n){case 0:if(!e[f]){_context109.n=1;break;}throw e[f];case 1:t=(r=(s=this.connectSettings)==null?void 0:s.headers)==null?void 0:r[he];_context109.n=2;return id(t,e.upload_url);case 2:n=_context109.v;return _context109.a(2,_defineProperty({},h,n[h]));}},_callee109,this);}));function extractResultData(_x209){return _extractResultData16.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(k);var ii=/*#__PURE__*/function(_k1){// prettier-ignore
179
+ function ii(e,t,n,s,r){var _this53$maxMessages,_u$model;var _this53;_classCallCheck(this,ii);var p,u;var o=C(e.directConnection),a=t||Dn(),c=n||Bn,l=s||o.openAI;_this53=_callSuper(this,ii,[e,a,c,l]),_this53.insertKeyPlaceholderText=_this53.genereteAPIKeyName("OpenAI"),_this53.keyHelpUrl="https://platform.openai.com/account/api-keys",_this53.permittedErrorPrefixes=[Ps,"Invalid value"];var d=r||((p=o.openAI)==null?void 0:p.chat);_typeof(d)===U&&_this53.processConfig(d,e),(_this53$maxMessages=_this53.maxMessages)!==null&&_this53$maxMessages!==void 0?_this53$maxMessages:_this53.maxMessages=-1,(_u$model=(u=_this53.rawBody).model)!==null&&_u$model!==void 0?_u$model:u.model="gpt-4o";return _this53;}_inherits(ii,_k1);return _createClass(ii,[{key:"processConfig",value:function processConfig(e,t){var n,s,r;this.completeConfig(e,(r=(s=(n=t.directConnection)==null?void 0:n.openAI)==null?void 0:s.chat)==null?void 0:r.function_handler);}}],[{key:"getBaseFileContent",value:function getBaseFileContent(e){return e.map(function(t){var n,s,r;if(t[E]===$){var o=(n=t[T])==null?void 0:n.split(",")[1],a=((r=(s=t.name)==null?void 0:s.split(".").pop())==null?void 0:r.toLowerCase())||"wav";return _defineProperty(_defineProperty({},E,sn),sn,{data:o,format:a});}return t;});}},{key:"getBaseContent",value:function getBaseContent(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;if(t&&e[b]&&e[b][X]>0){var s=this.getBaseFileContent(e[b]);return e[h]&&e[h].trim()[X]>0&&s.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),s;}return e[h];}}]);}(k);var ri=/*#__PURE__*/function(_ii){function ri(){var _this54;_classCallCheck(this,ri);_this54=_callSuper(this,ri,arguments),_this54.url="".concat(Ze,"chat/completions");return _this54;}_inherits(ri,_ii);return _createClass(ri,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:ri.getContent(r)},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI14=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee110(e,t){var _this$messages;return _regenerator().w(function(_context110){while(1)switch(_context110.n){case 0:(_this$messages=this.messages)!==null&&_this$messages!==void 0?_this$messages:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context110.a(2);}},_callee110,this);}));function callServiceAPI(_x210,_x211){return _callServiceAPI14.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee111(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context111){while(1)switch(_context111.n){case 0:if(!e[f]){_context111.n=1;break;}throw e[f].message;case 1:if(!((s=(n=e.choices)==null?void 0:n[0])!=null&&s.delta)){_context111.n=2;break;}return _context111.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!((o=(r=e.choices)==null?void 0:r[0])!=null&&o.message)){_context111.n=5;break;}if(!e.choices[0].message.tool_calls){_context111.n=3;break;}return _context111.a(2,this.handleToolsGeneric(e.choices[0].message,this.functionHandler,this.messages,t));case 3:if(!((a=e.choices[0].message)!=null&&a[$])){_context111.n=4;break;}l=this.deepChat.textToSpeech,d=_typeof(l)=="object"&&typeof((c=l==null?void 0:l[$])==null?void 0:c.displayText)=="boolean";return _context111.a(2,_defineProperty(_defineProperty({},b,[_defineProperty(_defineProperty({},T,"data:audio/wav;base64,".concat(e.choices[0].message[$].data)),E,$)]),h,d?e.choices[0].message[$].transcript:void 0));case 4:return _context111.a(2,_defineProperty({},h,e.choices[0].message.content));case 5:return _context111.a(2,_defineProperty({},h,""));}},_callee111,this);}));function extractResultData(_x212,_x213){return _extractResultData17.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee112(e,t){return _regenerator().w(function(_context112){while(1)switch(_context112.n){case 0:return _context112.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee112,this);}));function extractStreamResult(_x214,_x215){return _extractStreamResult.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return ii.getBaseFileContent(e).map(function(n){return n[E]===sn?n:_defineProperty(_defineProperty({},E,qe),qe,{url:n[T]});});}},{key:"getContent",value:function getContent(e){if(e[b]&&e[b][X]>0){var t=ri.getFileContent(e[b]);return e[h]&&e[h].trim()[X]>0&&t.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),t;}return e[h];}}]);}(ii);var kr=/*#__PURE__*/function(_k10){// prettier-ignore
180
+ function kr(e,t,n,s,r){var _this55;_classCallCheck(this,kr);_this55=_callSuper(this,kr,[e,Yl(n),t,s,r]),_this55.insertKeyPlaceholderText="Azure Speech Subscription Key",_this55.keyHelpUrl=ra;return _this55;}_inherits(kr,_k10);return _createClass(kr);}(k);kr.REGION_ERROR_PREFIX="Please define a region config property. [More Information](".concat(Z,"directConnection/Azure#");var Pn=kr;var Es=/*#__PURE__*/function(_Pn){// prettier-ignore
181
+ function Es(e){var _a$lang,_c$name,_l$gender;var _this56;_classCallCheck(this,Es);var s,r,o,a,c,l;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.textToSpeech,n=(o=e.directConnection)==null?void 0:o.azure;_this56=_callSuper(this,Es,[e,Wl.bind({},(t==null?void 0:t.outputFormat)||"audio-16khz-128kbitrate-mono-mp3"),t.region,n]),_this56.permittedErrorPrefixes=[Es.REGION_ERROR_MESSAGE],_this56.isTextInputDisabled=!1,_this56.url="",t.region?(Object.assign(_this56.rawBody,t),(_a$lang=(a=_this56.rawBody).lang)!==null&&_a$lang!==void 0?_a$lang:a.lang="en-US",(_c$name=(c=_this56.rawBody).name)!==null&&_c$name!==void 0?_c$name:c.name="en-US-JennyNeural",(_l$gender=(l=_this56.rawBody).gender)!==null&&_l$gender!==void 0?_l$gender:l.gender="Female",_this56.url="https://".concat(t.region,".tts.speech.microsoft.com/cognitiveservices/v1")):(_this56.isTextInputDisabled=!0,_this56.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,Es.REGION_ERROR_MESSAGE));}));return _this56;}_inherits(Es,_Pn);return _createClass(Es,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h];if(n)return"<speak version='1.0' xml:lang='".concat(e.lang,"'>\n <voice xml:lang='").concat(e.lang,"' xml:gender='").concat(e.gender,"' name='").concat(e.name,"'>\n ").concat(n,"\n </voice>\n </speak>");}},{key:"callServiceAPI",value:function(){var _callServiceAPI15=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee113(e,t){return _regenerator().w(function(_context113){while(1)switch(_context113.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),void 0,!1);case 1:return _context113.a(2);}},_callee113,this);}));function callServiceAPI(_x216,_x217){return _callServiceAPI15.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee114(e){return _regenerator().w(function(_context114){while(1)switch(_context114.n){case 0:return _context114.a(2,new Promise(function(t){var n=new FileReader();n.readAsDataURL(e),n.onload=function(s){t(_defineProperty({},b,[_defineProperty(_defineProperty({},T,s.target.result),E,$)]));};}));}},_callee114);}));function extractResultData(_x218){return _extractResultData18.apply(this,arguments);}return extractResultData;}()}]);}(Pn);Es.REGION_ERROR_MESSAGE="".concat(Pn.REGION_ERROR_PREFIX,"TextToSpeech)");var Ji=Es;var wn=/*#__PURE__*/function(_Pn2){function wn(e){var _this57;_classCallCheck(this,wn);var r,o,a;var t=(o=(r=e.directConnection)==null?void 0:r.azure)==null?void 0:o.speechToText,n=(a=e.directConnection)==null?void 0:a.azure,s={audio:_defineProperty({},b,{acceptedFormats:".wav,.ogg"})};if(_this57=_callSuper(this,wn,[e,Xl,t.region,n,s]),_this57.permittedErrorPrefixes=[wn.REGION_ERROR_MESSAGE],_this57.url="",_this57.isTextInputDisabled=!0,_this57.textInputPlaceholderText=lr,!t.region)_this57.isTextInputDisabled=!0,_this57.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,wn.REGION_ERROR_MESSAGE));});else{_this57.canSendMessage=wn.canFileSendMessage;var c=t.lang||"en-US";_this57.url="https://".concat(t.region,".stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=").concat(c,"&format=detailed"),_this57.recordAudio=void 0;}return _this57;}_inherits(wn,_Pn2);return _createClass(wn,[{key:"callServiceAPI",value:function(){var _callServiceAPI16=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee115(e,t,n){var s,r;return _regenerator().w(function(_context115){while(1)switch(_context115.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context115.n=1;break;}throw new Error(He);case 1:if(n!=null&&n[0]){_context115.n=2;break;}throw new Error(bi);case 2:(r=this.connectSettings)!=null&&r.headers&&(this.connectSettings.headers[q]=n[0].name.toLocaleLowerCase().endsWith(".wav")?"audio/wav; codecs=audio/pcm; samplerate=16000":"audio/ogg; codecs=opus"),ge.request(this,n[0],e,!1);case 3:return _context115.a(2);}},_callee115,this);}));function callServiceAPI(_x219,_x220,_x221){return _callServiceAPI16.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee116(e){return _regenerator().w(function(_context116){while(1)switch(_context116.n){case 0:if(!e[f]){_context116.n=1;break;}throw e[f];case 1:return _context116.a(2,_defineProperty({},h,e.DisplayText||""));}},_callee116);}));function extractResultData(_x222){return _extractResultData19.apply(this,arguments);}return extractResultData;}()}],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0]);}}]);}(Pn);wn.REGION_ERROR_MESSAGE="".concat(Pn.REGION_ERROR_PREFIX,"SpeechToText)");var Qi=wn;var cd=/*#__PURE__*/function(_k11){// prettier-ignore
182
+ function cd(e){var _this58;_classCallCheck(this,cd);var s,r,o;var t=(r=(s=e.directConnection)==null?void 0:s.azure)==null?void 0:r.translation,n=(o=e.directConnection)==null?void 0:o.azure;_this58=_callSuper(this,cd,[e,nd(t.region),oa.bind({},t==null?void 0:t.region),n]),_this58.insertKeyPlaceholderText="Azure Translate Subscription Key",_this58.keyHelpUrl=// eslint-disable-next-line max-len
183
+ "https://learn.microsoft.com/en-us/azure/api-management/api-management-subscriptions#create-and-manage-subscriptions-in-azure-portal",_this58.url="",_this58.url="https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=".concat(t.language||"es");return _this58;}_inherits(cd,_k11);return _createClass(cd,[{key:"preprocessBody",value:function preprocessBody(e){var t=e[e.length-1][h];if(t)return[{Text:t}];}},{key:"callServiceAPI",value:function(){var _callServiceAPI17=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee117(e,t){return _regenerator().w(function(_context117){while(1)switch(_context117.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context117.a(2);}},_callee117,this);}));function callServiceAPI(_x223,_x224){return _callServiceAPI17.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee118(e){var t;return _regenerator().w(function(_context118){while(1)switch(_context118.n){case 0:if(!Array.isArray(e)){_context118.n=1;break;}return _context118.a(2,_defineProperty({},h,((t=e[0].translations)==null?void 0:t[0][h])||""));case 1:throw e[f];case 2:return _context118.a(2);}},_callee118);}));function extractResultData(_x225){return _extractResultData20.apply(this,arguments);}return extractResultData;}()}]);}(k);var ld=/*#__PURE__*/function(_k12){function ld(e){var _o$model5;var _this59;_classCallCheck(this,ld);var r,o;var t=C(e.directConnection),n=t.bigModel;_this59=_callSuper(this,ld,[e,fr(),pr,n]),_this59.insertKeyPlaceholderText=_this59.genereteAPIKeyName("BigModel"),_this59.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this59.url="https://open.bigmodel.cn/api/paas/v4/images/generations",_this59.permittedErrorPrefixes=[he,Te];var s=(r=t.bigModel)==null?void 0:r[ee];_typeof(s)===U&&(_this59.cleanConfig(s),Object.assign(_this59.rawBody,s)),(_o$model5=(o=_this59.rawBody).model)!==null&&_o$model5!==void 0?_o$model5:o.model="cogview-4-250304";return _this59;}_inherits(ld,_k12);return _createClass(ld,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.prompt=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI18=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee119(e,t){return _regenerator().w(function(_context119){while(1)switch(_context119.n){case 0:return _context119.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee119,this);}));function callServiceAPI(_x226,_x227){return _callServiceAPI18.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee120(e){var t;return _regenerator().w(function(_context120){while(1)switch(_context120.n){case 0:t=e.data.map(function(n){return n!=null&&n.url?_defineProperty(_defineProperty({},T,n.url),E,W):_defineProperty(_defineProperty({},T,""),E,W);});return _context120.a(2,_defineProperty({},b,t));}},_callee120);}));function extractResultData(_x228){return _extractResultData21.apply(this,arguments);}return extractResultData;}()}]);}(k);var aa=function aa(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},dd=function dd(i,e,t,n){var s=i;s[f]?s[f].message===yi?n(pe):n(Ue):t(e);},ca=function ca(){return be("https://api.groq.com/openai/v1/models",ue,dd);};var hd=/*#__PURE__*/function(_k13){function hd(e){var _o$model6,_a$voice4,_c$response_format;var _this60;_classCallCheck(this,hd);var r,o,a,c;var t=C(e.directConnection),n=t.groq;_this60=_callSuper(this,hd,[e,ca(),aa,n]),_this60.insertKeyPlaceholderText=_this60.genereteAPIKeyName("Groq"),_this60.keyHelpUrl="https://console.groq.com/keys",_this60.url="https://api.groq.com/openai/v1/audio/speech",_this60.permittedErrorPrefixes=[zt,"property"];var s=(r=t.groq)==null?void 0:r.textToSpeech;_typeof(s)===U&&_this60.completeConfig(s),(_o$model6=(o=_this60.rawBody).model)!==null&&_o$model6!==void 0?_o$model6:o.model="playai-tts",(_a$voice4=(a=_this60.rawBody).voice)!==null&&_a$voice4!==void 0?_a$voice4:a.voice="Fritz-PlayAI",(_c$response_format=(c=_this60.rawBody).response_format)!==null&&_c$response_format!==void 0?_c$response_format:c.response_format="mp3";return _this60;}_inherits(hd,_k13);return _createClass(hd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.input=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI19=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee121(e,t){return _regenerator().w(function(_context121){while(1)switch(_context121.n){case 0:return _context121.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee121,this);}));function callServiceAPI(_x229,_x230){return _callServiceAPI19.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee122(e){var t,n,s;return _regenerator().w(function(_context122){while(1)switch(_context122.n){case 0:t=this.rawBody.response_format||"mp3",n=new Blob([e],_defineProperty({},E,"audio/".concat(t))),s=URL.createObjectURL(n);return _context122.a(2,_defineProperty({},b,[_defineProperty(_defineProperty({},T,s),E,$)]));}},_callee122,this);}));function extractResultData(_x231){return _extractResultData22.apply(this,arguments);}return extractResultData;}()}]);}(k);var ud=/*#__PURE__*/function(_k14){function ud(e){var _o$model7;var _this61;_classCallCheck(this,ud);var r,o;var t=C(e.directConnection),n=t.together;_this61=_callSuper(this,ud,[e,gr(),mr,n]),_this61.insertKeyPlaceholderText=_this61.genereteAPIKeyName("Together AI"),_this61.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this61.url="https://api.together.xyz/v1/images/generations",_this61.permittedErrorPrefixes=[it,Te];var s=(r=t.together)==null?void 0:r[ee];_typeof(s)===U&&_this61.completeConfig(s),(_o$model7=(o=_this61.rawBody).model)!==null&&_o$model7!==void 0?_o$model7:o.model="black-forest-labs/FLUX.1-schnell-Free";return _this61;}_inherits(ud,_k14);return _createClass(ud,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t[t.length-1];return n.prompt=(s==null?void 0:s[h])||"",n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI20=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee123(e,t){return _regenerator().w(function(_context123){while(1)switch(_context123.n){case 0:return _context123.a(2,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this)));}},_callee123,this);}));function callServiceAPI(_x232,_x233){return _callServiceAPI20.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee124(e){var t;return _regenerator().w(function(_context124){while(1)switch(_context124.n){case 0:t=e.data.map(function(n){return n!=null&&n.url?_defineProperty(_defineProperty({},T,n.url),E,W):n!=null&&n.b64_json?_defineProperty(_defineProperty({},T,"data:image/png;base64,".concat(n.b64_json)),E,W):_defineProperty(_defineProperty({},T,""),E,W);});return _context124.a(2,_defineProperty({},b,t));}},_callee124);}));function extractResultData(_x234){return _extractResultData23.apply(this,arguments);}return extractResultData;}()}]);}(k);var Xe=/*#__PURE__*/function(_ii2){// https://platform.openai.com/docs/models/gpt-4o-audio-preview
188
184
  // prettier-ignore
189
- function Xe(e,t,n,s,r){var _this62;_classCallCheck(this,Xe);var a,c;_this62=_callSuper(this,Xe,[e,t,n,s,r]),_this62.keyHelpUrl=Nn,_this62.url="".concat(Ze,"responses"),_this62._functionStreamInProgress=!1,_this62._useConversation=!1,_this62._conversationLoadLimit=50;var o=r||((c=(a=e.directConnection)==null?void 0:a.openAI)==null?void 0:c.chat);_this62._urlSegments=Xe.buildUrlSegments(o),_this62.url=_this62._urlSegments.responsesUrl,_typeof(o)===U&&o!==!0&&o&&(o.conversation&&(_this62._useConversation=!0,typeof o.conversation=="string"&&(_this62._conversationId=o.conversation)),typeof o.conversationLoadLimit=="number"&&(_this62._conversationLoadLimit=o.conversationLoadLimit),_this62.cleanConfig(o)),_this62._conversationId&&(_this62.fetchHistory=_this62.fetchHistoryFunc.bind(_this62));return _this62;}_inherits(Xe,_oi2);return _createClass(Xe,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Xe,"processConfig",this,3)([e,t]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.conversation,delete e.conversationLoadLimit,delete e.custom_base_url;}},{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(){var _this63=this;var e,t,_n8,_t48;return _regenerator().w(function(_context125){while(1)switch(_context125.p=_context125.n){case 0:setTimeout(function(){return _this63.deepChat.disableSubmitButton();},2);_context125.p=1;e=this.url,t=this._urlSegments.conversationsUrl;this.url="".concat(t,"/").concat(this._conversationId,"/items?limit=").concat(this._conversationLoadLimit);_context125.n=2;return jt(this,{},ue);case 2:_n8=_context125.v;return _context125.a(2,(this.connectSettings.method=ye,this.url=e,this.deepChat.disableSubmitButton(!1),this.processConversationHistory(_n8)));case 3:_context125.p=3;_t48=_context125.v;return _context125.a(2,(this.deepChat.disableSubmitButton(!1),[_defineProperty({},f,Ho)]));}},_callee125,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc2.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processConversationHistory",value:function processConversationHistory(e){if(!e.data||!Array.isArray(e.data))return[];var t=[];var _iterator2=_createForOfIteratorHelper(Xe.filterCompleted(e.data.reverse())),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _n9=_step2.value;if(_n9[E]==="message"&&_n9.content&&Array.isArray(_n9.content)){var _iterator3=_createForOfIteratorHelper(_n9.content),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var s=_step3.value;(s[E]===Ki||s[E]===io)&&s[h]?t.push(_defineProperty(_defineProperty({},x,_n9[x]),h,s[h])):s[E]===so&&t.push(_defineProperty(_defineProperty({},x,_n9[x]),b,Xe.generateImageFile(s[qe]||"")));}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}else _n9[E]===Di&&t.push(_defineProperty(_defineProperty({},x,ne),b,Xe.generateImageFile(_n9.result)));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e);t=this.processMessages(t),t=this._useConversation?[t[t[X]-1]]:t;var s=t.map(function(r){return _defineProperty({content:Xe.getContent(r)},x,k.getRoleViaUser(r[x]));});return n.input=s,this._conversationId&&(n.conversation=this._conversationId),n;}},{key:"createConversation",value:function(){var _createConversation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(){var e,t,_t49;return _regenerator().w(function(_context126){while(1)switch(_context126.p=_context126.n){case 0:_context126.p=0;e=this.url;this.url=this._urlSegments.conversationsUrl;_context126.n=1;return jt(this,{},ye);case 1:t=_context126.v;return _context126.a(2,(this.url=e,t.id));case 2:_context126.p=2;_t49=_context126.v;throw console[f]("Failed to create conversation:",_t49),_t49;case 3:return _context126.a(2);}},_callee126,this,[[0,2]]);}));function createConversation(){return _createConversation.apply(this,arguments);}return createConversation;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var _this$messages2;var _t50;return _regenerator().w(function(_context127){while(1)switch(_context127.n){case 0:(_this$messages2=this.messages)!==null&&_this$messages2!==void 0?_this$messages2:this.messages=e;_t50=this._useConversation&&!this._conversationId;if(!_t50){_context127.n=2;break;}_context127.n=1;return this.createConversation();case 1:this._conversationId=_context127.v;case 2:this._conversationId&&this.updateSessionId(this._conversationId);this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 3:return _context127.a(2);}},_callee127,this);}));function callServiceAPI(_x235,_x236){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e,t){var n;return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:_context128.n=1;return this.extractResult(e,t);case 1:n=_context128.v;return _context128.a(2,(this._conversationId&&(n._sessionId=this._conversationId),n));}},_callee128,this);}));function extractResultData(_x237,_x238){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractResult",value:function(){var _extractResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:if(!e[f]){_context129.n=1;break;}throw e[f].message;case 1:if(!e.status){_context129.n=5;break;}a=Xe.filterCompleted(e.output);if(!(a[X]>0)){_context129.n=4;break;}c=(r=(s=(n=a.find(function(p){var u,g;return _typeof((g=(u=p.content)==null?void 0:u[0])==null?void 0:g[h])===Ee;}))==null?void 0:n.content)==null?void 0:s[0])==null?void 0:r[h];_context129.n=2;return this.handleResponsesFunctionCalls(a,t,c);case 2:l=_context129.v;if(!l){_context129.n=3;break;}return _context129.a(2,l);case 3:d=this.handleFileGenerationResponse(a,c);return _context129.a(2,d||_defineProperty({},h,c));case 4:return _context129.a(2,_defineProperty({},h,""));case 5:return _context129.a(2,((o=e.item)==null?void 0:o[E])===qs&&e[E]?this.handleStreamedResponsesFunctionCall(e,t):e[E]==="".concat(Hn,".").concat(Di,".partial_image")&&e.partial_image_b64?_defineProperty({},b,[_defineProperty(_defineProperty({},T,"".concat(Xe.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),E,W)]):e.delta&&!this._functionStreamInProgress&&e[E]==="".concat(Hn,".").concat(io,".delta")?_defineProperty({},h,e.delta):_defineProperty({},h,""));}},_callee129,this);}));function extractResult(_x239,_x240){return _extractResult.apply(this,arguments);}return extractResult;}()},{key:"handleStreamedResponsesFunctionCall",value:function(){var _handleStreamedResponsesFunctionCall=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(e,t){var n;return _regenerator().w(function(_context130){while(1)switch(_context130.n){case 0:if(!(e[E]==="".concat(Hn,".output_item.done"))){_context130.n=2;break;}if(!(this._functionStreamInProgress=!1,((n=e.item)==null?void 0:n[E])===qs)){_context130.n=1;break;}return _context130.a(2,this.handleResponsesFunctionCalls([e.item],t));case 1:_context130.n=3;break;case 2:e[E]==="".concat(Hn,".output_item.added")&&(this._functionStreamInProgress=!0);case 3:return _context130.a(2,_defineProperty({},h,""));}},_callee130,this);}));function handleStreamedResponsesFunctionCall(_x241,_x242){return _handleStreamedResponsesFunctionCall.apply(this,arguments);}return handleStreamedResponsesFunctionCall;}()},{key:"handleFileGenerationResponse",value:function handleFileGenerationResponse(e,t){var n=e.find(function(s){return s[E]===Di;});return n?_defineProperty(_defineProperty({},b,Xe.generateImageFile(n.result)),h,t):null;}},{key:"handleResponsesFunctionCalls",value:function(){var _handleResponsesFunctionCalls=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(e,t,n){var s,r,_yield$this$callToolF2,o,a,c;return _regenerator().w(function(_context131){while(1)switch(_context131.n){case 0:s=e.filter(function(l){return l[E]===qs;});if(!(s[X]===0)){_context131.n=1;break;}return _context131.a(2,null);case 1:if(!(!t||!this.functionHandler)){_context131.n=2;break;}throw Error(qt);case 2:r=s.map(function(l){return{name:l.name,arguments:l.arguments};});_context131.n=3;return this.callToolFunction(this.functionHandler,r);case 3:_yield$this$callToolF2=_context131.v;o=_yield$this$callToolF2.responses;a=_yield$this$callToolF2.processedResponse;if(!a){_context131.n=4;break;}return _context131.a(2,a);case 4:c=C(t);if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref134){var l=_ref134.response;return _typeof(l)!==Ee;})&&r[X]===o[X]))){_context131.n=5;break;}return _context131.a(2,(o.forEach(function(l,d){var p=s[d];c.input.push(_defineProperty(_defineProperty(_defineProperty({},E,Qo),"call_id",p.call_id),"output",l[Hn]));}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(on);case 6:return _context131.a(2);}},_callee131,this);}));function handleResponsesFunctionCalls(_x243,_x244,_x245){return _handleResponsesFunctionCalls.apply(this,arguments);}return handleResponsesFunctionCalls;}()}],[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&(e==null?void 0:e.custom_base_url)||Ze;return{responsesUrl:"".concat(t,"responses"),conversationsUrl:"".concat(t,"conversations")};}},{key:"getFileContent",value:function getFileContent(e){return oi.getBaseFileContent(e).map(function(n){return n[E]===nn?n:_defineProperty(_defineProperty({detail:"auto"},E,so),qe,n[T]);});}},{key:"getContent",value:function getContent(e){if(e[x]===F&&e[b]&&e[b][X]>0){var _n0=Xe.getFileContent(e[b]);return e[h]&&e[h].trim()[X]>0&&_n0.unshift(_defineProperty(_defineProperty({},E,Ki),h,e[h])),_n0;}return e[h];}},{key:"filterCompleted",value:function filterCompleted(e){return(e==null?void 0:e.filter(function(t){return t.status===lr;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},T,"".concat(Xe.IMAGE_BASE64_PREFIX).concat(e)),E,W)];}}]);}(oi);Xe.IMAGE_BASE64_PREFIX="data:image/png;base64,";var ci=Xe;var Er=/*#__PURE__*/function(_ci){function Er(e){var _this64;_classCallCheck(this,Er);var o,a,c,l,d,p,u;var t=C(e.directConnection),n=t.azure,s=((a=(o=t.azure)==null?void 0:o.openAI)==null?void 0:a.urlDetails)||{},r=(l=(c=t.azure)==null?void 0:c.openAI)==null?void 0:l.chat;if(_this64=_callSuper(this,Er,[e,na(s),ta,n,r]),_this64.permittedErrorPrefixes=[ii],_this64.isTextInputDisabled=!1,_typeof(r)===U){var _ref137=(u=(p=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:p.openAI)==null?void 0:u.chat,g=_ref137.function_handler;g&&(_this64.functionHandler=g);}sa(s)?_this64.url=Er.buildURL(s):(_this64.isTextInputDisabled=!0,_this64.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,ii));}));return _this64;}_inherits(Er,_ci);return _createClass(Er,null,[{key:"buildURL",value:function buildURL(e){var t=e.endpoint,n=e.deploymentId,s=e.version;return"".concat(t,"/openai/deployments/").concat(n,"/chat/completions?api-version=").concat(s);}}]);}(ci);var li=/*#__PURE__*/function(_k15){function li(e){var _this65$maxMessages,_l$model2;var _this65;_classCallCheck(this,li);var r,o,a,c,l;var t=C(e.directConnection),n=t.bigModel;_this65=_callSuper(this,li,[e,mr(),fr,n]),_this65.insertKeyPlaceholderText=_this65.genereteAPIKeyName("BigModel"),_this65.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this65.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this65.permittedErrorPrefixes=[he,Te];var s=(r=t.bigModel)==null?void 0:r.chat;_typeof(s)===U&&_this65.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.bigModel)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this65$maxMessages=_this65.maxMessages)!==null&&_this65$maxMessages!==void 0?_this65$maxMessages:_this65.maxMessages=-1,(_l$model2=(l=_this65.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="glm-4.5";return _this65;}_inherits(li,_k15);return _createClass(li,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:li.getTextWFilesContent(r,li.getFileContent)},x,k.getRoleViaAI(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee132(e,t){var _this$messages3;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:(_this$messages3=this.messages)!==null&&_this$messages3!==void 0?_this$messages3:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context132.a(2);}},_callee132,this);}));function callServiceAPI(_x246,_x247){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var _n1;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:if(!e[f]){_context133.n=1;break;}throw e[f].message;case 1:if(!(e.choices.length>0)){_context133.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context133.n=2;break;}return _context133.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context133.n=3;break;}_n1=e.choices[0].message;return _context133.a(2,_n1.tool_calls?this.handleToolsGeneric({tool_calls:_n1.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n1.content));case 3:return _context133.a(2,_defineProperty({},h,""));}},_callee133,this);}));function extractResultData(_x248,_x249){return _extractResultData25.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t){var o,a,c,l,n,s,r,d;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:n=e.delta,s=e.finish_reason,r=(o=this.messages)==null?void 0:o.messageToElements[this.messages.messageToElements.length-2];if(!((r==null?void 0:r[0][x])===ne&&((a=r==null?void 0:r[0][h])==null?void 0:a.replace(/\n/g,"").trim().length)===0&&((c=this.messages)==null||c.removeMessage(r[1][h]),(l=this.messages)==null||l.messageToElements.splice(this.messages.messageToElements.length-2,1)),s==="tool_calls")){_context134.n=2;break;}if(!n.tool_calls){_context134.n=1;break;}d={tool_calls:n.tool_calls};return _context134.a(2,this.handleToolsGeneric(d,this.functionHandler,this.messages,t));case 1:return _context134.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));case 2:return _context134.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee134,this);}));function extractStreamResult(_x250,_x251){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t[E]===W?_defineProperty(_defineProperty({},E,qe),qe,{url:t[T]||""}):_defineProperty(_defineProperty({},E,se),"file_url",{url:t[T]||""});});}}]);}(k);var fd=/*#__PURE__*/function(_k16){function fd(e){var _this66$maxMessages,_o$model8;var _this66;_classCallCheck(this,fd);var r,o;var t=C(e.directConnection),n=t.together;_this66=_callSuper(this,fd,[e,br(),gr,n]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("Together AI"),_this66.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this66.url="https://api.together.xyz/v1/chat/completions",_this66.permittedErrorPrefixes=[it,Te];var s=(r=t.together)==null?void 0:r.chat;_typeof(s)===U&&_this66.completeConfig(s),(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1,(_o$model8=(o=_this66.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this66;}_inherits(fd,_k16);return _createClass(fd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,r[x]===ne?gt:r[x]);});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e,t){return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x252,_x253){return _callServiceAPI23.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e){return _regenerator().w(function(_context136){while(1)switch(_context136.n){case 0:if(!e[f]){_context136.n=1;break;}throw e[f].message;case 1:if(!(e.choices.length>0)){_context136.n=3;break;}if(!(e.choices[0].message!==void 0)){_context136.n=2;break;}return _context136.a(2,_defineProperty({},h,e.choices[0].message.content));case 2:if(!(e.choices[0].delta!==void 0)){_context136.n=3;break;}return _context136.a(2,_defineProperty({},h,e.choices[0].delta.content));case 3:return _context136.a(2,_defineProperty({},h,""));}},_callee136);}));function extractResultData(_x254){return _extractResultData26.apply(this,arguments);}return extractResultData;}()}]);}(k);var ot=/*#__PURE__*/function(_k17){function ot(e){var _this67;_classCallCheck(this,ot);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},b,{acceptedFormats:".png",maxNumberOfFiles:2})};_this67=_callSuper(this,ot,[e,Dn(),Bn,n,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenAI"),_this67.keyHelpUrl=Nn,_this67.url="",_this67.permittedErrorPrefixes=[Ls,"Invalid input image"];var r=(o=t==null?void 0:t.openAI)==null?void 0:o[ee];if(_this67[Fe]){var a=_typeof(r)=="object"&&r.size?Number.parseInt(r.size):1024;_this67[Fe][b]={dimensions:{width:a,height:a}};}_typeof(r)===U&&Object.assign(_this67.rawBody,r),_this67.canSendMessage=ot.canFileSendMessage;return _this67;}_inherits(ot,_k17);return _createClass(ot,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e);return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
185
+ function Xe(e,t,n,s,r){var _this62;_classCallCheck(this,Xe);var a,c;_this62=_callSuper(this,Xe,[e,t,n,s,r]),_this62.keyHelpUrl=Nn,_this62.url="".concat(Ze,"responses"),_this62._functionStreamInProgress=!1,_this62._useConversation=!1,_this62._conversationLoadLimit=50;var o=r||((c=(a=e.directConnection)==null?void 0:a.openAI)==null?void 0:c.chat);_this62._urlSegments=Xe.buildUrlSegments(o),_this62.url=_this62._urlSegments.responsesUrl,_typeof(o)===U&&o!==!0&&o&&(o.conversation&&(_this62._useConversation=!0,typeof o.conversation=="string"&&(_this62._conversationId=o.conversation)),typeof o.conversationLoadLimit=="number"&&(_this62._conversationLoadLimit=o.conversationLoadLimit),_this62.cleanConfig(o)),_this62._conversationId&&(_this62.fetchHistory=_this62.fetchHistoryFunc.bind(_this62));return _this62;}_inherits(Xe,_ii2);return _createClass(Xe,[{key:"processConfig",value:function processConfig(e,t){_superPropGet(Xe,"processConfig",this,3)([e,t]);}},{key:"cleanConfig",value:function cleanConfig(e){delete e.conversation,delete e.conversationLoadLimit,delete e.custom_base_url;}},{key:"fetchHistoryFunc",value:function(){var _fetchHistoryFunc2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee125(){var _this63=this;var e,t,_n8,_t48;return _regenerator().w(function(_context125){while(1)switch(_context125.p=_context125.n){case 0:setTimeout(function(){return _this63.deepChat.disableSubmitButton();},2);_context125.p=1;e=this.url,t=this._urlSegments.conversationsUrl;this.url="".concat(t,"/").concat(this._conversationId,"/items?limit=").concat(this._conversationLoadLimit);_context125.n=2;return $t(this,{},ue);case 2:_n8=_context125.v;return _context125.a(2,(this.connectSettings.method=ye,this.url=e,this.deepChat.disableSubmitButton(!1),this.processConversationHistory(_n8)));case 3:_context125.p=3;_t48=_context125.v;return _context125.a(2,(this.deepChat.disableSubmitButton(!1),[_defineProperty({},f,Uo)]));}},_callee125,this,[[1,3]]);}));function fetchHistoryFunc(){return _fetchHistoryFunc2.apply(this,arguments);}return fetchHistoryFunc;}()},{key:"processConversationHistory",value:function processConversationHistory(e){if(!e.data||!Array.isArray(e.data))return[];var t=[];var _iterator2=_createForOfIteratorHelper(Xe.filterCompleted(e.data.reverse())),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _n9=_step2.value;if(_n9[E]==="message"&&_n9.content&&Array.isArray(_n9.content)){var _iterator3=_createForOfIteratorHelper(_n9.content),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var s=_step3.value;(s[E]===zi||s[E]===so)&&s[h]?t.push(_defineProperty(_defineProperty({},x,_n9[x]),h,s[h])):s[E]===no&&t.push(_defineProperty(_defineProperty({},x,_n9[x]),b,Xe.generateImageFile(s[qe]||"")));}}catch(err){_iterator3.e(err);}finally{_iterator3.f();}}else _n9[E]===Ni&&t.push(_defineProperty(_defineProperty({},x,ne),b,Xe.generateImageFile(_n9.result)));}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}return t;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e);t=this.processMessages(t),t=this._useConversation?[t[t[X]-1]]:t;var s=t.map(function(r){return _defineProperty({content:Xe.getContent(r)},x,k.getRoleViaUser(r[x]));});return n.input=s,this._conversationId&&(n.conversation=this._conversationId),n;}},{key:"createConversation",value:function(){var _createConversation=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee126(){var e,t,_t49;return _regenerator().w(function(_context126){while(1)switch(_context126.p=_context126.n){case 0:_context126.p=0;e=this.url;this.url=this._urlSegments.conversationsUrl;_context126.n=1;return $t(this,{},ye);case 1:t=_context126.v;return _context126.a(2,(this.url=e,t.id));case 2:_context126.p=2;_t49=_context126.v;throw console[f]("Failed to create conversation:",_t49),_t49;case 3:return _context126.a(2);}},_callee126,this,[[0,2]]);}));function createConversation(){return _createConversation.apply(this,arguments);}return createConversation;}()},{key:"callServiceAPI",value:function(){var _callServiceAPI21=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee127(e,t){var _this$messages2;var _t50;return _regenerator().w(function(_context127){while(1)switch(_context127.n){case 0:(_this$messages2=this.messages)!==null&&_this$messages2!==void 0?_this$messages2:this.messages=e;_t50=this._useConversation&&!this._conversationId;if(!_t50){_context127.n=2;break;}_context127.n=1;return this.createConversation();case 1:this._conversationId=_context127.v;case 2:this._conversationId&&this.updateSessionId(this._conversationId);this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 3:return _context127.a(2);}},_callee127,this);}));function callServiceAPI(_x235,_x236){return _callServiceAPI21.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee128(e,t){var n;return _regenerator().w(function(_context128){while(1)switch(_context128.n){case 0:_context128.n=1;return this.extractResult(e,t);case 1:n=_context128.v;return _context128.a(2,(this._conversationId&&(n._sessionId=this._conversationId),n));}},_callee128,this);}));function extractResultData(_x237,_x238){return _extractResultData24.apply(this,arguments);}return extractResultData;}()},{key:"extractResult",value:function(){var _extractResult=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee129(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context129){while(1)switch(_context129.n){case 0:if(!e[f]){_context129.n=1;break;}throw e[f].message;case 1:if(!e.status){_context129.n=5;break;}a=Xe.filterCompleted(e.output);if(!(a[X]>0)){_context129.n=4;break;}c=(r=(s=(n=a.find(function(p){var u,g;return _typeof((g=(u=p.content)==null?void 0:u[0])==null?void 0:g[h])===Ee;}))==null?void 0:n.content)==null?void 0:s[0])==null?void 0:r[h];_context129.n=2;return this.handleResponsesFunctionCalls(a,t,c);case 2:l=_context129.v;if(!l){_context129.n=3;break;}return _context129.a(2,l);case 3:d=this.handleFileGenerationResponse(a,c);return _context129.a(2,d||_defineProperty({},h,c));case 4:return _context129.a(2,_defineProperty({},h,""));case 5:return _context129.a(2,((o=e.item)==null?void 0:o[E])===$s&&e[E]?this.handleStreamedResponsesFunctionCall(e,t):e[E]==="".concat(Hn,".").concat(Ni,".partial_image")&&e.partial_image_b64?_defineProperty({},b,[_defineProperty(_defineProperty({},T,"".concat(Xe.IMAGE_BASE64_PREFIX).concat(e.partial_image_b64)),E,W)]):e.delta&&!this._functionStreamInProgress&&e[E]==="".concat(Hn,".").concat(so,".delta")?_defineProperty({},h,e.delta):_defineProperty({},h,""));}},_callee129,this);}));function extractResult(_x239,_x240){return _extractResult.apply(this,arguments);}return extractResult;}()},{key:"handleStreamedResponsesFunctionCall",value:function(){var _handleStreamedResponsesFunctionCall=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee130(e,t){var n;return _regenerator().w(function(_context130){while(1)switch(_context130.n){case 0:if(!(e[E]==="".concat(Hn,".output_item.done"))){_context130.n=2;break;}if(!(this._functionStreamInProgress=!1,((n=e.item)==null?void 0:n[E])===$s)){_context130.n=1;break;}return _context130.a(2,this.handleResponsesFunctionCalls([e.item],t));case 1:_context130.n=3;break;case 2:e[E]==="".concat(Hn,".output_item.added")&&(this._functionStreamInProgress=!0);case 3:return _context130.a(2,_defineProperty({},h,""));}},_callee130,this);}));function handleStreamedResponsesFunctionCall(_x241,_x242){return _handleStreamedResponsesFunctionCall.apply(this,arguments);}return handleStreamedResponsesFunctionCall;}()},{key:"handleFileGenerationResponse",value:function handleFileGenerationResponse(e,t){var n=e.find(function(s){return s[E]===Ni;});return n?_defineProperty(_defineProperty({},b,Xe.generateImageFile(n.result)),h,t):null;}},{key:"handleResponsesFunctionCalls",value:function(){var _handleResponsesFunctionCalls=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee131(e,t,n){var s,r,_yield$this$callToolF2,o,a,c;return _regenerator().w(function(_context131){while(1)switch(_context131.n){case 0:s=e.filter(function(l){return l[E]===$s;});if(!(s[X]===0)){_context131.n=1;break;}return _context131.a(2,null);case 1:if(!(!t||!this.functionHandler)){_context131.n=2;break;}throw Error(Gt);case 2:r=s.map(function(l){return{name:l.name,arguments:l.arguments};});_context131.n=3;return this.callToolFunction(this.functionHandler,r);case 3:_yield$this$callToolF2=_context131.v;o=_yield$this$callToolF2.responses;a=_yield$this$callToolF2.processedResponse;if(!a){_context131.n=4;break;}return _context131.a(2,a);case 4:c=C(t);if(!(c.input&&(s.forEach(function(l){return c.input.push(l);}),!o.find(function(_ref138){var l=_ref138.response;return _typeof(l)!==Ee;})&&r[X]===o[X]))){_context131.n=5;break;}return _context131.a(2,(o.forEach(function(l,d){var p=s[d];c.input.push(_defineProperty(_defineProperty(_defineProperty({},E,Jo),"call_id",p.call_id),"output",l[Hn]));}),this.makeAnotherRequest(c,this.messages,n)));case 5:throw Error(an);case 6:return _context131.a(2);}},_callee131,this);}));function handleResponsesFunctionCalls(_x243,_x244,_x245){return _handleResponsesFunctionCalls.apply(this,arguments);}return handleResponsesFunctionCalls;}()}],[{key:"buildUrlSegments",value:function buildUrlSegments(e){var t=_typeof(e)=="object"&&(e==null?void 0:e.custom_base_url)||Ze;return{responsesUrl:"".concat(t,"responses"),conversationsUrl:"".concat(t,"conversations")};}},{key:"getFileContent",value:function getFileContent(e){return ii.getBaseFileContent(e).map(function(n){return n[E]===sn?n:_defineProperty(_defineProperty({detail:"auto"},E,no),qe,n[T]);});}},{key:"getContent",value:function getContent(e){if(e[x]===F&&e[b]&&e[b][X]>0){var _n0=Xe.getFileContent(e[b]);return e[h]&&e[h].trim()[X]>0&&_n0.unshift(_defineProperty(_defineProperty({},E,zi),h,e[h])),_n0;}return e[h];}},{key:"filterCompleted",value:function filterCompleted(e){return(e==null?void 0:e.filter(function(t){return t.status===cr;}))||[];}},{key:"generateImageFile",value:function generateImageFile(e){return[_defineProperty(_defineProperty({},T,"".concat(Xe.IMAGE_BASE64_PREFIX).concat(e)),E,W)];}}]);}(ii);Xe.IMAGE_BASE64_PREFIX="data:image/png;base64,";var oi=Xe;var _r=/*#__PURE__*/function(_oi){function _r(e){var _this64;_classCallCheck(this,_r);var o,a,c,l,d,p,u;var t=C(e.directConnection),n=t.azure,s=((a=(o=t.azure)==null?void 0:o.openAI)==null?void 0:a.urlDetails)||{},r=(l=(c=t.azure)==null?void 0:c.openAI)==null?void 0:l.chat;if(_this64=_callSuper(this,_r,[e,ta(s),ea,n,r]),_this64.permittedErrorPrefixes=[ni],_this64.isTextInputDisabled=!1,_typeof(r)===U){var _ref141=(u=(p=(d=e.directConnection)==null?void 0:d.azure)==null?void 0:p.openAI)==null?void 0:u.chat,g=_ref141.function_handler;g&&(_this64.functionHandler=g);}na(s)?_this64.url=_r.buildURL(s):(_this64.isTextInputDisabled=!0,_this64.canSendMessage=function(){return!1;},setTimeout(function(){e.addMessage(_defineProperty({},f,ni));}));return _this64;}_inherits(_r,_oi);return _createClass(_r,null,[{key:"buildURL",value:function buildURL(e){var t=e.endpoint,n=e.deploymentId,s=e.version;return"".concat(t,"/openai/deployments/").concat(n,"/chat/completions?api-version=").concat(s);}}]);}(oi);var ai=/*#__PURE__*/function(_k15){function ai(e){var _this65$maxMessages,_l$model2;var _this65;_classCallCheck(this,ai);var r,o,a,c,l;var t=C(e.directConnection),n=t.bigModel;_this65=_callSuper(this,ai,[e,fr(),pr,n]),_this65.insertKeyPlaceholderText=_this65.genereteAPIKeyName("BigModel"),_this65.keyHelpUrl="https://open.bigmodel.cn/usercenter/apikeys",_this65.url="https://open.bigmodel.cn/api/paas/v4/chat/completions",_this65.permittedErrorPrefixes=[he,Te];var s=(r=t.bigModel)==null?void 0:r.chat;_typeof(s)===U&&_this65.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.bigModel)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this65$maxMessages=_this65.maxMessages)!==null&&_this65$maxMessages!==void 0?_this65$maxMessages:_this65.maxMessages=-1,(_l$model2=(l=_this65.rawBody).model)!==null&&_l$model2!==void 0?_l$model2:l.model="glm-4.5";return _this65;}_inherits(ai,_k15);return _createClass(ai,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:ai.getTextWFilesContent(r,ai.getFileContent)},x,k.getRoleViaAI(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI22=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee132(e,t){var _this$messages3;return _regenerator().w(function(_context132){while(1)switch(_context132.n){case 0:(_this$messages3=this.messages)!==null&&_this$messages3!==void 0?_this$messages3:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context132.a(2);}},_callee132,this);}));function callServiceAPI(_x246,_x247){return _callServiceAPI22.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee133(e,t){var _n1;return _regenerator().w(function(_context133){while(1)switch(_context133.n){case 0:if(!e[f]){_context133.n=1;break;}throw e[f].message;case 1:if(!(e.choices.length>0)){_context133.n=3;break;}if(!(e.choices[0].delta!==void 0)){_context133.n=2;break;}return _context133.a(2,this.extractStreamResult(e.choices[0],t));case 2:if(!(e.choices[0].message!==void 0)){_context133.n=3;break;}_n1=e.choices[0].message;return _context133.a(2,_n1.tool_calls?this.handleToolsGeneric({tool_calls:_n1.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n1.content));case 3:return _context133.a(2,_defineProperty({},h,""));}},_callee133,this);}));function extractResultData(_x248,_x249){return _extractResultData25.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee134(e,t){var o,a,c,l,n,s,r,d;return _regenerator().w(function(_context134){while(1)switch(_context134.n){case 0:n=e.delta,s=e.finish_reason,r=(o=this.messages)==null?void 0:o.messageToElements[this.messages.messageToElements.length-2];if(!((r==null?void 0:r[0][x])===ne&&((a=r==null?void 0:r[0][h])==null?void 0:a.replace(/\n/g,"").trim().length)===0&&((c=this.messages)==null||c.removeMessage(r[1][h]),(l=this.messages)==null||l.messageToElements.splice(this.messages.messageToElements.length-2,1)),s==="tool_calls")){_context134.n=2;break;}if(!n.tool_calls){_context134.n=1;break;}d={tool_calls:n.tool_calls};return _context134.a(2,this.handleToolsGeneric(d,this.functionHandler,this.messages,t));case 1:return _context134.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));case 2:return _context134.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee134,this);}));function extractStreamResult(_x250,_x251){return _extractStreamResult2.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t[E]===W?_defineProperty(_defineProperty({},E,qe),qe,{url:t[T]||""}):_defineProperty(_defineProperty({},E,se),"file_url",{url:t[T]||""});});}}]);}(k);var pd=/*#__PURE__*/function(_k16){function pd(e){var _this66$maxMessages,_o$model8;var _this66;_classCallCheck(this,pd);var r,o;var t=C(e.directConnection),n=t.together;_this66=_callSuper(this,pd,[e,gr(),mr,n]),_this66.insertKeyPlaceholderText=_this66.genereteAPIKeyName("Together AI"),_this66.keyHelpUrl="https://api.together.xyz/settings/api-keys",_this66.url="https://api.together.xyz/v1/chat/completions",_this66.permittedErrorPrefixes=[it,Te];var s=(r=t.together)==null?void 0:r.chat;_typeof(s)===U&&_this66.completeConfig(s),(_this66$maxMessages=_this66.maxMessages)!==null&&_this66$maxMessages!==void 0?_this66$maxMessages:_this66.maxMessages=-1,(_o$model8=(o=_this66.rawBody).model)!==null&&_o$model8!==void 0?_o$model8:o.model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo";return _this66;}_inherits(pd,_k16);return _createClass(pd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,r[x]===ne?gt:r[x]);});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI23=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee135(e,t){return _regenerator().w(function(_context135){while(1)switch(_context135.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context135.a(2);}},_callee135,this);}));function callServiceAPI(_x252,_x253){return _callServiceAPI23.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee136(e){return _regenerator().w(function(_context136){while(1)switch(_context136.n){case 0:if(!e[f]){_context136.n=1;break;}throw e[f].message;case 1:if(!(e.choices.length>0)){_context136.n=3;break;}if(!(e.choices[0].message!==void 0)){_context136.n=2;break;}return _context136.a(2,_defineProperty({},h,e.choices[0].message.content));case 2:if(!(e.choices[0].delta!==void 0)){_context136.n=3;break;}return _context136.a(2,_defineProperty({},h,e.choices[0].delta.content));case 3:return _context136.a(2,_defineProperty({},h,""));}},_callee136);}));function extractResultData(_x254){return _extractResultData26.apply(this,arguments);}return extractResultData;}()}]);}(k);var ot=/*#__PURE__*/function(_k17){function ot(e){var _this67;_classCallCheck(this,ot);var o;var t=e.directConnection,n=t==null?void 0:t.openAI,s={images:_defineProperty({},b,{acceptedFormats:".png",maxNumberOfFiles:2})};_this67=_callSuper(this,ot,[e,Dn(),Bn,n,s]),_this67.insertKeyPlaceholderText=_this67.genereteAPIKeyName("OpenAI"),_this67.keyHelpUrl=Nn,_this67.url="",_this67.permittedErrorPrefixes=[Ps,"Invalid input image"];var r=(o=t==null?void 0:t.openAI)==null?void 0:o[ee];if(_this67[Fe]){var a=_typeof(r)=="object"&&r.size?Number.parseInt(r.size):1024;_this67[Fe][b]={dimensions:{width:a,height:a}};}_typeof(r)===U&&Object.assign(_this67.rawBody,r),_this67.canSendMessage=ot.canFileSendMessage;return _this67;}_inherits(ot,_k17);return _createClass(ot,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e);return t&&t!==""&&(n.prompt=t),n;}// prettier-ignore
190
186
  },{key:"callApiWithImage",value:function callApiWithImage(e,t,n){var o,a;var s;var r=(a=(o=t[t[X]-1])==null?void 0:o[h])==null?void 0:a.trim();if(n[1]||r&&r!==""){this.url=ot.IMAGE_EDIT_URL;var c=this.preprocessBody(this.rawBody,r);s=ot.createFormDataBody(c,n[0],n[1]);}else this.url=ot.IMAGE_VARIATIONS_URL,s=ot.createFormDataBody(this.rawBody,n[0]);D.tempRemoveContentHeader(this.connectSettings,ge.request.bind(this,this,s,e),!1);}},{key:"callServiceAPI",value:function(){var _callServiceAPI24=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee137(e,t,n){var s,r;return _regenerator().w(function(_context137){while(1)switch(_context137.n){case 0:if((s=this.connectSettings)!=null&&s.headers){_context137.n=1;break;}throw new Error(He);case 1:if(!(n!=null&&n[0])){_context137.n=2;break;}this.callApiWithImage(e,t,n);_context137.n=4;break;case 2:if(this.connectSettings){_context137.n=3;break;}throw new Error(He);case 3:this.url=ot.IMAGE_GENERATION_URL;r=this.preprocessBody(this.rawBody,t[t[X]-1][h]);ge.request(this,r,e);case 4:return _context137.a(2);}},_callee137,this);}));function callServiceAPI(_x255,_x256,_x257){return _callServiceAPI24.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee138(e){var t;return _regenerator().w(function(_context138){while(1)switch(_context138.n){case 0:if(!e[f]){_context138.n=1;break;}throw e[f].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},T,n.url),E,W):_defineProperty(_defineProperty({},T,"".concat(On).concat(n.b64_json)),E,W);});return _context138.a(2,_defineProperty({},b,t));}},_callee138);}));function extractResultData(_x258){return _extractResultData27.apply(this,arguments);}return extractResultData;}()// private static readonly MODAL_MARKDOWN = `
191
187
  // 1 image:
192
188
  // - With text - edits image based on the text
@@ -196,34 +192,34 @@ function Xe(e,t,n,s,r){var _this62;_classCallCheck(this,Xe);var a,c;_this62=_cal
196
192
  // Add text to describe the required modification.
197
193
  // Click here for [more info](https://platform.openai.com/docs/guides/images/introduction).
198
194
  // `;
199
- }],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,n){var s=new FormData();return s.append(W,t),n&&s.append("mask",n),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s;}}]);}(k);ot.IMAGE_GENERATION_URL="".concat(Ze,"images/generations"),ot.IMAGE_VARIATIONS_URL="".concat(Ze,"images/variations"),ot.IMAGE_EDIT_URL="".concat(Ze,"images/edits");var nr=ot;var md=function md(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},gd=function gd(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},bd=function bd(){return be("https://openrouter.ai/api/v1/key",ue,gd);};var fs=/*#__PURE__*/function(_k18){function fs(e){var _this68$maxMessages,_o$model9,_a$max_tokens;var _this68;_classCallCheck(this,fs);var s,r,o,a;var n=C(e.directConnection).openRouter;_this68=_callSuper(this,fs,[e,bd(),md,n]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("OpenRouter"),_this68.keyHelpUrl="https://openrouter.ai/keys",_this68.url="https://openrouter.ai/api/v1/chat/completions",_this68.permittedErrorPrefixes=[it,Te],_typeof(n)===U&&_this68.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.openRouter)==null?void 0:r.function_handler),(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_o$model9=(o=_this68.rawBody).model)!==null&&_o$model9!==void 0?_o$model9:o.model="openai/gpt-4o",(_a$max_tokens=(a=_this68.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=1e3;return _this68;}_inherits(fs,_k18);return _createClass(fs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(o){return _defineProperty({content:fs.getContent(o)},x,k.getRoleViaUser(o[x]));}),r=[];return this.systemMessage&&r.push(_defineProperty(_defineProperty({},x,Mn),"content",this.systemMessage)),r.push.apply(r,_toConsumableArray(s)),n.messages=r,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(e,t){var _this$messages4;return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:(_this$messages4=this.messages)!==null&&_this$messages4!==void 0?_this$messages4:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context139.a(2);}},_callee139,this);}));function callServiceAPI(_x259,_x260){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e,t){var n,s,r,o,a,c,_a5,_c5;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:if(!e[f]){_context140.n=1;break;}throw e[f].message;case 1:if(!(e.object==="chat.completion.chunk")){_context140.n=4;break;}a=(n=e.choices)==null?void 0:n[0];if(!(a!=null&&a.delta)){_context140.n=2;break;}return _context140.a(2,this.extractStreamResult(a,t));case 2:if(!((s=e.message)!=null&&s[ee])){_context140.n=3;break;}c=e.message[ee].map(function(l){return _defineProperty({},T,l[qe].url);});return _context140.a(2,_defineProperty(_defineProperty({},h,e.message.content||""),b,c));case 3:return _context140.a(2,_defineProperty({},h,""));case 4:if(!(e.object==="chat.completion")){_context140.n=6;break;}_a5=(r=e.choices)==null?void 0:r[0];if(!(_a5!=null&&_a5.message)){_context140.n=6;break;}if(!_a5.message.tool_calls){_context140.n=5;break;}return _context140.a(2,this.handleToolsGeneric({tool_calls:_a5.message.tool_calls},this.functionHandler,this.messages,t));case 5:_c5=((o=_a5.message[ee])==null?void 0:o.map(function(l){return _defineProperty({},T,l[qe].url);}))||[];return _context140.a(2,_defineProperty(_defineProperty({},h,_a5.message.content||""),"files",_c5));case 6:return _context140.a(2,_defineProperty({},h,""));}},_callee140,this);}));function extractResultData(_x261,_x262){return _extractResultData28.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){var n,s;return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:n=e.delta;if(!(n!=null&&n[ee])){_context141.n=1;break;}s=n[ee].map(function(r){return _defineProperty({},T,r[qe].url);});return _context141.a(2,_defineProperty(_defineProperty({},h,n.content||""),b,s));case 1:return _context141.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee141,this);}));function extractStreamResult(_x263,_x264){return _extractStreamResult3.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getAudioContent",value:function getAudioContent(e){return e.filter(function(t){return t[E]===$;}).map(function(t){var r,o,a;var n=(r=t[T])==null?void 0:r.split(",")[1],s=(a=(o=t[T])==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return _defineProperty(_defineProperty({},E,nn),nn,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[nn].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[b]&&e[b].length>0){var t=[].concat(_toConsumableArray(fs.getImageContent(e[b])),_toConsumableArray(fs.getAudioContent(e[b])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(k);var yd=function yd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},_d=function _d(i,e,t,n){i[f]?n(pe):t(e);},Ed=function Ed(){return be("https://api.perplexity.ai/chat/completions",ye,_d);};var vd=/*#__PURE__*/function(_k19){function vd(e){var _this69$maxMessages,_s$model;var _this69;_classCallCheck(this,vd);var s;var n=C(e.directConnection).perplexity;_this69=_callSuper(this,vd,[e,Ed(),yd,n]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Perplexity"),_this69.keyHelpUrl="https://www.perplexity.ai/settings/api",_this69.url="https://api.perplexity.ai/chat/completions",_this69.permittedErrorPrefixes=[Gt,jo,"Permission denied"],_typeof(n)===U&&_this69.completeConfig(n),(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_s$model=(s=_this69.rawBody).model)!==null&&_s$model!==void 0?_s$model:s.model="sonar";return _this69;}_inherits(vd,_k19);return _createClass(vd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e,t){return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context142.a(2);}},_callee142,this);}));function callServiceAPI(_x265,_x266){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e){var t;return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:if(!e[f]){_context143.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context143.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context143.n=2;break;}return _context143.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context143.n=3;break;}return _context143.a(2,_defineProperty({},h,t.message.content));case 3:return _context143.a(2,_defineProperty({},h,""));}},_callee143);}));function extractResultData(_x267){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(k);var Sd=function Sd(i){return _defineProperty(_defineProperty({},he,"Bearer ".concat(i)),q,te);},xd=function xd(i,e,t,n){var s=i;s.detail?n(s.detail):t(e);},Ad=function Ad(){return be("http://localhost:3000/api/v1/models",ue,xd);};var wd=/*#__PURE__*/function(_k20){function wd(e){var _this70$maxMessages,_o$model0,_a$stream;var _this70;_classCallCheck(this,wd);var s,r,o,a;var n=C(e.directConnection).openWebUI;_this70=_callSuper(this,wd,[e,Ad(),Sd,n]),_this70.insertKeyPlaceholderText="Open WebUI API Key",_this70.keyHelpUrl="https://docs.openwebui.com/getting-started/api-endpoints/",_this70.url="http://localhost:3000/api/chat/completions",_this70.permittedErrorPrefixes=["Error"],_typeof(n)===U&&(_this70.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.openWebUI)==null?void 0:r.function_handler),n[b]&&n[b].length>0&&(_this70.rawBody[b]=n[b])),(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_o$model0=(o=_this70.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="llama3.2",(_a$stream=(a=_this70.rawBody).stream)!==null&&_a$stream!==void 0?_a$stream:a.stream=!1;return _this70;}_inherits(wd,_k20);return _createClass(wd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:k.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){var _this$messages5;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:(_this$messages5=this.messages)!==null&&_this$messages5!==void 0?_this$messages5:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context144.a(2);}},_callee144,this);}));function callServiceAPI(_x268,_x269){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var n,s,_s8;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:if(!e[f]){_context145.n=1;break;}throw e[f].message;case 1:if(!e[h]){_context145.n=2;break;}s=e[h].trim();return _context145.a(2,this.processStreamingResponse(s,t));case 2:if(!(e.choices&&(n=e.choices[0])!=null&&n.message)){_context145.n=3;break;}_s8=e.choices[0].message;return _context145.a(2,_s8.tool_calls?this.handleTools({tool_calls:_s8.tool_calls},t):_defineProperty({},h,_s8.content||""));case 3:return _context145.a(2,_defineProperty({},h,""));}},_callee145,this);}));function extractResultData(_x270,_x271){return _extractResultData30.apply(this,arguments);}return extractResultData;}()},{key:"processStreamingResponse",value:function(){var _processStreamingResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){var r,n,s,_iterator4,_step4,o,a,c,l,_t51,_t52;return _regenerator().w(function(_context146){while(1)switch(_context146.p=_context146.n){case 0:n=e.split("\n").filter(function(o){return o.trim()!=="";});s="";_iterator4=_createForOfIteratorHelper(n);_context146.p=1;_iterator4.s();case 2:if((_step4=_iterator4.n()).done){_context146.n=8;break;}o=_step4.value;a=o.trim();if(!(a.startsWith("data: ")&&(a=a.substring(6)),a!=="[DONE]")){_context146.n=7;break;}_context146.p=3;c=JSON.parse(a);if(!(c.choices&&(r=c.choices[0])!=null&&r.delta)){_context146.n=5;break;}l=c.choices[0].delta;if(!l.tool_calls){_context146.n=4;break;}return _context146.a(2,this.handleTools({tool_calls:l.tool_calls},t));case 4:l.content&&(s+=l.content);case 5:_context146.n=7;break;case 6:_context146.p=6;_t51=_context146.v;return _context146.a(3,7);case 7:_context146.n=2;break;case 8:_context146.n=10;break;case 9:_context146.p=9;_t52=_context146.v;_iterator4.e(_t52);case 10:_context146.p=10;_iterator4.f();return _context146.f(10);case 11:return _context146.a(2,_defineProperty({},h,s));}},_callee146,this,[[3,6],[1,9,10,11]]);}));function processStreamingResponse(_x272,_x273){return _processStreamingResponse.apply(this,arguments);}return processStreamingResponse;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){var n,s,_yield$this$callToolF3,r,o;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context147.n=1;break;}throw Error(qt);case 1:n=C(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context147.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF3=_context147.v;r=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context147.n=3;break;}return _context147.a(2,o);case 3:if(!(n.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},x,gt),"content","")),!r.find(function(_ref173){var a=_ref173.response;return _typeof(a)!==Ee;})&&s.length===r.length)){_context147.n=4;break;}return _context147.a(2,(r.forEach(function(a,c){var d;var l=(d=e.tool_calls)==null?void 0:d[c];n==null||n.messages.push(_defineProperty(_defineProperty(_defineProperty({},x,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(on);case 5:return _context147.a(2);}},_callee147,this);}));function handleTools(_x274,_x275){return _handleTools2.apply(this,arguments);}return handleTools;}()}]);}(k);var Cd=function Cd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Td=function Td(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},Rd=function Rd(){return be("https://api.deepseek.com/models",ue,Td);};var Id=/*#__PURE__*/function(_k21){function Id(e){var _this71$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this71;_classCallCheck(this,Id);var s,r,o;var n=C(e.directConnection).deepSeek;_this71=_callSuper(this,Id,[e,Rd(),Cd,n]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("DeepSeek"),_this71.keyHelpUrl="https://platform.deepseek.com/api_keys",_this71.url="https://api.deepseek.com/v1/chat/completions",_this71.permittedErrorPrefixes=[it,Te],_typeof(n)===U&&_this71.completeConfig(n),(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_s$model2=(s=_this71.rawBody).model)!==null&&_s$model2!==void 0?_s$model2:s.model="deepseek-chat",(_r$temperature=(r=_this71.rawBody).temperature)!==null&&_r$temperature!==void 0?_r$temperature:r.temperature=1,(_o$max_tokens=(o=_this71.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this71;}_inherits(Id,_k21);return _createClass(Id,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e,t){return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context148.a(2);}},_callee148,this);}));function callServiceAPI(_x276,_x277){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e){var t;return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:if(!e[f]){_context149.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context149.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context149.n=2;break;}return _context149.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context149.n=3;break;}return _context149.a(2,_defineProperty({},h,t.message.content));case 3:return _context149.a(2,_defineProperty({},h,""));}},_callee149);}));function extractResultData(_x278){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(k);var Md=function Md(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},kd=function kd(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(pe):t(e);},Pd=function Pd(){return be("https://api.minimax.io/v1/files/delete",ye,kd);};var Ld=/*#__PURE__*/function(_k22){function Ld(e){var _this72$maxMessages,_s$model3;var _this72;_classCallCheck(this,Ld);var s;var n=C(e.directConnection).miniMax;_this72=_callSuper(this,Ld,[e,Pd(),Md,n]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("MiniMax"),_this72.keyHelpUrl="https://www.minimaxi.com",_this72.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this72.permittedErrorPrefixes=[it,Te,"insufficient balance"],_typeof(n)===U&&_this72.completeConfig(n),(_this72$maxMessages=_this72.maxMessages)!==null&&_this72$maxMessages!==void 0?_this72$maxMessages:_this72.maxMessages=-1,(_s$model3=(s=_this72.rawBody).model)!==null&&_s$model3!==void 0?_s$model3:s.model="MiniMax-M1";return _this72;}_inherits(Ld,_k22);return _createClass(Ld,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context150.a(2);}},_callee150,this);}));function callServiceAPI(_x279,_x280){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e){var t,_n10;return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:if(!e[f]){_context151.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context151.n=3;break;}_n10=e.choices[0];if(!(_n10.delta&&_n10.delta.content)){_context151.n=2;break;}return _context151.a(2,_defineProperty({},h,_n10.delta.content));case 2:if(!(_n10.message&&_n10.message.content)){_context151.n=3;break;}return _context151.a(2,_defineProperty({},h,_n10.message.content));case 3:if(!(typeof((t=e.base_resp)==null?void 0:t.status_code)=="number"&&e.base_resp.status_code>0)){_context151.n=4;break;}throw e.base_resp.status_msg;case 4:return _context151.a(2,_defineProperty({},h,""));}},_callee151);}));function extractResultData(_x281){return _extractResultData32.apply(this,arguments);}return extractResultData;}()}]);}(k);var Od=function Od(i){return _defineProperty(_defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te),"accept",te);},Nd=function Nd(i,e,t,n){i.detail?n(pe):t(e);},Bd=function Bd(){return be("https://api.mistral.ai/v1/models",ue,Nd);};var vr=/*#__PURE__*/function(_k23){function vr(e){var _this73$maxMessages,_o$model1;var _this73;_classCallCheck(this,vr);var s,r,o;var n=C(e.directConnection).mistral;_this73=_callSuper(this,vr,[e,Bd(),Od,n]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("Mistral"),_this73.keyHelpUrl="https://console.mistral.ai/api-keys/",_this73.url="https://api.mistral.ai/v1/chat/completions",_this73.permittedErrorPrefixes=[Gt],_typeof(n)===U&&_this73.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.mistral)==null?void 0:r.function_handler),(_this73$maxMessages=_this73.maxMessages)!==null&&_this73$maxMessages!==void 0?_this73$maxMessages:_this73.maxMessages=-1,(_o$model1=(o=_this73.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="mistral-small-latest";return _this73;}_inherits(vr,_k23);return _createClass(vr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty(_defineProperty({},x,k.getRoleViaAI(r[x])),"content",k.getTextWFilesContent(r,vr.getFileContent));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e,t){var _this$messages6;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:(_this$messages6=this.messages)!==null&&_this$messages6!==void 0?_this$messages6:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context152.a(2);}},_callee152,this);}));function callServiceAPI(_x282,_x283){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var _n11;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:if(!e.message){_context153.n=1;break;}throw e.message;case 1:if(!e[f]){_context153.n=2;break;}throw e[f].message;case 2:if(!(e.choices&&e.choices.length>0)){_context153.n=4;break;}_n11=e.choices[0];if(!_n11.delta){_context153.n=3;break;}return _context153.a(2,this.extractStreamResult(_n11,t));case 3:if(!_n11.message){_context153.n=4;break;}return _context153.a(2,_n11.message.tool_calls?this.handleToolsGeneric({tool_calls:_n11.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n11.message.content||""));case 4:return _context153.a(2,_defineProperty({},h,""));}},_callee153,this);}));function extractResultData(_x284,_x285){return _extractResultData33.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var n,s,r;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:n=e.delta,s=e.finish_reason;if(!(s==="tool_calls"&&n!=null&&n.tool_calls)){_context154.n=1;break;}r={tool_calls:n.tool_calls};return _context154.a(2,this.handleToolsGeneric(r,this.functionHandler,this.messages,t));case 1:return _context154.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee154,this);}));function extractStreamResult(_x286,_x287){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t[E]===W?_defineProperty(_defineProperty({},E,qe),qe,t[T]||""):_defineProperty(_defineProperty({},E,h),h,"[Unsupported ".concat(se," ").concat(E,": ").concat(t[E],"]"));});}}]);}(k);var Sr=/*#__PURE__*/function(_k24){function Sr(e){var _this74$maxMessages,_l$model3;var _this74;_classCallCheck(this,Sr);var r,o,a,c,l;var t=C(e.directConnection),n=t.groq;_this74=_callSuper(this,Sr,[e,la(),ca,n]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Groq"),_this74.keyHelpUrl="https://console.groq.com/keys",_this74.url="https://api.groq.com/openai/v1/chat/completions",_this74.permittedErrorPrefixes=[Gt,"property"];var s=(r=t.groq)==null?void 0:r.chat;_typeof(s)===U&&_this74.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.groq)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_l$model3=(l=_this74.rawBody).model)!==null&&_l$model3!==void 0?_l$model3:l.model="llama-3.3-70b-versatile";return _this74;}_inherits(Sr,_k24);return _createClass(Sr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Sr.getTextWImagesContent(r)},x,r[x]===ne?gt:r[x]);});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e,t){var _this$messages7;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:(_this$messages7=this.messages)!==null&&_this$messages7!==void 0?_this$messages7:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context155.a(2);}},_callee155,this);}));function callServiceAPI(_x288,_x289){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var n,s,r,o;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(!e[f]){_context156.n=1;break;}throw e[f].message;case 1:return _context156.a(2,(s=(n=e.choices)==null?void 0:n[0])!=null&&s.delta?this.extractStreamResult(e.choices[0],t):(o=(r=e.choices)==null?void 0:r[0])!=null&&o.message?e.choices[0].message.tool_calls?this.handleToolsGeneric(e.choices[0].message,this.functionHandler,this.messages,t,{message:this.systemMessage}):_defineProperty({},h,e.choices[0].message.content||""):_defineProperty({},h,""));}},_callee156,this);}));function extractResultData(_x290,_x291){return _extractResultData34.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
200
- },{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:return _context157.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee157,this);}));function extractStreamResult(_x292,_x293){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var Dd=function Dd(i){return _defineProperty(_defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te),"accept",te);},Fd=function Fd(i,e,t,n){_typeof(i.message)===Ee?n(pe):t(e);},Ud=function Ud(){return be("https://api.cohere.ai/v1/models",ue,Fd);};var di=/*#__PURE__*/function(_k25){function di(e){var _this75$maxMessages,_s$model4;var _this75;_classCallCheck(this,di);var s;var n=C(e.directConnection).cohere;if(_this75=_callSuper(this,di,[e,Ud(),Dd,n]),_this75.insertKeyPlaceholderText=_this75.genereteAPIKeyName("Cohere"),_this75.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this75.permittedErrorPrefixes=["invalid"],_this75.url="https://api.cohere.com/v2/chat",_typeof(n)===U){var r=de.processCohere(n);_this75.canSendMessage=function(){return r;},_this75.cleanConfig(n),Object.assign(_this75.rawBody,n);}(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1,(_s$model4=(s=_this75.rawBody).model)!==null&&_s$model4!==void 0?_s$model4:s.model="command-a-03-2025";return _this75;}_inherits(di,_k25);return _createClass(di,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t.filter(function(r){return r[h];});return n.messages=s.map(function(r){return _defineProperty(_defineProperty({},x,k.getRoleViaAI(r[x])),"content",r[h]);}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context158.a(2);}},_callee158,this);}));function callServiceAPI(_x294,_x295){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e){var t,n,s,r;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(!(typeof e.message=="string")){_context159.n=1;break;}throw e.message;case 1:if(!(this.stream&&e[h])){_context159.n=2;break;}r=di.parseBundledEvents(e[h]);return _context159.a(2,{text:di.aggregateBundledEventsText(r)});case 2:if(!("message"in e&&(s=(n=(t=e.message)==null?void 0:t.content)==null?void 0:n[0])!=null&&s[h])){_context159.n=3;break;}return _context159.a(2,_defineProperty({},h,e.message.content[0][h]));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context159.a(2);}},_callee159,this);}));function extractResultData(_x296){return _extractResultData35.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),n=[];var _iterator5=_createForOfIteratorHelper(t),_step5;try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var s=_step5.value;if(s.trim())try{var r=JSON.parse(s);n.push(r);}catch(r){console[f]("Failed to parse line:",s,r);}}}catch(err){_iterator5.e(err);}finally{_iterator5.f();}return n;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var n,s,r;return t[E]==="content-delta"&&((r=(s=(n=t.delta)==null?void 0:n.message)==null?void 0:s.content)==null?void 0:r[h]);}).map(function(t){var n,s,r;return(r=(s=(n=t.delta)==null?void 0:n.message)==null?void 0:s.content)==null?void 0:r[h];}).join("");}}]);}(k);var Hd=function Hd(){return _defineProperty({},q,te);},jd=function jd(i,e,t,n){var r;var s=i;s[f]?s[f].code===403||(r=s[f].message)!=null&&r.includes("API key")?n(pe):n(Ue):t(e);},$d=function $d(){var i="https://generativelanguage.googleapis.com/v1beta/models?key=";return be(i,ue,jd,function(e){return"".concat(i).concat(e);});};var xr=/*#__PURE__*/function(_k26){function xr(e){var _this76$maxMessages;var _this76;_classCallCheck(this,xr);var s,r;var n=C(e.directConnection).gemini;if(_this76=_callSuper(this,xr,[e,$d(),Hd,n]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("Gemini"),_this76.keyHelpUrl="https://aistudio.google.com/app/apikey",_this76.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",_this76.url="",_this76.permittedErrorPrefixes=["API_KEY_INVALID"],_typeof(n)===U){var o=n;o.model&&(_this76.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(o.model,":generateContent")),_this76.cleanConfig(o),_this76.completeConfig(o,(r=(s=e.directConnection)==null?void 0:s.gemini)==null?void 0:r.function_handler);}(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1;return _this76;}_inherits(xr,_k26);return _createClass(xr,[{key:"cleanConfig",value:function cleanConfig(e){delete e.model;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return xr.getContent(r);});return n.contents=s,this.systemMessage&&(n.systemInstruction={parts:[_defineProperty({},h,this.systemMessage)]}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e,t){var _this$messages8;var n,s;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if(this.connectSettings){_context160.n=1;break;}throw new Error(He);case 1:(_this$messages8=this.messages)!==null&&_this$messages8!==void 0?_this$messages8:this.messages=e;n=this.preprocessBody(this.rawBody,t),s=this.stream;s&&(_typeof(s)!==U||!s.simulation)||n.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),V.request(this,n,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),ge.request(this,n,e));case 2:return _context160.a(2);}},_callee160,this);}));function callServiceAPI(_x297,_x298){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()// https://ai.google.dev/gemini-api/docs/function-calling?example=weather
201
- },{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(!e[f]){_context161.n=1;break;}throw e[f].message||"Gemini API Error";case 1:if(!((r=(s=(n=e.candidates)==null?void 0:n[0])==null?void 0:s.content)!=null&&r.parts)){_context161.n=3;break;}a=e.candidates[0].content.parts,c=a.find(function(p){return p.functionCall;});if(!(c!=null&&c.functionCall)){_context161.n=2;break;}return _context161.a(2,this.handleTools([c.functionCall],t));case 2:l=a.find(function(p){return p[h];}),d=a.find(function(p){var u;return((u=p.inlineData)==null?void 0:u.mimeType)==="image/png";});return _context161.a(2,_defineProperty(_defineProperty({},h,(l==null?void 0:l[h])||""),b,(o=d==null?void 0:d.inlineData)!=null&&o.data?[_defineProperty({},T,"data:image/png;base64,".concat(d.inlineData.data))]:[]));case 3:return _context161.a(2,_defineProperty({},h,""));}},_callee161,this);}));function extractResultData(_x299,_x300){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){var n,s,_yield$this$callToolF4,r,o,a,c;return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:if(!(!e||!t||!this.functionHandler)){_context162.n=1;break;}throw Error(qt);case 1:n=C(t);s=e.map(function(c){return{name:c.name,arguments:le(c.args)};});_context162.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF4=_context162.v;r=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context162.n=3;break;}return _context162.a(2,o);case 3:a=_defineProperty({parts:e.map(function(c){return{functionCall:{name:c.name,args:c.args}};})},x,"model");if(!(n.contents.push(a),!r.find(function(_ref202){var c=_ref202.response;return _typeof(c)!==Ee;})&&s.length===r.length)){_context162.n=4;break;}c=_defineProperty({parts:r.map(function(l,d){return{functionResponse:{name:e[d].name,response:{result:l.response}}};})},x,F);return _context162.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(on);case 5:return _context162.a(2);}},_callee162,this);}));function handleTools(_x301,_x302){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e[h]&&e[h].trim().length>0&&t.push(_defineProperty({},h,e[h])),e[b]&&e[b].length>0&&e[b].forEach(function(n){if(n[T]&&n[T].includes("data:")){var _n$T$split=n[T].split(","),_n$T$split2=_slicedToArray(_n$T$split,2),s=_n$T$split2[0],r=_n$T$split2[1];t.push({inlineData:{mimeType:s.replace("data:","").replace(";base64",""),data:r}});}}),_defineProperty({parts:t},x,e[x]===F?F:"model");}}]);}(k);var qd=function qd(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},q,te),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");},Gd=function Gd(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},zd=function zd(){return be("https://api.anthropic.com/v1/models",ue,Gd);};var hi=/*#__PURE__*/function(_k27){function hi(e){var _this77$maxMessages,_o$model10,_a$max_tokens2;var _this77;_classCallCheck(this,hi);var s,r,o,a;var n=C(e.directConnection).claude;_this77=_callSuper(this,hi,[e,zd(),qd,n]),_this77.insertKeyPlaceholderText=_this77.genereteAPIKeyName("Claude"),_this77.keyHelpUrl="https://console.anthropic.com/settings/keys",_this77.url="https://api.anthropic.com/v1/messages",_this77.permittedErrorPrefixes=[Te,it],_this77._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},E,"tool_use"),"id",""),"name",""),"input",""),_typeof(n)===U&&_this77.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.claude)==null?void 0:r.function_handler),(_this77$maxMessages=_this77.maxMessages)!==null&&_this77$maxMessages!==void 0?_this77$maxMessages:_this77.maxMessages=-1,(_o$model10=(o=_this77.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="claude-sonnet-4-5-20250929",(_a$max_tokens2=(a=_this77.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this77;}_inherits(hi,_k27);return _createClass(hi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:hi.getTextWFilesContent(r,hi.getFileContent)},x,k.getRoleViaUser(r[x]));});return n.messages=s,this.systemMessage&&(n.system=this.systemMessage),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee163(e,t){var _this$messages9;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:(_this$messages9=this.messages)!==null&&_this$messages9!==void 0?_this$messages9:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context163.a(2);}},_callee163,this);}));function callServiceAPI(_x303,_x304){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var n,s,r,o,a;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:if(!e[f]){_context164.n=1;break;}throw e[f].message;case 1:if(!(e.content&&e.content.length>0)){_context164.n=3;break;}o=e.content.find(function(c){return c[E]==="tool_use";});if(!o){_context164.n=2;break;}return _context164.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(c){return c[E]===h;});if(!a){_context164.n=3;break;}return _context164.a(2,_defineProperty({},h,a[h]));case 3:if(!(e[E]==="content_block_delta"&&e.delta&&e.delta[E]==="text_delta")){_context164.n=4;break;}return _context164.a(2,_defineProperty({},h,e.delta[h]||""));case 4:if(!(e[E]==="content_block_start"&&((n=e.content_block)==null?void 0:n[E])==="tool_use")){_context164.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context164.n=7;break;case 5:if(!(e[E]==="content_block_delta"&&((s=e.delta)==null?void 0:s[E])==="input_json_delta")){_context164.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context164.n=7;break;case 6:if(!(e[E]==="message_delta"&&((r=e.delta)==null?void 0:r.stop_reason)==="tool_use")){_context164.n=7;break;}return _context164.a(2,(this._streamToolCalls.input=this._streamToolCalls.input?JSON.parse(this._streamToolCalls.input):{},this.handleTools([this._streamToolCalls],t)));case 7:return _context164.a(2,_defineProperty({},h,""));}},_callee164,this);}));function extractResultData(_x305,_x306){return _extractResultData37.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){var n,s,_yield$this$callToolF5,r,o,a,c;return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:if(!(!e||!t||!this.functionHandler)){_context165.n=1;break;}throw Error(qt);case 1:n=C(t);s=e.map(function(c){return{name:c.name,arguments:le(c.input)};});_context165.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF5=_context165.v;r=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context165.n=3;break;}return _context165.a(2,o);case 3:a=e.map(function(c){return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},E,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push(_defineProperty(_defineProperty({},x,"assistant"),"content",a)),!r.find(function(_ref210){var c=_ref210.response;return _typeof(c)!==Ee;})&&s.length===r.length)){_context165.n=4;break;}c=r.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},E,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context165.a(2,(n.messages.push(_defineProperty(_defineProperty({},x,F),"content",c)),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(on);case 5:return _context165.a(2);}},_callee165,this);}));function handleTools(_x307,_x308){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var n,s,r;if(t[E]===W){var o=(n=t[T])==null?void 0:n.split(",")[1],a=((r=(s=t[T])==null?void 0:s.match(/data:([^;]+)/))==null?void 0:r[1])||"image/jpeg";return _defineProperty(_defineProperty({},E,W),"source",_defineProperty(_defineProperty(_defineProperty({},E,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},E,h),h,"[Unsupported ".concat(se," ").concat(E,": ").concat(t[E],"]"));});}}]);}(k);var Vd=function Vd(){return{};},Kd=function Kd(){},Wd=function Wd(){return be("",ue,Kd);},Ss=/*#__PURE__*/function(_k28){function Ss(e){var _this78$maxMessages,_o$model11,_a$stream2;var _this78;_classCallCheck(this,Ss);var s,r,o,a;var t=C(e.directConnection);_this78=_callSuper(this,Ss,[e,Wd(),Vd,{key:"placeholder"}]),_this78.insertKeyPlaceholderText="",_this78.keyHelpUrl="",_this78.validateKeyProperty=!1,_this78.url="http://localhost:11434/api/chat",_this78.permittedErrorPrefixes=["Error"];var n=t.ollama;_typeof(n)===U&&_this78.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.ollama)==null?void 0:r.function_handler),(_this78$maxMessages=_this78.maxMessages)!==null&&_this78$maxMessages!==void 0?_this78$maxMessages:_this78.maxMessages=-1,(_o$model11=(o=_this78.rawBody).model)!==null&&_o$model11!==void 0?_o$model11:o.model="llama3.2",(_a$stream2=(a=_this78.rawBody).stream)!==null&&_a$stream2!==void 0?_a$stream2:a.stream=!1;return _this78;}_inherits(Ss,_k28);return _createClass(Ss,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){var o=_defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));if(r[b]&&r[b].length>0){var a=Ss.getImageData(r[b]);a.length>0&&(o[ee]=a);}return o;});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee166(e,t){var _this$messages0;return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:(_this$messages0=this.messages)!==null&&_this$messages0!==void 0?_this$messages0:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context166.a(2);}},_callee166,this);}));function callServiceAPI(_x309,_x310){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"parseMessage",value:function parseMessage(e){return e.split("\n").filter(function(t){return t.trim();}).map(function(t){return JSON.parse(t);});}},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e,t){var n,s,r,o,_iterator6,_step6,l,a,c,_t53,_t54,_t55;return _regenerator().w(function(_context167){while(1)switch(_context167.p=_context167.n){case 0:if(!e[f]){_context167.n=1;break;}throw e[f].message;case 1:if(!e[h]){_context167.n=11;break;}r=this.parseMessage(e[h]),o=[];_iterator6=_createForOfIteratorHelper(r);_context167.p=2;_iterator6.s();case 3:if((_step6=_iterator6.n()).done){_context167.n=7;break;}l=_step6.value;_t53=(n=l.message)!=null&&n.tool_calls;if(!_t53){_context167.n=5;break;}_t54=o;_context167.n=4;return this.handleTools({tool_calls:l.message.tool_calls},t);case 4:_t54.push.call(_t54,_context167.v);case 5:o.push(_defineProperty({},h,((s=l.message)==null?void 0:s.content)||""));case 6:_context167.n=3;break;case 7:_context167.n=9;break;case 8:_context167.p=8;_t55=_context167.v;_iterator6.e(_t55);case 9:_context167.p=9;_iterator6.f();return _context167.f(9);case 10:a=o.map(function(l){return l[h];}),c=a.lastIndexOf(Ss.THINK_END);return _context167.a(2,c===-1||t!=null&&t.think?_defineProperty({},h,a.join("")):_defineProperty(_defineProperty({},h,a.slice(c+1).join("")),"overwrite",!0));case 11:return _context167.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},h,e.message.content||""):_defineProperty({},h,""));}},_callee167,this,[[2,8,9,10]]);}));function extractResultData(_x311,_x312){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){var n,s,_yield$this$callToolF6,r,o;return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context168.n=1;break;}throw Error(qt);case 1:n=C(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:le(a["function"].arguments)};});_context168.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF6=_context168.v;r=_yield$this$callToolF6.responses;o=_yield$this$callToolF6.processedResponse;if(!o){_context168.n=3;break;}return _context168.a(2,o);case 3:if(!(n.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},x,gt),"content","")),!r.find(function(_ref218){var a=_ref218.response;return _typeof(a)!==Ee;})&&s.length===r.length)){_context168.n=4;break;}return _context168.a(2,(r.forEach(function(a,c){var d;var l=(d=e.tool_calls)==null?void 0:d[c];n==null||n.messages.push(_defineProperty(_defineProperty(_defineProperty({},x,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(on);case 5:return _context168.a(2);}},_callee168,this);}));function handleTools(_x313,_x314){return _handleTools5.apply(this,arguments);}return handleTools;}()}],[{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t[E]===W;}).map(function(t){var s;return((s=t[T])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(k);Ss.THINK_END="</think>";var sr=Ss;var da=function da(i){return _defineProperty({Authorization:"".concat(Ce).concat(i)},q,te);},Xd=function Xd(i,e,t,n){var s=i;s[f]?s[f][E]===Te||s[f][E]===it?n(pe):n(Ue):t(e);},ha=function ha(){return be("https://api.x.ai/v1/models",ue,Xd);},yi=/*#__PURE__*/function(_k29){function yi(e){var _o$model12;var _this79;_classCallCheck(this,yi);var r,o;var t=e.directConnection,n=t==null?void 0:t.x;_this79=_callSuper(this,yi,[e,ha(),da,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("X"),_this79.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this79.url=yi.IMAGE_GENERATION_URL,_this79.permittedErrorPrefixes=[it,Te];var s=(r=t==null?void 0:t.x)==null?void 0:r[ee];_typeof(s)===U&&Object.assign(_this79.rawBody,s),(_o$model12=(o=_this79.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="grok-2-image";return _this79;}_inherits(yi,_k29);return _createClass(yi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=C(e);return n&&n!==""&&(s.prompt=n),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e,t){return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context169.a(2);}},_callee169,this);}));function callServiceAPI(_x315,_x316){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e){var t;return _regenerator().w(function(_context170){while(1)switch(_context170.n){case 0:if(!e[f]){_context170.n=1;break;}throw e[f].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},T,n.url),E,W):_defineProperty(_defineProperty({},T,"".concat(On).concat(n.b64_json)),E,W);});return _context170.a(2,_defineProperty({},b,t));}},_callee170);}));function extractResultData(_x317){return _extractResultData39.apply(this,arguments);}return extractResultData;}()}]);}(k);yi.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var ir=yi;var Zd=function Zd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Yd=function Yd(i,e,t,n){var s=i;s[f]?s[f][E]===it?n(pe):n(Ue):t(e);},Jd=function Jd(){return be("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",ue,Yd);};var Ar=/*#__PURE__*/function(_k30){function Ar(e){var _this80$maxMessages,_o$model13;var _this80;_classCallCheck(this,Ar);var s,r,o;var n=C(e.directConnection).qwen;_this80=_callSuper(this,Ar,[e,Jd(),Zd,n]),_this80.insertKeyPlaceholderText=_this80.genereteAPIKeyName("Qwen"),_this80.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this80.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this80.permittedErrorPrefixes=["No static","The model",Ls],_typeof(n)===U&&_this80.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.qwen)==null?void 0:r.function_handler),(_this80$maxMessages=_this80.maxMessages)!==null&&_this80$maxMessages!==void 0?_this80$maxMessages:_this80.maxMessages=-1,(_o$model13=(o=_this80.rawBody).model)!==null&&_o$model13!==void 0?_o$model13:o.model="qwen-plus";return _this80;}_inherits(Ar,_k30);return _createClass(Ar,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Ar.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(e,t){var _this$messages1;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:(_this$messages1=this.messages)!==null&&_this$messages1!==void 0?_this$messages1:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context171.a(2);}},_callee171,this);}));function callServiceAPI(_x318,_x319){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee172(e,t){var _n12;return _regenerator().w(function(_context172){while(1)switch(_context172.n){case 0:if(!e[f]){_context172.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context172.n=3;break;}_n12=e.choices[0];if(!_n12.delta){_context172.n=2;break;}return _context172.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context172.n=3;break;}return _context172.a(2,_n12.message.tool_calls?this.handleToolsGeneric({tool_calls:_n12.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n12.message.content||""));case 3:return _context172.a(2,_defineProperty({},h,""));}},_callee172,this);}));function extractResultData(_x320,_x321){return _extractResultData40.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e,t){return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:return _context173.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee173,this);}));function extractStreamResult(_x322,_x323){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var Qd=function Qd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},eh=function eh(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},th=function th(){return be("https://api.moonshot.ai/v1/models",ue,eh);};var wr=/*#__PURE__*/function(_k31){function wr(e){var _this81$maxMessages,_o$model14;var _this81;_classCallCheck(this,wr);var s,r,o;var n=C(e.directConnection).kimi;_this81=_callSuper(this,wr,[e,th(),Qd,n]),_this81.insertKeyPlaceholderText=_this81.genereteAPIKeyName("Kimi"),_this81.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this81.url="https://api.moonshot.ai/v1/chat/completions",_this81.permittedErrorPrefixes=[Gt,"Not found"],_typeof(n)===U&&_this81.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.kimi)==null?void 0:r.function_handler),(_this81$maxMessages=_this81.maxMessages)!==null&&_this81$maxMessages!==void 0?_this81$maxMessages:_this81.maxMessages=-1,(_o$model14=(o=_this81.rawBody).model)!==null&&_o$model14!==void 0?_o$model14:o.model="moonshot-v1-8k";return _this81;}_inherits(wr,_k31);return _createClass(wr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:wr.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(e,t){var _this$messages10;return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:(_this$messages10=this.messages)!==null&&_this$messages10!==void 0?_this$messages10:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context174.a(2);}},_callee174,this);}));function callServiceAPI(_x324,_x325){return _callServiceAPI38.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(e,t){var _n13;return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:if(!e[f]){_context175.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context175.n=3;break;}_n13=e.choices[0];if(!_n13.delta){_context175.n=2;break;}return _context175.a(2,this.extractStreamResult(_n13,t));case 2:if(!_n13.message){_context175.n=3;break;}return _context175.a(2,_n13.message.tool_calls?this.handleToolsGeneric({tool_calls:_n13.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n13.message.content||""));case 3:return _context175.a(2,_defineProperty({},h,""));}},_callee175,this);}));function extractResultData(_x326,_x327){return _extractResultData41.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee176(e,t){return _regenerator().w(function(_context176){while(1)switch(_context176.n){case 0:return _context176.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee176,this);}));function extractStreamResult(_x328,_x329){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var nh=/*#__PURE__*/function(_k32){function nh(e){var _this82$maxMessages,_o$model15;var _this82;_classCallCheck(this,nh);var r,o;var t=C(e.directConnection),n=t.x;_this82=_callSuper(this,nh,[e,ha(),da,n]),_this82.insertKeyPlaceholderText=_this82.genereteAPIKeyName("X"),_this82.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this82.url="https://api.x.ai/v1/chat/completions",_this82.permittedErrorPrefixes=[it,Te];var s=(r=t.x)==null?void 0:r.chat;_typeof(s)===U&&_this82.completeConfig(s),(_this82$maxMessages=_this82.maxMessages)!==null&&_this82$maxMessages!==void 0?_this82$maxMessages:_this82.maxMessages=-1,(_o$model15=(o=_this82.rawBody).model)!==null&&_o$model15!==void 0?_o$model15:o.model="grok-3-latest";return _this82;}_inherits(nh,_k32);return _createClass(nh,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee177(e,t){return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context177.a(2);}},_callee177,this);}));function callServiceAPI(_x330,_x331){return _callServiceAPI39.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData42=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee178(e){var t,n,s,r,o;return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:if(!e[f]){_context178.n=1;break;}throw e[f].message;case 1:if(!(e.object==="chat.completion.chunk")){_context178.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context178.a(2,(n=o==null?void 0:o.delta)!=null&&n.content?_defineProperty({},h,o.delta.content):_defineProperty({},h,""));case 2:return _context178.a(2,e.object==="chat.completion"&&(r=(s=e.choices)==null?void 0:s[0])!=null&&r.message?_defineProperty({},h,e.choices[0].message.content||""):_defineProperty({},h,""));}},_callee178);}));function extractResultData(_x332){return _extractResultData42.apply(this,arguments);}return extractResultData;}()}]);}(k);var Gs=/* @__PURE__ */function(i){return i.BLOCKING="blocking",i.STREAMING="streaming",i;}(Gs||{}),yn=/* @__PURE__ */function(i){return i.MESSAGE="message",i.AGENT_MESSAGE="agent_message",i.WORKFLOW_FINISHED="workflow_finished",i.ERROR="error",i;}(yn||{});var sh="image/",ih="data:",rh=function rh(i,e){return{type:e,transfer_method:"local_file",upload_file_id:i};},oh=function oh(i){var e=i.trim();if(!e.startsWith(ih))return null;var t=e.replace(/^data:\s*/,"").trim();return t?JSON.parse(t):null;};function ah(_x333,_x334){return _ah.apply(this,arguments);}function _ah(){_ah=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee197(i,e){var t,_e$headers,n,s,r,a,o;return _regenerator().w(function(_context197){while(1)switch(_context197.n){case 0:t=new FormData();t.append(se,i),t.append(F,e[F]);_e$headers=e.headers;n=_e$headers[q];s=_objectWithoutProperties(_e$headers,[q].map(_toPropertyKey));_context197.n=1;return fetch(e.url,{method:ye,headers:s,body:t});case 1:r=_context197.v;if(r.ok){_context197.n=3;break;}_context197.n=2;return r.text();case 2:a=_context197.v;throw new Error(a);case 3:_context197.n=4;return r.json();case 4:o=_context197.v;if(o.id){_context197.n=5;break;}throw new Error("Upload response missing file ID");case 5:return _context197.a(2,o.id);}},_callee197);}));return _ah.apply(this,arguments);}function ch(_x335,_x336){return _ch.apply(this,arguments);}function _ch(){_ch=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee199(i,e){var t;return _regenerator().w(function(_context199){while(1)switch(_context199.n){case 0:if(!(i.length===0)){_context199.n=1;break;}return _context199.a(2,[]);case 1:t=i.map(/*#__PURE__*/function(){var _ref266=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee198(s){var r,o;return _regenerator().w(function(_context198){while(1)switch(_context198.n){case 0:_context198.n=1;return ah(s,e);case 1:r=_context198.v;o=s[E].startsWith(sh)?W:se;return _context198.a(2,rh(r,o));}},_callee198);}));return function(_x367){return _ref266.apply(this,arguments);};}());_context199.n=2;return Promise.all(t);case 2:return _context199.a(2,_context199.v.filter(function(s){return s!==null;}));}},_callee199);}));return _ch.apply(this,arguments);}function lh(i,e){return i.conversation_id&&e(i.conversation_id),i.code&&i.message&&!i.answer?_defineProperty({},f,i.message):_defineProperty({},h,i.answer||"");}var dh=function dh(i,e,t){var n,s;switch(!e.conversationIdSet&&i.conversation_id&&(t(i.conversation_id),e.conversationIdSet=!0),i.event){case yn.MESSAGE:case yn.AGENT_MESSAGE:e.fullAnswer+=i.answer||"";break;case yn.WORKFLOW_FINISHED:!e.fullAnswer&&(s=(n=i.data)==null?void 0:n.outputs)!=null&&s.answer&&(e.fullAnswer=i.data.outputs.answer);break;case yn.ERROR:e.errorMessage=i.message||yn.ERROR;break;}};function hh(_x337,_x338){return _hh.apply(this,arguments);}function _hh(){_hh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee200(i,e){var t,s,_iterator7,_step7,r,o;return _regenerator().w(function(_context200){while(1)switch(_context200.n){case 0:t={fullAnswer:"",conversationIdSet:!1,errorMessage:""};_context200.n=1;return i.text();case 1:s=_context200.v.split(/\r?\n\r?\n/);_iterator7=_createForOfIteratorHelper(s);try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){r=_step7.value;o=oh(r);o&&dh(o,t,e);}}catch(err){_iterator7.e(err);}finally{_iterator7.f();}return _context200.a(2,t.errorMessage?_defineProperty({},f,t.errorMessage):_defineProperty({},h,t.fullAnswer));}},_callee200);}));return _hh.apply(this,arguments);}var uh=function uh(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},ph=function ph(i,e,t,n){var s=i;s[f]?s[f].message===Ei?n(pe):n(Ue):"user_input_form"in i||"opening_statement"in i||"file_upload"in i?t(e):n(Ue);},fh=function fh(i){return be("".concat(i,"/parameters"),ue,ph);};var mh=/*#__PURE__*/function(_k33){function mh(e){var _ref239,_this83$maxMessages;var _this83;_classCallCheck(this,mh);var r;var t=C(e.directConnection),n=t==null?void 0:t.dify,s=(_ref239=(r=e.connect)==null?void 0:r.url)!==null&&_ref239!==void 0?_ref239:"https://api.dify.ai/v1";_this83=_callSuper(this,mh,[e,fh(s),uh,n]),_this83.insertKeyPlaceholderText=_this83.genereteAPIKeyName("Dify"),_this83.keyHelpUrl="https://docs.dify.ai/en/use-dify/publish/developing-with-apis",_this83.permittedErrorPrefixes=[Te],_this83._conversationId="",_this83._user=F,_this83._inputs={},_this83.url="".concat(s,"/chat-messages"),_this83._uploadUrl="".concat(s,"/").concat(b,"/upload"),_typeof(n)===U&&(n[F]&&(_this83._user=n[F]),n.inputs&&(_this83._inputs=n.inputs),_this83.completeConfig(n)),(_this83$maxMessages=_this83.maxMessages)!==null&&_this83$maxMessages!==void 0?_this83$maxMessages:_this83.maxMessages=-1,_this83._mode=_this83.stream?Gs.STREAMING:Gs.BLOCKING;return _this83;}_inherits(mh,_k33);return _createClass(mh,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var s=this.processMessages(t),r=s[s.length-1],o=(r==null?void 0:r[h])||" ",a=_defineProperty({inputs:this._inputs,query:o,response_mode:this._mode},F,this._user);return this._conversationId&&(a.conversation_id=this._conversationId),n&&n.length>0&&(a[b]=n),a;}},{key:"callServiceAPI",value:function(){var _callServiceAPI40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e,t,n){var _this$messages11,_this84=this;var s,_t56;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:(_this$messages11=this.messages)!==null&&_this$messages11!==void 0?_this$messages11:this.messages=e;s=[];_t56=n&&n.length>0;if(!_t56){_context179.n=2;break;}_context179.n=1;return ch(n,_defineProperty(_defineProperty({url:this._uploadUrl},F,this._user),"headers",this.connectSettings.headers));case 1:s=_context179.v;case 2:this.callDirectServiceServiceAPI(e,t,function(r,o){return _this84.preprocessBody(r,o,s);});case 3:return _context179.a(2);}},_callee179,this);}));function callServiceAPI(_x339,_x340,_x341){return _callServiceAPI40.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData43=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(e){var _this85=this;var t;return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:t=function t(n){_this85._conversationId=n;};return _context180.a(2,this._mode===Gs.BLOCKING&&!this.stream?lh(e,t):hh(e,t));}},_callee180,this);}));function extractResultData(_x342){return _extractResultData43.apply(this,arguments);}return extractResultData;}()}]);}(k);var gh=/*#__PURE__*/function(){function gh(){_classCallCheck(this,gh);}return _createClass(gh,null,[{key:"create",value:// this should only be called when no _activeService is set or is demo as otherwise we don't want to reconnect
202
- function create(e){var t=e.directConnection,n=e.connect,s=e.demo,r=e.webModel;if(r)return new Rs(e);if(t){if(t.openAI)return t.openAI[ee]?new nr(e):t.openAI.speechToText?new Ji(e):t.openAI.textToSpeech?new Yi(e):t.openAI.assistant?new yr(e):t.openAI.realtime?new Zi(e):t.openAI.completions?new ai(e):new ci(e);if(t.assemblyAI)return new _r(e);if(t.cohere)return new di(e);if(t.huggingFace)return t.huggingFace.textGeneration?new Dl(e):t.huggingFace.summarization?new Ul(e):t.huggingFace.translation?new jl(e):t.huggingFace.fillMask?new $l(e):t.huggingFace.questionAnswer?new Fl(e):t.huggingFace.audioSpeechRecognition?new Bl(e):t.huggingFace.audioClassification?new Ll(e):t.huggingFace.imageClassification?new Ol(e):new Hl(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new Er(e);if(t.azure.openAI.assistant)return new Wi(e);}if(t.azure.speechToText)return new tr(e);if(t.azure.textToSpeech)return new er(e);if(t.azure.summarization)return new Qi(e);if(t.azure.translation)return new ld(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new ti(e):t.stabilityAI.imageToImageUpscale?new Qs(e):t.stabilityAI.imageToImageMasking?new ei(e):new ni(e);if(t.mistral)return new vr(e);if(t.gemini)return new xr(e);if(t.claude)return new hi(e);if(t.deepSeek)return new Id(e);if(t.miniMax)return new Ld(e);if(t.openRouter)return new fs(e);if(t.kimi)return new wr(e);if(t.x)return t.x[ee]?new ir(e):new nh(e);if(t.qwen)return new Ar(e);if(t.together)return t.together[ee]?new pd(e):t.together.textToSpeech?new Vl(e):new fd(e);if(t.bigModel)return t.bigModel[ee]?new dd(e):t.bigModel.textToSpeech?new Gl(e):new li(e);if(t.groq)return t.groq.textToSpeech?new ud(e):new Sr(e);if(t.perplexity)return new vd(e);if(t.ollama)return new sr(e);if(t.openWebUI)return new wd(e);if(t.dify)return new mh(e);}return n&&Object.keys(n).length>0&&!s?new hn(e):new hn(e,void 0,s||!0);}}]);}();var Lr=/*#__PURE__*/_createClass(function Lr(){_classCallCheck(this,Lr);});Lr.attibutes={string:function string(e){return e;},number:function number(e){return parseFloat(e);},"boolean":function boolean(e){return e==="true";},object:function object(e){return JSON.parse(e);},array:function array(e){return JSON.parse(e);},"function":function _function(e){return new Function("return ".concat(e))();}};var rr=Lr;function O(i){return function(e,t){Object.defineProperty(e,t,{});var n=e.constructor,s=t.toLocaleLowerCase();n._attributes_[s]=rr.attibutes[i],n._attributeToProperty_[s]=t;};}var bh="deep-chat-downwards-mode",yh="deep-chat-upwards-mode",jn="submit-button",js="loading-button",$n="disabled-button",ro="text-input-container-start-adjustment",oo="text-input-container-end-adjustment",ao="text-input-container-start-small-adjustment",co="text-input-container-end-small-adjustment";var Cr=/*#__PURE__*/function(){function Cr(e){_classCallCheck(this,Cr);this._isDisplayed=!1,this._elementRef=this.createIntroPanelWithChild(e),this._isDisplayed=!0;}return _createClass(Cr,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e){var t=Cr.createIntroPanel();return e[v].display==="none"&&(e[v].display="block"),t.appendChild(e),t;}},{key:"hide",value:function hide(){this._isDisplayed&&(this._elementRef[v].display="none",this._isDisplayed=!1);}},{key:"display",value:function display(){this._isDisplayed||(this._elementRef[v].display="",this._isDisplayed=!0);}}],[{key:"createIntroPanel",value:function createIntroPanel(){var e=A();return e[m].add("intro-panel"),Object.assign(e[v]),e;}}]);}();var _h="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n\t viewBox=\"50 30 420 450\" xml:space=\"preserve\">\n<g filter=\"brightness(0) saturate(100%) invert(16%) sepia(0%) saturate(1942%) hue-rotate(215deg) brightness(99%) contrast(93%)\">\n\t<g>\n\t\t<path d=\"M447.933,103.629c-0.034-3.076-1.224-6.09-3.485-8.352L352.683,3.511c-0.004-0.004-0.007-0.005-0.011-0.008\n\t\t\tC350.505,1.338,347.511,0,344.206,0H89.278C75.361,0,64.04,11.32,64.04,25.237v461.525c0,13.916,11.32,25.237,25.237,25.237\n\t\t\th333.444c13.916,0,25.237-11.32,25.237-25.237V103.753C447.96,103.709,447.937,103.672,447.933,103.629z M356.194,40.931\n\t\t\tl50.834,50.834h-49.572c-0.695,0-1.262-0.567-1.262-1.262V40.931z M423.983,486.763c0,0.695-0.566,1.261-1.261,1.261H89.278\n\t\t\tc-0.695,0-1.261-0.566-1.261-1.261V25.237c0-0.695,0.566-1.261,1.261-1.261h242.94v66.527c0,13.916,11.322,25.239,25.239,25.239\n\t\t\th66.527V486.763z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,164.014H149.912c-6.62,0-11.988,5.367-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.368,11.988-11.988C374.076,169.381,368.707,164.014,362.088,164.014z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,236.353H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.368,11.988-11.988C374.076,241.721,368.707,236.353,362.088,236.353z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,308.691H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.367,11.988-11.988C374.076,314.06,368.707,308.691,362.088,308.691z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M256,381.031H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988H256\n\t\t\tc6.62,0,11.988-5.367,11.988-11.988C267.988,386.398,262.62,381.031,256,381.031z\"/>\n\t</g>\n</g>\n</svg>",Ie=/*#__PURE__*/function(){function Ie(){_classCallCheck(this,Ie);}return _createClass(Ie,null,[{key:"createImage",value:function createImage(e,t){var n=new Image();return n[T]=e[T],t&&Se.scrollDownOnImageLoad(n[T],t),Se.processContent(W,n,n[T],e.name);}// WORK - image still does not scroll down when loaded
203
- },{key:"createImageMessage",value:function createImageMessage(e,t,n,s,r){var o=e.createNewMessageElement("",n,s),a=!s&&r?e.scrollToFirstElement.bind(e,n,r):void 0,c=Ie.createImage(t,a);return o.bubbleElement.appendChild(c),o.bubbleElement[m].add(Ie.IMAGE_BUBBLE_CLASS),_defineProperty(_defineProperty({},E,W),"elements",o);}},{key:"createAudioElement",value:function createAudioElement(e,t){var n=A($);return n[T]=e[T],n[m].add("audio-player"),n.controls=!0,$e.IS_SAFARI&&(n[m].add("audio-player-safari"),n[m].add(t===F?"audio-player-safari-end":"audio-player-safari-start")),n;}},{key:"autoPlayAudio",value:function autoPlayAudio(e){e.addEventListener("loadeddata",function(){e.play()["catch"](function(t){console.warn("Auto-play failed:",t);});});}},{key:"createNewAudioMessage",value:function createNewAudioMessage(e,t,n,s){var r=Ie.createAudioElement(t,n),o=e.createMessageElementsOnOrientation("",n,s);return o.bubbleElement.appendChild(r),o.bubbleElement[m].add(Ie.AUDIO_BUBBLE_CLASS),_defineProperty(_defineProperty(_defineProperty({},E,$),"elements",o),"audioElement",r);}},{key:"createAnyFile",value:function createAnyFile(e){var t=A();t[m].add("any-file-message-contents");var n=A();n[m].add("any-file-message-icon-container");var s=kt.createSVGElement(_h);s[m].add("any-file-message-icon"),n.appendChild(s);var r=A();return r[m].add("any-file-message-text"),r.textContent=e.name||se,t.appendChild(n),t.appendChild(r),Se.processContent(rn,t,e[T],r.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,n,s){var r=e.createMessageElementsOnOrientation("",n,s),o=Ie.createAnyFile(t);return r.bubbleElement[m].add(Ie.ANY_FILE_BUBBLE_CLASS),r.bubbleElement.appendChild(o),_defineProperty(_defineProperty({},E,se),"elements",r);}},{key:"createMessages",value:function createMessages(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;return t.map(function(o,a){var c;if(o.ref&&(o=Se.removeFileRef(o)),Se.isAudioFile(o)){var l=Ie.createNewAudioMessage(e,o,n,r),d=(c=e.textToSpeech)==null?void 0:c.audio;return d&&(d.autoPlay&&Ie.autoPlayAudio(l.audioElement),typeof d.displayAudio=="boolean"&&!d.displayAudio)?void 0:l;}return Se.isImageFile(o)?Ie.createImageMessage(e,o,n,r,s&&a===0):Ie.createNewAnyFileMessage(e,o,n,r);}).filter(function(o){return o!==void 0;});}// no overwrite previous message logic as it is complex to track which files are to be overwritten
204
- },{key:"addMessages",value:function addMessages(e,t,n,s,r){Ie.createMessages(e,t,n,s,r).filter(function(a){return a!==void 0;}).forEach(function(_ref243){var a=_ref243[E],c=_ref243.elements;Se.addMessage(e,c,a,n,r);});}}]);}();Ie.IMAGE_BUBBLE_CLASS="image-message",Ie.AUDIO_BUBBLE_CLASS="audio-message",Ie.ANY_FILE_BUBBLE_CLASS="any-file-message";var ui=Ie;var Qe=/*#__PURE__*/function(){function Qe(){_classCallCheck(this,Qe);}return _createClass(Qe,null,[{key:"removeElements",value:function removeElements(e,t){if(!t)return;var n=e.findIndex(function(s){return s===t;});e.splice(n,1),t==null||t.outerContainer.remove();}},{key:"removeFilesMessages",value:function removeFilesMessages(e,t){var n;(n=t[1][b])==null||n.forEach(function(s){Qe.removeElements(e.messageElementRefs,s);}),delete t[0][b],delete t[1][b];}},{key:"removeTextHTMLMessage",value:function removeTextHTMLMessage(e,t,n){var s=t[1][n];Qe.removeElements(e.messageElementRefs,s),delete t[0][n],delete t[1][n];}},{key:"updateHTMLMessage",value:function updateHTMLMessage(e,t,n){var s,r,o;if(t[1][L])yt.overwriteElements(e,n,t[1][L]);else{var a=yt.create(e,n,t[0][x]),c=((r=t[1][b])==null?void 0:r[((s=t[1][b])==null?void 0:s.length)-1])||t[1][h],l=c.outerContainer.nextSibling;(o=l==null?void 0:l.parentElement)==null||o.insertBefore(a.outerContainer,l),e.messageElementRefs.splice(e.messageElementRefs.length-1,1);var d=e.messageElementRefs.findIndex(function(p){return p===c;});e.messageElementRefs.splice(d+1,0,a),t[1][L]=a;}t[0][L]=n;}// finds beforeElement, creates new elements, remove old and adds new ones
205
- },{key:"updateFileMessages",value:function updateFileMessages(e,t,n){var p,u;var s=t[0][x],r=ui.createMessages(e,n,s,!1),o=t[1][L],a=((u=t[1][b])==null?void 0:u[((p=t[1][b])==null?void 0:p.length)-1])||t[1][h],c=o||a;var l=e.messageElementRefs.findIndex(function(g){return g===c;});a&&(l+=1);var d=(o==null?void 0:o.outerContainer)||(a==null?void 0:a.outerContainer.nextSibling);r.forEach(function(_ref244,_){var g=_ref244.type,y=_ref244.elements;var S;Se.setElementProps(e,y,g,s),(S=d.parentElement)==null||S.insertBefore(y.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(l+_,0,y);}),Qe.removeFilesMessages(e,t),t[1][b]=r.map(function(_ref245){var g=_ref245.elements;return g;}),t[0][b]=n;}},{key:"updateTextMessage",value:function updateTextMessage(e,t,n){var s,r;if(t[1][h])e.renderText(t[1][h].bubbleElement,n,t[0][x]);else{var o=e.createElements(n,t[0][x]),a=((s=t[1][b])==null?void 0:s[0])||t[1][L];(r=a.outerContainer.parentElement)==null||r.insertBefore(o.outerContainer,a.outerContainer);var c=e.messageElementRefs.findIndex(function(l){return l===a;});e.messageElementRefs.splice(c,0,o),t[1][h]=o;}t[0][h]=n;}},{key:"isElementActive",value:function isElementActive(e){var t,n;return tt.isActiveElement((t=e[h])==null?void 0:t.bubbleElement[m])||tt.isActiveElement((n=e[L])==null?void 0:n.bubbleElement[m]);}// note that overwrite and 'deep-chat-temporary-message' are used to remove a message
206
- },{key:"update",value:function update(e,t,n){var s=e.messageToElements[n];if(s){if(Qe.isElementActive(s[1]))return console[f]("Cannot update a message that is being streamed");t[h]&&Qe.updateTextMessage(e,s,t[h]),t[b]?Qe.updateFileMessages(e,s,t[b]):Qe.removeFilesMessages(e,s),t[L]&&Qe.updateHTMLMessage(e,s,t[L]),!t[h]&&s[1][h]&&Qe.removeTextHTMLMessage(e,s,h),!t[L]&&s[1][L]&&Qe.removeTextHTMLMessage(e,s,L);var r=e.messageElementRefs,o=e.avatar,a=e.name;B.classifyRoleMessages(r),B.resetAllRoleElements(r,o,a);}else console[f]("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var Eh=/*#__PURE__*/function(){function Eh(){_classCallCheck(this,Eh);}return _createClass(Eh,null,[{key:"getText",value:function getText(e,t){var n,s;if(!e.directConnection&&!e.connect&&!e.webModel&&!e.demo)return"Connect to any API using the [connect](".concat(Z,"connect#connect-1) property or a popular service via [directConnection](").concat(Z,"directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](").concat(Z,"webModel).\n To get started checkout the [Start](https://deepchat.dev/start) page and live code [examples](https://deepchat.dev/examples/frameworks).\n To remove this message set the [demo](").concat(Z,"modes#demo) property to true.");if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](".concat(Z,"directConnection/#directConnection) object.");var r=(n=e.directConnection.openAI)==null?void 0:n.chat;if(_typeof(r)=="object"&&(s=r.tools)!=null&&s.find(function(o){return o[E]==="function";})&&!r.function_handler)return"Please define the `function_handler` property inside the openAI [chat](".concat(Z,"directConnection/openAI#Chat) object.");}else if(e.connect&&!e.connect.url&&!e.connect.handler)return"Please define a `url` or a `handler` property inside the [connect](".concat(Z,"connect#connect-1) object.");return null;}}]);}();var tt=/*#__PURE__*/function(_nt){function tt(e,t,n){var _this86;_classCallCheck(this,tt);var a,c;_this86=_callSuper(this,tt,[e]);var s=t.permittedErrorPrefixes,r=t.demo;_this86._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this86._onClearMessages=dn.onClearMessages.bind(_this86,e),_this86._onError=dn.onError.bind(_this86,e),_this86._isLoadingMessageAllowed=tt.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this86.setLoadingToggle.bind(_this86)),_this86._permittedErrorPrefixes=s,_this86.addSetupMessageIfNeeded(e,t)||_this86.populateIntroPanel(n),r&&_this86.prepareDemo(de.processDemo(r),e.loadHistory),_this86.addIntroductoryMessages(e,t);var o=new Ts(e,_this86,t);_this86._displayServiceErrorMessages=(c=e.errorMessages)==null?void 0:c.displayServiceErrorMessages,e.getMessages=function(){return B.deepCloneMessagesWithReferences(_this86.messageToElements.map(function(_ref246){var _ref247=_slicedToArray(_ref246,1),l=_ref247[0];return l;}));},e.clearMessages=_this86.clearMessages.bind(_this86,t),e.refreshMessages=_this86.refreshTextMessages.bind(_this86,e.remarkable),e.scrollToBottom=z.scrollToBottom.bind(_this86,_this86),e.addMessage=function(l,d){_this86.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(l,d){return Qe.update(_this86,l,d);},t.isWebModel()&&t.setUpMessages(_this86),e.textToSpeech&&Rn.processConfig(e.textToSpeech,function(l){_this86.textToSpeech=l;}),_this86.elementRef.onscroll=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee181(){var l,d;return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:e.loadHistory&&o.loadHistoryOnScroll(e.loadHistory),(l=_this86.scrollButton)==null||l.updateScroll(),(d=_this86.browserStorage)!=null&&d.trackScrollHeight&&_this86.browserStorage.addScrollHeight(_this86.elementRef.scrollTop);case 1:return _context181.a(2);}},_callee181);}));return _this86;}_inherits(tt,_nt);return _createClass(tt,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1],n=nt.isLoadingMessage(t);if(!e&&n)this.removeLastMessage(),delete this._activeLoadingConfig;else{if(this._activeLoadingConfig&&n){var s=oe.getTargetWrapper(t.bubbleElement);if(s)return this._activeLoadingConfig=e||{},this.updateLoadingMessage(s);this.removeLastMessage();}this._activeLoadingConfig=e||{},this.addLoadingMessage(!0);}}},{key:"prepareDemo",value:function prepareDemo(e,t){var n;if(_typeof(e)=="object"){if(!t&&e.displayLoading){var s=e.displayLoading.history;s!=null&&s.small&&Mt.addMessage(this,!1),s!=null&&s.full&&Mt.addMessage(this);}e.displayErrors&&(e.displayErrors[w]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage(ae,""),e.displayErrors.speechToText&&this.addNewErrorMessage("speechToText","")),(n=e.displayLoading)!=null&&n.message&&this.addLoadingMessage(),e.response&&(this.customDemoResponse=e.response);}}},{key:"addSetupMessageIfNeeded",value:function addSetupMessageIfNeeded(e,t){var n=Eh.getText(e,t);if(n){var s=this.createAndAppendNewMessageElement(n,ne);this.applyCustomStyles(s,ne,!1);}return!!n;}// WORK - const file for deep chat classes
207
- },{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this87=this;e!=null&&e.shadowRoot&&(this._introMessage=e.introMessage);var n=this._introMessage;t!=null&&t.isWebModel()&&(n!==null&&n!==void 0?n:n=t.getIntroMessage(n));var s=!(e!=null&&e.history)&&!!(e!=null&&e.loadHistory||t!=null&&t.fetchHistory);n&&(Array.isArray(n)?n.forEach(function(r,o){if(o!==0){var a=_this87.messageElementRefs[_this87.messageElementRefs.length-1].innerContainer;B.hideRoleElements(a,_this87.avatar,_this87.name);}_this87.addIntroductoryMessage(r,s);}):this.addIntroductoryMessage(n,s));}},{key:"addIntroductoryMessage",value:function addIntroductoryMessage(e,t){var s;var n;return e!=null&&e[h]?n=this.createAndAppendNewMessageElement(e[h],ne):e!=null&&e[L]&&(n=yt.add(this,e[L],ne)),n&&(this.applyCustomStyles(n,ne,!1,(s=this.messageStyles)==null?void 0:s.intro),n.outerContainer[m].add(nt.INTRO_CLASS),t&&(n.outerContainer[v].display="none")),n;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer[m].contains(nt.INTRO_CLASS)&&(e.outerContainer.remove(),this.messageElementRefs.shift());}},{key:"addAnyMessage",value:function addAnyMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;return e[f]?this.addNewErrorMessage(ae,e[f],n):this.addNewMessage(e,t,n);}},{key:"tryAddTextMessage",value:function tryAddTextMessage(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;e[h]!==void 0&&n[h]!==null&&(this.addNewTextMessage(e[h],e[x],t,r),!s&&this.textToSpeech&&e[x]!==F&&Rn.speak(e[h],this.textToSpeech));}},{key:"tryAddFileMessages",value:function tryAddFileMessages(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;e[b]&&Array.isArray(e[b])&&ui.addMessages(this,e[b],e[x],t,n);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e[L]!==void 0&&e[L]!==null){var s=yt.add(this,e[L],e[x],t,n);!n&&bt.isElementTemporary(s)&&delete e[L];}}// this should not be activated by streamed messages
208
- },{key:"addNewMessage",value:function addNewMessage(e){var _this88=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var c,l,d,p;e[x]!==F&&((c=this._hiddenAttachments)==null||c.removeHiddenFiles());var s=tt.createMessageContent(e),r=(d=(l=this.textToSpeech)==null?void 0:l.audio)==null?void 0:d.displayText;typeof r=="boolean"&&!r&&delete s[h];var o=z.isScrollbarAtBottomOfElement(this.elementRef),a={status:e.overwrite};return n?(this.tryAddFileMessages(s,o,n),this.tryAddHTMLMessage(s,a,n),this.tryAddTextMessage(s,a,e,t,n)):(this.tryAddTextMessage(s,a,e,t,n),this.tryAddHTMLMessage(s,a,n),this.tryAddFileMessages(s,o,n)),this.isValidMessageContent(s)&&!n&&(this.updateStateOnMessage(s,e.overwrite,e.sendUpdate,t),a.status||setTimeout(function(){return _this88.scrollToFirstElement(s[x],o);}),t||(p=this.browserStorage)==null||p.addMessages(this.messageToElements.map(function(_ref249){var _ref250=_slicedToArray(_ref249,1),u=_ref250[0];return u;})),this.scrollButton&&s[x]!==F&&this.tryUpdateHiddenMessageCount(t,e)),this._activeLoadingConfig&&this.addLoadingMessage(!1),s;}},{key:"tryUpdateHiddenMessageCount",value:function tryUpdateHiddenMessageCount(e,t){var _this89=this;(!e||t.sendUpdate!==void 0)&&setTimeout(function(){var n,s;return(s=(n=_this89.scrollButton)==null?void 0:n.updateHidden)==null?void 0:s.call(n);});}},{key:"isValidMessageContent",value:function isValidMessageContent(e){return e[h]||e[L]||e[b]&&e[b].length>0;}},{key:"updateStateOnMessage",value:function updateStateOnMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(!t){var r=B.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,r]);}n&&this.sendClientUpdate(e,s);}// prettier-ignore
195
+ }],[{key:"canFileSendMessage",value:function canFileSendMessage(e,t){return!!(t!=null&&t[0])||!!(e&&e.trim()!=="");}},{key:"createFormDataBody",value:function createFormDataBody(e,t,n){var s=new FormData();return s.append(W,t),n&&s.append("mask",n),Object.keys(e).forEach(function(r){s.append(r,String(e[r]));}),s;}}]);}(k);ot.IMAGE_GENERATION_URL="".concat(Ze,"images/generations"),ot.IMAGE_VARIATIONS_URL="".concat(Ze,"images/variations"),ot.IMAGE_EDIT_URL="".concat(Ze,"images/edits");var er=ot;var fd=function fd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},md=function md(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},gd=function gd(){return be("https://openrouter.ai/api/v1/key",ue,md);};var ps=/*#__PURE__*/function(_k18){function ps(e){var _this68$maxMessages,_o$model9,_a$max_tokens;var _this68;_classCallCheck(this,ps);var s,r,o,a;var n=C(e.directConnection).openRouter;_this68=_callSuper(this,ps,[e,gd(),fd,n]),_this68.insertKeyPlaceholderText=_this68.genereteAPIKeyName("OpenRouter"),_this68.keyHelpUrl="https://openrouter.ai/keys",_this68.url="https://openrouter.ai/api/v1/chat/completions",_this68.permittedErrorPrefixes=[it,Te],_typeof(n)===U&&_this68.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.openRouter)==null?void 0:r.function_handler),(_this68$maxMessages=_this68.maxMessages)!==null&&_this68$maxMessages!==void 0?_this68$maxMessages:_this68.maxMessages=-1,(_o$model9=(o=_this68.rawBody).model)!==null&&_o$model9!==void 0?_o$model9:o.model="openai/gpt-4o",(_a$max_tokens=(a=_this68.rawBody).max_tokens)!==null&&_a$max_tokens!==void 0?_a$max_tokens:a.max_tokens=1e3;return _this68;}_inherits(ps,_k18);return _createClass(ps,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(o){return _defineProperty({content:ps.getContent(o)},x,k.getRoleViaUser(o[x]));}),r=[];return this.systemMessage&&r.push(_defineProperty(_defineProperty({},x,Mn),"content",this.systemMessage)),r.push.apply(r,_toConsumableArray(s)),n.messages=r,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI25=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee139(e,t){var _this$messages4;return _regenerator().w(function(_context139){while(1)switch(_context139.n){case 0:(_this$messages4=this.messages)!==null&&_this$messages4!==void 0?_this$messages4:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context139.a(2);}},_callee139,this);}));function callServiceAPI(_x259,_x260){return _callServiceAPI25.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee140(e,t){var n,s,r,o,a,c,_a5,_c5;return _regenerator().w(function(_context140){while(1)switch(_context140.n){case 0:if(!e[f]){_context140.n=1;break;}throw e[f].message;case 1:if(!(e.object==="chat.completion.chunk")){_context140.n=4;break;}a=(n=e.choices)==null?void 0:n[0];if(!(a!=null&&a.delta)){_context140.n=2;break;}return _context140.a(2,this.extractStreamResult(a,t));case 2:if(!((s=e.message)!=null&&s[ee])){_context140.n=3;break;}c=e.message[ee].map(function(l){return _defineProperty({},T,l[qe].url);});return _context140.a(2,_defineProperty(_defineProperty({},h,e.message.content||""),b,c));case 3:return _context140.a(2,_defineProperty({},h,""));case 4:if(!(e.object==="chat.completion")){_context140.n=6;break;}_a5=(r=e.choices)==null?void 0:r[0];if(!(_a5!=null&&_a5.message)){_context140.n=6;break;}if(!_a5.message.tool_calls){_context140.n=5;break;}return _context140.a(2,this.handleToolsGeneric({tool_calls:_a5.message.tool_calls},this.functionHandler,this.messages,t));case 5:_c5=((o=_a5.message[ee])==null?void 0:o.map(function(l){return _defineProperty({},T,l[qe].url);}))||[];return _context140.a(2,_defineProperty(_defineProperty({},h,_a5.message.content||""),"files",_c5));case 6:return _context140.a(2,_defineProperty({},h,""));}},_callee140,this);}));function extractResultData(_x261,_x262){return _extractResultData28.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee141(e,t){var n,s;return _regenerator().w(function(_context141){while(1)switch(_context141.n){case 0:n=e.delta;if(!(n!=null&&n[ee])){_context141.n=1;break;}s=n[ee].map(function(r){return _defineProperty({},T,r[qe].url);});return _context141.a(2,_defineProperty(_defineProperty({},h,n.content||""),b,s));case 1:return _context141.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee141,this);}));function extractStreamResult(_x263,_x264){return _extractStreamResult3.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getAudioContent",value:function getAudioContent(e){return e.filter(function(t){return t[E]===$;}).map(function(t){var r,o,a;var n=(r=t[T])==null?void 0:r.split(",")[1],s=(a=(o=t[T])==null?void 0:o.match(/data:audio\/([^;]+)/))==null?void 0:a[1];return _defineProperty(_defineProperty({},E,sn),sn,{data:n||"",format:s==="wav"||s==="mp3"?s:"mp3"});}).filter(function(t){return t[sn].data.length>0;});}},{key:"getContent",value:function getContent(e){if(e[b]&&e[b].length>0){var t=[].concat(_toConsumableArray(ps.getImageContent(e[b])),_toConsumableArray(ps.getAudioContent(e[b])));return e[h]&&e[h].trim().length>0&&t.unshift(_defineProperty(_defineProperty({},E,h),h,e[h])),t.length>0?t:e[h]||"";}return e[h]||"";}}]);}(k);var bd=function bd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},yd=function yd(i,e,t,n){i[f]?n(pe):t(e);},_d=function _d(){return be("https://api.perplexity.ai/chat/completions",ye,yd);};var Ed=/*#__PURE__*/function(_k19){function Ed(e){var _this69$maxMessages,_s$model;var _this69;_classCallCheck(this,Ed);var s;var n=C(e.directConnection).perplexity;_this69=_callSuper(this,Ed,[e,_d(),bd,n]),_this69.insertKeyPlaceholderText=_this69.genereteAPIKeyName("Perplexity"),_this69.keyHelpUrl="https://www.perplexity.ai/settings/api",_this69.url="https://api.perplexity.ai/chat/completions",_this69.permittedErrorPrefixes=[zt,Ho,"Permission denied"],_typeof(n)===U&&_this69.completeConfig(n),(_this69$maxMessages=_this69.maxMessages)!==null&&_this69$maxMessages!==void 0?_this69$maxMessages:_this69.maxMessages=-1,(_s$model=(s=_this69.rawBody).model)!==null&&_s$model!==void 0?_s$model:s.model="sonar";return _this69;}_inherits(Ed,_k19);return _createClass(Ed,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI26=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee142(e,t){return _regenerator().w(function(_context142){while(1)switch(_context142.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context142.a(2);}},_callee142,this);}));function callServiceAPI(_x265,_x266){return _callServiceAPI26.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee143(e){var t;return _regenerator().w(function(_context143){while(1)switch(_context143.n){case 0:if(!e[f]){_context143.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context143.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context143.n=2;break;}return _context143.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context143.n=3;break;}return _context143.a(2,_defineProperty({},h,t.message.content));case 3:return _context143.a(2,_defineProperty({},h,""));}},_callee143);}));function extractResultData(_x267){return _extractResultData29.apply(this,arguments);}return extractResultData;}()}]);}(k);var vd=function vd(i){return _defineProperty(_defineProperty({},he,"Bearer ".concat(i)),q,te);},Sd=function Sd(i,e,t,n){var s=i;s.detail?n(s.detail):t(e);},xd=function xd(){return be("http://localhost:3000/api/v1/models",ue,Sd);};var Ad=/*#__PURE__*/function(_k20){function Ad(e){var _this70$maxMessages,_o$model0,_a$stream;var _this70;_classCallCheck(this,Ad);var s,r,o,a;var n=C(e.directConnection).openWebUI;_this70=_callSuper(this,Ad,[e,xd(),vd,n]),_this70.insertKeyPlaceholderText="Open WebUI API Key",_this70.keyHelpUrl="https://docs.openwebui.com/getting-started/api-endpoints/",_this70.url="http://localhost:3000/api/chat/completions",_this70.permittedErrorPrefixes=["Error"],_typeof(n)===U&&(_this70.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.openWebUI)==null?void 0:r.function_handler),n[b]&&n[b].length>0&&(_this70.rawBody[b]=n[b])),(_this70$maxMessages=_this70.maxMessages)!==null&&_this70$maxMessages!==void 0?_this70$maxMessages:_this70.maxMessages=-1,(_o$model0=(o=_this70.rawBody).model)!==null&&_o$model0!==void 0?_o$model0:o.model="llama3.2",(_a$stream=(a=_this70.rawBody).stream)!==null&&_a$stream!==void 0?_a$stream:a.stream=!1;return _this70;}_inherits(Ad,_k20);return _createClass(Ad,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:k.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI27=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee144(e,t){var _this$messages5;return _regenerator().w(function(_context144){while(1)switch(_context144.n){case 0:(_this$messages5=this.messages)!==null&&_this$messages5!==void 0?_this$messages5:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context144.a(2);}},_callee144,this);}));function callServiceAPI(_x268,_x269){return _callServiceAPI27.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee145(e,t){var n,s,_s8;return _regenerator().w(function(_context145){while(1)switch(_context145.n){case 0:if(!e[f]){_context145.n=1;break;}throw e[f].message;case 1:if(!e[h]){_context145.n=2;break;}s=e[h].trim();return _context145.a(2,this.processStreamingResponse(s,t));case 2:if(!(e.choices&&(n=e.choices[0])!=null&&n.message)){_context145.n=3;break;}_s8=e.choices[0].message;return _context145.a(2,_s8.tool_calls?this.handleTools({tool_calls:_s8.tool_calls},t):_defineProperty({},h,_s8.content||""));case 3:return _context145.a(2,_defineProperty({},h,""));}},_callee145,this);}));function extractResultData(_x270,_x271){return _extractResultData30.apply(this,arguments);}return extractResultData;}()},{key:"processStreamingResponse",value:function(){var _processStreamingResponse=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee146(e,t){var r,n,s,_iterator4,_step4,o,a,c,l,_t51,_t52;return _regenerator().w(function(_context146){while(1)switch(_context146.p=_context146.n){case 0:n=e.split("\n").filter(function(o){return o.trim()!=="";});s="";_iterator4=_createForOfIteratorHelper(n);_context146.p=1;_iterator4.s();case 2:if((_step4=_iterator4.n()).done){_context146.n=8;break;}o=_step4.value;a=o.trim();if(!(a.startsWith("data: ")&&(a=a.substring(6)),a!=="[DONE]")){_context146.n=7;break;}_context146.p=3;c=JSON.parse(a);if(!(c.choices&&(r=c.choices[0])!=null&&r.delta)){_context146.n=5;break;}l=c.choices[0].delta;if(!l.tool_calls){_context146.n=4;break;}return _context146.a(2,this.handleTools({tool_calls:l.tool_calls},t));case 4:l.content&&(s+=l.content);case 5:_context146.n=7;break;case 6:_context146.p=6;_t51=_context146.v;return _context146.a(3,7);case 7:_context146.n=2;break;case 8:_context146.n=10;break;case 9:_context146.p=9;_t52=_context146.v;_iterator4.e(_t52);case 10:_context146.p=10;_iterator4.f();return _context146.f(10);case 11:return _context146.a(2,_defineProperty({},h,s));}},_callee146,this,[[3,6],[1,9,10,11]]);}));function processStreamingResponse(_x272,_x273){return _processStreamingResponse.apply(this,arguments);}return processStreamingResponse;}()},{key:"handleTools",value:function(){var _handleTools2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee147(e,t){var n,s,_yield$this$callToolF3,r,o;return _regenerator().w(function(_context147){while(1)switch(_context147.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context147.n=1;break;}throw Error(Gt);case 1:n=C(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:a["function"].arguments};});_context147.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF3=_context147.v;r=_yield$this$callToolF3.responses;o=_yield$this$callToolF3.processedResponse;if(!o){_context147.n=3;break;}return _context147.a(2,o);case 3:if(!(n.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},x,gt),"content","")),!r.find(function(_ref177){var a=_ref177.response;return _typeof(a)!==Ee;})&&s.length===r.length)){_context147.n=4;break;}return _context147.a(2,(r.forEach(function(a,c){var d;var l=(d=e.tool_calls)==null?void 0:d[c];n==null||n.messages.push(_defineProperty(_defineProperty(_defineProperty({},x,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(an);case 5:return _context147.a(2);}},_callee147,this);}));function handleTools(_x274,_x275){return _handleTools2.apply(this,arguments);}return handleTools;}()}]);}(k);var wd=function wd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Cd=function Cd(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},Td=function Td(){return be("https://api.deepseek.com/models",ue,Cd);};var Rd=/*#__PURE__*/function(_k21){function Rd(e){var _this71$maxMessages,_s$model2,_r$temperature,_o$max_tokens;var _this71;_classCallCheck(this,Rd);var s,r,o;var n=C(e.directConnection).deepSeek;_this71=_callSuper(this,Rd,[e,Td(),wd,n]),_this71.insertKeyPlaceholderText=_this71.genereteAPIKeyName("DeepSeek"),_this71.keyHelpUrl="https://platform.deepseek.com/api_keys",_this71.url="https://api.deepseek.com/v1/chat/completions",_this71.permittedErrorPrefixes=[it,Te],_typeof(n)===U&&_this71.completeConfig(n),(_this71$maxMessages=_this71.maxMessages)!==null&&_this71$maxMessages!==void 0?_this71$maxMessages:_this71.maxMessages=-1,(_s$model2=(s=_this71.rawBody).model)!==null&&_s$model2!==void 0?_s$model2:s.model="deepseek-chat",(_r$temperature=(r=_this71.rawBody).temperature)!==null&&_r$temperature!==void 0?_r$temperature:r.temperature=1,(_o$max_tokens=(o=_this71.rawBody).max_tokens)!==null&&_o$max_tokens!==void 0?_o$max_tokens:o.max_tokens=4096;return _this71;}_inherits(Rd,_k21);return _createClass(Rd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI28=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee148(e,t){return _regenerator().w(function(_context148){while(1)switch(_context148.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context148.a(2);}},_callee148,this);}));function callServiceAPI(_x276,_x277){return _callServiceAPI28.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee149(e){var t;return _regenerator().w(function(_context149){while(1)switch(_context149.n){case 0:if(!e[f]){_context149.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context149.n=3;break;}t=e.choices[0];if(!(t.delta&&t.delta.content)){_context149.n=2;break;}return _context149.a(2,_defineProperty({},h,t.delta.content));case 2:if(!(t.message&&t.message.content)){_context149.n=3;break;}return _context149.a(2,_defineProperty({},h,t.message.content));case 3:return _context149.a(2,_defineProperty({},h,""));}},_callee149);}));function extractResultData(_x278){return _extractResultData31.apply(this,arguments);}return extractResultData;}()}]);}(k);var Id=function Id(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Md=function Md(i,e,t,n){var r;((r=i.base_resp)==null?void 0:r.status_code)===1004?n(pe):t(e);},kd=function kd(){return be("https://api.minimax.io/v1/files/delete",ye,Md);};var Pd=/*#__PURE__*/function(_k22){function Pd(e){var _this72$maxMessages,_s$model3;var _this72;_classCallCheck(this,Pd);var s;var n=C(e.directConnection).miniMax;_this72=_callSuper(this,Pd,[e,kd(),Id,n]),_this72.insertKeyPlaceholderText=_this72.genereteAPIKeyName("MiniMax"),_this72.keyHelpUrl="https://www.minimaxi.com",_this72.url="https://api.minimax.io/v1/text/chatcompletion_v2",_this72.permittedErrorPrefixes=[it,Te,"insufficient balance"],_typeof(n)===U&&_this72.completeConfig(n),(_this72$maxMessages=_this72.maxMessages)!==null&&_this72$maxMessages!==void 0?_this72$maxMessages:_this72.maxMessages=-1,(_s$model3=(s=_this72.rawBody).model)!==null&&_s$model3!==void 0?_s$model3:s.model="MiniMax-M1";return _this72;}_inherits(Pd,_k22);return _createClass(Pd,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI29=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee150(e,t){return _regenerator().w(function(_context150){while(1)switch(_context150.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context150.a(2);}},_callee150,this);}));function callServiceAPI(_x279,_x280){return _callServiceAPI29.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee151(e){var t,_n10;return _regenerator().w(function(_context151){while(1)switch(_context151.n){case 0:if(!e[f]){_context151.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context151.n=3;break;}_n10=e.choices[0];if(!(_n10.delta&&_n10.delta.content)){_context151.n=2;break;}return _context151.a(2,_defineProperty({},h,_n10.delta.content));case 2:if(!(_n10.message&&_n10.message.content)){_context151.n=3;break;}return _context151.a(2,_defineProperty({},h,_n10.message.content));case 3:if(!(typeof((t=e.base_resp)==null?void 0:t.status_code)=="number"&&e.base_resp.status_code>0)){_context151.n=4;break;}throw e.base_resp.status_msg;case 4:return _context151.a(2,_defineProperty({},h,""));}},_callee151);}));function extractResultData(_x281){return _extractResultData32.apply(this,arguments);}return extractResultData;}()}]);}(k);var Ld=function Ld(i){return _defineProperty(_defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te),"accept",te);},Od=function Od(i,e,t,n){i.detail?n(pe):t(e);},Nd=function Nd(){return be("https://api.mistral.ai/v1/models",ue,Od);};var Er=/*#__PURE__*/function(_k23){function Er(e){var _this73$maxMessages,_o$model1;var _this73;_classCallCheck(this,Er);var s,r,o;var n=C(e.directConnection).mistral;_this73=_callSuper(this,Er,[e,Nd(),Ld,n]),_this73.insertKeyPlaceholderText=_this73.genereteAPIKeyName("Mistral"),_this73.keyHelpUrl="https://console.mistral.ai/api-keys/",_this73.url="https://api.mistral.ai/v1/chat/completions",_this73.permittedErrorPrefixes=[zt],_typeof(n)===U&&_this73.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.mistral)==null?void 0:r.function_handler),(_this73$maxMessages=_this73.maxMessages)!==null&&_this73$maxMessages!==void 0?_this73$maxMessages:_this73.maxMessages=-1,(_o$model1=(o=_this73.rawBody).model)!==null&&_o$model1!==void 0?_o$model1:o.model="mistral-small-latest";return _this73;}_inherits(Er,_k23);return _createClass(Er,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty(_defineProperty({},x,k.getRoleViaAI(r[x])),"content",k.getTextWFilesContent(r,Er.getFileContent));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI30=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee152(e,t){var _this$messages6;return _regenerator().w(function(_context152){while(1)switch(_context152.n){case 0:(_this$messages6=this.messages)!==null&&_this$messages6!==void 0?_this$messages6:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context152.a(2);}},_callee152,this);}));function callServiceAPI(_x282,_x283){return _callServiceAPI30.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee153(e,t){var _n11;return _regenerator().w(function(_context153){while(1)switch(_context153.n){case 0:if(!e.message){_context153.n=1;break;}throw e.message;case 1:if(!e[f]){_context153.n=2;break;}throw e[f].message;case 2:if(!(e.choices&&e.choices.length>0)){_context153.n=4;break;}_n11=e.choices[0];if(!_n11.delta){_context153.n=3;break;}return _context153.a(2,this.extractStreamResult(_n11,t));case 3:if(!_n11.message){_context153.n=4;break;}return _context153.a(2,_n11.message.tool_calls?this.handleToolsGeneric({tool_calls:_n11.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n11.message.content||""));case 4:return _context153.a(2,_defineProperty({},h,""));}},_callee153,this);}));function extractResultData(_x284,_x285){return _extractResultData33.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee154(e,t){var n,s,r;return _regenerator().w(function(_context154){while(1)switch(_context154.n){case 0:n=e.delta,s=e.finish_reason;if(!(s==="tool_calls"&&n!=null&&n.tool_calls)){_context154.n=1;break;}r={tool_calls:n.tool_calls};return _context154.a(2,this.handleToolsGeneric(r,this.functionHandler,this.messages,t));case 1:return _context154.a(2,_defineProperty({},h,(n==null?void 0:n.content)||""));}},_callee154,this);}));function extractStreamResult(_x286,_x287){return _extractStreamResult4.apply(this,arguments);}return extractStreamResult;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){return t[E]===W?_defineProperty(_defineProperty({},E,qe),qe,t[T]||""):_defineProperty(_defineProperty({},E,h),h,"[Unsupported ".concat(se," ").concat(E,": ").concat(t[E],"]"));});}}]);}(k);var vr=/*#__PURE__*/function(_k24){function vr(e){var _this74$maxMessages,_l$model3;var _this74;_classCallCheck(this,vr);var r,o,a,c,l;var t=C(e.directConnection),n=t.groq;_this74=_callSuper(this,vr,[e,ca(),aa,n]),_this74.insertKeyPlaceholderText=_this74.genereteAPIKeyName("Groq"),_this74.keyHelpUrl="https://console.groq.com/keys",_this74.url="https://api.groq.com/openai/v1/chat/completions",_this74.permittedErrorPrefixes=[zt,"property"];var s=(r=t.groq)==null?void 0:r.chat;_typeof(s)===U&&_this74.completeConfig(s,(c=(a=(o=e.directConnection)==null?void 0:o.groq)==null?void 0:a.chat)==null?void 0:c.function_handler),(_this74$maxMessages=_this74.maxMessages)!==null&&_this74$maxMessages!==void 0?_this74$maxMessages:_this74.maxMessages=-1,(_l$model3=(l=_this74.rawBody).model)!==null&&_l$model3!==void 0?_l$model3:l.model="llama-3.3-70b-versatile";return _this74;}_inherits(vr,_k24);return _createClass(vr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:vr.getTextWImagesContent(r)},x,r[x]===ne?gt:r[x]);});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI31=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee155(e,t){var _this$messages7;return _regenerator().w(function(_context155){while(1)switch(_context155.n){case 0:(_this$messages7=this.messages)!==null&&_this$messages7!==void 0?_this$messages7:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context155.a(2);}},_callee155,this);}));function callServiceAPI(_x288,_x289){return _callServiceAPI31.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee156(e,t){var n,s,r,o;return _regenerator().w(function(_context156){while(1)switch(_context156.n){case 0:if(!e[f]){_context156.n=1;break;}throw e[f].message;case 1:return _context156.a(2,(s=(n=e.choices)==null?void 0:n[0])!=null&&s.delta?this.extractStreamResult(e.choices[0],t):(o=(r=e.choices)==null?void 0:r[0])!=null&&o.message?e.choices[0].message.tool_calls?this.handleToolsGeneric(e.choices[0].message,this.functionHandler,this.messages,t,{message:this.systemMessage}):_defineProperty({},h,e.choices[0].message.content||""):_defineProperty({},h,""));}},_callee156,this);}));function extractResultData(_x290,_x291){return _extractResultData34.apply(this,arguments);}return extractResultData;}()// https://console.groq.com/docs/tool-use
196
+ },{key:"extractStreamResult",value:function(){var _extractStreamResult5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee157(e,t){return _regenerator().w(function(_context157){while(1)switch(_context157.n){case 0:return _context157.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee157,this);}));function extractStreamResult(_x292,_x293){return _extractStreamResult5.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var Bd=function Bd(i){return _defineProperty(_defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te),"accept",te);},Dd=function Dd(i,e,t,n){_typeof(i.message)===Ee?n(pe):t(e);},Fd=function Fd(){return be("https://api.cohere.ai/v1/models",ue,Dd);};var ci=/*#__PURE__*/function(_k25){function ci(e){var _this75$maxMessages,_s$model4;var _this75;_classCallCheck(this,ci);var s;var n=C(e.directConnection).cohere;if(_this75=_callSuper(this,ci,[e,Fd(),Bd,n]),_this75.insertKeyPlaceholderText=_this75.genereteAPIKeyName("Cohere"),_this75.keyHelpUrl="https://dashboard.cohere.ai/api-keys",_this75.permittedErrorPrefixes=["invalid"],_this75.url="https://api.cohere.com/v2/chat",_typeof(n)===U){var r=le.processCohere(n);_this75.canSendMessage=function(){return r;},_this75.cleanConfig(n),Object.assign(_this75.rawBody,n);}(_this75$maxMessages=_this75.maxMessages)!==null&&_this75$maxMessages!==void 0?_this75$maxMessages:_this75.maxMessages=-1,(_s$model4=(s=_this75.rawBody).model)!==null&&_s$model4!==void 0?_s$model4:s.model="command-a-03-2025";return _this75;}_inherits(ci,_k25);return _createClass(ci,[{key:"cleanConfig",value:function cleanConfig(e){delete e.key;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=t.filter(function(r){return r[h];});return n.messages=s.map(function(r){return _defineProperty(_defineProperty({},x,k.getRoleViaAI(r[x])),"content",r[h]);}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI32=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee158(e,t){return _regenerator().w(function(_context158){while(1)switch(_context158.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context158.a(2);}},_callee158,this);}));function callServiceAPI(_x294,_x295){return _callServiceAPI32.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee159(e){var t,n,s,r;return _regenerator().w(function(_context159){while(1)switch(_context159.n){case 0:if(!(typeof e.message=="string")){_context159.n=1;break;}throw e.message;case 1:if(!(this.stream&&e[h])){_context159.n=2;break;}r=ci.parseBundledEvents(e[h]);return _context159.a(2,{text:ci.aggregateBundledEventsText(r)});case 2:if(!("message"in e&&(s=(n=(t=e.message)==null?void 0:t.content)==null?void 0:n[0])!=null&&s[h])){_context159.n=3;break;}return _context159.a(2,_defineProperty({},h,e.message.content[0][h]));case 3:throw new Error("Invalid response format from Cohere API");case 4:return _context159.a(2);}},_callee159,this);}));function extractResultData(_x296){return _extractResultData35.apply(this,arguments);}return extractResultData;}()}],[{key:"parseBundledEvents",value:function parseBundledEvents(e){var t=e.trim().split("\n"),n=[];var _iterator5=_createForOfIteratorHelper(t),_step5;try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var s=_step5.value;if(s.trim())try{var r=JSON.parse(s);n.push(r);}catch(r){console[f]("Failed to parse line:",s,r);}}}catch(err){_iterator5.e(err);}finally{_iterator5.f();}return n;}},{key:"aggregateBundledEventsText",value:function aggregateBundledEventsText(e){return e.filter(function(t){var n,s,r;return t[E]==="content-delta"&&((r=(s=(n=t.delta)==null?void 0:n.message)==null?void 0:s.content)==null?void 0:r[h]);}).map(function(t){var n,s,r;return(r=(s=(n=t.delta)==null?void 0:n.message)==null?void 0:s.content)==null?void 0:r[h];}).join("");}}]);}(k);var Ud=function Ud(){return _defineProperty({},q,te);},Hd=function Hd(i,e,t,n){var r;var s=i;s[f]?s[f].code===403||(r=s[f].message)!=null&&r.includes("API key")?n(pe):n(Ue):t(e);},jd=function jd(){var i="https://generativelanguage.googleapis.com/v1beta/models?key=";return be(i,ue,Hd,function(e){return"".concat(i).concat(e);});};var Sr=/*#__PURE__*/function(_k26){function Sr(e){var _this76$maxMessages;var _this76;_classCallCheck(this,Sr);var s,r;var n=C(e.directConnection).gemini;if(_this76=_callSuper(this,Sr,[e,jd(),Ud,n]),_this76.insertKeyPlaceholderText=_this76.genereteAPIKeyName("Gemini"),_this76.keyHelpUrl="https://aistudio.google.com/app/apikey",_this76.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",_this76.url="",_this76.permittedErrorPrefixes=["API_KEY_INVALID"],_typeof(n)===U){var o=n;o.model&&(_this76.urlPrefix="https://generativelanguage.googleapis.com/v1beta/models/".concat(o.model,":generateContent")),_this76.cleanConfig(o),_this76.completeConfig(o,(r=(s=e.directConnection)==null?void 0:s.gemini)==null?void 0:r.function_handler);}(_this76$maxMessages=_this76.maxMessages)!==null&&_this76$maxMessages!==void 0?_this76$maxMessages:_this76.maxMessages=-1;return _this76;}_inherits(Sr,_k26);return _createClass(Sr,[{key:"cleanConfig",value:function cleanConfig(e){delete e.model;}},{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return Sr.getContent(r);});return n.contents=s,this.systemMessage&&(n.systemInstruction={parts:[_defineProperty({},h,this.systemMessage)]}),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI33=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee160(e,t){var _this$messages8;var n,s;return _regenerator().w(function(_context160){while(1)switch(_context160.n){case 0:if(this.connectSettings){_context160.n=1;break;}throw new Error(He);case 1:(_this$messages8=this.messages)!==null&&_this$messages8!==void 0?_this$messages8:this.messages=e;n=this.preprocessBody(this.rawBody,t),s=this.stream;s&&(_typeof(s)!==U||!s.simulation)||n.stream?(this.url="".concat(this.urlPrefix.replace(":generateContent",":streamGenerateContent"),"?alt=sse&key=").concat(this.key),V.request(this,n,e)):(this.url="".concat(this.urlPrefix,"?key=").concat(this.key),ge.request(this,n,e));case 2:return _context160.a(2);}},_callee160,this);}));function callServiceAPI(_x297,_x298){return _callServiceAPI33.apply(this,arguments);}return callServiceAPI;}()// https://ai.google.dev/gemini-api/docs/function-calling?example=weather
197
+ },{key:"extractResultData",value:function(){var _extractResultData36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee161(e,t){var n,s,r,o,a,c,l,d;return _regenerator().w(function(_context161){while(1)switch(_context161.n){case 0:if(!e[f]){_context161.n=1;break;}throw e[f].message||"Gemini API Error";case 1:if(!((r=(s=(n=e.candidates)==null?void 0:n[0])==null?void 0:s.content)!=null&&r.parts)){_context161.n=3;break;}a=e.candidates[0].content.parts,c=a.find(function(p){return p.functionCall;});if(!(c!=null&&c.functionCall)){_context161.n=2;break;}return _context161.a(2,this.handleTools([c.functionCall],t));case 2:l=a.find(function(p){return p[h];}),d=a.find(function(p){var u;return((u=p.inlineData)==null?void 0:u.mimeType)==="image/png";});return _context161.a(2,_defineProperty(_defineProperty({},h,(l==null?void 0:l[h])||""),b,(o=d==null?void 0:d.inlineData)!=null&&o.data?[_defineProperty({},T,"data:image/png;base64,".concat(d.inlineData.data))]:[]));case 3:return _context161.a(2,_defineProperty({},h,""));}},_callee161,this);}));function extractResultData(_x299,_x300){return _extractResultData36.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools3=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee162(e,t){var n,s,_yield$this$callToolF4,r,o,a,c;return _regenerator().w(function(_context162){while(1)switch(_context162.n){case 0:if(!(!e||!t||!this.functionHandler)){_context162.n=1;break;}throw Error(Gt);case 1:n=C(t);s=e.map(function(c){return{name:c.name,arguments:ce(c.args)};});_context162.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF4=_context162.v;r=_yield$this$callToolF4.responses;o=_yield$this$callToolF4.processedResponse;if(!o){_context162.n=3;break;}return _context162.a(2,o);case 3:a=_defineProperty({parts:e.map(function(c){return{functionCall:{name:c.name,args:c.args}};})},x,"model");if(!(n.contents.push(a),!r.find(function(_ref206){var c=_ref206.response;return _typeof(c)!==Ee;})&&s.length===r.length)){_context162.n=4;break;}c=_defineProperty({parts:r.map(function(l,d){return{functionResponse:{name:e[d].name,response:{result:l.response}}};})},x,F);return _context162.a(2,(n.contents.push(c),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(an);case 5:return _context162.a(2);}},_callee162,this);}));function handleTools(_x301,_x302){return _handleTools3.apply(this,arguments);}return handleTools;}()}],[{key:"getContent",value:function getContent(e){var t=[];return e[h]&&e[h].trim().length>0&&t.push(_defineProperty({},h,e[h])),e[b]&&e[b].length>0&&e[b].forEach(function(n){if(n[T]&&n[T].includes("data:")){var _n$T$split=n[T].split(","),_n$T$split2=_slicedToArray(_n$T$split,2),s=_n$T$split2[0],r=_n$T$split2[1];t.push({inlineData:{mimeType:s.replace("data:","").replace(";base64",""),data:r}});}}),_defineProperty({parts:t},x,e[x]===F?F:"model");}}]);}(k);var $d=function $d(i){return _defineProperty(_defineProperty(_defineProperty({"x-api-key":i},q,te),"anthropic-version","2023-06-01"),"anthropic-dangerous-direct-browser-access","true");},qd=function qd(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},Gd=function Gd(){return be("https://api.anthropic.com/v1/models",ue,qd);};var li=/*#__PURE__*/function(_k27){function li(e){var _this77$maxMessages,_o$model10,_a$max_tokens2;var _this77;_classCallCheck(this,li);var s,r,o,a;var n=C(e.directConnection).claude;_this77=_callSuper(this,li,[e,Gd(),$d,n]),_this77.insertKeyPlaceholderText=_this77.genereteAPIKeyName("Claude"),_this77.keyHelpUrl="https://console.anthropic.com/settings/keys",_this77.url="https://api.anthropic.com/v1/messages",_this77.permittedErrorPrefixes=[Te,it],_this77._streamToolCalls=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},E,"tool_use"),"id",""),"name",""),"input",""),_typeof(n)===U&&_this77.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.claude)==null?void 0:r.function_handler),(_this77$maxMessages=_this77.maxMessages)!==null&&_this77$maxMessages!==void 0?_this77$maxMessages:_this77.maxMessages=-1,(_o$model10=(o=_this77.rawBody).model)!==null&&_o$model10!==void 0?_o$model10:o.model="claude-sonnet-4-5-20250929",(_a$max_tokens2=(a=_this77.rawBody).max_tokens)!==null&&_a$max_tokens2!==void 0?_a$max_tokens2:a.max_tokens=4096;return _this77;}_inherits(li,_k27);return _createClass(li,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:li.getTextWFilesContent(r,li.getFileContent)},x,k.getRoleViaUser(r[x]));});return n.messages=s,this.systemMessage&&(n.system=this.systemMessage),n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI34=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee163(e,t){var _this$messages9;return _regenerator().w(function(_context163){while(1)switch(_context163.n){case 0:(_this$messages9=this.messages)!==null&&_this$messages9!==void 0?_this$messages9:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context163.a(2);}},_callee163,this);}));function callServiceAPI(_x303,_x304){return _callServiceAPI34.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee164(e,t){var n,s,r,o,a;return _regenerator().w(function(_context164){while(1)switch(_context164.n){case 0:if(!e[f]){_context164.n=1;break;}throw e[f].message;case 1:if(!(e.content&&e.content.length>0)){_context164.n=3;break;}o=e.content.find(function(c){return c[E]==="tool_use";});if(!o){_context164.n=2;break;}return _context164.a(2,this.handleTools([o],t));case 2:a=e.content.find(function(c){return c[E]===h;});if(!a){_context164.n=3;break;}return _context164.a(2,_defineProperty({},h,a[h]));case 3:if(!(e[E]==="content_block_delta"&&e.delta&&e.delta[E]==="text_delta")){_context164.n=4;break;}return _context164.a(2,_defineProperty({},h,e.delta[h]||""));case 4:if(!(e[E]==="content_block_start"&&((n=e.content_block)==null?void 0:n[E])==="tool_use")){_context164.n=5;break;}this._streamToolCalls=e.content_block,this._streamToolCalls.input="";_context164.n=7;break;case 5:if(!(e[E]==="content_block_delta"&&((s=e.delta)==null?void 0:s[E])==="input_json_delta")){_context164.n=6;break;}this._streamToolCalls.input+=e.delta.partial_json||"";_context164.n=7;break;case 6:if(!(e[E]==="message_delta"&&((r=e.delta)==null?void 0:r.stop_reason)==="tool_use")){_context164.n=7;break;}return _context164.a(2,(this._streamToolCalls.input=this._streamToolCalls.input?JSON.parse(this._streamToolCalls.input):{},this.handleTools([this._streamToolCalls],t)));case 7:return _context164.a(2,_defineProperty({},h,""));}},_callee164,this);}));function extractResultData(_x305,_x306){return _extractResultData37.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools4=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee165(e,t){var n,s,_yield$this$callToolF5,r,o,a,c;return _regenerator().w(function(_context165){while(1)switch(_context165.n){case 0:if(!(!e||!t||!this.functionHandler)){_context165.n=1;break;}throw Error(Gt);case 1:n=C(t);s=e.map(function(c){return{name:c.name,arguments:ce(c.input)};});_context165.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF5=_context165.v;r=_yield$this$callToolF5.responses;o=_yield$this$callToolF5.processedResponse;if(!o){_context165.n=3;break;}return _context165.a(2,o);case 3:a=e.map(function(c){return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},E,"tool_use"),"id",c.id),"name",c.name),"input",c.input);});if(!(n.messages.push(_defineProperty(_defineProperty({},x,"assistant"),"content",a)),!r.find(function(_ref214){var c=_ref214.response;return _typeof(c)!==Ee;})&&s.length===r.length)){_context165.n=4;break;}c=r.map(function(l,d){return _defineProperty(_defineProperty(_defineProperty({},E,"tool_result"),"tool_use_id",e[d].id),"content",l.response);});return _context165.a(2,(n.messages.push(_defineProperty(_defineProperty({},x,F),"content",c)),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(an);case 5:return _context165.a(2);}},_callee165,this);}));function handleTools(_x307,_x308){return _handleTools4.apply(this,arguments);}return handleTools;}()}],[{key:"getFileContent",value:function getFileContent(e){return e.map(function(t){var n,s,r;if(t[E]===W){var o=(n=t[T])==null?void 0:n.split(",")[1],a=((r=(s=t[T])==null?void 0:s.match(/data:([^;]+)/))==null?void 0:r[1])||"image/jpeg";return _defineProperty(_defineProperty({},E,W),"source",_defineProperty(_defineProperty(_defineProperty({},E,"base64"),"media_type",a),"data",o||""));}return _defineProperty(_defineProperty({},E,h),h,"[Unsupported ".concat(se," ").concat(E,": ").concat(t[E],"]"));});}}]);}(k);var zd=function zd(){return{};},Vd=function Vd(){},Kd=function Kd(){return be("",ue,Vd);},vs=/*#__PURE__*/function(_k28){function vs(e){var _this78$maxMessages,_o$model11,_a$stream2;var _this78;_classCallCheck(this,vs);var s,r,o,a;var t=C(e.directConnection);_this78=_callSuper(this,vs,[e,Kd(),zd,{key:"placeholder"}]),_this78.insertKeyPlaceholderText="",_this78.keyHelpUrl="",_this78.validateKeyProperty=!1,_this78.url="http://localhost:11434/api/chat",_this78.permittedErrorPrefixes=["Error"];var n=t.ollama;_typeof(n)===U&&_this78.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.ollama)==null?void 0:r.function_handler),(_this78$maxMessages=_this78.maxMessages)!==null&&_this78$maxMessages!==void 0?_this78$maxMessages:_this78.maxMessages=-1,(_o$model11=(o=_this78.rawBody).model)!==null&&_o$model11!==void 0?_o$model11:o.model="llama3.2",(_a$stream2=(a=_this78.rawBody).stream)!==null&&_a$stream2!==void 0?_a$stream2:a.stream=!1;return _this78;}_inherits(vs,_k28);return _createClass(vs,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){var o=_defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));if(r[b]&&r[b].length>0){var a=vs.getImageData(r[b]);a.length>0&&(o[ee]=a);}return o;});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI35=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee166(e,t){var _this$messages0;return _regenerator().w(function(_context166){while(1)switch(_context166.n){case 0:(_this$messages0=this.messages)!==null&&_this$messages0!==void 0?_this$messages0:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{readable:!0});case 1:return _context166.a(2);}},_callee166,this);}));function callServiceAPI(_x309,_x310){return _callServiceAPI35.apply(this,arguments);}return callServiceAPI;}()},{key:"parseMessage",value:function parseMessage(e){return e.split("\n").filter(function(t){return t.trim();}).map(function(t){return JSON.parse(t);});}},{key:"extractResultData",value:function(){var _extractResultData38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee167(e,t){var n,s,r,o,_iterator6,_step6,l,a,c,_t53,_t54,_t55;return _regenerator().w(function(_context167){while(1)switch(_context167.p=_context167.n){case 0:if(!e[f]){_context167.n=1;break;}throw e[f].message;case 1:if(!e[h]){_context167.n=11;break;}r=this.parseMessage(e[h]),o=[];_iterator6=_createForOfIteratorHelper(r);_context167.p=2;_iterator6.s();case 3:if((_step6=_iterator6.n()).done){_context167.n=7;break;}l=_step6.value;_t53=(n=l.message)!=null&&n.tool_calls;if(!_t53){_context167.n=5;break;}_t54=o;_context167.n=4;return this.handleTools({tool_calls:l.message.tool_calls},t);case 4:_t54.push.call(_t54,_context167.v);case 5:o.push(_defineProperty({},h,((s=l.message)==null?void 0:s.content)||""));case 6:_context167.n=3;break;case 7:_context167.n=9;break;case 8:_context167.p=8;_t55=_context167.v;_iterator6.e(_t55);case 9:_context167.p=9;_iterator6.f();return _context167.f(9);case 10:a=o.map(function(l){return l[h];}),c=a.lastIndexOf(vs.THINK_END);return _context167.a(2,c===-1||t!=null&&t.think?_defineProperty({},h,a.join("")):_defineProperty(_defineProperty({},h,a.slice(c+1).join("")),"overwrite",!0));case 11:return _context167.a(2,e.message?e.message.tool_calls?this.handleTools({tool_calls:e.message.tool_calls},t):_defineProperty({},h,e.message.content||""):_defineProperty({},h,""));}},_callee167,this,[[2,8,9,10]]);}));function extractResultData(_x311,_x312){return _extractResultData38.apply(this,arguments);}return extractResultData;}()},{key:"handleTools",value:function(){var _handleTools5=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee168(e,t){var n,s,_yield$this$callToolF6,r,o;return _regenerator().w(function(_context168){while(1)switch(_context168.n){case 0:if(!(!e.tool_calls||!t||!this.functionHandler)){_context168.n=1;break;}throw Error(Gt);case 1:n=C(t);s=e.tool_calls.map(function(a){return{name:a["function"].name,arguments:ce(a["function"].arguments)};});_context168.n=2;return this.callToolFunction(this.functionHandler,s);case 2:_yield$this$callToolF6=_context168.v;r=_yield$this$callToolF6.responses;o=_yield$this$callToolF6.processedResponse;if(!o){_context168.n=3;break;}return _context168.a(2,o);case 3:if(!(n.messages.push(_defineProperty(_defineProperty({tool_calls:e.tool_calls},x,gt),"content","")),!r.find(function(_ref222){var a=_ref222.response;return _typeof(a)!==Ee;})&&s.length===r.length)){_context168.n=4;break;}return _context168.a(2,(r.forEach(function(a,c){var d;var l=(d=e.tool_calls)==null?void 0:d[c];n==null||n.messages.push(_defineProperty(_defineProperty(_defineProperty({},x,"tool"),"tool_name",l==null?void 0:l["function"].name),"content",a.response));}),this.makeAnotherRequest(n,this.messages)));case 4:throw Error(an);case 5:return _context168.a(2);}},_callee168,this);}));function handleTools(_x313,_x314){return _handleTools5.apply(this,arguments);}return handleTools;}()}],[{key:"getImageData",value:function getImageData(e){return e.filter(function(t){return t[E]===W;}).map(function(t){var s;return((s=t[T])==null?void 0:s.split(",")[1])||"";}).filter(function(t){return t.length>0;});}}]);}(k);vs.THINK_END="</think>";var tr=vs;var la=function la(i){return _defineProperty({Authorization:"".concat(Ce).concat(i)},q,te);},Wd=function Wd(i,e,t,n){var s=i;s[f]?s[f][E]===Te||s[f][E]===it?n(pe):n(Ue):t(e);},da=function da(){return be("https://api.x.ai/v1/models",ue,Wd);},gi=/*#__PURE__*/function(_k29){function gi(e){var _o$model12;var _this79;_classCallCheck(this,gi);var r,o;var t=e.directConnection,n=t==null?void 0:t.x;_this79=_callSuper(this,gi,[e,da(),la,n]),_this79.insertKeyPlaceholderText=_this79.genereteAPIKeyName("X"),_this79.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this79.url=gi.IMAGE_GENERATION_URL,_this79.permittedErrorPrefixes=[it,Te];var s=(r=t==null?void 0:t.x)==null?void 0:r[ee];_typeof(s)===U&&Object.assign(_this79.rawBody,s),(_o$model12=(o=_this79.rawBody).model)!==null&&_o$model12!==void 0?_o$model12:o.model="grok-2-image";return _this79;}_inherits(gi,_k29);return _createClass(gi,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=t[t.length-1][h],s=C(e);return n&&n!==""&&(s.prompt=n),s;}},{key:"callServiceAPI",value:function(){var _callServiceAPI36=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee169(e,t){return _regenerator().w(function(_context169){while(1)switch(_context169.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this));case 1:return _context169.a(2);}},_callee169,this);}));function callServiceAPI(_x315,_x316){return _callServiceAPI36.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee170(e){var t;return _regenerator().w(function(_context170){while(1)switch(_context170.n){case 0:if(!e[f]){_context170.n=1;break;}throw e[f].message;case 1:t=e.data.map(function(n){return n.url?_defineProperty(_defineProperty({},T,n.url),E,W):_defineProperty(_defineProperty({},T,"".concat(On).concat(n.b64_json)),E,W);});return _context170.a(2,_defineProperty({},b,t));}},_callee170);}));function extractResultData(_x317){return _extractResultData39.apply(this,arguments);}return extractResultData;}()}]);}(k);gi.IMAGE_GENERATION_URL="https://api.x.ai/v1/images/generations";var nr=gi;var Xd=function Xd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Zd=function Zd(i,e,t,n){var s=i;s[f]?s[f][E]===it?n(pe):n(Ue):t(e);},Yd=function Yd(){return be("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models",ue,Zd);};var xr=/*#__PURE__*/function(_k30){function xr(e){var _this80$maxMessages,_o$model13;var _this80;_classCallCheck(this,xr);var s,r,o;var n=C(e.directConnection).qwen;_this80=_callSuper(this,xr,[e,Yd(),Xd,n]),_this80.insertKeyPlaceholderText=_this80.genereteAPIKeyName("Qwen"),_this80.keyHelpUrl="https://www.alibabacloud.com/help/en/model-studio/get-api-key",_this80.url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",_this80.permittedErrorPrefixes=["No static","The model",Ps],_typeof(n)===U&&_this80.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.qwen)==null?void 0:r.function_handler),(_this80$maxMessages=_this80.maxMessages)!==null&&_this80$maxMessages!==void 0?_this80$maxMessages:_this80.maxMessages=-1,(_o$model13=(o=_this80.rawBody).model)!==null&&_o$model13!==void 0?_o$model13:o.model="qwen-plus";return _this80;}_inherits(xr,_k30);return _createClass(xr,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:xr.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI37=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee171(e,t){var _this$messages1;return _regenerator().w(function(_context171){while(1)switch(_context171.n){case 0:(_this$messages1=this.messages)!==null&&_this$messages1!==void 0?_this$messages1:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context171.a(2);}},_callee171,this);}));function callServiceAPI(_x318,_x319){return _callServiceAPI37.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee172(e,t){var _n12;return _regenerator().w(function(_context172){while(1)switch(_context172.n){case 0:if(!e[f]){_context172.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context172.n=3;break;}_n12=e.choices[0];if(!_n12.delta){_context172.n=2;break;}return _context172.a(2,this.extractStreamResult(_n12,t));case 2:if(!_n12.message){_context172.n=3;break;}return _context172.a(2,_n12.message.tool_calls?this.handleToolsGeneric({tool_calls:_n12.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n12.message.content||""));case 3:return _context172.a(2,_defineProperty({},h,""));}},_callee172,this);}));function extractResultData(_x320,_x321){return _extractResultData40.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult6=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee173(e,t){return _regenerator().w(function(_context173){while(1)switch(_context173.n){case 0:return _context173.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee173,this);}));function extractStreamResult(_x322,_x323){return _extractStreamResult6.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var Jd=function Jd(i){return _defineProperty(_defineProperty({},he,"".concat(Ce).concat(i)),q,te);},Qd=function Qd(i,e,t,n){var s=i;s[f]?s[f][E]===Te?n(pe):n(Ue):t(e);},eh=function eh(){return be("https://api.moonshot.ai/v1/models",ue,Qd);};var Ar=/*#__PURE__*/function(_k31){function Ar(e){var _this81$maxMessages,_o$model14;var _this81;_classCallCheck(this,Ar);var s,r,o;var n=C(e.directConnection).kimi;_this81=_callSuper(this,Ar,[e,eh(),Jd,n]),_this81.insertKeyPlaceholderText=_this81.genereteAPIKeyName("Kimi"),_this81.keyHelpUrl="https://platform.moonshot.ai/console/api-keys",_this81.url="https://api.moonshot.ai/v1/chat/completions",_this81.permittedErrorPrefixes=[zt,"Not found"],_typeof(n)===U&&_this81.completeConfig(n,(r=(s=e.directConnection)==null?void 0:s.kimi)==null?void 0:r.function_handler),(_this81$maxMessages=_this81.maxMessages)!==null&&_this81$maxMessages!==void 0?_this81$maxMessages:_this81.maxMessages=-1,(_o$model14=(o=_this81.rawBody).model)!==null&&_o$model14!==void 0?_o$model14:o.model="moonshot-v1-8k";return _this81;}_inherits(Ar,_k31);return _createClass(Ar,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:Ar.getTextWImagesContent(r)},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI38=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee174(e,t){var _this$messages10;return _regenerator().w(function(_context174){while(1)switch(_context174.n){case 0:(_this$messages10=this.messages)!==null&&_this$messages10!==void 0?_this$messages10:this.messages=e,this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context174.a(2);}},_callee174,this);}));function callServiceAPI(_x324,_x325){return _callServiceAPI38.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData41=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee175(e,t){var _n13;return _regenerator().w(function(_context175){while(1)switch(_context175.n){case 0:if(!e[f]){_context175.n=1;break;}throw e[f].message;case 1:if(!(e.choices&&e.choices.length>0)){_context175.n=3;break;}_n13=e.choices[0];if(!_n13.delta){_context175.n=2;break;}return _context175.a(2,this.extractStreamResult(_n13,t));case 2:if(!_n13.message){_context175.n=3;break;}return _context175.a(2,_n13.message.tool_calls?this.handleToolsGeneric({tool_calls:_n13.message.tool_calls},this.functionHandler,this.messages,t):_defineProperty({},h,_n13.message.content||""));case 3:return _context175.a(2,_defineProperty({},h,""));}},_callee175,this);}));function extractResultData(_x326,_x327){return _extractResultData41.apply(this,arguments);}return extractResultData;}()},{key:"extractStreamResult",value:function(){var _extractStreamResult7=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee176(e,t){return _regenerator().w(function(_context176){while(1)switch(_context176.n){case 0:return _context176.a(2,this.extractStreamResultWToolsGeneric(this,e,this.functionHandler,t));}},_callee176,this);}));function extractStreamResult(_x328,_x329){return _extractStreamResult7.apply(this,arguments);}return extractStreamResult;}()}]);}(k);var th=/*#__PURE__*/function(_k32){function th(e){var _this82$maxMessages,_o$model15;var _this82;_classCallCheck(this,th);var r,o;var t=C(e.directConnection),n=t.x;_this82=_callSuper(this,th,[e,da(),la,n]),_this82.insertKeyPlaceholderText=_this82.genereteAPIKeyName("X"),_this82.keyHelpUrl="https://console.x.ai/team/default/api-keys",_this82.url="https://api.x.ai/v1/chat/completions",_this82.permittedErrorPrefixes=[it,Te];var s=(r=t.x)==null?void 0:r.chat;_typeof(s)===U&&_this82.completeConfig(s),(_this82$maxMessages=_this82.maxMessages)!==null&&_this82$maxMessages!==void 0?_this82$maxMessages:_this82.maxMessages=-1,(_o$model15=(o=_this82.rawBody).model)!==null&&_o$model15!==void 0?_o$model15:o.model="grok-3-latest";return _this82;}_inherits(th,_k32);return _createClass(th,[{key:"preprocessBody",value:function preprocessBody(e,t){var n=C(e),s=this.processMessages(t).map(function(r){return _defineProperty({content:r[h]||""},x,k.getRoleViaUser(r[x]));});return this.addSystemMessage(s),n.messages=s,n;}},{key:"callServiceAPI",value:function(){var _callServiceAPI39=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee177(e,t){return _regenerator().w(function(_context177){while(1)switch(_context177.n){case 0:this.callDirectServiceServiceAPI(e,t,this.preprocessBody.bind(this),{});case 1:return _context177.a(2);}},_callee177,this);}));function callServiceAPI(_x330,_x331){return _callServiceAPI39.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData42=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee178(e){var t,n,s,r,o;return _regenerator().w(function(_context178){while(1)switch(_context178.n){case 0:if(!e[f]){_context178.n=1;break;}throw e[f].message;case 1:if(!(e.object==="chat.completion.chunk")){_context178.n=2;break;}o=(t=e.choices)==null?void 0:t[0];return _context178.a(2,(n=o==null?void 0:o.delta)!=null&&n.content?_defineProperty({},h,o.delta.content):_defineProperty({},h,""));case 2:return _context178.a(2,e.object==="chat.completion"&&(r=(s=e.choices)==null?void 0:s[0])!=null&&r.message?_defineProperty({},h,e.choices[0].message.content||""):_defineProperty({},h,""));}},_callee178);}));function extractResultData(_x332){return _extractResultData42.apply(this,arguments);}return extractResultData;}()}]);}(k);var qs=/* @__PURE__ */function(i){return i.BLOCKING="blocking",i.STREAMING="streaming",i;}(qs||{}),_n=/* @__PURE__ */function(i){return i.MESSAGE="message",i.AGENT_MESSAGE="agent_message",i.WORKFLOW_FINISHED="workflow_finished",i.ERROR="error",i;}(_n||{});var nh="image/",sh="data:",ih=function ih(i,e){return{type:e,transfer_method:"local_file",upload_file_id:i};},rh=function rh(i){var e=i.trim();if(!e.startsWith(sh))return null;var t=e.replace(/^data:\s*/,"").trim();return t?JSON.parse(t):null;};function oh(_x333,_x334){return _oh.apply(this,arguments);}function _oh(){_oh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee197(i,e){var t,_e$headers,n,s,r,a,o;return _regenerator().w(function(_context197){while(1)switch(_context197.n){case 0:t=new FormData();t.append(se,i),t.append(F,e[F]);_e$headers=e.headers;n=_e$headers[q];s=_objectWithoutProperties(_e$headers,[q].map(_toPropertyKey));_context197.n=1;return fetch(e.url,{method:ye,headers:s,body:t});case 1:r=_context197.v;if(r.ok){_context197.n=3;break;}_context197.n=2;return r.text();case 2:a=_context197.v;throw new Error(a);case 3:_context197.n=4;return r.json();case 4:o=_context197.v;if(o.id){_context197.n=5;break;}throw new Error("Upload response missing file ID");case 5:return _context197.a(2,o.id);}},_callee197);}));return _oh.apply(this,arguments);}function ah(_x335,_x336){return _ah.apply(this,arguments);}function _ah(){_ah=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee199(i,e){var t;return _regenerator().w(function(_context199){while(1)switch(_context199.n){case 0:if(!(i.length===0)){_context199.n=1;break;}return _context199.a(2,[]);case 1:t=i.map(/*#__PURE__*/function(){var _ref270=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee198(s){var r,o;return _regenerator().w(function(_context198){while(1)switch(_context198.n){case 0:_context198.n=1;return oh(s,e);case 1:r=_context198.v;o=s[E].startsWith(nh)?W:se;return _context198.a(2,ih(r,o));}},_callee198);}));return function(_x367){return _ref270.apply(this,arguments);};}());_context199.n=2;return Promise.all(t);case 2:return _context199.a(2,_context199.v.filter(function(s){return s!==null;}));}},_callee199);}));return _ah.apply(this,arguments);}function ch(i,e){return i.conversation_id&&e(i.conversation_id),i.code&&i.message&&!i.answer?_defineProperty({},f,i.message):_defineProperty({},h,i.answer||"");}var lh=function lh(i,e,t){var n,s;switch(!e.conversationIdSet&&i.conversation_id&&(t(i.conversation_id),e.conversationIdSet=!0),i.event){case _n.MESSAGE:case _n.AGENT_MESSAGE:e.fullAnswer+=i.answer||"";break;case _n.WORKFLOW_FINISHED:!e.fullAnswer&&(s=(n=i.data)==null?void 0:n.outputs)!=null&&s.answer&&(e.fullAnswer=i.data.outputs.answer);break;case _n.ERROR:e.errorMessage=i.message||_n.ERROR;break;}};function dh(_x337,_x338){return _dh.apply(this,arguments);}function _dh(){_dh=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee200(i,e){var t,s,_iterator7,_step7,r,o;return _regenerator().w(function(_context200){while(1)switch(_context200.n){case 0:t={fullAnswer:"",conversationIdSet:!1,errorMessage:""};_context200.n=1;return i.text();case 1:s=_context200.v.split(/\r?\n\r?\n/);_iterator7=_createForOfIteratorHelper(s);try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){r=_step7.value;o=rh(r);o&&lh(o,t,e);}}catch(err){_iterator7.e(err);}finally{_iterator7.f();}return _context200.a(2,t.errorMessage?_defineProperty({},f,t.errorMessage):_defineProperty({},h,t.fullAnswer));}},_callee200);}));return _dh.apply(this,arguments);}var hh=function hh(i){return _defineProperty(_defineProperty({},q,te),he,"".concat(Ce).concat(i));},uh=function uh(i,e,t,n){var s=i;s[f]?s[f].message===yi?n(pe):n(Ue):"user_input_form"in i||"opening_statement"in i||"file_upload"in i?t(e):n(Ue);},ph=function ph(i){return be("".concat(i,"/parameters"),ue,uh);};var fh=/*#__PURE__*/function(_k33){function fh(e){var _ref243,_this83$maxMessages;var _this83;_classCallCheck(this,fh);var r;var t=C(e.directConnection),n=t==null?void 0:t.dify,s=(_ref243=(r=e.connect)==null?void 0:r.url)!==null&&_ref243!==void 0?_ref243:"https://api.dify.ai/v1";_this83=_callSuper(this,fh,[e,ph(s),hh,n]),_this83.insertKeyPlaceholderText=_this83.genereteAPIKeyName("Dify"),_this83.keyHelpUrl="https://docs.dify.ai/en/use-dify/publish/developing-with-apis",_this83.permittedErrorPrefixes=[Te],_this83._conversationId="",_this83._user=F,_this83._inputs={},_this83.url="".concat(s,"/chat-messages"),_this83._uploadUrl="".concat(s,"/").concat(b,"/upload"),_typeof(n)===U&&(n[F]&&(_this83._user=n[F]),n.inputs&&(_this83._inputs=n.inputs),_this83.completeConfig(n)),(_this83$maxMessages=_this83.maxMessages)!==null&&_this83$maxMessages!==void 0?_this83$maxMessages:_this83.maxMessages=-1,_this83._mode=_this83.stream?qs.STREAMING:qs.BLOCKING;return _this83;}_inherits(fh,_k33);return _createClass(fh,[{key:"preprocessBody",value:function preprocessBody(e,t,n){var s=this.processMessages(t),r=s[s.length-1],o=(r==null?void 0:r[h])||" ",a=_defineProperty({inputs:this._inputs,query:o,response_mode:this._mode},F,this._user);return this._conversationId&&(a.conversation_id=this._conversationId),n&&n.length>0&&(a[b]=n),a;}},{key:"callServiceAPI",value:function(){var _callServiceAPI40=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee179(e,t,n){var _this$messages11,_this84=this;var s,_t56;return _regenerator().w(function(_context179){while(1)switch(_context179.n){case 0:(_this$messages11=this.messages)!==null&&_this$messages11!==void 0?_this$messages11:this.messages=e;s=[];_t56=n&&n.length>0;if(!_t56){_context179.n=2;break;}_context179.n=1;return ah(n,_defineProperty(_defineProperty({url:this._uploadUrl},F,this._user),"headers",this.connectSettings.headers));case 1:s=_context179.v;case 2:this.callDirectServiceServiceAPI(e,t,function(r,o){return _this84.preprocessBody(r,o,s);});case 3:return _context179.a(2);}},_callee179,this);}));function callServiceAPI(_x339,_x340,_x341){return _callServiceAPI40.apply(this,arguments);}return callServiceAPI;}()},{key:"extractResultData",value:function(){var _extractResultData43=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee180(e){var _this85=this;var t;return _regenerator().w(function(_context180){while(1)switch(_context180.n){case 0:t=function t(n){_this85._conversationId=n;};return _context180.a(2,this._mode===qs.BLOCKING&&!this.stream?ch(e,t):dh(e,t));}},_callee180,this);}));function extractResultData(_x342){return _extractResultData43.apply(this,arguments);}return extractResultData;}()}]);}(k);var mh=/*#__PURE__*/function(){function mh(){_classCallCheck(this,mh);}return _createClass(mh,null,[{key:"create",value:// this should only be called when no _activeService is set or is demo as otherwise we don't want to reconnect
198
+ function create(e){var t=e.directConnection,n=e.connect,s=e.demo,r=e.webModel;if(r)return new Ts(e);if(t){if(t.openAI)return t.openAI[ee]?new er(e):t.openAI.speechToText?new Zi(e):t.openAI.textToSpeech?new Xi(e):t.openAI.assistant?new br(e):t.openAI.realtime?new Wi(e):t.openAI.completions?new ri(e):new oi(e);if(t.assemblyAI)return new yr(e);if(t.cohere)return new ci(e);if(t.huggingFace)return t.huggingFace.textGeneration?new Bl(e):t.huggingFace.summarization?new Fl(e):t.huggingFace.translation?new Hl(e):t.huggingFace.fillMask?new jl(e):t.huggingFace.questionAnswer?new Dl(e):t.huggingFace.audioSpeechRecognition?new Nl(e):t.huggingFace.audioClassification?new Pl(e):t.huggingFace.imageClassification?new Ll(e):new Ul(e);if(t.azure){if(t.azure.openAI){if(t.azure.openAI.chat)return new _r(e);if(t.azure.openAI.assistant)return new Vi(e);}if(t.azure.speechToText)return new Qi(e);if(t.azure.textToSpeech)return new Ji(e);if(t.azure.summarization)return new Yi(e);if(t.azure.translation)return new cd(e);}if(t.stabilityAI)return t.stabilityAI.imageToImage?new Qs(e):t.stabilityAI.imageToImageUpscale?new Ys(e):t.stabilityAI.imageToImageMasking?new Js(e):new ei(e);if(t.mistral)return new Er(e);if(t.gemini)return new Sr(e);if(t.claude)return new li(e);if(t.deepSeek)return new Rd(e);if(t.miniMax)return new Pd(e);if(t.openRouter)return new ps(e);if(t.kimi)return new Ar(e);if(t.x)return t.x[ee]?new nr(e):new th(e);if(t.qwen)return new xr(e);if(t.together)return t.together[ee]?new ud(e):t.together.textToSpeech?new zl(e):new pd(e);if(t.bigModel)return t.bigModel[ee]?new ld(e):t.bigModel.textToSpeech?new ql(e):new ai(e);if(t.groq)return t.groq.textToSpeech?new hd(e):new vr(e);if(t.perplexity)return new Ed(e);if(t.ollama)return new tr(e);if(t.openWebUI)return new Ad(e);if(t.dify)return new fh(e);}return n&&Object.keys(n).length>0&&!s?new un(e):new un(e,void 0,s||!0);}}]);}();var Qt=/*#__PURE__*/function(){function Qt(){_classCallCheck(this,Qt);}return _createClass(Qt,null,[{key:"attemptAppendStyleSheetToHead",value:function attemptAppendStyleSheetToHead(e,t){var n=e.fontFamily||t;if(n&&n!==Qt.DEFAULT_FONT_FAMILY)return;var s=document.getElementsByTagName("head")[0];if(!Array.from(s.getElementsByTagName("link")).some(function(o){return o.getAttribute("href")===Qt.FONT_URL;})){var o=A("link");o.rel="stylesheet",o.href=Qt.FONT_URL,s.appendChild(o);}}}]);}();Qt.FONT_URL="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap",Qt.DEFAULT_FONT_FAMILY="'Inter', sans-serif, Avenir, Helvetica, Arial";var sr=Qt;var Pr=/*#__PURE__*/_createClass(function Pr(){_classCallCheck(this,Pr);});Pr.attibutes={string:function string(e){return e;},number:function number(e){return parseFloat(e);},"boolean":function boolean(e){return e==="true";},object:function object(e){return JSON.parse(e);},array:function array(e){return JSON.parse(e);},"function":function _function(e){return new Function("return ".concat(e))();}};var ir=Pr;function O(i){return function(e,t){Object.defineProperty(e,t,{});var n=e.constructor,s=t.toLocaleLowerCase();n._attributes_[s]=ir.attibutes[i],n._attributeToProperty_[s]=t;};}var gh="deep-chat-downwards-mode",bh="deep-chat-upwards-mode",jn="submit-button",Hs="loading-button",$n="disabled-button",io="text-input-container-start-adjustment",ro="text-input-container-end-adjustment",oo="text-input-container-start-small-adjustment",ao="text-input-container-end-small-adjustment";var wr=/*#__PURE__*/function(){function wr(e){_classCallCheck(this,wr);this._isDisplayed=!1,this._elementRef=this.createIntroPanelWithChild(e),this._isDisplayed=!0;}return _createClass(wr,[{key:"createIntroPanelWithChild",value:function createIntroPanelWithChild(e){var t=wr.createIntroPanel();return e[v].display==="none"&&(e[v].display="block"),t.appendChild(e),t;}},{key:"hide",value:function hide(){this._isDisplayed&&(this._elementRef[v].display="none",this._isDisplayed=!1);}},{key:"display",value:function display(){this._isDisplayed||(this._elementRef[v].display="",this._isDisplayed=!0);}}],[{key:"createIntroPanel",value:function createIntroPanel(){var e=A();return e[m].add("intro-panel"),Object.assign(e[v]),e;}}]);}();var yh="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n\t viewBox=\"50 30 420 450\" xml:space=\"preserve\">\n<g filter=\"brightness(0) saturate(100%) invert(16%) sepia(0%) saturate(1942%) hue-rotate(215deg) brightness(99%) contrast(93%)\">\n\t<g>\n\t\t<path d=\"M447.933,103.629c-0.034-3.076-1.224-6.09-3.485-8.352L352.683,3.511c-0.004-0.004-0.007-0.005-0.011-0.008\n\t\t\tC350.505,1.338,347.511,0,344.206,0H89.278C75.361,0,64.04,11.32,64.04,25.237v461.525c0,13.916,11.32,25.237,25.237,25.237\n\t\t\th333.444c13.916,0,25.237-11.32,25.237-25.237V103.753C447.96,103.709,447.937,103.672,447.933,103.629z M356.194,40.931\n\t\t\tl50.834,50.834h-49.572c-0.695,0-1.262-0.567-1.262-1.262V40.931z M423.983,486.763c0,0.695-0.566,1.261-1.261,1.261H89.278\n\t\t\tc-0.695,0-1.261-0.566-1.261-1.261V25.237c0-0.695,0.566-1.261,1.261-1.261h242.94v66.527c0,13.916,11.322,25.239,25.239,25.239\n\t\t\th66.527V486.763z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,164.014H149.912c-6.62,0-11.988,5.367-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.368,11.988-11.988C374.076,169.381,368.707,164.014,362.088,164.014z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,236.353H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.62,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.368,11.988-11.988C374.076,241.721,368.707,236.353,362.088,236.353z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M362.088,308.691H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988h212.175\n\t\t\tc6.62,0,11.988-5.367,11.988-11.988C374.076,314.06,368.707,308.691,362.088,308.691z\"/>\n\t</g>\n</g>\n<g>\n\t<g>\n\t\t<path d=\"M256,381.031H149.912c-6.62,0-11.988,5.368-11.988,11.988c0,6.621,5.368,11.988,11.988,11.988H256\n\t\t\tc6.62,0,11.988-5.367,11.988-11.988C267.988,386.398,262.62,381.031,256,381.031z\"/>\n\t</g>\n</g>\n</svg>",Ie=/*#__PURE__*/function(){function Ie(){_classCallCheck(this,Ie);}return _createClass(Ie,null,[{key:"createImage",value:function createImage(e,t){var n=new Image();return n[T]=e[T],t&&Se.scrollDownOnImageLoad(n[T],t),Se.processContent(W,n,n[T],e.name);}// WORK - image still does not scroll down when loaded
199
+ },{key:"createImageMessage",value:function createImageMessage(e,t,n,s,r){var o=e.createNewMessageElement("",n,s),a=!s&&r?e.scrollToFirstElement.bind(e,n,r):void 0,c=Ie.createImage(t,a);return o.bubbleElement.appendChild(c),o.bubbleElement[m].add(Ie.IMAGE_BUBBLE_CLASS),_defineProperty(_defineProperty({},E,W),"elements",o);}},{key:"createAudioElement",value:function createAudioElement(e,t){var n=A($);return n[T]=e[T],n[m].add("audio-player"),n.controls=!0,$e.IS_SAFARI&&(n[m].add("audio-player-safari"),n[m].add(t===F?"audio-player-safari-end":"audio-player-safari-start")),n;}},{key:"autoPlayAudio",value:function autoPlayAudio(e){e.addEventListener("loadeddata",function(){e.play()["catch"](function(t){console.warn("Auto-play failed:",t);});});}},{key:"createNewAudioMessage",value:function createNewAudioMessage(e,t,n,s){var r=Ie.createAudioElement(t,n),o=e.createMessageElementsOnOrientation("",n,s);return o.bubbleElement.appendChild(r),o.bubbleElement[m].add(Ie.AUDIO_BUBBLE_CLASS),_defineProperty(_defineProperty(_defineProperty({},E,$),"elements",o),"audioElement",r);}},{key:"createAnyFile",value:function createAnyFile(e){var t=A();t[m].add("any-file-message-contents");var n=A();n[m].add("any-file-message-icon-container");var s=kt.createSVGElement(yh);s[m].add("any-file-message-icon"),n.appendChild(s);var r=A();return r[m].add("any-file-message-text"),r.textContent=e.name||se,t.appendChild(n),t.appendChild(r),Se.processContent(on,t,e[T],r.textContent);}},{key:"createNewAnyFileMessage",value:function createNewAnyFileMessage(e,t,n,s){var r=e.createMessageElementsOnOrientation("",n,s),o=Ie.createAnyFile(t);return r.bubbleElement[m].add(Ie.ANY_FILE_BUBBLE_CLASS),r.bubbleElement.appendChild(o),_defineProperty(_defineProperty({},E,se),"elements",r);}},{key:"createMessages",value:function createMessages(e,t,n,s){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;return t.map(function(o,a){var c;if(o.ref&&(o=Se.removeFileRef(o)),Se.isAudioFile(o)){var l=Ie.createNewAudioMessage(e,o,n,r),d=(c=e.textToSpeech)==null?void 0:c.audio;return d&&(d.autoPlay&&Ie.autoPlayAudio(l.audioElement),typeof d.displayAudio=="boolean"&&!d.displayAudio)?void 0:l;}return Se.isImageFile(o)?Ie.createImageMessage(e,o,n,r,s&&a===0):Ie.createNewAnyFileMessage(e,o,n,r);}).filter(function(o){return o!==void 0;});}// no overwrite previous message logic as it is complex to track which files are to be overwritten
200
+ },{key:"addMessages",value:function addMessages(e,t,n,s,r){Ie.createMessages(e,t,n,s,r).filter(function(a){return a!==void 0;}).forEach(function(_ref247){var a=_ref247[E],c=_ref247.elements;Se.addMessage(e,c,a,n,r);});}}]);}();Ie.IMAGE_BUBBLE_CLASS="image-message",Ie.AUDIO_BUBBLE_CLASS="audio-message",Ie.ANY_FILE_BUBBLE_CLASS="any-file-message";var di=Ie;var Qe=/*#__PURE__*/function(){function Qe(){_classCallCheck(this,Qe);}return _createClass(Qe,null,[{key:"removeElements",value:function removeElements(e,t){if(!t)return;var n=e.findIndex(function(s){return s===t;});e.splice(n,1),t==null||t.outerContainer.remove();}},{key:"removeFilesMessages",value:function removeFilesMessages(e,t){var n;(n=t[1][b])==null||n.forEach(function(s){Qe.removeElements(e.messageElementRefs,s);}),delete t[0][b],delete t[1][b];}},{key:"removeTextHTMLMessage",value:function removeTextHTMLMessage(e,t,n){var s=t[1][n];Qe.removeElements(e.messageElementRefs,s),delete t[0][n],delete t[1][n];}},{key:"updateHTMLMessage",value:function updateHTMLMessage(e,t,n){var s,r,o;if(t[1][L])yt.overwriteElements(e,n,t[1][L]);else{var a=yt.create(e,n,t[0][x]),c=((r=t[1][b])==null?void 0:r[((s=t[1][b])==null?void 0:s.length)-1])||t[1][h],l=c.outerContainer.nextSibling;(o=l==null?void 0:l.parentElement)==null||o.insertBefore(a.outerContainer,l),e.messageElementRefs.splice(e.messageElementRefs.length-1,1);var d=e.messageElementRefs.findIndex(function(p){return p===c;});e.messageElementRefs.splice(d+1,0,a),t[1][L]=a;}t[0][L]=n;}// finds beforeElement, creates new elements, remove old and adds new ones
201
+ },{key:"updateFileMessages",value:function updateFileMessages(e,t,n){var p,u;var s=t[0][x],r=di.createMessages(e,n,s,!1),o=t[1][L],a=((u=t[1][b])==null?void 0:u[((p=t[1][b])==null?void 0:p.length)-1])||t[1][h],c=o||a;var l=e.messageElementRefs.findIndex(function(g){return g===c;});a&&(l+=1);var d=(o==null?void 0:o.outerContainer)||(a==null?void 0:a.outerContainer.nextSibling);r.forEach(function(_ref248,_){var g=_ref248.type,y=_ref248.elements;var S;Se.setElementProps(e,y,g,s),(S=d.parentElement)==null||S.insertBefore(y.outerContainer,d),e.messageElementRefs.splice(e.messageElementRefs.length-1,1),e.messageElementRefs.splice(l+_,0,y);}),Qe.removeFilesMessages(e,t),t[1][b]=r.map(function(_ref249){var g=_ref249.elements;return g;}),t[0][b]=n;}},{key:"updateTextMessage",value:function updateTextMessage(e,t,n){var s,r;if(t[1][h])e.renderText(t[1][h].bubbleElement,n,t[0][x]);else{var o=e.createElements(n,t[0][x]),a=((s=t[1][b])==null?void 0:s[0])||t[1][L];(r=a.outerContainer.parentElement)==null||r.insertBefore(o.outerContainer,a.outerContainer);var c=e.messageElementRefs.findIndex(function(l){return l===a;});e.messageElementRefs.splice(c,0,o),t[1][h]=o;}t[0][h]=n;}},{key:"isElementActive",value:function isElementActive(e){var t,n;return tt.isActiveElement((t=e[h])==null?void 0:t.bubbleElement[m])||tt.isActiveElement((n=e[L])==null?void 0:n.bubbleElement[m]);}// note that overwrite and 'deep-chat-temporary-message' are used to remove a message
202
+ },{key:"update",value:function update(e,t,n){var s=e.messageToElements[n];if(s){if(Qe.isElementActive(s[1]))return console[f]("Cannot update a message that is being streamed");t[h]&&Qe.updateTextMessage(e,s,t[h]),t[b]?Qe.updateFileMessages(e,s,t[b]):Qe.removeFilesMessages(e,s),t[L]&&Qe.updateHTMLMessage(e,s,t[L]),!t[h]&&s[1][h]&&Qe.removeTextHTMLMessage(e,s,h),!t[L]&&s[1][L]&&Qe.removeTextHTMLMessage(e,s,L);var r=e.messageElementRefs,o=e.avatar,a=e.name;B.classifyRoleMessages(r),B.resetAllRoleElements(r,o,a);}else console[f]("Message index not found. Please use the `getMessages` method to find the correct index");}}]);}();var _h=/*#__PURE__*/function(){function _h(){_classCallCheck(this,_h);}return _createClass(_h,null,[{key:"getText",value:function getText(e,t){var n,s;if(!e.directConnection&&!e.connect&&!e.webModel&&!e.demo)return"Connect to any API using the [connect](".concat(Z,"connect#connect-1) property or a popular service via [directConnection](").concat(Z,"directConnection/#directConnection).\n Host AI entirely on your browser via a [webModel](").concat(Z,"webModel).\n To get started checkout the [Start](https://deepchat.dev/start) page and live code [examples](https://deepchat.dev/examples/frameworks).\n To remove this message set the [demo](").concat(Z,"modes#demo) property to true.");if(e.directConnection){if(!t.isDirectConnection())return"Please define a valid service inside\n the [directConnection](".concat(Z,"directConnection/#directConnection) object.");var r=(n=e.directConnection.openAI)==null?void 0:n.chat;if(_typeof(r)=="object"&&(s=r.tools)!=null&&s.find(function(o){return o[E]==="function";})&&!r.function_handler)return"Please define the `function_handler` property inside the openAI [chat](".concat(Z,"directConnection/openAI#Chat) object.");}else if(e.connect&&!e.connect.url&&!e.connect.handler)return"Please define a `url` or a `handler` property inside the [connect](".concat(Z,"connect#connect-1) object.");return null;}}]);}();var tt=/*#__PURE__*/function(_nt){function tt(e,t,n){var _this86;_classCallCheck(this,tt);var a,c;_this86=_callSuper(this,tt,[e]);var s=t.permittedErrorPrefixes,r=t.demo;_this86._errorMessageOverrides=(a=e.errorMessages)==null?void 0:a.overrides,_this86._onClearMessages=hn.onClearMessages.bind(_this86,e),_this86._onError=hn.onError.bind(_this86,e),_this86._isLoadingMessageAllowed=tt.getDefaultDisplayLoadingMessage(e,t),_typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle&&(e.displayLoadingBubble.toggle=_this86.setLoadingToggle.bind(_this86)),_this86._permittedErrorPrefixes=s,_this86.addSetupMessageIfNeeded(e,t)||_this86.populateIntroPanel(n),r&&_this86.prepareDemo(le.processDemo(r),e.loadHistory),_this86.addIntroductoryMessages(e,t);var o=new Cs(e,_this86,t);_this86._displayServiceErrorMessages=(c=e.errorMessages)==null?void 0:c.displayServiceErrorMessages,e.getMessages=function(){return B.deepCloneMessagesWithReferences(_this86.messageToElements.map(function(_ref250){var _ref251=_slicedToArray(_ref250,1),l=_ref251[0];return l;}));},e.clearMessages=_this86.clearMessages.bind(_this86,t),e.refreshMessages=_this86.refreshTextMessages.bind(_this86,e.remarkable),e.scrollToBottom=z.scrollToBottom.bind(_this86,_this86),e.addMessage=function(l,d){_this86.addAnyMessage(_objectSpread(_objectSpread({},l),{},{sendUpdate:!!d}),!d);},e.updateMessage=function(l,d){return Qe.update(_this86,l,d);},t.isWebModel()&&t.setUpMessages(_this86),e.textToSpeech&&Rn.processConfig(e.textToSpeech,function(l){_this86.textToSpeech=l;}),_this86.elementRef.onscroll=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee181(){var l,d;return _regenerator().w(function(_context181){while(1)switch(_context181.n){case 0:e.loadHistory&&o.loadHistoryOnScroll(e.loadHistory),(l=_this86.scrollButton)==null||l.updateScroll(),(d=_this86.browserStorage)!=null&&d.trackScrollHeight&&_this86.browserStorage.addScrollHeight(_this86.elementRef.scrollTop);case 1:return _context181.a(2);}},_callee181);}));return _this86;}_inherits(tt,_nt);return _createClass(tt,[{key:"setLoadingToggle",value:function setLoadingToggle(e){var t=this.messageElementRefs[this.messageElementRefs.length-1],n=nt.isLoadingMessage(t);if(!e&&n)this.removeLastMessage(),delete this._activeLoadingConfig;else{if(this._activeLoadingConfig&&n){var s=oe.getTargetWrapper(t.bubbleElement);if(s)return this._activeLoadingConfig=e||{},this.updateLoadingMessage(s);this.removeLastMessage();}this._activeLoadingConfig=e||{},this.addLoadingMessage(!0);}}},{key:"prepareDemo",value:function prepareDemo(e,t){var n;if(_typeof(e)=="object"){if(!t&&e.displayLoading){var s=e.displayLoading.history;s!=null&&s.small&&Mt.addMessage(this,!1),s!=null&&s.full&&Mt.addMessage(this);}e.displayErrors&&(e.displayErrors[w]&&this.addNewErrorMessage("",""),e.displayErrors.service&&this.addNewErrorMessage(ae,""),e.displayErrors.speechToText&&this.addNewErrorMessage("speechToText","")),(n=e.displayLoading)!=null&&n.message&&this.addLoadingMessage(),e.response&&(this.customDemoResponse=e.response);}}},{key:"addSetupMessageIfNeeded",value:function addSetupMessageIfNeeded(e,t){var n=_h.getText(e,t);if(n){var s=this.createAndAppendNewMessageElement(n,ne);this.applyCustomStyles(s,ne,!1);}return!!n;}// WORK - const file for deep chat classes
203
+ },{key:"addIntroductoryMessages",value:function addIntroductoryMessages(e,t){var _this87=this;e!=null&&e.shadowRoot&&(this._introMessage=e.introMessage);var n=this._introMessage;t!=null&&t.isWebModel()&&(n!==null&&n!==void 0?n:n=t.getIntroMessage(n));var s=!(e!=null&&e.history)&&!!(e!=null&&e.loadHistory||t!=null&&t.fetchHistory);n&&(Array.isArray(n)?n.forEach(function(r,o){if(o!==0){var a=_this87.messageElementRefs[_this87.messageElementRefs.length-1].innerContainer;B.hideRoleElements(a,_this87.avatar,_this87.name);}_this87.addIntroductoryMessage(r,s);}):this.addIntroductoryMessage(n,s));}},{key:"addIntroductoryMessage",value:function addIntroductoryMessage(e,t){var s;var n;return e!=null&&e[h]?n=this.createAndAppendNewMessageElement(e[h],ne):e!=null&&e[L]&&(n=yt.add(this,e[L],ne)),n&&(this.applyCustomStyles(n,ne,!1,(s=this.messageStyles)==null?void 0:s.intro),n.outerContainer[m].add(nt.INTRO_CLASS),t&&(n.outerContainer[v].display="none")),n;}},{key:"removeIntroductoryMessage",value:function removeIntroductoryMessage(){var e=this.messageElementRefs[0];e.outerContainer[m].contains(nt.INTRO_CLASS)&&(e.outerContainer.remove(),this.messageElementRefs.shift());}},{key:"addAnyMessage",value:function addAnyMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;return e[f]?this.addNewErrorMessage(ae,e[f],n):this.addNewMessage(e,t,n);}},{key:"tryAddTextMessage",value:function tryAddTextMessage(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:!1;e[h]!==void 0&&n[h]!==null&&(this.addNewTextMessage(e[h],e[x],t,r),!s&&this.textToSpeech&&e[x]!==F&&Rn.speak(e[h],this.textToSpeech));}},{key:"tryAddFileMessages",value:function tryAddFileMessages(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;e[b]&&Array.isArray(e[b])&&di.addMessages(this,e[b],e[x],t,n);}},{key:"tryAddHTMLMessage",value:function tryAddHTMLMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;if(e[L]!==void 0&&e[L]!==null){var s=yt.add(this,e[L],e[x],t,n);!n&&bt.isElementTemporary(s)&&delete e[L];}}// this should not be activated by streamed messages
204
+ },{key:"addNewMessage",value:function addNewMessage(e){var _this88=this;var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!1;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var c,l,d,p;e[x]!==F&&((c=this._hiddenAttachments)==null||c.removeHiddenFiles());var s=tt.createMessageContent(e),r=(d=(l=this.textToSpeech)==null?void 0:l.audio)==null?void 0:d.displayText;typeof r=="boolean"&&!r&&delete s[h];var o=z.isScrollbarAtBottomOfElement(this.elementRef),a={status:e.overwrite};return n?(this.tryAddFileMessages(s,o,n),this.tryAddHTMLMessage(s,a,n),this.tryAddTextMessage(s,a,e,t,n)):(this.tryAddTextMessage(s,a,e,t,n),this.tryAddHTMLMessage(s,a,n),this.tryAddFileMessages(s,o,n)),this.isValidMessageContent(s)&&!n&&(this.updateStateOnMessage(s,e.overwrite,e.sendUpdate,t),a.status||setTimeout(function(){return _this88.scrollToFirstElement(s[x],o);}),t||(p=this.browserStorage)==null||p.addMessages(this.messageToElements.map(function(_ref253){var _ref254=_slicedToArray(_ref253,1),u=_ref254[0];return u;})),this.scrollButton&&s[x]!==F&&this.tryUpdateHiddenMessageCount(t,e)),this._activeLoadingConfig&&this.addLoadingMessage(!1),s;}},{key:"tryUpdateHiddenMessageCount",value:function tryUpdateHiddenMessageCount(e,t){var _this89=this;(!e||t.sendUpdate!==void 0)&&setTimeout(function(){var n,s;return(s=(n=_this89.scrollButton)==null?void 0:n.updateHidden)==null?void 0:s.call(n);});}},{key:"isValidMessageContent",value:function isValidMessageContent(e){return e[h]||e[L]||e[b]&&e[b].length>0;}},{key:"updateStateOnMessage",value:function updateStateOnMessage(e,t){var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!0;var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;if(!t){var r=B.generateMessageBody(e,this.messageElementRefs);this.messageToElements.push([e,r]);}n&&this.sendClientUpdate(e,s);}// prettier-ignore
209
205
  },{key:"removeMessageOnError",value:function removeMessageOnError(){var e=this.messageElementRefs[this.messageElementRefs.length-1],t=e==null?void 0:e.bubbleElement;(t!=null&&t[m].contains(ht.MESSAGE_CLASS)&&t.textContent===""||tt.isTemporaryElement(e))&&this.removeLastMessage();}// prettier-ignore
210
- },{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this90=this;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var l,d,p,u,g,y;(l=this._hiddenAttachments)==null||l.readdHiddenFiles(),this.removeMessageOnError();var s=this.getPermittedMessage(t)||((d=this._errorMessageOverrides)==null?void 0:d[e])||((p=this._errorMessageOverrides)==null?void 0:p[w])||"Error, please try again.",r=this.createMessageElementsOnOrientation(s,f,n);B.hideRoleElements(r.innerContainer,this.avatar,this.name);var o=r.bubbleElement,a=r.outerContainer;o[m].add(Ks),this.renderText(o,s);var c=Be.extractParticularSharedStyles(["fontSize","fontFamily"],(u=this.messageStyles)==null?void 0:u[w]);Be.applyCustomStylesToElements(r,!1,c),Be.applyCustomStylesToElements(r,!1,(g=this.messageStyles)==null?void 0:g[f]),n||this.appendOuterContainerElemet(a),this.textToSpeech&&Rn.speak(s,this.textToSpeech),(y=this._onError)==null||y.call(this,s),setTimeout(function(){return z.scrollToBottom(_this90);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=tt.extractErrorMessages(e);for(var _n14=0;_n14<t.length;_n14+=1){var s=t[_n14];if(_typeof(s)===Ee){if(this._displayServiceErrorMessages)return s;if(this._permittedErrorPrefixes){var r=tt.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,s);if(r)return r;}}}}}},{key:"removeError",value:function removeError(){this.isLastMessageError()&&B.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:ne;var n=this.createMessageElements("",t),s=n.bubbleElement;n.bubbleElement[m].add(mt.DOTS_CONTAINER_CLASS);var r=A();return r[m].add("loading-message-dots"),s.appendChild(r),mt.setDots(s,e),n;}// prettier-ignore
206
+ },{key:"addNewErrorMessage",value:function addNewErrorMessage(e,t){var _this90=this;var n=arguments.length>2&&arguments[2]!==undefined?arguments[2]:!1;var l,d,p,u,g,y;(l=this._hiddenAttachments)==null||l.readdHiddenFiles(),this.removeMessageOnError();var s=this.getPermittedMessage(t)||((d=this._errorMessageOverrides)==null?void 0:d[e])||((p=this._errorMessageOverrides)==null?void 0:p[w])||"Error, please try again.",r=this.createMessageElementsOnOrientation(s,f,n);B.hideRoleElements(r.innerContainer,this.avatar,this.name);var o=r.bubbleElement,a=r.outerContainer;o[m].add(Vs),this.renderText(o,s);var c=Be.extractParticularSharedStyles(["fontSize","fontFamily"],(u=this.messageStyles)==null?void 0:u[w]);Be.applyCustomStylesToElements(r,!1,c),Be.applyCustomStylesToElements(r,!1,(g=this.messageStyles)==null?void 0:g[f]),n||this.appendOuterContainerElemet(a),this.textToSpeech&&Rn.speak(s,this.textToSpeech),(y=this._onError)==null||y.call(this,s),setTimeout(function(){return z.scrollToBottom(_this90);});}},{key:"getPermittedMessage",value:function getPermittedMessage(e){if(e){var t=tt.extractErrorMessages(e);for(var _n14=0;_n14<t.length;_n14+=1){var s=t[_n14];if(_typeof(s)===Ee){if(this._displayServiceErrorMessages)return s;if(this._permittedErrorPrefixes){var r=tt.checkPermittedErrorPrefixes(this._permittedErrorPrefixes,s);if(r)return r;}}}}}},{key:"removeError",value:function removeError(){this.isLastMessageError()&&B.getLastMessageElement(this.elementRef).remove();}},{key:"addDefaultLoadingMessage",value:function addDefaultLoadingMessage(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:ne;var n=this.createMessageElements("",t),s=n.bubbleElement;n.bubbleElement[m].add(mt.DOTS_CONTAINER_CLASS);var r=A();return r[m].add("loading-message-dots"),s.appendChild(r),mt.setDots(s,e),n;}// prettier-ignore
211
207
  },{key:"addLoadingMessage",value:function addLoadingMessage(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;var a,c,l,d,p,u;if(nt.isLoadingMessage(this.messageElementRefs[this.messageElementRefs.length-1])||!this._activeLoadingConfig&&!e&&!this._isLoadingMessageAllowed)return;var t=((a=this._activeLoadingConfig)==null?void 0:a[x])||ne,n=((c=this._activeLoadingConfig)==null?void 0:c[v])||((d=(l=this.messageStyles)==null?void 0:l.loading)==null?void 0:d.message),s=n==null?void 0:n[L],r=s?yt.createElements(this,s,t,!1):this.addDefaultLoadingMessage(n,t);this.appendOuterContainerElemet(r.outerContainer),r.bubbleElement[m].add(mt.BUBBLE_CLASS),this.applyCustomStyles(r,t,!1,n==null?void 0:n[R]),(u=(p=this.avatar)==null?void 0:p.getAvatarContainer(r.innerContainer))==null||u[m].add("loading-avatar-container"),!this.focusMode&&z.isScrollbarAtBottomOfElement(this.elementRef)&&z.scrollToBottom(this);}// this is a special method not to constantly refresh loading animations
212
- },{key:"updateLoadingMessage",value:function updateLoadingMessage(e){var s;var t=(s=this._activeLoadingConfig)==null?void 0:s[v],n=t==null?void 0:t[L];e.innerHTML=n||"";}},{key:"populateIntroPanel",value:function populateIntroPanel(e){e&&(this._introPanel=new Cr(e),oe.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee182(e,t){return _regenerator().w(function(_context182){while(1)switch(_context182.n){case 0:return _context182.a(2,(this._hiddenAttachments=t,Promise.all((e||[]).map(function(n){return new Promise(function(s){if(!n[E]||n[E]===rn){var r=n[se].name||se;s(_defineProperty(_defineProperty({name:r},E,rn),"ref",n[se]));}else{var _r8=new FileReader();_r8.readAsDataURL(n[se]),_r8.onload=function(){var o=n[se].name;s(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},T,_r8.result),"name",o),E,n[E]),"ref",n[se]));};}});}))));}},_callee182,this);}));function addMultipleFiles(_x343,_x344){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
213
- function clearMessages(e,t){var _this$messageToElemen2;var r,o,a,c;var n=[];this.messageElementRefs.forEach(function(l){tt.isActiveElement(l.bubbleElement[m])?n.push(l):l.outerContainer.remove();}),Array.from(this.elementRef.children).forEach(function(l){var p;var d=(p=l.children[0])==null?void 0:p.children[0];d!=null&&d[m].contains(Ks)&&l.remove();}),this.messageElementRefs=n;var s=this.messageToElements.filter(function(l){return l[1][h]&&tt.isActiveElement(l[1][h].bubbleElement[m])||l[1][L]&&tt.isActiveElement(l[1][L].bubbleElement[m]);});(_this$messageToElemen2=this.messageToElements).splice.apply(_this$messageToElemen2,[0,this.messageToElements.length].concat(_toConsumableArray(s))),t!==!1&&((r=this._introPanel)!=null&&r._elementRef&&this._introPanel.display(),this.addIntroductoryMessages()),(o=this.browserStorage)==null||o.clear(),(a=this.scrollButton)==null||a.clearHidden(),(c=this._onClearMessages)==null||c.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref251;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===U?!1:!!e.displayLoadingBubble:(_ref251=_typeof(e.displayLoadingBubble)===U||e.displayLoadingBubble)!==null&&_ref251!==void 0?_ref251:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _n15=0;_n15<e.length;_n15+=1)if(t.startsWith(e[_n15]))return t;}},{key:"extractErrorMessages",value:function extractErrorMessages(e){return Array.isArray(e)?e:e instanceof Error?[e.message]:typeof e=="string"?[e]:_typeof(e)=="object"&&e[f]?[e[f]]:[];}},{key:"isActiveElement",value:function isActiveElement(e){return e?e.contains(mt.BUBBLE_CLASS)||e.contains(Mt.CLASS)||e.contains(ht.MESSAGE_CLASS):!1;}}]);}(nt);var ms=/*#__PURE__*/function(){function ms(){_classCallCheck(this,ms);}return _createClass(ms,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t[In].length>0&&e[m].add("text-input-inner-start-adjustment"),t[ft].length>0&&e[m].add("text-input-inner-end-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,n){n[ve].length===0&&n[Le].length>0?(e[0][m].add(ao),t[m].add(ao)):n[Le].length===0&&n[ve].length>0&&(e[3][m].add(co),t[m].add(co));}// when submit is the only button
208
+ },{key:"updateLoadingMessage",value:function updateLoadingMessage(e){var s;var t=(s=this._activeLoadingConfig)==null?void 0:s[v],n=t==null?void 0:t[L];e.innerHTML=n||"";}},{key:"populateIntroPanel",value:function populateIntroPanel(e){e&&(this._introPanel=new wr(e),oe.apply(this,this._introPanel._elementRef),this.elementRef.appendChild(this._introPanel._elementRef));}},{key:"addMultipleFiles",value:function(){var _addMultipleFiles=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee182(e,t){return _regenerator().w(function(_context182){while(1)switch(_context182.n){case 0:return _context182.a(2,(this._hiddenAttachments=t,Promise.all((e||[]).map(function(n){return new Promise(function(s){if(!n[E]||n[E]===on){var r=n[se].name||se;s(_defineProperty(_defineProperty({name:r},E,on),"ref",n[se]));}else{var _r8=new FileReader();_r8.readAsDataURL(n[se]),_r8.onload=function(){var o=n[se].name;s(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},T,_r8.result),"name",o),E,n[E]),"ref",n[se]));};}});}))));}},_callee182,this);}));function addMultipleFiles(_x343,_x344){return _addMultipleFiles.apply(this,arguments);}return addMultipleFiles;}()},{key:"clearMessages",value:// WORK - update all message classes to use deep-chat prefix
209
+ function clearMessages(e,t){var _this$messageToElemen2;var r,o,a,c;var n=[];this.messageElementRefs.forEach(function(l){tt.isActiveElement(l.bubbleElement[m])?n.push(l):l.outerContainer.remove();}),Array.from(this.elementRef.children).forEach(function(l){var p;var d=(p=l.children[0])==null?void 0:p.children[0];d!=null&&d[m].contains(Vs)&&l.remove();}),this.messageElementRefs=n;var s=this.messageToElements.filter(function(l){return l[1][h]&&tt.isActiveElement(l[1][h].bubbleElement[m])||l[1][L]&&tt.isActiveElement(l[1][L].bubbleElement[m]);});(_this$messageToElemen2=this.messageToElements).splice.apply(_this$messageToElemen2,[0,this.messageToElements.length].concat(_toConsumableArray(s))),t!==!1&&((r=this._introPanel)!=null&&r._elementRef&&this._introPanel.display(),this.addIntroductoryMessages()),(o=this.browserStorage)==null||o.clear(),(a=this.scrollButton)==null||a.clearHidden(),(c=this._onClearMessages)==null||c.call(this),delete e.sessionId;}}],[{key:"getDefaultDisplayLoadingMessage",value:function getDefaultDisplayLoadingMessage(e,t){var _ref255;return _typeof(e.displayLoadingBubble)=="object"&&e.displayLoadingBubble.toggle?!1:t.websocket?_typeof(e.displayLoadingBubble)===U?!1:!!e.displayLoadingBubble:(_ref255=_typeof(e.displayLoadingBubble)===U||e.displayLoadingBubble)!==null&&_ref255!==void 0?_ref255:!0;}},{key:"checkPermittedErrorPrefixes",value:function checkPermittedErrorPrefixes(e,t){for(var _n15=0;_n15<e.length;_n15+=1)if(t.startsWith(e[_n15]))return t;}},{key:"extractErrorMessages",value:function extractErrorMessages(e){return Array.isArray(e)?e:e instanceof Error?[e.message]:typeof e=="string"?[e]:_typeof(e)=="object"&&e[f]?[e[f]]:[];}},{key:"isActiveElement",value:function isActiveElement(e){return e?e.contains(mt.BUBBLE_CLASS)||e.contains(Mt.CLASS)||e.contains(ht.MESSAGE_CLASS):!1;}}]);}(nt);var fs=/*#__PURE__*/function(){function fs(){_classCallCheck(this,fs);}return _createClass(fs,null,[{key:"adjustInputPadding",value:function adjustInputPadding(e,t){t[In].length>0&&e[m].add("text-input-inner-start-adjustment"),t[ft].length>0&&e[m].add("text-input-inner-end-adjustment");}},{key:"adjustForOutsideButton",value:function adjustForOutsideButton(e,t,n){n[ve].length===0&&n[Le].length>0?(e[0][m].add(oo),t[m].add(oo)):n[Le].length===0&&n[ve].length>0&&(e[3][m].add(ao),t[m].add(ao));}// when submit is the only button
214
210
  // when submit button is outside by itself - we increase the height for a better look
215
- },{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,n){if(!(n[In].length>0||n[ft].length>0)){if(n[ve].length===0&&n[Le].length>0)return e[0][m].add(ro),t[m].add(ro),n[Le].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});if(n[Le].length===0&&n[ve].length>0)return e[3][m].add(oo),t[m].add(oo),n[ve].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});}}// prettier-ignore
216
- },{key:"set",value:function set(e,t,n,s){!!ms.adjustOutsideSubmit(t,n,s)||ms.adjustForOutsideButton(t,n,s),ms.adjustInputPadding(e,s);}}]);}();var Ln=/*#__PURE__*/function(){function Ln(){_classCallCheck(this,Ln);}return _createClass(Ln,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var n=A();return n[m].add("input-button-container"),(t===0||t===3)&&n[m].add("outer-button-container"),(t===1||t===2)&&n[m].add("inner-button-container"),n;});}},{key:"add",value:function add(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 getContainerIndex(e){return e===Le?0:e===In?1:e===ft?2:3;}},{key:"addButton",value:function addButton(e,t,n){t[m].add(n);var s=Ln.getContainerIndex(n);e[s].appendChild(t),s===3&&t[m].add(ve);}}]);}();var lo=["camera","gifs","images","audio","mixedFiles",st,"microphone"],vh="<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 22 22\" fill=\"none\">\n <rect x=\"2.5\" y=\"2.5\" width=\"17\" height=\"17\" rx=\"2\" stroke=\"#000000\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>\n",Me=/*#__PURE__*/function(){function Me(){_classCallCheck(this,Me);}return _createClass(Me,null,[{key:"addHighlightEvents",value:function addHighlightEvents(e,t){t.addEventListener(Ps,function(n){e.highlightedItem=n.target;}),t.addEventListener(an,function(){e.highlightedItem=void 0;});}},{key:"addItemEvents",value:function addItemEvents(e,t,n,s){Rt.add(t,s),t.addEventListener(J,function(){n[J]();}),Me.addHighlightEvents(e,t);}},{key:"createItemText",value:function createItemText(e,t){var n=A();return Object.assign(n[v],t),n[m].add(Me.TEXT_CLASS),n.textContent=e||"File",n;}},{key:"createItemIcon",value:function createItemIcon(e,t){var n=A();return Object.assign(n[v],t),n[m].add(Me.ICON_CLASS),n.appendChild(e),n;}},{key:"populateItem",value:function populateItem(e,t,n){var s=e.elementRef,r=e.dropupText,o=e.svg,a=e.customStyles,c=s.children[0],l=a&&Object.values(a).find(function(d){var p;return((p=d[G])==null?void 0:p.content)==="";});c[m].contains(Et.INPUT_BUTTON_INNER_TEXT_CLASS)?(l||t.appendChild(Me.createItemIcon(o,n==null?void 0:n.iconContainer)),t.appendChild(Me.createItemText(c.textContent,n==null?void 0:n[h]))):(l||t.appendChild(Me.createItemIcon(s.children[0],n==null?void 0:n.iconContainer)),t.appendChild(Me.createItemText(r,n==null?void 0:n[h])));}},{key:"createItem",value:function createItem(e,t,n){var o;var s=A();Object.assign(s[v],(o=n==null?void 0:n.item)==null?void 0:o[w]),Me.populateItem(t,s,n),s[m].add(Me.MENU_ITEM_CLASS),s.tabIndex=0;var r=t.elementRef;if(t.isCustom)t.setDropupItem(e,s);else{var a=ce.processStateful((n==null?void 0:n.item)||{});Me.addItemEvents(e,s,r,a);}return s;}}]);}();Me.MENU_ITEM_CLASS="dropup-menu-item",Me.CUSTOM_BUTTON_ITEM_CLASS="dropup-menu-item-custom-button",Me.TEXT_CLASS="dropup-menu-item-text",Me.ICON_CLASS="dropup-menu-item-icon";var lt=Me;var fe=/*#__PURE__*/function(_mn2){// prettier-ignore
217
- function fe(e,t,n,s){var _this91;_classCallCheck(this,fe);var c,l,d,p,u,g;var r=((p=(d=(l=(c=e==null?void 0:e[R])==null?void 0:c.button)==null?void 0:l[w])==null?void 0:d[h])==null?void 0:p.content)||"Custom ".concat(t),o=vh,a=ut.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this91=_callSuper(this,fe,[fe.createButtonElement(),o,e==null?void 0:e.position,a,((u=e==null?void 0:e[R])==null?void 0:u.button)||a&&{},r]),_this91._state=w,_this91.isCustom=!0,_this91._innerElements=_this91.createInnerElementsForStates(_this91.customStyles),_this91._menuStyles=s,_this91._onClick=e.onClick,_this91._dropupStyles=(g=e[R])==null?void 0:g.dropup,_this91.setSetState(e),_this91.addClickListener(n),_this91.changeState(e.initialState,!0);return _this91;}_inherits(fe,_mn2);return _createClass(fe,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="custom-icon",n=this.createInnerElements(t,w,e);return _defineProperty(_defineProperty(_defineProperty({},w,n),H,this.genStateInnerElements(t,H,n,e)),j,this.genStateInnerElements(t,j,n,e));}},{key:"setSetState",value:function setSetState(e){var _this92=this;e.setState=function(t){t===w&&_this92.changeToDefault(),t===H&&_this92.changeToActive(),t===j&&_this92.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this93=this;z.assignButtonEvents(this.elementRef,function(){var n;var t=(n=_this93._onClick)==null?void 0:n.call(_this93,_this93._state);e==null||e(),(t===w||t===H||t===j)&&_this93.changeState(t);});}},{key:"changeState",value:function changeState(e,t){e===j?this.changeToDisabled(t):e===H?this.changeToActive(t):this.changeToDefault(t);}},{key:"applyDropupContentStyles",value:function applyDropupContentStyles(e){var t=Array.from(this.elementRef.children);if(e!=null&&e[h]){var _n16=t.find(function(s){return s[m].contains(lt.TEXT_CLASS);});_n16&&Object.assign(_n16[v],e[h]);}if(e!=null&&e.iconContainer){var _n17=t.find(function(s){return s[m].contains(lt.ICON_CLASS);});_n17&&Object.assign(_n17[v],e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var n,s,r;this.elementRef=oe.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((n=e==null?void 0:e[G])==null?void 0:n.content)===""||this.elementRef.appendChild(lt.createItemIcon(this[G],(s=this._menuStyles)==null?void 0:s.iconContainer)),this.elementRef.appendChild(lt.createItemText(this.dropupText,(r=this._menuStyles)==null?void 0:r[h]));}},{key:"assignDropupItemStyle",value:function assignDropupItemStyle(e,t){var s;this.elementRef.parentElement&&this._originalElementRef&&this.resetDropupItem(t),lt.addHighlightEvents(this._menu,this.elementRef),this.applyDropupContentStyles(e),Object.assign(this.elementRef[v],(s=e==null?void 0:e.item)==null?void 0:s[w]);var n=ce.processStateful((e==null?void 0:e.item)||{});Rt.add(this.elementRef,n),this.addClickListener();}},{key:"changeToDefault",value:function changeToDefault(e){var t,n,s,r,o,a;!e&&this._state===w||(this.elementRef[m].contains(lt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[w],(n=this.customStyles)==null?void 0:n[w]):(this.changeElementsByState(this._innerElements[w]),(s=this.customStyles)!=null&&s[H]&&xe.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[H]),(o=this.customStyles)!=null&&o[j]&&xe.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[j]),this.reapplyStateStyle(w,[H,j])),this.elementRef[m].remove(fe.DISABLED_CONTAINER_CLASS,fe.ACTIVE_CONTAINER_CLASS),this.elementRef[m].add(fe.DEFAULT_CONTAINER_CLASS),me.removeAriaDisabled(this.elementRef),this._state=w);}},{key:"changeToActive",value:function changeToActive(e){var t,n;!e&&this._state===H||(this.elementRef[m].contains(lt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[H],(n=this.customStyles)==null?void 0:n[H]):(this.changeElementsByState(this._innerElements[H]),this.reapplyStateStyle(H,[j,w])),this.elementRef[m].remove(fe.DISABLED_CONTAINER_CLASS,fe.DEFAULT_CONTAINER_CLASS),this.elementRef[m].add(fe.ACTIVE_CONTAINER_CLASS),me.removeAriaDisabled(this.elementRef),this._state=H);}},{key:"changeToDisabled",value:function changeToDisabled(e){var t,n,s,r,o,a;!e&&this._state===j||(this.elementRef[m].contains(lt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[j],(n=this.customStyles)==null?void 0:n[j]):(this.changeElementsByState(this._innerElements[j]),(s=this.customStyles)!=null&&s[H]&&xe.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[H]),(o=this.customStyles)!=null&&o[w]&&xe.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[w]),this.reapplyStateStyle(j,[w,H])),this.elementRef[m].remove(fe.ACTIVE_CONTAINER_CLASS,fe.DEFAULT_CONTAINER_CLASS),this.elementRef[m].add(fe.DISABLED_CONTAINER_CLASS),me.addAriaDisabled(this.elementRef),this._state=j);}// called after class is initialised
218
- },{key:"setDropupItem",value:function setDropupItem(e,t){this._menu=e,this.elementRef=t,this._originalElementRef=t.cloneNode(!0),this.changeState(this._state,!0);}},{key:"genStateInnerElements",value:function genStateInnerElements(e,t,n,s){var c,l,d,p;var r=this.createInnerElements(e,t,s);var o=(l=(c=s==null?void 0:s[t])==null?void 0:c[G])==null?void 0:l.content,a=(p=(d=s==null?void 0:s[t])==null?void 0:d[h])==null?void 0:p.content;if(o===void 0||a===void 0){var _ps$parseSVGTextEleme4=ps.parseSVGTextElements(n),u=_ps$parseSVGTextEleme4.svg,g=_ps$parseSVGTextEleme4[h],_ps$parseSVGTextEleme5=ps.parseSVGTextElements(r),y=_ps$parseSVGTextEleme5.svg,_=_ps$parseSVGTextEleme5[h],S=[];fe.addToInnerElements(S,o,u,y),fe.addToInnerElements(S,a,g,_),r=S;}return r;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=A();return e[m].add("input-button",fe.BUTTON_CLASS),e;}},{key:"addToInnerElements",value:function addToInnerElements(e,t,n,s){t===void 0&&n?e.push(n.cloneNode(!0)):s&&e.push(s);}},{key:"add",value:function add(e,t){var n=e.customButtons,s=e.focusInput,r=e.dropupStyles;n==null||n.forEach(function(o,a){var c={button:new fe(o,a+1,s,r==null?void 0:r.menu)};t["".concat(fe.INDICATOR_PREFIX).concat(a+1)]=c;});}}]);}(mn);fe.INDICATOR_PREFIX="custom",fe.BUTTON_CLASS="custom-button",fe.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",fe.DEFAULT_CONTAINER_CLASS="custom-button-container-default",fe.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var sn=fe;var Sh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M16 0c-8.836 0-16 7.163-16 16s7.163 16 16 16c8.837 0 16-7.163 16-16s-7.163-16-16-16zM16 30.032c-7.72 0-14-6.312-14-14.032s6.28-14 14-14 14 6.28 14 14-6.28 14.032-14 14.032zM23 15h-6v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1v6h-6c-0.552 0-1 0.448-1 1s0.448 1 1 1h6v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6h6c0.552 0 1-0.448 1-1s-0.448-1-1-1z\"></path>\n</svg>";var Is=/*#__PURE__*/function(){function Is(){_classCallCheck(this,Is);}return _createClass(Is,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var n=e.elementRef,s=t?n.children[0]:n.children[n.children.length-1];Is.focusSiblingItem(e,s,t,!0);}// isEdgeItem means is it a start or end item
219
- },{key:"focusSiblingItem",value:function focusSiblingItem(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var r=s?t:t[n?"nextSibling":"previousSibling"];r?(t.dispatchEvent(new MouseEvent(an)),r.dispatchEvent(new MouseEvent(Ps)),r.focus()):(t.dispatchEvent(new MouseEvent(an)),Is.focusItemWhenOnEdge(e,n));}}]);}();var Tr=/*#__PURE__*/function(){function Tr(e,t){var _this94=this;_classCallCheck(this,Tr);var n;this._isOpen=!0,this._styles=t,this.elementRef=Tr.createElement((n=this._styles)==null?void 0:n.container),this.close(),setTimeout(function(){return _this94.addWindowEvents(e);});}return _createClass(Tr,[{key:"open",value:function open(){this.elementRef[v].display="block",this._isOpen=!0;}},{key:"close",value:function close(){this._isOpen&&(this.elementRef[v].display="none",this._isOpen=!1);}},{key:"toggle",value:function toggle(){this._isOpen?this.close():this.open();}},{key:"addItem",value:function addItem(e){var t=lt.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
211
+ },{key:"adjustOutsideSubmit",value:function adjustOutsideSubmit(e,t,n){if(!(n[In].length>0||n[ft].length>0)){if(n[ve].length===0&&n[Le].length>0)return e[0][m].add(io),t[m].add(io),n[Le].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});if(n[Le].length===0&&n[ve].length>0)return e[3][m].add(ro),t[m].add(ro),n[ve].map(function(s){return s.button.elementRef[m].add("submit-button-enlarged");});}}// prettier-ignore
212
+ },{key:"set",value:function set(e,t,n,s){!!fs.adjustOutsideSubmit(t,n,s)||fs.adjustForOutsideButton(t,n,s),fs.adjustInputPadding(e,s);}}]);}();var Ln=/*#__PURE__*/function(){function Ln(){_classCallCheck(this,Ln);}return _createClass(Ln,null,[{key:"create",value:function create(){return Array.from({length:4}).map(function(e,t){var n=A();return n[m].add("input-button-container"),(t===0||t===3)&&n[m].add("outer-button-container"),(t===1||t===2)&&n[m].add("inner-button-container"),n;});}},{key:"add",value:function add(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 getContainerIndex(e){return e===Le?0:e===In?1:e===ft?2:3;}},{key:"addButton",value:function addButton(e,t,n){t[m].add(n);var s=Ln.getContainerIndex(n);e[s].appendChild(t),s===3&&t[m].add(ve);}}]);}();var co=["camera","gifs","images","audio","mixedFiles",st,"microphone"],Eh="<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 22 22\" fill=\"none\">\n <rect x=\"2.5\" y=\"2.5\" width=\"17\" height=\"17\" rx=\"2\" stroke=\"#000000\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>\n",Me=/*#__PURE__*/function(){function Me(){_classCallCheck(this,Me);}return _createClass(Me,null,[{key:"addHighlightEvents",value:function addHighlightEvents(e,t){t.addEventListener(ks,function(n){e.highlightedItem=n.target;}),t.addEventListener(cn,function(){e.highlightedItem=void 0;});}},{key:"addItemEvents",value:function addItemEvents(e,t,n,s){Rt.add(t,s),t.addEventListener(J,function(){n[J]();}),Me.addHighlightEvents(e,t);}},{key:"createItemText",value:function createItemText(e,t){var n=A();return Object.assign(n[v],t),n[m].add(Me.TEXT_CLASS),n.textContent=e||"File",n;}},{key:"createItemIcon",value:function createItemIcon(e,t){var n=A();return Object.assign(n[v],t),n[m].add(Me.ICON_CLASS),n.appendChild(e),n;}},{key:"populateItem",value:function populateItem(e,t,n){var s=e.elementRef,r=e.dropupText,o=e.svg,a=e.customStyles,c=s.children[0],l=a&&Object.values(a).find(function(d){var p;return((p=d[G])==null?void 0:p.content)==="";});c[m].contains(Et.INPUT_BUTTON_INNER_TEXT_CLASS)?(l||t.appendChild(Me.createItemIcon(o,n==null?void 0:n.iconContainer)),t.appendChild(Me.createItemText(c.textContent,n==null?void 0:n[h]))):(l||t.appendChild(Me.createItemIcon(s.children[0],n==null?void 0:n.iconContainer)),t.appendChild(Me.createItemText(r,n==null?void 0:n[h])));}},{key:"createItem",value:function createItem(e,t,n){var o;var s=A();Object.assign(s[v],(o=n==null?void 0:n.item)==null?void 0:o[w]),Me.populateItem(t,s,n),s[m].add(Me.MENU_ITEM_CLASS),s.tabIndex=0;var r=t.elementRef;if(t.isCustom)t.setDropupItem(e,s);else{var a=de.processStateful((n==null?void 0:n.item)||{});Me.addItemEvents(e,s,r,a);}return s;}}]);}();Me.MENU_ITEM_CLASS="dropup-menu-item",Me.CUSTOM_BUTTON_ITEM_CLASS="dropup-menu-item-custom-button",Me.TEXT_CLASS="dropup-menu-item-text",Me.ICON_CLASS="dropup-menu-item-icon";var lt=Me;var fe=/*#__PURE__*/function(_gn2){// prettier-ignore
213
+ function fe(e,t,n,s){var _this91;_classCallCheck(this,fe);var c,l,d,p,u,g;var r=((p=(d=(l=(c=e==null?void 0:e[R])==null?void 0:c.button)==null?void 0:l[w])==null?void 0:d[h])==null?void 0:p.content)||"Custom ".concat(t),o=Eh,a=ut.tryCreateConfig("Custom ".concat(t),e==null?void 0:e.tooltip);_this91=_callSuper(this,fe,[fe.createButtonElement(),o,e==null?void 0:e.position,a,((u=e==null?void 0:e[R])==null?void 0:u.button)||a&&{},r]),_this91._state=w,_this91.isCustom=!0,_this91._innerElements=_this91.createInnerElementsForStates(_this91.customStyles),_this91._menuStyles=s,_this91._onClick=e.onClick,_this91._dropupStyles=(g=e[R])==null?void 0:g.dropup,_this91.setSetState(e),_this91.addClickListener(n),_this91.changeState(e.initialState,!0);return _this91;}_inherits(fe,_gn2);return _createClass(fe,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="custom-icon",n=this.createInnerElements(t,w,e);return _defineProperty(_defineProperty(_defineProperty({},w,n),H,this.genStateInnerElements(t,H,n,e)),j,this.genStateInnerElements(t,j,n,e));}},{key:"setSetState",value:function setSetState(e){var _this92=this;e.setState=function(t){t===w&&_this92.changeToDefault(),t===H&&_this92.changeToActive(),t===j&&_this92.changeToDisabled();};}},{key:"addClickListener",value:function addClickListener(e){var _this93=this;z.assignButtonEvents(this.elementRef,function(){var n;var t=(n=_this93._onClick)==null?void 0:n.call(_this93,_this93._state);e==null||e(),(t===w||t===H||t===j)&&_this93.changeState(t);});}},{key:"changeState",value:function changeState(e,t){e===j?this.changeToDisabled(t):e===H?this.changeToActive(t):this.changeToDefault(t);}},{key:"applyDropupContentStyles",value:function applyDropupContentStyles(e){var t=Array.from(this.elementRef.children);if(e!=null&&e[h]){var _n16=t.find(function(s){return s[m].contains(lt.TEXT_CLASS);});_n16&&Object.assign(_n16[v],e[h]);}if(e!=null&&e.iconContainer){var _n17=t.find(function(s){return s[m].contains(lt.ICON_CLASS);});_n17&&Object.assign(_n17[v],e.iconContainer);}}},{key:"resetDropupItem",value:function resetDropupItem(e){var n,s,r;this.elementRef=oe.replaceElementWithNewClone(this.elementRef,this._originalElementRef),this.elementRef.innerHTML="",((n=e==null?void 0:e[G])==null?void 0:n.content)===""||this.elementRef.appendChild(lt.createItemIcon(this[G],(s=this._menuStyles)==null?void 0:s.iconContainer)),this.elementRef.appendChild(lt.createItemText(this.dropupText,(r=this._menuStyles)==null?void 0:r[h]));}},{key:"assignDropupItemStyle",value:function assignDropupItemStyle(e,t){var s;this.elementRef.parentElement&&this._originalElementRef&&this.resetDropupItem(t),lt.addHighlightEvents(this._menu,this.elementRef),this.applyDropupContentStyles(e),Object.assign(this.elementRef[v],(s=e==null?void 0:e.item)==null?void 0:s[w]);var n=de.processStateful((e==null?void 0:e.item)||{});Rt.add(this.elementRef,n),this.addClickListener();}},{key:"changeToDefault",value:function changeToDefault(e){var t,n,s,r,o,a;!e&&this._state===w||(this.elementRef[m].contains(lt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[w],(n=this.customStyles)==null?void 0:n[w]):(this.changeElementsByState(this._innerElements[w]),(s=this.customStyles)!=null&&s[H]&&xe.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[H]),(o=this.customStyles)!=null&&o[j]&&xe.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[j]),this.reapplyStateStyle(w,[H,j])),this.elementRef[m].remove(fe.DISABLED_CONTAINER_CLASS,fe.ACTIVE_CONTAINER_CLASS),this.elementRef[m].add(fe.DEFAULT_CONTAINER_CLASS),me.removeAriaDisabled(this.elementRef),this._state=w);}},{key:"changeToActive",value:function changeToActive(e){var t,n;!e&&this._state===H||(this.elementRef[m].contains(lt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[H],(n=this.customStyles)==null?void 0:n[H]):(this.changeElementsByState(this._innerElements[H]),this.reapplyStateStyle(H,[j,w])),this.elementRef[m].remove(fe.DISABLED_CONTAINER_CLASS,fe.DEFAULT_CONTAINER_CLASS),this.elementRef[m].add(fe.ACTIVE_CONTAINER_CLASS),me.removeAriaDisabled(this.elementRef),this._state=H);}},{key:"changeToDisabled",value:function changeToDisabled(e){var t,n,s,r,o,a;!e&&this._state===j||(this.elementRef[m].contains(lt.MENU_ITEM_CLASS)?this.assignDropupItemStyle((t=this._dropupStyles)==null?void 0:t[j],(n=this.customStyles)==null?void 0:n[j]):(this.changeElementsByState(this._innerElements[j]),(s=this.customStyles)!=null&&s[H]&&xe.unsetAllCSS(this.elementRef,(r=this.customStyles)==null?void 0:r[H]),(o=this.customStyles)!=null&&o[w]&&xe.unsetAllCSS(this.elementRef,(a=this.customStyles)==null?void 0:a[w]),this.reapplyStateStyle(j,[w,H])),this.elementRef[m].remove(fe.ACTIVE_CONTAINER_CLASS,fe.DEFAULT_CONTAINER_CLASS),this.elementRef[m].add(fe.DISABLED_CONTAINER_CLASS),me.addAriaDisabled(this.elementRef),this._state=j);}// called after class is initialised
214
+ },{key:"setDropupItem",value:function setDropupItem(e,t){this._menu=e,this.elementRef=t,this._originalElementRef=t.cloneNode(!0),this.changeState(this._state,!0);}},{key:"genStateInnerElements",value:function genStateInnerElements(e,t,n,s){var c,l,d,p;var r=this.createInnerElements(e,t,s);var o=(l=(c=s==null?void 0:s[t])==null?void 0:c[G])==null?void 0:l.content,a=(p=(d=s==null?void 0:s[t])==null?void 0:d[h])==null?void 0:p.content;if(o===void 0||a===void 0){var _us$parseSVGTextEleme4=us.parseSVGTextElements(n),u=_us$parseSVGTextEleme4.svg,g=_us$parseSVGTextEleme4[h],_us$parseSVGTextEleme5=us.parseSVGTextElements(r),y=_us$parseSVGTextEleme5.svg,_=_us$parseSVGTextEleme5[h],S=[];fe.addToInnerElements(S,o,u,y),fe.addToInnerElements(S,a,g,_),r=S;}return r;}}],[{key:"createButtonElement",value:function createButtonElement(){var e=A();return e[m].add("input-button",fe.BUTTON_CLASS),e;}},{key:"addToInnerElements",value:function addToInnerElements(e,t,n,s){t===void 0&&n?e.push(n.cloneNode(!0)):s&&e.push(s);}},{key:"add",value:function add(e,t){var n=e.customButtons,s=e.focusInput,r=e.dropupStyles;n==null||n.forEach(function(o,a){var c={button:new fe(o,a+1,s,r==null?void 0:r.menu)};t["".concat(fe.INDICATOR_PREFIX).concat(a+1)]=c;});}}]);}(gn);fe.INDICATOR_PREFIX="custom",fe.BUTTON_CLASS="custom-button",fe.DISABLED_CONTAINER_CLASS="custom-button-container-disabled",fe.DEFAULT_CONTAINER_CLASS="custom-button-container-default",fe.ACTIVE_CONTAINER_CLASS="custom-button-container-active";var rn=fe;var vh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M16 0c-8.836 0-16 7.163-16 16s7.163 16 16 16c8.837 0 16-7.163 16-16s-7.163-16-16-16zM16 30.032c-7.72 0-14-6.312-14-14.032s6.28-14 14-14 14 6.28 14 14-6.28 14.032-14 14.032zM23 15h-6v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1v6h-6c-0.552 0-1 0.448-1 1s0.448 1 1 1h6v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6h6c0.552 0 1-0.448 1-1s-0.448-1-1-1z\"></path>\n</svg>";var Rs=/*#__PURE__*/function(){function Rs(){_classCallCheck(this,Rs);}return _createClass(Rs,null,[{key:"focusItemWhenOnEdge",value:function focusItemWhenOnEdge(e,t){var n=e.elementRef,s=t?n.children[0]:n.children[n.children.length-1];Rs.focusSiblingItem(e,s,t,!0);}// isEdgeItem means is it a start or end item
215
+ },{key:"focusSiblingItem",value:function focusSiblingItem(e,t,n){var s=arguments.length>3&&arguments[3]!==undefined?arguments[3]:!1;var r=s?t:t[n?"nextSibling":"previousSibling"];r?(t.dispatchEvent(new MouseEvent(cn)),r.dispatchEvent(new MouseEvent(ks)),r.focus()):(t.dispatchEvent(new MouseEvent(cn)),Rs.focusItemWhenOnEdge(e,n));}}]);}();var Cr=/*#__PURE__*/function(){function Cr(e,t){var _this94=this;_classCallCheck(this,Cr);var n;this._isOpen=!0,this._styles=t,this.elementRef=Cr.createElement((n=this._styles)==null?void 0:n.container),this.close(),setTimeout(function(){return _this94.addWindowEvents(e);});}return _createClass(Cr,[{key:"open",value:function open(){this.elementRef[v].display="block",this._isOpen=!0;}},{key:"close",value:function close(){this._isOpen&&(this.elementRef[v].display="none",this._isOpen=!1);}},{key:"toggle",value:function toggle(){this._isOpen?this.close():this.open();}},{key:"addItem",value:function addItem(e){var t=lt.createItem(this,e,this._styles);this.elementRef.appendChild(t);}// prettier-ignore
220
216
  },{key:"addWindowEvents",value:function addWindowEvents(e){this.clickEvent=this.windowClick.bind(this,e),window.addEventListener(J,this.clickEvent),this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent);}},{key:"windowClick",value:function windowClick(e,t){var n;!e.isConnected&&this.clickEvent?window.removeEventListener(J,this.clickEvent):e.parentElement!==((n=t.target.shadowRoot)==null?void 0:n.children[0])&&this.close();}// prettier-ignore
221
- },{key:"windowKeyDown",value:function windowKeyDown(e,t){var n,s,r;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===_e.ESCAPE?(this.close(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent(an))):t.key===_e.ENTER?((s=this.highlightedItem)==null||s[J](),(r=this.highlightedItem)==null||r.dispatchEvent(new MouseEvent(an))):t.key===_e.ARROW_DOWN?Is.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],!0):t.key===_e.ARROW_UP&&Is.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[0],!1));}}],[{key:"createElement",value:function createElement(e){var t=A();return t.id=et,Object.assign(t[v],e),t;}}]);}();var Qt=/*#__PURE__*/function(_mn3){function Qt(e,t){var _this95;_classCallCheck(this,Qt);var r,o;var n=ut.tryCreateConfig("Options",(r=t==null?void 0:t.button)==null?void 0:r.tooltip);_this95=_callSuper(this,Qt,[Qt.createButtonElement(),Sh,void 0,n,_defineProperty({},R,(o=t==null?void 0:t.button)==null?void 0:o[R])]);var s=_this95.createInnerElementsForStates(_this95.customStyles);_this95._menu=new Tr(e,t==null?void 0:t.menu),_this95.addClickEvent(),_this95.buttonContainer=Qt.createButtonContainer(),_this95.changeElementsByState(s[R]),_this95.buttonContainer.appendChild(_this95.elementRef),_this95.elementRef[m].add(Qt.BUTTON_ICON_CLASS),_this95.buttonContainer.appendChild(_this95._menu.elementRef),_this95.reapplyStateStyle(R),_this95.addContainerEvents(e);return _this95;}_inherits(Qt,_mn3);return _createClass(Qt,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty({},R,this.createInnerElements("dropup-icon",R,e));}},{key:"addClickEvent",value:function addClickEvent(){var _this96=this;this.elementRef.onclick=this._menu.toggle.bind(this._menu),this.elementRef.onkeydown=function(e){e.key===_e.ENTER&&setTimeout(function(){_this96._menu.toggle();var t=_this96._menu.elementRef.children[0];t.focus(),t.dispatchEvent(new MouseEvent(Ps));});};}},{key:"addItem",value:function addItem(e){this._menu.addItem(e);}},{key:"addContainerEvents",value:function addContainerEvents(e){var _this97=this;e.addEventListener(J,function(t){var n=t.target[m];!n.contains(Qt.BUTTON_ICON_CLASS)&&!n.contains(sn.DISABLED_CONTAINER_CLASS)&&_this97._menu.close();});}}],[{key:"createButtonElement",value:function createButtonElement(){var e=A();return e[m].add("input-button"),e;}},{key:"createButtonContainer",value:function createButtonContainer(){var e=A();return e.id="dropup-container",e;}},{key:"getPosition",value:function getPosition(e,t){var n,s;return(n=t==null?void 0:t.button)!=null&&n.position?de.processPosition((s=t==null?void 0:t.button)==null?void 0:s.position):e[Le].length>0&&e[ve].length===0?ve:Le;}}]);}(mn);Qt.BUTTON_ICON_CLASS="dropup-button";var pi=Qt;var Ne=/*#__PURE__*/function(){function Ne(){_classCallCheck(this,Ne);}return _createClass(Ne,null,[{key:"addToDropup",value:// prettier-ignore
222
- function addToDropup(e,t,n,s){var r=new pi(n,s);lo.forEach(function(a){var c=t[et].findIndex(function(d){return d.buttonType===a;}),l=t[et][c];l&&(r.addItem(l.button),t[et].splice(c,1));}),t[et].forEach(function(_ref255){var a=_ref255.button;return r.addItem(a);});var o=pi.getPosition(t,s);Ln.addButton(e,r.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){[In,ft,Le,ve].forEach(function(s){var r=s;t[r].forEach(function(o){Ln.addButton(e,o.button.elementRef,r);});});}},{key:"setPosition",value:function setPosition(e,t,n){var s=_objectSpread(_objectSpread({},e[t]),{},{buttonType:t});n.push(s),delete e[t];}},{key:"createPositionsToButtonsObj",value:function createPositionsToButtonsObj(){return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},et,[]),Le,[]),In,[]),ft,[]),ve,[]);}// prettier-ignore
223
- },{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Ne.createPositionsToButtonsObj();Object.keys(e).forEach(function(s){var o;var r=(o=e[s])==null?void 0:o.button.position;r&&Ne.setPosition(e,s,t[r]);}),t[ft].length===0&&e.submit&&Ne.setPosition(e,st,t[ft]),t[ve].length===0&&(e.submit?Ne.setPosition(e,st,t[ve]):e.microphone?Ne.setPosition(e,ct,t[ve]):e.camera?Ne.setPosition(e,Fe,t[ve]):e["".concat(sn.INDICATOR_PREFIX,"1")]&&Ne.setPosition(e,"".concat(sn.INDICATOR_PREFIX,"1"),t[ve])),e.submit&&Ne.setPosition(e,st,t[Le].length===0?t[Le]:t[ft]),e.microphone&&Ne.setPosition(e,ct,t[Le].length===0?t[Le]:t[ft]);var n=Object.keys(e);return n.length>1||t[et].length>0?(lo.forEach(function(s){e[s]&&t[et].push(_objectSpread(_objectSpread({},e[s]),{},{buttonType:s}));}),n.forEach(function(s){var r=s;r.startsWith(sn.INDICATOR_PREFIX)&&e[r]&&t[et].push(_objectSpread(_objectSpread({},e[r]),{},{customType:r}));})):n.length===1&&Ne.setPosition(e,n[0],t[ve].length===0?t[ve]:t[Le]),t;}// prettier-ignore
224
- },{key:"addButtons",value:function addButtons(e,t,n,s){var r=Ne.generatePositionToButtons(t);return Ne.addToSideContainer(e,r),r[et].length>0&&Ne.addToDropup(e,r,n,s),r;}}]);}();var xh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M20 10.9696L11.9628 18.5497C10.9782 19.4783 9.64274 20 8.25028 20C6.85782 20 5.52239 19.4783 4.53777 18.5497C3.55315 17.6211 3 16.3616 3 15.0483C3 13.7351 3.55315 12.4756 4.53777 11.547L12.575 3.96687C13.2314 3.34779 14.1217 3 15.05 3C15.9783 3 16.8686 3.34779 17.525 3.96687C18.1814 4.58595 18.5502 5.4256 18.5502 6.30111C18.5502 7.17662 18.1814 8.01628 17.525 8.63535L9.47904 16.2154C9.15083 16.525 8.70569 16.6989 8.24154 16.6989C7.77738 16.6989 7.33224 16.525 7.00403 16.2154C6.67583 15.9059 6.49144 15.4861 6.49144 15.0483C6.49144 14.6106 6.67583 14.1907 7.00403 13.8812L14.429 6.88674\" stroke=\"#000000\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>",Ah="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20,15.2928932 L20,5.5 C20,4.67157288 19.3284271,4 18.5,4 L5.5,4 C4.67157288,4 4,4.67157288 4,5.5 L4,12.2928932 L7.14644661,9.14644661 C7.34170876,8.95118446 7.65829124,8.95118446 7.85355339,9.14644661 L13.5,14.7928932 L16.1464466,12.1464466 C16.3417088,11.9511845 16.6582912,11.9511845 16.8535534,12.1464466 L20,15.2928932 Z M20,16.7071068 L16.5,13.2071068 L13.8535534,15.8535534 C13.6582912,16.0488155 13.3417088,16.0488155 13.1464466,15.8535534 L7.5,10.2071068 L4,13.7071068 L4,18.5 C4,19.3284271 4.67157288,20 5.5,20 L18.5,20 C19.3284271,20 20,19.3284271 20,18.5 L20,16.7071068 Z M3,5.5 C3,4.11928813 4.11928813,3 5.5,3 L18.5,3 C19.8807119,3 21,4.11928813 21,5.5 L21,18.5 C21,19.8807119 19.8807119,21 18.5,21 L5.5,21 C4.11928813,21 3,19.8807119 3,18.5 L3,5.5 Z M15,6 L17,6 C17.5522847,6 18,6.44771525 18,7 L18,9 C18,9.55228475 17.5522847,10 17,10 L15,10 C14.4477153,10 14,9.55228475 14,9 L14,7 C14,6.44771525 14.4477153,6 15,6 Z M15,7 L15,9 L17,9 L17,7 L15,7 Z\"/>\n</svg>\n",wh="<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"-49.49 -49.49 593.87 593.87\" stroke-width=\"3.95908\" transform=\"rotate(0)\">\n <g stroke-width=\"0\"></g>\n <g stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"0.98977\"></g>\n <g>\n <g>\n <g>\n <path d=\"M163.205,76.413v293.301c-3.434-3.058-7.241-5.867-11.486-8.339c-21.38-12.452-49.663-15.298-77.567-7.846 c-49.038,13.096-80.904,54.519-71.038,92.337c4.019,15.404,14.188,28.221,29.404,37.087c13.553,7.894,29.87,11.933,47.115,11.933 c9.962,0,20.231-1.356,30.447-4.087c42.74-11.406,72.411-44.344,72.807-77.654h0.011v-0.162c0.002-0.166,0-0.331,0-0.496V187.072 l290.971-67.3v178.082c-3.433-3.055-7.238-5.863-11.481-8.334c-21.385-12.452-49.654-15.308-77.567-7.846 c-49.038,13.087-80.904,54.519-71.038,92.356c4.019,15.385,14.183,28.212,29.404,37.067c13.548,7.894,29.875,11.933,47.115,11.933 c9.962,0,20.231-1.356,30.452-4.087c42.74-11.413,72.411-44.346,72.804-77.654h0.004v-0.065c0.003-0.236,0.001-0.469,0-0.704V0 L163.205,76.413z M104.999,471.779c-22.543,6.038-45.942,3.846-62.572-5.846c-10.587-6.163-17.591-14.817-20.255-25.038 c-7.144-27.375,18.452-58.029,57.062-68.346c8.409-2.25,16.938-3.346,25.188-3.346c13.87,0,26.962,3.115,37.389,9.192 c10.587,6.163,17.591,14.817,20.255,25.029c0.809,3.102,1.142,6.248,1.139,9.4v0.321h0.014 C162.99,437.714,139.082,462.678,104.999,471.779z M182.898,166.853V92.067l290.971-67.298v74.784L182.898,166.853z M415.677,399.923c-22.558,6.038-45.942,3.837-62.587-5.846c-10.587-6.163-17.587-14.817-20.25-25.019 c-7.144-27.385,18.452-58.058,57.058-68.365c8.414-2.25,16.942-3.346,25.192-3.346c13.875,0,26.962,3.115,37.385,9.192 c10.596,6.163,17.596,14.817,20.26,25.029v0.01c0.796,3.05,1.124,6.144,1.135,9.244v0.468h0.02 C473.668,365.851,449.763,390.814,415.677,399.923z\">\n </path>\n </g>\n </g>\n </g>\n</svg>",Ch="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 5.9266752 5.6408391\" height=\"21.31971\" width=\"22.4\">\n <g>\n <path d=\"m 5.2564627,1.548212 c -3.1136005,-0.4796804 -1.5568006,-0.2398402 0,0 z M 2.0001198,2.0922063 c 0.1556781,0 0.2657489,0.020893 0.3917849,0.080366 0.081154,0.038347 0.1153492,0.134065 0.076377,0.2138602 -0.038973,0.07979 -0.1363527,0.1134129 -0.2175069,0.075091 -0.078199,-0.036919 -0.1407455,-0.048792 -0.250655,-0.048792 -0.2260486,0 -0.3921482,0.2042182 -0.3921482,0.4801409 0,0.2761822 0.1663188,0.4810688 0.3921482,0.4810688 0.1117901,0 0.2064255,-0.046133 0.255659,-0.1284198 l 0.00162,-0.00389 V 3.0534032 l -0.098011,1.75e-4 c -0.081844,0 -0.1495979,-0.059305 -0.1612403,-0.1365887 l -0.00175,-0.023683 c 0,-0.08047 0.060311,-0.1470874 0.1389194,-0.1585331 l 0.024085,-0.00195 h 0.2612303 c 0.081842,0 0.149598,0.059305 0.1612404,0.1365891 l 0.00175,0.023683 -3.398e-4,0.3968809 v 0 l -0.00168,0.014211 v 0 l -0.00553,0.023034 v 0 l -0.00532,0.014145 c -0.098178,0.22826 -0.3236506,0.3528713 -0.5706303,0.3528713 -0.4240855,0 -0.7181621,-0.3622714 -0.7181621,-0.8016063 0,-0.4391857 0.2940275,-0.8006848 0.7181621,-0.8006848 z m 1.2034759,0.031275 c 0.081843,0 0.1495977,0.059305 0.1612403,0.1365891 l 0.00175,0.023683 v 1.2211775 c 0,0.088516 -0.07298,0.1602721 -0.1630073,0.1602721 -0.081841,0 -0.1495972,-0.059305 -0.1612397,-0.1365892 L 3.040589,3.5049308 V 2.2837527 c 0,-0.088516 0.07298,-0.1602721 0.1630067,-0.1602714 z m 0.7813442,0 0.5209469,0.00195 c 0.090025,3.048e-4 0.1627543,0.072306 0.1624458,0.1608234 -2.809e-4,0.08047 -0.06083,0.1468798 -0.1394772,0.158066 l -0.024092,0.00195 -0.3575326,-0.0013 v 0.4497782 l 0.2928918,2.27e-4 c 0.081842,0 0.1495979,0.059305 0.1612403,0.136589 l 0.00175,0.023683 c 0,0.080469 -0.06031,0.1470871 -0.1389193,0.1585393 l -0.024092,0.00195 -0.2928919,-2.336e-4 1.563e-4,0.2860316 c 0,0.080471 -0.06031,0.1470873 -0.1389193,0.1585395 l -0.024085,0.00195 c -0.081843,0 -0.1495979,-0.059305 -0.1612403,-0.1365826 l -0.00175,-0.023691 V 2.2841354 c 2.798e-4,-0.08047 0.060829,-0.1468797 0.1394758,-0.1580594 z\"/>\n <path d=\"m 5.0894191,1.0943261 c 0,-0.21918999 -0.177687,-0.39686999 -0.396876,-0.39686999 h -3.43959 c -0.2191879,0 -0.391262,0.1777519 -0.3968759,0.39686999 l -0.027082,3.4379266 c 0.040152,0.2939927 0.4235456,0.409415 0.4235456,0.409415 l 3.4785583,-0.00851 c 0,0 0.3008506,-0.1402998 0.3236271,-0.4201576 0.042911,-0.5272495 0.034693,-1.6106146 0.034693,-3.4186761 z m -4.49792494,0 c 0,-0.36530999 0.29614504,-0.66145999 0.66145894,-0.66145999 h 3.43959 c 0.365314,0 0.66146,0.29615 0.66146,0.66145999 v 3.43959 c 0,0.36532 -0.296146,0.66146 -0.66146,0.66146 h -3.43959 c -0.3653139,0 -0.66145894,-0.29614 -0.66145894,-0.66146 z\"/>\n </g>\n</svg>\n",Th=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},ee,{id:"upload-images-icon",svgString:Ah,dropupText:"Image"}),Cn,{id:"upload-gifs-icon",svgString:Ch,dropupText:"GIF"}),$,{id:"upload-audio-icon",svgString:wh,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:xh,dropupText:"File"});var Ci=/*#__PURE__*/function(_mn4){function Ci(e){var _this98;_classCallCheck(this,Ci);(e==null?void 0:e.position)===et&&(e.position=ve);var t=ut.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this98=_callSuper(this,Ci,[Ci.createMicrophoneElement(),ia,e==null?void 0:e.position,t,e]),_this98.isActive=!1,_this98._innerElements=_this98.createInnerElementsForStates(_this98.customStyles),_this98.changeToDefault();return _this98;}_inherits(Ci,_mn4);return _createClass(Ci,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},w,this.createInnerElements(t,w,e)),H,this.createInnerElements(t,H,e)),Un,this.createInnerElements(t,Un,e)),gn,this.createInnerElements(t,gn,e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements[H]),this.toggleIconFilter(H),this.reapplyStateStyle(H,[w,gn]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[w]),this.toggleIconFilter(w),this.reapplyStateStyle(w,[H,gn]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements[gn]),this.toggleIconFilter("command"),this.reapplyStateStyle(gn,[H]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements[Un]),this.elementRef[m].add("".concat(Un,"-microphone")),this.reapplyStateStyle(Un,[H]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()===G)switch(e){case w:t[m].remove("active-microphone-icon","command-microphone-icon"),t[m].add("default-microphone-icon");break;case H:t[m].remove("default-microphone-icon","command-microphone-icon"),t[m].add("active-microphone-icon");break;case"command":t[m].remove("active-microphone-icon","default-microphone-icon"),t[m].add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=A();return e.id="microphone-button",e[m].add("input-button"),e;}}]);}(mn);function Rh(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i["default"]:i;}var $s={},qn={},Gn={},zn={},Vn={},ho;function Ti(){if(ho)return Vn;ho=1,Object.defineProperty(Vn,"__esModule",{value:!0}),Vn.Text=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"capitalize",value:function capitalize(t){return t.replace(i.FIRST_CHAR_REGEX,function(n){return n.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(t){return t.replace(i.DOUBLE_LINE,"<p></p>").replace(i.ONE_LINE,"<br>");}},{key:"isCharDefined",value:function isCharDefined(t){return t!==void 0&&t!==" "&&t!==" "&&t!=="\n"&&t!=="";}},{key:"breakupIntoWordsArr",value:function breakupIntoWordsArr(t){return t.split(/(\W+)/);}}]);}();return Vn.Text=i,i.FIRST_CHAR_REGEX=/\S/,i.DOUBLE_LINE=/\n\n/g,i.ONE_LINE=/\n/g,Vn;}var uo;function ua(){if(uo)return zn;uo=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.Translate=void 0;var i=Ti();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"translate",value:function translate(n,s){var r=i.Text.breakupIntoWordsArr(n);for(var o=0;o<r.length;o+=1)s[r[o]]&&(r[o]=s[r[o]]);return r.join("");}}]);}();return zn.Translate=e,zn;}var po;function Ih(){if(po)return Gn;po=1,Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.WebSpeechTranscript=void 0;var i=ua();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:function extract(n,s,r){var o="";for(var a=n.resultIndex;a<n.results.length;++a){var c=n.results[a][0].transcript;r&&(c=i.Translate.translate(c,r)),n.results[a].isFinal?s+=c:o+=c;}return{interimTranscript:o,finalTranscript:s,newText:o||s};}},{key:"extractSafari",value:function extractSafari(n,s,r){var o="";for(var c=n.resultIndex;c<n.results.length;++c){var l=n.results[c][0].transcript;r&&(l=i.Translate.translate(l,r)),o+=l;}return{interimTranscript:"",finalTranscript:o,newText:o};}}]);}();return Gn.WebSpeechTranscript=e,Gn;}var Kn={},fo;function Rr(){if(fo)return Kn;fo=1,Object.defineProperty(Kn,"__esModule",{value:!0}),Kn.Browser=void 0;var i=/*#__PURE__*/_createClass(function i(){_classCallCheck(this,i);});return Kn.Browser=i,i.IS_SAFARI=function(){return i._IS_SAFARI===void 0&&(i._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),i._IS_SAFARI;},Kn;}var Wn={},Xn={},mo;function Mh(){if(mo)return Xn;mo=1,Object.defineProperty(Xn,"__esModule",{value:!0}),Xn.EventListeners=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(t,n){return Array.isArray(t)?t.find(function(s){return n===s;}):n===t?t:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(t){var _this99=this;t.element&&i.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(i.KEY_DOWN_TIMEOUT!==null&&clearTimeout(i.KEY_DOWN_TIMEOUT),i.KEY_DOWN_TIMEOUT=setTimeout(function(){i.KEY_DOWN_TIMEOUT=null,_this99.resetRecording(t);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(t,n){this.mouseDownElement=i.getElementIfFocusedOnAvailable(t,n.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0;}},{key:"add",value:function add(t,n){var s=(n==null?void 0:n.insertInCursorLocation)===void 0||(n==null?void 0:n.insertInCursorLocation);n!=null&&n.element&&s&&(t.mouseDownEvent=i.mouseDownWindow.bind(t,n.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=i.mouseUpWindow.bind(t,n),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=i.keyDownWindow.bind(t,n),document.addEventListener("keydown",t.keyDownEvent));}},{key:"remove",value:function remove(t){document.removeEventListener("mousedown",t.mouseDownEvent),document.removeEventListener("mouseup",t.mouseUpEvent),document.removeEventListener("keydown",t.keyDownEvent);}}]);}();return Xn.EventListeners=i,i.KEY_DOWN_TIMEOUT=null,Xn;}var Zn={},go;function kh(){if(go)return Zn;go=1,Object.defineProperty(Zn,"__esModule",{value:!0}),Zn.PreResultUtils=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"process",value:function process(t,n,s,r,o){var a=r==null?void 0:r(n,s);return a?(setTimeout(function(){a.restart?t.resetRecording(o):a.stop&&t.stop();}),(a.stop||a.restart)&&a.removeNewText):!1;}}]);}();return Zn.PreResultUtils=i,Zn;}var Yn={},Jn={},bo;function pa(){if(bo)return Jn;bo=1,Object.defineProperty(Jn,"__esModule",{value:!0}),Jn.AutoScroll=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(t,n){n&&!t.isCursorAtEnd&&(t.endPadding="",t.scrollingSpan.innerHTML="&nbsp;");}},{key:"scrollGeneric",value:function scrollGeneric(t,n){t.isCursorAtEnd?n.scrollTop=n.scrollHeight:t.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
217
+ },{key:"windowKeyDown",value:function windowKeyDown(e,t){var n,s,r;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===_e.ESCAPE?(this.close(),(n=this.highlightedItem)==null||n.dispatchEvent(new MouseEvent(cn))):t.key===_e.ENTER?((s=this.highlightedItem)==null||s[J](),(r=this.highlightedItem)==null||r.dispatchEvent(new MouseEvent(cn))):t.key===_e.ARROW_DOWN?Rs.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[this.elementRef.children.length-1],!0):t.key===_e.ARROW_UP&&Rs.focusSiblingItem(this,this.highlightedItem||this.elementRef.children[0],!1));}}],[{key:"createElement",value:function createElement(e){var t=A();return t.id=et,Object.assign(t[v],e),t;}}]);}();var en=/*#__PURE__*/function(_gn3){function en(e,t){var _this95;_classCallCheck(this,en);var r,o;var n=ut.tryCreateConfig("Options",(r=t==null?void 0:t.button)==null?void 0:r.tooltip);_this95=_callSuper(this,en,[en.createButtonElement(),vh,void 0,n,_defineProperty({},R,(o=t==null?void 0:t.button)==null?void 0:o[R])]);var s=_this95.createInnerElementsForStates(_this95.customStyles);_this95._menu=new Cr(e,t==null?void 0:t.menu),_this95.addClickEvent(),_this95.buttonContainer=en.createButtonContainer(),_this95.changeElementsByState(s[R]),_this95.buttonContainer.appendChild(_this95.elementRef),_this95.elementRef[m].add(en.BUTTON_ICON_CLASS),_this95.buttonContainer.appendChild(_this95._menu.elementRef),_this95.reapplyStateStyle(R),_this95.addContainerEvents(e);return _this95;}_inherits(en,_gn3);return _createClass(en,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty({},R,this.createInnerElements("dropup-icon",R,e));}},{key:"addClickEvent",value:function addClickEvent(){var _this96=this;this.elementRef.onclick=this._menu.toggle.bind(this._menu),this.elementRef.onkeydown=function(e){e.key===_e.ENTER&&setTimeout(function(){_this96._menu.toggle();var t=_this96._menu.elementRef.children[0];t.focus(),t.dispatchEvent(new MouseEvent(ks));});};}},{key:"addItem",value:function addItem(e){this._menu.addItem(e);}},{key:"addContainerEvents",value:function addContainerEvents(e){var _this97=this;e.addEventListener(J,function(t){var n=t.target[m];!n.contains(en.BUTTON_ICON_CLASS)&&!n.contains(rn.DISABLED_CONTAINER_CLASS)&&_this97._menu.close();});}}],[{key:"createButtonElement",value:function createButtonElement(){var e=A();return e[m].add("input-button"),e;}},{key:"createButtonContainer",value:function createButtonContainer(){var e=A();return e.id="dropup-container",e;}},{key:"getPosition",value:function getPosition(e,t){var n,s;return(n=t==null?void 0:t.button)!=null&&n.position?le.processPosition((s=t==null?void 0:t.button)==null?void 0:s.position):e[Le].length>0&&e[ve].length===0?ve:Le;}}]);}(gn);en.BUTTON_ICON_CLASS="dropup-button";var hi=en;var Ne=/*#__PURE__*/function(){function Ne(){_classCallCheck(this,Ne);}return _createClass(Ne,null,[{key:"addToDropup",value:// prettier-ignore
218
+ function addToDropup(e,t,n,s){var r=new hi(n,s);co.forEach(function(a){var c=t[et].findIndex(function(d){return d.buttonType===a;}),l=t[et][c];l&&(r.addItem(l.button),t[et].splice(c,1));}),t[et].forEach(function(_ref259){var a=_ref259.button;return r.addItem(a);});var o=hi.getPosition(t,s);Ln.addButton(e,r.buttonContainer,o),t[o].push({});}},{key:"addToSideContainer",value:function addToSideContainer(e,t){[In,ft,Le,ve].forEach(function(s){var r=s;t[r].forEach(function(o){Ln.addButton(e,o.button.elementRef,r);});});}},{key:"setPosition",value:function setPosition(e,t,n){var s=_objectSpread(_objectSpread({},e[t]),{},{buttonType:t});n.push(s),delete e[t];}},{key:"createPositionsToButtonsObj",value:function createPositionsToButtonsObj(){return _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},et,[]),Le,[]),In,[]),ft,[]),ve,[]);}// prettier-ignore
219
+ },{key:"generatePositionToButtons",value:function generatePositionToButtons(e){var t=Ne.createPositionsToButtonsObj();Object.keys(e).forEach(function(s){var o;var r=(o=e[s])==null?void 0:o.button.position;r&&Ne.setPosition(e,s,t[r]);}),t[ft].length===0&&e.submit&&Ne.setPosition(e,st,t[ft]),t[ve].length===0&&(e.submit?Ne.setPosition(e,st,t[ve]):e.microphone?Ne.setPosition(e,ct,t[ve]):e.camera?Ne.setPosition(e,Fe,t[ve]):e["".concat(rn.INDICATOR_PREFIX,"1")]&&Ne.setPosition(e,"".concat(rn.INDICATOR_PREFIX,"1"),t[ve])),e.submit&&Ne.setPosition(e,st,t[Le].length===0?t[Le]:t[ft]),e.microphone&&Ne.setPosition(e,ct,t[Le].length===0?t[Le]:t[ft]);var n=Object.keys(e);return n.length>1||t[et].length>0?(co.forEach(function(s){e[s]&&t[et].push(_objectSpread(_objectSpread({},e[s]),{},{buttonType:s}));}),n.forEach(function(s){var r=s;r.startsWith(rn.INDICATOR_PREFIX)&&e[r]&&t[et].push(_objectSpread(_objectSpread({},e[r]),{},{customType:r}));})):n.length===1&&Ne.setPosition(e,n[0],t[ve].length===0?t[ve]:t[Le]),t;}// prettier-ignore
220
+ },{key:"addButtons",value:function addButtons(e,t,n,s){var r=Ne.generatePositionToButtons(t);return Ne.addToSideContainer(e,r),r[et].length>0&&Ne.addToDropup(e,r,n,s),r;}}]);}();var Sh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M20 10.9696L11.9628 18.5497C10.9782 19.4783 9.64274 20 8.25028 20C6.85782 20 5.52239 19.4783 4.53777 18.5497C3.55315 17.6211 3 16.3616 3 15.0483C3 13.7351 3.55315 12.4756 4.53777 11.547L12.575 3.96687C13.2314 3.34779 14.1217 3 15.05 3C15.9783 3 16.8686 3.34779 17.525 3.96687C18.1814 4.58595 18.5502 5.4256 18.5502 6.30111C18.5502 7.17662 18.1814 8.01628 17.525 8.63535L9.47904 16.2154C9.15083 16.525 8.70569 16.6989 8.24154 16.6989C7.77738 16.6989 7.33224 16.525 7.00403 16.2154C6.67583 15.9059 6.49144 15.4861 6.49144 15.0483C6.49144 14.6106 6.67583 14.1907 7.00403 13.8812L14.429 6.88674\" stroke=\"#000000\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>",xh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20,15.2928932 L20,5.5 C20,4.67157288 19.3284271,4 18.5,4 L5.5,4 C4.67157288,4 4,4.67157288 4,5.5 L4,12.2928932 L7.14644661,9.14644661 C7.34170876,8.95118446 7.65829124,8.95118446 7.85355339,9.14644661 L13.5,14.7928932 L16.1464466,12.1464466 C16.3417088,11.9511845 16.6582912,11.9511845 16.8535534,12.1464466 L20,15.2928932 Z M20,16.7071068 L16.5,13.2071068 L13.8535534,15.8535534 C13.6582912,16.0488155 13.3417088,16.0488155 13.1464466,15.8535534 L7.5,10.2071068 L4,13.7071068 L4,18.5 C4,19.3284271 4.67157288,20 5.5,20 L18.5,20 C19.3284271,20 20,19.3284271 20,18.5 L20,16.7071068 Z M3,5.5 C3,4.11928813 4.11928813,3 5.5,3 L18.5,3 C19.8807119,3 21,4.11928813 21,5.5 L21,18.5 C21,19.8807119 19.8807119,21 18.5,21 L5.5,21 C4.11928813,21 3,19.8807119 3,18.5 L3,5.5 Z M15,6 L17,6 C17.5522847,6 18,6.44771525 18,7 L18,9 C18,9.55228475 17.5522847,10 17,10 L15,10 C14.4477153,10 14,9.55228475 14,9 L14,7 C14,6.44771525 14.4477153,6 15,6 Z M15,7 L15,9 L17,9 L17,7 L15,7 Z\"/>\n</svg>\n",Ah="<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"-49.49 -49.49 593.87 593.87\" stroke-width=\"3.95908\" transform=\"rotate(0)\">\n <g stroke-width=\"0\"></g>\n <g stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"0.98977\"></g>\n <g>\n <g>\n <g>\n <path d=\"M163.205,76.413v293.301c-3.434-3.058-7.241-5.867-11.486-8.339c-21.38-12.452-49.663-15.298-77.567-7.846 c-49.038,13.096-80.904,54.519-71.038,92.337c4.019,15.404,14.188,28.221,29.404,37.087c13.553,7.894,29.87,11.933,47.115,11.933 c9.962,0,20.231-1.356,30.447-4.087c42.74-11.406,72.411-44.344,72.807-77.654h0.011v-0.162c0.002-0.166,0-0.331,0-0.496V187.072 l290.971-67.3v178.082c-3.433-3.055-7.238-5.863-11.481-8.334c-21.385-12.452-49.654-15.308-77.567-7.846 c-49.038,13.087-80.904,54.519-71.038,92.356c4.019,15.385,14.183,28.212,29.404,37.067c13.548,7.894,29.875,11.933,47.115,11.933 c9.962,0,20.231-1.356,30.452-4.087c42.74-11.413,72.411-44.346,72.804-77.654h0.004v-0.065c0.003-0.236,0.001-0.469,0-0.704V0 L163.205,76.413z M104.999,471.779c-22.543,6.038-45.942,3.846-62.572-5.846c-10.587-6.163-17.591-14.817-20.255-25.038 c-7.144-27.375,18.452-58.029,57.062-68.346c8.409-2.25,16.938-3.346,25.188-3.346c13.87,0,26.962,3.115,37.389,9.192 c10.587,6.163,17.591,14.817,20.255,25.029c0.809,3.102,1.142,6.248,1.139,9.4v0.321h0.014 C162.99,437.714,139.082,462.678,104.999,471.779z M182.898,166.853V92.067l290.971-67.298v74.784L182.898,166.853z M415.677,399.923c-22.558,6.038-45.942,3.837-62.587-5.846c-10.587-6.163-17.587-14.817-20.25-25.019 c-7.144-27.385,18.452-58.058,57.058-68.365c8.414-2.25,16.942-3.346,25.192-3.346c13.875,0,26.962,3.115,37.385,9.192 c10.596,6.163,17.596,14.817,20.26,25.029v0.01c0.796,3.05,1.124,6.144,1.135,9.244v0.468h0.02 C473.668,365.851,449.763,390.814,415.677,399.923z\">\n </path>\n </g>\n </g>\n </g>\n</svg>",wh="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"0 0 5.9266752 5.6408391\" height=\"21.31971\" width=\"22.4\">\n <g>\n <path d=\"m 5.2564627,1.548212 c -3.1136005,-0.4796804 -1.5568006,-0.2398402 0,0 z M 2.0001198,2.0922063 c 0.1556781,0 0.2657489,0.020893 0.3917849,0.080366 0.081154,0.038347 0.1153492,0.134065 0.076377,0.2138602 -0.038973,0.07979 -0.1363527,0.1134129 -0.2175069,0.075091 -0.078199,-0.036919 -0.1407455,-0.048792 -0.250655,-0.048792 -0.2260486,0 -0.3921482,0.2042182 -0.3921482,0.4801409 0,0.2761822 0.1663188,0.4810688 0.3921482,0.4810688 0.1117901,0 0.2064255,-0.046133 0.255659,-0.1284198 l 0.00162,-0.00389 V 3.0534032 l -0.098011,1.75e-4 c -0.081844,0 -0.1495979,-0.059305 -0.1612403,-0.1365887 l -0.00175,-0.023683 c 0,-0.08047 0.060311,-0.1470874 0.1389194,-0.1585331 l 0.024085,-0.00195 h 0.2612303 c 0.081842,0 0.149598,0.059305 0.1612404,0.1365891 l 0.00175,0.023683 -3.398e-4,0.3968809 v 0 l -0.00168,0.014211 v 0 l -0.00553,0.023034 v 0 l -0.00532,0.014145 c -0.098178,0.22826 -0.3236506,0.3528713 -0.5706303,0.3528713 -0.4240855,0 -0.7181621,-0.3622714 -0.7181621,-0.8016063 0,-0.4391857 0.2940275,-0.8006848 0.7181621,-0.8006848 z m 1.2034759,0.031275 c 0.081843,0 0.1495977,0.059305 0.1612403,0.1365891 l 0.00175,0.023683 v 1.2211775 c 0,0.088516 -0.07298,0.1602721 -0.1630073,0.1602721 -0.081841,0 -0.1495972,-0.059305 -0.1612397,-0.1365892 L 3.040589,3.5049308 V 2.2837527 c 0,-0.088516 0.07298,-0.1602721 0.1630067,-0.1602714 z m 0.7813442,0 0.5209469,0.00195 c 0.090025,3.048e-4 0.1627543,0.072306 0.1624458,0.1608234 -2.809e-4,0.08047 -0.06083,0.1468798 -0.1394772,0.158066 l -0.024092,0.00195 -0.3575326,-0.0013 v 0.4497782 l 0.2928918,2.27e-4 c 0.081842,0 0.1495979,0.059305 0.1612403,0.136589 l 0.00175,0.023683 c 0,0.080469 -0.06031,0.1470871 -0.1389193,0.1585393 l -0.024092,0.00195 -0.2928919,-2.336e-4 1.563e-4,0.2860316 c 0,0.080471 -0.06031,0.1470873 -0.1389193,0.1585395 l -0.024085,0.00195 c -0.081843,0 -0.1495979,-0.059305 -0.1612403,-0.1365826 l -0.00175,-0.023691 V 2.2841354 c 2.798e-4,-0.08047 0.060829,-0.1468797 0.1394758,-0.1580594 z\"/>\n <path d=\"m 5.0894191,1.0943261 c 0,-0.21918999 -0.177687,-0.39686999 -0.396876,-0.39686999 h -3.43959 c -0.2191879,0 -0.391262,0.1777519 -0.3968759,0.39686999 l -0.027082,3.4379266 c 0.040152,0.2939927 0.4235456,0.409415 0.4235456,0.409415 l 3.4785583,-0.00851 c 0,0 0.3008506,-0.1402998 0.3236271,-0.4201576 0.042911,-0.5272495 0.034693,-1.6106146 0.034693,-3.4186761 z m -4.49792494,0 c 0,-0.36530999 0.29614504,-0.66145999 0.66145894,-0.66145999 h 3.43959 c 0.365314,0 0.66146,0.29615 0.66146,0.66145999 v 3.43959 c 0,0.36532 -0.296146,0.66146 -0.66146,0.66146 h -3.43959 c -0.3653139,0 -0.66145894,-0.29614 -0.66145894,-0.66146 z\"/>\n </g>\n</svg>\n",Ch=_defineProperty(_defineProperty(_defineProperty(_defineProperty({},ee,{id:"upload-images-icon",svgString:xh,dropupText:"Image"}),Cn,{id:"upload-gifs-icon",svgString:wh,dropupText:"GIF"}),$,{id:"upload-audio-icon",svgString:Ah,dropupText:"Audio"}),"mixedFiles",{id:"upload-mixed-files-icon",svgString:Sh,dropupText:"File"});var Ai=/*#__PURE__*/function(_gn4){function Ai(e){var _this98;_classCallCheck(this,Ai);(e==null?void 0:e.position)===et&&(e.position=ve);var t=ut.tryCreateConfig("Microphone",e==null?void 0:e.tooltip);_this98=_callSuper(this,Ai,[Ai.createMicrophoneElement(),sa,e==null?void 0:e.position,t,e]),_this98.isActive=!1,_this98._innerElements=_this98.createInnerElementsForStates(_this98.customStyles),_this98.changeToDefault();return _this98;}_inherits(Ai,_gn4);return _createClass(Ai,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){var t="microphone-icon";return _defineProperty(_defineProperty(_defineProperty(_defineProperty({},w,this.createInnerElements(t,w,e)),H,this.createInnerElements(t,H,e)),Un,this.createInnerElements(t,Un,e)),bn,this.createInnerElements(t,bn,e));}},{key:"changeToActive",value:function changeToActive(){this.changeElementsByState(this._innerElements[H]),this.toggleIconFilter(H),this.reapplyStateStyle(H,[w,bn]),this.isActive=!0;}},{key:"changeToDefault",value:function changeToDefault(){this.changeElementsByState(this._innerElements[w]),this.toggleIconFilter(w),this.reapplyStateStyle(w,[H,bn]),this.isActive=!1;}},{key:"changeToCommandMode",value:function changeToCommandMode(){this.changeElementsByState(this._innerElements[bn]),this.toggleIconFilter("command"),this.reapplyStateStyle(bn,[H]);}},{key:"changeToUnsupported",value:function changeToUnsupported(){this.changeElementsByState(this._innerElements[Un]),this.elementRef[m].add("".concat(Un,"-microphone")),this.reapplyStateStyle(Un,[H]);}},{key:"toggleIconFilter",value:function toggleIconFilter(e){var t=this.elementRef.children[0];if(t.tagName.toLocaleLowerCase()===G)switch(e){case w:t[m].remove("active-microphone-icon","command-microphone-icon"),t[m].add("default-microphone-icon");break;case H:t[m].remove("default-microphone-icon","command-microphone-icon"),t[m].add("active-microphone-icon");break;case"command":t[m].remove("active-microphone-icon","default-microphone-icon"),t[m].add("command-microphone-icon");break;}}}],[{key:"createMicrophoneElement",value:function createMicrophoneElement(){var e=A();return e.id="microphone-button",e[m].add("input-button"),e;}}]);}(gn);function Th(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i["default"]:i;}var js={},qn={},Gn={},zn={},Vn={},lo;function wi(){if(lo)return Vn;lo=1,Object.defineProperty(Vn,"__esModule",{value:!0}),Vn.Text=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"capitalize",value:function capitalize(t){return t.replace(i.FIRST_CHAR_REGEX,function(n){return n.toUpperCase();});}},{key:"lineBreak",value:function lineBreak(t){return t.replace(i.DOUBLE_LINE,"<p></p>").replace(i.ONE_LINE,"<br>");}},{key:"isCharDefined",value:function isCharDefined(t){return t!==void 0&&t!==" "&&t!==" "&&t!=="\n"&&t!=="";}},{key:"breakupIntoWordsArr",value:function breakupIntoWordsArr(t){return t.split(/(\W+)/);}}]);}();return Vn.Text=i,i.FIRST_CHAR_REGEX=/\S/,i.DOUBLE_LINE=/\n\n/g,i.ONE_LINE=/\n/g,Vn;}var ho;function ha(){if(ho)return zn;ho=1,Object.defineProperty(zn,"__esModule",{value:!0}),zn.Translate=void 0;var i=wi();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"translate",value:function translate(n,s){var r=i.Text.breakupIntoWordsArr(n);for(var o=0;o<r.length;o+=1)s[r[o]]&&(r[o]=s[r[o]]);return r.join("");}}]);}();return zn.Translate=e,zn;}var uo;function Rh(){if(uo)return Gn;uo=1,Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.WebSpeechTranscript=void 0;var i=ha();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:function extract(n,s,r){var o="";for(var a=n.resultIndex;a<n.results.length;++a){var c=n.results[a][0].transcript;r&&(c=i.Translate.translate(c,r)),n.results[a].isFinal?s+=c:o+=c;}return{interimTranscript:o,finalTranscript:s,newText:o||s};}},{key:"extractSafari",value:function extractSafari(n,s,r){var o="";for(var c=n.resultIndex;c<n.results.length;++c){var l=n.results[c][0].transcript;r&&(l=i.Translate.translate(l,r)),o+=l;}return{interimTranscript:"",finalTranscript:o,newText:o};}}]);}();return Gn.WebSpeechTranscript=e,Gn;}var Kn={},po;function Tr(){if(po)return Kn;po=1,Object.defineProperty(Kn,"__esModule",{value:!0}),Kn.Browser=void 0;var i=/*#__PURE__*/_createClass(function i(){_classCallCheck(this,i);});return Kn.Browser=i,i.IS_SAFARI=function(){return i._IS_SAFARI===void 0&&(i._IS_SAFARI=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)),i._IS_SAFARI;},Kn;}var Wn={},Xn={},fo;function Ih(){if(fo)return Xn;fo=1,Object.defineProperty(Xn,"__esModule",{value:!0}),Xn.EventListeners=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"getElementIfFocusedOnAvailable",value:function getElementIfFocusedOnAvailable(t,n){return Array.isArray(t)?t.find(function(s){return n===s;}):n===t?t:void 0;}},{key:"keyDownWindow",value:function keyDownWindow(t){var _this99=this;t.element&&i.getElementIfFocusedOnAvailable(t.element,document.activeElement)&&(i.KEY_DOWN_TIMEOUT!==null&&clearTimeout(i.KEY_DOWN_TIMEOUT),i.KEY_DOWN_TIMEOUT=setTimeout(function(){i.KEY_DOWN_TIMEOUT=null,_this99.resetRecording(t);},500));}},{key:"mouseDownWindow",value:function mouseDownWindow(t,n){this.mouseDownElement=i.getElementIfFocusedOnAvailable(t,n.target);}},{key:"mouseUpWindow",value:function mouseUpWindow(t){this.mouseDownElement&&this.resetRecording(t),this.mouseDownElement=void 0;}},{key:"add",value:function add(t,n){var s=(n==null?void 0:n.insertInCursorLocation)===void 0||(n==null?void 0:n.insertInCursorLocation);n!=null&&n.element&&s&&(t.mouseDownEvent=i.mouseDownWindow.bind(t,n.element),document.addEventListener("mousedown",t.mouseDownEvent),t.mouseUpEvent=i.mouseUpWindow.bind(t,n),document.addEventListener("mouseup",t.mouseUpEvent),t.keyDownEvent=i.keyDownWindow.bind(t,n),document.addEventListener("keydown",t.keyDownEvent));}},{key:"remove",value:function remove(t){document.removeEventListener("mousedown",t.mouseDownEvent),document.removeEventListener("mouseup",t.mouseUpEvent),document.removeEventListener("keydown",t.keyDownEvent);}}]);}();return Xn.EventListeners=i,i.KEY_DOWN_TIMEOUT=null,Xn;}var Zn={},mo;function Mh(){if(mo)return Zn;mo=1,Object.defineProperty(Zn,"__esModule",{value:!0}),Zn.PreResultUtils=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"process",value:function process(t,n,s,r,o){var a=r==null?void 0:r(n,s);return a?(setTimeout(function(){a.restart?t.resetRecording(o):a.stop&&t.stop();}),(a.stop||a.restart)&&a.removeNewText):!1;}}]);}();return Zn.PreResultUtils=i,Zn;}var Yn={},Jn={},go;function ua(){if(go)return Jn;go=1,Object.defineProperty(Jn,"__esModule",{value:!0}),Jn.AutoScroll=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"changeStateIfNeeded",value:function changeStateIfNeeded(t,n){n&&!t.isCursorAtEnd&&(t.endPadding="",t.scrollingSpan.innerHTML="&nbsp;");}},{key:"scrollGeneric",value:function scrollGeneric(t,n){t.isCursorAtEnd?n.scrollTop=n.scrollHeight:t.scrollingSpan.scrollIntoView({block:"nearest"});}// primitives don't need to be scrolled except in safari
225
221
  // they can only safely be scrolled to the end
226
- },{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(t){t.scrollLeft=t.scrollWidth,t.scrollTop=t.scrollHeight;}},{key:"isElementOverflown",value:function isElementOverflown(t){return t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;}},{key:"isRequired",value:function isRequired(t,n){return t&&i.isElementOverflown(n);}}]);}();return Jn.AutoScroll=i,Jn;}var Qn={},yo;function Ri(){if(yo)return Qn;yo=1,Object.defineProperty(Qn,"__esModule",{value:!0}),Qn.Elements=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"isPrimitiveElement",value:function isPrimitiveElement(t){return t.tagName==="INPUT"||t.tagName==="TEXTAREA";}},{key:"createInterimSpan",value:function createInterimSpan(){var t=document.createElement("span");return t.style.color="grey",t.style.pointerEvents="none",t;}},{key:"createGenericSpan",value:function createGenericSpan(){var t=document.createElement("span");return t.style.pointerEvents="none",t;}},{key:"appendSpans",value:function appendSpans(t,n){if(t.spansPopulated=!0,t.insertInCursorLocation&&document.activeElement===n){var s=window.getSelection();if(s!=null&&s.focusNode){var r=s.getRangeAt(0);r.insertNode(t.scrollingSpan),r.insertNode(t.interimSpan),r.insertNode(t.finalSpan),r.collapse(!1),s.removeAllRanges(),s.addRange(r);return;}}n.appendChild(t.finalSpan),n.appendChild(t.interimSpan),n.appendChild(t.scrollingSpan);}},{key:"applyCustomColors",value:function applyCustomColors(t,n){n.interim&&(t.interimSpan.style.color=n.interim),n["final"]&&(t.finalSpan.style.color=n["final"]);}},{key:"isInsideShadowDOM",value:function isInsideShadowDOM(t){return t.getRootNode()instanceof ShadowRoot;}}]);}();return Qn.Elements=i,Qn;}var es={},_o;function Ii(){if(_o)return es;_o=1,Object.defineProperty(es,"__esModule",{value:!0}),es.Cursor=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"setOffsetForGeneric",value:function setOffsetForGeneric(t,n){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var r=0;for(var o=0;o<t.childNodes.length;o+=1){var a=t.childNodes[o];if(a.childNodes.length>0){var c=i.setOffsetForGeneric(a,n,s);if(c===-1)return-1;s+=c;}else if(a.textContent!==null){if(s+a.textContent.length>n){var _c7=document.createRange();_c7.setStart(a,n-s),_c7.collapse(!0);var l=window.getSelection();return l==null||l.removeAllRanges(),l==null||l.addRange(_c7),t.focus(),-1;}s+=a.textContent.length,r+=a.textContent.length;}}return r;}},{key:"focusEndOfGeneric",value:function focusEndOfGeneric(t){var n=document.createRange();n.selectNodeContents(t),n.collapse(!1);var s=window.getSelection();s&&(s.removeAllRanges(),s.addRange(n));}},{key:"setOffsetForSafariGeneric",value:function setOffsetForSafariGeneric(t,n){var s=window.getSelection();if(s){var r=i.getGenericElementCursorOffset(t,s,!0);i.setOffsetForGeneric(t,r+n);}}// set to automatically scroll to cursor (scroll does not work in Safari)
222
+ },{key:"scrollSafariPrimitiveToEnd",value:function scrollSafariPrimitiveToEnd(t){t.scrollLeft=t.scrollWidth,t.scrollTop=t.scrollHeight;}},{key:"isElementOverflown",value:function isElementOverflown(t){return t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;}},{key:"isRequired",value:function isRequired(t,n){return t&&i.isElementOverflown(n);}}]);}();return Jn.AutoScroll=i,Jn;}var Qn={},bo;function Ci(){if(bo)return Qn;bo=1,Object.defineProperty(Qn,"__esModule",{value:!0}),Qn.Elements=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"isPrimitiveElement",value:function isPrimitiveElement(t){return t.tagName==="INPUT"||t.tagName==="TEXTAREA";}},{key:"createInterimSpan",value:function createInterimSpan(){var t=document.createElement("span");return t.style.color="grey",t.style.pointerEvents="none",t;}},{key:"createGenericSpan",value:function createGenericSpan(){var t=document.createElement("span");return t.style.pointerEvents="none",t;}},{key:"appendSpans",value:function appendSpans(t,n){if(t.spansPopulated=!0,t.insertInCursorLocation&&document.activeElement===n){var s=window.getSelection();if(s!=null&&s.focusNode){var r=s.getRangeAt(0);r.insertNode(t.scrollingSpan),r.insertNode(t.interimSpan),r.insertNode(t.finalSpan),r.collapse(!1),s.removeAllRanges(),s.addRange(r);return;}}n.appendChild(t.finalSpan),n.appendChild(t.interimSpan),n.appendChild(t.scrollingSpan);}},{key:"applyCustomColors",value:function applyCustomColors(t,n){n.interim&&(t.interimSpan.style.color=n.interim),n["final"]&&(t.finalSpan.style.color=n["final"]);}},{key:"isInsideShadowDOM",value:function isInsideShadowDOM(t){return t.getRootNode()instanceof ShadowRoot;}}]);}();return Qn.Elements=i,Qn;}var es={},yo;function Ti(){if(yo)return es;yo=1,Object.defineProperty(es,"__esModule",{value:!0}),es.Cursor=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"setOffsetForGeneric",value:function setOffsetForGeneric(t,n){var s=arguments.length>2&&arguments[2]!==undefined?arguments[2]:0;var r=0;for(var o=0;o<t.childNodes.length;o+=1){var a=t.childNodes[o];if(a.childNodes.length>0){var c=i.setOffsetForGeneric(a,n,s);if(c===-1)return-1;s+=c;}else if(a.textContent!==null){if(s+a.textContent.length>n){var _c7=document.createRange();_c7.setStart(a,n-s),_c7.collapse(!0);var l=window.getSelection();return l==null||l.removeAllRanges(),l==null||l.addRange(_c7),t.focus(),-1;}s+=a.textContent.length,r+=a.textContent.length;}}return r;}},{key:"focusEndOfGeneric",value:function focusEndOfGeneric(t){var n=document.createRange();n.selectNodeContents(t),n.collapse(!1);var s=window.getSelection();s&&(s.removeAllRanges(),s.addRange(n));}},{key:"setOffsetForSafariGeneric",value:function setOffsetForSafariGeneric(t,n){var s=window.getSelection();if(s){var r=i.getGenericElementCursorOffset(t,s,!0);i.setOffsetForGeneric(t,r+n);}}// set to automatically scroll to cursor (scroll does not work in Safari)
227
223
  },{key:"setOffsetForPrimitive",value:function setOffsetForPrimitive(t,n,s){s&&t.blur(),t.setSelectionRange(n,n),t.focus();}// Scroll Input in Safari - does not work for TextArea and uses span which can have a different style
228
224
  // private static getCursorOffsetFromLeft(inputElement: HTMLInputElement, position: number) {
229
225
  // // Get the value of the input element up to the cursor position
@@ -241,39 +237,39 @@ function addToDropup(e,t,n,s){var r=new pi(n,s);lo.forEach(function(a){var c=t[e
241
237
  // document.body.removeChild(tempSpan);
242
238
  // return {left: offsetWidth, top: offsetHeight};
243
239
  // }
244
- },{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(t,n,s){var r=0;if(n.rangeCount>0){var o=n.getRangeAt(0),a=o.cloneRange();a.selectNodeContents(t),s?a.setEnd(o.startContainer,o.startOffset):a.setEnd(o.endContainer,o.endOffset),r=a.toString().length;}return r;}}]);}();return es.Cursor=i,es;}var Eo;function fa(){if(Eo)return Yn;Eo=1,Object.defineProperty(Yn,"__esModule",{value:!0}),Yn.CommandUtils=void 0;var i=pa(),e=Ri(),t=Rr(),n=Ii(),s=Ti();var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"processCommand",value:function processCommand(a,c){return(!c||!c.caseSensitive)&&(a=a.toLowerCase()),(c==null?void 0:c.substrings)===!1?s.Text.breakupIntoWordsArr(a):a;}},{key:"process",value:function process(a){var c;return((c=a.settings)===null||c===void 0?void 0:c.caseSensitive)===!0?a:Object.keys(a).reduce(function(d,p){var u=a[p];return d[p]=typeof u=="string"?r.processCommand(u,a.settings):u,d;},{});}},{key:"toggleCommandModeOn",value:function toggleCommandModeOn(a){var c;a.isWaitingForCommand=!0,(c=a.onCommandModeTrigger)===null||c===void 0||c.call(a,!0);}},{key:"toggleCommandModeOff",value:function toggleCommandModeOff(a){var c;a.isWaitingForCommand&&((c=a.onCommandModeTrigger)===null||c===void 0||c.call(a,!1),a.isWaitingForCommand=!1);}},{key:"setText",value:function setText(a,c,l,d){r.toggleCommandModeOff(a),e.Elements.isPrimitiveElement(d)?(d.value=l,a.isTargetInShadow||n.Cursor.setOffsetForPrimitive(d,l.length,!0),t.Browser.IS_SAFARI()&&a.autoScroll&&i.AutoScroll.scrollSafariPrimitiveToEnd(d)):(d.textContent=l,a.isTargetInShadow||n.Cursor.focusEndOfGeneric(d),setTimeout(function(){return i.AutoScroll.scrollGeneric(a,d);})),a.resetRecording(c);}},{key:"checkIfMatchesSubstring",value:function checkIfMatchesSubstring(a,c){return c.includes(a);}},{key:"checkIfMatchesWord",value:function checkIfMatchesWord(a,c,l){var d=a;for(var p=l.length-1;p>=0;p-=1){var u=p,g=d.length-1;for(;l[u]===d[g]&&g>=0;)u-=1,g-=1;if(g<0)return!0;}return!1;}// prettier-ignore
245
- },{key:"execCommand",value:function execCommand(a,c,l,d,p){var u,g,y;var _=a.commands;if(!_||!d||!l)return;var S=((u=_.settings)===null||u===void 0?void 0:u.caseSensitive)===!0?c:c.toLowerCase(),M=s.Text.breakupIntoWordsArr(S),K=((g=_.settings)===null||g===void 0?void 0:g.substrings)===!1?r.checkIfMatchesWord:r.checkIfMatchesSubstring;if(_.commandMode&&K(_.commandMode,S,M))return a.setInterimColorToFinal(),setTimeout(function(){return r.toggleCommandModeOn(a);}),{doNotProcessTranscription:!1};if(!(_.commandMode&&!a.isWaitingForCommand)){if(_.stop&&K(_.stop,S,M))return r.toggleCommandModeOff(a),setTimeout(function(){return a.stop();}),{doNotProcessTranscription:!1};if(_.pause&&K(_.pause,S,M))return r.toggleCommandModeOff(a),a.setInterimColorToFinal(),setTimeout(function(){var ie;a.isPaused=!0,(ie=a.onPauseTrigger)===null||ie===void 0||ie.call(a,!0);}),{doNotProcessTranscription:!1};if(_.resume&&K(_.resume,S,M))return a.isPaused=!1,(y=a.onPauseTrigger)===null||y===void 0||y.call(a,!1),r.toggleCommandModeOff(a),a.resetRecording(l),{doNotProcessTranscription:!0};if(_.reset&&K(_.reset,S,M))return p!==void 0&&r.setText(a,l,p,d),{doNotProcessTranscription:!0};if(_.removeAllText&&K(_.removeAllText,S,M))return r.setText(a,l,"",d),{doNotProcessTranscription:!0};}}}]);}();return Yn.CommandUtils=r,Yn;}var ts={},vo;function Ph(){if(vo)return ts;vo=1,Object.defineProperty(ts,"__esModule",{value:!0}),ts.Highlight=void 0;var i=Ri(),e=Ii();var t=/*#__PURE__*/function(){function t(){_classCallCheck(this,t);}return _createClass(t,null,[{key:"setStateForPrimitive",value:function setStateForPrimitive(s,r){var o,a;r.selectionStart!==null&&(o=r.selectionStart),r.selectionEnd!==null&&(a=r.selectionEnd),s.isHighlighted=o!==a;}},{key:"setStateForGeneric",value:function setStateForGeneric(s,r){var o=window.getSelection();if(o!=null&&o.focusNode){var a=e.Cursor.getGenericElementCursorOffset(r,o,!0),c=e.Cursor.getGenericElementCursorOffset(r,o,!1);s.isHighlighted=a!==c;}}},{key:"setState",value:function setState(s,r){document.activeElement===r&&(i.Elements.isPrimitiveElement(r)?t.setStateForPrimitive(s,r):t.setStateForGeneric(s,r));}},{key:"removeForGeneric",value:function removeForGeneric(s,r){var o=window.getSelection();if(o){var a=e.Cursor.getGenericElementCursorOffset(r,o,!0);o.deleteFromDocument(),e.Cursor.setOffsetForGeneric(r,a),s.isHighlighted=!1;}}},{key:"removeForPrimitive",value:function removeForPrimitive(s,r){var o=r.selectionStart,a=r.selectionEnd,c=r.value;if(o&&a){var l=c.substring(0,o)+c.substring(a);r.value=l,e.Cursor.setOffsetForPrimitive(r,o,s.autoScroll);}s.isHighlighted=!1;}}]);}();return ts.Highlight=t,ts;}var ns={},So;function Lh(){if(So)return ns;So=1,Object.defineProperty(ns,"__esModule",{value:!0}),ns.Padding=void 0;var i=Ri(),e=Ii(),t=Ti();var n=/*#__PURE__*/function(){function n(){_classCallCheck(this,n);}return _createClass(n,null,[{key:"setStateForPrimitiveElement",value:function setStateForPrimitiveElement(r,o){if(document.activeElement===o&&o.selectionStart!==null){var c=o.selectionStart,l=o.value[c-1],d=o.selectionEnd===null?c:o.selectionEnd,p=o.value[d];t.Text.isCharDefined(l)&&(r.startPadding=" ",r.numberOfSpacesBeforeNewText=1),t.Text.isCharDefined(p)&&(r.endPadding=" ",r.numberOfSpacesAfterNewText=1),r.isCursorAtEnd=o.value.length===d;return;}var a=o.value[o.value.length-1];t.Text.isCharDefined(a)&&(r.startPadding=" ",r.numberOfSpacesBeforeNewText=1),r.isCursorAtEnd=!0;}},{key:"setStateForGenericElement",value:function setStateForGenericElement(r,o){var a,c,l;if(document.activeElement===o){var p=window.getSelection();if(p!=null&&p.focusNode){var u=e.Cursor.getGenericElementCursorOffset(o,p,!0),g=(a=o.textContent)===null||a===void 0?void 0:a[u-1],y=e.Cursor.getGenericElementCursorOffset(o,p,!1),_=(c=o.textContent)===null||c===void 0?void 0:c[y];t.Text.isCharDefined(g)&&(r.startPadding=" "),t.Text.isCharDefined(_)&&(r.endPadding=" "),r.isCursorAtEnd=((l=o.textContent)===null||l===void 0?void 0:l.length)===y;return;}}var d=o.innerText.charAt(o.innerText.length-1);t.Text.isCharDefined(d)&&(r.startPadding=" "),r.isCursorAtEnd=!0;}},{key:"setState",value:function setState(r,o){i.Elements.isPrimitiveElement(o)?n.setStateForPrimitiveElement(r,o):n.setStateForGenericElement(r,o);}},{key:"adjustStateAfterRecodingPrimitiveElement",value:function adjustStateAfterRecodingPrimitiveElement(r,o){if(r.primitiveTextRecorded=!0,r.insertInCursorLocation&&document.activeElement===o&&(o.selectionEnd!==null&&(r.endPadding=r.endPadding+o.value.slice(o.selectionEnd)),o.selectionStart!==null)){r.startPadding=o.value.slice(0,o.selectionStart)+r.startPadding;return;}r.startPadding=o.value+r.startPadding;}},{key:"adjustSateForNoTextPrimitiveElement",value:function adjustSateForNoTextPrimitiveElement(r){r.numberOfSpacesBeforeNewText===1&&(r.startPadding=r.startPadding.substring(0,r.startPadding.length-1),r.numberOfSpacesBeforeNewText=0),r.numberOfSpacesAfterNewText===1&&(r.endPadding=r.endPadding.substring(1),r.numberOfSpacesAfterNewText=0);}}]);}();return ns.Padding=n,ns;}var xo;function ma(){if(xo)return Wn;xo=1,Object.defineProperty(Wn,"__esModule",{value:!0}),Wn.Speech=void 0;var i=Mh(),e=kh(),t=fa(),n=pa(),s=Ph(),r=Ri(),o=Lh(),a=Rr(),c=Ii(),l=Ti();var d=/*#__PURE__*/function(){function d(){_classCallCheck(this,d);this.finalTranscript="",this.interimSpan=r.Elements.createInterimSpan(),this.finalSpan=r.Elements.createGenericSpan(),this.scrollingSpan=r.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 _createClass(d,[{key:"prepareBeforeStart",value:function prepareBeforeStart(u){var g,y;if(u!=null&&u.element)if(i.EventListeners.add(this,u),Array.isArray(u.element)){var S=u.element.find(function(M){return M===document.activeElement;})||u.element[0];if(!S)return;this.prepare(S);}else this.prepare(u.element);(u==null?void 0:u.displayInterimResults)!==void 0&&(this._displayInterimResults=u.displayInterimResults),u!=null&&u.textColor&&(this._finalTextColor=(g=u==null?void 0:u.textColor)===null||g===void 0?void 0:g["final"],r.Elements.applyCustomColors(this,u.textColor)),(u==null?void 0:u.insertInCursorLocation)!==void 0&&(this.insertInCursorLocation=u.insertInCursorLocation),(u==null?void 0:u.autoScroll)!==void 0&&(this.autoScroll=u.autoScroll),this._onResult=u==null?void 0:u.onResult,this._onPreResult=u==null?void 0:u.onPreResult,this._onStart=u==null?void 0:u.onStart,this._onStop=u==null?void 0:u.onStop,this._onError=u==null?void 0:u.onError,this.onCommandModeTrigger=u==null?void 0:u.onCommandModeTrigger,this.onPauseTrigger=u==null?void 0:u.onPauseTrigger,this._options=u,!((y=this._options)===null||y===void 0)&&y.commands&&(this.commands=t.CommandUtils.process(this._options.commands));}},{key:"prepare",value:function prepare(u){o.Padding.setState(this,u),s.Highlight.setState(this,u),this.isTargetInShadow=r.Elements.isInsideShadowDOM(u),r.Elements.isPrimitiveElement(u)?(this._primitiveElement=u,this._originalText=this._primitiveElement.value):(this._genericElement=u,this._originalText=this._genericElement.textContent);}// there was an attempt to optimize this by not having to restart the service and just reset state:
240
+ },{key:"getGenericElementCursorOffset",value:function getGenericElementCursorOffset(t,n,s){var r=0;if(n.rangeCount>0){var o=n.getRangeAt(0),a=o.cloneRange();a.selectNodeContents(t),s?a.setEnd(o.startContainer,o.startOffset):a.setEnd(o.endContainer,o.endOffset),r=a.toString().length;}return r;}}]);}();return es.Cursor=i,es;}var _o;function pa(){if(_o)return Yn;_o=1,Object.defineProperty(Yn,"__esModule",{value:!0}),Yn.CommandUtils=void 0;var i=ua(),e=Ci(),t=Tr(),n=Ti(),s=wi();var r=/*#__PURE__*/function(){function r(){_classCallCheck(this,r);}return _createClass(r,null,[{key:"processCommand",value:function processCommand(a,c){return(!c||!c.caseSensitive)&&(a=a.toLowerCase()),(c==null?void 0:c.substrings)===!1?s.Text.breakupIntoWordsArr(a):a;}},{key:"process",value:function process(a){var c;return((c=a.settings)===null||c===void 0?void 0:c.caseSensitive)===!0?a:Object.keys(a).reduce(function(d,p){var u=a[p];return d[p]=typeof u=="string"?r.processCommand(u,a.settings):u,d;},{});}},{key:"toggleCommandModeOn",value:function toggleCommandModeOn(a){var c;a.isWaitingForCommand=!0,(c=a.onCommandModeTrigger)===null||c===void 0||c.call(a,!0);}},{key:"toggleCommandModeOff",value:function toggleCommandModeOff(a){var c;a.isWaitingForCommand&&((c=a.onCommandModeTrigger)===null||c===void 0||c.call(a,!1),a.isWaitingForCommand=!1);}},{key:"setText",value:function setText(a,c,l,d){r.toggleCommandModeOff(a),e.Elements.isPrimitiveElement(d)?(d.value=l,a.isTargetInShadow||n.Cursor.setOffsetForPrimitive(d,l.length,!0),t.Browser.IS_SAFARI()&&a.autoScroll&&i.AutoScroll.scrollSafariPrimitiveToEnd(d)):(d.textContent=l,a.isTargetInShadow||n.Cursor.focusEndOfGeneric(d),setTimeout(function(){return i.AutoScroll.scrollGeneric(a,d);})),a.resetRecording(c);}},{key:"checkIfMatchesSubstring",value:function checkIfMatchesSubstring(a,c){return c.includes(a);}},{key:"checkIfMatchesWord",value:function checkIfMatchesWord(a,c,l){var d=a;for(var p=l.length-1;p>=0;p-=1){var u=p,g=d.length-1;for(;l[u]===d[g]&&g>=0;)u-=1,g-=1;if(g<0)return!0;}return!1;}// prettier-ignore
241
+ },{key:"execCommand",value:function execCommand(a,c,l,d,p){var u,g,y;var _=a.commands;if(!_||!d||!l)return;var S=((u=_.settings)===null||u===void 0?void 0:u.caseSensitive)===!0?c:c.toLowerCase(),M=s.Text.breakupIntoWordsArr(S),K=((g=_.settings)===null||g===void 0?void 0:g.substrings)===!1?r.checkIfMatchesWord:r.checkIfMatchesSubstring;if(_.commandMode&&K(_.commandMode,S,M))return a.setInterimColorToFinal(),setTimeout(function(){return r.toggleCommandModeOn(a);}),{doNotProcessTranscription:!1};if(!(_.commandMode&&!a.isWaitingForCommand)){if(_.stop&&K(_.stop,S,M))return r.toggleCommandModeOff(a),setTimeout(function(){return a.stop();}),{doNotProcessTranscription:!1};if(_.pause&&K(_.pause,S,M))return r.toggleCommandModeOff(a),a.setInterimColorToFinal(),setTimeout(function(){var ie;a.isPaused=!0,(ie=a.onPauseTrigger)===null||ie===void 0||ie.call(a,!0);}),{doNotProcessTranscription:!1};if(_.resume&&K(_.resume,S,M))return a.isPaused=!1,(y=a.onPauseTrigger)===null||y===void 0||y.call(a,!1),r.toggleCommandModeOff(a),a.resetRecording(l),{doNotProcessTranscription:!0};if(_.reset&&K(_.reset,S,M))return p!==void 0&&r.setText(a,l,p,d),{doNotProcessTranscription:!0};if(_.removeAllText&&K(_.removeAllText,S,M))return r.setText(a,l,"",d),{doNotProcessTranscription:!0};}}}]);}();return Yn.CommandUtils=r,Yn;}var ts={},Eo;function kh(){if(Eo)return ts;Eo=1,Object.defineProperty(ts,"__esModule",{value:!0}),ts.Highlight=void 0;var i=Ci(),e=Ti();var t=/*#__PURE__*/function(){function t(){_classCallCheck(this,t);}return _createClass(t,null,[{key:"setStateForPrimitive",value:function setStateForPrimitive(s,r){var o,a;r.selectionStart!==null&&(o=r.selectionStart),r.selectionEnd!==null&&(a=r.selectionEnd),s.isHighlighted=o!==a;}},{key:"setStateForGeneric",value:function setStateForGeneric(s,r){var o=window.getSelection();if(o!=null&&o.focusNode){var a=e.Cursor.getGenericElementCursorOffset(r,o,!0),c=e.Cursor.getGenericElementCursorOffset(r,o,!1);s.isHighlighted=a!==c;}}},{key:"setState",value:function setState(s,r){document.activeElement===r&&(i.Elements.isPrimitiveElement(r)?t.setStateForPrimitive(s,r):t.setStateForGeneric(s,r));}},{key:"removeForGeneric",value:function removeForGeneric(s,r){var o=window.getSelection();if(o){var a=e.Cursor.getGenericElementCursorOffset(r,o,!0);o.deleteFromDocument(),e.Cursor.setOffsetForGeneric(r,a),s.isHighlighted=!1;}}},{key:"removeForPrimitive",value:function removeForPrimitive(s,r){var o=r.selectionStart,a=r.selectionEnd,c=r.value;if(o&&a){var l=c.substring(0,o)+c.substring(a);r.value=l,e.Cursor.setOffsetForPrimitive(r,o,s.autoScroll);}s.isHighlighted=!1;}}]);}();return ts.Highlight=t,ts;}var ns={},vo;function Ph(){if(vo)return ns;vo=1,Object.defineProperty(ns,"__esModule",{value:!0}),ns.Padding=void 0;var i=Ci(),e=Ti(),t=wi();var n=/*#__PURE__*/function(){function n(){_classCallCheck(this,n);}return _createClass(n,null,[{key:"setStateForPrimitiveElement",value:function setStateForPrimitiveElement(r,o){if(document.activeElement===o&&o.selectionStart!==null){var c=o.selectionStart,l=o.value[c-1],d=o.selectionEnd===null?c:o.selectionEnd,p=o.value[d];t.Text.isCharDefined(l)&&(r.startPadding=" ",r.numberOfSpacesBeforeNewText=1),t.Text.isCharDefined(p)&&(r.endPadding=" ",r.numberOfSpacesAfterNewText=1),r.isCursorAtEnd=o.value.length===d;return;}var a=o.value[o.value.length-1];t.Text.isCharDefined(a)&&(r.startPadding=" ",r.numberOfSpacesBeforeNewText=1),r.isCursorAtEnd=!0;}},{key:"setStateForGenericElement",value:function setStateForGenericElement(r,o){var a,c,l;if(document.activeElement===o){var p=window.getSelection();if(p!=null&&p.focusNode){var u=e.Cursor.getGenericElementCursorOffset(o,p,!0),g=(a=o.textContent)===null||a===void 0?void 0:a[u-1],y=e.Cursor.getGenericElementCursorOffset(o,p,!1),_=(c=o.textContent)===null||c===void 0?void 0:c[y];t.Text.isCharDefined(g)&&(r.startPadding=" "),t.Text.isCharDefined(_)&&(r.endPadding=" "),r.isCursorAtEnd=((l=o.textContent)===null||l===void 0?void 0:l.length)===y;return;}}var d=o.innerText.charAt(o.innerText.length-1);t.Text.isCharDefined(d)&&(r.startPadding=" "),r.isCursorAtEnd=!0;}},{key:"setState",value:function setState(r,o){i.Elements.isPrimitiveElement(o)?n.setStateForPrimitiveElement(r,o):n.setStateForGenericElement(r,o);}},{key:"adjustStateAfterRecodingPrimitiveElement",value:function adjustStateAfterRecodingPrimitiveElement(r,o){if(r.primitiveTextRecorded=!0,r.insertInCursorLocation&&document.activeElement===o&&(o.selectionEnd!==null&&(r.endPadding=r.endPadding+o.value.slice(o.selectionEnd)),o.selectionStart!==null)){r.startPadding=o.value.slice(0,o.selectionStart)+r.startPadding;return;}r.startPadding=o.value+r.startPadding;}},{key:"adjustSateForNoTextPrimitiveElement",value:function adjustSateForNoTextPrimitiveElement(r){r.numberOfSpacesBeforeNewText===1&&(r.startPadding=r.startPadding.substring(0,r.startPadding.length-1),r.numberOfSpacesBeforeNewText=0),r.numberOfSpacesAfterNewText===1&&(r.endPadding=r.endPadding.substring(1),r.numberOfSpacesAfterNewText=0);}}]);}();return ns.Padding=n,ns;}var So;function fa(){if(So)return Wn;So=1,Object.defineProperty(Wn,"__esModule",{value:!0}),Wn.Speech=void 0;var i=Ih(),e=Mh(),t=pa(),n=ua(),s=kh(),r=Ci(),o=Ph(),a=Tr(),c=Ti(),l=wi();var d=/*#__PURE__*/function(){function d(){_classCallCheck(this,d);this.finalTranscript="",this.interimSpan=r.Elements.createInterimSpan(),this.finalSpan=r.Elements.createGenericSpan(),this.scrollingSpan=r.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 _createClass(d,[{key:"prepareBeforeStart",value:function prepareBeforeStart(u){var g,y;if(u!=null&&u.element)if(i.EventListeners.add(this,u),Array.isArray(u.element)){var S=u.element.find(function(M){return M===document.activeElement;})||u.element[0];if(!S)return;this.prepare(S);}else this.prepare(u.element);(u==null?void 0:u.displayInterimResults)!==void 0&&(this._displayInterimResults=u.displayInterimResults),u!=null&&u.textColor&&(this._finalTextColor=(g=u==null?void 0:u.textColor)===null||g===void 0?void 0:g["final"],r.Elements.applyCustomColors(this,u.textColor)),(u==null?void 0:u.insertInCursorLocation)!==void 0&&(this.insertInCursorLocation=u.insertInCursorLocation),(u==null?void 0:u.autoScroll)!==void 0&&(this.autoScroll=u.autoScroll),this._onResult=u==null?void 0:u.onResult,this._onPreResult=u==null?void 0:u.onPreResult,this._onStart=u==null?void 0:u.onStart,this._onStop=u==null?void 0:u.onStop,this._onError=u==null?void 0:u.onError,this.onCommandModeTrigger=u==null?void 0:u.onCommandModeTrigger,this.onPauseTrigger=u==null?void 0:u.onPauseTrigger,this._options=u,!((y=this._options)===null||y===void 0)&&y.commands&&(this.commands=t.CommandUtils.process(this._options.commands));}},{key:"prepare",value:function prepare(u){o.Padding.setState(this,u),s.Highlight.setState(this,u),this.isTargetInShadow=r.Elements.isInsideShadowDOM(u),r.Elements.isPrimitiveElement(u)?(this._primitiveElement=u,this._originalText=this._primitiveElement.value):(this._genericElement=u,this._originalText=this._genericElement.textContent);}// there was an attempt to optimize this by not having to restart the service and just reset state:
246
242
  // unfortunately it did not work because the service would still continue firing the intermediate and final results
247
243
  // into the new position
248
244
  },{key:"resetRecording",value:function resetRecording(u){this.isRestarting=!0,this.stop(!0),this.resetState(!0),this.start(u,!0);}// prettier-ignore
249
245
  },{key:"updateElements",value:function updateElements(u,g,y){var _;var S=l.Text.capitalize(g);if(this.finalTranscript===S&&u==="")return;e.PreResultUtils.process(this,y,u==="",this._onPreResult,this._options)&&(u="",y="");var M=this.commands&&t.CommandUtils.execCommand(this,y,this._options,this._primitiveElement||this._genericElement,this._originalText);if(M){if(M.doNotProcessTranscription)return;u="",y="";}if(this.isPaused||this.isWaitingForCommand)return;(_=this._onResult)===null||_===void 0||_.call(this,y,u===""),this.finalTranscript=S,this._displayInterimResults||(u="");var K=this.finalTranscript===""&&u==="";this._primitiveElement?this.updatePrimitiveElement(this._primitiveElement,u,K):this._genericElement&&this.updateGenericElement(this._genericElement,u,K);}// prettier-ignore
250
246
  // remember that padding values here contain actual text left and right
251
- },{key:"updatePrimitiveElement",value:function updatePrimitiveElement(u,g,y){this.isHighlighted&&s.Highlight.removeForPrimitive(this,u),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,u),y&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var _=this.startPadding+this.finalTranscript+g;if(u.value=_+this.endPadding,!this.isTargetInShadow){var S=_.length+this.numberOfSpacesAfterNewText;c.Cursor.setOffsetForPrimitive(u,S,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&n.AutoScroll.scrollSafariPrimitiveToEnd(u);}},{key:"updateGenericElement",value:function updateGenericElement(u,g,y){this.isHighlighted&&s.Highlight.removeForGeneric(this,u),this.spansPopulated||r.Elements.appendSpans(this,u);var _=(y?"":this.startPadding)+l.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=_;var S=n.AutoScroll.isRequired(this.autoScroll,u);n.AutoScroll.changeStateIfNeeded(this,S);var M=l.Text.lineBreak(g)+(y?"":this.endPadding);this.interimSpan.innerHTML=M,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&c.Cursor.setOffsetForSafariGeneric(u,_.length+M.length),S&&n.AutoScroll.scrollGeneric(this,u),y&&(this.scrollingSpan.innerHTML="");}},{key:"finalise",value:function finalise(u){this._genericElement&&(u?(this.finalSpan=r.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=r.Elements.createInterimSpan(),this.scrollingSpan=r.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),i.EventListeners.remove(this);}},{key:"setInterimColorToFinal",value:function setInterimColorToFinal(){this.interimSpan.style.color=this._finalTextColor||"black";}},{key:"resetState",value:function resetState(u){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,u||(this.stopTimeout=void 0);}},{key:"setStateOnStart",value:function setStateOnStart(){var u;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(u=this._onStart)===null||u===void 0||u.call(this);}},{key:"setStateOnStop",value:function setStateOnStop(){var u;this.recognizing=!1,this.isRestarting||(u=this._onStop)===null||u===void 0||u.call(this);}},{key:"setStateOnError",value:function setStateOnError(u){var g;(g=this._onError)===null||g===void 0||g.call(this,u),this.recognizing=!1;}}]);}();return Wn.Speech=d,Wn;}var Ao;function Oh(){if(Ao)return qn;Ao=1,Object.defineProperty(qn,"__esModule",{value:!0}),qn.WebSpeech=void 0;var i=Ih(),e=Rr(),t=ma();var n=/*#__PURE__*/function(_t$Speech){function n(){_classCallCheck(this,n);return _callSuper(this,n);}_inherits(n,_t$Speech);return _createClass(n,[{key:"start",value:function start(r){var o;this._extractText===void 0&&(this._extractText=e.Browser.IS_SAFARI()?i.WebSpeechTranscript.extractSafari:i.WebSpeechTranscript.extract),this.validate()&&(this.prepareBeforeStart(r),this.instantiateService(r),(o=this._service)===null||o===void 0||o.start(),this._translations=r==null?void 0:r.translations);}},{key:"validate",value:function validate(){return n.getAPI()?!0:(this.error("Speech Recognition is unsupported"),!1);}},{key:"instantiateService",value:function instantiateService(r){var o,a;var c=n.getAPI();this._service=new c(),this._service.continuous=!0,this._service.interimResults=(o=r==null?void 0:r.displayInterimResults)!==null&&o!==void 0?o:!0,this._service.lang=((a=r==null?void 0:r.language)===null||a===void 0?void 0:a.trim())||"en-US",this.setEvents();}},{key:"setEvents",value:function setEvents(){var _this100=this;this._service&&(this._service.onstart=function(){_this100.setStateOnStart();},this._service.onerror=function(r){e.Browser.IS_SAFARI()&&r.message==="Another request is started"||r.error==="aborted"&&_this100.isRestarting||r.error!=="no-speech"&&_this100.error(r.message||r.error);},this._service.onaudioend=function(){_this100.setStateOnStop();},this._service.onend=function(){_this100._stopping=!1;},this._service.onresult=function(r){if(_typeof(r.results)>"u"&&_this100._service)_this100._service.onend=null,_this100._service.stop();else if(_this100._extractText&&!_this100._stopping){var _this100$_extractText=_this100._extractText(r,_this100.finalTranscript,_this100._translations),o=_this100$_extractText.interimTranscript,a=_this100$_extractText.finalTranscript,c=_this100$_extractText.newText;_this100.updateElements(o,a,c);}});}},{key:"stop",value:function stop(r){var o;this._stopping=!0,(o=this._service)===null||o===void 0||o.stop(),this.finalise(r);}},{key:"error",value:function error(r){console.error(r),this.setStateOnError(r),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.webkitSpeechRecognition||window.SpeechRecognition;}}]);}(t.Speech);return qn.WebSpeech=n,qn;}var ss={},wo;function Nh(){if(wo)return ss;wo=1,Object.defineProperty(ss,"__esModule",{value:!0}),ss.GlobalState=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"doubleClickDetector",value:function doubleClickDetector(){return i.doubleClickPending?!0:(i.doubleClickPending=!0,setTimeout(function(){i.doubleClickPending=!1;},300),!1);}}]);}();return ss.GlobalState=i,i.doubleClickPending=!1,ss;}var is={},rs={},Co;function Bh(){if(Co)return rs;Co=1,Object.defineProperty(rs,"__esModule",{value:!0}),rs.PreventConnectionStop=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"applyPrevention",value:function applyPrevention(t){clearTimeout(t._manualConnectionStopPrevention),t.cannotBeStopped=!0,t._manualConnectionStopPrevention=setTimeout(function(){t.cannotBeStopped=!1;},800);}},{key:"clearPrevention",value:function clearPrevention(t){clearTimeout(t._manualConnectionStopPrevention),t.cannotBeStopped=!1;}}]);}();return rs.PreventConnectionStop=i,rs;}var os={},as={},To;function Dh(){return To||(To=1,Object.defineProperty(as,"__esModule",{value:!0}),as.README_URL=void 0,as.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),as;}var Ro;function Fh(){if(Ro)return os;Ro=1,Object.defineProperty(os,"__esModule",{value:!0}),os.AzureSpeechConfig=void 0;var i=Dh();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"validateOptions",value:function validateOptions(n,s){return s?!s.subscriptionKey&&!s.token&&!s.retrieveToken?(n("Please define a 'subscriptionKey', 'token' or 'retrieveToken' property - more info: ".concat(i.README_URL)),!1):s.region?!0:(n("Please define a 'region' property - more info: ".concat(i.README_URL)),!1):(n("Please provide subscription details - more info: ".concat(i.README_URL)),!1);}},{key:"getNewSpeechConfig",value:function(){var _getNewSpeechConfig=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee183(n,s){return _regenerator().w(function(_context183){while(1)switch(_context183.n){case 0:if(!s.region){_context183.n=1;break;}return _context183.a(2,s.subscriptionKey?n.fromSubscription(s.subscriptionKey.trim(),s.region.trim()):s.token?n.fromAuthorizationToken(s.token.trim(),s.region.trim()):s.retrieveToken?s.retrieveToken().then(function(r){return s.region?n.fromAuthorizationToken((r==null?void 0:r.trim())||"",s.region.trim()):null;})["catch"](function(r){return console.error(r),null;}):null);case 1:return _context183.a(2);}},_callee183);}));function getNewSpeechConfig(_x345,_x346){return _getNewSpeechConfig.apply(this,arguments);}return getNewSpeechConfig;}()},{key:"process",value:function process(n,s){s.endpointId&&(n.endpointId=s.endpointId.trim()),s.language&&(n.speechRecognitionLanguage=s.language.trim());}},{key:"get",value:function(){var _get2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee184(n,s){var r;return _regenerator().w(function(_context184){while(1)switch(_context184.n){case 0:_context184.n=1;return e.getNewSpeechConfig(n,s);case 1:r=_context184.v;return _context184.a(2,(r&&e.process(r,s),r));}},_callee184);}));function get(_x347,_x348){return _get2.apply(this,arguments);}return get;}()}]);}();return os.AzureSpeechConfig=e,os;}var cs={},Io;function Uh(){if(Io)return cs;Io=1,Object.defineProperty(cs,"__esModule",{value:!0}),cs.StopTimeout=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"set",value:function set(t){t.stopTimeout=setTimeout(function(){return t.stop();},t.stopTimeoutMS);}},{key:"reset",value:function reset(t,n){t.stopTimeoutMS=n||i.DEFAULT_MS,i.stop(t),i.set(t);}},{key:"stop",value:function stop(t){t.stopTimeout&&clearTimeout(t.stopTimeout);}}]);}();return cs.StopTimeout=i,i.DEFAULT_MS=2e4,cs;}var ls={},Mo;function Hh(){if(Mo)return ls;Mo=1,Object.defineProperty(ls,"__esModule",{value:!0}),ls.AzureAudioConfig=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"get",value:function get(t,n){return n?t.fromMicrophoneInput(n):t.fromDefaultMicrophoneInput();}}]);}();return ls.AzureAudioConfig=i,ls;}var ds={},ko;function jh(){if(ko)return ds;ko=1,Object.defineProperty(ds,"__esModule",{value:!0}),ds.AzureTranscript=void 0;var i=ua();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:// newText is used to only send new text in onResult as finalTranscript is continuously accumulated
252
- function extract(n,s,r,o){return o&&(n=i.Translate.translate(n,o)),r?{interimTranscript:"",finalTranscript:s+n,newText:n}:{interimTranscript:n,finalTranscript:s,newText:n};}}]);}();return ds.AzureTranscript=e,ds;}var Po;function $h(){if(Po)return is;Po=1,Object.defineProperty(is,"__esModule",{value:!0}),is.Azure=void 0;var i=Bh(),e=Fh(),t=Uh(),n=Hh(),s=jh(),r=ma();var o=/*#__PURE__*/function(_r$Speech){function o(){var _this101;_classCallCheck(this,o);_this101=_callSuper(this,o,arguments),_this101._newTextPadding="";return _this101;}_inherits(o,_r$Speech);return _createClass(o,[{key:"start",value:function start(c,l){this._newTextPadding="",this.stopTimeout===void 0&&t.StopTimeout.reset(this,c==null?void 0:c.stopAfterSilenceMs),this.prepareBeforeStart(c),this.startAsync(c),l||i.PreventConnectionStop.applyPrevention(this);}},{key:"startAsync",value:function(){var _startAsync=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee185(c){var l,_t57;return _regenerator().w(function(_context185){while(1)switch(_context185.n){case 0:_t57=this.validate(c);if(!_t57){_context185.n=2;break;}_context185.n=1;return this.instantiateService(c);case 1:this._translations=c==null?void 0:c.translations;(l=this._service)===null||l===void 0||l.startContinuousRecognitionAsync(function(){},this.error);case 2:return _context185.a(2);}},_callee185,this);}));function startAsync(_x349){return _startAsync.apply(this,arguments);}return startAsync;}()},{key:"validate",value:function validate(c){return o.getAPI()?e.AzureSpeechConfig.validateOptions(this.error.bind(this),c):(this.moduleNotFound(),!1);}},{key:"instantiateService",value:function(){var _instantiateService=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee186(c){var l,d,p,u,_c$autoLanguage,g,y,_,S;return _regenerator().w(function(_context186){while(1)switch(_context186.n){case 0:l=o.getAPI();d=n.AzureAudioConfig.get(l.AudioConfig,c.deviceId);_context186.n=1;return e.AzureSpeechConfig.get(l.SpeechConfig,c);case 1:p=_context186.v;if(p){if(c.autoLanguage&&c.autoLanguage.languages.length>0){_c$autoLanguage=c.autoLanguage,g=_c$autoLanguage.type,y=_c$autoLanguage.languages,_=y.slice(0,g==="Continuous"?10:4),S=l.AutoDetectSourceLanguageConfig.fromLanguages(_);g==="Continuous"&&(S.mode=1),u=l.SpeechRecognizer.FromConfig(p,S,d);}else u=new l.SpeechRecognizer(p,d);this.setEvents(u),this._service=u,c.retrieveToken&&this.retrieveTokenInterval(c.retrieveToken);}else this.error("Unable to contact Azure server");case 2:return _context186.a(2);}},_callee186,this);}));function instantiateService(_x350){return _instantiateService.apply(this,arguments);}return instantiateService;}()},{key:"setEvents",value:function setEvents(c){c.recognizing=this.onRecognizing.bind(this),c.recognized=this.onRecognized.bind(this),c.sessionStarted=this.onSessionStarted.bind(this),c.canceled=this.onCanceled.bind(this),c.sessionStopped=this.onSessionStopped.bind(this);}// prettier-ignore
247
+ },{key:"updatePrimitiveElement",value:function updatePrimitiveElement(u,g,y){this.isHighlighted&&s.Highlight.removeForPrimitive(this,u),this.primitiveTextRecorded||o.Padding.adjustStateAfterRecodingPrimitiveElement(this,u),y&&o.Padding.adjustSateForNoTextPrimitiveElement(this);var _=this.startPadding+this.finalTranscript+g;if(u.value=_+this.endPadding,!this.isTargetInShadow){var S=_.length+this.numberOfSpacesAfterNewText;c.Cursor.setOffsetForPrimitive(u,S,this.autoScroll);}this.autoScroll&&a.Browser.IS_SAFARI()&&this.isCursorAtEnd&&n.AutoScroll.scrollSafariPrimitiveToEnd(u);}},{key:"updateGenericElement",value:function updateGenericElement(u,g,y){this.isHighlighted&&s.Highlight.removeForGeneric(this,u),this.spansPopulated||r.Elements.appendSpans(this,u);var _=(y?"":this.startPadding)+l.Text.lineBreak(this.finalTranscript);this.finalSpan.innerHTML=_;var S=n.AutoScroll.isRequired(this.autoScroll,u);n.AutoScroll.changeStateIfNeeded(this,S);var M=l.Text.lineBreak(g)+(y?"":this.endPadding);this.interimSpan.innerHTML=M,a.Browser.IS_SAFARI()&&this.insertInCursorLocation&&c.Cursor.setOffsetForSafariGeneric(u,_.length+M.length),S&&n.AutoScroll.scrollGeneric(this,u),y&&(this.scrollingSpan.innerHTML="");}},{key:"finalise",value:function finalise(u){this._genericElement&&(u?(this.finalSpan=r.Elements.createGenericSpan(),this.setInterimColorToFinal(),this.interimSpan=r.Elements.createInterimSpan(),this.scrollingSpan=r.Elements.createGenericSpan()):this._genericElement.textContent=this._genericElement.textContent,this.spansPopulated=!1),i.EventListeners.remove(this);}},{key:"setInterimColorToFinal",value:function setInterimColorToFinal(){this.interimSpan.style.color=this._finalTextColor||"black";}},{key:"resetState",value:function resetState(u){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,u||(this.stopTimeout=void 0);}},{key:"setStateOnStart",value:function setStateOnStart(){var u;this.recognizing=!0,this.isRestarting?this.isRestarting=!1:(u=this._onStart)===null||u===void 0||u.call(this);}},{key:"setStateOnStop",value:function setStateOnStop(){var u;this.recognizing=!1,this.isRestarting||(u=this._onStop)===null||u===void 0||u.call(this);}},{key:"setStateOnError",value:function setStateOnError(u){var g;(g=this._onError)===null||g===void 0||g.call(this,u),this.recognizing=!1;}}]);}();return Wn.Speech=d,Wn;}var xo;function Lh(){if(xo)return qn;xo=1,Object.defineProperty(qn,"__esModule",{value:!0}),qn.WebSpeech=void 0;var i=Rh(),e=Tr(),t=fa();var n=/*#__PURE__*/function(_t$Speech){function n(){_classCallCheck(this,n);return _callSuper(this,n);}_inherits(n,_t$Speech);return _createClass(n,[{key:"start",value:function start(r){var o;this._extractText===void 0&&(this._extractText=e.Browser.IS_SAFARI()?i.WebSpeechTranscript.extractSafari:i.WebSpeechTranscript.extract),this.validate()&&(this.prepareBeforeStart(r),this.instantiateService(r),(o=this._service)===null||o===void 0||o.start(),this._translations=r==null?void 0:r.translations);}},{key:"validate",value:function validate(){return n.getAPI()?!0:(this.error("Speech Recognition is unsupported"),!1);}},{key:"instantiateService",value:function instantiateService(r){var o,a;var c=n.getAPI();this._service=new c(),this._service.continuous=!0,this._service.interimResults=(o=r==null?void 0:r.displayInterimResults)!==null&&o!==void 0?o:!0,this._service.lang=((a=r==null?void 0:r.language)===null||a===void 0?void 0:a.trim())||"en-US",this.setEvents();}},{key:"setEvents",value:function setEvents(){var _this100=this;this._service&&(this._service.onstart=function(){_this100.setStateOnStart();},this._service.onerror=function(r){e.Browser.IS_SAFARI()&&r.message==="Another request is started"||r.error==="aborted"&&_this100.isRestarting||r.error!=="no-speech"&&_this100.error(r.message||r.error);},this._service.onaudioend=function(){_this100.setStateOnStop();},this._service.onend=function(){_this100._stopping=!1;},this._service.onresult=function(r){if(_typeof(r.results)>"u"&&_this100._service)_this100._service.onend=null,_this100._service.stop();else if(_this100._extractText&&!_this100._stopping){var _this100$_extractText=_this100._extractText(r,_this100.finalTranscript,_this100._translations),o=_this100$_extractText.interimTranscript,a=_this100$_extractText.finalTranscript,c=_this100$_extractText.newText;_this100.updateElements(o,a,c);}});}},{key:"stop",value:function stop(r){var o;this._stopping=!0,(o=this._service)===null||o===void 0||o.stop(),this.finalise(r);}},{key:"error",value:function error(r){console.error(r),this.setStateOnError(r),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.webkitSpeechRecognition||window.SpeechRecognition;}}]);}(t.Speech);return qn.WebSpeech=n,qn;}var ss={},Ao;function Oh(){if(Ao)return ss;Ao=1,Object.defineProperty(ss,"__esModule",{value:!0}),ss.GlobalState=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"doubleClickDetector",value:function doubleClickDetector(){return i.doubleClickPending?!0:(i.doubleClickPending=!0,setTimeout(function(){i.doubleClickPending=!1;},300),!1);}}]);}();return ss.GlobalState=i,i.doubleClickPending=!1,ss;}var is={},rs={},wo;function Nh(){if(wo)return rs;wo=1,Object.defineProperty(rs,"__esModule",{value:!0}),rs.PreventConnectionStop=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"applyPrevention",value:function applyPrevention(t){clearTimeout(t._manualConnectionStopPrevention),t.cannotBeStopped=!0,t._manualConnectionStopPrevention=setTimeout(function(){t.cannotBeStopped=!1;},800);}},{key:"clearPrevention",value:function clearPrevention(t){clearTimeout(t._manualConnectionStopPrevention),t.cannotBeStopped=!1;}}]);}();return rs.PreventConnectionStop=i,rs;}var os={},as={},Co;function Bh(){return Co||(Co=1,Object.defineProperty(as,"__esModule",{value:!0}),as.README_URL=void 0,as.README_URL="https://github.com/OvidijusParsiunas/speech-to-element"),as;}var To;function Dh(){if(To)return os;To=1,Object.defineProperty(os,"__esModule",{value:!0}),os.AzureSpeechConfig=void 0;var i=Bh();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"validateOptions",value:function validateOptions(n,s){return s?!s.subscriptionKey&&!s.token&&!s.retrieveToken?(n("Please define a 'subscriptionKey', 'token' or 'retrieveToken' property - more info: ".concat(i.README_URL)),!1):s.region?!0:(n("Please define a 'region' property - more info: ".concat(i.README_URL)),!1):(n("Please provide subscription details - more info: ".concat(i.README_URL)),!1);}},{key:"getNewSpeechConfig",value:function(){var _getNewSpeechConfig=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee183(n,s){return _regenerator().w(function(_context183){while(1)switch(_context183.n){case 0:if(!s.region){_context183.n=1;break;}return _context183.a(2,s.subscriptionKey?n.fromSubscription(s.subscriptionKey.trim(),s.region.trim()):s.token?n.fromAuthorizationToken(s.token.trim(),s.region.trim()):s.retrieveToken?s.retrieveToken().then(function(r){return s.region?n.fromAuthorizationToken((r==null?void 0:r.trim())||"",s.region.trim()):null;})["catch"](function(r){return console.error(r),null;}):null);case 1:return _context183.a(2);}},_callee183);}));function getNewSpeechConfig(_x345,_x346){return _getNewSpeechConfig.apply(this,arguments);}return getNewSpeechConfig;}()},{key:"process",value:function process(n,s){s.endpointId&&(n.endpointId=s.endpointId.trim()),s.language&&(n.speechRecognitionLanguage=s.language.trim());}},{key:"get",value:function(){var _get2=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee184(n,s){var r;return _regenerator().w(function(_context184){while(1)switch(_context184.n){case 0:_context184.n=1;return e.getNewSpeechConfig(n,s);case 1:r=_context184.v;return _context184.a(2,(r&&e.process(r,s),r));}},_callee184);}));function get(_x347,_x348){return _get2.apply(this,arguments);}return get;}()}]);}();return os.AzureSpeechConfig=e,os;}var cs={},Ro;function Fh(){if(Ro)return cs;Ro=1,Object.defineProperty(cs,"__esModule",{value:!0}),cs.StopTimeout=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"set",value:function set(t){t.stopTimeout=setTimeout(function(){return t.stop();},t.stopTimeoutMS);}},{key:"reset",value:function reset(t,n){t.stopTimeoutMS=n||i.DEFAULT_MS,i.stop(t),i.set(t);}},{key:"stop",value:function stop(t){t.stopTimeout&&clearTimeout(t.stopTimeout);}}]);}();return cs.StopTimeout=i,i.DEFAULT_MS=2e4,cs;}var ls={},Io;function Uh(){if(Io)return ls;Io=1,Object.defineProperty(ls,"__esModule",{value:!0}),ls.AzureAudioConfig=void 0;var i=/*#__PURE__*/function(){function i(){_classCallCheck(this,i);}return _createClass(i,null,[{key:"get",value:function get(t,n){return n?t.fromMicrophoneInput(n):t.fromDefaultMicrophoneInput();}}]);}();return ls.AzureAudioConfig=i,ls;}var ds={},Mo;function Hh(){if(Mo)return ds;Mo=1,Object.defineProperty(ds,"__esModule",{value:!0}),ds.AzureTranscript=void 0;var i=ha();var e=/*#__PURE__*/function(){function e(){_classCallCheck(this,e);}return _createClass(e,null,[{key:"extract",value:// newText is used to only send new text in onResult as finalTranscript is continuously accumulated
248
+ function extract(n,s,r,o){return o&&(n=i.Translate.translate(n,o)),r?{interimTranscript:"",finalTranscript:s+n,newText:n}:{interimTranscript:n,finalTranscript:s,newText:n};}}]);}();return ds.AzureTranscript=e,ds;}var ko;function jh(){if(ko)return is;ko=1,Object.defineProperty(is,"__esModule",{value:!0}),is.Azure=void 0;var i=Nh(),e=Dh(),t=Fh(),n=Uh(),s=Hh(),r=fa();var o=/*#__PURE__*/function(_r$Speech){function o(){var _this101;_classCallCheck(this,o);_this101=_callSuper(this,o,arguments),_this101._newTextPadding="";return _this101;}_inherits(o,_r$Speech);return _createClass(o,[{key:"start",value:function start(c,l){this._newTextPadding="",this.stopTimeout===void 0&&t.StopTimeout.reset(this,c==null?void 0:c.stopAfterSilenceMs),this.prepareBeforeStart(c),this.startAsync(c),l||i.PreventConnectionStop.applyPrevention(this);}},{key:"startAsync",value:function(){var _startAsync=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee185(c){var l,_t57;return _regenerator().w(function(_context185){while(1)switch(_context185.n){case 0:_t57=this.validate(c);if(!_t57){_context185.n=2;break;}_context185.n=1;return this.instantiateService(c);case 1:this._translations=c==null?void 0:c.translations;(l=this._service)===null||l===void 0||l.startContinuousRecognitionAsync(function(){},this.error);case 2:return _context185.a(2);}},_callee185,this);}));function startAsync(_x349){return _startAsync.apply(this,arguments);}return startAsync;}()},{key:"validate",value:function validate(c){return o.getAPI()?e.AzureSpeechConfig.validateOptions(this.error.bind(this),c):(this.moduleNotFound(),!1);}},{key:"instantiateService",value:function(){var _instantiateService=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee186(c){var l,d,p,u,_c$autoLanguage,g,y,_,S;return _regenerator().w(function(_context186){while(1)switch(_context186.n){case 0:l=o.getAPI();d=n.AzureAudioConfig.get(l.AudioConfig,c.deviceId);_context186.n=1;return e.AzureSpeechConfig.get(l.SpeechConfig,c);case 1:p=_context186.v;if(p){if(c.autoLanguage&&c.autoLanguage.languages.length>0){_c$autoLanguage=c.autoLanguage,g=_c$autoLanguage.type,y=_c$autoLanguage.languages,_=y.slice(0,g==="Continuous"?10:4),S=l.AutoDetectSourceLanguageConfig.fromLanguages(_);g==="Continuous"&&(S.mode=1),u=l.SpeechRecognizer.FromConfig(p,S,d);}else u=new l.SpeechRecognizer(p,d);this.setEvents(u),this._service=u,c.retrieveToken&&this.retrieveTokenInterval(c.retrieveToken);}else this.error("Unable to contact Azure server");case 2:return _context186.a(2);}},_callee186,this);}));function instantiateService(_x350){return _instantiateService.apply(this,arguments);}return instantiateService;}()},{key:"setEvents",value:function setEvents(c){c.recognizing=this.onRecognizing.bind(this),c.recognized=this.onRecognized.bind(this),c.sessionStarted=this.onSessionStarted.bind(this),c.canceled=this.onCanceled.bind(this),c.sessionStopped=this.onSessionStopped.bind(this);}// prettier-ignore
253
249
  },{key:"onRecognizing",value:function onRecognizing(c,l){if(this._stopping)return;var _s$AzureTranscript$ex=s.AzureTranscript.extract(this._newTextPadding+l.result.text,this.finalTranscript,!1,this._translations),d=_s$AzureTranscript$ex.interimTranscript,p=_s$AzureTranscript$ex.finalTranscript,u=_s$AzureTranscript$ex.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(d,p,u);}// prettier-ignore
254
- },{key:"onRecognized",value:function onRecognized(c,l){var d=l.result;switch(d.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(d.text&&!this._stopping){var _s$AzureTranscript$ex2=s.AzureTranscript.extract(this._newTextPadding+d.text,this.finalTranscript,!0,this._translations),p=_s$AzureTranscript$ex2.interimTranscript,u=_s$AzureTranscript$ex2.finalTranscript,g=_s$AzureTranscript$ex2.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(p,u,g),u!==""&&(this._newTextPadding=" ");}break;}}},{key:"onCanceled",value:function onCanceled(c,l){l.reason===window.SpeechSDK.CancellationReason.Error&&this.error(l.errorDetails);}},{key:"onSessionStarted",value:function onSessionStarted(){i.PreventConnectionStop.clearPrevention(this),this.setStateOnStart();}},{key:"onSessionStopped",value:function onSessionStopped(){this._retrieveTokenInterval||clearInterval(this._retrieveTokenInterval),this._stopping=!1,this.setStateOnStop();}},{key:"retrieveTokenInterval",value:function retrieveTokenInterval(c){var _this102=this;this._retrieveTokenInterval=setInterval(function(){c==null||c().then(function(l){_this102._service&&(_this102._service.authorizationToken=(l==null?void 0:l.trim())||"");})["catch"](function(l){_this102.error(l);});},1e4);}},{key:"stop",value:function stop(c){var l;!c&&this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),this._stopping=!0,(l=this._service)===null||l===void 0||l.stopContinuousRecognitionAsync(),t.StopTimeout.stop(this),this.finalise(c);}},{key:"moduleNotFound",value:function moduleNotFound(){console.error("speech recognition module not found:"),console.error("please install the 'microsoft-cognitiveservices-speech-sdk' npm package or add a script tag: <script src=\"https://aka.ms/csspeech/jsbrowserpackageraw\"></script>"),this.setStateOnError("speech recognition module not found");}},{key:"error",value:function error(c){this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),console.error(c),this.setStateOnError(c),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.SpeechSDK;}}]);}(r.Speech);return is.Azure=o,is;}var Lo;function qh(){if(Lo)return $s;Lo=1,Object.defineProperty($s,"__esModule",{value:!0});var i=Oh(),e=fa(),t=Nh(),n=$h();var s=/*#__PURE__*/function(){function s(){_classCallCheck(this,s);}return _createClass(s,null,[{key:"toggle",value:function toggle(o,a){var c,l;var d=o.toLocaleLowerCase().trim();!((c=t.GlobalState.service)===null||c===void 0)&&c.recognizing?this.stop():d==="webspeech"?s.startWebSpeech(a):d==="azure"?s.startAzure(a):(console.error("service not found - must be either 'webspeech' or 'azure'"),(l=a==null?void 0:a.onError)===null||l===void 0||l.call(a,"service not found - must be either 'webspeech' or 'azure'"));}},{key:"startWebSpeech",value:function startWebSpeech(o){s.stop()||(t.GlobalState.service=new i.WebSpeech(),t.GlobalState.service.start(o));}},{key:"isWebSpeechSupported",value:function isWebSpeechSupported(){return!!i.WebSpeech.getAPI();}},{key:"startAzure",value:function startAzure(o){var a;s.stop()||!((a=t.GlobalState.service)===null||a===void 0)&&a.cannotBeStopped||(t.GlobalState.service=new n.Azure(),t.GlobalState.service.start(o));}},{key:"stop",value:function stop(){var o;return t.GlobalState.doubleClickDetector()?!0:(!((o=t.GlobalState.service)===null||o===void 0)&&o.recognizing&&t.GlobalState.service.stop(),!1);}},{key:"endCommandMode",value:function endCommandMode(){t.GlobalState.service&&e.CommandUtils.toggleCommandModeOff(t.GlobalState.service);}}]);}();return $s["default"]=s,$s;}var Gh=qh();var zs=/* @__PURE__ */Rh(Gh);var zh=/*#__PURE__*/function(){function zh(e,t){_classCallCheck(this,zh);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(zh,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this103=this;this._silenceTimeout=setTimeout(function(){var n;(n=e.submit)==null||n.call(e),zs.stop(),_this103._stop||setTimeout(t,Ms.MICROPHONE_RESET_TIMEOUT_MS);},this._silenceMS);}},{key:"clearSilenceTimeout",value:function clearSilenceTimeout(){this._silenceTimeout&&clearTimeout(this._silenceTimeout);}},{key:"resetSilenceTimeout",value:function resetSilenceTimeout(e,t){this.clearSilenceTimeout(),this.setSilenceTimeout(e,t);}},{key:"onPause",value:function onPause(e,t,n){e?this.resetSilenceTimeout(t,n):this.clearSilenceTimeout();}}]);}();var xs=/*#__PURE__*/function(_Ci){function xs(e,t,n){var _this104;_classCallCheck(this,xs);var s=_typeof(e.speechToText)=="object"?e.speechToText:{};_this104=_callSuper(this,xs,[s==null?void 0:s.button]);var _this104$processConfi=_this104.processConfiguration(t,e.speechToText),r=_this104$processConfi.serviceName,o=_this104$processConfi.processedConfig;if(_this104._addErrorMessage=n,r==="webspeech"&&!zs.isWebSpeechSupported())_this104.changeToUnsupported();else{var a=!e.textInput||!e.textInput[j];z.assignButtonEvents(_this104.elementRef,_this104.buttonClick.bind(_this104,t,a,r,o));}setTimeout(function(){_this104._validationHandler=e._validationHandler;});return _this104;}// prettier-ignore
255
- _inherits(xs,_Ci);return _createClass(xs,[{key:"processConfiguration",value:function processConfiguration(e,t){var _n$displayInterimResu,_n$textColor,_n$translations,_n$commands,_n$events;var l;var n=_typeof(t)=="object"?t:{},s=_typeof(n.webSpeech)=="object"?n.webSpeech:{},r=n.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_n$displayInterimResu=n.displayInterimResults)!==null&&_n$displayInterimResu!==void 0?_n$displayInterimResu:void 0,textColor:(_n$textColor=n.textColor)!==null&&_n$textColor!==void 0?_n$textColor:void 0,translations:(_n$translations=n.translations)!==null&&_n$translations!==void 0?_n$translations:void 0,commands:(_n$commands=n.commands)!==null&&_n$commands!==void 0?_n$commands:void 0,events:(_n$events=n.events)!==null&&_n$events!==void 0?_n$events:void 0},s),r),a=(l=n.commands)==null?void 0:l.submit;return a&&(o.onPreResult=function(d){return d.toLowerCase().includes(a)?(setTimeout(function(){var p;return(p=e.submit)==null?void 0:p.call(e);}),zs.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),n.submitAfterSilence&&(this._silenceSubmit=new zh(n.submitAfterSilence,n.stopAfterSubmit)),{serviceName:xs.getServiceName(n),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,n,s){var _this105=this;var r=s==null?void 0:s.events;e.removePlaceholderStyle(),zs.toggle(n,_objectSpread({insertInCursorLocation:!1,element:t?e.inputElementRef:void 0,onError:function onError(){var o;_this105.onError(),(o=_this105._silenceSubmit)==null||o.clearSilenceTimeout();},onStart:function onStart(){var o;_this105.changeToActive(),(o=r==null?void 0:r.onStart)==null||o.call(r);},onStop:function onStop(){var o,a,c;(o=_this105._validationHandler)==null||o.call(_this105),(a=_this105._silenceSubmit)==null||a.clearSilenceTimeout(),_this105.changeToDefault(),(c=r==null?void 0:r.onStop)==null||c.call(r);},onPauseTrigger:function onPauseTrigger(o){var a,c;(a=_this105._silenceSubmit)==null||a.onPause(o,e,_this105.elementRef.onclick),(c=r==null?void 0:r.onPauseTrigger)==null||c.call(r,o);},onPreResult:function onPreResult(o,a){var c;(c=r==null?void 0:r.onPreResult)==null||c.call(r,o,a);},onResult:function onResult(o,a){var c,l,d;a&&((c=_this105._validationHandler)==null||c.call(_this105)),(l=_this105._silenceSubmit)==null||l.resetSilenceTimeout(e,_this105.elementRef.onclick),(d=r==null?void 0:r.onResult)==null||d.call(r,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this105.onCommandModeTrigger(o),(a=r==null?void 0:r.onCommandModeTrigger)==null||a.call(r,o);}},s));}},{key:"onCommandModeTrigger",value:function onCommandModeTrigger(e){e?this.changeToCommandMode():this.changeToActive();}},{key:"onError",value:function onError(){this._addErrorMessage("speechToText","speech input error");}}],[{key:"getServiceName",value:function getServiceName(e){return e.azure?"azure":"webspeech";}},{key:"toggleSpeechAfterSubmit",value:function toggleSpeechAfterSubmit(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;e[J](),t||setTimeout(function(){return e[J]();},xs.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(Ci);xs.MICROPHONE_RESET_TIMEOUT_MS=300;var Ms=xs;var Tt=/*#__PURE__*/function(){// prettier-ignore
256
- function Tt(e,t,n,s,r){var _this106=this;_classCallCheck(this,Tt);this._attachments=[],this._fileCountLimit=99,this._acceptedFormat="",this._hiddenAttachments=/* @__PURE__ */new Set(),n.maxNumberOfFiles&&(this._fileCountLimit=n.maxNumberOfFiles),this._toggleContainerDisplay=s,this._fileAttachmentsContainerRef=r,n.acceptedFormats&&(this._acceptedFormat=n.acceptedFormats),setTimeout(function(){_this106._validationHandler=e._validationHandler,_this106._onInput=t.onInput;});}return _createClass(Tt,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var n;return Tt.isFileTypeValid(e,this._acceptedFormat)?(this.addAttachmentBasedOnType(e,t,!0),(n=this._onInput)==null||n.call(this,!0),!0):!1;}},{key:"addAttachmentBasedOnType",value:function addAttachmentBasedOnType(e,t,n){var s=Tt.getTypeFromBlob(e);if(s===W){var r=Tt.createImageAttachment(t);this.addFileAttachment(e,W,r,n);}else if(s===$){var _r9=ks.createAudioAttachment(t);this.addFileAttachment(e,$,_r9,n);}else{var _r0=Tt.createAnyFileAttachment(e.name);this.addFileAttachment(e,rn,_r0,n);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,n,s){var a;var r=Tt.createContainer(n);if(this._attachments.length>=this._fileCountLimit){var c=this._attachments[this._attachments.length-1].removeButton;c==null||c[J]();var l=this._fileAttachmentsContainerRef.children;this._fileAttachmentsContainerRef.insertBefore(r,l[0]);}else this._fileAttachmentsContainerRef.appendChild(r);var o={file:e,attachmentContainerElement:r,fileType:t};return s&&(o.removeButton=this.createRemoveAttachmentButton(o),r.appendChild(o.removeButton)),this._toggleContainerDisplay(!0),this._attachments.push(o),this._fileAttachmentsContainerRef.scrollTop=this._fileAttachmentsContainerRef.scrollHeight,(a=this._validationHandler)==null||a.call(this),o;}},{key:"createRemoveAttachmentButton",value:function createRemoveAttachmentButton(e){var t=A();t[m].add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var n=A();return n[m].add("x-icon"),n.innerText="×",t.appendChild(n),t;}},{key:"removeAttachment",value:function removeAttachment(e,t){var r,o;var n=this._attachments.findIndex(function(a){return a===e;});if(n<0)return;(r=this._onInput)==null||r.call(this,!!(t!=null&&t.isTrusted));var s=this._attachments[n].attachmentContainerElement;this._attachments.splice(n,1),ks.stopAttachmentPlayback(s),s.remove(),this._toggleContainerDisplay(!1),(o=this._validationHandler)==null||o.call(this);}},{key:"getFiles",value:function getFiles(){return Array.from(this._attachments).map(function(e){return _defineProperty(_defineProperty({},se,e[se]),E,e.fileType);});}},{key:"hideAttachments",value:function hideAttachments(){var _this107=this;this._hiddenAttachments.clear(),this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t[J]();}),_this107._hiddenAttachments.add(e);});}},{key:"removeAttachments",value:function removeAttachments(){this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t[J]();});}),this._hiddenAttachments.clear();}},{key:"readdAttachments",value:function readdAttachments(){var _this108=this;var e;Array.from(this._hiddenAttachments).forEach(function(t){_this108._fileAttachmentsContainerRef.appendChild(t.attachmentContainerElement),_this108._attachments.push(t);}),(e=this._onInput)==null||e.call(this,!1),this._hiddenAttachments.clear();}}],[{key:"isFileTypeValid",value:function isFileTypeValid(e,t){if(t==="")return!0;var n=t.split(",");for(var s=0;s<n.length;s++){var r=n[s].trim();if(e[E]===r)return!0;if(r.startsWith(".")){var o=r.slice(1);if(e.name.endsWith(o))return!0;}else{if(e.name.endsWith(r))return!0;if(r.endsWith("/*")&&e[E].startsWith(r.slice(0,-2)))return!0;}}return!1;}},{key:"getTypeFromBlob",value:function getTypeFromBlob(e){var t=e.type;return t.startsWith(W)?W:t.startsWith($)?$:rn;}},{key:"createImageAttachment",value:function createImageAttachment(e){var t=new Image();return t[T]=e,t[m].add("image-attachment"),t;}},{key:"createAnyFileAttachment",value:function createAnyFileAttachment(e){var t=A();t[m].add("border-bound-attachment"),$e.IS_SAFARI&&t[m].add("border-bound-attachment-safari");var n=A();n[m].add("any-file-attachment-text");var s=A();return s[m].add("file-attachment-text-container"),s.appendChild(n),n.textContent=e,t.appendChild(s),t;}},{key:"createContainer",value:function createContainer(e){var t=A();return t[m].add("file-attachment"),t.appendChild(e),t;}}]);}();var wt=/*#__PURE__*/function(_Tt){// prettier-ignore
257
- function wt(e,t,n,s,r){_classCallCheck(this,wt);return _callSuper(this,wt,[e,t,n,s,r]);}_inherits(wt,_Tt);return _createClass(wt,[{key:"createTimer",value:function createTimer(e,t){var _this109=this;var n=0;var s=t!==void 0&&t<wt.TIMER_LIMIT_S?t:wt.TIMER_LIMIT_S;return setInterval(function(){var a;n+=1,n===s&&((a=_this109.stopPlaceholderCallback)==null||a.call(_this109),_this109.clearTimer()),n===600&&e[m].add("audio-placeholder-text-4-digits");var r=Math.floor(n/60),o=(n%60).toString().padStart(2,"0");e.textContent="".concat(r,":").concat(o);},1e3);}},{key:"createPlaceholderAudioAttachment",value:function createPlaceholderAudioAttachment(e){var t=wt.createAudioContainer(),n=A();n[m].add("audio-placeholder-text-3-digits");var s=A();s[m].add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),s.appendChild(n);var r=kt.createSVGElement(Xi);return r[m].add("attachment-icon","stop-icon","not-removable-attachment-icon"),n.textContent="0:00",this._activePlaceholderTimer=this.createTimer(n,e),t.appendChild(s),this.addPlaceholderAudioAttachmentEvents(t,r,s),t;}},{key:"addPlaceholderAudioAttachmentEvents",value:function addPlaceholderAudioAttachmentEvents(e,t,n){var _this110=this;var s=function s(){return e.replaceChildren(t);};e.addEventListener(Ps,s);var r=function r(){return e.replaceChildren(n);};e.addEventListener(an,r);var o=function o(){var a;return(a=_this110.stopPlaceholderCallback)==null?void 0:a.call(_this110);};e.addEventListener(J,o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var n=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),$,n,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
258
- },{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[se]=e,wt.addAudioElements(n.attachmentContainerElement.children[0],t),n.removeButton=this.createRemoveAttachmentButton(n),n.attachmentContainerElement.appendChild(n.removeButton),this._activePlaceholderAttachment=void 0,this.clearTimer());}},{key:"removePlaceholderAttachment",value:function removePlaceholderAttachment(){this._activePlaceholderAttachment&&(this.removeAttachment(this._activePlaceholderAttachment),this._activePlaceholderAttachment=void 0,this.clearTimer());}},{key:"clearTimer",value:function clearTimer(){this._activePlaceholderTimer!==void 0&&(clearInterval(this._activePlaceholderTimer),this._activePlaceholderTimer=void 0,this.stopPlaceholderCallback=void 0);}}],[{key:"createAudioContainer",value:function createAudioContainer(){var e=A();return e[m].add("border-bound-attachment","audio-attachment-icon-container"),$e.IS_SAFARI&&e[m].add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var n=e.parentElement?z.cloneElement(e):e,s=A($);s[T]=t;var r=kt.createSVGElement(ra);r[m].add("attachment-icon","play-icon");var o=kt.createSVGElement(Xi);o[m].add("attachment-icon","stop-icon"),n.replaceChildren(r),s.onplay=function(){n.replaceChildren(o);},s.onpause=function(){n.replaceChildren(r),s.currentTime=0;},s.onended=function(){n.replaceChildren(r);},z.assignButtonEvents(n,function(){s.paused?s.play():s.pause();});}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=wt.createAudioContainer();return wt.addAudioElements(t,e),t;}},{key:"stopAttachmentPlayback",value:function stopAttachmentPlayback(e){var t,n,s;(s=(n=(t=e.children[0])==null?void 0:t.children)==null?void 0:n[0])!=null&&s[m].contains("stop-icon")&&e.children[0][J]();}}]);}(Tt);wt.TIMER_LIMIT_S=5999;var ks=wt;var Vh=/*#__PURE__*/function(){function Vh(){_classCallCheck(this,Vh);}return _createClass(Vh,null,[{key:"create",value:// prettier-ignore
259
- function create(e,t,n,s,r,o){return o===$?new ks(e,t,n,s,r):new Tt(e,t,n,s,r);}}]);}();var Ns=/*#__PURE__*/function(){function Ns(e,t,n){_classCallCheck(this,Ns);this._fileAttachmentsTypes=[],this.elementRef=this.createAttachmentContainer();var s=_typeof(n)=="object"&&!!n.displayFileAttachmentContainer;this.toggleContainerDisplay(s),e.appendChild(this.elementRef),t&&Object.assign(this.elementRef[v],t);}// prettier-ignore
260
- return _createClass(Ns,[{key:"addType",value:function addType(e,t,n,s){var r=Vh.create(e,t,n,this.toggleContainerDisplay.bind(this),this.elementRef,s);return this._fileAttachmentsTypes.push(r),r;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=A();return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef[v].display="block":this.elementRef.children.length===0&&(this.elementRef[v].display="none");}},{key:"getAllFileData",value:function getAllFileData(){var e=this._fileAttachmentsTypes.map(function(t){return t.getFiles();}).flat();return e.length>0?e:void 0;}},{key:"completePlaceholders",value:function(){var _completePlaceholders=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee188(){return _regenerator().w(function(_context188){while(1)switch(_context188.n){case 0:_context188.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref259=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee187(e){var t;return _regenerator().w(function(_context187){while(1)switch(_context187.n){case 0:return _context187.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee187);}));return function(_x351){return _ref259.apply(this,arguments);};}()));case 1:return _context188.a(2);}},_callee188,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){Ns.addFilesToType(e,this._fileAttachmentsTypes);}},{key:"hideFiles",value:function hideFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.hideAttachments();}),this.elementRef.replaceChildren(),this.toggleContainerDisplay(!1);}},{key:"removeHiddenFiles",value:function removeHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.removeAttachments();});}},{key:"readdHiddenFiles",value:function readdHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.readdAttachments();}),this.toggleContainerDisplay(!0);}},{key:"getNumberOfTypes",value:function getNumberOfTypes(){return this._fileAttachmentsTypes.length;}}],[{key:"addFilesToType",value:function addFilesToType(e,t){e.forEach(function(n){var s=new FileReader();s.readAsDataURL(n),s.onload=function(r){for(var o=0;o<t.length&&!t[o].attemptAddFile(n,r.target.result);o+=1);};});}}]);}();var at=/*#__PURE__*/function(){function at(e,t,n){_classCallCheck(this,at);this._isOpen=!1,this._contentRef=at.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=at.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=at.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=at.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(at,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this111=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){me.addAttributes(t),_this111._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this112=this;this._elementRef[m].remove("show-modal"),this._elementRef[m].add("hide-modal"),this._backgroundPanelRef[m].remove("show-modal-background"),this._backgroundPanelRef[m].add("hide-modal-background"),this._isOpen=!1,setTimeout(function(){_this112._elementRef[v].display="none",_this112._backgroundPanelRef[v].display="none";},at.MODAL_CLOSE_TIMEOUT_MS);}},{key:"displayModalElements",value:function displayModalElements(){this._elementRef[v].display="flex",this._elementRef[m].remove("hide-modal"),this._elementRef[m].add("show-modal"),this._backgroundPanelRef[v].display="block",this._backgroundPanelRef[m].remove("hide-modal-background"),this._backgroundPanelRef[m].add("show-modal-background"),this._isOpen=!0;}},{key:"openTextModal",value:function openTextModal(e){this._contentRef.innerHTML=e,this.displayModalElements();}},{key:"addCloseButton",value:function addCloseButton(e,t,n){var _this113=this;var s=t?at.createSVGButton(e):at.createTextButton(e);return this.addButtons(s),z.assignButtonEvents(s,function(){_this113.close(),setTimeout(function(){n==null||n();},140);}),s;}},{key:"addWindowEvents",value:function addWindowEvents(e){this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent);}},{key:"windowKeyDown",value:function windowKeyDown(e,t){var n,s;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===_e.ESCAPE?(this.close(),(n=this.extensionCloseCallback)==null||n.call(this)):t.key===_e.ENTER&&(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)));}}],[{key:"createContainer",value:function createContainer(e,t){var n=A();return n[m].add("modal"),n.appendChild(e),t&&delete t.backgroundColor,Object.assign(n[v],t),n;}},{key:"createModalContent",value:function createModalContent(e,t){var _n$m;var n=A();return(_n$m=n[m]).add.apply(_n$m,_toConsumableArray(e)),t&&(n[v].backgroundColor=t),A().appendChild(n),n;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=A();return t[m].add("modal-button-panel"),e&&(t[v].backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=A();return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=A();return t[m].add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=A();t[m].add("modal-button","modal-svg-button");var n=kt.createSVGElement(e);return n[m].add("modal-svg-button-icon"),t.appendChild(n),t;}},{key:"createTextModalFunc",value:function createTextModalFunc(e,t,n){var s;if(_typeof(t)=="object"&&(s=t[b])!=null&&s.infoModal){var r=new at(e,["modal-content"],t[b].infoModal.containerStyle);return r.addCloseButton("OK",!1,n),r.openTextModal.bind(r,t.infoModalTextMarkUp||"");}}}]);}();at.MODAL_CLOSE_TIMEOUT_MS=190;var en=at;var fi=/*#__PURE__*/function(_mn5){// prettier-ignore
261
- function fi(e,t,n,s,r,o){var _this114;_classCallCheck(this,fi);var p,u,g,y,_,S,M,K,ie,re;var a=de.processPosition((p=n==null?void 0:n.button)==null?void 0:p.position),c=((y=(g=(u=n==null?void 0:n.button)==null?void 0:u[R])==null?void 0:g[h])==null?void 0:y.content)||o,l=ut.tryCreateConfig("Upload File",(_=n==null?void 0:n.button)==null?void 0:_.tooltip);_this114=_callSuper(this,fi,[fi.createButtonElement(),r,a,l,n.button,c]);var d=_this114.createInnerElementsForStates(s,_this114.customStyles);_this114._inputElement=fi.createInputElement((S=n==null?void 0:n[b])==null?void 0:S.acceptedFormats),_this114.addClickEvent(e,n),_this114.changeElementsByState(d[R]),_this114.reapplyStateStyle(R),_this114._fileAttachmentsType=t,_this114._openModalOnce=((K=(M=n[b])==null?void 0:M.infoModal)==null?void 0:K.openModalOnce)===!1||(re=(ie=n[b])==null?void 0:ie.infoModal)==null?void 0:re.openModalOnce;return _this114;}_inherits(fi,_mn5);return _createClass(fi,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e,t){return _defineProperty({},R,this.createInnerElements(e,R,t));}},{key:"triggerImportPrompt",value:function triggerImportPrompt(e){e.onchange=this["import"].bind(this,e),e[J]();}},{key:"import",value:function _import(e){Ns.addFilesToType(Array.from(e[b]||[]),[this._fileAttachmentsType]),e.value="";}},{key:"addClickEvent",value:function addClickEvent(e,t){var n=this.triggerImportPrompt.bind(this,this._inputElement),s=en.createTextModalFunc(e,t,n);this.elementRef.onclick=this[J].bind(this,s);}},{key:"click",value:function click(e){e&&(this._openModalOnce===void 0||this._openModalOnce===!0)?(e(),this._openModalOnce===!0&&(this._openModalOnce=!1)):this.triggerImportPrompt(this._inputElement);}}],[{key:"createInputElement",value:function createInputElement(e){var t=A("input");return t[E]=se,t.accept=e||"",t.hidden=!0,t.multiple=!0,t;}},{key:"createButtonElement",value:function createButtonElement(){var e=A();return e[m].add("input-button"),e;}}]);}(mn);var Ct=/*#__PURE__*/function(){function Ct(){_classCallCheck(this,Ct);}return _createClass(Ct,null,[{key:"create",value:function create(e,t,n){var s=Ct.createElement(n);Ct.addEvents(s,e,t),e.appendChild(s);}},{key:"createElement",value:function createElement(e){var t=A();return t.id="drag-and-drop",_typeof(e)===U&&Object.assign(t[v],e),t;}},{key:"addEvents",value:function addEvents(e,t,n){t.ondragenter=function(s){s.preventDefault(),Ct.display(e);},e.ondragleave=function(s){s.preventDefault(),Ct.hide(e);},e.ondragover=function(s){s.preventDefault();},e.ondrop=function(s){s.preventDefault(),Ct.uploadFile(n,s),Ct.hide(e);};}},{key:"uploadFile",value:function uploadFile(e,t){var s;var n=(s=t.dataTransfer)==null?void 0:s[b];n&&e.addFilesToAnyType(Array.from(n));}},{key:"display",value:function display(e){e[v].display="block";}},{key:"hide",value:function hide(e){e[v].display="none";}},{key:"isEnabled",value:function isEnabled(e,t){return t!==void 0&&t===!1?!1:!!t||e.getNumberOfTypes()>0;}}]);}();var Kt=/*#__PURE__*/function(){function Kt(){_classCallCheck(this,Kt);}return _createClass(Kt,null,[{key:"validate",value:// prettier-ignore
250
+ },{key:"onRecognized",value:function onRecognized(c,l){var d=l.result;switch(d.reason){case window.SpeechSDK.ResultReason.Canceled:break;case window.SpeechSDK.ResultReason.RecognizedSpeech:if(d.text&&!this._stopping){var _s$AzureTranscript$ex2=s.AzureTranscript.extract(this._newTextPadding+d.text,this.finalTranscript,!0,this._translations),p=_s$AzureTranscript$ex2.interimTranscript,u=_s$AzureTranscript$ex2.finalTranscript,g=_s$AzureTranscript$ex2.newText;t.StopTimeout.reset(this,this.stopTimeoutMS),this.updateElements(p,u,g),u!==""&&(this._newTextPadding=" ");}break;}}},{key:"onCanceled",value:function onCanceled(c,l){l.reason===window.SpeechSDK.CancellationReason.Error&&this.error(l.errorDetails);}},{key:"onSessionStarted",value:function onSessionStarted(){i.PreventConnectionStop.clearPrevention(this),this.setStateOnStart();}},{key:"onSessionStopped",value:function onSessionStopped(){this._retrieveTokenInterval||clearInterval(this._retrieveTokenInterval),this._stopping=!1,this.setStateOnStop();}},{key:"retrieveTokenInterval",value:function retrieveTokenInterval(c){var _this102=this;this._retrieveTokenInterval=setInterval(function(){c==null||c().then(function(l){_this102._service&&(_this102._service.authorizationToken=(l==null?void 0:l.trim())||"");})["catch"](function(l){_this102.error(l);});},1e4);}},{key:"stop",value:function stop(c){var l;!c&&this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),this._stopping=!0,(l=this._service)===null||l===void 0||l.stopContinuousRecognitionAsync(),t.StopTimeout.stop(this),this.finalise(c);}},{key:"moduleNotFound",value:function moduleNotFound(){console.error("speech recognition module not found:"),console.error("please install the 'microsoft-cognitiveservices-speech-sdk' npm package or add a script tag: <script src=\"https://aka.ms/csspeech/jsbrowserpackageraw\"></script>"),this.setStateOnError("speech recognition module not found");}},{key:"error",value:function error(c){this._retrieveTokenInterval&&clearInterval(this._retrieveTokenInterval),console.error(c),this.setStateOnError(c),this.stop();}}],[{key:"getAPI",value:function getAPI(){return window.SpeechSDK;}}]);}(r.Speech);return is.Azure=o,is;}var Po;function $h(){if(Po)return js;Po=1,Object.defineProperty(js,"__esModule",{value:!0});var i=Lh(),e=pa(),t=Oh(),n=jh();var s=/*#__PURE__*/function(){function s(){_classCallCheck(this,s);}return _createClass(s,null,[{key:"toggle",value:function toggle(o,a){var c,l;var d=o.toLocaleLowerCase().trim();!((c=t.GlobalState.service)===null||c===void 0)&&c.recognizing?this.stop():d==="webspeech"?s.startWebSpeech(a):d==="azure"?s.startAzure(a):(console.error("service not found - must be either 'webspeech' or 'azure'"),(l=a==null?void 0:a.onError)===null||l===void 0||l.call(a,"service not found - must be either 'webspeech' or 'azure'"));}},{key:"startWebSpeech",value:function startWebSpeech(o){s.stop()||(t.GlobalState.service=new i.WebSpeech(),t.GlobalState.service.start(o));}},{key:"isWebSpeechSupported",value:function isWebSpeechSupported(){return!!i.WebSpeech.getAPI();}},{key:"startAzure",value:function startAzure(o){var a;s.stop()||!((a=t.GlobalState.service)===null||a===void 0)&&a.cannotBeStopped||(t.GlobalState.service=new n.Azure(),t.GlobalState.service.start(o));}},{key:"stop",value:function stop(){var o;return t.GlobalState.doubleClickDetector()?!0:(!((o=t.GlobalState.service)===null||o===void 0)&&o.recognizing&&t.GlobalState.service.stop(),!1);}},{key:"endCommandMode",value:function endCommandMode(){t.GlobalState.service&&e.CommandUtils.toggleCommandModeOff(t.GlobalState.service);}}]);}();return js["default"]=s,js;}var qh=$h();var Gs=/* @__PURE__ */Th(qh);var Gh=/*#__PURE__*/function(){function Gh(e,t){_classCallCheck(this,Gh);this._silenceMS=2e3,this._stop=!0,typeof t=="boolean"&&t===!1&&(this._stop=!1),typeof e=="number"&&(this._silenceMS=e);}return _createClass(Gh,[{key:"setSilenceTimeout",value:function setSilenceTimeout(e,t){var _this103=this;this._silenceTimeout=setTimeout(function(){var n;(n=e.submit)==null||n.call(e),Gs.stop(),_this103._stop||setTimeout(t,Is.MICROPHONE_RESET_TIMEOUT_MS);},this._silenceMS);}},{key:"clearSilenceTimeout",value:function clearSilenceTimeout(){this._silenceTimeout&&clearTimeout(this._silenceTimeout);}},{key:"resetSilenceTimeout",value:function resetSilenceTimeout(e,t){this.clearSilenceTimeout(),this.setSilenceTimeout(e,t);}},{key:"onPause",value:function onPause(e,t,n){e?this.resetSilenceTimeout(t,n):this.clearSilenceTimeout();}}]);}();var Ss=/*#__PURE__*/function(_Ai){function Ss(e,t,n){var _this104;_classCallCheck(this,Ss);var s=_typeof(e.speechToText)=="object"?e.speechToText:{};_this104=_callSuper(this,Ss,[s==null?void 0:s.button]);var _this104$processConfi=_this104.processConfiguration(t,e.speechToText),r=_this104$processConfi.serviceName,o=_this104$processConfi.processedConfig;if(_this104._addErrorMessage=n,r==="webspeech"&&!Gs.isWebSpeechSupported())_this104.changeToUnsupported();else{var a=!e.textInput||!e.textInput[j];z.assignButtonEvents(_this104.elementRef,_this104.buttonClick.bind(_this104,t,a,r,o));}setTimeout(function(){_this104._validationHandler=e._validationHandler;});return _this104;}// prettier-ignore
251
+ _inherits(Ss,_Ai);return _createClass(Ss,[{key:"processConfiguration",value:function processConfiguration(e,t){var _n$displayInterimResu,_n$textColor,_n$translations,_n$commands,_n$events;var l;var n=_typeof(t)=="object"?t:{},s=_typeof(n.webSpeech)=="object"?n.webSpeech:{},r=n.azure||{},o=_objectSpread(_objectSpread({displayInterimResults:(_n$displayInterimResu=n.displayInterimResults)!==null&&_n$displayInterimResu!==void 0?_n$displayInterimResu:void 0,textColor:(_n$textColor=n.textColor)!==null&&_n$textColor!==void 0?_n$textColor:void 0,translations:(_n$translations=n.translations)!==null&&_n$translations!==void 0?_n$translations:void 0,commands:(_n$commands=n.commands)!==null&&_n$commands!==void 0?_n$commands:void 0,events:(_n$events=n.events)!==null&&_n$events!==void 0?_n$events:void 0},s),r),a=(l=n.commands)==null?void 0:l.submit;return a&&(o.onPreResult=function(d){return d.toLowerCase().includes(a)?(setTimeout(function(){var p;return(p=e.submit)==null?void 0:p.call(e);}),Gs.endCommandMode(),{restart:!0,removeNewText:!0}):null;}),n.submitAfterSilence&&(this._silenceSubmit=new Gh(n.submitAfterSilence,n.stopAfterSubmit)),{serviceName:Ss.getServiceName(n),processedConfig:o};}},{key:"buttonClick",value:function buttonClick(e,t,n,s){var _this105=this;var r=s==null?void 0:s.events;e.removePlaceholderStyle(),Gs.toggle(n,_objectSpread({insertInCursorLocation:!1,element:t?e.inputElementRef:void 0,onError:function onError(){var o;_this105.onError(),(o=_this105._silenceSubmit)==null||o.clearSilenceTimeout();},onStart:function onStart(){var o;_this105.changeToActive(),(o=r==null?void 0:r.onStart)==null||o.call(r);},onStop:function onStop(){var o,a,c;(o=_this105._validationHandler)==null||o.call(_this105),(a=_this105._silenceSubmit)==null||a.clearSilenceTimeout(),_this105.changeToDefault(),(c=r==null?void 0:r.onStop)==null||c.call(r);},onPauseTrigger:function onPauseTrigger(o){var a,c;(a=_this105._silenceSubmit)==null||a.onPause(o,e,_this105.elementRef.onclick),(c=r==null?void 0:r.onPauseTrigger)==null||c.call(r,o);},onPreResult:function onPreResult(o,a){var c;(c=r==null?void 0:r.onPreResult)==null||c.call(r,o,a);},onResult:function onResult(o,a){var c,l,d;a&&((c=_this105._validationHandler)==null||c.call(_this105)),(l=_this105._silenceSubmit)==null||l.resetSilenceTimeout(e,_this105.elementRef.onclick),(d=r==null?void 0:r.onResult)==null||d.call(r,o,a);},onCommandModeTrigger:function onCommandModeTrigger(o){var a;_this105.onCommandModeTrigger(o),(a=r==null?void 0:r.onCommandModeTrigger)==null||a.call(r,o);}},s));}},{key:"onCommandModeTrigger",value:function onCommandModeTrigger(e){e?this.changeToCommandMode():this.changeToActive();}},{key:"onError",value:function onError(){this._addErrorMessage("speechToText","speech input error");}}],[{key:"getServiceName",value:function getServiceName(e){return e.azure?"azure":"webspeech";}},{key:"toggleSpeechAfterSubmit",value:function toggleSpeechAfterSubmit(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;e[J](),t||setTimeout(function(){return e[J]();},Ss.MICROPHONE_RESET_TIMEOUT_MS);}}]);}(Ai);Ss.MICROPHONE_RESET_TIMEOUT_MS=300;var Is=Ss;var Tt=/*#__PURE__*/function(){// prettier-ignore
252
+ function Tt(e,t,n,s,r){var _this106=this;_classCallCheck(this,Tt);this._attachments=[],this._fileCountLimit=99,this._acceptedFormat="",this._hiddenAttachments=/* @__PURE__ */new Set(),n.maxNumberOfFiles&&(this._fileCountLimit=n.maxNumberOfFiles),this._toggleContainerDisplay=s,this._fileAttachmentsContainerRef=r,n.acceptedFormats&&(this._acceptedFormat=n.acceptedFormats),setTimeout(function(){_this106._validationHandler=e._validationHandler,_this106._onInput=t.onInput;});}return _createClass(Tt,[{key:"attemptAddFile",value:function attemptAddFile(e,t){var n;return Tt.isFileTypeValid(e,this._acceptedFormat)?(this.addAttachmentBasedOnType(e,t,!0),(n=this._onInput)==null||n.call(this,!0),!0):!1;}},{key:"addAttachmentBasedOnType",value:function addAttachmentBasedOnType(e,t,n){var s=Tt.getTypeFromBlob(e);if(s===W){var r=Tt.createImageAttachment(t);this.addFileAttachment(e,W,r,n);}else if(s===$){var _r9=Ms.createAudioAttachment(t);this.addFileAttachment(e,$,_r9,n);}else{var _r0=Tt.createAnyFileAttachment(e.name);this.addFileAttachment(e,on,_r0,n);}}},{key:"addFileAttachment",value:function addFileAttachment(e,t,n,s){var a;var r=Tt.createContainer(n);if(this._attachments.length>=this._fileCountLimit){var c=this._attachments[this._attachments.length-1].removeButton;c==null||c[J]();var l=this._fileAttachmentsContainerRef.children;this._fileAttachmentsContainerRef.insertBefore(r,l[0]);}else this._fileAttachmentsContainerRef.appendChild(r);var o={file:e,attachmentContainerElement:r,fileType:t};return s&&(o.removeButton=this.createRemoveAttachmentButton(o),r.appendChild(o.removeButton)),this._toggleContainerDisplay(!0),this._attachments.push(o),this._fileAttachmentsContainerRef.scrollTop=this._fileAttachmentsContainerRef.scrollHeight,(a=this._validationHandler)==null||a.call(this),o;}},{key:"createRemoveAttachmentButton",value:function createRemoveAttachmentButton(e){var t=A();t[m].add("remove-file-attachment-button"),t.onclick=this.removeAttachment.bind(this,e);var n=A();return n[m].add("x-icon"),n.innerText="×",t.appendChild(n),t;}},{key:"removeAttachment",value:function removeAttachment(e,t){var r,o;var n=this._attachments.findIndex(function(a){return a===e;});if(n<0)return;(r=this._onInput)==null||r.call(this,!!(t!=null&&t.isTrusted));var s=this._attachments[n].attachmentContainerElement;this._attachments.splice(n,1),Ms.stopAttachmentPlayback(s),s.remove(),this._toggleContainerDisplay(!1),(o=this._validationHandler)==null||o.call(this);}},{key:"getFiles",value:function getFiles(){return Array.from(this._attachments).map(function(e){return _defineProperty(_defineProperty({},se,e[se]),E,e.fileType);});}},{key:"hideAttachments",value:function hideAttachments(){var _this107=this;this._hiddenAttachments.clear(),this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t[J]();}),_this107._hiddenAttachments.add(e);});}},{key:"removeAttachments",value:function removeAttachments(){this._attachments.forEach(function(e){setTimeout(function(){var t;return(t=e.removeButton)==null?void 0:t[J]();});}),this._hiddenAttachments.clear();}},{key:"readdAttachments",value:function readdAttachments(){var _this108=this;var e;Array.from(this._hiddenAttachments).forEach(function(t){_this108._fileAttachmentsContainerRef.appendChild(t.attachmentContainerElement),_this108._attachments.push(t);}),(e=this._onInput)==null||e.call(this,!1),this._hiddenAttachments.clear();}}],[{key:"isFileTypeValid",value:function isFileTypeValid(e,t){if(t==="")return!0;var n=t.split(",");for(var s=0;s<n.length;s++){var r=n[s].trim();if(e[E]===r)return!0;if(r.startsWith(".")){var o=r.slice(1);if(e.name.endsWith(o))return!0;}else{if(e.name.endsWith(r))return!0;if(r.endsWith("/*")&&e[E].startsWith(r.slice(0,-2)))return!0;}}return!1;}},{key:"getTypeFromBlob",value:function getTypeFromBlob(e){var t=e.type;return t.startsWith(W)?W:t.startsWith($)?$:on;}},{key:"createImageAttachment",value:function createImageAttachment(e){var t=new Image();return t[T]=e,t[m].add("image-attachment"),t;}},{key:"createAnyFileAttachment",value:function createAnyFileAttachment(e){var t=A();t[m].add("border-bound-attachment"),$e.IS_SAFARI&&t[m].add("border-bound-attachment-safari");var n=A();n[m].add("any-file-attachment-text");var s=A();return s[m].add("file-attachment-text-container"),s.appendChild(n),n.textContent=e,t.appendChild(s),t;}},{key:"createContainer",value:function createContainer(e){var t=A();return t[m].add("file-attachment"),t.appendChild(e),t;}}]);}();var wt=/*#__PURE__*/function(_Tt){// prettier-ignore
253
+ function wt(e,t,n,s,r){_classCallCheck(this,wt);return _callSuper(this,wt,[e,t,n,s,r]);}_inherits(wt,_Tt);return _createClass(wt,[{key:"createTimer",value:function createTimer(e,t){var _this109=this;var n=0;var s=t!==void 0&&t<wt.TIMER_LIMIT_S?t:wt.TIMER_LIMIT_S;return setInterval(function(){var a;n+=1,n===s&&((a=_this109.stopPlaceholderCallback)==null||a.call(_this109),_this109.clearTimer()),n===600&&e[m].add("audio-placeholder-text-4-digits");var r=Math.floor(n/60),o=(n%60).toString().padStart(2,"0");e.textContent="".concat(r,":").concat(o);},1e3);}},{key:"createPlaceholderAudioAttachment",value:function createPlaceholderAudioAttachment(e){var t=wt.createAudioContainer(),n=A();n[m].add("audio-placeholder-text-3-digits");var s=A();s[m].add("file-attachment-text-container","audio-placeholder-text-3-digits-container"),s.appendChild(n);var r=kt.createSVGElement(Ki);return r[m].add("attachment-icon","stop-icon","not-removable-attachment-icon"),n.textContent="0:00",this._activePlaceholderTimer=this.createTimer(n,e),t.appendChild(s),this.addPlaceholderAudioAttachmentEvents(t,r,s),t;}},{key:"addPlaceholderAudioAttachmentEvents",value:function addPlaceholderAudioAttachmentEvents(e,t,n){var _this110=this;var s=function s(){return e.replaceChildren(t);};e.addEventListener(ks,s);var r=function r(){return e.replaceChildren(n);};e.addEventListener(cn,r);var o=function o(){var a;return(a=_this110.stopPlaceholderCallback)==null?void 0:a.call(_this110);};e.addEventListener(J,o);}},{key:"addPlaceholderAttachment",value:function addPlaceholderAttachment(e,t){var n=this.createPlaceholderAudioAttachment(t);this._activePlaceholderAttachment=this.addFileAttachment(new File([],""),$,n,!1),this.stopPlaceholderCallback=e;}// prettier-ignore
254
+ },{key:"completePlaceholderAttachment",value:function completePlaceholderAttachment(e,t){var n=this._activePlaceholderAttachment;n&&(n[se]=e,wt.addAudioElements(n.attachmentContainerElement.children[0],t),n.removeButton=this.createRemoveAttachmentButton(n),n.attachmentContainerElement.appendChild(n.removeButton),this._activePlaceholderAttachment=void 0,this.clearTimer());}},{key:"removePlaceholderAttachment",value:function removePlaceholderAttachment(){this._activePlaceholderAttachment&&(this.removeAttachment(this._activePlaceholderAttachment),this._activePlaceholderAttachment=void 0,this.clearTimer());}},{key:"clearTimer",value:function clearTimer(){this._activePlaceholderTimer!==void 0&&(clearInterval(this._activePlaceholderTimer),this._activePlaceholderTimer=void 0,this.stopPlaceholderCallback=void 0);}}],[{key:"createAudioContainer",value:function createAudioContainer(){var e=A();return e[m].add("border-bound-attachment","audio-attachment-icon-container"),$e.IS_SAFARI&&e[m].add("border-bound-attachment-safari"),e;}},{key:"addAudioElements",value:function addAudioElements(e,t){var n=e.parentElement?z.cloneElement(e):e,s=A($);s[T]=t;var r=kt.createSVGElement(ia);r[m].add("attachment-icon","play-icon");var o=kt.createSVGElement(Ki);o[m].add("attachment-icon","stop-icon"),n.replaceChildren(r),s.onplay=function(){n.replaceChildren(o);},s.onpause=function(){n.replaceChildren(r),s.currentTime=0;},s.onended=function(){n.replaceChildren(r);},z.assignButtonEvents(n,function(){s.paused?s.play():s.pause();});}},{key:"createAudioAttachment",value:function createAudioAttachment(e){var t=wt.createAudioContainer();return wt.addAudioElements(t,e),t;}},{key:"stopAttachmentPlayback",value:function stopAttachmentPlayback(e){var t,n,s;(s=(n=(t=e.children[0])==null?void 0:t.children)==null?void 0:n[0])!=null&&s[m].contains("stop-icon")&&e.children[0][J]();}}]);}(Tt);wt.TIMER_LIMIT_S=5999;var Ms=wt;var zh=/*#__PURE__*/function(){function zh(){_classCallCheck(this,zh);}return _createClass(zh,null,[{key:"create",value:// prettier-ignore
255
+ function create(e,t,n,s,r,o){return o===$?new Ms(e,t,n,s,r):new Tt(e,t,n,s,r);}}]);}();var Os=/*#__PURE__*/function(){function Os(e,t,n){_classCallCheck(this,Os);this._fileAttachmentsTypes=[],this.elementRef=this.createAttachmentContainer();var s=_typeof(n)=="object"&&!!n.displayFileAttachmentContainer;this.toggleContainerDisplay(s),e.appendChild(this.elementRef),t&&Object.assign(this.elementRef[v],t);}// prettier-ignore
256
+ return _createClass(Os,[{key:"addType",value:function addType(e,t,n,s){var r=zh.create(e,t,n,this.toggleContainerDisplay.bind(this),this.elementRef,s);return this._fileAttachmentsTypes.push(r),r;}},{key:"createAttachmentContainer",value:function createAttachmentContainer(){var e=A();return e.id="file-attachment-container",e;}},{key:"toggleContainerDisplay",value:function toggleContainerDisplay(e){e?this.elementRef[v].display="block":this.elementRef.children.length===0&&(this.elementRef[v].display="none");}},{key:"getAllFileData",value:function getAllFileData(){var e=this._fileAttachmentsTypes.map(function(t){return t.getFiles();}).flat();return e.length>0?e:void 0;}},{key:"completePlaceholders",value:function(){var _completePlaceholders=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee188(){return _regenerator().w(function(_context188){while(1)switch(_context188.n){case 0:_context188.n=1;return Promise.all(this._fileAttachmentsTypes.map(/*#__PURE__*/function(){var _ref263=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee187(e){var t;return _regenerator().w(function(_context187){while(1)switch(_context187.n){case 0:return _context187.a(2,(t=e.stopPlaceholderCallback)==null?void 0:t.call(e));}},_callee187);}));return function(_x351){return _ref263.apply(this,arguments);};}()));case 1:return _context188.a(2);}},_callee188,this);}));function completePlaceholders(){return _completePlaceholders.apply(this,arguments);}return completePlaceholders;}()},{key:"addFilesToAnyType",value:function addFilesToAnyType(e){Os.addFilesToType(e,this._fileAttachmentsTypes);}},{key:"hideFiles",value:function hideFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.hideAttachments();}),this.elementRef.replaceChildren(),this.toggleContainerDisplay(!1);}},{key:"removeHiddenFiles",value:function removeHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.removeAttachments();});}},{key:"readdHiddenFiles",value:function readdHiddenFiles(){this._fileAttachmentsTypes.forEach(function(e){return e.readdAttachments();}),this.toggleContainerDisplay(!0);}},{key:"getNumberOfTypes",value:function getNumberOfTypes(){return this._fileAttachmentsTypes.length;}}],[{key:"addFilesToType",value:function addFilesToType(e,t){e.forEach(function(n){var s=new FileReader();s.readAsDataURL(n),s.onload=function(r){for(var o=0;o<t.length&&!t[o].attemptAddFile(n,r.target.result);o+=1);};});}}]);}();var at=/*#__PURE__*/function(){function at(e,t,n){_classCallCheck(this,at);this._isOpen=!1,this._contentRef=at.createModalContent(t,n==null?void 0:n.backgroundColor),this._buttonPanel=at.createButtonPanel(n==null?void 0:n.backgroundColor),this._elementRef=at.createContainer(this._contentRef,n),this._elementRef.appendChild(this._buttonPanel),e.appendChild(this._elementRef),this._backgroundPanelRef=at.createDarkBackgroundPanel(),e.appendChild(this._backgroundPanelRef),this.addWindowEvents(e);}return _createClass(at,[{key:"isOpen",value:function isOpen(){return this._isOpen;}},{key:"addButtons",value:function addButtons(){var _this111=this;for(var _len2=arguments.length,e=new Array(_len2),_key2=0;_key2<_len2;_key2++){e[_key2]=arguments[_key2];}e.forEach(function(t){me.addAttributes(t),_this111._buttonPanel.appendChild(t);});}},{key:"close",value:function close(){var _this112=this;this._elementRef[m].remove("show-modal"),this._elementRef[m].add("hide-modal"),this._backgroundPanelRef[m].remove("show-modal-background"),this._backgroundPanelRef[m].add("hide-modal-background"),this._isOpen=!1,setTimeout(function(){_this112._elementRef[v].display="none",_this112._backgroundPanelRef[v].display="none";},at.MODAL_CLOSE_TIMEOUT_MS);}},{key:"displayModalElements",value:function displayModalElements(){this._elementRef[v].display="flex",this._elementRef[m].remove("hide-modal"),this._elementRef[m].add("show-modal"),this._backgroundPanelRef[v].display="block",this._backgroundPanelRef[m].remove("hide-modal-background"),this._backgroundPanelRef[m].add("show-modal-background"),this._isOpen=!0;}},{key:"openTextModal",value:function openTextModal(e){this._contentRef.innerHTML=e,this.displayModalElements();}},{key:"addCloseButton",value:function addCloseButton(e,t,n){var _this113=this;var s=t?at.createSVGButton(e):at.createTextButton(e);return this.addButtons(s),z.assignButtonEvents(s,function(){_this113.close(),setTimeout(function(){n==null||n();},140);}),s;}},{key:"addWindowEvents",value:function addWindowEvents(e){this.keyDownEvent=this.windowKeyDown.bind(this,e),window.addEventListener("keydown",this.keyDownEvent);}},{key:"windowKeyDown",value:function windowKeyDown(e,t){var n,s;!e.isConnected&&this.keyDownEvent?window.removeEventListener("keydown",this.keyDownEvent):this._isOpen&&(t.key===_e.ESCAPE?(this.close(),(n=this.extensionCloseCallback)==null||n.call(this)):t.key===_e.ENTER&&(this.close(),(s=this.extensionCloseCallback)==null||s.call(this)));}}],[{key:"createContainer",value:function createContainer(e,t){var n=A();return n[m].add("modal"),n.appendChild(e),t&&delete t.backgroundColor,Object.assign(n[v],t),n;}},{key:"createModalContent",value:function createModalContent(e,t){var _n$m;var n=A();return(_n$m=n[m]).add.apply(_n$m,_toConsumableArray(e)),t&&(n[v].backgroundColor=t),A().appendChild(n),n;}},{key:"createButtonPanel",value:function createButtonPanel(e){var t=A();return t[m].add("modal-button-panel"),e&&(t[v].backgroundColor=e),t;}},{key:"createDarkBackgroundPanel",value:function createDarkBackgroundPanel(){var e=A();return e.id="modal-background-panel",e;}},{key:"createTextButton",value:function createTextButton(e){var t=A();return t[m].add("modal-button"),t.textContent=e,t;}},{key:"createSVGButton",value:function createSVGButton(e){var t=A();t[m].add("modal-button","modal-svg-button");var n=kt.createSVGElement(e);return n[m].add("modal-svg-button-icon"),t.appendChild(n),t;}},{key:"createTextModalFunc",value:function createTextModalFunc(e,t,n){var s;if(_typeof(t)=="object"&&(s=t[b])!=null&&s.infoModal){var r=new at(e,["modal-content"],t[b].infoModal.containerStyle);return r.addCloseButton("OK",!1,n),r.openTextModal.bind(r,t.infoModalTextMarkUp||"");}}}]);}();at.MODAL_CLOSE_TIMEOUT_MS=190;var tn=at;var ui=/*#__PURE__*/function(_gn5){// prettier-ignore
257
+ function ui(e,t,n,s,r,o){var _this114;_classCallCheck(this,ui);var p,u,g,y,_,S,M,K,ie,re;var a=le.processPosition((p=n==null?void 0:n.button)==null?void 0:p.position),c=((y=(g=(u=n==null?void 0:n.button)==null?void 0:u[R])==null?void 0:g[h])==null?void 0:y.content)||o,l=ut.tryCreateConfig("Upload File",(_=n==null?void 0:n.button)==null?void 0:_.tooltip);_this114=_callSuper(this,ui,[ui.createButtonElement(),r,a,l,n.button,c]);var d=_this114.createInnerElementsForStates(s,_this114.customStyles);_this114._inputElement=ui.createInputElement((S=n==null?void 0:n[b])==null?void 0:S.acceptedFormats),_this114.addClickEvent(e,n),_this114.changeElementsByState(d[R]),_this114.reapplyStateStyle(R),_this114._fileAttachmentsType=t,_this114._openModalOnce=((K=(M=n[b])==null?void 0:M.infoModal)==null?void 0:K.openModalOnce)===!1||(re=(ie=n[b])==null?void 0:ie.infoModal)==null?void 0:re.openModalOnce;return _this114;}_inherits(ui,_gn5);return _createClass(ui,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e,t){return _defineProperty({},R,this.createInnerElements(e,R,t));}},{key:"triggerImportPrompt",value:function triggerImportPrompt(e){e.onchange=this["import"].bind(this,e),e[J]();}},{key:"import",value:function _import(e){Os.addFilesToType(Array.from(e[b]||[]),[this._fileAttachmentsType]),e.value="";}},{key:"addClickEvent",value:function addClickEvent(e,t){var n=this.triggerImportPrompt.bind(this,this._inputElement),s=tn.createTextModalFunc(e,t,n);this.elementRef.onclick=this[J].bind(this,s);}},{key:"click",value:function click(e){e&&(this._openModalOnce===void 0||this._openModalOnce===!0)?(e(),this._openModalOnce===!0&&(this._openModalOnce=!1)):this.triggerImportPrompt(this._inputElement);}}],[{key:"createInputElement",value:function createInputElement(e){var t=A("input");return t[E]=se,t.accept=e||"",t.hidden=!0,t.multiple=!0,t;}},{key:"createButtonElement",value:function createButtonElement(){var e=A();return e[m].add("input-button"),e;}}]);}(gn);var Ct=/*#__PURE__*/function(){function Ct(){_classCallCheck(this,Ct);}return _createClass(Ct,null,[{key:"create",value:function create(e,t,n){var s=Ct.createElement(n);Ct.addEvents(s,e,t),e.appendChild(s);}},{key:"createElement",value:function createElement(e){var t=A();return t.id="drag-and-drop",_typeof(e)===U&&Object.assign(t[v],e),t;}},{key:"addEvents",value:function addEvents(e,t,n){t.ondragenter=function(s){s.preventDefault(),Ct.display(e);},e.ondragleave=function(s){s.preventDefault(),Ct.hide(e);},e.ondragover=function(s){s.preventDefault();},e.ondrop=function(s){s.preventDefault(),Ct.uploadFile(n,s),Ct.hide(e);};}},{key:"uploadFile",value:function uploadFile(e,t){var s;var n=(s=t.dataTransfer)==null?void 0:s[b];n&&e.addFilesToAnyType(Array.from(n));}},{key:"display",value:function display(e){e[v].display="block";}},{key:"hide",value:function hide(e){e[v].display="none";}},{key:"isEnabled",value:function isEnabled(e,t){return t!==void 0&&t===!1?!1:!!t||e.getNumberOfTypes()>0;}}]);}();var Wt=/*#__PURE__*/function(){function Wt(){_classCallCheck(this,Wt);}return _createClass(Wt,null,[{key:"validate",value:// prettier-ignore
262
258
  function validate(e,t,n,s,r,o,a){var c=n.isSubmitProgrammaticallyDisabled?!1:e(s,r,a);return c?t.changeToSubmitIcon():t.changeToDisabledIcon(),o==null||o.addInputText(s||""),c;}// prettier-ignore
263
- },{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee189(e,t,n,s,r,o){var a,c,l;return _regenerator().w(function(_context189){while(1)switch(_context189.n){case 0:a=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context189.n=1;return n.completePlaceholders();case 1:c=n.getAllFileData(),l=c==null?void 0:c.map(function(d){return d[se];});return _context189.a(2,Kt.validate(e,s,r,a,l,o));}},_callee189);}));function useValidationFunc(_x352,_x353,_x354,_x355,_x356,_x357){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
264
- },{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee190(e,t,n,s,r){var a,o;return _regenerator().w(function(_context190){while(1)switch(_context190.n){case 0:o=(a=t[b])==null?void 0:a.map(function(c){return c[se];});return _context190.a(2,Kt.validate(e,n,s,t[h],o,r,!0));}},_callee190);}));function useValidationFuncProgrammatic(_x358,_x359,_x360,_x361,_x362){return _useValidationFuncProgrammatic.apply(this,arguments);}return useValidationFuncProgrammatic;}()},{key:"validateWebsocket",value:function validateWebsocket(e,t){var n=e.websocket,s=e.connectSettings;return n&&s.url!==pt.URL&&!ke.canSendMessage(n)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
265
- },{key:"attach",value:function attach(e,t,n,s,r,o){var a=e.validateInput||de.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref261=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee191(c){var l;return _regenerator().w(function(_context191){while(1)switch(_context191.n){case 0:if(!(r.status.loadingActive||r.status.requestInProgress||!Kt.validateWebsocket(t,r))){_context191.n=1;break;}return _context191.a(2,!1);case 1:l=a||t.canSendMessage;return _context191.a(2,l?c?Kt.useValidationFuncProgrammatic(l,c,r,t,o):Kt.useValidationFunc(l,n,s,r,t,o):null);}},_callee191);}));return function(_x363){return _ref261.apply(this,arguments);};}();}}]);}();var ga=/*#__PURE__*/function(){function ga(){_classCallCheck(this,ga);}return _createClass(ga,null,[{key:"getFileName",value:function getFileName(e,t){var n=/* @__PURE__ */new Date(),s=String(n.getHours()).padStart(2,"0"),r=String(n.getMinutes()).padStart(2,"0"),o=String(n.getSeconds()).padStart(2,"0");return"".concat(e,"-").concat(s,"-").concat(r,"-").concat(o,".").concat(t);}}]);}();var Kh=/*#__PURE__*/function(_Ci2){function Kh(e,t){var _this115;_classCallCheck(this,Kh);var n,s;_this115=_callSuper(this,Kh,[t.button]),_this115._waitingForBrowserApproval=!1,_this115._audioType=e,_this115._extension=((n=t[b])==null?void 0:n.format)||"mp3",_this115._maxDurationSeconds=(s=t[b])==null?void 0:s.maxDurationSeconds,z.assignButtonEvents(_this115.elementRef,_this115.buttonClick.bind(_assertThisInitialized(_this115)));return _this115;}_inherits(Kh,_Ci2);return _createClass(Kh,[{key:"buttonClick",value:function buttonClick(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()));}},{key:"stop",value:function stop(){var _this116=this;return new Promise(function(e){var t,n;_this116.changeToDefault(),(t=_this116._mediaRecorder)==null||t.stop(),(n=_this116._mediaStream)==null||n.getTracks().forEach(function(s){return s.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this117=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this117.changeToActive(),_this117._mediaRecorder=new MediaRecorder(e),_this117._audioType.addPlaceholderAttachment(_this117.stop.bind(_this117),_this117._maxDurationSeconds),_this117._mediaStream=e,_this117._mediaRecorder.addEventListener("dataavailable",function(t){_this117.createFile(t);}),_this117._mediaRecorder[$t]();})["catch"](function(e){console[f](e),_this117.stop();})["finally"](function(){_this117._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this118=this;var t=new Blob([e.data],{type:"audio/".concat(this._extension)}),n=ga.getFileName(this._newFilePrefix||$,this._extension),s=new File([t],n,{type:t[E]}),r=new FileReader();r.readAsDataURL(s),r.onload=function(o){_this118._audioType.completePlaceholderAttachment(s,o.target.result);};}}]);}(Ci);var Wh="<?xml version=\"1.0\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n<svg xmlns=\"http://www.w3.org/2000/svg\" stroke=\"currentColor\" fill=\"none\" stroke-width=\"1\" viewBox=\"0 0 24 24\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <line x1=\"22\" y1=\"2\" x2=\"11\" y2=\"14\"></line>\n <polygon points=\"22 2 15 22 11 14 2 10 22 2\"></polygon>\n</svg>\n";var tn=/*#__PURE__*/function(){function tn(){_classCallCheck(this,tn);}return _createClass(tn,null,[{key:"resetSubmit",value:function resetSubmit(e,t){t?e.unsetCustomStateStyles([It,st]):e.unsetCustomStateStyles([Fi,It,st]),e.reapplyStateStyle(st);}},{key:"overwriteDefaultStyleWithSubmit",value:function overwriteDefaultStyleWithSubmit(e,t){if(!e.submit)return;var n=C(e[t]||{});Pe.overwritePropertyObjectFromAnother(n,e.submit,["container",w]),Pe.overwritePropertyObjectFromAnother(n,e.submit,[h,"styles",w]),Pe.overwritePropertyObjectFromAnother(n,e.submit,[G,"styles",w]),e[t]=n;}// prettier-ignore
266
- },{key:"setUpDisabledButton",value:function setUpDisabledButton(e){Pe.setPropertyValueIfDoesNotExist(e,[st,"container",w,"backgroundColor"],""),Pe.setPropertyValueIfDoesNotExist(e,[j,"container",w,"backgroundColor"],ba),Pe.setPropertyValueIfDoesNotExist(e.submit,[G,"styles",w,"filter"],""),Pe.setPropertyValueIfDoesNotExist(e[j],[G,"styles",w,"filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),Pe.setPropertyValueIfDoesNotExist(e[j],[h,"styles",w,"color"],"grey"),tn.overwriteDefaultStyleWithSubmit(e,j);}},{key:"process",value:function process(e){var t=C(e||{});return tn.overwriteDefaultStyleWithSubmit(t,It),tn.overwriteDefaultStyleWithSubmit(t,Fi),e!=null&&e.alwaysEnabled||tn.setUpDisabledButton(t),t;}}]);}();var gs=/*#__PURE__*/function(_mn6){// prettier-ignore
267
- function gs(e,t,n,s,r,o){var _this119;_classCallCheck(this,gs);var a=tn.process(e.submitButtonStyles),c=Wh,l=ut.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this119=_callSuper(this,gs,[gs.createButtonContainerElement(),c,a==null?void 0:a.position,l,a]),_this119._isSVGLoadingIconOverriden=!1,_this119.status={requestInProgress:!1,loadingActive:!1},_this119._messages=n,_this119._textInput=t,_this119._fileAttachments=r,_this119._innerElements=_this119.createInnerElementsForStates(),_this119._stopClicked={listener:function listener(){}},_this119._serviceIO=s,_this119._alwaysEnabled=!!(a!=null&&a.alwaysEnabled),e.disableSubmitButton=_this119.disableSubmitButton.bind(_assertThisInitialized(_this119),s),_this119.attemptOverwriteLoadingStyle(e),o.microphone&&_this119.setUpSpeechToText(o.microphone.button,e.speechToText),setTimeout(function(){var d;_this119._validationHandler=e._validationHandler,_this119.assignHandlers(_this119._validationHandler),(d=_this119._validationHandler)==null||d.call(_assertThisInitialized(_this119));});return _this119;}_inherits(gs,_mn6);return _createClass(gs,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(){var _this$createCustomEle=this.createCustomElements(),e=_this$createCustomEle.submit,t=_this$createCustomEle.loading,n=_this$createCustomEle.stop;return _defineProperty({submit:e,loading:t||[gs.createLoadingIconElement()],stop:n||[gs.createStopIconElement()]},j,this.createDisabledIconElement(e));}},{key:"createCustomElements",value:function createCustomElements(){var _this120=this;var e=Et.createCustomElements(st,this[G],this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(n){var s=n,r=Et.createCustomElements(s,_this120[G],_this120.customStyles);r&&(t[s]=r);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return Et.createCustomElements(j,this[G],this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
268
- },{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,n,s,r,o,a,c,l,d;if(!((n=(t=this.customStyles)==null?void 0:t.submit)!=null&&n[G]||(o=(r=(s=this.customStyles)==null?void 0:s.loading)==null?void 0:r[G])!=null&&o.content||(l=(c=(a=this.customStyles)==null?void 0:a.loading)==null?void 0:c[h])!=null&&l.content)&&(e.displayLoadingBubble===void 0||e.displayLoadingBubble===!0)){var p=A("style");p.textContent="\n .loading-button > * {\n filter: brightness(0) saturate(100%) invert(72%) sepia(0%) saturate(3044%) hue-rotate(322deg) brightness(100%)\n contrast(96%) !important;\n }",(d=e.shadowRoot)==null||d.appendChild(p),this._isSVGLoadingIconOverriden=!0;}}},{key:"assignHandlers",value:function assignHandlers(e){this._serviceIO.completionsHandlers={onFinish:this.resetSubmit.bind(this,e)},this._serviceIO.streamHandlers={onOpen:this.changeToStopIcon.bind(this),onClose:this.resetSubmit.bind(this,e),stopClicked:this._stopClicked};var t=this._serviceIO.stream;_typeof(t)=="object"&&typeof t.simulation=="number"&&(this._serviceIO.streamHandlers.simulationInterim=t.simulation);}},{key:"setUpSpeechToText",value:function setUpSpeechToText(e,t){this._microphoneButton=e,this._stopSTTAfterSubmit=_typeof(t)=="object"?t.stopAfterSubmit:!1;}},{key:"resetSubmit",value:function resetSubmit(e){this.status.requestInProgress=!1,this.status.loadingActive=!1,e();}},{key:"submitFromInput",value:function(){var _submitFromInput=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee192(){var _this121=this;var e,t;return _regenerator().w(function(_context192){while(1)switch(_context192.n){case 0:_context192.n=1;return this._fileAttachments.completePlaceholders();case 1:e=this._fileAttachments.getAllFileData();if(this._textInput.isTextInputEmpty())this.attemptSubmit(_defineProperty(_defineProperty({},h,""),b,e));else{t=this._textInput.inputElementRef.innerText.trim();this.attemptSubmit(_defineProperty(_defineProperty({},h,t),b,e));}($e.IS_SAFARI||$e.IS_MOBILE)&&setTimeout(function(){return cn.focusEndOfInput(_this121._textInput.inputElementRef);});case 2:return _context192.a(2);}},_callee192,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee193(e){var _this122=this;var t;return _regenerator().w(function(_context193){while(1)switch(_context193.n){case 0:typeof e=="string"&&(e=de.processSubmitUserMessage(e));t=_defineProperty({},h,e[h]);e[b]&&(t[b]=Array.from(e[b]).map(function(n){return _defineProperty({file:n},E,Tt.getTypeFromBlob(n));})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this122.attemptSubmit(t,!0);});case 1:return _context193.a(2);}},_callee193);}));function programmaticSubmit(_x364){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
269
- },{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee194(e){var _this123=this;var t,r,o,a,c,n,s,_args194=arguments,_t59,_t60,_t61;return _regenerator().w(function(_context194){while(1)switch(_context194.n){case 0:t=_args194.length>1&&_args194[1]!==undefined?_args194[1]:!1;_context194.n=1;return(r=this._validationHandler)==null?void 0:r.call(this,t?e:void 0);case 1:_t59=_context194.v;_t60=!1;if(!(_t59===_t60)){_context194.n=2;break;}return _context194.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();$e.IS_MOBILE&&setTimeout(function(){return _this123._textInput.inputElementRef.focus();});_t61=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t61){_context194.n=3;break;}_context194.n=3;return Zs.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context194.n=4;return this.addNewMessage(e);case 4:this._serviceIO.isWebModel()||this._messages.addLoadingMessage();n=(a=e[b])==null?void 0:a.map(function(l){return l[se];}),s=_defineProperty(_defineProperty({},h,e[h]===""?void 0:e[h]),b,n);_context194.n=5;return this._serviceIO.callAPI(s,this._messages);case 5:(c=this._fileAttachments)==null||c.hideFiles();case 6:return _context194.a(2);}},_callee194,this);}));function attemptSubmit(_x365){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee195(_ref264){var e,t,n,s,_t62;return _regenerator().w(function(_context195){while(1)switch(_context195.n){case 0:e=_ref264.text,t=_ref264.files,n=_ref264.custom;s=_defineProperty(_defineProperty({},x,F),"custom",n);e&&(s[h]=e);_t62=t;if(!_t62){_context195.n=2;break;}_context195.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:s[b]=_context195.v;case 2:this._serviceIO.sessionId&&(s._sessionId=this._serviceIO.sessionId);Object.keys(s).length>0&&this._messages.addNewMessage(s);case 3:return _context195.a(2);}},_callee195,this);}));function addNewMessage(_x366){return _addNewMessage.apply(this,arguments);}return addNewMessage;}()},{key:"stopStream",value:function stopStream(){var e,t,n;(t=(e=this._serviceIO.streamHandlers).onAbort)==null||t.call(e),(n=this._stopClicked)==null||n.listener(),this._validationHandler&&this.resetSubmit(this._validationHandler);}},{key:"changeToStopIcon",value:function changeToStopIcon(){this._serviceIO.websocket||(this.elementRef[m].remove(js,$n,jn),me.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle(Fi,[It,st]),z.assignButtonEvents(this.elementRef,this.stopStream.bind(this)),this.status.loadingActive=!1);}},{key:"changeToLoadingIcon",value:function changeToLoadingIcon(){this._serviceIO.websocket||(this._isSVGLoadingIconOverriden||this.changeElementsByState(this._innerElements.loading),this.elementRef[m].remove(jn,$n),me.removeAriaDisabled(this.elementRef),this.elementRef[m].add(js),me.addAriaBusy(this.elementRef),this.reapplyStateStyle(It,[st]),z.assignButtonEvents(this.elementRef,function(){}),this.status.requestInProgress=!0,this.status.loadingActive=!0);}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
270
- },{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this124=this;this.elementRef[m].contains(jn)||(this.elementRef[m].remove(js,$n),me.removeAriaAttributes(this.elementRef),this.elementRef[m].add(jn),this.changeElementsByState(this._innerElements.submit),tn.resetSubmit(this,this.status.loadingActive),z.assignButtonEvents(this.elementRef,function(){var e;_this124.submitFromInput(),(e=_this124._microphoneButton)!=null&&e.isActive&&Ms.toggleSpeechAfterSubmit(_this124._microphoneButton.elementRef,!!_this124._stopSTTAfterSubmit),setTimeout(function(){return cn.focusEndOfInput(_this124._textInput.inputElementRef);});}));}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
271
- },{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef[m].contains($n)||(this.elementRef[m].remove(js,jn),me.removeAriaBusy(this.elementRef),this.elementRef[m].add($n),me.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements[j]),this.reapplyStateStyle(j,[st]),z.assignButtonEvents(this.elementRef,function(){}));}},{key:"disableSubmitButton",value:function disableSubmitButton(e,t){var n;e.isSubmitProgrammaticallyDisabled=t!==!1,!(this.status.requestInProgress||this.status.loadingActive)&&(t===!1?(n=this._validationHandler)==null||n.call(this):this.changeToDisabledIcon(!0));}}],[{key:"createButtonContainerElement",value:function createButtonContainerElement(){var e=A();return e[m].add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=A();return e[m].add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=A();return e.id="stop-icon",e;}}]);}(mn);var Xh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M27.1 14.313V5.396L24.158 8.34c-2.33-2.325-5.033-3.503-8.11-3.503C9.902 4.837 4.901 9.847 4.899 16c.001 6.152 5.003 11.158 11.15 11.16 4.276 0 9.369-2.227 10.836-8.478l.028-.122h-3.23l-.022.068c-1.078 3.242-4.138 5.421-7.613 5.421a8 8 0 0 1-5.691-2.359A7.993 7.993 0 0 1 8 16.001c0-4.438 3.611-8.049 8.05-8.049 2.069 0 3.638.58 5.924 2.573l-3.792 3.789H27.1z\"/>\n</svg>\n",Zh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M0 16q0 3.264 1.28 6.208t3.392 5.12 5.12 3.424 6.208 1.248 6.208-1.248 5.12-3.424 3.392-5.12 1.28-6.208-1.28-6.208-3.392-5.12-5.088-3.392-6.24-1.28q-3.264 0-6.208 1.28t-5.12 3.392-3.392 5.12-1.28 6.208zM4 16q0-3.264 1.6-6.016t4.384-4.352 6.016-1.632 6.016 1.632 4.384 4.352 1.6 6.016-1.6 6.048-4.384 4.352-6.016 1.6-6.016-1.6-4.384-4.352-1.6-6.048z\"></path>\n</svg>\n",Yh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 1024 1024\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M195.2 195.2a64 64 0 0 1 90.496 0L512 421.504 738.304 195.2a64 64 0 0 1 90.496 90.496L602.496 512 828.8 738.304a64 64 0 0 1-90.496 90.496L512 602.496 285.696 828.8a64 64 0 0 1-90.496-90.496L421.504 512 195.2 285.696a64 64 0 0 1 0-90.496z\"/>\n</svg>",Jh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M4.89163 13.2687L9.16582 17.5427L18.7085 8\" stroke=\"#000000\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>";var Ir=/*#__PURE__*/function(_en){// prettier-ignore
272
- function Ir(e,t,n,s){var _this125;_classCallCheck(this,Ir);_this125=_callSuper(this,Ir,[e,["modal-content","modal-camera-content"],n]),_this125._stopped=!1,_this125._format="image/png",_this125._canvas=A("canvas"),_this125._canvas[m].add("camera-modal-canvas");var _this125$addButtonsAn=_this125.addButtonsAndTheirEvents(t),r=_this125$addButtonsAn.captureButton,o=_this125$addButtonsAn.submitButton;_this125._captureButton=r,_this125._submitButton=o,_this125._captureIcon=_this125._captureButton.children[0],_this125._refreshIcon=kt.createSVGElement(Xh),_this125._refreshIcon[m].add("modal-svg-button-icon","modal-svg-refresh-icon"),(s==null?void 0:s.format)==="jpeg"&&(_this125._format="image/jpeg"),s!=null&&s.dimensions&&(_this125._dimensions=s.dimensions),_this125._contentRef.appendChild(_this125._canvas),_this125.extensionCloseCallback=_this125.stop;return _this125;}_inherits(Ir,_en);return _createClass(Ir,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=en.createSVGButton(Zh);t[m].add("modal-svg-camera-button"),t.children[0][m].add("modal-svg-camera-icon");var n=this.addCloseButton(Yh,!0);n[m].add("modal-svg-close-button"),n.children[0][m].add("modal-svg-close-icon");var s=en.createSVGButton(Jh);return s[m].add("modal-svg-submit-button"),this.addButtons(t,s),this.addButtonEvents(t,n,s,e),{captureButton:t,submitButton:s};}// prettier-ignore
273
- },{key:"addButtonEvents",value:function addButtonEvents(e,t,n,s){var _this126=this;z.assignButtonEvents(e,this.capture.bind(this)),z.assignButtonEvents(t,this.stop.bind(this)),z.assignButtonEvents(n,function(){var r=_this126.getFile();r&&Ns.addFilesToType([r],[s]),_this126.stop(),_this126.close();});}},{key:"stop",value:function stop(){var _this127=this;this._mediaStream&&this._mediaStream.getTracks().forEach(function(e){return e.stop();}),this._stopped=!0,setTimeout(function(){_this127._captureButton.replaceChildren(_this127._captureIcon),_this127._captureButton[m].replace("modal-svg-refresh-button","modal-svg-camera-button");var e=_this127._canvas.getContext("2d");e==null||e.clearRect(0,0,_this127._canvas.width,_this127._canvas.height);},en.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this128=this;this._dataURL=void 0,this._submitButton[m].add("modal-svg-submit-".concat(j)),this._stopped=!1,navigator.mediaDevices.getUserMedia({video:this._dimensions||!0}).then(function(e){if(_this128._mediaStream=e,!_this128.isOpen())return _this128.stop();var t=A("video");t.srcObject=e,t.play(),requestAnimationFrame(_this128.updateCanvas.bind(_this128,t,_this128._canvas));})["catch"](function(e){console[f](e),_this128.stop(),_this128.close();});}},{key:"capture",value:function capture(){this._dataURL?(this._captureButton.replaceChildren(this._captureIcon),this._captureButton[m].replace("modal-svg-refresh-button","modal-svg-camera-button"),this._submitButton[m].add("modal-svg-submit-".concat(j)),this._dataURL=void 0):(this._captureButton.replaceChildren(this._refreshIcon),this._captureButton[m].replace("modal-svg-camera-button","modal-svg-refresh-button"),this._submitButton[m].remove("modal-svg-submit-".concat(j)),this._dataURL=this._canvas.toDataURL());}},{key:"getFile",value:function getFile(){if(this._dataURL){var e=atob(this._dataURL.split(",")[1]),t=new Array(e.length);for(var a=0;a<e.length;a++)t[a]=e.charCodeAt(a);var _n18=new Uint8Array(t),s=new Blob([_n18],{type:this._format}),r=this._format==="image/jpeg"?"jpeg":"png",o=ga.getFileName(this._newFilePrefix||"photo",r);return new File([s],o,{type:s[E]});}}},{key:"updateCanvas",value:function updateCanvas(e,t){if(!this._stopped){if(!this._dataURL){t.width=e.videoWidth,t.height=e.videoHeight;var _n19=t.getContext("2d");_n19==null||_n19.drawImage(e,0,0,t.width,t.height);}requestAnimationFrame(this.updateCanvas.bind(this,e,t));}}},{key:"openCameraModal",value:function openCameraModal(e){this.displayModalElements(),e[$t]();}// prettier-ignore
274
- }],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,n,s){var r=new Ir(e,t,n,s);return r.openCameraModal.bind(r,r);}}]);}(en);var Qh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M29 7h-4.599l-2.401-4h-12l-2.4 4h-4.6c-1 0-3 1-3 2.969v16.031c0 1.657 1.5 3 2.792 3h26.271c1.313 0 2.938-1.406 2.938-2.968v-16.032c0-1-1-3-3-3zM30 26.032c0 0.395-0.639 0.947-0.937 0.969h-26.265c-0.232-0.019-0.797-0.47-0.797-1v-16.031c0-0.634 0.851-0.953 1-0.969h5.732l2.4-4h9.802l1.785 3.030 0.55 0.97h5.731c0.705 0 0.99 0.921 1 1v16.032zM16 10c-3.866 0-7 3.134-7 7s3.134 7 7 7 7-3.134 7-7-3.134-7-7-7zM16 22c-2.757 0-5-2.243-5-5s2.243-5 5-5 5 2.243 5 5-2.243 5-5 5z\"></path>\n</svg>";var Mr=/*#__PURE__*/function(_mn7){function Mr(e,t,n){var _this129;_classCallCheck(this,Mr);var l,d,p,u,g,y;var s=de.processPosition((l=n==null?void 0:n.button)==null?void 0:l.position),r=((u=(p=(d=n==null?void 0:n.button)==null?void 0:d[R])==null?void 0:p[h])==null?void 0:u.content)||"Photo",o=ut.tryCreateConfig("Camera",(g=n==null?void 0:n.button)==null?void 0:g.tooltip),a=((y=n==null?void 0:n.button)==null?void 0:y[R])||{};_this129=_callSuper(this,Mr,[Mr.createButtonElement(),Qh,s,o,a,r]);var c=_this129.createInnerElementsForStates(_this129.customStyles);n&&_this129.addClickEvent(e,t,n.modalContainerStyle,n[b]),_this129.changeElementsByState(c[R]),_this129.reapplyStateStyle(R);return _this129;}_inherits(Mr,_mn7);return _createClass(Mr,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty({},R,this.createInnerElements("camera-icon",R,e));}},{key:"addClickEvent",value:// prettier-ignore
275
- function addClickEvent(e,t,n,s){var r=Ir.createCameraModalFunc(e,t,n,s);z.assignButtonEvents(this.elementRef,r);}}],[{key:"createButtonElement",value:function createButtonElement(){var e=A();return e[m].add("input-button"),e;}}]);}(mn);var En=/*#__PURE__*/function(){function En(e,t,n,s){_classCallCheck(this,En);this.elementRef=En.createPanelElement(e.inputAreaStyle);var r={},o=this.createFileUploadComponents(e,n,s,r),a=new Xs(e,n,o,t.browserStorage);e.speechToText&&!r.microphone&&(r.microphone={button:new Ms(e,a,t.addNewErrorMessage.bind(t))});var c=new gs(e,a,t,n,o,r);a.submit=c.submitFromInput.bind(c),Kt.attach(e,n,a,o,c,t.browserStorage),e.submitUserMessage=c.programmaticSubmit.bind(c),r.submit={button:c},e.customButtons&&sn.add(e,r),En.addElements(this.elementRef,a,r,s,o,e.dropupStyles),En.assignOnInput(e,n,o,a);}return _createClass(En,[{key:"createFileUploadComponents",value:// prettier-ignore
276
- function createFileUploadComponents(e,t,n,s){var o,a,c,l;var r=new Ns(this.elementRef,e.attachmentContainerStyle,t.demo);if(En.createUploadButtons(e,t,t.fileTypes||{},r,n,s),(o=t[Fe])!=null&&o[b]){var d=((a=s[ee])==null?void 0:a.fileType)||r.addType(e,t,t[Fe][b],ee);s[Fe]={button:new Mr(n,d,t[Fe])};}if((c=t.recordAudio)!=null&&c[b]){var _d3=((l=s[$])==null?void 0:l.fileType)||r.addType(e,t,t.recordAudio[b],$);s.microphone={button:new Kh(_d3,t.recordAudio)};}return Ct.isEnabled(r,e.dragAndDrop)&&Ct.create(n,r,e.dragAndDrop),r;}// prettier-ignore
277
- }],[{key:"createPanelElement",value:function createPanelElement(e){var t=A();return t.id="input",Object.assign(t[v],e),t;}},{key:"createUploadButtons",value:function createUploadButtons(e,t,n,s,r,o){Object.keys(n).forEach(function(a){var c=a,l=n[c];if(l[b]){var d=s.addType(e,t,l[b],c),_Th$c=Th[c],p=_Th$c.id,u=_Th$c.svgString,g=_Th$c.dropupText,y=new fi(r,d,l,p,u,g);o[c]={button:y,fileType:d};}});}// prettier-ignore
278
- },{key:"addElements",value:function addElements(e,t,n,s,r,o){z.addElements(e,t.elementRef);var a=Ln.create(),c=Ne.addButtons(a,n,s,o);ms.set(t.inputElementRef,a,r.elementRef,c),Ln.add(e,a);}},{key:"assignOnInput",value:function assignOnInput(e,t,n,s){t.onInput=function(r){setTimeout(function(){var o=n.getAllFileData(),a=s.inputElementRef.innerText.trim(),c=_defineProperty({},h,a);o&&(c[b]=o.map(function(l){return l[se];})),dn.onInput(e,c,r);});};}}]);}();var kr=/*#__PURE__*/function(){function kr(){_classCallCheck(this,kr);}return _createClass(kr,null,[{key:"createElements",value:function createElements(e,t,n){var s=A();s.id="chat-view";var r=!e.focusMode&&e.upwardsMode;s.classList.add(r?yh:bh);var o=new tt(e,t,n);t.websocket&&ke.createConnection(t,o);var a=new En(e,o,t,s),c=r?o.elementRef.parentElement:o.elementRef;return z.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=kr.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var eu="#validate-property-key-view{height:100%;position:relative;display:flex;justify-content:center;align-items:center;padding:8px}#loading-validate-key-property{display:inline-block;width:50px;height:50px}#loading-validate-key-property:after{content:\" \";display:block;width:38px;height:38px;margin:1px;border-radius:50%;border:5px solid #5fb2ff;border-color:#5fb2ff transparent #5fb2ff transparent;animation:loading-spinner 1.4s linear infinite}#deep-chat-openai-realtime-container{height:100%;width:100%}#deep-chat-openai-realtime-avatar-container{height:60%;width:100%;display:flex;justify-content:center;align-items:center}#deep-chat-openai-realtime-avatar{border-radius:50%;height:110px;border:1px solid rgb(215,215,215);padding:8px;-webkit-user-select:none;user-select:none;margin-top:20px}#deep-chat-openai-realtime-buttons-container{height:40%;display:flex;position:relative}.deep-chat-openai-realtime-button-container{height:100%;width:50%;display:flex;justify-content:center;align-items:center}.deep-chat-openai-realtime-button{width:70px;height:70px;border-radius:50%;display:flex;justify-content:center;align-items:center;cursor:pointer}.deep-chat-openai-realtime-button-default{background-color:#e3e3e3}.deep-chat-openai-realtime-button-default:hover{background-color:#d4d4d4}.deep-chat-openai-realtime-button-default:active{background-color:#c5c5c5}.deep-chat-openai-realtime-button-loading{opacity:.7;pointer-events:none}.deep-chat-openai-realtime-microphone-active{background-color:#ffe7e7}.deep-chat-openai-realtime-microphone-active:hover{background-color:#ffdede}.deep-chat-openai-realtime-microphone-active:active{background-color:#ffd2d2}.deep-chat-openai-realtime-microphone>*{height:30px;width:30px}.deep-chat-openai-realtime-microphone-active>*{filter:brightness(0) saturate(100%) invert(35%) sepia(60%) saturate(1360%) hue-rotate(325deg) brightness(95%) contrast(92%)}.deep-chat-openai-realtime-toggle>*{height:32px;width:32px;padding-inline-start:3px;filter:brightness(0) saturate(100%) invert(22%) sepia(0%) saturate(4537%) hue-rotate(208deg) brightness(105%) contrast(91%)}.deep-chat-openai-realtime-button-unavailable{opacity:.45;pointer-events:none}#deep-chat-openai-realtime-error{color:red;position:absolute;top:calc(50% + 40px);inset-inline-start:50%;transform:translate(-50%,-50%);font-size:17px}#deep-chat-openai-realtime-loading{position:absolute;font-size:15px;top:50%;inset-inline-start:50%;transform:translate(-50%,-50%)}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;inset-block-start:44%;inset-inline-start:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-inline-end:2.7em;width:calc(100% - 80px)}#insert-key-input{padding:.3em 1.7em .3em .3em;border-width:1px;border-style:solid;border-radius:3px;width:100%;font-size:inherit}.insert-key-input-valid{border-color:gray}.insert-key-input-invalid{border-color:red}#visibility-icon-container{position:relative;float:inline-end;cursor:pointer;-webkit-user-select:none;user-select:none}.visibility-icon{filter:brightness(0) saturate(100%) invert(63%) sepia(1%) saturate(9%) hue-rotate(43deg) brightness(98%) contrast(92%);position:absolute;inset-inline-end:-1.7em;inset-block-start:-1.43em}#visible-icon{inset-block-start:-1.4em}.visibility-icon:hover{filter:unset}.visibility-icon>*{pointer-events:none}#start-button{border:1px solid grey;color:#454545;border-radius:4px;width:3em;display:flex;justify-content:center;align-items:center;cursor:pointer;padding:.28em .3em;-webkit-user-select:none;user-select:none;background-color:#fff}#start-button:hover{background-color:#f2f2f2}#start-button:active{background-color:#d2d2d2}#insert-key-help-text-container{width:100%;position:absolute;margin-top:32px;margin-bottom:20px}#insert-key-help-text-contents{width:100%;position:absolute}#insert-key-input-invalid-text{display:block;margin-top:1em;margin-bottom:.5em;color:red}.insert-key-input-help-text{display:block;margin-top:16px}#loading-key{display:inline-block;width:16px;height:16px}#loading-key:after{content:\" \";display:block;width:11px;height:11px;margin:1px;border-radius:50%;border:2px solid #0084ff;border-color:#0084ff transparent #0084ff transparent;animation:loading-spinner 1.2s linear infinite}#error-view{color:red;font-size:1.2em;line-height:1.3em;margin-top:-5px;text-align:center;height:100%;display:flex;justify-content:center;align-items:center;padding-inline:8px}@keyframes loading-spinner{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.intro-panel{position:absolute;display:flex;justify-content:center;right:0;bottom:0;left:0;margin:auto;height:fit-content;top:-2.5em}pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!\n Theme: a11y-dark\n Author: @ericwbailey\n Maintainer: @ericwbailey\n\n Based on the Tomorrow Night Eighties theme: https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css\n*/.hljs{background:#2b2b2b;color:#f8f8f2}.hljs-comment,.hljs-quote{color:#d4d0ab}.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#ffa07a}.hljs-built_in,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#f5ab35}.hljs-attribute{color:gold}.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#abe338}.hljs-section,.hljs-title{color:#00e0e0}.hljs-keyword,.hljs-selector-tag{color:#dcc6e0}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}@media screen and (-ms-high-contrast:active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}}#messages,.deep-chat-upwards-mode #messages>div{overflow:auto;overflow-anchor:none}.deep-chat-upwards-mode #messages{height:100%;display:flex;flex-direction:column;justify-content:flex-end}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-inline:auto;width:calc(97.5% - 24px);max-width:100%}.message-bubble{margin-top:10px;word-wrap:break-word;width:fit-content;max-width:60%;border-radius:10px;padding:.42em .55em;height:fit-content;line-height:1.26}.user-message-text{color:#fff;background-color:#0084ff;margin-inline-end:0px;margin-inline-start:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-inline-start:0px;margin-inline-end:auto}.deep-chat-last-group-messages-active{height:100%}#scroll-button{position:absolute;top:75%;left:50%;right:50%;transform:translate(-50%,-50%);transition:opacity .1s ease;display:flex;opacity:0;padding:8px;background-color:#fff;border:.5px solid #000000;justify-content:center;align-items:center;white-space:nowrap;cursor:pointer}#scroll-button:hover{background-color:#fafafa}.loading-history-message-full-view{position:absolute;height:70%;width:100%;display:flex;align-items:center}.deep-chat-upwards-mode #messages .loading-history-message-full-view{height:100%}.loading-history-message-small{height:20px;margin-bottom:30px}.loading-history-message-small>div>div{scale:.6}.loading-history-message{margin-top:0;width:100%;max-width:100%;display:flex;justify-content:center;background-color:unset}.loading-history{width:70px}.loading-history div{position:absolute;width:var(--loading-history-width);height:var(--loading-history-height);margin:var(--loading-history-margin);border:var(--loading-history-border);border-radius:50%;animation:loading-spinner 1.2s cubic-bezier(.5,0,.5,1) infinite;border-color:var(--loading-history-color) transparent transparent transparent}.loading-history div:nth-child(1){animation-delay:-.45s}.loading-history div:nth-child(2){animation-delay:-.3s}.loading-history div:nth-child(3){animation-delay:-.15s}.html-message{max-width:unset}.error-message-text{margin-inline:auto;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%;margin-top:14px;margin-bottom:10px}.deep-chat-loading-message-dots-container{width:1em;padding-top:.6em;padding-bottom:.6em;padding-inline-start:1.3em;padding-inline-end:.75em}.loading-message-dots{position:relative;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite linear alternate;animation-delay:.5s}.loading-message-dots:before,.loading-message-dots:after{content:\"\";display:inline-block;position:absolute;top:0}.loading-message-dots:before{inset-inline-start:-.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:0s}.loading-message-dots:after{inset-inline-start:.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:1s}@keyframes loading-message-dots{0%{background-color:var(--loading-message-color)}50%,to{background-color:var(--loading-message-color-fade)}}.message-bubble>p:first-child,.message-bubble>.partial-render-message>p:first-child,.html-wrapper>p:first-child{margin-top:0}.message-bubble>p:last-child,.message-bubble>.partial-render-message:last-child>p,.html-wrapper>p:last-child{margin-bottom:0}pre{overflow:auto;display:block;word-break:break-all;word-wrap:break-word;border-radius:7px;background:#2b2b2b;color:#f8f8f2;margin-top:.8em;margin-bottom:.8em;padding:.6em;font-size:.9em;line-height:1.5em}.image-message{padding:0;display:flex;background-color:#ddd}.image-message>*,.image-message>*>*{width:100%;border-radius:8px;display:flex}.audio-message{width:60%;max-width:300px;height:2.2em;max-height:54px;padding:0;background-color:unset}.audio-player{width:100%;height:100%}.audio-player-safari{height:fit-content;width:40px}.audio-player-safari-start{float:inline-start}.audio-player-safari-end{float:inline-end}.any-file-message{padding:1px}.any-file-message-contents{display:flex}.any-file-message-icon-container{width:1.3em;min-width:1.3em;position:relative;border-radius:4px;margin-inline-start:6px;margin-inline-end:2px}.any-file-message-icon{background-color:#fff;border-radius:4px;position:absolute;width:1em;height:1.25em;padding:1px;margin-top:auto;margin-bottom:auto;top:0;bottom:0}.any-file-message-text{padding-top:5px;overflow-wrap:anywhere;padding-bottom:5px;padding-inline-end:7px}.message-bubble>a{color:inherit}.start-item-position{margin-inline-end:10px}.end-item-position{margin-inline-start:10px}.role-hidden{display:none}.avatar{padding-top:5px;width:1.5em;height:1.5em;border-radius:1px}.avatar-container{margin-top:9px}.name{margin-top:16px;font-size:15px}#drag-and-drop{position:absolute;display:none;z-index:10;height:calc(100% - 10px);width:calc(100% - 10px);background-color:#70c6ff4d;border:5px dashed #6dafff}#file-attachment-container{position:absolute;height:3.6em;width:calc(80% - 4px);top:-2.5em;border-radius:5px;overflow:auto;text-align:start;background-color:#d7d7d73b;padding-inline-start:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-inline-end:.6em;margin-bottom:.44em;margin-top:4px;position:relative;background-color:#fff;border-radius:5px}.image-attachment{width:100%;height:100%;object-fit:cover;border-radius:5px}.border-bound-attachment{width:calc(100% - 2px);height:calc(100% - 2px);border:1px solid #c3c3c3;border-radius:5px;overflow:hidden}.border-bound-attachment-safari{width:calc(100% - 1px);height:calc(100% - 1px)}.audio-attachment-icon-container{cursor:pointer}.audio-attachment-icon-container:hover{background-color:#f8f8f8}.attachment-icon{inset-inline:0;bottom:0;top:2px;margin:auto;position:absolute;width:25px;-webkit-user-select:none;user-select:none}.not-removable-attachment-icon{top:0;right:0;bottom:0;left:0}.play-icon{filter:brightness(0) saturate(100%) invert(17%) sepia(0%) saturate(1392%) hue-rotate(67deg) brightness(98%) contrast(97%)}.stop-icon{filter:brightness(0) saturate(100%) invert(29%) sepia(90%) saturate(1228%) hue-rotate(198deg) brightness(93%) contrast(98%)}.audio-placeholder-text-3-digits{padding-inline-start:.26rem}.audio-placeholder-text-4-digits{padding-inline-start:.1rem}.any-file-attachment{padding:2px 0}.file-attachment-text-container{position:absolute;width:inherit;display:flex;align-items:center;height:100%;top:-1px}.audio-placeholder-text-3-digits-container{padding-top:1px;cursor:default}.any-file-attachment-text{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;padding-inline-start:.13em;margin-inline:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;inset-inline-end:-5px;position:absolute;display:flex;justify-content:center;cursor:pointer;-webkit-user-select:none;user-select:none}.remove-file-attachment-button:hover{background-color:#e4e4e4}.remove-file-attachment-button:active{background-color:#d7d7d7}.x-icon{color:#4e4e4e;top:-.075em;position:relative;font-size:1.05em}.modal{display:none;flex-direction:column;align-items:center;justify-content:center;position:absolute;width:80%;max-width:420px;max-height:80%;margin:auto;top:0;right:0;bottom:0;left:0;z-index:3}.modal-content{border-top:1px solid rgb(217,217,217);border-inline:1px solid rgb(217,217,217);border-start-start-radius:inherit;border-start-end-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-inline:1em}.modal-content>ul{margin-inline-end:1em}.modal-button-panel{height:3.3em;border:1px solid;border-color:rgb(223,223,223) rgb(217,217,217) rgb(217,217,217);border-end-start-radius:inherit;border-end-end-radius:inherit;background-color:#fff;text-align:center;justify-content:center;display:flex;width:100%}.modal-button{min-width:2.5em;text-align:center;color:#fff;border-radius:5px;padding:.4em .4em .3em;height:1.25em;background-color:#3279b2;inset-block:0;margin-top:auto;margin-bottom:auto;cursor:pointer;-webkit-user-select:none;user-select:none;margin-inline:.31em}.modal-button:hover{background-color:#276da7}.modal-button:active{background-color:#1b5687}.modal-svg-button{padding:0 0 2px;width:2em;height:1.8em}.modal-svg-button-icon{width:100%;height:100%;filter:brightness(0) saturate(100%) invert(100%) sepia(15%) saturate(4%) hue-rotate(346deg) brightness(101%) contrast(102%)}#modal-background-panel{position:absolute;width:100%;height:100%;background-color:#00000042;z-index:2;display:none}.show-modal-background{animation:fadeInBackground .3s ease-in-out}@keyframes fadeInBackground{0%{opacity:0}to{opacity:1}}.show-modal{animation:fadeInModal .3s ease-in-out}@keyframes fadeInModal{0%{opacity:0;scale:.95}to{opacity:1;scale:1}}.hide-modal-background{animation:fadeOutBackground .2s ease-in-out}@keyframes fadeOutBackground{0%{opacity:1}to{opacity:0}}.hide-modal{animation:fadeOutModal .2s ease-in-out}@keyframes fadeOutModal{0%{opacity:1;scale:1}to{opacity:0;scale:.95}}.modal-camera-content{overflow:hidden;text-align:center;border:unset;height:100%;background-color:#2a2a2a;display:flex;justify-content:center}.camera-modal-canvas{max-width:100%;max-height:100%;margin-top:auto;margin-bottom:auto}.modal-svg-submit-button{background-color:green}.modal-svg-submit-button:hover{background-color:#007500}.modal-svg-submit-button:active{background-color:#006500}.modal-svg-submit-disabled{pointer-events:none;background-color:#747474}.modal-svg-close-button{height:1.56em;padding-top:.37em;padding-bottom:0;background-color:#c13e3e}.modal-svg-close-button:hover{background-color:#b43434}.modal-svg-close-button:active{background-color:#972929}.modal-svg-close-icon{width:80%;height:80%}.modal-svg-camera-button{height:1.6em;padding-top:.38em;padding-bottom:0}.modal-svg-camera-icon{height:76%}.modal-svg-refresh-icon{height:105%}.modal-svg-refresh-button{height:1.66em;padding-top:.11em;padding-bottom:.21em}.input-button-container{position:relative;z-index:1}.inside-end{position:absolute;inset-inline-end:calc(10% + .35em);inset-block-end:.85em}.inside-start{position:absolute;inset-inline-start:calc(10% + .35em);inset-block-end:.85em}.outside-start{position:absolute;inset-inline-end:calc(11px - .55em);inset-block-end:.88em}.outside-end{position:absolute;inset-inline-start:calc(11px - .55em);inset-block-end:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;inset-inline-start:.11em;inset-block-end:.08em;filter:brightness(0) saturate(100%) invert(43%) sepia(0%) saturate(740%) hue-rotate(77deg) brightness(99%) contrast(92%)}#upload-gifs-icon{position:absolute;pointer-events:none;width:1.5em;height:1.48em;inset-inline-start:.07em;inset-block-end:.08em;filter:brightness(0) saturate(100%) invert(49%) sepia(0%) saturate(2586%) hue-rotate(12deg) brightness(93%) contrast(90%)}#upload-audio-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.17em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%);transform:scaleX(.95)}#camera-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.23em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(52%) sepia(0%) saturate(161%) hue-rotate(164deg) brightness(91%) contrast(92%);transform:scaleX(.95)}#upload-mixed-files-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.25em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(53%) sepia(0%) saturate(36%) hue-rotate(74deg) brightness(98%) contrast(93%);transform:scaleX(.95)}#interim-text{color:gray}#microphone-button{padding-top:.5px}.outer-button-container>#microphone-button{padding-bottom:1px}#microphone-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.25em;inset-block-end:.25em}.default-microphone-icon{filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%)}.active-microphone-icon{filter:brightness(0) saturate(100%) invert(10%) sepia(97%) saturate(7495%) hue-rotate(0deg) brightness(101%) contrast(107%);border-radius:10px}.command-microphone-icon{filter:brightness(0) saturate(100%) invert(42%) sepia(96%) saturate(1067%) hue-rotate(77deg) brightness(99%) contrast(102%)}.unsupported-microphone{display:none}#submit-icon{height:100%;filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%);width:1.21em}#stop-icon{background-color:#acacac;position:absolute;width:.95em;height:.95em;inset-inline-start:.35em;inset-block-end:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-inline:.3em}.loading-submit-button{position:relative;inset-inline-start:calc(-9990px + .275em);width:.22em;height:.22em;border-radius:5px;background-color:#848484;color:#848484;box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484;animation:loading-submit-button 1.5s infinite linear;inset-block-end:-.75em}@keyframes loading-submit-button{0%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}16.667%{box-shadow:9990px -6px #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}33.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}50%{box-shadow:9990px 0 #848484,calc(9990px + .44em) -6px 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}66.667%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}83.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) -6px 0 0 #848484}to{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}}.tooltip{position:absolute;visibility:hidden;z-index:1;pointer-events:none;padding:5px;padding-inline:7px;background-color:#333;border-radius:5px;width:max-content}.tooltip-text{color:#fff;font-size:13px}.input-button{border-radius:4px;cursor:pointer;margin-bottom:.2em;-webkit-user-select:none;user-select:none}.input-button-svg{width:1.65em;height:1.65em}.input-button-svg-text{padding:1px;height:1.65em;display:flex}.input-button-svg-text>svg{padding:.22rem}.input-button-svg-text>div{margin-inline-start:2px}.input-button:hover,.input-button:focus-visible{background-color:#9c9c9c2e}.input-button:active{background-color:#9c9c9c5e}.input-button:active:not(:hover){background-color:transparent}.loading-button{cursor:auto}.loading-button:hover{background-color:unset}.text-button{filter:unset!important;display:flex;justify-content:center;align-items:center;margin-inline:4px;height:1.6em;width:max-content}#custom-icon{height:100%;width:1.2em}.custom-button-container-default{color:#505050}.custom-button-container-default>.dropup-menu-item-icon{color:unset}.custom-button-container-default>svg{filter:brightness(0) saturate(100%) invert(39%) sepia(1%) saturate(0%) hue-rotate(83deg) brightness(93%) contrast(90%)}.custom-button-container-default>.dropup-menu-item-icon>svg{position:absolute;inset-inline-start:.2em}.custom-button-container-active{background-color:#edf7ff;color:#0285ff}.custom-button-container-active:hover,.custom-button-container-active:focus-visible{background-color:#def0ff}.custom-button-container-active:active{background-color:#d2eaff}.custom-button-container-active>svg{filter:brightness(0) saturate(100%) invert(32%) sepia(34%) saturate(4196%) hue-rotate(196deg) brightness(107%) contrast(104%)}.custom-button-container-disabled{color:#aeaeae;cursor:auto}.custom-button-container-disabled>div{pointer-events:none}.custom-button-container-disabled:hover,.custom-button-container-disabled:focus-visible{background-color:transparent}.custom-button-container-disabled:active{background-color:transparent}.custom-button-container-disabled>svg{filter:brightness(0) saturate(100%) invert(67%) sepia(0%) saturate(818%) hue-rotate(28deg) brightness(102%) contrast(100%)}#text-input-container{background-color:#fff;width:80%;display:flex;border:1px solid #0000001a;border-radius:5px;margin-top:.8em;margin-bottom:.8em;box-shadow:#959da533 0 1px 12px;overflow-y:auto;max-height:200px;position:relative}.text-input-container-start-adjustment{margin-inline-start:1.5em}.text-input-container-end-adjustment{margin-inline-end:1.5em}.text-input-container-start-small-adjustment{margin-inline-start:1.1em}.text-input-container-start-small-adjustment>.outside-start{inset-inline-end:calc(14px - .55em)}.text-input-container-end-small-adjustment{margin-inline-end:1.1em}.text-input-container-end-small-adjustment>.outside-end{inset-inline-start:calc(14px - .55em)}#text-input{text-align:start;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-start-adjustment{padding-inline-start:2.2em}.text-input-inner-end-adjustment{padding-inline-end:2em}.text-input-disabled{pointer-events:none;-webkit-user-select:none;user-select:none}[contenteditable]:empty:before{content:attr(deep-chat-placeholder-text);pointer-events:none}[contenteditable][textcolor]:empty:before{color:gray}.outside-end>#dropup-menu,.inside-end>#dropup-menu{inset-inline-end:0px}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;inset-inline-start:.265em;bottom:.43em;filter:brightness(0) saturate(100%) invert(54%) sepia(0%) saturate(724%) hue-rotate(6deg) brightness(92%) contrast(90%)}.dropup-button>*{pointer-events:none}#dropup-menu{background-color:#fff;position:absolute;transform:translateY(-100%);border-radius:5px;z-index:1;top:-.49em;box-shadow:#0003 -1px 2px 10px,#0000001a 0 2px 4px;cursor:pointer;-webkit-user-select:none;user-select:none}.dropup-menu-item{height:1.4em;padding-inline-start:.35em;padding-inline-end:.84em;padding-top:.28em;padding-bottom:.28em;display:flex;position:relative}.dropup-menu-item:hover,.dropup-menu-item:focus-visible{background-color:#f3f3f3}.dropup-menu-item:active{background-color:#ebebeb}.dropup-menu-item:active:not(:hover){background-color:transparent}.dropup-menu-item:first-child{padding-top:.49em;border-start-start-radius:inherit;border-start-end-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-end-start-radius:inherit;border-end-end-radius:inherit}.dropup-menu-item-icon{width:1.39em;position:relative}.dropup-menu-item-icon>svg{bottom:0!important;top:0!important;margin-bottom:auto;margin-top:auto}#dropup-menu-item-icon-element-custom{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.28em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%)}.dropup-menu-item-text{margin-inline-start:.56em;margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-inline:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;grid-template-columns:100%}.deep-chat-downwards-mode{display:grid}.deep-chat-upwards-mode{display:flex;flex-direction:column}::-webkit-scrollbar{width:9px;height:9px}::-webkit-scrollbar-thumb{background-color:#d0d0d0;border-radius:5px}::-webkit-scrollbar-track{background-color:#f2f2f2}.deep-chat-web-model-button{margin-top:10px;margin-bottom:5px;margin-inline-start:1px}:host{all:initial;display:table-cell}#container{height:inherit;width:inherit;overflow:hidden}";var tu=Object.defineProperty,N=function N(i,e,t,n){for(var s=void 0,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=o(e,t,s)||s);return s&&tu(e,t,s),s;};var P=/*#__PURE__*/function(_zi){function P(){var _this130;_classCallCheck(this,P);var e;_this130=_callSuper(this,P),_this130.getMessages=function(){return[];},_this130.submitUserMessage=function(){return console.warn(Hr("submitUserMessage"));},_this130.addMessage=function(){return console.warn(Hr("addMessage"));},_this130.updateMessage=function(){},_this130.clearMessages=function(){},_this130.focusInput=function(){return cn.focusFromParentElement(_this130._elementRef);},_this130.refreshMessages=function(){},_this130.scrollToBottom=function(){},_this130.disableSubmitButton=function(){},_this130.setPlaceholderText=function(){},_this130._hasBeenRendered=!1,_this130._auxiliaryStyleApplied=!1,_this130._elementRef=A(),_this130._elementRef.id="container",_this130.attachShadow({mode:"open"}).appendChild(_this130._elementRef),(e=_this130.shadowRoot)==null||e.appendChild(ut.buildElement()),hs.apply(eu,_this130.shadowRoot),setTimeout(function(){_this130._hasBeenRendered||_this130.onRender();},20);return _this130;}_inherits(P,_zi);return _createClass(P,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
279
- },{key:"onRender",value:function onRender(){var _this$_childElement;Ws.attemptAppendStyleSheetToHead(this.style),de.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=gh.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(hs.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),hs.applyDefaultStyleToComponent(this.style,this.chatStyle),de.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?Vs.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof k)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],kr.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof k&&Oe.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||dn.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){Rs.chat=void 0;}}]);}(zi);N([O("object")],P.prototype,"connect");N([O("object")],P.prototype,"directConnection");N([O("object")],P.prototype,"webModel");N([O("object")],P.prototype,"requestBodyLimits");N([O("function")],P.prototype,"requestInterceptor");N([O("function")],P.prototype,"responseInterceptor");N([O("function")],P.prototype,"validateInput");N([O("function")],P.prototype,"loadHistory");N([O("object")],P.prototype,"chatStyle");N([O("object")],P.prototype,"attachmentContainerStyle");N([O("object")],P.prototype,"dropupStyles");N([O("object")],P.prototype,"inputAreaStyle");N([O("object")],P.prototype,"textInput");N([O("object")],P.prototype,"defaultInput");N([O("object")],P.prototype,"submitButtonStyles");N([O("object")],P.prototype,"customButtons");N([O("string")],P.prototype,"auxiliaryStyle");N([O("array")],P.prototype,"history");N([O("object")],P.prototype,"browserStorage");N([O("object")],P.prototype,"introMessage");N([O("object")],P.prototype,"avatars");N([O("object")],P.prototype,"names");N([O("object")],P.prototype,"displayLoadingBubble");N([O("object")],P.prototype,"errorMessages");N([O("object")],P.prototype,"messageStyles");N([O("object")],P.prototype,"textToSpeech");N([O("object")],P.prototype,"speechToText");N([O("object")],P.prototype,"images");N([O("object")],P.prototype,"gifs");N([O("object")],P.prototype,"camera");N([O("object")],P.prototype,"audio");N([O("object")],P.prototype,"microphone");N([O("object")],P.prototype,"mixedFiles");N([O("object")],P.prototype,"dragAndDrop");N([O("object")],P.prototype,"htmlWrappers");N([O("object")],P.prototype,"htmlClassUtilities");N([O("object")],P.prototype,"remarkable");N([O("object")],P.prototype,"focusMode");N([O("boolean")],P.prototype,"upwardsMode");N([O("object")],P.prototype,"scrollButton");N([O("object")],P.prototype,"hiddenMessages");N([O("number")],P.prototype,"maxVisibleMessages");N([O("function")],P.prototype,"onMessage");N([O("function")],P.prototype,"onClearMessages");N([O("function")],P.prototype,"onComponentRender");N([O("function")],P.prototype,"onInput");N([O("function")],P.prototype,"onError");N([O("object")],P.prototype,"demo");N([O("object")],P.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",P);export{P as DeepChat};
259
+ },{key:"useValidationFunc",value:function(){var _useValidationFunc=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee189(e,t,n,s,r,o){var a,c,l;return _regenerator().w(function(_context189){while(1)switch(_context189.n){case 0:a=t.isTextInputEmpty()?"":t.inputElementRef.textContent;_context189.n=1;return n.completePlaceholders();case 1:c=n.getAllFileData(),l=c==null?void 0:c.map(function(d){return d[se];});return _context189.a(2,Wt.validate(e,s,r,a,l,o));}},_callee189);}));function useValidationFunc(_x352,_x353,_x354,_x355,_x356,_x357){return _useValidationFunc.apply(this,arguments);}return useValidationFunc;}()// prettier-ignore
260
+ },{key:"useValidationFuncProgrammatic",value:function(){var _useValidationFuncProgrammatic=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee190(e,t,n,s,r){var a,o;return _regenerator().w(function(_context190){while(1)switch(_context190.n){case 0:o=(a=t[b])==null?void 0:a.map(function(c){return c[se];});return _context190.a(2,Wt.validate(e,n,s,t[h],o,r,!0));}},_callee190);}));function useValidationFuncProgrammatic(_x358,_x359,_x360,_x361,_x362){return _useValidationFuncProgrammatic.apply(this,arguments);}return useValidationFuncProgrammatic;}()},{key:"validateWebsocket",value:function validateWebsocket(e,t){var n=e.websocket,s=e.connectSettings;return n&&s.url!==pt.URL&&!ke.canSendMessage(n)?(t.changeToDisabledIcon(),!1):!0;}// prettier-ignore
261
+ },{key:"attach",value:function attach(e,t,n,s,r,o){var a=e.validateInput||le.processValidateInput(e);e._validationHandler=/*#__PURE__*/function(){var _ref265=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee191(c){var l;return _regenerator().w(function(_context191){while(1)switch(_context191.n){case 0:if(!(r.status.loadingActive||r.status.requestInProgress||!Wt.validateWebsocket(t,r))){_context191.n=1;break;}return _context191.a(2,!1);case 1:l=a||t.canSendMessage;return _context191.a(2,l?c?Wt.useValidationFuncProgrammatic(l,c,r,t,o):Wt.useValidationFunc(l,n,s,r,t,o):null);}},_callee191);}));return function(_x363){return _ref265.apply(this,arguments);};}();}}]);}();var ma=/*#__PURE__*/function(){function ma(){_classCallCheck(this,ma);}return _createClass(ma,null,[{key:"getFileName",value:function getFileName(e,t){var n=/* @__PURE__ */new Date(),s=String(n.getHours()).padStart(2,"0"),r=String(n.getMinutes()).padStart(2,"0"),o=String(n.getSeconds()).padStart(2,"0");return"".concat(e,"-").concat(s,"-").concat(r,"-").concat(o,".").concat(t);}}]);}();var Vh=/*#__PURE__*/function(_Ai2){function Vh(e,t){var _this115;_classCallCheck(this,Vh);var n,s;_this115=_callSuper(this,Vh,[t.button]),_this115._waitingForBrowserApproval=!1,_this115._audioType=e,_this115._extension=((n=t[b])==null?void 0:n.format)||"mp3",_this115._maxDurationSeconds=(s=t[b])==null?void 0:s.maxDurationSeconds,z.assignButtonEvents(_this115.elementRef,_this115.buttonClick.bind(_assertThisInitialized(_this115)));return _this115;}_inherits(Vh,_Ai2);return _createClass(Vh,[{key:"buttonClick",value:function buttonClick(){this._waitingForBrowserApproval||(this.isActive?this.stop():(this._waitingForBrowserApproval=!0,this.record()));}},{key:"stop",value:function stop(){var _this116=this;return new Promise(function(e){var t,n;_this116.changeToDefault(),(t=_this116._mediaRecorder)==null||t.stop(),(n=_this116._mediaStream)==null||n.getTracks().forEach(function(s){return s.stop();}),setTimeout(function(){e();},10);});}},{key:"record",value:function record(){var _this117=this;navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){_this117.changeToActive(),_this117._mediaRecorder=new MediaRecorder(e),_this117._audioType.addPlaceholderAttachment(_this117.stop.bind(_this117),_this117._maxDurationSeconds),_this117._mediaStream=e,_this117._mediaRecorder.addEventListener("dataavailable",function(t){_this117.createFile(t);}),_this117._mediaRecorder[qt]();})["catch"](function(e){console[f](e),_this117.stop();})["finally"](function(){_this117._waitingForBrowserApproval=!1;});}},{key:"createFile",value:function createFile(e){var _this118=this;var t=new Blob([e.data],{type:"audio/".concat(this._extension)}),n=ma.getFileName(this._newFilePrefix||$,this._extension),s=new File([t],n,{type:t[E]}),r=new FileReader();r.readAsDataURL(s),r.onload=function(o){_this118._audioType.completePlaceholderAttachment(s,o.target.result);};}}]);}(Ai);var Kh="<?xml version=\"1.0\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n<svg xmlns=\"http://www.w3.org/2000/svg\" stroke=\"currentColor\" fill=\"none\" stroke-width=\"1\" viewBox=\"0 0 24 24\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <line x1=\"22\" y1=\"2\" x2=\"11\" y2=\"14\"></line>\n <polygon points=\"22 2 15 22 11 14 2 10 22 2\"></polygon>\n</svg>\n";var nn=/*#__PURE__*/function(){function nn(){_classCallCheck(this,nn);}return _createClass(nn,null,[{key:"resetSubmit",value:function resetSubmit(e,t){t?e.unsetCustomStateStyles([It,st]):e.unsetCustomStateStyles([Bi,It,st]),e.reapplyStateStyle(st);}},{key:"overwriteDefaultStyleWithSubmit",value:function overwriteDefaultStyleWithSubmit(e,t){if(!e.submit)return;var n=C(e[t]||{});Pe.overwritePropertyObjectFromAnother(n,e.submit,["container",w]),Pe.overwritePropertyObjectFromAnother(n,e.submit,[h,"styles",w]),Pe.overwritePropertyObjectFromAnother(n,e.submit,[G,"styles",w]),e[t]=n;}// prettier-ignore
262
+ },{key:"setUpDisabledButton",value:function setUpDisabledButton(e){Pe.setPropertyValueIfDoesNotExist(e,[st,"container",w,"backgroundColor"],""),Pe.setPropertyValueIfDoesNotExist(e,[j,"container",w,"backgroundColor"],ga),Pe.setPropertyValueIfDoesNotExist(e.submit,[G,"styles",w,"filter"],""),Pe.setPropertyValueIfDoesNotExist(e[j],[G,"styles",w,"filter"],"brightness(0) saturate(100%) invert(70%) sepia(0%) saturate(5564%) hue-rotate(207deg) brightness(100%) contrast(97%)"),Pe.setPropertyValueIfDoesNotExist(e[j],[h,"styles",w,"color"],"grey"),nn.overwriteDefaultStyleWithSubmit(e,j);}},{key:"process",value:function process(e){var t=C(e||{});return nn.overwriteDefaultStyleWithSubmit(t,It),nn.overwriteDefaultStyleWithSubmit(t,Bi),e!=null&&e.alwaysEnabled||nn.setUpDisabledButton(t),t;}}]);}();var ms=/*#__PURE__*/function(_gn6){// prettier-ignore
263
+ function ms(e,t,n,s,r,o){var _this119;_classCallCheck(this,ms);var a=nn.process(e.submitButtonStyles),c=Kh,l=ut.tryCreateConfig("Submit",a==null?void 0:a.tooltip);_this119=_callSuper(this,ms,[ms.createButtonContainerElement(),c,a==null?void 0:a.position,l,a]),_this119._isSVGLoadingIconOverriden=!1,_this119.status={requestInProgress:!1,loadingActive:!1},_this119._messages=n,_this119._textInput=t,_this119._fileAttachments=r,_this119._innerElements=_this119.createInnerElementsForStates(),_this119._stopClicked={listener:function listener(){}},_this119._serviceIO=s,_this119._alwaysEnabled=!!(a!=null&&a.alwaysEnabled),e.disableSubmitButton=_this119.disableSubmitButton.bind(_assertThisInitialized(_this119),s),_this119.attemptOverwriteLoadingStyle(e),o.microphone&&_this119.setUpSpeechToText(o.microphone.button,e.speechToText),setTimeout(function(){var d;_this119._validationHandler=e._validationHandler,_this119.assignHandlers(_this119._validationHandler),(d=_this119._validationHandler)==null||d.call(_assertThisInitialized(_this119));});return _this119;}_inherits(ms,_gn6);return _createClass(ms,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(){var _this$createCustomEle=this.createCustomElements(),e=_this$createCustomEle.submit,t=_this$createCustomEle.loading,n=_this$createCustomEle.stop;return _defineProperty({submit:e,loading:t||[ms.createLoadingIconElement()],stop:n||[ms.createStopIconElement()]},j,this.createDisabledIconElement(e));}},{key:"createCustomElements",value:function createCustomElements(){var _this120=this;var e=Et.createCustomElements(st,this[G],this.customStyles),t={loading:void 0,stop:void 0};return Object.keys(t).forEach(function(n){var s=n,r=Et.createCustomElements(s,_this120[G],_this120.customStyles);r&&(t[s]=r);}),t.submit=e||this.buildDefaultIconElement("submit-icon"),t;}},{key:"createDisabledIconElement",value:function createDisabledIconElement(e){return Et.createCustomElements(j,this[G],this.customStyles)||[e[0].cloneNode(!0)];}// prettier-ignore
264
+ },{key:"attemptOverwriteLoadingStyle",value:function attemptOverwriteLoadingStyle(e){var t,n,s,r,o,a,c,l,d;if(!((n=(t=this.customStyles)==null?void 0:t.submit)!=null&&n[G]||(o=(r=(s=this.customStyles)==null?void 0:s.loading)==null?void 0:r[G])!=null&&o.content||(l=(c=(a=this.customStyles)==null?void 0:a.loading)==null?void 0:c[h])!=null&&l.content)&&(e.displayLoadingBubble===void 0||e.displayLoadingBubble===!0)){var p=A("style");p.textContent="\n .loading-button > * {\n filter: brightness(0) saturate(100%) invert(72%) sepia(0%) saturate(3044%) hue-rotate(322deg) brightness(100%)\n contrast(96%) !important;\n }",(d=e.shadowRoot)==null||d.appendChild(p),this._isSVGLoadingIconOverriden=!0;}}},{key:"assignHandlers",value:function assignHandlers(e){this._serviceIO.completionsHandlers={onFinish:this.resetSubmit.bind(this,e)},this._serviceIO.streamHandlers={onOpen:this.changeToStopIcon.bind(this),onClose:this.resetSubmit.bind(this,e),stopClicked:this._stopClicked};var t=this._serviceIO.stream;_typeof(t)=="object"&&typeof t.simulation=="number"&&(this._serviceIO.streamHandlers.simulationInterim=t.simulation);}},{key:"setUpSpeechToText",value:function setUpSpeechToText(e,t){this._microphoneButton=e,this._stopSTTAfterSubmit=_typeof(t)=="object"?t.stopAfterSubmit:!1;}},{key:"resetSubmit",value:function resetSubmit(e){this.status.requestInProgress=!1,this.status.loadingActive=!1,e();}},{key:"submitFromInput",value:function(){var _submitFromInput=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee192(){var _this121=this;var e,t;return _regenerator().w(function(_context192){while(1)switch(_context192.n){case 0:_context192.n=1;return this._fileAttachments.completePlaceholders();case 1:e=this._fileAttachments.getAllFileData();if(this._textInput.isTextInputEmpty())this.attemptSubmit(_defineProperty(_defineProperty({},h,""),b,e));else{t=this._textInput.inputElementRef.innerText.trim();this.attemptSubmit(_defineProperty(_defineProperty({},h,t),b,e));}($e.IS_SAFARI||$e.IS_MOBILE)&&setTimeout(function(){return ln.focusEndOfInput(_this121._textInput.inputElementRef);});case 2:return _context192.a(2);}},_callee192,this);}));function submitFromInput(){return _submitFromInput.apply(this,arguments);}return submitFromInput;}()},{key:"programmaticSubmit",value:function(){var _programmaticSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee193(e){var _this122=this;var t;return _regenerator().w(function(_context193){while(1)switch(_context193.n){case 0:typeof e=="string"&&(e=le.processSubmitUserMessage(e));t=_defineProperty({},h,e[h]);e[b]&&(t[b]=Array.from(e[b]).map(function(n){return _defineProperty({file:n},E,Tt.getTypeFromBlob(n));})),e.custom&&(t.custom=e.custom),setTimeout(function(){return _this122.attemptSubmit(t,!0);});case 1:return _context193.a(2);}},_callee193);}));function programmaticSubmit(_x364){return _programmaticSubmit.apply(this,arguments);}return programmaticSubmit;}()// TO-DO - should be disabled when loading history
265
+ },{key:"attemptSubmit",value:function(){var _attemptSubmit=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee194(e){var _this123=this;var t,r,o,a,c,n,s,_args194=arguments,_t59,_t60,_t61;return _regenerator().w(function(_context194){while(1)switch(_context194.n){case 0:t=_args194.length>1&&_args194[1]!==undefined?_args194[1]:!1;_context194.n=1;return(r=this._validationHandler)==null?void 0:r.call(this,t?e:void 0);case 1:_t59=_context194.v;_t60=!1;if(!(_t59===_t60)){_context194.n=2;break;}return _context194.a(2);case 2:this.changeToLoadingIcon();this._textInput.clear();$e.IS_MOBILE&&setTimeout(function(){return _this123._textInput.inputElementRef.focus();});_t61=typeof this._messages.focusMode!="boolean"&&(o=this._messages.focusMode)!=null&&o.fade;if(!_t61){_context194.n=3;break;}_context194.n=3;return Ws.fadeAnimation(this._messages.elementRef,this._messages.focusMode.fade);case 3:_context194.n=4;return this.addNewMessage(e);case 4:this._serviceIO.isWebModel()||this._messages.addLoadingMessage();n=(a=e[b])==null?void 0:a.map(function(l){return l[se];}),s=_defineProperty(_defineProperty({},h,e[h]===""?void 0:e[h]),b,n);_context194.n=5;return this._serviceIO.callAPI(s,this._messages);case 5:(c=this._fileAttachments)==null||c.hideFiles();case 6:return _context194.a(2);}},_callee194,this);}));function attemptSubmit(_x365){return _attemptSubmit.apply(this,arguments);}return attemptSubmit;}()},{key:"addNewMessage",value:function(){var _addNewMessage=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee195(_ref268){var e,t,n,s,_t62;return _regenerator().w(function(_context195){while(1)switch(_context195.n){case 0:e=_ref268.text,t=_ref268.files,n=_ref268.custom;s=_defineProperty(_defineProperty({},x,F),"custom",n);e&&(s[h]=e);_t62=t;if(!_t62){_context195.n=2;break;}_context195.n=1;return this._messages.addMultipleFiles(t,this._fileAttachments);case 1:s[b]=_context195.v;case 2:this._serviceIO.sessionId&&(s._sessionId=this._serviceIO.sessionId);Object.keys(s).length>0&&this._messages.addNewMessage(s);case 3:return _context195.a(2);}},_callee195,this);}));function addNewMessage(_x366){return _addNewMessage.apply(this,arguments);}return addNewMessage;}()},{key:"stopStream",value:function stopStream(){var e,t,n;(t=(e=this._serviceIO.streamHandlers).onAbort)==null||t.call(e),(n=this._stopClicked)==null||n.listener(),this._validationHandler&&this.resetSubmit(this._validationHandler);}},{key:"changeToStopIcon",value:function changeToStopIcon(){this._serviceIO.websocket||(this.elementRef[m].remove(Hs,$n,jn),me.removeAriaAttributes(this.elementRef),this.changeElementsByState(this._innerElements.stop),this.reapplyStateStyle(Bi,[It,st]),z.assignButtonEvents(this.elementRef,this.stopStream.bind(this)),this.status.loadingActive=!1);}},{key:"changeToLoadingIcon",value:function changeToLoadingIcon(){this._serviceIO.websocket||(this._isSVGLoadingIconOverriden||this.changeElementsByState(this._innerElements.loading),this.elementRef[m].remove(jn,$n),me.removeAriaDisabled(this.elementRef),this.elementRef[m].add(Hs),me.addAriaBusy(this.elementRef),this.reapplyStateStyle(It,[st]),z.assignButtonEvents(this.elementRef,function(){}),this.status.requestInProgress=!0,this.status.loadingActive=!0);}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
266
+ },{key:"changeToSubmitIcon",value:function changeToSubmitIcon(){var _this124=this;this.elementRef[m].contains(jn)||(this.elementRef[m].remove(Hs,$n),me.removeAriaAttributes(this.elementRef),this.elementRef[m].add(jn),this.changeElementsByState(this._innerElements.submit),nn.resetSubmit(this,this.status.loadingActive),z.assignButtonEvents(this.elementRef,function(){var e;_this124.submitFromInput(),(e=_this124._microphoneButton)!=null&&e.isActive&&Is.toggleSpeechAfterSubmit(_this124._microphoneButton.elementRef,!!_this124._stopSTTAfterSubmit),setTimeout(function(){return ln.focusEndOfInput(_this124._textInput.inputElementRef);});}));}// called every time when user triggers an input via ValidationHandler - hence use class to check if not already present
267
+ },{key:"changeToDisabledIcon",value:function changeToDisabledIcon(){var e=arguments.length>0&&arguments[0]!==undefined?arguments[0]:!1;this._alwaysEnabled&&!e?this.changeToSubmitIcon():this.elementRef[m].contains($n)||(this.elementRef[m].remove(Hs,jn),me.removeAriaBusy(this.elementRef),this.elementRef[m].add($n),me.addAriaDisabled(this.elementRef),this.changeElementsByState(this._innerElements[j]),this.reapplyStateStyle(j,[st]),z.assignButtonEvents(this.elementRef,function(){}));}},{key:"disableSubmitButton",value:function disableSubmitButton(e,t){var n;e.isSubmitProgrammaticallyDisabled=t!==!1,!(this.status.requestInProgress||this.status.loadingActive)&&(t===!1?(n=this._validationHandler)==null||n.call(this):this.changeToDisabledIcon(!0));}}],[{key:"createButtonContainerElement",value:function createButtonContainerElement(){var e=A();return e[m].add("input-button"),e;}},{key:"createLoadingIconElement",value:function createLoadingIconElement(){var e=A();return e[m].add("loading-submit-button"),e;}},{key:"createStopIconElement",value:function createStopIconElement(){var e=A();return e.id="stop-icon",e;}}]);}(gn);var Wh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M27.1 14.313V5.396L24.158 8.34c-2.33-2.325-5.033-3.503-8.11-3.503C9.902 4.837 4.901 9.847 4.899 16c.001 6.152 5.003 11.158 11.15 11.16 4.276 0 9.369-2.227 10.836-8.478l.028-.122h-3.23l-.022.068c-1.078 3.242-4.138 5.421-7.613 5.421a8 8 0 0 1-5.691-2.359A7.993 7.993 0 0 1 8 16.001c0-4.438 3.611-8.049 8.05-8.049 2.069 0 3.638.58 5.924 2.573l-3.792 3.789H27.1z\"/>\n</svg>\n",Xh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M0 16q0 3.264 1.28 6.208t3.392 5.12 5.12 3.424 6.208 1.248 6.208-1.248 5.12-3.424 3.392-5.12 1.28-6.208-1.28-6.208-3.392-5.12-5.088-3.392-6.24-1.28q-3.264 0-6.208 1.28t-5.12 3.392-3.392 5.12-1.28 6.208zM4 16q0-3.264 1.6-6.016t4.384-4.352 6.016-1.632 6.016 1.632 4.384 4.352 1.6 6.016-1.6 6.048-4.384 4.352-6.016 1.6-6.016-1.6-4.384-4.352-1.6-6.048z\"></path>\n</svg>\n",Zh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 1024 1024\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M195.2 195.2a64 64 0 0 1 90.496 0L512 421.504 738.304 195.2a64 64 0 0 1 90.496 90.496L602.496 512 828.8 738.304a64 64 0 0 1-90.496 90.496L512 602.496 285.696 828.8a64 64 0 0 1-90.496-90.496L421.504 512 195.2 285.696a64 64 0 0 1 0-90.496z\"/>\n</svg>",Yh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M4.89163 13.2687L9.16582 17.5427L18.7085 8\" stroke=\"#000000\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</svg>";var Rr=/*#__PURE__*/function(_tn){// prettier-ignore
268
+ function Rr(e,t,n,s){var _this125;_classCallCheck(this,Rr);_this125=_callSuper(this,Rr,[e,["modal-content","modal-camera-content"],n]),_this125._stopped=!1,_this125._format="image/png",_this125._canvas=A("canvas"),_this125._canvas[m].add("camera-modal-canvas");var _this125$addButtonsAn=_this125.addButtonsAndTheirEvents(t),r=_this125$addButtonsAn.captureButton,o=_this125$addButtonsAn.submitButton;_this125._captureButton=r,_this125._submitButton=o,_this125._captureIcon=_this125._captureButton.children[0],_this125._refreshIcon=kt.createSVGElement(Wh),_this125._refreshIcon[m].add("modal-svg-button-icon","modal-svg-refresh-icon"),(s==null?void 0:s.format)==="jpeg"&&(_this125._format="image/jpeg"),s!=null&&s.dimensions&&(_this125._dimensions=s.dimensions),_this125._contentRef.appendChild(_this125._canvas),_this125.extensionCloseCallback=_this125.stop;return _this125;}_inherits(Rr,_tn);return _createClass(Rr,[{key:"addButtonsAndTheirEvents",value:function addButtonsAndTheirEvents(e){var t=tn.createSVGButton(Xh);t[m].add("modal-svg-camera-button"),t.children[0][m].add("modal-svg-camera-icon");var n=this.addCloseButton(Zh,!0);n[m].add("modal-svg-close-button"),n.children[0][m].add("modal-svg-close-icon");var s=tn.createSVGButton(Yh);return s[m].add("modal-svg-submit-button"),this.addButtons(t,s),this.addButtonEvents(t,n,s,e),{captureButton:t,submitButton:s};}// prettier-ignore
269
+ },{key:"addButtonEvents",value:function addButtonEvents(e,t,n,s){var _this126=this;z.assignButtonEvents(e,this.capture.bind(this)),z.assignButtonEvents(t,this.stop.bind(this)),z.assignButtonEvents(n,function(){var r=_this126.getFile();r&&Os.addFilesToType([r],[s]),_this126.stop(),_this126.close();});}},{key:"stop",value:function stop(){var _this127=this;this._mediaStream&&this._mediaStream.getTracks().forEach(function(e){return e.stop();}),this._stopped=!0,setTimeout(function(){_this127._captureButton.replaceChildren(_this127._captureIcon),_this127._captureButton[m].replace("modal-svg-refresh-button","modal-svg-camera-button");var e=_this127._canvas.getContext("2d");e==null||e.clearRect(0,0,_this127._canvas.width,_this127._canvas.height);},tn.MODAL_CLOSE_TIMEOUT_MS);}},{key:"start",value:function start(){var _this128=this;this._dataURL=void 0,this._submitButton[m].add("modal-svg-submit-".concat(j)),this._stopped=!1,navigator.mediaDevices.getUserMedia({video:this._dimensions||!0}).then(function(e){if(_this128._mediaStream=e,!_this128.isOpen())return _this128.stop();var t=A("video");t.srcObject=e,t.play(),requestAnimationFrame(_this128.updateCanvas.bind(_this128,t,_this128._canvas));})["catch"](function(e){console[f](e),_this128.stop(),_this128.close();});}},{key:"capture",value:function capture(){this._dataURL?(this._captureButton.replaceChildren(this._captureIcon),this._captureButton[m].replace("modal-svg-refresh-button","modal-svg-camera-button"),this._submitButton[m].add("modal-svg-submit-".concat(j)),this._dataURL=void 0):(this._captureButton.replaceChildren(this._refreshIcon),this._captureButton[m].replace("modal-svg-camera-button","modal-svg-refresh-button"),this._submitButton[m].remove("modal-svg-submit-".concat(j)),this._dataURL=this._canvas.toDataURL());}},{key:"getFile",value:function getFile(){if(this._dataURL){var e=atob(this._dataURL.split(",")[1]),t=new Array(e.length);for(var a=0;a<e.length;a++)t[a]=e.charCodeAt(a);var _n18=new Uint8Array(t),s=new Blob([_n18],{type:this._format}),r=this._format==="image/jpeg"?"jpeg":"png",o=ma.getFileName(this._newFilePrefix||"photo",r);return new File([s],o,{type:s[E]});}}},{key:"updateCanvas",value:function updateCanvas(e,t){if(!this._stopped){if(!this._dataURL){t.width=e.videoWidth,t.height=e.videoHeight;var _n19=t.getContext("2d");_n19==null||_n19.drawImage(e,0,0,t.width,t.height);}requestAnimationFrame(this.updateCanvas.bind(this,e,t));}}},{key:"openCameraModal",value:function openCameraModal(e){this.displayModalElements(),e[qt]();}// prettier-ignore
270
+ }],[{key:"createCameraModalFunc",value:function createCameraModalFunc(e,t,n,s){var r=new Rr(e,t,n,s);return r.openCameraModal.bind(r,r);}}]);}(tn);var Jh="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M29 7h-4.599l-2.401-4h-12l-2.4 4h-4.6c-1 0-3 1-3 2.969v16.031c0 1.657 1.5 3 2.792 3h26.271c1.313 0 2.938-1.406 2.938-2.968v-16.032c0-1-1-3-3-3zM30 26.032c0 0.395-0.639 0.947-0.937 0.969h-26.265c-0.232-0.019-0.797-0.47-0.797-1v-16.031c0-0.634 0.851-0.953 1-0.969h5.732l2.4-4h9.802l1.785 3.030 0.55 0.97h5.731c0.705 0 0.99 0.921 1 1v16.032zM16 10c-3.866 0-7 3.134-7 7s3.134 7 7 7 7-3.134 7-7-3.134-7-7-7zM16 22c-2.757 0-5-2.243-5-5s2.243-5 5-5 5 2.243 5 5-2.243 5-5 5z\"></path>\n</svg>";var Ir=/*#__PURE__*/function(_gn7){function Ir(e,t,n){var _this129;_classCallCheck(this,Ir);var l,d,p,u,g,y;var s=le.processPosition((l=n==null?void 0:n.button)==null?void 0:l.position),r=((u=(p=(d=n==null?void 0:n.button)==null?void 0:d[R])==null?void 0:p[h])==null?void 0:u.content)||"Photo",o=ut.tryCreateConfig("Camera",(g=n==null?void 0:n.button)==null?void 0:g.tooltip),a=((y=n==null?void 0:n.button)==null?void 0:y[R])||{};_this129=_callSuper(this,Ir,[Ir.createButtonElement(),Jh,s,o,a,r]);var c=_this129.createInnerElementsForStates(_this129.customStyles);n&&_this129.addClickEvent(e,t,n.modalContainerStyle,n[b]),_this129.changeElementsByState(c[R]),_this129.reapplyStateStyle(R);return _this129;}_inherits(Ir,_gn7);return _createClass(Ir,[{key:"createInnerElementsForStates",value:function createInnerElementsForStates(e){return _defineProperty({},R,this.createInnerElements("camera-icon",R,e));}},{key:"addClickEvent",value:// prettier-ignore
271
+ function addClickEvent(e,t,n,s){var r=Rr.createCameraModalFunc(e,t,n,s);z.assignButtonEvents(this.elementRef,r);}}],[{key:"createButtonElement",value:function createButtonElement(){var e=A();return e[m].add("input-button"),e;}}]);}(gn);var vn=/*#__PURE__*/function(){function vn(e,t,n,s){_classCallCheck(this,vn);this.elementRef=vn.createPanelElement(e.inputAreaStyle);var r={},o=this.createFileUploadComponents(e,n,s,r),a=new Ks(e,n,o,t.browserStorage);e.speechToText&&!r.microphone&&(r.microphone={button:new Is(e,a,t.addNewErrorMessage.bind(t))});var c=new ms(e,a,t,n,o,r);a.submit=c.submitFromInput.bind(c),Wt.attach(e,n,a,o,c,t.browserStorage),e.submitUserMessage=c.programmaticSubmit.bind(c),r.submit={button:c},e.customButtons&&rn.add(e,r),vn.addElements(this.elementRef,a,r,s,o,e.dropupStyles),vn.assignOnInput(e,n,o,a);}return _createClass(vn,[{key:"createFileUploadComponents",value:// prettier-ignore
272
+ function createFileUploadComponents(e,t,n,s){var o,a,c,l;var r=new Os(this.elementRef,e.attachmentContainerStyle,t.demo);if(vn.createUploadButtons(e,t,t.fileTypes||{},r,n,s),(o=t[Fe])!=null&&o[b]){var d=((a=s[ee])==null?void 0:a.fileType)||r.addType(e,t,t[Fe][b],ee);s[Fe]={button:new Ir(n,d,t[Fe])};}if((c=t.recordAudio)!=null&&c[b]){var _d3=((l=s[$])==null?void 0:l.fileType)||r.addType(e,t,t.recordAudio[b],$);s.microphone={button:new Vh(_d3,t.recordAudio)};}return Ct.isEnabled(r,e.dragAndDrop)&&Ct.create(n,r,e.dragAndDrop),r;}// prettier-ignore
273
+ }],[{key:"createPanelElement",value:function createPanelElement(e){var t=A();return t.id="input",Object.assign(t[v],e),t;}},{key:"createUploadButtons",value:function createUploadButtons(e,t,n,s,r,o){Object.keys(n).forEach(function(a){var c=a,l=n[c];if(l[b]){var d=s.addType(e,t,l[b],c),_Ch$c=Ch[c],p=_Ch$c.id,u=_Ch$c.svgString,g=_Ch$c.dropupText,y=new ui(r,d,l,p,u,g);o[c]={button:y,fileType:d};}});}// prettier-ignore
274
+ },{key:"addElements",value:function addElements(e,t,n,s,r,o){z.addElements(e,t.elementRef);var a=Ln.create(),c=Ne.addButtons(a,n,s,o);fs.set(t.inputElementRef,a,r.elementRef,c),Ln.add(e,a);}},{key:"assignOnInput",value:function assignOnInput(e,t,n,s){t.onInput=function(r){setTimeout(function(){var o=n.getAllFileData(),a=s.inputElementRef.innerText.trim(),c=_defineProperty({},h,a);o&&(c[b]=o.map(function(l){return l[se];})),hn.onInput(e,c,r);});};}}]);}();var Mr=/*#__PURE__*/function(){function Mr(){_classCallCheck(this,Mr);}return _createClass(Mr,null,[{key:"createElements",value:function createElements(e,t,n){var s=A();s.id="chat-view";var r=!e.focusMode&&e.upwardsMode;s.classList.add(r?bh:gh);var o=new tt(e,t,n);t.websocket&&ke.createConnection(t,o);var a=new vn(e,o,t,s),c=r?o.elementRef.parentElement:o.elementRef;return z.addElements(s,c,a.elementRef),s;}},{key:"render",value:function render(e,t,n,s){var r=Mr.createElements(e,n,s);t.replaceChildren(r),n.isCustomView()&&n.setUpView(r,t);}}]);}();var Qh="#validate-property-key-view{height:100%;position:relative;display:flex;justify-content:center;align-items:center;padding:8px}#loading-validate-key-property{display:inline-block;width:50px;height:50px}#loading-validate-key-property:after{content:\" \";display:block;width:38px;height:38px;margin:1px;border-radius:50%;border:5px solid #5fb2ff;border-color:#5fb2ff transparent #5fb2ff transparent;animation:loading-spinner 1.4s linear infinite}#deep-chat-openai-realtime-container{height:100%;width:100%}#deep-chat-openai-realtime-avatar-container{height:60%;width:100%;display:flex;justify-content:center;align-items:center}#deep-chat-openai-realtime-avatar{border-radius:50%;height:110px;border:1px solid rgb(215,215,215);padding:8px;-webkit-user-select:none;user-select:none;margin-top:20px}#deep-chat-openai-realtime-buttons-container{height:40%;display:flex;position:relative}.deep-chat-openai-realtime-button-container{height:100%;width:50%;display:flex;justify-content:center;align-items:center}.deep-chat-openai-realtime-button{width:70px;height:70px;border-radius:50%;display:flex;justify-content:center;align-items:center;cursor:pointer}.deep-chat-openai-realtime-button-default{background-color:#e3e3e3}.deep-chat-openai-realtime-button-default:hover{background-color:#d4d4d4}.deep-chat-openai-realtime-button-default:active{background-color:#c5c5c5}.deep-chat-openai-realtime-button-loading{opacity:.7;pointer-events:none}.deep-chat-openai-realtime-microphone-active{background-color:#ffe7e7}.deep-chat-openai-realtime-microphone-active:hover{background-color:#ffdede}.deep-chat-openai-realtime-microphone-active:active{background-color:#ffd2d2}.deep-chat-openai-realtime-microphone>*{height:30px;width:30px}.deep-chat-openai-realtime-microphone-active>*{filter:brightness(0) saturate(100%) invert(35%) sepia(60%) saturate(1360%) hue-rotate(325deg) brightness(95%) contrast(92%)}.deep-chat-openai-realtime-toggle>*{height:32px;width:32px;padding-inline-start:3px;filter:brightness(0) saturate(100%) invert(22%) sepia(0%) saturate(4537%) hue-rotate(208deg) brightness(105%) contrast(91%)}.deep-chat-openai-realtime-button-unavailable{opacity:.45;pointer-events:none}#deep-chat-openai-realtime-error{color:red;position:absolute;top:calc(50% + 40px);inset-inline-start:50%;transform:translate(-50%,-50%);font-size:17px}#deep-chat-openai-realtime-loading{position:absolute;font-size:15px;top:50%;inset-inline-start:50%;transform:translate(-50%,-50%)}#insert-key-view{height:100%;position:relative}#insert-key-contents{text-align:center;position:absolute;inset-block-start:44%;inset-inline-start:50%;transform:translate(-50%,-50%);width:82%;display:flex;max-width:700px}#insert-key-title{margin-bottom:15px}#insert-key-input-container{margin-inline-end:2.7em;width:calc(100% - 80px)}#insert-key-input{padding:.3em 1.7em .3em .3em;border-width:1px;border-style:solid;border-radius:3px;width:100%;font-size:inherit}.insert-key-input-valid{border-color:gray}.insert-key-input-invalid{border-color:red}#visibility-icon-container{position:relative;float:inline-end;cursor:pointer;-webkit-user-select:none;user-select:none}.visibility-icon{filter:brightness(0) saturate(100%) invert(63%) sepia(1%) saturate(9%) hue-rotate(43deg) brightness(98%) contrast(92%);position:absolute;inset-inline-end:-1.7em;inset-block-start:-1.43em}#visible-icon{inset-block-start:-1.4em}.visibility-icon:hover{filter:unset}.visibility-icon>*{pointer-events:none}#start-button{border:1px solid grey;color:#454545;border-radius:4px;width:3em;display:flex;justify-content:center;align-items:center;cursor:pointer;padding:.28em .3em;-webkit-user-select:none;user-select:none;background-color:#fff}#start-button:hover{background-color:#f2f2f2}#start-button:active{background-color:#d2d2d2}#insert-key-help-text-container{width:100%;position:absolute;margin-top:32px;margin-bottom:20px}#insert-key-help-text-contents{width:100%;position:absolute}#insert-key-input-invalid-text{display:block;margin-top:1em;margin-bottom:.5em;color:red}.insert-key-input-help-text{display:block;margin-top:16px}#loading-key{display:inline-block;width:16px;height:16px}#loading-key:after{content:\" \";display:block;width:11px;height:11px;margin:1px;border-radius:50%;border:2px solid #0084ff;border-color:#0084ff transparent #0084ff transparent;animation:loading-spinner 1.2s linear infinite}#error-view{color:red;font-size:1.2em;line-height:1.3em;margin-top:-5px;text-align:center;height:100%;display:flex;justify-content:center;align-items:center;padding-inline:8px}@keyframes loading-spinner{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.intro-panel{position:absolute;display:flex;justify-content:center;right:0;bottom:0;left:0;margin:auto;height:fit-content;top:-2.5em}pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!\n Theme: a11y-dark\n Author: @ericwbailey\n Maintainer: @ericwbailey\n\n Based on the Tomorrow Night Eighties theme: https://github.com/isagalaev/highlight.js/blob/master/src/styles/tomorrow-night-eighties.css\n*/.hljs{background:#2b2b2b;color:#f8f8f2}.hljs-comment,.hljs-quote{color:#d4d0ab}.hljs-deletion,.hljs-name,.hljs-regexp,.hljs-selector-class,.hljs-selector-id,.hljs-tag,.hljs-template-variable,.hljs-variable{color:#ffa07a}.hljs-built_in,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-type{color:#f5ab35}.hljs-attribute{color:gold}.hljs-addition,.hljs-bullet,.hljs-string,.hljs-symbol{color:#abe338}.hljs-section,.hljs-title{color:#00e0e0}.hljs-keyword,.hljs-selector-tag{color:#dcc6e0}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}@media screen and (-ms-high-contrast:active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}}#messages,.deep-chat-upwards-mode #messages>div{overflow:auto;overflow-anchor:none}.deep-chat-upwards-mode #messages{height:100%;display:flex;flex-direction:column;justify-content:flex-end}.outer-message-container:last-child{margin-bottom:5px}.inner-message-container{display:flex;margin-inline:auto;width:calc(97.5% - 24px);max-width:100%}.message-bubble{margin-top:10px;word-wrap:break-word;width:fit-content;max-width:60%;border-radius:10px;padding:.42em .55em;height:fit-content;line-height:1.26}.user-message-text{color:#fff;background-color:#0084ff;margin-inline-end:0px;margin-inline-start:auto}.ai-message-text{color:#000;background-color:#e4e6eb;margin-inline-start:0px;margin-inline-end:auto}.deep-chat-last-group-messages-active{height:100%}#scroll-button{position:absolute;top:75%;left:50%;right:50%;transform:translate(-50%,-50%);transition:opacity .1s ease;display:flex;opacity:0;padding:8px;background-color:#fff;border:.5px solid #000000;justify-content:center;align-items:center;white-space:nowrap;cursor:pointer}#scroll-button:hover{background-color:#fafafa}.loading-history-message-full-view{position:absolute;height:70%;width:100%;display:flex;align-items:center}.deep-chat-upwards-mode #messages .loading-history-message-full-view{height:100%}.loading-history-message-small{height:20px;margin-bottom:30px}.loading-history-message-small>div>div{scale:.6}.loading-history-message{margin-top:0;width:100%;max-width:100%;display:flex;justify-content:center;background-color:unset}.loading-history{width:70px}.loading-history div{position:absolute;width:var(--loading-history-width);height:var(--loading-history-height);margin:var(--loading-history-margin);border:var(--loading-history-border);border-radius:50%;animation:loading-spinner 1.2s cubic-bezier(.5,0,.5,1) infinite;border-color:var(--loading-history-color) transparent transparent transparent}.loading-history div:nth-child(1){animation-delay:-.45s}.loading-history div:nth-child(2){animation-delay:-.3s}.loading-history div:nth-child(3){animation-delay:-.15s}.html-message{max-width:unset}.error-message-text{margin-inline:auto;background-color:#f4c0c0;color:#474747;text-align:center;max-width:95%;margin-top:14px;margin-bottom:10px}.deep-chat-loading-message-dots-container{width:1em;padding-top:.6em;padding-bottom:.6em;padding-inline-start:1.3em;padding-inline-end:.75em}.loading-message-dots{position:relative;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite linear alternate;animation-delay:.5s}.loading-message-dots:before,.loading-message-dots:after{content:\"\";display:inline-block;position:absolute;top:0}.loading-message-dots:before{inset-inline-start:-.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:0s}.loading-message-dots:after{inset-inline-start:.7em;width:.45em;height:.45em;border-radius:5px;background-color:var(--loading-message-color);color:var(--loading-message-color);animation:loading-message-dots 1s infinite alternate;animation-delay:1s}@keyframes loading-message-dots{0%{background-color:var(--loading-message-color)}50%,to{background-color:var(--loading-message-color-fade)}}.message-bubble>p:first-child,.message-bubble>.partial-render-message>p:first-child,.html-wrapper>p:first-child{margin-top:0}.message-bubble>p:last-child,.message-bubble>.partial-render-message:last-child>p,.html-wrapper>p:last-child{margin-bottom:0}pre{overflow:auto;display:block;word-break:break-all;word-wrap:break-word;border-radius:7px;background:#2b2b2b;color:#f8f8f2;margin-top:.8em;margin-bottom:.8em;padding:.6em;font-size:.9em;line-height:1.5em}.image-message{padding:0;display:flex;background-color:#ddd}.image-message>*,.image-message>*>*{width:100%;border-radius:8px;display:flex}.audio-message{width:60%;max-width:300px;height:2.2em;max-height:54px;padding:0;background-color:unset}.audio-player{width:100%;height:100%}.audio-player-safari{height:fit-content;width:40px}.audio-player-safari-start{float:inline-start}.audio-player-safari-end{float:inline-end}.any-file-message{padding:1px}.any-file-message-contents{display:flex}.any-file-message-icon-container{width:1.3em;min-width:1.3em;position:relative;border-radius:4px;margin-inline-start:6px;margin-inline-end:2px}.any-file-message-icon{background-color:#fff;border-radius:4px;position:absolute;width:1em;height:1.25em;padding:1px;margin-top:auto;margin-bottom:auto;top:0;bottom:0}.any-file-message-text{padding-top:5px;overflow-wrap:anywhere;padding-bottom:5px;padding-inline-end:7px}.message-bubble>a{color:inherit}.start-item-position{margin-inline-end:10px}.end-item-position{margin-inline-start:10px}.role-hidden{display:none}.avatar{padding-top:5px;width:1.5em;height:1.5em;border-radius:1px}.avatar-container{margin-top:9px}.name{margin-top:16px;font-size:15px}#drag-and-drop{position:absolute;display:none;z-index:10;height:calc(100% - 10px);width:calc(100% - 10px);background-color:#70c6ff4d;border:5px dashed #6dafff}#file-attachment-container{position:absolute;height:3.6em;width:calc(80% - 4px);top:-2.5em;border-radius:5px;overflow:auto;text-align:start;background-color:#d7d7d73b;padding-inline-start:4px}.file-attachment{width:2.85em;height:2.85em;display:inline-flex;margin-inline-end:.6em;margin-bottom:.44em;margin-top:4px;position:relative;background-color:#fff;border-radius:5px}.image-attachment{width:100%;height:100%;object-fit:cover;border-radius:5px}.border-bound-attachment{width:calc(100% - 2px);height:calc(100% - 2px);border:1px solid #c3c3c3;border-radius:5px;overflow:hidden}.border-bound-attachment-safari{width:calc(100% - 1px);height:calc(100% - 1px)}.audio-attachment-icon-container{cursor:pointer}.audio-attachment-icon-container:hover{background-color:#f8f8f8}.attachment-icon{inset-inline:0;bottom:0;top:2px;margin:auto;position:absolute;width:25px;-webkit-user-select:none;user-select:none}.not-removable-attachment-icon{top:0;right:0;bottom:0;left:0}.play-icon{filter:brightness(0) saturate(100%) invert(17%) sepia(0%) saturate(1392%) hue-rotate(67deg) brightness(98%) contrast(97%)}.stop-icon{filter:brightness(0) saturate(100%) invert(29%) sepia(90%) saturate(1228%) hue-rotate(198deg) brightness(93%) contrast(98%)}.audio-placeholder-text-3-digits{padding-inline-start:.26rem}.audio-placeholder-text-4-digits{padding-inline-start:.1rem}.any-file-attachment{padding:2px 0}.file-attachment-text-container{position:absolute;width:inherit;display:flex;align-items:center;height:100%;top:-1px}.audio-placeholder-text-3-digits-container{padding-top:1px;cursor:default}.any-file-attachment-text{text-overflow:ellipsis;white-space:nowrap;overflow:hidden;padding-inline-start:.13em;margin-inline:auto}.remove-file-attachment-button{height:1.25em;width:1.25em;border:1px solid #cfcfcf;border-radius:25px;background-color:#fff;top:-4px;inset-inline-end:-5px;position:absolute;display:flex;justify-content:center;cursor:pointer;-webkit-user-select:none;user-select:none}.remove-file-attachment-button:hover{background-color:#e4e4e4}.remove-file-attachment-button:active{background-color:#d7d7d7}.x-icon{color:#4e4e4e;top:-.075em;position:relative;font-size:1.05em}.modal{display:none;flex-direction:column;align-items:center;justify-content:center;position:absolute;width:80%;max-width:420px;max-height:80%;margin:auto;top:0;right:0;bottom:0;left:0;z-index:3}.modal-content{border-top:1px solid rgb(217,217,217);border-inline:1px solid rgb(217,217,217);border-start-start-radius:inherit;border-start-end-radius:inherit;background-color:#fff;overflow-y:auto;height:fit-content;max-height:calc(100% - 3.3em);width:100%}.modal-content>p{margin-inline:1em}.modal-content>ul{margin-inline-end:1em}.modal-button-panel{height:3.3em;border:1px solid;border-color:rgb(223,223,223) rgb(217,217,217) rgb(217,217,217);border-end-start-radius:inherit;border-end-end-radius:inherit;background-color:#fff;text-align:center;justify-content:center;display:flex;width:100%}.modal-button{min-width:2.5em;text-align:center;color:#fff;border-radius:5px;padding:.4em .4em .3em;height:1.25em;background-color:#3279b2;inset-block:0;margin-top:auto;margin-bottom:auto;cursor:pointer;-webkit-user-select:none;user-select:none;margin-inline:.31em}.modal-button:hover{background-color:#276da7}.modal-button:active{background-color:#1b5687}.modal-svg-button{padding:0 0 2px;width:2em;height:1.8em}.modal-svg-button-icon{width:100%;height:100%;filter:brightness(0) saturate(100%) invert(100%) sepia(15%) saturate(4%) hue-rotate(346deg) brightness(101%) contrast(102%)}#modal-background-panel{position:absolute;width:100%;height:100%;background-color:#00000042;z-index:2;display:none}.show-modal-background{animation:fadeInBackground .3s ease-in-out}@keyframes fadeInBackground{0%{opacity:0}to{opacity:1}}.show-modal{animation:fadeInModal .3s ease-in-out}@keyframes fadeInModal{0%{opacity:0;scale:.95}to{opacity:1;scale:1}}.hide-modal-background{animation:fadeOutBackground .2s ease-in-out}@keyframes fadeOutBackground{0%{opacity:1}to{opacity:0}}.hide-modal{animation:fadeOutModal .2s ease-in-out}@keyframes fadeOutModal{0%{opacity:1;scale:1}to{opacity:0;scale:.95}}.modal-camera-content{overflow:hidden;text-align:center;border:unset;height:100%;background-color:#2a2a2a;display:flex;justify-content:center}.camera-modal-canvas{max-width:100%;max-height:100%;margin-top:auto;margin-bottom:auto}.modal-svg-submit-button{background-color:green}.modal-svg-submit-button:hover{background-color:#007500}.modal-svg-submit-button:active{background-color:#006500}.modal-svg-submit-disabled{pointer-events:none;background-color:#747474}.modal-svg-close-button{height:1.56em;padding-top:.37em;padding-bottom:0;background-color:#c13e3e}.modal-svg-close-button:hover{background-color:#b43434}.modal-svg-close-button:active{background-color:#972929}.modal-svg-close-icon{width:80%;height:80%}.modal-svg-camera-button{height:1.6em;padding-top:.38em;padding-bottom:0}.modal-svg-camera-icon{height:76%}.modal-svg-refresh-icon{height:105%}.modal-svg-refresh-button{height:1.66em;padding-top:.11em;padding-bottom:.21em}.input-button-container{position:relative;z-index:1}.inside-end{position:absolute;inset-inline-end:calc(10% + .35em);inset-block-end:.85em}.inside-start{position:absolute;inset-inline-start:calc(10% + .35em);inset-block-end:.85em}.outside-start{position:absolute;inset-inline-end:calc(11px - .55em);inset-block-end:.88em}.outside-end{position:absolute;inset-inline-start:calc(11px - .55em);inset-block-end:.88em}#upload-images-icon{position:absolute;pointer-events:none;width:1.45em;height:1.45em;inset-inline-start:.11em;inset-block-end:.08em;filter:brightness(0) saturate(100%) invert(43%) sepia(0%) saturate(740%) hue-rotate(77deg) brightness(99%) contrast(92%)}#upload-gifs-icon{position:absolute;pointer-events:none;width:1.5em;height:1.48em;inset-inline-start:.07em;inset-block-end:.08em;filter:brightness(0) saturate(100%) invert(49%) sepia(0%) saturate(2586%) hue-rotate(12deg) brightness(93%) contrast(90%)}#upload-audio-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.17em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%);transform:scaleX(.95)}#camera-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.23em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(52%) sepia(0%) saturate(161%) hue-rotate(164deg) brightness(91%) contrast(92%);transform:scaleX(.95)}#upload-mixed-files-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.25em;inset-block-end:.2em;filter:brightness(0) saturate(100%) invert(53%) sepia(0%) saturate(36%) hue-rotate(74deg) brightness(98%) contrast(93%);transform:scaleX(.95)}#interim-text{color:gray}#microphone-button{padding-top:.5px}.outer-button-container>#microphone-button{padding-bottom:1px}#microphone-icon{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.25em;inset-block-end:.25em}.default-microphone-icon{filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%)}.active-microphone-icon{filter:brightness(0) saturate(100%) invert(10%) sepia(97%) saturate(7495%) hue-rotate(0deg) brightness(101%) contrast(107%);border-radius:10px}.command-microphone-icon{filter:brightness(0) saturate(100%) invert(42%) sepia(96%) saturate(1067%) hue-rotate(77deg) brightness(99%) contrast(102%)}.unsupported-microphone{display:none}#submit-icon{height:100%;filter:brightness(0) saturate(100%) invert(32%) sepia(0%) saturate(924%) hue-rotate(46deg) brightness(95%) contrast(99%);width:1.21em}#stop-icon{background-color:#acacac;position:absolute;width:.95em;height:.95em;inset-inline-start:.35em;inset-block-end:.35em;border-radius:2px}.submit-button-enlarged{scale:1.1;margin-inline:.3em}.loading-submit-button{position:relative;inset-inline-start:calc(-9990px + .275em);width:.22em;height:.22em;border-radius:5px;background-color:#848484;color:#848484;box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484;animation:loading-submit-button 1.5s infinite linear;inset-block-end:-.75em}@keyframes loading-submit-button{0%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}16.667%{box-shadow:9990px -6px #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}33.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}50%{box-shadow:9990px 0 #848484,calc(9990px + .44em) -6px 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}66.667%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}83.333%{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) -6px 0 0 #848484}to{box-shadow:9990px 0 #848484,calc(9990px + .44em) 0 0 0 #848484,calc(9990px + .8em) 0 0 0 #848484}}.tooltip{position:absolute;visibility:hidden;z-index:1;pointer-events:none;padding:5px;padding-inline:7px;background-color:#333;border-radius:5px;width:max-content}.tooltip-text{color:#fff;font-size:13px}.input-button{border-radius:4px;cursor:pointer;margin-bottom:.2em;-webkit-user-select:none;user-select:none}.input-button-svg{width:1.65em;height:1.65em}.input-button-svg-text{padding:1px;height:1.65em;display:flex}.input-button-svg-text>svg{padding:.22rem}.input-button-svg-text>div{margin-inline-start:2px}.input-button:hover,.input-button:focus-visible{background-color:#9c9c9c2e}.input-button:active{background-color:#9c9c9c5e}.input-button:active:not(:hover){background-color:transparent}.loading-button{cursor:auto}.loading-button:hover{background-color:unset}.text-button{filter:unset!important;display:flex;justify-content:center;align-items:center;margin-inline:4px;height:1.6em;width:max-content}#custom-icon{height:100%;width:1.2em}.custom-button-container-default{color:#505050}.custom-button-container-default>.dropup-menu-item-icon{color:unset}.custom-button-container-default>svg{filter:brightness(0) saturate(100%) invert(39%) sepia(1%) saturate(0%) hue-rotate(83deg) brightness(93%) contrast(90%)}.custom-button-container-default>.dropup-menu-item-icon>svg{position:absolute;inset-inline-start:.2em}.custom-button-container-active{background-color:#edf7ff;color:#0285ff}.custom-button-container-active:hover,.custom-button-container-active:focus-visible{background-color:#def0ff}.custom-button-container-active:active{background-color:#d2eaff}.custom-button-container-active>svg{filter:brightness(0) saturate(100%) invert(32%) sepia(34%) saturate(4196%) hue-rotate(196deg) brightness(107%) contrast(104%)}.custom-button-container-disabled{color:#aeaeae;cursor:auto}.custom-button-container-disabled>div{pointer-events:none}.custom-button-container-disabled:hover,.custom-button-container-disabled:focus-visible{background-color:transparent}.custom-button-container-disabled:active{background-color:transparent}.custom-button-container-disabled>svg{filter:brightness(0) saturate(100%) invert(67%) sepia(0%) saturate(818%) hue-rotate(28deg) brightness(102%) contrast(100%)}#text-input-container{background-color:#fff;width:80%;display:flex;border:1px solid #0000001a;border-radius:5px;margin-top:.8em;margin-bottom:.8em;box-shadow:#959da533 0 1px 12px;overflow-y:auto;max-height:200px;position:relative}.text-input-container-start-adjustment{margin-inline-start:1.5em}.text-input-container-end-adjustment{margin-inline-end:1.5em}.text-input-container-start-small-adjustment{margin-inline-start:1.1em}.text-input-container-start-small-adjustment>.outside-start{inset-inline-end:calc(14px - .55em)}.text-input-container-end-small-adjustment{margin-inline-end:1.1em}.text-input-container-end-small-adjustment>.outside-end{inset-inline-start:calc(14px - .55em)}#text-input{text-align:start;outline:none;word-wrap:break-word;line-break:auto}.text-input-styling{padding:.4em .5em;overflow:overlay;width:100%}.text-input-inner-start-adjustment{padding-inline-start:2.2em}.text-input-inner-end-adjustment{padding-inline-end:2em}.text-input-disabled{pointer-events:none;-webkit-user-select:none;user-select:none}[contenteditable]:empty:before{content:attr(deep-chat-placeholder-text);pointer-events:none}[contenteditable][textcolor]:empty:before{color:gray}.outside-end>#dropup-menu,.inside-end>#dropup-menu{inset-inline-end:0px}#dropup-icon{position:absolute;pointer-events:none;width:1.16em;height:1.2em;inset-inline-start:.265em;bottom:.43em;filter:brightness(0) saturate(100%) invert(54%) sepia(0%) saturate(724%) hue-rotate(6deg) brightness(92%) contrast(90%)}.dropup-button>*{pointer-events:none}#dropup-menu{background-color:#fff;position:absolute;transform:translateY(-100%);border-radius:5px;z-index:1;top:-.49em;box-shadow:#0003 -1px 2px 10px,#0000001a 0 2px 4px;cursor:pointer;-webkit-user-select:none;user-select:none}.dropup-menu-item{height:1.4em;padding-inline-start:.35em;padding-inline-end:.84em;padding-top:.28em;padding-bottom:.28em;display:flex;position:relative}.dropup-menu-item:hover,.dropup-menu-item:focus-visible{background-color:#f3f3f3}.dropup-menu-item:active{background-color:#ebebeb}.dropup-menu-item:active:not(:hover){background-color:transparent}.dropup-menu-item:first-child{padding-top:.49em;border-start-start-radius:inherit;border-start-end-radius:inherit}.dropup-menu-item:last-child{padding-bottom:.45em;border-end-start-radius:inherit;border-end-end-radius:inherit}.dropup-menu-item-icon{width:1.39em;position:relative}.dropup-menu-item-icon>svg{bottom:0!important;top:0!important;margin-bottom:auto;margin-top:auto}#dropup-menu-item-icon-element-custom{position:absolute;pointer-events:none;width:1.21em;height:1.21em;inset-inline-start:.28em;filter:brightness(0) saturate(100%) invert(15%) sepia(0%) saturate(337%) hue-rotate(125deg) brightness(91%) contrast(94%)}.dropup-menu-item-text{margin-inline-start:.56em;margin-top:.08em;width:max-content}#input{width:100%;display:inline-flex;text-align:center;margin-inline:auto;margin-top:auto;position:relative;justify-content:center}#chat-view{height:100%;grid-template-columns:100%}.deep-chat-downwards-mode{display:grid}.deep-chat-upwards-mode{display:flex;flex-direction:column}::-webkit-scrollbar{width:9px;height:9px}::-webkit-scrollbar-thumb{background-color:#d0d0d0;border-radius:5px}::-webkit-scrollbar-track{background-color:#f2f2f2}.deep-chat-web-model-button{margin-top:10px;margin-bottom:5px;margin-inline-start:1px}:host{all:initial;display:table-cell;height:350px;width:320px;border:1px solid #cacaca;font-family:Inter,sans-serif,Avenir,Helvetica,Arial;font-size:.9rem;background-color:#fff;position:relative;overflow:hidden}#container{height:inherit;width:inherit;overflow:hidden}";var eu=Object.defineProperty,N=function N(i,e,t,n){for(var s=void 0,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=o(e,t,s)||s);return s&&eu(e,t,s),s;};var P=/*#__PURE__*/function(_qi){function P(){var _this130;_classCallCheck(this,P);var e;_this130=_callSuper(this,P),_this130.getMessages=function(){return[];},_this130.submitUserMessage=function(){return console.warn(Ur("submitUserMessage"));},_this130.addMessage=function(){return console.warn(Ur("addMessage"));},_this130.updateMessage=function(){},_this130.clearMessages=function(){},_this130.focusInput=function(){return ln.focusFromParentElement(_this130._elementRef);},_this130.refreshMessages=function(){},_this130.scrollToBottom=function(){},_this130.disableSubmitButton=function(){},_this130.setPlaceholderText=function(){},_this130._hasBeenRendered=!1,_this130._auxiliaryStyleApplied=!1,_this130._chatStyleApplied=!1,_this130._elementRef=A(),_this130._elementRef.id="container",_this130.attachShadow({mode:"open"}).appendChild(_this130._elementRef),(e=_this130.shadowRoot)==null||e.appendChild(ut.buildElement()),jt.apply(Qh,_this130.shadowRoot),setTimeout(function(){_this130._hasBeenRendered||_this130.onRender();},20);return _this130;}_inherits(P,_qi);return _createClass(P,[{key:"changeToChatView",value:function changeToChatView(){this._activeService&&(this._activeService.validateKeyProperty=!1),this.onRender();}// prettier-ignore
275
+ },{key:"onRender",value:function onRender(){var _this$_childElement;var e;sr.attemptAppendStyleSheetToHead(this.style,(e=this.chatStyle)==null?void 0:e.fontFamily),le.processConnect(this),(!this._activeService||this._activeService.demo)&&(this._activeService=mh.create(this)),this.auxiliaryStyle&&!this._auxiliaryStyleApplied&&(jt.apply(this.auxiliaryStyle,this.shadowRoot),this._auxiliaryStyleApplied=!0),this.chatStyle&&!this._chatStyleApplied&&(jt.applyChatStyle(this.chatStyle,this.shadowRoot),this._chatStyleApplied=!0),le.checkForContainerStyles(this,this._elementRef),this._activeService.key&&this._activeService.validateKeyProperty?zs.render(this._elementRef,this.changeToChatView.bind(this),this._activeService):!(this._activeService instanceof k)||this._activeService.key?((_this$_childElement=this._childElement)!==null&&_this$_childElement!==void 0?_this$_childElement:this._childElement=this.children[0],Mr.render(this,this._elementRef,this._activeService,this._childElement)):this._activeService instanceof k&&Oe.render(this._elementRef,this.changeToChatView.bind(this),this._activeService),this._hasBeenRendered||hn.onRender(this),this._hasBeenRendered=!0;}},{key:"disconnectedCallback",value:function disconnectedCallback(){Ts.chat=void 0;}}]);}(qi);N([O("object")],P.prototype,"connect");N([O("object")],P.prototype,"directConnection");N([O("object")],P.prototype,"webModel");N([O("object")],P.prototype,"requestBodyLimits");N([O("function")],P.prototype,"requestInterceptor");N([O("function")],P.prototype,"responseInterceptor");N([O("function")],P.prototype,"validateInput");N([O("function")],P.prototype,"loadHistory");N([O("object")],P.prototype,"chatStyle");N([O("object")],P.prototype,"attachmentContainerStyle");N([O("object")],P.prototype,"dropupStyles");N([O("object")],P.prototype,"inputAreaStyle");N([O("object")],P.prototype,"textInput");N([O("object")],P.prototype,"defaultInput");N([O("object")],P.prototype,"submitButtonStyles");N([O("object")],P.prototype,"customButtons");N([O("string")],P.prototype,"auxiliaryStyle");N([O("array")],P.prototype,"history");N([O("object")],P.prototype,"browserStorage");N([O("object")],P.prototype,"introMessage");N([O("object")],P.prototype,"avatars");N([O("object")],P.prototype,"names");N([O("object")],P.prototype,"displayLoadingBubble");N([O("object")],P.prototype,"errorMessages");N([O("object")],P.prototype,"messageStyles");N([O("object")],P.prototype,"textToSpeech");N([O("object")],P.prototype,"speechToText");N([O("object")],P.prototype,"images");N([O("object")],P.prototype,"gifs");N([O("object")],P.prototype,"camera");N([O("object")],P.prototype,"audio");N([O("object")],P.prototype,"microphone");N([O("object")],P.prototype,"mixedFiles");N([O("object")],P.prototype,"dragAndDrop");N([O("object")],P.prototype,"htmlWrappers");N([O("object")],P.prototype,"htmlClassUtilities");N([O("object")],P.prototype,"remarkable");N([O("object")],P.prototype,"focusMode");N([O("boolean")],P.prototype,"upwardsMode");N([O("object")],P.prototype,"scrollButton");N([O("object")],P.prototype,"hiddenMessages");N([O("number")],P.prototype,"maxVisibleMessages");N([O("function")],P.prototype,"onMessage");N([O("function")],P.prototype,"onClearMessages");N([O("function")],P.prototype,"onComponentRender");N([O("function")],P.prototype,"onInput");N([O("function")],P.prototype,"onError");N([O("object")],P.prototype,"demo");N([O("object")],P.prototype,"_insertKeyViewStyles");customElements.define("deep-chat",P);export{P as DeepChat};